| | |
| | | @Autowired |
| | | StockMapper stockMapper; |
| | | @Autowired |
| | | AgentAgencyFeeMapper agentAgencyFeeMapper; |
| | | @Autowired |
| | | IAgentAgencyFeeService iAgentAgencyFeeService; |
| | | @Autowired |
| | | ISiteProductService iSiteProductService; |
| | | |
| | | @Autowired |
| | | FundsApplyMapper fundsApplyMapper; |
| | | @Autowired |
| | | UserStockSubscribeMapper userStockSubscribeMapper; |
| | | @Resource |
| | |
| | | @Resource |
| | | UserIndexPositionMapper userIndexPositionMapper; |
| | | |
| | | @Autowired |
| | | IStockFuturesService iStockFuturesService; |
| | | @Autowired |
| | | IStockCoinService iStockCoinService; |
| | | @Autowired |
| | | CurrencyUtils currencyUtils; |
| | | @Resource |
| | | StockDzMapper stockDzMapper; |
| | | |
| | |
| | | return ServerResponse.createByErrorMsg("报价0,请稍后再试", request); |
| | | } |
| | | |
| | | |
| | | BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever)); |
| | | BigDecimal finalBuyAmt = buyAmt; |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!stock.getStockType().equals(EStockType.MX.getCode())) { |
| | | buyAmt = userAssetsServices.exchangeAmountByRate(stock.getStockType(), buyAmt); |
| | | } |
| | | BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt); |
| | | |
| | | BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100)); |
| | | 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); |
| | |
| | | } |
| | | userPosition.setIsLock(Integer.valueOf(0)); |
| | | userPosition.setOrderLever(lever); |
| | | userPosition.setOrderTotalPrice(buyAmt); |
| | | userPosition.setOrderTotalPrice(finalBuyAmt); |
| | | // 手续费 |
| | | |
| | | userPosition.setOrderFee(orderFree); |
| | |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } |
| | | |
| | | public ServerResponse findMyPositionByParam(String stockCode, String stockSpell, |
| | | Integer state, HttpServletRequest request, |
| | | int pageNum, int pageSize, String stockType, Integer positionType) { |
| | | try { |
| | | User user = iUserService.getCurrentUser(request); |
| | | if (user == null ){ |
| | | return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录", request); |
| | | } |
| | | |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<UserPositionVO> userPositions = userPositionMapper.findMyPositionByParam(user.getId(), |
| | | stockCode, stockSpell, state, stockType, positionType); |
| | | PageInfo<UserPositionVO> pageInfo = new PageInfo<>(userPositions); |
| | | |
| | | List<UserPositionVO> resultUserPositions = new ArrayList<>(); |
| | | if (!pageInfo.getList().isEmpty()) { |
| | | for (UserPositionVO position : userPositions) { |
| | | UserPositionVO userPositionVO = position; |
| | | if (position.getPositionType() != 4) { |
| | | BigDecimal nowPrice; |
| | | if(state == 0){ |
| | | nowPrice = priceServices.getNowPrice(position.getStockCode()); |
| | | }else{ |
| | | nowPrice = position.getSellOrderPrice(); |
| | | } |
| | | |
| | | userPositionVO = UserPointUtil.assembleUserPositionVO2(position,nowPrice); |
| | | userPositionVO.setOrderTotalPrice(userPositionVO.getOrderTotalPrice().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | |
| | | StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>() |
| | | .eq(StockSubscribe::getCode, userPositionVO.getStockCode())); |
| | | if(position.getSellOrderId() == null){ |
| | | if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) { |
| | | userPositionVO.setProfitAndLose(BigDecimal.ZERO); |
| | | userPositionVO.setProfitAndLoseParent("0%"); |
| | | userPositionVO.setIsListed(false); |
| | | }else{ |
| | | userPositionVO.setIsListed(true); |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | } |
| | | }else{ |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | } |
| | | } else { |
| | | //ai交易 计算收益率 收益/本金*100 |
| | | BigDecimal profitAndLose = userPositionVO.getProfitAndLose() |
| | | .divide(userPositionVO.getOrderTotalPrice(), RoundingMode.HALF_UP) |
| | | .multiply(new BigDecimal(100)) |
| | | .setScale(2, RoundingMode.DOWN); |
| | | userPositionVO.setNow_price(String.valueOf(userPositionVO.getSellOrderPrice().setScale(2, RoundingMode.HALF_UP))); |
| | | userPositionVO.setProfitAndLoseParent(profitAndLose + "%"); |
| | | userPositionVO.setSellOrderTotalPrice(userPositionVO.getSellOrderPrice().multiply(BigDecimal.valueOf(userPositionVO.getOrderNum()))); |
| | | } |
| | | resultUserPositions.add(userPositionVO); |
| | | } |
| | | } |
| | | pageInfo.setList(resultUserPositions); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("IUserPositionService findMyPositionByParam {}", e.getMessage()); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | |
| | | public PositionVO findUserPositionAllProfitAndLose(Integer userId) { |
| | | List<UserPosition> userPositions = this.userPositionMapper.findPositionByUserIdAndSellIdIsNull(userId); |
| | | |
| | |
| | | userPosition.setAgentId(user.getAgentId()); |
| | | userPosition.setStockCode(stock.getStockCode()); |
| | | userPosition.setStockName(stock.getStockName()); |
| | | userPosition.setStockGid(stock.getStockGid()); |
| | | userPosition.setStockGid(stock.getStockType()); |
| | | userPosition.setStockSpell(stock.getStockSpell()); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(DateTimeUtil.strToDate(buyTime)); |
| | |
| | | stockType = stock.getStockType(); |
| | | } |
| | | |
| | | userPosition.setPositionType(1); |
| | | userPosition.setPositionType(2); |
| | | userPosition.setPositionSn(KeyUtils.getUniqueKey()); |
| | | userPosition.setUserId(userStockSubscribe.getUserId()); |
| | | userPosition.setNickName(userStockSubscribe.getRealName()); |
| | |
| | | userPosition.setAgentId(user.getAgentId()); |
| | | userPosition.setStockCode(stock.getStockCode()); |
| | | userPosition.setStockName(stock.getStockName()); |
| | | userPosition.setStockGid(stock.getStockGid()); |
| | | userPosition.setStockGid(stock.getStockType()); |
| | | userPosition.setStockSpell(stock.getStockSpell()); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | |
| | | return ServerResponse.createByErrorMsg("订单失败,配资不足", request); |
| | | } |
| | | |
| | | BigDecimal newBuyAmt = buyAmt; |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!stock.getStockType().equals(EStockType.MX.getCode())) { |
| | | newBuyAmt = userAssetsServices.exchangeAmountByRate(stock.getStockType(), buyAmt); |
| | | } |
| | | if(newBuyAmt.compareTo(userAssets.getAvailableBalance()) > 0){ |
| | | return ServerResponse.createByErrorMsg("可用余额不足" + userAssets.getAvailableBalance(), request); |
| | | } |
| | | |
| | | //判断审核开关 |
| | | if(stockDz.getSwitchType() == 1) { |
| | | UserPosition userPosition = getUserPosition(dzId,num, user, stockDz, nowPrice, stock, buyAmt); |
| | |
| | | // 创建UserPosition对象 |
| | | UserPosition userPosition = getUserPosition(dzId,num, user, stockDz, nowPrice, stock, buyAmt); |
| | | userPositionMapper.insert(userPosition); |
| | | BigDecimal buy_fee_amt = siteSettingBuyFee.multiply(buyAmt); |
| | | userAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, buyAmt.negate(),"",""); |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", ""); |
| | | BigDecimal buy_fee_amt = siteSettingBuyFee.multiply(newBuyAmt); |
| | | //已经转化 直接穿MEX类型 |
| | | userAssetsServices.availablebalanceChange(EStockType.MX.getCode(), user.getId(), EUserAssets.BUY, newBuyAmt.negate(),"",""); |
| | | iUserAssetsServices.availablebalanceChange(EStockType.MX.getCode(), userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", ""); |
| | | return ServerResponse.createBySuccess("购买成功", request); |
| | | } |
| | | |
| | |
| | | BigDecimal usPositionEarningsParent = BigDecimal.ZERO; //美股持仓收益百分比 |
| | | BigDecimal mxPositionEarningsParent = BigDecimal.ZERO; //墨西哥持仓收益百分比 |
| | | |
| | | if (userPositions.size() > 0) { |
| | | if (!userPositions.isEmpty()) { |
| | | for (UserPosition position : userPositions) { |
| | | BigDecimal nowPrice; |
| | | if(state == 0){ |
| | | BigDecimal nowPrice = priceServices.getNowPrice(position.getStockCode()); |
| | | /*if(state == 0){ |
| | | nowPrice = priceServices.getNowPrice(position.getStockCode()); |
| | | }else{ |
| | | nowPrice = position.getSellOrderPrice(); |
| | | } |
| | | }*/ |
| | | UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position,nowPrice); |
| | | userPositionVO.setOrderTotalPrice(userPositionVO.getOrderTotalPrice().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | |
| | |
| | | userPositionCheckDzService.updateById(userPositionCheckDz); |
| | | return ServerResponse.createBySuccess("审核成功", request); |
| | | } |
| | | if (orderNum > userPositionCheckDz.getOrderNum()) { |
| | | return ServerResponse.createByErrorMsg("输入数量大于用户买入数量", request); |
| | | } |
| | | User user = userMapper.selectById(userPositionCheckDz.getUserId()); |
| | | |
| | | StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("id", userPositionCheckDz.getDzId())); |
| | |
| | | userPosition.setId(null); |
| | | userPosition.setDzId(stockDz.getId()); |
| | | userPositionMapper.insert(userPosition); |
| | | userAssetsServices.availablebalanceChange(userAssets.getAccectType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", ""); |
| | | userAssetsServices.availablebalanceChange(stockDz.getStockType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", ""); |
| | | return ServerResponse.createBySuccessMsg("审核成功,订单已转客户持仓", request); |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |