Explorar o código

服务单元概览报表修改

wangliang hai 1 ano
pai
achega
0e526cc373

+ 1 - 1
sop-business/src/main/java/com/qmth/sop/business/mapper/ServiceAnalyseMapper.java

@@ -26,7 +26,7 @@ public interface ServiceAnalyseMapper extends BaseMapper<TBService> {
 
     List<Map<String,Object>> projectProgress(@Param("serviceUnitId") Long serviceUnitId);
 
-    Integer equipmentOutboundTotal(@Param("serviceUnitId") Long serviceUnitId);
+    List<Map<String,Object>> equipmentOutboundTotal(@Param("serviceUnitId") Long serviceUnitId);
 
     Integer projectCount(@Param("serviceUnitId") Long serviceUnitId);
 

+ 8 - 0
sop-business/src/main/java/com/qmth/sop/business/mapper/TBSopInfoMapper.java

@@ -108,4 +108,12 @@ public interface TBSopInfoMapper extends BaseMapper<TBSopInfo> {
     List<SopInfoResult> findFlowByServiceId(@Param("serviceId") Long serviceId, @Param("userId") Long userId, @Param("roleType") String roleType);
 
     List<SysUser> userList(@Param("id") Long id);
+
+    /**
+     * 根据服务单元查找在途的区域协调人、实施工程师、助理工程师
+     *
+     * @param serviceId
+     * @return
+     */
+    List<Map<String, Object>> findSopPassage(@Param("serviceId") Long serviceId);
 }

+ 8 - 0
sop-business/src/main/java/com/qmth/sop/business/service/TBSopInfoService.java

@@ -157,4 +157,12 @@ public interface TBSopInfoService extends IService<TBSopInfo> {
     public Boolean sopSave(SopSaveParam sopSaveParam) throws InterruptedException;
 
     List<SysUser> userList(Long id);
+
+    /**
+     * 根据服务单元查找在途的区域协调人、实施工程师、助理工程师
+     *
+     * @param serviceId
+     * @return
+     */
+    List<Map<String, Object>> findSopPassage(Long serviceId);
 }

+ 41 - 25
sop-business/src/main/java/com/qmth/sop/business/service/impl/ServiceAnalyseServiceImpl.java

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

+ 11 - 0
sop-business/src/main/java/com/qmth/sop/business/service/impl/TBSopInfoServiceImpl.java

@@ -1042,6 +1042,17 @@ public class TBSopInfoServiceImpl extends ServiceImpl<TBSopInfoMapper, TBSopInfo
         return this.baseMapper.userList(id);
     }
 
+    /**
+     * 根据服务单元查找在途的区域协调人、实施工程师、助理工程师
+     *
+     * @param serviceId
+     * @return
+     */
+    @Override
+    public List<Map<String, Object>> findSopPassage(Long serviceId) {
+        return this.baseMapper.findSopPassage(serviceId);
+    }
+
     /**
      * 获取表单内容
      *

+ 13 - 23
sop-business/src/main/resources/mapper/ServiceAnalyseMapper.xml

@@ -23,38 +23,29 @@
         </where>
         order by s.start_time desc
     </select>
-    <select id="equipmentOutboundTotal" resultType="java.lang.Integer">
+
+    <select id="equipmentOutboundTotal" resultType="java.util.Map">
         SELECT
-        IFNULL(sum( CASE WHEN io.type = 'OUT' THEN 1 ELSE 0 END )- sum( CASE WHEN io.type = 'IN' THEN 1 ELSE 0 END ) ,0) OUTS
-        FROM
-        t_b_device_in_out io
+            IFNULL(sum(case when io.status = 'NORMAL' then 1 else 0 end),0) deviceSum,
+            IFNULL(sum(case when io.type = 'OUT' then 1 else 0 end),0) outs
+        from t_b_device_in_out io
         <where>
             <if test="serviceUnitId != null and serviceUnitId != ''">
                 and io.service_id = #{serviceUnitId}
             </if>
         </where>
     </select>
+
     <select id="projectProgress" resultType="java.util.Map">
-        SELECT
-        s.id,
-        s.`name`,
-        c.crm_no,
-        cu.type,
-        si.sop_no,
-        tffa.`status`
-        FROM
-        t_b_service s
-        LEFT JOIN t_b_crm c ON c.service_id = s.id
-        LEFT JOIN sys_custom cu ON cu.id = c.custom_id
-        LEFT JOIN t_b_sop_info si ON si.crm_no = c.crm_no
-        LEFT JOIN t_f_custom_flow_entity tfcfe ON tfcfe.CODE = si.sop_no
-        LEFT JOIN t_f_flow_approve tffa ON tffa.flow_id = tfcfe.flow_id
+        select tfcfe.code as code,tfcfe.crm_no as crmNo,tfcfe.flow_id as flowId,tffa.status as status from t_b_service tbs
+        left join t_b_crm tbc ON tbc.service_id = tbs.id
+        left join t_f_custom_flow_entity tfcfe on tfcfe.crm_no = tbc.crm_no
+        left join t_f_flow_approve tffa on tffa.flow_id = tfcfe.flow_id
         <where>
-            and c.crm_no IS NOT NULL
             <if test="serviceUnitId != null and serviceUnitId != ''">
-                and s.id = #{serviceUnitId}
+                and tbs.id = #{serviceUnitId}
             </if>
-
+            and tfcfe.code like 'SOP%'
         </where>
     </select>
 
@@ -216,8 +207,7 @@
 <!--            </if>-->
         </where>
     </select>
-    <select id="findCrmAllocation"
-            resultType="com.qmth.sop.business.bean.result.UserArchivesAllocationResult">
+    <select id="findCrmAllocation" resultType="com.qmth.sop.business.bean.result.UserArchivesAllocationResult">
         SELECT
         *,
         (result.effectQuota + result.assistantQuota + result.coordinatorQuota) AS quota,

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

@@ -244,4 +244,31 @@
         SELECT a.engineer_user_id  FROM t_b_sop_info_detail a  WHERE a.sop_info_id = #{id}
         )
     </select>
+
+    <select id="findSopPassage" resultType="java.util.Map">
+        select
+            IFNULL(sum(case when tbsid.region_user_id is not null then 1 else 0 end),0) as regionUserSum,
+            IFNULL(sum(case when tbsid.engineer_user_id is not null then 1 else 0 end),0) as engineerUserSum,
+            group_concat(tbsid.assistant_engineer_user_ids) as assistantEngineerUserIds
+        from
+            t_b_sop_info_detail tbsid
+        where
+            exists(
+                    select
+                        tbsi.id
+                    from
+                        t_b_sop_info tbsi
+                            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> 1 = 1
+                        <if test="serviceId != null and serviceId != ''">
+                            and tbsi.service_id = #{serviceId}
+                        </if>
+                      and tbsi.status = 'START'
+                      and tffa.status not in('FINISH', 'END')
+                      and tbsid.sop_info_id = tbsi.id)
+                    </where>
+    </select>
 </mapper>