Explorar o código

Merge remote-tracking branch 'origin/master'

xiari hai 11 meses
pai
achega
6ad2d3035e
Modificáronse 19 ficheiros con 226 adicións e 167 borrados
  1. 6 0
      ruoyi-api/ruoyi-api-consume/src/main/java/org/dromara/consume/api/RemoteConsumeService.java
  2. 20 23
      ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/manager/PlusSpringCacheManager.java
  3. 18 9
      ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/business/errfill/ErrFillBusiness.java
  4. 7 8
      ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/business/payments/PayOrderBusiness.java
  5. 1 2
      ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/payment/service/IPtBagService.java
  6. 3 0
      ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/payment/service/impl/PtBagServiceImpl.java
  7. 22 21
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/BaseBusiness.java
  8. 0 12
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/EmployeeBusiness.java
  9. 17 52
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/InitBusiness.java
  10. 4 1
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/TermBusiness.java
  11. 13 0
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/cache/CardCacheManager.java
  12. 13 0
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/cache/UserAccountCacheManager.java
  13. 14 5
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/check/CardConsumeValidationContext.java
  14. 14 27
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/check/CommonCheck.java
  15. 14 0
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/dubbo/RemoteConsumeServiceImpl.java
  16. 2 0
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/service/IPtBagService.java
  17. 4 0
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/service/IXfCardLimitedService.java
  18. 6 1
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/service/impl/PtBagServiceImpl.java
  19. 48 6
      ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/service/impl/XfCardLimitedServiceImpl.java

+ 6 - 0
ruoyi-api/ruoyi-api-consume/src/main/java/org/dromara/consume/api/RemoteConsumeService.java

@@ -5,6 +5,8 @@ import org.dromara.common.core.domain.model.ErrorInfo;
 import org.dromara.consume.api.domain.bo.RemoteConsumeBo;
 import org.dromara.consume.api.domain.bo.RemoteResultDto;
 
+import java.math.BigDecimal;
+
 /**
  * @ClassName RemoteConsumeService
  * @Description 消费远程服务接口
@@ -54,4 +56,8 @@ public interface RemoteConsumeService {
      * @return 返回一个包含错误信息的响应对象,如果操作成功则data为null,如果失败则data包含具体的错误信息
      */
     RemoteResultDto dealHikUploadOffLineRecord(RemoteConsumeBo remoteBo);
+
+    BigDecimal getUserTotalBalance(Long userId);
+
+    BigDecimal cacheUserTotalBalance(Long userId, BigDecimal balance);
 }

+ 20 - 23
ruoyi-common/ruoyi-common-redis/src/main/java/org/dromara/common/redis/manager/PlusSpringCacheManager.java

@@ -15,6 +15,7 @@
  */
 package org.dromara.common.redis.manager;
 
+import lombok.Setter;
 import org.dromara.common.redis.utils.RedisUtils;
 import org.redisson.api.RMap;
 import org.redisson.api.RMapCache;
@@ -47,8 +48,27 @@ public class PlusSpringCacheManager implements CacheManager {
 
     private boolean dynamic = true;
 
+    /**
+     * -- SETTER --
+     *  Defines possibility of storing
+     *  values.
+     *  <p>
+     *  Default is <code>true</code>
+     *
+     */
+    @Setter
     private boolean allowNullValues = true;
 
+    /**
+     * -- SETTER --
+     *  Defines if cache aware of Spring-managed transactions.
+     *  If
+     *  put/evict operations are executed only for successful transaction in after-commit phase.
+     *  <p>
+     *  Default is <code>false</code>
+     *
+     */
+    @Setter
     private boolean transactionAware = true;
 
     Map<String, CacheConfig> configMap = new ConcurrentHashMap<>();
@@ -61,29 +81,6 @@ public class PlusSpringCacheManager implements CacheManager {
     }
 
 
-    /**
-     * Defines possibility of storing {@code null} values.
-     * <p>
-     * Default is <code>true</code>
-     *
-     * @param allowNullValues stores if <code>true</code>
-     */
-    public void setAllowNullValues(boolean allowNullValues) {
-        this.allowNullValues = allowNullValues;
-    }
-
-    /**
-     * Defines if cache aware of Spring-managed transactions.
-     * If {@code true} put/evict operations are executed only for successful transaction in after-commit phase.
-     * <p>
-     * Default is <code>false</code>
-     *
-     * @param transactionAware cache is transaction aware if <code>true</code>
-     */
-    public void setTransactionAware(boolean transactionAware) {
-        this.transactionAware = transactionAware;
-    }
-
     /**
      * Defines 'fixed' cache names.
      * A new cache instance will not be created in dynamic for non-defined names.

+ 18 - 9
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/business/errfill/ErrFillBusiness.java

@@ -4,6 +4,8 @@ import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.json.JSONUtil;
 import lombok.RequiredArgsConstructor;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.apache.dubbo.config.annotation.DubboService;
 import org.dromara.backstage.basics.domain.vo.PtMealTypeVo;
 import org.dromara.backstage.basics.service.IPtMealtypeService;
 import org.dromara.backstage.cardCenter.service.IPtCardService;
@@ -32,6 +34,7 @@ import org.dromara.common.core.exception.consume.BagException;
 import org.dromara.common.core.exception.consume.ConsumeException;
 import org.dromara.common.core.utils.RecordIdUtils;
 import org.dromara.common.redis.utils.RedisUtils;
+import org.dromara.consume.api.RemoteConsumeService;
 import org.jetbrains.annotations.NotNull;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -67,6 +70,9 @@ public class ErrFillBusiness {
     private final IXfUserTotalService userTotalService;
     private final IXfTermTotalService termTotalService;
 
+    @DubboReference
+    private final RemoteConsumeService remoteConsumeService;
+
     @Transactional(rollbackFor = ConsumeException.class)
     public PtBagVo createErrFillRecord(ConsumptionBo bo) {
         java.lang.String message;
@@ -205,7 +211,7 @@ public class ErrFillBusiness {
      * @param consumeId 消费明细Id
      * @param balance   卡余
      */
-    private void updateConsumeRecordBalance(java.lang.String consumeId, BigDecimal balance){
+    private void updateConsumeRecordBalance(String consumeId, BigDecimal balance){
         XfConsumeDetailBo consumeDetailBo = new XfConsumeDetailBo();
         consumeDetailBo.setConsumeId(consumeId);
         consumeDetailBo.setCardValue(balance);
@@ -299,18 +305,21 @@ public class ErrFillBusiness {
      * @return 生成的记录Id
      */
     @NotNull
-    private java.lang.String getRecordKeyId(ConsumptionBo bo, PtUserAccountVo accountVo, PtBagVo bagVo) {
+    private String getRecordKeyId(ConsumptionBo bo, PtUserAccountVo accountVo, PtBagVo bagVo) {
         return RecordIdUtils.getRecordId(new Date(), Short.parseShort(bo.getTermNo().toString()), 0, accountVo.getUserNo().intValue(), Integer.parseInt(bagVo.getBagCode()));
     }
 
     private void updateCacheBalanceByUserId(Long id, BigDecimal dealMoney) {
-        String userId = String.valueOf(id);
-        BigDecimal balance = BigDecimal.ZERO;
-        if (RedisUtils.getCacheMapValue(CacheNames.USER_TOTAL_BALANCE, userId) != null) {
-            balance = RedisUtils.getCacheMapValue(CacheNames.USER_TOTAL_BALANCE, userId);
-        }
+        BigDecimal balance = remoteConsumeService.getUserTotalBalance(id);
         balance = balance.add(dealMoney);
-        RedisUtils.delCacheMapValue(CacheNames.USER_TOTAL_BALANCE, userId);
-        RedisUtils.setCacheMapValue(CacheNames.USER_TOTAL_BALANCE, userId, balance);
+        remoteConsumeService.cacheUserTotalBalance(id, balance);
+        // String userId = String.valueOf(id);
+        // BigDecimal balance = BigDecimal.ZERO;
+        // if (RedisUtils.getCacheMapValue(CacheNames.USER_TOTAL_BALANCE, userId) != null) {
+        //     balance = RedisUtils.getCacheMapValue(CacheNames.USER_TOTAL_BALANCE, userId);
+        // }
+        // balance = balance.add(dealMoney);
+        // RedisUtils.delCacheMapValue(CacheNames.USER_TOTAL_BALANCE, userId);
+        // RedisUtils.setCacheMapValue(CacheNames.USER_TOTAL_BALANCE, userId, balance);
     }
 }

+ 7 - 8
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/business/payments/PayOrderBusiness.java

@@ -6,6 +6,7 @@ import cn.hutool.core.util.ObjUtil;
 import cn.hutool.json.JSONUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.dubbo.config.annotation.DubboReference;
 import org.dromara.backstage.basics.domain.vo.PtWorkstationVo;
 import org.dromara.backstage.cardCenter.domain.bo.PtSubsidyitemBo;
 import org.dromara.backstage.cardCenter.domain.vo.PtSubsidyitemVo;
@@ -21,6 +22,7 @@ import org.dromara.common.core.domain.R;
 import org.dromara.common.core.enums.*;
 import org.dromara.common.core.exception.consume.ConsumeException;
 import org.dromara.common.redis.utils.RedisUtils;
+import org.dromara.consume.api.RemoteConsumeService;
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -46,10 +48,12 @@ import java.util.Map;
 @Service
 @Slf4j
 public class PayOrderBusiness {
-
     private final PayBaseBusiness payBaseBusiness;
     private final ThreadPoolTaskExecutor threadPoolTaskExecutor;
 
+    @DubboReference
+    private final RemoteConsumeService remoteConsumeService;
+
     /**
      * 生成收支原始订单信息,写t_xf_creditAccountBack表
      *
@@ -288,13 +292,8 @@ public class PayOrderBusiness {
     }
 
     private void updateCacheBalanceByUserId(Long id, BigDecimal dealMoney) {
-        String userId = String.valueOf(id);
-        BigDecimal balance = BigDecimal.ZERO;
-        if (RedisUtils.getCacheMapValue(CacheNames.USER_TOTAL_BALANCE, userId) != null) {
-            balance = RedisUtils.getCacheMapValue(CacheNames.USER_TOTAL_BALANCE, userId);
-        }
+        BigDecimal balance = remoteConsumeService.getUserTotalBalance(id);
         balance = balance.add(dealMoney);
-        RedisUtils.delCacheMapValue(CacheNames.USER_TOTAL_BALANCE, userId);
-        RedisUtils.setCacheMapValue(CacheNames.USER_TOTAL_BALANCE, userId, balance);
+        remoteConsumeService.cacheUserTotalBalance(id, balance);
     }
 }

+ 1 - 2
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/payment/service/IPtBagService.java

@@ -6,6 +6,7 @@ import org.dromara.backstage.payment.domain.vo.PtBagVo;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 
+import java.math.BigDecimal;
 import java.util.Collection;
 import java.util.List;
 
@@ -105,6 +106,4 @@ public interface IPtBagService {
      * @return 账户钱包
      */
     PtBagVo queryByUserBagCode(Long userId,String bagCode);
-
-
 }

+ 3 - 0
ruoyi-modules/ruoyi-backstage/src/main/java/org/dromara/backstage/payment/service/impl/PtBagServiceImpl.java

@@ -13,6 +13,7 @@ import org.dromara.backstage.payment.domain.bo.PtBagBo;
 import org.dromara.backstage.payment.domain.vo.PtBagVo;
 import org.dromara.backstage.payment.mapper.PtBagMapper;
 import org.dromara.backstage.payment.service.IPtBagService;
+import org.dromara.common.core.constant.CacheNames;
 import org.dromara.common.core.enums.BalanceUpdateEnum;
 import org.dromara.common.core.exception.consume.BagException;
 import org.dromara.common.core.utils.MapstructUtils;
@@ -21,6 +22,7 @@ import org.dromara.common.core.utils.StringUtils;
 import org.dromara.common.encrypt.utils.YcEncryptUtil;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.springframework.cache.annotation.CachePut;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
@@ -278,6 +280,7 @@ public class PtBagServiceImpl implements IPtBagService {
         }
         return entity;
     }
+
     /**
      * 组装充值钱包数据
      * 1.设置充值后余额=账户原余额+充值金额

+ 22 - 21
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/BaseBusiness.java

@@ -35,6 +35,7 @@ import org.dromara.server.common.constant.ConsumeConstants;
 import org.dromara.server.common.domain.consume.bo.ConsumptionBo;
 import org.dromara.server.common.domain.vo.yc.YcPushConsumeInfoVo;
 import org.dromara.server.common.util.CardDateUtils;
+import org.dromara.server.consume.cache.CardCacheManager;
 import org.dromara.server.consume.domain.bo.XfConsumeDetailBo;
 import org.dromara.server.consume.domain.bo.XfConsumeDetailOriginalBo;
 import org.dromara.server.consume.domain.bo.XfTermTotalBo;
@@ -79,7 +80,7 @@ public class BaseBusiness {
     private final SyncRemoteSendMessageRecordService syncRemoteSendMessageRecordService;
     private final IXfCardLimitedService cardLimitedService;
     private final ThreadPoolTaskExecutor taskExecutor;
-    private final InitBusiness initBusiness;
+    private final CardCacheManager cardCacheManager;
 
     @DubboReference
     private final RemoteRegisterInfoService remoteRegisterInfoService;
@@ -198,7 +199,7 @@ public class BaseBusiness {
         userCardVo.setLastMeal(mealType);
         userCardVo.setLastPay(consumeDate);
 
-        initBusiness.resetUserCard(userCardVo);
+        cardCacheManager.cacheCardVo(userCardVo);
 
         // 更新数据库
         remoteCardService.updateCardDayData(userCardVo);
@@ -212,10 +213,7 @@ public class BaseBusiness {
      */
     public void resetUserBalance(Long userId, BigDecimal balance) {
         log.info("[请求交易完成]-[更新人员余额缓存]");
-        String strUserId = String.valueOf(userId);
-
-        RedisUtils.delCacheMapValue(CacheNames.USER_TOTAL_BALANCE, strUserId);
-        RedisUtils.setCacheMapValue(CacheNames.USER_TOTAL_BALANCE, strUserId, balance);
+        bagService.cacheUserTotalBalance(userId, balance);
     }
 
     /**
@@ -240,12 +238,12 @@ public class BaseBusiness {
             cardLimitedVo.setMealCount(cardLimitedVo.getMealCount() + 1);
             cardLimitedVo.setDayCount(cardLimitedVo.getDayCount() + 1);
         }
-        String cardNo = String.valueOf(cardLimitedVo.getCardNo());
-
-        RedisUtils.delCacheMapValue(CacheNames.T_XF_CARD_LIMITED, cardNo);
-        RedisUtils.setCacheMapValue(CacheNames.T_XF_CARD_LIMITED, cardNo, JsonUtils.toJsonString(cardLimitedVo));
+        // String cardNo = String.valueOf(cardLimitedVo.getCardNo());
+        //
+        // RedisUtils.delCacheMapValue(CacheNames.T_XF_CARD_LIMITED, cardNo);
+        // RedisUtils.setCacheMapValue(CacheNames.T_XF_CARD_LIMITED, cardNo, JsonUtils.toJsonString(cardLimitedVo));
+        cardLimitedService.cacheLimitedAndOther(cardLimitedVo);
         cardLimitedService.updateByVo(cardLimitedVo);
-
     }
 
     //endregion
@@ -510,17 +508,19 @@ public class BaseBusiness {
     public List<ConsumptionBo> selectOriginalReconciliation(Date consumeDate) {
         return TenantHelper.ignore(() -> originalService.selectReconciliationData(consumeDate));
     }
-    public List<ConsumptionBo> selectOriginalNoSend(Date consumeDate){
+
+    public List<ConsumptionBo> selectOriginalNoSend(Date consumeDate) {
         LocalDateTime beginTime = CardDateUtils.toLocalDateTime(consumeDate);
         LocalDateTime endTime = beginTime.plusDays(1);
         Date beginDate = CardDateUtils.toDate(beginTime, ZoneId.of("Asia/Shanghai"));
         Date endDate = CardDateUtils.toDate(endTime, ZoneId.of("Asia/Shanghai"));
-        return selectOriginalNoSend(beginDate,endDate);
+        return selectOriginalNoSend(beginDate, endDate);
     }
-    public List<ConsumptionBo> selectOriginalNoSend(Date beginDate,Date endDate) {
+
+    public List<ConsumptionBo> selectOriginalNoSend(Date beginDate, Date endDate) {
         List<XfConsumeDetailOriginalVo> list = originalService.queryListByConsumeDate(beginDate, endDate);
-        List<ConsumptionBo>  consumptionBos = new ArrayList<>();
-        list.parallelStream().forEach(p->{
+        List<ConsumptionBo> consumptionBos = new ArrayList<>();
+        list.parallelStream().forEach(p -> {
             ConsumptionBo bo = new ConsumptionBo();
             bo.setRecordId(p.getRecordId());
             bo.setUserId(p.getUserId());
@@ -541,14 +541,15 @@ public class BaseBusiness {
         return consumptionBos;
     }
 
-    public R<Void> sendToJwKafkaTest(Date consumeDate){
+    public R<Void> sendToJwKafkaTest(Date consumeDate) {
         LocalDateTime endTime = LocalDateTime.now().plusDays(1);
-        return sendToJwKafkaTest(consumeDate,CardDateUtils.toDate(endTime));
+        return sendToJwKafkaTest(consumeDate, CardDateUtils.toDate(endTime));
     }
-    public R<Void> sendToJwKafkaTest(Date beginDate,Date endDate){
-        List<ConsumptionBo> list = selectOriginalNoSend(beginDate,endDate);
+
+    public R<Void> sendToJwKafkaTest(Date beginDate, Date endDate) {
+        List<ConsumptionBo> list = selectOriginalNoSend(beginDate, endDate);
         if (CollUtil.isNotEmpty(list)) {
-            list.parallelStream().forEach(p->{
+            list.parallelStream().forEach(p -> {
                 List<RemoteUserAccountVo> accountVoList = RedisUtils.getCacheList(CacheNames.PT_USER_ACCOUNT_LIST);
                 RemoteUserAccountVo accountVo = accountVoList.parallelStream()
                     .filter(k -> k.getUserId().equals(p.getUserId())).findFirst().orElse(null);

+ 0 - 12
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/EmployeeBusiness.java

@@ -2,28 +2,21 @@ package org.dromara.server.consume.business;
 
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.dubbo.config.annotation.DubboReference;
 import org.dromara.backstage.api.domain.vo.RemoteCardVo;
 import org.dromara.backstage.api.domain.vo.RemoteUserAccountVo;
 import org.dromara.common.core.api.ReturnResult;
 import org.dromara.common.core.constant.ApiErrorTypeConstants;
-import org.dromara.common.core.constant.CacheNames;
 import org.dromara.common.core.domain.model.ErrorInfo;
 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.CardCacheManager;
 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;
 import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
-
 /**
  * @ClassName EmployeeBusiness
  * @Description TODO
@@ -39,9 +32,6 @@ public class EmployeeBusiness {
     private final UserAccountCacheManager userAccountCacheManager;
     private final CardCacheManager cardCacheManager;
 
-    @DubboReference
-    private final RemoteDeptService remoteDeptService;
-
     public ReturnResult getEmployeeVoByNumb(String userNumb) {
         RemoteUserAccountVo userAccountVo = userAccountCacheManager.getByUserNumb(userNumb);
         if (userAccountVo == null) {
@@ -78,10 +68,8 @@ public class EmployeeBusiness {
     }
 
     private Object setReturnEmployeeVo(RemoteUserAccountVo userAccountVo) {
-        // RemoteDeptVo remoteDeptVo = remoteDeptService.selectDeptById(userAccountVo.getDeptId());
         DepartmentVo departmentVo = new DepartmentVo();
         departmentVo.setDepartmentID(userAccountVo.getDeptId().toString());
-        // departmentVo.setParentDepartmentID(remoteDeptVo.getParentId().toString());
         departmentVo.setDepartmentName(userAccountVo.getDeptName());
 
         Long userId = userAccountVo.getUserId();

+ 17 - 52
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/InitBusiness.java

@@ -12,6 +12,8 @@ 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.CardCacheManager;
+import org.dromara.server.consume.cache.UserAccountCacheManager;
 import org.dromara.server.consume.cache.ValidationParam;
 import org.dromara.server.consume.domain.bo.XfCardLimitedBo;
 import org.dromara.server.consume.domain.vo.PtBagVo;
@@ -48,6 +50,8 @@ public class InitBusiness {
     private final IXfCardLimitedService cardLimitedService;
     private final IXfTermService xfTermService;
     private final ValidationParam validationParam;
+    private final CardCacheManager cardCacheManager;
+    private final UserAccountCacheManager userAccountCacheManager;
 
     @DubboReference
     private final RemotePtParameterService remotePtParameterService;
@@ -165,16 +169,15 @@ public class InitBusiness {
      */
     public void initUserBalance() {
         List<PtBagVo> list = bagService.selectBalanceBag();
-        Map<String, BigDecimal> sumMap = new HashMap<>();
+        Map<Long, BigDecimal> sumMap = new HashMap<>();
         for (PtBagVo vo : list) {
-            String userId = String.valueOf(vo.getUserId());
+            Long userId = vo.getUserId();
             BigDecimal amount = vo.getBalance();
             sumMap.merge(userId, amount, BigDecimal::add);
         }
-        for (Map.Entry<String, BigDecimal> entry : sumMap.entrySet()) {
-            RedisUtils.setCacheMapValue(CacheNames.USER_TOTAL_BALANCE, entry.getKey(), entry.getValue());
+        for (Map.Entry<Long, BigDecimal> entry : sumMap.entrySet()) {
+            bagService.cacheUserTotalBalance(entry.getKey(), entry.getValue());
         }
-        RedisUtils.expire(CacheNames.USER_TOTAL_BALANCE, Duration.ofHours(5));
         log.info("初始化人员余额参数完成");
     }
 
@@ -194,15 +197,7 @@ public class InitBusiness {
     public void initUserCard() {
         List<RemoteCardVo> list = remoteCardService.selectNormalCards();
         if (CollUtil.isNotEmpty(list)) {
-            RedisUtils.deleteKeys(CacheNames.PT_USER_CARD_NO);
-            RedisUtils.deleteKeys(CacheNames.PT_USER_CARD_USER_ID);
-            RedisUtils.deleteKeys(CacheNames.PT_USER_CARD_FACTORYID);
-
-            list.forEach(this::resetUserCard);
-
-            RedisUtils.expire(CacheNames.PT_USER_CARD_NO, Duration.ofHours(5));
-            RedisUtils.expire(CacheNames.PT_USER_CARD_USER_ID, Duration.ofHours(5));
-            RedisUtils.expire(CacheNames.PT_USER_CARD_FACTORYID, Duration.ofHours(5));
+            list.forEach(cardCacheManager::cacheCardVo);
         }
         log.info("初始化人员卡片参数完成");
     }
@@ -214,7 +209,7 @@ public class InitBusiness {
      */
     public void initUserCardByUserId(Long id) {
         RemoteCardVo cardVo = remoteCardService.queryMainCardByUserId(id);
-        resetUserCard(cardVo);
+        cardCacheManager.cacheCardVo(cardVo);
         log.info("初始指定人员卡片参数完成,人员Id:{}", id);
     }
 
@@ -229,22 +224,7 @@ public class InitBusiness {
                 && p.getLifespan().getTime() > System.currentTimeMillis()).toList();
 
         if (CollectionUtil.isNotEmpty(filterList)) {
-            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));
+            filterList.forEach(userAccountCacheManager::cacheUserAccountVo);
         }
         log.info("初始化人员账户参数完成");
     }
@@ -256,22 +236,11 @@ public class InitBusiness {
      * @param id 人员Id
      */
     public void initUserAccountById(Long id) {
-        // 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);
-        // }
+        RemoteUserAccountVo accountVo = remoteUserAccountService.getUserAccountVoById(id);
+        if (ObjectUtil.isNotEmpty(accountVo)) {
+            userAccountCacheManager.cacheUserAccountVo(accountVo);
+        }
+
         log.info("初始化指定人员账户参数完成,人员Id:{}", id);
     }
 
@@ -282,11 +251,7 @@ public class InitBusiness {
         XfCardLimitedBo bo = new XfCardLimitedBo();
         List<XfCardLimitedVo> list = cardLimitedService.queryList(bo);
         if (CollUtil.isNotEmpty(list)) {
-            RedisUtils.deleteKeys(CacheNames.T_XF_CARD_LIMITED);
-            list.forEach(p -> {
-                RedisUtils.setCacheMapValue(CacheNames.T_XF_CARD_LIMITED, p.getCardNo().toString(), JsonUtils.toJsonString(p));
-            });
-            RedisUtils.expire(CacheNames.T_XF_CARD_LIMITED, Duration.ofHours(5));
+            list.forEach(cardLimitedService::cacheLimitedAndOther);
         }
         log.info("卡片消费限制参数完成");
     }

+ 4 - 1
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/business/TermBusiness.java

@@ -204,9 +204,12 @@ public class TermBusiness {
             case ConsumeConstants.TERM_MAC -> {
                 return termService.queryVoOneByMac(checkParam);
             }
+            default -> {
+                return null;
+            }
         }
-        return null;
     }
+
     /**
      * 将系统中的设备信息转换成消费机可接收的类型
      * @param termVo 系统消费机信息

+ 13 - 0
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/cache/CardCacheManager.java

@@ -7,7 +7,9 @@ import org.dromara.backstage.api.RemoteCardService;
 import org.dromara.backstage.api.domain.vo.RemoteCardVo;
 import org.dromara.common.core.constant.CacheNames;
 import org.dromara.common.json.utils.JsonUtils;
+import org.springframework.cache.annotation.CachePut;
 import org.springframework.cache.annotation.Cacheable;
+import org.springframework.cache.annotation.Caching;
 import org.springframework.stereotype.Service;
 
 /**
@@ -52,4 +54,15 @@ public class CardCacheManager {
         }
         return JsonUtils.toJsonString(cardVo);
     }
+
+    @Caching(
+        put = {
+            @CachePut(cacheNames = CacheNames.PT_USER_CARD_FACTORYID, key = "#cardVo.factoryId"),
+            @CachePut(cacheNames = CacheNames.PT_USER_CARD_USER_ID, key = "#cardVo.userId"),
+            @CachePut(cacheNames = CacheNames.PT_USER_CARD_NO, key = "#cardVo.cardNo")
+        }
+    )
+    public String cacheCardVo(RemoteCardVo cardVo) {
+        return JsonUtils.toJsonString(cardVo);
+    }
 }

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

@@ -9,7 +9,9 @@ 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.CachePut;
 import org.springframework.cache.annotation.Cacheable;
+import org.springframework.cache.annotation.Caching;
 import org.springframework.stereotype.Service;
 
 /**
@@ -42,4 +44,15 @@ public class UserAccountCacheManager {
     public RemoteUserAccountVo getByUserNumb(String userNumb) {
         return remoteUserAccountService.getUserAccountVoByUserNumb(userNumb);
     }
+
+    @Caching(
+        put = {
+            @CachePut(cacheNames = CacheNames.PT_USER_ACCOUNT_ID, key = "#accountVo.userId"),
+            @CachePut(cacheNames = CacheNames.PT_USER_ACCOUNT_NO, key = "#accountVo.userNo"),
+            @CachePut(cacheNames = CacheNames.PT_USER_ACCOUNT_NUMB, key = "#accountVo.userNumb")
+        }
+    )
+    public RemoteUserAccountVo cacheUserAccountVo(RemoteUserAccountVo accountVo) {
+        return accountVo;
+    }
 }

+ 14 - 5
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/check/CardConsumeValidationContext.java

@@ -2,18 +2,19 @@ package org.dromara.server.consume.check;
 
 import cn.hutool.core.util.ObjectUtil;
 import lombok.Data;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.dromara.backstage.api.domain.vo.RemoteCardVo;
 import org.dromara.backstage.api.domain.vo.RemoteDiscountVo;
 import org.dromara.backstage.api.domain.vo.RemoteLimitedVo;
 import org.dromara.backstage.api.domain.vo.RemoteQuotaVo;
-import org.dromara.common.core.constant.CacheNames;
+import org.dromara.common.core.utils.SpringUtils;
 import org.dromara.common.json.utils.JsonUtils;
-import org.dromara.common.redis.utils.RedisUtils;
 import org.dromara.server.common.domain.consume.bo.ConsumptionBo;
 import org.dromara.server.common.util.CardDateUtils;
 import org.dromara.server.consume.domain.vo.XfCardLimitedVo;
 import org.dromara.server.consume.domain.vo.XfTermVo;
+import org.dromara.server.consume.service.IXfCardLimitedService;
 
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
@@ -32,6 +33,7 @@ import java.util.Objects;
  */
 @Data
 @Slf4j
+@RequiredArgsConstructor
 public class CardConsumeValidationContext {
     /**
      * 设备Id
@@ -133,12 +135,19 @@ public class CardConsumeValidationContext {
         context.lastPayTime = CardDateUtils.toLocalDateTime(bo.getConsumeDate());
 
         // 从缓存获取卡片限制数据
-        String strCardNo = String.valueOf(userCardVo.getCardNo());
-        Object objXfCardLimited = RedisUtils.getCacheMapValue(CacheNames.T_XF_CARD_LIMITED, strCardNo);
+        // String strCardNo = String.valueOf(userCardVo.getCardNo());
+        // Object objXfCardLimited = RedisUtils.getCacheMapValue(CacheNames.T_XF_CARD_LIMITED, strCardNo);
+        // if (objXfCardLimited != null) {
+        //     context.cardLimitedVo = JsonUtils.parseObject(objXfCardLimited.toString(), XfCardLimitedVo.class);
+        // }
+        // // 如果缓存中没有则初始化为当天当餐
+        // if (ObjectUtil.isEmpty(context.cardLimitedVo)) {
+        //     context.cardLimitedVo = initXfCardLimited(context.cardNo, context.consumeDate, context.lastMeal);
+        // }
+        Object objXfCardLimited = SpringUtils.getBean(IXfCardLimitedService.class).getLimitedAndOtherByNo(context.getCardNo());
         if (objXfCardLimited != null) {
             context.cardLimitedVo = JsonUtils.parseObject(objXfCardLimited.toString(), XfCardLimitedVo.class);
         }
-        // 如果缓存中没有则初始化为当天当餐
         if (ObjectUtil.isEmpty(context.cardLimitedVo)) {
             context.cardLimitedVo = initXfCardLimited(context.cardNo, context.consumeDate, context.lastMeal);
         }

+ 14 - 27
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/check/CommonCheck.java

@@ -54,14 +54,6 @@ import java.util.function.Supplier;
 @Service
 @RequiredArgsConstructor
 public class CommonCheck {
-    // 用户校验模式 0-userId 1- userNo 2-userNumb
-    private static final Integer userIdMode = 0;
-    private static final Integer userNoMode = 1;
-    private static final Integer userNumbMode = 2;
-    // 卡片校验模式 0-userId 1- cardNo
-    private static final Integer cardIdMode = 0;
-    private static final int cardNoMode = 1;
-    private static final Integer cardFactoryMode = 2;
     // 异步线程执行超时时间,以毫秒为单位
     private static final long VALIDATION_TIMEOUT = 500;
 
@@ -268,24 +260,19 @@ public class CommonCheck {
      */
     public R<ErrorInfo> checkTerm(AllowConsumeValidationContext ctx) {
         String msgInfo = ObjectUtil.isEmpty(ctx.getTermMac()) ? ctx.getTermNo().toString() : ctx.getTermMac();
-        XfTermVo termVo;
-        String mac = ctx.getTermMac();
-        String termNo = String.valueOf(ctx.getTermNo());
-        if (ObjectUtil.isNotEmpty(mac)) {
-            termVo = termBusiness.getTermFromCache(mac,ConsumeConstants.TERM_MAC);
-        } else {
-            termVo = termBusiness.getTermFromCache(termNo,ConsumeConstants.TERM_NO);;
-        }
+        String checkParam = ObjectUtil.isNotEmpty(ctx.getTermMac()) ? ctx.getTermMac() : ctx.getTermNo().toString();
+        Integer checkMode = ObjectUtil.isNotEmpty(ctx.getTermMac()) ? ConsumeConstants.TERM_MAC : ConsumeConstants.TERM_NO;
+        XfTermVo termVo = termBusiness.getTermFromCache(checkParam, checkMode);
+
         if (ObjectUtil.isEmpty(termVo)) {
             return createErrorResponse(400, ApiErrorTypeConstants.OBJECT_NOT_EXISTS,
                 "设备不存在",
                 MessageFormat.format("机号或MAC为[{0}]的设备不存在,不允许交易", msgInfo));
         }
         // 因为后续处理都是用的机号,如果消费机上传的是mac地址,则将termNo更新到消费业务对象
-        if (termVo != null) {
-            ctx.getBo().setTermNo(termVo.getTermNo());
-            ctx.getBo().setTermName(termVo.getTermName());
-        }
+        ctx.getBo().setTermNo(termVo.getTermNo());
+        ctx.getBo().setTermName(termVo.getTermName());
+
         // 将消费机数据复制提供后续业务使用
         ctx.setUseTermVo(termVo);
 
@@ -332,7 +319,7 @@ public class CommonCheck {
     private R<ErrorInfo> checkCardNo(AllowConsumeValidationContext ctx) {
         // 检查卡片
         long cardNo = ctx.getCardNo();
-        R<ErrorInfo> result = checkCard(cardNo, cardNoMode, ctx);
+        R<ErrorInfo> result = checkCard(cardNo, ConsumeConstants.CARD_NO, ctx);
         if (R.isError(result)) {
             return result;
         }
@@ -348,7 +335,7 @@ public class CommonCheck {
         }
         // 获取消费账户信息
         String strUserId = String.valueOf(ctx.getUserCardVo().getUserId());
-        result = checkUser(strUserId, userIdMode, ctx);
+        result = checkUser(strUserId, ConsumeConstants.USER_ID, ctx);
         if (R.isError(result)) {
             return result;
         }
@@ -367,13 +354,13 @@ public class CommonCheck {
     private R<ErrorInfo> checkFactoryId(AllowConsumeValidationContext ctx) {
         // 检查卡片
         long factoryId = ctx.getFactoryId();
-        R<ErrorInfo> result = checkCard(factoryId, cardFactoryMode, ctx);
+        R<ErrorInfo> result = checkCard(factoryId, ConsumeConstants.CARD_FACTORY, ctx);
         if (R.isError(result)) {
             return result;
         }
         // 获取消费账户信息
         String strUserId = String.valueOf(ctx.getUserCardVo().getUserId());
-        result = checkUser(strUserId, userIdMode, ctx);
+        result = checkUser(strUserId, ConsumeConstants.USER_ID, ctx);
         if (R.isError(result)) {
             return result;
         }
@@ -393,7 +380,7 @@ public class CommonCheck {
     private R<ErrorInfo> checkUserNo(AllowConsumeValidationContext ctx) {
         // 校验账户信息
         String userNo = String.valueOf(ctx.getUserNo());
-        R<ErrorInfo> result = checkUser(userNo, userNoMode, ctx);
+        R<ErrorInfo> result = checkUser(userNo, ConsumeConstants.USER_NO, ctx);
         if (R.isError(result)) {
             return result;
         }
@@ -410,7 +397,7 @@ public class CommonCheck {
     private R<ErrorInfo> checkUserNumb(AllowConsumeValidationContext ctx) {
         // 校验账户信息
         String userNumb = ctx.getUserNumb();
-        R<ErrorInfo> result = checkUser(userNumb, userNumbMode, ctx);
+        R<ErrorInfo> result = checkUser(userNumb, ConsumeConstants.USER_NUMB, ctx);
         if (R.isError(result)) {
             return result;
         }
@@ -422,7 +409,7 @@ public class CommonCheck {
     private R<ErrorInfo> checkCardAfterUser(AllowConsumeValidationContext ctx) {
         R<ErrorInfo> result;
         Long userId = ctx.getUserAccountVo().getUserId();
-        result = checkCard(userId, cardIdMode, ctx);
+        result = checkCard(userId, ConsumeConstants.CARD_USER, ctx);
         if (R.isError(result)) {
             return result;
         }

+ 14 - 0
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/dubbo/RemoteConsumeServiceImpl.java

@@ -19,8 +19,11 @@ import org.dromara.server.consume.business.ArcFaceBusiness;
 import org.dromara.server.consume.business.BaseBusiness;
 import org.dromara.server.consume.business.ConsumeBusiness;
 import org.dromara.server.consume.domain.convert.RemoteConsumeBoConvert;
+import org.dromara.server.consume.service.IPtBagService;
 import org.springframework.stereotype.Service;
 
+import java.math.BigDecimal;
+
 /**
  * @ClassName RemoteConsumeServiceImpl
  * @Description TODO
@@ -38,6 +41,7 @@ public class RemoteConsumeServiceImpl implements RemoteConsumeService {
     private final ArcFaceBusiness faceBusiness;
     private final BaseBusiness baseBusiness;
     private final DefaultConfig defaultConfig;
+    private final IPtBagService bagService;
 
 
     /**
@@ -101,4 +105,14 @@ public class RemoteConsumeServiceImpl implements RemoteConsumeService {
 
         return new RemoteResultDto(result, updatedRemote);
     }
+
+    @Override
+    public BigDecimal getUserTotalBalance(Long userId) {
+        return bagService.getUserTotalBalance(userId);
+    }
+
+    @Override
+    public BigDecimal cacheUserTotalBalance(Long userId, BigDecimal balance) {
+        return bagService.cacheUserTotalBalance(userId, balance);
+    }
 }

+ 2 - 0
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/service/IPtBagService.java

@@ -117,5 +117,7 @@ public interface IPtBagService {
     void updateConsumeBalance(List<PtBagVo> bagVos);
 
     List<PtBagVo> selectBalanceBag();
+
+    BigDecimal cacheUserTotalBalance(Long userId, BigDecimal balance);
     // boolean updateBalanceByByConsume(PtBagBo bo);
 }

+ 4 - 0
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/service/IXfCardLimitedService.java

@@ -124,4 +124,8 @@ public interface IXfCardLimitedService {
     void insertOrUpdate(XfCardLimitedBo bo);
 
     void updateByVo(XfCardLimitedVo vo);
+
+    String cacheLimitedAndOther(XfCardLimitedVo vo);
+
+    String getLimitedAndOtherByNo(Long cardNo);
 }

+ 6 - 1
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/service/impl/PtBagServiceImpl.java

@@ -25,6 +25,7 @@ import org.dromara.server.consume.domain.bo.PtBagBo;
 import org.dromara.server.consume.domain.vo.PtBagVo;
 import org.dromara.server.consume.mapper.PtBagMapper;
 import org.dromara.server.consume.service.IPtBagService;
+import org.springframework.cache.annotation.CachePut;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
@@ -341,7 +342,11 @@ public class PtBagServiceImpl implements IPtBagService {
 
         return baseMapper.selectVoList(queryWrapper);
     }
-
+    @Override
+    @CachePut(cacheNames = CacheNames.USER_TOTAL_BALANCE, key = "#userId")
+    public BigDecimal cacheUserTotalBalance(Long userId, BigDecimal balance) {
+        return balance;
+    }
     /**
      * 组装充值钱包数据
      * 1.设置充值后余额=账户原余额+充值金额

+ 48 - 6
ruoyi-server/ruoyi-server-consume/src/main/java/org/dromara/server/consume/service/impl/XfCardLimitedServiceImpl.java

@@ -9,8 +9,11 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import lombok.RequiredArgsConstructor;
+import org.apache.poi.ss.formula.functions.Now;
+import org.dromara.common.core.constant.CacheNames;
 import org.dromara.common.core.utils.MapstructUtils;
 import org.dromara.common.core.utils.StringUtils;
+import org.dromara.common.json.utils.JsonUtils;
 import org.dromara.common.mybatis.core.page.PageQuery;
 import org.dromara.common.mybatis.core.page.TableDataInfo;
 import org.dromara.server.consume.domain.XfCardLimited;
@@ -18,11 +21,14 @@ import org.dromara.server.consume.domain.bo.XfCardLimitedBo;
 import org.dromara.server.consume.domain.vo.XfCardLimitedVo;
 import org.dromara.server.consume.mapper.XfCardLimitedMapper;
 import org.dromara.server.consume.service.IXfCardLimitedService;
+import org.springframework.cache.annotation.CachePut;
+import org.springframework.cache.annotation.Cacheable;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.util.Collection;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
@@ -295,8 +301,8 @@ public class XfCardLimitedServiceImpl implements IXfCardLimitedService {
         XfCardLimitedVo vo = this.queryByCardNo(cardNo);
         if (ObjUtil.isNotEmpty(vo)) {
             LambdaUpdateWrapper<XfCardLimited> luw = new LambdaUpdateWrapper<>();
-            luw.set(XfCardLimited::getDayDiscountCount, vo.getDayDiscountCount()+1);
-            luw.set(XfCardLimited::getMealDiscountCount, vo.getMealDiscountCount()+1);
+            luw.set(XfCardLimited::getDayDiscountCount, vo.getDayDiscountCount() + 1);
+            luw.set(XfCardLimited::getMealDiscountCount, vo.getMealDiscountCount() + 1);
 
             luw.eq(XfCardLimited::getCardNo, cardNo);
             return baseMapper.update(null, luw) > 0;
@@ -309,7 +315,7 @@ public class XfCardLimitedServiceImpl implements IXfCardLimitedService {
     public void insertOrUpdate(XfCardLimitedBo bo) {
         XfCardLimited entity = MapstructUtils.convert(bo, XfCardLimited.class);
         XfCardLimited temp = baseMapper.selectOne(new LambdaQueryWrapper<XfCardLimited>().eq(XfCardLimited::getCardNo, bo.getCardNo()));
-        if(ObjUtil.isNotEmpty(temp)){
+        if (ObjUtil.isNotEmpty(temp)) {
             entity.setLimitedId(temp.getLimitedId());
             baseMapper.updateById(entity);
         } else {
@@ -320,9 +326,45 @@ public class XfCardLimitedServiceImpl implements IXfCardLimitedService {
     @Override
     public void updateByVo(XfCardLimitedVo vo) {
         XfCardLimited entity = MapstructUtils.convert(vo, XfCardLimited.class);
-        LambdaUpdateWrapper<XfCardLimited> luw = new LambdaUpdateWrapper<XfCardLimited>()
-                                                     .eq(XfCardLimited::getCardNo, vo.getCardNo());
-        baseMapper.update(entity, luw);
+        XfCardLimitedVo limitedVo = queryByCardNo(vo.getCardNo());
+        if (limitedVo != null) {
+            LambdaUpdateWrapper<XfCardLimited> luw = new LambdaUpdateWrapper<XfCardLimited>()
+                .eq(XfCardLimited::getCardNo, vo.getCardNo());
+            baseMapper.update(entity, luw);
+        } else {
+            baseMapper.insert(entity);
+        }
+
+    }
+
+    @Override
+    @CachePut(cacheNames = CacheNames.T_XF_CARD_LIMITED, key = "#vo.cardNo")
+    public String cacheLimitedAndOther(XfCardLimitedVo vo) {
+        return JsonUtils.toJsonString(vo);
+    }
+
+    @Override
+    @Cacheable(cacheNames = CacheNames.T_XF_CARD_LIMITED, key = "#cardNo", unless = "#result == null")
+    public String getLimitedAndOtherByNo(Long cardNo) {
+        XfCardLimitedVo vo = queryByCardNo(cardNo);
+        if (vo == null) {
+            vo = initXfCardLimited(cardNo);
+        }
+        return JsonUtils.toJsonString(vo);
+    }
+
+    private static XfCardLimitedVo initXfCardLimited(Long cardNo) {
+        XfCardLimitedVo vo = new XfCardLimitedVo();
+        vo.setCardNo(cardNo);
+        vo.setDayCount(0L);
+        vo.setDayMoney(BigDecimal.ZERO);
+        vo.setMealCount(0L);
+        vo.setMealMoney(BigDecimal.ZERO);
+        vo.setDayDiscountCount(0L);
+        vo.setMealDiscountCount(0L);
+        vo.setLastPay(new Date());
+        vo.setLastMeal(0L);
 
+        return vo;
     }
 }