ipo
zyy
2025-12-31 f7d714ecc4210b96de9e78eacf6fad394533a082
trading-order-admin/src/main/java/com/yami/trading/admin/task/NewSharesTask.java
@@ -1,11 +1,10 @@
package com.yami.trading.admin.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yami.trading.bean.etf.domain.EtfMinuteKLine;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.bean.ipo.UserPromiseRecord;
import com.yami.trading.bean.model.Wallet;
import com.yami.trading.service.WalletService;
import com.yami.trading.service.ipo.UserPromiseRecordService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -15,7 +14,6 @@
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -32,8 +30,11 @@
    @Autowired
    WalletService walletService;
    @Autowired
    UserPromiseRecordService userPromiseRecordService;
    /**
     * 同步系统所需要的股票
     * 待补自动扣费
     */
    @Scheduled(cron = "0 0/5 * * * ?")
    public void syncINStockData() {
@@ -50,13 +51,40 @@
                List<Wallet> walletList = walletService.list(queryWrapper);
                if (!walletList.isEmpty()) {
                    log.info("==================进入待补自动扣费================");
                    walletList.forEach((wallet) -> {
                        BigDecimal money = wallet.getMoney();
                        BigDecimal amountToBeCovered = wallet.getAmountToBeCovered();
                        if (money.compareTo(amountToBeCovered) >= 0) {
                            wallet.setMoney(money.subtract(amountToBeCovered));
                            wallet.setAmountToBeCovered(BigDecimal.ZERO);
                            log.info("用户id{}已补完待补", wallet.getUserId());
                            LambdaQueryWrapper<UserPromiseRecord> queryWrapper2 = new LambdaQueryWrapper<>();
                            queryWrapper2.eq(UserPromiseRecord::getUserId, wallet.getUserId());
                            queryWrapper2.eq(UserPromiseRecord::getStatus, 1);
                            List<UserPromiseRecord> userPromiseRecords = userPromiseRecordService.list(queryWrapper2);
                            if (!userPromiseRecords.isEmpty()) {
                                userPromiseRecords.forEach((userPromiseRecord) -> {
                                    userPromiseRecord.setStatus(2);
                                    log.info("订单{}已确认认缴", userPromiseRecord.getOrderNo());
                                });
                                userPromiseRecordService.updateBatchById(userPromiseRecords);
                            }
                        } else {
                            //资金不足
                            BigDecimal newAmountToBeCovered = amountToBeCovered.subtract(money);
                            wallet.setMoney(BigDecimal.ZERO);
                            wallet.setAmountToBeCovered(newAmountToBeCovered);
                            log.info("用户id{}补待补{}", wallet.getUserId(), money.toString());
                        }
                        walletService.updateById(wallet);
                    });
                }
            } catch (Exception e) {
                log.error("同步股票数据出错", e);
                log.error("待补自动扣费出错", e);
            } finally {
                syncINStockDataLock.unlock();
                syncINStockData.set(false);