Forráskód Böngészése

fix(task): 修复任务类型数据分析查询

- 优化了 SQL 查询语句,简化了部分计算逻辑
- 提高了查询效率,减少了数据库负担
wanyuan 3 hónapja
szülő
commit
1ce740f1e6

+ 5 - 6
tc-service/tap-task/src/main/java/com/minto/app/task/dao/TaskAnalysisDaoImpl.java

@@ -2116,12 +2116,11 @@ hql.append("AND EXISTS (\n" +
     public List<Map<String, Object>> findTaskTypeSettingDataAnalysis(Map<String, Object> params){
         String sql = "select te.id as id, te.value as name, te.color as color, (case when te.color is null or te"
                 + ".color = '1' then count(CASE WHEN tts.type_state = '1' THEN tts.id END) else sum(CASE WHEN tts.type_state "
-                + "is not null THEN tts.type_state else 0 END) end) as c1, (case when te.color is null or te.color = '1' then"
-                + " count(tts.id) else count(CASE WHEN tts.type_state is not null THEN 1 END) end) as c2 from "
-        + "task_type_setting tts inner join task_summary ts on ts.id = tts.reference_id left join (SELECT * FROM "
-        + "tip_enum WHERE type IN ( SELECT id FROM tip_enum WHERE key = 'matter_type_settings' ) AND status <> -1 ) "
-        + "te on te.id = tts.type_id where ts.tstate != 7 and to_char(ts.create_date,'yyyy') = :year group by te.id, "
-        + "te.value, te.color ";
+                + "is not null THEN tts.type_state else 1 END) end) as c1, (case when te.color is null or te.color = '1' then"
+        + " count(tts.id) else count(tts.id) end) as c2 from task_type_setting tts inner join task_summary ts on ts"
+        + ".id = tts.reference_id left join (SELECT * FROM tip_enum WHERE type IN ( SELECT id FROM tip_enum WHERE key"
+        + " = 'matter_type_settings' ) AND status <> -1 ) te on te.id = tts.type_id where ts.tstate != 7 and to_char"
+        + "(ts.create_date,'yyyy') = :year group by te.id, te.value, te.color ";
         String order = ParameterUtil.getString(params, "order", "name");
         Integer asc = ParameterUtil.getInteger(params, "asc", 0);
         sql = sql + (" ORDER BY " + order + (asc == 1 ? " ASC " : " DESC "));