|
|
@ -1,13 +1,7 @@ |
|
|
|
package com.hnac.hzims.safeproduct.service.impl; |
|
|
|
package com.hnac.hzims.safeproduct.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DatePattern; |
|
|
|
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.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.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
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.HygienePlanEntity; |
|
|
|
import com.hnac.hzims.safeproduct.entity.HygieneRecordEntity; |
|
|
|
import com.hnac.hzims.safeproduct.entity.HygieneRecordEntity; |
|
|
|
import com.hnac.hzims.safeproduct.entity.HygieneZoneEntity; |
|
|
|
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.enums.RehearsalStatusEnum; |
|
|
|
import com.hnac.hzims.safeproduct.mapper.HygienePlanMapper; |
|
|
|
import com.hnac.hzims.safeproduct.mapper.HygienePlanMapper; |
|
|
|
import com.hnac.hzims.safeproduct.mapper.HygieneRecordMapper; |
|
|
|
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.HygieneRecordPageVO; |
|
|
|
import com.hnac.hzims.safeproduct.vo.HygieneZoneDetailVO; |
|
|
|
import com.hnac.hzims.safeproduct.vo.HygieneZoneDetailVO; |
|
|
|
import com.hnac.hzims.safeproduct.vo.HygieneRecordDetailVO; |
|
|
|
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.mp.support.Query; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.LocalDate; |
|
|
|
import java.time.ZoneId; |
|
|
|
import java.time.ZoneId; |
|
|
|
import java.time.temporal.WeekFields; |
|
|
|
import java.time.temporal.WeekFields; |
|
|
@ -60,6 +50,9 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
IHygieneZoneService hygieneZoneService; |
|
|
|
IHygieneZoneService hygieneZoneService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${hzims.hygiene.savePath}") |
|
|
|
|
|
|
|
private String savePath; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 删除关联卫生自查记录 |
|
|
|
* 删除关联卫生自查记录 |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -170,50 +163,13 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H |
|
|
|
* 卫生自查数据导出 |
|
|
|
* 卫生自查数据导出 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void exportHygieneData(Long hygieneRecordId, HttpServletResponse response) { |
|
|
|
public void exportHygieneRecordData(Long id, HttpServletResponse response) { |
|
|
|
ServletOutputStream outputStream = null; |
|
|
|
HygieneRecordDetailVO hygieneRecordDetailVO = this.getRecordDetail(id); |
|
|
|
try { |
|
|
|
Map<String, Object> params = BaseUtil.obj2Map(hygieneRecordDetailVO); |
|
|
|
outputStream = response.getOutputStream(); |
|
|
|
String templateFile = "template/卫生自查记录表" + SafeProductConstant.DOCX_SUFFIX; |
|
|
|
HygieneRecordDetailVO recordDetailVO = getRecordDetail(hygieneRecordId); |
|
|
|
String wordPath = savePath + "/卫生自查记录表" + SafeProductConstant.DOCX_SUFFIX; |
|
|
|
List<HygieneZoneDetailVO> records = recordDetailVO.getCheckList(); |
|
|
|
String pdfPath = savePath + "/卫生自查记录表" + SafeProductConstant.PDF_SUFFIX; |
|
|
|
// 设置响应头
|
|
|
|
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response); |
|
|
|
// 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()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|