Browse Source

fix:sop监控统计 供应商预警走势

caozixuan 1 year ago
parent
commit
b1d40ea8e7

+ 65 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/analyze/sopWarn/CrmSupplierRelation.java

@@ -0,0 +1,65 @@
+package com.qmth.sop.business.bean.result.analyze.sopWarn;
+
+import io.swagger.annotations.ApiModelProperty;
+
+/**
+ * @Description: 派单和供应商关系
+ * @Author: CaoZixuan
+ * @Date: 2023-11-24
+ */
+public class CrmSupplierRelation {
+    @ApiModelProperty("服务单元id")
+    private Long serviceId;
+
+    @ApiModelProperty("派单号")
+    private String crmNo;
+
+    @ApiModelProperty("用户id")
+    private Long userId;
+
+    @ApiModelProperty("供应商id")
+    private Long supplierId;
+
+    @ApiModelProperty("供应商名称")
+    private String supplierName;
+
+    public Long getServiceId() {
+        return serviceId;
+    }
+
+    public void setServiceId(Long serviceId) {
+        this.serviceId = serviceId;
+    }
+
+    public String getCrmNo() {
+        return crmNo;
+    }
+
+    public void setCrmNo(String crmNo) {
+        this.crmNo = crmNo;
+    }
+
+    public Long getUserId() {
+        return userId;
+    }
+
+    public void setUserId(Long userId) {
+        this.userId = userId;
+    }
+
+    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;
+    }
+}

+ 36 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/analyze/sopWarn/SopSupplierAvgView.java

@@ -1,9 +1,45 @@
 package com.qmth.sop.business.bean.result.analyze.sopWarn;
 
+import io.swagger.annotations.ApiModelProperty;
+
+import java.math.BigDecimal;
+
 /**
  * @Description: sop供应商预警均值
  * @Author: CaoZixuan
  * @Date: 2023-11-12
  */
 public class SopSupplierAvgView {
+    @ApiModelProperty("供应商id")
+    private Long supplierId;
+
+    @ApiModelProperty("供应商名称")
+    private String supplierName;
+
+    @ApiModelProperty("预警均值 预警总数/派单数")
+    private BigDecimal rate;
+
+    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 BigDecimal getRate() {
+        return rate;
+    }
+
+    public void setRate(BigDecimal rate) {
+        this.rate = rate;
+    }
 }

+ 45 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/analyze/sopWarn/SopSupplierAvgViewTimes.java

@@ -0,0 +1,45 @@
+package com.qmth.sop.business.bean.result.analyze.sopWarn;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import java.util.List;
+
+/**
+ * @Description: 2023-11-24
+ * @Author: CaoZixuan
+ * @Date: 供应商预警在每天均值
+ */
+public class SopSupplierAvgViewTimes {
+    @ApiModelProperty("日期")
+    private Long time;
+
+    @ApiModelProperty("日期描述")
+    private String timeStr;
+
+    @ApiModelProperty("在该日期分布")
+    private List<SopSupplierAvgView> sopSupplierAvgViewInfo;
+
+    public Long getTime() {
+        return time;
+    }
+
+    public void setTime(Long time) {
+        this.time = time;
+    }
+
+    public String getTimeStr() {
+        return timeStr;
+    }
+
+    public void setTimeStr(String timeStr) {
+        this.timeStr = timeStr;
+    }
+
+    public List<SopSupplierAvgView> getSopSupplierAvgViewInfo() {
+        return sopSupplierAvgViewInfo;
+    }
+
+    public void setSopSupplierAvgViewInfo(List<SopSupplierAvgView> sopSupplierAvgViewInfo) {
+        this.sopSupplierAvgViewInfo = sopSupplierAvgViewInfo;
+    }
+}

+ 9 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/SopAnalyseMapper.java

@@ -2,6 +2,7 @@ package com.qmth.sop.business.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.qmth.sop.business.bean.dto.DataPermissionDto;
+import com.qmth.sop.business.bean.result.analyze.sopWarn.CrmSupplierRelation;
 import com.qmth.sop.business.bean.result.analyze.sopWarn.SopMonitor;
 import com.qmth.sop.business.entity.TBService;
 import com.qmth.sop.business.entity.TBSopInfo;
@@ -35,4 +36,12 @@ public interface SopAnalyseMapper extends BaseMapper<TBSopInfo> {
      * @return 监控数据集
      */
     List<SopMonitor> findSopMonitorListByServiceId(@Param("serviceId") Long serviceId);
+
+    /**
+     * 根据服务单元查询 派单和供应商关系
+     *
+     * @param serviceId 服务单元id
+     * @return 关系
+     */
+    List<CrmSupplierRelation> findCrmSupplierRelationByServiceId(@Param("serviceId") Long serviceId);
 }

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

@@ -2,6 +2,7 @@ package com.qmth.sop.business.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.qmth.sop.business.bean.result.analyze.sopWarn.SopSupplierAvgView;
+import com.qmth.sop.business.bean.result.analyze.sopWarn.SopSupplierAvgViewTimes;
 import com.qmth.sop.business.bean.result.analyze.sopWarn.SopWarnOverview;
 import com.qmth.sop.business.entity.TBService;
 import com.qmth.sop.business.entity.TBSopInfo;
@@ -24,7 +25,7 @@ public interface SopAnalyseService extends IService<TBSopInfo> {
     @Deprecated
     Map<Object, List<Map<String, Object>>> trend1(Long serviceId);
 
-    List<SopSupplierAvgView> trend(Long serviceId);
+    List<SopSupplierAvgViewTimes> trend(Long serviceId);
 
     List<Map<String, Object>> attendance(Long serviceId, SopAnalyseGroupEnum group);
 }

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

@@ -158,7 +158,7 @@ public interface TBCrmService extends IService<TBCrm> {
     void updateCrmStatus(String crmNo, CrmStatusEnum status);
 
     /**
-     * 根据服务单元id和地址查询复核的crm派单集合
+     * 根据服务单元id和地址查询符合的crm派单集合
      *
      * @param serviceUnitId 服务单元id
      * @param province      省份

+ 95 - 6
sop-business/src/main/java/com/qmth/sop/business/service/impl/SopAnalyseServiceImpl.java

@@ -4,20 +4,19 @@ import cn.hutool.core.date.DateUnit;
 import cn.hutool.core.date.DateUtil;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.qmth.sop.business.bean.dto.DataPermissionDto;
-import com.qmth.sop.business.bean.result.analyze.sopWarn.SopMonitor;
-import com.qmth.sop.business.bean.result.analyze.sopWarn.SopMonitorEnum;
-import com.qmth.sop.business.bean.result.analyze.sopWarn.SopSupplierAvgView;
-import com.qmth.sop.business.bean.result.analyze.sopWarn.SopWarnOverview;
+import com.qmth.sop.business.bean.result.analyze.sopWarn.*;
 import com.qmth.sop.business.entity.SysUser;
 import com.qmth.sop.business.entity.TBService;
 import com.qmth.sop.business.entity.TBSopInfo;
 import com.qmth.sop.business.mapper.SopAnalyseMapper;
 import com.qmth.sop.business.service.SopAnalyseService;
 import com.qmth.sop.business.service.SysUserService;
+import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.SopAnalyseGroupEnum;
 import com.qmth.sop.common.enums.SopAnalyseSortEnum;
 import com.qmth.sop.common.util.ServletUtil;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.time.DateFormatUtils;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
@@ -289,11 +288,101 @@ public class SopAnalyseServiceImpl extends ServiceImpl<SopAnalyseMapper, TBSopIn
      * ④(预警数)均值:由于供应商分配的项目数量不同,所以单从总数无法判定供应商对预警处理的力度。均值=预警总数/派单数;
      */
     @Override
-    public List<SopSupplierAvgView> trend(Long serviceId) {
+    public List<SopSupplierAvgViewTimes> trend(Long serviceId) {
+        List<CrmSupplierRelation> crmSupplierRelationList = this.baseMapper.findCrmSupplierRelationByServiceId(serviceId);
+        Map<Long, Set<String>> supplierCrmNumMap = new HashMap<>();
+        for (CrmSupplierRelation crmSupplierRelation : crmSupplierRelationList) {
+            String crmNo = crmSupplierRelation.getCrmNo();
+            Long supplierId = crmSupplierRelation.getSupplierId();
+            if (supplierCrmNumMap.containsKey(supplierId)) {
+                supplierCrmNumMap.get(supplierId).add(crmNo);
+            } else {
+                Set<String> crmNoSet = new HashSet<>();
+                crmNoSet.add(crmNo);
+                supplierCrmNumMap.put(supplierId, crmNoSet);
+            }
+        }
+
+
         List<SopMonitor> sopMonitorList = this.baseMapper.findSopMonitorListByServiceId(serviceId);
+        Date date = new Date();
+        List<Long> times = new ArrayList<>();
+        for (int i = 0; i < 7; i++) {
+            int v = i + 1;
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(date);
+            calendar.add(Calendar.DAY_OF_MONTH, -v);
+            calendar.set(Calendar.HOUR_OF_DAY, 24);
+            calendar.set(Calendar.MINUTE, 0);
+            calendar.set(Calendar.SECOND, 0);
+            calendar.set(Calendar.MILLISECOND, 0);
+            Long endTime = calendar.getTimeInMillis() - 1;
+            times.add(endTime);
+        }
+        // 7天涉及到的所有供应商信息 id - name 补充零用
+        Map<Long, String> supplierInfoMap = new HashMap<>();
+        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<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());
+
+                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);
+
+                        SopSupplierAvgView sopSupplierAvgView = new SopSupplierAvgView();
+                        sopSupplierAvgView.setSupplierId(supplierId);
+                        sopSupplierAvgView.setRate(rate);
+                        sopSupplierAvgView.setSupplierName(supplierName);
+                        sopSupplierAvgViewList.add(sopSupplierAvgView);
+                        if (!supplierInfoMap.containsKey(supplierId)) {
+                            supplierInfoMap.put(supplierId, supplierName);
+                        }
+                    }
 
-        return null;
+                }
+            }
+
+            SopSupplierAvgViewTimes sopSupplierAvgViewTimes = new SopSupplierAvgViewTimes();
+            sopSupplierAvgViewTimes.setTime(time);
+            sopSupplierAvgViewTimes.setTimeStr(DateFormatUtils.format(time, SystemConstant.DEFAULT_DATE_DAY_PATTERN));
+            if (CollectionUtils.isNotEmpty(sopSupplierAvgViewList)) {
+                sopSupplierAvgViewTimes.setSopSupplierAvgViewInfo(sopSupplierAvgViewList);
+            }
+            result.add(sopSupplierAvgViewTimes);
 
+            // 补零
+            for (SopSupplierAvgViewTimes supplierAvgViewTimes : result) {
+                List<SopSupplierAvgView> list = supplierAvgViewTimes.getSopSupplierAvgViewInfo();
+                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());
+                for (Long supplierId : needFillIdList) {
+                    SopSupplierAvgView view = new SopSupplierAvgView();
+                    view.setRate(new BigDecimal(0));
+                    view.setSupplierId(supplierId);
+                    view.setSupplierName(supplierInfoMap.get(supplierId));
+                    list.add(view);
+                }
+            }
+        }
+        return result;
     }
 
     /*

+ 33 - 0
sop-business/src/main/resources/mapper/SopAnalyseMapper.xml

@@ -200,4 +200,37 @@
             </if>
         </where>
     </select>
+    <select id="findCrmSupplierRelationByServiceId"
+            resultType="com.qmth.sop.business.bean.result.analyze.sopWarn.CrmSupplierRelation">
+        SELECT
+            cu.service_id AS serviceId,
+            cu.crm_no AS crmNo,
+            cu.user_id AS userId,
+            IFNULL(ss.id, 0) AS supplierId,
+            IFNULL(ss.name, '大区经理兼任') AS supplierName
+        FROM
+            (SELECT
+                 service_id, crm_no, user_id
+             FROM
+                 t_b_user_archives_allocation
+             UNION ALL SELECT
+                           service_id, crm_no, region_coordinator_id AS user_id
+             FROM
+                 t_b_crm) cu
+                LEFT JOIN
+            sys_user su ON cu.user_id = su.id
+                LEFT JOIN
+            t_b_user_archives tbua ON su.mobile_number = tbua.mobile_number
+                LEFT JOIN
+            t_b_user_archives_supplier tbuas ON tbuas.user_archives_id = tbua.id
+                LEFT JOIN
+            sys_supplier ss ON ss.id = tbuas.supplier_id
+                LEFT JOIN
+            t_b_crm tbc ON tbc.crm_no = cu.crm_no
+        <where>
+            <if test="serviceId != null">
+                AND cu.service_id = #{serviceId}
+            </if>
+        </where>
+    </select>
 </mapper>