wujiefeng hai 1 ano
pai
achega
318d1c96df

+ 5 - 4
PaymentServer/src/main/java/com/zhongshu/payment/server/core/controller/feign/WalletFeignController.java

@@ -1,12 +1,12 @@
 package com.zhongshu.payment.server.core.controller.feign;
 
+import com.github.microservice.core.delegate.DelegateMapping;
 import com.zhongshu.payment.client.service.WalletFeignService;
 import lombok.experimental.Delegate;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import javax.annotation.Resource;
-
 /**
  * @author wjf
  * @date 2024/7/26
@@ -14,9 +14,10 @@ import javax.annotation.Resource;
 
 @RestController
 @RequestMapping("manager/wallet")
-public class WalletFeignController {
+@DelegateMapping(types = WalletFeignService.class)
+public class WalletFeignController implements WalletFeignService{
 
-    @Resource(name = "walletFeignServiceImpl")
+    @Autowired
     @Delegate
     private WalletFeignService walletFeignService;
 }

+ 4 - 1
PaymentServer/src/main/java/com/zhongshu/payment/server/core/dao/WalletDao.java

@@ -1,6 +1,7 @@
 package com.zhongshu.payment.server.core.dao;
 
 import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.zhongshu.payment.client.types.WalletType;
 import com.zhongshu.payment.server.core.domain.wallet.Wallet;
 
 import java.util.List;
@@ -13,7 +14,9 @@ public interface WalletDao extends MongoDao<Wallet> {
 
     Wallet findByUserIdAndOid(String userId, String oid);
 
-    Wallet findByShopIdAndOid(String shopId, String oid);
+    Wallet findByUserIdAndOidAndWalletType(String userId, String oid, WalletType walletType);
+
+    Wallet findByShopIdAndOidAndWalletType(String shopId, String oid, WalletType walletType);
 
     Wallet findTop1ById(String id);
 

+ 8 - 8
PaymentServer/src/main/java/com/zhongshu/payment/server/core/service/impl/WalletFeignServiceImpl.java

@@ -41,24 +41,24 @@ public class WalletFeignServiceImpl implements WalletFeignService {
 
     @NotNull
     private Wallet findWallet(String oid, @NotNull WalletType walletType, String shopId, String userId){
-        Wallet wallet = null;
+        Wallet findWallet = null;;
+        Wallet wallet = new Wallet();;
         if (walletType.equals(WalletType.User)){
-            wallet = walletDao.findByUserIdAndOid(userId, oid);
+            findWallet = walletDao.findByUserIdAndOidAndWalletType(userId, oid, walletType);
+            wallet.setUserId(userId);
         }
         if (walletType.equals(WalletType.Shop)){
-            wallet = walletDao.findByShopIdAndOid(shopId, oid);
+            findWallet = walletDao.findByShopIdAndOidAndWalletType(shopId, oid, walletType);
+            wallet.setShopId(shopId);
         }
-        if (wallet!=null){
-            return wallet;
+        if (findWallet!=null){
+            return findWallet;
         }
-        wallet = new Wallet();
         wallet.setOid(oid);
         wallet.setAmount(BigDecimal.ZERO);
         wallet.setAmount(BigDecimal.ZERO);
         wallet.setDataState(DataState.Enable);
         wallet.setWalletType(walletType);
-        wallet.setShopId(shopId);
-        wallet.setUserId(userId);
         walletDao.save(wallet);
         return wallet;
     }