|
|
|
@ -9,6 +9,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.beust.ah.A; |
|
|
|
|
import digital.laboratory.platform.common.core.exception.CheckedException; |
|
|
|
|
import digital.laboratory.platform.common.core.util.R; |
|
|
|
|
import digital.laboratory.platform.entrustment.convert.DrugLiteConvert; |
|
|
|
@ -527,7 +528,7 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus |
|
|
|
|
|
|
|
|
|
LocalDateTime startTime = excelDTO.getStartTime(); |
|
|
|
|
LocalDateTime endTime = excelDTO.getEndTime(); |
|
|
|
|
String oldResult = excelDTO.getOldResult(); |
|
|
|
|
List<String> oldResults = excelDTO.getOldResult(); |
|
|
|
|
Integer entrustType = excelDTO.getEntrustType(); |
|
|
|
|
// 创建查询条件包装器
|
|
|
|
|
LambdaQueryWrapper<Entrustment> wrapper = new LambdaQueryWrapper<>(); |
|
|
|
@ -539,20 +540,26 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus |
|
|
|
|
} else { |
|
|
|
|
wrapper.ge(Entrustment::getAcceptTime, this.getStartTime(null)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 处理 oldResult 过滤条件
|
|
|
|
|
if (StringUtils.isNotBlank(oldResult)) { |
|
|
|
|
if ("委托".equals(oldResult)) { |
|
|
|
|
wrapper.in(Entrustment::getOldIdentificationResult, "首次鉴定", "补充鉴定", "重新鉴定"); |
|
|
|
|
} else { |
|
|
|
|
wrapper.eq(Entrustment::getOldIdentificationResult, oldResult); |
|
|
|
|
List<String> allResults = new ArrayList<>(); |
|
|
|
|
for (String oldResult : oldResults) { |
|
|
|
|
if (StringUtils.isNotBlank(oldResult)) { |
|
|
|
|
if ("委托".equals(oldResult)) { |
|
|
|
|
allResults.add("首次鉴定"); |
|
|
|
|
allResults.add("补充鉴定"); |
|
|
|
|
allResults.add("重新鉴定"); |
|
|
|
|
} else { |
|
|
|
|
allResults.add(oldResult); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!allResults.isEmpty()) { |
|
|
|
|
wrapper.in(Entrustment::getOldIdentificationResult, allResults); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询符合条件的 Entrustment 列表,避免重复查询数据库
|
|
|
|
|
List<Entrustment> entrustmentList = entrustmentService.list( |
|
|
|
|
wrapper.eq(entrustType != null, Entrustment::getEntrustmentType, entrustType) |
|
|
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
System.out.println("委托的数量:" + entrustmentList.size()); |
|
|
|
@ -592,7 +599,7 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus |
|
|
|
|
.in(EntrustMaterialCheckoutResult::getId, materialIds) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 将检测结果转换为 Map,避免后续 O(n^2) 复杂度查询
|
|
|
|
|
// 将检测结果转换为 Map
|
|
|
|
|
Map<String, EntrustMaterialCheckoutResult> resultMap = resultList.stream() |
|
|
|
|
.collect(Collectors.toMap(EntrustMaterialCheckoutResult::getId, Function.identity())); |
|
|
|
|
|
|
|
|
@ -630,7 +637,7 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus |
|
|
|
|
ResultExcelDTO excelDTO) { |
|
|
|
|
LocalDateTime startTime = excelDTO.getStartTime(); |
|
|
|
|
LocalDateTime endTime = excelDTO.getEndTime(); |
|
|
|
|
String oldResult = excelDTO.getOldResult(); |
|
|
|
|
List<String> oldResults = excelDTO.getOldResult(); |
|
|
|
|
Integer entrustType = excelDTO.getEntrustType(); |
|
|
|
|
try { |
|
|
|
|
// 1. 构建查询条件
|
|
|
|
@ -643,14 +650,23 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus |
|
|
|
|
qw.ge(Entrustment::getAcceptTime, this.getStartTime(null)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(oldResult)) { |
|
|
|
|
if (oldResult.equals("委托")) { |
|
|
|
|
String types[] = {"首次鉴定", "补充鉴定", "重新鉴定"}; |
|
|
|
|
qw.in(Entrustment::getOldIdentificationResult, types); |
|
|
|
|
} else { |
|
|
|
|
qw.eq(Entrustment::getOldIdentificationResult, oldResult); |
|
|
|
|
List<String> allResults = new ArrayList<>(); |
|
|
|
|
for (String oldResult : oldResults) { |
|
|
|
|
if (StringUtils.isNotBlank(oldResult)) { |
|
|
|
|
if ("委托".equals(oldResult)) { |
|
|
|
|
allResults.add("首次鉴定"); |
|
|
|
|
allResults.add("补充鉴定"); |
|
|
|
|
allResults.add("重新鉴定"); |
|
|
|
|
} else { |
|
|
|
|
allResults.add(oldResult); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!allResults.isEmpty()) { |
|
|
|
|
qw.in(Entrustment::getOldIdentificationResult, allResults); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 2. 查询委托数据
|
|
|
|
|
List<Entrustment> entrusts = entrustmentService.list(qw |
|
|
|
|
.eq(Entrustment::getEntrustmentType, entrustType) |
|
|
|
@ -772,8 +788,8 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus |
|
|
|
|
|
|
|
|
|
LocalDateTime startTime = excelDTO.getStartTime(); |
|
|
|
|
LocalDateTime endTime = excelDTO.getEndTime(); |
|
|
|
|
String oldResult = excelDTO.getOldResult(); |
|
|
|
|
Integer entrustType = excelDTO.getEntrustType(); |
|
|
|
|
List<String> oldResults = excelDTO.getOldResult(); |
|
|
|
|
|
|
|
|
|
if (resultData.isEmpty() || resultDataMap.isEmpty()) { |
|
|
|
|
return R.failed("没有符合条件的数据!"); |
|
|
|
@ -781,17 +797,17 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus |
|
|
|
|
|
|
|
|
|
Workbook workbook = new XSSFWorkbook(); |
|
|
|
|
|
|
|
|
|
createDataSheet(workbook, entrustType, oldResult, resultData); |
|
|
|
|
createStatisticsSheet(workbook, resultDataMap, entrustType, oldResult, startTime, endTime); |
|
|
|
|
createDataSheet(workbook, entrustType, resultData); |
|
|
|
|
createStatisticsSheet(workbook, resultDataMap, oldResults, entrustType, startTime, endTime); |
|
|
|
|
createDrugSheets(workbook, resultDataMap, entrustType); |
|
|
|
|
|
|
|
|
|
workbook.write(response.getOutputStream()); |
|
|
|
|
return R.ok("导出成功!"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void createDataSheet(Workbook workbook, Integer entrustType, String oldResult, List<EntrustmentIdentificationMaterialVO> resultData) { |
|
|
|
|
private void createDataSheet(Workbook workbook, Integer entrustType, List<EntrustmentIdentificationMaterialVO> resultData) { |
|
|
|
|
// 确定表名
|
|
|
|
|
String sheetName = (entrustType == 0) ? "常规毒品" : (StringUtils.isNotBlank(oldResult) ? "生物样本-" + oldResult : "生物样本"); |
|
|
|
|
String sheetName = (entrustType == 0) ? "常规毒品" : "生物样本"; |
|
|
|
|
Sheet sheet = workbook.createSheet(sheetName); |
|
|
|
|
|
|
|
|
|
// 定义表头
|
|
|
|
@ -824,10 +840,10 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus |
|
|
|
|
lastRow.createCell(2).setCellValue("总检出率:" + result.toString() + "%"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void createStatisticsSheet(Workbook workbook, Map<String, List<EntrustmentIdentificationMaterialVO>> resultDataMap, Integer entrustType, String oldResult, LocalDateTime startTime, LocalDateTime endTime) { |
|
|
|
|
private void createStatisticsSheet(Workbook workbook, Map<String, List<EntrustmentIdentificationMaterialVO>> resultDataMap, List<String> oldResults, Integer entrustType, LocalDateTime startTime, LocalDateTime endTime) { |
|
|
|
|
Sheet sheet = workbook.createSheet("统计"); |
|
|
|
|
|
|
|
|
|
String[] headers = {"化合物种类", "类型", "检出数量", "总数量", "检出率"}; |
|
|
|
|
String[] headers = {"化合物种类", "检出数量", "总数量", "检出率"}; |
|
|
|
|
|
|
|
|
|
// 创建表头
|
|
|
|
|
Row headerRow = sheet.createRow(0); |
|
|
|
@ -837,7 +853,7 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 获取总数量
|
|
|
|
|
Map<String, Integer> sizeMap = this.getSizeMap(entrustType, oldResult, startTime, endTime); |
|
|
|
|
Integer size = this.getSizeMap(entrustType, oldResults, startTime, endTime); |
|
|
|
|
|
|
|
|
|
// 填充统计数据
|
|
|
|
|
int rowIndex = 1; |
|
|
|
@ -845,23 +861,10 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus |
|
|
|
|
String drugName = entry.getKey(); |
|
|
|
|
List<EntrustmentIdentificationMaterialVO> materials = entry.getValue(); |
|
|
|
|
Row row = sheet.createRow(rowIndex++); |
|
|
|
|
if (StringUtils.isNotBlank(oldResult)) { |
|
|
|
|
|
|
|
|
|
row.createCell(0).setCellValue(drugName); |
|
|
|
|
row.createCell(1).setCellValue(oldResult); |
|
|
|
|
row.createCell(2).setCellValue(materials.size()); |
|
|
|
|
row.createCell(3).setCellValue(sizeMap.getOrDefault(oldResult, 0)); |
|
|
|
|
row.createCell(4).setCellValue(String.format("%.2f%%", materials.size() * 100.0 / sizeMap.getOrDefault(oldResult, 1))); |
|
|
|
|
} else { |
|
|
|
|
Map<String, List<EntrustmentIdentificationMaterialVO>> groupedData = materials.stream().collect(Collectors.groupingBy(EntrustmentIdentificationMaterialVO::getOldIdentificationResult)); |
|
|
|
|
for (Map.Entry<String, List<EntrustmentIdentificationMaterialVO>> group : groupedData.entrySet()) { |
|
|
|
|
row.createCell(0).setCellValue(drugName); |
|
|
|
|
row.createCell(1).setCellValue(group.getKey()); |
|
|
|
|
row.createCell(2).setCellValue(group.getValue().size()); |
|
|
|
|
row.createCell(3).setCellValue(sizeMap.getOrDefault(group.getKey(), 0)); |
|
|
|
|
row.createCell(4).setCellValue(String.format("%.2f%%", group.getValue().size() * 100.0 / sizeMap.getOrDefault(group.getKey(), 1))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
row.createCell(0).setCellValue(drugName); |
|
|
|
|
row.createCell(1).setCellValue(materials.size()); |
|
|
|
|
row.createCell(2).setCellValue(size); |
|
|
|
|
row.createCell(3).setCellValue(String.format("%.2f%%", materials.size() * 100.0 / size)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -927,15 +930,11 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Map<String, Integer> getSizeMap(Integer entrustType, String oldResult, LocalDateTime startTime, LocalDateTime endTime) { |
|
|
|
|
public Integer getSizeMap(Integer entrustType, List<String> oldResults, LocalDateTime startTime, LocalDateTime endTime) { |
|
|
|
|
// 构造查询条件,查询 EntrustmentIdentificationMaterial 数据
|
|
|
|
|
LambdaQueryWrapper<EntrustmentIdentificationMaterial> qw = new LambdaQueryWrapper<>(); |
|
|
|
|
|
|
|
|
|
LocalDateTime queryStartTime = Optional.ofNullable(startTime).orElseGet(() -> this.getStartTime(null)); |
|
|
|
|
if (endTime != null) { |
|
|
|
|
qw.between(EntrustmentIdentificationMaterial::getAcceptTime, queryStartTime, endTime); |
|
|
|
|
} else { |
|
|
|
|
qw.ge(EntrustmentIdentificationMaterial::getAcceptTime, queryStartTime); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 统计各类委托的数量
|
|
|
|
|
int entrustSize = 0; |
|
|
|
@ -951,55 +950,72 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus |
|
|
|
|
wrapper.ge(Entrustment::getAcceptTime, queryStartTime); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ArrayList<String> results = new ArrayList<>(); |
|
|
|
|
for (String oldResult : oldResults) { |
|
|
|
|
if (oldResult.equals("委托")) { |
|
|
|
|
results.add("首次鉴定"); |
|
|
|
|
results.add("补充鉴定"); |
|
|
|
|
results.add("重新鉴定"); |
|
|
|
|
} else results.add(oldResult); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 查询符合条件的 Entrustment 记录
|
|
|
|
|
List<Entrustment> entrusts = entrustmentService.list(wrapper |
|
|
|
|
.eq(Entrustment::getEntrustmentType, entrustType) |
|
|
|
|
.eq(Entrustment::getStatus, EntrustStatusConstants.ENTRUST_STATUS_ACCEPTED.getStatus()) |
|
|
|
|
.ge(Entrustment::getStatus, EntrustStatusConstants.ENTRUST_STATUS_ACCEPTED.getStatus()) |
|
|
|
|
.in(Entrustment::getOldIdentificationResult, results) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
// 按照 oldIdentificationResult 进行分组
|
|
|
|
|
Map<String, List<Entrustment>> entrustMap = entrusts.stream() |
|
|
|
|
.collect(Collectors.groupingBy(Entrustment::getOldIdentificationResult)); |
|
|
|
|
|
|
|
|
|
// 遍历分组数据,计算各类 EntrustmentIdentificationMaterial 的数量
|
|
|
|
|
for (Map.Entry<String, List<Entrustment>> entry : entrustMap.entrySet()) { |
|
|
|
|
String oldIdentificationResult = entry.getKey(); |
|
|
|
|
List<Entrustment> entrustList = entry.getValue(); |
|
|
|
|
|
|
|
|
|
// 获取 Entrustment ID 列表
|
|
|
|
|
List<String> entIdList = entrustList.stream() |
|
|
|
|
.map(Entrustment::getId) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
// 查询与这些 Entrustment 关联的 EntrustmentIdentificationMaterial 数量
|
|
|
|
|
int size = entrustmentIdentificationMaterialService.list(Wrappers.<EntrustmentIdentificationMaterial>lambdaQuery() |
|
|
|
|
.in(EntrustmentIdentificationMaterial::getEntrustmentId, entIdList)).size(); |
|
|
|
|
|
|
|
|
|
// 根据 oldIdentificationResult 分类累加数量
|
|
|
|
|
switch (oldIdentificationResult) { |
|
|
|
|
case "初筛": |
|
|
|
|
preliminaryScreeningSize += size; |
|
|
|
|
break; |
|
|
|
|
case "涉缅人员": |
|
|
|
|
myanmarRelatedSize += size; |
|
|
|
|
break; |
|
|
|
|
case "自愿戒治人员": |
|
|
|
|
voluntaryRehabilitationSize += size; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
entrustSize += size; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 组装返回结果
|
|
|
|
|
Map<String, Integer> sizeMap = new HashMap<>(); |
|
|
|
|
sizeMap.put("委托", entrustSize); |
|
|
|
|
sizeMap.put("初筛", preliminaryScreeningSize); |
|
|
|
|
sizeMap.put("涉缅人员", myanmarRelatedSize); |
|
|
|
|
sizeMap.put("自愿戒治人员", voluntaryRehabilitationSize); |
|
|
|
|
List<String> entrustIds = entrusts.stream().map(Entrustment::getId).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
return sizeMap; |
|
|
|
|
return entrustmentIdentificationMaterialService.lambdaQuery() |
|
|
|
|
.in(EntrustmentIdentificationMaterial::getEntrustmentId, entrustIds) |
|
|
|
|
.list() |
|
|
|
|
.size(); |
|
|
|
|
//
|
|
|
|
|
// // 按照 oldIdentificationResult 进行分组
|
|
|
|
|
// Map<String, List<Entrustment>> entrustMap = entrusts.stream()
|
|
|
|
|
// .collect(Collectors.groupingBy(Entrustment::getOldIdentificationResult));
|
|
|
|
|
//
|
|
|
|
|
// // 遍历分组数据,计算各类 EntrustmentIdentificationMaterial 的数量
|
|
|
|
|
// for (Map.Entry<String, List<Entrustment>> entry : entrustMap.entrySet()) {
|
|
|
|
|
// String oldIdentificationResult = entry.getKey();
|
|
|
|
|
// List<Entrustment> entrustList = entry.getValue();
|
|
|
|
|
//
|
|
|
|
|
// // 获取 Entrustment ID 列表
|
|
|
|
|
// List<String> entIdList = entrustList.stream()
|
|
|
|
|
// .map(Entrustment::getId)
|
|
|
|
|
// .collect(Collectors.toList());
|
|
|
|
|
//
|
|
|
|
|
// // 查询与这些 Entrustment 关联的 EntrustmentIdentificationMaterial 数量
|
|
|
|
|
// int size = entrustmentIdentificationMaterialService.list(Wrappers.<EntrustmentIdentificationMaterial>lambdaQuery()
|
|
|
|
|
// .in(EntrustmentIdentificationMaterial::getEntrustmentId, entIdList)).size();
|
|
|
|
|
//
|
|
|
|
|
// // 根据 oldIdentificationResult 分类累加数量
|
|
|
|
|
// switch (oldIdentificationResult) {
|
|
|
|
|
// case "初筛":
|
|
|
|
|
// preliminaryScreeningSize += size;
|
|
|
|
|
// break;
|
|
|
|
|
// case "涉缅人员":
|
|
|
|
|
// myanmarRelatedSize += size;
|
|
|
|
|
// break;
|
|
|
|
|
// case "自愿戒治人员":
|
|
|
|
|
// voluntaryRehabilitationSize += size;
|
|
|
|
|
// break;
|
|
|
|
|
// default:
|
|
|
|
|
// entrustSize += size;
|
|
|
|
|
// break;
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// // 组装返回结果
|
|
|
|
|
// Map<String, Integer> sizeMap = new HashMap<>();
|
|
|
|
|
// sizeMap.put("委托", entrustSize);
|
|
|
|
|
// sizeMap.put("初筛", preliminaryScreeningSize);
|
|
|
|
|
// sizeMap.put("涉缅人员", myanmarRelatedSize);
|
|
|
|
|
// sizeMap.put("自愿戒治人员", voluntaryRehabilitationSize);
|
|
|
|
|
|
|
|
|
|
// return entrusts.size();
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|