更新了生成统计Excel的功能
This commit is contained in:
+4
-4
@@ -7,6 +7,7 @@ import digital.laboratory.platform.common.core.exception.CheckedException;
|
|||||||
import digital.laboratory.platform.common.core.util.R;
|
import digital.laboratory.platform.common.core.util.R;
|
||||||
import digital.laboratory.platform.entrustment.convert.EntrustMaterialCheckoutResultConvert;
|
import digital.laboratory.platform.entrustment.convert.EntrustMaterialCheckoutResultConvert;
|
||||||
import digital.laboratory.platform.entrustment.dto.EntrustMaterialCheckoutResultDTO;
|
import digital.laboratory.platform.entrustment.dto.EntrustMaterialCheckoutResultDTO;
|
||||||
|
import digital.laboratory.platform.entrustment.dto.ResultExcelDTO;
|
||||||
import digital.laboratory.platform.entrustment.query.BaseQuery;
|
import digital.laboratory.platform.entrustment.query.BaseQuery;
|
||||||
import digital.laboratory.platform.entrustment.query.EntrustMaterialCheckoutResultQuery;
|
import digital.laboratory.platform.entrustment.query.EntrustMaterialCheckoutResultQuery;
|
||||||
import digital.laboratory.platform.entrustment.service.EntrustMaterialCheckoutResultService;
|
import digital.laboratory.platform.entrustment.service.EntrustMaterialCheckoutResultService;
|
||||||
@@ -104,9 +105,8 @@ public class EntrustMaterialCheckoutResultController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("导出Excel")
|
@ApiOperation("导出Excel")
|
||||||
@GetMapping("/getExcelByResult")
|
@PostMapping("/getExcelByResult")
|
||||||
public void getResultData(HttpServletResponse response, Integer entrustType, String oldResult, LocalDateTime startTime, LocalDateTime endTime) throws IOException {
|
public R getResultData(HttpServletResponse response, @RequestBody ResultExcelDTO excelDTO) throws IOException {
|
||||||
entrustMaterialCheckoutResultService.getExcelByResult(response, entrustType, oldResult, startTime, endTime);
|
return entrustMaterialCheckoutResultService.getExcelByResult(response, excelDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package digital.laboratory.platform.entrustment.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class ResultExcelDTO {
|
||||||
|
Integer entrustType;
|
||||||
|
String oldResult;
|
||||||
|
LocalDateTime startTime;
|
||||||
|
LocalDateTime endTime;
|
||||||
|
}
|
||||||
+3
-2
@@ -3,7 +3,9 @@ package digital.laboratory.platform.entrustment.service;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import digital.laboratory.platform.common.core.util.R;
|
||||||
import digital.laboratory.platform.entrustment.dto.EntrustMaterialCheckoutResultDTO;
|
import digital.laboratory.platform.entrustment.dto.EntrustMaterialCheckoutResultDTO;
|
||||||
|
import digital.laboratory.platform.entrustment.dto.ResultExcelDTO;
|
||||||
import digital.laboratory.platform.entrustment.entity.EntrustMaterialCheckoutResult;
|
import digital.laboratory.platform.entrustment.entity.EntrustMaterialCheckoutResult;
|
||||||
import digital.laboratory.platform.entrustment.query.EntrustMaterialCheckoutResultQuery;
|
import digital.laboratory.platform.entrustment.query.EntrustMaterialCheckoutResultQuery;
|
||||||
import digital.laboratory.platform.entrustment.vo.DetectionRateVO;
|
import digital.laboratory.platform.entrustment.vo.DetectionRateVO;
|
||||||
@@ -71,7 +73,6 @@ public interface EntrustMaterialCheckoutResultService extends IService<EntrustMa
|
|||||||
*/
|
*/
|
||||||
DetectionRateVO getDetectionRateByMaterial(Integer year, String orgId);
|
DetectionRateVO getDetectionRateByMaterial(Integer year, String orgId);
|
||||||
|
|
||||||
List<EntrustmentIdentificationMaterialVO> getResultData(Integer entrustType, String oldResult, LocalDateTime startTime, LocalDateTime endTime);
|
|
||||||
|
|
||||||
void getExcelByResult(HttpServletResponse response, Integer entrustType, String oldResult, LocalDateTime startTime, LocalDateTime endTime) throws IOException;
|
R getExcelByResult(HttpServletResponse response, ResultExcelDTO excelDTO) throws IOException;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
@@ -114,4 +114,8 @@ public interface EntrustmentIdentificationMaterialService extends IService<Entru
|
|||||||
String printMaterialArchives(String entrustmentId) throws Exception;
|
String printMaterialArchives(String entrustmentId) throws Exception;
|
||||||
|
|
||||||
void conformityDrugs(List<EntrustmentIdentificationMaterial> list);
|
void conformityDrugs(List<EntrustmentIdentificationMaterial> list);
|
||||||
|
|
||||||
|
List<EntrustmentIdentificationMaterial> sortByAcceptNo(List<EntrustmentIdentificationMaterial> materials);
|
||||||
|
|
||||||
|
List<EntrustmentIdentificationMaterialVO> sortVoByAcceptNo(List<EntrustmentIdentificationMaterialVO> materials);
|
||||||
}
|
}
|
||||||
|
|||||||
+221
-218
@@ -1,8 +1,8 @@
|
|||||||
package digital.laboratory.platform.entrustment.service.impl;
|
package digital.laboratory.platform.entrustment.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.log.Log;
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||||
@@ -10,10 +10,12 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import digital.laboratory.platform.common.core.exception.CheckedException;
|
import digital.laboratory.platform.common.core.exception.CheckedException;
|
||||||
|
import digital.laboratory.platform.common.core.util.R;
|
||||||
import digital.laboratory.platform.entrustment.convert.DrugLiteConvert;
|
import digital.laboratory.platform.entrustment.convert.DrugLiteConvert;
|
||||||
import digital.laboratory.platform.entrustment.convert.EntrustMaterialCheckoutResultConvert;
|
import digital.laboratory.platform.entrustment.convert.EntrustMaterialCheckoutResultConvert;
|
||||||
import digital.laboratory.platform.entrustment.dto.CheckoutResultExcelDTO;
|
import digital.laboratory.platform.entrustment.dto.CheckoutResultExcelDTO;
|
||||||
import digital.laboratory.platform.entrustment.dto.EntrustMaterialCheckoutResultDTO;
|
import digital.laboratory.platform.entrustment.dto.EntrustMaterialCheckoutResultDTO;
|
||||||
|
import digital.laboratory.platform.entrustment.dto.ResultExcelDTO;
|
||||||
import digital.laboratory.platform.entrustment.entity.EntrustMaterialCheckoutResult;
|
import digital.laboratory.platform.entrustment.entity.EntrustMaterialCheckoutResult;
|
||||||
import digital.laboratory.platform.entrustment.entity.Entrustment;
|
import digital.laboratory.platform.entrustment.entity.Entrustment;
|
||||||
import digital.laboratory.platform.entrustment.entity.EntrustmentIdentificationMaterial;
|
import digital.laboratory.platform.entrustment.entity.EntrustmentIdentificationMaterial;
|
||||||
@@ -39,6 +41,7 @@ import javax.annotation.Resource;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
@@ -517,122 +520,115 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus
|
|||||||
return materialPage;
|
return materialPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EntrustmentIdentificationMaterialVO> getResultData(Integer entrustType, String oldResult, LocalDateTime startTime, LocalDateTime endTime) {
|
public List<EntrustmentIdentificationMaterialVO> getResultData(ResultExcelDTO excelDTO) {
|
||||||
|
|
||||||
LambdaQueryWrapper<EntrustMaterialCheckoutResult> qw = new LambdaQueryWrapper<>();
|
|
||||||
|
|
||||||
if (startTime != null && endTime != null) {
|
|
||||||
qw.ge(startTime != null, EntrustMaterialCheckoutResult::getCreateTime, startTime)
|
|
||||||
.le(endTime != null, EntrustMaterialCheckoutResult::getCreateTime, endTime);
|
|
||||||
} else {
|
|
||||||
qw.ge(EntrustMaterialCheckoutResult::getCreateTime, this.getStartTime(null));
|
|
||||||
}
|
|
||||||
// 查询所有符合时间条件的检测结果
|
|
||||||
List<EntrustMaterialCheckoutResult> resultList = this.list(qw
|
|
||||||
.isNotNull(EntrustMaterialCheckoutResult::getQualitativeResult)
|
|
||||||
.ne(EntrustMaterialCheckoutResult::getQualitativeResult, ""));
|
|
||||||
|
|
||||||
// 如果没有查询到数据,则直接返回空列表
|
|
||||||
if (CollUtil.isEmpty(resultList)) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 按委托 ID 进行分组
|
|
||||||
Map<String, List<EntrustMaterialCheckoutResult>> resultMap = resultList.stream()
|
|
||||||
.collect(Collectors.groupingBy(EntrustMaterialCheckoutResult::getEntrustId));
|
|
||||||
|
|
||||||
// 获取所有的委托 ID
|
|
||||||
Set<String> entrustIdList = resultMap.keySet();
|
|
||||||
|
|
||||||
|
LocalDateTime startTime = excelDTO.getStartTime();
|
||||||
|
LocalDateTime endTime = excelDTO.getEndTime();
|
||||||
|
String oldResult = excelDTO.getOldResult();
|
||||||
|
Integer entrustType = excelDTO.getEntrustType();
|
||||||
|
// 创建查询条件包装器
|
||||||
LambdaQueryWrapper<Entrustment> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<Entrustment> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
// 设置时间范围过滤条件
|
||||||
|
if (startTime != null && endTime != null) {
|
||||||
|
wrapper.between(Entrustment::getAcceptTime, startTime, endTime);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
wrapper.ge(Entrustment::getAcceptTime, this.getStartTime(null));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理 oldResult 过滤条件
|
||||||
if (StringUtils.isNotBlank(oldResult)) {
|
if (StringUtils.isNotBlank(oldResult)) {
|
||||||
if (oldResult.equals("委托")) {
|
if ("委托".equals(oldResult)) {
|
||||||
String types[] = {"首次鉴定", "补充鉴定", "重新鉴定"};
|
wrapper.in(Entrustment::getOldIdentificationResult, "首次鉴定", "补充鉴定", "重新鉴定");
|
||||||
wrapper.in(Entrustment::getOldIdentificationResult, types);
|
|
||||||
} else {
|
} else {
|
||||||
wrapper.eq(Entrustment::getOldIdentificationResult, oldResult);
|
wrapper.eq(Entrustment::getOldIdentificationResult, oldResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 批量查询符合条件的委托信息,避免多次查询数据库
|
|
||||||
List<Entrustment> entrustmentList = entrustmentService.list(wrapper
|
|
||||||
.in(Entrustment::getId, entrustIdList)
|
|
||||||
.eq(entrustType != null, Entrustment::getEntrustmentType, entrustType));
|
|
||||||
|
|
||||||
|
// 查询符合条件的 Entrustment 列表,避免重复查询数据库
|
||||||
|
List<Entrustment> entrustmentList = entrustmentService.list(
|
||||||
|
wrapper.eq(entrustType != null, Entrustment::getEntrustmentType, entrustType)
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
System.out.println("委托的数量:" + entrustmentList.size());
|
||||||
|
// 如果无符合条件的委托信息,则返回空列表
|
||||||
if (CollUtil.isEmpty(entrustmentList)) {
|
if (CollUtil.isEmpty(entrustmentList)) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取所有符合条件的委托 ID
|
// 获取符合条件的委托 ID 集合,提高查询效率
|
||||||
Set<String> filteredEntrustIds = entrustmentList.stream()
|
Set<String> entrustIds = entrustmentList.stream()
|
||||||
.map(Entrustment::getId)
|
.map(Entrustment::getId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
// 获取所有符合条件的委托map
|
// 将 Entrustment 列表转换为 Map,提高后续查询速度
|
||||||
Map<String, Entrustment> entrustMap = entrustmentList.stream()
|
Map<String, Entrustment> entrustMap = entrustmentList.stream()
|
||||||
.collect(Collectors.toMap(Entrustment::getId, Function.identity()));
|
.collect(Collectors.toMap(Entrustment::getId, Function.identity()));
|
||||||
|
|
||||||
// 过滤出符合条件的检测结果
|
// 查询所有符合条件的 EntrustmentIdentificationMaterial 数据
|
||||||
List<EntrustMaterialCheckoutResult> newResultList = resultList.stream()
|
List<EntrustmentIdentificationMaterial> materialList = entrustmentIdentificationMaterialService.list(
|
||||||
.filter(result -> filteredEntrustIds.contains(result.getEntrustId()))
|
Wrappers.<EntrustmentIdentificationMaterial>lambdaQuery()
|
||||||
.collect(Collectors.toList());
|
.in(EntrustmentIdentificationMaterial::getEntrustmentId, entrustIds)
|
||||||
|
);
|
||||||
|
|
||||||
// 提取所有 resultId 批量查询 EntrustmentIdentificationMaterial,避免循环查询数据库
|
// 若无符合条件的材料,则直接返回空列表
|
||||||
Set<String> resultIds = newResultList.stream()
|
if (CollUtil.isEmpty(materialList)) {
|
||||||
.map(EntrustMaterialCheckoutResult::getId)
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取材料 ID 集合,提高查询效率
|
||||||
|
Set<String> materialIds = materialList.stream()
|
||||||
|
.map(EntrustmentIdentificationMaterial::getId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
// 批量查询所有相关的材料信息
|
// 查询所有符合条件的检测结果数据
|
||||||
List<EntrustmentIdentificationMaterial> materialList = entrustmentIdentificationMaterialService.list(Wrappers
|
List<EntrustMaterialCheckoutResult> resultList = this.list(
|
||||||
.<EntrustmentIdentificationMaterial>lambdaQuery()
|
Wrappers.<EntrustMaterialCheckoutResult>lambdaQuery()
|
||||||
.in(EntrustmentIdentificationMaterial::getId, resultIds)
|
.in(EntrustMaterialCheckoutResult::getId, materialIds)
|
||||||
.last("ORDER BY " +
|
);
|
||||||
"CAST(SUBSTRING_INDEX(accept_no, '-', 1) AS UNSIGNED) ASC, " + // 年份排序
|
|
||||||
"CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(accept_no, '-', -2), '-', 1) AS UNSIGNED) ASC, " + // 流水号排序
|
|
||||||
"CAST(SUBSTRING_INDEX(accept_no, '-', -1) AS UNSIGNED) ASC")); // 子流水号排序
|
|
||||||
|
|
||||||
|
// 将检测结果转换为 Map,避免后续 O(n^2) 复杂度查询
|
||||||
|
Map<String, EntrustMaterialCheckoutResult> resultMap = resultList.stream()
|
||||||
|
.collect(Collectors.toMap(EntrustMaterialCheckoutResult::getId, Function.identity()));
|
||||||
|
|
||||||
// 将材料信息转换为 Map 以便快速查找
|
// 构造返回的 VO 列表
|
||||||
Map<String, EntrustmentIdentificationMaterial> materialMap = materialList.stream()
|
List<EntrustmentIdentificationMaterialVO> voList = materialList.stream().map(material -> {
|
||||||
.collect(Collectors.toMap(EntrustmentIdentificationMaterial::getId, Function.identity()));
|
EntrustmentIdentificationMaterialVO vo = new EntrustmentIdentificationMaterialVO();
|
||||||
|
BeanUtils.copyProperties(material, vo);
|
||||||
|
|
||||||
// 构建返回的 VO 对象列表
|
// 设置检测结果
|
||||||
List<EntrustmentIdentificationMaterialVO> voList = newResultList.stream()
|
vo.setDrugLites(Optional.ofNullable(resultMap.get(material.getId()))
|
||||||
.map(result -> {
|
.map(EntrustMaterialCheckoutResult::getQualitativeResult)
|
||||||
EntrustmentIdentificationMaterial material = materialMap.get(result.getId());
|
.map(DrugLiteConvert::getDrugLites)
|
||||||
if (material == null) {
|
.orElse(null));
|
||||||
return null;
|
|
||||||
}
|
|
||||||
EntrustmentIdentificationMaterialVO vo = new EntrustmentIdentificationMaterialVO();
|
|
||||||
BeanUtils.copyProperties(material, vo);
|
|
||||||
vo.setDrugLites(DrugLiteConvert.getDrugLites(result.getQualitativeResult()));
|
|
||||||
Entrustment entrust = entrustMap.get(vo.getEntrustmentId());
|
|
||||||
String oldIdentificationResult = entrust.getOldIdentificationResult();
|
|
||||||
if (oldIdentificationResult.equals("首次鉴定") || oldIdentificationResult.equals("补充鉴定") || oldIdentificationResult.equals("重新鉴定")) {
|
|
||||||
vo.setOldIdentificationResult("委托");
|
|
||||||
} else {
|
|
||||||
vo.setOldIdentificationResult(oldIdentificationResult);
|
|
||||||
}
|
|
||||||
vo.setOrgName(entrust.getClientOrgName());
|
|
||||||
return vo;
|
|
||||||
})
|
|
||||||
.filter(Objects::nonNull) // 过滤掉可能为空的数据
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
// 按 acceptNo 进行排序
|
// 设置委托信息
|
||||||
voList.sort(Comparator.comparing((EntrustmentIdentificationMaterial m) -> {
|
Entrustment entrust = entrustMap.get(material.getEntrustmentId());
|
||||||
String[] parts = m.getAcceptNo().split("-");
|
if (entrust != null) {
|
||||||
return new int[]{Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])};
|
String oldIdentificationResult = entrust.getOldIdentificationResult();
|
||||||
}, Comparator.comparingInt((int[] arr) -> arr[0]) // 按年份排序
|
vo.setOldIdentificationResult(
|
||||||
.thenComparingInt(arr -> arr[1]) // 按流水号排序
|
("首次鉴定".equals(oldIdentificationResult) || "补充鉴定".equals(oldIdentificationResult) || "重新鉴定".equals(oldIdentificationResult))
|
||||||
.thenComparingInt(arr -> arr[2]))); // 按子流水号排序
|
? "委托"
|
||||||
return voList;
|
: oldIdentificationResult
|
||||||
|
);
|
||||||
|
vo.setOrgName(entrust.getClientOrgName());
|
||||||
|
}
|
||||||
|
return vo;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
|
||||||
|
// 按 acceptNo 进行排序并返回结果
|
||||||
|
return entrustmentIdentificationMaterialService.sortVoByAcceptNo(voList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, List<EntrustmentIdentificationMaterialVO>> getResultDataMap(
|
public Map<String, List<EntrustmentIdentificationMaterialVO>> getResultDataMap(
|
||||||
Integer entrustType, String oldResult, LocalDateTime startTime, LocalDateTime endTime) {
|
ResultExcelDTO excelDTO) {
|
||||||
|
LocalDateTime startTime = excelDTO.getStartTime();
|
||||||
|
LocalDateTime endTime = excelDTO.getEndTime();
|
||||||
|
String oldResult = excelDTO.getOldResult();
|
||||||
|
Integer entrustType = excelDTO.getEntrustType();
|
||||||
try {
|
try {
|
||||||
// 1. 构建查询条件
|
// 1. 构建查询条件
|
||||||
LambdaQueryWrapper<Entrustment> qw = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<Entrustment> qw = new LambdaQueryWrapper<>();
|
||||||
@@ -766,165 +762,172 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void getExcelByResult(HttpServletResponse response, Integer entrustType, String oldResult, LocalDateTime
|
public R getExcelByResult(HttpServletResponse response, ResultExcelDTO excelDTO) throws IOException {
|
||||||
startTime, LocalDateTime endTime) throws IOException {
|
// 获取查询数据
|
||||||
List<EntrustmentIdentificationMaterialVO> resultData = this.getResultData(entrustType, oldResult, startTime, endTime);
|
List<EntrustmentIdentificationMaterialVO> resultData = this.getResultData(excelDTO);
|
||||||
Map<String, List<EntrustmentIdentificationMaterialVO>> resultDataMap = this.getResultDataMap(entrustType, oldResult, startTime, endTime);
|
Map<String, List<EntrustmentIdentificationMaterialVO>> resultDataMap = this.getResultDataMap(excelDTO);
|
||||||
|
|
||||||
|
LocalDateTime startTime = excelDTO.getStartTime();
|
||||||
|
LocalDateTime endTime = excelDTO.getEndTime();
|
||||||
|
String oldResult = excelDTO.getOldResult();
|
||||||
|
Integer entrustType = excelDTO.getEntrustType();
|
||||||
|
|
||||||
if (resultData.isEmpty() || resultDataMap.isEmpty()) {
|
if (resultData.isEmpty() || resultDataMap.isEmpty()) {
|
||||||
throw new RuntimeException("没有符合条件的数据!");
|
return R.failed("没有符合条件的数据!");
|
||||||
}
|
}
|
||||||
|
|
||||||
Workbook workbook = new XSSFWorkbook();
|
Workbook workbook = new XSSFWorkbook();
|
||||||
Sheet sheet = null;
|
|
||||||
if (entrustType == 0) {
|
|
||||||
sheet = workbook.createSheet("常规毒品");
|
|
||||||
} else {
|
|
||||||
if (StringUtils.isNotBlank(oldResult)) {
|
|
||||||
sheet = workbook.createSheet("生物样本-" + oldResult);
|
|
||||||
} else {
|
|
||||||
sheet = workbook.createSheet("生物样本");
|
|
||||||
|
|
||||||
}
|
createDataSheet(workbook, entrustType, oldResult, resultData);
|
||||||
}
|
createStatisticsSheet(workbook, resultDataMap, entrustType, oldResult, startTime, endTime);
|
||||||
String[] InVivoHeadList = new String[]{"检材类型", "检材编号", "检材名称", "检材性状", "检材质量", "年龄", "性别", "委托单位", "受理日期", "检出结果"};
|
createDrugSheets(workbook, resultDataMap, entrustType);
|
||||||
String[] InVitroHeadList = new String[]{"检材类型", "检材编号", "检材名称", "检材性状", "检材质量", "委托单位", "受理日期", "检出结果"};
|
|
||||||
String[] headList;
|
|
||||||
if (entrustType == 0) {
|
|
||||||
headList = InVitroHeadList;
|
|
||||||
} else {
|
|
||||||
headList = InVivoHeadList;
|
|
||||||
}
|
|
||||||
|
|
||||||
Row row = sheet.createRow(0);
|
workbook.write(response.getOutputStream());
|
||||||
for (int i = 0; i < headList.length; i++) {
|
return R.ok("导出成功!");
|
||||||
Cell cell = row.createCell(i);
|
}
|
||||||
cell.setCellValue(headList[i]);
|
|
||||||
|
private void createDataSheet(Workbook workbook, Integer entrustType, String oldResult, List<EntrustmentIdentificationMaterialVO> resultData) {
|
||||||
|
// 确定表名
|
||||||
|
String sheetName = (entrustType == 0) ? "常规毒品" : (StringUtils.isNotBlank(oldResult) ? "生物样本-" + oldResult : "生物样本");
|
||||||
|
Sheet sheet = workbook.createSheet(sheetName);
|
||||||
|
|
||||||
|
// 定义表头
|
||||||
|
String[] inVivoHeaders = {"检材类型", "检材编号", "检材名称", "检材性状", "检材质量", "年龄", "性别", "委托单位", "受理日期", "检出结果"};
|
||||||
|
String[] inVitroHeaders = {"检材类型", "检材编号", "检材名称", "检材性状", "检材质量", "委托单位", "受理日期", "检出结果"};
|
||||||
|
String[] headers = (entrustType == 0) ? inVitroHeaders : inVivoHeaders;
|
||||||
|
|
||||||
|
// 创建表头行
|
||||||
|
Row headerRow = sheet.createRow(0);
|
||||||
|
for (int i = 0; i < headers.length; i++) {
|
||||||
|
headerRow.createCell(i).setCellValue(headers[i]);
|
||||||
|
sheet.setColumnWidth(i, 20 * 256);
|
||||||
}
|
}
|
||||||
|
int masculineSize = 0;
|
||||||
|
// 填充数据
|
||||||
for (int i = 0; i < resultData.size(); i++) {
|
for (int i = 0; i < resultData.size(); i++) {
|
||||||
EntrustmentIdentificationMaterialVO vo = resultData.get(i);
|
EntrustmentIdentificationMaterialVO vo = resultData.get(i);
|
||||||
Row contentRow = sheet.createRow(i + 1);
|
Row row = sheet.createRow(i + 1);
|
||||||
contentRow.createCell(0).setCellValue(vo.getOldIdentificationResult());
|
fillRowData(row, vo, entrustType);
|
||||||
contentRow.createCell(1).setCellValue(vo.getAcceptNo());
|
if (CollUtil.isNotEmpty(vo.getDrugLites())) {
|
||||||
contentRow.createCell(2).setCellValue(vo.getName());
|
masculineSize++;
|
||||||
contentRow.createCell(3).setCellValue(vo.getFormName());
|
|
||||||
contentRow.createCell(4).setCellValue(vo.getQuantity() + vo.getUnit());
|
|
||||||
if (entrustType == 1) {
|
|
||||||
contentRow.createCell(5).setCellValue(vo.getMaterialAge());
|
|
||||||
contentRow.createCell(6).setCellValue(vo.getBiologyGender());
|
|
||||||
contentRow.createCell(7).setCellValue(vo.getOrgName());
|
|
||||||
contentRow.createCell(8).setCellValue(vo.getAcceptTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
||||||
List<DrugLite> drugLites = vo.getDrugLites();
|
|
||||||
if (CollUtil.isNotEmpty(drugLites)) {
|
|
||||||
StringBuilder drugName = new StringBuilder();
|
|
||||||
for (DrugLite drugLite : drugLites) {
|
|
||||||
drugName.append(drugLite.getName()).append(",");
|
|
||||||
}
|
|
||||||
contentRow.createCell(9).setCellValue(drugName.substring(0, drugName.length() - 1));
|
|
||||||
} else {
|
|
||||||
contentRow.createCell(9).setCellValue("");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
contentRow.createCell(5).setCellValue(vo.getOrgName());
|
|
||||||
contentRow.createCell(6).setCellValue(vo.getAcceptTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
||||||
List<DrugLite> drugLites = vo.getDrugLites();
|
|
||||||
if (CollUtil.isNotEmpty(drugLites)) {
|
|
||||||
StringBuilder drugName = new StringBuilder();
|
|
||||||
for (DrugLite drugLite : drugLites) {
|
|
||||||
drugName.append(drugLite.getName()).append(",");
|
|
||||||
}
|
|
||||||
contentRow.createCell(7).setCellValue(drugName.substring(0, drugName.length() - 1));
|
|
||||||
} else {
|
|
||||||
contentRow.createCell(7).setCellValue("");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Row lastRow = sheet.createRow(resultData.size() + 2);
|
||||||
|
lastRow.createCell(0).setCellValue("检材总数量:" + resultData.size());
|
||||||
|
lastRow.createCell(1).setCellValue("阳性总数量:" + masculineSize);
|
||||||
|
BigDecimal result = new BigDecimal(masculineSize)
|
||||||
|
.multiply(new BigDecimal(100))
|
||||||
|
.divide(new BigDecimal(resultData.size()), 2, RoundingMode.HALF_UP);
|
||||||
|
lastRow.createCell(2).setCellValue("总检出率:" + result.toString() + "%");
|
||||||
|
}
|
||||||
|
|
||||||
Sheet statisticsSheet = workbook.createSheet("统计");
|
private void createStatisticsSheet(Workbook workbook, Map<String, List<EntrustmentIdentificationMaterialVO>> resultDataMap, Integer entrustType, String oldResult, LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
|
Sheet sheet = workbook.createSheet("统计");
|
||||||
|
|
||||||
Row statisticsSheetRow = statisticsSheet.createRow(0);
|
String[] headers = {"化合物种类", "类型", "检出数量", "总数量", "检出率"};
|
||||||
|
|
||||||
String[] statisticsHeadList = new String[]{"化合物种类", "类型", "检出数量", "总数量", "检出率"};
|
// 创建表头
|
||||||
|
Row headerRow = sheet.createRow(0);
|
||||||
for (int i = 0; i < statisticsHeadList.length; i++) {
|
for (int i = 0; i < headers.length; i++) {
|
||||||
Cell cell = statisticsSheetRow.createCell(i);
|
headerRow.createCell(i).setCellValue(headers[i]);
|
||||||
cell.setCellValue(statisticsHeadList[i]);
|
sheet.setColumnWidth(i, 20 * 256);
|
||||||
}
|
|
||||||
Set<String> drugSet = resultDataMap.keySet();
|
|
||||||
|
|
||||||
int materialSize = 0;
|
|
||||||
|
|
||||||
for (String s : drugSet) {
|
|
||||||
materialSize += resultDataMap.get(s).size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取总数量
|
||||||
Map<String, Integer> sizeMap = this.getSizeMap(entrustType, oldResult, startTime, endTime);
|
Map<String, Integer> sizeMap = this.getSizeMap(entrustType, oldResult, startTime, endTime);
|
||||||
|
|
||||||
System.out.println(sizeMap);
|
// 填充统计数据
|
||||||
|
int rowIndex = 1;
|
||||||
for (String drugName : drugSet) {
|
for (Map.Entry<String, List<EntrustmentIdentificationMaterialVO>> entry : resultDataMap.entrySet()) {
|
||||||
List<EntrustmentIdentificationMaterialVO> materialVOList = resultDataMap.get(drugName);
|
String drugName = entry.getKey();
|
||||||
|
List<EntrustmentIdentificationMaterialVO> materials = entry.getValue();
|
||||||
|
Row row = sheet.createRow(rowIndex++);
|
||||||
if (StringUtils.isNotBlank(oldResult)) {
|
if (StringUtils.isNotBlank(oldResult)) {
|
||||||
Row sheetRow = statisticsSheet.createRow(statisticsSheet.getLastRowNum() + 1);
|
|
||||||
sheetRow.createCell(0).setCellValue(drugName);
|
row.createCell(0).setCellValue(drugName);
|
||||||
sheetRow.createCell(1).setCellValue(oldResult);
|
row.createCell(1).setCellValue(oldResult);
|
||||||
sheetRow.createCell(2).setCellValue(materialVOList.size());
|
row.createCell(2).setCellValue(materials.size());
|
||||||
sheetRow.createCell(3).setCellValue(sizeMap.get(oldResult));
|
row.createCell(3).setCellValue(sizeMap.getOrDefault(oldResult, 0));
|
||||||
sheetRow.createCell(4).setCellValue(String.format("%.2f", materialVOList.size() * 1.0 / sizeMap.get(oldResult) * 100) + "%");
|
row.createCell(4).setCellValue(String.format("%.2f%%", materials.size() * 100.0 / sizeMap.getOrDefault(oldResult, 1)));
|
||||||
} else {
|
} else {
|
||||||
Map<String, List<EntrustmentIdentificationMaterialVO>> map = materialVOList.stream().collect(Collectors.groupingBy(EntrustmentIdentificationMaterialVO::getOldIdentificationResult));
|
Map<String, List<EntrustmentIdentificationMaterialVO>> groupedData = materials.stream().collect(Collectors.groupingBy(EntrustmentIdentificationMaterialVO::getOldIdentificationResult));
|
||||||
Set<String> keySet = map.keySet();
|
for (Map.Entry<String, List<EntrustmentIdentificationMaterialVO>> group : groupedData.entrySet()) {
|
||||||
for (String key : keySet) {
|
row.createCell(0).setCellValue(drugName);
|
||||||
System.out.println(key);
|
row.createCell(1).setCellValue(group.getKey());
|
||||||
int size = map.get(key).size();
|
row.createCell(2).setCellValue(group.getValue().size());
|
||||||
Row sheetRow = statisticsSheet.createRow(statisticsSheet.getLastRowNum() + 1);
|
row.createCell(3).setCellValue(sizeMap.getOrDefault(group.getKey(), 0));
|
||||||
sheetRow.createCell(0).setCellValue(drugName);
|
row.createCell(4).setCellValue(String.format("%.2f%%", group.getValue().size() * 100.0 / sizeMap.getOrDefault(group.getKey(), 1)));
|
||||||
sheetRow.createCell(1).setCellValue(key);
|
|
||||||
sheetRow.createCell(2).setCellValue(size);
|
|
||||||
sheetRow.createCell(3).setCellValue(Integer.valueOf(sizeMap.get(key)));
|
|
||||||
sheetRow.createCell(4).setCellValue(String.format("%.2f", size * 1.0 / sizeMap.get(key) * 100) + "%");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String drugName : drugSet) {
|
|
||||||
List<EntrustmentIdentificationMaterialVO> materialVOList = resultDataMap.get(drugName);
|
|
||||||
String title = drugName.replaceAll("[^\\u4e00-\\u9fa5a-zA-Z0-9]", "");
|
|
||||||
sheet = workbook.createSheet(title);
|
|
||||||
Row row0 = sheet.createRow(0);
|
|
||||||
for (int i = 0; i < headList.length; i++) {
|
|
||||||
Cell cell = row0.createCell(i);
|
|
||||||
cell.setCellValue(headList[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < materialVOList.size(); i++) {
|
|
||||||
EntrustmentIdentificationMaterialVO vo = materialVOList.get(i);
|
|
||||||
Row contentRow = sheet.createRow(i + 1);
|
|
||||||
contentRow.createCell(0).setCellValue(vo.getOldIdentificationResult());
|
|
||||||
contentRow.createCell(1).setCellValue(vo.getAcceptNo());
|
|
||||||
contentRow.createCell(2).setCellValue(vo.getName());
|
|
||||||
contentRow.createCell(3).setCellValue(vo.getFormName());
|
|
||||||
contentRow.createCell(4).setCellValue(vo.getQuantity() + vo.getUnit());
|
|
||||||
if (entrustType == 1) {
|
|
||||||
contentRow.createCell(5).setCellValue(vo.getMaterialAge());
|
|
||||||
contentRow.createCell(6).setCellValue(vo.getBiologyGender());
|
|
||||||
contentRow.createCell(7).setCellValue(vo.getOrgName());
|
|
||||||
contentRow.createCell(8).setCellValue(vo.getAcceptTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
||||||
contentRow.createCell(9).setCellValue(drugName);
|
|
||||||
} else {
|
|
||||||
contentRow.createCell(5).setCellValue(vo.getOrgName());
|
|
||||||
contentRow.createCell(6).setCellValue(vo.getAcceptTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
||||||
contentRow.createCell(7).setCellValue(drugName);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
workbook.write(response.getOutputStream());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createDrugSheets(Workbook workbook, Map<String, List<EntrustmentIdentificationMaterialVO>> resultDataMap, Integer entrustType) {
|
||||||
|
for (Map.Entry<String, List<EntrustmentIdentificationMaterialVO>> entry : resultDataMap.entrySet()) {
|
||||||
|
String drugName = entry.getKey().replaceAll("[^\u4e00-\u9fa5a-zA-Z0-9]", "");
|
||||||
|
Sheet sheet = workbook.createSheet(drugName);
|
||||||
|
|
||||||
|
// 定义表头
|
||||||
|
String[] headers = (entrustType == 0) ? new String[]{"检材类型", "检材编号", "检材名称", "检材性状", "检材质量", "委托单位", "受理日期", "检出结果"}
|
||||||
|
: new String[]{"检材类型", "检材编号", "检材名称", "检材性状", "检材质量", "年龄", "性别", "委托单位", "受理日期", "检出结果"};
|
||||||
|
|
||||||
|
// 创建表头行
|
||||||
|
Row headerRow = sheet.createRow(0);
|
||||||
|
for (int i = 0; i < headers.length; i++) {
|
||||||
|
headerRow.createCell(i).setCellValue(headers[i]);
|
||||||
|
sheet.setColumnWidth(i, 20 * 256);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 填充数据
|
||||||
|
int rowIndex = 1;
|
||||||
|
for (EntrustmentIdentificationMaterialVO vo : entry.getValue()) {
|
||||||
|
Row row = sheet.createRow(rowIndex++);
|
||||||
|
fillRowData(row, vo, entrustType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fillRowData(Row row, EntrustmentIdentificationMaterialVO vo, Integer entrustType) {
|
||||||
|
row.createCell(0).setCellValue(vo.getOldIdentificationResult());
|
||||||
|
row.createCell(1).setCellValue(vo.getAcceptNo());
|
||||||
|
row.createCell(2).setCellValue(vo.getName());
|
||||||
|
row.createCell(3).setCellValue(vo.getFormName());
|
||||||
|
row.createCell(4).setCellValue(vo.getQuantity() + vo.getUnit());
|
||||||
|
|
||||||
|
if (entrustType == 1) {
|
||||||
|
row.createCell(5).setCellValue(vo.getMaterialAge() != null || vo.getMaterialAge() != 0 ? vo.getMaterialAge().toString() + "岁" : "未知");
|
||||||
|
row.createCell(6).setCellValue(StringUtils.isNotBlank(vo.getBiologyGender()) ? vo.getBiologyGender() : "未知");
|
||||||
|
row.createCell(7).setCellValue(vo.getOrgName());
|
||||||
|
row.createCell(8).setCellValue(LocalDateTimeUtil.format(vo.getAcceptTime(), "yyyy-MM-dd"));
|
||||||
|
List<DrugLite> drugLites = vo.getDrugLites();
|
||||||
|
if (drugLites != null && !drugLites.isEmpty()) {
|
||||||
|
String result = drugLites.stream()
|
||||||
|
.map(DrugLite::getName)
|
||||||
|
.collect(Collectors.joining(",")); // 自动去除最后的逗号
|
||||||
|
row.createCell(9).setCellValue(result);
|
||||||
|
} else {
|
||||||
|
row.createCell(9).setCellValue("未检出");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
row.createCell(5).setCellValue(vo.getOrgName());
|
||||||
|
row.createCell(6).setCellValue(LocalDateTimeUtil.format(vo.getAcceptTime(), "yyyy-MM-dd"));
|
||||||
|
List<DrugLite> drugLites = vo.getDrugLites();
|
||||||
|
if (drugLites != null && !drugLites.isEmpty()) {
|
||||||
|
String result = drugLites.stream()
|
||||||
|
.map(DrugLite::getName)
|
||||||
|
.collect(Collectors.joining(",")); // 自动去除最后的逗号
|
||||||
|
row.createCell(7).setCellValue(result);
|
||||||
|
} else {
|
||||||
|
row.createCell(7).setCellValue("未检出");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String, Integer> getSizeMap(Integer entrustType, String oldResult, LocalDateTime startTime, LocalDateTime endTime) {
|
public Map<String, Integer> getSizeMap(Integer entrustType, String oldResult, LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
// 构造查询条件,查询 EntrustmentIdentificationMaterial 数据
|
// 构造查询条件,查询 EntrustmentIdentificationMaterial 数据
|
||||||
LambdaQueryWrapper<EntrustmentIdentificationMaterial> qw = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<EntrustmentIdentificationMaterial> qw = new LambdaQueryWrapper<>();
|
||||||
LocalDateTime queryStartTime = Optional.ofNullable(startTime).orElseGet(() -> this.getStartTime(null));
|
LocalDateTime queryStartTime = Optional.ofNullable(startTime).orElseGet(() -> this.getStartTime(null));
|
||||||
|
|
||||||
if (endTime != null) {
|
if (endTime != null) {
|
||||||
qw.between(EntrustmentIdentificationMaterial::getAcceptTime, queryStartTime, endTime);
|
qw.between(EntrustmentIdentificationMaterial::getAcceptTime, queryStartTime, endTime);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+22
@@ -1627,4 +1627,26 @@ public class EntrustmentIdentificationMaterialServiceImpl extends ServiceImpl<En
|
|||||||
}
|
}
|
||||||
return cj;
|
return cj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<EntrustmentIdentificationMaterial> sortByAcceptNo(List<EntrustmentIdentificationMaterial> materials){
|
||||||
|
materials.sort(Comparator.comparing((EntrustmentIdentificationMaterial m) -> {
|
||||||
|
String[] parts = m.getAcceptNo().split("-");
|
||||||
|
return new int[]{Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])};
|
||||||
|
}, Comparator.comparingInt((int[] arr) -> arr[0]) // 按年份排序
|
||||||
|
.thenComparingInt(arr -> arr[1]) // 按流水号排序
|
||||||
|
.thenComparingInt(arr -> arr[2]))); // 按子流水号排序
|
||||||
|
return materials;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<EntrustmentIdentificationMaterialVO> sortVoByAcceptNo(List<EntrustmentIdentificationMaterialVO> materials){
|
||||||
|
materials.sort(Comparator.comparing((EntrustmentIdentificationMaterial m) -> {
|
||||||
|
String[] parts = m.getAcceptNo().split("-");
|
||||||
|
return new int[]{Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])};
|
||||||
|
}, Comparator.comparingInt((int[] arr) -> arr[0]) // 按年份排序
|
||||||
|
.thenComparingInt(arr -> arr[1]) // 按流水号排序
|
||||||
|
.thenComparingInt(arr -> arr[2]))); // 按子流水号排序
|
||||||
|
return materials;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -2459,8 +2459,8 @@ public class EntrustmentServiceImpl extends ServiceImpl<EntrustmentMapper, Entru
|
|||||||
// HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
// HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||||
// // 让异步线程继承主线程的上下文
|
// // 让异步线程继承主线程的上下文
|
||||||
// RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
|
// RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
|
||||||
applicationContext.publishEvent(new PushDataToLabsCareEvent(this, entrust.getId(), 1));
|
// applicationContext.publishEvent(new PushDataToLabsCareEvent(this, entrust.getId(), 1));
|
||||||
applicationContext.publishEvent(new PushDataToLabsCareEvent(this, entrust.getId(), 2));
|
// applicationContext.publishEvent(new PushDataToLabsCareEvent(this, entrust.getId(), 2));
|
||||||
});
|
});
|
||||||
|
|
||||||
//同步第三方禁毒系统的受理功能 开始--------------------------------------------------------------
|
//同步第三方禁毒系统的受理功能 开始--------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user