소스 검색

表名修改:投资者账户->站点账户

skyline 1 년 전
부모
커밋
add2990c98

+ 2 - 2
car-wash-entity/src/main/java/com/kym/entity/SplitRecord.java

@@ -32,12 +32,12 @@ public class SplitRecord extends BaseEntity {
     /**
      * 出账账户ID
      */
-    private Long fromAccount;
+    private String fromStationId;
 
     /**
      * 入账账户ID
      */
-    private Long toAccount;
+    private String toStationId;
 
     /**
      * 分账交易流水号

+ 5 - 7
car-wash-entity/src/main/java/com/kym/entity/InvestorAccount.java → car-wash-entity/src/main/java/com/kym/entity/StationAccount.java

@@ -5,24 +5,22 @@ import lombok.Getter;
 import lombok.Setter;
 
 /**
- * <p>
- * 商户账户表
- * </p>
+ * 站点账户
  *
  * @author skyline
  * @since 2025-02-24
  */
 @Getter
 @Setter
-@TableName("t_investor_account")
-public class InvestorAccount extends BaseEntity {
+@TableName("t_station_account")
+public class StationAccount extends BaseEntity {
 
     private static final long serialVersionUID = 1L;
 
     /**
-     * 商户用户id
+     * 站点ID
      */
-    private Long adminUserId;
+    private String stationId;
     /**
      * 总余额(分)
      */

+ 0 - 16
car-wash-mapper/src/main/java/com/kym/mapper/InvestorAccountMapper.java

@@ -1,16 +0,0 @@
-package com.kym.mapper;
-
-import com.kym.entity.InvestorAccount;
-import com.kym.mapper.mybatisplus.MyBaseMapper;
-
-/**
- * <p>
- * 商户账户表 Mapper 接口
- * </p>
- *
- * @author skyline
- * @since 2025-02-24
- */
-public interface InvestorAccountMapper extends MyBaseMapper<InvestorAccount> {
-
-}

+ 16 - 0
car-wash-mapper/src/main/java/com/kym/mapper/StationAccountMapper.java

@@ -0,0 +1,16 @@
+package com.kym.mapper;
+
+import com.kym.entity.StationAccount;
+import com.kym.mapper.mybatisplus.MyBaseMapper;
+
+/**
+ * <p>
+ * 站点账户表 Mapper 接口
+ * </p>
+ *
+ * @author skyline
+ * @since 2025-02-24
+ */
+public interface StationAccountMapper extends MyBaseMapper<StationAccount> {
+
+}

+ 0 - 17
car-wash-service/src/main/java/com/kym/service/InvestorAccountService.java

@@ -1,17 +0,0 @@
-package com.kym.service;
-
-import com.kym.entity.InvestorAccount;
-import com.kym.service.mybatisplus.MyBaseService;
-
-/**
- * <p>
- * 商户账户表 服务类
- * </p>
- *
- * @author skyline
- * @since 2025-02-24
- */
-public interface InvestorAccountService extends MyBaseService<InvestorAccount> {
-
-    InvestorAccount getInvestorAccount(String stationId);
-}

+ 17 - 0
car-wash-service/src/main/java/com/kym/service/StationAccountService.java

@@ -0,0 +1,17 @@
+package com.kym.service;
+
+import com.kym.entity.StationAccount;
+import com.kym.service.mybatisplus.MyBaseService;
+
+/**
+ * <p>
+ * 商户账户表 服务类
+ * </p>
+ *
+ * @author skyline
+ * @since 2025-02-24
+ */
+public interface StationAccountService extends MyBaseService<StationAccount> {
+
+    StationAccount getStationAccount(String stationId);
+}

+ 21 - 22
car-wash-service/src/main/java/com/kym/service/awoara/event/handle/OrderCloseEventHandler.java

@@ -24,11 +24,11 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
     private final WashOrderService washOrderService;
     private final WalletDetailService walletDetailService;
     private final AccountService accountService;
-    private final InvestorAccountService investorAccountService;
+    private final StationAccountService investorAccountService;
     private final SplitRecordService splitRecordService;
 
     public OrderCloseEventHandler(WashOrderService washOrderService, WalletDetailService walletDetailService,
-                                  AccountService accountService, InvestorAccountService investorAccountService, SplitRecordService splitRecordService) {
+                                  AccountService accountService, StationAccountService investorAccountService, SplitRecordService splitRecordService) {
         this.washOrderService = washOrderService;
         this.walletDetailService = walletDetailService;
         this.accountService = accountService;
@@ -83,18 +83,17 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
             washOrderService.updateById(washOrder);
 
 
-            // todo t_account减(上面已完成),t_investor_account冻结户减,t_investor_account商户加,t_split_record记录
+            // todo t_account减(上面已完成),t_station_account冻结户减,t_station_account商户加,t_split_record记录
             // todo 需要判断是否跨网点,分开处理;跨网点结算比例是消费站点分订单额的30%,充值站点分70%
             if (washOrder.getIsCross()) {
                 // 跨网点订单结算比例是消费站点分订单额的30%,充值站点分70%
-                doCrossSplit(washOrder, KymCache.INSTANCE.getInvestorAdminUserIdByUserId(washOrder.getUserId()));
+                doCrossSplit(washOrder, KymCache.INSTANCE.getUserStationId(washOrder.getUserId()));
             } else {
                 // 不跨网点订单结算比例是消费站点分订单额的100%,消费金额*商家消费分润比例30%-消费金额*平台分润10%=消费金额*(商家消费分润比例-平台分润)
                 doLocalSplit(washOrder);
             }
 
 
-
             var walletDetail = new WalletDetail();
             walletDetail.setUserId(washOrder.getUserId());
             walletDetail.setType(WalletDetail.TYPE_消费);
@@ -120,24 +119,24 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
      * @param washOrder
      */
     private void doLocalSplit(WashOrder washOrder) {
-        var investorAccount = investorAccountService.getInvestorAccount(washOrder.getStationId());
+        var stationAccount = investorAccountService.getStationAccount(washOrder.getStationId());
         var amount = (int) (washOrder.getAmount() * (0.3 - 0.1));
         investorAccountService.lambdaUpdate()
                 .setSql("frozen_amount = frozen_amount - {0}", amount)
-                .eq(InvestorAccount::getId, investorAccount.getId())
+                .eq(StationAccount::getId, stationAccount.getId())
                 .update();
         // 冻结户解冻
         var splitRecord1 = new SplitRecord()
-                .setFromAccount(investorAccount.getAdminUserId())
-                .setToAccount(investorAccount.getAdminUserId())
+                .setFromStationId(stationAccount.getStationId())
+                .setToStationId(stationAccount.getStationId())
                 .setTradeNo(washOrder.getOrderId())
                 .setAmount(amount)
                 .setType(SplitRecord.TYPE_UNFREEZE);
 
         // 基本户入账
         var splitRecord2 = new SplitRecord()
-                .setFromAccount(investorAccount.getAdminUserId())
-                .setToAccount(investorAccount.getAdminUserId())
+                .setFromStationId(stationAccount.getStationId())
+                .setToStationId(stationAccount.getStationId())
                 .setTradeNo(washOrder.getOrderId())
                 .setAmount(amount)
                 .setType(SplitRecord.TYPE_CONSUME);
@@ -151,10 +150,10 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
      * 执行跨店分账操作
      *
      * @param washOrder
-     * @param InvestorAdminUserId 用户归属的站点的商户投资者adminUserId
+     * @param stationId 用户归属的站点Id
      */
-    private void doCrossSplit(WashOrder washOrder, Long InvestorAdminUserId) {
-        var investorAccount = investorAccountService.getInvestorAccount(washOrder.getStationId());
+    private void doCrossSplit(WashOrder washOrder, String stationId) {
+        var investorAccount = investorAccountService.getStationAccount(washOrder.getStationId());
         var splitAmount = (int) (washOrder.getAmount() * (0.3 - 0.1));
         var localAmount = (int) (splitAmount * 0.7);
         var crossAmount = splitAmount - localAmount;
@@ -162,7 +161,7 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
         // 当前消费站点收入(跨店消费,原充值站点要分订单的70%)
         investorAccountService.lambdaUpdate()
                 .setSql("balance = balance + {0}", crossAmount)
-                .eq(InvestorAccount::getId, investorAccount.getId())
+                .eq(StationAccount::getId, investorAccount.getId())
                 .update();
 
 //        // 充值站点收入
@@ -181,28 +180,28 @@ public class OrderCloseEventHandler implements AwoaraEventHandler<OrderInfoObjec
         // 充值站点收入
         investorAccountService.lambdaUpdate()
                 .setSql("balance = balance + {0}, frozen_amount = frozen_amount - {1}", localAmount - crossAmount, splitAmount)
-                .eq(InvestorAccount::getId, investorAccount.getId())
+                .eq(StationAccount::getId, investorAccount.getId())
                 .update();
 
 
         // t_split_record 1.消费站点收入 2.归属站点收入 3.充值站点支出
         var splitRecord1 = new SplitRecord()
-                .setFromAccount(InvestorAdminUserId)
-                .setToAccount(investorAccount.getAdminUserId())
+                .setFromStationId(stationId)
+                .setToStationId(investorAccount.getStationId())
                 .setTradeNo(washOrder.getOrderId())
                 .setAmount(crossAmount)
                 .setType(SplitRecord.TYPE_CONSUME);
 
         var splitRecord2 = new SplitRecord()
-                .setFromAccount(InvestorAdminUserId)
-                .setToAccount(InvestorAdminUserId)
+                .setFromStationId(stationId)
+                .setToStationId(stationId)
                 .setTradeNo(washOrder.getOrderId())
                 .setAmount(localAmount)
                 .setType(SplitRecord.TYPE_CONSUME);
 
         var splitRecord3 = new SplitRecord()
-                .setFromAccount(investorAccount.getAdminUserId())
-                .setToAccount(investorAccount.getAdminUserId())
+                .setFromStationId(investorAccount.getStationId())
+                .setToStationId(investorAccount.getStationId())
                 .setTradeNo(washOrder.getOrderId())
                 .setAmount(splitAmount)
                 .setType(SplitRecord.TYPE_UNFREEZE);

+ 5 - 4
car-wash-service/src/main/java/com/kym/service/awoara/factory/AwoaraEventHandlerFactory.java

@@ -18,15 +18,16 @@ public class AwoaraEventHandlerFactory {
     private static WalletDetailService walletDetailService;
     private static AccountService accountService;
 
-    private static InvestorAccountService investorAccountService;
+    private static StationAccountService stationAccountService;
     private static SplitRecordService splitRecordService;
 
-    public AwoaraEventHandlerFactory(WashDeviceService washDeviceService, WashOrderService washOrderService, WalletDetailService walletDetailService, AccountService accountService, InvestorAccountService investorAccountService, SplitRecordService splitRecordService) {
+    public AwoaraEventHandlerFactory(WashDeviceService washDeviceService, WashOrderService washOrderService, WalletDetailService walletDetailService,
+                                     AccountService accountService, StationAccountService stationAccountService, SplitRecordService splitRecordService) {
         AwoaraEventHandlerFactory.washDeviceService = washDeviceService;
         AwoaraEventHandlerFactory.washOrderService = washOrderService;
         AwoaraEventHandlerFactory.walletDetailService = walletDetailService;
         AwoaraEventHandlerFactory.accountService = accountService;
-        AwoaraEventHandlerFactory.investorAccountService = investorAccountService;
+        AwoaraEventHandlerFactory.stationAccountService = stationAccountService;
         AwoaraEventHandlerFactory.splitRecordService = splitRecordService;
     }
 
@@ -39,7 +40,7 @@ public class AwoaraEventHandlerFactory {
                 case order_create -> new OrderCreateEventHandler(washOrderService);
                 case order_update -> new OrderUpdateEventHandler(washOrderService);
                 case order_close ->
-                        new OrderCloseEventHandler(washOrderService, walletDetailService, accountService, investorAccountService, splitRecordService);
+                        new OrderCloseEventHandler(washOrderService, walletDetailService, accountService, stationAccountService, splitRecordService);
                 case user_login -> new UserLoginEventHandler();
                 case card_event -> new CardEventHandler();
             };

+ 10 - 1
car-wash-service/src/main/java/com/kym/service/cache/KymCache.java

@@ -34,13 +34,22 @@ public enum KymCache {
         map.forEach((k, v) -> KymCacheInjector.redisTemplate.opsForValue().set(RedisKeys.USER_ID_TO_STATION_ID + k, v));
     }
 
+    /**
+     * 通过消费用户id获取归属站点Id
+     *
+     * @param userId
+     */
+    public String getUserStationId(Long userId) {
+        return  KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.USER_ID_TO_STATION_ID + userId);
+    }
+
     /**
      * 通过消费用户id获取站点商户投资者adminUserId
      *
      * @param userId
      */
     public Long getInvestorAdminUserIdByUserId(Long userId) {
-        return  getInvestorAdminUserIdByStationId(Objects.requireNonNull(KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.USER_ID_TO_STATION_ID + userId)));
+        return getInvestorAdminUserIdByStationId(Objects.requireNonNull(KymCacheInjector.redisTemplate.opsForValue().get(RedisKeys.USER_ID_TO_STATION_ID + userId)));
     }
 
     /**

+ 0 - 25
car-wash-service/src/main/java/com/kym/service/impl/InvestorAccountServiceImpl.java

@@ -1,25 +0,0 @@
-package com.kym.service.impl;
-
-import com.kym.entity.InvestorAccount;
-import com.kym.mapper.InvestorAccountMapper;
-import com.kym.service.InvestorAccountService;
-import com.kym.service.cache.KymCache;
-import com.kym.service.mybatisplus.MyBaseServiceImpl;
-import org.springframework.stereotype.Service;
-
-/**
- * <p>
- * 商户账户表 服务实现类
- * </p>
- *
- * @author skyline
- * @since 2025-02-24
- */
-@Service
-public class InvestorAccountServiceImpl extends MyBaseServiceImpl<InvestorAccountMapper, InvestorAccount> implements InvestorAccountService {
-
-    @Override
-    public InvestorAccount getInvestorAccount(String stationId) {
-        return lambdaQuery().eq(InvestorAccount::getAdminUserId, KymCache.INSTANCE.getInvestorAdminUserIdByStationId(stationId)).one();
-    }
-}

+ 24 - 0
car-wash-service/src/main/java/com/kym/service/impl/StationAccountServiceImpl.java

@@ -0,0 +1,24 @@
+package com.kym.service.impl;
+
+import com.kym.entity.StationAccount;
+import com.kym.mapper.StationAccountMapper;
+import com.kym.service.StationAccountService;
+import com.kym.service.mybatisplus.MyBaseServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ * 商户账户表 服务实现类
+ * </p>
+ *
+ * @author skyline
+ * @since 2025-02-24
+ */
+@Service
+public class StationAccountServiceImpl extends MyBaseServiceImpl<StationAccountMapper, StationAccount> implements StationAccountService {
+
+    @Override
+    public StationAccount getStationAccount(String stationId) {
+        return lambdaQuery().eq(StationAccount::getStationId, stationId).one();
+    }
+}

+ 3 - 3
car-wash-service/src/main/java/com/kym/service/wechat/impl/WxPayServiceImpl.java

@@ -88,7 +88,7 @@ public class WxPayServiceImpl implements WxPayService {
     private final UserRechargeRightsService userRechargeRightsService;
 
     private final RechargeConfigService rechargeConfigService;
-    private final InvestorAccountService investorAccountService;
+    private final StationAccountService investorAccountService;
 
 
     /**
@@ -101,7 +101,7 @@ public class WxPayServiceImpl implements WxPayService {
                             PayLogService payLogService, AccountService accountService,
                             RefundLogService refundLogService,
                             ActivityService activityService, UserRechargeRightsService userRechargeRightsService,
-                            RechargeConfigService rechargeConfigService, InvestorAccountService investorAccountService) {
+                            RechargeConfigService rechargeConfigService, StationAccountService investorAccountService) {
         this.conf = conf;
         this.walletDetailService = walletDetailService;
         this.payLogService = payLogService;
@@ -347,7 +347,7 @@ public class WxPayServiceImpl implements WxPayService {
                 var stationFreezeAmount = totalAmount - stationBasicAmount;
                 investorAccountService.lambdaUpdate()
                         .setSql("balance = (balance + %d), frozen_amount = (frozen_amount + %d)".formatted(stationBasicAmount, stationFreezeAmount))
-                        .eq(InvestorAccount::getId, KymCache.INSTANCE.getInvestorAdminUserIdByStationId(stationId))
+                        .eq(StationAccount::getId, KymCache.INSTANCE.getInvestorAdminUserIdByStationId(stationId))
                         .update();
 
                 LOGGER.info("微信支付回调{}:业务处理结束", notifyRes[2]);