|
@@ -1,6 +1,7 @@
|
|
|
package com.rongwei.sfcommon.sys.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.rongwe.scentity.domian.ApsHazardInvestigationTemplateDo;
|
|
|
import com.rongwe.scentity.domian.ApsHazardInvestigationTemplateZibiaoDo;
|
|
|
import com.rongwe.scentity.domian.CheckTemplateDo;
|
|
@@ -14,8 +15,8 @@ import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
import com.rongwei.rwcommon.utils.StringUtils;
|
|
|
import com.rongwei.safecommon.utils.ExportExcelByEasyExcel;
|
|
|
import com.rongwei.safecommon.utils.JSCommonUtils;
|
|
|
+import com.rongwei.safecommon.utils.SaveConstans;
|
|
|
import com.rongwei.sfcommon.sys.dao.SaveCheckCommonDao;
|
|
|
-import com.rongwei.sfcommon.sys.service.ThemeCheckWorkparkService;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -24,20 +25,18 @@ import org.springframework.stereotype.Service;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.LocalTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.COMPANY_MAP;
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.DatePattern.DATE_PATTERN_YMD;
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.DictType.*;
|
|
|
-import static com.rongwei.safecommon.utils.SaveConstans.DictType.HIDDEN_DANGER_STATUS;
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.FileSuffix.XLSX;
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.NotifyContent.HIDDEN_DANGER_TASK_CONTENT;
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.NotifyTitle.*;
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.NotifyType.*;
|
|
|
-import static com.rongwei.safecommon.utils.SaveConstans.NotifyType.DANGERTASKS;
|
|
|
import static com.rongwei.safecommon.utils.SaveConstans.RoleCode.*;
|
|
|
-import static com.rongwei.safecommon.utils.SaveConstans.RoleCode.LCZG;
|
|
|
import static com.rongwei.sfcommon.utils.MlConstants.DANGER_SOURCE_POINTCHECK;
|
|
|
|
|
|
/**
|
|
@@ -48,25 +47,21 @@ import static com.rongwei.sfcommon.utils.MlConstants.DANGER_SOURCE_POINTCHECK;
|
|
|
*/
|
|
|
@Service
|
|
|
public class ScheduledTasksServiceImpl implements ScheduledTasksService {
|
|
|
- private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
|
|
|
/**
|
|
|
* 隐患跟踪任务整改提醒内容
|
|
|
*/
|
|
|
public static final String RECTIFICATION_MAIL_CONTENT = "总编号:【%s】\n 发现时间:【%tF】\n 发现人:【%s】\n 发现项:【%s】\n限整改期:【%tF】";
|
|
|
-
|
|
|
/**
|
|
|
* 隐患跟踪任务验证完成提醒内容
|
|
|
*/
|
|
|
public static final String VERIFICATION_REMIND_MAIL_CONTENT = "【%s】 已整改完成,请您验证关闭";
|
|
|
-
|
|
|
public static final String VERIFICATION_REMIND_TEMP = "总编号:【%s】 【%s】\n";
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 隐患跟踪任务验证完成提醒内容
|
|
|
*/
|
|
|
public static final String AFFIRM_REMIND_MAIL_CONTENT = "【%s】 已验证完成,请您确认关闭";
|
|
|
|
|
|
+ private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
|
|
|
@Autowired
|
|
|
private ApsHazardInvestigationTemplateServiceImpl apsHazardInvestigationTemplateService;
|
|
|
@Autowired
|
|
@@ -79,6 +74,18 @@ public class ScheduledTasksServiceImpl implements ScheduledTasksService {
|
|
|
private CheckTemplateServiceImpl checkTemplateService;
|
|
|
@Autowired
|
|
|
private ApsHazardInvestigationTemplateZibiaoServiceImpl apsHazardInvestigationTemplateZibiaoService;
|
|
|
+ @Autowired
|
|
|
+ private HazardInvestigationServiceImpl hazardInvestigationService;
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ int currentMonth = calendar.get(Calendar.MONTH) + 1; // 月份是从0开始的,所以加1
|
|
|
+ int currentDay = calendar.get(Calendar.DAY_OF_MONTH); // 当前日
|
|
|
+
|
|
|
+ System.out.println("当前月份: " + currentMonth);
|
|
|
+ System.out.println("当前日: " + currentDay);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public void rectificationSystem() {
|
|
@@ -195,6 +202,7 @@ public class ScheduledTasksServiceImpl implements ScheduledTasksService {
|
|
|
|
|
|
/**
|
|
|
* 生成隐患排查任务
|
|
|
+ *
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
@@ -204,9 +212,9 @@ public class ScheduledTasksServiceImpl implements ScheduledTasksService {
|
|
|
new LambdaQueryWrapper<ApsHazardInvestigationTemplateDo>()
|
|
|
.eq(BaseDo::getDeleted, "0")
|
|
|
.eq(ApsHazardInvestigationTemplateDo::getTaskgenerator, "1")
|
|
|
- .eq(ApsHazardInvestigationTemplateDo::getTempstate,"10")
|
|
|
+ .eq(ApsHazardInvestigationTemplateDo::getTempstate, "10")
|
|
|
);
|
|
|
- if(tempList.isEmpty()){
|
|
|
+ if (tempList.isEmpty()) {
|
|
|
log.debug("暂无开启的定时任务模板");
|
|
|
return R.ok();
|
|
|
}
|
|
@@ -217,24 +225,88 @@ public class ScheduledTasksServiceImpl implements ScheduledTasksService {
|
|
|
.in(ApsHazardInvestigationTemplateZibiaoDo::getMubanid, tempIds)
|
|
|
.eq(BaseDo::getDeleted, "0"));
|
|
|
List<ApsHazardInvestigationTemplateZibiaoDo> subList;
|
|
|
+ Calendar instance = Calendar.getInstance();
|
|
|
for (ApsHazardInvestigationTemplateDo mainData : tempList) {
|
|
|
- String tempId =mainData.getId();
|
|
|
- subList = templateZibiaoDos.stream().filter(subData -> tempId.equals(subData.getMubanid())).collect(Collectors.toList());
|
|
|
- if(subList.isEmpty()){
|
|
|
+ String tempId = mainData.getId();
|
|
|
+ // 获取本次需要生成任务的模板检查项
|
|
|
+ subList = templateZibiaoDos.stream()
|
|
|
+ .filter(subData -> tempId.equals(subData.getMubanid()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (subList.isEmpty()) {
|
|
|
continue;
|
|
|
}
|
|
|
- for (ApsHazardInvestigationTemplateZibiaoDo apsHazardInvestigationTemplateZibiaoDo : subList) {
|
|
|
-
|
|
|
+ Date date = preGenerationCheck(mainData, instance);
|
|
|
+ if (date == null) {
|
|
|
+ continue;
|
|
|
}
|
|
|
-
|
|
|
+ apsHazardInvestigationTemplateService.update(new LambdaUpdateWrapper<ApsHazardInvestigationTemplateDo>()
|
|
|
+ .eq(ApsHazardInvestigationTemplateDo::getId,mainData.getId())
|
|
|
+ .set(ApsHazardInvestigationTemplateDo::getGenerationdate,date));
|
|
|
+ hazardInvestigationService.assembleTask(mainData,subList);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
return R.ok();
|
|
|
}
|
|
|
|
|
|
+ public Date preGenerationCheck(ApsHazardInvestigationTemplateDo hazardInvestigationTemplateDo,
|
|
|
+ Calendar calendar) {
|
|
|
+ int currentMonth = calendar.get(Calendar.MONTH) + 1; // 月份是从0开始的,所以加1
|
|
|
+ int currentDay = calendar.get(Calendar.DAY_OF_MONTH); // 当前日
|
|
|
+ int currentHour = calendar.get(Calendar.HOUR_OF_DAY); // 当前时间
|
|
|
+ // 周期单位
|
|
|
+ String inspectioncycleunit = hazardInvestigationTemplateDo.getInspectioncycleunit();
|
|
|
+ // 巡检周期
|
|
|
+ int inspectioncycle = hazardInvestigationTemplateDo.getInspectioncycle();
|
|
|
+ // 上一次生产该任务的周期
|
|
|
+ Date generationdate = hazardInvestigationTemplateDo.getGenerationdate();
|
|
|
+ Date returnDate = calendar.getTime();
|
|
|
+ int i = 0;
|
|
|
+ if (generationdate != null) {
|
|
|
+ // 当前时间距离上次生成时间的差值
|
|
|
+ i = JSCommonUtils.DateDifferenceExample(generationdate, calendar.getTime(), inspectioncycleunit);
|
|
|
+ }
|
|
|
+ if (SaveConstans.INSPECTION_CYCLE_UNIT.HOUR.equals(inspectioncycleunit)) {
|
|
|
+ LocalTime startTime = LocalTime.parse(hazardInvestigationTemplateDo.getStartingtimeofwork());
|
|
|
+ LocalTime endTime = LocalTime.parse(hazardInvestigationTemplateDo.getEndtimeofwork());
|
|
|
+ LocalTime currentTime = LocalTime.now();
|
|
|
+ if(!currentTime.isBefore(startTime) && !currentTime.isAfter(endTime)){
|
|
|
+ if(generationdate==null || i == inspectioncycle){
|
|
|
+ return returnDate;
|
|
|
+ }else{
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else if (SaveConstans.INSPECTION_CYCLE_UNIT.DAY.equals(inspectioncycleunit)) {
|
|
|
+ if (generationdate == null) {
|
|
|
+ return returnDate;
|
|
|
+ } else if (i == inspectioncycle) {
|
|
|
+ return returnDate;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else if (SaveConstans.INSPECTION_CYCLE_UNIT.MONTH.equals(inspectioncycleunit)) {
|
|
|
+ if (generationdate == null) {
|
|
|
+ return returnDate;
|
|
|
+ } else if (i == inspectioncycle && currentHour == 1) {
|
|
|
+ return returnDate;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else if (SaveConstans.INSPECTION_CYCLE_UNIT.YEAR.equals(inspectioncycleunit)) {
|
|
|
+ if (generationdate == null) {
|
|
|
+ return returnDate;
|
|
|
+ } else if (i == inspectioncycle && currentMonth == 1 && currentDay == 1 && currentHour == 1) {
|
|
|
+ return returnDate;
|
|
|
+ } else {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("未知的周期单位:{}", inspectioncycleunit);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发送消息提醒
|
|
|
*/
|