zyy
2026-03-15 35ececb0d9959e010f1ac160f20afd4dba27de57
trading-order-service/src/main/java/com/yami/trading/service/finance/service/impl/FinanceOrderServiceImpl.java
@@ -4,12 +4,10 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.trading.bean.constans.WalletConstants;
import com.yami.trading.bean.data.domain.Realtime;
import com.yami.trading.bean.finance.Finance;
import com.yami.trading.bean.finance.FinanceOrder;
import com.yami.trading.bean.model.MoneyLog;
import com.yami.trading.bean.model.User;
import com.yami.trading.bean.model.UserRecom;
import com.yami.trading.bean.model.Wallet;
import com.yami.trading.bean.model.*;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.exception.BusinessException;
import com.yami.trading.common.util.Arith;
@@ -19,6 +17,7 @@
import com.yami.trading.dao.finance.FinanceOrderMapper;
import com.yami.trading.service.MoneyLogService;
import com.yami.trading.service.WalletService;
import com.yami.trading.service.data.DataService;
import com.yami.trading.service.finance.service.FinanceOrderService;
import com.yami.trading.service.finance.service.FinanceService;
import com.yami.trading.service.syspara.SysparaService;
@@ -53,6 +52,8 @@
    protected UserDataService userDataService;
    @Autowired
    protected UserRecomService userRecomService;
    @Autowired
    protected DataService dataService;
    public void saveCreate(FinanceOrder entity) {
@@ -151,27 +152,43 @@
        }
        if (get_amount > 0) {
            Wallet wallet = this.walletService.saveWalletByPartyId((String) entity.getPartyId());
            double amount_before = wallet.getMoney().doubleValue();
//         wallet.setMoney(Arith.add(wallet.getMoney(), get_amount));
//         this.walletService.update(wallet);
            this.walletService.update(wallet.getUserId(), get_amount);
            String symbol = entity.getBuyCurrency().toLowerCase();
            double amount_before;
            double amount_after;
            double amount;
            if (symbol.equals("usdt")) {
                Wallet wallet = this.walletService.saveWalletByPartyId(entity.getPartyId());
                amount_before = wallet.getMoney().doubleValue();
                amount_after = Arith.add(amount_before, get_amount);
                amount = get_amount;
                this.walletService.update(wallet.getUserId(), get_amount);
            } else {
                //USDT转对应symbol
                Realtime realtime = this.dataService.realtime(symbol).get(0);
                amount = Arith.div(get_amount, realtime.getClose(), 8);
                WalletExtend walletExtend = walletService.saveExtendByPara(entity.getPartyId(), symbol);
                amount_before = walletExtend.getAmount();
                amount_after = Arith.add(amount_before, get_amount);
                this.walletService.updateExtend(walletExtend.getPartyId(), walletExtend.getWallettype(), amount);
            }
            /**
             * 保存资金日志
             */
            MoneyLog moneylog = new MoneyLog();
            moneylog.setCategory(Constants.MONEYLOG_CATEGORY_FINANCE);
            moneylog.setAmountBefore(BigDecimal.valueOf(amount_before));
            moneylog.setAmount(BigDecimal.valueOf(Arith.add(0, get_amount)));
            moneylog.setAmountAfter(BigDecimal.valueOf(Arith.add(amount_before, get_amount)));
            moneylog.setAmount(BigDecimal.valueOf(Arith.add(0, amount)));
            moneylog.setAmountAfter(BigDecimal.valueOf(amount_after));
            moneylog.setLog("赎回理财产品,订单号[" + entity.getOrderNo() + "]");
            moneylog.setUserId((String) entity.getPartyId());
            moneylog.setWalletType(Constants.WALLET);
            moneylog.setUserId(entity.getPartyId());
            moneylog.setWalletType(symbol.toUpperCase());
            moneylog.setContentType(WalletConstants.MONEYLOG_CONTENT_FINANCE_BACK);
            moneylog.setCreateTime(systemTime != null ? systemTime : new Date());
            moneylog.setCreateTime(new Date());
            moneyLogService.save(moneylog);
            entity.setVolume(amount);
        }
        entity.setCloseTime(new Date());// 赎回时间
@@ -189,27 +206,43 @@
        }
        if (get_amount > 0) {
            Wallet wallet = this.walletService.saveWalletByPartyId(entity.getPartyId().toString());
            double amount_before = wallet.getMoney().doubleValue();
//         wallet.setMoney(Arith.add(wallet.getMoney(), get_amount));
//         this.walletService.update(wallet);
            this.walletService.update(wallet.getUserId(), get_amount);
            String symbol = entity.getBuyCurrency().toLowerCase();
            double amount_before;
            double amount_after;
            double amount;
            if (symbol.equals("usdt")) {
                Wallet wallet = this.walletService.saveWalletByPartyId(entity.getPartyId());
                amount_before = wallet.getMoney().doubleValue();
                amount_after = Arith.add(amount_before, get_amount);
                amount = get_amount;
                this.walletService.update(wallet.getUserId(), get_amount);
            } else {
                //USDT转对应symbol
                Realtime realtime = this.dataService.realtime(symbol).get(0);
                amount = Arith.div(get_amount, realtime.getClose(), 8);
                WalletExtend walletExtend = walletService.saveExtendByPara(entity.getPartyId(), symbol);
                amount_before = walletExtend.getAmount();
                amount_after = Arith.add(amount_before, amount);
                this.walletService.updateExtend(walletExtend.getPartyId(), walletExtend.getWallettype(), amount);
            }
            /**
             * 保存资金日志
             */
            MoneyLog moneylog = new MoneyLog();
            moneylog.setCategory(Constants.MONEYLOG_CATEGORY_FINANCE);
            moneylog.setAmountBefore(BigDecimal.valueOf(amount_before));
            moneylog.setAmount(BigDecimal.valueOf(Arith.add(0, get_amount)));
            moneylog.setAmountAfter(BigDecimal.valueOf(Arith.add(wallet.getMoney().doubleValue(), get_amount)));
            moneylog.setAmount(BigDecimal.valueOf(Arith.add(0, amount)));
            moneylog.setAmountAfter(BigDecimal.valueOf(amount_after));
            moneylog.setLog("赎回理财产品,订单号[" + entity.getOrderNo() + "]");
            moneylog.setUserId(entity.getPartyId().toString());
            moneylog.setWalletType(Constants.WALLET);
            moneylog.setUserId(entity.getPartyId());
            moneylog.setWalletType(symbol.toUpperCase());
            moneylog.setContentType(WalletConstants.MONEYLOG_CONTENT_FINANCE_BACK);
            moneylog.setCreateTime(new Date());
            moneyLogService.save(moneylog);
            entity.setVolume(amount);
        }
        entity.setCloseTime(new Date());// 赎回时间
@@ -776,8 +809,6 @@
        if (get_amount > 0) {
            Wallet wallet = this.walletService.saveWalletByPartyId(entity.getPartyId().toString());
            double amount_before = wallet.getMoney().doubleValue();
//         wallet.setMoney(Arith.add(wallet.getMoney(), get_amount));
//         this.walletService.update(wallet);
            this.walletService.update(wallet.getUserId().toString(), get_amount);
            /**
             * 保存资金日志