haogh 9 місяців тому
батько
коміт
fcb6d5c215
16 змінених файлів з 324 додано та 241 видалено
  1. 4 2
      sop-api/src/main/java/com/qmth/sop/server/api/ServiceUnitAnalyseController.java
  2. 16 1
      sop-api/src/main/java/com/qmth/sop/server/api/SopWarnMonitorController.java
  3. 12 0
      sop-business/src/main/java/com/qmth/sop/business/bean/result/ProjectMonitorResult.java
  4. 8 19
      sop-business/src/main/java/com/qmth/sop/business/bean/result/SopInfoExportResult.java
  5. 19 0
      sop-business/src/main/java/com/qmth/sop/business/bean/result/SopProcessExportResult.java
  6. 19 0
      sop-business/src/main/java/com/qmth/sop/business/bean/result/SopWarnExportResult.java
  7. 44 0
      sop-business/src/main/java/com/qmth/sop/business/bean/result/SopWarnMonitorDetailResult.java
  8. 4 3
      sop-business/src/main/java/com/qmth/sop/business/mapper/ServiceUnitAnalyseMapper.java
  9. 4 0
      sop-business/src/main/java/com/qmth/sop/business/mapper/SopWarnMonitorMapper.java
  10. 1 1
      sop-business/src/main/java/com/qmth/sop/business/service/ServiceUnitAnalyseService.java
  11. 2 1
      sop-business/src/main/java/com/qmth/sop/business/service/SopWarnMonitorService.java
  12. 24 10
      sop-business/src/main/java/com/qmth/sop/business/service/impl/ServiceUnitAnalyseServiceImpl.java
  13. 46 10
      sop-business/src/main/java/com/qmth/sop/business/service/impl/SopWarnMonitorServiceImpl.java
  14. 83 194
      sop-business/src/main/resources/mapper/ServiceUnitAnalyseMapper.xml
  15. 27 0
      sop-business/src/main/resources/mapper/SopWarnMonitorMapper.xml
  16. 11 0
      sop-common/src/main/java/com/qmth/sop/common/enums/WarnFieldEnum.java

+ 4 - 2
sop-api/src/main/java/com/qmth/sop/server/api/ServiceUnitAnalyseController.java

@@ -88,8 +88,10 @@ public class ServiceUnitAnalyseController {
             @ApiParam(value = "大区经理", required = false) @RequestParam(required = false) Long leadId,
             @ApiParam(value = "客户所在省份", required = false) @RequestParam(required = false) String province,
             @ApiParam(value = "项目经理所在人力商", required = false) @RequestParam(required = false) Long supplierId,
-            @ApiParam(value = "区域协调人ID", required = false) @RequestParam(required = false) Long coordinatorId) {
-        serviceUnitAnalyseService.export(serviceUnitId, crmUserId, customName, process, leadId, province, supplierId, coordinatorId);
+            @ApiParam(value = "区域协调人ID", required = false) @RequestParam(required = false) Long coordinatorId,
+            @ApiParam(value = "类型", required = false) @RequestParam(required = false) String type,
+            @ApiParam(value = "预警字段", required = false) @RequestParam(required = false) String fieldObj) {
+        serviceUnitAnalyseService.export(serviceUnitId, crmUserId, customName, process, leadId, province, supplierId, coordinatorId, type, fieldObj);
     }
 
 }

+ 16 - 1
sop-api/src/main/java/com/qmth/sop/server/api/SopWarnMonitorController.java

@@ -4,6 +4,7 @@ import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.sop.business.bean.result.SopWarnMonitorResult;
 import com.qmth.sop.business.service.SopWarnMonitorService;
 import com.qmth.sop.common.contant.SystemConstant;
+import com.qmth.sop.common.enums.CrmProgressMonitorEnum;
 import com.qmth.sop.common.util.Result;
 import com.qmth.sop.common.util.ResultUtil;
 import io.swagger.annotations.*;
@@ -31,7 +32,21 @@ public class SopWarnMonitorController {
     @RequestMapping(value = "/region", method = RequestMethod.POST)
     @ApiResponses({ @ApiResponse(code = 200, message = "返回信息", response = SopWarnMonitorResult.class) })
     public Result region(@ApiParam(value = "服务单元ID", required = true) @RequestParam(required = true) Long serviceUnitId) {
-        return ResultUtil.ok(sopWarnMonitorService.listWarnByRegion(serviceUnitId));
+        return ResultUtil.ok(sopWarnMonitorService.listWarnByRegion(serviceUnitId, CrmProgressMonitorEnum.BY_LEAD));
+    }
+
+    @ApiOperation(value = "按人力商预警统计")
+    @RequestMapping(value = "/supplier", method = RequestMethod.POST)
+    @ApiResponses({ @ApiResponse(code = 200, message = "返回信息", response = SopWarnMonitorResult.class) })
+    public Result supplier(@ApiParam(value = "服务单元ID", required = true) @RequestParam(required = true) Long serviceUnitId) {
+        return ResultUtil.ok(sopWarnMonitorService.listWarnByRegion(serviceUnitId, CrmProgressMonitorEnum.BY_SUPPLIER));
+    }
+
+    @ApiOperation(value = "按区域协调人预警统计")
+    @RequestMapping(value = "/coordinator", method = RequestMethod.POST)
+    @ApiResponses({ @ApiResponse(code = 200, message = "返回信息", response = SopWarnMonitorResult.class) })
+    public Result coordinator(@ApiParam(value = "服务单元ID", required = true) @RequestParam(required = true) Long serviceUnitId) {
+        return ResultUtil.ok(sopWarnMonitorService.listWarnByRegion(serviceUnitId, CrmProgressMonitorEnum.BY_COORDINATOR));
     }
 
 

+ 12 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/ProjectMonitorResult.java

@@ -52,6 +52,10 @@ public class ProjectMonitorResult implements Serializable {
     @ApiModelProperty(value = "预警字段")
     private String fieldObj;
 
+    @ApiModelProperty(value = "预警表的ID")
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long warnId;
+
     @ApiModelProperty(value = "区域协调人")
     private ProjectMonitorUserResult regionCoordinator;
 
@@ -172,4 +176,12 @@ public class ProjectMonitorResult implements Serializable {
     public void setFieldObj(String fieldObj) {
         this.fieldObj = fieldObj;
     }
+
+    public Long getWarnId() {
+        return warnId;
+    }
+
+    public void setWarnId(Long warnId) {
+        this.warnId = warnId;
+    }
 }

+ 8 - 19
sop-business/src/main/java/com/qmth/sop/business/bean/result/SopInfoExportResult.java

@@ -17,35 +17,31 @@ import io.swagger.annotations.ApiModelProperty;
 public class SopInfoExportResult {
 
     @ApiModelProperty(value = "客户名称")
-    @ExcelProperty(value = "客户名称")
+    @ExcelProperty(value = "客户名称", order = 1)
     private String customName;
 
     @ApiModelProperty(value = "项目名称")
-    @ExcelProperty(value = "项目名称")
+    @ExcelProperty(value = "项目名称", order = 2)
     private String crmName;
 
     @ApiModelProperty(value = "科目名称")
-    @ExcelProperty(value = "科目名称")
+    @ExcelProperty(value = "科目名称", order = 3)
     private String courseName;
 
-    @ApiModelProperty(value = "当前进度")
-    @ExcelProperty(value = "当前进度")
-    private String process;
-
     @ApiModelProperty(value = "大区经理")
-    @ExcelProperty(value = "大区经理")
+    @ExcelProperty(value = "大区经理", order = 5)
     private String leadName;
 
     @ApiModelProperty(value = "区域协调人")
-    @ExcelProperty(value = "区域协调人")
+    @ExcelProperty(value = "区域协调人", order = 6)
     private String regionCoordinator;
 
     @ApiModelProperty(value = "项目经理")
-    @ExcelProperty(value = "项目经理")
+    @ExcelProperty(value = "项目经理", order = 7)
     private String projectManager;
 
     @ApiModelProperty(value = "工程师")
-    @ExcelProperty(value = "工程师")
+    @ExcelProperty(value = "工程师", order = 8)
     private String engineer;
 
     public String getCustomName() {
@@ -72,14 +68,6 @@ public class SopInfoExportResult {
         this.courseName = courseName;
     }
 
-    public String getProcess() {
-        return process;
-    }
-
-    public void setProcess(String process) {
-        this.process = process;
-    }
-
     public String getLeadName() {
         return leadName;
     }
@@ -111,4 +99,5 @@ public class SopInfoExportResult {
     public void setEngineer(String engineer) {
         this.engineer = engineer;
     }
+
 }

+ 19 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/SopProcessExportResult.java

@@ -0,0 +1,19 @@
+package com.qmth.sop.business.bean.result;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModelProperty;
+
+public class SopProcessExportResult extends SopInfoExportResult {
+
+    @ApiModelProperty(value = "当前进度")
+    @ExcelProperty(value = "当前进度", order = 4)
+    private String process;
+
+    public String getProcess() {
+        return process;
+    }
+
+    public void setProcess(String process) {
+        this.process = process;
+    }
+}

+ 19 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/SopWarnExportResult.java

@@ -0,0 +1,19 @@
+package com.qmth.sop.business.bean.result;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModelProperty;
+
+public class SopWarnExportResult extends SopInfoExportResult {
+
+    @ApiModelProperty(value = "预警字段")
+    @ExcelProperty(value = "预警字段", order = 4)
+    private String fieldObj;
+
+    public String getFieldObj() {
+        return fieldObj;
+    }
+
+    public void setFieldObj(String fieldObj) {
+        this.fieldObj = fieldObj;
+    }
+}

+ 44 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/SopWarnMonitorDetailResult.java

@@ -24,6 +24,18 @@ public class SopWarnMonitorDetailResult {
     @ApiModelProperty(value = "大区经理名称")
     private String leadName;
 
+    @ApiModelProperty(value = "供应商ID")
+    private Long supplierId;
+
+    @ApiModelProperty(value = "供应商名称")
+    private String supplierName;
+
+    @ApiModelProperty(value = "区域协调人ID")
+    private Long coordinatorId;
+
+    @ApiModelProperty(value = "区域协调人名称")
+    private String coordinatorName;
+
     public String getCrmNo() {
         return crmNo;
     }
@@ -63,4 +75,36 @@ public class SopWarnMonitorDetailResult {
     public void setLeadName(String leadName) {
         this.leadName = leadName;
     }
+
+    public Long getSupplierId() {
+        return supplierId;
+    }
+
+    public void setSupplierId(Long supplierId) {
+        this.supplierId = supplierId;
+    }
+
+    public String getSupplierName() {
+        return supplierName;
+    }
+
+    public void setSupplierName(String supplierName) {
+        this.supplierName = supplierName;
+    }
+
+    public Long getCoordinatorId() {
+        return coordinatorId;
+    }
+
+    public void setCoordinatorId(Long coordinatorId) {
+        this.coordinatorId = coordinatorId;
+    }
+
+    public String getCoordinatorName() {
+        return coordinatorName;
+    }
+
+    public void setCoordinatorName(String coordinatorName) {
+        this.coordinatorName = coordinatorName;
+    }
 }

+ 4 - 3
sop-business/src/main/java/com/qmth/sop/business/mapper/ServiceUnitAnalyseMapper.java

@@ -92,7 +92,8 @@ public interface ServiceUnitAnalyseMapper extends BaseMapper<TBService> {
      */
     List<ProjectMonitorResult> listSop(@Param(value = "serviceUnitId") Long serviceUnitId,
             @Param(value = "crmUserId") Long crmUserId, @Param(value = "customName") String customName, @Param(value = "process") CrmProcessEnum process,
-            @Param(value = "leadId") Long leadId, @Param(value = "province") String province, @Param(value = "prList") List<String> processList);
+            @Param(value = "leadId") Long leadId, @Param(value = "province") String province, @Param(value = "prList") List<String> processList,
+            @Param(value = "type") String type, @Param(value = "fieldObj") String fieldObj);
 
     /**
      * 通过服务单元等条件分页查询sop
@@ -114,7 +115,7 @@ public interface ServiceUnitAnalyseMapper extends BaseMapper<TBService> {
             @Param(value = "crmUserId") Long crmUserId, @Param(value = "customName") String customName, @Param(value = "process") CrmProcessEnum process,
             @Param(value = "leadId") Long leadId, @Param(value = "province") String province, @Param(value = "prList") List<String> processList,
             @Param(value = "supplierId") Long supplierId, @Param(value = "coordinatorId") Long coordinatorId,
-            @Param(value = "roleType") SopRoleTypeEnum roleType);
+            @Param(value = "roleType") SopRoleTypeEnum roleType, @Param(value = "type") String type, @Param(value = "fieldObj") String fieldObj);
 
     /**
      * 过服务单元等条件查询sop列表
@@ -132,5 +133,5 @@ public interface ServiceUnitAnalyseMapper extends BaseMapper<TBService> {
             @Param(value = "crmUserId") Long crmUserId, @Param(value = "customName") String customName, @Param(value = "process") CrmProcessEnum process,
             @Param(value = "leadId") Long leadId, @Param(value = "province") String province, @Param(value = "prList") List<String> processList,
             @Param(value = "supplierId") Long supplierId, @Param(value = "coordinatorId") Long coordinatorId,
-            @Param(value = "roleType") SopRoleTypeEnum roleType);
+            @Param(value = "roleType") SopRoleTypeEnum roleType, @Param(value = "type") String type, @Param(value = "fieldObj") String fieldObj);
 }

+ 4 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/SopWarnMonitorMapper.java

@@ -3,6 +3,7 @@ package com.qmth.sop.business.mapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.qmth.sop.business.bean.result.SopWarnMonitorDetailResult;
 import com.qmth.sop.business.entity.TBDelayWarn;
+import com.qmth.sop.common.enums.SopRoleTypeEnum;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -11,4 +12,7 @@ public interface SopWarnMonitorMapper extends BaseMapper<TBDelayWarn> {
 
     List<SopWarnMonitorDetailResult> listDelayWarn(@Param(value = "serviceUnitId") Long serviceUnitId,
             @Param(value = "warnFieldList") List<String> warnFieldList);
+
+    List<SopWarnMonitorDetailResult> listDelayWarnByUserRole(@Param(value = "serviceUnitId") Long serviceUnitId,
+            @Param(value = "warnFieldList") List<String> warnFieldList, @Param(value = "sopRoleType") SopRoleTypeEnum sopRoleType);
 }

+ 1 - 1
sop-business/src/main/java/com/qmth/sop/business/service/ServiceUnitAnalyseService.java

@@ -29,6 +29,6 @@ public interface ServiceUnitAnalyseService extends IService<TBService> {
             Long leadId, String province, Long supplierId, Long coordinatorId, String type, String fieldObj);
 
     void export(Long serviceUnitId, Long crmUserId, String customName, CrmProcessEnum process, Long leadId, String province, Long supplierId,
-            Long coordinatorId);
+            Long coordinatorId, String type, String fieldObj);
 
 }

+ 2 - 1
sop-business/src/main/java/com/qmth/sop/business/service/SopWarnMonitorService.java

@@ -3,10 +3,11 @@ package com.qmth.sop.business.service;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.bean.result.SopWarnMonitorResult;
 import com.qmth.sop.business.entity.TBDelayWarn;
+import com.qmth.sop.common.enums.CrmProgressMonitorEnum;
 
 import java.util.List;
 
 public interface SopWarnMonitorService extends IService<TBDelayWarn> {
 
-    List<SopWarnMonitorResult> listWarnByRegion(Long serviceUnitId);
+    List<SopWarnMonitorResult> listWarnByRegion(Long serviceUnitId, CrmProgressMonitorEnum type);
 }

+ 24 - 10
sop-business/src/main/java/com/qmth/sop/business/service/impl/ServiceUnitAnalyseServiceImpl.java

@@ -179,7 +179,7 @@ public class ServiceUnitAnalyseServiceImpl extends ServiceImpl<ServiceUnitAnalys
                     customName, process, leadId, province, processList, type, fieldObj);
         } else { // 人力供应商、区域协调人
             pageSop = baseMapper.pageSopByUserAllocation(new Page<>(page.getCurrent(), page.getSize()), serviceUnitId, crmUserId,
-                    customName, process, leadId, province, processList, supplierId, coordinatorId, roleType);
+                    customName, process, leadId, province, processList, supplierId, coordinatorId, roleType, type, fieldObj);
         }
 
         List<ProjectMonitorResult> monitorResultList = pageSop.getRecords();
@@ -198,7 +198,8 @@ public class ServiceUnitAnalyseServiceImpl extends ServiceImpl<ServiceUnitAnalys
     }
 
     @Override
-    public void export(Long serviceUnitId, Long crmUserId, String customName, CrmProcessEnum process, Long leadId, String province, Long supplierId, Long coordinatorId) {
+    public void export(Long serviceUnitId, Long crmUserId, String customName, CrmProcessEnum process, Long leadId, String province, Long supplierId,
+            Long coordinatorId, String type, String fieldObj) {
         List<String> processList = new ArrayList<>();
         if (process != null) {
             processList = getProcessList(process);
@@ -214,24 +215,38 @@ public class ServiceUnitAnalyseServiceImpl extends ServiceImpl<ServiceUnitAnalys
         List<ProjectMonitorResult> resultList;
         // 人力供应商、区域协调人
         if (supplierId == null && coordinatorId == null) {
-            resultList = baseMapper.listSop(serviceUnitId, crmUserId, customName, process, leadId, province, processList);
+            resultList = baseMapper.listSop(serviceUnitId, crmUserId, customName, process, leadId, province, processList, type, fieldObj);
         } else {
             resultList = baseMapper.listSopByUserAllocation(serviceUnitId, crmUserId, customName, process, leadId, province, processList, supplierId,
-                    coordinatorId, roleType);
+                    coordinatorId, roleType, type, fieldObj);
         }
 
         //封装导出结果
-        List<SopInfoExportResult> exportResultList = new ArrayList<>();
-        for(ProjectMonitorResult result : resultList) {
-            result.setProcess(CrmProcessEnum.findCrmProcessByDesc(result.getTaskName()));
+        List<SopProcessExportResult> exportResultList = new ArrayList<>();
+        List<SopWarnExportResult> warnExportResultList = new ArrayList<>();
+        for (ProjectMonitorResult result : resultList) {
             SopInfoExportResult exportResult = getSopInfoExportResult(result);
-            exportResultList.add(exportResult);
+            if (type == null) {// 预警导出
+                SopProcessExportResult sopProcessExportResult = new SopProcessExportResult();
+                sopProcessExportResult.setProcess(Objects.requireNonNull(CrmProcessEnum.findCrmProcessByDesc(result.getTaskName())).getTitle());
+                BeanUtils.copyProperties(exportResult, sopProcessExportResult);
+                exportResultList.add(sopProcessExportResult);
+            } else {// 其他导出
+                SopWarnExportResult sopWarnExportResult = new SopWarnExportResult();
+                sopWarnExportResult.setFieldObj(Objects.requireNonNull(WarnFieldEnum.findWarnFieldEnumByTitle(result.getFieldObj())).getDesc());
+                BeanUtils.copyProperties(exportResult, sopWarnExportResult);
+                warnExportResultList.add(sopWarnExportResult);
+            }
         }
 
         File fileTemp = null;
         try {
             fileTemp = SystemConstant.getFileTempVar(SystemConstant.XLSX_PREFIX);
-            EasyExcel.write(fileTemp, SopInfoExportResult.class).sheet("sop信息").doWrite(exportResultList);
+            if (type == null) {
+                EasyExcel.write(fileTemp, SopProcessExportResult.class).sheet("sop信息").doWrite(exportResultList);
+            } else {
+                EasyExcel.write(fileTemp, SopWarnExportResult.class).sheet("sop信息").doWrite(warnExportResultList);
+            }
             HttpServletResponse response = ServletUtil.getResponse();
             FileUtil.outputFile(response, fileTemp, "sop信息.xlsx");
         } catch (IOException e) {
@@ -249,7 +264,6 @@ public class ServiceUnitAnalyseServiceImpl extends ServiceImpl<ServiceUnitAnalys
         exportResult.setCustomName(result.getCustomName());
         exportResult.setCrmName(result.getCrmName());
         exportResult.setCourseName(result.getCourseName());
-        exportResult.setProcess(result.getProcess().getTitle());
         exportResult.setLeadName(result.getLeadName()+"-"+ result.getLeadMobile());
         List<UserArchivesAllocationDto> allocationDtoList = tbUserArchivesAllocationService.listUserArchivesAllocation(result.getCrmDetailId());
         //设置区域协调人

+ 46 - 10
sop-business/src/main/java/com/qmth/sop/business/service/impl/SopWarnMonitorServiceImpl.java

@@ -6,6 +6,8 @@ import com.qmth.sop.business.bean.result.SopWarnMonitorResult;
 import com.qmth.sop.business.entity.TBDelayWarn;
 import com.qmth.sop.business.mapper.SopWarnMonitorMapper;
 import com.qmth.sop.business.service.SopWarnMonitorService;
+import com.qmth.sop.common.enums.CrmProgressMonitorEnum;
+import com.qmth.sop.common.enums.SopRoleTypeEnum;
 import com.qmth.sop.common.enums.WarnFieldEnum;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.stereotype.Service;
@@ -21,13 +23,26 @@ import java.util.stream.Collectors;
 public class SopWarnMonitorServiceImpl extends ServiceImpl<SopWarnMonitorMapper, TBDelayWarn> implements SopWarnMonitorService {
 
     @Override
-    public List<SopWarnMonitorResult> listWarnByRegion(Long serviceUnitId) {
+    public List<SopWarnMonitorResult> listWarnByRegion(Long serviceUnitId, CrmProgressMonitorEnum type) {
         List<SopWarnMonitorResult> resultList = new ArrayList<>();
         List<String> warnFieldList = getWarnField();
 
-        List<SopWarnMonitorDetailResult> warnDetailList = baseMapper.listDelayWarn(serviceUnitId, warnFieldList);
-        //按照大区经理分组
-        Function<SopWarnMonitorDetailResult, List<Object>> compositeKey = warn -> Arrays.asList(warn.getLeadId(), warn.getLeadName());
+        List<SopWarnMonitorDetailResult> warnDetailList = new ArrayList<>();
+        Function<SopWarnMonitorDetailResult, List<Object>> compositeKey = null;
+        if (type.equals(CrmProgressMonitorEnum.BY_LEAD)) {
+            //大区经理
+            warnDetailList = baseMapper.listDelayWarn(serviceUnitId, warnFieldList);
+            compositeKey = warn -> Arrays.asList(warn.getLeadId(), warn.getLeadName());
+        } else if (type.equals(CrmProgressMonitorEnum.BY_SUPPLIER)) {
+            //项目经理所属人力商
+            warnDetailList = baseMapper.listDelayWarnByUserRole(serviceUnitId, warnFieldList, SopRoleTypeEnum.PROJECT_MANAGER);
+            compositeKey = warn -> Arrays.asList(warn.getSupplierId(), warn.getSupplierName());
+        } else if (type.equals(CrmProgressMonitorEnum.BY_COORDINATOR)) {
+            //区域协调人
+            warnDetailList = baseMapper.listDelayWarnByUserRole(serviceUnitId, warnFieldList, SopRoleTypeEnum.REGION_COORDINATOR);
+            compositeKey = warn -> Arrays.asList(warn.getCoordinatorId(), warn.getCoordinatorName());
+        }
+
         Map<List<Object>, List<SopWarnMonitorDetailResult>> warnMap = warnDetailList.stream().collect(Collectors.groupingBy(compositeKey, Collectors.toList()));
 
         Set<Map.Entry<List<Object>, List<SopWarnMonitorDetailResult>>> entries = warnMap.entrySet();
@@ -36,8 +51,17 @@ public class SopWarnMonitorServiceImpl extends ServiceImpl<SopWarnMonitorMapper,
             List<Object> leadList = entry.getKey();
             List<SopWarnMonitorDetailResult> detailList = entry.getValue();
 
-            result.setLeadId(Long.parseLong(leadList.get(0).toString()));
-            result.setLeadName(leadList.get(1).toString());
+            if (type.equals(CrmProgressMonitorEnum.BY_LEAD)) {
+                result.setLeadId(Long.parseLong(leadList.get(0).toString()));
+                result.setLeadName(leadList.get(1).toString());
+            } else if (type.equals(CrmProgressMonitorEnum.BY_SUPPLIER)) {
+                result.setSupplierId(Long.parseLong(leadList.get(0).toString()));
+                result.setSupplierName(leadList.get(1).toString());
+            } else {
+                result.setCoordinatorId(Long.parseLong(leadList.get(0).toString()));
+                result.setCoordinatorName(leadList.get(1).toString());
+            }
+
             result.setTotal(detailList.size());
             resultList.add(result);
         }
@@ -48,9 +72,21 @@ public class SopWarnMonitorServiceImpl extends ServiceImpl<SopWarnMonitorMapper,
                 .collect(Collectors.toList());
         //设置预警数量和占比
         for (SopWarnMonitorResult result : warnOrderList) {
-            List<SopWarnMonitorDetailResult> filterWarnList = warnDetailList.stream()
-                    .filter(item -> item.getLeadId().equals(result.getLeadId()))
-                    .collect(Collectors.toList());
+            List<SopWarnMonitorDetailResult> filterWarnList;
+
+            if (type.equals(CrmProgressMonitorEnum.BY_LEAD)) {
+                filterWarnList = warnDetailList.stream()
+                        .filter(item -> item.getLeadId().equals(result.getLeadId()))
+                        .collect(Collectors.toList());
+            } else if (type.equals(CrmProgressMonitorEnum.BY_SUPPLIER)) {
+                filterWarnList = warnDetailList.stream()
+                        .filter(item -> item.getSupplierId().equals(result.getSupplierId()))
+                        .collect(Collectors.toList());
+            } else {
+                filterWarnList = warnDetailList.stream()
+                        .filter(item -> item.getCoordinatorId().equals(result.getCoordinatorId()))
+                        .collect(Collectors.toList());
+            }
             getWarnFieldNum(result, filterWarnList);
         }
 
@@ -127,7 +163,7 @@ public class SopWarnMonitorServiceImpl extends ServiceImpl<SopWarnMonitorMapper,
     private String getRatio(BigDecimal total, BigDecimal num) {
         String ratio = "";
         //计算占比
-        if (total.intValue() != 0) {
+        if (total.intValue() != 0 && num.intValue() != 0) {
             num = num.divide(total, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100));
             NumberFormat formatter = NumberFormat.getPercentInstance();
             formatter.setMinimumFractionDigits(2);

+ 83 - 194
sop-business/src/main/resources/mapper/ServiceUnitAnalyseMapper.xml

@@ -2,62 +2,7 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.qmth.sop.business.mapper.ServiceUnitAnalyseMapper">
 
-    <select id="countLead" resultType="java.lang.Integer" parameterType="java.lang.Long">
-        select count(distinct lead_id)
-        from t_b_crm
-        where service_id = #{serviceUnitId}
-    </select>
-
-    <select id="countTotalPerson" resultType="java.lang.Integer" parameterType="java.lang.Long">
-        select count(distinct user_id)
-        from t_b_user_archives_allocation
-        where service_id = #{serviceUnitId}
-    </select>
-
-    <select id="countScanner" resultType="java.lang.Integer">
-        SELECT
-        count( 1 )
-        FROM
-        t_b_device_delivery tdd,
-        t_b_crm tbc
-        WHERE
-        tdd.crm_no = tbc.crm_no
-        AND tbc.service_id = #{serviceUnitId}
-        AND tdd.delivery_type = #{out}
-        <if test="deliveryStatusList != null and deliveryStatusList.size() > 0">
-            AND tdd.STATUS IN
-            <foreach collection="deliveryStatusList" item="item" open="(" close=")" index="index" separator=",">
-                #{item}
-            </foreach>
-        </if>
-    </select>
-
-    <select id="listSopProgress" resultType="com.qmth.sop.business.bean.result.ServiceUnitProgressResult" parameterType="java.lang.Long">
-        SELECT DISTINCT IFNULL(art.NAME_, '已完成') AS taskName,
-                        tbsi.sop_no                 AS sopNo,
-                        sc.province                 AS provinceName
-        FROM t_b_sop_info tbsi
-                 INNER JOIN t_b_crm tbc ON tbc.crm_no = tbsi.crm_no
-                 INNER JOIN t_b_service tbs ON tbs.id = tbsi.service_id
-                 INNER JOIN t_f_custom_flow_entity tfcfe ON tfcfe.CODE = tbsi.sop_no
-                 INNER JOIN t_f_flow_approve tffa ON tffa.flow_id = tfcfe.flow_id
-                 LEFT JOIN ACT_RU_TASK art ON art.PROC_INST_ID_ = tffa.flow_id
-                 INNER JOIN t_f_custom_flow tfcf ON tfcf.id = tfcfe.t_f_custom_flow_id
-                 INNER JOIN t_b_crm_detail tbcd ON tbcd.sop_no = tbsi.sop_no
-                 INNER JOIN sys_custom sc on sc.id = tbc.custom_id
-        WHERE tbsi.service_id = #{serviceUnitId}
-    </select>
-
-    <select id="listProvinceCrmNum" resultType="com.qmth.sop.business.bean.result.ServiceUnitProvinceResult" parameterType="java.lang.Long">
-        SELECT sc.province,
-               count(1) AS provinceCrmNum
-        FROM t_b_crm tbc
-                 INNER JOIN sys_custom sc ON tbc.custom_id = sc.id
-        WHERE tbc.service_id = #{serviceUnitId}
-        GROUP BY sc.province
-    </select>
-
-    <select id="pageSop" resultType="com.qmth.sop.business.bean.result.ProjectMonitorResult">
+    <sql id="sopSql">
         SELECT DISTINCT
         sc.NAME AS customName,
         tbc.NAME AS crmName,
@@ -71,7 +16,8 @@
         IF ( sc.type = 'OFFICE', '教务处', '研究生' ) AS customManagerTypeStr,
         cast( tfcfe.flow_id AS CHAR ) AS flowId,
         tbsi.update_time AS updateTime,
-        tbdw.field_obj AS fieldObj
+        tbdw.field_obj AS fieldObj,
+        tbdw.id warnId
         FROM
         t_b_sop_info tbsi
         LEFT JOIN t_b_crm tbc ON tbc.crm_no = tbsi.crm_no
@@ -101,7 +47,7 @@
             <if test="province != null and province != '' ">
                 AND sc.province=#{province}
             </if>
-             <!-- 预警字段 -->
+            <!-- 预警字段 -->
             <if test="type != null and type != '' ">
                 AND tbdw.field_obj is not null
             </if>
@@ -127,9 +73,9 @@
             and IF(tbs.`status` = 'PUBLISH', tffa.status in ('START', 'DRAFT', 'AUDITING', 'REJECT', 'CANCEL', 'FINISH'), 1 <![CDATA[ <> ]]> 1)
         </where>
         ORDER BY tbsi.update_time DESC,tbsi.sop_no DESC
-    </select>
+    </sql>
 
-    <select id="pageSopByUserAllocation" resultType="com.qmth.sop.business.bean.result.ProjectMonitorResult">
+    <sql id="sopByUserAllocationSql">
         SELECT DISTINCT
         sc.NAME AS customName,
         tbc.NAME AS crmName,
@@ -142,7 +88,9 @@
         tbcd.id AS crmDetailId,
         IF ( sc.type = 'OFFICE', '教务处', '研究生' ) AS customManagerTypeStr,
         cast( tfcfe.flow_id AS CHAR ) AS flowId,
-        tbsi.update_time AS updateTime
+        tbsi.update_time AS updateTime,
+        tbdw.field_obj AS fieldObj,
+        tbdw.id warnId
         FROM
         t_b_sop_info tbsi
         LEFT JOIN t_b_crm tbc ON tbc.crm_no = tbsi.crm_no
@@ -159,6 +107,7 @@
         LEFT JOIN t_b_user_archives_supplier tbusas ON tbusas.user_archives_id = tbusaa.archives_id
         LEFT JOIN sys_supplier ss ON ss.id = tbusas.supplier_id
         LEFT JOIN sys_user syu ON syu.id = tbusaa.user_id
+        LEFT JOIN t_b_delay_warn tbdw on tbdw.crm_no=tbc.crm_no and tbdw.sop_no=tbcd.sop_no
         <where>
             <if test="serviceUnitId != null">
                 AND tbsi.service_id=#{serviceUnitId}
@@ -184,6 +133,13 @@
             <if test="roleType != null">
                 AND tbusaa.sop_role_type = #{roleType}
             </if>
+            <!-- 预警字段 -->
+            <if test="type != null and type != '' ">
+                AND tbdw.field_obj is not null
+            </if>
+            <if test="fieldObj != null and fieldObj != '' ">
+                AND tbdw.field_obj = #{fieldObj}
+            </if>
 
             <if test="process != null">
                 <choose>
@@ -203,147 +159,80 @@
             and IF(tbs.`status` = 'PUBLISH', tffa.status in ('START', 'DRAFT', 'AUDITING', 'REJECT', 'CANCEL', 'FINISH'), 1 <![CDATA[ <> ]]> 1)
         </where>
         ORDER BY tbsi.update_time DESC,tbsi.sop_no DESC
-    </select>
+    </sql>
 
 
+    <select id="countLead" resultType="java.lang.Integer" parameterType="java.lang.Long">
+        select count(distinct lead_id)
+        from t_b_crm
+        where service_id = #{serviceUnitId}
+    </select>
 
-    <select id="listSop" resultType="com.qmth.sop.business.bean.result.ProjectMonitorResult">
-        SELECT DISTINCT
-        sc.NAME AS customName,
-        tbc.NAME AS crmName,
-        tbcd.course_name AS courseName,
-        IFNULL( art.NAME_, '已完成' ) AS taskName,
-        tbc.lead_id leadId,
-        su3.real_name AS leadName,
-        su3.mobile_number leadMobile,
-        tbsi.sop_no AS sopNo,
-        tbcd.id AS crmDetailId,
-        IF ( sc.type = 'OFFICE', '教务处', '研究生' ) AS customManagerTypeStr,
-        cast( tfcfe.flow_id AS CHAR ) AS flowId,
-        tbsi.update_time AS updateTime
+    <select id="countTotalPerson" resultType="java.lang.Integer" parameterType="java.lang.Long">
+        select count(distinct user_id)
+        from t_b_user_archives_allocation
+        where service_id = #{serviceUnitId}
+    </select>
+
+    <select id="countScanner" resultType="java.lang.Integer">
+        SELECT
+        count( 1 )
         FROM
-        t_b_sop_info tbsi
-        LEFT JOIN t_b_crm tbc ON tbc.crm_no = tbsi.crm_no
-        LEFT JOIN t_b_service tbs ON tbs.id = tbsi.service_id
-        LEFT JOIN sys_custom sc ON sc.id = tbsi.custom_id
-        LEFT JOIN sys_user su1 ON su1.id = tbc.crm_user_id
-        LEFT JOIN t_f_custom_flow_entity tfcfe ON tfcfe.CODE = tbsi.sop_no
-        LEFT JOIN t_f_flow_approve tffa ON tffa.flow_id = tfcfe.flow_id
-        LEFT JOIN ACT_RU_TASK art ON art.PROC_INST_ID_ = tffa.flow_id
-        LEFT JOIN t_f_custom_flow tfcf ON tfcf.id = tfcfe.t_f_custom_flow_id
-        LEFT JOIN t_b_crm_detail tbcd ON tbcd.sop_no = tbsi.sop_no
-        LEFT JOIN sys_user su3 ON su3.id = tbc.lead_id
-        <where>
-            <if test="serviceUnitId != null">
-                AND tbsi.service_id=#{serviceUnitId}
-            </if>
-            <if test="crmUserId != null">
-                AND tbc.crm_user_id=#{crmUserId}
-            </if>
-            <if test="customName != null and customName != ''">
-                AND sc.name=#{customName}
-            </if>
-            <if test="leadId != null">
-                AND tbc.lead_id=#{leadId}
-            </if>
-            <if test="province != null and province != '' ">
-                AND sc.province=#{province}
-            </if>
+        t_b_device_delivery tdd,
+        t_b_crm tbc
+        WHERE
+        tdd.crm_no = tbc.crm_no
+        AND tbc.service_id = #{serviceUnitId}
+        AND tdd.delivery_type = #{out}
+        <if test="deliveryStatusList != null and deliveryStatusList.size() > 0">
+            AND tdd.STATUS IN
+            <foreach collection="deliveryStatusList" item="item" open="(" close=")" index="index" separator=",">
+                #{item}
+            </foreach>
+        </if>
+    </select>
 
-            <if test="process != null">
-                <choose>
-                    <!--非已完成状态-->
-                    <when test="prList != null and prList.size > 0">
-                        AND art.NAME_ in
-                        <foreach collection="prList" item="item" index="index" open="(" separator="," close=")">
-                            #{item}
-                        </foreach>
-                    </when>
-                    <!-- 已完成状态-->
-                    <otherwise>
-                        AND art.NAME_ is null
-                    </otherwise>
-                </choose>
-            </if>
-            and IF(tbs.`status` = 'PUBLISH', tffa.status in ('START', 'DRAFT', 'AUDITING', 'REJECT', 'CANCEL', 'FINISH'), 1 <![CDATA[ <> ]]> 1)
-        </where>
-        ORDER BY tbsi.update_time DESC,tbsi.sop_no DESC
+    <select id="listSopProgress" resultType="com.qmth.sop.business.bean.result.ServiceUnitProgressResult" parameterType="java.lang.Long">
+        SELECT DISTINCT IFNULL(art.NAME_, '已完成') AS taskName,
+                        tbsi.sop_no                 AS sopNo,
+                        sc.province                 AS provinceName
+        FROM t_b_sop_info tbsi
+                 INNER JOIN t_b_crm tbc ON tbc.crm_no = tbsi.crm_no
+                 INNER JOIN t_b_service tbs ON tbs.id = tbsi.service_id
+                 INNER JOIN t_f_custom_flow_entity tfcfe ON tfcfe.CODE = tbsi.sop_no
+                 INNER JOIN t_f_flow_approve tffa ON tffa.flow_id = tfcfe.flow_id
+                 LEFT JOIN ACT_RU_TASK art ON art.PROC_INST_ID_ = tffa.flow_id
+                 INNER JOIN t_f_custom_flow tfcf ON tfcf.id = tfcfe.t_f_custom_flow_id
+                 INNER JOIN t_b_crm_detail tbcd ON tbcd.sop_no = tbsi.sop_no
+                 INNER JOIN sys_custom sc on sc.id = tbc.custom_id
+        WHERE tbsi.service_id = #{serviceUnitId}
     </select>
 
-    <select id="listSopByUserAllocation" resultType="com.qmth.sop.business.bean.result.ProjectMonitorResult">
-        SELECT DISTINCT
-        sc.NAME AS customName,
-        tbc.NAME AS crmName,
-        tbcd.course_name AS courseName,
-        IFNULL( art.NAME_, '已完成' ) AS taskName,
-        tbc.lead_id AS leadId,
-        su3.real_name AS leadName,
-        su3.mobile_number leadMobile,
-        tbsi.sop_no AS sopNo,
-        tbcd.id AS crmDetailId,
-        IF ( sc.type = 'OFFICE', '教务处', '研究生' ) AS customManagerTypeStr,
-        cast( tfcfe.flow_id AS CHAR ) AS flowId,
-        tbsi.update_time AS updateTime
-        FROM
-        t_b_sop_info tbsi
-        LEFT JOIN t_b_crm tbc ON tbc.crm_no = tbsi.crm_no
-        LEFT JOIN t_b_service tbs ON tbs.id = tbsi.service_id
-        LEFT JOIN sys_custom sc ON sc.id = tbsi.custom_id
-        LEFT JOIN sys_user su1 ON su1.id = tbc.crm_user_id
-        LEFT JOIN t_f_custom_flow_entity tfcfe ON tfcfe.CODE = tbsi.sop_no
-        LEFT JOIN t_f_flow_approve tffa ON tffa.flow_id = tfcfe.flow_id
-        LEFT JOIN ACT_RU_TASK art ON art.PROC_INST_ID_ = tffa.flow_id
-        LEFT JOIN t_f_custom_flow tfcf ON tfcf.id = tfcfe.t_f_custom_flow_id
-        LEFT JOIN t_b_crm_detail tbcd ON tbcd.sop_no = tbsi.sop_no
-        LEFT JOIN sys_user su3 ON su3.id = tbc.lead_id
-        LEFT JOIN t_b_user_archives_allocation tbusaa ON tbusaa.crm_detail_id = tbcd.id
-        LEFT JOIN t_b_user_archives_supplier tbusas ON tbusas.user_archives_id = tbusaa.archives_id
-        LEFT JOIN sys_supplier ss ON ss.id = tbusas.supplier_id
-        LEFT JOIN sys_user syu ON syu.id = tbusaa.user_id
-        <where>
-            <if test="serviceUnitId != null">
-                AND tbsi.service_id=#{serviceUnitId}
-            </if>
-            <if test="crmUserId != null">
-                AND tbc.crm_user_id=#{crmUserId}
-            </if>
-            <if test="customName != null and customName != ''">
-                AND sc.name=#{customName}
-            </if>
-            <if test="leadId != null">
-                AND tbc.lead_id=#{leadId}
-            </if>
-            <if test="province != null and province != '' ">
-                AND sc.province=#{province}
-            </if>
-            <if test="supplierId != null">
-                AND ss.id = #{supplierId}
-            </if>
-            <if test="coordinatorId != null">
-                AND tbusaa.user_id = #{coordinatorId}
-            </if>
-            <if test="roleType != null">
-                AND tbusaa.sop_role_type = #{roleType}
-            </if>
+    <select id="listProvinceCrmNum" resultType="com.qmth.sop.business.bean.result.ServiceUnitProvinceResult" parameterType="java.lang.Long">
+        SELECT sc.province,
+               count(1) AS provinceCrmNum
+        FROM t_b_crm tbc
+                 INNER JOIN sys_custom sc ON tbc.custom_id = sc.id
+        WHERE tbc.service_id = #{serviceUnitId}
+        GROUP BY sc.province
+    </select>
 
-            <if test="process != null">
-                <choose>
-                    <!--非已完成状态-->
-                    <when test="prList != null and prList.size > 0">
-                        AND art.NAME_ in
-                        <foreach collection="prList" item="item" index="index" open="(" separator="," close=")">
-                            #{item}
-                        </foreach>
-                    </when>
-                    <!-- 已完成状态-->
-                    <otherwise>
-                        AND art.NAME_ is null
-                    </otherwise>
-                </choose>
-            </if>
-            and IF(tbs.`status` = 'PUBLISH', tffa.status in ('START', 'DRAFT', 'AUDITING', 'REJECT', 'CANCEL', 'FINISH'), 1 <![CDATA[ <> ]]> 1)
-        </where>
-        ORDER BY tbsi.update_time DESC,tbsi.sop_no DESC
+
+    <select id="pageSop" resultType="com.qmth.sop.business.bean.result.ProjectMonitorResult">
+        <include refid="sopSql"/>
+    </select>
+
+    <select id="pageSopByUserAllocation" resultType="com.qmth.sop.business.bean.result.ProjectMonitorResult">
+        <include refid="sopByUserAllocationSql"/>
+    </select>
+
+
+    <select id="listSop" resultType="com.qmth.sop.business.bean.result.ProjectMonitorResult">
+        <include refid="sopSql"/>
+    </select>
+
+    <select id="listSopByUserAllocation" resultType="com.qmth.sop.business.bean.result.ProjectMonitorResult">
+        <include refid="sopByUserAllocationSql"/>
     </select>
 
 

+ 27 - 0
sop-business/src/main/resources/mapper/SopWarnMonitorMapper.xml

@@ -12,6 +12,7 @@
         FROM
         t_b_delay_warn tbdw
         LEFT JOIN t_b_crm tbc ON tbdw.crm_no = tbc.crm_no
+        INNER JOIN t_b_crm_detail tbcd on tbcd.crm_no = tbdw.crm_no and tbcd.sop_no = tbdw.sop_no
         LEFT JOIN sys_user su ON su.id = tbc.lead_id
         WHERE
         tbdw.service_id = #{serviceUnitId}
@@ -22,4 +23,30 @@
             </foreach>
         </if>
     </select>
+    <select id="listDelayWarnByUserRole" resultType="com.qmth.sop.business.bean.result.SopWarnMonitorDetailResult">
+        SELECT DISTINCT tbdw.crm_no AS crmNo,
+        tbdw.sop_no AS sopNo,
+        tbdw.field_obj AS fieldObj,
+        ss.id AS supplierId,
+        ss.NAME AS supplierName,
+        tbaa.user_id AS coordinatorId,
+        su.real_name AS coordinatorName
+        FROM t_b_delay_warn tbdw
+        LEFT JOIN t_b_crm tbc ON tbc.crm_no = tbdw.crm_no
+        LEFT JOIN t_b_crm_detail tbcd ON tbcd.crm_no = tbc.crm_no AND tbcd.sop_no = tbdw.sop_no
+        LEFT JOIN t_b_user_archives_allocation tbaa ON tbaa.crm_detail_id = tbcd.id AND tbdw.user_id = tbaa.user_id
+        LEFT JOIN t_b_user_archives_supplier tbusa ON tbusa.user_archives_id = tbaa.archives_id
+        LEFT JOIN sys_supplier ss ON ss.id = tbusa.supplier_id
+        LEFT JOIN sys_user su ON su.id = tbaa.user_id
+        WHERE tbdw.service_id = #{serviceUnitId}
+        <if test="sopRoleType != null">
+            AND tbaa.sop_role_type = #{sopRoleType}
+        </if>
+        <if test="warnFieldList != null and warnFieldList.size() > 0">
+            AND tbdw.field_obj IN
+            <foreach collection="warnFieldList" item="item" index="index" separator="," open="(" close=")">
+                #{item}
+            </foreach>
+        </if>
+    </select>
 </mapper>

+ 11 - 0
sop-common/src/main/java/com/qmth/sop/common/enums/WarnFieldEnum.java

@@ -30,4 +30,15 @@ public enum WarnFieldEnum {
     public String getDesc() {
         return desc;
     }
+
+    public static WarnFieldEnum findWarnFieldEnumByTitle(String title) {
+        WarnFieldEnum[] values = WarnFieldEnum.values();
+        for (WarnFieldEnum value : values) {
+            if (value.getTitle().equals(title)) {
+                return value;
+            }
+        }
+        return null;
+    }
+
 }