From 71b40978d780eaa8e64f5669683d908e6a8aa7ea Mon Sep 17 00:00:00 2001 From: liwen Date: Mon, 15 Jan 2024 14:37:02 +0800 Subject: [PATCH] =?UTF-8?q?update:=20=E5=8D=AB=E7=94=9F=E8=87=AA=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../safeproduct/entity/HygieneRecordEntity.java | 2 + .../safeproduct/entity/HygieneZoneEntity.java | 5 ++ .../safeproduct/controller/HygieneController.java | 8 +-- .../safeproduct/service/IHygieneRecordService.java | 6 +- .../service/impl/HygieneRecordServiceImpl.java | 66 ++++------------------ 5 files changed, 25 insertions(+), 62 deletions(-) diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneRecordEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneRecordEntity.java index e58f745..933ecb9 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneRecordEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneRecordEntity.java @@ -39,9 +39,11 @@ public class HygieneRecordEntity extends BaseEntity { @ApiModelProperty("实际结束时间") private Date actualEndTime; + @Size(max = 20, message = "检查人字段长度不能超过20") @ApiModelProperty("检查人") private String checkUser; + @Size(max = 1000, message = "责任区id字段长度不能超过1000") @ApiModelProperty("责任区id") private String hygieneZoneIds; diff --git a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneZoneEntity.java b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneZoneEntity.java index 415e47b..5406110 100644 --- a/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneZoneEntity.java +++ b/hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneZoneEntity.java @@ -7,6 +7,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import org.springblade.core.mp.base.BaseEntity; +import javax.validation.constraints.Size; + /** * @author liwen * @date 2024-01-02 @@ -20,15 +22,18 @@ public class HygieneZoneEntity extends BaseEntity { @ApiModelProperty("卫生自查计划id") private Long hygienePlanId; + @Size(max = 50, message = "责任区字段长度不能超过50") @ApiModelProperty("责任区") private String zone; + @Size(max = 20, message = "责任人字段长度不能超过20") @ApiModelProperty("责任人") private String principal; @ApiModelProperty("检查项") private String checkItem; + @Size(max = 255, message = "检查项分值字段长度不能超过255") @ApiModelProperty("检查项分值") private String checkItemScore; } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java index 63bdafe..0a271f9 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java @@ -131,11 +131,11 @@ public class HygieneController extends BladeController { return R.data(page); } - @GetMapping("/exportHygieneData") - @ApiOperation(value = "卫生自查数据导出") + @GetMapping("/exportHygieneRecordData") + @ApiOperation(value = "卫生自查记录表导出") @ApiOperationSupport(order = 12) - public void exportHygieneData(@RequestParam Long hygieneRecordId, HttpServletResponse response) { - hygieneRecordService.exportHygieneData(hygieneRecordId, response); + public void exportHygieneRecordData(@RequestParam Long id, HttpServletResponse response) { + hygieneRecordService.exportHygieneRecordData(id, response); } @GetMapping("/exportMonthData") diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneRecordService.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneRecordService.java index d717ad5..86d8637 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneRecordService.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneRecordService.java @@ -57,9 +57,9 @@ public interface IHygieneRecordService extends IService { IPage recordPage(Map param, Query query); /** - * 卫生自查记录数据导出 - * @param hygieneRecordId 卫生自查记录id + * 卫生自查记录表导出 + * @param id 卫生自查记录id * @param response 响应类 */ - void exportHygieneData(Long hygieneRecordId, HttpServletResponse response); + void exportHygieneRecordData(Long id, HttpServletResponse response); } diff --git a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java index 2baeec5..051e0c7 100644 --- a/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java +++ b/hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java @@ -1,13 +1,7 @@ package com.hnac.hzims.safeproduct.service.impl; import cn.hutool.core.date.DatePattern; -import cn.hutool.core.date.DateUtil; -import com.alibaba.excel.EasyExcel; -import com.alibaba.excel.ExcelWriter; -import com.alibaba.excel.converters.longconverter.LongStringConverter; import com.alibaba.excel.util.CollectionUtils; -import com.alibaba.excel.write.metadata.WriteSheet; -import com.alibaba.excel.write.style.column.SimpleColumnWidthStyleStrategy; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -17,7 +11,6 @@ import com.hnac.hzims.safeproduct.dto.HygieneRecordDTO; import com.hnac.hzims.safeproduct.entity.HygienePlanEntity; import com.hnac.hzims.safeproduct.entity.HygieneRecordEntity; import com.hnac.hzims.safeproduct.entity.HygieneZoneEntity; -import com.hnac.hzims.safeproduct.entity.RehearsalPlanEntity; import com.hnac.hzims.safeproduct.enums.RehearsalStatusEnum; import com.hnac.hzims.safeproduct.mapper.HygienePlanMapper; import com.hnac.hzims.safeproduct.mapper.HygieneRecordMapper; @@ -27,18 +20,15 @@ import com.hnac.hzims.safeproduct.utils.BaseUtil; import com.hnac.hzims.safeproduct.vo.HygieneRecordPageVO; import com.hnac.hzims.safeproduct.vo.HygieneZoneDetailVO; import com.hnac.hzims.safeproduct.vo.HygieneRecordDetailVO; -import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.net.URLEncoder; import java.time.LocalDate; import java.time.ZoneId; import java.time.temporal.WeekFields; @@ -60,6 +50,9 @@ public class HygieneRecordServiceImpl extends ServiceImpl records = recordDetailVO.getCheckList(); - // 设置响应头 - // URLEncoder.encode防止中文乱码 - String fileName = URLEncoder.encode("卫生自查记录数据表", "UTF-8"); - response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); - response.setContentType("application/vnd.ms-excel"); - response.setCharacterEncoding("UTF-8"); - // ExcelWriter初始化 - ExcelWriter excelWriter = EasyExcel - .write(response.getOutputStream()) - .autoCloseStream(Boolean.TRUE) - .registerConverter(new LongStringConverter()) - .registerWriteHandler(new SimpleColumnWidthStyleStrategy(25)) - .build(); - Date endTime = recordDetailVO.getActualEndTime(); - String name = DateUtil.format(endTime, "yyyy年mm月") + "第" + recordDetailVO.getWeekNum() + "周卫生自查表"; - List head = new ArrayList<>(); - head.add(name); - WriteSheet writeSheet = EasyExcel.writerSheet(1, "卫生自查记录数据表") - .head(Collections.singletonList(head)) - .head(HygieneZoneDetailVO.class) - .build(); - excelWriter.write(records, writeSheet); - excelWriter.finish(); - } catch (Exception e) { - // 重置response - response.reset(); - response.setContentType("application/json"); - response.setCharacterEncoding("utf-8"); - throw new ServiceException("卫生自查记录数据导出异常: " + e.getMessage()); - } finally { - if (outputStream != null) { - try { - outputStream.close(); - } catch (IOException e) { - log.error("卫生自查记录数据导出输出流关闭异常: " + e.getMessage()); - } - } - } + public void exportHygieneRecordData(Long id, HttpServletResponse response) { + HygieneRecordDetailVO hygieneRecordDetailVO = this.getRecordDetail(id); + Map params = BaseUtil.obj2Map(hygieneRecordDetailVO); + String templateFile = "template/卫生自查记录表" + SafeProductConstant.DOCX_SUFFIX; + String wordPath = savePath + "/卫生自查记录表" + SafeProductConstant.DOCX_SUFFIX; + String pdfPath = savePath + "/卫生自查记录表" + SafeProductConstant.PDF_SUFFIX; + BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response); } /**