This commit is contained in:
xiaofajia 2024-12-18 17:38:22 +08:00
parent ec37eaf03b
commit 324b241e12
4 changed files with 90 additions and 8 deletions

View File

@ -359,4 +359,15 @@ public class InspectionInfoController extends BaseController {
String name = inspectionInfoService.easyPoiExport("template/word/四川省超标排放汽车维护修理告知书.docx", str, map, request, response); String name = inspectionInfoService.easyPoiExport("template/word/四川省超标排放汽车维护修理告知书.docx", str, map, request, response);
return CommonResult.success(name); 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));
}
} }

View File

@ -139,4 +139,12 @@ public interface IInspectionInfoService extends IService<InspectionInfo>
List<RoleDO> getRoleList(); List<RoleDO> getRoleList();
String easyPoiExport(String templatePath, String filename, Map<String, Object> data, HttpServletRequest request, HttpServletResponse response); String easyPoiExport(String templatePath, String filename, Map<String, Object> data, HttpServletRequest request, HttpServletResponse response);
/**
* 获得不同状态的数据的数量
*
* @author 小李
* @date 16:22 2024/12/18
**/
Map<String, Long> getCountByType(Integer partnerId);
} }

View File

@ -9,9 +9,11 @@ import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import cn.afterturn.easypoi.word.WordExportUtil; import cn.afterturn.easypoi.word.WordExportUtil;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
@ -623,26 +625,26 @@ public class InspectionInfoServiceImpl extends ServiceImpl<InspectionInfoMapper,
/** /**
* 判断是否可以修改引车员 * 判断是否可以修改引车员
* *
* @param id 工单ID
* @author 小李 * @author 小李
* @date 15:22 2024/12/11 * @date 15:22 2024/12/11
* @param id 工单ID
**/ **/
@Override @Override
public Boolean judgeUpdateLeadMan(Long id){ public Boolean judgeUpdateLeadMan(Long id) {
boolean result = true; boolean result = true;
InspectionInfo inspectionInfo = baseMapper.selectById(id); InspectionInfo inspectionInfo = baseMapper.selectById(id);
if (!inspectionInfo.getStatus().equals("2")){ if (!inspectionInfo.getStatus().equals("2")) {
result = false; result = false;
} }
if (!result){ if (!result) {
List<InspectionWorkNode> list = workNodeService.list(new LambdaQueryWrapper<InspectionWorkNode>().eq(InspectionWorkNode::getInspectionInfoId, id)); List<InspectionWorkNode> list = workNodeService.list(new LambdaQueryWrapper<InspectionWorkNode>().eq(InspectionWorkNode::getInspectionInfoId, id));
Set<String> status = list.stream().map(InspectionWorkNode::getStatus).collect(Collectors.toSet()); Set<String> status = list.stream().map(InspectionWorkNode::getStatus).collect(Collectors.toSet());
if (status.contains("3")){ if (status.contains("3")) {
result = true; result = true;
} }
} }
if (result){ if (result) {
result = inspectionInfo.getCreator().equals(SecurityFrameworkUtils.getLoginUserId()+""); result = inspectionInfo.getCreator().equals(SecurityFrameworkUtils.getLoginUserId() + "");
} }
return result; return result;
} }
@ -663,6 +665,7 @@ public class InspectionInfoServiceImpl extends ServiceImpl<InspectionInfoMapper,
/** /**
* EasyPoi 替换数据 导出 word * EasyPoi 替换数据 导出 word
*
* @param templatePath word模板地址 * @param templatePath word模板地址
* @param filename 文件名称 * @param filename 文件名称
* @param data 替换参数 * @param data 替换参数
@ -691,10 +694,71 @@ public class InspectionInfoServiceImpl extends ServiceImpl<InspectionInfoMapper,
} }
return filename; return filename;
} }
public static MultipartFile convertXWPFDocumentToMultipartFile(XWPFDocument document, String filename) throws IOException { public static MultipartFile convertXWPFDocumentToMultipartFile(XWPFDocument document, String filename) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
document.write(bos); document.write(bos);
byte[] bytes = bos.toByteArray(); byte[] bytes = bos.toByteArray();
return new MockMultipartFile(filename, filename, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", bytes); return new MockMultipartFile(filename, filename, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", bytes);
} }
/**
* 获得不同状态的数据的数量
*
* @author 小李
* @date 16:22 2024/12/18
**/
@Override
public Map<String, Long> getCountByType(Integer partnerId) {
// 创建线程池
ExecutorService executor = Executors.newFixedThreadPool(6);
try {
InspectionInfo inspectionInfo = new InspectionInfo();
inspectionInfo.setPartnerId(partnerId.longValue());
// 获取当前登录人
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
// 获取当前登陆人的角色
List<UserRoleDO> byUserId = roleService.getByUserId(loginUser.getId());
inspectionInfo.setLeadManId(loginUser.getId());
List<Long> roleIds = byUserId.stream().map(UserRoleDO::getRoleId).collect(Collectors.toList());
if (!"1".equals(inspectionInfo.getStatus())) {
// 进行中 已完成
inspectionInfo.setDealUserId(loginUser.getId());
}
Map<String, Long> result = new ConcurrentHashMap<>(); // 使用ConcurrentHashMap以确保线程安全
// 定义一个数组来保存所有的CompletableFuture
CompletableFuture<Void>[] 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<InspectionInfo> page = new Page<>(1, 10);
futures[i] = CompletableFuture.runAsync(() -> {
IPage<InspectionInfo> 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();
}
}
} }

View File

@ -409,5 +409,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- </if>--> <!-- </if>-->
<!-- </where>--> <!-- </where>-->
</select> </select>
</mapper> </mapper>