skjcmanager/skjcmanager-service-api/skjcmanager-sm-api/src/main/java/cn/gistack/sm/patrol/feign/PatrolTaskClient.java
@@ -34,7 +34,8 @@ List<Integer> createTaskJobHandler(@RequestParam("processDefinitionId") String processDefinitionId, @RequestParam("taskType") String taskType, @RequestParam("title") String title, @RequestParam("content") String content); @RequestParam("content") String content, @RequestParam("type") int type); /** * 给巡查责任人定时创建任务执行器 skjcmanager/skjcmanager-service-api/skjcmanager-sm-api/src/main/java/cn/gistack/sm/patrol/feign/PatrolTaskClientFallback.java
@@ -13,7 +13,7 @@ public class PatrolTaskClientFallback implements PatrolTaskClient { @Override public List<Integer> createTaskJobHandler(String processDefinitionId, String taskType, String title, String content) { public List<Integer> createTaskJobHandler(String processDefinitionId, String taskType, String title, String content, int type) { return null; } skjcmanager/skjcmanager-service/skjcmanager-sm/src/main/java/cn/gistack/sm/patrol/feign/PatrolTaskImplClient.java
@@ -24,6 +24,9 @@ import org.springframework.web.client.RestTemplate; import springfox.documentation.annotations.ApiIgnore; import java.time.LocalDate; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoField; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -76,9 +79,9 @@ public List<Integer> createTaskJobHandler(String processDefinitionId, String taskType, String title, String content) { String content, int type) { List<PatrolResponsiblePerson> patrolResponsiblePersonList = attResManagePersonService.getPatrolResponsiblePersonAll(); List<Integer> taskJob = createTaskJob(processDefinitionId, taskType, title, content, patrolResponsiblePersonList); List<Integer> taskJob = createTaskJob(processDefinitionId, taskType, title, content, type, patrolResponsiblePersonList); return taskJob; } @@ -215,5 +218,56 @@ return list; } public List<Integer> createTaskJob(String processDefinitionId, String taskType, String title, String content, int type, List<PatrolResponsiblePerson> patrolResponsiblePersonList){ AtomicInteger failureCount = new AtomicInteger(); patrolResponsiblePersonList.forEach(item -> { log.info("当前创建任务对象:" + JSON.toJSONString(item)); try { PatrolTask patrolTask = new PatrolTask(); patrolTask.setProcessDefinitionId(processDefinitionId); patrolTask.setToUserId(item.getUserId()); patrolTask.setProjectId(item.getResGuid()); patrolTask.setReservoirName(item.getName()); // 开始时间-结束时间 if (type == 1) { //周任务 LocalDate today = LocalDate.now(); LocalDate firstDayOfWeek = today.with(ChronoField.DAY_OF_WEEK, 1); LocalDate lastDayOfWeek = today.with(ChronoField.DAY_OF_WEEK, 7); String firstDayOfWeekString = firstDayOfWeek.format(DateTimeFormatter.ofPattern("yyyy-MM-dd 00:00:00")); String lastDayOfWeekString = lastDayOfWeek.format(DateTimeFormatter.ofPattern("yyyy-MM-dd 23:59:59")); patrolTask.setStartTime(firstDayOfWeekString); patrolTask.setEndTime(lastDayOfWeekString); } else { // 默认天任务 patrolTask.setStartTime(DateUtil.format(new Date(),"yyyy-MM-dd 00:00:00")); patrolTask.setEndTime(DateUtil.format(new Date(),"yyyy-MM-dd 23:59:59")); } // 标题格式 月-日 水库名称 每日巡检任务 patrolTask.setTitle(DateUtil.format(new Date(),"MM-dd") + item.getName() + "-" + title); patrolTask.setContent(DateUtil.format(new Date(),"yyyyMMdd") +content); patrolTask.setTaskType(taskType); // 创建任务 patrolTaskService.startProcess(patrolTask); } catch (Exception e) { log.error("创建任务失败:" + e.getMessage()); log.error("创建任务失败对象:" + JSON.toJSONString(item)); failureCount.getAndIncrement(); } }); List<Integer> list = new ArrayList<>(); list.add(patrolResponsiblePersonList.size()); list.add(failureCount.get()); // 返回 return list; } } skjcmanager/skjcmanager-service/skjcmanager-xxljob/src/main/java/cn/gistack/job/executor/jobhandler/PatrolXxlJob.java
@@ -6,8 +6,10 @@ import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; import io.swagger.models.auth.In; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springblade.core.tool.utils.StringUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -32,13 +34,19 @@ @XxlJob("createTaskJobHandler") public ReturnT<String> createTaskJobHandler(String param){ XxlJobLogger.log("开始自动创建任务..."); XxlJobLogger.log("参数:" + param); XxlJobLogger.log("..."); JSONObject jsonParam = JSON.parseObject(param); String processDefinitionId = jsonParam.getString("processDefinitionId"); String taskType = jsonParam.getString("taskType"); String title = jsonParam.getString("title"); String content = jsonParam.getString("content"); String typeStr = jsonParam.getString("type"); int type = 0; if (!StringUtil.isBlank(typeStr)) type = Integer.parseInt(typeStr); // 远程调用 List<Integer> taskJobHandler = patrolTasClient.createTaskJobHandler(processDefinitionId, taskType, title, content); List<Integer> taskJobHandler = patrolTasClient.createTaskJobHandler(processDefinitionId, taskType, title, content, type); // 打印响应数据 XxlJobLogger.log("结束自动创建任务..."); XxlJobLogger.log("总数量:<span style='color:red'>" + taskJobHandler.get(0) + "</span> ... 失败数量:<span style='color:red'>" + taskJobHandler.get(1) + "</span> ");