zj
2026-01-11 01d5b1dddaefae84ffb6457ab7a7be87ea0041f6
src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -558,7 +558,7 @@
        SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
        if (siteSetting == null) {
            log.error("平倉出錯,網站設置表不存在");
            return ServerResponse.createByErrorMsg("下單失敗,系統設置錯誤");
            return ServerResponse.createByErrorMsg("下单失败,系统设置错误");
        }
        SiteProduct siteProduct = iSiteProductService.getProductSetting();
        UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn);
@@ -573,7 +573,7 @@
                log.info("是否在上午交易時間 = {} 是否在下午交易時間 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag));
                if (!am_flag && !pm_flag) {
                    return ServerResponse.createByErrorMsg("平倉失敗,不在交易時段內");
                    return ServerResponse.createByErrorMsg("下单失败,系统设置错误");
                }
            } else if (userPosition.getStockGid().contains("hk")) {
                String am_begin = siteSetting.getTransAmBeginhk();
@@ -596,44 +596,44 @@
                boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end);
                log.info("是否在上午交易時間 = {} 是否在下午交易時間 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag));
                if (!am_flag && !pm_flag) {
                    return ServerResponse.createByErrorMsg("平倉失敗,不在交易時段內");
                    return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内");
                }
            }
            if (siteProduct.getHolidayDisplay()) {
                return ServerResponse.createByErrorMsg("周末或節假日不能交易!");
                return ServerResponse.createByErrorMsg("周末或节假日不能交易!");
            }
        }
        if (userPosition == null) {
            return ServerResponse.createByErrorMsg("平倉失敗,訂單不存在");
            return ServerResponse.createByErrorMsg("平仓失败,订单不存在");
        }
        User user = this.userMapper.selectByPrimaryKey(userPosition.getUserId());
        if (user == null) {
            return ServerResponse.createByErrorMsg("平倉失敗,用戶不存在");
            return ServerResponse.createByErrorMsg("平仓失败,用户不存在");
        }
        /*實名認證開關開啟*/
        if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) {
            return ServerResponse.createByErrorMsg("平倉失敗,用戶已被鎖定");
            return ServerResponse.createByErrorMsg("平仓失败,用户已被锁定");
        }
        if (userPosition.getSellOrderId() != null) {
            return ServerResponse.createByErrorMsg("平倉失敗,此訂單已平倉");
            return ServerResponse.createByErrorMsg("平仓失败,此订单已平仓");
        }
        if (1 == userPosition.getIsLock().intValue()) {
            return ServerResponse.createByErrorMsg("平倉失敗 " + userPosition.getLockMsg());
            return ServerResponse.createByErrorMsg("平仓失败 " + userPosition.getLockMsg());
        }
        if (!DateTimeUtil.isCanSell(userPosition.getBuyOrderTime(), siteSetting.getCantSellTimes().intValue())) {
            // return ServerResponse.createByErrorMsg(siteSetting.getCantSellTimes() + "分鐘內不能平倉");
            return ServerResponse.createByErrorMsg("當日成交不可平倉");
            return ServerResponse.createByErrorMsg("当日成交不可平仓");
        }
//        if (DateTimeUtil.sameDate(DateTimeUtil.getCurrentDate(),userPosition.getBuyOrderTime())) {
@@ -681,7 +681,7 @@
//        }
        if (stockListVO.getNowPrice() == null) {
            return ServerResponse.createByErrorMsg("平倉失敗,獲取股票信息失敗");
            return ServerResponse.createByErrorMsg("平仓失败,获取股票信息失败");
        }
        now_price = new BigDecimal(stockListVO.getNowPrice());
@@ -689,7 +689,7 @@
//        BigDecimal now_price = new BigDecimal(stockListVO.getNowPrice());
        if (now_price.compareTo(new BigDecimal("0")) != 1) {
            log.error("股票 = {} 收到報價 = {}", userPosition.getStockName(), now_price);
            return ServerResponse.createByErrorMsg("報價0,平倉失敗,請稍後再試");
            return ServerResponse.createByErrorMsg("报价0,平仓失败,请稍后再试");
        }
        double stock_crease = stockListVO.getHcrate().doubleValue();
@@ -706,7 +706,7 @@
        log.info("股票當前漲跌幅 = {} 跌停幅度 = {}", Double.valueOf(stock_crease), ztRate);
        if ((new BigDecimal(String.valueOf(stock_crease))).compareTo(ztRate) == 0 && "買漲"
                .equals(userPosition.getOrderDirection())) {
            return ServerResponse.createByErrorMsg("當前股票已跌停不能賣出");
            return ServerResponse.createByErrorMsg("当前股票已跌停不能卖出");
        }
        Integer buy_num = userPosition.getOrderNum();
@@ -745,11 +745,11 @@
        log.info("點差費 = {}", spreadRatePrice);
        BigDecimal sell_fee_amt = all_sell_amt.multiply(siteSetting.getSellFee()).setScale(2, 4);
        log.info("賣出手續費 = {}", sell_fee_amt);
        log.info("卖出手续费 = {}", sell_fee_amt);
        //總手續費= 買入手續費+賣出手續費+印花稅+遞延費+點差費
        BigDecimal all_fee_amt = buy_fee_amt.add(sell_fee_amt).add(orderSpread).add(orderStayFee).add(spreadRatePrice);
        log.info("總的手續費費用 = {}", all_fee_amt);
        log.info("总的手续费费用 = {}", all_fee_amt);
        userPosition.setSellOrderId(GeneratePosition.getPositionId());
        userPosition.setSellOrderPrice(now_price);
@@ -765,10 +765,10 @@
        int updatePositionCount = this.userPositionMapper.updateByPrimaryKeySelective(userPosition);
        if (updatePositionCount > 0) {
            log.info("【用戶平倉】修改浮動盈虧記錄成功");
            log.info("【用户平仓】修改浮动盈亏记录成功");
        } else {
            log.error("用戶平倉】修改浮動盈虧記錄出錯");
            throw new Exception("用戶平倉】修改浮動盈虧記錄出錯");
            log.error("用户平仓】修改浮动盈亏记录出错");
            throw new Exception("用户平仓】修改浮动盈亏记录出错");
        }
        BigDecimal freez_amt = all_buy_amt.divide(new BigDecimal(userPosition.getOrderLever().intValue()), 2, 4);
@@ -795,9 +795,9 @@
        ucd.setAgentName(user.getAgentName());
        ucd.setUserId(user.getId());
        ucd.setUserName(user.getRealName());
        ucd.setDeType("總盈虧");
        ucd.setDeType("总盈亏");
        ucd.setDeAmt(all_profit);
        ucd.setDeSummary("賣出股票," + userPosition.getStockCode() + "/" + userPosition.getStockName() + ",占用本金:" + freez_amt + ",總手續費:" + all_fee_amt + ",遞延費:" + orderStayFee + ",印花稅:" + orderSpread + ",盈虧:" + profitLoss + ",總盈虧:" + all_profit);
        ucd.setDeSummary("卖出股票," + userPosition.getStockCode() + "/" + userPosition.getStockName() + ",占用本金:" + freez_amt + ",总手续费:" + all_fee_amt + ",递延费:" + orderStayFee + ",印花稅:" + orderSpread + ",盈亏:" + profitLoss + ",总盈亏:" + all_profit);
        ucd.setAddTime(new Date());
        ucd.setIsRead(Integer.valueOf(0));
@@ -814,7 +814,7 @@
            throw new Exception("用戶平倉】保存明細記錄出錯");
        }
        return ServerResponse.createBySuccessMsg("平倉成功!");
        return ServerResponse.createBySuccessMsg("平仓成功!");
    }
    public ServerResponse sellbf(String positionSn, Integer quantity) throws Exception {
@@ -822,8 +822,8 @@
        SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
        if (siteSetting == null) {
            log.error("平倉出錯,網站設置表不存在");
            return ServerResponse.createByErrorMsg("下單失敗,系統設置錯誤");
            log.error("平仓出错,网站设置表不存在");
            return ServerResponse.createByErrorMsg("下单失败,系统设置错误");
        }
        SiteProduct siteProduct = iSiteProductService.getProductSetting();
        UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn);
@@ -840,29 +840,29 @@
        boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end);
        log.info("是否在上午交易時間 = {} 是否在下午交易時間 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag));
        if (!am_flag && !pm_flag) {
            return ServerResponse.createByErrorMsg("平倉失敗,不在交易時段內");
            return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内");
        }
        if (userPosition == null) {
            return ServerResponse.createByErrorMsg("平倉失敗,訂單不存在");
            return ServerResponse.createByErrorMsg("平仓失败,订单不存在");
        }
        User user = this.userMapper.selectByPrimaryKey(userPosition.getUserId());
        if (user == null) {
            return ServerResponse.createByErrorMsg("平倉失敗,用戶不存在");
            return ServerResponse.createByErrorMsg("平仓失败,用户不存在");
        }
        /*實名認證開關開啟*/
        if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) {
            return ServerResponse.createByErrorMsg("平倉失敗,用戶已被鎖定");
            return ServerResponse.createByErrorMsg("平仓失败,用户已被锁定");
        }
        if (userPosition.getSellOrderId() != null) {
            return ServerResponse.createByErrorMsg("平倉失敗,此訂單已平倉");
            return ServerResponse.createByErrorMsg("平仓失败,此订单已平仓");
        }
        if (1 == userPosition.getIsLock().intValue()) {
            return ServerResponse.createByErrorMsg("平倉失敗 " + userPosition.getLockMsg());
            return ServerResponse.createByErrorMsg("平仓失败 " + userPosition.getLockMsg());
        }
        if (!DateTimeUtil.isCanSell(userPosition.getBuyOrderTime(), siteSetting.getCantSellTimes().intValue())) {
            return ServerResponse.createByErrorMsg("當日成交不可平倉");
            return ServerResponse.createByErrorMsg("当日成交不可平仓");
        }
        BigDecimal now_price;
@@ -873,13 +873,13 @@
            stockListVO = SinaStockApi.assembleStockListVO(SinaStockApi.getSinaStock(userPosition.getStockGid()));
        }
        if (stockListVO.getNowPrice() == null) {
            return ServerResponse.createByErrorMsg("平倉失敗,獲取股票信息失敗");
            return ServerResponse.createByErrorMsg("平仓失败,获取股票信息失败");
        }
        now_price = new BigDecimal(stockListVO.getNowPrice());
        if (now_price.compareTo(new BigDecimal("0")) != 1) {
            log.error("股票 = {} 收到報價 = {}", userPosition.getStockName(), now_price);
            return ServerResponse.createByErrorMsg("報價0,平倉失敗,請稍後再試");
            return ServerResponse.createByErrorMsg("报价0,平仓失败,请稍后再试");
        }
        double stock_crease = stockListVO.getHcrate().doubleValue();
@@ -896,13 +896,13 @@
        log.info("股票當前漲跌幅 = {} 跌停幅度 = {}", Double.valueOf(stock_crease), ztRate);
        if ((new BigDecimal(String.valueOf(stock_crease))).compareTo(ztRate) == 0 && "買漲"
                .equals(userPosition.getOrderDirection())) {
            return ServerResponse.createByErrorMsg("當前股票已跌停不能賣出");
            return ServerResponse.createByErrorMsg("当前股票已跌停不能卖出");
        }
        if (quantity <= 0) {
            return ServerResponse.createByErrorMsg("平倉失敗, 平仓数量不可小于0");
            return ServerResponse.createByErrorMsg("平仓失败, 平仓数量不可小于0");
        }
        if (quantity > userPosition.getOrderNum()) {
            return ServerResponse.createByErrorMsg("平倉失敗,平仓数量不可小于"+userPosition.getOrderNum());
            return ServerResponse.createByErrorMsg("平仓失败,平仓数量不可小于"+userPosition.getOrderNum());
        }
//        Integer buy_num = userPosition.getOrderNum();
@@ -978,7 +978,7 @@
            log.info("【用戶平倉】修改浮動盈虧記錄成功");
        } else {
            log.error("用戶平倉】修改浮動盈虧記錄出錯");
            throw new Exception("用戶平倉】修改浮動盈虧記錄出錯");
            throw new Exception("用户平仓】修改浮动盈亏记录出错");
        }
        BigDecimal freez_amt = all_buy_amt.divide(new BigDecimal(userPositionNew.getOrderLever().intValue()), 2, 4);
@@ -995,7 +995,7 @@
            log.info("【用戶平倉】修改用戶金額成功");
        } else {
            log.error("用戶平倉】修改用戶金額出錯");
            throw new Exception("用戶平倉】修改用戶金額出錯");
            throw new Exception("【用户平仓】修改用户金额出错");
        }
        UserCashDetail ucd = new UserCashDetail();
@@ -1004,9 +1004,9 @@
        ucd.setAgentName(user.getAgentName());
        ucd.setUserId(user.getId());
        ucd.setUserName(user.getRealName());
        ucd.setDeType("總盈虧");
        ucd.setDeType("总盈亏");
        ucd.setDeAmt(all_profit);
        ucd.setDeSummary("賣出股票," + userPositionNew.getStockCode() + "/" + userPositionNew.getStockName() + ",占用本金:" + freez_amt + ",總手續費:" + all_fee_amt + ",遞延費:" + 0 + ",印花稅:" + orderSpread + ",盈虧:" + profitLoss + ",總盈虧:" + all_profit);
        ucd.setDeSummary("卖出股票," + userPositionNew.getStockCode() + "/" + userPositionNew.getStockName() + ",占用本金:" + freez_amt + ",总手续费:" + all_fee_amt + ",递延费:" + 0 + ",印花稅:" + orderSpread + ",盈亏:" + profitLoss + ",总盈亏:" + all_profit);
        ucd.setAddTime(new Date());
        ucd.setIsRead(Integer.valueOf(0));
@@ -1020,10 +1020,10 @@
            log.info("【用戶平倉】保存明細記錄成功");
        } else {
            log.error("用戶平倉】保存明細記錄出錯");
            throw new Exception("用戶平倉】保存明細記錄出錯");
            throw new Exception("【用户平仓】保存明细记录出错");
        }
        return ServerResponse.createBySuccessMsg("平倉成功!");
        return ServerResponse.createBySuccessMsg("平仓成功!");
    }
@@ -1847,6 +1847,7 @@
        userPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose());
        userPositionVO.setNow_price(positionProfitVO.getNowPrice());
        userPositionVO.setAllProfitAndLoseStr(positionProfitVO.getAllProfitAndLoseStr());
        userPositionVO.setOrderTotalPrice(positionProfitVO.getOrderTotalPrice());
        return userPositionVO;
@@ -1857,6 +1858,7 @@
        BigDecimal allProfitAndLose = new BigDecimal("0");
        String allProfitAndLoseStr = "";
        String nowPrice = "";
        BigDecimal orderTotalPrice = position.getOrderTotalPrice();
        if (position.getSellOrderId() != null) {
@@ -1884,8 +1886,9 @@
                }else {
                    nowPrice = String.valueOf(position.getBuyOrderPrice());
                }
            }
            orderTotalPrice = new BigDecimal(nowPrice).multiply(new BigDecimal(position.getOrderNum()));
            BigDecimal subPrice = (new BigDecimal(nowPrice)).subtract(position.getBuyOrderPrice());
//            profitAndLose = subPrice.multiply(new BigDecimal(position.getOrderNum().intValue())).multiply(new BigDecimal(position.getOrderLever())).setScale(2,4);
@@ -1901,6 +1904,7 @@
        }
        PositionProfitVO positionProfitVO = new PositionProfitVO();
        positionProfitVO.setProfitAndLose(profitAndLose);
        positionProfitVO.setOrderTotalPrice(orderTotalPrice);
        positionProfitVO.setAllProfitAndLose(allProfitAndLose);
        positionProfitVO.setAllProfitAndLoseStr(allProfitAndLoseStr);
        positionProfitVO.setNowPrice(nowPrice);