| | |
| | | package com.ots.project.monitor.job.task; |
| | | |
| | | import com.ots.common.enums.LangTypeEnum; |
| | | import com.ots.common.enums.ReportTypeEnum; |
| | | import com.ots.common.enums.SenderCode; |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 邮件短信发送任务 |
| | | */ |
| | | @Component("SenderEmailReportTask") |
| | | @Slf4j |
| | | public class SenderEmailReportTask { |
| | | |
| | | private static final String SMS_ZJCM = "SMS_ZJCM"; |
| | | private static final String SMS_ZJCM_INTERNATIONAL = "SMS_ZJCM_INTERNATIONAL"; |
| | | private static final String EMAIL_126 = "EMAIL_126"; |
| | |
| | | private TReportTemplateMapper tReportTemplateMapper; |
| | | @Autowired |
| | | private ITReportTemplateService itReportTemplateService; |
| | | |
| | | public void senderTask() { |
| | | |
| | | // 查找report表得出要发送报告的用户 |
| | | TExamReport tExamReportTemp = new TExamReport(); |
| | | tExamReportTemp.setFinish(1); |
| | | tExamReportTemp.setSendTesterStatus(0); |
| | |
| | | if (ExamUtil.isListEmpty(tExamReportList)) { |
| | | return; |
| | | } |
| | | |
| | | |
| | | // textMapList的 |
| | | List<Map<String, Object>> textMapList = new ArrayList<>(); |
| | | List<String> deleteFileStrList = new ArrayList<>(); |
| | | |
| | | // 语言类型 |
| | | Map<String, LangTypeEnum> langTypeEnumMap = getLangTypeEnumMap(); |
| | | |
| | | // 报告类型 |
| | | Map<String, ReportTypeEnum> reportTypeEnumMap = getStringReportTypeEnumMap(); |
| | | |
| | | // 查出全部的报告,减少消耗的性能 |
| | | Map<Long, TReportTemplate> tReportTemplateMap = getAllTReportTemplateMap(); |
| | | |
| | | |
| | | |
| | | // 遍历每个report表 |
| | | // 给测试者发送邮件 |
| | | List<String> allReportList = new ArrayList<>(); |
| | | |
| | | |
| | | // hr 邮箱 |
| | | Map<String, List<String>> hrEmail = new HashMap<>(); |
| | | |
| | | |
| | | // 循环每个个报告记录 |
| | | for (TExamReport tExamReport : tExamReportList) { |
| | | String[] reportIds = tExamReport.getReportTemplateId().split(","); |
| | | |
| | | |
| | | // 遍历出模版生成文件 |
| | | List<String> reprotList = saveReport(textMapList, deleteFileStrList, langTypeEnumMap, reportTypeEnumMap, tReportTemplateMap, allReportList, tExamReport, reportIds); |
| | | |
| | | |
| | | // 调用发送程序发给用户 |
| | | if (emailMessage.sendEmailwithAttachment(tExamReport.getMemberEmail(), "测试报告", "您已完成测试", reprotList.stream().toArray(String[]::new)).isResult()) { |
| | | tExamReport.setSendTesterStatus(SenderCode.success.getCode()); |
| | | } else { |
| | | } else { // 发送成功,发送失败处理 |
| | | tExamReport.setSendTesterStatus(SenderCode.fail.getCode()); |
| | | } |
| | | |
| | | |
| | | // 发送给Hr |
| | | if (emailMessage.sendEmailwithAttachment(tExamReport.getTestEmail(), "测试报告", "您已完成测试", reprotList.stream().toArray(String[]::new)).isResult()) { |
| | | tExamReport.setSendHrStatus(SenderCode.success.getCode()); |
| | | } else { |
| | | } else { // 发送成功,发送失败处理 |
| | | tExamReport.setSendHrStatus(SenderCode.fail.getCode()); |
| | | } |
| | | |
| | | tExamReportService.updateTExamReportStatus(tExamReport); |
| | | } |
| | | } |
| | | |
| | | private void setHrFiles(Map<String, List<String>> hrEmail, TExamReport tExamReport, List<String> reprotList) { |
| | | |
| | | // 保留发给Hr的邮箱 |
| | | List<String> hrEmailList = hrEmail.get(tExamReport.getTestEmail()); |
| | | if (ExamUtil.isListEmpty(hrEmailList)) { |
| | | List<String> hrFileList = new ArrayList<>(); |
| | |
| | | hrEmailList.addAll(reprotList); |
| | | } |
| | | } |
| | | |
| | | private List<String> saveReport(List<Map<String, Object>> textMapList, List<String> deleteFileStrList, Map<String, LangTypeEnum> langTypeEnumMap, Map<String, ReportTypeEnum> reportTypeEnumMap, Map<Long, TReportTemplate> tReportTemplateMap, List<String> allReportList, TExamReport tExamReport, String[] reportIds) { |
| | | List<String> sendReportList = new ArrayList<>(); |
| | | for (String reportId : reportIds) { |
| | | |
| | | // 模拟调用接口 |
| | | Map<String, String> thaiCalculationMap = new HashMap<>(); |
| | | MAQReport report = new MAQReport(); |
| | | WordUtil util = new WordUtil(); |
| | | |
| | | String reportType = tReportTemplateMap.get(Long.valueOf(reportId)).getReportType(); |
| | | String templateType = tReportTemplateMap.get(Long.valueOf(reportId)).getTemplateType(); |
| | | // 导出基础版本还是详细版 |
| | | String reportType = tReportTemplateMap.get(Long.valueOf(reportId)).getReportType();// "Brief"; |
| | | String templateType = tReportTemplateMap.get(Long.valueOf(reportId)).getTemplateType();// "Brief"; |
| | | String path = ""; |
| | | Map<String, Object> textMap = new HashMap<>(); |
| | | TReportTemplate tReportTemplate = tReportTemplateMap.get(Long.valueOf(reportId)); |
| | |
| | | e.printStackTrace(); |
| | | continue; |
| | | } |
| | | |
| | | |
| | | // 生成报告文件 |
| | | String zipFileName = util.makeReportFile(path, tReportTemplate, textMap, new HashMap<>(), deleteFileStrList); |
| | | allReportList.add(zipFileName); |
| | | for (String fileName : allReportList) { |
| | | sendReportList.add(EssConfig.getProfile() + "/" + fileName); |
| | | } |
| | | |
| | | // 清空,给下一个用户用 |
| | | textMapList.clear(); |
| | | textMap.clear(); |
| | | |
| | | // 删除临时文件 |
| | | util.deleteFileByStr(deleteFileStrList); |
| | | } |
| | | |
| | | return sendReportList; |
| | | } |
| | | |
| | | private Map<Long, TReportTemplate> getAllTReportTemplateMap() { |
| | | List<TReportTemplate> tReportTemplateList = tReportTemplateMapper.selectTReportTemplateList(new TReportTemplate()); |
| | | Map<Long, TReportTemplate> tReportTemplateMap = new HashMap<>(); |
| | |
| | | } |
| | | return tReportTemplateMap; |
| | | } |
| | | |
| | | private Map<String, ReportTypeEnum> getStringReportTypeEnumMap() { |
| | | Map<String, ReportTypeEnum> reportTypeEnumMap = new HashMap<>(); |
| | | for (ReportTypeEnum reportTypeEnumTemp : ReportTypeEnum.values()) { |
| | |
| | | } |
| | | return reportTypeEnumMap; |
| | | } |
| | | |
| | | private Map<String, LangTypeEnum> getLangTypeEnumMap() { |
| | | Map<String, LangTypeEnum> langTypeEnumMap = new HashMap<>(); |
| | | for (LangTypeEnum langTypeEnumTemp : LangTypeEnum.values()) { |