|
@@ -0,0 +1,211 @@
|
|
|
+package com.bizmatics.service.job;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.bizmatics.common.core.util.DateUtils;
|
|
|
+import com.bizmatics.model.PatrolInspectionRecord;
|
|
|
+import com.bizmatics.model.PatrolInspectionRoute;
|
|
|
+import com.bizmatics.model.PatrolInspectionScheme;
|
|
|
+import com.bizmatics.model.PatrolRecordRoute;
|
|
|
+import com.bizmatics.model.vo.PatrolRouteContentTimingVo;
|
|
|
+import com.bizmatics.persistence.mapper.PatrolInspectionRecordMapper;
|
|
|
+import com.bizmatics.service.PatrolInspectionRecordService;
|
|
|
+import com.bizmatics.service.PatrolInspectionRouteService;
|
|
|
+import com.bizmatics.service.PatrolInspectionSchemeService;
|
|
|
+import com.bizmatics.service.PatrolRecordRouteService;
|
|
|
+import com.bizmatics.service.es.RtAnalogService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author yq
|
|
|
+ * @date 2021/7/17 19:41
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class PatrolTask {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionSchemeService patrolInspectionSchemeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionRecordService patrolInspectionRecordService;
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionRouteService patrolInspectionRouteService;
|
|
|
+ @Autowired
|
|
|
+ private PatrolInspectionRecordMapper patrolInspectionRecordMapper;
|
|
|
+ @Autowired
|
|
|
+ private PatrolRecordRouteService patrolRecordRouteService;
|
|
|
+
|
|
|
+ //每天凌晨0点执行一次
|
|
|
+// @Scheduled(cron = "30 * * * * ?")
|
|
|
+ @Scheduled(cron = "0 0 0 * * ?")
|
|
|
+ public void PatrolInspectionRecordTiming() {
|
|
|
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ SimpleDateFormat formatterOne = new SimpleDateFormat("dd");
|
|
|
+ SimpleDateFormat formatterTwo = new SimpleDateFormat("MM-dd");
|
|
|
+// SysUser user = SecurityUtils.getLoginUser().getUser();
|
|
|
+ Date date = new Date();
|
|
|
+ String week = DateUtils.getWeek(date);
|
|
|
+ String datef = formatter.format(date);
|
|
|
+ String day = formatterOne.format(date);
|
|
|
+ String monthDay = formatterTwo.format(date);
|
|
|
+ log.info("巡检管理---" + datef + "巡检记录定时任务生成");
|
|
|
+// log.info("addHadJob---startTime"+day);
|
|
|
+ LambdaQueryWrapper<PatrolInspectionScheme> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.lt(PatrolInspectionScheme::getSchemeStartDate, datef)
|
|
|
+ .gt(PatrolInspectionScheme::getSchemeEndDate, datef)
|
|
|
+ .eq(PatrolInspectionScheme::getStatus, 1);
|
|
|
+ List<PatrolInspectionScheme> patrolInspectionSchemeList = patrolInspectionSchemeService.list(queryWrapper);
|
|
|
+ if (patrolInspectionSchemeList.size() > 0) {
|
|
|
+ for (int i = 0; i < patrolInspectionSchemeList.size(); i++) {
|
|
|
+ PatrolInspectionRecord patrolInspectionRecord = new PatrolInspectionRecord();
|
|
|
+ patrolInspectionRecord.setInspectionSchemeId(patrolInspectionSchemeList.get(i).getId());
|
|
|
+ patrolInspectionRecord.setInspectionTeamId(patrolInspectionSchemeList.get(i).getInspectionTeamId());
|
|
|
+ patrolInspectionRecord.setInspectionSchedule(0.00);
|
|
|
+ patrolInspectionRecord.setCreateTime(new Date());
|
|
|
+ patrolInspectionRecord.setStatus(1);
|
|
|
+ if (patrolInspectionSchemeList.get(i).getInspectionCycleType() == 1) {
|
|
|
+ LambdaQueryWrapper<PatrolInspectionRoute> queryWrapperTwo = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperTwo.eq(PatrolInspectionRoute::getStatus, 1).eq(PatrolInspectionRoute::getInspectionSchemeId, patrolInspectionSchemeList.get(i).getId());
|
|
|
+ List<PatrolInspectionRoute> patrolInspectionRouteList = patrolInspectionRouteService.list(queryWrapperTwo);
|
|
|
+
|
|
|
+ for (int j = 0; j < patrolInspectionRouteList.size(); j++) {
|
|
|
+ patrolInspectionRecord.setInspectionNumber(patrolInspectionSchemeList.get(i).getExecutions() + 1);
|
|
|
+ patrolInspectionRecord.setSiteId(patrolInspectionRouteList.get(j).getSiteId());
|
|
|
+ patrolInspectionRecord.setInspectionRouteId(patrolInspectionRouteList.get(j).getId());
|
|
|
+ patrolInspectionRecordService.save(patrolInspectionRecord);
|
|
|
+ Integer inspectionRecordId = patrolInspectionRecord.getId();
|
|
|
+ List<PatrolRouteContentTimingVo> patrolRouteContentTimingVoList = patrolInspectionRecordMapper.patrolRouteContentTimingVoList(patrolInspectionRouteList.get(j).getId());
|
|
|
+ if (patrolRouteContentTimingVoList.size()>0){
|
|
|
+ for (int k=0;k<patrolRouteContentTimingVoList.size();k++){
|
|
|
+ PatrolRecordRoute patrolRecordRoute = new PatrolRecordRoute();
|
|
|
+ patrolRecordRoute.setInspectionRecordId(inspectionRecordId);
|
|
|
+ patrolRecordRoute.setInspectionRouteId(patrolInspectionRouteList.get(j).getId());
|
|
|
+ patrolRecordRoute.setCreateTime(new Date());
|
|
|
+ patrolRecordRoute.setInspectionSchemeId(patrolInspectionSchemeList.get(i).getId());
|
|
|
+ patrolRecordRoute.setStatus(0);
|
|
|
+ patrolRecordRoute.setCheckEntryName(patrolRouteContentTimingVoList.get(k).getCheckEntryName());
|
|
|
+ patrolRecordRoute.setInspectionContentId(patrolRouteContentTimingVoList.get(k).getInspectionContentId());
|
|
|
+ patrolRecordRouteService.save(patrolRecordRoute);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ PatrolInspectionScheme patrolInspectionScheme = new PatrolInspectionScheme();
|
|
|
+ patrolInspectionScheme.setId(patrolInspectionSchemeList.get(i).getId());
|
|
|
+ patrolInspectionScheme.setExecutions(patrolInspectionSchemeList.get(i).getExecutions() + 1);
|
|
|
+ patrolInspectionSchemeService.updateById(patrolInspectionScheme);
|
|
|
+
|
|
|
+ } else if (patrolInspectionSchemeList.get(i).getInspectionCycleType() == 2) {
|
|
|
+ if (week.equals(patrolInspectionSchemeList.get(i).getExecutionTime())) {
|
|
|
+ LambdaQueryWrapper<PatrolInspectionRoute> queryWrapperTwo = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperTwo.eq(PatrolInspectionRoute::getStatus, 1).eq(PatrolInspectionRoute::getInspectionSchemeId, patrolInspectionSchemeList.get(i).getId());
|
|
|
+ List<PatrolInspectionRoute> patrolInspectionRouteList = patrolInspectionRouteService.list(queryWrapperTwo);
|
|
|
+
|
|
|
+ for (int j = 0; j < patrolInspectionRouteList.size(); j++) {
|
|
|
+ patrolInspectionRecord.setInspectionNumber(patrolInspectionSchemeList.get(i).getExecutions() + 1);
|
|
|
+ patrolInspectionRecord.setSiteId(patrolInspectionRouteList.get(j).getSiteId());
|
|
|
+ patrolInspectionRecord.setInspectionRouteId(patrolInspectionRouteList.get(j).getId());
|
|
|
+ patrolInspectionRecordService.save(patrolInspectionRecord);
|
|
|
+ Integer inspectionRecordId = patrolInspectionRecord.getId();
|
|
|
+ List<PatrolRouteContentTimingVo> patrolRouteContentTimingVoList = patrolInspectionRecordMapper.patrolRouteContentTimingVoList(patrolInspectionRouteList.get(j).getId());
|
|
|
+ if (patrolRouteContentTimingVoList.size()>0){
|
|
|
+ for (int k=0;k<patrolRouteContentTimingVoList.size();k++){
|
|
|
+ PatrolRecordRoute patrolRecordRoute = new PatrolRecordRoute();
|
|
|
+ patrolRecordRoute.setInspectionRecordId(inspectionRecordId);
|
|
|
+ patrolRecordRoute.setInspectionRouteId(patrolInspectionRouteList.get(j).getId());
|
|
|
+ patrolRecordRoute.setCreateTime(new Date());
|
|
|
+ patrolRecordRoute.setInspectionSchemeId(patrolInspectionSchemeList.get(i).getId());
|
|
|
+ patrolRecordRoute.setStatus(0);
|
|
|
+ patrolRecordRoute.setCheckEntryName(patrolRouteContentTimingVoList.get(k).getCheckEntryName());
|
|
|
+ patrolRecordRoute.setInspectionContentId(patrolRouteContentTimingVoList.get(k).getInspectionContentId());
|
|
|
+ patrolRecordRouteService.save(patrolRecordRoute);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PatrolInspectionScheme patrolInspectionScheme = new PatrolInspectionScheme();
|
|
|
+ patrolInspectionScheme.setId(patrolInspectionSchemeList.get(i).getId());
|
|
|
+ patrolInspectionScheme.setExecutions(patrolInspectionSchemeList.get(i).getExecutions() + 1);
|
|
|
+ patrolInspectionSchemeService.updateById(patrolInspectionScheme);
|
|
|
+ }
|
|
|
+ } else if (patrolInspectionSchemeList.get(i).getInspectionCycleType() == 3) {
|
|
|
+ if (day.equals(patrolInspectionSchemeList.get(i).getExecutionTime())) {
|
|
|
+ LambdaQueryWrapper<PatrolInspectionRoute> queryWrapperTwo = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperTwo.eq(PatrolInspectionRoute::getStatus, 1).eq(PatrolInspectionRoute::getInspectionSchemeId, patrolInspectionSchemeList.get(i).getId());
|
|
|
+ List<PatrolInspectionRoute> patrolInspectionRouteList = patrolInspectionRouteService.list(queryWrapperTwo);
|
|
|
+
|
|
|
+ for (int j = 0; j < patrolInspectionRouteList.size(); j++) {
|
|
|
+ patrolInspectionRecord.setInspectionNumber(patrolInspectionSchemeList.get(i).getExecutions() + 1);
|
|
|
+ patrolInspectionRecord.setSiteId(patrolInspectionRouteList.get(j).getSiteId());
|
|
|
+ patrolInspectionRecord.setInspectionRouteId(patrolInspectionRouteList.get(j).getId());
|
|
|
+ patrolInspectionRecordService.save(patrolInspectionRecord);
|
|
|
+ Integer inspectionRecordId = patrolInspectionRecord.getId();
|
|
|
+ List<PatrolRouteContentTimingVo> patrolRouteContentTimingVoList = patrolInspectionRecordMapper.patrolRouteContentTimingVoList(patrolInspectionRouteList.get(j).getId());
|
|
|
+ if (patrolRouteContentTimingVoList.size()>0){
|
|
|
+ for (int k=0;k<patrolRouteContentTimingVoList.size();k++){
|
|
|
+ PatrolRecordRoute patrolRecordRoute = new PatrolRecordRoute();
|
|
|
+ patrolRecordRoute.setInspectionRecordId(inspectionRecordId);
|
|
|
+ patrolRecordRoute.setInspectionRouteId(patrolInspectionRouteList.get(j).getId());
|
|
|
+ patrolRecordRoute.setCreateTime(new Date());
|
|
|
+ patrolRecordRoute.setInspectionSchemeId(patrolInspectionSchemeList.get(i).getId());
|
|
|
+ patrolRecordRoute.setStatus(0);
|
|
|
+ patrolRecordRoute.setCheckEntryName(patrolRouteContentTimingVoList.get(k).getCheckEntryName());
|
|
|
+ patrolRecordRoute.setInspectionContentId(patrolRouteContentTimingVoList.get(k).getInspectionContentId());
|
|
|
+ patrolRecordRouteService.save(patrolRecordRoute);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PatrolInspectionScheme patrolInspectionScheme = new PatrolInspectionScheme();
|
|
|
+ patrolInspectionScheme.setId(patrolInspectionSchemeList.get(i).getId());
|
|
|
+ patrolInspectionScheme.setExecutions(patrolInspectionSchemeList.get(i).getExecutions() + 1);
|
|
|
+ patrolInspectionSchemeService.updateById(patrolInspectionScheme);
|
|
|
+ }
|
|
|
+ } else if (patrolInspectionSchemeList.get(i).getInspectionCycleType() == 4) {
|
|
|
+ if (monthDay.equals(patrolInspectionSchemeList.get(i).getExecutionTime())) {
|
|
|
+ LambdaQueryWrapper<PatrolInspectionRoute> queryWrapperTwo = Wrappers.lambdaQuery();
|
|
|
+ queryWrapperTwo.eq(PatrolInspectionRoute::getStatus, 1).eq(PatrolInspectionRoute::getInspectionSchemeId, patrolInspectionSchemeList.get(i).getId());
|
|
|
+ List<PatrolInspectionRoute> patrolInspectionRouteList = patrolInspectionRouteService.list(queryWrapperTwo);
|
|
|
+
|
|
|
+ for (int j = 0; j < patrolInspectionRouteList.size(); j++) {
|
|
|
+ patrolInspectionRecord.setInspectionNumber(patrolInspectionSchemeList.get(i).getExecutions() + 1);
|
|
|
+ patrolInspectionRecord.setSiteId(patrolInspectionRouteList.get(j).getSiteId());
|
|
|
+ patrolInspectionRecord.setInspectionRouteId(patrolInspectionRouteList.get(j).getId());
|
|
|
+ patrolInspectionRecordService.save(patrolInspectionRecord);
|
|
|
+ Integer inspectionRecordId = patrolInspectionRecord.getId();
|
|
|
+ List<PatrolRouteContentTimingVo> patrolRouteContentTimingVoList = patrolInspectionRecordMapper.patrolRouteContentTimingVoList(patrolInspectionRouteList.get(j).getId());
|
|
|
+ if (patrolRouteContentTimingVoList.size()>0){
|
|
|
+ for (int k=0;k<patrolRouteContentTimingVoList.size();k++){
|
|
|
+ PatrolRecordRoute patrolRecordRoute = new PatrolRecordRoute();
|
|
|
+ patrolRecordRoute.setInspectionRecordId(inspectionRecordId);
|
|
|
+ patrolRecordRoute.setInspectionRouteId(patrolInspectionRouteList.get(j).getId());
|
|
|
+ patrolRecordRoute.setCreateTime(new Date());
|
|
|
+ patrolRecordRoute.setInspectionSchemeId(patrolInspectionSchemeList.get(i).getId());
|
|
|
+ patrolRecordRoute.setStatus(0);
|
|
|
+ patrolRecordRoute.setCheckEntryName(patrolRouteContentTimingVoList.get(k).getCheckEntryName());
|
|
|
+ patrolRecordRoute.setInspectionContentId(patrolRouteContentTimingVoList.get(k).getInspectionContentId());
|
|
|
+ patrolRecordRouteService.save(patrolRecordRoute);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PatrolInspectionScheme patrolInspectionScheme = new PatrolInspectionScheme();
|
|
|
+ patrolInspectionScheme.setId(patrolInspectionSchemeList.get(i).getId());
|
|
|
+ patrolInspectionScheme.setExecutions(patrolInspectionSchemeList.get(i).getExecutions() + 1);
|
|
|
+ patrolInspectionSchemeService.updateById(patrolInspectionScheme);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("addHadJob---startTime" + datef);
|
|
|
+ }
|
|
|
+}
|