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,7 +453,8 @@ 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();
try {
boolean isLocked = lock.tryLock(0, 180, TimeUnit.SECONDS);
// 解决并发问题:多个人同时操作一个流程(并发执行通过、驳回)
if(!isLocked){
throw new BadRequest("当前流程已经被执行!");
......@@ -492,6 +494,14 @@ public class JgChangeRegistrationNameServiceImpl extends BaseService<JgChangeReg
// 判断撤回后当前的节点,如果当前节点为提交节点则页面可编辑
jsonObject.put("pageType", this.getPageTypeByCurrentNode(jgChangeRegistrationName.getAuditStatus()));
commonService.rollbackTask(instanceId, jsonObject);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
if(lock.isHeldByCurrentThread()){
lock.unlock();
}
}
}
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