Browse Source

履职统计代码优化

zhulu 1 year ago
parent
commit
e6aeedd18b

+ 4 - 2
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/reportForms/resumption/controller/ResumptionReportController.java

@@ -28,6 +28,8 @@ import java.time.LocalDate;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
 
 /**
  * @author :LuoWei
@@ -47,7 +49,7 @@ public class ResumptionReportController {
     @RequiresPermissions("core:resumptionReport:export")
     @Log(title = "履职报表导出", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(ResumptionDTO request, HttpServletResponse response) throws IOException {
+    public void export(ResumptionDTO request, HttpServletResponse response) throws IOException, ExecutionException, InterruptedException, TimeoutException {
         if (null == request.getSearchTime()) {
             LocalDate currentDate = LocalDate.now();
             if (null == request.getCycle() || request.getCycle() == 1) {
@@ -62,7 +64,7 @@ public class ResumptionReportController {
     @ApiOperation(value = "每日安全保卫履职-日报表")
     @RequiresPermissions("core:resumptionReport:list")
     @GetMapping("/list")
-    public AjaxResult list(ResumptionDTO resumptionDTO) {
+    public AjaxResult list(ResumptionDTO resumptionDTO) throws ExecutionException, InterruptedException, TimeoutException {
         if (null == resumptionDTO.getSearchTime()) {
             LocalDate currentDate = LocalDate.now();
             if (null == resumptionDTO.getCycle() || resumptionDTO.getCycle() == 1) {

+ 4 - 2
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/reportForms/resumption/service/ResumptionReportService.java

@@ -8,15 +8,17 @@ import com.xunmei.core.reportForms.resumption.vo.ResumptionDayVO;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeoutException;
 
 /**
  * @author :LuoWei
  * @date : 2023/11/8
  */
 public interface ResumptionReportService {
-    List<ResumptionDayVO> report(ResumptionDTO resumptionDTO);
+    List<ResumptionDayVO> report(ResumptionDTO resumptionDTO) throws ExecutionException, InterruptedException, TimeoutException;
 
-    void export(ResumptionDTO resumptionDTO, HttpServletResponse response) throws IOException;
+    void export(ResumptionDTO resumptionDTO, HttpServletResponse response) throws IOException, ExecutionException, InterruptedException, TimeoutException;
 
     void intrusionTestExport(ResumptionDTO resumptionDTO, HttpServletResponse response)throws IOException;
 

+ 171 - 65
soc-modules/soc-modules-core/src/main/java/com/xunmei/core/reportForms/resumption/service/impl/ResumptionReportServiceImpl.java

@@ -3,6 +3,10 @@ package com.xunmei.core.reportForms.resumption.service.impl;
 import cn.hutool.core.util.ObjectUtil;
 import com.alibaba.excel.EasyExcel;
 import com.xunmei.common.core.constant.SecurityConstants;
+import com.xunmei.common.core.domain.edu.domain.CoreEduTrainingPlan;
+import com.xunmei.common.core.domain.panel.vo.PanelListVo;
+import com.xunmei.common.core.enums.edu.EduTrainingPlanStatus;
+import com.xunmei.common.core.thread.ThreadPoolConfig;
 import com.xunmei.common.core.utils.DateHelper;
 import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.core.edu.service.impl.ValueCellWriteHandler;
@@ -17,6 +21,8 @@ import com.xunmei.system.api.RemoteOrgService;
 import com.xunmei.system.api.domain.SysOrg;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpServletResponse;
@@ -24,6 +30,14 @@ import java.io.IOException;
 import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.bouncycastle.asn1.x500.style.RFC4519Style.o;
 
 /**
  * @author :LuoWei
@@ -38,8 +52,12 @@ public class ResumptionReportServiceImpl implements ResumptionReportService {
     @Autowired
     private ResumptionReportMapper resumptionReportMapper;
 
+    @Autowired
+    @Qualifier(ThreadPoolConfig.SOC_EXECUTOR)
+    private ThreadPoolTaskExecutor threadPoolTaskExecutor;
+
     @Override
-    public List<ResumptionDayVO> report(ResumptionDTO resumptionDTO) {
+    public List<ResumptionDayVO> report(ResumptionDTO resumptionDTO) throws ExecutionException, InterruptedException, TimeoutException {
         if (null == resumptionDTO.getOrgId()) {
             resumptionDTO.setOrgId(SecurityUtils.getLoginUser().getOrgId());
         }
@@ -57,78 +75,166 @@ public class ResumptionReportServiceImpl implements ResumptionReportService {
             return Collections.emptyList();
         }
         List<ResumptionDayVO> resumptionDayVOS = new ArrayList<>();
+//        sysOrgs.forEach(o -> {
+//            ResumptionDayVO resumptionDayVO = new ResumptionDayVO();
+////            SysOrg sysOrg1;
+////            if (sysOrg.getType() < 3 || sysOrg.getShortName().endsWith("地区行社") || sysOrg.getType() == 9) {
+////                sysOrg1 = orgService.selectOrgById(o.getParentId(), SecurityConstants.INNER);
+////            } else {
+////                sysOrg1 = orgService.selectOrgById(orgService.selectOrgById(o.getParentId(), SecurityConstants.INNER).getParentId(), SecurityConstants.INNER);
+////                if (-1 == sysOrg1.getShortName().indexOf("地区行社")) {
+////                    sysOrg1 = orgService.selectOrgById(orgService.selectOrgById(orgService.selectOrgById(o.getParentId(), SecurityConstants.INNER).getParentId(), SecurityConstants.INNER).getParentId(), SecurityConstants.INNER);
+////                }
+////            }
+//            resumptionDayVO.setCity(o.getAffiliatedArea());
+//            resumptionDayVO.setOrgName(o.getShortName());
+//            Integer integer = monitorAccessReportMapper.selectNetworkNumberByPath(o.getPath());
+//            ResumptionDayVO resumptionDayVO1 =null;
+//            ResumptionDayVO resumptionDayVO2 =null;
+//            ResumptionDayVO resumptionDayVO3 =null;
+//
+//            if(o.getType()!=4) {
+//                //营业前
+//                resumptionDayVO1 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 1, null, resumptionDTO.getSearchTime(), o.getPath());
+//                //营业中
+//                resumptionDayVO2 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 2, null, resumptionDTO.getSearchTime(), o.getPath());
+//                //后
+//                resumptionDayVO3 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 3, null, resumptionDTO.getSearchTime(), o.getPath());
+//            }
+//            if (o.getType() == 4) {
+//                integer = 1;
+//                resumptionDayVO1 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 1, o.getId(), resumptionDTO.getSearchTime(), null);
+//                resumptionDayVO2 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 2, o.getId(), resumptionDTO.getSearchTime(), null);
+//                resumptionDayVO3 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 3, o.getId(), resumptionDTO.getSearchTime(), null);
+//            }
+//
+//            resumptionDayVO.setNetworkNumber(integer);
+//
+//            resumptionDayVO.setFrontRate(resumptionDayVO1.getFrontRate());
+//            resumptionDayVO.setFrontAbnormalNumber(resumptionDayVO1.getFrontAbnormalNumber());
+//            resumptionDayVO.setFrontPlanNumber(resumptionDayVO1.getFrontPlanNumber());
+//            resumptionDayVO.setFrontRealityNumber(resumptionDayVO1.getFrontRealityNumber());
+//
+//            resumptionDayVO.setCentreRate(resumptionDayVO2.getFrontRate());
+//            resumptionDayVO.setCentreAbnormalNumber(resumptionDayVO2.getFrontAbnormalNumber());
+//            resumptionDayVO.setCentrePlanNumber(resumptionDayVO2.getFrontPlanNumber());
+//            resumptionDayVO.setCentreRealityNumber(resumptionDayVO2.getFrontRealityNumber());
+//
+//            resumptionDayVO.setAfterRate(resumptionDayVO3.getFrontRate());
+//            resumptionDayVO.setAfterAbnormalNumber(resumptionDayVO3.getFrontAbnormalNumber());
+//            resumptionDayVO.setAfterPlanNumber(resumptionDayVO3.getFrontPlanNumber());
+//            resumptionDayVO.setAfterRealityNumber(resumptionDayVO3.getFrontRealityNumber());
+//            Integer totalPlan = resumptionDayVO3.getFrontPlanNumber() + resumptionDayVO2.getFrontPlanNumber() + resumptionDayVO1.getFrontPlanNumber();
+//            //总计实际履职次数
+//            Integer totalReality = resumptionDayVO3.getFrontRealityNumber() + resumptionDayVO2.getFrontRealityNumber() + resumptionDayVO1.getFrontRealityNumber();
+//            //总计隐患问题数
+//            Integer totalAbnormal = resumptionDayVO3.getFrontAbnormalNumber() + resumptionDayVO2.getFrontAbnormalNumber() + resumptionDayVO1.getFrontAbnormalNumber();
+//            //总计已整改数量
+//            Integer totalRealityRectificationNumber = resumptionDayVO3.getTotalRealityRectificationNumber() + resumptionDayVO2.getTotalRealityRectificationNumber() + resumptionDayVO1.getTotalRealityRectificationNumber();
+//            //总计应履职次数
+//            resumptionDayVO.setTotalPlanNumber(totalPlan);
+//            resumptionDayVO.setTotalRealityNumber(totalReality);
+//            Double i = 0d;
+//            if (totalReality != 0 && totalPlan != 0) {
+//                i = (double) totalReality / totalPlan * 100;
+//            }
+//            resumptionDayVO.setTotalRate(String.format("%.2f", i) + "%");
+//            resumptionDayVO.setTotalAbnormalNumber(totalAbnormal);
+//            Double n = 0d;
+//            if (totalAbnormal != 0 && totalRealityRectificationNumber != 0) {
+//                n = (double) totalRealityRectificationNumber / totalAbnormal * 100;
+//            }
+//            resumptionDayVO.setTotalRealityRectificationRate(String.format("%.2f", n) + "%");
+//            resumptionDayVO.setTotalRealityRectificationNumber(totalRealityRectificationNumber);
+//            resumptionDayVOS.add(resumptionDayVO);
+//        });
+
+        List<CompletableFuture<ResumptionDayVO>> completableFutureList=new ArrayList<>();
         sysOrgs.forEach(o -> {
-            ResumptionDayVO resumptionDayVO = new ResumptionDayVO();
-            SysOrg sysOrg1;
-            if (sysOrg.getType() < 3 || sysOrg.getShortName().endsWith("地区行社") || sysOrg.getType() == 9) {
-                sysOrg1 = orgService.selectOrgById(o.getParentId(), SecurityConstants.INNER);
-            } else {
-                sysOrg1 = orgService.selectOrgById(orgService.selectOrgById(o.getParentId(), SecurityConstants.INNER).getParentId(), SecurityConstants.INNER);
-                if (-1 == sysOrg1.getShortName().indexOf("地区行社")) {
-                    sysOrg1 = orgService.selectOrgById(orgService.selectOrgById(orgService.selectOrgById(o.getParentId(), SecurityConstants.INNER).getParentId(), SecurityConstants.INNER).getParentId(), SecurityConstants.INNER);
-                }
-            }
-            resumptionDayVO.setCity(sysOrg1.getShortName().indexOf("地区行社") == -1 ? sysOrg1.getShortName().substring(0, 2) : sysOrg1.getShortName().split("地区行社")[0]);
-            resumptionDayVO.setOrgName(o.getShortName());
-            Integer integer = monitorAccessReportMapper.selectNetworkNumberByPath(o.getPath());
+            CompletableFuture<ResumptionDayVO> getOneOrgResumptionDayVO = CompletableFuture.supplyAsync(() ->
+                    getOneOrgResumptionDayVO(o,resumptionDTO),threadPoolTaskExecutor
+            );
+            completableFutureList.add(getOneOrgResumptionDayVO);
+        });
+
+        CompletableFuture<Void> allQueries = CompletableFuture.allOf(completableFutureList.toArray(new CompletableFuture[0]));
+
+        allQueries.get(10L, TimeUnit.SECONDS);
+
+        completableFutureList.forEach(x->{
+            resumptionDayVOS.add(x.join());
+        });
+        return resumptionDayVOS;
+    }
+
+    private ResumptionDayVO getOneOrgResumptionDayVO(SysOrg org,ResumptionDTO resumptionDTO)
+    {
+        ResumptionDayVO resumptionDayVO = new ResumptionDayVO();
+        resumptionDayVO.setCity(org.getAffiliatedArea());
+        resumptionDayVO.setOrgName(org.getShortName());
+        Integer integer = monitorAccessReportMapper.selectNetworkNumberByPath(org.getPath());
+        ResumptionDayVO resumptionDayVO1 =null;
+        ResumptionDayVO resumptionDayVO2 =null;
+        ResumptionDayVO resumptionDayVO3 =null;
+
+        if(org.getType()!=4) {
             //营业前
-            ResumptionDayVO resumptionDayVO1 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 1, null, resumptionDTO.getSearchTime(), o.getPath());
+            resumptionDayVO1 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 1, null, resumptionDTO.getSearchTime(), org.getPath());
             //营业中
-            ResumptionDayVO resumptionDayVO2 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 2, null, resumptionDTO.getSearchTime(), o.getPath());
+            resumptionDayVO2 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 2, null, resumptionDTO.getSearchTime(), org.getPath());
             //后
-            ResumptionDayVO resumptionDayVO3 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 3, null, resumptionDTO.getSearchTime(), o.getPath());
-            if (o.getType() == 4) {
-                integer = 1;
-                resumptionDayVO1 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 1, o.getId(), resumptionDTO.getSearchTime(), o.getPath());
-                resumptionDayVO2 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 2, o.getId(), resumptionDTO.getSearchTime(), o.getPath());
-                resumptionDayVO3 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 3, o.getId(), resumptionDTO.getSearchTime(), o.getPath());
-            }
+            resumptionDayVO3 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 3, null, resumptionDTO.getSearchTime(), org.getPath());
+        }
+        if (org.getType() == 4) {
+            integer = 1;
+            resumptionDayVO1 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 1, org.getId(), resumptionDTO.getSearchTime(), null);
+            resumptionDayVO2 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 2, org.getId(), resumptionDTO.getSearchTime(), null);
+            resumptionDayVO3 = resumptionReportMapper.selectReport(resumptionDTO.getCycle(), 3, org.getId(), resumptionDTO.getSearchTime(), null);
+        }
 
-            resumptionDayVO.setNetworkNumber(integer);
-
-            resumptionDayVO.setFrontRate(resumptionDayVO1.getFrontRate());
-            resumptionDayVO.setFrontAbnormalNumber(resumptionDayVO1.getFrontAbnormalNumber());
-            resumptionDayVO.setFrontPlanNumber(resumptionDayVO1.getFrontPlanNumber());
-            resumptionDayVO.setFrontRealityNumber(resumptionDayVO1.getFrontRealityNumber());
-
-            resumptionDayVO.setCentreRate(resumptionDayVO2.getFrontRate());
-            resumptionDayVO.setCentreAbnormalNumber(resumptionDayVO2.getFrontAbnormalNumber());
-            resumptionDayVO.setCentrePlanNumber(resumptionDayVO2.getFrontPlanNumber());
-            resumptionDayVO.setCentreRealityNumber(resumptionDayVO2.getFrontRealityNumber());
-
-            resumptionDayVO.setAfterRate(resumptionDayVO3.getFrontRate());
-            resumptionDayVO.setAfterAbnormalNumber(resumptionDayVO3.getFrontAbnormalNumber());
-            resumptionDayVO.setAfterPlanNumber(resumptionDayVO3.getFrontPlanNumber());
-            resumptionDayVO.setAfterRealityNumber(resumptionDayVO3.getFrontRealityNumber());
-            Integer totalPlan = resumptionDayVO3.getFrontPlanNumber() + resumptionDayVO2.getFrontPlanNumber() + resumptionDayVO1.getFrontPlanNumber();
-            //总计实际履职次数
-            Integer totalReality = resumptionDayVO3.getFrontRealityNumber() + resumptionDayVO2.getFrontRealityNumber() + resumptionDayVO1.getFrontRealityNumber();
-            //总计隐患问题数
-            Integer totalAbnormal = resumptionDayVO3.getFrontAbnormalNumber() + resumptionDayVO2.getFrontAbnormalNumber() + resumptionDayVO1.getFrontAbnormalNumber();
-            //总计已整改数量
-            Integer totalRealityRectificationNumber = resumptionDayVO3.getTotalRealityRectificationNumber() + resumptionDayVO2.getTotalRealityRectificationNumber() + resumptionDayVO1.getTotalRealityRectificationNumber();
-            //总计应履职次数
-            resumptionDayVO.setTotalPlanNumber(totalPlan);
-            resumptionDayVO.setTotalRealityNumber(totalReality);
-            Double i = 0d;
-            if (totalReality != 0 && totalPlan != 0) {
-                i = (double) totalReality / totalPlan * 100;
-            }
-            resumptionDayVO.setTotalRate(String.format("%.2f", i) + "%");
-            resumptionDayVO.setTotalAbnormalNumber(totalAbnormal);
-            Double n = 0d;
-            if (totalAbnormal != 0 && totalRealityRectificationNumber != 0) {
-                n = (double) totalRealityRectificationNumber / totalAbnormal * 100;
-            }
-            resumptionDayVO.setTotalRealityRectificationRate(String.format("%.2f", n) + "%");
-            resumptionDayVO.setTotalRealityRectificationNumber(totalRealityRectificationNumber);
-            resumptionDayVOS.add(resumptionDayVO);
-        });
-        return resumptionDayVOS;
+        resumptionDayVO.setNetworkNumber(integer);
+
+        resumptionDayVO.setFrontRate(resumptionDayVO1.getFrontRate());
+        resumptionDayVO.setFrontAbnormalNumber(resumptionDayVO1.getFrontAbnormalNumber());
+        resumptionDayVO.setFrontPlanNumber(resumptionDayVO1.getFrontPlanNumber());
+        resumptionDayVO.setFrontRealityNumber(resumptionDayVO1.getFrontRealityNumber());
+
+        resumptionDayVO.setCentreRate(resumptionDayVO2.getFrontRate());
+        resumptionDayVO.setCentreAbnormalNumber(resumptionDayVO2.getFrontAbnormalNumber());
+        resumptionDayVO.setCentrePlanNumber(resumptionDayVO2.getFrontPlanNumber());
+        resumptionDayVO.setCentreRealityNumber(resumptionDayVO2.getFrontRealityNumber());
+
+        resumptionDayVO.setAfterRate(resumptionDayVO3.getFrontRate());
+        resumptionDayVO.setAfterAbnormalNumber(resumptionDayVO3.getFrontAbnormalNumber());
+        resumptionDayVO.setAfterPlanNumber(resumptionDayVO3.getFrontPlanNumber());
+        resumptionDayVO.setAfterRealityNumber(resumptionDayVO3.getFrontRealityNumber());
+        Integer totalPlan = resumptionDayVO3.getFrontPlanNumber() + resumptionDayVO2.getFrontPlanNumber() + resumptionDayVO1.getFrontPlanNumber();
+        //总计实际履职次数
+        Integer totalReality = resumptionDayVO3.getFrontRealityNumber() + resumptionDayVO2.getFrontRealityNumber() + resumptionDayVO1.getFrontRealityNumber();
+        //总计隐患问题数
+        Integer totalAbnormal = resumptionDayVO3.getFrontAbnormalNumber() + resumptionDayVO2.getFrontAbnormalNumber() + resumptionDayVO1.getFrontAbnormalNumber();
+        //总计已整改数量
+        Integer totalRealityRectificationNumber = resumptionDayVO3.getTotalRealityRectificationNumber() + resumptionDayVO2.getTotalRealityRectificationNumber() + resumptionDayVO1.getTotalRealityRectificationNumber();
+        //总计应履职次数
+        resumptionDayVO.setTotalPlanNumber(totalPlan);
+        resumptionDayVO.setTotalRealityNumber(totalReality);
+        Double i = 0d;
+        if (totalReality != 0 && totalPlan != 0) {
+            i = (double) totalReality / totalPlan * 100;
+        }
+        resumptionDayVO.setTotalRate(String.format("%.2f", i) + "%");
+        resumptionDayVO.setTotalAbnormalNumber(totalAbnormal);
+        Double n = 0d;
+        if (totalAbnormal != 0 && totalRealityRectificationNumber != 0) {
+            n = (double) totalRealityRectificationNumber / totalAbnormal * 100;
+        }
+        resumptionDayVO.setTotalRealityRectificationRate(String.format("%.2f", n) + "%");
+        resumptionDayVO.setTotalRealityRectificationNumber(totalRealityRectificationNumber);
+        return resumptionDayVO;
     }
 
     @Override
-    public void export(ResumptionDTO resumptionDTO, HttpServletResponse response) throws IOException {
+    public void export(ResumptionDTO resumptionDTO, HttpServletResponse response) throws IOException, ExecutionException, InterruptedException, TimeoutException {
         String orgName = null;
         if (null != resumptionDTO.getOrgId()) {
             SysOrg sysOrg = orgService.selectSysOrgById(resumptionDTO.getOrgId(), SecurityConstants.INNER);