Explorar el Código

总后台看课统计营期维度bug修复

wangxy hace 2 días
padre
commit
06964500a8

+ 10 - 0
fs-admin/src/main/java/com/fs/course/controller/FsUserCoursePeriodController.java

@@ -264,6 +264,16 @@ public class FsUserCoursePeriodController extends BaseController {
         return R.ok().put("data", new PageInfo<>(periodList));
     }
 
+    @GetMapping("/getAllPeriodList")
+    public  R getAllPeriodList(@RequestParam(required = false) String name,
+                               @RequestParam(required = false) Long campId) {
+        Map<String,Object> params = new HashMap<>();
+        params.put("name", name);
+        params.put("campId", campId);
+        List<OptionsVO> periodList =  fsUserCoursePeriodDaysService.selectPeriodListByMap(params);
+        return R.ok().put("data", periodList);
+    }
+
     @PreAuthorize("@ss.hasPermi('course:period:courseMove')")
     @ApiOperation("营期课程-上移/下移")
     @PutMapping("/courseMove")

+ 22 - 22
fs-service/src/main/java/com/fs/course/service/impl/FsCourseWatchLogServiceImpl.java

@@ -1323,27 +1323,27 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
                 .collect(Collectors.toList());
         param.setCompanyIds(companyIds);
 
-        Map<Long, FsCourseReportVO> watchStatistics = getWatchStatistics(param);
-        Map<Long, FsCourseReportVO> answerStatistics = getAnswerStatistics(param);
-        Map<Long, FsCourseReportVO> redPacketStatistics = getRedPacketStatistics(param);
+        Map<String , FsCourseReportVO> watchStatistics = getWatchStatistics(param);
+        Map<String, FsCourseReportVO> answerStatistics = getAnswerStatistics(param);
+        Map<String, FsCourseReportVO> redPacketStatistics = getRedPacketStatistics(param);
         // 4. 组装最终结果
         return assembleStatisticsResult(companyList, watchStatistics, answerStatistics,
                 redPacketStatistics, param);
     }
 
-    private List<FsCourseReportVO> assembleStatisticsResult(List<FsCourseReportVO> companyList, Map<Long, FsCourseReportVO> watchStatistics, Map<Long, FsCourseReportVO> answerStatistics, Map<Long, FsCourseReportVO> redPacketStatistics, FsCourseWatchLogStatisticsListParam param) {
+    private List<FsCourseReportVO> assembleStatisticsResult(List<FsCourseReportVO> companyList, Map<String, FsCourseReportVO> watchStatistics, Map<String, FsCourseReportVO> answerStatistics, Map<String, FsCourseReportVO> redPacketStatistics, FsCourseWatchLogStatisticsListParam param) {
         for (FsCourseReportVO company : companyList) {
             FsCourseReportVO watchStats;
             FsCourseReportVO answerStats;
             FsCourseReportVO redPacketStats;
             if ("camp".equals(param.getDimension())) {
-                watchStats = watchStatistics.getOrDefault(company.getPeriodId(), new FsCourseReportVO());
-                answerStats = answerStatistics.getOrDefault(company.getPeriodId(), new FsCourseReportVO());
-                redPacketStats = redPacketStatistics.getOrDefault(company.getPeriodId(), new FsCourseReportVO());
+                watchStats = watchStatistics.getOrDefault(company.getPeriodId() + "_" + company.getCompanyId(), new FsCourseReportVO());
+                answerStats = answerStatistics.getOrDefault(company.getPeriodId() + "_" + company.getCompanyId(), new FsCourseReportVO());
+                redPacketStats = redPacketStatistics.getOrDefault(company.getPeriodId() + "_" + company.getCompanyId(), new FsCourseReportVO());
             } else {
-                watchStats = watchStatistics.getOrDefault(company.getCompanyId(), new FsCourseReportVO());
-                answerStats = answerStatistics.getOrDefault(company.getCompanyId(), new FsCourseReportVO());
-                redPacketStats = redPacketStatistics.getOrDefault(company.getCompanyId(), new FsCourseReportVO());
+                watchStats = watchStatistics.getOrDefault(company.getCompanyId().toString(), new FsCourseReportVO());
+                answerStats = answerStatistics.getOrDefault(company.getCompanyId().toString(), new FsCourseReportVO());
+                redPacketStats = redPacketStatistics.getOrDefault(company.getCompanyId().toString(), new FsCourseReportVO());
             }
             // 设置看课统计数据
             if (watchStats != null) {
@@ -1395,20 +1395,20 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
                 .setScale(2, RoundingMode.HALF_UP);
     }
 
-    private Map<Long, FsCourseReportVO> getWatchStatistics(FsCourseWatchLogStatisticsListParam query) {
+    private Map<String, FsCourseReportVO> getWatchStatistics(FsCourseWatchLogStatisticsListParam query) {
         List<FsCourseReportVO> watchStatistics = fsCourseWatchLogMapper.selectWatchStatistics(query);
-        Map<Long, FsCourseReportVO> watchStatisticsMap = new HashMap<>();
+        Map<String, FsCourseReportVO> watchStatisticsMap = new HashMap<>();
         if ("company".equals(query.getDimension())) {
             watchStatisticsMap = watchStatistics.stream()
                     .collect(Collectors.toMap(
-                            stats -> stats.getCompanyId(),
+                            stats -> String.valueOf(stats.getCompanyId()),
                             Function.identity(),
                             (existing, replacement) -> existing // 当出现重复键时,保留第一个值
                     ));
         } else if ("camp".equals(query.getDimension())) {
             watchStatisticsMap = watchStatistics.stream()
                     .collect(Collectors.toMap(
-                            stats -> stats.getPeriodId(),
+                            stats -> stats.getPeriodId() + "_" + stats.getCompanyId(),
                             Function.identity(),
                             (existing, replacement) -> existing // 当出现重复键时,保留第一个值
                     ));
@@ -1417,20 +1417,20 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
         return watchStatisticsMap;
     }
 
-    private Map<Long, FsCourseReportVO> getAnswerStatistics(FsCourseWatchLogStatisticsListParam query) {
+    private Map<String, FsCourseReportVO> getAnswerStatistics(FsCourseWatchLogStatisticsListParam query) {
         List<FsCourseReportVO> answerStatistics = fsCourseWatchLogMapper.selectAnswerStatistics(query);
-        Map<Long, FsCourseReportVO> answerMap = new HashMap<>();
+        Map<String, FsCourseReportVO> answerMap = new HashMap<>();
         if ("company".equals(query.getDimension())) {
             answerMap = answerStatistics.stream()
                     .collect(Collectors.toMap(
-                            stats -> stats.getCompanyId(),
+                            stats -> String.valueOf(stats.getCompanyId()),
                             Function.identity(),
                             (existing, replacement) -> existing // 当出现重复键时,保留第一个值
                     ));
         } else if ("camp".equals(query.getDimension())) {
             answerMap = answerStatistics.stream()
                     .collect(Collectors.toMap(
-                            stats -> stats.getPeriodId(),
+                            stats -> stats.getPeriodId() + "_" + stats.getCompanyId(),
                             Function.identity(),
                             (existing, replacement) -> existing // 当出现重复键时,保留第一个值
                     ));
@@ -1439,18 +1439,18 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
         return answerMap;
     }
 
-    private Map<Long, FsCourseReportVO> getRedPacketStatistics(FsCourseWatchLogStatisticsListParam query) {
+    private Map<String, FsCourseReportVO> getRedPacketStatistics(FsCourseWatchLogStatisticsListParam query) {
         List<FsCourseReportVO> redPacketStatistics = fsCourseWatchLogMapper.selectRedPacketStatistics(query);
-        Map<Long, FsCourseReportVO> redPacketMap = new HashMap<>();
+        Map<String, FsCourseReportVO> redPacketMap = new HashMap<>();
         if ("company".equals(query.getDimension())) {
             redPacketMap = redPacketStatistics.stream().collect(Collectors.toMap(
-                    stats -> stats.getCompanyId(),
+                    stats -> String.valueOf(stats.getCompanyId()),
                     Function.identity(),
                     (existing, replacement) -> existing // 当出现重复键时,保留第一个值
             ));
         } else if ("camp".equals(query.getDimension())) {
             redPacketMap = redPacketStatistics.stream().collect(Collectors.toMap(
-                    stats -> stats.getPeriodId(),
+                    stats -> stats.getPeriodId() + "_" + stats.getCompanyId(),
                     Function.identity(),
                     (existing, replacement) -> existing // 当出现重复键时,保留第一个值
             ));

+ 10 - 7
fs-service/src/main/resources/mapper/course/FsCourseWatchLogMapper.xml

@@ -1469,6 +1469,7 @@ FROM
             <!-- 营期维度查询 -->
             <when test="dimension == 'camp'">
                 period_id AS periodId,
+                company_id AS companyId,
             </when>
         </choose>
         COUNT(DISTINCT CASE WHEN log_type = 3 THEN user_id END) AS pendingCount,
@@ -1513,7 +1514,7 @@ FROM
                 GROUP BY company_id
             </when>
             <when test="dimension == 'camp'">
-                GROUP BY period_id
+                GROUP BY period_id,company_id
             </when>
         </choose>
     </select>
@@ -1527,6 +1528,7 @@ FROM
             <!-- 营期维度查询 -->
             <when test="dimension == 'camp'">
                 w.period_id AS periodId,
+                w.company_id AS companyId,
             </when>
         </choose>
         COUNT(DISTINCT a.user_id) AS answerUserCount
@@ -1568,7 +1570,7 @@ FROM
                 GROUP BY w.company_id
             </when>
             <when test="dimension == 'camp'">
-                GROUP BY w.period_id
+                GROUP BY w.period_id,w.company_id
             </when>
         </choose>
     </select>
@@ -1582,6 +1584,7 @@ FROM
             <!-- 营期维度查询 -->
             <when test="dimension == 'camp'">
                 w.period_id AS periodId,
+                w.company_id AS companyId,
             </when>
         </choose>
         COUNT(DISTINCT rpl.user_id) AS packetUserCount,
@@ -1625,7 +1628,7 @@ FROM
                 GROUP BY w.company_id
             </when>
             <when test="dimension == 'camp'">
-                GROUP BY w.period_id
+                GROUP BY w.period_id,w.company_id
             </when>
         </choose>
     </select>
@@ -1898,8 +1901,10 @@ FROM
         c.company_id companyId
         FROM
         fs_user_course_period period
-        LEFT JOIN company c ON period.company_id = c.company_id
-        LEFT JOIN fs_user_course_training_camp camp on camp.training_camp_id=period.training_camp_id
+        LEFT JOIN fs_user_course_training_camp camp
+        ON camp.training_camp_id = period.training_camp_id
+        LEFT JOIN company c
+        ON FIND_IN_SET(c.company_id, period.company_id) > 0
        <where>
         <!-- 只有当传入公司ID参数时才筛选公司 -->
         <if test="companyId != null">
@@ -1914,8 +1919,6 @@ FROM
             AND period.period_id = #{periodId}
         </if>
         </where>
-        GROUP BY
-        period.period_id
         ORDER BY period.create_time DESC
     </select>
     <sql id="commonConditions">

+ 1 - 0
fs-service/src/main/resources/mapper/course/FsUserCoursePeriodDaysMapper.xml

@@ -159,6 +159,7 @@
                 and ucp.training_camp_id = #{params.campId}
             </if>
         </where>
+        ORDER BY ucp.create_time desc
     </select>
 
     <update id="batchUpdateCoursePeriodDays" parameterType="java.util.List">