通过redis来进行单据的单号重复判断

This commit is contained in:
jishenghua
2025-07-09 17:19:48 +08:00
parent ed90a47b61
commit 07d3d70cf6
2 changed files with 23 additions and 2 deletions

View File

@@ -73,6 +73,8 @@ public class DepotHeadService {
@Resource @Resource
private SequenceService sequenceService; private SequenceService sequenceService;
@Resource @Resource
private RedisService redisService;
@Resource
DepotItemMapperEx depotItemMapperEx; DepotItemMapperEx depotItemMapperEx;
@Resource @Resource
private LogService logService; private LogService logService;
@@ -1107,6 +1109,17 @@ public class DepotHeadService {
HttpServletRequest request) throws Exception { HttpServletRequest request) throws Exception {
/**处理单据主表数据*/ /**处理单据主表数据*/
DepotHead depotHead = JSONObject.parseObject(beanJson, DepotHead.class); DepotHead depotHead = JSONObject.parseObject(beanJson, DepotHead.class);
//判断用户是否已经登录过,登录过不再处理
User userInfo=userService.getCurrentUser();
//通过redis去校验重复
String keyNo = userInfo.getLoginName() + "_" + depotHead.getNumber();
String keyValue = redisService.getCacheObject(keyNo);
if(StringUtil.isNotEmpty(keyValue)) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_CODE,
String.format(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_MSG));
} else {
redisService.storageKeyWithTime(keyNo, depotHead.getNumber(), 10L);
}
//校验单号是否重复 //校验单号是否重复
if(checkIsBillNumberExist(0L, depotHead.getNumber())>0) { if(checkIsBillNumberExist(0L, depotHead.getNumber())>0) {
throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_CODE, throw new BusinessRunTimeException(ExceptionConstants.DEPOT_HEAD_BILL_NUMBER_EXIST_CODE,
@@ -1125,8 +1138,6 @@ public class DepotHeadService {
String.format(ExceptionConstants.DEPOT_HEAD_ACCOUNT_FAILED_MSG)); String.format(ExceptionConstants.DEPOT_HEAD_ACCOUNT_FAILED_MSG));
} }
} }
//判断用户是否已经登录过,登录过不再处理
User userInfo=userService.getCurrentUser();
depotHead.setCreator(userInfo==null?null:userInfo.getId()); depotHead.setCreator(userInfo==null?null:userInfo.getId());
depotHead.setCreateTime(new Timestamp(System.currentTimeMillis())); depotHead.setCreateTime(new Timestamp(System.currentTimeMillis()));
if(StringUtil.isEmpty(depotHead.getStatus())) { if(StringUtil.isEmpty(depotHead.getStatus())) {

View File

@@ -104,6 +104,16 @@ public class RedisService {
redisTemplate.opsForValue().set(verifyKey, codeNum, BusinessConstants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); redisTemplate.opsForValue().set(verifyKey, codeNum, BusinessConstants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES);
} }
/**
* 带有效时间缓存数据
* @param key
* @param value
* @param time 单位秒
*/
public void storageKeyWithTime(String key, String value, Long time) {
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
}
/** /**
* 删除单个对象 * 删除单个对象
* *