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

培训看板bug调整(不涉及是否是新版培训还是旧版培训)

wy 8 месяцев назад
Родитель
Сommit
ed24ff0f31

+ 21 - 11
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/service/impl/StaffTrainServiceImpl.java

@@ -287,44 +287,54 @@ public class StaffTrainServiceImpl implements StaffTrainService {
         List<TraineeStatisticsDto> statisticsDtoList = new ArrayList<>();
         // 定义SQL模板
         String countSqlTemplate = "SELECT COALESCE(SUM(num), 0) AS total_num FROM (" +
-                "SELECT LENGTH(pei_xun_ren_yuan_) - LENGTH(REPLACE(pei_xun_ren_yuan_, ',', '')) + 1 AS num " +
-                "FROM t_lhrypxjlb " +
-                "WHERE pei_xun_zhuang_ta = '已结束' %s) AS subquery";
+                " SELECT " +
+                " CASE "+
+                " WHEN pei_xun_ren_yuan_ LIKE '%,' THEN  LENGTH(pei_xun_ren_yuan_) - LENGTH(REPLACE(pei_xun_ren_yuan_, ',', '')) "+
+                " ELSE  LENGTH(pei_xun_ren_yuan_) - LENGTH(REPLACE(pei_xun_ren_yuan_, ',', '')) + 1 "+
+                " END AS num "+
+                //"SELECT LENGTH(pei_xun_ren_yuan_) - LENGTH(REPLACE(pei_xun_ren_yuan_, ',', '')) + 1 AS num " +
+                " FROM t_lhrypxjlb " +
+                " WHERE pei_xun_zhuang_ta = '已结束' ";
 
         String signSqlTemplate = "SELECT count(DISTINCT b.ren_yuan_id_) total_num from t_lhrypxjlb a,t_qdxxb b " +
                 " WHERE a.id_ =b.guan_lian_id_ and FIND_IN_SET(b.ren_yuan_id_,a.pei_xun_ren_yuan_) " +
                 " and a.pei_xun_zhuang_ta = '已结束' %s ";
 
         String sumRealSqlTemplate = "SELECT COALESCE(SUM(num),0) AS realNum FROM (" +
-                "SELECT count(id_) as num FROM t_qdxxb " +
-                "WHERE guan_lian_id_ IN (SELECT id_ FROM t_lhrypxjlb " +
-                "WHERE pei_xun_zhuang_ta = '已结束' %s) " +
-                "GROUP BY guan_lian_id_, ren_yuan_id_) AS re";
-
+                " SELECT COUNT(DISTINCT q.ren_yuan_id_) AS num FROM  t_qdxxb q " +
+                " JOIN t_lhrypxjlb p ON q.guan_lian_id_ = p.id_" +
+                " WHERE pei_xun_zhuang_ta = '已结束' ";
+        String sumRealSqlSuffix = " GROUP BY guan_lian_id_, ren_yuan_id_) AS re";
         for (String date : dateStr) {
             TraineeStatisticsDto traineeDto = new TraineeStatisticsDto();
 
-            String dateCondition = "";String params;
+            String dateCondition = "";String params;String dateConditionTwo = "";
             if ("year".equals(type)) {
                 traineeDto.setDayName(date + "月");
                 date = Integer.parseInt(date)<10?year + "-0" + date : year + "-" + date;
                 traineeDto.setDate(date);
                 dateCondition = String.format("AND DATE_FORMAT(pei_xun_shi_jian_, '%%Y-%%m') = '%s'", date);
+                dateConditionTwo = String.format("AND DATE_FORMAT(p.pei_xun_shi_jian_, '%%Y-%%m') = '%s'", date);
             } else if ("month".equals(type)) {
                 traineeDto.setDate(date);
                 dateCondition = String.format("AND DATE_FORMAT(pei_xun_shi_jian_, '%%Y-%%m-%%d') = '%s'", date);
+                dateConditionTwo = String.format("AND DATE_FORMAT(p.pei_xun_shi_jian_, '%%Y-%%m-%%d') = '%s'", date);
                 traineeDto.setDayName(getDayName(date));
             }
 
             if (BeanUtils.isNotEmpty(dept)) {
                 params = dateCondition + String.format(" AND a.bian_zhi_bu_men_ = '%s'", dept);
                 dateCondition += String.format(" AND bian_zhi_bu_men_ = '%s'", dept);
+                dateConditionTwo += String.format(" AND p.bian_zhi_bu_men_ = '%s'", dept);
             }else {
                 params = dateCondition + String.format(" AND a.di_dian_ = '%s'", getDiDian());
             }
             dateCondition += String.format(" AND di_dian_ = '%s'", getDiDian());
-            String countSql = String.format(countSqlTemplate, dateCondition);
-            String sumRealSql = String.format(sumRealSqlTemplate, dateCondition);
+            dateConditionTwo += String.format(" AND p.di_dian_ = '%s'", getDiDian());
+            String countSql = countSqlTemplate + dateCondition + " ) AS subquery";
+           // String countSql = String.format(countSqlTemplate, dateCondition);
+            //String sumRealSql = String.format(sumRealSqlTemplate, dateCondition);
+            String sumRealSql =sumRealSqlTemplate + dateConditionTwo +sumRealSqlSuffix;
             String signSql = String.format(signSqlTemplate, params);
             // 应该签到总数
             Map<String, Object> countResult = commonDao.queryOne(countSql);