浏览代码

add
废液管理
修改异常标识

lifang 3 月之前
父节点
当前提交
9c27d3703a

+ 9 - 0
nb-service-api/web-service-api/src/main/java/com/nb/web/api/bean/FormulaDrugDetailDomain.java

@@ -1,5 +1,6 @@
 package com.nb.web.api.bean;
 
+import cn.hutool.core.util.StrUtil;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -28,4 +29,12 @@ public class FormulaDrugDetailDomain {
 
     @ApiModelProperty("用法")
     private String use;
+
+    public String getName() {
+        return StrUtil.isEmpty(name)? "" : name;
+    }
+
+    public String getUnit() {
+        return StrUtil.isEmpty(unit)? "" : unit;
+    }
 }

+ 39 - 27
nb-service/web-service/src/main/java/com/nb/web/service/bus/controller/BusLiquidController.java

@@ -2,6 +2,9 @@ package com.nb.web.service.bus.controller;
 
 import cn.dev33.satoken.annotation.SaCheckPermission;
 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 com.alibaba.excel.EasyExcel;
 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.FormulaDrugDomain;
 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.dto.*;
-import com.nb.web.service.bus.utils.LiquidExcelMergeWriteHandler;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -21,7 +26,10 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.nio.charset.Charset;
 import java.util.*;
 
@@ -56,7 +64,7 @@ public class BusLiquidController {
 
     @ApiOperation("导出废液记录单")
     @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)){
             throw new CustomException("请选择要导出的废液记录");
         }
@@ -66,36 +74,32 @@ public class BusLiquidController {
         }
         List<BusLiquidExcelVO> excelList = new ArrayList<>();
         // 将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<FormulaDrugDetailDomain> detail=new ArrayList<>();
         FormulaDrugDomain formula = record.getFormula();
         if(formula!=null&&CollectionUtil.isNotEmpty(formula.getDetail())){
             detail=formula.getDetail();
         }else {
-           detail.add(new FormulaDrugDetailDomain());
+            detail.add(new FormulaDrugDetailDomain());
         }
         for (FormulaDrugDetailDomain formulaDrugDetailDomain : detail) {
             BusLiquidExcelVO excelVO = new BusLiquidExcelVO();
+            excelVO.setNum(index);
             // 这里需要根据实际字段进行映射
             excelVO.setClinicId(record.getClinicId());
             excelVO.setClinicName(record.getClinicName());
@@ -109,19 +113,27 @@ public class BusLiquidController {
             }else {
                 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.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.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.setLiquidChecker(record.getLiquidChecker());
             excelVO.setLiquidRemark(record.getLiquidRemark());
-            excelVO.setLiquidTime(record.getLiquidTime());
+            excelVO.setLiquidTime(DateUtil.formatDateTime(record.getLiquidTime()));
             result.add(excelVO);
         }
         return result;

+ 36 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/excel/ExportResult.java

@@ -0,0 +1,36 @@
+package com.nb.web.service.bus.excel;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @ClassName : ExportResult
+ * @Description : 文件导出结果
+ * @Author : LF
+ * @Date: 2023年06月15日
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class ExportResult {
+    private String fileName;
+    private String base64;
+    private ExportType type;
+    public String getFileName() {
+        if(CollectionUtil.size(StrUtil.split(fileName,"."))>2){
+            return fileName;
+        }
+        return fileName+type.getSuffix();
+    }
+
+    public static ExportResult of(String fileName,String base64){
+        return new ExportResult(fileName,base64,ExportType.EXCEL);
+    }
+
+    public static ExportResult of(String fileName,String base64,ExportType type){
+        return new ExportResult(fileName,base64,type);
+    }
+}

+ 20 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/excel/ExportType.java

@@ -0,0 +1,20 @@
+package com.nb.web.service.bus.excel;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * @Enum : ExportType
+ * @Description :
+ * @Author : LF
+ * @Date: 2023年09月25日
+ */
+@AllArgsConstructor
+@Getter
+public enum ExportType {
+    DOCX(".docx"),
+    EXCEL(".xlsx"),
+    ZIP(".zip"),;
+    @Getter
+    private String suffix;
+}

+ 82 - 33
nb-service/web-service/src/main/java/com/nb/web/service/bus/excel/LiquidExcelMergeWriteHandler.java

@@ -1,4 +1,4 @@
-package com.nb.web.service.bus.utils;
+package com.nb.web.service.bus.excel;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
@@ -21,14 +21,24 @@ import java.util.HashSet;
 
 public class LiquidExcelMergeWriteHandler implements RowWriteHandler {
     // 最小行索引
-    private int minRowIndex = 4;
-    // 不需要合并的列索引(根据ExcelProperty的order值)
-    private Set<Integer> excludeColumnIndexes = new HashSet<Integer>() {{
-        add(9);  // 药品名称 (name) - order = 9
-        add(10); // 药品用量 (dose) - order = 10
-        add(11); // 药品单位 (unit) - order = 11
-        add(12); // 批号 (batchCode) - order = 12
-        add(13); // 用法 (use) - order = 13
+    private int minRowIndex = 0;
+    // 需要合并的列索引(根据ExcelProperty的order值)
+    private Set<Integer> includeColumnIndexes = new HashSet<Integer>() {{
+        add(0);  // 序号 (num) - order = 1
+        add(1);  // 手术名称 (clinicName) - order = 1
+        add(2);  // 住院号 (patientCode) - order = 2
+        add(3);  // 病人名称 (patientName) - order = 3
+        add(4);  // 病区 (ward) - order = 4
+        add(5);  // 床号 (bedNo) - order = 5
+        add(6);  // 泵别名 (deviceAlias) - order = 6
+        add(7);  // 用泵时间 (clinicStartTime) - order = 7
+        add(8);  // 撤泵时间 (undoTime) - order = 8
+        add(14); // 总量 (totalDose) - order = 14
+        add(15); // 剩余量 (remainDose) - order = 15
+        add(16); // 废液执行人 (liquidExecutor) - order = 16
+        add(17); // 废液检查人 (liquidChecker) - order = 17
+        add(18); // 废液核对备注 (liquidRemark) - order = 18
+        add(19); // 废液核对时间 (liquidTime) - order = 19
     }};
 
     private List<BusLiquidExcelVO> source;
@@ -40,63 +50,102 @@ public class LiquidExcelMergeWriteHandler implements RowWriteHandler {
     @Override
     public void afterRowDispose(RowWriteHandlerContext context) {
         Integer rowIndex = context.getRowIndex();
-        if (rowIndex != CollectionUtil.size(source) + 3) {
+        // 只有在处理最后一行时才执行合并操作
+        if (rowIndex != CollectionUtil.size(source)) {
             return;
         }
 
+        // 设置表头字体和大小
+        setHeaderStyle(context.getWriteSheetHolder().getSheet());
+        // 设置所有单元格垂直居中
+        setVerticalAlignment(context.getWriteSheetHolder().getSheet());
         // 自适应列宽
         autoSizeColumns(context.getWriteSheetHolder().getSheet());
 
         Integer lastRowIndex = rowIndex;
         int lastMergeIndex = lastRowIndex;
         int currentIndex = lastRowIndex;
-        while (currentIndex >= 4) {
-            int preIndex = currentIndex - 1;
-            preIndex = preIndex > 4 ? preIndex : 4;
-            BusLiquidExcelVO curSource = CollectionUtil.get(source, currentIndex - 4);
-            BusLiquidExcelVO preSource = CollectionUtil.get(source, preIndex - 4);
-            if (!StrUtil.equals(curSource.getClinicId(), preSource.getClinicId()) || currentIndex == 4) {
-                // 合并除指定列外的所有列 (总共20列,从0到19)
-                for (int i = 0; i <= 19; i++) {
-                    // 跳过不需要合并的列
-                    if (!excludeColumnIndexes.contains(i)) {
-                        mergeCell(context.getWriteSheetHolder().getSheet(), currentIndex, lastMergeIndex, i, i);
-                    }
+        while (currentIndex >= 1) {
+            BusLiquidExcelVO curSource = CollectionUtil.get(source, currentIndex -1 );
+            BusLiquidExcelVO preSource = CollectionUtil.get(source, currentIndex -2);
+            if (!StrUtil.equals(curSource.getClinicId(), preSource.getClinicId()) || currentIndex == 1) {
+                // 合并指定的列
+                for (Integer i : includeColumnIndexes) {
+                    mergeCell(context.getWriteSheetHolder().getSheet(), currentIndex, lastMergeIndex, i, i);
                 }
-                lastMergeIndex = preIndex;
+                currentIndex--;
+                lastMergeIndex = currentIndex;
+            }else {
+                currentIndex--;
             }
-            currentIndex--;
         }
     }
 
-    private void setFontStyle(Sheet sheet) {
-        Font font = sheet.getWorkbook().createFont();
-        font.setFontHeightInPoints((short) 8); // 设置字体大小为8号
-
+    private void setVerticalAlignment(Sheet sheet) {
         CellStyle style = sheet.getWorkbook().createCellStyle();
-        style.setFont(font);
-
-        // 设置所有单元格的样式
-        for (int i = 0; i < sheet.getLastRowNum(); i++) {
+        // 设置垂直居中
+        style.setVerticalAlignment(VerticalAlignment.CENTER);
+        // 设置水平左对齐
+        style.setAlignment(HorizontalAlignment.LEFT);
+        // 设置边框
+        style.setBorderTop(BorderStyle.THIN);
+        style.setBorderBottom(BorderStyle.THIN);
+        style.setBorderLeft(BorderStyle.THIN);
+        style.setBorderRight(BorderStyle.THIN);
+        // 应用到所有单元格
+        for (int i = 1; i <= sheet.getLastRowNum(); i++) {
             Row row = sheet.getRow(i);
             if (row != null) {
                 for (int j = 0; j < row.getLastCellNum(); j++) {
                     Cell cell = row.getCell(j);
                     if (cell != null) {
                         cell.setCellStyle(style);
+                    } else {
+                        cell = row.createCell(j);
+                        cell.setCellStyle(style);
                     }
                 }
             }
         }
     }
 
+
     private void autoSizeColumns(Sheet sheet) {
         // 自适应列宽
         for (int i = 0; i < 20; i++) { // 20列
-            sheet.autoSizeColumn(i);
+//            sheet.autoSizeColumn(i);
         }
     }
 
+    private void setHeaderStyle(Sheet sheet) {
+        // 创建表头样式
+        CellStyle headerStyle = sheet.getWorkbook().createCellStyle();
+        Font headerFont = sheet.getWorkbook().createFont();
+        headerFont.setFontName("微软雅黑"); // 设置字体为微软雅黑
+        headerFont.setFontHeightInPoints((short) 10); // 设置字体大小为10号
+        headerFont.setBold(true); // 设置粗体
+        headerStyle.setFont(headerFont);
+        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER); // 垂直居中
+        headerStyle.setAlignment(HorizontalAlignment.CENTER); // 水平居中
+        // 设置灰色背景
+        headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
+        headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+        // 设置边框
+        headerStyle.setBorderTop(BorderStyle.THIN);
+        headerStyle.setBorderBottom(BorderStyle.THIN);
+        headerStyle.setBorderLeft(BorderStyle.THIN);
+        headerStyle.setBorderRight(BorderStyle.THIN);
+        // 应用表头样式到第一行(表头行)
+        Row headerRow = sheet.getRow(0);
+        if (headerRow != null) {
+            for (int i = 0; i < headerRow.getLastCellNum(); i++) {
+                Cell cell = headerRow.getCell(i);
+                if (cell != null) {
+                    cell.setCellStyle(headerStyle);
+                }
+            }
+        }
+    }
     private void mergeCell(Sheet sheet, int startRowIndex, int endRowIndex, int startColumnIndex, int endColumnIndex) {
         // 开始和结束行数一样
         if (startRowIndex == endRowIndex) {

+ 9 - 12
nb-service/web-service/src/main/java/com/nb/web/service/bus/service/dto/BusLiquidExcelVO.java

@@ -1,5 +1,6 @@
 package com.nb.web.service.bus.service.dto;
 
+import cn.hutool.core.date.DateUtil;
 import com.alibaba.excel.annotation.ExcelIgnore;
 import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.alibaba.excel.annotation.ExcelProperty;
@@ -44,8 +45,6 @@ public class BusLiquidExcelVO implements Serializable {
     @ExcelProperty(value = "住院号", order = 2)
     private String patientCode;
 
-
-
     @ApiModelProperty(value = "病人名称")
     @ExcelProperty(value = "病人名称", order = 3)
     private String patientName;
@@ -64,13 +63,11 @@ public class BusLiquidExcelVO implements Serializable {
 
     @ApiModelProperty("用泵时间")
     @ExcelProperty(value = "用泵时间", order = 7)
-    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
-    private Date clinicStartTime;
+    private String clinicStartTime;
 
     @ApiModelProperty("撤泵时间")
     @ExcelProperty(value = "撤泵时间", order = 8)
-    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
-    private Date undoTime;
+    private String undoTime;
 
     @ApiModelProperty(value = "药品名称")
     @ExcelProperty(value = "药品名称", order = 9)
@@ -80,9 +77,9 @@ public class BusLiquidExcelVO implements Serializable {
     @ExcelProperty(value = "药品用量", order = 10)
     private String dose;
 
-    @ApiModelProperty(value = "药品单位")
-    @ExcelProperty(value = "药品单位", order = 11)
-    private String unit;
+    @ApiModelProperty(value = "药品残余量")
+    @ExcelProperty(value = "药品残余量", order = 11)
+    private String drugRemainDose;
 
     @ApiModelProperty("批号")
     @ExcelProperty(value = "批号", order = 12)
@@ -94,11 +91,11 @@ public class BusLiquidExcelVO implements Serializable {
 
     @ApiModelProperty(value = "总量")
     @ExcelProperty(value = "总量", order = 14)
-    private BigDecimal totalDose;
+    private String totalDose;
 
     @ApiModelProperty(value = "剩余量")
     @ExcelProperty(value = "剩余量", order = 15)
-    private BigDecimal remainDose;
+    private String remainDose;
 
     @ApiModelProperty(value = "废液执行人")
     @ExcelProperty(value = "废液执行人", order = 16)
@@ -114,5 +111,5 @@ public class BusLiquidExcelVO implements Serializable {
 
     @ApiModelProperty(value = "废液核对时间")
     @ExcelProperty(value = "废液核对时间", order = 19)
-    private Date liquidTime;
+    private String liquidTime;
 }

+ 2 - 2
nb-service/web-service/src/main/resources/mapper/bus/BusClinicMapper.xml

@@ -366,8 +366,8 @@
         c.liquid_remark as liquid_remark,
         c.liquid_time as liquid_time
         from bus_clinic as c
-        join bus_patient as p on c.patient_id = p.id
-        join bus_infusion_history as i on p.infusion_id = i.id
+        left join bus_patient as p on c.patient_id = p.id
+        left join bus_infusion_history as i on p.infusion_id = i.id
         <where>
             and c.id in
             <foreach item="w" index="index" collection="ids" open="(" separator="," close=")">