zhaops 5 gadi atpakaļ
vecāks
revīzija
dc9d80b36b

+ 132 - 12
src/main/java/com/diagbot/aggregate/AverageStatisticsAggregate.java

@@ -3,6 +3,10 @@ package com.diagbot.aggregate;
 import com.diagbot.dto.AverageStatisticsDTO;
 import com.diagbot.facade.ConsoleFacade;
 import com.diagbot.facade.HomePageFacade;
+import com.diagbot.facade.QcresultInfoFacade;
+import com.diagbot.util.BeanUtil;
+import com.diagbot.util.DateUtil;
+import com.diagbot.util.EntityUtil;
 import com.diagbot.util.ListUtil;
 import com.diagbot.vo.FilterVO;
 import com.google.common.collect.Lists;
@@ -12,6 +16,9 @@ import io.github.lvyahui8.spring.annotation.InvokeParameter;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Date;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
@@ -26,13 +33,16 @@ public class AverageStatisticsAggregate {
     @Autowired
     private HomePageFacade homePageFacade;
     @Autowired
+    private QcresultInfoFacade qcresultInfoFacade;
+    @Autowired
     private ConsoleFacade consoleFacade;
 
     @DataProvider("setAllAverage")
     public Map<String, Object> setAllResult(
             @InvokeParameter("filterVO") FilterVO filterVO,
             @DataConsumer("getAverageDayNum") List<AverageStatisticsDTO> averageDayNumList,
-            @DataConsumer("getAverageFee") List<AverageStatisticsDTO> averageFeeList) {
+            @DataConsumer("getAverageFee") List<AverageStatisticsDTO> averageFeeList,
+            @DataConsumer("getAverageScore") List<AverageStatisticsDTO> averageScoreList) {
         Map<String, Object> retMap = new LinkedHashMap<>();
         if (ListUtil.isNotEmpty(averageDayNumList)) {
             retMap.put("平均住院日", averageDayNumList);
@@ -40,6 +50,9 @@ public class AverageStatisticsAggregate {
         if (ListUtil.isNotEmpty(averageFeeList)) {
             retMap.put("平均住院费用", averageFeeList);
         }
+        if (ListUtil.isNotEmpty(averageScoreList)) {
+            retMap.put("各科室质控平均分", averageScoreList);
+        }
         return retMap;
     }
 
@@ -53,14 +66,40 @@ public class AverageStatisticsAggregate {
     public List<AverageStatisticsDTO> getAverageDayNum(@InvokeParameter("filterVO") FilterVO filterVO) {
         List<AverageStatisticsDTO> retAverageDayNumList = Lists.newLinkedList();
         List<AverageStatisticsDTO> averageDayNumList = homePageFacade.getAverageDayNum(filterVO);
-        if (filterVO.getLimitCount() == null || filterVO.getLimitCount().equals(0)) {
-            filterVO.setLimitCount(10);
-        }
-        Integer limitCount = filterVO.getLimitCount();
-        //平均住院日
-        if (ListUtil.isNotEmpty(averageDayNumList)) {
-            retAverageDayNumList = consoleFacade.getLimitAverageList(averageDayNumList, limitCount);
+
+        //上月、去年
+        String startDate = consoleFacade.getLastStartDateStr(filterVO.getType());
+        String endDate = consoleFacade.getLastEndDateStr(filterVO.getType());
+        filterVO.setStartDate(startDate);
+        filterVO.setEndDate(endDate);
+        List<AverageStatisticsDTO> lastAverageDayNumList = homePageFacade.getAverageDayNum(filterVO);
+        Map<String, Double> lastMap
+                = EntityUtil.makeMapWithKeyValue(lastAverageDayNumList, "deptName", "averageValue");
+
+        //去年本月
+        if (filterVO.getType().equals(1)) {
+            Date date = new Date();
+            String year = DateUtil.getYear(date);
+            startDate = consoleFacade.getStartDateStr(filterVO.getType(), Integer.valueOf(year) - 1);
+            endDate = consoleFacade.getEndDateStr(filterVO.getType(), Integer.valueOf(year) - 1);
+            filterVO.setStartDate(startDate);
+            filterVO.setEndDate(endDate);
         }
+        //按年统计,同比环比相同
+        List<AverageStatisticsDTO> lastYearAverageDayNumList = homePageFacade.getAverageDayNum(filterVO);
+
+        Map<String, Double> lastYearMap
+                = EntityUtil.makeMapWithKeyValue(lastYearAverageDayNumList, "deptName", "averageValue");
+
+        averageDayNumList.forEach(item -> {
+            if (lastMap.containsKey(item.getDeptName())) {
+                item.setLastAverageValue(lastMap.get(item.getDeptName()));
+            }
+            if (lastYearMap.containsKey(item.getDeptName())) {
+                item.setLastYearAverageValue(lastYearMap.get(item.getDeptName()));
+            }
+        });
+        retAverageDayNumList = averageDayNumList.subList(0, 10);
         return retAverageDayNumList;
     }
 
@@ -74,14 +113,95 @@ public class AverageStatisticsAggregate {
     public List<AverageStatisticsDTO> getAverageFee(@InvokeParameter("filterVO") FilterVO filterVO) {
         List<AverageStatisticsDTO> retAverageFeeList = Lists.newLinkedList();
         List<AverageStatisticsDTO> averageFeeList = homePageFacade.getAverageFee(filterVO);
+        //上月、去年
+        String startDate = consoleFacade.getLastStartDateStr(filterVO.getType());
+        String endDate = consoleFacade.getLastEndDateStr(filterVO.getType());
+        filterVO.setStartDate(startDate);
+        filterVO.setEndDate(endDate);
+        List<AverageStatisticsDTO> lastAverageFeeList = homePageFacade.getAverageDayNum(filterVO);
+        Map<String, Double> lastMap
+                = EntityUtil.makeMapWithKeyValue(lastAverageFeeList, "deptName", "averageValue");
+
+        //去年本月
+        if (filterVO.getType().equals(1)) {
+            Date date = new Date();
+            String year = DateUtil.getYear(date);
+            startDate = consoleFacade.getStartDateStr(filterVO.getType(), Integer.valueOf(year) - 1);
+            endDate = consoleFacade.getEndDateStr(filterVO.getType(), Integer.valueOf(year) - 1);
+            filterVO.setStartDate(startDate);
+            filterVO.setEndDate(endDate);
+        }
+        //按年统计,同比环比相同
+        List<AverageStatisticsDTO> lastYearAverageFeeList = homePageFacade.getAverageDayNum(filterVO);
+
+        Map<String, Double> lastYearMap
+                = EntityUtil.makeMapWithKeyValue(lastYearAverageFeeList, "deptName", "averageValue");
+
+        averageFeeList.forEach(item -> {
+            if (lastMap.containsKey(item.getDeptName())) {
+                item.setLastAverageValue(lastMap.get(item.getDeptName()));
+            }
+            if (lastYearMap.containsKey(item.getDeptName())) {
+                item.setLastYearAverageValue(lastYearMap.get(item.getDeptName()));
+            }
+        });
+        retAverageFeeList = averageFeeList.subList(0, 10);
+        return retAverageFeeList;
+    }
+
+    /**
+     * 质控平均分按科室统计
+     *
+     * @param filterVO
+     * @return
+     */
+    @DataProvider("getAverageScore")
+    public List<AverageStatisticsDTO> getAverageScore(@InvokeParameter("filterVO") FilterVO filterVO) {
+        List<AverageStatisticsDTO> retAverageScoreList = Lists.newLinkedList();
+        List<AverageStatisticsDTO> averageScoreList = qcresultInfoFacade.getAverageScoreByDept(filterVO);
         if (filterVO.getLimitCount() == null || filterVO.getLimitCount().equals(0)) {
             filterVO.setLimitCount(10);
         }
         Integer limitCount = filterVO.getLimitCount();
-        //平均住院费用
-        if (ListUtil.isNotEmpty(averageFeeList)) {
-            retAverageFeeList = consoleFacade.getLimitAverageList(averageFeeList, limitCount);
+        //质控平均分
+        if (ListUtil.isNotEmpty(averageScoreList)) {
+            retAverageScoreList = getLimitAverageList(averageScoreList, limitCount);
         }
-        return retAverageFeeList;
+        return retAverageScoreList;
+    }
+
+    /**
+     * 根据限制数量重组统计结果
+     *
+     * @param averageList
+     * @param limitCount
+     * @return
+     */
+    public List<AverageStatisticsDTO> getLimitAverageList(List<AverageStatisticsDTO> averageList, Integer limitCount) {
+        List<AverageStatisticsDTO> retAverageList = Lists.newLinkedList();
+        if (averageList.size() <= limitCount) {
+            retAverageList = BeanUtil.listCopyTo(averageList, AverageStatisticsDTO.class);
+        } else {
+            retAverageList = averageList.subList(0, limitCount - 1);
+            List<AverageStatisticsDTO> otherList = averageList.subList(limitCount - 1, averageList.size());
+            Double totleValue = otherList
+                    .stream()
+                    .map(i -> BigDecimal.valueOf(i.getTotleValue()))
+                    .reduce(BigDecimal.ZERO, BigDecimal::add).doubleValue();
+            Integer num = otherList
+                    .stream()
+                    .map(AverageStatisticsDTO::getNum)
+                    .reduce(0, Integer::sum);
+            Double averageValue = BigDecimal.valueOf(totleValue)
+                    .divide(BigDecimal.valueOf(num), 2, RoundingMode.HALF_UP)
+                    .doubleValue();
+            AverageStatisticsDTO retAverageStatistics = new AverageStatisticsDTO();
+            retAverageStatistics.setDeptName("其他");
+            retAverageStatistics.setNum(num);
+            retAverageStatistics.setAverageValue(averageValue);
+            retAverageStatistics.setTotleValue(totleValue);
+            retAverageList.add(retAverageStatistics);
+        }
+        return retAverageList;
     }
 }

+ 13 - 1
src/main/java/com/diagbot/aggregate/DeptStatisticsAggregate.java

@@ -49,6 +49,12 @@ public class DeptStatisticsAggregate {
         return retMap;
     }
 
+    /**
+     * 各科室甲级病历占比
+     *
+     * @param filterVO
+     * @return
+     */
     @DataProvider("getLevelResultDept")
     public List<QcResultPercentDTO> getLevelResultDept(@InvokeParameter("filterVO") FilterVO filterVO) {
         List<QcResultPercentDTO> qcResultPercentList = qcresultInfoFacade.levelPercentGroupByDept(filterVO);
@@ -57,6 +63,12 @@ public class DeptStatisticsAggregate {
     }
 
 
+    /**
+     * 各科室缺陷占比
+     *
+     * @param filterVO
+     * @return
+     */
     @DataProvider("getResultDept")
     public List<ResultDetailDTO> getResultDept(@InvokeParameter("filterVO") FilterVO filterVO) {
         List<ResultDetailDTO> results2 = behospitalInfoFacade.resultStatisticsByDept2(filterVO);
@@ -104,4 +116,4 @@ public class DeptStatisticsAggregate {
         }
         return null;
     }
-}
+}

+ 78 - 42
src/main/java/com/diagbot/aggregate/ResultStatisticsAggregate.java

@@ -1,8 +1,6 @@
 package com.diagbot.aggregate;
 
 import com.diagbot.dto.NumDTO;
-import com.diagbot.dto.ResultDetailDTO;
-import com.diagbot.facade.BehospitalInfoFacade;
 import com.diagbot.facade.QcCasesFacade;
 import com.diagbot.facade.QcresultInfoFacade;
 import com.diagbot.util.BeanUtil;
@@ -34,8 +32,6 @@ import java.util.stream.Collectors;
  */
 @Component
 public class ResultStatisticsAggregate {
-    @Autowired
-    private BehospitalInfoFacade behospitalInfoFacade;
     @Autowired
     private QcresultInfoFacade qcresultInfoFacade;
     @Autowired
@@ -44,50 +40,24 @@ public class ResultStatisticsAggregate {
     @DataProvider("setAllResult")
     public Map<String, Object> setAllResult(
             @InvokeParameter("filterVO") FilterVO filterVO,
-            @DataConsumer("getResult") List<ResultDetailDTO> results,
-            @DataConsumer("entryCountGroupByCase") List<NumDTO> entryNums) {
+            @DataConsumer("entryCountGroupByEntry") List<NumDTO> entryList,
+            @DataConsumer("entryCountGroupByCase") List<NumDTO> caseList) {
         Map<String, Object> retMap = new LinkedHashMap<>();
-        if (ListUtil.isNotEmpty(entryNums)) {
-            retMap.put("各模块缺陷占比排行", entryNums);
+        if (ListUtil.isNotEmpty(caseList)) {
+            retMap.put("各模块缺陷占比排行", caseList);
         }
-        if (ListUtil.isNotEmpty(results)) {
-            retMap.put("条目缺陷占比", results);
+        if (ListUtil.isNotEmpty(entryList)) {
+            retMap.put("条目缺陷占比", entryList);
         }
         return retMap;
     }
 
-    @DataProvider("getResult")
-    public List<ResultDetailDTO> getResult(@InvokeParameter("filterVO") FilterVO filterVO) {
-        List<ResultDetailDTO> results = behospitalInfoFacade.resultStatistics2(filterVO);
-
-        if (ListUtil.isNotEmpty(results)) {
-            int totle = results
-                    .stream()
-                    .map(ResultDetailDTO::getNum)
-                    .reduce(0, Integer::sum);
-            List<ResultDetailDTO> retResutls = Lists.newLinkedList();
-            results.forEach(result -> {
-                Double percent = BigDecimal.valueOf(result.getNum())
-                        .divide(BigDecimal.valueOf(totle), 4, RoundingMode.HALF_UP)
-                        .doubleValue();
-                result.setPercent(percent);
-                DecimalFormat df = new DecimalFormat("#0.00");
-                String percentStr
-                        = df.format(BigDecimal.valueOf(result.getPercent()).multiply(BigDecimal.valueOf(100))) + "%";
-                result.setPercentStr(percentStr);
-                //top9+其他
-                if (retResutls.size() < 10) {
-                    retResutls.add(result);
-                } else {
-                }
-
-            });
-            return retResutls;
-        }
-
-        return null;
-    }
-
+    /**
+     * 各模块缺陷占比排行
+     *
+     * @param filterVO
+     * @return
+     */
     @DataProvider("entryCountGroupByCase")
     public List<NumDTO> entryCountGroupByCase(@InvokeParameter("filterVO") FilterVO filterVO) {
         QcresultFilterVO qcresultFilterVO = new QcresultFilterVO();
@@ -142,4 +112,70 @@ public class ResultStatisticsAggregate {
 
         return standardEntryNumList;
     }
+
+    /**
+     * 条目缺陷占比
+     *
+     * @param filterVO
+     * @return
+     */
+    @DataProvider("entryCountGroupByEntry")
+    public List<NumDTO> entryCountGroupByEntry(@InvokeParameter("filterVO") FilterVO filterVO) {
+        DecimalFormat df = new DecimalFormat("#0.00");
+        List<NumDTO> numDTOList = qcresultInfoFacade.entryCountGroupByEntry(filterVO);
+        if (ListUtil.isNotEmpty(numDTOList)) {
+            int totle = numDTOList
+                    .stream()
+                    .map(NumDTO::getNum)
+                    .reduce(0, Integer::sum);
+            List<NumDTO> retList = Lists.newLinkedList();
+            numDTOList.forEach(numDTO -> {
+                Double percent = BigDecimal.valueOf(numDTO.getNum())
+                        .divide(BigDecimal.valueOf(totle), 4, RoundingMode.HALF_UP)
+                        .doubleValue();
+                numDTO.setPercent(percent);
+                String percentStr
+                        = df.format(BigDecimal.valueOf(percent).multiply(BigDecimal.valueOf(100))) + "%";
+                numDTO.setPercentStr(percentStr);
+            });
+
+            //降序排序
+            Collections.sort(numDTOList, new Comparator<NumDTO>() {
+                @Override
+                public int compare(NumDTO o1, NumDTO o2) {
+                    return o2.getPercent().compareTo(o1.getPercent());
+                }
+            });
+
+            //top9+其他
+            if (numDTOList.size() <= 10) {
+                retList.addAll(numDTOList);
+            } else {
+                int count = 0;
+                for (NumDTO numDTO : numDTOList) {
+                    if (retList.size() < 10) {
+                        retList.add(numDTO);
+                        count += numDTO.getNum();
+                    } else {
+                        NumDTO otherNumDTO = new NumDTO();
+                        int num = totle - count;
+                        otherNumDTO.setName("其他");
+                        otherNumDTO.setNum(num);
+                        otherNumDTO.setTotleNum(totle);
+                        Double percent = BigDecimal.valueOf(numDTO.getNum())
+                                .divide(BigDecimal.valueOf(totle), 4, RoundingMode.HALF_UP)
+                                .doubleValue();
+                        otherNumDTO.setPercent(percent);
+                        String percentStr
+                                = df.format(BigDecimal.valueOf(percent).multiply(BigDecimal.valueOf(100))) + "%";
+                        otherNumDTO.setPercentStr(percentStr);
+                        retList.add(otherNumDTO);
+                        break;
+                    }
+                }
+            }
+            return retList;
+        }
+        return null;
+    }
 }

+ 6 - 2
src/main/java/com/diagbot/dto/AverageStatisticsDTO.java

@@ -11,9 +11,13 @@ import lombok.Setter;
 @Getter
 @Setter
 public class AverageStatisticsDTO {
-    private String deptId;
-    private String deptName;
+    private String id;
+    private String name;
     private Integer num;
     private Double averageValue;
     private Double totleValue;
+    //环比平均值
+    private Double lastAverageValue;
+    //同比平均值
+    private Double lastYearAverageValue;
 }

+ 41 - 72
src/main/java/com/diagbot/facade/ConsoleFacade.java

@@ -1,6 +1,5 @@
 package com.diagbot.facade;
 
-import com.diagbot.dto.AverageStatisticsDTO;
 import com.diagbot.dto.NumDTO;
 import com.diagbot.exception.CommonErrorCode;
 import com.diagbot.exception.CommonException;
@@ -21,7 +20,6 @@ import java.text.DecimalFormat;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
-import java.util.List;
 import java.util.Map;
 
 /**
@@ -54,8 +52,8 @@ public class ConsoleFacade {
         retMap.put("新生儿人数", 0);
         retMap.put("手术病人数", 0);
         filterVO.setHospitalId(hospitalId);
-        filterVO.setStartDate(getStartDateStr(filterVO.getType()));
-        filterVO.setEndDate(getEndDateStr(filterVO.getType()));
+        filterVO.setStartDate(getStartDateStr(filterVO.getType(), null));
+        filterVO.setEndDate(getEndDateStr(filterVO.getType(), null));
         HomePageFilterVO homePageFilterVO = new HomePageFilterVO();
         BeanUtil.copyProperties(filterVO, homePageFilterVO);
         Integer totleNum = behospitalInfoFacade.homePageCount(homePageFilterVO);
@@ -81,8 +79,8 @@ public class ConsoleFacade {
         DecimalFormat df = new DecimalFormat("#0.00");
         Map<String, Object> retMap = new LinkedHashMap<>();
         String hospitalId = SysUserUtils.getCurrentHospitalID();
-        String startDate = getStartDateStr(filterVO.getType());
-        String endDate = getEndDateStr(filterVO.getType());
+        String startDate = getStartDateStr(filterVO.getType(), null);
+        String endDate = getEndDateStr(filterVO.getType(), null);
         filterVO.setStartDate(startDate);
         filterVO.setEndDate(endDate);
         filterVO.setHospitalId(hospitalId);
@@ -139,7 +137,7 @@ public class ConsoleFacade {
     }
 
     /**
-     * 科室统计
+     * 科室相关统计
      *
      * @param filterVO
      * @return
@@ -149,13 +147,11 @@ public class ConsoleFacade {
         retMap.put("各科室甲级病历占比", Lists.newLinkedList());
         retMap.put("各科室缺陷占比", Lists.newLinkedList());
         String hospitalId = SysUserUtils.getCurrentHospitalID();
-        String startDate = getStartDateStr(filterVO.getType());
-        String endDate = getEndDateStr(filterVO.getType());
+        String startDate = getStartDateStr(filterVO.getType(), null);
+        String endDate = getEndDateStr(filterVO.getType(), null);
         filterVO.setStartDate(startDate);
         filterVO.setEndDate(endDate);
         filterVO.setHospitalId(hospitalId);
-        QcresultFilterVO qcresultFilterVO = new QcresultFilterVO();
-        BeanUtil.copyProperties(filterVO, qcresultFilterVO);
         try {
             Map<String, Object> invokeParams = new HashMap<>();
             invokeParams.put("filterVO", filterVO);
@@ -178,7 +174,7 @@ public class ConsoleFacade {
         retMap.put("各模块缺陷占比排行", Lists.newLinkedList());
         retMap.put("条目缺陷占比", Lists.newLinkedList());
         String hospitalId = SysUserUtils.getCurrentHospitalID();
-        String startDate = getStartDateStr(filterVO.getType());
+        String startDate = getStartDateStr(filterVO.getType(), null);
         filterVO.setStartDate(startDate);
         filterVO.setHospitalId(hospitalId);
         try {
@@ -193,7 +189,7 @@ public class ConsoleFacade {
     }
 
     /**
-     * 医院运营相关统计
+     * 平局值相关统计
      *
      * @param filterVO
      * @return
@@ -202,34 +198,11 @@ public class ConsoleFacade {
         Map<String, Object> retMap = new LinkedHashMap<>();
         retMap.put("平均住院日", Lists.newLinkedList());
         retMap.put("平均住院费用", Lists.newLinkedList());
+        retMap.put("各科室质控平均分", Lists.newLinkedList());
         String hospitalId = SysUserUtils.getCurrentHospitalID();
         filterVO.setHospitalId(hospitalId);
-        String startDate = getStartDateStr(filterVO.getType());
+        String startDate = getStartDateStr(filterVO.getType(), null);
         filterVO.setStartDate(startDate);
-
-        /*
-        List<AverageStatisticsDTO> retAverageDayNumList = Lists.newLinkedList();
-        List<AverageStatisticsDTO> retAverageFeeList = Lists.newLinkedList();
-        List<AverageStatisticsDTO> averageDayNumList = homePageFacade.getAverageDayNum(filterVO);
-        List<AverageStatisticsDTO> averageFeeList = homePageFacade.getAverageFee(filterVO);
-
-        if (filterVO.getLimitCount() == null || filterVO.getLimitCount().equals(0)) {
-            filterVO.setLimitCount(10);
-        }
-        Integer limitCount = filterVO.getLimitCount();
-
-        //平均住院日
-        if (ListUtil.isNotEmpty(averageDayNumList)) {
-            retAverageDayNumList = getLimitAverageList(averageDayNumList, limitCount);
-            retMap.put("平均住院日", retAverageDayNumList);
-        }
-
-        //平均住院费用
-        if (ListUtil.isNotEmpty(averageFeeList)) {
-            retAverageFeeList = getLimitAverageList(averageFeeList, limitCount);
-            retMap.put("平均住院费用", retAverageFeeList);
-        }*/
-
         try {
             Map<String, Object> invokeParams = new HashMap<>();
             invokeParams.put("filterVO", filterVO);
@@ -248,10 +221,10 @@ public class ConsoleFacade {
      * @param type
      * @return
      */
-    public String getStartDateStr(Integer type) {
+    public String getStartDateStr(Integer type, Integer optYear) {
         Date date = new Date();
         String startDate = "";
-        String year = DateUtil.getYear(date);
+        String year = optYear == null ? DateUtil.getYear(date) : optYear.toString();
         int month = DateUtil.getMonth(date);
         if (type.equals(1)) {
             //本月统计
@@ -269,10 +242,10 @@ public class ConsoleFacade {
      * @param type
      * @return
      */
-    public String getEndDateStr(Integer type) {
+    public String getEndDateStr(Integer type, Integer optYear) {
         Date date = new Date();
         String endDate = "";
-        String year = DateUtil.getYear(date);
+        String year = optYear == null ? DateUtil.getYear(date) : optYear.toString();
         int month = DateUtil.getMonth(date);
         if (type.equals(1)) {
             //本月统计
@@ -289,41 +262,37 @@ public class ConsoleFacade {
     }
 
     /**
-     * 根据限制数量重组统计结果
+     * 上一统计周期(上月/去年)的起始时间
      *
-     * @param averageList
-     * @param limitCount
+     * @param type
      * @return
      */
-    public List<AverageStatisticsDTO> getLimitAverageList(List<AverageStatisticsDTO> averageList, Integer limitCount) {
-        List<AverageStatisticsDTO> retAverageList = Lists.newLinkedList();
-        if (averageList.size() < limitCount) {
-            retAverageList = BeanUtil.listCopyTo(averageList, AverageStatisticsDTO.class);
-        } else {
-            if (averageList.size() > limitCount) {
-                retAverageList = averageList.subList(0, limitCount - 1);
-                List<AverageStatisticsDTO> otherList = averageList.subList(limitCount - 1, averageList.size());
-                Double totleValue = otherList
-                        .stream()
-                        .map(i -> BigDecimal.valueOf(i.getTotleValue()))
-                        .reduce(BigDecimal.ZERO, BigDecimal::add).doubleValue();
-                Integer num = otherList
-                        .stream()
-                        .map(AverageStatisticsDTO::getNum)
-                        .reduce(0, Integer::sum);
-                Double averageValue = BigDecimal.valueOf(totleValue)
-                        .divide(BigDecimal.valueOf(num), 2, RoundingMode.HALF_UP)
-                        .doubleValue();
-                AverageStatisticsDTO retAverageStatistics = new AverageStatisticsDTO();
-                retAverageStatistics.setDeptName("其他");
-                retAverageStatistics.setNum(num);
-                retAverageStatistics.setAverageValue(averageValue);
-                retAverageStatistics.setTotleValue(totleValue);
-                retAverageList.add(retAverageStatistics);
+    public String getLastStartDateStr(Integer type) {
+        Date date = new Date();
+        String dateStr = "";
+        String year = DateUtil.getYear(date);
+        int month = DateUtil.getMonth(date);
+        if (type.equals(1)) {
+            if (month == 1) {
+                dateStr = (Integer.valueOf(year) - 1) + "-12-1";
             } else {
-                retAverageList = averageList;
+                dateStr = year + "-" + (month - 1) + "-1";
             }
+        } else if (type.equals(2)) {
+            dateStr = (Integer.valueOf(year) - 1) + "-1-1";
         }
-        return retAverageList;
+        return dateStr;
+    }
+
+    /**
+     * 获取上一统计周期(上月/去年)的起始时间
+     *
+     * @param type
+     * @return
+     */
+    public String getLastEndDateStr(Integer type) {
+        //上一统计周期的截止时间等于本周期的起始时间
+        return getStartDateStr(type, null);
     }
+
 }

+ 17 - 0
src/main/java/com/diagbot/mapper/QcresultInfoMapper.java

@@ -1,6 +1,7 @@
 package com.diagbot.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.diagbot.dto.AverageStatisticsDTO;
 import com.diagbot.dto.NumDTO;
 import com.diagbot.dto.QcResultPercentDTO;
 import com.diagbot.entity.QcresultInfo;
@@ -51,4 +52,20 @@ public interface QcresultInfoMapper extends BaseMapper<QcresultInfo> {
      * @return
      */
     public List<NumDTO> entryCountGroupByCase(FilterVO filterVO);
+
+    /**
+     * 条目缺陷分组统计
+     *
+     * @param filterVO
+     * @return
+     */
+    public List<NumDTO> entryCountGroupByEntry(FilterVO filterVO);
+
+    /**
+     * 质控平均分按科室统计
+     *
+     * @param filterVO
+     * @return
+     */
+    public List<AverageStatisticsDTO> getAverageScoreByDept(FilterVO filterVO);
 }

+ 17 - 0
src/main/java/com/diagbot/service/QcresultInfoService.java

@@ -1,6 +1,7 @@
 package com.diagbot.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.diagbot.dto.AverageStatisticsDTO;
 import com.diagbot.dto.NumDTO;
 import com.diagbot.dto.QcResultPercentDTO;
 import com.diagbot.entity.QcresultInfo;
@@ -52,4 +53,20 @@ public interface QcresultInfoService extends IService<QcresultInfo> {
      * @return
      */
     public List<NumDTO> entryCountGroupByCase(FilterVO filterVO);
+
+    /**
+     * 条目缺陷分组统计
+     *
+     * @param filterVO
+     * @return
+     */
+    public List<NumDTO> entryCountGroupByEntry(FilterVO filterVO);
+
+    /**
+     * 质控平均分按科室统计
+     *
+     * @param filterVO
+     * @return
+     */
+    public List<AverageStatisticsDTO> getAverageScoreByDept(FilterVO filterVO);
 }

+ 23 - 0
src/main/java/com/diagbot/service/impl/QcresultInfoServiceImpl.java

@@ -1,6 +1,7 @@
 package com.diagbot.service.impl;
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.diagbot.dto.AverageStatisticsDTO;
 import com.diagbot.dto.NumDTO;
 import com.diagbot.dto.QcResultPercentDTO;
 import com.diagbot.entity.QcresultInfo;
@@ -68,4 +69,26 @@ public class QcresultInfoServiceImpl extends ServiceImpl<QcresultInfoMapper, Qcr
     public List<NumDTO> entryCountGroupByCase(FilterVO filterVO) {
         return baseMapper.entryCountGroupByCase(filterVO);
     }
+
+    /**
+     * 条目缺陷分组统计
+     *
+     * @param filterVO
+     * @return
+     */
+    @Override
+    public List<NumDTO> entryCountGroupByEntry(FilterVO filterVO) {
+        return baseMapper.entryCountGroupByEntry(filterVO);
+    }
+
+    /**
+     * 质控平均分按科室统计
+     *
+     * @param filterVO
+     * @return
+     */
+    @Override
+    public List<AverageStatisticsDTO> getAverageScoreByDept(FilterVO filterVO) {
+        return baseMapper.getAverageScoreByDept(filterVO);
+    }
 }

+ 1 - 1
src/main/java/com/diagbot/web/ConsoleController.java

@@ -46,7 +46,7 @@ public class ConsoleController {
         return RespDTO.onSuc(data);
     }
 
-    @ApiOperation(value = "医院运营相关统计[by:zhaops]",
+    @ApiOperation(value = "平均值相关统计[by:zhaops]",
             notes = "type: 统计维度 1-本月,2-本年(必填)<br>")
     @PostMapping("/averageStatistics")
     @SysLogger("averageStatistics")

+ 8 - 8
src/main/resources/mapper/HomePageMapper.xml

@@ -141,11 +141,11 @@
     <!-- 按科室统计平均住院天数 -->
     <select id="getAverageDayNum"  parameterType="com.diagbot.vo.FilterVO" resultType="com.diagbot.dto.AverageStatisticsDTO">
         SELECT
-        a.beh_dept_id as deptId,
-        a.beh_dept_name as deptName,
+        a.beh_dept_id as id,
+        a.beh_dept_name as name,
         count(*) AS num,
-        round( sum( b.behospital_day_num )/ count(*), 2 ) AS averageValue,
-        round( sum( b.behospital_day_num ), 2 ) AS totleValue
+        round( sum( CAST(b.behospital_day_num AS DECIMAL ))/ count(*), 2 ) AS averageValue,
+        round( sum( CAST(b.behospital_day_num AS DECIMAL )), 2 ) AS totleValue
         FROM
         med_behospital_info a,
         med_home_page b
@@ -170,11 +170,11 @@
     <!-- 按科室统计平均费用 -->
     <select id="getAverageFee"  parameterType="com.diagbot.vo.FilterVO"  resultType="com.diagbot.dto.AverageStatisticsDTO">
         SELECT
-        a.beh_dept_id as deptId,
-        a.beh_dept_name as deptName,
+        a.beh_dept_id as id,
+        a.beh_dept_name as name,
         count(*) AS num,
-        round( sum( b.total_fee )/ count(*), 2 ) AS averageValue,
-        round( sum( b.total_fee ), 2 ) AS totleValue
+        round( sum( CAST(b.total_fee AS DECIMAL ))/ count(*), 2 ) AS averageValue,
+        round( sum( CAST(b.total_fee AS DECIMAL )), 2 ) AS totleValue
         FROM
         med_behospital_info a,
         med_home_page b

+ 70 - 0
src/main/resources/mapper/QcresultInfoMapper.xml

@@ -157,4 +157,74 @@
         d.cases_id,
         e.`name`
     </select>
+
+    <!-- 条目缺陷分组统计 -->
+    <select id="entryCountGroupByEntry" parameterType="com.diagbot.vo.FilterVO" resultType="com.diagbot.dto.NumDTO">
+        SELECT
+        d.id,
+        d.NAME,
+        count(*) AS num
+        FROM
+        med_behospital_info a,
+        med_home_page b,
+        med_qcresult_detail c,
+        qc_cases_entry d
+        WHERE
+        a.is_deleted = 'N'
+        AND b.is_deleted = 'N'
+        AND c.is_deleted = 'N'
+        AND d.is_deleted = 'N'
+        AND a.hospital_id = b.hospital_id
+        AND a.hospital_id = c.hospital_id
+        AND a.behospital_code = b.behospital_code
+        AND a.behospital_code = c.behospital_code
+        AND c.cases_id = d.cases_id
+        AND c.cases_entry_id = d.id
+        <if test="hospitalId != null and hospitalId != ''">
+            AND a.hospital_id = #{hospitalId}
+        </if>
+        <if test="startDate != null and startDate != ''">
+            <![CDATA[ and a.behospital_date >= DATE(#{startDate})]]>
+        </if>
+        <if test="endDate != null and endDate != ''">
+            <![CDATA[AND a.leave_hospital_date < DATE(#{endDate})]]>
+        </if>
+        GROUP BY
+        d.id,
+        d.NAME
+    </select>
+
+    <!-- 质控平均分按科室统计 -->
+    <select id="getAverageScoreByDept" parameterType="com.diagbot.vo.FilterVO" resultType="com.diagbot.dto.AverageStatisticsDTO">
+        SELECT
+        a.beh_dept_id AS id,
+        a.beh_dept_name AS name,
+        ROUND( sum( CAST( c.score_res AS DECIMAL )), 2 ) AS totleValue,
+        ROUND( sum( CAST( c.score_res AS DECIMAL ))/ count(*), 2 ) AS averageValue,
+        count(*) AS num
+        FROM
+        med_behospital_info a,
+        med_home_page b,
+        med_qcresult_info c
+        WHERE
+        a.is_deleted = 'N'
+        AND b.is_deleted = 'N'
+        AND c.is_deleted = 'N'
+        AND a.hospital_id = b.hospital_id
+        AND a.hospital_id = c.hospital_id
+        AND a.behospital_code = b.behospital_code
+        AND a.behospital_code = c.behospital_code
+        <if test="hospitalId != null and hospitalId != ''">
+            AND a.hospital_id = #{hospitalId}
+        </if>
+        <if test="startDate != null and startDate != ''">
+            <![CDATA[ and a.behospital_date >= DATE(#{startDate})]]>
+        </if>
+        <if test="endDate != null and endDate != ''">
+            <![CDATA[AND a.leave_hospital_date < DATE(#{endDate})]]>
+        </if>
+        GROUP BY
+        a.beh_dept_id,
+        a.beh_dept_name
+    </select>
 </mapper>