|
@@ -2,6 +2,9 @@ package com.nb.web.service.bus.controller;
|
|
|
|
|
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
@@ -10,9 +13,11 @@ import com.nb.core.result.R;
|
|
|
import com.nb.web.api.bean.FormulaDrugDetailDomain;
|
|
import com.nb.web.api.bean.FormulaDrugDetailDomain;
|
|
|
import com.nb.web.api.bean.FormulaDrugDomain;
|
|
import com.nb.web.api.bean.FormulaDrugDomain;
|
|
|
import com.nb.web.service.bus.controller.vo.*;
|
|
import com.nb.web.service.bus.controller.vo.*;
|
|
|
|
|
+import com.nb.web.service.bus.excel.ExportResult;
|
|
|
|
|
+import com.nb.web.service.bus.excel.ExportType;
|
|
|
|
|
+import com.nb.web.service.bus.excel.LiquidExcelMergeWriteHandler;
|
|
|
import com.nb.web.service.bus.service.*;
|
|
import com.nb.web.service.bus.service.*;
|
|
|
import com.nb.web.service.bus.service.dto.*;
|
|
import com.nb.web.service.bus.service.dto.*;
|
|
|
-import com.nb.web.service.bus.utils.LiquidExcelMergeWriteHandler;
|
|
|
|
|
import io.swagger.annotations.*;
|
|
import io.swagger.annotations.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -21,7 +26,10 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.nio.charset.Charset;
|
|
import java.nio.charset.Charset;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
@@ -56,7 +64,7 @@ public class BusLiquidController {
|
|
|
|
|
|
|
|
@ApiOperation("导出废液记录单")
|
|
@ApiOperation("导出废液记录单")
|
|
|
@PostMapping("/export/record")
|
|
@PostMapping("/export/record")
|
|
|
- public void exportRecord(HttpServletResponse response, @RequestBody Collection<String> ids) throws IOException {
|
|
|
|
|
|
|
+ public R<ExportResult> exportRecord(@RequestBody Collection<String> ids) throws IOException {
|
|
|
if(CollectionUtil.isEmpty(ids)){
|
|
if(CollectionUtil.isEmpty(ids)){
|
|
|
throw new CustomException("请选择要导出的废液记录");
|
|
throw new CustomException("请选择要导出的废液记录");
|
|
|
}
|
|
}
|
|
@@ -66,36 +74,32 @@ public class BusLiquidController {
|
|
|
}
|
|
}
|
|
|
List<BusLiquidExcelVO> excelList = new ArrayList<>();
|
|
List<BusLiquidExcelVO> excelList = new ArrayList<>();
|
|
|
// 将BusLiquidListVO转换为BusLiquidExcelVO
|
|
// 将BusLiquidListVO转换为BusLiquidExcelVO
|
|
|
- for (BusLiquidListVO record : records) {
|
|
|
|
|
- excelList.addAll(convertExcelVO(record));
|
|
|
|
|
- }
|
|
|
|
|
- try {
|
|
|
|
|
- String fileName = "废液记录单";
|
|
|
|
|
- response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("utf-8"), Charset.defaultCharset()) + ".xlsx");
|
|
|
|
|
- response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
|
|
|
|
- response.setCharacterEncoding("utf-8");
|
|
|
|
|
-
|
|
|
|
|
- ServletOutputStream outputStream = response.getOutputStream();
|
|
|
|
|
- EasyExcel.write(outputStream, BusLiquidExcelVO.class)
|
|
|
|
|
- .registerWriteHandler(new LiquidExcelMergeWriteHandler(excelList))
|
|
|
|
|
- .sheet("废液记录单")
|
|
|
|
|
- .doWrite(excelList);
|
|
|
|
|
- } catch (IOException e) {
|
|
|
|
|
- throw new CustomException("导出失败: " + e.getMessage());
|
|
|
|
|
|
|
+ for (int i = 0; i < records.size(); i++) {
|
|
|
|
|
+ BusLiquidListVO record = records.get(i);
|
|
|
|
|
+ excelList.addAll(convertExcelVO(record,i+1));
|
|
|
}
|
|
}
|
|
|
|
|
+ String fileName = "废液记录单";
|
|
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
|
|
+ EasyExcel.write(outputStream, BusLiquidExcelVO.class)
|
|
|
|
|
+ .registerWriteHandler(new LiquidExcelMergeWriteHandler(excelList))
|
|
|
|
|
+ .sheet("废液记录单")
|
|
|
|
|
+ .doWrite(excelList);
|
|
|
|
|
+ String base64Str = "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,"+java.util.Base64.getEncoder().encodeToString(outputStream.toByteArray());
|
|
|
|
|
+ return R.success(ExportResult.of(fileName, base64Str, ExportType.EXCEL));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private List<BusLiquidExcelVO> convertExcelVO(BusLiquidListVO record){
|
|
|
|
|
|
|
+ private List<BusLiquidExcelVO> convertExcelVO(BusLiquidListVO record,int index){
|
|
|
List<BusLiquidExcelVO> result=new ArrayList<>();
|
|
List<BusLiquidExcelVO> result=new ArrayList<>();
|
|
|
List<FormulaDrugDetailDomain> detail=new ArrayList<>();
|
|
List<FormulaDrugDetailDomain> detail=new ArrayList<>();
|
|
|
FormulaDrugDomain formula = record.getFormula();
|
|
FormulaDrugDomain formula = record.getFormula();
|
|
|
if(formula!=null&&CollectionUtil.isNotEmpty(formula.getDetail())){
|
|
if(formula!=null&&CollectionUtil.isNotEmpty(formula.getDetail())){
|
|
|
detail=formula.getDetail();
|
|
detail=formula.getDetail();
|
|
|
}else {
|
|
}else {
|
|
|
- detail.add(new FormulaDrugDetailDomain());
|
|
|
|
|
|
|
+ detail.add(new FormulaDrugDetailDomain());
|
|
|
}
|
|
}
|
|
|
for (FormulaDrugDetailDomain formulaDrugDetailDomain : detail) {
|
|
for (FormulaDrugDetailDomain formulaDrugDetailDomain : detail) {
|
|
|
BusLiquidExcelVO excelVO = new BusLiquidExcelVO();
|
|
BusLiquidExcelVO excelVO = new BusLiquidExcelVO();
|
|
|
|
|
+ excelVO.setNum(index);
|
|
|
// 这里需要根据实际字段进行映射
|
|
// 这里需要根据实际字段进行映射
|
|
|
excelVO.setClinicId(record.getClinicId());
|
|
excelVO.setClinicId(record.getClinicId());
|
|
|
excelVO.setClinicName(record.getClinicName());
|
|
excelVO.setClinicName(record.getClinicName());
|
|
@@ -109,19 +113,27 @@ public class BusLiquidController {
|
|
|
}else {
|
|
}else {
|
|
|
excelVO.setDeviceAlias(record.getDeviceId());
|
|
excelVO.setDeviceAlias(record.getDeviceId());
|
|
|
}
|
|
}
|
|
|
- excelVO.setClinicStartTime(record.getClinicStartTime());
|
|
|
|
|
- excelVO.setUndoTime(record.getUndoTime());
|
|
|
|
|
|
|
+ excelVO.setClinicStartTime(DateUtil.formatDateTime(record.getClinicStartTime()));
|
|
|
|
|
+ excelVO.setUndoTime(DateUtil.formatDateTime(record.getUndoTime()));
|
|
|
excelVO.setName(formulaDrugDetailDomain.getName());
|
|
excelVO.setName(formulaDrugDetailDomain.getName());
|
|
|
- excelVO.setDose(formulaDrugDetailDomain.getDose());
|
|
|
|
|
- excelVO.setUnit(formulaDrugDetailDomain.getUnit());
|
|
|
|
|
|
|
+ excelVO.setDose(formulaDrugDetailDomain.getDose()+formulaDrugDetailDomain.getUnit());
|
|
|
|
|
+ //根据药液剩余量计算药品残余量
|
|
|
|
|
+ if(StrUtil.isEmpty(formulaDrugDetailDomain.getDose())|| !NumberUtil.isNumber(formulaDrugDetailDomain.getDose()) ||ObjectUtil.equals(record.getRemainDose(), BigDecimal.ZERO)){
|
|
|
|
|
+ excelVO.setDrugRemainDose("0"+formulaDrugDetailDomain.getUnit());
|
|
|
|
|
+ }else {
|
|
|
|
|
+ BigDecimal divide = record.getRemainDose().divide(record.getTotalDose(), 2, RoundingMode.CEILING);
|
|
|
|
|
+ BigDecimal totalDose = BigDecimal.valueOf(Double.valueOf(formulaDrugDetailDomain.getDose()));
|
|
|
|
|
+ BigDecimal multiply = totalDose.multiply(divide);
|
|
|
|
|
+ excelVO.setDrugRemainDose(multiply+formulaDrugDetailDomain.getUnit());
|
|
|
|
|
+ }
|
|
|
excelVO.setBatchCode(formulaDrugDetailDomain.getBatchCode());
|
|
excelVO.setBatchCode(formulaDrugDetailDomain.getBatchCode());
|
|
|
excelVO.setUse(formulaDrugDetailDomain.getUse());
|
|
excelVO.setUse(formulaDrugDetailDomain.getUse());
|
|
|
- excelVO.setTotalDose(record.getTotalDose());
|
|
|
|
|
- excelVO.setRemainDose(record.getRemainDose());
|
|
|
|
|
|
|
+ excelVO.setTotalDose(record.getTotalDose()+"ml");
|
|
|
|
|
+ excelVO.setRemainDose(record.getRemainDose()+"ml");
|
|
|
excelVO.setLiquidExecutor(record.getLiquidExecutor());
|
|
excelVO.setLiquidExecutor(record.getLiquidExecutor());
|
|
|
excelVO.setLiquidChecker(record.getLiquidChecker());
|
|
excelVO.setLiquidChecker(record.getLiquidChecker());
|
|
|
excelVO.setLiquidRemark(record.getLiquidRemark());
|
|
excelVO.setLiquidRemark(record.getLiquidRemark());
|
|
|
- excelVO.setLiquidTime(record.getLiquidTime());
|
|
|
|
|
|
|
+ excelVO.setLiquidTime(DateUtil.formatDateTime(record.getLiquidTime()));
|
|
|
result.add(excelVO);
|
|
result.add(excelVO);
|
|
|
}
|
|
}
|
|
|
return result;
|
|
return result;
|