Commit 58f3af9f authored by suhuiguang's avatar suhuiguang

1.修改锁释放逻辑

parent 7ff2de81
......@@ -84,6 +84,7 @@ import java.lang.reflect.Modifier;
import java.net.URLEncoder;
import java.nio.file.Files;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
......@@ -962,8 +963,8 @@ public class CommonServiceImpl implements ICommonService {
String assignee = map.get("assignee").toString();
String lockKey = buildJgExecuteLockKey(instanceId);
RLock lock = redissonClient.getLock(lockKey);
boolean isLocked = lock.tryLock();
try {
boolean isLocked = lock.tryLock(0, 180, TimeUnit.SECONDS);
// 解决并发问题:多个人同时操作一个流程(并发执行通过、驳回、撤回)
if(!isLocked){
throw new BadRequest("当前流程已经被执行!");
......@@ -1012,13 +1013,14 @@ public class CommonServiceImpl implements ICommonService {
.nextTaskId(nextTaskId)
.promoter(commonMapper.selectPromoterData(tableName, instanceId)).build());
return Boolean.TRUE;
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if(isLocked){
if(lock.isHeldByCurrentThread()){
lock.unlock();
}
}
return Boolean.FALSE;
}
public void deleteTaskModel(String id) {
......
......@@ -51,6 +51,7 @@ import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
......@@ -452,46 +453,55 @@ public class JgChangeRegistrationNameServiceImpl extends BaseService<JgChangeReg
public void revocation(String instanceId, String taskId) {
String lockKey = CommonServiceImpl.buildJgExecuteLockKey(instanceId);
RLock lock = redissonClient.getLock(lockKey);
boolean isLocked = lock.tryLock();
// 解决并发问题:多个人同时操作一个流程(并发执行通过、驳回)
if(!isLocked){
throw new BadRequest("当前流程已经被执行!");
}
commonService.checkForRevocationFlow(taskId, instanceId);
// 执行流程
String taskCode = FlowStatusEnum.TO_BE_FINISHED.getName();
JgChangeRegistrationName jgChangeRegistrationName = new JgChangeRegistrationName();
LambdaQueryWrapper<JgChangeRegistrationName> lambda = new QueryWrapper<JgChangeRegistrationName>().lambda();
lambda.eq(JgChangeRegistrationName::getInstanceId, instanceId);
jgChangeRegistrationName = this.getOne(lambda);
List<String> roleListNext = new ArrayList<>();
List<String> roleListAll = new ArrayList<>();
ProcessTaskDTO processTaskDTO = cmWorkflowService.rollBack(instanceId);
String nextTaskId = processTaskDTO.getNextTask().get(0).getId();
this.buildRoleList(Collections.singletonList(processTaskDTO), roleListNext, roleListAll);
// 待调整
taskCode = processTaskDTO.getNextTask().get(0).getKey();
if (!FlowStatusEnum.TO_BE_FINISHED.getName().equals(taskCode)) {
jgChangeRegistrationName.setAuditStatus(WorkFlowStatusEnum.getMessage(taskCode).getRollBack());
try {
boolean isLocked = lock.tryLock(0, 180, TimeUnit.SECONDS);
// 解决并发问题:多个人同时操作一个流程(并发执行通过、驳回)
if(!isLocked){
throw new BadRequest("当前流程已经被执行!");
}
commonService.checkForRevocationFlow(taskId, instanceId);
// 执行流程
String taskCode = FlowStatusEnum.TO_BE_FINISHED.getName();
JgChangeRegistrationName jgChangeRegistrationName = new JgChangeRegistrationName();
LambdaQueryWrapper<JgChangeRegistrationName> lambda = new QueryWrapper<JgChangeRegistrationName>().lambda();
lambda.eq(JgChangeRegistrationName::getInstanceId, instanceId);
jgChangeRegistrationName = this.getOne(lambda);
List<String> roleListNext = new ArrayList<>();
List<String> roleListAll = new ArrayList<>();
ProcessTaskDTO processTaskDTO = cmWorkflowService.rollBack(instanceId);
String nextTaskId = processTaskDTO.getNextTask().get(0).getId();
this.buildRoleList(Collections.singletonList(processTaskDTO), roleListNext, roleListAll);
// 待调整
taskCode = processTaskDTO.getNextTask().get(0).getKey();
if (!FlowStatusEnum.TO_BE_FINISHED.getName().equals(taskCode)) {
jgChangeRegistrationName.setAuditStatus(WorkFlowStatusEnum.getMessage(taskCode).getRollBack());
}
jgChangeRegistrationName.setPromoter(RequestContext.getExeUserId());
jgChangeRegistrationName.setNextExecutorIds(String.join(",", roleListNext));
jgChangeRegistrationName.setNextTaskId(nextTaskId);
List<WorkflowResultDto> workflowResultDtos = commonService.buildWorkFlowInfo(Collections.singletonList(processTaskDTO));
// 更新下一步可执行人
String nextUserIds = workflowResultDtos.get(0).getNextExecutorUserIds();
jgChangeRegistrationName.setNextExecuteUserIds(nextUserIds);
this.updateById(jgChangeRegistrationName);
// 删除待办
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(jgChangeRegistrationName));
jsonObject.put("nextExecuteUser", jgChangeRegistrationName.getNextExecutorIds());
jsonObject.put("taskType", BusinessTypeEnum.JG_NAME_CHANGE_REGISTRATION.getCode());
jsonObject.put("flowStatus", this.getTaskCodeByName(jgChangeRegistrationName.getAuditStatus()));
jsonObject.put("flowStatusLabel", jgChangeRegistrationName.getAuditStatus());
jsonObject.put("changeCertificate", null);
// 判断撤回后当前的节点,如果当前节点为提交节点则页面可编辑
jsonObject.put("pageType", this.getPageTypeByCurrentNode(jgChangeRegistrationName.getAuditStatus()));
commonService.rollbackTask(instanceId, jsonObject);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if(lock.isHeldByCurrentThread()){
lock.unlock();
}
}
jgChangeRegistrationName.setPromoter(RequestContext.getExeUserId());
jgChangeRegistrationName.setNextExecutorIds(String.join(",", roleListNext));
jgChangeRegistrationName.setNextTaskId(nextTaskId);
List<WorkflowResultDto> workflowResultDtos = commonService.buildWorkFlowInfo(Collections.singletonList(processTaskDTO));
// 更新下一步可执行人
String nextUserIds = workflowResultDtos.get(0).getNextExecutorUserIds();
jgChangeRegistrationName.setNextExecuteUserIds(nextUserIds);
this.updateById(jgChangeRegistrationName);
// 删除待办
JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(jgChangeRegistrationName));
jsonObject.put("nextExecuteUser", jgChangeRegistrationName.getNextExecutorIds());
jsonObject.put("taskType", BusinessTypeEnum.JG_NAME_CHANGE_REGISTRATION.getCode());
jsonObject.put("flowStatus", this.getTaskCodeByName(jgChangeRegistrationName.getAuditStatus()));
jsonObject.put("flowStatusLabel", jgChangeRegistrationName.getAuditStatus());
jsonObject.put("changeCertificate", null);
// 判断撤回后当前的节点,如果当前节点为提交节点则页面可编辑
jsonObject.put("pageType", this.getPageTypeByCurrentNode(jgChangeRegistrationName.getAuditStatus()));
commonService.rollbackTask(instanceId, jsonObject);
}
private String getPageTypeByCurrentNode(String auditStatus) {
......@@ -511,8 +521,8 @@ public class JgChangeRegistrationNameServiceImpl extends BaseService<JgChangeReg
public void flowExecute(Long id, String instanceId, String operate, String comment) {
String lockKey = CommonServiceImpl.buildJgExecuteLockKey(instanceId);
RLock lock = redissonClient.getLock(lockKey);
boolean isLocked = lock.tryLock();
try {
boolean isLocked = lock.tryLock();
// 解决并发问题:多个人同时操作一个流程(并发执行通过、驳回)
if(!isLocked){
throw new BadRequest("当前流程已经被执行!");
......@@ -540,7 +550,7 @@ public class JgChangeRegistrationNameServiceImpl extends BaseService<JgChangeReg
// 更新下一步执行人、创建待办
updateExecuteIds(instanceId, id, operate, processTaskDTO);
} finally {
if(isLocked){
if(lock.isHeldByCurrentThread()){
lock.unlock();
}
}
......
......@@ -53,6 +53,7 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* 服务实现类
......@@ -632,9 +633,9 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
public void flowExecute(Long id, String instanceId, String operate, String comment, String carNumber, String nextTaskId) {
String lockKey = CommonServiceImpl.buildJgExecuteLockKey(instanceId);
RLock lock = redissonClient.getLock(lockKey);
boolean isLocked = lock.tryLock();
try {
// 解决并发问题:多个人同时操作一个流程(并发执行通过、驳回)
boolean isLocked = lock.tryLock(0, 180, TimeUnit.SECONDS);
// 解决并发问题:多个人同时操作一个流程(并发执行通过、驳回、撤回)
if(!isLocked){
throw new BadRequest("当前流程已经被执行!");
}
......@@ -667,8 +668,10 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
WorkflowResultDto workflowResultDto = resultDto.get(0);
updateData(jgUseRegistration.getSequenceNbr(), operate, workflowResultDto, Boolean.FALSE,carNumber);
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if(isLocked){
if(lock.isHeldByCurrentThread()){
lock.unlock();
}
}
......@@ -678,8 +681,8 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
public void withdraw(String instanceId, String nextTaskId) {
String lockKey = CommonServiceImpl.buildJgExecuteLockKey(instanceId);
RLock lock = redissonClient.getLock(lockKey);
boolean isLocked = lock.tryLock();
try {
boolean isLocked = lock.tryLock();
// 解决并发问题:多个人同时操作一个流程(并发执行通过、驳回、撤回)
if(!isLocked){
throw new BadRequest("当前流程已经被执行!");
......@@ -730,7 +733,7 @@ public class JgUseRegistrationServiceImpl extends BaseService<JgUseRegistrationD
// redis流程实时数据更新
commonServiceImpl.saveExecuteFlowData2Redis(instanceId, this.buildInstanceRuntimeData(data));
} finally {
if(isLocked){
if(lock.isHeldByCurrentThread()){
lock.unlock();
}
}
......
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