| | |
| | | |
| | | @Autowired |
| | | UserPositionCheckDzService userPositionCheckDzService; |
| | | @Autowired |
| | | UserPendingorderMapper userPendingorderMapper; |
| | | |
| | | |
| | | |
| | | @Transactional |
| | | public ServerResponse buy(Integer stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) { |
| | | public ServerResponse buy(Integer stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget,BigDecimal preMarketPrice, HttpServletRequest request) { |
| | | |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | |
| | |
| | | if (stopTarget != null && stopTarget.compareTo(new BigDecimal("0")) > 0) { |
| | | userPosition.setStopTargetPrice(stopTarget); |
| | | } |
| | | userPosition.setPositionType(user.getAccountType()); |
| | | userPosition.setPositionSn(KeyUtils.getUniqueKey()); |
| | | userPosition.setUserId(user.getId()); |
| | | userPosition.setNickName(user.getRealName()); |
| | | userPosition.setAgentId(user.getAgentId()); |
| | | userPosition.setStockCode(stock.getStockCode()); |
| | | userPosition.setStockName(stock.getStockName()); |
| | | userPosition.setStockGid(stock.getStockType()); |
| | | userPosition.setStockSpell(stock.getStockSpell()); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(nowPrice); |
| | | userPosition.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌"); |
| | | userPosition.setOrderNum(buyNum); |
| | | if (stock.getStockPlate() != null) { |
| | | userPosition.setStockPlate(stock.getStockPlate()); |
| | | } |
| | | userPosition.setIsLock(Integer.valueOf(0)); |
| | | userPosition.setOrderLever(lever); |
| | | userPosition.setOrderTotalPrice(buyAmt); |
| | | // 手续费 |
| | | //判断是否盘前,和价格 |
| | | StockSetting stockSetting = tradingHourService.preMarketPrice(stock.getStockCode()); |
| | | if(null != preMarketPrice && preMarketPrice.compareTo(new BigDecimal(0)) > 0 && null != stockSetting && preMarketPrice.compareTo(new BigDecimal(stockSetting.getPrice())) != 0){ |
| | | //挂单 |
| | | UserPendingorder userPendingorder = new UserPendingorder(); |
| | | userPendingorder.setUserId(user.getId()); |
| | | userPendingorder.setStockId(String.valueOf(stockId)); |
| | | userPendingorder.setBuyNum(buyNum); |
| | | userPendingorder.setBuyType(buyType); |
| | | userPendingorder.setLever(lever); |
| | | userPendingorder.setProfitTarget(profitTarget); |
| | | userPendingorder.setStopTarget(stopTarget); |
| | | userPendingorder.setNowPrice(new BigDecimal(0)); |
| | | userPendingorder.setTargetPrice(preMarketPrice); |
| | | userPendingorder.setAddTime(new Date()); |
| | | userPendingorder.setStatus(0); |
| | | userPendingorder.setBuyAmt(buyAmt); |
| | | int ret = userPendingorderMapper.insert(userPendingorder); |
| | | }else { |
| | | userPosition.setPositionType(user.getAccountType()); |
| | | userPosition.setPositionSn(KeyUtils.getUniqueKey()); |
| | | userPosition.setUserId(user.getId()); |
| | | userPosition.setNickName(user.getRealName()); |
| | | userPosition.setAgentId(user.getAgentId()); |
| | | userPosition.setStockCode(stock.getStockCode()); |
| | | userPosition.setStockName(stock.getStockName()); |
| | | userPosition.setStockGid(stock.getStockType()); |
| | | userPosition.setStockSpell(stock.getStockSpell()); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(nowPrice); |
| | | userPosition.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌"); |
| | | userPosition.setOrderNum(buyNum); |
| | | if (stock.getStockPlate() != null) { |
| | | userPosition.setStockPlate(stock.getStockPlate()); |
| | | } |
| | | userPosition.setIsLock(Integer.valueOf(0)); |
| | | userPosition.setOrderLever(lever); |
| | | userPosition.setOrderTotalPrice(buyAmt); |
| | | // 手续费 |
| | | |
| | | userPosition.setOrderFee(orderFree); |
| | | userPosition.setOrderSpread(BigDecimal.ZERO); |
| | | userPosition.setSpreadRatePrice(BigDecimal.ZERO); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPosition.setProfitAndLose(profit_and_lose); |
| | | userPosition.setAllProfitAndLose(profit_and_lose.add(orderFree)); |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(BigDecimal.ZERO); |
| | | userPositionMapper.insert(userPosition); |
| | | userPosition.setOrderFee(orderFree); |
| | | userPosition.setOrderSpread(BigDecimal.ZERO); |
| | | userPosition.setSpreadRatePrice(BigDecimal.ZERO); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPosition.setProfitAndLose(profit_and_lose); |
| | | userPosition.setAllProfitAndLose(profit_and_lose.add(orderFree)); |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(BigDecimal.ZERO); |
| | | userPositionMapper.insert(userPosition); |
| | | |
| | | } |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", ""); |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | return ServerResponse.createBySuccessMsg("下单成功", request); |
| | |
| | | |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, userPosition.getUserId()) |
| | | .eq(UserAssets::getAccectType, "IN") |
| | | .eq(UserAssets::getAccectType, "US") |
| | | ); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | |
| | | return ServerResponse.createBySuccessMsg("平仓成功!", request); |
| | | } |
| | | |
| | | @Transactional |
| | | @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); |
| | | } |
| | | } |
| | | |
| | | //用户追加保证金操作 |
| | |
| | | } |
| | | }else{ |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | } |
| | | Stock stock = stockMapper.findStockByCode(position.getStockCode()); |
| | | if(null != stock){ |
| | | userPositionVO.setStockId(stock.getId().toString()); |
| | | userPositionVO.setStockGidJb(stock.getStockGid()); |
| | | } |
| | | userPositionVOS.add(userPositionVO); |
| | | } |
| | |
| | | userPosition.setUserId(userStockSubscribe.getUserId()); |
| | | userPosition.setNickName(userStockSubscribe.getRealName()); |
| | | userPosition.setAgentId(userStockSubscribe.getAgentId()); |
| | | |
| | | userPosition.setStockName(userStockSubscribe.getNewName()); |
| | | // StringBuffer gid = new StringBuffer(); |
| | | // gid.append(stockSubscribe.getStockType()!=null?stockSubscribe.getStockType():""); |
| | | // gid.append(userStockSubscribe.getNewCode()!=null?userStockSubscribe.getNewCode():"stock code invaild"); |
| | | userPosition.setStockGid("IN"); |
| | | userPosition.setStockGid("US"); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(userStockSubscribe.getBuyPrice()); |
| | |
| | | userPosition.setNewId(stockSubscribe.getNewlistId()); |
| | | int ret = 0; |
| | | ret = this.userPositionMapper.insert(userPosition); |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("IN", userPosition.getUserId()); |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("US", userPosition.getUserId()); |
| | | if(null == userAssets){ |
| | | return ServerResponse.createByErrorMsg("新股转持仓失败"); |
| | | } |
| | | userAssetsMapper.updateById(userAssets); |
| | | iUserAssetsServices.availablebalanceChange("IN", userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", ""); |
| | | iUserAssetsServices.availablebalanceChange("US", userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", ""); |
| | | if (ret > 0) { |
| | | userStockSubscribe.setStatus(5); |
| | | userStockSubscribeMapper.update1(userStockSubscribe); |
| | |
| | | if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) { |
| | | return ServerResponse.createByErrorMsg("Order failed, account has been locked"); |
| | | } |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId("IN", user.getId()); |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId("US", user.getId()); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | | } |
| | |
| | | UserPosition userPosition = getUserPosition(dzId,num, user, stockDz, nowPrice, stock, buyAmt); |
| | | userPositionMapper.insert(userPosition); |
| | | BigDecimal buy_fee_amt = siteSettingBuyFee.multiply(buyAmt); |
| | | userAssetsServices.availablebalanceChange(EStockType.IN.getCode(), user.getId(), EUserAssets.BUY, buyAmt.negate(),"",""); |
| | | iUserAssetsServices.availablebalanceChange("IN", userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", ""); |
| | | userAssetsServices.availablebalanceChange(EStockType.US.getCode(), user.getId(), EUserAssets.BUY, buyAmt.negate(),"",""); |
| | | iUserAssetsServices.availablebalanceChange("US", userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", ""); |
| | | return ServerResponse.createBySuccess("购买成功", request); |
| | | } |
| | | |
| | |
| | | for (UserPosition position : list) { |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, position.getUserId()) |
| | | .eq(UserAssets::getAccectType, "IN") |
| | | .eq(UserAssets::getAccectType, "US") |
| | | ); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | continue; |