Parcourir la source

大屏统计接口功能完善

王苗苗 il y a 3 mois
Parent
commit
214cec92c5

BIN
.DS_Store


+ 1 - 1
slibra-common/src/main/java/com/slibra/common/constant/MyConstants.java

@@ -414,7 +414,7 @@ public class MyConstants {
     //字典配置
     //字典配置
     public static final String TPFQD = "tpfqd";
     public static final String TPFQD = "tpfqd";
 
 
-    public static final int DEFAULT_DAYS_QUERY_COUNT = 7;
+    public static final int DEFAULT_DAYS_QUERY_COUNT = 6;
 
 
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {

+ 61 - 27
slibra-common/src/main/java/com/slibra/common/utils/DateUtils.java

@@ -13,6 +13,8 @@ import java.util.List;
 
 
 import org.apache.commons.lang3.time.DateFormatUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
 
 
+import static com.slibra.common.constant.MyConstants.DEFAULT_DAYS_QUERY_COUNT;
+
 /**
 /**
  * 时间工具类
  * 时间工具类
  * 
  * 
@@ -251,7 +253,12 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
         return dates;
         return dates;
     }
     }
 
 
-
+    /**
+     * 获取n个月之前的YYYY_MM格式的月份数据,输入参数也为YYYY_MM
+     * @param inputDate
+     * @param n
+     * @return
+     */
     public static String getMonthsBefore(String inputDate, int n) {
     public static String getMonthsBefore(String inputDate, int n) {
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern(YYYY_MM_DD);
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern(YYYY_MM_DD);
         DateTimeFormatter formatterOut = DateTimeFormatter.ofPattern(YYYY_MM);
         DateTimeFormatter formatterOut = DateTimeFormatter.ofPattern(YYYY_MM);
@@ -278,7 +285,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
 
 
 
 
     public static String getNYearSameMonth(String inputDate, int n) {
     public static String getNYearSameMonth(String inputDate, int n) {
-        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(YYYY_MM);
         try {
         try {
             // 解析输入的字符串为YearMonth对象
             // 解析输入的字符串为YearMonth对象
             YearMonth currentYearMonth = YearMonth.parse(inputDate, formatter);
             YearMonth currentYearMonth = YearMonth.parse(inputDate, formatter);
@@ -302,7 +309,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
      * @throws ParseException 如果日期字符串格式不正确
      * @throws ParseException 如果日期字符串格式不正确
      */
      */
     public static List<String> getAllDatesInRangeStr(String startDateStr, String endDateStr) {
     public static List<String> getAllDatesInRangeStr(String startDateStr, String endDateStr) {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        SimpleDateFormat sdf = new SimpleDateFormat(YYYY_MM_DD);
         Date startDate = null;
         Date startDate = null;
         Date endDate = null;
         Date endDate = null;
         try {
         try {
@@ -345,31 +352,58 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
     }
     }
 
 
 
 
+
+    public static List<String> getMonthsBetween(String startDateStr, String endDateStr) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(YYYY_MM);
+        YearMonth startDate = YearMonth.parse(startDateStr, formatter);
+        YearMonth endDate = YearMonth.parse(endDateStr, formatter);
+
+        List<String> monthsBetween = new ArrayList<>();
+        YearMonth currentMonth = startDate;
+
+        while (!currentMonth.isAfter(endDate)) {
+            monthsBetween.add(currentMonth.format(formatter));
+            currentMonth = currentMonth.plusMonths(1);
+        }
+
+        return monthsBetween;
+    }
+
+
     public static void main(String[] args) {
     public static void main(String[] args) {
-        Date nowDate = DateUtils.getNowDate();
-        Date date = plusDate(1, nowDate);
-        Date date1 = plusDate(-1, nowDate);
-        System.out.println(date);
-        System.out.println(date1);
-        /*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));
-        List<String> allDatesInRangeDate = getAllDatesInRangeDate(date1, date);
-        for (String s : allDatesInRangeDate) {
-            System.out.println(s);
+        Date nowDate = getNowDate();
+        //近七日呼入电话量趋势
+        String date = DateUtils.getDate();
+        String sevenDaysAgo = DateUtils.plusDate(-DEFAULT_DAYS_QUERY_COUNT, nowDate, YYYY_MM_DD);
+        List<String> allDatesInRangeStr = DateUtils.getAllDatesInRangeStr(sevenDaysAgo, date);
+        for (String todayYearDate : allDatesInRangeStr) {
+            System.out.println(todayYearDate);
         }
         }
-        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();
-        }*/
-        System.out.println(plusDate(-1, nowDate, YYYY_MM_DD));
+        System.out.println("11111111");
+        //近七日呼入电话量趋势--去年数据
+        String dateLastYear = DateUtils.getNYearSameDay(date, 1);
+        String sevenDaysAgoLastYear = DateUtils.getNYearSameDay(sevenDaysAgo, 1);
+        List<String> allDatesInRangeStrLastYear = DateUtils.getAllDatesInRangeStr(sevenDaysAgoLastYear, dateLastYear);
+        for (String lastYearDate : allDatesInRangeStrLastYear) {
+            System.out.println(lastYearDate);
+        }
+        System.out.println("22222222");
+        //近7个月电话量同比趋势
+        //获取当前的月份
+        String nowMonth = DateUtils.parseDateToStr(DateUtils.YYYY_MM, nowDate);
+        String sevenMonthAgo = DateUtils.getMonthsBefore(nowMonth, DEFAULT_DAYS_QUERY_COUNT);
+        List<String> todayMonths = DateUtils.getMonthsBetween(sevenMonthAgo, nowMonth);
+        for (String todayMonth : todayMonths) {
+            System.out.println(todayMonth);
+        }
+        System.out.println("333333333");
+        //近7个月电话量同比趋势--去年数据
+        String nowMonthLastYear = DateUtils.getNYearSameMonth(nowMonth, 1);
+        String sevenMonthAgoLastYear = DateUtils.getMonthsBefore(nowMonthLastYear, DEFAULT_DAYS_QUERY_COUNT);
+        List<String> lastYearMonths = DateUtils.getMonthsBetween(sevenMonthAgoLastYear, nowMonthLastYear);
+        for (String lastYearMonth : lastYearMonths) {
+            System.out.println(lastYearMonth);
+        }
+
     }
     }
 }
 }

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

@@ -102,4 +102,8 @@ public interface TCallRecordMapper
     int getRecentCallRecordAfterSomeDay(@Param("type") Integer type, @Param("date") String date);
     int getRecentCallRecordAfterSomeDay(@Param("type") Integer type, @Param("date") String date);
 
 
     long getRecentCallTimes(String date);
     long getRecentCallTimes(String date);
+
+    int getCallInEqualsDay(String date);
+
+    int getCallInEqualsMonth(String month);
 }
 }

+ 6 - 0
slibra-system/src/main/java/com/slibra/business/res/HomeCountResp.java

@@ -38,9 +38,15 @@ public class HomeCountResp {
     //近七日呼入电话量趋势
     //近七日呼入电话量趋势
     private List<DayAndCountRes> recent7DayAndCounts;
     private List<DayAndCountRes> recent7DayAndCounts;
 
 
+    //近七日呼入电话量趋势--去年数据
+    private List<DayAndCountRes> recent7DayAndCountsLastYear;
+
     //近7个月电话量同比趋势
     //近7个月电话量同比趋势
     private List<DayAndCountRes> recent7MonthAndCounts;
     private List<DayAndCountRes> recent7MonthAndCounts;
 
 
+    //近7个月电话量同比趋势--去年数据
+    private List<DayAndCountRes> recent7MonthAndCountsLastYear;
+
     //本月业务类型 top7
     //本月业务类型 top7
     private List<Top7Res> businessTop7;
     private List<Top7Res> businessTop7;
     //------中间的图表数据------截止
     //------中间的图表数据------截止

+ 51 - 2
slibra-system/src/main/java/com/slibra/business/service/impl/TCallRecordServiceImpl.java

@@ -536,7 +536,7 @@ public class TCallRecordServiceImpl implements ITCallRecordService
     public HomeCountResp homeScreenCount() {
     public HomeCountResp homeScreenCount() {
         HomeCountResp build = HomeCountResp.builder().build();
         HomeCountResp build = HomeCountResp.builder().build();
         //获取7天前的日期
         //获取7天前的日期
-        String lastDate = DateUtils.plusDate(-1, DateUtils.getNowDate(), YYYY_MM_DD);
+        String lastDate = DateUtils.plusDate(-DEFAULT_DAYS_QUERY_COUNT, DateUtils.getNowDate(), YYYY_MM_DD);
         //查询说明: type未空是查询所有呼入的 0:成功接通的
         //查询说明: type未空是查询所有呼入的 0:成功接通的
         int inTotal = this.tCallRecordMapper.getRecentCallRecordAfterSomeDay(null, lastDate);
         int inTotal = this.tCallRecordMapper.getRecentCallRecordAfterSomeDay(null, lastDate);
         build.setInTotal(inTotal);
         build.setInTotal(inTotal);
@@ -549,7 +549,56 @@ public class TCallRecordServiceImpl implements ITCallRecordService
             build.setInTimesAvg(inTimes/inTotalSuccess);
             build.setInTimesAvg(inTimes/inTotalSuccess);
         build.setTotalTimes(this.tCallRecordMapper.getRecentCallTimes(null));
         build.setTotalTimes(this.tCallRecordMapper.getRecentCallTimes(null));
         build.setTotalCounts(this.tCallRecordMapper.getRecentCallRecordAfterSomeDay(null, null));
         build.setTotalCounts(this.tCallRecordMapper.getRecentCallRecordAfterSomeDay(null, null));
-
+        //近七日呼入电话量趋势
+        List<DayAndCountRes> recent7DayAndCounts = new ArrayList<>();
+        List<DayAndCountRes> recent7DayAndCountsLastYear = new ArrayList<>();
+        Date nowDate = DateUtils.getNowDate();
+        String date = DateUtils.getDate();
+        String sevenDaysAgo = DateUtils.plusDate(-DEFAULT_DAYS_QUERY_COUNT, nowDate, YYYY_MM_DD);
+        List<String> allDatesInRangeStr = DateUtils.getAllDatesInRangeStr(sevenDaysAgo, date);
+        for (String todayYearDate : allDatesInRangeStr) {
+            DayAndCountRes dayAndCountRes = new DayAndCountRes();
+            dayAndCountRes.setDate(todayYearDate);
+            dayAndCountRes.setCount(this.tCallRecordMapper.getCallInEqualsDay(todayYearDate));
+            recent7DayAndCounts.add(dayAndCountRes);
+        }
+        build.setRecent7DayAndCounts(recent7DayAndCounts);
+        //近七日呼入电话量趋势--去年数据
+        String dateLastYear = DateUtils.getNYearSameDay(date, 1);
+        String sevenDaysAgoLastYear = DateUtils.getNYearSameDay(sevenDaysAgo, 1);
+        List<String> allDatesInRangeStrLastYear = DateUtils.getAllDatesInRangeStr(sevenDaysAgoLastYear, dateLastYear);
+        for (String lastYearDate : allDatesInRangeStrLastYear) {
+            DayAndCountRes dayAndCountRes = new DayAndCountRes();
+            dayAndCountRes.setDate(lastYearDate);
+            dayAndCountRes.setCount(this.tCallRecordMapper.getCallInEqualsDay(lastYearDate));
+            recent7DayAndCountsLastYear.add(dayAndCountRes);
+        }
+        build.setRecent7DayAndCountsLastYear(recent7DayAndCountsLastYear);
+        //近7个月电话量同比趋势
+        List<DayAndCountRes> recent7MonthAndCounts = new ArrayList<>();
+        //获取当前的月份
+        String nowMonth = DateUtils.parseDateToStr(DateUtils.YYYY_MM, nowDate);
+        String sevenMonthAgo = DateUtils.getMonthsBefore(nowMonth, DEFAULT_DAYS_QUERY_COUNT);
+        List<String> todayMonths = DateUtils.getMonthsBetween(sevenMonthAgo, nowMonth);
+        for (String todayMonth : todayMonths) {
+            DayAndCountRes dayAndCountRes = new DayAndCountRes();
+            dayAndCountRes.setDate(todayMonth);
+            dayAndCountRes.setCount(this.tCallRecordMapper.getCallInEqualsMonth(todayMonth));
+            recent7MonthAndCounts.add(dayAndCountRes);
+        }
+        build.setRecent7MonthAndCounts(recent7MonthAndCounts);
+        //近7个月电话量同比趋势--去年数据
+        List<DayAndCountRes> recent7MonthAndCountsLastYear = new ArrayList<>();
+        String nowMonthLastYear = DateUtils.getNYearSameMonth(nowMonth, 1);
+        String sevenMonthAgoLastYear = DateUtils.getMonthsBefore(nowMonthLastYear, DEFAULT_DAYS_QUERY_COUNT);
+        List<String> lastYearMonths = DateUtils.getMonthsBetween(sevenMonthAgoLastYear, nowMonthLastYear);
+        for (String lastYearMonth : lastYearMonths) {
+            DayAndCountRes dayAndCountRes = new DayAndCountRes();
+            dayAndCountRes.setDate(lastYearMonth);
+            dayAndCountRes.setCount(this.tCallRecordMapper.getCallInEqualsMonth(lastYearMonth));
+            recent7MonthAndCountsLastYear.add(dayAndCountRes);
+        }
+        build.setRecent7MonthAndCountsLastYear(recent7MonthAndCountsLastYear);
         return build;
         return build;
     }
     }
 
 

+ 27 - 5
slibra-system/src/main/resources/mapper/business/TCallRecordMapper.xml

@@ -280,7 +280,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         WHERE
         WHERE
             1 = 1 and service_category = 2 AND del_flag = 0
             1 = 1 and service_category = 2 AND del_flag = 0
         <if test="userId != null "> and user_id = #{userId} </if>
         <if test="userId != null "> and user_id = #{userId} </if>
-        <if test="date != null "> and DATE_FORMAT(create_time, '%Y-%m-%d') = #{date} </if>
+        <if test="date != null "> and DATE_FORMAT(time_begin, '%Y-%m-%d') = #{date} </if>
     </select>
     </select>
 
 
     <select id="getPersonCountByState" resultType="int">
     <select id="getPersonCountByState" resultType="int">
@@ -395,7 +395,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
           AND del_flag = 0
           AND del_flag = 0
           AND category = #{category}
           AND category = #{category}
           AND user_id = #{userId}
           AND user_id = #{userId}
-        <if test="date != null "> and DATE_FORMAT(create_time, '%Y-%m-%d') = #{date} </if>
+        <if test="date != null "> and DATE_FORMAT(time_begin, '%Y-%m-%d') = #{date} </if>
     </select>
     </select>
 
 
 
 
@@ -407,7 +407,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         WHERE
         WHERE
             del_flag = 0
             del_flag = 0
           AND category = 0
           AND category = 0
-          AND DATE_FORMAT(create_time, '%Y-%m-%d') = #{date}
+          AND DATE_FORMAT(time_begin, '%Y-%m-%d') = #{date}
         <if test="type != null ">
         <if test="type != null ">
             <choose>
             <choose>
                 <when test="0 == type">
                 <when test="0 == type">
@@ -444,7 +444,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         del_flag = 0
         del_flag = 0
         AND category = 0
         AND category = 0
         <if test="date != null and date != ''">
         <if test="date != null and date != ''">
-            AND DATE_FORMAT(create_time, '%Y-%m-%d') >= #{date}
+            AND DATE_FORMAT(time_begin, '%Y-%m-%d') >= #{date}
         </if>
         </if>
         <if test="type != null ">
         <if test="type != null ">
             <choose>
             <choose>
@@ -482,7 +482,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             del_flag = 0
             del_flag = 0
           AND category = 0
           AND category = 0
         <if test="date != null and date != ''">
         <if test="date != null and date != ''">
-          AND DATE_FORMAT( create_time, '%Y-%m-%d' ) >= #{date}
+          AND DATE_FORMAT(time_begin, '%Y-%m-%d' ) >= #{date}
         </if>
         </if>
     </select>
     </select>
+
+    <select id="getCallInEqualsDay" resultType="int">
+        SELECT
+            IFNULL( SUM( times ), 0 )
+        FROM
+            t_call_record
+        WHERE
+            del_flag = 0
+          AND category = 0
+          AND DATE_FORMAT(time_begin, '%Y-%m-%d' ) = #{date}
+    </select>
+
+    <select id="getCallInEqualsMonth" resultType="int">
+        SELECT
+            IFNULL( SUM( times ), 0 )
+        FROM
+            t_call_record
+        WHERE
+            del_flag = 0
+          AND category = 0
+          AND DATE_FORMAT(time_begin, '%Y-%m' ) = #{date}
+    </select>
 </mapper>
 </mapper>