Commit d6986cfa authored by suhuiguang's avatar suhuiguang

1.删除可能由于日志打印查询导致的循环判断时间过长问题

parent aae6f77d
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import com.yeejoin.amos.boot.module.jg.api.dto.FlowingEquipRedisKeyDTO;
import com.yeejoin.amos.boot.module.jg.api.mapper.CommonMapper;
import com.yeejoin.amos.boot.module.jg.api.service.IEquipUsedCheck;
import com.yeejoin.amos.boot.module.jg.biz.context.FlowingEquipRedisContext;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBucket;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.Collections;
import java.util.List;
......@@ -23,8 +21,6 @@ import java.util.stream.Collectors;
@Slf4j
public abstract class BaseEquipUsedCheckService implements IEquipUsedCheck {
@Autowired
CommonMapper commonMapper;
/**
* 并发校验(页面同时提交或者页面同时打开多个时,某些设备都是为使用状态)校验设备流程在用状态及更新不在用为再使用状态
......@@ -44,26 +40,29 @@ public abstract class BaseEquipUsedCheckService implements IEquipUsedCheck {
RBucket<Set<String>> RBucket = getRedisClient().getBucket(this.getFlowingEquipRedisKey(companyCode, getApplyBizType()));
Set<String> equipListOfUsed = RBucket.get();
// 查询当前设备在流程中的申请单号列表
List<String> equipInUseList = commonMapper.findEquipInUseService(record);
if (equipListOfUsed != null && equipListOfUsed.contains(record)) {
String joinedEquipInUse = String.join(",", equipInUseList);
log.error("设备已被其他流程使用,不允许重复提交,设备ID:{},在流程中申请单:{}", record, joinedEquipInUse);
log.error("设备已被其他流程使用,不允许重复提交,设备ID:{}", record);
throw new BadRequest("设备已被其他流程使用,不允许重复提交,请联系管理员!");
}
if (equipListOfUsed == null || equipListOfUsed.isEmpty()) {
equipListOfUsed = new TreeSet<>();
}
equipListOfUsed.add(record);
getRedisClient().getBucket(this.getFlowingEquipRedisKey(companyCode, getApplyBizType())).set(equipListOfUsed);
FlowingEquipRedisContext.setRedisKeyInfo(new FlowingEquipRedisKeyDTO(this.getFlowingEquipRedisKey(companyCode, getApplyBizType()), Collections.singletonList(record)));
setUsingData2Redis(record, companyCode, equipListOfUsed);
} catch (InterruptedException e) {
e.printStackTrace();
log.error( e.getMessage(), e);
} finally {
if (lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
}
private void setUsingData2Redis(String record, String companyCode, Set<String> equipListOfUsed) {
if (equipListOfUsed == null || equipListOfUsed.isEmpty()) {
equipListOfUsed = new TreeSet<>();
}
equipListOfUsed.add(record);
getRedisClient().getBucket(this.getFlowingEquipRedisKey(companyCode, getApplyBizType())).set(equipListOfUsed);
FlowingEquipRedisContext.setRedisKeyInfo(new FlowingEquipRedisKeyDTO(this.getFlowingEquipRedisKey(companyCode, getApplyBizType()), Collections.singletonList(record)));
}
@Override
public void registrationRepeatUsedCheck(String record, String companyCode) {
RLock lock = getRedisClient().getLock(this.getRepeatUsedCheckLockKey(companyCode, getApplyBizType(), record));
......@@ -76,20 +75,13 @@ public abstract class BaseEquipUsedCheckService implements IEquipUsedCheck {
RBucket<Set<String>> RBucket = getRedisClient().getBucket(this.getFlowingEquipRedisKey(companyCode, getApplyBizType()));
Set<String> equipListOfUsed = RBucket.get();
// 查询当前设备在用的申请单号列表
List<String> equipInUseList = commonMapper.findEquipInUseService(record);
if (equipListOfUsed != null && equipListOfUsed.contains(record)) {
String joinedEquipInUse = String.join(",", equipInUseList);
log.error("使用登记证已被其他流程使用,不允许重复提交,设备ID:{},在流程中申请单:{}", record, joinedEquipInUse);
log.error("使用登记证已被其他流程使用,不允许重复提交,使用登记证ID:{}", record);
throw new BadRequest("使用登记证已被其他流程使用,不允许重复提交,请联系管理员!");
}
if (equipListOfUsed == null || equipListOfUsed.isEmpty()) {
equipListOfUsed = new TreeSet<>();
}
equipListOfUsed.add(record);
getRedisClient().getBucket(this.getFlowingEquipRedisKey(companyCode, getApplyBizType())).set(equipListOfUsed);
FlowingEquipRedisContext.setRedisKeyInfo(new FlowingEquipRedisKeyDTO(this.getFlowingEquipRedisKey(companyCode, getApplyBizType()), Collections.singletonList(record)));
setUsingData2Redis(record, companyCode, equipListOfUsed);
} catch (InterruptedException e) {
e.printStackTrace();
log.error( e.getMessage(), e);
} finally {
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