From d89a42213b4a32535e93185dedf41fe7a7fc1940 Mon Sep 17 00:00:00 2001
From: mitao <2763622819@qq.com>
Date: 星期五, 04 四月 2025 01:57:13 +0800
Subject: [PATCH] bug修改

---
 medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java |   64 ++++++++++++++++++++++---------
 1 files changed, 45 insertions(+), 19 deletions(-)

diff --git a/medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java b/medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java
index 6970076..bd9680f 100644
--- a/medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java
+++ b/medicalWaste-system/src/main/java/com/sinata/system/service/biz/StaticsService.java
@@ -7,6 +7,7 @@
 import com.sinata.common.utils.DateUtils;
 import com.sinata.common.utils.StringUtils;
 import com.sinata.system.config.AutoColumnWidthStrategy;
+import com.sinata.system.config.CustomCellWriteHeightConfig;
 import com.sinata.system.domain.MwCollectRecord;
 import com.sinata.system.domain.MwWarningRecord;
 import com.sinata.system.domain.SysDepartment;
@@ -29,15 +30,20 @@
 import com.sinata.system.service.MwWarningRecordService;
 import com.sinata.system.service.SysDepartmentService;
 import com.sinata.system.utils.ImageToBase64;
+import com.sinata.system.utils.ImgUtils;
 import lombok.RequiredArgsConstructor;
+import net.coobird.thumbnailator.Thumbnails;
+import org.apache.commons.io.FilenameUtils;
 import org.springframework.stereotype.Service;
 
+import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.net.MalformedURLException;
-import java.net.URL;
 import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
@@ -276,10 +282,10 @@
         String finalTitle = title;
         wasteTypeList.forEach(item -> {
             headTitles.add(Lists.newArrayList(finalTitle, item.getDictLabel(), "数量"));
-            headTitles.add(Lists.newArrayList(finalTitle, item.getDictLabel(), "重量(KG)"));
+            headTitles.add(Lists.newArrayList(finalTitle, item.getDictLabel(), "重量(kg)"));
         });
         headTitles.add(Lists.newArrayList(title, "小计", "数量"));
-        headTitles.add(Lists.newArrayList(title, "小计", "重量(KG)"));
+        headTitles.add(Lists.newArrayList(title, "小计", "重量(kg)"));
         headTitles.add(Lists.newArrayList(title, "是否超时", "是否超时"));
         return headTitles;
     }
@@ -388,20 +394,21 @@
     }
 
     public void transformListExport(TransformQuery query) throws IOException {
-        List<List<String>> head = transformReportHead(query.getWasteTypeCodeList());
+        List<List<String>> head = transformReportHead(query);
         System.out.println(JSONObject.toJSONString(head));
         // 这里注意 有同学反应使用swagger 会导致各种问题,请直接用浏览器或者用postman
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
         response.setCharacterEncoding("utf-8");
         // 这里URLEncoder.encode可以防止中文乱码 当然和easyexcel没有关系
-        String fileName = URLEncoder.encode("医院报表", "UTF-8").replaceAll("\\+", "%20");
+        String fileName = URLEncoder.encode("转移联单", "UTF-8").replaceAll("\\+", "%20");
         response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
         // 这里需要设置不关闭流
         FastExcel.write(response.getOutputStream())
                 .head(head)
                 .autoCloseStream(Boolean.TRUE)
                 .registerWriteHandler(new AutoColumnWidthStrategy())
-                .sheet("转运联单")
+                .registerWriteHandler(new CustomCellWriteHeightConfig())
+                .sheet("转移联单")
                 .doWrite(getTransformReportStaticsData(query));
     }
 
@@ -421,7 +428,19 @@
                 List<Object> data = new ArrayList<>();
                 data.add(departmentReportItemVO.getName());
                 data.addAll(departmentReportItemVO.getData());
-                data.add(StringUtils.isNotBlank(departmentReportItemVO.getHospitalSignatureUrl()) ? new URL(departmentReportItemVO.getHospitalSignatureUrl()) : "");
+                if (StringUtils.isNotBlank(departmentReportItemVO.getHospitalSignatureUrl())) {
+                    try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
+                        //获取文件后缀
+                        String extension = FilenameUtils.getExtension(departmentReportItemVO.getHospitalSignatureUrl());
+                        BufferedImage originalImage = ImageIO.read(ImgUtils.getFileByHttpURL(departmentReportItemVO.getHospitalSignatureUrl()));
+                        Thumbnails.of(originalImage).scale(0.8).rotate(270).outputFormat(extension).toOutputStream(outputStream);
+                        data.add(outputStream.toByteArray());
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                } else {
+                    data.add("");
+                }
                 data.add(departmentReportItemVO.getDriverName());
                 data.add(departmentReportItemVO.getHandoverTime());
                 result.add(data);
@@ -430,27 +449,34 @@
         }
         return CollUtils.emptyList();
     }
-
     /**
      * 转运联单导出表头
      *
-     * @param wasteTypeCodeList
+     * @param query
      * @return
      */
-    private List<List<String>> transformReportHead(List<Long> wasteTypeCodeList) {
+    private List<List<String>> transformReportHead(TransformQuery query) {
         //查询医废类型
-        List<SysDictDataVO> sysDictDataVOS = sysDictDataService.medicalWasteTypeListByDictCode(wasteTypeCodeList);
+        List<SysDictDataVO> sysDictDataVOS = sysDictDataService.medicalWasteTypeListByDictCode(query.getWasteTypeCodeList());
+        SysDepartment department = sysDepartmentService.getById(query.getDepartmentId());
+        String title = "";
+        if (Objects.nonNull(department)) {
+            title = department.getDepartmentName() + "转移联单";
+        } else {
+            title = "转移联单";
+        }
         List<List<String>> headTitles = Lists.newArrayList();
-        headTitles.add(Lists.newArrayList("医院名称", "医院名称"));
+        headTitles.add(Lists.newArrayList(title, "医院名称", "医院名称"));
+        String finalTitle = title;
         sysDictDataVOS.forEach(item -> {
-            headTitles.add(Lists.newArrayList(item.getDictLabel(), "数量"));
-            headTitles.add(Lists.newArrayList(item.getDictLabel(), "重量(KG)"));
+            headTitles.add(Lists.newArrayList(finalTitle, item.getDictLabel(), "数量"));
+            headTitles.add(Lists.newArrayList(finalTitle, item.getDictLabel(), "重量(kg)"));
         });
-        headTitles.add(Lists.newArrayList("小计", "数量"));
-        headTitles.add(Lists.newArrayList("小计", "重量(KG)"));
-        headTitles.add(Lists.newArrayList("机构人员签字", "机构人员签字"));
-        headTitles.add(Lists.newArrayList("运输人员签字", "运输人员签字"));
-        headTitles.add(Lists.newArrayList("交接时间", "交接时间"));
+        headTitles.add(Lists.newArrayList(title, "小计", "数量"));
+        headTitles.add(Lists.newArrayList(title, "小计", "重量(kg)"));
+        headTitles.add(Lists.newArrayList(title, "机构人员签字", "机构人员签字"));
+        headTitles.add(Lists.newArrayList(title, "运输人员签字", "运输人员签字"));
+        headTitles.add(Lists.newArrayList(title, "交接时间", "交接时间"));
         return headTitles;
     }
 

--
Gitblit v1.7.1