diff --git a/src/main/java/com/zhgd/xmgl/modules/exam/service/impl/ExamTrainServiceImpl.java b/src/main/java/com/zhgd/xmgl/modules/exam/service/impl/ExamTrainServiceImpl.java index 95a7702dd..b06c6bc03 100644 --- a/src/main/java/com/zhgd/xmgl/modules/exam/service/impl/ExamTrainServiceImpl.java +++ b/src/main/java/com/zhgd/xmgl/modules/exam/service/impl/ExamTrainServiceImpl.java @@ -1,26 +1,22 @@ package com.zhgd.xmgl.modules.exam.service.impl; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.zhgd.xmgl.modules.basicdata.entity.SystemUser; import com.zhgd.xmgl.modules.basicdata.service.ISystemUserService; -import com.zhgd.xmgl.modules.exam.entity.ExamCourseRecord; -import com.zhgd.xmgl.modules.exam.entity.ExamPaper; -import com.zhgd.xmgl.modules.exam.entity.ExamTrain; -import com.zhgd.xmgl.modules.exam.entity.ExamTrainRecord; +import com.zhgd.xmgl.modules.exam.entity.*; import com.zhgd.xmgl.modules.exam.mapper.ExamTrainMapper; -import com.zhgd.xmgl.modules.exam.service.IExamCourseRecordService; -import com.zhgd.xmgl.modules.exam.service.IExamPaperService; -import com.zhgd.xmgl.modules.exam.service.IExamTrainRecordService; -import com.zhgd.xmgl.modules.exam.service.IExamTrainService; +import com.zhgd.xmgl.modules.exam.service.*; import com.zhgd.xmgl.modules.exam.vo.ExamTrainRecordVo; import com.zhgd.xmgl.modules.worker.entity.WorkerInfo; import com.zhgd.xmgl.modules.worker.service.IWorkerInfoService; import com.zhgd.xmgl.security.entity.UserInfo; import com.zhgd.xmgl.security.util.SecurityUtils; import com.zhgd.xmgl.util.DateUtils; +import com.zhgd.xmgl.util.EmailUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -28,6 +24,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import java.math.BigDecimal; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -49,11 +46,14 @@ public class ExamTrainServiceImpl extends ServiceImpl recordList = examTrain.getExamTrainRecordList(); if (examTrain.getExamPaperId() != null) { ExamPaper examPaper = examPaperService.getById(examTrain.getExamPaperId()); @@ -122,6 +123,13 @@ public class ExamTrainServiceImpl extends ServiceImpl workerIds = examTrain.getExamTrainRecordList().stream().map(e -> e.getWorkerId()).collect(Collectors.toList()); + String emails = workerInfoService.listByIds(workerIds).stream().map(w -> w.getPersonMail()).collect(Collectors.joining(",")); + emailUtils.sendHtmlMail(emails, "安全教育培训提醒", StrUtil.format("【尾矿固废资源综合利用项目】智慧工地管理系统提醒:您有一条培训通知请查收!\n" + + "【{}】在【{}}】下发了一个培训计划名称为【{}}】、科目名称为【{}】、教育主题为【{}】的培训计划," + + "需要您使用姓名、身份证号登录手机APP端进行课程学习及考试测评,培训有效期限为【{}】,未避免超期未参与培训导致您的安全积分被扣除," + + "请在规定有效期限内参加培训!", user.getRealName(), new Date(), examTrain.getName(), examSubject.getName(), + examTrain.getTitle(), examTrain.getTrainBeginTime() + " - " + examTrain.getTrainEndTime())); } return flag; } diff --git a/src/main/java/com/zhgd/xmgl/modules/xz/controller/XzRiskPredictionController.java b/src/main/java/com/zhgd/xmgl/modules/xz/controller/XzRiskPredictionController.java index 7088c8dbc..dd55cae0c 100644 --- a/src/main/java/com/zhgd/xmgl/modules/xz/controller/XzRiskPredictionController.java +++ b/src/main/java/com/zhgd/xmgl/modules/xz/controller/XzRiskPredictionController.java @@ -174,7 +174,7 @@ public class XzRiskPredictionController { int pass = trainRecordList.stream().filter(t -> t.getIsPass() == 1).collect(Collectors.toList()).size(); record.setPassRadio(new BigDecimal(pass).divide(new BigDecimal(trainRecordList.size()), 2, BigDecimal.ROUND_HALF_UP)); } else { - record.setPassRadio(new BigDecimal(1)); + record.setPassRadio(new BigDecimal(0)); } } } @@ -678,7 +678,7 @@ public class XzRiskPredictionController { int pass = trainRecordList.stream().filter(t -> t.getIsPass() == 1).collect(Collectors.toList()).size(); record.setPassRadio(new BigDecimal(pass).divide(new BigDecimal(trainRecordList.size()), 2, BigDecimal.ROUND_HALF_UP)); } else { - record.setPassRadio(new BigDecimal(1)); + record.setPassRadio(new BigDecimal(0)); } } } @@ -795,11 +795,14 @@ public class XzRiskPredictionController { Map resultMap = new HashMap<>(); // 安全检查隐患 List xzSecurityQualityInspectionRecords = allXzSecurityQualityInspectionRecords.stream().filter(x -> enterpriseIds.contains(x.getEnterpriseId())).collect(Collectors.toList()); + if (xzSecurityQualityInspectionRecords.size() > 0) { + resultMap.put("total", new BigDecimal(xzSecurityQualityInspectionRecords.size()).divide(new BigDecimal(allXzSecurityQualityInspectionRecords.size()), 2, BigDecimal.ROUND_HALF_UP)); long inspectionCount = xzSecurityQualityInspectionRecords.stream().filter(x -> x.getStatus() != 5).count(); resultMap.put("security", new BigDecimal(inspectionCount).divide(new BigDecimal(xzSecurityQualityInspectionRecords.size()), 2, BigDecimal.ROUND_HALF_UP)); } else { resultMap.put("security", 0); + resultMap.put("total", 0); } // 安全评分 List list = allWorkerList.stream().filter(a -> enterpriseIds.contains(a.getEnterpriseId())).collect(Collectors.toList()); @@ -825,7 +828,7 @@ public class XzRiskPredictionController { BigDecimal limitTime = new BigDecimal(resultMap.get("limitTime").toString()); BigDecimal levelRisk = new BigDecimal(resultMap.get("levelRisk").toString()); BigDecimal safe = new BigDecimal(resultMap.get("safe").toString()); - resultMap.put("area", NumberUtils.percent(PolygonUtil.calRadioArea(1.0, 4, security.doubleValue(), + resultMap.put("area", NumberUtils.percent(PolygonUtil.calRadioArea(1.0, 5, security.doubleValue(), limitTime.doubleValue(), levelRisk.doubleValue(), safe.doubleValue()), 2)); resultList.add(resultMap); } diff --git a/src/main/java/com/zhgd/xmgl/task/ExamTask.java b/src/main/java/com/zhgd/xmgl/task/ExamTask.java index 008fe25bb..aecc84b3d 100644 --- a/src/main/java/com/zhgd/xmgl/task/ExamTask.java +++ b/src/main/java/com/zhgd/xmgl/task/ExamTask.java @@ -6,6 +6,8 @@ import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.zhgd.xmgl.async.AsyncHikvision; +import com.zhgd.xmgl.modules.basicdata.entity.SystemUser; +import com.zhgd.xmgl.modules.basicdata.service.ISystemUserService; import com.zhgd.xmgl.modules.car.entity.CarInfo; import com.zhgd.xmgl.modules.car.service.ICarInfoService; import com.zhgd.xmgl.modules.exam.entity.*; @@ -16,6 +18,7 @@ import com.zhgd.xmgl.modules.worker.entity.WorkerInfo; import com.zhgd.xmgl.modules.worker.service.IWorkerInfoService; import com.zhgd.xmgl.modules.xz.entity.XzMaterial; import com.zhgd.xmgl.modules.xz.service.IXzMaterialService; +import com.zhgd.xmgl.util.EmailUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; @@ -70,7 +73,13 @@ public class ExamTask { private ICarInfoService carInfoService; @Autowired - private AsyncHikvision asyncHikvision; + private EmailUtils emailUtils; + + @Autowired + private IExamSubjectService examSubjectService; + + @Autowired + private ISystemUserService systemUserService; @Scheduled(cron = "0 0/1 * * * ?") public void xzMaterial() { @@ -100,7 +109,7 @@ public class ExamTask { } } - @Scheduled(cron = "0 0/1 * * * ?") + @Scheduled(cron = "0 0 8 * * ?") public void examNotice() { List list = projectService.list(); List noticeList = new ArrayList<>(); @@ -112,6 +121,9 @@ public class ExamTask { if (examNoticeConfig.getExamNum() != null && examNoticeConfig.getExamType() != null) { List examTrainList = examTrainService.list(Wrappers.lambdaQuery().eq(ExamTrain::getProjectSn, list.get(i).getProjectSn())); for (int j = 0; j < examTrainList.size(); j++) { + SystemUser systemUser = systemUserService.getById(examTrainList.get(j).getCreateBy()); + ExamSubject examSubject = examSubjectService.getById(examTrainList.get(j).getSubjectId()); + StringBuilder examTrain = new StringBuilder(); if (DateUtil.compare(examTrainList.get(j).getTrainBeginTime(), getTime(examNoticeConfig.getExamType(), examNoticeConfig.getExamNum())) <= 0) { List examTrainRecordList = examTrainRecordService.list(Wrappers.lambdaQuery().eq(ExamTrainRecord::getTrainId, examTrainList.get(j).getId())); for (int i1 = 0; i1 < examTrainRecordList.size(); i1++) { @@ -130,6 +142,9 @@ public class ExamTask { examNotice.setEnterpriseId(workerInfo.getEnterpriseId()); examNotice.setRecordId(examTrainRecordList.get(i1).getId()); noticeList.add(examNotice); + if (StringUtils.isNotBlank(workerInfo.getPersonMail()) && DateUtil.formatDate(examTrainList.get(j).getTrainBeginTime()).equals(DateUtil.formatDate(getTime(examNoticeConfig.getExamType(), examNoticeConfig.getExamNum())))) { + examTrain.append(workerInfo.getPersonMail() + ","); + } } } } @@ -151,53 +166,22 @@ public class ExamTask { examNotice.setEnterpriseId(workerInfo.getEnterpriseId()); examNotice.setRecordId(examCourseRecords.get(i2).getId()); noticeList.add(examNotice); +// if (StringUtils.isNotBlank(workerInfo.getPersonMail()) && DateUtil.formatDate(examTrainList.get(j).getTrainBeginTime()).equals(DateUtil.formatDate(getTime(examNoticeConfig.getExamType(), examNoticeConfig.getExamNum())))) { +// examTrain.append(workerInfo.getPersonMail() + ","); +// } } } } } + if (StringUtils.isNotBlank(examTrain) || examTrain.length() == 0) { + emailUtils.sendHtmlMail(examTrain.toString(), "安全教育培训提醒", StrUtil.format("【尾矿固废资源综合利用项目】智慧工地管理系统提醒:您有一条培训通知请查收!\n" + + "【{}】在【{}}】下发了一个培训计划名称为【{}}】、科目名称为【{}】、教育主题为【{}】的培训计划," + + "需要您使用姓名、身份证号登录手机APP端进行课程学习及考试测评,培训有效期限为【{}】,未避免超期未参与培训导致您的安全积分被扣除," + + "请在规定有效期限内参加培训!", systemUser.getRealName(), new Date(), examTrainList.get(j).getName(), examSubject.getName(), + examTrainList.get(j).getTitle(), examTrainList.get(j).getTrainBeginTime() + " - " + examTrainList.get(j).getTrainEndTime())); + } } } - -// if (examNoticeConfig.getExamNum() != null && examNoticeConfig.getExamType() != null) { -// List examPapers = examPaperService.list(Wrappers.lambdaQuery().eq(ExamPaper::getProjectSn, list.get(i))); -// for (int j = 0; j < examPapers.size(); j++) { -// if (DateUtil.compare(new Date(), getTime(examNoticeConfig.getExamType(), examNoticeConfig.getExamNum())) < 0) { -// List examRecords = examRecordService.list(Wrappers.lambdaQuery().eq(ExamRecord::getExamId, examPapers.get(j))); -// for (int i1 = 0; i1 < examRecords.size(); i1++) { -// if (examRecords.get(i1).getScore() == null) { -// ExamNotice examNotice = new ExamNotice(); -// examNotice.setWorkerId(examRecords.get(i1).getUserId()); -// examNotice.setWorkerName(examRecords.get(i1).getUserName()); -// examNotice.setType(1); -// examNotice.setContent("参加安全教育课程考试"); -// examNotice.setProjectSn(list.get(i).getProjectSn()); -// noticeList.add(examNotice); -// } -// } -// } -// } -// } -// if (examNoticeConfig.getCourseNum() != null && examNoticeConfig.getCourseType() != null) { -// List examCourseList = examCourseService.list(Wrappers.lambdaQuery().eq(ExamCourse::getProjectSn, list.get(i))); -// for (int j = 0; j < examCourseList.size(); j++) { -// if (DateUtil.compare(new Date(), getTime(examNoticeConfig.getCourseType(), examNoticeConfig.getCourseNum())) < 0) { -// List examCourseRecords = examCourseRecordService.list(Wrappers.lambdaQuery().eq(ExamCourseRecord::getCourseId, examCourseList.get(j))); -//// List examCourseTasks = examCourseTaskService.list(Wrappers.lambdaQuery() -//// .in(ExamCourseTask::getRecordId, examCourseRecords.stream().map(r -> r.getId()).collect(Collectors.toList()))); -// for (int i1 = 0; i1 < examCourseRecords.size(); i1++) { -// if (examCourseRecords.get(i).getNumber() == null || examCourseRecords.get(i).getNumber() == 0) { -// ExamNotice examNotice = new ExamNotice(); -// examNotice.setWorkerId(examCourseRecords.get(i1).getWorkerId().toString()); -// examNotice.setWorkerName(examCourseRecords.get(i1).getWorkerName()); -// examNotice.setType(1); -// examNotice.setContent("参加安全教育课程学习"); -// examNotice.setProjectSn(list.get(i).getProjectSn()); -// noticeList.add(examNotice); -// } -// } -// } -// } -// } } } examNoticeService.saveBatch(noticeList);