|
@@ -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;
|
|
|
}
|
|
|
|
|
|
/*
|