|
|
@ -26,17 +26,35 @@ |
|
|
|
package com.yxt.anrui.flowable.biz.flow; |
|
|
|
|
|
|
|
|
|
|
|
import com.yxt.anrui.flowable.api.flow.FlowTaskQuery; |
|
|
|
import com.yxt.anrui.flowable.api.flow.FlowTaskVo; |
|
|
|
import com.yxt.anrui.flowable.api.flow.FlowableFeign; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.yxt.anrui.flowable.api.flow.*; |
|
|
|
import com.yxt.anrui.flowable.api.flowtask.LatestTaskVo; |
|
|
|
import com.yxt.anrui.flowable.api.sysformlink.SysFormLinkFlowStateEnum; |
|
|
|
import com.yxt.anrui.flowable.api.utils.ProcDefEnum; |
|
|
|
import com.yxt.anrui.flowable.api.utils.ProcessStateEnum; |
|
|
|
import com.yxt.anrui.flowable.biz.flowtask.FlowTaskService; |
|
|
|
import com.yxt.anrui.flowable.common.FlowComment; |
|
|
|
import com.yxt.anrui.flowable.sqloperationsymbol.BusinessVariables; |
|
|
|
import com.yxt.anrui.portal.api.sysuser.SysUserFeign; |
|
|
|
import com.yxt.anrui.portal.api.sysuser.SysUserVo; |
|
|
|
import com.yxt.anrui.portal.api.sysuser.UserQuery; |
|
|
|
import com.yxt.common.base.utils.StringUtils; |
|
|
|
import com.yxt.common.core.query.PagerQuery; |
|
|
|
import com.yxt.common.core.result.ResultBean; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiParam; |
|
|
|
import org.flowable.engine.TaskService; |
|
|
|
import org.flowable.task.api.DelegationState; |
|
|
|
import org.flowable.task.api.Task; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
/** |
|
|
|
* Project: anrui-parent <br/> |
|
|
@ -58,6 +76,12 @@ public class FlowableRest implements FlowableFeign { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private FlowableService flowableService; |
|
|
|
@Autowired |
|
|
|
private FlowTaskService flowtaskService; |
|
|
|
@Autowired |
|
|
|
private SysUserFeign sysUserFeign; |
|
|
|
@Resource |
|
|
|
protected TaskService taskService; |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultBean businessStart(@ApiParam(value = "流程定义id") @PathVariable(value = "procDefId") String procDefId, |
|
|
@ -89,4 +113,220 @@ public class FlowableRest implements FlowableFeign { |
|
|
|
flowableService.deleteProcess(procInsId); |
|
|
|
return ResultBean.fireSuccess(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultBean<String> getNextNodeUserSidsOfCreate(Map<String, Object> variables) { |
|
|
|
String orgSidPath=(String)variables.get("orgSidPath"); |
|
|
|
//根据业务参数取流程流转的环节 信息
|
|
|
|
List<Map<String, Object>> list = (List<Map<String, Object>>) flowtaskService.getProcessCirculationNodesByMap(variables).getData(); |
|
|
|
//取第二个环节的配置角色
|
|
|
|
Object o = list.get(1).get("candidateGroups"); |
|
|
|
JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(o)); |
|
|
|
String roleSid = jsonArray.get(0).toString(); |
|
|
|
//根据组织架构、角色两个参数取相关符合条件的用户信息
|
|
|
|
UserQuery userQuery = new UserQuery(); |
|
|
|
userQuery.setRoleSid(roleSid); |
|
|
|
userQuery.setOrgSidPath(orgSidPath); |
|
|
|
List<SysUserVo> sysUserVos = sysUserFeign.getUserByRole(userQuery).getData(); |
|
|
|
StringBuilder nextNodeUserSids = new StringBuilder(); |
|
|
|
for (SysUserVo su : sysUserVos) { |
|
|
|
nextNodeUserSids.append(su.getSid()).append(","); |
|
|
|
} |
|
|
|
//符合条件的用户的sid,拼接的字符串
|
|
|
|
String nextNodeUserSids_ = nextNodeUserSids.toString(); |
|
|
|
nextNodeUserSids_ = nextNodeUserSids_.substring(0, nextNodeUserSids_.length() - 1); |
|
|
|
ResultBean rb = ResultBean.fireSuccess(); |
|
|
|
return rb.setData(nextNodeUserSids_); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultBean getNextNodeUserSidsOfSubmit(Map<String, Object> variables) { |
|
|
|
ResultBean rb = ResultBean.fireSuccess(); |
|
|
|
String orgSidPath=(String)variables.get("orgSidPath"); |
|
|
|
String taskDefKey=(String)variables.get("taskDefKey"); |
|
|
|
//根据业务参数取流程流转的环节 信息
|
|
|
|
List<Map<String, Object>> list = (List<Map<String, Object>>) flowtaskService.getProcessCirculationNodesByMap(variables).getData(); |
|
|
|
Map<String, Object> task_map=new HashMap<>(); |
|
|
|
//取第二个环节的配置角色
|
|
|
|
boolean endTask=true; |
|
|
|
for (int i=0;i< list.size();i++){ |
|
|
|
String id=list.get(i).get("id").toString(); |
|
|
|
if(id.equals(taskDefKey)){ |
|
|
|
task_map=list.get(i+1); |
|
|
|
endTask=false; |
|
|
|
} |
|
|
|
} |
|
|
|
if(endTask){ |
|
|
|
task_map.put("name","结束"); |
|
|
|
return rb.setData(""); |
|
|
|
}else{ |
|
|
|
//如果不是最后一个环节 要取下一个环节的角色sid
|
|
|
|
List<String> candidateGroups= (List<String>) task_map.get("candidateGroups"); |
|
|
|
String roleSid=candidateGroups.get(0); |
|
|
|
//根据组织架构、角色两个参数取相关符合条件的用户信息
|
|
|
|
UserQuery userQuery = new UserQuery(); |
|
|
|
userQuery.setRoleSid(roleSid); |
|
|
|
userQuery.setOrgSidPath(orgSidPath); |
|
|
|
List<SysUserVo> sysUserVos = sysUserFeign.getUserByRole(userQuery).getData(); |
|
|
|
StringBuilder nextNodeUserSids = new StringBuilder(); |
|
|
|
for (SysUserVo su : sysUserVos) { |
|
|
|
nextNodeUserSids.append(su.getSid()).append(","); |
|
|
|
} |
|
|
|
//符合条件的用户的sid,拼接的字符串
|
|
|
|
String nextNodeUserSids_ = nextNodeUserSids.toString(); |
|
|
|
nextNodeUserSids_ = nextNodeUserSids_.substring(0, nextNodeUserSids_.length() - 1); |
|
|
|
return rb.setData(nextNodeUserSids_); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultBean<UpdateFlowFieldVo> startProcess(StartProcessDto dto) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
String nextNodeUserSids_=getNextNodeUserSidsOfCreate(dto.getVariables()).getData(); |
|
|
|
dto.getVariables().put("nextNodeUserSids",nextNodeUserSids_); |
|
|
|
ResultBean resultBean1 = flowableService.businessStart(ProcDefEnum.BASEOUTSOURCINGAPPLICATION.getProDefId(), dto.getUserSid(), dto.getVariables()); |
|
|
|
UpdateFlowFieldVo vo = new UpdateFlowFieldVo(); |
|
|
|
if (resultBean1.getSuccess() && resultBean1.getData() != null) { |
|
|
|
vo.setSid("" + dto.getVariables().get("businessSid")); |
|
|
|
Map<String, String> map = (Map<String, String>) resultBean1.getData(); |
|
|
|
vo.setProcDefId(ProcDefEnum.BASEOUTSOURCINGAPPLICATION.getProDefId()); |
|
|
|
vo.setNodeState(map.get("nodeState")); |
|
|
|
vo.setProcInsId(map.get("procInsId")); |
|
|
|
vo.setTaskDefKey(map.get("taskDefKey")); |
|
|
|
vo.setTaskId(map.get("taskId")); |
|
|
|
vo.setNextNodeUserSids(nextNodeUserSids_); |
|
|
|
} |
|
|
|
return rb.success().setData(vo); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultBean handleProsess(BusinessVariables dto) { |
|
|
|
UpdateFlowFieldVo vo = new UpdateFlowFieldVo(); |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
Map<String, Object> formVariables = dto.getFormVariables(); |
|
|
|
String taskId = (String) formVariables.get("taskId"); |
|
|
|
if (StringUtils.isBlank(taskId)) { |
|
|
|
return rb.setMsg("taskId 不能为空!"); |
|
|
|
} |
|
|
|
String procInsId = (String) formVariables.get("instanceId"); |
|
|
|
ResultBean<String> resultBean = getNextNodeUserSidsOfSubmit(dto.getFormVariables()); |
|
|
|
String nextUserSid=resultBean.getData(); |
|
|
|
String comment = (String) formVariables.get("comment"); |
|
|
|
if (StringUtils.isBlank(comment)) { |
|
|
|
return rb.setMsg("comment 不能为空!"); |
|
|
|
} |
|
|
|
String instanceId = (String) formVariables.get("instanceId"); |
|
|
|
if (StringUtils.isBlank(instanceId)) { |
|
|
|
return rb.setMsg("instanceId 不能为空!"); |
|
|
|
} |
|
|
|
String userSid = (String) formVariables.get("userSid"); |
|
|
|
if (StringUtils.isBlank(userSid)) { |
|
|
|
return rb.setMsg("userSid 不能为空!"); |
|
|
|
|
|
|
|
} |
|
|
|
String businessSid = (String) formVariables.get("businessSid"); |
|
|
|
if (StringUtils.isBlank(businessSid)) { |
|
|
|
return rb.setMsg("业务sid 不能为空!"); |
|
|
|
} |
|
|
|
Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); |
|
|
|
if (Objects.isNull(task)) { |
|
|
|
return rb.setMsg("任务不存在"); |
|
|
|
} |
|
|
|
|
|
|
|
String nodeState = ""; |
|
|
|
String taskDefKey = ""; |
|
|
|
vo.setSid(businessSid); |
|
|
|
|
|
|
|
if (DelegationState.PENDING.equals(task.getDelegationState())) { |
|
|
|
taskService.addComment(taskId, instanceId, |
|
|
|
FlowComment.DELEGATE.getType(), comment); |
|
|
|
// Map<String,Object> values =(Map<String,Object>) formVariables.get("values");
|
|
|
|
taskService.resolveTask(taskId, formVariables); |
|
|
|
} else { |
|
|
|
taskService.addComment(taskId, instanceId, |
|
|
|
FlowComment.NORMAL.getType(), comment); |
|
|
|
//taskService.setAssignee(taskId, userSid);
|
|
|
|
//formVariables.remove("userSid");
|
|
|
|
taskService.complete(taskId, formVariables); |
|
|
|
|
|
|
|
//根据流程实例的id取最新的待办环节,给环节设置上用户sid
|
|
|
|
ResultBean<List<LatestTaskVo>> ll = flowtaskService.getLatestTasksNew(procInsId); |
|
|
|
if (ll.getData().size() > 0) { |
|
|
|
LatestTaskVo latestTaskVo = ll.getData().get(0); |
|
|
|
String id_ = latestTaskVo.getId_(); |
|
|
|
taskService.setAssignee(id_, nextUserSid); |
|
|
|
vo.setTaskId(id_); |
|
|
|
nodeState = latestTaskVo.getName_(); |
|
|
|
taskDefKey = latestTaskVo.getTask_def_key_(); |
|
|
|
} else { |
|
|
|
|
|
|
|
nodeState = ProcessStateEnum.FINISHED.getStateName(); |
|
|
|
taskDefKey = "Event_end"; |
|
|
|
vo.setNodeState(SysFormLinkFlowStateEnum.FINISH.getCode()); |
|
|
|
} |
|
|
|
} |
|
|
|
vo.setProcInsId(instanceId); |
|
|
|
vo.setProcDefId(task.getProcessDefinitionId()); |
|
|
|
vo.setNodeState(nodeState); |
|
|
|
vo.setTaskDefKey(taskDefKey); |
|
|
|
vo.setNextNodeUserSids(nextUserSid); |
|
|
|
return rb.setData(vo).success(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultBean revokeProcess(com.yxt.anrui.flowable.api.flowtask.FlowTaskVo fl) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
UpdateFlowFieldVo vo = new UpdateFlowFieldVo(); |
|
|
|
ResultBean<List<LatestTaskVo>> resultBean = flowtaskService.revokeProcess(fl); |
|
|
|
if (!resultBean.getSuccess()) { |
|
|
|
return rb; |
|
|
|
} |
|
|
|
String nodeState = resultBean.getData().get(0).getName_(); |
|
|
|
String taskDefKey = resultBean.getData().get(0).getTask_def_key_(); |
|
|
|
String incomingSourceRef = resultBean.getData().get(0).getIncomingSourceRef(); |
|
|
|
vo.setSid(fl.getBusinessSid()); |
|
|
|
if (incomingSourceRef.contains("start")) { |
|
|
|
vo.setNodeState(SysFormLinkFlowStateEnum.UNCOMMITTED.getState()); |
|
|
|
vo.setTaskDefKey(taskDefKey); |
|
|
|
} else { |
|
|
|
vo.setNodeState( nodeState); |
|
|
|
vo.setTaskDefKey( taskDefKey); |
|
|
|
} |
|
|
|
return rb.setData(vo).setSuccess(true); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultBean<UpdateFlowFieldVo> taskReject(com.yxt.anrui.flowable.api.flowtask.FlowTaskVo fl) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
UpdateFlowFieldVo vo = new UpdateFlowFieldVo(); |
|
|
|
ResultBean<List<LatestTaskVo>> resultBean = flowtaskService.taskReject(fl); |
|
|
|
if (!resultBean.getSuccess()) { |
|
|
|
return rb; |
|
|
|
} |
|
|
|
String nodeState = resultBean.getData().get(0).getName_(); |
|
|
|
String taskDefKey = resultBean.getData().get(0).getTask_def_key_(); |
|
|
|
String incomingSourceRef = resultBean.getData().get(0).getIncomingSourceRef(); |
|
|
|
vo.setSid(fl.getBusinessSid()); |
|
|
|
vo.setNodeState( nodeState); |
|
|
|
vo.setTaskDefKey( taskDefKey); |
|
|
|
if (incomingSourceRef.contains("start")) { |
|
|
|
vo.setNodeState( SysFormLinkFlowStateEnum.REJECT.getCode()); |
|
|
|
} |
|
|
|
return rb.setData(vo).setSuccess(true); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public ResultBean breakProcess(com.yxt.anrui.flowable.api.flowtask.FlowTaskVo fl) { |
|
|
|
ResultBean rb = ResultBean.fireFail(); |
|
|
|
UpdateFlowFieldVo vo = new UpdateFlowFieldVo(); |
|
|
|
ResultBean resultBean = flowableService.breakProcess(fl); |
|
|
|
if (!resultBean.getSuccess()) { |
|
|
|
return resultBean; |
|
|
|
} |
|
|
|
vo.setSid(fl.getBusinessSid()); |
|
|
|
vo.setNodeState( String.valueOf(resultBean.getData())); |
|
|
|
vo.setTaskDefKey( "Event_end"); |
|
|
|
return rb.setData(vo).setSuccess(true); |
|
|
|
} |
|
|
|
} |
|
|
|