| | |
| | | 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; |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | } |