|
@@ -0,0 +1,243 @@
|
|
|
|
|
+package org.dromara.backstage.business;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.dromara.backstage.api.domain.vo.*;
|
|
|
|
|
+import org.dromara.backstage.basics.domain.bo.PtMealTypeBo;
|
|
|
|
|
+import org.dromara.backstage.basics.domain.vo.PtMealTypeVo;
|
|
|
|
|
+import org.dromara.backstage.basics.service.IPtMealtypeService;
|
|
|
|
|
+import org.dromara.backstage.basics.service.IPtParameterService;
|
|
|
|
|
+import org.dromara.backstage.cardCenter.service.IPtCardService;
|
|
|
|
|
+import org.dromara.backstage.consumption.domain.bo.*;
|
|
|
|
|
+import org.dromara.backstage.consumption.domain.vo.*;
|
|
|
|
|
+import org.dromara.backstage.consumption.service.*;
|
|
|
|
|
+import org.dromara.backstage.domain.vo.card.PtCardVo;
|
|
|
|
|
+import org.dromara.backstage.payment.domain.bo.PtUserAccountBo;
|
|
|
|
|
+import org.dromara.backstage.payment.domain.vo.PtUserAccountVo;
|
|
|
|
|
+import org.dromara.backstage.payment.service.IPtUserAccountService;
|
|
|
|
|
+import org.dromara.common.core.constant.CacheNames;
|
|
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
|
|
+import org.dromara.common.json.utils.JsonUtils;
|
|
|
|
|
+import org.dromara.common.redis.utils.RedisUtils;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.time.Duration;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 服务启动后一些初始化业务处理
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * [功能说明]
|
|
|
|
|
+ * ${1:在此简要描述文件核心功能}
|
|
|
|
|
+ *
|
|
|
|
|
+ * @author luoyibo
|
|
|
|
|
+ * @version 2.2.0
|
|
|
|
|
+ * @date 2025-07-10
|
|
|
|
|
+ * @since JDK17
|
|
|
|
|
+ */
|
|
|
|
|
+@Service
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@RequiredArgsConstructor
|
|
|
|
|
+public class InitServiceBusiness {
|
|
|
|
|
+ private final IPtParameterService parameterService;
|
|
|
|
|
+ private final IPtMealtypeService mealTypeService;
|
|
|
|
|
+ private final IXfLimitedTermService limitedTermService;
|
|
|
|
|
+ private final IXfLimitedService limitedService;
|
|
|
|
|
+ private final IXfDiscountService discountService;
|
|
|
|
|
+ private final IXfDiscountTermService discountTermService;
|
|
|
|
|
+ private final IXfQuotaService xfQuotaService;
|
|
|
|
|
+ private final IXfQuotaTermService xfQuotaTermService;
|
|
|
|
|
+ private final IPtCardService cardService;
|
|
|
|
|
+ private final IPtUserAccountService userAccountService;
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 初始化全局消费参数.
|
|
|
|
|
+ * 这部分数据系统初始化时设置后基本不会改动,只需要启动后初始化即可
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 1.是否全局启用了消费限次
|
|
|
|
|
+ * 2.是否全局启用了消费限额
|
|
|
|
|
+ * 3.是否全局启用了消费折扣
|
|
|
|
|
+ * >
|
|
|
|
|
+ */
|
|
|
|
|
+ public void initGlobalData() {
|
|
|
|
|
+ String disCount = parameterService.selectParamByCode("RATE_CONSUME");
|
|
|
|
|
+ String quota = parameterService.selectParamByCode("XE_CONSUME");
|
|
|
|
|
+ String limited = parameterService.selectParamByCode("XC_CONSUME");
|
|
|
|
|
+
|
|
|
|
|
+ log.info("初始化全局限次、限额和折扣参数完成");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 初始化消费餐类清单参数.
|
|
|
|
|
+ * <p>
|
|
|
|
|
+ * 该方法用于在系统启动时初始化消费餐类的相关信息,并将其存储在 Redis 缓存中以便快速访问。
|
|
|
|
|
+ */
|
|
|
|
|
+ public void initMealTypeInfo() {
|
|
|
|
|
+ PtMealTypeBo bo = new PtMealTypeBo();
|
|
|
|
|
+ List<PtMealTypeVo> list = mealTypeService.queryList(bo);
|
|
|
|
|
+
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.PT_MEAL_TYPE_LIST);
|
|
|
|
|
+ RedisUtils.setCacheList(CacheNames.PT_MEAL_TYPE_LIST, MapstructUtils.convert(list, RemoteMealTypeVo.class));
|
|
|
|
|
+ RedisUtils.expire(CacheNames.PT_MEAL_TYPE_LIST, Duration.ofDays(1));
|
|
|
|
|
+
|
|
|
|
|
+ log.info("初始化消费餐类清单参数完成");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 初始化折扣、限次、限额信息
|
|
|
|
|
+ * 需要折扣、限额和限次的设备与卡类在系统使用前就会初始化,后续除了增加新设备外,一般不再改动
|
|
|
|
|
+ * 在服务启动时加载一次,再根据是否有调整数据手工加载或第天定时加载一次
|
|
|
|
|
+ */
|
|
|
|
|
+ public void initDiscountAndOther() {
|
|
|
|
|
+ XfLimitedTermBo bo = new XfLimitedTermBo();
|
|
|
|
|
+ List<XfLimitedTermVo> list = limitedTermService.queryList(bo);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(list)) {
|
|
|
|
|
+ List<Long> limitedTermIds = list.stream().map(XfLimitedTermVo::getTermId).toList();
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.T_XF_LIMITEDTERM);
|
|
|
|
|
+ limitedTermIds.forEach(p -> {
|
|
|
|
|
+ String key = String.valueOf(p);
|
|
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.T_XF_LIMITEDTERM, key, p);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("初始化限次设备参数完成");
|
|
|
|
|
+
|
|
|
|
|
+ XfLimitedBo limitedBo = new XfLimitedBo();
|
|
|
|
|
+ limitedBo.setStatus("1");
|
|
|
|
|
+ List<XfLimitedVo> limitedVos = limitedService.queryList(limitedBo);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(limitedVos)) {
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.T_XF_LIMITED);
|
|
|
|
|
+ limitedVos.forEach(p -> {
|
|
|
|
|
+ RemoteLimitedVo remoteLimitedVo = new RemoteLimitedVo();
|
|
|
|
|
+ remoteLimitedVo.setLimitedId(p.getLimitedId());
|
|
|
|
|
+ remoteLimitedVo.setCardType(p.getCardType());
|
|
|
|
|
+ remoteLimitedVo.setCardTypeName(p.getCardTypeName());
|
|
|
|
|
+ remoteLimitedVo.setDailyCount(p.getDailyCount());
|
|
|
|
|
+ remoteLimitedVo.setOneCount(p.getOneCount());
|
|
|
|
|
+ remoteLimitedVo.setTwoCount(p.getTwoCount());
|
|
|
|
|
+ remoteLimitedVo.setThreeCount(p.getThreeCount());
|
|
|
|
|
+ remoteLimitedVo.setFourCount(p.getFourCount());
|
|
|
|
|
+ remoteLimitedVo.setRemark(p.getRemark());
|
|
|
|
|
+ remoteLimitedVo.setStatus(p.getStatus());
|
|
|
|
|
+
|
|
|
|
|
+ String key = String.valueOf(p.getCardType());
|
|
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.T_XF_LIMITED, key, remoteLimitedVo);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("初始化限次卡类参数完成");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ XfDiscountTermBo xfDiscountTermBo = new XfDiscountTermBo();
|
|
|
|
|
+ List<XfDiscountTermVo> xfDiscountTermVos = discountTermService.queryList(xfDiscountTermBo);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(xfDiscountTermVos)) {
|
|
|
|
|
+ List<Long> discountTermIds = xfDiscountTermVos.stream().map(XfDiscountTermVo::getTermId).toList();
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.T_XF_DISCOUNTTERM);
|
|
|
|
|
+ discountTermIds.forEach(p -> {
|
|
|
|
|
+ String key = String.valueOf(p);
|
|
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.T_XF_DISCOUNTTERM, key, p);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("初始化折扣设备参数完成");
|
|
|
|
|
+
|
|
|
|
|
+ XfDiscountBo xfDiscountBo = new XfDiscountBo();
|
|
|
|
|
+ xfDiscountBo.setStatus("1");
|
|
|
|
|
+ List<XfDiscountVo> xfDiscountVos = discountService.queryList(xfDiscountBo);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(xfDiscountVos)) {
|
|
|
|
|
+ // List<RemoteDiscountVo> discountCards = MapstructUtils.convert(list, RemoteDiscountVo.class);
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.T_XF_DISCOUNT);
|
|
|
|
|
+ xfDiscountVos.forEach(p -> {
|
|
|
|
|
+ String key = String.format("%s-%s", p.getCardType(), p.getMealType());
|
|
|
|
|
+ RemoteDiscountVo remoteDiscountVo = new RemoteDiscountVo();
|
|
|
|
|
+ remoteDiscountVo.setDiscountId(p.getDiscountId());
|
|
|
|
|
+ remoteDiscountVo.setCardType(p.getCardType());
|
|
|
|
|
+ remoteDiscountVo.setCardTypeName(p.getCardTypeName());
|
|
|
|
|
+ remoteDiscountVo.setMealType(p.getMealType());
|
|
|
|
|
+ remoteDiscountVo.setMealTypeName(p.getCardTypeName());
|
|
|
|
|
+ remoteDiscountVo.setRateType(p.getRateType());
|
|
|
|
|
+ remoteDiscountVo.setOneRate(p.getOneRate());
|
|
|
|
|
+ remoteDiscountVo.setTwoRate(p.getTwoRate());
|
|
|
|
|
+ remoteDiscountVo.setThreeRate(p.getThreeRate());
|
|
|
|
|
+ remoteDiscountVo.setFourRate(p.getFourRate());
|
|
|
|
|
+ remoteDiscountVo.setRemark(p.getRemark());
|
|
|
|
|
+ remoteDiscountVo.setStatus(p.getStatus());
|
|
|
|
|
+
|
|
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.T_XF_DISCOUNT, key, remoteDiscountVo);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("初始化折扣卡类参数完成");
|
|
|
|
|
+
|
|
|
|
|
+ XfQuotaTermBo xfQuotaTermBo = new XfQuotaTermBo();
|
|
|
|
|
+ List<XfQuotatermVo> xfQuotatermVoList = xfQuotaTermService.queryList(xfQuotaTermBo);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(xfQuotatermVoList)) {
|
|
|
|
|
+ List<Long> quotaTermIds = xfQuotatermVoList.stream().map(XfQuotatermVo::getTermId).toList();
|
|
|
|
|
+ if (CollUtil.isNotEmpty(quotaTermIds)) {
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.T_XF_QUOTATERM);
|
|
|
|
|
+ quotaTermIds.forEach(p -> {
|
|
|
|
|
+ String key = String.valueOf(p);
|
|
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.T_XF_QUOTATERM, key, p);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("初始化限额设备参数完成");
|
|
|
|
|
+
|
|
|
|
|
+ XfQuotaBo xfQuotaBo = new XfQuotaBo();
|
|
|
|
|
+ xfQuotaBo.setStatus("1");
|
|
|
|
|
+ List<XfQuotaVo> xfQuotaVos = xfQuotaService.queryList(xfQuotaBo);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(xfQuotaVos)) {
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.T_XF_QUOTA);
|
|
|
|
|
+ xfQuotaVos.forEach(p -> {
|
|
|
|
|
+ String key = String.valueOf(p.getCardType());
|
|
|
|
|
+ RemoteQuotaVo remoteQuotaVo = new RemoteQuotaVo();
|
|
|
|
|
+ remoteQuotaVo.setQuotaId(p.getQuotaId());
|
|
|
|
|
+ remoteQuotaVo.setCardType(p.getCardType());
|
|
|
|
|
+ remoteQuotaVo.setCardTypeName(p.getCardTypeName());
|
|
|
|
|
+ remoteQuotaVo.setDailyMoney(p.getDailyMoney());
|
|
|
|
|
+ remoteQuotaVo.setOneMoney(p.getOneMoney());
|
|
|
|
|
+ remoteQuotaVo.setTwoMoney(p.getTwoMoney());
|
|
|
|
|
+ remoteQuotaVo.setThreeMoney(p.getThreeMoney());
|
|
|
|
|
+ remoteQuotaVo.setFourMoney(p.getFourMoney());
|
|
|
|
|
+ remoteQuotaVo.setRemark(p.getRemark());
|
|
|
|
|
+ remoteQuotaVo.setStatus(p.getStatus());
|
|
|
|
|
+
|
|
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.T_XF_QUOTA, key, remoteQuotaVo);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("初始化限额卡类参数完成");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 初始化人员卡片
|
|
|
|
|
+ */
|
|
|
|
|
+ public void initUserCard() {
|
|
|
|
|
+ List<PtCardVo> list = cardService.selectNormalCards();
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.PT_USER_CARD_NO);
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.PT_USER_CARD_USER_ID);
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.PT_USER_CARD_FACTORYID);
|
|
|
|
|
+ list.forEach(p -> {
|
|
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.PT_USER_CARD_NO, p.getCardNo().toString(), JsonUtils.toJsonString(p));
|
|
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.PT_USER_CARD_USER_ID, p.getUserId().toString(), JsonUtils.toJsonString(p));
|
|
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.PT_USER_CARD_FACTORYID, p.getFactoryId().toString(), JsonUtils.toJsonString(p));
|
|
|
|
|
+ });
|
|
|
|
|
+ log.info("初始化人员卡片参数完成");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void initUserAccount() {
|
|
|
|
|
+ PtUserAccountBo bo = new PtUserAccountBo();
|
|
|
|
|
+ List<PtUserAccountVo> voList = userAccountService.queryList(bo);
|
|
|
|
|
+ List<PtUserAccountVo> filterList = voList.stream().filter(
|
|
|
|
|
+ p -> p.getDelFlag().equals("0")
|
|
|
|
|
+ && p.getLifespan().getTime() > System.currentTimeMillis()).toList();
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.PT_USER_ACCOUNT_NO);
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.PT_USER_ACCOUNT_NUMB);
|
|
|
|
|
+ RedisUtils.deleteKeys(CacheNames.PT_USER_ACCOUNT_ID);
|
|
|
|
|
+ if (CollUtil.isNotEmpty(filterList)) {
|
|
|
|
|
+ filterList.forEach(p -> {
|
|
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.PT_USER_ACCOUNT_NO, p.getUserNo().toString(), JsonUtils.toJsonString(p));
|
|
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.PT_USER_ACCOUNT_NUMB, p.getUserNumb(), JsonUtils.toJsonString(p));
|
|
|
|
|
+ RedisUtils.setCacheMapValue(CacheNames.PT_USER_ACCOUNT_ID, p.getUserId().toString(), JsonUtils.toJsonString(p));
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ log.info("初始化人员账户参数完成");
|
|
|
|
|
+ }
|
|
|
|
|
+}
|