소스 검색

Merge remote-tracking branch 'origin/dev_v1.0.0' into dev_v1.0.0

# Conflicts:
#	sop-business/src/main/java/com/qmth/sop/business/mapper/QualityAnalyseMapper.java
#	sop-business/src/main/java/com/qmth/sop/business/service/impl/QualityAnalyseServiceImpl.java
wangliang 1 년 전
부모
커밋
714d17e4e4

+ 4 - 3
sop-api/src/main/java/com/qmth/sop/server/api/QualityAnalyseController.java

@@ -1,7 +1,9 @@
 package com.qmth.sop.server.api;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.google.gson.JsonObject;
 import com.qmth.boot.api.annotation.Aac;
 import com.qmth.boot.api.constant.ApiConstant;
 import com.qmth.sop.business.bean.result.TBQualityProblemApplyResult;
@@ -98,11 +100,10 @@ public class QualityAnalyseController {
      */
     @ApiOperation(value = "影响度/归因")
     @RequestMapping(value = "/influence", method = RequestMethod.POST)
-    @ApiResponses({@ApiResponse(code = 200, message = "影响度/归因", response = Map.class)})
+    @ApiResponses({@ApiResponse(code = 200, message = "影响度/归因", response = JSONObject.class)})
     public Result influence(@ApiParam(value = "服务单元", required = true) @RequestParam Long serviceUnitId,
                             @ApiParam(value = "影响度分组", required = true) @RequestParam QualityAnalyseGroupEnum group) {
-        Map<String, Map<String, Object>> map = qualityAnalyseService.influence(serviceUnitId, group);
-        return ResultUtil.ok(map);
+        return ResultUtil.ok(qualityAnalyseService.influence(serviceUnitId, group));
     }
 
     //* ②【数据下钻】点击影响度行数据,可显示影响度下质量问题查询明细,筛选条件为:年度+服务单元+非“不是问题”+影响度;

+ 1 - 2
sop-api/src/main/java/com/qmth/sop/server/api/ServiceAnalyseController.java

@@ -70,8 +70,7 @@ public class ServiceAnalyseController {
     @RequestMapping(value = "/overview", method = RequestMethod.POST)
     @ApiResponses({@ApiResponse(code = 200, message = "服务单元概览", response = Map.class)})
     public Result overview(@ApiParam(value = "服务单元", required = true) @RequestParam Long serviceUnitId) {
-        Map<String, Object> map = serviceAnalyseService.overview(serviceUnitId);
-        return ResultUtil.ok(map);
+        return ResultUtil.ok(serviceAnalyseService.overview(serviceUnitId));
     }
 
     /**

+ 67 - 0
sop-business/src/main/java/com/qmth/sop/business/bean/result/analyze/ServiceUnitOverview.java

@@ -0,0 +1,67 @@
+package com.qmth.sop.business.bean.result.analyze;
+
+import io.swagger.annotations.ApiModelProperty;
+
+import java.math.BigDecimal;
+
+/**
+ * @Description: 服务单元概况
+ * @Author: CaoZixuan
+ * @Date: 2023-11-18
+ */
+public class ServiceUnitOverview {
+    @ApiModelProperty("项目执行进度")
+    private BigDecimal projectProgress;
+
+    @ApiModelProperty("设备出库总量")
+    private Integer equipmentOutboundTotal;
+
+    @ApiModelProperty("设备占用率")
+    private BigDecimal equipmentOccupancyRate;
+
+    @ApiModelProperty("在服务人员总数")
+    private Integer servicePersonnelTotal;
+
+    @ApiModelProperty("现场人员占用率")
+    private BigDecimal sitePersonnelOccupancyRate;
+
+    public BigDecimal getProjectProgress() {
+        return projectProgress;
+    }
+
+    public void setProjectProgress(BigDecimal projectProgress) {
+        this.projectProgress = projectProgress;
+    }
+
+    public Integer getEquipmentOutboundTotal() {
+        return equipmentOutboundTotal;
+    }
+
+    public void setEquipmentOutboundTotal(Integer equipmentOutboundTotal) {
+        this.equipmentOutboundTotal = equipmentOutboundTotal;
+    }
+
+    public BigDecimal getEquipmentOccupancyRate() {
+        return equipmentOccupancyRate;
+    }
+
+    public void setEquipmentOccupancyRate(BigDecimal equipmentOccupancyRate) {
+        this.equipmentOccupancyRate = equipmentOccupancyRate;
+    }
+
+    public Integer getServicePersonnelTotal() {
+        return servicePersonnelTotal;
+    }
+
+    public void setServicePersonnelTotal(Integer servicePersonnelTotal) {
+        this.servicePersonnelTotal = servicePersonnelTotal;
+    }
+
+    public BigDecimal getSitePersonnelOccupancyRate() {
+        return sitePersonnelOccupancyRate;
+    }
+
+    public void setSitePersonnelOccupancyRate(BigDecimal sitePersonnelOccupancyRate) {
+        this.sitePersonnelOccupancyRate = sitePersonnelOccupancyRate;
+    }
+}

+ 9 - 6
sop-business/src/main/java/com/qmth/sop/business/mapper/QualityAnalyseMapper.java

@@ -7,6 +7,8 @@ import com.qmth.sop.business.bean.dto.DataPermissionDto;
 import com.qmth.sop.business.bean.result.TBQualityProblemApplyResult;
 import com.qmth.sop.business.entity.TBQualityProblemApply;
 import com.qmth.sop.business.entity.TBService;
+import com.qmth.sop.common.enums.InfluenceDegreeEnum;
+import com.qmth.sop.common.enums.QualityProblemReasonEnum;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -17,21 +19,22 @@ import java.util.Map;
  * </p>
  *
  * @author dhshu
+ *
  */
 public interface QualityAnalyseMapper extends BaseMapper<TBQualityProblemApply> {
 
 
     IPage<TBQualityProblemApplyResult> detail(Page<Object> objectPage, @Param("serviceUnitId") Long serviceUnitId, @Param("degree") String degree);
 
-    List<Map<String, Object>> radar(@Param("serviceUnitId") Long serviceUnitId, @Param("supplierId") Long supplierId);
+    List<Map<String, Object>> radar(@Param("serviceUnitId")Long serviceUnitId,@Param("supplierId") Long supplierId);
 
-    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);
 
-    Double progress(@Param("serviceUnitId") Long serviceUnitId);
+    Double progress( @Param("serviceUnitId")Long serviceUnitId);
 
-    List<Map<String, Object>> influence(@Param("serviceUnitId") Long serviceUnitId);
+    List<Map<String, Object>> influence( @Param("serviceUnitId")Long serviceUnitId);
 
-    List<Map<String, Object>> pie(@Param("serviceUnitId") Long serviceUnitId, @Param("supplierId") Long supplierId);
+    List<Map<String, Object>> pie(@Param("serviceUnitId")Long serviceUnitId,@Param("supplierId") Long supplierId);
 
-    IPage<TBQualityProblemApplyResult> influenceDetail(Page<Object> tPage, @Param("serviceUnitId") Long serviceUnitId, @Param("supplierId") Long supplierId, @Param("region_id") Long region_id, @Param("influenceDegree") String influenceDegree, @Param("reason") String reason);
+    IPage<TBQualityProblemApplyResult> influenceDetail(Page<Object> tPage,@Param("serviceUnitId") Long serviceUnitId,@Param("supplierId") Long supplierId,@Param("region_id") Long region_id,@Param("influenceDegree") String influenceDegree,@Param("reason") String reason);
 }

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

@@ -1,8 +1,10 @@
 package com.qmth.sop.business.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.google.gson.JsonObject;
 import com.qmth.sop.business.bean.result.TBQualityProblemApplyResult;
 import com.qmth.sop.business.entity.TBQualityProblemApply;
 import com.qmth.sop.business.entity.TBService;
@@ -19,7 +21,7 @@ public interface QualityAnalyseService extends IService<TBQualityProblemApply> {
 
     Double progress(Long serviceUnitId);
 
-    Map<String,Map<String, Object>> influence(Long serviceUnitId, QualityAnalyseGroupEnum group);
+    JSONObject influence(Long serviceUnitId, QualityAnalyseGroupEnum group);
 
     Map<String, Object> pie(Long serviceUnitId);
 

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

@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 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.bean.result.analyze.ServiceUnitOverview;
 import com.qmth.sop.business.entity.TBService;
 
 import java.util.List;
@@ -14,7 +15,10 @@ import java.util.Map;
 public interface ServiceAnalyseService extends IService<TBService> {
     List<TBService> list(Long startTime, Long endTime);
 
-    Map<String, Object> overview(Long serviceUnitId);
+    @Deprecated
+    Map<String, Object> overview1(Long serviceUnitId);
+
+    ServiceUnitOverview overview(Long serviceUnitId);
 
     Map<String, Object> supplier(Long serviceUnitId);
 

+ 55 - 34
sop-business/src/main/java/com/qmth/sop/business/service/impl/QualityAnalyseServiceImpl.java

@@ -3,6 +3,7 @@ package com.qmth.sop.business.service.impl;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.alibaba.fastjson.JSONObject;
 import com.qmth.sop.business.bean.dto.DataPermissionDto;
 import com.qmth.sop.business.bean.result.TBQualityProblemApplyResult;
 import com.qmth.sop.business.entity.SysUser;
@@ -29,12 +30,11 @@ public class QualityAnalyseServiceImpl extends ServiceImpl<QualityAnalyseMapper,
 
     @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);
     }
 
 
@@ -44,31 +44,53 @@ public class QualityAnalyseServiceImpl extends ServiceImpl<QualityAnalyseMapper,
     }
 
     @Override
-    public Map<String, Map<String, Object>> influence(Long serviceUnitId, QualityAnalyseGroupEnum group) {
+    public JSONObject influence(Long serviceUnitId, QualityAnalyseGroupEnum group) {
         List<Map<String, Object>> influence = this.baseMapper.influence(serviceUnitId);
-        Map<String, Map<String, Object>> result = new HashMap<>();
+//        Map<String, Map<String, Object>> result = new HashMap<>();
+        JSONObject result=new JSONObject();
+
         if (group.equals(QualityAnalyseGroupEnum.INFLUENCE_REGION)) {
-            influence.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<>();
-                v.stream().filter(map1 -> map1.get("Influence_degree") != null).collect(Collectors.groupingBy(map1 -> map1.get("Influence_degree"))).forEach((k1, v1) -> map.put(k1.toString(), v1.size()));
+            influence.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<>();
+                JSONObject map=new JSONObject();
+                v.stream().filter(map1->map1.get("Influence_degree")!=null).collect(Collectors.groupingBy(map1 -> map1.get("Influence_degree"))).forEach((k1, v1) -> {
+                    map.put(k1.toString(), v1.size());
+                });
+                map.put("id",v.get(0).get("region_id"));
                 result.put(k.toString(), map);
             });
         } else if (group.equals(QualityAnalyseGroupEnum.INFLUENCE_SUPPLIER)) {
-            influence.stream().filter(map -> map.get("Influence_degree") != null).collect(Collectors.groupingBy(map -> map.get("Influence_degree"))).forEach((k, v) -> {
-                Map<String, Object> map = new HashMap<>();
-                v.stream().filter(map1 -> map1.get("supplier") != null).collect(Collectors.groupingBy(map1 -> map1.get("supplier"))).forEach((k1, v1) -> map.put(k1.toString(), v1.size()));
+            influence.stream().filter(map->map.get("Influence_degree")!=null).collect(Collectors.groupingBy(map -> map.get("Influence_degree"))).forEach((k, v) -> {
+                JSONObject map=new JSONObject();
+
+                v.stream().filter(map1->map1.get("supplier")!=null).collect(Collectors.groupingBy(map1 -> map1.get("supplier"))).forEach((k1, v1) -> {
+                    JSONObject map1=new JSONObject();
+                    map1.put("value",v1.size());
+                    map1.put("id",v.get(0).get("supplier_id"));
+                    map.put(k1.toString(), map1);
+                });
                 result.put(k.toString(), map);
             });
         } else if (group.equals(QualityAnalyseGroupEnum.REASON_REGION)) {
-            influence.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<>();
-                v.stream().filter(map1 -> map1.get("reason") != null).collect(Collectors.groupingBy(map1 -> map1.get("reason"))).forEach((k1, v1) -> map.put(k1.toString(), v1.size()));
+            influence.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<>();
+                JSONObject map=new JSONObject();
+                v.stream().filter(map1->map1.get("Influence_degree")!=null).collect(Collectors.groupingBy(map1 -> map1.get("Influence_degree"))).forEach((k1, v1) -> {
+                    map.put(k1.toString(), v1.size());
+                });
+                map.put("id",v.get(0).get("region_id"));
                 result.put(k.toString(), map);
             });
         } else if (group.equals(QualityAnalyseGroupEnum.REASON_SUPPLIER)) {
-            influence.stream().filter(map -> map.get("reason") != null).collect(Collectors.groupingBy(map -> map.get("reason"))).forEach((k, v) -> {
-                Map<String, Object> map = new HashMap<>();
-                v.stream().filter(map1 -> map1.get("supplier") != null).collect(Collectors.groupingBy(map1 -> map1.get("supplier"))).forEach((k1, v1) -> map.put(k1.toString(), v1.size()));
+            influence.stream().filter(map->map.get("reason")!=null).collect(Collectors.groupingBy(map -> map.get("reason"))).forEach((k, v) -> {
+                JSONObject map=new JSONObject();
+
+                v.stream().filter(map1->map1.get("supplier")!=null).collect(Collectors.groupingBy(map1 -> map1.get("supplier"))).forEach((k1, v1) -> {
+                    JSONObject map1=new JSONObject();
+                    map1.put("value",v1.size());
+                    map1.put("id",v.get(0).get("supplier_id"));
+                    map.put(k1.toString(), map1);
+                });
                 result.put(k.toString(), map);
             });
         }
@@ -80,49 +102,48 @@ public class QualityAnalyseServiceImpl extends ServiceImpl<QualityAnalyseMapper,
     public Map<String, Object> pie(Long serviceUnitId) {
         List<Map<String, Object>> pie = this.baseMapper.pie(serviceUnitId, null);
         Map<String, Object> result = new HashMap<>();
-        pie.stream().filter(map1 -> map1.get("Influence_degree") != null).collect(Collectors.groupingBy(map -> map.get("Influence_degree"))).forEach((k, v) -> result.put(k.toString(), v.stream().filter(map1 -> map1.get("count") != null).mapToLong(map1 -> (long) map1.get("count")).sum()));
+        pie.stream().filter(map1->map1.get("Influence_degree")!=null).collect(Collectors.groupingBy(map -> map.get("Influence_degree"))).forEach((k, v) -> result.put(k.toString(),v.stream().filter(map1->map1.get("count")!=null).mapToLong(map1-> (long) map1.get("count")).sum()));
         return result;
     }
 
     @Override
     public Map<String, Map<String, Object>> radar(Long serviceUnitId, QualityAnalyseGroupEnum group) {
+
+
         List<Map<String, Object>> radar = this.baseMapper.radar(serviceUnitId, null);
         Map<String, Map<String, Object>> result = new HashMap<>();
-        radar.stream().filter(map1 -> map1.get("reason") != null).collect(Collectors.groupingBy(map -> map.get("reason"))).forEach((k, v) -> {
-            Map<String, Object> countMap = new HashMap<>(), map = new HashMap<>();
-            countMap.put(k.toString(), v.stream().filter(map1 -> map1.get("count") != null).mapToLong(map1 -> (long) map1.get("count")).sum());
-            if (result.containsKey("all")) {
-                map = result.get("all");
-                map.put(k.toString(), countMap.get(k.toString()));
-            } else {
-                map.put(k.toString(), countMap.get(k.toString()));
-            }
+        radar.stream().filter(map1->map1.get("reason")!=null).collect(Collectors.groupingBy(map -> map.get("reason"))).forEach((k, v) -> {
+            Map<String, Object> map = new HashMap<>();
+            map.put(k.toString(),v.stream().filter(map1->map1.get("count")!=null).mapToLong(map1-> (long) map1.get("count")).sum());
             result.put("all", map);
         });
 
+
         if (group.equals(QualityAnalyseGroupEnum.REASON_REGION)) {
-            radar.stream().filter(map1 -> map1.get("region_name") != null).collect(Collectors.groupingBy(map -> map.get("region_name"))).forEach((k, v) -> {
+
+            radar.stream().filter(map1->map1.get("region_name")!=null).collect(Collectors.groupingBy(map -> map.get("region_name"))).forEach((k, v) -> {
                 Map<String, Object> z = new HashMap<>();
-                v.stream().filter(map1 -> map1.get("reason") != null).collect(Collectors.groupingBy(map2 -> map2.get("reason"))).forEach((k1, v1) -> z.put(k1.toString(), v1.stream().filter(map1 -> map1.get("count") != null).mapToLong(map1 -> (long) map1.get("count")).sum()));
+                v.stream().filter(map1->map1.get("reason")!=null).collect(Collectors.groupingBy(map2 -> map2.get("reason"))).forEach((k1, v1) -> z.put(k1.toString(),v1.stream().filter(map1->map1.get("count")!=null).mapToLong(map1-> (long) map1.get("count")).sum()));
                 result.put(k.toString(), z);
             });
         } else if (group.equals(QualityAnalyseGroupEnum.REASON_SUPPLIER)) {
-            radar.stream().filter(map1 -> map1.get("supplier") != null).collect(Collectors.groupingBy(map -> map.get("supplier"))).forEach((k, v) -> {
+            radar.stream().filter(map1->map1.get("supplier")!=null).collect(Collectors.groupingBy(map -> map.get("supplier"))).forEach((k, v) -> {
                 Map<String, Object> z = new HashMap<>();
-                v.stream().filter(map1 -> map1.get("reason") != null).collect(Collectors.groupingBy(map2 -> map2.get("reason"))).forEach((k1, v1) -> z.put(k1.toString(), v1.stream().filter(map1 -> map1.get("count") != null).mapToLong(map1 -> (long) map1.get("count")).sum()));
+                v.stream().filter(map1->map1.get("reason")!=null).collect(Collectors.groupingBy(map2 -> map2.get("reason"))).forEach((k1, v1) -> z.put(k1.toString(),v1.stream().filter(map1->map1.get("count")!=null).mapToLong(map1-> (long) map1.get("count")).sum()));
                 result.put(k.toString(), z);
             });
         }
         return result;
+
     }
 
     @Override
-    public IPage<TBQualityProblemApplyResult> detail(Page<Object> objectPage, Long serviceUnitId, InfluenceDegreeEnum degree) {
-        return this.baseMapper.detail(objectPage, serviceUnitId, Objects.nonNull(degree) ? degree.name() : null);
+    public IPage<TBQualityProblemApplyResult> detail(Page<Object> objectPage, Long serviceUnitId,InfluenceDegreeEnum degree) {
+        return this.baseMapper.detail(objectPage, serviceUnitId, Objects.nonNull(degree)?degree.toString():null );
     }
 
     @Override
     public IPage<TBQualityProblemApplyResult> influence(Page<Object> tPage, Long serviceUnitId, Long supplierId, Long region_id, InfluenceDegreeEnum influenceDegree, QualityProblemReasonEnum reason) {
-        return this.baseMapper.influenceDetail(tPage, serviceUnitId, supplierId, region_id, Objects.nonNull(influenceDegree) ? influenceDegree.name() : null, Objects.nonNull(reason) ? reason.name() : null);
+        return this.baseMapper.influenceDetail(tPage, serviceUnitId, supplierId,region_id,  Objects.nonNull(influenceDegree)?influenceDegree.toString():null,  Objects.nonNull(reason)?reason.toString():null);
     }
 }

+ 127 - 6
sop-business/src/main/java/com/qmth/sop/business/service/impl/ServiceAnalyseServiceImpl.java

@@ -1,5 +1,6 @@
 package com.qmth.sop.business.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -7,34 +8,48 @@ 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.SysUser;
-import com.qmth.sop.business.entity.TBService;
+import com.qmth.sop.business.bean.result.analyze.ServiceUnitOverview;
+import com.qmth.sop.business.entity.*;
 import com.qmth.sop.business.mapper.ServiceAnalyseMapper;
 import com.qmth.sop.business.service.*;
 import com.qmth.sop.common.contant.SystemConstant;
 import com.qmth.sop.common.enums.CrmStatusEnum;
+import com.qmth.sop.common.enums.DeviceStatusEnum;
+import com.qmth.sop.common.enums.ExceptionResultEnum;
+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.math.RoundingMode;
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class ServiceAnalyseServiceImpl extends ServiceImpl<ServiceAnalyseMapper, TBService> implements ServiceAnalyseService {
 
     @Resource
-    TBSopInfoService tbSopInfoService;
+    private TBSopInfoService tbSopInfoService;
 
     @Resource
-    TBUserArchivesSupplierService tbUserArchivesSupplierService;
+    private TBUserArchivesSupplierService tbUserArchivesSupplierService;
 
     @Resource
     private SysUserService sysUserService;
 
     @Resource
-    TBUserArchivesAllocationService tbUserArchivesAllocationService;
+    private TBUserArchivesAllocationService tbUserArchivesAllocationService;
+
+    @Resource
+    private TBCrmService tbCrmService;
+
+    @Resource
+    private TBDeviceInOutService tbDeviceInOutService;
+
+    @Resource
+    private SysDeviceService sysDeviceService;
 
     @Override
     public List<TBService> list(Long startTime, Long endTime) {
@@ -51,8 +66,9 @@ public class ServiceAnalyseServiceImpl extends ServiceImpl<ServiceAnalyseMapper,
      * ④在服务人员总数:在执行的SOP现场服务人员数量,包括助理工程师、实施工程师、区域协调人;
      * ⑤现场人员占用率:(在服务人员总数÷认证有效的在服务人员总数)×100%;
      */
+    @Deprecated
     @Override
-    public Map<String, Object> overview(Long serviceUnitId) {
+    public Map<String, Object> overview1(Long serviceUnitId) {
         Map<String, Object> map = new HashMap<>();
         List<Map<String, Object>> list = this.baseMapper.projectProgress(serviceUnitId);
         int finishCount = 0, size = 0;
@@ -106,6 +122,111 @@ public class ServiceAnalyseServiceImpl extends ServiceImpl<ServiceAnalyseMapper,
         return map;
     }
 
+    /**
+     * 4.服务单元概览
+     * ①项目执行进度=服务单元下已完成的派单(研究生派单下SOP已完结;教务处派单下已有完成的SOP,无在执行的SOP。可能存在教务处多个SOP之间空窗期导致数据的误差,这个指标允许少量误差存在);
+     * ②设备出库总量:当前服务单元下已出库且尚未入库的设备总量;
+     * ③设备占用率:(设备出库总量÷正常设备总量)×100%;
+     * ④在服务人员总数:在执行的SOP现场服务人员数量,包括助理工程师、实施工程师、区域协调人;
+     * ⑤现场人员占用率:(在服务人员总数÷认证有效的在服务人员总数)×100%;
+     */
+    @Override
+    public ServiceUnitOverview overview(Long serviceUnitId) {
+        ServiceUnitOverview result = new ServiceUnitOverview();
+        BigDecimal percent = new BigDecimal(100);
+        // -- 项目执行进度 --
+        List<TBCrm> tbCrmDatasource = tbCrmService.list(new QueryWrapper<TBCrm>().lambda()
+                .eq(TBCrm::getServiceId, serviceUnitId)
+                .eq(TBCrm::getEnable,true));
+        int crmFinishCount = (int) tbCrmDatasource.stream().filter(e -> CrmStatusEnum.FINISH.equals(e.getStatus())).count();
+        int crmTotalCount = tbCrmDatasource.size();
+        BigDecimal projectProgress = new BigDecimal(0);
+        if (crmTotalCount > 0){
+            projectProgress = new BigDecimal(crmFinishCount).divide(new BigDecimal(crmTotalCount), 2, RoundingMode.HALF_UP).multiply(percent);
+        }
+
+        // -- 设备出库总量 -- (可以知道是哪个设备没入库)
+        List<TBDeviceInOut> tbDeviceInOutDatasource = tbDeviceInOutService.list(new QueryWrapper<TBDeviceInOut>().lambda().eq(TBDeviceInOut::getServiceId, serviceUnitId));
+
+        // 设备入库map -> (设备编号,入库次数)
+        Map<String, Integer> deviceInMap = tbDeviceInOutDatasource
+                .stream()
+                .filter(e -> InOutTypeEnum.IN.equals(e.getType()))
+                .collect(Collectors.toMap(TBDeviceInOut::getDeviceNo, e -> 1, Integer::sum));
+
+        // 设备出库map -> (设备编号,出库次数)
+        int equipmentOutboundTotal = 0;
+        Map<String, Integer> deviceOutMap = tbDeviceInOutDatasource
+                .stream()
+                .filter(e -> InOutTypeEnum.OUT.equals(e.getType()))
+                .collect(Collectors.toMap(TBDeviceInOut::getDeviceNo, e -> 1, Integer::sum));
+
+        for (String deviceNo : deviceOutMap.keySet()) {
+            // 出库次数
+            Integer outCount = deviceOutMap.get(deviceNo);
+            Integer inCount = 0;
+            if (deviceInMap.containsKey(deviceNo)) {
+                inCount = deviceInMap.get(deviceNo);
+            }
+            if (inCount > outCount) {
+                throw ExceptionResultEnum.ERROR.exception(String.format("在服务单元下,设备[%s]入库次数比出库次数多异常", deviceNo));
+            }
+            outCount = outCount - inCount;
+            if (outCount > 1) {
+                throw ExceptionResultEnum.ERROR.exception(String.format("在服务单元下,设备[%s]出库次数异常", deviceNo));
+            }
+            equipmentOutboundTotal = equipmentOutboundTotal + outCount;
+        }
+
+        // -- 设备占用率 --
+        int normalDeviceCount = sysDeviceService.count(new QueryWrapper<SysDevice>().lambda().eq(SysDevice::getStatus, DeviceStatusEnum.NORMAL));
+        BigDecimal equipmentOccupancyRate = new BigDecimal(0);
+        if (normalDeviceCount > 0){
+            equipmentOccupancyRate = new BigDecimal(equipmentOutboundTotal).divide(new BigDecimal(normalDeviceCount), 2, RoundingMode.HALF_UP).multiply(percent);
+        }
+
+        // -- 在服务人员总数 --
+        List<Map<String, Object>> sopPassageMap = tbSopInfoService.findSopPassage(serviceUnitId);
+        Integer servicePersonnelTotal = 0;
+        if (!CollectionUtils.isEmpty(sopPassageMap)) {
+            for (Map m : sopPassageMap) {
+                //需要去重
+                String regionUserStr = Objects.nonNull(m) && Objects.nonNull(m.get("regionUserIds")) ? m.get("regionUserIds").toString() : null;
+                if (Objects.nonNull(regionUserStr)) {
+                    String[] strs = regionUserStr.split(",");
+                    Set<String> set = new HashSet<>(Arrays.asList(strs));
+                    servicePersonnelTotal = servicePersonnelTotal + set.size();
+                }
+                String engineerUserStr = Objects.nonNull(m) && Objects.nonNull(m.get("engineerUserIds")) ? m.get("engineerUserIds").toString() : null;
+                if (Objects.nonNull(engineerUserStr)) {
+                    String[] strs = engineerUserStr.split(",");
+                    Set<String> set = new HashSet<>(Arrays.asList(strs));
+                    servicePersonnelTotal = servicePersonnelTotal + set.size();
+                }
+                String assistantEngineerUserId = Objects.nonNull(m) && Objects.nonNull(m.get("assistantEngineerUserIds")) ? m.get("assistantEngineerUserIds").toString() : null;
+                if (Objects.nonNull(assistantEngineerUserId)) {
+                    String[] strs = assistantEngineerUserId.split(",");
+                    Set<String> set = new HashSet<>(Arrays.asList(strs));
+                    servicePersonnelTotal = servicePersonnelTotal + set.size();
+                }
+            }
+        }
+
+
+        //认证有效的人员总数
+        int totalUserArchives = tbUserArchivesSupplierService.countAuthentication();
+        BigDecimal sitePersonnelOccupancyRate = new BigDecimal(0);
+        if (totalUserArchives > 0) {
+            sitePersonnelOccupancyRate = new BigDecimal(servicePersonnelTotal).divide(new BigDecimal(totalUserArchives), 2, RoundingMode.HALF_UP).multiply(percent);
+        }
+        result.setProjectProgress(projectProgress);
+        result.setEquipmentOutboundTotal(equipmentOutboundTotal);
+        result.setEquipmentOccupancyRate(equipmentOccupancyRate);
+        result.setServicePersonnelTotal(servicePersonnelTotal);
+        result.setSitePersonnelOccupancyRate(sitePersonnelOccupancyRate);
+        return result;
+    }
+
     /**
      * ①当前服务单元已划分了区域协调人的项目总数、供应商分布占比;
      */

+ 3 - 2
sop-business/src/main/resources/mapper/SopScheduleMapper.xml

@@ -31,7 +31,7 @@
         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
         <where>
-
+            and tffa.status != 'END'
             <if test="serviceId != null and serviceId != ''">
                 and tbsi.service_id= #{serviceId}
             </if>
@@ -92,6 +92,7 @@
         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
         <where>
+            and tffa.status != 'END'
             <if test="serviceId != null and serviceId != ''">
                 and tbsi.service_id = #{serviceId}
             </if>
@@ -117,7 +118,7 @@
         FROM
         t_b_ding d
         <where>
-
+            and (d.sign_in_time is not null or d.sign_out_time is not null)
             <if test="serviceId != null and serviceId != ''">
                 and d.service_id= #{serviceId}
             </if>