Commit a1ec0a44 authored by 王飞's avatar 王飞

Merge branch 'wangfei' into 'dev'

Wangfei

See merge request !77
parents 59df62d7 3e7b5c16
...@@ -24,11 +24,16 @@ import java.util.List; ...@@ -24,11 +24,16 @@ import java.util.List;
public class Task { public class Task {
@TableField(exist = false) @TableField(exist = false)
public static final String STATUS_RUNNABLE = "RUNNABLE"; public static final String RUN_STATUS_RUNNABLE = "RUNNABLE";
@TableField(exist = false) @TableField(exist = false)
public static final String STATUS_RUNNING = "RUNNING"; public static final String RUN_STATUS_STATUS_RUNNING = "RUNNING";
@TableField(exist = false)
public static final String TASK_STATUS_NEW = "NEW";
@TableField(exist = false) @TableField(exist = false)
public static final String STATUS_FINISH = "FINISH"; public static final String TASK_STATUS_PENDING = "PENDING";
@TableField(exist = false)
public static final String TASK_STATUS_FINISH = "FINISH";
@TableField(exist = false) @TableField(exist = false)
public static final String SUB_TASK_GRFIS = "grfis"; public static final String SUB_TASK_GRFIS = "grfis";
...@@ -58,9 +63,12 @@ public class Task { ...@@ -58,9 +63,12 @@ public class Task {
@ApiModelProperty("任务名称") @ApiModelProperty("任务名称")
private String taskName; private String taskName;
@ApiModelProperty("任务状态(NEW、FINISH)") @ApiModelProperty("任务状态[NEW、PENDING、FINISH]")
private String taskStatus; private String taskStatus;
@ApiModelProperty("运行状态[RUNNABLE、RUNNING]")
public String runStatus;
@ApiModelProperty("下一个节点 SUB_TASK_SRAIF(体系审查子任务)、SUB_TASK_TRFIS(车辆实验子任务)、SUB_TASK_GRFIS(车辆问卷子任务)") @ApiModelProperty("下一个节点 SUB_TASK_SRAIF(体系审查子任务)、SUB_TASK_TRFIS(车辆实验子任务)、SUB_TASK_GRFIS(车辆问卷子任务)")
private String nextNode; private String nextNode;
......
package com.ruoyi.service;
import com.ruoyi.domain.Task;
import java.util.List;
public interface TaskState {
void doCreate(Task task, List<String> taskList);
void doStart(Task task);
void doSubmit(Task task);
}
...@@ -43,6 +43,9 @@ public class StrategyCarReviewTaskSigned implements StrategyCarReviewTask, Initi ...@@ -43,6 +43,9 @@ public class StrategyCarReviewTaskSigned implements StrategyCarReviewTask, Initi
@Autowired @Autowired
private TaskMapper taskMapper; private TaskMapper taskMapper;
@Autowired
private TaskStateFacade taskStateFacade;
// SIGNED状态下 // SIGNED状态下
// 1.standard字段使用task中归档的问卷 // 1.standard字段使用task中归档的问卷
// 2.不查询场景变更任务 // 2.不查询场景变更任务
...@@ -84,7 +87,7 @@ public class StrategyCarReviewTaskSigned implements StrategyCarReviewTask, Initi ...@@ -84,7 +87,7 @@ public class StrategyCarReviewTaskSigned implements StrategyCarReviewTask, Initi
// 5.再找带该子任务所属的总任务,将总任务的状态由 RUNNING 改回 RUNNABLE // 5.再找带该子任务所属的总任务,将总任务的状态由 RUNNING 改回 RUNNABLE
Task task = taskMapper.selectById(taskMapper.findByCarReviewTaskId(carReviewTask.getId())); Task task = taskMapper.selectById(taskMapper.findByCarReviewTaskId(carReviewTask.getId()));
task.setTaskStatus(Task.STATUS_RUNNABLE); taskStateFacade.doSubmit(task);
carReviewTaskMapper.updateById(carReviewTask); carReviewTaskMapper.updateById(carReviewTask);
taskMapper.updateById(task); taskMapper.updateById(task);
......
...@@ -42,6 +42,9 @@ public class StrategySystemReviewTaskSigned implements StrategySystemReviewTask, ...@@ -42,6 +42,9 @@ public class StrategySystemReviewTaskSigned implements StrategySystemReviewTask,
@Autowired @Autowired
private TaskMapper taskMapper; private TaskMapper taskMapper;
@Autowired
private TaskStateFacade taskStateFacade;
@Override @Override
public void doStart(SystemReviewTask systemReviewTask) { public void doStart(SystemReviewTask systemReviewTask) {
...@@ -73,7 +76,7 @@ public class StrategySystemReviewTaskSigned implements StrategySystemReviewTask, ...@@ -73,7 +76,7 @@ public class StrategySystemReviewTaskSigned implements StrategySystemReviewTask,
// 5.再找带该子任务所属的总任务,将总任务的状态由 RUNNING 改回 RUNNABLE // 5.再找带该子任务所属的总任务,将总任务的状态由 RUNNING 改回 RUNNABLE
Task task = taskMapper.selectById(taskMapper.findBySystemReviewTaskId(systemReviewTask.getId())); Task task = taskMapper.selectById(taskMapper.findBySystemReviewTaskId(systemReviewTask.getId()));
task.setTaskStatus(Task.STATUS_RUNNABLE); taskStateFacade.doSubmit(task);
systemReviewTaskMapper.updateById(systemReviewTask); systemReviewTaskMapper.updateById(systemReviewTask);
taskMapper.updateById(task); taskMapper.updateById(task);
......
...@@ -59,6 +59,10 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta ...@@ -59,6 +59,10 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
@Autowired @Autowired
private AutomobileEnterpriseMapper automobileEnterpriseMapper; private AutomobileEnterpriseMapper automobileEnterpriseMapper;
@Autowired
private TaskStateFacade taskStateFacade;
@Override @Override
public List<Task> findList(TaskListRequest request) { public List<Task> findList(TaskListRequest request) {
return taskMapper.findList(request); return taskMapper.findList(request);
...@@ -87,7 +91,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta ...@@ -87,7 +91,7 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
Task task = new Task(); Task task = new Task();
task.setTaskInitiator(initiator.getNickName()); task.setTaskInitiator(initiator.getNickName());
task.setTaskInitiatorDept(initiator.getDept().getDeptName()); task.setTaskInitiatorDept(initiator.getDept().getDeptName());
task.setTaskStatus(Task.STATUS_RUNNABLE); task.setTaskStatus(Task.TASK_STATUS_NEW);
task.setLeaderId(leader.getUserId()); task.setLeaderId(leader.getUserId());
task.setLeader(leader.getName()); task.setLeader(leader.getName());
task.setCreateTime(new Date()); task.setCreateTime(new Date());
...@@ -98,24 +102,15 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta ...@@ -98,24 +102,15 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
AutomobileEnterprise automobileEnterprise = automobileEnterpriseMapper.selectAutomobileEnterpriseById(request.getProductionId()); AutomobileEnterprise automobileEnterprise = automobileEnterpriseMapper.selectAutomobileEnterpriseById(request.getProductionId());
task.setProductionEnterprise(automobileEnterprise.getEnterpriseName()); task.setProductionEnterprise(automobileEnterprise.getEnterpriseName());
String nextNode = null;
if(request.getTaskList().contains(Task.SUB_TASK_TRFIS)) {
nextNode = Task.SUB_TASK_TRFIS;
}
if(request.getTaskList().contains(Task.SUB_TASK_GRFIS)) { if(request.getTaskList().contains(Task.SUB_TASK_GRFIS)) {
// 保存车型审查问卷任务 // 保存车型审查问卷任务
nextNode = Task.SUB_TASK_GRFIS;;
task.setCarReviewTaskId(saveCarReview(request,initiator,standard,leader)); task.setCarReviewTaskId(saveCarReview(request,initiator,standard,leader));
} }
if(request.getTaskList().contains(Task.SUB_TASK_SRAIF)) { if(request.getTaskList().contains(Task.SUB_TASK_SRAIF)) {
// 保存体系审查任务 // 保存体系审查任务
nextNode = Task.SUB_TASK_SRAIF;
task.setSystemReviewTaskId(saveSystemReview(request,initiator,standard,leader)); task.setSystemReviewTaskId(saveSystemReview(request,initiator,standard,leader));
} }
task.setNextNode(nextNode);
taskService.save(task); taskService.save(task);
// 构建并保存该任务所关联的审核组信息 // 构建并保存该任务所关联的审核组信息
...@@ -195,18 +190,16 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta ...@@ -195,18 +190,16 @@ public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements Ta
carRequest.setTaskId(task.getCarReviewTaskId()); carRequest.setTaskId(task.getCarReviewTaskId());
if (Objects.equals(task.getNextNode(), Task.SUB_TASK_SRAIF)) { if (Objects.equals(task.getNextNode(), Task.SUB_TASK_SRAIF)) {
systemReviewTaskService.start(systemRequest); systemReviewTaskService.start(systemRequest);
task.setTaskStatus(Task.STATUS_RUNNING);
task.setNextNode(Task.SUB_TASK_GRFIS);
taskMapper.updateById(task);
} else if (Objects.equals(task.getNextNode(), Task.SUB_TASK_GRFIS)) { } else if (Objects.equals(task.getNextNode(), Task.SUB_TASK_GRFIS)) {
carReviewTaskService.startReviewTask(carRequest); carReviewTaskService.startReviewTask(carRequest);
task.setTaskStatus(Task.STATUS_RUNNING);
task.setNextNode(Task.SUB_TASK_TRFIS);
taskMapper.updateById(task);
} }
taskStateFacade.doStart(task);
} }
public Long saveSystemReview(TaskCreateRequest request,SysUser initiator,Standard standard,TaskUserRelation leader) { public Long saveSystemReview(TaskCreateRequest request,SysUser initiator,Standard standard,TaskUserRelation leader) {
......
package com.ruoyi.service.impl;
import com.ruoyi.service.StrategyReviewSceneChange;
import com.ruoyi.service.TaskState;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Transactional
@Service
public class TaskStateContext {
private final Map<String, TaskState> strategyMap = new ConcurrentHashMap<>();
public void putResource(String key, TaskState taskState) {
strategyMap.put(key, taskState);
}
public TaskState getResource(String operation){
return strategyMap.get(operation);
}
}
package com.ruoyi.service.impl;
import com.ruoyi.domain.Task;
import com.ruoyi.service.TaskState;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
@Component
public class TaskStateFacade implements TaskState {
@Autowired
private TaskStateContext taskStateContext;
@Override
public void doCreate(Task task, List<String> taskList) {
taskStateContext.getResource(task.getTaskStatus()).doCreate(task, taskList);
}
@Override
public void doStart(Task task) {
taskStateContext.getResource(task.getTaskStatus()).doStart(task);
}
@Override
public void doSubmit(Task task) {
taskStateContext.getResource(task.getTaskStatus()).doSubmit(task);
}
}
package com.ruoyi.service.impl;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.domain.Task;
import com.ruoyi.service.TaskState;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Transactional
@Service
public class TaskStateFinish implements TaskState, InitializingBean {
@Autowired
private TaskStateContext taskStateContext;
@Autowired
private ApplicationContext applicationContext;
@Override
public void doCreate(Task task, List<String> taskList) {
throw new ServiceException("不能创建一个已经结束的任务", HttpStatus.ERROR);
}
@Override
public void doStart(Task task) {
throw new ServiceException("不能开始一个已经结束的任务", HttpStatus.ERROR);
}
@Override
public void doSubmit(Task task) {
throw new ServiceException("不能完成一个已经结束的任务", HttpStatus.ERROR);
}
@Override
public void afterPropertiesSet() throws Exception {
taskStateContext.putResource(Task.TASK_STATUS_FINISH, applicationContext.getBean(this.getClass()));
}
}
package com.ruoyi.service.impl;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.domain.Task;
import com.ruoyi.service.TaskService;
import com.ruoyi.service.TaskState;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Objects;
@Transactional
@Service
public class TaskStateNew implements TaskState, InitializingBean {
@Autowired
private TaskStateContext taskStateContext;
@Autowired
private ApplicationContext applicationContext;
@Autowired
private TaskService taskService;
@Override
public void doCreate(Task task, List<String> taskList) {
String nextNode = null;
if(taskList.contains(Task.SUB_TASK_TRFIS)) {
nextNode = Task.SUB_TASK_TRFIS;
}
if(taskList.contains(Task.SUB_TASK_GRFIS)) {
// 保存车型审查问卷任务
nextNode = Task.SUB_TASK_GRFIS;;
}
if(taskList.contains(Task.SUB_TASK_SRAIF)) {
// 保存体系审查任务
nextNode = Task.SUB_TASK_SRAIF;
}
task.setNextNode(nextNode);
}
@Override
public void doStart(Task task) {
task.setTaskStatus(Task.TASK_STATUS_PENDING);
task.setRunStatus(Task.RUN_STATUS_STATUS_RUNNING);
if (Objects.equals(task.getNextNode(), Task.SUB_TASK_SRAIF)) {
task.setNextNode(Task.SUB_TASK_GRFIS);
taskService.updateById(task);
} else if (Objects.equals(task.getNextNode(), Task.SUB_TASK_GRFIS)) {
task.setNextNode(Task.SUB_TASK_TRFIS);
taskService.updateById(task);
}
taskService.updateById(task);
}
@Override
public void doSubmit(Task task) {
throw new ServiceException("不能提交一个尚未开始的任务", HttpStatus.ERROR);
}
@Override
public void afterPropertiesSet() throws Exception {
taskStateContext.putResource(Task.TASK_STATUS_PENDING, applicationContext.getBean(this.getClass()));
}
}
package com.ruoyi.service.impl;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.domain.CarReviewTask;
import com.ruoyi.domain.SystemReviewTask;
import com.ruoyi.domain.Task;
import com.ruoyi.mapper.ReviewDetailsMapper;
import com.ruoyi.service.TaskService;
import com.ruoyi.service.TaskState;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Objects;
@Transactional
@Service
public class TaskStatePending implements TaskState, InitializingBean {
@Autowired
private TaskStateContext taskStateContext;
private ReviewDetailsMapper reviewDetailsMapper;
@Autowired
private TaskService taskService;
@Autowired
private ApplicationContext applicationContext;
@Override
public void doCreate(Task task, List<String> taskList) {
throw new ServiceException("不能创建一个已经开始的任务", HttpStatus.ERROR);
}
@Override
public void doStart(Task task) {
task.setTaskStatus(Task.TASK_STATUS_PENDING);
task.setRunStatus(Task.RUN_STATUS_STATUS_RUNNING);
if (Objects.equals(task.getNextNode(), Task.SUB_TASK_SRAIF)) {
task.setNextNode(Task.SUB_TASK_GRFIS);
taskService.updateById(task);
} else if (Objects.equals(task.getNextNode(), Task.SUB_TASK_GRFIS)) {
task.setNextNode(Task.SUB_TASK_TRFIS);
taskService.updateById(task);
}
}
@Override
public void doSubmit(Task task) {
long subTaskCount = 0;
if(task.getSystemReviewTaskId() != null) {
subTaskCount = reviewDetailsMapper.count(task.getSystemReviewTaskId(), SystemReviewTask.TYPE);
}
if(task.getCarReviewTaskId() != null) {
subTaskCount = reviewDetailsMapper.count(task.getCarReviewTaskId(), CarReviewTask.TYPE);
}
if(subTaskCount > 0) {
task.setTaskStatus(Task.TASK_STATUS_PENDING);
task.setRunStatus(Task.RUN_STATUS_RUNNABLE);
} else {
task.setTaskStatus(Task.TASK_STATUS_FINISH);
task.setRunStatus(Task.RUN_STATUS_STATUS_RUNNING);
}
taskService.updateById(task);
}
@Override
public void afterPropertiesSet() throws Exception {
taskStateContext.putResource(Task.TASK_STATUS_PENDING, applicationContext.getBean(this.getClass()));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment