|
|
|
@ -1,24 +1,19 @@
|
|
|
|
|
package com.hnac.hzims.safeproduct.service.impl; |
|
|
|
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil; |
|
|
|
|
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; |
|
|
|
|
import cn.hutool.core.date.DatePattern; |
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
|
|
|
|
import com.hnac.hzims.common.utils.DateUtil; |
|
|
|
|
import com.hnac.hzims.safeproduct.constants.SafeProductConstant; |
|
|
|
|
import com.hnac.hzims.safeproduct.dto.HygieneEvaluationExportDTO; |
|
|
|
|
import com.hnac.hzims.safeproduct.vo.HygieneEvaluationExportVO; |
|
|
|
|
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.enums.RehearsalStatusEnum; |
|
|
|
|
import com.hnac.hzims.safeproduct.hazard.util.ExcelConvertPdf; |
|
|
|
|
import com.hnac.hzims.safeproduct.mapper.HygienePlanMapper; |
|
|
|
|
import com.hnac.hzims.safeproduct.mapper.HygieneRecordMapper; |
|
|
|
|
import com.hnac.hzims.safeproduct.service.IHygieneRecordService; |
|
|
|
@ -26,9 +21,6 @@ import com.hnac.hzims.safeproduct.service.IHygieneZoneService;
|
|
|
|
|
import com.hnac.hzims.safeproduct.utils.BaseUtil; |
|
|
|
|
import com.hnac.hzims.safeproduct.vo.*; |
|
|
|
|
import com.hnac.hzinfo.exception.HzServiceException; |
|
|
|
|
import com.itextpdf.text.DocumentException; |
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet; |
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
|
import org.springblade.core.log.exception.ServiceException; |
|
|
|
|
import org.springblade.core.mp.support.Query; |
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
@ -42,14 +34,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.ServletOutputStream; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.io.OutputStream; |
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
import java.net.URLEncoder; |
|
|
|
|
import java.nio.file.Files; |
|
|
|
|
import java.nio.file.Paths; |
|
|
|
|
import java.time.DayOfWeek; |
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
import java.time.ZoneId; |
|
|
|
@ -339,12 +324,11 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
|
|
|
|
|
throw new HzServiceException(ResultCode.FAILURE, "无卫生考核数据"); |
|
|
|
|
} |
|
|
|
|
// 数据处理
|
|
|
|
|
HygieneEvaluationExportDTO exportDTO = new HygieneEvaluationExportDTO(); |
|
|
|
|
exportDTO.setRemark(page.getRemark()); |
|
|
|
|
HygieneEvaluationExportVO exportVO = new HygieneEvaluationExportVO(); |
|
|
|
|
// 年份、月份
|
|
|
|
|
String[] time = month.split("-"); |
|
|
|
|
exportDTO.setYear(time[0]); |
|
|
|
|
exportDTO.setMonth(time[1]); |
|
|
|
|
exportVO.setYear(time[0]); |
|
|
|
|
exportVO.setMonth(time[1]); |
|
|
|
|
// 周数据
|
|
|
|
|
List<HygieneWeekVO> weekList = page.getWeekList(); |
|
|
|
|
weekList.forEach(week -> { |
|
|
|
@ -354,52 +338,70 @@ public class HygieneRecordServiceImpl extends ServiceImpl<HygieneRecordMapper, H
|
|
|
|
|
end = end.substring(end.indexOf("-") + 1); |
|
|
|
|
switch (week.getWeekNum()) { |
|
|
|
|
case 1: |
|
|
|
|
exportDTO.setFirstWeekStart(start); |
|
|
|
|
exportDTO.setFirstWeekEnd(end); |
|
|
|
|
exportVO.setFirstWeekStart(start); |
|
|
|
|
exportVO.setFirstWeekEnd(end); |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
exportDTO.setSecondWeekStart(start); |
|
|
|
|
exportDTO.setSecondWeekEnd(end); |
|
|
|
|
exportVO.setSecondWeekStart(start); |
|
|
|
|
exportVO.setSecondWeekEnd(end); |
|
|
|
|
break; |
|
|
|
|
case 3: |
|
|
|
|
exportDTO.setThirdWeekStart(start); |
|
|
|
|
exportDTO.setThirdWeekEnd(end); |
|
|
|
|
exportVO.setThirdWeekStart(start); |
|
|
|
|
exportVO.setThirdWeekEnd(end); |
|
|
|
|
break; |
|
|
|
|
case 4: |
|
|
|
|
exportDTO.setFourthWeekStart(start); |
|
|
|
|
exportDTO.setFourthWeekEnd(end); |
|
|
|
|
exportVO.setFourthWeekStart(start); |
|
|
|
|
exportVO.setFourthWeekEnd(end); |
|
|
|
|
break; |
|
|
|
|
case 5: |
|
|
|
|
exportDTO.setFifthWeekStart(start); |
|
|
|
|
exportDTO.setFifthWeekEnd(end); |
|
|
|
|
exportVO.setFifthWeekStart(start); |
|
|
|
|
exportVO.setFifthWeekEnd(end); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
// 考核人员数据
|
|
|
|
|
exportDTO.setEvaluationList(page.getEvaluationList()); |
|
|
|
|
// 封装参数
|
|
|
|
|
Map<String, Object> params = BaseUtil.obj2Map(exportDTO); |
|
|
|
|
TemplateExportParams templateParams = new TemplateExportParams("template/卫生考核表.xlsx", true); |
|
|
|
|
// 导出
|
|
|
|
|
try { |
|
|
|
|
String fileName = URLEncoder.encode("卫生考核表.xlsx", "UTF-8"); |
|
|
|
|
response.setHeader("Content-Disposition", "attachment; filename=" + fileName); |
|
|
|
|
response.setContentType("application/vnd.ms-excel;charset=utf-8"); |
|
|
|
|
Workbook workbook = ExcelExportUtil.exportExcel(templateParams, params); |
|
|
|
|
Sheet sheet = workbook.getSheetAt(0); |
|
|
|
|
BaseUtil.mergeCell(0, 0, JSONArray.parseArray(JSON.toJSONString(exportDTO)), "unit").forEach(sheet::addMergedRegion); |
|
|
|
|
BaseUtil.mergeCell(0, 7, JSONArray.parseArray(JSON.toJSONString(exportDTO)), "remark").forEach(sheet::addMergedRegion); |
|
|
|
|
String pdfPath = "D://" + "/卫生考核表" + SafeProductConstant.PDF_SUFFIX; |
|
|
|
|
OutputStream outputStream = Files.newOutputStream(Paths.get(pdfPath)); |
|
|
|
|
ExcelConvertPdf.excelConvertPdf(workbook, outputStream); |
|
|
|
|
BaseUtil.readPdf(response, pdfPath); |
|
|
|
|
} catch (UnsupportedEncodingException e) { |
|
|
|
|
log.error("卫生考核表导出异常-UnsupportedEncodingException:" + e.getMessage()); |
|
|
|
|
} catch (DocumentException e) { |
|
|
|
|
log.error("卫生考核表导出异常-DocumentException:" + e.getMessage()); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
log.error("卫生考核表导出异常-IOException:" + e.getMessage()); |
|
|
|
|
List<HygieneEvaluationPeopleExportVO> evaluationExportList = new ArrayList<>(); |
|
|
|
|
List<HygieneEvaluationPeopleVO> evaluationList = page.getEvaluationList(); |
|
|
|
|
evaluationList.forEach(x -> { |
|
|
|
|
HygieneEvaluationPeopleExportVO peopleExportVO = new HygieneEvaluationPeopleExportVO(); |
|
|
|
|
peopleExportVO.setUnit(x.getUnit()); |
|
|
|
|
peopleExportVO.setPrincipal(x.getPrincipal()); |
|
|
|
|
peopleExportVO.setSumScore(x.getSumScore()); |
|
|
|
|
peopleExportVO.setRemark(page.getRemark()); |
|
|
|
|
List<HygieneEvaluationScoreVO> scoreList = x.getScoreList(); |
|
|
|
|
scoreList.forEach(score -> { |
|
|
|
|
Long weekScore = score.getScore(); |
|
|
|
|
switch (score.getWeekNum()) { |
|
|
|
|
case 1: |
|
|
|
|
peopleExportVO.setFirstWeekScore(weekScore); |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
peopleExportVO.setSecondWeekScore(weekScore); |
|
|
|
|
break; |
|
|
|
|
case 3: |
|
|
|
|
peopleExportVO.setThirdWeekScore(weekScore); |
|
|
|
|
break; |
|
|
|
|
case 4: |
|
|
|
|
peopleExportVO.setFourthWeekScore(weekScore); |
|
|
|
|
break; |
|
|
|
|
case 5: |
|
|
|
|
peopleExportVO.setFifthWeekScore(weekScore); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
evaluationExportList.add(peopleExportVO); |
|
|
|
|
}); |
|
|
|
|
exportVO.setEvaluationList(evaluationExportList); |
|
|
|
|
Map<String, Object> params = BaseUtil.obj2Map(exportVO); |
|
|
|
|
String templateFile; |
|
|
|
|
if (weekList.size() == 4) { |
|
|
|
|
templateFile = "template/卫生考核表(四周)" + SafeProductConstant.DOCX_SUFFIX; |
|
|
|
|
} else { |
|
|
|
|
templateFile = "template/卫生考核表(五周)" + SafeProductConstant.DOCX_SUFFIX; |
|
|
|
|
} |
|
|
|
|
String wordPath = "D:/" + "/卫生考核表" + SafeProductConstant.DOCX_SUFFIX; |
|
|
|
|
String pdfPath = "D:/" + "/卫生考核表" + SafeProductConstant.PDF_SUFFIX; |
|
|
|
|
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, "",response); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|