修改
This commit is contained in:
parent
ec37eaf03b
commit
324b241e12
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -139,4 +139,12 @@ public interface IInspectionInfoService extends IService<InspectionInfo>
|
||||
List<RoleDO> getRoleList();
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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,9 +625,9 @@ public class InspectionInfoServiceImpl extends ServiceImpl<InspectionInfoMapper,
|
||||
/**
|
||||
* 判断是否可以修改引车员
|
||||
*
|
||||
* @param id 工单ID
|
||||
* @author 小李
|
||||
* @date 15:22 2024/12/11
|
||||
* @param id 工单ID
|
||||
**/
|
||||
@Override
|
||||
public Boolean judgeUpdateLeadMan(Long id) {
|
||||
@ -663,6 +665,7 @@ public class InspectionInfoServiceImpl extends ServiceImpl<InspectionInfoMapper,
|
||||
|
||||
/**
|
||||
* EasyPoi 替换数据 导出 word
|
||||
*
|
||||
* @param templatePath word模板地址
|
||||
* @param filename 文件名称
|
||||
* @param data 替换参数
|
||||
@ -691,10 +694,71 @@ public class InspectionInfoServiceImpl extends ServiceImpl<InspectionInfoMapper,
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
public static MultipartFile convertXWPFDocumentToMultipartFile(XWPFDocument document, String filename) throws IOException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
document.write(bos);
|
||||
byte[] bytes = bos.toByteArray();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -409,5 +409,4 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<!-- </if>-->
|
||||
<!-- </where>-->
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
Loading…
Reference in New Issue
Block a user