Pārlūkot izejas kodu

看课统计修改为营期维度

wangxy 1 nedēļu atpakaļ
vecāks
revīzija
4dbb1865dd

+ 7 - 0
fs-service/src/main/java/com/fs/course/mapper/FsCourseWatchLogMapper.java

@@ -631,6 +631,13 @@ public interface FsCourseWatchLogMapper extends BaseMapper<FsCourseWatchLog> {
      */
     List<FsCourseReportVO> selectCompanyBaseInfo(FsCourseWatchLogStatisticsListParam param);
 
+    /**
+     *营期维度基本信息
+     * @param param
+     * @return
+     */
+    List<FsCourseReportVO> selectPeriodInfo(FsCourseWatchLogStatisticsListParam param);
+
     /**
      * 看课信息
      * @param param

+ 1 - 0
fs-service/src/main/java/com/fs/course/param/FsCourseWatchLogStatisticsListParam.java

@@ -97,4 +97,5 @@ public class FsCourseWatchLogStatisticsListParam extends BaseEntity {
     private  List<Long> deptIds;
 
 
+
 }

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

@@ -1296,51 +1296,57 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
     @Override
     public List<FsCourseReportVO> selectFsCourseReportVO(FsCourseWatchLogStatisticsListParam param) {
         //时间处理
-        if(param.getSTime()!=null||param.getETime()!=null){
+        if (param.getSTime() != null || param.getETime() != null) {
             Date date = removeTime(param.getSTime());
             param.setSTime(date);
             Date endDate = removeTime(param.getETime());
             param.setETime(endDate);
         }
-        // 1. 查询公司基础信息
-        List<FsCourseReportVO> companyList = fsCourseWatchLogMapper.selectCompanyBaseInfo(param);
+        // 基础信息
+        List<FsCourseReportVO> companyList = new ArrayList<>();
+        if ("camp".equals(param.getDimension())) {
+            companyList = fsCourseWatchLogMapper.selectPeriodInfo(param);
+        } else {
+            companyList = fsCourseWatchLogMapper.selectCompanyBaseInfo(param);
+        }
         if (CollectionUtils.isEmpty(companyList)) {
             return Collections.emptyList();
         }
+        if ("camp".equals(param.getDimension())) {
+            List<Long> periodIds = companyList.stream()
+                    .map(company -> (Long) company.getPeriodId())
+                    .collect(Collectors.toList());
+            param.setPeriodIds(periodIds);
+        }
         List<Long> companyIds = companyList.stream()
                 .map(company -> (Long) company.getCompanyId())
                 .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<Long, FsCourseReportVO> campPeriodMap = new HashMap<>();
-        if ("camp".equals(param.getDimension())) {
-            List<Long> periodIds = watchStatistics.values().stream()
-                    .map(stats -> stats.getPeriodId())
-                    .filter(Objects::nonNull)
-                    .collect(Collectors.toList());
-            if (!periodIds.isEmpty()) {
-                campPeriodMap = getCampPeriodInfo(periodIds);
-            }
-        }
         // 4. 组装最终结果
         return assembleStatisticsResult(companyList, watchStatistics, answerStatistics,
-                redPacketStatistics, campPeriodMap, param);
-    }
-
-    private List<FsCourseReportVO> assembleStatisticsResult(List<FsCourseReportVO> companyList, Map<Long, FsCourseReportVO> watchStatistics, Map<Long, FsCourseReportVO> answerStatistics, Map<Long, FsCourseReportVO> redPacketStatistics, Map<Long, FsCourseReportVO> campPeriodMap, FsCourseWatchLogStatisticsListParam param) {
-        for (FsCourseReportVO  company : companyList) {
-            Long companyId = company.getCompanyId();
-
-            // 获取各类统计数据
-            FsCourseReportVO watchStats = watchStatistics.get(companyId);
-            FsCourseReportVO answerStats = answerStatistics.get(companyId);
-            FsCourseReportVO redPacketStats = redPacketStatistics.get(companyId);
-
-
+                redPacketStatistics, param);
+    }
+
+    private List<FsCourseReportVO> assembleStatisticsResult(List<FsCourseReportVO> companyList, Map<Long, FsCourseReportVO> watchStatistics, Map<Long, FsCourseReportVO> answerStatistics, Map<Long, 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());
+            } else {
+                watchStats = watchStatistics.getOrDefault(company.getCompanyId(), new FsCourseReportVO());
+                answerStats = answerStatistics.getOrDefault(company.getCompanyId(), new FsCourseReportVO());
+                redPacketStats = redPacketStatistics.getOrDefault(company.getCompanyId(), new FsCourseReportVO());
+            }
             // 设置看课统计数据
-            if(watchStats!=null){
+            if (watchStats != null) {
                 company.setPendingCount(watchStats.getPendingCount());
                 company.setWatchingCount(watchStats.getWatchingCount());
                 company.setFinishedCount(watchStats.getFinishedCount());
@@ -1351,30 +1357,18 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
             }
 
             // 设置答题统计数据
-            if(answerStats!=null){
+            if (answerStats != null) {
                 company.setAnswerUserCount(answerStats.getAnswerUserCount());
             }
 
             // 设置红包统计数据
-           if(redPacketStats!=null){
-               company.setPacketUserCount(redPacketStats.getPacketUserCount());
-               company.setPacketAmount(redPacketStats.getPacketAmount());
-           }
-
-            // 设置营期信息(如果维度是camp)
-            if ("camp".equals(param.getDimension()) && watchStats != null) {
-                Long samplePeriodId = watchStats.getPeriodId();
-                if (samplePeriodId != null) {
-                    FsCourseReportVO campPeriod = campPeriodMap.get(samplePeriodId);
-                    if (campPeriod != null) {
-                        company.setTrainingCampName(campPeriod.getTrainingCampName());
-                        company.setPeriodName(campPeriod.getPeriodName());
-                    }
-                }
+            if (redPacketStats != null) {
+                company.setPacketUserCount(redPacketStats.getPacketUserCount());
+                company.setPacketAmount(redPacketStats.getPacketAmount());
             }
 
         }
-        return  companyList;
+        return companyList;
     }
 
     /**
@@ -1403,32 +1397,65 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
 
     private Map<Long, FsCourseReportVO> getWatchStatistics(FsCourseWatchLogStatisticsListParam query) {
         List<FsCourseReportVO> watchStatistics = fsCourseWatchLogMapper.selectWatchStatistics(query);
-        Map<Long, FsCourseReportVO> watchStatisticsMap = watchStatistics.stream()
-                .collect(Collectors.toMap(
-                        stats -> stats.getCompanyId(),
-                        Function.identity(),
-                        (existing, replacement) -> existing // 当出现重复键时,保留第一个值
-                ));
+        Map<Long, FsCourseReportVO> watchStatisticsMap = new HashMap<>();
+        if ("company".equals(query.getDimension())) {
+            watchStatisticsMap = watchStatistics.stream()
+                    .collect(Collectors.toMap(
+                            stats -> stats.getCompanyId(),
+                            Function.identity(),
+                            (existing, replacement) -> existing // 当出现重复键时,保留第一个值
+                    ));
+        } else if ("camp".equals(query.getDimension())) {
+            watchStatisticsMap = watchStatistics.stream()
+                    .collect(Collectors.toMap(
+                            stats -> stats.getPeriodId(),
+                            Function.identity(),
+                            (existing, replacement) -> existing // 当出现重复键时,保留第一个值
+                    ));
+        }
+
         return watchStatisticsMap;
     }
+
     private Map<Long, FsCourseReportVO> getAnswerStatistics(FsCourseWatchLogStatisticsListParam query) {
         List<FsCourseReportVO> answerStatistics = fsCourseWatchLogMapper.selectAnswerStatistics(query);
-        Map<Long, FsCourseReportVO> answerMap = answerStatistics.stream()
-                .collect(Collectors.toMap(
-                        stats -> stats.getCompanyId(),
-                        Function.identity(),
-                        (existing, replacement) -> existing // 当出现重复键时,保留第一个值
-                ));
+        Map<Long, FsCourseReportVO> answerMap = new HashMap<>();
+        if ("company".equals(query.getDimension())) {
+            answerMap = answerStatistics.stream()
+                    .collect(Collectors.toMap(
+                            stats -> stats.getCompanyId(),
+                            Function.identity(),
+                            (existing, replacement) -> existing // 当出现重复键时,保留第一个值
+                    ));
+        } else if ("camp".equals(query.getDimension())) {
+            answerMap = answerStatistics.stream()
+                    .collect(Collectors.toMap(
+                            stats -> stats.getPeriodId(),
+                            Function.identity(),
+                            (existing, replacement) -> existing // 当出现重复键时,保留第一个值
+                    ));
+        }
+
         return answerMap;
     }
 
-    private Map<Long, FsCourseReportVO> getRedPacketStatistics(FsCourseWatchLogStatisticsListParam query){
+    private Map<Long, FsCourseReportVO> getRedPacketStatistics(FsCourseWatchLogStatisticsListParam query) {
         List<FsCourseReportVO> redPacketStatistics = fsCourseWatchLogMapper.selectRedPacketStatistics(query);
-        Map<Long, FsCourseReportVO> redPacketMap = redPacketStatistics.stream().collect(Collectors.toMap(
-                stats -> stats.getCompanyId(),
-                Function.identity(),
-                (existing, replacement) -> existing // 当出现重复键时,保留第一个值
-        ));
+        Map<Long, FsCourseReportVO> redPacketMap = new HashMap<>();
+        if ("company".equals(query.getDimension())) {
+            redPacketMap = redPacketStatistics.stream().collect(Collectors.toMap(
+                    stats -> stats.getCompanyId(),
+                    Function.identity(),
+                    (existing, replacement) -> existing // 当出现重复键时,保留第一个值
+            ));
+        } else if ("camp".equals(query.getDimension())) {
+            redPacketMap = redPacketStatistics.stream().collect(Collectors.toMap(
+                    stats -> stats.getPeriodId(),
+                    Function.identity(),
+                    (existing, replacement) -> existing // 当出现重复键时,保留第一个值
+            ));
+        }
+
         return redPacketMap;
     }
 
@@ -1440,7 +1467,7 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
                         Function.identity(),
                         (existing, replacement) -> existing // 当出现重复键时,保留第一个值
                 ));
-        return  campPeriodMap;
+        return campPeriodMap;
 
     }
 
@@ -1468,7 +1495,7 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
                         Function.identity()
                 ));
 
-        Map<Long, FsUserReportVO> integralStatsMap = fsCourseWatchLogMapper.selectIntegralStatsByUserIds(userIds,param)
+        Map<Long, FsUserReportVO> integralStatsMap = fsCourseWatchLogMapper.selectIntegralStatsByUserIds(userIds, param)
                 .stream()
                 .collect(Collectors.toMap(FsUserReportVO::getUserId, Function.identity()));
 
@@ -1479,7 +1506,7 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
                         Function.identity()
                 ));
 
-        Map<Long, FsUserReportVO> orderStatsMap = fsCourseWatchLogMapper.selectOrderStatsByUserIds(userIds,param)
+        Map<Long, FsUserReportVO> orderStatsMap = fsCourseWatchLogMapper.selectOrderStatsByUserIds(userIds, param)
                 .stream()
                 .collect(Collectors.toMap(FsUserReportVO::getUserId, Function.identity()));
         userList.forEach(user -> {
@@ -1542,6 +1569,7 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
                 return Collections.emptyList();
         }
     }
+
     /**
      * 优化后的公司维度基础数据查询
      */
@@ -1590,6 +1618,7 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
 
         return deptBaseData;
     }
+
     /**
      * 复制参数属性的辅助方法
      */
@@ -1628,7 +1657,7 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
         );
 
         Map<Long, WatchLogReportVO> orderMap = convertOrderToMap(
-                fsCourseWatchLogMapper.selectOrderStats(userIds,param)
+                fsCourseWatchLogMapper.selectOrderStats(userIds, param)
         );
         Map<Long, WatchLogReportVO> answerMap = convertAnswerToMap(
                 fsCourseWatchLogMapper.selectAnswerStats(logIds)
@@ -1637,7 +1666,7 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
 
         // 组装数据
         for (WatchLogReportVO item : baseData) {
-            if(!"user".equals(param.getDimension())){
+            if (!"user".equals(param.getDimension())) {
                 //完课率
                 item.setCompletionRate(calculateCompletionRate(item));
             }
@@ -1648,19 +1677,19 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
                 item.setTrainingCampName(watchStats.getTrainingCampName());
             }
             // 红包数据
-            WatchLogReportVO redPacketStats = redPacketMap.getOrDefault(item.getLogId(),null);
+            WatchLogReportVO redPacketStats = redPacketMap.getOrDefault(item.getLogId(), null);
             if (redPacketStats != null) {
                 item.setRedPacketAmount(redPacketStats.getRedPacketAmount());
             }
 
             // 订单数据
-            WatchLogReportVO order = orderMap.getOrDefault(item.getUserId(),null);
+            WatchLogReportVO order = orderMap.getOrDefault(item.getUserId(), null);
             if (order != null) {
                 item.setHistoryOrderCount(order.getHistoryOrderCount());
             }
 
             // 答题数据
-            WatchLogReportVO answer = answerMap.getOrDefault(item.getLogId(),null);
+            WatchLogReportVO answer = answerMap.getOrDefault(item.getLogId(), null);
             if (answer != null) {
                 setAnswerData(item, answer, param.getDimension());
             }
@@ -1701,8 +1730,6 @@ public class FsCourseWatchLogServiceImpl extends ServiceImpl<FsCourseWatchLogMap
     }
 
 
-
-
     /**
      * 会员数据转Map
      */

+ 164 - 42
fs-service/src/main/resources/mapper/course/FsCourseWatchLogMapper.xml

@@ -1435,7 +1435,7 @@ FROM
             </when>
             <!-- 当只传了时间范围时 -->
             <when test="(trainingCampId == null and periodId == null) and (sTime != null and eTime != null)">
-                INNER JOIN fs_course_watch_log w ON c.company_id = w.company_id
+                    INNER JOIN fs_course_watch_log w ON c.company_id = w.company_id
             </when>
 <!--            &lt;!&ndash; 默认情况:必须有关联记录 &ndash;&gt;-->
 <!--            <otherwise>-->
@@ -1457,11 +1457,20 @@ FROM
             </if>
         </where>
         GROUP BY c.company_id, c.company_name
+        ORDER BY c.create_time DESC
     </select>
     <select id="selectWatchStatistics" resultType="com.fs.his.vo.FsCourseReportVO">
         SELECT
-        company_id AS companyId,
-        period_id AS periodId,
+        <choose>
+            <!-- 公司维度查询 -->
+            <when test="dimension == 'company'">
+                company_id AS companyId,
+            </when>
+            <!-- 营期维度查询 -->
+            <when test="dimension == 'camp'">
+                period_id AS periodId,
+            </when>
+        </choose>
         COUNT(DISTINCT CASE WHEN log_type = 3 THEN user_id END) AS pendingCount,
         COUNT(DISTINCT CASE WHEN log_type = 1 THEN user_id END) AS watchingCount,
         COUNT(DISTINCT CASE WHEN log_type = 2 THEN user_id END) AS finishedCount,
@@ -1472,25 +1481,54 @@ FROM
             <if test="sTime != null and eTime != null">
                 AND Date(create_time)  BETWEEN #{sTime} AND #{eTime}
             </if>
-            <if test="trainingCampId != null">
-                AND period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
-            </if>
-            <if test="periodId != null">
-                AND period_id = #{periodId}
-            </if>
-            <if test="companyIds != null and companyIds.size() > 0">
-                AND company_id IN
-                <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
-                    #{companyId}
-                </foreach>
-            </if>
+            <choose>
+                <!-- 公司维度筛选 -->
+                <when test="dimension == 'company'">
+                    <if test="companyIds != null and companyIds.size() > 0">
+                        AND company_id IN
+                        <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
+                            #{companyId}
+                        </foreach>
+                    </if>
+                </when>
+                <!-- 营期维度筛选 -->
+                <when test="dimension == 'camp'">
+                    <if test="periodIds != null and periodIds.size() > 0">
+                        AND period_id IN
+                        <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
+                            #{periodId}
+                        </foreach>
+                    </if>
+                    <if test="companyIds != null and companyIds.size() > 0">
+                        AND company_id IN
+                        <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
+                            #{companyId}
+                        </foreach>
+                    </if>
+                </when>
+            </choose>
         </where>
-        GROUP BY company_id
-
+        <choose>
+            <when test="dimension == 'company'">
+                GROUP BY company_id
+            </when>
+            <when test="dimension == 'camp'">
+                GROUP BY period_id
+            </when>
+        </choose>
     </select>
     <select id="selectAnswerStatistics" resultType="com.fs.his.vo.FsCourseReportVO">
         SELECT
-        w.company_id AS companyId,
+        <choose>
+            <!-- 公司维度查询 -->
+            <when test="dimension == 'company'">
+                w.company_id AS companyId,
+            </when>
+            <!-- 营期维度查询 -->
+            <when test="dimension == 'camp'">
+                w.period_id AS periodId,
+            </when>
+        </choose>
         COUNT(DISTINCT a.user_id) AS answerUserCount
         FROM fs_course_answer_logs a
         INNER JOIN fs_course_watch_log w ON a.watch_log_id = w.log_id
@@ -1498,43 +1536,98 @@ FROM
             <if test="sTime != null and eTime != null">
                 AND Date(w.create_time) BETWEEN #{sTime} AND #{eTime}
             </if>
-            <if test="trainingCampId != null">
-                AND w.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
-            </if>
-            <if test="periodId != null">
-                AND w.period_id = #{periodId}
-            </if>
-            <if test="companyIds != null and companyIds.size() > 0">
-                AND w.company_id IN
-                <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
-                    #{companyId}
-                </foreach>
-            </if>
+            <choose>
+                <!-- 公司维度筛选 -->
+                <when test="dimension == 'company'">
+                    <if test="companyIds != null and companyIds.size() > 0">
+                        AND w.company_id IN
+                        <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
+                            #{companyId}
+                        </foreach>
+                    </if>
+                </when>
+                <!-- 营期维度筛选 -->
+                <when test="dimension == 'camp'">
+                    <if test="periodIds != null and periodIds.size() > 0">
+                        AND w.period_id IN
+                        <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
+                            #{periodId}
+                        </foreach>
+                    </if>
+                    <if test="companyIds != null and companyIds.size() > 0">
+                        AND w.company_id IN
+                        <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
+                            #{companyId}
+                        </foreach>
+                    </if>
+                </when>
+            </choose>
         </where>
-        GROUP BY w.company_id
+        <choose>
+            <when test="dimension == 'company'">
+                GROUP BY w.company_id
+            </when>
+            <when test="dimension == 'camp'">
+                GROUP BY w.period_id
+            </when>
+        </choose>
     </select>
     <select id="selectRedPacketStatistics" resultType="com.fs.his.vo.FsCourseReportVO">
         SELECT
-        w.company_id AS companyId,
+        <choose>
+            <!-- 公司维度查询 -->
+            <when test="dimension == 'company'">
+                w.company_id AS companyId,
+            </when>
+            <!-- 营期维度查询 -->
+            <when test="dimension == 'camp'">
+                w.period_id AS periodId,
+            </when>
+        </choose>
         COUNT(DISTINCT rpl.user_id) AS packetUserCount,
         COALESCE(SUM(rpl.amount), 0) AS packetAmount
         FROM fs_course_red_packet_log rpl
         INNER JOIN fs_course_watch_log w ON rpl.watch_log_id = w.log_id
         <where>
+            rpl.status=1
             <if test="sTime != null and eTime != null">
                 AND DATE(w.create_time)  BETWEEN #{sTime} AND #{eTime}
             </if>
-            <if test="trainingCampId != null">
-                AND w.period_id IN (SELECT period_id FROM fs_user_course_period WHERE training_camp_id = #{trainingCampId})
-            </if>
-            <if test="companyIds != null and companyIds.size() > 0">
-                AND w.company_id IN
-                <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
-                    #{companyId}
-                </foreach>
-            </if>
+            <choose>
+                <!-- 公司维度筛选 -->
+                <when test="dimension == 'company'">
+                    <if test="companyIds != null and companyIds.size() > 0">
+                        AND w.company_id IN
+                        <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
+                            #{companyId}
+                        </foreach>
+                    </if>
+                </when>
+                <!-- 营期维度筛选 -->
+                <when test="dimension == 'camp'">
+                    <if test="periodIds != null and periodIds.size() > 0">
+                        AND w.period_id IN
+                        <foreach collection="periodIds" item="periodId" open="(" separator="," close=")">
+                            #{periodId}
+                        </foreach>
+                    </if>
+                    <if test="companyIds != null and companyIds.size() > 0">
+                        AND w.company_id IN
+                        <foreach collection="companyIds" item="companyId" open="(" separator="," close=")">
+                            #{companyId}
+                        </foreach>
+                    </if>
+                </when>
+            </choose>
         </where>
-        GROUP BY w.company_id
+        <choose>
+            <when test="dimension == 'company'">
+                GROUP BY w.company_id
+            </when>
+            <when test="dimension == 'camp'">
+                GROUP BY w.period_id
+            </when>
+        </choose>
     </select>
     <select id="selectCampPeriodInfo" resultType="com.fs.his.vo.FsCourseReportVO">
         SELECT
@@ -1796,6 +1889,35 @@ FROM
         d.dept_name,
         c.company_name
     </select>
+    <select id="selectPeriodInfo" resultType="com.fs.his.vo.FsCourseReportVO">
+        SELECT
+        period.period_id periodId,
+        period.period_name periodName,
+        camp.training_camp_name trainingCampName,
+        c.company_name companyName,
+        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
+       <where>
+        <!-- 只有当传入公司ID参数时才筛选公司 -->
+        <if test="companyId != null">
+            period.company_id = #{companyId}
+        </if>
+        <!-- 训练营 -->
+        <if test="trainingCampId != null and trainingCampId != ''">
+            AND period.training_camp_id= #{trainingCampId}
+        </if>
+        <!-- 营期 -->
+        <if test="periodId != null and periodId != ''">
+            AND period.period_id = #{periodId}
+        </if>
+        </where>
+        GROUP BY
+        period.period_id
+        ORDER BY period.create_time DESC
+    </select>
     <sql id="commonConditions">
         <!-- 销售公司 -->
         <if test="companyId != null and companyId != ''">