zyy
2025-12-05 6983124000997b16d88b13ee99af339566a69128
ETF改版
10 files modified
181 ■■■■ changed files
trading-order-admin/src/main/java/com/yami/trading/admin/controller/dz/AdminETFDarkPoolsController.java 2 ●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/admin/controller/dz/AdminETFDzController.java 7 ●●●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/admin/controller/dz/AdminStockDarkPoolsController.java 2 ●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/admin/controller/dz/AdminStockDzController.java 2 ●●● patch | view | raw | blame | history
trading-order-bean/src/main/java/com/yami/trading/bean/dz/StockDz.java 4 ●●●● patch | view | raw | blame | history
trading-order-bean/src/main/java/com/yami/trading/bean/dz/dto/ExchangeApplyOrderDzDto.java 9 ●●●●● patch | view | raw | blame | history
trading-order-common/src/main/java/com/yami/trading/common/util/DateUtil.java 12 ●●●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/dz/StockDzService.java 2 ●●● patch | view | raw | blame | history
trading-order-service/src/main/java/com/yami/trading/service/dz/impl/StockDzServiceImpl.java 139 ●●●● patch | view | raw | blame | history
trading-order-service/src/main/resources/mapper/dz/StockDzMapper.xml 2 ●●● patch | view | raw | blame | history
trading-order-admin/src/main/java/com/yami/trading/admin/controller/dz/AdminETFDarkPoolsController.java
@@ -50,7 +50,7 @@
                                     @RequestParam(value = "period", required = false) Integer period,
                                     @RequestParam(value = "nowPrice") String nowPrice,
                                     @RequestParam(value = "switchType", defaultValue = "0") Integer switchType) {
        return stockDzService.addByAdmin(stockCode, stockNum, password, startTime, endTime, discount, period,nowPrice,switchType, Constants.indices_dark);
        return stockDzService.addByAdmin(stockCode, stockNum, password, startTime, endTime, discount, period,nowPrice,switchType, Constants.indices_dark, 0);
    }
    /**
trading-order-admin/src/main/java/com/yami/trading/admin/controller/dz/AdminETFDzController.java
@@ -37,15 +37,16 @@
    @ApiOperation("新增大宗")
    @PostMapping({"addByAdmin.do"})
    public Result addByAdmin(@RequestParam(value = "stockCode") String stockCode,
                                     @RequestParam(value = "stockNum") String stockNum,
                                     @RequestParam(value = "stockNum", required = false) String stockNum,
                                     @RequestParam(value = "password", required = false) String password,
                                     @RequestParam(value = "startTime") String startTime,
                                     @RequestParam(value = "endTime") String endTime,
                                     @RequestParam(value = "discount", required = false) String discount,
                                     @RequestParam(value = "period", required = false) Integer period,
                                     @RequestParam(value = "nowPrice") String nowPrice,
                                     @RequestParam(value = "switchType", defaultValue = "0") Integer switchType) {
        return stockDzService.addByAdmin(stockCode, stockNum, password, startTime, endTime, discount, period,nowPrice,switchType, Constants.indices);
                                     @RequestParam(value = "switchType", defaultValue = "0") Integer switchType,
                                     @RequestParam(value = "dayRate", defaultValue = "0") double dayRate) {
        return stockDzService.addByAdmin(stockCode, stockNum, password, startTime, endTime, discount, period,nowPrice,switchType, Constants.indices, dayRate);
    }
    /**
trading-order-admin/src/main/java/com/yami/trading/admin/controller/dz/AdminStockDarkPoolsController.java
@@ -56,7 +56,7 @@
                                     @RequestParam(value = "period", required = false) Integer period,
                                     @RequestParam(value = "nowPrice") String nowPrice,
                                     @RequestParam(value = "switchType", defaultValue = "0") Integer switchType) {
        return stockDzService.addByAdmin(stockCode, stockNum, password, startTime, endTime, discount, period,nowPrice,switchType, Constants.US_DARK);
        return stockDzService.addByAdmin(stockCode, stockNum, password, startTime, endTime, discount, period,nowPrice,switchType, Constants.US_DARK, 0);
    }
    /**
trading-order-admin/src/main/java/com/yami/trading/admin/controller/dz/AdminStockDzController.java
@@ -53,7 +53,7 @@
                                     @RequestParam(value = "period", required = false) Integer period,
                                     @RequestParam(value = "nowPrice") String nowPrice,
                                     @RequestParam(value = "switchType", defaultValue = "0") Integer switchType) {
        return stockDzService.addByAdmin(stockCode, stockNum, password, startTime, endTime, discount, period,nowPrice,switchType, Constants.US_STOCKS);
        return stockDzService.addByAdmin(stockCode, stockNum, password, startTime, endTime, discount, period,nowPrice,switchType, Constants.US_STOCKS, 0);
    }
    /**
trading-order-bean/src/main/java/com/yami/trading/bean/dz/StockDz.java
@@ -53,4 +53,8 @@
    //价格
    private BigDecimal nowPrice;
    //日利率
    private double dayRate;
}
trading-order-bean/src/main/java/com/yami/trading/bean/dz/dto/ExchangeApplyOrderDzDto.java
@@ -21,6 +21,15 @@
    @ApiModelProperty("浮动盈亏比例")
    private double profitLossPercentage;
    @ApiModelProperty("日收益率")
    private double dayRate;
    @ApiModelProperty("日收益")
    private double dayEarnings;
    @ApiModelProperty("周期")
    private Integer period;
    @ApiModelProperty("推荐人")
    private String recomUserName;
trading-order-common/src/main/java/com/yami/trading/common/util/DateUtil.java
@@ -5,6 +5,7 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@@ -924,4 +925,15 @@
        return berlinZonedTime.format(formatter);
    }
    public static void main(String[] args) {
        String start="2025-12-04 22:37:22";
        Date startTime= Date.from(
                LocalDateTime.parse(start, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
                        .atZone(ZoneId.systemDefault())
                        .toInstant()
        );
        Date date=new Date();
        System.out.println(dateNum(startTime, date));;
    }
}
trading-order-service/src/main/java/com/yami/trading/service/dz/StockDzService.java
@@ -13,7 +13,7 @@
    Result getDzList(int pageNum, int pageSize, String orderBy, String keyWords, String stockType);
    Result addByAdmin(String stockCode, String stockNum, String password, String startTime, String endTime, String discount,Integer period,String nowPrice,Integer switchType, String stockType);
    Result addByAdmin(String stockCode, String stockNum, String password, String startTime, String endTime, String discount,Integer period,String nowPrice,Integer switchType, String stockType, double dayRate);
    Result getDzListByAdmin(int pageNum, int pageSize, String keywords, String stockType);
trading-order-service/src/main/java/com/yami/trading/service/dz/impl/StockDzServiceImpl.java
@@ -24,6 +24,7 @@
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.common.util.Arith;
import com.yami.trading.common.util.DateUtils;
import com.yami.trading.common.util.RandomUtil;
import com.yami.trading.dao.dz.ExchangeApplyOrderDzMapper;
import com.yami.trading.dao.dz.StockDzMapper;
@@ -99,9 +100,12 @@
    }
    @Override
    public Result addByAdmin(String stockCode, String stockNum, String password, String startTime, String endTime, String discount,Integer period,String nowPrice,Integer switchType, String stockType) {
        if (stockCode == null || stockCode.isEmpty() ||stockNum == null || stockNum.isEmpty() || startTime == null || startTime.isEmpty() ||endTime == null || endTime.isEmpty() || nowPrice == null){
    public Result addByAdmin(String stockCode, String stockNum, String password, String startTime, String endTime, String discount,Integer period,String nowPrice,Integer switchType, String stockType, double dayRate) {
        if (stockCode == null || stockCode.isEmpty() || startTime == null || startTime.isEmpty() ||endTime == null || endTime.isEmpty() || nowPrice == null){
            return Result.failed("参数不能为空");
        }
        if (stockType.equalsIgnoreCase(Item.indices) && dayRate == 0) {
            return Result.failed("请输入日收益率");
        }
        //该类型是否已添加
@@ -125,7 +129,9 @@
        stockDz.setIsLock(0);
        stockDz.setIsShow(1);
        stockDz.setAddTime(new Date());
        stockDz.setStockNum(Integer.valueOf(stockNum));
        if (stockNum != null && !stockNum.isEmpty()){
            stockDz.setStockNum(Integer.valueOf(stockNum));
        }
        stockDz.setPassword(password);
        stockDz.setStartTime(DateUtil.parseDateTime(startTime));
        stockDz.setEndTime(DateUtil.parseDateTime(endTime));
@@ -133,6 +139,7 @@
        stockDz.setPeriod(period);
        stockDz.setSwitchType(switchType);
        stockDz.setNowPrice(new BigDecimal(nowPrice));
        stockDz.setDayRate(dayRate);
        if (save(stockDz)) {
            return Result.succeed("添加成功");
        }
@@ -201,15 +208,33 @@
                    } else { //已结算
                        closePrice = dz.getClosePrice();
                    }
                    //盈亏
                    double profitLoss = (closePrice - dz.getPrice()) * dz.getSymbolValue();
                    DecimalFormat df = new DecimalFormat("#.##");
                    String resultStr = df.format(profitLoss);
                    dz.setProfitLoss(Double.parseDouble(resultStr));
                    if (dz.getDayRate() > 0) {
                        Date startTime = dz.getCreateTime();
                        // 计算相差天数
                        int num = com.yami.trading.common.util.DateUtil.dateNum(startTime, new Date());
                        num = Math.max(1, Math.min(num, dz.getPeriod()));
                        double dayEarnings = dz.getDayRate() * dz.getVolume();
                        double profitLoss = dayEarnings * num;
                        DecimalFormat df = new DecimalFormat("#.##");
                        String resultStr = df.format(profitLoss);
                        String resultStr2 = df.format(dayEarnings);
                        dz.setProfitLoss(Double.parseDouble(resultStr));
                        dz.setDayEarnings(Double.parseDouble(resultStr2));
                    double profitPercentage = (profitLoss / dz.getVolume()) * 100;
                    String resultPer = df.format(profitPercentage);
                    dz.setProfitLossPercentage(Double.parseDouble(resultPer));
                        double profitPercentage = (profitLoss / dz.getVolume()) * 100;
                        String resultPer = df.format(profitPercentage);
                        dz.setProfitLossPercentage(Double.parseDouble(resultPer));
                    } else {
                        //盈亏
                        double profitLoss = (closePrice - dz.getPrice()) * dz.getSymbolValue();
                        DecimalFormat df = new DecimalFormat("#.##");
                        String resultStr = df.format(profitLoss);
                        dz.setProfitLoss(Double.parseDouble(resultStr));
                        double profitPercentage = (profitLoss / dz.getVolume()) * 100;
                        String resultPer = df.format(profitPercentage);
                        dz.setProfitLossPercentage(Double.parseDouble(resultPer));
                    }
                });
            }
@@ -238,7 +263,7 @@
    public Result buyDz(String dzId, String password, double num, String partyId) {
        try {
            if (num <= 0) {
                throw new YamiShopBindException("请输入正确的货币数量");
                throw new YamiShopBindException("请输入");
            }
            User party = userService.getById(partyId);
            if (!party.isEnabled()) {
@@ -252,7 +277,6 @@
                    throw new YamiShopBindException("无网络");
                }
            }
            StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("uuid", dzId));
            if (stockDz == null) {
@@ -273,8 +297,15 @@
            if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
                throw new YamiShopBindException("股票价格0,请重试");
            }
            if (stockDz.getStockNum() > num) {
                return Result.failed("请购买最小数量");
            boolean isETF = stockDz.getStockType().equalsIgnoreCase(Item.indices);
            if (isETF) {
                if (stockDz.getNowPrice().doubleValue() > num) {
                    return Result.failed("请输入最小购买金额");
                }
            } else {
                if (stockDz.getStockNum() > num) {
                    return Result.failed("请购买最小数量");
                }
            }
            boolean isOpen = MarketOpenChecker.isMarketOpenBuyDz(Item.US_STOCKS);
            if (!isOpen) {
@@ -283,7 +314,12 @@
            Wallet wallet = this.walletService.saveWalletByPartyId(partyId);
            BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(num));
            BigDecimal buyAmt;
            if (isETF) {
                buyAmt = new BigDecimal(num);
            } else {
                buyAmt = nowPrice.multiply(new BigDecimal(num));
            }
            //手续费比率
            Double feeRate = sysparaService.find("exchange_apply_order_dz_buy_fee").getDouble();
            BigDecimal orderFree = buyAmt.multiply(BigDecimal.valueOf(feeRate));
@@ -362,16 +398,27 @@
                exchangeApplyOrderDzMapper.updateById(order);
                return Result.succeed("操作成功");
            }
            if (orderNum > order.getSymbolValue()) {
                throw new YamiShopBindException("输入数量大于用户买入数量");
            }
            StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("uuid", order.getDzId()));
            if (stockDz == null) {
                throw new YamiShopBindException("大宗不存在");
            }
            BigDecimal nowPrice = stockDz.getNowPrice();
            BigDecimal nowPrice;
            boolean isETF = stockDz.getStockType().equalsIgnoreCase(Item.indices);
            if (isETF) {
                if (orderNum > order.getPrice()) {
                    throw new YamiShopBindException("输入金额大于用户买入金额");
                }
                nowPrice = new  BigDecimal(orderNum);
                order.setPrice(nowPrice.doubleValue());
            } else {
                if (orderNum > order.getSymbolValue()) {
                    throw new YamiShopBindException("输入数量大于用户买入数量");
                }
                nowPrice = stockDz.getNowPrice();
            }
            if (price > 0) {
                nowPrice = BigDecimal.valueOf(price);
                order.setPrice(price);
@@ -381,7 +428,10 @@
            }
            Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
            BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(orderNum));
            BigDecimal buyAmt = nowPrice;
            if (!isETF) {
                buyAmt = nowPrice.multiply(new BigDecimal(orderNum));
            }
            //手续费比率
            Double feeRate = sysparaService.find("exchange_apply_order_dz_buy_fee").getDouble();
            BigDecimal orderFree = buyAmt.multiply(BigDecimal.valueOf(feeRate));
@@ -492,7 +542,13 @@
                throw new YamiShopBindException("大宗不存在");
            }
            BigDecimal nowPrice = stockDz.getNowPrice();
            BigDecimal nowPrice;
            boolean isETF = stockDz.getStockType().equalsIgnoreCase(Item.indices);
            if (isETF) {
                nowPrice = BigDecimal.valueOf(order.getPrice());
            } else {
                nowPrice = stockDz.getNowPrice();
            }
            if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
                throw new YamiShopBindException("股票价格0,请重试");
            }
@@ -509,14 +565,24 @@
                    return Result.failed("未到平仓时间");
                }
            }
            if (stockDz.getStockName().contains("测试")) {
            boolean isOpen = MarketOpenChecker.isMarketOpenByItemCloseType(Item.US_STOCKS);
            if (!isOpen) {
                return Result.failed("当前股市休市");
            } else {
                boolean isOpen = MarketOpenChecker.isMarketOpenByItemCloseType(Item.US_STOCKS);
                if (!isOpen) {
                    return Result.failed("当前股市休市");
                }
            }
            Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId());
            BigDecimal sellAmt = nowPrice.multiply(new BigDecimal(num));
            BigDecimal sellAmt;
            if (isETF) {
                sellAmt = nowPrice;
            } else {
                sellAmt = nowPrice.multiply(new BigDecimal(num));
            }
            //手续费比率
            Double feeRate = sysparaService.find("exchange_apply_order_dz_sell_fee").getDouble();
            BigDecimal orderFree = sellAmt.multiply(BigDecimal.valueOf(feeRate));
@@ -524,13 +590,22 @@
                orderFree = BigDecimal.ONE;
            }
            String symbol = stockDz.getStockCode();
            Realtime realtime = this.dataService.realtime(symbol).get(0);
            double closePrice = realtime.getClose();
            //结算金额
            double closeAmt = closePrice * num - orderFree.doubleValue();
            double closeAmt;
            String symbol = stockDz.getStockCode();
            double closePrice;
            if (isETF) {
                //按日收益率结算
                closeAmt = order.getPrice();
                closeAmt = closeAmt + stockDz.getDayRate() * closeAmt * stockDz.getPeriod();
                closePrice = closeAmt;
                closeAmt = closeAmt - orderFree.doubleValue();
            } else {
                Realtime realtime = this.dataService.realtime(symbol).get(0);
                closePrice = realtime.getClose();
                closeAmt = closePrice * num - orderFree.doubleValue();
            }
            if (closeAmt < 0) {
                return Result.failed("余额不足");
            }
trading-order-service/src/main/resources/mapper/dz/StockDzMapper.xml
@@ -51,7 +51,7 @@
    <select id="getDzOrderList" resultType="com.yami.trading.bean.dz.dto.ExchangeApplyOrderDzDto" parameterType="map">
        SELECT
        t.*,s.stock_name
        t.*,s.stock_name,s.day_rate,s.period
        FROM t_exchange_apply_order_dz t
        LEFT JOIN t_stock_dz s ON t.dz_id=s.uuid
        WHERE 1=1