提交 2a201452 编写于 作者: zhouweidong's avatar zhouweidong

加签、获取流程参数逻辑优化

上级 6aaf6ad3
......@@ -142,26 +142,13 @@ public class ProcessInstanceListener extends AbstractFlowableEventListener {
// 多实例(会签)
if(event.getType() == FlowableEngineEventType.MULTI_INSTANCE_ACTIVITY_STARTED){
UserTask task = (UserTask) event.getExecution().getCurrentFlowElement();
List fieldList = task.getExtensionElements().get("field");
String strCandidate = "";
if(!ObjectUtils.isEmpty(fieldList)){
for (Object field : fieldList) {
if(!ObjectUtils.isEmpty(((ExtensionElement) field).getAttributes())){
List<ExtensionAttribute> attributes = ((ExtensionElement) field).getAttributes().get("name");
if(attributes.size() > 0){
if(attributes.get(0).getValue().equals("candidateUsersList")){
strCandidate = ((ExtensionElement) field).getChildElements().get("string").get(0).getElementText();
break;
}
}
}
String strCandidate = wfCoreService.getParam(task,"form","candidateUsersList");
if(StringUtils.isEmpty(strCandidate)){
throw new BadRequestAlertException("获取流程用户失败","","");
}
}
DelegateExecution execution = event.getExecution();
Set processRoles = new HashSet();
Set processUserIds = new HashSet();
LinkedHashMap executionMap = (LinkedHashMap) execution.getVariable("activedata");
String[] groups = strCandidate.split("\\|\\|");
if (groups.length > 0) {
......@@ -203,7 +190,6 @@ public class ProcessInstanceListener extends AbstractFlowableEventListener {
}
}
}
//设置会签用户
if(!ObjectUtils.isEmpty(processUserIds)){
event.getExecution().setVariableLocal("candidateUsersList",processUserIds);
......
......@@ -613,22 +613,24 @@ public class WFCoreService
Authentication.setAuthenticatedUserId(userId);
Authentication.setAuthenticationContext(createAuthenticationContext());
Task curTask = taskService.createTaskQuery().taskId(taskId).singleResult();
taskService.complete(taskId, variables,transientVariables);
WFProcessInstance instance = new WFProcessInstance();
instance.setBusinesskey(processInstanceBusinessKey);
Task curTask = taskService.createTaskQuery().taskId(taskId).singleResult();
//加签处理
if (curTask != null && DelegationState.PENDING != curTask.getDelegationState() && !StringUtils.isEmpty(curTask.getParentTaskId())) {
String tableName = managementService.getTableName(TaskEntity.class);
String sql = "select count(1) from " + tableName + " where PARENT_TASK_ID_=#{parentTaskId}";
long subTaskCount = taskService.createNativeTaskQuery().sql(sql).parameter("parentTaskId", curTask.getParentTaskId()).count();
//完成加签任务,激活主任务
if (subTaskCount == 0) {
taskService.resolveTask(curTask.getParentTaskId());
log.info("加签任务结束,激活主任务[{}]", curTask.getParentTaskId());
//加签任务处理
if (curTask != null && DelegationState.PENDING == curTask.getDelegationState()) {
if(userId.equals(curTask.getAssignee())){
taskService.resolveTask(taskId);
//saveTask(curTask);
}
else{
throw new BadRequestAlertException("当前任务正在加签中","","");
}
}
else{
//常规任务处理
taskService.complete(taskId, variables, transientVariables);
instance.setBusinesskey(processInstanceBusinessKey);
}
return instance;
}
......@@ -1306,7 +1308,6 @@ public class WFCoreService
public boolean beforeSign(String system, String appname,
String entity, String businessKey, String taskId, WFTaskWay taskWay) {
String userId=AuthenticationUser.getAuthenticationUser().getUserid();
if(StringUtils.isEmpty(userId))
if (StringUtils.isEmpty(userId))
throw new BadRequestAlertException("未传入当前用户", entity, businessKey);
......@@ -1314,25 +1315,15 @@ public class WFCoreService
if (ObjectUtils.isEmpty(signUsers)) {
throw new BadRequestAlertException("未传入加签用户", entity, businessKey);
}
//当前任务
Task curTask = taskService.createTaskQuery().taskId(taskId).singleResult();
if(curTask == null){
throw new BadRequestAlertException(String.format("未能获取到[%s]运行任务", curTask.getId()),"","");
if (curTask == null) {
throw new BadRequestAlertException(String.format("未能获取到[%s]运行任务", curTask.getId()), "", "");
}
if(DelegationState.PENDING != curTask.getDelegationState()){
//生成加签任务
for (String signUser : ((String) signUsers).split(",")) {
Task signTask = createTask(curTask);
signTask.setParentTaskId(curTask.getId());
taskService.saveTask(signTask);
taskService.addUserIdentityLink(signTask.getId(), signUser, "candidate");
}
//挂起主任务
taskService.delegateTask(taskId, userId);
log.info("用户[{}]发起加签操作,挂起[{}]主任务", userId, taskId);
}
else{
throw new BadRequestAlertException(String.format("任务正在加签中,无法进行二次加签", curTask.getId()),"","");
if (DelegationState.PENDING != curTask.getDelegationState()) {
taskService.delegateTask(taskId, String.valueOf(signUsers));
//saveTask(curTask);
} else {
throw new BadRequestAlertException(String.format("任务正在加签中,无法进行二次加签", curTask.getId()), "", "");
}
return true;
}
......@@ -1349,7 +1340,6 @@ public class WFCoreService
public boolean afterSign(String system,String appname,
String entity,String businessKey,String taskId,WFTaskWay taskWay){
String userId=AuthenticationUser.getAuthenticationUser().getUserid();
if(StringUtils.isEmpty(userId))
if (StringUtils.isEmpty(userId))
throw new BadRequestAlertException("未传入当前用户", entity, businessKey);
......@@ -1362,16 +1352,11 @@ public class WFCoreService
throw new BadRequestAlertException(String.format("未能获取到[%s]运行任务", taskId),"","");
}
log.info("用户[{}]发起转办操作,将任务[{}]转办至[{}]用户", userId, taskId,signUser);
//转办任务
taskService.deleteUserIdentityLink(curTask.getId(),userId,"candidate");
taskService.addUserIdentityLink(curTask.getId(), (String) signUser,"candidate");
//提交当前任务
Task signTask = createTask(curTask);
taskService.saveTask(signTask);
// taskService.addUserIdentityLink(signTask.getId(), String.valueOf(signUser), "candidate");
taskService.complete(signTask.getId());
//saveTask(curTask);
return true;
}
......@@ -1480,56 +1465,84 @@ public class WFCoreService
/**
* 设置流程表单
*
* @param sequenceFlow
* @param way
*/
private void setTaskWayForm(SequenceFlow sequenceFlow,WFTaskWay way){
if(!ObjectUtils.isEmpty(sequenceFlow.getExtensionElements())){
List<ExtensionElement> formProps=sequenceFlow.getExtensionElements().get("form");
if(!ObjectUtils.isEmpty(formProps)){
for(ExtensionElement prop : formProps){
if(!ObjectUtils.isEmpty(prop.getAttributes())){
for(String attribute : prop.getAttributes().keySet()){
List<ExtensionAttribute> attributes=prop.getAttributes().get(attribute);
if(!ObjectUtils.isEmpty(attributes)){
for(ExtensionAttribute param:attributes){
way.set(param.getName(),param.getValue());
}
}
}
}
}
private void setTaskWayForm(SequenceFlow sequenceFlow, WFTaskWay way) {
Map<String,String> attributes = getAllParam(sequenceFlow,"form");
if (!ObjectUtils.isEmpty(attributes)) {
for (Map.Entry<String,String> entry : attributes.entrySet()) {
way.set(entry.getKey(), entry.getValue());
}
}
}
/**
* 将流程表单设置到请求头中
*
* @param userTask
*/
private void setProcessForm(UserTask userTask){
Object objReq=RequestContextHolder.currentRequestAttributes();
if(!ObjectUtils.isEmpty(objReq) && objReq instanceof ServletRequestAttributes){
private void setProcessForm(UserTask userTask) {
Object objReq = RequestContextHolder.currentRequestAttributes();
if (!ObjectUtils.isEmpty(objReq) && objReq instanceof ServletRequestAttributes) {
ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
HttpServletRequest req = attr.getRequest();
if(!ObjectUtils.isEmpty(userTask) && !ObjectUtils.isEmpty(userTask.getExtensionElements())){
List<ExtensionElement> formProps=userTask.getExtensionElements().get("form");
if(!ObjectUtils.isEmpty(formProps)){
for(ExtensionElement prop : formProps){
if(!ObjectUtils.isEmpty(prop.getAttributes())){
for(String attribute : prop.getAttributes().keySet()){
List<ExtensionAttribute> attributes=prop.getAttributes().get(attribute);
if(!ObjectUtils.isEmpty(attributes)){
for(ExtensionAttribute param:attributes){
req.setAttribute(param.getName(),param.getValue());
Map<String,String> attributes = getAllParam(userTask,"form");
if (!ObjectUtils.isEmpty(attributes)) {
for (Map.Entry<String,String> entry : attributes.entrySet()) {
req.setAttribute(entry.getKey(), entry.getValue());
}
}
}
}
/**
* 获取流程节点指定参数
* @param element
* @param property
* @param attribute
* @return
*/
public String getParam(FlowElement element, String property, String attribute) {
List<ExtensionElement> formProps = element.getExtensionElements().get(property);
if (formProps == null) {
return null;
}
for (ExtensionElement prop : formProps) {
if (prop.getAttributes() == null)
return null;
Map<String, List<ExtensionAttribute>> attributes = prop.getAttributes();
if (attributes.containsKey(attribute)) {
return ObjectUtils.isEmpty(attributes.get(attribute)) ? null : String.valueOf(attributes.get(attribute).get(0).getValue());
}
}
return null;
}
/**
* 获取流程节点所有参数
* @param element
* @param property
* @return
*/
public Map<String, String> getAllParam(FlowElement element, String property) {
Map<String, String> params = new HashMap();
List<ExtensionElement> formProps = element.getExtensionElements().get(property);
if (formProps == null) {
return null;
}
for (ExtensionElement prop : formProps) {
if (prop.getAttributes() == null)
return null;
Map<String, List<ExtensionAttribute>> attributes = prop.getAttributes();
for (String attribute : attributes.keySet()) {
if (!ObjectUtils.isEmpty(attributes.get(attribute))) {
params.put(attribute, attributes.get(attribute).get(0).getValue());
}
}
}
return params;
}
/**
......@@ -1589,19 +1602,8 @@ public class WFCoreService
if (!ObjectUtils.isEmpty(execution.getCurrentFlowElement()) && execution.getCurrentFlowElement() instanceof UserTask) {
UserTask userTask = (UserTask) execution.getCurrentFlowElement();
for (SequenceFlow flow : userTask.getOutgoingFlows()) {
if (sequenceFlowId.equals(flow.getId()) && !ObjectUtils.isEmpty(flow.getExtensionElements().get("form"))) {
for (ExtensionElement formProp : flow.getExtensionElements().get("form")) {
for (String attribute : formProp.getAttributes().keySet()) {
List<ExtensionAttribute> attributes = formProp.getAttributes().get(attribute);
if (!ObjectUtils.isEmpty(attributes)) {
for (ExtensionAttribute param : attributes) {
if (param.getName().equalsIgnoreCase("nextCondition")) {
return param.getValue();
}
}
}
}
}
if (sequenceFlowId.equals(flow.getId())) {
return getParam(flow, "form", "nextCondition");
}
}
}
......@@ -1616,25 +1618,11 @@ public class WFCoreService
*/
public Set<String> getRoleByUserId(String userId, DelegateExecution execution) {
Set roles = new HashSet();
if(!ObjectUtils.isEmpty(userId)){
UserTask task = (UserTask) execution.getCurrentFlowElement();
List fieldList = task.getExtensionElements().get("field");
String strCandidate = "";
if(!ObjectUtils.isEmpty(fieldList)){
for (Object field : fieldList) {
if(!ObjectUtils.isEmpty(((ExtensionElement) field).getAttributes())){
List<ExtensionAttribute> attributes = ((ExtensionElement) field).getAttributes().get("name");
if(attributes.size() > 0){
if(attributes.get(0).getValue().equals("candidateUsersList")){
strCandidate = ((ExtensionElement) field).getChildElements().get("string").get(0).getElementText();
break;
}
}
}
}
}
if (!ObjectUtils.isEmpty(userId)) {
String candidateUsers = getParam(execution.getCurrentFlowElement(),"form","candidateUsersList");
if (!StringUtils.isEmpty(candidateUsers)) {
LinkedHashMap executionMap = (LinkedHashMap) execution.getVariable("activedata");
String[] groups = strCandidate.split("\\|\\|");
String[] groups = candidateUsers.split("\\|\\|");
if (groups.length > 0) {
for (String group : groups) {
if (group.contains("activedata")) {
......@@ -1643,9 +1631,9 @@ public class WFCoreService
StandardEvaluationContext context = new StandardEvaluationContext();
Expression exp = parser.parseExpression(elUserId);
context.addPropertyAccessor(new MapAccessor());
context.setVariable("activedata",executionMap);
String processUserId = exp.getValue(context,String.class);
if(!StringUtils.isEmpty(processUserId) && processUserId.contains(userId)){
context.setVariable("activedata", executionMap);
String processUserId = exp.getValue(context, String.class);
if (!StringUtils.isEmpty(processUserId) && processUserId.contains(userId)) {
roles.add(group);
}
}
......@@ -1658,13 +1646,12 @@ public class WFCoreService
Expression oldExp = parser.parseExpression(exp);
List<WFMember> users = oldExp.getValue(oldContext, List.class);
if (!StringUtils.isEmpty(users)) {
users.forEach(groupMember->{
if(!ObjectUtils.isEmpty(groupMember.getUserid()) && userId.equals(groupMember.getUserid())){
users.forEach(groupMember -> {
if (!ObjectUtils.isEmpty(groupMember.getUserid()) && userId.equals(groupMember.getUserid())) {
String roleId;
if(!ObjectUtils.isEmpty(groupMember.getMdeptid())){
roleId = String.format("%s_%s",groupMember.getGroupid(),groupMember.getMdeptid());
}
else{
if (!ObjectUtils.isEmpty(groupMember.getMdeptid())) {
roleId = String.format("%s_%s", groupMember.getGroupid(), groupMember.getMdeptid());
} else {
roleId = groupMember.getGroupid();
}
roles.add(roleId);
......@@ -1675,6 +1662,7 @@ public class WFCoreService
}
}
}
}
return roles;
}
......@@ -1739,7 +1727,7 @@ public class WFCoreService
public Set<String> getUsersByRole(Set roles, DelegateExecution execution) {
Set userIds = new HashSet();
if (!ObjectUtils.isEmpty(roles)) {
String candidateUsers = getCandidateUsers(execution);
String candidateUsers = getParam(execution.getCurrentFlowElement(),"form","candidateUsersList");
if (!StringUtils.isEmpty(candidateUsers)) {
LinkedHashMap executionMap = (LinkedHashMap) execution.getVariable("activedata");
String[] groups = candidateUsers.split("\\|\\|");
......@@ -1788,28 +1776,22 @@ public class WFCoreService
}
/**
* 获取步骤审批用户
* @param execution
* 审批记录
* @param curTask
* @return
*/
private String getCandidateUsers(DelegateExecution execution){
String strCandidateUsers ="";
UserTask task = (UserTask) execution.getCurrentFlowElement();
List fieldList = task.getExtensionElements().get("field");
if(!ObjectUtils.isEmpty(fieldList)){
for (Object field : fieldList) {
if(!ObjectUtils.isEmpty(((ExtensionElement) field).getAttributes())){
List<ExtensionAttribute> attributes = ((ExtensionElement) field).getAttributes().get("name");
if(attributes.size() > 0){
if(attributes.get(0).getValue().equals("candidateUsersList")){
strCandidateUsers = ((ExtensionElement) field).getChildElements().get("string").get(0).getElementText();
break;
}
}
}
}
}
return strCandidateUsers;
private Task saveTask(Task curTask){
String userId = "0100";
if (StringUtils.isEmpty(userId))
if (StringUtils.isEmpty(userId))
throw new BadRequestAlertException("未传入当前用户", "", "");
Task signTask = createTask(curTask);
signTask.setParentTaskId(curTask.getId());
taskService.saveTask(signTask);
taskService.addUserIdentityLink(signTask.getId(), userId, "candidate");
taskService.complete(signTask.getId());
return signTask;
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册