Browse Source

[task-1938]【后端】实验室管理看板接口开发

Li Yuan 1 năm trước cách đây
mục cha
commit
a9fb936118

+ 17 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/controller/StatisticController.java

@@ -2,6 +2,7 @@ package com.lc.ibps.business.controller;
 
 import com.lc.ibps.api.base.constants.StateEnum;
 import com.lc.ibps.base.core.util.I18nUtil;
+import com.lc.ibps.business.dto.LabsDashBoardDTO;
 import com.lc.ibps.business.service.StatisticService;
 import com.lc.ibps.cloud.entity.APIResult;
 import com.lc.ibps.cloud.provider.GenericProvider;
@@ -36,4 +37,20 @@ public class StatisticController extends GenericProvider {
         }
         return result;
     }
+
+    @ApiOperation("获取实验室管理看板")
+    @GetMapping("/labsDashBoard")
+    APIResult<List<LabsDashBoardDTO>> getLabsDashBoard(@NotBlank(message = "统计年份")
+                                                          @RequestParam(name = "year", required = true) String year,
+                                                          @NotBlank(message = "过滤专业组")
+                                                          @RequestParam(name = "filter", required = false) String filter) {
+        APIResult<List<LabsDashBoardDTO>> result = new APIResult<>();
+        try {
+            List<LabsDashBoardDTO> labsDashBoard = statisticService.getLabsDashBoard(year,filter);
+            result.setData(labsDashBoard);
+        } catch (Exception e) {
+            setExceptionResult(result, StateEnum.ILLEGAL_REQUEST.getCode(), I18nUtil.getMessage(StateEnum.ILLEGAL_REQUEST.getCode() + ""), e);
+        }
+        return result;
+    }
 }

+ 70 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/dto/LabsDashBoardDTO.java

@@ -0,0 +1,70 @@
+package com.lc.ibps.business.dto;
+
+import com.lc.ibps.base.core.util.Collections;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.*;
+
+public class LabsDashBoardDTO  implements Serializable {
+    private String name;
+    private List<LabsDashBoardGroupDTO> groups;
+    private LabsDashBoardGroupDTO totally;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public List<LabsDashBoardGroupDTO> getGroups() {
+        return groups;
+    }
+
+    public void setGroups(List<LabsDashBoardGroupDTO> groups) {
+        this.groups = groups;
+    }
+
+    public LabsDashBoardGroupDTO getTotally() {
+        return totally;
+    }
+
+    public void setTotally(LabsDashBoardGroupDTO totally) {
+        this.totally = totally;
+    }
+
+    public void calcTotally(Collection<LabsDashBoardGroupDTO> groups){
+        totally = new LabsDashBoardGroupDTO();
+        totally.setName("全科室");
+        if(Collections.isEmpty(groups)){
+            return;
+        }
+        totally.setNumAll(groups.stream().mapToInt(LabsDashBoardGroupDTO::getNumAll).sum());
+        totally.setNumSuccess(groups.stream().mapToInt(LabsDashBoardGroupDTO::getNumSuccess).sum());
+        totally.setNumUn(totally.getNumAll() - totally.getNumSuccess());
+        double d = (double) 100d * totally.getNumSuccess()/totally.getNumAll();
+        totally.setRate(new BigDecimal(d).setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
+    }
+
+    public void generateGroups(Map<String,LabsDashBoardGroupDTO> dtoGroup, List<String> deptList, String filter) {
+        groups = new ArrayList<>();
+        List<String> filterList = new ArrayList<>();
+        if(StringUtils.isNotBlank(filter)){
+            filterList = Arrays.asList(filter.split(","));
+        }
+
+        for (String group : deptList) {
+            if(filterList.contains(group)) continue;
+            if (dtoGroup.containsKey(group)) {
+                groups.add(dtoGroup.get(group));
+            } else {
+                LabsDashBoardGroupDTO dto = new LabsDashBoardGroupDTO();
+                dto.setName(group);
+                groups.add(dto);
+            }
+        }
+    }
+}

+ 53 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/dto/LabsDashBoardGroupDTO.java

@@ -0,0 +1,53 @@
+package com.lc.ibps.business.dto;
+
+import java.io.Serializable;
+
+public class LabsDashBoardGroupDTO implements Serializable {
+
+    private String name = "";
+    private int numAll;
+    private int numSuccess;
+    private int numUn;
+    private double rate;
+
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getNumAll() {
+        return numAll;
+    }
+
+    public void setNumAll(int numAll) {
+        this.numAll = numAll;
+    }
+
+    public int getNumSuccess() {
+        return numSuccess;
+    }
+
+    public void setNumSuccess(int numSuccess) {
+        this.numSuccess = numSuccess;
+    }
+
+    public int getNumUn() {
+        return numUn;
+    }
+
+    public void setNumUn(int numUn) {
+        this.numUn = numUn;
+    }
+
+    public double getRate() {
+        return rate;
+    }
+
+    public void setRate(double rate) {
+        this.rate = rate;
+    }
+}

+ 2 - 0
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/service/StatisticService.java

@@ -1,5 +1,6 @@
 package com.lc.ibps.business.service;
 
+import com.lc.ibps.business.dto.LabsDashBoardDTO;
 import com.lc.ibps.cloud.entity.APIResult;
 
 import java.util.List;
@@ -7,4 +8,5 @@ import java.util.Map;
 
 public interface StatisticService {
     List<Map<String, Object>> getRiskReport(String riskId, String type);
+    List<LabsDashBoardDTO> getLabsDashBoard(String year, String filter);
 }

+ 100 - 3
ibps-provider-root/modules/provider-business/src/main/java/com/lc/ibps/business/service/impl/StatisticServiceImpl.java

@@ -1,17 +1,28 @@
 package com.lc.ibps.business.service.impl;
 
 
+import com.lc.ibps.base.core.constants.StringPool;
+import com.lc.ibps.base.core.util.AppUtil;
+import com.lc.ibps.base.core.util.Collections;
 import com.lc.ibps.base.framework.table.ICommonDao;
+import com.lc.ibps.base.web.context.ContextUtil;
+import com.lc.ibps.business.dto.LabsDashBoardDTO;
+import com.lc.ibps.business.dto.LabsDashBoardGroupDTO;
 import com.lc.ibps.business.service.StatisticService;
+import com.lc.ibps.cloud.entity.APIResult;
+import com.lc.ibps.org.api.IPartyPositionService;
+import com.lc.ibps.org.party.persistence.entity.PartyPositionPo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.List;
-import java.util.Map;
+import java.math.BigDecimal;
+import java.util.*;
 
 @Service
 public class StatisticServiceImpl implements StatisticService {
-
+    private static final Logger logger = LoggerFactory.getLogger(StatisticServiceImpl.class);
     @Resource
     private ICommonDao<?> commonDao;
 
@@ -22,6 +33,79 @@ public class StatisticServiceImpl implements StatisticService {
         return (List<Map<String, Object>>) commonDao.query(typeSql,new String[]{riskId});
     }
 
+    @Override
+    public List<LabsDashBoardDTO> getLabsDashBoard(String year, String filter) {
+        String diDian = getDiDian();
+        if (diDian == null) return null;
+        List<String> deptList = getDeptList(diDian);
+        if(Collections.isEmpty(deptList)) return null;
+        List<LabsDashBoardDTO> result = new ArrayList<>();
+        for (Map.Entry<String,String> entry: getZhiBiao().entrySet()) {
+            LabsDashBoardDTO dto = new LabsDashBoardDTO();
+            Map<String,LabsDashBoardGroupDTO> dtoGroup = getIndex(diDian,year,deptList,entry.getKey());
+            dto.calcTotally(dtoGroup.values());
+            dto.setName(entry.getValue());
+            dto.generateGroups(dtoGroup,deptList,filter);
+            result.add(dto);
+        }
+
+        return result;
+    }
+
+    private Map<String,String> getZhiBiao(){
+        Map<String,String> map = new HashMap<>();
+        map.put("v_LabsDashBoard_1_zaiGang","在岗人员培训");
+        map.put("v_LabsDashBoard_2_gangQian","岗前培训");
+        map.put("v_LabsDashBoard_3_waiBuZhiLiang","外部质量管理");
+        map.put("v_LabsDashBoard_4_neiBuBiDui","内部比对实验");
+        return map;
+    }
+
+    private Map<String,LabsDashBoardGroupDTO> getIndex(String diDian, String year, List<String> deptList, String viewName) {
+        Map<String,LabsDashBoardGroupDTO> dtoList = new HashMap<>();
+        String sql = "SELECT NAME_,numA,num,chu FROM %s WHERE di_dian_='%s' AND year_='%s'";
+        sql = String.format(sql,viewName,diDian,year);
+        List<Map<String, Object>> l = (List<Map<String, Object>>) commonDao.query(sql);
+        if (Collections.isEmpty(l)) return dtoList;
+        for (Map<String, Object> val : l) {
+            val = transformLowerCase(val);
+            LabsDashBoardGroupDTO group  = new LabsDashBoardGroupDTO();
+            group.setName((String)val.get("name_") );
+            group.setNumAll(((Long)val.get("numa")).intValue() );
+            group.setNumSuccess(((Long)val.get("num")).intValue() );
+            group.setRate(((BigDecimal) val.get("chu")).doubleValue());
+            group.setNumUn(group.getNumAll() - group.getNumSuccess());
+            dtoList.put(group.getName(),group);
+        }
+        return dtoList;
+    }
+
+    private String getDiDian() {
+        IPartyPositionService partyPositionService = AppUtil.getBean(IPartyPositionService.class);
+        APIResult<List<PartyPositionPo>> result = partyPositionService.findByUserId(ContextUtil.getCurrentUserId());
+        String diDian ="";
+        try {
+            diDian = result.getData().get(0).getPath().split(StringPool.BACK_SLASH + StringPool.DOT)[1];
+        }catch (Exception ex){
+            logger.error("Can't get didian information",ex);
+            return null;
+        }
+        return diDian;
+    }
+
+    private List<String> getDeptList(String diDian) {
+        String sql = "SELECT name_ FROM ibps_party_entity WHERE party_type_='position'  AND depth_ =4 AND path_ LIKE '%%%s%%' ORDER BY sn_";
+        sql =String.format(sql, diDian);
+        List<Map<String, Object>> l = (List<Map<String, Object>>) commonDao.query(sql);
+        if (Collections.isEmpty(l)) return null;
+        List<String> deptList = new ArrayList<>();
+        for (Map<String, Object> val : l) {
+            val = transformLowerCase(val);
+            deptList.add( (String)val.get("name_") );
+        }
+        return deptList;
+    }
+
     private String getFetchSqlForRiskReport(String type){
         String fetchSql = "";
         if(type.equalsIgnoreCase("FXDJ")){
@@ -55,4 +139,17 @@ public class StatisticServiceImpl implements StatisticService {
 
         return fetchSql;
     }
+
+    private Map<String, Object> transformLowerCase(Map<String, Object> map) {
+        Map<String, Object> resultMap = new HashMap<>();
+        if (map == null || map.isEmpty()) {
+            return resultMap;
+        }
+        Set<String> keySet = map.keySet();
+        for (String key : keySet) {
+            String newKey = key.toLowerCase();
+            resultMap.put(newKey, map.get(key));
+        }
+        return resultMap;
+    }
 }