Browse Source

add
废液管理
修改异常标识

lifang 3 months ago
parent
commit
410ba7d242

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

@@ -22,4 +22,10 @@ public class FormulaDrugDetailDomain {
 
     @ApiModelProperty(value = "药品单位")
     private String unit;
+
+    @ApiModelProperty("批号")
+    private String batchCode;
+
+    @ApiModelProperty("用法")
+    private String use;
 }

+ 80 - 17
nb-service/web-service/src/main/java/com/nb/web/service/bus/controller/BusLiquidController.java

@@ -1,39 +1,29 @@
 package com.nb.web.service.bus.controller;
 
 import cn.dev33.satoken.annotation.SaCheckPermission;
-import cn.dev33.satoken.annotation.SaMode;
-import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.StrUtil;
-import cn.hutool.json.JSONUtil;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.alibaba.excel.EasyExcel;
 import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.nb.core.annotation.Log;
-import com.nb.core.entity.GenericEntity;
-import com.nb.core.enums.ExportType;
 import com.nb.core.exception.CustomException;
-import com.nb.core.result.ExportResult;
 import com.nb.core.result.R;
-import com.nb.web.api.entity.*;
-import com.nb.web.api.feign.query.PatientMonitorQuery;
-import com.nb.web.api.feign.result.PatientMonitorResult;
+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.entity.BusInfusionModifyEntity;
-import com.nb.web.service.bus.entity.BusPatientEntity;
 import com.nb.web.service.bus.service.*;
 import com.nb.web.service.bus.service.dto.*;
-import com.nb.web.service.bus.utils.AnalExportUtils;
+import com.nb.web.service.bus.utils.LiquidExcelMergeWriteHandler;
 import io.swagger.annotations.*;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.ServletOutputStream;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.nio.charset.Charset;
 import java.util.*;
-import java.util.stream.Collectors;
 
 /**
  * @author lifang
@@ -63,4 +53,77 @@ public class BusLiquidController {
         clinicService.batchHandleLiquid(source);
         return R.success(Boolean.TRUE);
     }
+
+    @ApiOperation("导出废液记录单")
+    @PostMapping("/export/record")
+    public void exportRecord(HttpServletResponse response, @RequestBody Collection<String> ids) throws IOException {
+        if(CollectionUtil.isEmpty(ids)){
+            throw new CustomException("请选择要导出的废液记录");
+        }
+        List<BusLiquidListVO> records= clinicService.selectLiquidByIds(ids);
+        if(CollectionUtil.isEmpty(records)){
+            throw new CustomException("请选择要导出的废液记录");
+        }
+        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());
+        }
+    }
+
+    private  List<BusLiquidExcelVO> convertExcelVO(BusLiquidListVO record){
+        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());
+        }
+        for (FormulaDrugDetailDomain formulaDrugDetailDomain : detail) {
+            BusLiquidExcelVO excelVO = new BusLiquidExcelVO();
+            // 这里需要根据实际字段进行映射
+            excelVO.setClinicId(record.getClinicId());
+            excelVO.setClinicName(record.getClinicName());
+            excelVO.setPatientCode(record.getPatientCode());
+            excelVO.setPatientId(record.getPatientId());
+            excelVO.setPatientName(record.getPatientName());
+            excelVO.setWard(record.getWard());
+            excelVO.setBedNo(record.getBedNo());
+            if(StrUtil.isNotEmpty(record.getDeviceAlias())){
+                excelVO.setDeviceAlias(record.getDeviceAlias());
+            }else {
+                excelVO.setDeviceAlias(record.getDeviceId());
+            }
+            excelVO.setClinicStartTime(record.getClinicStartTime());
+            excelVO.setUndoTime(record.getUndoTime());
+            excelVO.setName(formulaDrugDetailDomain.getName());
+            excelVO.setDose(formulaDrugDetailDomain.getDose());
+            excelVO.setUnit(formulaDrugDetailDomain.getUnit());
+            excelVO.setBatchCode(formulaDrugDetailDomain.getBatchCode());
+            excelVO.setUse(formulaDrugDetailDomain.getUse());
+            excelVO.setTotalDose(record.getTotalDose());
+            excelVO.setRemainDose(record.getRemainDose());
+            excelVO.setLiquidExecutor(record.getLiquidExecutor());
+            excelVO.setLiquidChecker(record.getLiquidChecker());
+            excelVO.setLiquidRemark(record.getLiquidRemark());
+            excelVO.setLiquidTime(record.getLiquidTime());
+            result.add(excelVO);
+        }
+        return result;
+    }
 }

+ 108 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/excel/LiquidExcelMergeWriteHandler.java

@@ -0,0 +1,108 @@
+package com.nb.web.service.bus.utils;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.excel.write.handler.RowWriteHandler;
+import com.alibaba.excel.write.handler.context.RowWriteHandlerContext;
+import com.nb.web.service.bus.service.dto.BusLiquidExcelVO;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellRangeAddress;
+
+import java.util.List;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * @ClassName : LiquidExcelMergeWriteHandler
+ * @Description : 废液Excel导出合并单元格处理类
+ * @Author :
+ * @Date: 2025年09月11日
+ */
+
+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 List<BusLiquidExcelVO> source;
+
+    public LiquidExcelMergeWriteHandler(List<BusLiquidExcelVO> source) {
+        this.source = source;
+    }
+
+    @Override
+    public void afterRowDispose(RowWriteHandlerContext context) {
+        Integer rowIndex = context.getRowIndex();
+        if (rowIndex != CollectionUtil.size(source) + 3) {
+            return;
+        }
+
+        // 自适应列宽
+        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);
+                    }
+                }
+                lastMergeIndex = preIndex;
+            }
+            currentIndex--;
+        }
+    }
+
+    private void setFontStyle(Sheet sheet) {
+        Font font = sheet.getWorkbook().createFont();
+        font.setFontHeightInPoints((short) 8); // 设置字体大小为8号
+
+        CellStyle style = sheet.getWorkbook().createCellStyle();
+        style.setFont(font);
+
+        // 设置所有单元格的样式
+        for (int i = 0; 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);
+                    }
+                }
+            }
+        }
+    }
+
+    private void autoSizeColumns(Sheet sheet) {
+        // 自适应列宽
+        for (int i = 0; i < 20; i++) { // 20列
+            sheet.autoSizeColumn(i);
+        }
+    }
+
+    private void mergeCell(Sheet sheet, int startRowIndex, int endRowIndex, int startColumnIndex, int endColumnIndex) {
+        // 开始和结束行数一样
+        if (startRowIndex == endRowIndex) {
+            return;
+        }
+        CellRangeAddress cellRangeAddress = new CellRangeAddress(startRowIndex, endRowIndex, startColumnIndex, endColumnIndex);
+        sheet.addMergedRegion(cellRangeAddress);
+    }
+}

+ 2 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/mapper/BusClinicMapper.java

@@ -50,4 +50,6 @@ public interface BusClinicMapper extends BaseMapper<BusClinicEntity> {
     IPage<ClinicResult> latestQueryPage(Page<ClinicResult> page, @Param("query") ClinicQuery query);
 
     IPage<BusLiquidListVO> selectLiquidPage(Page<BusLiquidListVO> page, @Param("query")BusLiquidQuery query);
+
+    List<BusLiquidListVO> selectLiquidByIds(@Param("ids")Collection<String> ids);
 }

+ 18 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/service/LocalBusClinicService.java

@@ -428,4 +428,22 @@ public class LocalBusClinicService extends BaseService<BusClinicMapper, BusClini
                 .set(BusClinicEntity::getLiquidTime,source.getLiquidTime())
                 .set(BusClinicEntity::getLiquidRemark,source.getLiquidRemark()));
     }
+
+    public List<BusLiquidListVO> selectLiquidByIds(Collection<String> ids) {
+        if(CollectionUtil.isEmpty(ids)){
+            return Collections.emptyList();
+        }
+        List<BusLiquidListVO> result = this.baseMapper.selectLiquidByIds(ids);
+        if(CollectionUtil.isNotEmpty(result)){
+            List<BusDeviceEntity> deviceList = deviceService.listByIds(result.stream().map(BusLiquidListVO::getDeviceId).collect(Collectors.toList()));
+            Map<String, BusDeviceEntity> deviceMap = deviceList.stream().collect(Collectors.toMap(BusDeviceEntity::getId, item->item));
+            for (BusLiquidListVO record : result) {
+                BusDeviceEntity device = deviceMap.get(record.getDeviceId());
+                if(ObjectUtil.isNotNull(device)){
+                    record.setDeviceAlias(device.getAlias());
+                }
+            }
+        }
+        return result;
+    }
 }

+ 118 - 0
nb-service/web-service/src/main/java/com/nb/web/service/bus/service/dto/BusLiquidExcelVO.java

@@ -0,0 +1,118 @@
+package com.nb.web.service.bus.service.dto;
+
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.format.DateTimeFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.ToString;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @author lifang
+ * @version 1.0.0
+ * @ClassName PatientMonitorResult.java
+ * @Description TODO
+ * @createTime 2022年04月21日 15:57:00
+ */
+@ApiModel("废液显示")
+@Data
+@ToString
+@ExcelIgnoreUnannotated
+public class BusLiquidExcelVO implements Serializable {
+    @ApiModelProperty("手术id")
+    @ExcelIgnore
+    private String clinicId;
+
+    @ApiModelProperty(value = "病人id")
+    @ExcelIgnore
+    private String patientId;
+
+    @ExcelProperty(value = "序号", order = 0)
+    private Integer num;
+
+    @ApiModelProperty("手术名称")
+    @ExcelProperty(value = "手术名称", order = 1)
+    private String clinicName;
+
+    @ApiModelProperty(value = "住院号")
+    @ExcelProperty(value = "住院号", order = 2)
+    private String patientCode;
+
+
+
+    @ApiModelProperty(value = "病人名称")
+    @ExcelProperty(value = "病人名称", order = 3)
+    private String patientName;
+
+    @ApiModelProperty(value = "病区")
+    @ExcelProperty(value = "病区", order = 4)
+    private String ward;
+
+    @ApiModelProperty(value = "床号")
+    @ExcelProperty(value = "床号", order = 5)
+    private String bedNo;
+
+    @ApiModelProperty(value = "泵别名")
+    @ExcelProperty(value = "泵别名", order = 6)
+    private String deviceAlias;
+
+    @ApiModelProperty("用泵时间")
+    @ExcelProperty(value = "用泵时间", order = 7)
+    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
+    private Date clinicStartTime;
+
+    @ApiModelProperty("撤泵时间")
+    @ExcelProperty(value = "撤泵时间", order = 8)
+    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
+    private Date undoTime;
+
+    @ApiModelProperty(value = "药品名称")
+    @ExcelProperty(value = "药品名称", order = 9)
+    private String name;
+
+    @ApiModelProperty(value = "药品用量")
+    @ExcelProperty(value = "药品用量", order = 10)
+    private String dose;
+
+    @ApiModelProperty(value = "药品单位")
+    @ExcelProperty(value = "药品单位", order = 11)
+    private String unit;
+
+    @ApiModelProperty("批号")
+    @ExcelProperty(value = "批号", order = 12)
+    private String batchCode;
+
+    @ApiModelProperty("用法")
+    @ExcelProperty(value = "用法", order = 13)
+    private String use;
+
+    @ApiModelProperty(value = "总量")
+    @ExcelProperty(value = "总量", order = 14)
+    private BigDecimal totalDose;
+
+    @ApiModelProperty(value = "剩余量")
+    @ExcelProperty(value = "剩余量", order = 15)
+    private BigDecimal remainDose;
+
+    @ApiModelProperty(value = "废液执行人")
+    @ExcelProperty(value = "废液执行人", order = 16)
+    private String liquidExecutor;
+
+    @ApiModelProperty(value = "废液检查人")
+    @ExcelProperty(value = "废液检查人", order = 17)
+    private String liquidChecker;
+
+    @ApiModelProperty(value = "废液核对备注")
+    @ExcelProperty(value = "废液核对备注", order = 18)
+    private String liquidRemark;
+
+    @ApiModelProperty(value = "废液核对时间")
+    @ExcelProperty(value = "废液核对时间", order = 19)
+    private Date liquidTime;
+}

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

@@ -341,4 +341,38 @@
         </where>
         order by undo_time desc
     </select>
+
+
+    <select id="selectLiquidByIds" resultMap="stdLiquidResult">
+        select
+        c.id as clinic_id,
+        c.patient_id as patient_id,
+        c.patient_code as patient_code,
+        c.patient_name as patient_name,
+        c.ward as ward,
+        CASE
+        WHEN c.manual_bedno IS NOT NULL AND c.manual_bedno != '' THEN c.manual_bedno
+        ELSE c.bed_no
+        END as bed_no,
+        c.surgery_name  as clinic_name,
+        i.device_id as device_id,
+        c.monitor_start_time as clinic_start_time,
+        i.undo_time as undo_time,
+        c.formula as formula,
+        i.total_dose as total_dose,
+        i.remain_dose as remain_dose,
+        c.liquid_executor as liquid_executor,
+        c.liquid_checker as liquid_checker,
+        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
+        <where>
+            and c.id in
+            <foreach item="w" index="index" collection="ids" open="(" separator="," close=")">
+                #{w, jdbcType=VARCHAR}
+            </foreach>
+        </where>
+    </select>
 </mapper>