shudonghui 1 vuosi sitten
vanhempi
commit
647451d2cc

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

@@ -150,7 +150,7 @@ public class ServiceAnalyseController {
     @ApiResponses({@ApiResponse(code = 200, message = "项目调配完成进度", response = Long.class)})
     public Result allocation(@ApiParam(value = "服务单元", required = true) @RequestParam Long serviceUnitId) {
         List<UserArchivesAllocationResult> crmAllocation = serviceAnalyseService.findCrmAllocation(serviceUnitId, null, null);
-        return ResultUtil.ok(crmAllocation.isEmpty() ? 0 : crmAllocation.stream().filter(e -> e.getDistributed() < e.getQuota()).count() / crmAllocation.size());
+        return ResultUtil.ok(crmAllocation.isEmpty() ? 0 : crmAllocation.stream().filter(e -> e.getUnDistributed()<=0).count() / crmAllocation.size());
     }
 
     /**

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

@@ -24,7 +24,7 @@ public interface ServiceAnalyseMapper extends BaseMapper<TBService> {
 
     List<TBService> list(@Param("startTime")Long startTime, @Param("endTime")Long endTime, @Param("dpr") DataPermissionDto dpr);
 
-    Long projectProgress(@Param("serviceUnitId") Long serviceUnitId);
+    List<Map<String,Object>> projectProgress(@Param("serviceUnitId") Long serviceUnitId);
 
     Integer servicePersonnelTotal(@Param("serviceUnitId") Long serviceUnitId);
 

+ 4 - 9
sop-business/src/main/java/com/qmth/sop/business/service/impl/CrmAnalyseServiceImpl.java

@@ -109,23 +109,18 @@ public class CrmAnalyseServiceImpl extends ServiceImpl<CrmAnalyseMapper, TBCrm>
             crmAnalyseResult.setName((String) k);
             crmAnalyseResult.setId(Long.valueOf(v.get(0).get("id").toString()));
             int crmNum=v.stream().collect(Collectors.groupingBy(map -> map.get("crm_no"))).size();
-            final int[] finsh = {0};
+            final int[] finish = {0};
             v.stream().collect(Collectors.groupingBy(map -> map.get("crm_no")))
                     .forEach((k1, v1) -> {
                         if (v1.stream().filter(map -> map.get("sop_no") != null).count() == v1.stream().filter(map -> "FINISH".equals(map.get("status"))).count()) {
-                            finsh[0] = finsh[0] + 1;
+                            finish[0] = finish[0] + 1;
                         }
                     });
-            crmAnalyseResult.setRate(finsh[0] *100/crmNum+"%");
+            crmAnalyseResult.setRate(finish[0] *100/crmNum+"%");
             list.add(crmAnalyseResult);
         });
         //list 按字符串Rate升序排列
-        Collections.sort(list, new Comparator<CrmAnalyseResult>() {
-            @Override
-            public int compare(CrmAnalyseResult o1, CrmAnalyseResult o2) {
-                return Double.compare(Double.parseDouble(o1.getRate().replace("%","")),Double.parseDouble(o2.getRate().replace("%","")));
-            }
-        });
+        list.sort(Comparator.comparingDouble(o -> Double.parseDouble(o.getRate().replace("%", ""))));
         return list;
 
 

+ 34 - 8
sop-business/src/main/java/com/qmth/sop/business/service/impl/ServiceAnalyseServiceImpl.java

@@ -18,6 +18,8 @@ import com.qmth.sop.business.service.SysUserService;
 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.ProductTypeEnum;
+import com.qmth.sop.common.enums.TFCustomTypeEnum;
 import com.qmth.sop.common.util.ServletUtil;
 import org.springframework.stereotype.Service;
 
@@ -25,6 +27,7 @@ import javax.annotation.Resource;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 @Service
 public class ServiceAnalyseServiceImpl extends ServiceImpl<ServiceAnalyseMapper, TBService> implements ServiceAnalyseService {
@@ -38,11 +41,12 @@ public class ServiceAnalyseServiceImpl extends ServiceImpl<ServiceAnalyseMapper,
     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);
     }
+
     /**
      * 4.服务单元概览
      * ①项目执行进度=服务单元下已完成的派单(研究生派单下SOP已完结;教务处派单下已有完成的SOP,无在执行的SOP。可能存在教务处多个SOP之间空窗期导致数据的误差,这个指标允许少量误差存在);
@@ -54,14 +58,36 @@ public class ServiceAnalyseServiceImpl extends ServiceImpl<ServiceAnalyseMapper,
     @Override
     public Map<String, Object> overview(Long serviceUnitId) {
         Map<String, Object> map = new HashMap<>();
-        map.put("projectProgress", this.baseMapper.projectProgress(serviceUnitId));
+        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, 0};
+        list.stream().collect(Collectors.groupingBy(map1 -> map1.get("crm_no")))
+                .forEach((k, v) -> {
+                    v.stream().collect(Collectors.groupingBy(map2 -> map2.get("type"))).forEach((k1, v1) -> {
+                        if (ProductTypeEnum.OFFICE.toString().equals(k1)) {
+                            if (v1.stream().anyMatch(map3 -> "FINISH".equals(map3.get("status"))) && v1.stream().noneMatch(map3 -> "FINISH".equals(map3.get("START")))) {
+                                finish[1] = finish[1] + 1;
+                            }
+                        } else if (ProductTypeEnum.CLOUD_MARK.toString().equals(k1)) {
+                            if (v1.stream().filter(map3 -> map3.get("sop_no") != null).count() == v1.stream().filter(map3 -> "FINISH".equals(map3.get("status"))).count()) {
+                                finish[1] = finish[1] + 1;
+                            }
+                        }
+
+                    });
+
+                });
+
+        map.put("projectProgress", (finish[0] + finish[1])*100 / crmNum);
         map.put("equipmentOutboundTotal", this.baseMapper.equipmentOutboundTotal(serviceUnitId));
+        Integer outboundTotal = this.baseMapper.equipmentOutboundTotal(null);
         int totalDevices = sysDeviceService.count(new LambdaQueryWrapper<SysDevice>().eq(SysDevice::getStatus, DeviceStatusEnum.NORMAL));
-        map.put("equipmentOccupancyRate",totalDevices==0?0: ((Integer) map.get("equipmentOutboundTotal")) * 100 / totalDevices);
+        map.put("equipmentOccupancyRate", totalDevices == 0 ? 0 : outboundTotal* 100 / totalDevices);
         map.put("servicePersonnelTotal", this.baseMapper.servicePersonnelTotal(serviceUnitId));
         //认证有效的人员总数
+        Integer personnelTotal = this.baseMapper.servicePersonnelTotal(null);
         int totalUserArchives = tbUserArchivesSupplierService.countAuthentication();
-        map.put("sitePersonnelOccupancyRate",totalUserArchives==0?0: ((Integer) map.get("servicePersonnelTotal")) * 100 / totalUserArchives);
+        map.put("sitePersonnelOccupancyRate", totalUserArchives == 0 ? 0 : personnelTotal* 100 / totalUserArchives);
         return map;
     }
 
@@ -80,16 +106,16 @@ public class ServiceAnalyseServiceImpl extends ServiceImpl<ServiceAnalyseMapper,
 
     @Override
     public IPage<TBCrmResult> supplierDetail(Page<Object> iPage, Long serviceUnitId, Long supplierId) {
-        return this.baseMapper.crmDetail(iPage, serviceUnitId,supplierId);
+        return this.baseMapper.crmDetail(iPage, serviceUnitId, supplierId);
     }
 
     @Override
-    public  List<Map<String,Object>> supplierRole(Long supplierId) {
+    public List<Map<String, Object>> supplierRole(Long supplierId) {
         return this.baseMapper.supplierRole(supplierId);
     }
 
     @Override
-    public  List<Map<String,Object>> supplierRegion(Long serviceUnitId, Long supplierId) {
+    public List<Map<String, Object>> supplierRegion(Long serviceUnitId, Long supplierId) {
         return this.baseMapper.supplierRegion(serviceUnitId, supplierId);
     }
 

+ 1 - 0
sop-business/src/main/resources/mapper/CrmAnalyseMapper.xml

@@ -146,6 +146,7 @@
             <!--            <if test="year != null and year != ''">-->
             <!--                and YEAR ( FROM_UNIXTIME( s.start_time / 1000 ))=  #{year}-->
             <!--            </if>-->
+            and su.id is not null
             <if test="startTime != null">
                 AND s.start_time >= #{startTime}
             </if>

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

@@ -25,26 +25,34 @@
     </select>
     <select id="equipmentOutboundTotal" resultType="java.lang.Integer">
         SELECT
-        sum(case when d.bound='OUT' then 1 else 0 end ) OUTS
+        count( DISTINCT d.id ) OUTS
         FROM
-        t_b_service s
-        LEFT JOIN t_b_crm c ON c.service_id = s.id
-        left join t_b_device_in_out io on io.service_id=s.id
-        left join sys_device d on d.device_code=io.device_no
+        sys_device d
+        LEFT JOIN t_b_device_in_out io ON d.device_code = io.device_no
         <where>
+            and d.bound = 'OUT'
             <if test="serviceUnitId != null and serviceUnitId != ''">
-                and s.id = #{serviceUnitId}
+                and io.service_id = #{serviceUnitId}
             </if>
         </where>
     </select>
-    <select id="projectProgress" resultType="java.lang.Long">
+    <select id="projectProgress" resultType="java.util.Map">
         SELECT
-        sum(case when c.`status`='FINISH' then 1 else 0 end)*100/count(c.id)
+        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
         <where>
-
+            and c.crm_no IS NOT NULL
             <if test="serviceUnitId != null and serviceUnitId != ''">
                 and s.id = #{serviceUnitId}
             </if>
@@ -60,26 +68,61 @@
 <!--        t_b_service s-->
 <!--        LEFT JOIN t_b_sop_info sop ON sop.service_id = s.id-->
 <!--        LEFT JOIN t_b_sop_info_detail sd ON sd.sop_info_id = sop.id-->
-        SELECT
-        count(DISTINCT s.user_id)
-        FROM
-        t_b_user_archives_allocation s
+<!--        SELECT-->
+<!--        count(DISTINCT s.user_id)-->
+<!--        FROM-->
+<!--        t_b_user_archives_allocation s-->
+
+        SELECT count(DISTINCT id)  FROM sys_user  WHERE
+        id IN (
+        SELECT a.lead_id  FROM t_b_sop_info_detail a
+        left join t_b_sop_info i on a.sop_info_id=i.id
+
+        LEFT JOIN t_f_custom_flow_entity tfcfe ON tfcfe.CODE = i.sop_no
+        LEFT JOIN t_f_flow_approve tffa ON tffa.flow_id = tfcfe.flow_id
+        <where>
+            and tffa.status!='FINISH'
+            <if test="serviceUnitId != null and serviceUnitId != ''">
+                and i.service_id = #{serviceUnitId}
+            </if>
+
+        </where>
+        UNION ALL
+        SELECT a.region_user_id  FROM t_b_sop_info_detail a
+        left join t_b_sop_info i on a.sop_info_id=i.id
+
+        LEFT JOIN t_f_custom_flow_entity tfcfe ON tfcfe.CODE = i.sop_no
+        LEFT JOIN t_f_flow_approve tffa ON tffa.flow_id = tfcfe.flow_id
         <where>
+            and tffa.status!='FINISH'
+            <if test="serviceUnitId != null and serviceUnitId != ''">
+                and i.service_id = #{serviceUnitId}
+            </if>
+
+        </where>
+        UNION ALL
+        SELECT a.engineer_user_id  FROM t_b_sop_info_detail a
+        left join t_b_sop_info i on a.sop_info_id=i.id
 
+        LEFT JOIN t_f_custom_flow_entity tfcfe ON tfcfe.CODE = i.sop_no
+        LEFT JOIN t_f_flow_approve tffa ON tffa.flow_id = tfcfe.flow_id
+        <where>
+            and tffa.status!='FINISH'
             <if test="serviceUnitId != null and serviceUnitId != ''">
-                and s.service_id = #{serviceUnitId}
+                and i.service_id = #{serviceUnitId}
             </if>
 
         </where>
+        )
     </select>
     <select id="projectCount" resultType="java.lang.Integer">
         SELECT
-        count( c.id )
+        count(DISTINCT c.id )
         FROM
         t_b_service s
         LEFT JOIN t_b_crm c ON c.service_id = s.id
         <where>
-            and c.lead_id is not null
+
             <if test="serviceUnitId != null and serviceUnitId != ''">
                 and s.id = #{serviceUnitId}
             </if>
@@ -88,21 +131,20 @@
     </select>
     <select id="supplierDistribution" resultType="java.util.Map">
         SELECT
-        su.id,
+        CONCAT( su.id, '' ) id,
         su.`name`,
-        count(DISTINCT c.id ) count
+        count( DISTINCT c.id ) count
         FROM
-        t_b_user_archives_allocation aa
-        left join t_b_service_region r on aa.service_id=r.service_id
-        LEFT JOIN t_b_crm c ON aa.service_id = c.service_id
+        t_b_service s
+        LEFT JOIN t_b_crm c ON s.id = c.service_id
         LEFT JOIN sys_user u ON u.id = c.region_coordinator_id
         LEFT JOIN t_b_user_archives ua ON u.mobile_number = ua.mobile_number
         LEFT JOIN t_b_user_archives_supplier us ON us.user_archives_id = ua.id
         LEFT JOIN sys_supplier su ON su.id = us.supplier_id
-                <where>
+        <where>
                     and su.id IS NOT NULL
                     <if test="serviceUnitId != null and serviceUnitId != ''">
-                        and aa.service_id = #{serviceUnitId}
+                        and s.id = #{serviceUnitId}
                     </if>
                 </where>
         GROUP BY