Commit 58f3af9f authored by suhuiguang's avatar suhuiguang

1.修改锁释放逻辑

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