1
zj
2024-04-26 92310aaa56ae040c9147f6495630f2c1ae41fac2
src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -1,5 +1,6 @@
package com.nq.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nq.dao.*;
import com.nq.enums.EConfigKey;
@@ -177,7 +178,7 @@
        BigDecimal   fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
        BigDecimal availableBalance =  fundratio.multiply(userAssets.getAvailableBalance());
        if (availableBalance.compareTo(buyAmt.add(orderFree)) < 0) {
            return ServerResponse.createByErrorMsg("订单失败,余额不足", request);
            return ServerResponse.createByErrorMsg("订单失败,配资不足", request);
        }
        UserPosition userPosition = new UserPosition();
        if (profitTarget != null && profitTarget.compareTo(new BigDecimal("0")) > 0) {
@@ -316,7 +317,7 @@
    public ServerResponse sell(String positionSn, int doType, HttpServletRequest request) {
        UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn);
        // 手续费率
        BigDecimal siitteBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ;
        BigDecimal siitteBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.SELL_HANDLING_CHARGE.getCode()).getCValue()) ;
        Boolean b = tradingHourService.timeCheck(userPosition.getStockCode());
        if (!b) {
@@ -337,7 +338,7 @@
        }
        Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode()));
        if (!priceServices.isLimitDownSell(stock.getStockCode())) {
            return ServerResponse.createByErrorMsg("股票垫停,无法平仓", request);
            return ServerResponse.createByErrorMsg("股票跌停,无法平仓", request);
        }
        BigDecimal nowPrice = priceServices.getNowPrice(userPosition.getStockCode());
        if (nowPrice.compareTo(new BigDecimal("0")) != 1) {
@@ -1154,24 +1155,23 @@
        if (userStockSubscribe == null) {
            return ServerResponse.createByErrorMsg("无该申购记录");
        }
        StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<StockSubscribe>().eq("code", userStockSubscribe.getNewCode()));
        StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<StockSubscribe>().eq("code", userStockSubscribe.getNewCode()).eq("type",userStockSubscribe.getType()));
        if (userStockSubscribe == null) {
            return ServerResponse.createByErrorMsg("该新股不存在");
        }
        if (userStockSubscribe.getStatus() == 4 || userStockSubscribe.getStatus() == 3 && stockSubscribe.getType() == 2) {
//                String sinaStock = SinaStockApi.getSinaStock(stockSubscribe.getStockType()+userStockSubscribe.getNewCode());
//                String[] arrayOfString = sinaStock.split(",");
//                 if (arrayOfString.length < 10){
//                 return ServerResponse.createByErrorMsg("数据源无该新股数据,转持仓失败");
//                 }
            Stock stock = stockMapper.selectOne(new LambdaQueryWrapper<Stock>().eq(Stock::getStockSpell, userStockSubscribe.getNewCode()));
            if(null == stock){
                return ServerResponse.createByErrorMsg("该新股不存在");
            }
            UserPosition userPosition = new UserPosition();
            userPosition.setPositionType(1);
            userPosition.setPositionSn(KeyUtils.getUniqueKey());
            userPosition.setUserId(userStockSubscribe.getUserId());
            userPosition.setNickName(userStockSubscribe.getRealName());
            userPosition.setAgentId(userStockSubscribe.getAgentId());
            userPosition.setStockCode(userStockSubscribe.getNewCode());
            userPosition.setStockCode(stock.getStockCode());
            userPosition.setStockSpell(stock.getStockSpell());
            userPosition.setStockName(userStockSubscribe.getNewName());
            userPosition.setStockGid(stockSubscribe.getStockType() + userStockSubscribe.getNewCode());
@@ -1208,14 +1208,6 @@
            log.info("用户购买印花税(配资后总资金 * 百分比) = {}", buy_yhs_amt);
            userPosition.setOrderSpread(buy_yhs_amt);
            //            SiteSpread siteSpread = iSiteSpreadService.findSpreadRateOne(new BigDecimal(stock_crease), buy_amt, stock.getStockCode(), now_price);
            //            BigDecimal spread_rate_amt = new BigDecimal("0");
            //            if(siteSpread != null){
            //                spread_rate_amt = buy_amt.multiply(siteSpread.getSpreadRate()).setScale(2, 4);
            //                log.info("用户购买点差费(配资后总资金 * 百分比{}) = {}", siteSpread.getSpreadRate(), spread_rate_amt);
            //            } else{
            //                log.info("用户购买点差费(配资后总资金 * 百分比{}) = {}", "设置异常", spread_rate_amt);
            //            }
            BigDecimal spread_rate_amt = new BigDecimal(0);
            userPosition.setSpreadRatePrice(spread_rate_amt);
@@ -1239,7 +1231,7 @@
                userStockSubscribeMapper.update1(userStockSubscribe);
                if (userStockSubscribe.getType() == 1 || userStockSubscribe.getType() == 2) {
                    User user = userMapper.selectById(userStockSubscribe.getUserId());
                    ret = userMapper.updateByPrimaryKey(user);
                    ret = userMapper.updateById(user);
                }
                if (ret > 0) {
                    return ServerResponse.createBySuccessMsg("新股转持仓成功");
@@ -1538,7 +1530,7 @@
        //价格处理
        Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", stockDz.getStockCode()));
        if(stockDz.getStartTime().after(new Date()) || stockDz.getEndTime().after(new Date())){
        if(stockDz.getStartTime().getTime() > new Date().getTime() || stockDz.getEndTime().getTime() < new Date().getTime()){
            return ServerResponse.createByErrorMsg("不在大宗交易所时间之内", request);
        }
        BigDecimal nowPrice = priceServices.getNowPrice(stockCode).multiply(stockDz.getDiscount());
@@ -1554,7 +1546,7 @@
        BigDecimal   fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
        BigDecimal availableBalance =  fundratio.multiply(userAssets.getAvailableBalance());
        if (buyAmt.compareTo(availableBalance) > 0) {
            return ServerResponse.createByErrorMsg("订单失败,余额不足", request);
            return ServerResponse.createByErrorMsg("订单失败,配资不足", request);
        }
        UserPosition userPosition = new UserPosition();
        userPosition.setPositionType(3);
@@ -1654,7 +1646,7 @@
        // 检查股票是否垫停
        Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", position.getStockCode()));
        if (!priceServices.isLimitDownSell(stock.getStockCode())) {
            log.info("股票垫停,无法平仓,订单id: {}", position.getId());
            log.info("股票跌停,无法平仓,订单id: {}", position.getId());
            return null;
        }