Procházet zdrojové kódy

[task-2106]子设备管理看板开发/设备管理看板接口

szjbdgzl před 1 rokem
rodič
revize
b3934b5dfe

+ 14 - 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.EquipmentDashBoardDTO;
 import com.lc.ibps.business.dto.LabsDashBoardDTO;
 import com.lc.ibps.business.dto.TrainingDashBoardDTO;
 import com.lc.ibps.business.service.StatisticService;
@@ -72,4 +73,17 @@ public class StatisticController extends GenericProvider {
         }
         return result;
     }
+
+    @ApiOperation("获取设备管理看板")
+    @GetMapping("/equipDashBoard")
+    APIResult<List<EquipmentDashBoardDTO>> getEquipmentDashBoard() {
+        APIResult<List<EquipmentDashBoardDTO>> result = new APIResult<>();
+        try {
+            List<EquipmentDashBoardDTO> labsDashBoard = statisticService.getEquipmentDashBoard();
+            result.setData(labsDashBoard);
+        } catch (Exception e) {
+            setExceptionResult(result, StateEnum.ILLEGAL_REQUEST.getCode(), I18nUtil.getMessage(StateEnum.ILLEGAL_REQUEST.getCode() + ""), e);
+        }
+        return result;
+    }
 }

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

@@ -0,0 +1,34 @@
+package com.lc.ibps.business.dto;
+
+public class EquipDeptDTO {
+
+    private String name;
+
+    private int value;
+
+    private String rate;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getValue() {
+        return value;
+    }
+
+    public void setValue(int value) {
+        this.value = value;
+    }
+
+    public String getRate() {
+        return rate;
+    }
+
+    public void setRate(String rate) {
+        this.rate = rate;
+    }
+}

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

@@ -0,0 +1,54 @@
+package com.lc.ibps.business.dto;
+
+public class EquipServiceLifeDTO {
+
+    private String org;
+
+    private int numO;
+
+    private int numOT;
+
+    private int numTF;
+
+    private int numF;
+
+    public String getOrg() {
+        return org;
+    }
+
+    public void setOrg(String org) {
+        this.org = org;
+    }
+
+    public int getNumO() {
+        return numO;
+    }
+
+    public void setNumO(int numO) {
+        this.numO = numO;
+    }
+
+    public int getNumOT() {
+        return numOT;
+    }
+
+    public void setNumOT(int numOT) {
+        this.numOT = numOT;
+    }
+
+    public int getNumTF() {
+        return numTF;
+    }
+
+    public void setNumTF(int numTF) {
+        this.numTF = numTF;
+    }
+
+    public int getNumF() {
+        return numF;
+    }
+
+    public void setNumF(int numF) {
+        this.numF = numF;
+    }
+}

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

@@ -0,0 +1,50 @@
+package com.lc.ibps.business.dto;
+
+public class EquipTypeDTO {
+
+    private String name;
+
+    private int value;
+
+    private String rate;
+
+    public static final EquipTypeDTO[] TYPELIST = {
+            new EquipTypeDTO("检验系统", 0, "0.00"),
+            new EquipTypeDTO("通用设备", 0, "0.00"),
+            new EquipTypeDTO("信息系统", 0, "0.00"),
+            new EquipTypeDTO("软件", 0, "0.00")
+    };
+
+    public EquipTypeDTO(String name, int value, String rate) {
+        this.name = name;
+        this.value = value;
+        this.rate = rate;
+    }
+
+    public EquipTypeDTO() {
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public int getValue() {
+        return value;
+    }
+
+    public void setValue(int value) {
+        this.value = value;
+    }
+
+    public String getRate() {
+        return rate;
+    }
+
+    public void setRate(String rate) {
+        this.rate = rate;
+    }
+}

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

@@ -0,0 +1,49 @@
+package com.lc.ibps.business.dto;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class EquipmentDashBoardDTO {
+
+    private List<EquipTypeDTO> distributionDataObj;//检验科各个类型设备分布情况
+
+    private List<EquipDeptDTO> numDistributionDataObj;//  各组设备总数分布情况
+
+    private List<EquipServiceLifeDTO> lifeTimeData; // 部门设备寿命情况统计
+
+    public List<EquipServiceLifeDTO> getLifeTimeData() {
+        return lifeTimeData;
+    }
+
+    public void setLifeTimeData(List<EquipServiceLifeDTO> lifeTimeData) {
+        this.lifeTimeData = lifeTimeData;
+    }
+
+    public List<EquipDeptDTO> getNumDistributionDataObj() {
+        return numDistributionDataObj;
+    }
+
+    public void setNumDistributionDataObj(List<EquipDeptDTO> numDistributionDataObj) {
+        this.numDistributionDataObj = numDistributionDataObj;
+    }
+
+    public List<EquipTypeDTO> getDistributionDataObj() {
+        return distributionDataObj;
+    }
+
+    public void setDistributionDataObj(List<EquipTypeDTO> distributionDataObj) {
+        Set<String> existingTypeNames = new HashSet<>();
+        for (EquipTypeDTO rate : distributionDataObj) {
+            existingTypeNames.add(rate.getName());
+        }
+        List<EquipTypeDTO> finalList = new ArrayList<>(distributionDataObj);
+        for (EquipTypeDTO predefined : EquipTypeDTO.TYPELIST) {
+            if (!existingTypeNames.contains(predefined.getName())) {
+                finalList.add(predefined);
+            }
+        }
+        this.distributionDataObj = finalList;
+    }
+}

+ 3 - 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.EquipmentDashBoardDTO;
 import com.lc.ibps.business.dto.LabsDashBoardDTO;
 import com.lc.ibps.business.dto.TrainingDashBoardDTO;
 import com.lc.ibps.cloud.entity.APIResult;
@@ -12,4 +13,6 @@ public interface StatisticService {
     List<LabsDashBoardDTO> getLabsDashBoard(String year, String filter);
 
     List<TrainingDashBoardDTO> getTrainingDashBoard(String dept, String type, String date);
+
+    List<EquipmentDashBoardDTO> getEquipmentDashBoard();
 }

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

@@ -14,11 +14,13 @@ import com.lc.ibps.common.api.IDictionaryService;
 import com.lc.ibps.common.cat.persistence.entity.DictionaryPo;
 import com.lc.ibps.org.api.IPartyPositionService;
 import com.lc.ibps.org.party.persistence.entity.PartyPositionPo;
+import org.apache.poi.ss.formula.functions.T;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.lang.reflect.Method;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.time.DayOfWeek;
@@ -146,6 +148,192 @@ public class StatisticServiceImpl implements StatisticService {
         return list;
     }
 
+    @Override
+    public List<EquipmentDashBoardDTO> getEquipmentDashBoard() {
+        List<EquipmentDashBoardDTO> list = new ArrayList<>();
+        EquipmentDashBoardDTO equipDTO = new EquipmentDashBoardDTO();
+
+        String sql = "SELECT count(*) as total from t_sbdj WHERE di_dian_='%s'";
+        int total = Integer.parseInt(commonDao.queryOne(String.format(sql,getDiDian())).get("total").toString());
+
+        // 检验科各个类型设备分布情况
+        equipDTO.setDistributionDataObj(getEquipType(total));
+
+        //  各组设备总数分布情况
+        equipDTO.setNumDistributionDataObj(getEquipByPosition(total));
+
+        //  部门设备寿命情况统计
+        equipDTO.setLifeTimeData(getEquipServiceLife());
+
+        //  设备调整情况
+
+        //  各部门设备完好情况
+
+        //  各部门设备维护完成情况
+
+        //  各部门设备检定/校准完成情况
+
+        //  检验科设备停用/报废列表
+
+        list.add(equipDTO);
+        return list;
+    }
+
+    public List<EquipServiceLifeDTO> getEquipServiceLife(){
+        Set<String> existsDept = new HashSet<>();
+        List<EquipServiceLifeDTO> lifeDTOList = new ArrayList<>();
+        String sql = "SELECT p.name_,q.bian_zhi_bu_men_,COUNT(bian_zhi_bu_men_)as value from ( " +
+                " SELECT bian_zhi_bu_men_ FROM t_sbdj WHERE %s and di_dian_='%s') q, " +
+                " (SELECT name_,id_ from ibps_party_entity WHERE path_ like '%%%s%%' and DEPTH_>=3) p " +
+                " where q.bian_zhi_bu_men_=p.id_ GROUP BY q.bian_zhi_bu_men_";
+
+        String conditions = "TIMESTAMPDIFF(YEAR, chu_chang_ri_qi_, CURDATE())<1";
+        List<Map<String, Object>> listO = (List<Map<String, Object>>) commonDao.query(String.format(sql,conditions,getDiDian(),getDiDian()));
+        getLife(listO,lifeDTOList,existsDept,"O");
+
+        conditions = "TIMESTAMPDIFF(YEAR, chu_chang_ri_qi_, CURDATE())>=1 and TIMESTAMPDIFF(YEAR, chu_chang_ri_qi_, CURDATE())<3";
+        List<Map<String, Object>> listOT = (List<Map<String, Object>>) commonDao.query(String.format(sql,conditions,getDiDian(),getDiDian()));
+        getLife(listOT,lifeDTOList,existsDept,"OF");
+
+        conditions = "TIMESTAMPDIFF(YEAR, chu_chang_ri_qi_, CURDATE())>=3 and TIMESTAMPDIFF(YEAR, chu_chang_ri_qi_, CURDATE())<5";
+        List<Map<String, Object>> listTF = (List<Map<String, Object>>) commonDao.query(String.format(sql,conditions,getDiDian(),getDiDian()));
+        getLife(listTF,lifeDTOList,existsDept,"TF");
+
+        conditions = "TIMESTAMPDIFF(YEAR, chu_chang_ri_qi_, CURDATE())>=5";
+        List<Map<String, Object>> listF = (List<Map<String, Object>>) commonDao.query(String.format(sql,conditions,getDiDian(),getDiDian()));
+        getLife(listF,lifeDTOList,existsDept,"F");
+
+        Map<String, EquipServiceLifeDTO> mergedDTOMap = new HashMap<>();
+        for (EquipServiceLifeDTO dto : lifeDTOList) {
+            if (!mergedDTOMap.containsKey(dto.getOrg())) {
+                mergedDTOMap.put(dto.getOrg(), dto);
+            } else {
+                EquipServiceLifeDTO mergedDTO = mergedDTOMap.get(dto.getOrg());
+                mergedDTO.setNumO(mergedDTO.getNumO() + dto.getNumO());
+                mergedDTO.setNumOT(mergedDTO.getNumOT() + dto.getNumOT());
+                mergedDTO.setNumTF(mergedDTO.getNumTF() + dto.getNumTF());
+                mergedDTO.setNumF(mergedDTO.getNumF() + dto.getNumF());
+            }
+        }
+        List<EquipServiceLifeDTO> mergedList = new ArrayList<>(mergedDTOMap.values());
+
+        List<EquipServiceLifeDTO> finalList = new ArrayList<>(mergedList);
+        List<Map<String, Object>> deptList = getPositionBy34(getDiDian());
+        for (Map<String, Object> dept : deptList) {
+            if (!existsDept.contains(dept.get("name_"))) {
+                EquipServiceLifeDTO lifeDTO = new EquipServiceLifeDTO();
+                lifeDTO.setOrg(dept.get("name_").toString());
+                lifeDTO.setNumO(0);
+                lifeDTO.setNumOT(0);
+                lifeDTO.setNumTF(0);
+                lifeDTO.setNumF(0);
+                finalList.add(lifeDTO);
+            }
+        }
+        return finalList;
+    }
+
+    public void getLife(List<Map<String, Object>> list,List<EquipServiceLifeDTO> lifeDTOList,Set<String> existsDept,String flag){
+        for (Map<String, Object> map: list){
+            EquipServiceLifeDTO lifeDTO = new EquipServiceLifeDTO();
+            lifeDTO.setOrg(map.get("name_").toString());
+            int value = Integer.parseInt(map.get("value").toString());
+            switch (flag){
+                case "O":
+                    lifeDTO.setNumO(value);
+                    break;
+                case "OT":
+                    lifeDTO.setNumOT(value);
+                    break;
+                case "TF":
+                    lifeDTO.setNumTF(value);
+                    break;
+                case "F":
+                    lifeDTO.setNumF(value);
+                    break;
+            }
+            lifeDTOList.add(lifeDTO);
+            existsDept.add(map.get("name_").toString());
+        }
+    }
+
+
+    public List<EquipDeptDTO> getEquipByPosition(int total){
+        String sql = "SELECT p.name_,q.bian_zhi_bu_men_,COUNT(bian_zhi_bu_men_)as value from ( " +
+                " SELECT bian_zhi_bu_men_ from t_sbdj WHERE di_dian_='%s') q, " +
+                " (SELECT name_,id_ from ibps_party_entity WHERE path_ like '%%%s%%' and DEPTH_>=3) p " +
+                " where q.bian_zhi_bu_men_=p.id_ GROUP BY q.bian_zhi_bu_men_ ";
+        List<Map<String, Object>> list = (List<Map<String, Object>>) commonDao.query(String.format(sql,getDiDian(),getDiDian()));
+        List<EquipDeptDTO> typeDTOList = new ArrayList<>();
+        Set<String> existsDept = new HashSet<>();
+        for (Map<String, Object> map: list){
+            EquipDeptDTO typeDTO = new EquipDeptDTO();
+            int value = Integer.parseInt(map.get("value").toString());
+            typeDTO.setValue(value);
+            typeDTO.setName(map.get("name_").toString());
+            typeDTO.setRate(getRate(total,value));
+            typeDTOList.add(typeDTO);
+            existsDept.add(map.get("name_").toString());
+        }
+        List<EquipDeptDTO> finalList = new ArrayList<>(typeDTOList);
+        List<Map<String, Object>> deptList = getPositionBy34(getDiDian());
+        for (Map<String, Object> dept : deptList) {
+            if (!existsDept.contains(dept.get("name_"))) {
+                EquipDeptDTO typeDTO = new EquipDeptDTO();
+                typeDTO.setName(dept.get("name_").toString());
+                typeDTO.setValue(0);
+                typeDTO.setRate("0.00");
+                finalList.add(typeDTO);
+            }
+        }
+        return finalList;
+    }
+
+    public List<T> setPosition(List<T> original, Set<String> exists, Class<T> clazz) throws Exception {
+        Method setNameMethod = clazz.getMethod("setName", String.class);
+        List<Map<String, Object>> deptList = getPositionBy34(getDiDian());
+        for (Map<String, Object> map : deptList) {
+            if (!exists.contains(map.get("name_"))) {
+                for (T t : original) {
+                    setNameMethod.invoke(t, map.get("name_"));
+                }
+            }
+        }
+        return original;
+    }
+
+    public List<Map<String, Object>> getPositionBy34(String diDian){
+        String sql = "SELECT name_,id_ from ibps_party_entity WHERE path_ like '%%%s%%' and DEPTH_>=3";
+        return  (List<Map<String, Object>>) commonDao.query(String.format(sql,diDian));
+    }
+
+    public List<EquipTypeDTO> getEquipType(int total){
+        String sql = "SELECT she_bei_lei_xing_ name,COUNT(she_bei_lei_xing_) as value from t_sbdj WHERE di_dian_='%s' GROUP BY she_bei_lei_xing_";
+        List<Map<String, Object>> list = (List<Map<String, Object>>) commonDao.query(String.format(sql,getDiDian()));
+        List<EquipTypeDTO> typeDTOList = new ArrayList<>();
+        for (Map<String, Object> map: list){
+            EquipTypeDTO typeDTO = new EquipTypeDTO();
+            int value = Integer.parseInt(map.get("value").toString());
+            typeDTO.setValue(value);
+            typeDTO.setName(map.get("name").toString());
+            typeDTO.setRate(getRate(total,value));
+            typeDTOList.add(typeDTO);
+        }
+        return typeDTOList;
+    }
+
+    public String getRate(int total,int count){
+        BigDecimal sum = new BigDecimal(total);
+        BigDecimal sign = new BigDecimal(count);
+        if (sum.compareTo(BigDecimal.ZERO) != 0) {
+            BigDecimal percentage = sign.divide(sum, 10, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
+            percentage = percentage.setScale(2, RoundingMode.HALF_UP);
+            return percentage.toString();
+        }else {
+            return "0.00";
+        }
+    }
+
     public TrainGuardAutoPlanDto getPlanRate(String dept){
         TrainGuardAutoPlanDto planDto = new TrainGuardAutoPlanDto();
         String zdSql = "select count(*) as auto from t_rypxcjb where ji_hua_wai_jian_ in(select id_ from t_ndrypxjhzb) and ji_hua_lei_xing_='在岗培训' and di_dian_='"+getDiDian()+"'";