日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

随笔7

發布時間:2025/5/22 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 随笔7 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天在主播后臺中添加客服回復統計的功能,把遇到的問題和過程整理下來:
1.首先,在菜單的數據庫中添加一條"客服回復統計"的菜單數據,并添加到相應的父菜單中;寫一個頁面:

<!DOCTYPE html> <html> <head> <#include "../inc/inc.ftl"/> </head> <body> <div class="easyui-layout" data-options="fit:true,border:false" ><table id="dg"></table> </div> <div id="toolbar" style="padding:5px;height:auto"><form id="queryForm"><div>客服號:<input class="easyui-textbox" name="username" value="0" style="width:120px">時間:<input class="easyui-datetimebox" id="startDate" name="startDate" data-options="width:120">-<input class="easyui-datetimebox" id="endDate" name="endDate" data-options="width:120"><a href="javascript:void(0);" οnclick="javascript:loadData();" class="easyui-linkbutton" iconCls="icon-search">Search</a></div></form> </div> </body> </html> <script type="text/javascript">$(document).ready(function () {$('#startDate').datetimebox('setValue', getFormatDate(1));$('#endDate').datetimebox('setValue',getFormatDate(-1));loadData();});function getFormatDate(dateNum) {var day1 = new Date();day1.setTime(day1.getTime()-24*60*60*1000*dateNum);var s1 = day1.getFullYear()+"-" + (day1.getMonth()+1) + "-" + day1.getDate();return s1;}function loadData() {$("#dg").datagrid({url:'${request.contextPath}/examine/getStatisticsReplay',striped: true,border: false,collapsible:false, //是否可折疊的loadMsg:'正在加載數據...',fit: true, //自動大小singleSelect:true,//是否單選pagination:true,//分頁控件remoteSort: false,pageSize:50,showFooter: true,queryParams: $('#queryForm').serializeJSON(),columns:[[{field:'username',title:'客服號',width:110,halign:'center',},{field:'serviceAccid',title:'客服云信號',width:110,halign:'center',},{field: 'totalTime',title: '總時長',width: 100,halign: 'center',/* formatter: function (value, row, index) {return (value / 60).toFixed(0);}*/},{field:'replayNum',title:'總回復數',width:100,halign:'center',},{field:'aveTime',title:'平均回復時長',width:140,halign:'center'}]],toolbar: '#toolbar'});}</script>

效果是這樣:

欄目數和內容在

columns:

添加或刪除

2.習慣性寫完前端頁面后寫數據庫操作:

在StatisticsReplayRecordMapper中寫selectReplayRecord方法

public interface StatisticsReplayRecordMapper extends BaseMapper<StatisticsReplayRecord> {List<StatisticsReplayRecord> selectReplayRecord(@Param(value = "username") String username,@Param(value = "startDate")String startDate,@Param(value = "endDate")String endDate); }

然后去相應的xml進行配置:

在調試過程中有發現只能得到id和username的數據,是因為映射沒配置好

<resultMap id="BaseResultMap" type="com.yd.anchor.domain.mybatis.model.StatisticsReplayRecord"><result column="create_time" property="createTime" /><result column="modify_time" property="modifyTime" /><result column="service_accid" property="serviceAccid" /><result column="user_accid" property="userAccid" /><result column="interval_time" property="intervalTime" /></resultMap>

在mybatis中,數據庫字段的映射需要自己配置,特別注意resultMap 的id和type.

在寫where里面的內容時,我最初寫的是create_time>#{startDate} and?create_time<>#{endDate},但是出現了報錯,提示的大概意思是數據庫的格式不允許">"這類意思,網上描述的也很模糊,我改成了下面的語句后能正常運行

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <mapper namespace="com.yd.anchor.domain.mybatis.mapper.StatisticsReplayRecordMapper"><resultMap id="BaseResultMap" type="com.yd.anchor.domain.mybatis.model.StatisticsReplayRecord"><result column="create_time" property="createTime" /><result column="modify_time" property="modifyTime" /><result column="service_accid" property="serviceAccid" /><result column="user_accid" property="userAccid" /><result column="interval_time" property="intervalTime" /></resultMap><select id="selectReplayRecord" resultMap="BaseResultMap">select * from statistics_replay_record<where><if test="startDate != null and startDate != '' or endDate != null and endDate != ''">AND create_time between #{startDate} and #{endDate}</if><if test="username!= null and username!=''">and username=#{username}</if></where></select> </mapper>

?

3.controller的代碼省略了,直接到service層:

在寫的過程中發現

StatisticsReplayRecord中的字段和我需要返回前端的數據不同,所以創建了一個新的DTO用來承載這些數據 /*** 客服回復統計* @param username* @param startDate* @param endDate* @return*/public List<StatisticsReplayRecordDTO> getStatisticsReplay(String username, String startDate, String endDate){//根據username,startDate,endDate查詢到數據封裝在list中List<StatisticsReplayRecord> list = statisticsReplayRecordMapper.selectReplayRecord(username,startDate,endDate);StatisticsReplayRecordDTO dto=new StatisticsReplayRecordDTO();List<StatisticsReplayRecordDTO> list1 = new ArrayList<>();//對集合操作前判空if(!CollectionUtils.isEmpty(list)){dto.setTotalTime(0);dto.setUsername(list.get(0).getUsername());dto.setServiceAccid(list.get(0).getServiceAccid());dto.setReplayNum(list.size());//遍歷循環,每循環一次加上相應的時間list.forEach(x->{dto.setTotalTime(x.getIntervalTime()+dto.getTotalTime());});//調用Math.floor去掉小數Double ave = Math.floor(dto.getTotalTime()/dto.getReplayNum());dto.setAveTime(ave);list1.add(dto);}return list1;}

大概的操作都寫了注釋,但是需要注意一個是在對集合操作的時候要判空,另一個是要返回list或者規定的datagrid格式,因為頁面上是用easyui的datagrid接受,剛開始我直接返回dto,一直出現什么length的報錯.



?

轉載于:https://www.cnblogs.com/Lukizzz/p/9544443.html

總結

以上是生活随笔為你收集整理的随笔7的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。