每日5点,将跳过未完成点检的任务,创建新的点检任务

master
zpl 3 years ago
parent d3f040aa45
commit 1615ec8785

@ -0,0 +1,6 @@
package com.foreverwin.mesnac.equip.service;
public interface ResourceInspectTaskJobService {
void resourceInspectTaskJobProcess(String site);
}

@ -0,0 +1,49 @@
package com.foreverwin.mesnac.equip.service.impl;
import com.foreverwin.mesnac.common.constant.Constants;
import com.foreverwin.mesnac.equip.mapper.ResourceInspectTaskMapper;
import com.foreverwin.mesnac.equip.model.ResourceInspectTask;
import com.foreverwin.mesnac.equip.service.ResourceInspectPlanService;
import com.foreverwin.mesnac.equip.service.ResourceInspectTaskJobService;
import com.foreverwin.mesnac.equip.service.ResourceInspectTaskService;
import com.foreverwin.modular.core.util.CommonMethods;
import org.apache.tomcat.jni.Local;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class ResourceInspectTaskJobServiceImpl implements ResourceInspectTaskJobService {
@Autowired
ResourceInspectTaskMapper resourceInspectTaskMapper;
@Autowired
ResourceInspectPlanService resourceInspectPlanService;
@Autowired
ResourceInspectTaskService resourceInspectTaskService;
@Override
public void resourceInspectTaskJobProcess(String site) {
String user = CommonMethods.getUser();
ResourceInspectTask resourceInspectTask = new ResourceInspectTask();
resourceInspectTask.setSite(site);
resourceInspectTask.setCategory(Constants.INSPECTION_TYPE_DM);
LocalDateTime now = LocalDateTime.now();
LocalDateTime dateTime = LocalDateTime.now().minusDays(1);
resourceInspectTask.setPlanStartDate(dateTime);
resourceInspectTask.setPlanCompleteDate(now);
List<ResourceInspectTask> inspectTaskList = resourceInspectTaskMapper.getInspectTaskList(resourceInspectTask);
for (ResourceInspectTask inspectTask: inspectTaskList) {
resourceInspectPlanService.autoCreateTaskByResourceInspectTask(inspectTask);
inspectTask.setModifyUser(user);
inspectTask.setModifiedDateTime(LocalDateTime.now());
}
if (inspectTaskList.size() > 0){
resourceInspectTaskService.updateBatchById(inspectTaskList);
}
}
}

@ -0,0 +1,44 @@
package com.foreverwin.mesnac.quartz.job;
import com.foreverwin.mesnac.common.util.StringUtil;
import com.foreverwin.mesnac.equip.service.ResourceInspectTaskJobService;
import com.foreverwin.mesnac.equip.service.ResourceInspectTaskService;
import com.foreverwin.modular.core.exception.BaseException;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
/**
* @Description TODO
* @Author zhaojiawei
* @Since 2021-07-22
*/
@DisallowConcurrentExecution
public class ResourceInspectTaskJob implements Job {
private static final String SITE_UPPERCASE = "SITE";
private static final String SITE_LOWERCASE = "site";
@Autowired
private ResourceInspectTaskJobService resourceInspectTaskJobService;
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
//获取站点,若站点为空则抛出异常
String site = getSite(context);
if (StringUtil.isBlank(site)) {
throw new BaseException("equip.quartz.task.not.site", null);
}
resourceInspectTaskJobService.resourceInspectTaskJobProcess(site);
}
private String getSite(JobExecutionContext context) {
String site = context.getJobDetail().getJobDataMap().getString(SITE_LOWERCASE);
if (StringUtil.isBlank(site)) {
site = context.getJobDetail().getJobDataMap().getString(SITE_UPPERCASE);
}
return site;
}
}
Loading…
Cancel
Save