浏览代码

[task-3312] 设施环境总览添加对二级部门的支持

Li Yuan 1 年之前
父节点
当前提交
11bc1d5f5c

+ 31 - 10
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/service/impl/FacilityEnvironmentServiceImpl.java

@@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.util.List;
 import java.util.Map;
+import java.util.StringJoiner;
 import java.util.stream.Collectors;
 
 @Service
@@ -23,6 +24,12 @@ public class FacilityEnvironmentServiceImpl implements FacilityEnvironmentServic
     private ICommonDao<?> commonDao;
     @Override
     public List<Map<String, Object>> getDailySummary(String buMen) {
+        String fetchSqlForAllPOS =  "SELECT jian_ce_zhou_qi_,facs_type,pos.name_,COUNT(shi_fou_guo_shen_<>'已完成'  OR NULL ) AS todo,COUNT(shi_fou_guo_shen_='已完成'  OR NULL) AS done ,MAX(facs.pagePath) AS pagePath" +
+                "   FROM v_facs_summary_daily, ibps_party_position pos,(SELECT DISTINCT pagePath,`type` FROM v_facs WHERE pagePath <>'') facs" +
+                "   WHERE di_dian_='%s' AND bian_zhi_bu_men_=pos.id_ AND facs_type = facs.type" +
+                "   GROUP BY jian_ce_zhou_qi_,facs_type,bian_zhi_bu_men_ ORDER BY facs_type;";
+
+
         if(StringUtils.isEmpty(buMen)){
             String userId = ContextUtil.getCurrentUserId();
             String sql = "SELECT pos.path_ as path  " +
@@ -38,31 +45,45 @@ public class FacilityEnvironmentServiceImpl implements FacilityEnvironmentServic
             List<Map<String,Object>> objects =
                     (List<Map<String, Object>>) commonDao.query(String.format(sql,userId));
             if(!Collections.isEmpty(objects)){
+                //如果是安全小组负责人,则全部显示
                 String path = objects.get(0).get("path").toString();
-                buMen = path.split(StringPool.BACK_SLASH+StringPool.DOT)[2];
+                buMen = path.split(StringPool.BACK_SLASH+StringPool.DOT)[1];
+                return (List<Map<String, Object>>)commonDao.query(String.format(fetchSqlForAllPOS,buMen));
             }else{
                 IPartyPositionService partyPositionService = AppUtil.getBean(IPartyPositionService.class);
                 APIResult<List<PartyPositionPo>> result1 = partyPositionService.findByUserId(userId);
                 if (result1.isFailed() || Collections.isEmpty(result1.getData())) {
                     throw new IllegalArgumentException("buMen not match!");
                 }
+                for (PartyPositionPo po :  result1.getData()) {
+                    if(po.getPath().split("\\.").length == 2){
+                        //如果用户有配置2级部门,则全部显示
+                        return (List<Map<String, Object>>)commonDao.query(String.format(fetchSqlForAllPOS,po.getId()));
+                    }
+                }
                 buMen = result1.getData().stream().map(n -> n.getId()).collect(Collectors.joining(","));
             }
         }
-        String sql = " SELECT parent_id_ as id_ FROM ibps_party_entity  WHERE party_type_='position' AND depth_=3 AND FIND_IN_SET(id_,'%s')";
+        String sql = " SELECT  id_ FROM ibps_party_entity  WHERE party_type_='position' AND depth_=3 AND FIND_IN_SET(id_,'%s')";
         List<Map<String,Object>> object3 =
                 (List<Map<String, Object>>) commonDao.query(String.format(sql,buMen));
-        if(Collections.isEmpty(object3)) {
-            String fetchSql =  "SELECT jian_ce_zhou_qi_,facs_type,pos.name_,COUNT(shi_fou_guo_shen_<>'已完成'  OR NULL ) AS todo,COUNT(shi_fou_guo_shen_='已完成'  OR NULL) AS done ,MAX(facs.pagePath) AS pagePath" +
-                    "   FROM v_facs_summary_daily, ibps_party_position pos,(SELECT DISTINCT pagePath,`type` FROM v_facs WHERE pagePath <>'') facs" +
-                    "   WHERE FIND_IN_SET(bian_zhi_bu_men_,'%s') AND bian_zhi_bu_men_=pos.id_ AND facs_type = facs.type" +
-                    "   GROUP BY jian_ce_zhou_qi_,facs_type,bian_zhi_bu_men_ ORDER BY facs_type;";
-            return (List<Map<String, Object>>)commonDao.query(String.format(fetchSql,buMen));
+        if(Collections.isNotEmpty(object3)) {
+            //如果用户有配置3级部门,则需要把3级部门下的所有子部门加入到查询项中
+            String sql4 = "SELECT id_ FROM ibps_party_entity WHERE parent_id_='%s'";
+            StringJoiner joiner = new StringJoiner(StringPool.COMMA);
+            for (Map<String, Object> m: object3 ) {
+                List<Map<String, Object>> list3 = (List<Map<String, Object>>) commonDao.query(String.format(sql4, m.get("id_")));
+                for (Map<String, Object> mm: list3 ) {
+                    joiner.add(mm.get("id_").toString());
+                }
+            }
+            buMen += StringPool.COMMA + joiner.toString();
         }
         String fetchSql =  "SELECT jian_ce_zhou_qi_,facs_type,pos.name_,COUNT(shi_fou_guo_shen_<>'已完成'  OR NULL ) AS todo,COUNT(shi_fou_guo_shen_='已完成'  OR NULL) AS done ,MAX(facs.pagePath) AS pagePath" +
                 "   FROM v_facs_summary_daily, ibps_party_position pos,(SELECT DISTINCT pagePath,`type` FROM v_facs WHERE pagePath <>'') facs" +
-                "   WHERE di_dian_='%s' AND bian_zhi_bu_men_=pos.id_ AND facs_type = facs.type" +
+                "   WHERE FIND_IN_SET(bian_zhi_bu_men_,'%s') AND bian_zhi_bu_men_=pos.id_ AND facs_type = facs.type" +
                 "   GROUP BY jian_ce_zhou_qi_,facs_type,bian_zhi_bu_men_ ORDER BY facs_type;";
-        return (List<Map<String, Object>>)commonDao.query(String.format(fetchSql,object3.get(0).get("id_")));
+        return (List<Map<String, Object>>)commonDao.query(String.format(fetchSql,buMen));
+
     }
 }