| | |
| | | @Autowired |
| | | UserPositionCheckDzService userPositionCheckDzService; |
| | | |
| | | @Resource |
| | | StockBuySettingMapper stockBuySettingMapper; |
| | | |
| | | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | |
| | | } |
| | | |
| | | |
| | | StockConfig mainBuyConfig = iStockConfigServices.queryByKey(EConfigKey.MIN_BUY.getCode()); |
| | | |
| | | /*StockConfig mainBuyConfig = iStockConfigServices.queryByKey(EConfigKey.MIN_BUY.getCode()); |
| | | if(buyNum<Integer.parseInt(mainBuyConfig.getCValue())){ |
| | | return ServerResponse.createByErrorMsg("最低购买数量"+mainBuyConfig.getCValue(), request); |
| | | }*/ |
| | | //最低购买数量 US 10 印度100 香港台湾1000 |
| | | /*Integer minBuyNum; |
| | | if (stock.getStockType().equals(EStockType.US.getCode())) { |
| | | minBuyNum = 10; |
| | | } else if (stock.getStockType().equals(EStockType.IN.getCode())) { |
| | | minBuyNum = 100; |
| | | } else { |
| | | minBuyNum = 1000; |
| | | } |
| | | if(buyNum < minBuyNum){ |
| | | return ServerResponse.createByErrorMsg("最低购买数量" + minBuyNum, request); |
| | | }*/ |
| | | |
| | | StockBuySetting stockBuySetting = stockBuySettingMapper.selectOne(new QueryWrapper<StockBuySetting>().eq("accets_type", stock.getStockType())); |
| | | if (stockBuySetting != null && stockBuySetting.getHandsNum() != null && stockBuySetting.getStockNum() != null) { |
| | | if(buyNum < stockBuySetting.getHandsNum()){ |
| | | return ServerResponse.createByErrorMsg("最低购买手数" + stockBuySetting.getHandsNum(), request); |
| | | } |
| | | buyNum = buyNum * stockBuySetting.getStockNum(); |
| | | } |
| | | |
| | | |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(stock.getStockType(), user.getId()); |
| | | StockConfig maxBuyConfig = iStockConfigServices.queryByKey(EConfigKey.MAX_BUY.getCode()); |
| | | if(buyNum<Integer.parseInt(mainBuyConfig.getCValue())){ |
| | | return ServerResponse.createByErrorMsg("最高购买数量"+maxBuyConfig.getCValue(), request); |
| | | if(buyNum > Integer.parseInt(maxBuyConfig.getCValue())){ |
| | | return ServerResponse.createByErrorMsg("最高购买数量" + maxBuyConfig.getCValue(), request); |
| | | } |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public ServerResponse allSell(HttpServletRequest request, String stockType) throws Exception { |
| | | //判断股票是否在可交易时间段 |
| | | public ServerResponse allSell(HttpServletRequest request) throws Exception { |
| | | User user = iUserService.getCurrentUser(request); |
| | | QueryWrapper<UserPosition> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("user_id", user.getId()); |
| | | queryWrapper.isNull("sell_order_id"); |
| | | |
| | | List<UserPosition> userPositionList = userPositionMapper.selectList(queryWrapper); |
| | | for (int i = 0; i < userPositionList.size(); i++) { |
| | | sell(userPositionList.get(i).getPositionSn(), 0); |
| | | |
| | | // 如果没有需要平仓的持仓 |
| | | if (userPositionList.isEmpty()) { |
| | | return ServerResponse.createBySuccessMsg("没有需要平仓的持仓订单"); |
| | | } |
| | | return ServerResponse.createBySuccessMsg("平仓成功!"); |
| | | |
| | | // 收集所有提示信息 |
| | | List<String> successMessages = new ArrayList<>(); |
| | | List<String> errorMessages = new ArrayList<>(); |
| | | |
| | | for (UserPosition position : userPositionList) { |
| | | ServerResponse response = sell(position.getPositionSn(), 0, position.getOrderNum(), request); |
| | | |
| | | if (response.getStatus() == 0) { |
| | | // 失败的情况 |
| | | errorMessages.add("订单号:" + position.getPositionSn() + " 失败,原因:" + response.getMsg()); |
| | | } |
| | | } |
| | | |
| | | // 根据是否有错误返回不同的状态 |
| | | if (!errorMessages.isEmpty()) { |
| | | return ServerResponse.createByErrorMsg(errorMessages.toString(), request); |
| | | } else { |
| | | return ServerResponse.createBySuccessMsg("平仓成功!", request); |
| | | } |
| | | } |
| | | |
| | | //用户追加保证金操作 |
| | |
| | | |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(new BigDecimal("0")); |
| | | userPosition.setAmountToBeCovered(amountToBeCovered); |
| | | //userPosition.setAmountToBeCovered(amountToBeCovered); |
| | | userPosition.setNewId(stockSubscribe.getNewlistId()); |
| | | int ret = 0; |
| | | ret = this.userPositionMapper.insert(userPosition); |
| | |
| | | }else{ |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | } |
| | | BigDecimal nowPriceSUM = nowPrice.multiply(BigDecimal.valueOf(position.getOrderNum())); |
| | | if (position.getStockGid().equals(EStockType.US.getCode())) { |
| | | usMarketValue = usMarketValue.add(nowPrice); |
| | | usMarketValue = usMarketValue.add(nowPriceSUM); |
| | | usPositionEarnings = usPositionEarnings.add(userPositionVO.getProfitAndLose()); |
| | | usPositionEarningsParent = usPositionEarningsParent.add(userPositionVO.getProfitAndLoseParent2()); |
| | | } else if(position.getStockGid().equals(EStockType.HK.getCode())) { |
| | | hkMarketValue = hkMarketValue.add(nowPrice); |
| | | hkMarketValue = hkMarketValue.add(nowPriceSUM); |
| | | hkPositionEarnings = hkPositionEarnings.add(userPositionVO.getProfitAndLose()); |
| | | hkPositionEarningsParent = hkPositionEarningsParent.add(userPositionVO.getProfitAndLoseParent2()); |
| | | } else if(position.getStockGid().equals(EStockType.IN.getCode())) { |
| | | inMarketValue = inMarketValue.add(nowPrice); |
| | | inMarketValue = inMarketValue.add(nowPriceSUM); |
| | | inPositionEarnings = inPositionEarnings.add(userPositionVO.getProfitAndLose()); |
| | | inPositionEarningsParent = inPositionEarningsParent.add(userPositionVO.getProfitAndLoseParent2()); |
| | | } else if(position.getStockGid().equals(EStockType.TW.getCode())) { |
| | | twMarketValue = twMarketValue.add(nowPrice); |
| | | twMarketValue = twMarketValue.add(nowPriceSUM); |
| | | twPositionEarnings = twPositionEarnings.add(userPositionVO.getProfitAndLose()); |
| | | twPositionEarningsParent = twPositionEarningsParent.add(userPositionVO.getProfitAndLoseParent2()); |
| | | } |