zyy
2025-10-29 d4ab82f09c8900c603703d48a2635b54f872d122
trading-order-service/src/main/java/com/yami/trading/service/dz/impl/StockDzServiceImpl.java
@@ -7,12 +7,16 @@
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.trading.bean.contract.domain.ContractApplyOrder;
import com.yami.trading.bean.data.domain.Realtime;
import com.yami.trading.bean.dz.ExchangeApplyOrderDz;
import com.yami.trading.bean.dz.StockDz;
import com.yami.trading.bean.exchange.ExchangeApplyOrder;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.bean.model.MoneyLog;
import com.yami.trading.bean.model.User;
import com.yami.trading.bean.model.Wallet;
import com.yami.trading.bean.model.WalletExtend;
import com.yami.trading.bean.syspara.domain.Syspara;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.domain.Result;
@@ -23,7 +27,9 @@
import com.yami.trading.dao.dz.StockDzMapper;
import com.yami.trading.service.MoneyLogService;
import com.yami.trading.service.WalletService;
import com.yami.trading.service.data.DataService;
import com.yami.trading.service.dz.StockDzService;
import com.yami.trading.service.exchange.ExchangeApplyOrderService;
import com.yami.trading.service.item.ItemService;
import com.yami.trading.service.syspara.SysparaService;
import com.yami.trading.service.user.UserService;
@@ -63,6 +69,12 @@
    @Resource
    private ItemService itemService;
    @Resource
    private ExchangeApplyOrderService exchangeApplyOrderService;
    @Resource
    private DataService dataService;
    @Override
    public Result getDzList(int pageNum, int pageSize, String orderBy, String keyWords, String stockType) {
@@ -266,11 +278,12 @@
            walletService.update(wallet.getUserId(), Arith.sub(0, orderAmt.doubleValue()));
            //TODO 转持仓
            this.intoPosition(order, stockDz.getStockType());
            MoneyLog log = new MoneyLog();
            log.setCategory(Constants.MONEYLOG_CATEGORY_EXCHANGE);
            String name = Constants.MONEYLOG_MAP.get(Constants.US_STOCKS);
            String type2 = Constants.MONEYLOG_MAP_TYPE.get(Constants.US_STOCKS);
            String name = Constants.MONEYLOG_MAP.get(stockDz.getStockType());
            String type2 = Constants.MONEYLOG_MAP_TYPE.get(stockDz.getStockType());
            log.setAmountBefore(amountBefore);
            log.setAmount(orderAmt.negate());
            log.setAmountAfter(amountBefore.subtract(orderAmt));
@@ -340,12 +353,12 @@
            walletService.update(wallet.getUserId(), Arith.sub(0, orderAmt.doubleValue()));
            //TODO 转持仓
            this.intoPosition(order, stockDz.getStockType());
            MoneyLog log = new MoneyLog();
            log.setCategory(Constants.MONEYLOG_CATEGORY_EXCHANGE);
            String name = Constants.MONEYLOG_MAP.get(Constants.US_STOCKS);
            String type2 = Constants.MONEYLOG_MAP_TYPE.get(Constants.US_STOCKS);
            String name = Constants.MONEYLOG_MAP.get(stockDz.getStockType());
            String type2 = Constants.MONEYLOG_MAP_TYPE.get(stockDz.getStockType());
            log.setAmountBefore(amountBefore);
            log.setAmount(orderAmt.negate());
            log.setAmountAfter(amountBefore.subtract(orderAmt));
@@ -364,5 +377,44 @@
        }
    }
    public void intoPosition(ExchangeApplyOrderDz orderDz, String stockType) {
        ExchangeApplyOrder exOrder = new ExchangeApplyOrder();
        exOrder.setPartyId(orderDz.getPartyId());
        exOrder.setSymbol(orderDz.getSymbol());
        exOrder.setOffset(ExchangeApplyOrder.OFFSET_OPEN);
        exOrder.setSymbolValue(orderDz.getSymbolValue());
        exOrder.setVolume(orderDz.getVolume());
        exOrder.setPrice(orderDz.getPrice());
        exOrder.setOrderPriceType(ContractApplyOrder.ORDER_PRICE_TYPE_OPPONENT);
        exOrder.setState(ExchangeApplyOrder.STATE_CREATED);
        exOrder.setClosePrice(orderDz.getPrice());
        exOrder.setOrderNo(com.yami.trading.common.util.DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8));
        exOrder.setFee(orderDz.getFee());
        exOrder.setCreateTime(new Date());
        double realValue = exOrder.getSymbolValue();
        //入账
        WalletExtend walletExtend = walletService.saveExtendByPara(exOrder.getPartyId(), exOrder.getSymbol());
        double amountBeforeExtend = walletExtend.getAmount();
        this.walletService.updateExtend(walletExtend.getPartyId(), walletExtend.getWallettype(), realValue);
        MoneyLog log = new MoneyLog();
        log.setCategory(Constants.MONEYLOG_CATEGORY_EXCHANGE);
        String name = Constants.MONEYLOG_MAP.get(stockType);
        String type2 = Constants.MONEYLOG_MAP_TYPE.get(stockType);
        log.setAmountBefore(new BigDecimal(amountBeforeExtend));
        log.setAmount(BigDecimal.valueOf(realValue));
        log.setAmountAfter(BigDecimal.valueOf(amountBeforeExtend + realValue));
        log.setLog(name + type2 + "现货交易买入委托单成交,订单号[" + exOrder.getOrderNo() + "]");
        log.setUserId(exOrder.getPartyId());
        log.setSymbol(exOrder.getSymbol());
        log.setWalletType(exOrder.getSymbol());
        log.setContentType(type2 + Constants.MONEYLOG_CONTENT_OPEN);
        // 记录账变日志
        moneyLogService.save(log);
        exchangeApplyOrderService.save(exOrder);
    }
}