20250102 更新

1.导出检出结果excel表格
master
陈江保 2 months ago
parent 48b5d73bbf
commit 75467681a7
  1. 10
      doc/贵阳禁毒送检受理委托新增需求文档.md
  2. 24
      src/main/java/digital/laboratory/platform/entrustment/dto/CheckoutResultExcelDTO.java
  3. 97
      src/main/java/digital/laboratory/platform/entrustment/service/impl/EntrustMaterialCheckoutResultServiceImpl.java

@ -283,8 +283,6 @@ DESC LIMIT 1;
![](assets/2024-12-23-11-14-56-image.png)
## 20241223-2 填报委托时的页面,还是需要在检材重量这一块满足他们的填写需求(100 以下保留两位小数,100以上保留一位小数)。
### 1 解决方案
@ -295,8 +293,12 @@ DESC LIMIT 1;
![](assets/2024-12-23-14-40-37-image.png)
用法
![](assets/2024-12-23-14-41-27-image.png)
## 20250102 在受理页面添加可以录入检材检出结果的功能

@ -14,15 +14,15 @@ import java.util.List;
public class CheckoutResultExcelDTO {
@ApiModelProperty("序号")
@ExcelProperty("序号")
@ExcelProperty(value = "序号", index = 0)
private Integer order;
@ApiModelProperty("送检日期")
@ExcelProperty("送检日期")
@ExcelProperty(value = "送检日期", index = 1)
private String deliverTime;
@ApiModelProperty("送检单位")
@ExcelProperty("送检单位")
@ExcelProperty(value = "送检单位", index = 2)
private String clientOrgName;
@ApiModelProperty("检材采集地-省")
@ -34,38 +34,38 @@ public class CheckoutResultExcelDTO {
private String cityCollectPlace;
@ApiModelProperty(value="受理编号")
@ExcelProperty("受理编号")
@ExcelProperty(value = "受理编号", index = 5)
private String acceptNo;
@ApiModelProperty(value = "委托检材顺序号,由系统根据录入顺序生成")
@ExcelProperty("检材编号")
@ExcelProperty(value = "检材编号", index = 6)
private Integer orderNo;
@ApiModelProperty(value = "检材类别名称:继承所取物证的类别或从物证类别选择")
@ExcelProperty("检材类型")
@ExcelProperty(value = "检材类型", index = 7)
private String typeName;
@ApiModelProperty(value = "检材颜色:继承所取物证颜色或手动填入")
@ExcelProperty("检材颜色")
@ExcelProperty(value = "检材颜色", index = 8)
private String color;
@ApiModelProperty(value = "检材性状名称:继承所取物证性状或从物证性状类别选择")
@ExcelProperty("检材形态")
@ExcelProperty(value = "检材形态", index = 9)
private String formName;
@ApiModelProperty("定性结果")
@ExcelProperty("定性结果")
@ExcelProperty(value = "定性结果", index = 10)
private String qualitativeResult;
@ApiModelProperty("定量结果")
@ExcelProperty("定量结果")
@ExcelProperty(value = "定量结果", index = 11)
private String quantitativeResult;
@ApiModelProperty("其他鉴定结果")
@ExcelProperty("其他鉴定结果")
@ExcelProperty(value = "其他鉴定结果", index = 12)
private String otherResult;
@ApiModelProperty("备注")
@ExcelProperty("备注")
@ExcelProperty(value = "备注", index = 13)
private String remark;
}

@ -2,6 +2,8 @@ package digital.laboratory.platform.entrustment.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.idev.excel.FastExcel;
import cn.idev.excel.write.metadata.style.WriteCellStyle;
import cn.idev.excel.write.style.HorizontalCellStyleStrategy;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import digital.laboratory.platform.common.core.exception.CheckedException;
@ -20,6 +22,8 @@ import digital.laboratory.platform.entrustment.service.EntrustmentIdentification
import digital.laboratory.platform.entrustment.service.EntrustmentService;
import digital.laboratory.platform.sys.entity.Area;
import digital.laboratory.platform.sys.entity.DrugLite;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -119,12 +123,97 @@ public class EntrustMaterialCheckoutResultServiceImpl extends ServiceImpl<Entrus
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setCharacterEncoding("utf-8");
String fileName = URLEncoder.encode("测试", "UTF-8").replaceAll("\\+", "%20");
String fileName = URLEncoder.encode("检材检出结果excel表", "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
FastExcel.write(response.getOutputStream(), CheckoutResultExcelDTO.class)
.sheet(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
.doWrite(checkoutResultExcelDTOS);
// 不使用默认样式
// 空的头部样式
// WriteCellStyle headWriteCellStyle = new WriteCellStyle();
// headWriteCellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
//
// // 空的内容样式
// WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
//
// // 不使用任何样式
// HorizontalCellStyleStrategy horizontalCellStyleStrategy =
// new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
//
// FastExcel.write(response.getOutputStream(), CheckoutResultExcelDTO.class)
// .sheet(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")))
// .registerWriteHandler(horizontalCellStyleStrategy)
// .doWrite(checkoutResultExcelDTOS);
// 使用poi导出
buildExcel(response, checkoutResultExcelDTOS);
}
/**
* 构建并输出Excel文件
*
* @param response HttpServletResponse对象用于输出Excel文件
* @param checkoutResultExcelDTOS 需要写入Excel的数据列表
* @throws IOException 如果在写入Excel文件时发生IO异常
*
* 此方法用于将给定的checkoutResultExcelDTOS列表数据写入Excel文件并输出到HttpServletResponse对象中
* 方法首先创建一个新的XSSFWorkbook对象作为Excel工作簿并为其创建一个名为当前日期时间的工作表
* 接着根据buildExcelHead方法返回的表头信息构建Excel的表头行
* 然后遍历checkoutResultExcelDTOS列表将每个元素的数据写入Excel的对应行中
* 最后使用response.getOutputStream()获取输出流将构建好的Excel工作簿写入该输出流中实现文件的下载
*/
private void buildExcel(HttpServletResponse response, List<CheckoutResultExcelDTO> checkoutResultExcelDTOS) throws IOException {
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
// 表头导入
List<String> head = buildExcelHead();
// 算上表头的行数
int rowCount = checkoutResultExcelDTOS.size() + 1;
for (int i = 0; i < rowCount; i++) {
if (i == 0) {
Row row = sheet.createRow(i);
for (int j = 0; j < head.size(); j++) {
row.createCell(j).setCellValue(head.get(j));
}
} else {
// 开始写入具体数据内容
Row row = sheet.createRow(i);
CheckoutResultExcelDTO excelDTO = checkoutResultExcelDTOS.get(i - 1);
row.createCell(0).setCellValue(excelDTO.getOrder());
row.createCell(1).setCellValue(excelDTO.getDeliverTime());
row.createCell(2).setCellValue(excelDTO.getClientOrgName());
row.createCell(3).setCellValue(excelDTO.getProvinceCollectPlace());
row.createCell(4).setCellValue(excelDTO.getCityCollectPlace());
row.createCell(5).setCellValue(excelDTO.getAcceptNo());
row.createCell(6).setCellValue(excelDTO.getOrderNo());
row.createCell(7).setCellValue(excelDTO.getTypeName());
row.createCell(8).setCellValue(excelDTO.getColor());
row.createCell(9).setCellValue(excelDTO.getFormName());
row.createCell(10).setCellValue(excelDTO.getQualitativeResult());
row.createCell(11).setCellValue(excelDTO.getQuantitativeResult());
row.createCell(12).setCellValue(excelDTO.getOtherResult());
row.createCell(13).setCellValue(excelDTO.getRemark());
}
}
// 输出到流
workbook.write(response.getOutputStream());
}
private List<String> buildExcelHead() {
List<String> headList = new ArrayList<>();
headList.add("序号");
headList.add("送检日期");
headList.add("送检单位");
headList.add("检材采集地");
headList.add("检材采集地");
headList.add("受理编号");
headList.add("检材编号");
headList.add("检材类型");
headList.add("检材颜色");
headList.add("检材形态");
headList.add("定性结果");
headList.add("定量结果");
headList.add("其他鉴定结果");
headList.add("备注");
return headList;
}
/**

Loading…
Cancel
Save