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