Bläddra i källkod

统计列表逻辑完善

王苗苗 3 månader sedan
förälder
incheckning
fd535c8efe

+ 28 - 8
slibra-common/src/main/java/com/slibra/common/utils/DateUtils.java

@@ -287,11 +287,16 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
      * @return 包含所有日期的集合
      * @throws ParseException 如果日期字符串格式不正确
      */
-    public static List<String> getAllDatesInRangeStr(String startDateStr, String endDateStr) throws ParseException {
+    public static List<String> getAllDatesInRangeStr(String startDateStr, String endDateStr) {
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-        Date startDate = sdf.parse(startDateStr);
-        Date endDate = sdf.parse(endDateStr);
-
+        Date startDate = null;
+        Date endDate = null;
+        try {
+            startDate = sdf.parse(startDateStr);
+            endDate = sdf.parse(endDateStr);
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
         List<String> dateList = new ArrayList<>();
         Calendar calendar = Calendar.getInstance();
         calendar.setTime(startDate);
@@ -300,7 +305,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         dateList.add(sdf.format(calendar.getTime()));
 
         // 循环遍历日期范围
-        while (!calendar.getTime().after(endDate)) {
+        while (calendar.getTime().before(endDate)) {
             calendar.add(Calendar.DAY_OF_MONTH, 1);
             dateList.add(sdf.format(calendar.getTime()));
         }
@@ -318,7 +323,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         dateList.add(sdf.format(calendar.getTime()));
 
         // 循环遍历日期范围
-        while (!calendar.getTime().after(endDate)) {
+        while (calendar.getTime().before(endDate)) {
             calendar.add(Calendar.DAY_OF_MONTH, 1);
             dateList.add(sdf.format(calendar.getTime()));
         }
@@ -332,9 +337,24 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         Date date1 = plusDate(-1, nowDate);
         System.out.println(date);
         System.out.println(date1);
-        System.out.println(getMonthsBefore("2024-02", 2));
+        /*System.out.println(getMonthsBefore("2024-02", 2));
         System.out.println();
         System.out.println(getNYearSameDay("2024-02-01", 1));
-        System.out.println(getNYearSameMonth("2024-02", 1));
+        System.out.println(getNYearSameMonth("2024-02", 1));*/
+        List<String> allDatesInRangeDate = getAllDatesInRangeDate(date1, date);
+        for (String s : allDatesInRangeDate) {
+            System.out.println(s);
+        }
+        System.out.println("------");
+        try {
+            String startDate = "2023-10-01";
+            String endDate = "2023-10-10";
+            List<String> dates = getAllDatesInRangeStr(startDate, endDate);
+            for (String s : dates) {
+                System.out.println(s);
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
     }
 }

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

@@ -97,4 +97,6 @@ public interface TCallRecordMapper
     int getPersonCountByType(int type);
 
     List<CallUserCountInfo> selectAllPersonUserIds();
+
+    int getTotalInByType(Integer type);
 }

+ 34 - 3
slibra-system/src/main/java/com/slibra/business/service/impl/TCallRecordServiceImpl.java

@@ -489,14 +489,45 @@ public class TCallRecordServiceImpl implements ITCallRecordService
 
     @Override
     public List<CallRecordListResp> callRecordCountPageList(TCallRecord callRecordReq) {
+        List<CallRecordListResp> result = new ArrayList<>();
         String timeBeginReq = callRecordReq.getTimeBeginReq();
         String timeEndReq = callRecordReq.getTimeEndReq();
         if(StringUtils.isBlank(timeBeginReq) || StringUtils.isBlank(timeEndReq))
           throw new ServiceException("起止日期必须填写");
         //获取2个时间段内的所有日期,经确到天,即【yyyy-MM-dd】格式的
-        List<String> allDatesInRangeDate = DateUtils.getAllDatesInRangeDate(null, null);
-        return null;
-
+        List<String> allDatesInRangeDate = DateUtils.getAllDatesInRangeStr(timeBeginReq, timeEndReq);
+        if(!CollectionUtils.isEmpty(allDatesInRangeDate)){
+            for (String date : allDatesInRangeDate) {
+                CallRecordListResp callRecordListResp = new CallRecordListResp();
+                callRecordListResp.setDate(date);
+                //根据日期获取统计数据
+                //请求参数type说明: 0:接通总量  1:未接通总量  2:机器人接听  3:机器人转人工  4:人工接听  5:机器人处理量  6:人工处理量
+                //呼入总量
+                int inTotal = this.tCallRecordMapper.getTotalInByType(null);
+                callRecordListResp.setInTotal(inTotal);
+                callRecordListResp.setSuccessTotal(this.tCallRecordMapper.getTotalInByType(0));
+                callRecordListResp.setFailTotal(this.tCallRecordMapper.getTotalInByType(1));
+                callRecordListResp.setRobotHearTotal(this.tCallRecordMapper.getTotalInByType(2));
+                callRecordListResp.setTransferTotal(this.tCallRecordMapper.getTotalInByType(3));
+                callRecordListResp.setHumanTotal(this.tCallRecordMapper.getTotalInByType(4));
+                //机器人处理量
+                int robotHandleTotal = this.tCallRecordMapper.getTotalInByType(5);
+                callRecordListResp.setRobotHandleTotal(robotHandleTotal);
+                //人工处理量
+                int humanHandleTotal = this.tCallRecordMapper.getTotalInByType(6);
+                callRecordListResp.setHumanHandleTotal(humanHandleTotal);
+                //处理 占比
+                if(inTotal > 0){
+                    BigDecimal robotRate = DecimalUtils.getNLengthHalfUp(new BigDecimal(robotHandleTotal/(double)inTotal).multiply(BigDecimal_100), INT_2);
+                    BigDecimal humanRate = DecimalUtils.getNLengthHalfUp(new BigDecimal(humanHandleTotal/(double)inTotal).multiply(BigDecimal_100), INT_2);
+                    callRecordListResp.setRobotRate(robotRate);
+                    callRecordListResp.setHumanRate(humanRate);
+                    callRecordListResp.setFailRate(DecimalUtils.getNLengthHalfUp(BigDecimal_100.subtract(robotRate).subtract(humanRate), INT_2));
+                }
+                result.add(callRecordListResp);
+            }
+        }
+        return result;
     }
 
 

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

@@ -383,4 +383,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
           AND user_id = #{userId}
         <if test="date != null "> and DATE_FORMAT(create_time, '%Y-%m-%d') = #{date} </if>
     </select>
+
+
+    <select id="getTotalInByType" resultType="int">
+        SELECT
+            COUNT(*)
+        FROM
+            t_call_record
+        WHERE
+            del_flag = 0
+          AND category = 0
+        <if test="type != null ">
+            <choose>
+                <when test="0 == type">
+                    AND status = 1
+                </when>
+                <when test="1 == type">
+                    AND status = 0
+                </when>
+                <when test="2 == type">
+                    AND (service_category = 1 or service_category = 2)
+                </when>
+                <when test="3 == type">
+                    AND service_category = 2
+                </when>
+                <when test="4 == type">
+                    AND service_category = 0
+                </when>
+                <when test="5 == type">
+                    AND service_category = 1
+                </when>
+                <when test="6 == type">
+                    AND (service_category = 2 or service_category = 0)
+                </when>
+            </choose>
+        </if>
+    </select>
 </mapper>