From dc11990acb945329cdcb28dae7a0aa353a3c18c7 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Fri, 18 Jul 2025 10:38:35 +0800
Subject: [PATCH] 货币转换优化

---
 src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java b/src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java
index 3faf5d6..ee62972 100644
--- a/src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserStockSubscribeServiceImpl.java
@@ -5,6 +5,7 @@
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.nq.Repository.ExchangeRateRepository;
 import com.nq.common.ResponseCode;
 import com.nq.common.ServerResponse;
 import com.nq.dao.StockSubscribeMapper;
@@ -69,6 +70,9 @@
 
     @Autowired
     UserAssetsMapper userAssetsMapper;
+
+    @Autowired
+    ExchangeRateRepository exchangeRateRepository;
 
     /**
      * 用户新股申购
@@ -148,7 +152,6 @@
                 }else{
                     bound =  new BigDecimal(model.getApplyNums()).multiply(stockSubscribe.getPrice());
                 }
-
                 if(stockSubscribe.getType() == 1){
                     model.setUserId(user.getId());
                     model.setNewName(stockSubscribe.getName());
@@ -165,6 +168,10 @@
                     userStockSubscribe.setNewStockId(stockSubscribe.getNewlistId());
                     ret = userStockSubscribeMapper.insert(userStockSubscribe);
 
+                    //如果不是墨西哥币需要转换金额
+                    if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
+                        bound = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), bound);
+                    }
                     BigDecimal subtract = userAssets.getAvailableBalance().subtract(bound);
                     if(subtract.compareTo(BigDecimal.ZERO) >= 0){
                         userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(bound));
@@ -268,12 +275,20 @@
                         if(applyNumber > 0){
                             //需要退回的资金
                             BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber));
+                            //如果不是墨西哥币需要转换金额
+                            if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
+                                refundPrice = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), refundPrice);
+                            }
                             userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(refundPrice));
                             userAssets.setFreezeMoney(userAssets.getFreezeMoney().subtract(refundPrice));
                         }
                     }else{
                         if(applyNumber > 0){
                             BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber));
+                            //如果不是墨西哥币需要转换金额
+                            if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) {
+                                refundPrice = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), refundPrice);
+                            }
                             BigDecimal subtract = refundPrice.subtract(userAssets.getAmountToBeCovered());
                             if(subtract.compareTo(BigDecimal.ZERO) <= 0){//如果退回的资金不足补足待补则直接减
                                 userAssets.setAmountToBeCovered(userAssets.getAmountToBeCovered().subtract(refundPrice));

--
Gitblit v1.9.3