Commit a52c139f by yuwei

项目初始化

parent f3940250
...@@ -110,7 +110,7 @@ public class DataConstant { ...@@ -110,7 +110,7 @@ public class DataConstant {
AUDIT("2","审核中"), AUDIT("2","审核中"),
AGREE("3","成功"), AGREE("3","成功"),
REJECT("4","失败"), REJECT("4","失败"),
CANCEL("5", "已取消"); CANCEL("5", "已撤销");
AuditState(String key, String val){ AuditState(String key, String val){
this.key = key; this.key = key;
this.val = val; this.val = val;
......
...@@ -17,6 +17,8 @@ public class ProcessInstanceCreateRequest implements Serializable { ...@@ -17,6 +17,8 @@ public class ProcessInstanceCreateRequest implements Serializable {
@ApiModelProperty(value = "流程定义ID") @ApiModelProperty(value = "流程定义ID")
private String processDefinitionId; private String processDefinitionId;
@ApiModelProperty(value = "提交人")
private String submitter;
@ApiModelProperty(value = "业务ID") @ApiModelProperty(value = "业务ID")
private String businessKey; private String businessKey;
@ApiModelProperty(value = "业务类型") @ApiModelProperty(value = "业务类型")
...@@ -26,16 +28,11 @@ public class ProcessInstanceCreateRequest implements Serializable { ...@@ -26,16 +28,11 @@ public class ProcessInstanceCreateRequest implements Serializable {
@ApiModelProperty(value = "流程参数") @ApiModelProperty(value = "流程参数")
private Map<String, Object> variables = new HashMap<>(); private Map<String, Object> variables = new HashMap<>();
public ProcessInstanceCreateRequest() {} public Map<String, Object> getVariables() {
variables.put(VariablesEnum.submitter.toString(), submitter);
public ProcessInstanceCreateRequest(String processDefinitionId, String businessKey, String businessType, String businessName, Map<String, Object> var){
setProcessDefinitionId(processDefinitionId);
setBusinessKey(businessKey);
setBusinessType(businessType);
setBusinessName(businessName);
variables.putAll(var);
variables.put(VariablesEnum.businessKey.toString(), businessKey); variables.put(VariablesEnum.businessKey.toString(), businessKey);
variables.put(VariablesEnum.businessType.toString(), businessType); variables.put(VariablesEnum.businessType.toString(), businessType);
variables.put(VariablesEnum.businessName.toString(), businessName); variables.put(VariablesEnum.businessName.toString(), businessName);
return variables;
} }
} }
package cn.datax.service.workflow.api.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Map;
@ApiModel(value = "任务执行Model")
@Data
public class TaskRequest implements Serializable {
private static final long serialVersionUID=1L;
@ApiModelProperty(value = "执行任务类型")
private String action;
@ApiModelProperty(value = "任务ID")
private String taskId;
@ApiModelProperty(value = "流程实例ID")
private String processInstanceId;
@ApiModelProperty(value = "用户ID")
private String userId;
@ApiModelProperty(value = "审批意见")
private String message;
@ApiModelProperty(value = "参数")
private Map<String, Object> variables;
}
...@@ -10,20 +10,16 @@ import lombok.Getter; ...@@ -10,20 +10,16 @@ import lombok.Getter;
@AllArgsConstructor @AllArgsConstructor
public enum ActionEnum { public enum ActionEnum {
COMPLETE("complete","完成任务成功"), COMPLETE("complete", "完成任务"),
CLAIM("claim","任务签收成功"), CLAIM("claim", "任务签收"),
UNCLAIM("unclaim","任务反签收成功"), UNCLAIM("unclaim", "任务反签收"),
DELEGATE("delegate","任务委派成功"), DELEGATE("delegate", "任务委派"),
RESOLVE("resolve"," 任务签收完成,返回任务人完成"), RESOLVE("resolve", "任务归还"),
ASSIGNEE("assignee","任务转办成功"), ASSIGNEE("assignee", "任务转办");
SUSPEND("suspend","挂起流程成功"),
ACTIVATE("activate","激活流程成功");
private String action; private String action;
private String title; private String title;
public static ActionEnum actionOf(String action) { public static ActionEnum actionOf(String action) {
for(ActionEnum actionEnum : values()){ for(ActionEnum actionEnum : values()){
if(actionEnum.getAction().equals(action)){ if(actionEnum.getAction().equals(action)){
......
...@@ -11,7 +11,7 @@ public enum VariablesEnum { ...@@ -11,7 +11,7 @@ public enum VariablesEnum {
/** 提交节点 */ /** 提交节点 */
submitNode, submitNode,
/** 提交人*/ /** 提交人 */
submitter, submitter,
/** 初审节点 */ /** 初审节点 */
...@@ -23,15 +23,18 @@ public enum VariablesEnum { ...@@ -23,15 +23,18 @@ public enum VariablesEnum {
/** 通过结束节点 */ /** 通过结束节点 */
approveEnd, approveEnd,
/** 不通过结束节点 */ /** 失败结束节点 */
rejectEnd, rejectEnd,
/** 活动主题*/ /** 活动主题 */
businessName, businessName,
/** 活动类型*/ /** 活动类型 */
businessType, businessType,
/** 主键id*/ /** 主键id */
businessKey; businessKey,
/** 审核结果 */
approved;
} }
...@@ -11,4 +11,7 @@ public class FlowInstanceQuery extends BaseQueryParams { ...@@ -11,4 +11,7 @@ public class FlowInstanceQuery extends BaseQueryParams {
private static final long serialVersionUID=1L; private static final long serialVersionUID=1L;
private String name; private String name;
private String businessKey;
private String businessType;
private String businessName;
} }
...@@ -26,9 +26,9 @@ public class FlowInstanceController extends BaseController { ...@@ -26,9 +26,9 @@ public class FlowInstanceController extends BaseController {
@Autowired @Autowired
private FlowInstanceService flowInstanceService; private FlowInstanceService flowInstanceService;
@PostMapping @PostMapping("/startById")
@ApiOperation(value = "启动通过流程定义ID流程实例") @ApiOperation(value = "启动通过流程定义ID流程实例")
@ApiImplicitParam(name = "request", value = "详细实体request", required = true, dataType = "ProcessInstanceCreateRequest") @ApiImplicitParam(name = "request", value = "启动流程实例实体request", required = true, dataType = "ProcessInstanceCreateRequest")
public R startById(@RequestBody ProcessInstanceCreateRequest request) { public R startById(@RequestBody ProcessInstanceCreateRequest request) {
flowInstanceService.startProcessInstanceById(request); flowInstanceService.startProcessInstanceById(request);
return R.ok(); return R.ok();
...@@ -45,6 +45,26 @@ public class FlowInstanceController extends BaseController { ...@@ -45,6 +45,26 @@ public class FlowInstanceController extends BaseController {
return R.ok().setData(jsonPage); return R.ok().setData(jsonPage);
} }
@ApiOperation(value = "分页查询本人发起的流程实例")
@ApiImplicitParams({
@ApiImplicitParam(name = "flowInstanceQuery", value = "查询实体flowInstanceQuery", required = true, dataTypeClass = FlowInstanceQuery.class)
})
@GetMapping("/pageMyStarted")
public R pageMyStarted(FlowInstanceQuery flowInstanceQuery) {
flowInstanceService.pageMyStartedProcessInstance(flowInstanceQuery);
return R.ok();
}
@ApiOperation(value = "分页查询本人参与的流程实例")
@ApiImplicitParams({
@ApiImplicitParam(name = "flowInstanceQuery", value = "查询实体flowInstanceQuery", required = true, dataTypeClass = FlowInstanceQuery.class)
})
@GetMapping("/pageMyInvolved")
public R pageMyInvolved(FlowInstanceQuery flowInstanceQuery) {
flowInstanceService.pageMyInvolvedProcessInstance(flowInstanceQuery);
return R.ok();
}
@ApiOperation(value = "激活流程实例", notes = "根据url的id来指定激活流程实例") @ApiOperation(value = "激活流程实例", notes = "根据url的id来指定激活流程实例")
@ApiImplicitParam(name = "processInstanceId", value = "流程实例ID", required = true, dataType = "String", paramType = "path") @ApiImplicitParam(name = "processInstanceId", value = "流程实例ID", required = true, dataType = "String", paramType = "path")
@PutMapping("/activate/{processInstanceId}") @PutMapping("/activate/{processInstanceId}")
...@@ -80,4 +100,12 @@ public class FlowInstanceController extends BaseController { ...@@ -80,4 +100,12 @@ public class FlowInstanceController extends BaseController {
response.getOutputStream().write(b, 0, len); response.getOutputStream().write(b, 0, len);
} }
} }
@ApiOperation(value = "获取审批意见")
@ApiImplicitParam(name = "processInstanceId", value = "流程实例ID", required = true, dataType = "String", paramType = "path")
@GetMapping("/comments")
public R getComments(String processInstanceId) {
flowInstanceService.getProcessInstanceComments(processInstanceId);
return R.ok();
}
} }
...@@ -3,6 +3,7 @@ package cn.datax.service.workflow.controller; ...@@ -3,6 +3,7 @@ package cn.datax.service.workflow.controller;
import cn.datax.common.base.BaseController; import cn.datax.common.base.BaseController;
import cn.datax.common.core.JsonPage; import cn.datax.common.core.JsonPage;
import cn.datax.common.core.R; import cn.datax.common.core.R;
import cn.datax.service.workflow.api.dto.TaskRequest;
import cn.datax.service.workflow.api.query.FlowTaskQuery; import cn.datax.service.workflow.api.query.FlowTaskQuery;
import cn.datax.service.workflow.api.vo.FlowHistTaskVo; import cn.datax.service.workflow.api.vo.FlowHistTaskVo;
import cn.datax.service.workflow.api.vo.FlowTaskVo; import cn.datax.service.workflow.api.vo.FlowTaskVo;
...@@ -13,9 +14,7 @@ import io.swagger.annotations.ApiImplicitParam; ...@@ -13,9 +14,7 @@ import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = {"流程任务"}) @Api(tags = {"流程任务"})
@RestController @RestController
...@@ -46,4 +45,15 @@ public class FlowTaskController extends BaseController { ...@@ -46,4 +45,15 @@ public class FlowTaskController extends BaseController {
JsonPage<FlowHistTaskVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), page.getRecords()); JsonPage<FlowHistTaskVo> jsonPage = new JsonPage<>(page.getCurrent(), page.getSize(), page.getTotal(), page.getRecords());
return R.ok().setData(jsonPage); return R.ok().setData(jsonPage);
} }
@ApiOperation(value = "执行任务", notes = "执行任务类型:claim签收 unclaim反签收 complete完成 delegate任务委派 resolve任务归还 assignee任务转办")
@ApiImplicitParams({
@ApiImplicitParam(name = "taskId", value = "任务ID", required = true, dataType = "String", paramType = "path"),
@ApiImplicitParam(name = "request", value = "执行任务实体request", required = true, dataType = "TaskRequest")
})
@PostMapping(value = "/execute/{taskId}")
public R executeTask(@PathVariable String taskId, @RequestBody TaskRequest request) {
flowTaskService.execute(request);
return R.ok();
}
} }
package cn.datax.service.workflow.flowable;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
@Slf4j
public class EndTaskListener implements ExecutionListener {
@Override
public void notify(DelegateExecution delegateExecution) {
log.info("业务编号{}", delegateExecution.getProcessInstanceBusinessKey());
log.info("节点{},{}", delegateExecution.getId(), delegateExecution.getEventName());
}
}
package cn.datax.service.workflow.flowable;
import cn.datax.common.utils.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.TaskService;
import org.flowable.task.service.delegate.DelegateTask;
import org.flowable.task.service.delegate.TaskListener;
@Slf4j
public class FinalAuditTaskListener implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
log.info("进入终审节点用户任务启动监听器");
TaskService taskService = SpringContextHolder.getBean(TaskService.class);
taskService.setAssignee(delegateTask.getId(), "1214835832967581698");
// taskService.addCandidateUser(delegateTask.getId(), "");
// taskService.addCandidateGroup(delegateTask.getId(), "");
log.info("任务执行人:{}", delegateTask.getAssignee());
log.info("任务配置ID: {}", delegateTask.getTaskDefinitionKey());
log.info("退出终审节点用户任务启动监听器");
}
}
package cn.datax.service.workflow.flowable;
import cn.datax.common.utils.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.TaskService;
import org.flowable.task.service.delegate.DelegateTask;
import org.flowable.task.service.delegate.TaskListener;
@Slf4j
public class InitialAuditTaskListener implements TaskListener {
@Override
public void notify(DelegateTask delegateTask) {
log.info("进入初审节点用户任务启动监听器");
TaskService taskService = SpringContextHolder.getBean(TaskService.class);
taskService.setAssignee(delegateTask.getId(), "1214835832967581698");
// taskService.addCandidateUser(delegateTask.getId(), "");
// taskService.addCandidateGroup(delegateTask.getId(), "");
log.info("任务执行人:{}", delegateTask.getAssignee());
log.info("任务配置ID: {}", delegateTask.getTaskDefinitionKey());
log.info("退出初审节点用户任务启动监听器");
}
}
...@@ -66,4 +66,10 @@ public interface FlowInstanceService { ...@@ -66,4 +66,10 @@ public interface FlowInstanceService {
* @return * @return
*/ */
void pageMyInvolvedProcessInstance(FlowInstanceQuery flowInstanceQuery); void pageMyInvolvedProcessInstance(FlowInstanceQuery flowInstanceQuery);
/**
* 获取审批意见
* @param processInstanceId
*/
void getProcessInstanceComments(String processInstanceId);
} }
package cn.datax.service.workflow.service; package cn.datax.service.workflow.service;
import cn.datax.service.workflow.api.dto.TaskRequest;
import cn.datax.service.workflow.api.query.FlowTaskQuery; import cn.datax.service.workflow.api.query.FlowTaskQuery;
import cn.datax.service.workflow.api.vo.FlowHistTaskVo; import cn.datax.service.workflow.api.vo.FlowHistTaskVo;
import cn.datax.service.workflow.api.vo.FlowTaskVo; import cn.datax.service.workflow.api.vo.FlowTaskVo;
...@@ -20,4 +21,11 @@ public interface FlowTaskService { ...@@ -20,4 +21,11 @@ public interface FlowTaskService {
* @return * @return
*/ */
Page<FlowHistTaskVo> pageDone(FlowTaskQuery flowTaskQuery); Page<FlowHistTaskVo> pageDone(FlowTaskQuery flowTaskQuery);
/**
* 执行任务
* 执行任务类型:claim签收 unclaim反签收 complete完成 delegate任务委派 resolve任务归还 assignee任务转办
* @param request
*/
void execute(TaskRequest request);
} }
...@@ -2,6 +2,7 @@ package cn.datax.service.workflow.service.impl; ...@@ -2,6 +2,7 @@ package cn.datax.service.workflow.service.impl;
import cn.datax.common.utils.SecurityUtil; import cn.datax.common.utils.SecurityUtil;
import cn.datax.service.workflow.api.dto.ProcessInstanceCreateRequest; import cn.datax.service.workflow.api.dto.ProcessInstanceCreateRequest;
import cn.datax.service.workflow.api.enums.VariablesEnum;
import cn.datax.service.workflow.api.query.FlowInstanceQuery; import cn.datax.service.workflow.api.query.FlowInstanceQuery;
import cn.datax.service.workflow.api.vo.FlowInstanceVo; import cn.datax.service.workflow.api.vo.FlowInstanceVo;
import cn.datax.service.workflow.service.FlowInstanceService; import cn.datax.service.workflow.service.FlowInstanceService;
...@@ -15,12 +16,14 @@ import org.flowable.common.engine.impl.identity.Authentication; ...@@ -15,12 +16,14 @@ import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.engine.HistoryService; import org.flowable.engine.HistoryService;
import org.flowable.engine.RepositoryService; import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService; import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.history.HistoricActivityInstance; import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.history.HistoricProcessInstanceQuery; import org.flowable.engine.history.HistoricProcessInstanceQuery;
import org.flowable.engine.runtime.ProcessInstance; import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.engine.runtime.ProcessInstanceBuilder; import org.flowable.engine.runtime.ProcessInstanceBuilder;
import org.flowable.engine.runtime.ProcessInstanceQuery; import org.flowable.engine.runtime.ProcessInstanceQuery;
import org.flowable.engine.task.Comment;
import org.flowable.image.impl.DefaultProcessDiagramGenerator; import org.flowable.image.impl.DefaultProcessDiagramGenerator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -43,6 +46,9 @@ public class FlowInstanceServiceImpl implements FlowInstanceService { ...@@ -43,6 +46,9 @@ public class FlowInstanceServiceImpl implements FlowInstanceService {
@Autowired @Autowired
private RepositoryService repositoryService; private RepositoryService repositoryService;
@Autowired
private TaskService taskService;
private static final String IMAGE_TYPE = "png"; private static final String IMAGE_TYPE = "png";
private static final String FONT_NAME = "宋体"; private static final String FONT_NAME = "宋体";
...@@ -52,10 +58,21 @@ public class FlowInstanceServiceImpl implements FlowInstanceService { ...@@ -52,10 +58,21 @@ public class FlowInstanceServiceImpl implements FlowInstanceService {
if(StrUtil.isNotBlank(flowInstanceQuery.getName())){ if(StrUtil.isNotBlank(flowInstanceQuery.getName())){
processInstanceQuery.processInstanceNameLike(flowInstanceQuery.getName()); processInstanceQuery.processInstanceNameLike(flowInstanceQuery.getName());
} }
long count = processInstanceQuery.count(); if(StrUtil.isNotBlank(flowInstanceQuery.getBusinessKey())){
List<ProcessInstance> processInstanceList = processInstanceQuery.orderByStartTime().desc().listPage((flowInstanceQuery.getPageNum() - 1) * flowInstanceQuery.getPageSize(), flowInstanceQuery.getPageSize()); processInstanceQuery.processInstanceBusinessKey(flowInstanceQuery.getBusinessKey());
}
if(StrUtil.isNotBlank(flowInstanceQuery.getBusinessType())){
processInstanceQuery.variableValueEquals(VariablesEnum.businessType.toString(), flowInstanceQuery.getBusinessType());
}
if(StrUtil.isNotBlank(flowInstanceQuery.getBusinessName())){
processInstanceQuery.variableValueEquals(VariablesEnum.businessName.toString(), flowInstanceQuery.getBusinessName());
}
List<ProcessInstance> processInstanceList = processInstanceQuery.includeProcessVariables()
.orderByStartTime().desc()
.listPage((flowInstanceQuery.getPageNum() - 1) * flowInstanceQuery.getPageSize(), flowInstanceQuery.getPageSize());
List<FlowInstanceVo> flowInstanceVoList = BeanCopyUtil.copyListProperties(processInstanceList, FlowInstanceVo::new); List<FlowInstanceVo> flowInstanceVoList = BeanCopyUtil.copyListProperties(processInstanceList, FlowInstanceVo::new);
Page<FlowInstanceVo> page = new Page<>(flowInstanceQuery.getPageNum(), flowInstanceQuery.getPageSize()); Page<FlowInstanceVo> page = new Page<>(flowInstanceQuery.getPageNum(), flowInstanceQuery.getPageSize());
long count = processInstanceQuery.count();
page.setRecords(flowInstanceVoList); page.setRecords(flowInstanceVoList);
page.setTotal(count); page.setTotal(count);
return page; return page;
...@@ -81,6 +98,7 @@ public class FlowInstanceServiceImpl implements FlowInstanceService { ...@@ -81,6 +98,7 @@ public class FlowInstanceServiceImpl implements FlowInstanceService {
@Override @Override
public void startProcessInstanceById(ProcessInstanceCreateRequest request) { public void startProcessInstanceById(ProcessInstanceCreateRequest request) {
Assert.notNull(request.getSubmitter(), "请输入提交人");
Assert.notNull(request.getBusinessKey(), "请输入业务id"); Assert.notNull(request.getBusinessKey(), "请输入业务id");
Assert.notNull(request.getBusinessType(), "请输入业务类型"); Assert.notNull(request.getBusinessType(), "请输入业务类型");
Assert.notNull(request.getProcessDefinitionId(), "请输入流程定义ID"); Assert.notNull(request.getProcessDefinitionId(), "请输入流程定义ID");
...@@ -91,11 +109,11 @@ public class FlowInstanceServiceImpl implements FlowInstanceService { ...@@ -91,11 +109,11 @@ public class FlowInstanceServiceImpl implements FlowInstanceService {
if(StrUtil.isNotBlank(request.getBusinessKey())){ if(StrUtil.isNotBlank(request.getBusinessKey())){
processInstanceBuilder.businessKey(request.getBusinessKey()); processInstanceBuilder.businessKey(request.getBusinessKey());
} }
processInstanceBuilder.variables(request.getVariables());
// 流程实例标题(动态拼接) // 流程实例标题(动态拼接)
if(StrUtil.isNotBlank(request.getBusinessName())){ if(StrUtil.isNotBlank(request.getBusinessName())){
processInstanceBuilder.name(request.getBusinessName()); processInstanceBuilder.name(request.getBusinessName());
} }
processInstanceBuilder.variables(request.getVariables());
Authentication.setAuthenticatedUserId(SecurityUtil.getUserId()); Authentication.setAuthenticatedUserId(SecurityUtil.getUserId());
ProcessInstance processInstance = processInstanceBuilder.start(); ProcessInstance processInstance = processInstanceBuilder.start();
Authentication.setAuthenticatedUserId(null); Authentication.setAuthenticatedUserId(null);
...@@ -151,17 +169,48 @@ public class FlowInstanceServiceImpl implements FlowInstanceService { ...@@ -151,17 +169,48 @@ public class FlowInstanceServiceImpl implements FlowInstanceService {
public void pageMyStartedProcessInstance(FlowInstanceQuery flowInstanceQuery) { public void pageMyStartedProcessInstance(FlowInstanceQuery flowInstanceQuery) {
HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery(); HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery();
historicProcessInstanceQuery.startedBy(SecurityUtil.getUserId()); historicProcessInstanceQuery.startedBy(SecurityUtil.getUserId());
long count = historicProcessInstanceQuery.count(); if(StrUtil.isNotBlank(flowInstanceQuery.getName())){
List<HistoricProcessInstance> historicProcessInstanceList = historicProcessInstanceQuery.orderByProcessInstanceStartTime().desc() historicProcessInstanceQuery.processInstanceNameLike(flowInstanceQuery.getName());
}
if(StrUtil.isNotBlank(flowInstanceQuery.getBusinessKey())){
historicProcessInstanceQuery.processInstanceBusinessKey(flowInstanceQuery.getBusinessKey());
}
if(StrUtil.isNotBlank(flowInstanceQuery.getBusinessType())){
historicProcessInstanceQuery.variableValueEquals(VariablesEnum.businessType.toString(), flowInstanceQuery.getBusinessType());
}
if(StrUtil.isNotBlank(flowInstanceQuery.getBusinessName())){
historicProcessInstanceQuery.variableValueEquals(VariablesEnum.businessName.toString(), flowInstanceQuery.getBusinessName());
}
List<HistoricProcessInstance> historicProcessInstanceList = historicProcessInstanceQuery.includeProcessVariables()
.orderByProcessInstanceStartTime().desc()
.listPage((flowInstanceQuery.getPageNum() - 1) * flowInstanceQuery.getPageSize(), flowInstanceQuery.getPageSize()); .listPage((flowInstanceQuery.getPageNum() - 1) * flowInstanceQuery.getPageSize(), flowInstanceQuery.getPageSize());
long count = historicProcessInstanceQuery.count();
} }
@Override @Override
public void pageMyInvolvedProcessInstance(FlowInstanceQuery flowInstanceQuery) { public void pageMyInvolvedProcessInstance(FlowInstanceQuery flowInstanceQuery) {
HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery(); HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery();
historicProcessInstanceQuery.involvedUser(SecurityUtil.getUserId()); historicProcessInstanceQuery.involvedUser(SecurityUtil.getUserId());
long count = historicProcessInstanceQuery.count(); if(StrUtil.isNotBlank(flowInstanceQuery.getName())){
List<HistoricProcessInstance> historicProcessInstanceList = historicProcessInstanceQuery.orderByProcessInstanceStartTime().desc() historicProcessInstanceQuery.processInstanceNameLike(flowInstanceQuery.getName());
}
if(StrUtil.isNotBlank(flowInstanceQuery.getBusinessKey())){
historicProcessInstanceQuery.processInstanceBusinessKey(flowInstanceQuery.getBusinessKey());
}
if(StrUtil.isNotBlank(flowInstanceQuery.getBusinessType())){
historicProcessInstanceQuery.variableValueEquals(VariablesEnum.businessType.toString(), flowInstanceQuery.getBusinessType());
}
if(StrUtil.isNotBlank(flowInstanceQuery.getBusinessName())){
historicProcessInstanceQuery.variableValueEquals(VariablesEnum.businessName.toString(), flowInstanceQuery.getBusinessName());
}
List<HistoricProcessInstance> historicProcessInstanceList = historicProcessInstanceQuery.includeProcessVariables()
.orderByProcessInstanceStartTime().desc()
.listPage((flowInstanceQuery.getPageNum() - 1) * flowInstanceQuery.getPageSize(), flowInstanceQuery.getPageSize()); .listPage((flowInstanceQuery.getPageNum() - 1) * flowInstanceQuery.getPageSize(), flowInstanceQuery.getPageSize());
long count = historicProcessInstanceQuery.count();
}
@Override
public void getProcessInstanceComments(String processInstanceId) {
List<Comment> processInstanceComments = taskService.getProcessInstanceComments(processInstanceId);
} }
} }
package cn.datax.service.workflow.service.impl; package cn.datax.service.workflow.service.impl;
import cn.datax.common.utils.SecurityUtil; import cn.datax.common.utils.SecurityUtil;
import cn.datax.service.workflow.api.dto.TaskRequest;
import cn.datax.service.workflow.api.enums.ActionEnum;
import cn.datax.service.workflow.api.enums.VariablesEnum; import cn.datax.service.workflow.api.enums.VariablesEnum;
import cn.datax.service.workflow.api.query.FlowTaskQuery; import cn.datax.service.workflow.api.query.FlowTaskQuery;
import cn.datax.service.workflow.api.vo.FlowHistTaskVo; import cn.datax.service.workflow.api.vo.FlowHistTaskVo;
...@@ -9,18 +11,24 @@ import cn.datax.service.workflow.service.FlowTaskService; ...@@ -9,18 +11,24 @@ import cn.datax.service.workflow.service.FlowTaskService;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.HistoryService; import org.flowable.engine.HistoryService;
import org.flowable.engine.TaskService; import org.flowable.engine.TaskService;
import org.flowable.engine.task.Comment;
import org.flowable.task.api.Task; import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery; import org.flowable.task.api.TaskQuery;
import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.api.history.HistoricTaskInstanceQuery; import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
@Slf4j
@Service @Service
public class FlowTaskServiceImpl implements FlowTaskService { public class FlowTaskServiceImpl implements FlowTaskService {
...@@ -92,4 +100,92 @@ public class FlowTaskServiceImpl implements FlowTaskService { ...@@ -92,4 +100,92 @@ public class FlowTaskServiceImpl implements FlowTaskService {
page.setTotal(count); page.setTotal(count);
return page; return page;
} }
@Override
public void execute(TaskRequest request) {
String action = request.getAction();
String processInstanceId = request.getProcessInstanceId();
String taskId = request.getTaskId();
String userId = request.getUserId();
String message = request.getMessage();
Map<String, Object> variables = request.getVariables();
log.info("执行任务类型:{},流程实例ID:{},执行任务ID:{},处理人ID:{},参数:{}", action, processInstanceId, taskId, userId, variables);
Assert.notNull(action, "请输入执行任务类型");
Assert.notNull(processInstanceId, "请输入流程实例ID");
Assert.notNull(taskId, "请输入任务ID");
ActionEnum actionEnum = ActionEnum.actionOf(action);
switch (actionEnum) {
case COMPLETE:
//完成任务
this.completeTask(taskId, variables, processInstanceId, message);
break;
case CLAIM:
//签收任务
this.claimTask(taskId, processInstanceId);
break;
case UNCLAIM:
//反签收
this.unClaimTask(taskId, processInstanceId);
break;
case DELEGATE:
//任务委派
this.delegateTask(taskId, userId, processInstanceId);
break;
case RESOLVE:
//任务归还
this.resolveTask(taskId, variables, processInstanceId);
break;
case ASSIGNEE:
//任务转办
this.assigneeTask(taskId, userId, processInstanceId);
break;
default:
break;
}
}
private void completeTask(String taskId, Map<String, Object> variables, String processInstanceId, String message) {
log.info("完成任务ID:{}", taskId);
Boolean approved = (Boolean) Optional.ofNullable(variables).map(s -> s.get(VariablesEnum.approved)).orElse(true);
this.addComment(ActionEnum.COMPLETE, taskId, processInstanceId, StrUtil.isBlank(message) ? (approved ? "默认同意" : "默认不同意") : message);
taskService.complete(taskId, variables);
}
private void claimTask(String taskId, String processInstanceId) {
log.info("签收任务ID:{},签收人ID:{}", taskId, SecurityUtil.getUserId());
this.addComment(ActionEnum.CLAIM, taskId, processInstanceId, null);
taskService.claim(taskId, SecurityUtil.getUserId());
}
private void unClaimTask(String taskId, String processInstanceId) {
log.info("反签收任务ID:{}", taskId);
this.addComment(ActionEnum.UNCLAIM, taskId, processInstanceId, null);
taskService.unclaim(taskId);
}
private void delegateTask(String taskId, String userId, String processInstanceId) {
log.info("委派任务ID:{},委派给用户ID:{}", taskId, userId);
this.addComment(ActionEnum.DELEGATE, taskId, processInstanceId, null);
taskService.delegateTask(taskId, userId);
}
private void resolveTask(String taskId, Map<String, Object> variables, String processInstanceId) {
log.info("任务归还ID:{}", taskId);
this.addComment(ActionEnum.RESOLVE, taskId, processInstanceId, null);
taskService.resolveTask(taskId);
taskService.complete(taskId, variables);
}
private void assigneeTask(String taskId, String userId, String processInstanceId) {
log.info("任务转办ID:{},移交给用户ID:{}", taskId, userId);
this.addComment(ActionEnum.ASSIGNEE, taskId, processInstanceId, null);
taskService.setAssignee(taskId, userId);
}
private void addComment(ActionEnum actionEnum, String taskId, String processInstanceId, String message) {
log.info("任务或者流程实例添加审批意见:任务ID:{},流程实例ID{}", taskId, processInstanceId);
Comment comment = taskService.addComment(taskId, processInstanceId, StrUtil.isBlank(message) ? actionEnum.getTitle() : message);
comment.setUserId(SecurityUtil.getUserId());
taskService.saveComment(comment);
}
} }
...@@ -247,7 +247,7 @@ export default { ...@@ -247,7 +247,7 @@ export default {
// 表格头 // 表格头
tableColumns: [ tableColumns: [
{ prop: 'id', label: '流程定义ID', show: true }, { prop: 'id', label: '流程定义ID', show: true },
{ prop: 'description', label: '流程名称', show: true }, { prop: 'name', label: '流程名称', show: true },
{ prop: 'version', label: '版本', show: true }, { prop: 'version', label: '版本', show: true },
{ {
prop: 'suspensionState', prop: 'suspensionState',
......
...@@ -126,13 +126,16 @@ export default { ...@@ -126,13 +126,16 @@ export default {
multiple: true, multiple: true,
// 表格头 // 表格头
tableColumns: [ tableColumns: [
{ prop: 'setName', label: '数据集名称', show: true }, { prop: 'processDefinitionId', label: '流程定义ID', show: true },
{ prop: 'processDefinitionName', label: '流程定义名称', show: true },
{ prop: 'name', label: '流程实列名称', show: true },
{ {
prop: 'status', prop: 'suspensionState',
label: '状态', label: '状态',
show: true show: true,
formatter: this.statusFormatter
}, },
{ prop: 'createTime', label: '创建时间', show: true } { prop: 'startTime', label: '开始时间', show: true }
], ],
// 表格数据 // 表格数据
tableDataList: [], tableDataList: [],
...@@ -253,6 +256,13 @@ export default { ...@@ -253,6 +256,13 @@ export default {
console.log(`当前页: ${val}`) console.log(`当前页: ${val}`)
this.queryParams.pageNum = val this.queryParams.pageNum = val
this.getList() this.getList()
},
statusFormatter(row, column, cellValue, index) {
if (cellValue === 1) {
return <el-tag type='success'>激活</el-tag>
} else if (cellValue === 2) {
return <el-tag type='warning'>挂起</el-tag>
}
} }
} }
} }
......
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