216 lines
12 KiB
Java
Raw Normal View History

2024-05-16 02:20:09 +08:00
package com.zhgd.xmgl.task;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
2024-05-23 23:27:51 +08:00
import cn.hutool.core.util.StrUtil;
2024-05-25 22:05:38 +08:00
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
2024-05-16 02:20:09 +08:00
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
2024-05-26 11:41:19 +08:00
import com.zhgd.xmgl.async.AsyncHikvision;
2024-05-25 22:05:38 +08:00
import com.zhgd.xmgl.modules.car.entity.CarInfo;
import com.zhgd.xmgl.modules.car.service.ICarInfoService;
2024-05-16 02:20:09 +08:00
import com.zhgd.xmgl.modules.exam.entity.*;
import com.zhgd.xmgl.modules.exam.service.*;
import com.zhgd.xmgl.modules.project.entity.Project;
import com.zhgd.xmgl.modules.project.service.IProjectService;
2024-05-23 22:31:10 +08:00
import com.zhgd.xmgl.modules.worker.entity.WorkerInfo;
import com.zhgd.xmgl.modules.worker.service.IWorkerInfoService;
2024-05-25 22:05:38 +08:00
import com.zhgd.xmgl.modules.xz.entity.XzMaterial;
import com.zhgd.xmgl.modules.xz.service.IXzMaterialService;
2024-05-16 02:20:09 +08:00
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
2024-05-21 12:33:06 +08:00
import org.springframework.scheduling.annotation.Scheduled;
2024-05-16 02:20:09 +08:00
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Component
public class ExamTask {
@Autowired
private IProjectService projectService;
@Autowired
private IExamPaperService examPaperService;
@Autowired
private IExamRecordService examRecordService;
@Autowired
private IExamCourseTaskService examCourseTaskService;
@Autowired
private IExamCourseService examCourseService;
@Autowired
private IExamCourseRecordService examCourseRecordService;
@Autowired
private IExamNoticeConfigService examConfigService;
2024-05-21 12:33:06 +08:00
@Autowired
private IExamTrainService examTrainService;
@Autowired
private IExamTrainRecordService examTrainRecordService;
2024-05-23 17:55:42 +08:00
@Autowired
private IExamNoticeService examNoticeService;
2024-05-23 22:31:10 +08:00
@Autowired
private IWorkerInfoService workerInfoService;
2024-05-25 22:05:38 +08:00
@Autowired
private IXzMaterialService xzMaterialService;
@Autowired
private ICarInfoService carInfoService;
2024-05-26 11:41:19 +08:00
@Autowired
private AsyncHikvision asyncHikvision;
2024-05-25 22:05:38 +08:00
@Scheduled(cron = "0 0/1 * * * ?")
public void xzMaterial() {
2024-06-19 11:07:08 +08:00
List<XzMaterial> list = xzMaterialService.list(Wrappers.<XzMaterial>lambdaQuery().ne(XzMaterial::getIsDelete, 1));
2024-05-25 22:05:38 +08:00
List<String> carNumber = new ArrayList<>();
2024-06-19 11:07:08 +08:00
List<XzMaterial> update = new ArrayList<>();
2024-05-25 22:05:38 +08:00
for (XzMaterial xzMaterial : list) {
2024-05-26 11:41:19 +08:00
if (xzMaterial.getEntryEndTime() != null && xzMaterial.getEntryEndTime().compareTo(new Date()) < 0) {
2024-05-25 22:05:38 +08:00
if (StringUtils.isNotBlank(xzMaterial.getCarNumber())) {
carNumber.add(xzMaterial.getCarNumber());
2024-06-19 11:07:08 +08:00
xzMaterial.setIsDelete(1);
update.add(xzMaterial);
2024-05-25 22:05:38 +08:00
}
}
}
2024-06-19 11:07:08 +08:00
xzMaterialService.updateBatchById(update);
2024-05-25 23:40:04 +08:00
List<CarInfo> carInfos = carInfoService.list(Wrappers.<CarInfo>lambdaQuery().eq(CarInfo::getCarModuleType, 3));
2024-05-25 22:05:38 +08:00
if (carInfos.size() > 0) {
carInfos = carInfos.stream().filter(c -> carNumber.contains(c.getCarNumber())).collect(Collectors.toList());
if (carInfos.size() > 0) {
carInfoService.removeByIds(carInfos.stream().map(c -> c.getId()).collect(Collectors.toSet()));
2024-05-26 11:41:19 +08:00
for (CarInfo carInfo : carInfos) {
//同步海康
2024-06-18 21:13:52 +08:00
carInfoService.deleteCarInfoForHikvision(carInfo, false);
2024-05-26 11:41:19 +08:00
}
2024-05-25 22:05:38 +08:00
}
}
}
2024-05-23 17:55:42 +08:00
2024-05-21 12:33:06 +08:00
@Scheduled(cron = "0 0/1 * * * ?")
2024-05-16 02:20:09 +08:00
public void examNotice() {
List<Project> list = projectService.list();
List<ExamNotice> noticeList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
2024-05-21 12:33:06 +08:00
ExamNoticeConfig examNoticeConfig = examConfigService.getOne(Wrappers.<ExamNoticeConfig>lambdaQuery()
2024-05-22 21:57:53 +08:00
.eq(ExamNoticeConfig::getProjectSn, list.get(i).getProjectSn())
2024-05-21 12:33:06 +08:00
.eq(ExamNoticeConfig::getEnable, 1));
2024-05-16 02:20:09 +08:00
if (examNoticeConfig != null) {
if (examNoticeConfig.getExamNum() != null && examNoticeConfig.getExamType() != null) {
2024-05-22 21:57:53 +08:00
List<ExamTrain> examTrainList = examTrainService.list(Wrappers.<ExamTrain>lambdaQuery().eq(ExamTrain::getProjectSn, list.get(i).getProjectSn()));
2024-05-21 12:33:06 +08:00
for (int j = 0; j < examTrainList.size(); j++) {
2024-05-24 17:59:19 +08:00
if (DateUtil.compare(examTrainList.get(j).getTrainBeginTime(), getTime(examNoticeConfig.getExamType(), examNoticeConfig.getExamNum())) <= 0) {
2024-05-21 12:33:06 +08:00
List<ExamTrainRecord> examTrainRecordList = examTrainRecordService.list(Wrappers.<ExamTrainRecord>lambdaQuery().eq(ExamTrainRecord::getTrainId, examTrainList.get(j).getId()));
for (int i1 = 0; i1 < examTrainRecordList.size(); i1++) {
if (examTrainRecordList.get(i1).getScore() == null) {
2024-05-23 22:31:10 +08:00
ExamNotice exist = examNoticeService.getOne(Wrappers.<ExamNotice>lambdaQuery().eq(ExamNotice::getWorkerId, examTrainRecordList.get(i1).getWorkerId())
.eq(ExamNotice::getRecordId, examTrainRecordList.get(i1).getId())
2024-05-23 23:27:51 +08:00
.eq(ExamNotice::getType, 1));
2024-05-23 22:31:10 +08:00
if (exist == null) {
WorkerInfo workerInfo = workerInfoService.getById(examTrainRecordList.get(i1).getWorkerId());
ExamNotice examNotice = new ExamNotice();
examNotice.setWorkerId(examTrainRecordList.get(i1).getWorkerId().toString());
examNotice.setWorkerName(examTrainRecordList.get(i1).getWorkerName());
examNotice.setType(1);
2024-05-23 23:27:51 +08:00
examNotice.setContent(StrUtil.format("参加《{}》安全教育培训", examTrainList.get(j).getName()));
2024-05-23 22:31:10 +08:00
examNotice.setProjectSn(list.get(i).getProjectSn());
examNotice.setEnterpriseId(workerInfo.getEnterpriseId());
2024-05-23 22:34:39 +08:00
examNotice.setRecordId(examTrainRecordList.get(i1).getId());
2024-05-23 22:31:10 +08:00
noticeList.add(examNotice);
}
2024-05-19 20:39:44 +08:00
}
2024-05-16 02:20:09 +08:00
}
2024-05-23 17:55:42 +08:00
List<ExamCourseRecord> examCourseRecords = examCourseRecordService.list(Wrappers.<ExamCourseRecord>lambdaQuery()
.eq(ExamCourseRecord::getTrainId, examTrainList.get(j).getId()));
for (int i2 = 0; i2 < examCourseRecords.size(); i2++) {
if (examCourseRecords.get(i2).getNumber() == null || examCourseRecords.get(i2).getNumber() == 0) {
2024-05-23 22:31:10 +08:00
ExamNotice exist = examNoticeService.getOne(Wrappers.<ExamNotice>lambdaQuery().eq(ExamNotice::getWorkerId, examCourseRecords.get(i2).getWorkerId())
.eq(ExamNotice::getRecordId, examCourseRecords.get(i2).getId())
2024-05-23 23:27:51 +08:00
.eq(ExamNotice::getType, 2));
2024-05-23 22:31:10 +08:00
if (exist == null) {
WorkerInfo workerInfo = workerInfoService.getById(examCourseRecords.get(i2).getWorkerId());
ExamNotice examNotice = new ExamNotice();
examNotice.setWorkerId(examCourseRecords.get(i2).getWorkerId().toString());
examNotice.setWorkerName(examCourseRecords.get(i2).getWorkerName());
2024-05-23 23:27:51 +08:00
examNotice.setType(2);
examNotice.setContent(StrUtil.format("参加《{}》安全教育课程学习", examTrainList.get(j).getName()));
2024-05-23 22:31:10 +08:00
examNotice.setProjectSn(list.get(i).getProjectSn());
examNotice.setEnterpriseId(workerInfo.getEnterpriseId());
examNotice.setRecordId(examCourseRecords.get(i2).getId());
noticeList.add(examNotice);
}
2024-05-22 21:57:53 +08:00
}
}
}
}
2024-05-16 02:20:09 +08:00
}
2024-05-21 12:33:06 +08:00
// if (examNoticeConfig.getExamNum() != null && examNoticeConfig.getExamType() != null) {
// List<ExamPaper> examPapers = examPaperService.list(Wrappers.<ExamPaper>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<ExamRecord> examRecords = examRecordService.list(Wrappers.<ExamRecord>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<ExamCourse> examCourseList = examCourseService.list(Wrappers.<ExamCourse>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<ExamCourseRecord> examCourseRecords = examCourseRecordService.list(Wrappers.<ExamCourseRecord>lambdaQuery().eq(ExamCourseRecord::getCourseId, examCourseList.get(j)));
//// List<ExamCourseTask> examCourseTasks = examCourseTaskService.list(Wrappers.<ExamCourseTask>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);
// }
// }
// }
// }
// }
2024-05-16 02:20:09 +08:00
}
}
2024-05-23 17:55:42 +08:00
examNoticeService.saveBatch(noticeList);
2024-05-16 02:20:09 +08:00
}
private DateTime getTime(int type, int num){
DateTime dateTime = null;
if (type == 1) {
2024-05-23 17:55:42 +08:00
dateTime = DateUtil.offsetHour(new Date(), num);
2024-05-21 12:33:06 +08:00
} else if (type == 2) {
2024-05-23 17:55:42 +08:00
dateTime = DateUtil.offsetDay(new Date(), num);
2024-05-16 02:20:09 +08:00
}
return dateTime;
}
}