diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/controller/InspectionInfoController.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/controller/InspectionInfoController.java index adf31725..b10a6b04 100644 --- a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/controller/InspectionInfoController.java +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/controller/InspectionInfoController.java @@ -359,4 +359,15 @@ public class InspectionInfoController extends BaseController { String name = inspectionInfoService.easyPoiExport("template/word/四川省超标排放汽车维护修理告知书.docx", str, map, request, response); return CommonResult.success(name); } + + /** + * 获得不同状态的数据的数量 + * + * @author 小李 + * @date 16:22 2024/12/18 + **/ + @GetMapping("/getCountByType") + public CommonResult getCountByType(@RequestParam("partnerId")Integer partnerId){ + return success(inspectionInfoService.getCountByType(partnerId)); + } } diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/IInspectionInfoService.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/IInspectionInfoService.java index f5532128..4b5e841b 100644 --- a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/IInspectionInfoService.java +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/IInspectionInfoService.java @@ -139,4 +139,12 @@ public interface IInspectionInfoService extends IService List getRoleList(); String easyPoiExport(String templatePath, String filename, Map data, HttpServletRequest request, HttpServletResponse response); + + /** + * 获得不同状态的数据的数量 + * + * @author 小李 + * @date 16:22 2024/12/18 + **/ + Map getCountByType(Integer partnerId); } diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionInfoServiceImpl.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionInfoServiceImpl.java index 32a4924f..111f4581 100644 --- a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionInfoServiceImpl.java +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionInfoServiceImpl.java @@ -9,9 +9,11 @@ import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.concurrent.*; import java.util.stream.Collectors; import cn.afterturn.easypoi.word.WordExportUtil; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.date.DateUtil; @@ -623,26 +625,26 @@ public class InspectionInfoServiceImpl extends ServiceImpl list = workNodeService.list(new LambdaQueryWrapper().eq(InspectionWorkNode::getInspectionInfoId, id)); Set status = list.stream().map(InspectionWorkNode::getStatus).collect(Collectors.toSet()); - if (status.contains("3")){ + if (status.contains("3")) { result = true; } } - if (result){ - result = inspectionInfo.getCreator().equals(SecurityFrameworkUtils.getLoginUserId()+""); + if (result) { + result = inspectionInfo.getCreator().equals(SecurityFrameworkUtils.getLoginUserId() + ""); } return result; } @@ -663,6 +665,7 @@ public class InspectionInfoServiceImpl extends ServiceImpl getCountByType(Integer partnerId) { + // 创建线程池 + ExecutorService executor = Executors.newFixedThreadPool(6); + + try { + InspectionInfo inspectionInfo = new InspectionInfo(); + inspectionInfo.setPartnerId(partnerId.longValue()); + + // 获取当前登录人 + LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); + // 获取当前登陆人的角色 + List byUserId = roleService.getByUserId(loginUser.getId()); + inspectionInfo.setLeadManId(loginUser.getId()); + List roleIds = byUserId.stream().map(UserRoleDO::getRoleId).collect(Collectors.toList()); + if (!"1".equals(inspectionInfo.getStatus())) { + // 进行中 已完成 + inspectionInfo.setDealUserId(loginUser.getId()); + } + + Map result = new ConcurrentHashMap<>(); // 使用ConcurrentHashMap以确保线程安全 + + // 定义一个数组来保存所有的CompletableFuture + CompletableFuture[] futures = new CompletableFuture[6]; + + for (int i = 0; i < 6; i++) { + final String status = String.valueOf(i); + + // 复制一份inspectionInfo对象,避免多线程修改同一个对象导致的问题 + InspectionInfo infoCopy = BeanUtil.toBean(inspectionInfo, InspectionInfo.class); + infoCopy.setStatus(status); + + // 为每个任务创建一个新的Page对象 + Page page = new Page<>(1, 10); + + futures[i] = CompletableFuture.runAsync(() -> { + IPage iPage = baseMapper.selectByUser(page, roleIds, infoCopy); + result.put(status, iPage.getTotal()); + }, executor); + } + + // 等待所有任务完成 + CompletableFuture.allOf(futures).join(); + + return result; + + } catch (Exception e) { + throw new RuntimeException("Failed to execute tasks in parallel", e); + } finally { + // 关闭线程池 + executor.shutdown(); + } + } } diff --git a/dl-module-inspection/src/main/resources/mapper/inspection/InspectionInfoMapper.xml b/dl-module-inspection/src/main/resources/mapper/inspection/InspectionInfoMapper.xml index 11ff1280..ef5cb90e 100644 --- a/dl-module-inspection/src/main/resources/mapper/inspection/InspectionInfoMapper.xml +++ b/dl-module-inspection/src/main/resources/mapper/inspection/InspectionInfoMapper.xml @@ -409,5 +409,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" -