瀏覽代碼

培训看板去除补签后的逗号(病理版)

wy 8 月之前
父節點
當前提交
057db94921

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

@@ -286,15 +286,17 @@ public class StaffTrainServiceImpl implements StaffTrainService {
     public List<TraineeStatisticsDto> getYmdData(List<String> dateStr, String dept, String type, String year) {
         List<TraineeStatisticsDto> statisticsDtoList = new ArrayList<>();
         // 定义SQL模板
-        String countSqlTemplate = "SELECT COALESCE(SUM(num), 0) AS total_num FROM (" +
-                " 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 countSqlTemplate = "SELECT COALESCE(SUM(num), 0) AS total_num " +
+                                  " FROM ( " +
+                                  " SELECT "+
+                                  " CASE "+
+                                  " WHEN pei_xun_ren_yuan_ = '' OR pei_xun_ren_yuan_ IS NULL THEN 0 " +
+                                  " ELSE LENGTH( " +
+                                  " REPLACE( REPLACE( TRIM(BOTH ',' FROM pei_xun_ren_yuan_),   ',,', ','  ), ',,', ','  ) ) - LENGTH( " +
+                                  " REPLACE( REPLACE( REPLACE( TRIM(BOTH ',' FROM pei_xun_ren_yuan_), ',,', ',' ), ',,', ',' ), ',', '' ) ) + 1 " +
+                                  " END 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_) " +