Просмотр исходного кода

新增统计人工客服和机器人客服相关的数据

王苗苗 2 дней назад
Родитель
Сommit
80dc07b67f

+ 23 - 0
slibra-admin/src/main/java/com/slibra/web/controller/business/FrontController.java

@@ -9,6 +9,7 @@ import com.slibra.business.mapper.*;
 import com.slibra.business.req.AiChatReq;
 import com.slibra.business.req.AiChatRes;
 import com.slibra.business.res.CallRecordCount;
+import com.slibra.business.res.CallUserCountInfo;
 import com.slibra.business.res.PumpAndNumber;
 import com.slibra.business.service.IFrontService;
 import com.slibra.business.service.ITCallRecordService;
@@ -101,6 +102,28 @@ public class FrontController extends BaseController {
     }
 
 
+    /**
+     * 人工客服统计 接口
+     * @return
+     */
+    @GetMapping("/userCallCount")
+    public R<List<CallUserCountInfo>> userCallCount(){
+        log.info("进入了 人工客服统计 接口");
+        return R.ok(this.itCallRecordService.userCallCount());
+    }
+
+
+    /**
+     * 机器人客服统计 接口
+     * @return
+     */
+    @GetMapping("/robotCallCount")
+    public R<List<CallUserCountInfo>> robotCallCount(){
+        log.info("进入了 机器人客服统计 接口");
+        return R.ok(this.itCallRecordService.robotCallCount());
+    }
+
+
 
 
 

+ 8 - 2
slibra-system/src/main/java/com/slibra/business/mapper/TCallRecordMapper.java

@@ -2,9 +2,9 @@ package com.slibra.business.mapper;
 
 import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import com.slibra.business.domain.TCallRecord;
+import com.slibra.business.res.CallUserCountInfo;
 import org.apache.ibatis.annotations.Param;
 
 /**
@@ -85,5 +85,11 @@ public interface TCallRecordMapper
 
     int getPersonCountRecordIsRobot(int type);
 
-    long getPersonTotalRecordIsRobot(int type);
+    long getPersonTotalRecordIsRobot(@Param("type") int type, @Param("userId") String userId);
+
+    List<CallUserCountInfo> selectAllUsersByType(int type);
+
+    Integer getStatusByUserId(String userId);
+
+    int getCountByTypeAndDate(@Param("category") int category, @Param("date") String date);
 }

+ 39 - 0
slibra-system/src/main/java/com/slibra/business/res/CallUserCountInfo.java

@@ -0,0 +1,39 @@
+package com.slibra.business.res;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Builder
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+//人工客服/机器人客统计返回的bean
+public class CallUserCountInfo {
+
+    //客服编号
+    private String userId;
+
+    //姓名
+    private String userName;
+
+    //当前状态
+    private Integer status;
+
+    //今日呼入
+    private int inTodayCount;
+
+    //累计呼入
+    private int inAllCount;
+
+    //今日呼出
+    private int outTodayCount;
+
+    //累计呼出
+    private int outAllCount;
+
+    //累计通话时长
+    private long totalTimes;
+}
+

+ 5 - 0
slibra-system/src/main/java/com/slibra/business/service/ITCallRecordService.java

@@ -5,6 +5,7 @@ import java.util.List;
 
 import com.slibra.business.domain.TCallRecord;
 import com.slibra.business.res.CallRecordCount;
+import com.slibra.business.res.CallUserCountInfo;
 
 /**
  * 通话记录Service接口
@@ -71,4 +72,8 @@ public interface ITCallRecordService
     String updateFile2TextByIdOneLine(Long id);
 
     CallRecordCount callRecordCountInfo();
+
+    List<CallUserCountInfo> userCallCount();
+
+    List<CallUserCountInfo> robotCallCount();
 }

+ 46 - 6
slibra-system/src/main/java/com/slibra/business/service/impl/TCallRecordServiceImpl.java

@@ -1,9 +1,6 @@
 package com.slibra.business.service.impl;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 
 import com.alibaba.fastjson2.JSON;
 import com.slibra.business.domain.TCutOffWater;
@@ -11,6 +8,7 @@ import com.slibra.business.domain.TUserInfo;
 import com.slibra.business.mapper.TCutOffWaterMapper;
 import com.slibra.business.mapper.TUserInfoMapper;
 import com.slibra.business.res.CallRecordCount;
+import com.slibra.business.res.CallUserCountInfo;
 import com.slibra.common.DecimalUtils;
 import com.slibra.common.exception.ServiceException;
 import com.slibra.common.utils.DateUtils;
@@ -286,16 +284,58 @@ public class TCallRecordServiceImpl implements ITCallRecordService
 
         //通话次数和通话时长
         callRecordCount.setPersonCount(this.tCallRecordMapper.getPersonCountRecordIsRobot(0));
-        callRecordCount.setPersonTotal(this.tCallRecordMapper.getPersonTotalRecordIsRobot(0));
+        callRecordCount.setPersonTotal(this.tCallRecordMapper.getPersonTotalRecordIsRobot(0, null));
 
         callRecordCount.setRobotCount(this.tCallRecordMapper.getPersonCountRecordIsRobot(1));
-        callRecordCount.setRobotTotal(this.tCallRecordMapper.getPersonTotalRecordIsRobot(1));
+        callRecordCount.setRobotTotal(this.tCallRecordMapper.getPersonTotalRecordIsRobot(1, null));
         //转人工次数
         callRecordCount.setRobotTransfer(transferCount);
 
         return callRecordCount;
     }
 
+    @Override
+    public List<CallUserCountInfo> userCallCount() {
+        //先获取所有的人工信息 再查状态 再统计数据
+        List<CallUserCountInfo> result = this.tCallRecordMapper.selectAllUsersByType(0);
+        String date = DateUtils.getDate();
+        if(!CollectionUtils.isEmpty(result)){
+            for (CallUserCountInfo callUserCountInfo : result) {
+                String userId = callUserCountInfo.getUserId();
+                if(StringUtils.isNotBlank(userId)){
+                    callUserCountInfo.setStatus(this.tCallRecordMapper.getStatusByUserId(userId));
+                    callUserCountInfo.setTotalTimes(this.tCallRecordMapper.getPersonTotalRecordIsRobot(0, userId));
+                    callUserCountInfo.setInTodayCount(this.tCallRecordMapper.getCountByTypeAndDate(0, date));
+                    callUserCountInfo.setInAllCount(this.tCallRecordMapper.getCountByTypeAndDate(0, null));
+                    callUserCountInfo.setOutTodayCount(this.tCallRecordMapper.getCountByTypeAndDate(1, date));
+                    callUserCountInfo.setOutAllCount(this.tCallRecordMapper.getCountByTypeAndDate(1, null));
+                }
+            }
+        }
+        return result;
+    }
+
+    @Override
+    public List<CallUserCountInfo> robotCallCount() {
+        //先获取所有的机器人信息 再查状态 再统计数据
+        List<CallUserCountInfo> result = this.tCallRecordMapper.selectAllUsersByType(1);
+        String date = DateUtils.getDate();
+        if(!CollectionUtils.isEmpty(result)){
+            for (CallUserCountInfo callUserCountInfo : result) {
+                String userId = callUserCountInfo.getUserId();
+                if(StringUtils.isNotBlank(userId)){
+//                    callUserCountInfo.setStatus(this.tCallRecordMapper.getStatusByUserId(userId));
+                    callUserCountInfo.setTotalTimes(this.tCallRecordMapper.getPersonTotalRecordIsRobot(1, userId));
+                    callUserCountInfo.setInTodayCount(this.tCallRecordMapper.getCountByTypeAndDate(0, date));
+                    callUserCountInfo.setInAllCount(this.tCallRecordMapper.getCountByTypeAndDate(0, null));
+                    callUserCountInfo.setOutTodayCount(this.tCallRecordMapper.getCountByTypeAndDate(1, date));
+                    callUserCountInfo.setOutAllCount(this.tCallRecordMapper.getCountByTypeAndDate(1, null));
+                }
+            }
+        }
+        return result;
+    }
+
 
     /**
      * 校验数据

+ 41 - 0
slibra-system/src/main/resources/mapper/business/TCallRecordMapper.xml

@@ -278,5 +278,46 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         AND del_flag = 0
         <if test="type == 0 "> and service_category = 0</if>
         <if test="type == 1 "> and service_category != 0 </if>
+        <if test="userId != null "> and user_id = #{userId} </if>
+    </select>
+
+    <select id="selectAllUsersByType" resultType="com.slibra.business.res.CallUserCountInfo">
+        SELECT DISTINCT
+            user_id userId,
+            user_name userName
+        FROM
+            t_call_record
+        WHERE
+            1 = 1
+          AND del_flag = 0
+        <if test="type == 0 "> and service_category = 0</if>
+        <if test="type == 1 "> and service_category != 0 </if>
+    </select>
+
+    <select id="getStatusByUserId" resultType="java.lang.Integer">
+        SELECT
+            service_state
+        FROM
+            c_agent_monitor
+        WHERE
+            out_id = (
+                SELECT
+                    out_id
+                FROM
+                    c_agent
+                WHERE
+                    user_id = #{userId} AND is_delete = 0 LIMIT 1)
+    </select>
+
+    <select id="getCountByTypeAndDate" resultType="int">
+        SELECT
+            COUNT(*)
+        FROM
+            t_call_record
+        WHERE
+            1 = 1
+          AND del_flag = 0
+          AND category = #{category}
+        <if test="date != null "> and DATE_FORMAT(create_time, '%Y-%m-%d') = #{date} </if>
     </select>
 </mapper>