فهرست منبع

报表bug fix

wangliang 1 سال پیش
والد
کامیت
a0d19f3eeb

+ 5 - 6
sop-business/src/main/java/com/qmth/sop/business/mapper/SopAnalyseMapper.java

@@ -16,21 +16,20 @@ import java.util.Map;
  * </p>
  *
  * @author dhshu
- *
  */
 public interface SopAnalyseMapper extends BaseMapper<TBSopInfo> {
 
+    List<TBService> list(@Param("startTime") Long startTime, @Param("endTime") Long endTime,
+            @Param("dpr") DataPermissionDto dpr);
 
-    List<TBService> list(@Param("startTime") Long startTime, @Param("endTime") Long endTime, @Param("dpr") DataPermissionDto dpr);
-
-    List<Map<String, Object>> overview(@Param("serviceId") Long serviceId);
+    List<Map<String, Object>> overview(@Param("serviceId") Long serviceId, @Param("type") String type);
 
     List<Map<String, Object>> trend(@Param("serviceId") Long serviceId);
 
-    List<Map<String, Object>> attendance(@Param("serviceId") Long serviceId);
+    List<Map<String, Object>> attendance(@Param("serviceId") Long serviceId, @Param("type") String type);
 
     /**
-     * 根据服务单元id查询sop监控数据集
+s     * 根据服务单元id查询sop监控数据集
      *
      * @param serviceId 服务单元id
      * @return 监控数据集

+ 203 - 146
sop-business/src/main/java/com/qmth/sop/business/service/impl/SopAnalyseServiceImpl.java

@@ -27,17 +27,17 @@ import java.util.stream.Collectors;
 
 @Service
 public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopInfo> implements SopAnalyseService {
+
     @Resource
     private SysUserService sysUserService;
 
     @Override
-    public List<TBService> list(Long startTime,Long endTime) {
+    public List<TBService> list(Long startTime, Long endTime) {
         SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
         DataPermissionDto dpr = sysUserService.buildUserDataPermission(requestUser.getId());
-        return this.baseMapper.list(startTime,endTime,dpr);
+        return this.baseMapper.list(startTime, endTime, dpr);
     }
 
-
     /**
      * * ①可按照大区/人力供应商进行切换如图;
      * * ②按照派单数TOP3的大区、人力供应商显示;
@@ -47,24 +47,27 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
     @Deprecated
     @Override
     public List<Map<String, Object>> overview1(Long serviceId, SopAnalyseGroupEnum group) {
-        List<Map<String, Object>> list = this.baseMapper.overview(serviceId);
+        List<Map<String, Object>> list = this.baseMapper.overview(serviceId, group.name());
         List<Map<String, Object>> result = new ArrayList<>();
         if (group.equals(SopAnalyseGroupEnum.REGION)) {
-            list.stream().filter(map->map.get("region_name")!=null).collect(Collectors.groupingBy(map -> map.get("region_name"))).forEach((k, v) -> {
-                Map<String, Object> map = new HashMap<>();
-                map.put("region_name", k);
-                processOverviewData(v, map);
-                result.add(map);
-            });
+            list.stream().filter(map -> map.get("region_name") != null)
+                    .collect(Collectors.groupingBy(map -> map.get("region_name"))).forEach((k, v) -> {
+                        Map<String, Object> map = new HashMap<>();
+                        map.put("region_name", k);
+                        processOverviewData(v, map);
+                        result.add(map);
+                    });
         } else if (group.equals(SopAnalyseGroupEnum.SUPPLIER)) {
-            list.stream().filter(map -> map.get("supplier")!=null).collect(Collectors.groupingBy(map -> map.get("supplier"))).forEach((k, v) -> {
-                Map<String, Object> map = new HashMap<>();
-                map.put("supplier", k);
-                processOverviewData(v, map);
-                result.add(map);
-            });
+            list.stream().filter(map -> map.get("supplier") != null)
+                    .collect(Collectors.groupingBy(map -> map.get("supplier"))).forEach((k, v) -> {
+                        Map<String, Object> map = new HashMap<>();
+                        map.put("supplier", k);
+                        processOverviewData(v, map);
+                        result.add(map);
+                    });
         }
-        return result.stream().sorted(Comparator.comparingInt(o -> Integer.parseInt(o.get("crmNum").toString()))).limit(3).collect(Collectors.toList());
+        return result.stream().sorted(Comparator.comparingInt(o -> Integer.parseInt(o.get("crmNum").toString())))
+                .limit(3).collect(Collectors.toList());
     }
 
     /**
@@ -78,34 +81,40 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
         List<SopMonitor> sopMonitorList = this.baseMapper.findSopMonitorListByServiceId(serviceId);
         List<SopWarnOverview> result = new ArrayList<>();
         switch (group) {
-            case REGION:
-                Set<Long> regionIdSet = sopMonitorList.stream().filter(e -> e.getRegionId() != null && e.getRegionId() > 0).map(SopMonitor::getRegionId).collect(Collectors.toSet());
-                for (Long regionId : regionIdSet) {
-                    List<SopMonitor> dataCell = sopMonitorList.stream().filter(e -> regionId.equals(e.getRegionId())).collect(Collectors.toList());
-                    String regionName = dataCell.get(0).getRegionName();
-                    SopWarnOverview regionOverview = buildSopOverviewStatistic(dataCell);
-                    regionOverview.setRegionId(regionId);
-                    regionOverview.setRegionName(regionName);
-                    result.add(regionOverview);
-                }
-                break;
-            case SUPPLIER:
-                // 由大区经理兼任不显示
-                Set<Long> supplierIdSet = sopMonitorList.stream().filter(e -> e.getSupplierId() != null && e.getSupplierId() > 0).map(SopMonitor::getSupplierId).collect(Collectors.toSet());
-                for (Long supplierId : supplierIdSet) {
-                    List<SopMonitor> dataCell = sopMonitorList.stream().filter(e -> supplierId.equals(e.getSupplierId())).collect(Collectors.toList());
-                    SopWarnOverview supplierOverview = buildSopOverviewStatistic(dataCell);
-                    supplierOverview.setSupplierName(dataCell.get(0).getSupplierName());
-                    supplierOverview.setSupplierId(supplierId);
-                    result.add(supplierOverview);
-                }
-                break;
+        case REGION:
+            Set<Long> regionIdSet = sopMonitorList.stream().filter(e -> e.getRegionId() != null && e.getRegionId() > 0)
+                    .map(SopMonitor::getRegionId).collect(Collectors.toSet());
+            for (Long regionId : regionIdSet) {
+                List<SopMonitor> dataCell = sopMonitorList.stream().filter(e -> regionId.equals(e.getRegionId()))
+                        .collect(Collectors.toList());
+                String regionName = dataCell.get(0).getRegionName();
+                SopWarnOverview regionOverview = buildSopOverviewStatistic(dataCell);
+                regionOverview.setRegionId(regionId);
+                regionOverview.setRegionName(regionName);
+                result.add(regionOverview);
+            }
+            break;
+        case SUPPLIER:
+            // 由大区经理兼任不显示
+            Set<Long> supplierIdSet = sopMonitorList.stream()
+                    .filter(e -> e.getSupplierId() != null && e.getSupplierId() > 0).map(SopMonitor::getSupplierId)
+                    .collect(Collectors.toSet());
+            for (Long supplierId : supplierIdSet) {
+                List<SopMonitor> dataCell = sopMonitorList.stream().filter(e -> supplierId.equals(e.getSupplierId()))
+                        .collect(Collectors.toList());
+                SopWarnOverview supplierOverview = buildSopOverviewStatistic(dataCell);
+                supplierOverview.setSupplierName(dataCell.get(0).getSupplierName());
+                supplierOverview.setSupplierId(supplierId);
+                result.add(supplierOverview);
+            }
+            break;
         }
         return result;
     }
 
     /**
      * 创建sop监控统计
+     *
      * @param dataCell 数据集
      * @return sop监控
      */
@@ -113,7 +122,8 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
         SopWarnOverview sopWarnOverview = new SopWarnOverview();
         if (CollectionUtils.isNotEmpty(dataCell)) {
             int crmNum = (int) dataCell.stream().map(SopMonitor::getCrmNo).distinct().count();
-            int finishCrmNum = (int) (crmNum - dataCell.stream().filter(e -> !e.getFinishStatus()).map(SopMonitor::getCrmNo).distinct().count());
+            int finishCrmNum = (int) (crmNum - dataCell.stream().filter(e -> !e.getFinishStatus())
+                    .map(SopMonitor::getCrmNo).distinct().count());
             int effectAvgTimeCount = 0;
             long effectTotalMinutes = 0L;
             int violationNum = 0;
@@ -124,15 +134,14 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
             for (SopMonitor sopMonitor : dataCell) {
                 SopMonitorEnum sopMonitorType = sopMonitor.getSopMonitorType();
                 switch (sopMonitorType) {
-                    case DELAY_WARN:
-                        delayNum++;
-                        break;
-                    case VIOLATION:
-                        violationNum++;
-                        break;
+                case DELAY_WARN:
+                    delayNum++;
+                    break;
+                case VIOLATION:
+                    violationNum++;
+                    break;
                 }
 
-
                 Boolean finishStatus = sopMonitor.getFinishStatus();
                 if (finishStatus) {
                     Long startTime = sopMonitor.getStartTime();
@@ -144,12 +153,12 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
                     }
 
                     switch (sopMonitorType) {
-                        case DELAY_WARN:
-                            finishDelayNum++;
-                            break;
-                        case VIOLATION:
-                            finishViolationNum++;
-                            break;
+                    case DELAY_WARN:
+                        finishDelayNum++;
+                        break;
+                    case VIOLATION:
+                        finishViolationNum++;
+                        break;
                     }
                 }
             }
@@ -158,7 +167,8 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
             sopWarnOverview.setFinishCrmNum(finishCrmNum);
             BigDecimal avgMinutes = new BigDecimal(0);
             if (effectAvgTimeCount > 0) {
-                avgMinutes = new BigDecimal(effectTotalMinutes).divide(new BigDecimal(effectAvgTimeCount), 2, RoundingMode.HALF_UP);
+                avgMinutes = new BigDecimal(effectTotalMinutes).divide(new BigDecimal(effectAvgTimeCount), 2,
+                        RoundingMode.HALF_UP);
             }
             sopWarnOverview.setAvgMinutes(avgMinutes);
             sopWarnOverview.setViolationNum(violationNum);
@@ -169,26 +179,38 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
         return sopWarnOverview;
     }
 
-
     private static void processOverviewData(List<Map<String, Object>> v, Map<String, Object> map) {
         //派单数
         map.put("crmNum", v.stream().collect(Collectors.groupingBy(map1 -> map1.get("crm_no"))).size());
         //已完成派单数
-        map.put("finishCrmNum", v.stream().collect(Collectors.groupingBy(map1 -> map1.get("crm_no"))).values().stream().filter(list1 -> list1.stream().allMatch(map1 -> "FINISH".equals(map1.get("sopStatus"))) || list1.stream().allMatch(map1 -> "FINISH".equals(map1.get("status")))).count());
+        map.put("finishCrmNum", v.stream().collect(Collectors.groupingBy(map1 -> map1.get("crm_no"))).values().stream()
+                .filter(list1 -> list1.stream().allMatch(map1 -> "FINISH".equals(map1.get("sopStatus")))
+                        || list1.stream().allMatch(map1 -> "FINISH".equals(map1.get("status")))).count());
         //违规数
-        map.put("violationNum", v.stream().filter(map1 -> map1.get("vid") != null).collect(Collectors.groupingBy(map1 -> map1.get("vid"))).size());
+        map.put("violationNum", v.stream().filter(map1 -> map1.get("vid") != null)
+                .collect(Collectors.groupingBy(map1 -> map1.get("vid"))).size());
         //已关闭违规数
-        map.put("finishViolationNum", v.stream().filter(map1 -> map1.get("vid") != null && "CLOSE".equals(map1.get("vstatus"))).collect(Collectors.groupingBy(map1 -> map1.get("vid"))).size());
+        map.put("finishViolationNum",
+                v.stream().filter(map1 -> map1.get("vid") != null && "CLOSE".equals(map1.get("vstatus")))
+                        .collect(Collectors.groupingBy(map1 -> map1.get("vid"))).size());
         //延期数
-        map.put("delayNum", v.stream().filter(map1 -> map1.get("did") != null).collect(Collectors.groupingBy(map1 -> map1.get("did"))).size());
+        map.put("delayNum", v.stream().filter(map1 -> map1.get("did") != null)
+                .collect(Collectors.groupingBy(map1 -> map1.get("did"))).size());
         //已关闭延期数
-        map.put("finishDelayNum", v.stream().filter(map1 -> map1.get("did") != null && "CLOSE".equals(map1.get("dstatus"))).collect(Collectors.groupingBy(map1 -> map1.get("vid"))).size());
-        Double processViolationTime = v.stream().filter(map1 -> map1.get("vdiff") != null).mapToDouble(map1 -> Double.parseDouble(map1.get("vdiff").toString())).sum();
-        Double processDelayTime = v.stream().filter(map1 -> map1.get("ddiff") != null).mapToDouble(map1 -> Double.parseDouble(map1.get("ddiff").toString())).sum();
+        map.put("finishDelayNum",
+                v.stream().filter(map1 -> map1.get("did") != null && "CLOSE".equals(map1.get("dstatus")))
+                        .collect(Collectors.groupingBy(map1 -> map1.get("vid"))).size());
+        Double processViolationTime = v.stream().filter(map1 -> map1.get("vdiff") != null)
+                .mapToDouble(map1 -> Double.parseDouble(map1.get("vdiff").toString())).sum();
+        Double processDelayTime = v.stream().filter(map1 -> map1.get("ddiff") != null)
+                .mapToDouble(map1 -> Double.parseDouble(map1.get("ddiff").toString())).sum();
         //平均处理时限分钟
-        int total = (Integer.parseInt(map.get("finishViolationNum").toString()) + Integer.parseInt(map.get("finishDelayNum").toString()));
-        map.put("avgMinutes", total == 0 ? 0 : new BigDecimal(processViolationTime + processDelayTime).divide(new BigDecimal(total), 2, RoundingMode.HALF_UP));
-
+        int total = (Integer.parseInt(map.get("finishViolationNum").toString()) + Integer.parseInt(
+                map.get("finishDelayNum").toString()));
+        map.put("avgMinutes", total == 0 ?
+                0 :
+                new BigDecimal(processViolationTime + processDelayTime).divide(new BigDecimal(total), 2,
+                        RoundingMode.HALF_UP));
 
     }
 
@@ -208,40 +230,49 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
     @Override
     public List<Map<String, Object>> processing(Long serviceId, SopAnalyseGroupEnum group, SopAnalyseSortEnum sort) {
         List<Map<String, Object>> result = new ArrayList<>();
-        List<Map<String, Object>> list = this.baseMapper.overview(serviceId);
+        List<Map<String, Object>> list = this.baseMapper.overview(serviceId, group.name());
         if (group.equals(SopAnalyseGroupEnum.CRM)) {
-            list.stream().filter(map->map.get("name")!=null).collect(Collectors.groupingBy(map -> map.get("name"))).forEach((k, v) -> {
-                Map<String, Object> map = new HashMap<>();
-                map.put("crmName", k);
-                //大区
-                map.put("region_name", v.get(0).get("region_name"));
-                processing(v, map);
-                result.add(map);
-            });
+            list.stream().filter(map -> map.get("name") != null).collect(Collectors.groupingBy(map -> map.get("name")))
+                    .forEach((k, v) -> {
+                        Map<String, Object> map = new HashMap<>();
+                        map.put("crmName", k);
+                        //大区
+                        map.put("region_name", v.get(0).get("region_name"));
+                        processing(v, map);
+                        result.add(map);
+                    });
         } else if (group.equals(SopAnalyseGroupEnum.REGION)) {
-            list.stream().filter(map->map.get("region_name")!=null).collect(Collectors.groupingBy(map -> map.get("region_name"))).forEach((k, v) -> {
-                Map<String, Object> map = new HashMap<>();
-                map.put("region_name", k);
-                processing(v, map);
-                result.add(map);
-            });
+            list.stream().filter(map -> map.get("region_name") != null)
+                    .collect(Collectors.groupingBy(map -> map.get("region_name"))).forEach((k, v) -> {
+                        Map<String, Object> map = new HashMap<>();
+                        map.put("region_name", k);
+                        processing(v, map);
+                        result.add(map);
+                    });
         } else if (group.equals(SopAnalyseGroupEnum.SUPPLIER)) {
-            list.stream().filter(map->map.get("supplier")!=null).collect(Collectors.groupingBy(map -> map.get("supplier"))).forEach((k, v) -> {
-                Map<String, Object> map = new HashMap<>();
-                map.put("supplier", k);
-                //大区
-                map.put("region_name", v.get(0).get("region_name"));
-                processing(v, map);
-                result.add(map);
-            });
+            list.stream().filter(map -> map.get("supplier") != null)
+                    .collect(Collectors.groupingBy(map -> map.get("supplier"))).forEach((k, v) -> {
+                        Map<String, Object> map = new HashMap<>();
+                        map.put("supplier", k);
+                        //大区
+                        map.put("region_name", v.get(0).get("region_name"));
+                        processing(v, map);
+                        result.add(map);
+                    });
         }
 
         if (sort.equals(SopAnalyseSortEnum.PENDING)) {
-            return result.stream().sorted(Comparator.comparingInt(o -> -Integer.parseInt(o.get("pendingProcessing").toString()))).limit(10).collect(Collectors.toList());
+            return result.stream()
+                    .sorted(Comparator.comparingInt(o -> -Integer.parseInt(o.get("pendingProcessing").toString())))
+                    .limit(10).collect(Collectors.toList());
         } else if (sort.equals(SopAnalyseSortEnum.SLOWEST)) {
-            return result.stream().sorted(Comparator.comparingDouble(o -> -Double.parseDouble(o.get("avgMinutes").toString()))).limit(10).collect(Collectors.toList());
+            return result.stream()
+                    .sorted(Comparator.comparingDouble(o -> -Double.parseDouble(o.get("avgMinutes").toString())))
+                    .limit(10).collect(Collectors.toList());
         } else if (sort.equals(SopAnalyseSortEnum.FASTEST)) {
-            return result.stream().sorted(Comparator.comparingDouble(o -> Double.parseDouble(o.get("avgMinutes").toString()))).limit(10).collect(Collectors.toList());
+            return result.stream()
+                    .sorted(Comparator.comparingDouble(o -> Double.parseDouble(o.get("avgMinutes").toString())))
+                    .limit(10).collect(Collectors.toList());
         }
         return null;
 
@@ -251,22 +282,33 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
         //区域协调人
         map.put("real_name", v.get(0).get("real_name"));
         //违规数
-        Integer violationNum = v.stream().filter(map1 -> map1.get("did") != null).collect(Collectors.groupingBy(map1 -> map1.get("did"))).size();
+        Integer violationNum = v.stream().filter(map1 -> map1.get("did") != null)
+                .collect(Collectors.groupingBy(map1 -> map1.get("did"))).size();
         //已关闭违规数
-        Long finishViolationNum = v.stream().filter(map1 -> map1.get("did") != null && "CLOSE".equals(map1.get("dstatus"))).count();
+        Long finishViolationNum = v.stream()
+                .filter(map1 -> map1.get("did") != null && "CLOSE".equals(map1.get("dstatus"))).count();
         //延期数
-        Integer delayNum = v.stream().filter(map1 -> map1.get("vid") != null).collect(Collectors.groupingBy(map1 -> map1.get("vid"))).size();
+        Integer delayNum = v.stream().filter(map1 -> map1.get("vid") != null)
+                .collect(Collectors.groupingBy(map1 -> map1.get("vid"))).size();
         //已关闭延期数
-        Long finishDelayNum = v.stream().filter(map1 -> map1.get("vid") != null && "CLOSE".equals(map1.get("vstatus"))).count();
-        Double processViolationTime = v.stream().filter(map1 -> map1.get("ddiff") != null).mapToDouble(map1 -> Double.parseDouble(map1.get("ddiff").toString())).sum();
-        Double processDelayTime = v.stream().filter(map1 -> map1.get("vdiff") != null).mapToDouble(map1 -> Double.parseDouble(map1.get("vdiff").toString())).sum();
+        Long finishDelayNum = v.stream().filter(map1 -> map1.get("vid") != null && "CLOSE".equals(map1.get("vstatus")))
+                .count();
+        Double processViolationTime = v.stream().filter(map1 -> map1.get("ddiff") != null)
+                .mapToDouble(map1 -> Double.parseDouble(map1.get("ddiff").toString())).sum();
+        Double processDelayTime = v.stream().filter(map1 -> map1.get("vdiff") != null)
+                .mapToDouble(map1 -> Double.parseDouble(map1.get("vdiff").toString())).sum();
         //平均处理时限分钟
         long total = finishViolationNum + finishDelayNum;
-        map.put("avgMinutes", total == 0 ? 0 : new BigDecimal(processViolationTime + processDelayTime).divide(new BigDecimal(total), 2, RoundingMode.HALF_UP));
+        map.put("avgMinutes", total == 0 ?
+                0 :
+                new BigDecimal(processViolationTime + processDelayTime).divide(new BigDecimal(total), 2,
+                        RoundingMode.HALF_UP));
         //待处理总数数
         map.put("pendingProcessing", violationNum + delayNum - total);
         //预警均值
-        map.put("avgWarn", new BigDecimal(violationNum + delayNum).divide(new BigDecimal(v.stream().collect(Collectors.groupingBy(map1 -> map1.get("crm_no"))).size()), 2, RoundingMode.HALF_UP));
+        map.put("avgWarn", new BigDecimal(violationNum + delayNum).divide(
+                new BigDecimal(v.stream().collect(Collectors.groupingBy(map1 -> map1.get("crm_no"))).size()), 2,
+                RoundingMode.HALF_UP));
     }
 
     /*
@@ -276,10 +318,11 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
     @Override
     public Map<Object, List<Map<String, Object>>> trend1(Long serviceId) {
         List<Map<String, Object>> list = this.baseMapper.trend(serviceId);
-//        Map<Object, List<Map<String, Object>>> collect1 = list.stream().collect(Collectors.groupingBy(map -> map.get("click_date")));
-//        Map<Object, Map<Object, List<Map<String, Object>>>> collect = new HashMap<>();
-//        collect1.forEach((k, v) -> collect.put(k,v.stream().filter(map -> map.get("supplier") != null).collect(Collectors.groupingBy(map1 -> map1.get("supplier")))));
-        return list.stream().filter(map -> map.get("supplier") != null).collect(Collectors.groupingBy(map1 -> map1.get("supplier")));
+        //        Map<Object, List<Map<String, Object>>> collect1 = list.stream().collect(Collectors.groupingBy(map -> map.get("click_date")));
+        //        Map<Object, Map<Object, List<Map<String, Object>>>> collect = new HashMap<>();
+        //        collect1.forEach((k, v) -> collect.put(k,v.stream().filter(map -> map.get("supplier") != null).collect(Collectors.groupingBy(map1 -> map1.get("supplier")))));
+        return list.stream().filter(map -> map.get("supplier") != null)
+                .collect(Collectors.groupingBy(map1 -> map1.get("supplier")));
 
     }
 
@@ -290,7 +333,8 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
      */
     @Override
     public List<SopSupplierAvgViewTimes> trend(Long serviceId) {
-        List<CrmSupplierRelation> crmSupplierRelationList = this.baseMapper.findCrmSupplierRelationByServiceId(serviceId);
+        List<CrmSupplierRelation> crmSupplierRelationList = this.baseMapper.findCrmSupplierRelationByServiceId(
+                serviceId);
         Map<Long, Set<String>> supplierCrmNumMap = new HashMap<>();
         for (CrmSupplierRelation crmSupplierRelation : crmSupplierRelationList) {
             String crmNo = crmSupplierRelation.getCrmNo();
@@ -304,7 +348,6 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
             }
         }
 
-
         List<SopMonitor> sopMonitorList = this.baseMapper.findSopMonitorListByServiceId(serviceId);
         Date date = new Date();
         List<Long> times = new ArrayList<>();
@@ -325,25 +368,24 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
         List<SopSupplierAvgViewTimes> result = new ArrayList<>();
         for (Long time : times) {
             // 当天之前的预警(大区经理兼任的不算)
-            List<SopMonitor> monitorTimeCell = sopMonitorList
-                    .stream()
-                    .filter(e -> !e.getFinishStatus() && e.getStartTime() < time && e.getSupplierId() != null && e.getSupplierId() > 0)
-                    .collect(Collectors.toList());
+            List<SopMonitor> monitorTimeCell = sopMonitorList.stream()
+                    .filter(e -> !e.getFinishStatus() && e.getStartTime() < time && e.getSupplierId() != null
+                            && e.getSupplierId() > 0).collect(Collectors.toList());
 
-            List<Long> supplierIdList = monitorTimeCell.stream().map(SopMonitor::getSupplierId).distinct().collect(Collectors.toList());
+            List<Long> supplierIdList = monitorTimeCell.stream().map(SopMonitor::getSupplierId).distinct()
+                    .collect(Collectors.toList());
             List<SopSupplierAvgView> sopSupplierAvgViewList = new ArrayList<>();
             for (Long supplierId : supplierIdList) {
-                List<SopMonitor> monitorSupplierCell = monitorTimeCell
-                        .stream()
-                        .filter(e -> e.getSupplierId().equals(supplierId))
-                        .collect(Collectors.toList());
+                List<SopMonitor> monitorSupplierCell = monitorTimeCell.stream()
+                        .filter(e -> e.getSupplierId().equals(supplierId)).collect(Collectors.toList());
 
                 if (CollectionUtils.isNotEmpty(monitorSupplierCell)) {
                     String supplierName = monitorSupplierCell.get(0).getSupplierName();
                     int warnCount = monitorSupplierCell.size();
                     if (supplierCrmNumMap.containsKey(supplierId)) {
                         int crmCount = supplierCrmNumMap.get(supplierId).size();
-                        BigDecimal rate = new BigDecimal(warnCount).divide(new BigDecimal(crmCount), 2, RoundingMode.HALF_UP);
+                        BigDecimal rate = new BigDecimal(warnCount).divide(new BigDecimal(crmCount), 2,
+                                RoundingMode.HALF_UP);
 
                         SopSupplierAvgView sopSupplierAvgView = new SopSupplierAvgView();
                         sopSupplierAvgView.setSupplierId(supplierId);
@@ -369,11 +411,13 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
             // 补零
             for (SopSupplierAvgViewTimes supplierAvgViewTimes : result) {
                 List<SopSupplierAvgView> list = supplierAvgViewTimes.getSopSupplierAvgViewInfo();
-                if (CollectionUtils.isEmpty(list)){
+                if (CollectionUtils.isEmpty(list)) {
                     list = new ArrayList<>();
                 }
-                List<Long> alreadyUsedSupplierIdList = list.stream().map(SopSupplierAvgView::getSupplierId).collect(Collectors.toList());
-                List<Long> needFillIdList = supplierInfoMap.keySet().stream().filter(k -> !alreadyUsedSupplierIdList.contains(k)).collect(Collectors.toList());
+                List<Long> alreadyUsedSupplierIdList = list.stream().map(SopSupplierAvgView::getSupplierId)
+                        .collect(Collectors.toList());
+                List<Long> needFillIdList = supplierInfoMap.keySet().stream()
+                        .filter(k -> !alreadyUsedSupplierIdList.contains(k)).collect(Collectors.toList());
                 for (Long supplierId : needFillIdList) {
                     SopSupplierAvgView view = new SopSupplierAvgView();
                     view.setRate(new BigDecimal(0));
@@ -394,41 +438,54 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
     @Override
     public List<Map<String, Object>> attendance(Long serviceId, SopAnalyseGroupEnum group) {
         List<Map<String, Object>> result = new ArrayList<>();
-        List<Map<String, Object>> attendance = this.baseMapper.attendance(serviceId);
+        List<Map<String, Object>> attendance = this.baseMapper.attendance(serviceId, group.name());
         if (group.equals(SopAnalyseGroupEnum.CRM)) {
-            attendance.stream().filter(map -> map.get("name")!=null).collect(Collectors.groupingBy(map -> map.get("name"))).forEach((k, v) -> v.stream().filter(map -> map.get("dname")!=null).collect(Collectors.groupingBy(map -> map.get("dname"))).forEach((x, y)->{
-                Map<String, Object> map = new HashMap<>();
-                map.put("crmName", k);
-                map.put("dname", x);
-                map.put("real_name", v.get(0).get("real_name"));
-                map.put("total", y.stream().filter(map1 -> map1.get("id") != null).count());
-                result.add(map);
-            }));
-
+            attendance.stream().filter(map -> map.get("name") != null)
+                    .collect(Collectors.groupingBy(map -> map.get("name"))).forEach(
+                            (k, v) -> v.stream().filter(map -> map.get("dname") != null)
+                                    .collect(Collectors.groupingBy(map -> map.get("dname"))).forEach((x, y) -> {
+                                        Map<String, Object> map = new HashMap<>();
+                                        map.put("crmName", k);
+                                        map.put("dname", x);
+                                        map.put("real_name", v.get(0).get("real_name"));
+                                        map.put("total", y.stream().filter(map1 -> map1.get("id") != null).count());
+                                        result.add(map);
+                                    }));
 
         } else if (group.equals(SopAnalyseGroupEnum.REGION)) {
-            attendance.stream().filter(map -> map.get("region_name")!=null).collect(Collectors.groupingBy(map -> map.get("region_name"))).forEach((k, v) -> {
-                Map<String, Object> map = new HashMap<>();
-                map.put("region_name", k);
-                map.put("real_name", v.get(0).get("real_name"));
-                long total = v.stream().filter(map1 -> map1.get("id") != null).count();
-                map.put("total", total);
-                map.put("avg", Double.parseDouble(total+"")/v.stream().collect(Collectors.groupingBy(map1 -> map1.get("crm_no"))).size());
-                result.add(map);
-            });
+            attendance.stream().filter(map -> map.get("region_name") != null)
+                    .collect(Collectors.groupingBy(map -> map.get("region_name"))).forEach((k, v) -> {
+                        Map<String, Object> map = new HashMap<>();
+                        map.put("region_name", k);
+                        map.put("real_name", v.get(0).get("real_name"));
+                        long total = v.stream().filter(map1 -> map1.get("id") != null).count();
+                        map.put("total", total);
+                        map.put("avg", total == 0 ?
+                                0 :
+                                new BigDecimal(total).divide(new BigDecimal(
+                                                v.stream().collect(Collectors.groupingBy(map1 -> map1.get("crm_no"))).size()), 2,
+                                        RoundingMode.HALF_UP));
+                        result.add(map);
+                    });
 
         } else if (group.equals(SopAnalyseGroupEnum.SUPPLIER)) {
-            attendance.stream().filter(map -> map.get("supplier")!=null).collect(Collectors.groupingBy(map -> map.get("supplier"))).forEach((k, v) -> {
-                Map<String, Object> map = new HashMap<>();
-                map.put("supplier", k);
-                long total = v.stream().filter(map1 -> map1.get("id") != null).count();
-                map.put("total",total);
-                map.put("avg", Double.parseDouble(total+"")/v.stream().collect(Collectors.groupingBy(map1 -> map1.get("crm_no"))).size());
-                result.add(map);
-            });
+            attendance.stream().filter(map -> map.get("supplier") != null)
+                    .collect(Collectors.groupingBy(map -> map.get("supplier"))).forEach((k, v) -> {
+                        Map<String, Object> map = new HashMap<>();
+                        map.put("supplier", k);
+                        long total = v.stream().filter(map1 -> map1.get("id") != null).count();
+                        map.put("total", total);
+                        map.put("avg", total == 0 ?
+                                0 :
+                                new BigDecimal(total).divide(new BigDecimal(
+                                                v.stream().collect(Collectors.groupingBy(map1 -> map1.get("crm_no"))).size()), 2,
+                                        RoundingMode.HALF_UP));
+                        result.add(map);
+                    });
 
         }
-        return result.stream().sorted(Comparator.comparingInt(o -> -Integer.parseInt(o.get("total").toString()))).limit(10).collect(Collectors.toList());
+        return result.stream().sorted(Comparator.comparingInt(o -> -Integer.parseInt(o.get("total").toString())))
+                .limit(10).collect(Collectors.toList());
     }
 
 }

+ 22 - 5
sop-business/src/main/resources/mapper/SopAnalyseMapper.xml

@@ -23,6 +23,7 @@
         </where>
         order by s.start_time desc
     </select>
+
     <select id="overview" resultType="java.util.Map">
         SELECT
         r.region_name,
@@ -46,7 +47,16 @@
         LEFT join t_f_custom_flow_entity tfcfe on tfcfe.code = s.sop_no
         LEFT join t_f_flow_approve tffa on tffa.flow_id = tfcfe.flow_id
         LEFT JOIN t_b_sop_info_detail sd ON sd.sop_info_id = s.id
-        LEFT JOIN sys_user u ON u.id = c.lead_id
+        <if test="type != null and type != ''">
+            <choose>
+                <when test="type == 'CRM' or type == 'SUPPLIER'">
+                    LEFT JOIN sys_user u ON u.id = c.region_coordinator_id
+                </when>
+                <otherwise>
+                    LEFT JOIN sys_user u ON u.id = c.lead_id
+                </otherwise>
+            </choose>
+        </if>
         LEFT JOIN t_b_user_archives ua ON ua.mobile_number = u.mobile_number
         LEFT JOIN t_b_user_archives_supplier us ON us.user_archives_id = ua.id
         LEFT JOIN sys_supplier su ON su.id = us.supplier_id
@@ -124,26 +134,33 @@
         s.sop_no,
         d.id,
         du.real_name dname
-
         FROM
         t_b_sop_info s
         left join t_b_crm c on c.crm_no=s.crm_no
         left join t_b_service_region r on r.id=c.region_id
         LEFT JOIN t_b_sop_info_detail sd ON sd.sop_info_id = s.id
-        LEFT JOIN sys_user u ON u.id = c.region_coordinator_id
+        <if test="type != null and type != ''">
+            <choose>
+                <when test="type == 'CRM' or type == 'SUPPLIER'">
+                    LEFT JOIN sys_user u ON u.id = c.region_coordinator_id
+                </when>
+                <otherwise>
+                    LEFT JOIN sys_user u ON u.id = c.lead_id
+                </otherwise>
+            </choose>
+        </if>
         LEFT JOIN t_b_user_archives ua ON ua.mobile_number = u.mobile_number
         LEFT JOIN t_b_user_archives_supplier us ON us.user_archives_id = ua.id
         LEFT JOIN sys_supplier su ON su.id = us.supplier_id
         left join t_b_ding_apply d on d.sop_no=s.sop_no
         left join sys_user du on du.id=d.create_id
         <where>
-
             <if test="serviceId != null and serviceId != ''">
                 and  s.service_id= #{serviceId}
             </if>
-
         </where>
     </select>
+
     <select id="findSopMonitorListByServiceId"
             resultType="com.qmth.sop.business.bean.result.analyze.sopWarn.SopMonitor">
         SELECT