|
@@ -1,6 +1,5 @@
|
|
|
package com.qmth.sop.business.service.impl;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -8,34 +7,34 @@ import com.qmth.sop.business.bean.dto.DataPermissionDto;
|
|
|
import com.qmth.sop.business.bean.result.TBCrmResult;
|
|
|
import com.qmth.sop.business.bean.result.UserArchivesAllocationResult;
|
|
|
import com.qmth.sop.business.bean.result.UserArchivesAllocationSubTotalResult;
|
|
|
-import com.qmth.sop.business.entity.SysDevice;
|
|
|
import com.qmth.sop.business.entity.SysUser;
|
|
|
import com.qmth.sop.business.entity.TBService;
|
|
|
import com.qmth.sop.business.mapper.ServiceAnalyseMapper;
|
|
|
import com.qmth.sop.business.service.ServiceAnalyseService;
|
|
|
-import com.qmth.sop.business.service.SysDeviceService;
|
|
|
import com.qmth.sop.business.service.SysUserService;
|
|
|
+import com.qmth.sop.business.service.TBSopInfoService;
|
|
|
import com.qmth.sop.business.service.TBUserArchivesSupplierService;
|
|
|
import com.qmth.sop.common.enums.CrmStatusEnum;
|
|
|
-import com.qmth.sop.common.enums.DeviceStatusEnum;
|
|
|
-import com.qmth.sop.common.enums.InOutTypeEnum;
|
|
|
import com.qmth.sop.common.util.ServletUtil;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
public class ServiceAnalyseServiceImpl extends ServiceImpl<ServiceAnalyseMapper, TBService> implements ServiceAnalyseService {
|
|
|
|
|
|
@Resource
|
|
|
- SysDeviceService sysDeviceService;
|
|
|
+ TBSopInfoService tbSopInfoService;
|
|
|
|
|
|
@Resource
|
|
|
TBUserArchivesSupplierService tbUserArchivesSupplierService;
|
|
|
+
|
|
|
@Resource
|
|
|
private SysUserService sysUserService;
|
|
|
|
|
@@ -58,26 +57,43 @@ public class ServiceAnalyseServiceImpl extends ServiceImpl<ServiceAnalyseMapper,
|
|
|
public Map<String, Object> overview(Long serviceUnitId) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
List<Map<String, Object>> list = this.baseMapper.projectProgress(serviceUnitId);
|
|
|
- int crmNum = list.stream().collect(Collectors.groupingBy(map1 -> map1.get("crm_no"))).size();
|
|
|
- final int[] finish = {0};
|
|
|
- list.stream().collect(Collectors.groupingBy(map1 -> map1.get("crm_no")))
|
|
|
- .forEach((k1, v1) -> {
|
|
|
- if (v1.stream().anyMatch(map2 -> map2.get("sop_no") != null) &&v1.stream().filter(map2 -> map2.get("sop_no") != null).count() == v1.stream().filter(map2 -> "FINISH".equals(map2.get("status"))).count()) {
|
|
|
- finish[0] = finish[0] + 1;
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- map.put("projectProgress", (crmNum==0?0:finish[0]) * 100 / crmNum);
|
|
|
- map.put("equipmentOutboundTotal", this.baseMapper.equipmentOutboundTotal(serviceUnitId));
|
|
|
- //Integer outboundTotal = sysDeviceService.count(new LambdaQueryWrapper<SysDevice>().eq(SysDevice::getBound, InOutTypeEnum.OUT));
|
|
|
- int totalDevices = sysDeviceService.count(new LambdaQueryWrapper<SysDevice>().eq(SysDevice::getStatus, DeviceStatusEnum.NORMAL));
|
|
|
- map.put("equipmentOccupancyRate", totalDevices == 0 ? 0 :((Integer) map.get("equipmentOutboundTotal")) * 100 / totalDevices);
|
|
|
- List<UserArchivesAllocationResult> userArchivesAllocationResults = this.baseMapper.findCrmAllocation(serviceUnitId, null, null);
|
|
|
- Integer distributed = userArchivesAllocationResults.stream().mapToInt(UserArchivesAllocationResult::getDistributed).sum();
|
|
|
- map.put("servicePersonnelTotal",distributed);
|
|
|
+ int finishCount = 0, size = 0;
|
|
|
+ if (!CollectionUtils.isEmpty(list)) {
|
|
|
+ size = list.size();
|
|
|
+ finishCount = (int) list.stream().filter(s -> Objects.nonNull(s.get("status")) && s.get("status").equals("FINISH")).count();
|
|
|
+ }
|
|
|
+ BigDecimal sizeBig = BigDecimal.valueOf(size), percent = BigDecimal.valueOf(100),
|
|
|
+ finishCompleteRate = BigDecimal.valueOf(finishCount);
|
|
|
+ finishCompleteRate = size > 0 ? finishCompleteRate.divide(sizeBig, 2, BigDecimal.ROUND_HALF_UP).multiply(percent).setScale(2, BigDecimal.ROUND_HALF_UP) : sizeBig;
|
|
|
+ map.put("projectProgress", finishCompleteRate);
|
|
|
+ List<Map<String, Object>> deviceMap = this.baseMapper.equipmentOutboundTotal(serviceUnitId);
|
|
|
+ map.put("equipmentOutboundTotal", !CollectionUtils.isEmpty(deviceMap) ? Integer.parseInt(deviceMap.get(0).get("outs").toString()) : 0);
|
|
|
+ int totalDevices = !CollectionUtils.isEmpty(deviceMap) ? Integer.parseInt(deviceMap.get(0).get("deviceSum").toString()) : 0;
|
|
|
+ BigDecimal totalDevicesBig = BigDecimal.valueOf(totalDevices),
|
|
|
+ OutboundTotal = BigDecimal.valueOf(Integer.parseInt(map.get("equipmentOutboundTotal").toString())),
|
|
|
+ deviceRate = totalDevices > 0 ? OutboundTotal.divide(totalDevicesBig, 2, BigDecimal.ROUND_HALF_UP).multiply(percent).setScale(2, BigDecimal.ROUND_HALF_UP) : OutboundTotal;
|
|
|
+ map.put("equipmentOccupancyRate", deviceRate);
|
|
|
+ List<Map<String, Object>> sopPassageMap = tbSopInfoService.findSopPassage(serviceUnitId);
|
|
|
+ Integer distributed = 0;
|
|
|
+ if (!CollectionUtils.isEmpty(sopPassageMap)) {
|
|
|
+ for (Map m : sopPassageMap) {
|
|
|
+ Integer regionUserSum = Objects.nonNull(m.get("regionUserSum")) ? Integer.parseInt(m.get("regionUserSum").toString()) : 0;
|
|
|
+ Integer engineerUserSum = Objects.nonNull(m.get("engineerUserSum")) ? Integer.parseInt(m.get("engineerUserSum").toString()) : 0;
|
|
|
+ distributed = distributed + regionUserSum + engineerUserSum;
|
|
|
+ String assistantEngineerUserId = Objects.nonNull(m.get("assistantEngineerUserIds")) ? m.get("assistantEngineerUserIds").toString() : null;
|
|
|
+ if (Objects.nonNull(assistantEngineerUserId)) {
|
|
|
+ String[] strs = assistantEngineerUserId.split(",");
|
|
|
+ distributed = distributed + strs.length;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put("servicePersonnelTotal", distributed);
|
|
|
//认证有效的人员总数
|
|
|
int totalUserArchives = tbUserArchivesSupplierService.countAuthentication();
|
|
|
- map.put("sitePersonnelOccupancyRate", totalUserArchives == 0 ? 0 : distributed * 100 / totalUserArchives);
|
|
|
+ BigDecimal totalUserBig = BigDecimal.valueOf(totalUserArchives),
|
|
|
+ userServicesTotal = BigDecimal.valueOf(distributed),
|
|
|
+ userRate = totalUserArchives > 0 ? userServicesTotal.divide(totalUserBig, 2, BigDecimal.ROUND_HALF_UP).multiply(percent).setScale(2, BigDecimal.ROUND_HALF_UP) : userServicesTotal;
|
|
|
+ map.put("sitePersonnelOccupancyRate", userRate);
|
|
|
return map;
|
|
|
}
|
|
|
|