Explorar o código

多线程优化(项目成本汇集页,首页一级汇总中的合同额,合同数量,已收款)

longw hai 1 ano
pai
achega
b2937a8cb8

+ 2 - 0
jeecg-module-system/jeecg-system-start/src/main/java/org/jeecg/JeecgSystemApplication.java

@@ -10,6 +10,7 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer
 import org.springframework.context.ConfigurableApplicationContext;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.core.env.Environment;
+import org.springframework.scheduling.annotation.EnableAsync;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
@@ -26,6 +27,7 @@ import java.net.UnknownHostException;
 @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})//-----------改的地方
 //@EnableAutoConfiguration(exclude={MongoAutoConfiguration.class})
 @EnableAspectJAutoProxy //开启Spring Boot对AOP的支持-----------改的地方
+@EnableAsync
 public class JeecgSystemApplication extends SpringBootServletInitializer {
 
     @Override

+ 34 - 24
module_kzks/src/main/java/org/jeecg/modules/Index/controller/IndexController.java

@@ -16,6 +16,7 @@ import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 
 import java.util.*;
+import java.util.concurrent.CompletableFuture;
 
 @Api(tags = "首页")
 @RestController
@@ -28,58 +29,67 @@ public class IndexController {
     @Autowired
     private IndexZcbService indexZcbService;
 
-    @ApiOperation(value="首页一层汇总", notes="首页一层汇总")
+    @ApiOperation(value = "首页一层汇总", notes = "首页一层汇总")
     @GetMapping("getCollect")
-    public Result<Map<String,IndexTotalVo>> getCollect(HttpServletRequest request) {
-        //合同额
-        IndexTotalVo hte = indexService.getTotalIncome(request);
-        //收款额
-        IndexTotalVo ske = indexService.getTotalReceived(request);
-        //利润额
-        IndexTotalVo lre = indexService.countLre();
-        //支出额
-        IndexTotalVo zce = indexZcbService.getZhiChuTotalList().get(0);
-
+    public Result<Map<String, IndexTotalVo>> getCollect(HttpServletRequest request) {
+        CompletableFuture<IndexTotalVo> hteFuture = CompletableFuture.supplyAsync(() -> {
+            // 合同额
+            return indexService.getTotalIncome(request);
+        });
+        CompletableFuture<IndexTotalVo> skeFuture = CompletableFuture.supplyAsync(() -> {
+            // 收款额
+            return indexService.getTotalReceived(request);
+        });
+        CompletableFuture<IndexTotalVo> lreFuture = CompletableFuture.supplyAsync(() -> {
+            // 利润额
+            return indexService.countLre();
+        });
+        CompletableFuture<IndexTotalVo> zceFuture = CompletableFuture.supplyAsync(() -> {
+            // 支出额
+            return indexZcbService.getZhiChuTotalList().get(0);
+        });
+        CompletableFuture<Void> allFutures = CompletableFuture.allOf(hteFuture, skeFuture, lreFuture, zceFuture);
+        allFutures.join();
         HashMap<String, IndexTotalVo> resultMap = new HashMap<>();
-        resultMap.put("hte",hte);
-        resultMap.put("ske",ske);
-        resultMap.put("lre",lre);
-        resultMap.put("zce",zce);
+        resultMap.put("hte", hteFuture.join());
+        resultMap.put("ske", skeFuture.join());
+        resultMap.put("lre", lreFuture.join());
+        resultMap.put("zce", zceFuture.join());
         return Result.ok(resultMap);
     }
 
 
-    @ApiOperation(value="计算合同数量", notes="计算合同数量")
+    @ApiOperation(value = "计算合同数量", notes = "计算合同数量")
     @GetMapping("getTotalContract")
     public Result<IndexTotalVo> getTotalContract(HttpServletRequest request) {
-        IndexTotalVo reslut = indexService.getTotalContract(request);
+        IndexTotalVo reslut = indexService.getTotalContractNum(request);
         return Result.ok(reslut);
     }
 
-    @ApiOperation(value="计算已收款", notes="计算已收款")
+    @ApiOperation(value = "计算已收款", notes = "计算已收款")
     @GetMapping("getTotalReceived")
     public Result<IndexTotalVo> getTotalReceived(HttpServletRequest request) {
         IndexTotalVo reslut = indexService.getTotalReceived(request);
         return Result.ok(reslut);
     }
 
-    @ApiOperation(value="首页二层合同额显示", notes="首页二层合同额显示")
+    @ApiOperation(value = "首页二层合同额显示", notes = "首页二层合同额显示")
     @PostMapping("getContractAmountInfo")
     public Result<ContractChartInfoVo> getContractAmountInfo(HttpServletRequest request, @RequestBody IndexInfoParamDto indexInfoParamDto) {
-        return Result.ok(indexService.getContractAmountInfo(request,indexInfoParamDto));
+        return Result.ok(indexService.getContractAmountInfo(request, indexInfoParamDto));
     }
 
 
     @ApiOperation("领导驾驶舱---支出模块")
     @GetMapping("/getZcb")
-    public List<IndexTotalVo> getZhiChuTotalList(){
+    public List<IndexTotalVo> getZhiChuTotalList() {
         List<IndexTotalVo> zhiChuTotalList = indexZcbService.getZhiChuTotalList();
         return zhiChuTotalList;
     }
 
     @ApiOperation("领导驾驶舱---支出模块下的统计")
     @GetMapping("/getEightCost")
-    public List<IndexChartInfoVo> getEightCost(IndexInfoParamDto indexInfoParamDto){
+    public List<IndexChartInfoVo> getEightCost(IndexInfoParamDto indexInfoParamDto) {
         List<IndexChartInfoVo> resultList = indexZcbService.getEightCostsList(indexInfoParamDto);
         return resultList;
     }
@@ -89,7 +99,7 @@ public class IndexController {
      *
      * @return
      */
-    @ApiOperation(value="计算总利润额以及同比环比", notes="计算总利润额以及同比环比")
+    @ApiOperation(value = "计算总利润额以及同比环比", notes = "计算总利润额以及同比环比")
     @GetMapping(value = "/countLre")
     public Result<IndexTotalVo> countLre() {
         return Result.ok(indexService.countLre());
@@ -114,7 +124,7 @@ public class IndexController {
      * @param indexInfoParamDto
      * @return IndexChartInfoVo<BigDecimal>
      */
-    @ApiOperation(value="首页二层利润额显示", notes="首页二层利润额显示")
+    @ApiOperation(value = "首页二层利润额显示", notes = "首页二层利润额显示")
     @GetMapping(value = "/countLreByDate")
     public Result<IndexChartInfoVo<BigDecimal>> countLreByDate(IndexInfoParamDto indexInfoParamDto) {
         return indexService.countLreByDate(indexInfoParamDto);

+ 1 - 1
module_kzks/src/main/java/org/jeecg/modules/Index/service/IndexService.java

@@ -14,7 +14,7 @@ import java.util.List;
 public interface IndexService {
     IndexTotalVo getTotalIncome(HttpServletRequest request);
 
-    IndexTotalVo getTotalContract(HttpServletRequest request);
+    IndexTotalVo getTotalContractNum(HttpServletRequest request);
 
     IndexTotalVo getTotalReceived(HttpServletRequest request);
 

+ 183 - 162
module_kzks/src/main/java/org/jeecg/modules/Index/service/impl/IndexServiceImpl.java

@@ -136,15 +136,13 @@ public class IndexServiceImpl implements IndexService {
         setZeroYear(instance);
         Date currentYearBeginDate = instance.getTime();
 
-        List<BigDecimal> currentYearIncomeList = new ArrayList<>();
-        IndexTotalVo finalIncomeDataInfoVo = incomeDataInfoVO;
-        CompletableFuture.runAsync(() -> {
+
+        CompletableFuture<BigDecimal> currentYearTotalFuture = CompletableFuture.supplyAsync(() -> {
             //根据年份和当前部门对应的任务号查询,部门当前年的年收入
             BigDecimal currentYearTotal = exchangeMapper.getIncomeYearTotalByTasknoListAndByQsrqRange(tasknoList, currentYearBeginDate, currentYearEndDate);
             if (ObjectUtils.isEmpty(currentYearTotal)) currentYearTotal = BigDecimal.valueOf(0);
-            finalIncomeDataInfoVo.setYearTotal(currentYearTotal);
-            currentYearIncomeList.add(currentYearTotal);
-        }).join();
+            return currentYearTotal;
+        });
 
         instance.setTime(new Date());
         instance.add(Calendar.YEAR, -1);
@@ -153,29 +151,23 @@ public class IndexServiceImpl implements IndexService {
         setZeroYear(instance);
         Date LastYearBeginDate = instance.getTime();
 
-        ArrayList<BigDecimal> lastYearTqIncomeList = new ArrayList<>();
         //根据年份和当前部门对应的任务号查询,部门去年同期年收入
-        CompletableFuture.runAsync(() -> {
+        CompletableFuture<BigDecimal> lastYearTqTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal lastYearTqTotal = exchangeMapper.getIncomeYearTotalByTasknoListAndByQsrqRange(tasknoList, LastYearBeginDate, LastTqEndDate);
             if (ObjectUtils.isEmpty(lastYearTqTotal)) lastYearTqTotal = BigDecimal.valueOf(0);
-            finalIncomeDataInfoVo.setYearTq(lastYearTqTotal);
-            lastYearTqIncomeList.add(lastYearTqTotal);
-        }).join();
-
+            return lastYearTqTotal;
+        });
 
         instance.setTime(new Date());
         Date currentMothEndDate = instance.getTime();
         setZeroMonth(instance);
         Date currentMothBginDate = instance.getTime();
 
-        ArrayList<BigDecimal> currentMonthTotalList = new ArrayList<>();
-
-        CompletableFuture.runAsync(() -> {
+        CompletableFuture<BigDecimal> currentMonthTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal currentMonthTotal = exchangeMapper.getIncomeYearTotalByTasknoListAndByQsrqRange(tasknoList, currentMothBginDate, currentMothEndDate);
             if (ObjectUtils.isEmpty(currentMonthTotal)) currentMonthTotal = BigDecimal.valueOf(0);
-            finalIncomeDataInfoVo.setMonthTotal(currentMonthTotal);
-            currentMonthTotalList.add(currentMonthTotal);
-        }).join();
+            return currentMonthTotal;
+        });
 
 
         instance.setTime(new Date());
@@ -184,12 +176,12 @@ public class IndexServiceImpl implements IndexService {
         setZeroMonth(instance);
         Date LastMothTqBeginDate = instance.getTime();
 
-        ArrayList<BigDecimal> lastMothTqTotalList = new ArrayList<>();
-        CompletableFuture.runAsync(() -> {
+
+        CompletableFuture<BigDecimal> lastMothTqTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal lastMothTqTotal = exchangeMapper.getIncomeYearTotalByTasknoListAndByQsrqRange(tasknoList, LastMothTqBeginDate, LastMothTqEndDate);
             if (ObjectUtils.isEmpty(lastMothTqTotal)) lastMothTqTotal = BigDecimal.valueOf(0);
-            lastMothTqTotalList.add(lastMothTqTotal);
-        }).join();
+            return lastMothTqTotal;
+        });
 
 
         instance.setTime(new Date());
@@ -198,69 +190,84 @@ public class IndexServiceImpl implements IndexService {
         setZeroMonth(instance);
         Date lastYearMonthTqBeginDate = instance.getTime();
 
-        ArrayList<BigDecimal> lastYearMonthTqTotalList = new ArrayList<>();
-        CompletableFuture.runAsync(() -> {
+        CompletableFuture<BigDecimal> lastYearMonthTqTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal lastYearMonthTqTotal = exchangeMapper.getIncomeYearTotalByTasknoListAndByQsrqRange(tasknoList, lastYearMonthTqBeginDate, lastYearMonthTqEndDate);
             if (ObjectUtils.isEmpty(lastYearMonthTqTotal)) lastYearMonthTqTotal = BigDecimal.valueOf(0);
-            lastYearMonthTqTotalList.add(lastYearMonthTqTotal);
-        }).join();
+            return lastYearMonthTqTotal;
+        });
+
+        CompletableFuture<Void> future = CompletableFuture.allOf(currentYearTotalFuture,lastYearTqTotalFuture, currentMonthTotalFuture, lastMothTqTotalFuture, lastYearMonthTqTotalFuture);
+        future.join();
+        BigDecimal currentYearTotal = currentYearTotalFuture.join();
+        BigDecimal lastYearTqTotal = lastYearTqTotalFuture.join();
+        BigDecimal currentMonthTotal = currentMonthTotalFuture.join();
+        BigDecimal lastMothTqTotal = lastMothTqTotalFuture.join();
+        BigDecimal lastYearMonthTqTotal = lastYearMonthTqTotalFuture.join();
+
+        incomeDataInfoVO.setYearTotal(currentYearTotal);
+        incomeDataInfoVO.setYearTq(lastYearTqTotal);
+        incomeDataInfoVO.setMonthTotal(currentMonthTotal);
+
 
 
-        CompletableFuture.runAsync(() -> {
-            BigDecimal currentYearTotal = currentYearIncomeList.get(0);
-            BigDecimal lastYearTqTotal = lastYearTqIncomeList.get(0);
+        CompletableFuture<BigDecimal> incomeYearTbFuture = CompletableFuture.supplyAsync(() -> {
             //去年同比
             BigDecimal YearDifference = currentYearTotal.subtract(lastYearTqTotal);
             BigDecimal incomeYearTb = BigDecimal.valueOf(1);
             if (lastYearTqTotal.compareTo(BigDecimal.valueOf(0)) != 0)
                 incomeYearTb = YearDifference.divide(lastYearTqTotal, 2, RoundingMode.HALF_UP);
-            finalIncomeDataInfoVo.setYearTb(incomeYearTb);
-        }).join();
+            return incomeYearTb;
+        });
 
-        CompletableFuture.runAsync(() -> {
-            BigDecimal currentMonthTotal = currentMonthTotalList.get(0);
-            BigDecimal lastMothTqTotal = lastMothTqTotalList.get(0);
+        CompletableFuture<BigDecimal> incomeMothHbFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal MothDifference = currentMonthTotal.subtract(lastMothTqTotal);
             BigDecimal incomeMothHb = BigDecimal.valueOf(1);
             if (lastMothTqTotal.compareTo(BigDecimal.valueOf(0)) != 0)
                 incomeMothHb = MothDifference.divide(lastMothTqTotal, 2, RoundingMode.HALF_UP);
-            finalIncomeDataInfoVo.setMonthHb(incomeMothHb);
-        }).join();
+            return incomeMothHb;
+        });
 
-        CompletableFuture.runAsync(() -> {
-            BigDecimal currentMonthTotal = currentMonthTotalList.get(0);
-            BigDecimal lastYearMonthTqTotal = lastYearMonthTqTotalList.get(0);
+        CompletableFuture<BigDecimal> incomeYearMothTbFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal yearMothDifference = currentMonthTotal.subtract(lastYearMonthTqTotal);
             BigDecimal incomeYearMothTb = BigDecimal.valueOf(1);
             if (lastYearMonthTqTotal.compareTo(BigDecimal.valueOf(0)) != 0)
                 incomeYearMothTb = yearMothDifference.divide(lastYearMonthTqTotal, 2, RoundingMode.HALF_UP);
-            finalIncomeDataInfoVo.setMonthTb(incomeYearMothTb);
-        }).join();
+            return incomeYearMothTb;
+        });
 
-        redisUtil.set(INCOME_DATA_REDIS_KEY + depart, finalIncomeDataInfoVo, 1000L * 60 * 60 * 2);
+        CompletableFuture<Void> future1 = CompletableFuture.allOf(incomeYearTbFuture, incomeMothHbFuture, incomeYearMothTbFuture);
+        future1.join();
+        BigDecimal incomeYearTb = incomeYearTbFuture.join();
+        BigDecimal incomeMothHb = incomeMothHbFuture.join();
+        BigDecimal incomeYearMothTb = incomeYearMothTbFuture.join();
+        incomeDataInfoVO.setYearTb(incomeYearTb);
+        incomeDataInfoVO.setMonthTb(incomeYearMothTb);
+        incomeDataInfoVO.setMonthHb(incomeMothHb);
 
-        return finalIncomeDataInfoVo;
+        redisUtil.set(INCOME_DATA_REDIS_KEY + depart, incomeDataInfoVO, 1000L * 60 * 60 * 2);
+
+        return incomeDataInfoVO;
     }
 
 
     /*合同数量一层*/
     @Override
-    public IndexTotalVo getTotalContract(HttpServletRequest request) {
-        //首页合同渲染对象
+    public IndexTotalVo getTotalContractNum(HttpServletRequest request) {
+        //首页收入渲染对象
         BigDecimal initValue = BigDecimal.valueOf(0);
-        IndexTotalVo contractDataInfoVo = new IndexTotalVo();
-        contractDataInfoVo.setYearTotal(initValue);
-        contractDataInfoVo.setYearTq(initValue);
-        contractDataInfoVo.setYearTb(initValue);
-        contractDataInfoVo.setMonthTotal(initValue);
-        contractDataInfoVo.setMonthHb(initValue);
-        contractDataInfoVo.setMonthTb(initValue);
+        IndexTotalVo totalContractNumInfoVO = new IndexTotalVo();
+        totalContractNumInfoVO.setYearTotal(initValue);
+        totalContractNumInfoVO.setYearTq(initValue);
+        totalContractNumInfoVO.setYearTb(initValue);
+        totalContractNumInfoVO.setMonthTotal(initValue);
+        totalContractNumInfoVO.setMonthHb(initValue);
+        totalContractNumInfoVO.setMonthTb(initValue);
 
         String userNameByToken = JwtUtil.getUserNameByToken(request);
         LoginUser sysUser = sysBaseApi.getUserByName(userNameByToken);
 
         List<String> departNames = sysDepartMapper.getSysUserOfDepartNameList(sysUser.getId());
-        if (departNames.isEmpty()) return contractDataInfoVo;
+        if (departNames.isEmpty()) return totalContractNumInfoVO;
 
         StringBuilder stringBuilder = new StringBuilder();
         for (String departName : departNames) {
@@ -269,8 +276,8 @@ public class IndexServiceImpl implements IndexService {
         String depart = stringBuilder.toString();
         IndexTotalVo cacheObject = (IndexTotalVo) redisUtil.get(CONTRACT_DATA_REDIS_KEY + depart);
         if (ObjectUtils.isNotEmpty(cacheObject)) {
-            contractDataInfoVo = cacheObject;
-            return contractDataInfoVo;
+            totalContractNumInfoVO = cacheObject;
+            return totalContractNumInfoVO;
         }
 
         ArrayList<String> tasknoList = new ArrayList<>();
@@ -278,7 +285,8 @@ public class IndexServiceImpl implements IndexService {
         List<String> XdbmTasknoList = projectCostMapper.queryXdbmTasknoListbydepartNames(departNames);
         tasknoList.addAll(ZrbmTasknoList);
         tasknoList.addAll(XdbmTasknoList);
-        if (tasknoList.isEmpty()) return contractDataInfoVo;
+        if (tasknoList.isEmpty()) return totalContractNumInfoVO;
+
 
         Calendar instance = Calendar.getInstance();
 
@@ -286,15 +294,13 @@ public class IndexServiceImpl implements IndexService {
         setZeroYear(instance);
         Date currentYearBeginDate = instance.getTime();
 
-        List<BigDecimal> currentYearIncomeList = new ArrayList<>();
-        IndexTotalVo finalContractDataInfoVo = contractDataInfoVo;
-        CompletableFuture.runAsync(() -> {
+
+        CompletableFuture<BigDecimal> currentYearTotalFuture = CompletableFuture.supplyAsync(() -> {
             //根据年份和当前部门对应的任务号查询,部门当前年的年收入
             BigDecimal currentYearTotal = exchangeMapper.getContractNumYearTotalByTasknoListAndByQsrqRange(tasknoList, currentYearBeginDate, currentYearEndDate);
             if (ObjectUtils.isEmpty(currentYearTotal)) currentYearTotal = BigDecimal.valueOf(0);
-            finalContractDataInfoVo.setYearTotal(currentYearTotal);
-            currentYearIncomeList.add(currentYearTotal);
-        }).join();
+            return currentYearTotal;
+        });
 
         instance.setTime(new Date());
         instance.add(Calendar.YEAR, -1);
@@ -303,28 +309,23 @@ public class IndexServiceImpl implements IndexService {
         setZeroYear(instance);
         Date LastYearBeginDate = instance.getTime();
 
-        ArrayList<BigDecimal> lastYearTqIncomeList = new ArrayList<>();
         //根据年份和当前部门对应的任务号查询,部门去年同期年收入
-        CompletableFuture.runAsync(() -> {
+        CompletableFuture<BigDecimal> lastYearTqTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal lastYearTqTotal = exchangeMapper.getContractNumYearTotalByTasknoListAndByQsrqRange(tasknoList, LastYearBeginDate, LastTqEndDate);
             if (ObjectUtils.isEmpty(lastYearTqTotal)) lastYearTqTotal = BigDecimal.valueOf(0);
-            finalContractDataInfoVo.setYearTq(lastYearTqTotal);
-            lastYearTqIncomeList.add(lastYearTqTotal);
-        }).join();
+            return lastYearTqTotal;
+        });
 
         instance.setTime(new Date());
         Date currentMothEndDate = instance.getTime();
         setZeroMonth(instance);
         Date currentMothBginDate = instance.getTime();
 
-        ArrayList<BigDecimal> currentMonthTotalList = new ArrayList<>();
-
-        CompletableFuture.runAsync(() -> {
+        CompletableFuture<BigDecimal> currentMonthTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal currentMonthTotal = exchangeMapper.getContractNumYearTotalByTasknoListAndByQsrqRange(tasknoList, currentMothBginDate, currentMothEndDate);
             if (ObjectUtils.isEmpty(currentMonthTotal)) currentMonthTotal = BigDecimal.valueOf(0);
-            finalContractDataInfoVo.setMonthTotal(currentMonthTotal);
-            currentMonthTotalList.add(currentMonthTotal);
-        }).join();
+            return currentMonthTotal;
+        });
 
 
         instance.setTime(new Date());
@@ -333,12 +334,13 @@ public class IndexServiceImpl implements IndexService {
         setZeroMonth(instance);
         Date LastMothTqBeginDate = instance.getTime();
 
-        ArrayList<BigDecimal> lastMothTqTotalList = new ArrayList<>();
-        CompletableFuture.runAsync(() -> {
+
+        CompletableFuture<BigDecimal> lastMothTqTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal lastMothTqTotal = exchangeMapper.getContractNumYearTotalByTasknoListAndByQsrqRange(tasknoList, LastMothTqBeginDate, LastMothTqEndDate);
             if (ObjectUtils.isEmpty(lastMothTqTotal)) lastMothTqTotal = BigDecimal.valueOf(0);
-            lastMothTqTotalList.add(lastMothTqTotal);
-        }).join();
+            return lastMothTqTotal;
+        });
+
 
         instance.setTime(new Date());
         instance.add(Calendar.YEAR, -1);
@@ -346,69 +348,84 @@ public class IndexServiceImpl implements IndexService {
         setZeroMonth(instance);
         Date lastYearMonthTqBeginDate = instance.getTime();
 
-        ArrayList<BigDecimal> lastYearMonthTqTotalList = new ArrayList<>();
-        CompletableFuture.runAsync(() -> {
+        CompletableFuture<BigDecimal> lastYearMonthTqTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal lastYearMonthTqTotal = exchangeMapper.getContractNumYearTotalByTasknoListAndByQsrqRange(tasknoList, lastYearMonthTqBeginDate, lastYearMonthTqEndDate);
             if (ObjectUtils.isEmpty(lastYearMonthTqTotal)) lastYearMonthTqTotal = BigDecimal.valueOf(0);
-            lastYearMonthTqTotalList.add(lastYearMonthTqTotal);
-        }).join();
+            return lastYearMonthTqTotal;
+        });
+
+        CompletableFuture<Void> future = CompletableFuture.allOf(currentYearTotalFuture,lastYearTqTotalFuture, currentMonthTotalFuture, lastMothTqTotalFuture, lastYearMonthTqTotalFuture);
+        future.join();
+        BigDecimal currentYearTotal = currentYearTotalFuture.join();
+        BigDecimal lastYearTqTotal = lastYearTqTotalFuture.join();
+        BigDecimal currentMonthTotal = currentMonthTotalFuture.join();
+        BigDecimal lastMothTqTotal = lastMothTqTotalFuture.join();
+        BigDecimal lastYearMonthTqTotal = lastYearMonthTqTotalFuture.join();
+
+        totalContractNumInfoVO.setYearTotal(currentYearTotal);
+        totalContractNumInfoVO.setYearTq(lastYearTqTotal);
+        totalContractNumInfoVO.setMonthTotal(currentMonthTotal);
+
 
 
-        CompletableFuture.runAsync(() -> {
-            BigDecimal currentYearTotal = currentYearIncomeList.get(0);
-            BigDecimal lastYearTqTotal = lastYearTqIncomeList.get(0);
+        CompletableFuture<BigDecimal> yearTbFuture = CompletableFuture.supplyAsync(() -> {
             //去年同比
             BigDecimal YearDifference = currentYearTotal.subtract(lastYearTqTotal);
-            BigDecimal contractYearTb = BigDecimal.valueOf(1);
+            BigDecimal incomeYearTb = BigDecimal.valueOf(1);
             if (lastYearTqTotal.compareTo(BigDecimal.valueOf(0)) != 0)
-                contractYearTb = YearDifference.divide(lastYearTqTotal, 2, RoundingMode.HALF_UP);
-            finalContractDataInfoVo.setYearTb(contractYearTb);
-        }).join();
+                incomeYearTb = YearDifference.divide(lastYearTqTotal, 2, RoundingMode.HALF_UP);
+            return incomeYearTb;
+        });
 
-        CompletableFuture.runAsync(() -> {
-            BigDecimal currentMonthTotal = currentMonthTotalList.get(0);
-            BigDecimal lastMothTqTotal = lastMothTqTotalList.get(0);
+        CompletableFuture<BigDecimal> mothHbFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal MothDifference = currentMonthTotal.subtract(lastMothTqTotal);
-            BigDecimal contractMothHb = BigDecimal.valueOf(1);
+            BigDecimal incomeMothHb = BigDecimal.valueOf(1);
             if (lastMothTqTotal.compareTo(BigDecimal.valueOf(0)) != 0)
-                contractMothHb = MothDifference.divide(lastMothTqTotal, 2, RoundingMode.HALF_UP);
-            finalContractDataInfoVo.setMonthHb(contractMothHb);
-        }).join();
+                incomeMothHb = MothDifference.divide(lastMothTqTotal, 2, RoundingMode.HALF_UP);
+            return incomeMothHb;
+        });
 
-        CompletableFuture.runAsync(() -> {
-            BigDecimal currentMonthTotal = currentMonthTotalList.get(0);
-            BigDecimal lastYearMonthTqTotal = lastYearMonthTqTotalList.get(0);
+        CompletableFuture<BigDecimal> yearMothTbFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal yearMothDifference = currentMonthTotal.subtract(lastYearMonthTqTotal);
-            BigDecimal contractYearMothTb = BigDecimal.valueOf(1);
+            BigDecimal incomeYearMothTb = BigDecimal.valueOf(1);
             if (lastYearMonthTqTotal.compareTo(BigDecimal.valueOf(0)) != 0)
-                contractYearMothTb = yearMothDifference.divide(lastYearMonthTqTotal, 2, RoundingMode.HALF_UP);
-            finalContractDataInfoVo.setMonthTb(contractYearMothTb);
-        }).join();
+                incomeYearMothTb = yearMothDifference.divide(lastYearMonthTqTotal, 2, RoundingMode.HALF_UP);
+            return incomeYearMothTb;
+        });
 
-        redisUtil.set(CONTRACT_DATA_REDIS_KEY + depart, finalContractDataInfoVo, 1000L * 60 * 60 * 2);
+        CompletableFuture<Void> future1 = CompletableFuture.allOf(yearTbFuture, mothHbFuture, yearMothTbFuture);
+        future1.join();
+        BigDecimal yearTb = yearTbFuture.join();
+        BigDecimal mothHb = mothHbFuture.join();
+        BigDecimal yearMothTb = yearMothTbFuture.join();
+        totalContractNumInfoVO.setYearTb(yearTb);
+        totalContractNumInfoVO.setMonthTb(yearMothTb);
+        totalContractNumInfoVO.setMonthHb(mothHb);
 
+        redisUtil.set(CONTRACT_DATA_REDIS_KEY + depart, totalContractNumInfoVO, 1000L * 60 * 60 * 2);
 
-        return finalContractDataInfoVo;
+        return totalContractNumInfoVO;
     }
 
 
     /*已收款一层*/
     @Override
     public IndexTotalVo getTotalReceived(HttpServletRequest request) {
+        //首页收入渲染对象
         BigDecimal initValue = BigDecimal.valueOf(0);
-        IndexTotalVo receivedDataInfoVo = new IndexTotalVo();
-        receivedDataInfoVo.setYearTotal(initValue);
-        receivedDataInfoVo.setYearTq(initValue);
-        receivedDataInfoVo.setYearTb(initValue);
-        receivedDataInfoVo.setMonthTotal(initValue);
-        receivedDataInfoVo.setMonthHb(initValue);
-        receivedDataInfoVo.setMonthTb(initValue);
+        IndexTotalVo indexTotalVo = new IndexTotalVo();
+        indexTotalVo.setYearTotal(initValue);
+        indexTotalVo.setYearTq(initValue);
+        indexTotalVo.setYearTb(initValue);
+        indexTotalVo.setMonthTotal(initValue);
+        indexTotalVo.setMonthHb(initValue);
+        indexTotalVo.setMonthTb(initValue);
 
         String userNameByToken = JwtUtil.getUserNameByToken(request);
         LoginUser sysUser = sysBaseApi.getUserByName(userNameByToken);
 
         List<String> departNames = sysDepartMapper.getSysUserOfDepartNameList(sysUser.getId());
-        if (departNames.isEmpty()) return receivedDataInfoVo;
+        if (departNames.isEmpty()) return indexTotalVo;
 
         StringBuilder stringBuilder = new StringBuilder();
         for (String departName : departNames) {
@@ -417,8 +434,8 @@ public class IndexServiceImpl implements IndexService {
         String depart = stringBuilder.toString();
         IndexTotalVo cacheObject = (IndexTotalVo) redisUtil.get(RECEIVED_DATA_REDIS_KEY + depart);
         if (ObjectUtils.isNotEmpty(cacheObject)) {
-            receivedDataInfoVo = cacheObject;
-            return receivedDataInfoVo;
+            indexTotalVo = cacheObject;
+            return indexTotalVo;
         }
 
         ArrayList<String> tasknoList = new ArrayList<>();
@@ -426,7 +443,7 @@ public class IndexServiceImpl implements IndexService {
         List<String> XdbmTasknoList = projectCostMapper.queryXdbmTasknoListbydepartNames(departNames);
         tasknoList.addAll(ZrbmTasknoList);
         tasknoList.addAll(XdbmTasknoList);
-        if (tasknoList.isEmpty()) return receivedDataInfoVo;
+        if (tasknoList.isEmpty()) return indexTotalVo;
 
 
         Calendar instance = Calendar.getInstance();
@@ -435,15 +452,12 @@ public class IndexServiceImpl implements IndexService {
         setZeroYear(instance);
         Date currentYearBeginDate = instance.getTime();
 
-        List<BigDecimal> currentYearIncomeList = new ArrayList<>();
-        IndexTotalVo finalIncomeDataInfoVo = receivedDataInfoVo;
-        CompletableFuture.runAsync(() -> {
-            //根据年份和当前部门对应的任务号查询,部门当前年的年收入
+
+        CompletableFuture<BigDecimal> currentYearTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal currentYearTotal = exchangeMapper.getReceivedYearTotalByTasknoListAndByQsrqRange(tasknoList, currentYearBeginDate, currentYearEndDate);
             if (ObjectUtils.isEmpty(currentYearTotal)) currentYearTotal = BigDecimal.valueOf(0);
-            finalIncomeDataInfoVo.setYearTotal(currentYearTotal);
-            currentYearIncomeList.add(currentYearTotal);
-        }).join();
+            return currentYearTotal;
+        });
 
         instance.setTime(new Date());
         instance.add(Calendar.YEAR, -1);
@@ -452,29 +466,22 @@ public class IndexServiceImpl implements IndexService {
         setZeroYear(instance);
         Date LastYearBeginDate = instance.getTime();
 
-        ArrayList<BigDecimal> lastYearTqIncomeList = new ArrayList<>();
-        //根据年份和当前部门对应的任务号查询,部门去年同期年收入
-        CompletableFuture.runAsync(() -> {
+        CompletableFuture<BigDecimal> lastYearTqTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal lastYearTqTotal = exchangeMapper.getReceivedYearTotalByTasknoListAndByQsrqRange(tasknoList, LastYearBeginDate, LastTqEndDate);
             if (ObjectUtils.isEmpty(lastYearTqTotal)) lastYearTqTotal = BigDecimal.valueOf(0);
-            finalIncomeDataInfoVo.setYearTq(lastYearTqTotal);
-            lastYearTqIncomeList.add(lastYearTqTotal);
-        }).join();
-
+            return lastYearTqTotal;
+        });
 
         instance.setTime(new Date());
         Date currentMothEndDate = instance.getTime();
         setZeroMonth(instance);
         Date currentMothBginDate = instance.getTime();
 
-        ArrayList<BigDecimal> currentMonthTotalList = new ArrayList<>();
-
-        CompletableFuture.runAsync(() -> {
+        CompletableFuture<BigDecimal> currentMonthTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal currentMonthTotal = exchangeMapper.getReceivedYearTotalByTasknoListAndByQsrqRange(tasknoList, currentMothBginDate, currentMothEndDate);
             if (ObjectUtils.isEmpty(currentMonthTotal)) currentMonthTotal = BigDecimal.valueOf(0);
-            finalIncomeDataInfoVo.setMonthTotal(currentMonthTotal);
-            currentMonthTotalList.add(currentMonthTotal);
-        }).join();
+            return currentMonthTotal;
+        });
 
 
         instance.setTime(new Date());
@@ -483,12 +490,12 @@ public class IndexServiceImpl implements IndexService {
         setZeroMonth(instance);
         Date LastMothTqBeginDate = instance.getTime();
 
-        ArrayList<BigDecimal> lastMothTqTotalList = new ArrayList<>();
-        CompletableFuture.runAsync(() -> {
+
+        CompletableFuture<BigDecimal> lastMothTqTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal lastMothTqTotal = exchangeMapper.getReceivedYearTotalByTasknoListAndByQsrqRange(tasknoList, LastMothTqBeginDate, LastMothTqEndDate);
             if (ObjectUtils.isEmpty(lastMothTqTotal)) lastMothTqTotal = BigDecimal.valueOf(0);
-            lastMothTqTotalList.add(lastMothTqTotal);
-        }).join();
+            return lastMothTqTotal;
+        });
 
 
         instance.setTime(new Date());
@@ -497,51 +504,66 @@ public class IndexServiceImpl implements IndexService {
         setZeroMonth(instance);
         Date lastYearMonthTqBeginDate = instance.getTime();
 
-        ArrayList<BigDecimal> lastYearMonthTqTotalList = new ArrayList<>();
-        CompletableFuture.runAsync(() -> {
+        CompletableFuture<BigDecimal> lastYearMonthTqTotalFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal lastYearMonthTqTotal = exchangeMapper.getReceivedYearTotalByTasknoListAndByQsrqRange(tasknoList, lastYearMonthTqBeginDate, lastYearMonthTqEndDate);
             if (ObjectUtils.isEmpty(lastYearMonthTqTotal)) lastYearMonthTqTotal = BigDecimal.valueOf(0);
-            lastYearMonthTqTotalList.add(lastYearMonthTqTotal);
-        }).join();
+            return lastYearMonthTqTotal;
+        });
+
+        CompletableFuture<Void> future = CompletableFuture.allOf(currentYearTotalFuture,lastYearTqTotalFuture, currentMonthTotalFuture, lastMothTqTotalFuture, lastYearMonthTqTotalFuture);
+        future.join();
+        BigDecimal currentYearTotal = currentYearTotalFuture.join();
+        BigDecimal lastYearTqTotal = lastYearTqTotalFuture.join();
+        BigDecimal currentMonthTotal = currentMonthTotalFuture.join();
+        BigDecimal lastMothTqTotal = lastMothTqTotalFuture.join();
+        BigDecimal lastYearMonthTqTotal = lastYearMonthTqTotalFuture.join();
 
+        indexTotalVo.setYearTotal(currentYearTotal);
+        indexTotalVo.setYearTq(lastYearTqTotal);
+        indexTotalVo.setMonthTotal(currentMonthTotal);
 
-        CompletableFuture.runAsync(() -> {
-            BigDecimal currentYearTotal = currentYearIncomeList.get(0);
-            BigDecimal lastYearTqTotal = lastYearTqIncomeList.get(0);
+
+
+        CompletableFuture<BigDecimal> yearTbFuture = CompletableFuture.supplyAsync(() -> {
             //去年同比
             BigDecimal YearDifference = currentYearTotal.subtract(lastYearTqTotal);
             BigDecimal incomeYearTb = BigDecimal.valueOf(1);
             if (lastYearTqTotal.compareTo(BigDecimal.valueOf(0)) != 0)
                 incomeYearTb = YearDifference.divide(lastYearTqTotal, 2, RoundingMode.HALF_UP);
-            finalIncomeDataInfoVo.setYearTb(incomeYearTb);
-        }).join();
+            return incomeYearTb;
+        });
 
-        CompletableFuture.runAsync(() -> {
-            BigDecimal currentMonthTotal = currentMonthTotalList.get(0);
-            BigDecimal lastMothTqTotal = lastMothTqTotalList.get(0);
+        CompletableFuture<BigDecimal> mothHbFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal MothDifference = currentMonthTotal.subtract(lastMothTqTotal);
             BigDecimal incomeMothHb = BigDecimal.valueOf(1);
             if (lastMothTqTotal.compareTo(BigDecimal.valueOf(0)) != 0)
                 incomeMothHb = MothDifference.divide(lastMothTqTotal, 2, RoundingMode.HALF_UP);
-            finalIncomeDataInfoVo.setMonthHb(incomeMothHb);
-        }).join();
+            return incomeMothHb;
+        });
 
-        CompletableFuture.runAsync(() -> {
-            BigDecimal currentMonthTotal = currentMonthTotalList.get(0);
-            BigDecimal lastYearMonthTqTotal = lastYearMonthTqTotalList.get(0);
+        CompletableFuture<BigDecimal> yearMothTbFuture = CompletableFuture.supplyAsync(() -> {
             BigDecimal yearMothDifference = currentMonthTotal.subtract(lastYearMonthTqTotal);
             BigDecimal incomeYearMothTb = BigDecimal.valueOf(1);
             if (lastYearMonthTqTotal.compareTo(BigDecimal.valueOf(0)) != 0)
                 incomeYearMothTb = yearMothDifference.divide(lastYearMonthTqTotal, 2, RoundingMode.HALF_UP);
-            finalIncomeDataInfoVo.setMonthTb(incomeYearMothTb);
-        }).join();
+            return incomeYearMothTb;
+        });
+
+        CompletableFuture<Void> future1 = CompletableFuture.allOf(yearTbFuture, mothHbFuture, yearMothTbFuture);
+        future1.join();
+        BigDecimal yearTb = yearTbFuture.join();
+        BigDecimal mothHb = mothHbFuture.join();
+        BigDecimal yearMothTb = yearMothTbFuture.join();
+        indexTotalVo.setYearTb(yearTb);
+        indexTotalVo.setMonthTb(yearMothTb);
+        indexTotalVo.setMonthHb(mothHb);
 
-        redisUtil.set(RECEIVED_DATA_REDIS_KEY + depart, finalIncomeDataInfoVo, 1000L * 60 * 60 * 2);
+        redisUtil.set(RECEIVED_DATA_REDIS_KEY + depart, indexTotalVo, 1000L * 60 * 60 * 2);
 
-        return finalIncomeDataInfoVo;
+        return indexTotalVo;
     }
 
-    public void setZeroYear(Calendar instance) {
+    public void  setZeroYear(Calendar instance) {
         instance.set(Calendar.MONTH, 0);
         instance.set(Calendar.DAY_OF_MONTH, 0);
         instance.set(Calendar.HOUR_OF_DAY, 0);
@@ -577,7 +599,6 @@ public class IndexServiceImpl implements IndexService {
         return resultl;
     }
 
-
     public ContractChartInfoVo getContractAmountInfo(HttpServletRequest request, IndexInfoParamDto indexInfoParamDto,String Time) {
         /*根据传进来年份或者月份初始化返回结果对象*/
         ContractChartInfoVo resVo = new ContractChartInfoVo();

+ 34 - 51
module_kzks/src/main/java/org/jeecg/modules/projectCostHuiji/controller/ProjectCostHuijiController.java

@@ -30,10 +30,7 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
 import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 
@@ -100,11 +97,7 @@ public class ProjectCostHuijiController extends JeecgController<ProjectCostHuiji
                                                        @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                        HttpServletRequest req) {
         ProjectCostHuijiSumVO sumVO = new ProjectCostHuijiSumVO();
-        final List<ProjectCostHuiji> huijiList = new ArrayList<>();
-        CompletableFuture.runAsync(()->{
             ProjectCostHuiji huiji = projectCostHuijiService.costHJSum(projectCostHuiji);//汇集总和
-            huijiList.add(huiji);
-        }).join();
 
         QueryWrapper<ProjectCostHuiji> queryWrapper = QueryGenerator.initQueryWrapper(projectCostHuiji, req.getParameterMap());
         Page<ProjectCostHuiji> page = new Page<ProjectCostHuiji>(pageNo, pageSize);
@@ -116,49 +109,22 @@ public class ProjectCostHuijiController extends JeecgController<ProjectCostHuiji
                 List<ProjectCostVO> children2 = costService.costListByTaskNoSub(i.getTaskno()); //子任务及批产的子任务
                 List<ProjectCostVO> children = new ArrayList<>();
 
-                final ArrayList<List<ProjectCostVO>> children3List = new ArrayList<>();
-                CompletableFuture.runAsync(() -> {
-                    List<ProjectCostVO> children3 = children1.stream().map(x -> {
-                        KzksProjectCostYs ys = costYsService.selectYSByTaskno(x.getTaskno());
-                        if (ys != null) {
-                            if (ys.getClys() != null) {
-                                x.setClys(ys.getClys());
-                            } else {
-                                x.setClys(BigDecimal.valueOf(0));
-                            }
-                            if (ys.getWxys() != null) {
-                                x.setWxys(ys.getWxys());
-                            } else {
-                                x.setWxys(BigDecimal.valueOf(0));
-                            }
-                        }
-                        return x;
-                    }).collect(Collectors.toList());
-                    children3List.add(children3);
-                    children.addAll(children3List.get(0));
-                }).join();
+                CompletableFuture<List<ProjectCostVO>> children3Future = CompletableFuture.supplyAsync(() -> {
+                    return children1.stream().map(this::apply).collect(Collectors.toList());
+                });
 
-                final ArrayList<List<ProjectCostVO>> children4List = new ArrayList<>();
-                CompletableFuture.runAsync(() -> {
-                    List<ProjectCostVO> children4 = children2.stream().map(x -> {
-                        KzksProjectCostYs ys = costYsService.selectYSByTaskno(x.getTaskno());
-                        if (ys != null) {
-                            if (ys.getClys() != null) {
-                                x.setClys(ys.getClys());
-                            } else {
-                                x.setClys(BigDecimal.valueOf(0));
-                            }
-                            if (ys.getWxys() != null) {
-                                x.setWxys(ys.getWxys());
-                            } else {
-                                x.setWxys(BigDecimal.valueOf(0));
-                            }
-                        }
-                        return x;
-                    }).collect(Collectors.toList());
-                    children4List.add(children4);
-                    children.addAll(children4List.get(0));
-                }).join();
+
+                CompletableFuture<List<ProjectCostVO>> children4Future = CompletableFuture.supplyAsync(() -> {
+                    return children2.stream().map(this::apply).collect(Collectors.toList());
+                });
+
+                CompletableFuture<Void> future = CompletableFuture.allOf(children3Future, children4Future);
+                future.join();
+
+                List<ProjectCostVO> children3 = children3Future.join();
+                List<ProjectCostVO> children4 = children4Future.join();
+                children.addAll(children3);
+                children.addAll(children4);
 
                 return ProjectCostHuijiConvert.INSTANCE.toHuijiListVO(i, children, 1);
 
@@ -166,12 +132,28 @@ public class ProjectCostHuijiController extends JeecgController<ProjectCostHuiji
 
             IPage<ProjectCostHuijiListVO> pageList1 = ProjectCostHuijiConvert.INSTANCE.toHuijiListVOPage(pageList, list);
 
-            sumVO.setProjectCostHuijiSum(huijiList.get(0));
+            sumVO.setProjectCostHuijiSum(huiji);
             sumVO.setPageList(pageList1);
             return Result.OK(sumVO);
         } else return Result.OK(new ProjectCostHuijiSumVO());
     }
 
+    private ProjectCostVO apply(ProjectCostVO x) {
+        KzksProjectCostYs ys = costYsService.selectYSByTaskno(x.getTaskno());
+        if (ys != null) {
+            if (ys.getClys() != null) {
+                x.setClys(ys.getClys());
+            } else {
+                x.setClys(BigDecimal.valueOf(0));
+            }
+            if (ys.getWxys() != null) {
+                x.setWxys(ys.getWxys());
+            } else {
+                x.setWxys(BigDecimal.valueOf(0));
+            }
+        }
+        return x;
+    }
     /**
      * 添加
      *
@@ -274,4 +256,5 @@ public class ProjectCostHuijiController extends JeecgController<ProjectCostHuiji
         return super.importExcel(request, response, ProjectCostHuiji.class);
     }
 
+
 }