| | |
| | | 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()) |
| | | .multiply(new BigDecimal(100)) |
| | | .setScale(2, BigDecimal.ROUND_DOWN); |
| | | userPositionVO.setProfitAndLoseParent(profitAndLose + "%"); |
| | | } |
| | | resultUserPositions.add(userPositionVO); |
| | | } |
| | | } |
| | | pageInfo.setList(resultUserPositions); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } catch (Exception e) { |
| | | 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()); |
| | |
| | | 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()))); |
| | | |