Преглед изворни кода

perf(消费服务): 人员账户验证处理

1.人员账户数据默认从缓存获取,如果缓存不存在则从数据库获取并初始人化缓存
autumnal_wind пре 11 месеци
родитељ
комит
679c536e11

+ 1 - 0
ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java

@@ -193,6 +193,7 @@ public interface CacheNames {
      */
     String PT_USER_ACCOUNT_ID = "pt_user_account_id";
     String PT_USER_ACCOUNT_NO = "pt_user_account_no";
+    String PT_USER_ACCOUNT_NUMB = "pt_user_account_numb";
     String PT_USER_ACCOUNT_LIST = "pt_user_account_list";
     /**
      * 营业时段/餐类

+ 39 - 46
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/payment/service/impl/PtUserAccountServiceImpl.java

@@ -1,6 +1,7 @@
 package org.dromara.backstage.payment.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.lang.UUID;
@@ -14,6 +15,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.dubbo.config.annotation.DubboReference;
+import org.dromara.backstage.basics.domain.bo.PtCardtypeBo;
 import org.dromara.backstage.basics.domain.vo.PtCardtypeVo;
 import org.dromara.backstage.basics.service.IPtCardtypeService;
 import org.dromara.backstage.cardCenter.domain.bo.PtCardBo;
@@ -90,7 +92,7 @@ public class PtUserAccountServiceImpl implements IPtUserAccountService {
      */
     @Override
     public PtUserAccountVo queryById(Long userId) {
-        PtUserAccountVo vo = TenantHelper.ignore(()->baseMapper.selectVoById(userId));
+        PtUserAccountVo vo = TenantHelper.ignore(() -> baseMapper.selectVoById(userId));
         if (vo != null && ObjectUtil.isNotEmpty(vo.getDeptId())) {
             RemoteDeptVo remoteDeptVo = remoteDeptService.selectDeptById(vo.getDeptId());
             vo.setDeptName(remoteDeptVo.getDeptName());
@@ -147,10 +149,18 @@ public class PtUserAccountServiceImpl implements IPtUserAccountService {
         LambdaQueryWrapper<PtUserAccount> lqw = buildQueryWrapper(bo);
         List<PtUserAccountVo> accountVoList = baseMapper.selectVoList(lqw);
         List<RemoteDeptVo> deptVoList = remoteDeptService.selectDeptList();
-        accountVoList.forEach(p->{
+        PtCardtypeBo cardTypeBo = new PtCardtypeBo();
+        cardTypeBo.setStatus("0");
+
+        List<PtCardtypeVo> cardTypeVos = cardTypeService.queryList(cardTypeBo);
+        accountVoList.forEach(p -> {
             String deptName = deptVoList.parallelStream().filter(k -> k.getDeptId().equals(p.getDeptId()))
-                                  .findFirst().map(RemoteDeptVo::getDeptName).orElse("未知部门");
+                .findFirst().map(RemoteDeptVo::getDeptName).orElse("未知部门");
             p.setDeptName(deptName);
+
+            String cardTypeNme = cardTypeVos.parallelStream().filter(k -> k.getCode().equals(p.getCardType()))
+                .findFirst().map(PtCardtypeVo::getTypeName).orElse("未知卡类");
+            p.setCardTypeName(cardTypeNme);
         });
         return accountVoList;
     }
@@ -164,18 +174,18 @@ public class PtUserAccountServiceImpl implements IPtUserAccountService {
         LambdaQueryWrapper<PtUserAccount> lqw = Wrappers.lambdaQuery();
         lqw.eq(bo.getUserId() != null, PtUserAccount::getUserId, bo.getUserId());
         lqw.eq(bo.getPostId() != null, PtUserAccount::getPostId, bo.getPostId());
-       lqw.eq(bo.getDeptId() != null, PtUserAccount::getDeptId, bo.getDeptId());
+        lqw.eq(bo.getDeptId() != null, PtUserAccount::getDeptId, bo.getDeptId());
         lqw.like(StringUtils.isNotBlank(bo.getUserName()), PtUserAccount::getUserName, bo.getUserName());
         // lqw.eq(StringUtils.isNotBlank(bo.getPassword()), PtUserAccount::getPassword, bo.getPassword());
         lqw.eq(StringUtils.isNotBlank(bo.getUserNumb()), PtUserAccount::getUserNumb, bo.getUserNumb());
         // lqw.like(StringUtils.isNotBlank(bo.getNickName()), PtUserAccount::getNickName, bo.getNickName());
         lqw.like(StringUtils.isNotBlank(bo.getRealName()), PtUserAccount::getRealName, bo.getRealName());
         lqw.eq(StringUtils.isNotBlank(bo.getSex()), PtUserAccount::getSex, bo.getSex());
-        if(StringUtils.isNotBlank(bo.getCategory())){
+        if (StringUtils.isNotBlank(bo.getCategory())) {
             List<String> list = Arrays.asList(bo.getCategory().split(","));
-            if(list.size()>1){
+            if (list.size() > 1) {
                 lqw.in(StringUtils.isNotBlank(bo.getCategory()), PtUserAccount::getCategory, list);
-            } else{
+            } else {
                 lqw.eq(PtUserAccount::getCategory, bo.getCategory());
             }
         }
@@ -502,7 +512,7 @@ public class PtUserAccountServiceImpl implements IPtUserAccountService {
 
         if (ObjUtil.isNotNull(redisList) && !redisList.isEmpty()) {
             vo = redisList.stream().filter(p -> Objects.equals(p.getRealName(), realName)
-            && Objects.equals(p.getUserNumb(),userNumb)).findFirst().orElse(null);
+                && Objects.equals(p.getUserNumb(), userNumb)).findFirst().orElse(null);
             if (ObjUtil.isNotNull(vo)) {
                 return vo;
             }
@@ -530,39 +540,19 @@ public class PtUserAccountServiceImpl implements IPtUserAccountService {
         bo.setUserNo(userNo);
         return this.selectVoOneByBo(bo);
     }
+
     @Override
     public PtUserAccountVo getUserAccountVoByUserNumb(String userNumb) {
-        PtUserAccountVo vo;
-        List<PtUserAccountVo> redisList = RedisUtils.getCacheList(CacheNames.PT_USER_ACCOUNT);
-
-        if (ObjUtil.isNotNull(redisList) && !redisList.isEmpty()) {
-            vo = redisList.stream().filter(p -> Objects.equals(p.getUserNumb(), userNumb)).findFirst().orElse(null);
-            if (ObjUtil.isNotNull(vo)) {
-                return vo;
-            }
-        }
-
         PtUserAccountBo bo = new PtUserAccountBo();
         bo.setUserNumb(userNumb);
         return this.selectVoOneByBo(bo);
     }
+
     @Override
     public PtUserAccountVo selectVoOneByBo(PtUserAccountBo bo) {
         List<PtUserAccountVo> list = this.queryList(bo);
         if (ObjectUtil.isNotEmpty(list) && !list.isEmpty()) {
-            PtUserAccountVo vo = list.get(0);
-            if (vo != null) {
-                String deptName = remoteDeptService.selectDeptNameByIds(vo.getDeptId().toString());
-                vo.setDeptName(deptName);
-
-                PtCardtypeVo cardTypeVo  = cardTypeService.queryByCode(vo.getCardType());
-                if  (cardTypeVo != null) {
-                    vo.setCardTypeName(cardTypeVo.getTypeName());
-                }
-
-                RedisUtils.addCacheList(CacheNames.PT_USER_ACCOUNT, vo);
-                return vo;
-            }
+            return list.get(0);
         }
         return null;
     }
@@ -571,19 +561,22 @@ public class PtUserAccountServiceImpl implements IPtUserAccountService {
     public YcTraineeVo selectTraineeByBo(PtUserAccountBo bo, Date doingDate) {
         return TenantHelper.ignore(() -> baseMapper.selectTraineeByBo(bo, doingDate));
     }
+
     /**
      * 删除指定部门下的一卡通账户信息
-     * @param deptId 部门Id
+     *
+     * @param deptId     部门Id
      * @param operatorId 操作员Id
      * @return 删除结果
      */
     @Override
     public int deleteByDeptId(Long deptId, Long operatorId) {
         LambdaUpdateWrapper<PtUserAccount> luw = new LambdaUpdateWrapper<PtUserAccount>().set(PtUserAccount::getDelFlag, DefaultConstants.DELETED)
-                                               .set(PtUserAccount::getUpdateBy, operatorId)
-                                               .eq(PtUserAccount::getDeptId, deptId);
+            .set(PtUserAccount::getUpdateBy, operatorId)
+            .eq(PtUserAccount::getDeptId, deptId);
         return baseMapper.update(null, luw);
     }
+
     /**
      * 根据第三方Id删除人员账户信息
      *
@@ -603,9 +596,9 @@ public class PtUserAccountServiceImpl implements IPtUserAccountService {
             // 如果存在账户信息,则先注销卡片
             ptCardService.cancelCard(userId, operatorId);
             LambdaUpdateWrapper<PtUserAccount> luw = new LambdaUpdateWrapper<PtUserAccount>().set(PtUserAccount::getDelFlag, DefaultConstants.DELETED)
-                                                         .set(PtUserAccount::getUpdateBy, operatorId)
-                                                         .eq(PtUserAccount::getDeptId, deptId)
-                                                         .eq(PtUserAccount::getDeptId, deptId);
+                .set(PtUserAccount::getUpdateBy, operatorId)
+                .eq(PtUserAccount::getDeptId, deptId)
+                .eq(PtUserAccount::getDeptId, deptId);
             return baseMapper.update(null, luw);
         }
         return 0;
@@ -613,16 +606,16 @@ public class PtUserAccountServiceImpl implements IPtUserAccountService {
 
     @Override
     public PtUserAccount4SelectVo getCardInfoByFactoryId(String factoryId) {
-        if (StringUtils.isBlank(factoryId)){
+        if (StringUtils.isBlank(factoryId)) {
             return null;
         }
         List<PtUserAccount4SelectVo> list = baseMapper.getCardInfoByFactoryId(factoryId);
-        if (list.isEmpty()){
+        if (list.isEmpty()) {
             return null;
         }
         PtUserAccount4SelectVo res = list.get(0);
-        if(StringUtils.isNotBlank(res.getCardStatus())){
-            String cardStatusName = dictService.getDictLabel("KZT",  res.getCardStatus());
+        if (StringUtils.isNotBlank(res.getCardStatus())) {
+            String cardStatusName = dictService.getDictLabel("KZT", res.getCardStatus());
             res.setCardStatus(cardStatusName);
         }
         return res;
@@ -642,17 +635,17 @@ public class PtUserAccountServiceImpl implements IPtUserAccountService {
         LambdaQueryWrapper<PtUserAccount> lqw = Wrappers.lambdaQuery();
         lqw.eq(userId != null, PtUserAccount::getUserId, userId);
         List<PtUserAccountVo> userAccounts = baseMapper.selectVoList(lqw);
-        if(CollectionUtil.isEmpty(userAccounts)){
+        if (CollectionUtil.isEmpty(userAccounts)) {
             return res;
         }
         // 正常卡信息
         PtCardBo ptCardBo = new PtCardBo();
         ptCardBo.setStatus(CardStatusEnum.NORMAL.code().toString());
-        if(userId != null){
+        if (userId != null) {
             ptCardBo.setUserId(userId);
         }
         List<PtCardVo> cards = ptCardService.getList(ptCardBo);
-        if(CollectionUtil.isEmpty(cards)){
+        if (CollectionUtil.isEmpty(cards)) {
             return userAccounts;
         }
 
@@ -664,11 +657,11 @@ public class PtUserAccountServiceImpl implements IPtUserAccountService {
             Optional<PtCardVo> first = cards.stream()
                 .filter(p -> Objects.equals(p.getUserId(), id))
                 .sorted(Comparator.comparing(PtCardVo::getChangeTime).reversed()).findFirst();
-            if(first.isPresent()){
+            if (first.isPresent()) {
                 ptCardVo = first.get();
             }
             userAccount.setCard(ptCardVo);
-            userAccount.setFacePicUrl(photoPrefix+userAccount.getPhoto());
+            userAccount.setFacePicUrl(photoPrefix + userAccount.getPhoto());
 
             res.add(userAccount);
         }

+ 14 - 4
ruoyi-server/ruoyi-server-common/src/main/java/org/dromara/server/common/constant/ConsumeConstants.java

@@ -20,10 +20,20 @@ public interface ConsumeConstants {
         put("4", "夜宵");
     }};
 
-    // 用户校验模式 0-userId 1- userNo 2-userNumb
-    Integer userIdMode = 0;
-    Integer userNoMode = 1;
-    Integer userNumbMode = 2;
+    /**
+     * 根据用户Id获取账户信息
+     */
+    int USER_ID = 0;
+
+    /**
+     * 根据用户流水号获取用户信息
+     */
+    int USER_NO = 1;
+
+    /**
+     * 根据用户编号获取用户信息
+     */
+    int USER_NUMB = 2;
     // 卡片校验模式 0-userId 1- cardNo
     /**
      * 根据userId获取卡片

+ 52 - 31
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/EmployeeBusiness.java

@@ -13,6 +13,8 @@ import org.dromara.common.core.domain.model.ErrorResult;
 import org.dromara.common.core.enums.ResultCodeEnum;
 import org.dromara.common.json.utils.JsonUtils;
 import org.dromara.common.redis.utils.RedisUtils;
+import org.dromara.server.common.constant.ConsumeConstants;
+import org.dromara.server.consume.cache.UserAccountCacheManager;
 import org.dromara.server.consume.domain.vo.yc.*;
 import org.dromara.system.api.RemoteDeptService;
 import org.dromara.system.api.domain.vo.RemoteDeptVo;
@@ -33,15 +35,15 @@ import java.util.List;
 @Service
 @RequiredArgsConstructor
 public class EmployeeBusiness {
+    private final UserAccountCacheManager userAccountCacheManager;
+    private final CardBusiness cardBusiness;
+
     @DubboReference
     private final RemoteDeptService remoteDeptService;
 
     public ReturnResult getEmployeeVoByNumb(String userNumb) {
-        List<RemoteUserAccountVo> list = RedisUtils.getCacheList(CacheNames.PT_USER_ACCOUNT_LIST);
-        RemoteUserAccountVo userAccountVo = list.parallelStream()
-            .filter(p -> userNumb.equals(p.getUserNumb()))
-            .findFirst().orElse(null);
-        if (userAccountVo==null) {
+        RemoteUserAccountVo userAccountVo = getAccountFromCache(userNumb, ConsumeConstants.USER_NUMB);
+        if (userAccountVo == null) {
             ErrorResult result = new ErrorResult();
             result.setStatusCode(HttpStatus.NOT_FOUND.value());
             result.setMessage("获取用户信息失败");
@@ -52,42 +54,61 @@ public class EmployeeBusiness {
         }
         return ReturnResult.success(setReturnEmployeeVo(userAccountVo));
     }
+    /**
+     * 从缓存获取账户信息
+     *
+     * @param checkParam 用户标识
+     * @param checkMode  校验模式
+     * @return 账户信息对象
+     */
+    public RemoteUserAccountVo getAccountFromCache(String checkParam, Integer checkMode) {
+        switch (checkMode) {
+            case ConsumeConstants.USER_ID -> {
+                return userAccountCacheManager.getByUserId(Long.valueOf(checkParam));
+            }
+            case ConsumeConstants.USER_NO -> {
+                return userAccountCacheManager.getByUserNo(Long.valueOf(checkParam));
+            }
+            case ConsumeConstants.USER_NUMB -> {
+                return userAccountCacheManager.getByUserNumb(checkParam);
+            }
+        }
+        return null;
+    }
 
     private Object setReturnEmployeeVo(RemoteUserAccountVo userAccountVo) {
-        RemoteDeptVo remoteDeptVo = remoteDeptService.selectDeptById(userAccountVo.getDeptId());
+        // RemoteDeptVo remoteDeptVo = remoteDeptService.selectDeptById(userAccountVo.getDeptId());
         DepartmentVo departmentVo = new DepartmentVo();
-        departmentVo.setDepartmentID(remoteDeptVo.getDeptId().toString());
-        departmentVo.setParentDepartmentID(remoteDeptVo.getParentId().toString());
-        departmentVo.setDepartmentName(remoteDeptVo.getDeptName());
+        departmentVo.setDepartmentID(userAccountVo.getDeptId().toString());
+        // departmentVo.setParentDepartmentID(remoteDeptVo.getParentId().toString());
+        departmentVo.setDepartmentName(userAccountVo.getDeptName());
 
-        String userId = String.valueOf(userAccountVo.getUserId());
-        Object objCard = RedisUtils.getCacheMapValue(CacheNames.PT_USER_CARD_USER_ID, userId);
-        if (objCard == null) {
-            log.info("无人员卡片信息,userNumb:{},userId:{}", userAccountVo.getUserNumb(), userAccountVo.getUserId());
+        Long userId = userAccountVo.getUserId();
+        RemoteCardVo remoteCardVo = cardBusiness.getCardFromCache(userId, ConsumeConstants.CARD_USER);
+
+        if (remoteCardVo == null) {
+            log.warn("无人员有效卡片信息,userNumb:{},userId:{}", userAccountVo.getUserNumb(), userAccountVo.getUserId());
             return null;
         }
-        RemoteCardVo remoteCardVo = JsonUtils.parseObject(objCard.toString(), RemoteCardVo.class);
         UserCardVo userCardVo = new UserCardVo();
         Long cardNo = 0L;
-        if (remoteCardVo != null) {
-            CardStatusVo cardStatusVo = new CardStatusVo();
-            int cardStatusId = Integer.parseInt(remoteCardVo.getStatus());
-            cardStatusVo.setCardStatusID(cardStatusId);
-            cardStatusVo.setCardStatus(cardStatusId == 1 ? "正常"
-                : cardStatusId == 2 ? "挂失" : cardStatusId == 3 ? "注销"
-                : cardStatusId == 4 ? "退卡" : cardStatusId == 7 ? "冻结" : "未知");
-            userCardVo.setCardStatus(cardStatusVo);
+        CardStatusVo cardStatusVo = new CardStatusVo();
+        int cardStatusId = Integer.parseInt(remoteCardVo.getStatus());
+        cardStatusVo.setCardStatusID(cardStatusId);
+        cardStatusVo.setCardStatus(cardStatusId == 1 ? "正常"
+            : cardStatusId == 2 ? "挂失" : cardStatusId == 3 ? "注销"
+            : cardStatusId == 4 ? "退卡" : cardStatusId == 7 ? "冻结" : "未知");
+        userCardVo.setCardStatus(cardStatusVo);
 
-            CardTypeVo cardTypeVo = new CardTypeVo();
-            cardTypeVo.setCardTypeId(remoteCardVo.getCardType().intValue());
-            cardTypeVo.setCardType(remoteCardVo.getCardTypeName());
-            userCardVo.setCardType(cardTypeVo);
+        CardTypeVo cardTypeVo = new CardTypeVo();
+        cardTypeVo.setCardTypeId(remoteCardVo.getCardType().intValue());
+        cardTypeVo.setCardType(remoteCardVo.getCardTypeName());
+        userCardVo.setCardType(cardTypeVo);
 
-            userCardVo.setCardTypeID(remoteCardVo.getCardType().intValue());
-            userCardVo.setEmployeeID(userAccountVo.getUserNo());
-            userCardVo.setFactoryFixID(remoteCardVo.getFactoryId());
-            cardNo = remoteCardVo.getCardNo();
-        }
+        userCardVo.setCardTypeID(remoteCardVo.getCardType().intValue());
+        userCardVo.setEmployeeID(userAccountVo.getUserNo());
+        userCardVo.setFactoryFixID(remoteCardVo.getFactoryId());
+        cardNo = remoteCardVo.getCardNo();
         UserInfoVo userInfoVo = new UserInfoVo();
         userInfoVo.setDepartment(departmentVo);
         userInfoVo.setCard(userCardVo);

+ 37 - 19
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/InitBusiness.java

@@ -12,6 +12,7 @@ import org.dromara.common.core.constant.CacheNames;
 import org.dromara.common.json.utils.JsonUtils;
 import org.dromara.common.redis.utils.RedisUtils;
 import org.dromara.server.common.util.CardDateUtils;
+import org.dromara.server.consume.cache.ValidationParam;
 import org.dromara.server.consume.domain.PtBag;
 import org.dromara.server.consume.domain.bo.XfCardLimitedBo;
 import org.dromara.server.consume.domain.bo.XfUserTotalBo;
@@ -49,6 +50,7 @@ public class InitBusiness {
     private final IPtBagService bagService;
     private final IXfCardLimitedService cardLimitedService;
     private final IXfTermService xfTermService;
+    private final ValidationParam validationParam;
 
     @DubboReference
     private final RemotePtParameterService remotePtParameterService;
@@ -131,7 +133,7 @@ public class InitBusiness {
         if (CollUtil.isNotEmpty(discountCards)) {
             RedisUtils.deleteKeys(CacheNames.T_XF_DISCOUNT);
             discountCards.forEach(p -> {
-                String key = String.format("%s-%s",p.getCardType(),p.getMealType());
+                String key = String.format("%s-%s", p.getCardType(), p.getMealType());
                 RedisUtils.setCacheMapValue(CacheNames.T_XF_DISCOUNT, key, p);
             });
         }
@@ -155,6 +157,8 @@ public class InitBusiness {
                 RedisUtils.setCacheMapValue(CacheNames.T_XF_QUOTA, key, p);
             });
         }
+        validationParam.refresh();
+
         log.info("初始化限额卡类参数完成");
     }
 
@@ -167,7 +171,7 @@ public class InitBusiness {
         Map<String, BigDecimal> sumMap = new HashMap<>();
         for (PtBagVo vo : list) {
             String userId = String.valueOf(vo.getUserId());
-             BigDecimal amount = vo.getBalance();
+            BigDecimal amount = vo.getBalance();
             sumMap.merge(userId, amount, BigDecimal::add);
         }
         for (Map.Entry<String, BigDecimal> entry : sumMap.entrySet()) {
@@ -231,9 +235,22 @@ public class InitBusiness {
                 && p.getLifespan().getTime() > System.currentTimeMillis()).toList();
 
         if (CollectionUtil.isNotEmpty(filterList)) {
-            RedisUtils.deleteKeys(CacheNames.PT_USER_ACCOUNT_LIST);
-            RedisUtils.setCacheList(CacheNames.PT_USER_ACCOUNT_LIST, filterList);
-            RedisUtils.expire(CacheNames.PT_USER_ACCOUNT_LIST, Duration.ofHours(5));
+            RedisUtils.deleteKeys(CacheNames.PT_USER_ACCOUNT_ID);
+            RedisUtils.deleteKeys(CacheNames.PT_USER_ACCOUNT_NUMB);
+            RedisUtils.deleteKeys(CacheNames.PT_USER_ACCOUNT_NO);
+
+            filterList.parallelStream().forEach(p -> {
+                String strUserId = String.valueOf(p.getUserId());
+                String strUserNo = String.valueOf(p.getUserNo());
+                String userNumb = String.valueOf(p.getUserNumb());
+
+                RedisUtils.setCacheMapValue(CacheNames.PT_USER_ACCOUNT_ID, strUserId, p);
+                RedisUtils.setCacheMapValue(CacheNames.PT_USER_ACCOUNT_NO, strUserNo, p);
+                RedisUtils.setCacheMapValue(CacheNames.PT_USER_ACCOUNT_NUMB, userNumb, p);
+            });
+            RedisUtils.expire(CacheNames.PT_USER_ACCOUNT_ID, Duration.ofHours(5));
+            RedisUtils.expire(CacheNames.PT_USER_ACCOUNT_NUMB, Duration.ofHours(5));
+            RedisUtils.expire(CacheNames.PT_USER_ACCOUNT_NO, Duration.ofHours(5));
         }
         log.info("初始化人员账户参数完成");
     }
@@ -248,18 +265,18 @@ public class InitBusiness {
         // RemoteUserAccountVo accountVo = remoteUserAccountService.getUserAccountVoById(id);
         // if (ObjectUtil.isNotEmpty(accountVo)) {
         //     List<RemoteUserAccountVo> list = RedisUtils.getCacheList(CacheNames.PT_USER_ACCOUNT_LIST);
-            // String strUserId = String.valueOf(id);
-            // String strUserNo = String.valueOf(accountVo.getUserNo());
-            //
-            // RedisUtils.delCacheMapValue(CacheNames.PT_USER_ACCOUNT_ID, strUserId);
-            // RedisUtils.delCacheMapValue(CacheNames.PT_USER_ACCOUNT_NO, strUserNo);
-            //
-            // RedisUtils.setCacheMapValue(CacheNames.PT_USER_ACCOUNT_ID, strUserId, accountVo);
-            // RedisUtils.setCacheMapValue(CacheNames.PT_USER_ACCOUNT_NO, strUserNo, accountVo);
-            //
-            // BigDecimal balance = bagService.getUserBalance(id);
-            // RedisUtils.delCacheMapValue(CacheNames.PT_USER_CARD_NO, strUserId);
-            // RedisUtils.setCacheMapValue(CacheNames.USER_TOTAL_BALANCE, strUserId, balance);
+        // String strUserId = String.valueOf(id);
+        // String strUserNo = String.valueOf(accountVo.getUserNo());
+        //
+        // RedisUtils.delCacheMapValue(CacheNames.PT_USER_ACCOUNT_ID, strUserId);
+        // RedisUtils.delCacheMapValue(CacheNames.PT_USER_ACCOUNT_NO, strUserNo);
+        //
+        // RedisUtils.setCacheMapValue(CacheNames.PT_USER_ACCOUNT_ID, strUserId, accountVo);
+        // RedisUtils.setCacheMapValue(CacheNames.PT_USER_ACCOUNT_NO, strUserNo, accountVo);
+        //
+        // BigDecimal balance = bagService.getUserBalance(id);
+        // RedisUtils.delCacheMapValue(CacheNames.PT_USER_CARD_NO, strUserId);
+        // RedisUtils.setCacheMapValue(CacheNames.USER_TOTAL_BALANCE, strUserId, balance);
         // }
         log.info("初始化指定人员账户参数完成,人员Id:{}", id);
     }
@@ -289,7 +306,7 @@ public class InitBusiness {
             RedisUtils.deleteKeys(CacheNames.PT_TERM_NO);
             RedisUtils.deleteKeys(CacheNames.PT_TERM_MAC_MAP);
 
-            list.parallelStream().forEach(p->{
+            list.parallelStream().forEach(p -> {
                 String no = String.valueOf(p.getTermNo());
                 String mac = p.getTermMac();
 
@@ -318,9 +335,10 @@ public class InitBusiness {
 
     /**
      * 重置指定卡片的缓存数据
+     *
      * @param cardVo 卡片信息
      */
-    public void resetUserCard(RemoteCardVo cardVo){
+    public void resetUserCard(RemoteCardVo cardVo) {
         if (ObjectUtil.isNotEmpty(cardVo)) {
             String cardNo = String.valueOf(cardVo.getCardNo());
             String userId = String.valueOf(cardVo.getUserId());

+ 45 - 0
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/cache/UserAccountCacheManager.java

@@ -0,0 +1,45 @@
+package org.dromara.server.consume.cache;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.dromara.backstage.api.RemoteCardService;
+import org.dromara.backstage.api.RemoteUserAccountService;
+import org.dromara.backstage.api.domain.vo.RemoteCardVo;
+import org.dromara.backstage.api.domain.vo.RemoteUserAccountVo;
+import org.dromara.common.core.constant.CacheNames;
+import org.dromara.common.json.utils.JsonUtils;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Service;
+
+/**
+ * 用户败户缓存处理
+ * <p>
+ * 对消费业务用到的卡用户账户据缓存处理
+ *
+ * @author luoyibo
+ * @version 2.2.0
+ * @date 2025-06-25
+ * @since JDK17
+ */
+@Slf4j
+@RequiredArgsConstructor
+@Service
+public class UserAccountCacheManager {
+    @DubboReference
+    private final RemoteUserAccountService remoteUserAccountService;
+
+    @Cacheable(cacheNames = CacheNames.PT_USER_ACCOUNT_ID, key = "#userId", unless = "#result == null")
+    public RemoteUserAccountVo getByUserId(Long userId) {
+        return remoteUserAccountService.getUserAccountVoById(userId);
+    }
+    @Cacheable(cacheNames = CacheNames.PT_USER_ACCOUNT_NO, key = "#userNo", unless = "#result == null")
+    public RemoteUserAccountVo getByUserNo(Long userNo) {
+        return  remoteUserAccountService.getUserAccountVoByUserNo(userNo);
+    }
+
+    @Cacheable(cacheNames = CacheNames.PT_USER_ACCOUNT_NUMB, key = "#userNumb", unless = "#result == null")
+    public RemoteUserAccountVo getByUserNumb(String userNumb) {
+        return remoteUserAccountService.getUserAccountVoByUserNumb(userNumb);
+    }
+}

+ 3 - 37
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/check/CommonCheck.java

@@ -23,10 +23,7 @@ import org.dromara.common.redis.utils.RedisUtils;
 import org.dromara.server.common.constant.ConsumeConstants;
 import org.dromara.server.common.domain.consume.bo.ConsumptionBo;
 import org.dromara.server.common.util.CardDateUtils;
-import org.dromara.server.consume.business.BaseBusiness;
-import org.dromara.server.consume.business.CardBusiness;
-import org.dromara.server.consume.business.InitBusiness;
-import org.dromara.server.consume.business.TermBusiness;
+import org.dromara.server.consume.business.*;
 import org.dromara.server.consume.cache.CardCacheManager;
 import org.dromara.server.consume.domain.vo.XfCardLimitedVo;
 import org.dromara.server.consume.domain.vo.XfTermVo;
@@ -69,7 +66,7 @@ public class CommonCheck {
     private static final long VALIDATION_TIMEOUT = 500;
 
     private final BaseBusiness baseBusiness;
-    private final InitBusiness initBusiness;
+    private final EmployeeBusiness employeeBusiness;
     private final CardBusiness cardBusiness;
     private final ThreadPoolTaskExecutor taskExecutor;
     private final TermBusiness termBusiness;
@@ -447,7 +444,7 @@ public class CommonCheck {
      */
     private R<ErrorInfo> checkUser(String checkParam, Integer checkMode, AllowConsumeValidationContext ctx) {
         // 1. 从缓存获取账户信息
-        RemoteUserAccountVo accountVo = getAccountFromCache(checkParam, checkMode);
+        RemoteUserAccountVo accountVo = employeeBusiness.getAccountFromCache(checkParam, checkMode);
         // 账户不存在,不允许交易
         if (accountVo == null) {
             return createErrorResponse(400, ApiErrorTypeConstants.NOT_FOUND,
@@ -522,37 +519,6 @@ public class CommonCheck {
         return R.ok();
     }
 
-    /**
-     * 从缓存获取账户信息
-     *
-     * @param checkParam 用户标识
-     * @param checkMode  校验模式
-     * @return 账户信息对象
-     */
-    private RemoteUserAccountVo getAccountFromCache(String checkParam, Integer checkMode) {
-        List<RemoteUserAccountVo> list = RedisUtils.getCacheList(CacheNames.PT_USER_ACCOUNT_LIST);
-        if (CollectionUtil.isEmpty(list)) {
-            // 如果缓存没有,初始化
-            initBusiness.initUserAccount();
-            list = RedisUtils.getCacheList(CacheNames.PT_USER_ACCOUNT_LIST);
-            // 初始化后还没有,返回空
-            if (CollectionUtil.isEmpty(list)) {
-                return null;
-            }
-        }
-        Long tempValue = Long.valueOf(checkParam);
-        if (checkMode.equals(userIdMode)) {
-            return list.parallelStream().filter(p -> tempValue.equals(p.getUserId())).findFirst().orElse(null);
-        } else if (checkMode.equals(userNoMode)) {
-            return list.parallelStream().filter(p -> tempValue.equals(p.getUserNo())).findFirst().orElse(null);
-        } else if (checkMode.equals(userNumbMode)) {
-            return list.parallelStream().filter(p -> checkParam.equals(p.getUserNumb())).findFirst().orElse(null);
-        }
-        return null;
-    }
-
-    // endregion
-
     /**
      * 创建错误响应对象
      *