| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | 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; |
| | | } |
| | |
| | | } |
| | | |
| | | 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)); |
| | | } |
| | | |
| | |
| | | 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); |
| | |
| | | } |
| | | 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; |
| | | } |
| | | |