Browse Source

update: 卫生自查

zhongwei
liwen 10 months ago
parent
commit
71b40978d7
  1. 2
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneRecordEntity.java
  2. 5
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/HygieneZoneEntity.java
  3. 8
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/HygieneController.java
  4. 6
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneRecordService.java
  5. 66
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/HygieneRecordServiceImpl.java

2
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;

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

8
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")

6
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/IHygieneRecordService.java

@ -57,9 +57,9 @@ public interface IHygieneRecordService extends IService<HygieneRecordEntity> {
IPage<HygieneRecordPageVO> recordPage(Map<String, Object> param, Query query);
/**
* 卫生自查记录数据导出
* @param hygieneRecordId 卫生自查记录id
* 卫生自查记录导出
* @param id 卫生自查记录id
* @param response 响应类
*/
void exportHygieneData(Long hygieneRecordId, HttpServletResponse response);
void exportHygieneRecordData(Long id, HttpServletResponse response);
}

66
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<HygieneRecordMapper, H
@Autowired
IHygieneZoneService hygieneZoneService;
@Value("${hzims.hygiene.savePath}")
private String savePath;
/**
* 删除关联卫生自查记录
*/
@ -170,50 +163,13 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
* 卫生自查数据导出
*/
@Override
public void exportHygieneData(Long hygieneRecordId, HttpServletResponse response) {
ServletOutputStream outputStream = null;
try {
outputStream = response.getOutputStream();
HygieneRecordDetailVO recordDetailVO = getRecordDetail(hygieneRecordId);
List<HygieneZoneDetailVO> 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<String> 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<String, Object> 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);
}
/**

Loading…
Cancel
Save