| | |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.nq.common.ResponseCode; |
| | | import com.nq.dao.*; |
| | | import com.nq.enums.EConfigKey; |
| | | import com.nq.enums.EStockType; |
| | |
| | | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.sql.Timestamp; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | |
| | | if(null == stock){ |
| | | return ServerResponse.createByErrorMsg("股票不存在,平仓失败", request); |
| | | } |
| | | UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | /*UserAssets userAssets = userAssetsMapper.selectOne(new LambdaQueryWrapper<UserAssets>() |
| | | .eq(UserAssets::getUserId, userPosition.getUserId()) |
| | | .eq(UserAssets::getAccectType, stock.getStockType()) |
| | | ); |
| | | );*/ |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId(stock.getStockType(), userPosition.getUserId()); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | | } |
| | |
| | | try { |
| | | User user = iUserService.getCurrentUser(request); |
| | | if (user == null ){ |
| | | return ServerResponse.createByErrorCodeMsg(401,"请先登录"); |
| | | return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录"); |
| | | } |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<UserPositionCheckDz> userPositionCheckDzs = userPositionCheckDzService.list( |
| | |
| | | PageInfo<UserPositionCheckDz> pageInfo = new PageInfo<>(userPositionCheckDzs); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } catch (Exception e) { |
| | | log.error("StockAiService getStockAiOrderList error", e); |
| | | log.error("IUserPositionService getDzOrderList error", e); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | |
| | | log.info("强制平仓成功,订单id: {}", position.getId()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 查询账户市值和持仓收益 |
| | | * @param request |
| | | * @return |
| | | */ |
| | | public ServerResponse getMyPositionProfitAndLose(HttpServletRequest request) { |
| | | try { |
| | | User user = iUserService.getCurrentUser(request); |
| | | if (user == null ){ |
| | | return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录"); |
| | | } |
| | | Integer state = 0; |
| | | //status 0 持仓 1 平仓 |
| | | List<UserPosition> userPositions = userPositionMapper.findMyPositionByCodeAndSpell(user.getId(), |
| | | null, null, state, null); |
| | | |
| | | BigDecimal usMarketValue = BigDecimal.ZERO; //美股市值 |
| | | BigDecimal mxMarketValue = BigDecimal.ZERO; //墨西哥股市值 |
| | | BigDecimal usPositionEarnings = BigDecimal.ZERO; //美股持仓收益 |
| | | BigDecimal mxPositionEarnings = BigDecimal.ZERO; //墨西哥持仓收益 |
| | | BigDecimal usPositionEarningsParent = BigDecimal.ZERO; //美股持仓收益百分比 |
| | | BigDecimal mxPositionEarningsParent = BigDecimal.ZERO; //墨西哥持仓收益百分比 |
| | | |
| | | if (userPositions.size() > 0) { |
| | | for (UserPosition position : userPositions) { |
| | | BigDecimal nowPrice; |
| | | 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()))); |
| | | |
| | | 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()))); |
| | | } |
| | | if (position.getStockGid().equals(EStockType.US.getCode())) { |
| | | usMarketValue = usMarketValue.add(nowPrice); |
| | | usPositionEarnings = usPositionEarnings.add(userPositionVO.getProfitAndLose()); |
| | | usPositionEarningsParent = usPositionEarningsParent.add(userPositionVO.getProfitAndLoseParent2()); |
| | | } else if(position.getStockGid().equals(EStockType.MX.getCode())) { |
| | | mxMarketValue = mxMarketValue.add(nowPrice); |
| | | mxPositionEarnings = mxPositionEarnings.add(userPositionVO.getProfitAndLose()); |
| | | mxPositionEarningsParent = mxPositionEarningsParent.add(userPositionVO.getProfitAndLoseParent2()); |
| | | } |
| | | } |
| | | usPositionEarnings = usPositionEarnings.setScale(2, RoundingMode.DOWN); |
| | | mxPositionEarnings = mxPositionEarnings.setScale(2, RoundingMode.DOWN); |
| | | } |
| | | |
| | | Map<String, String> map = new HashMap<>(); |
| | | map.put("usMarketValue", String.valueOf(usMarketValue)); //美股市值 |
| | | map.put("usPositionEarnings", String.valueOf(usPositionEarnings)); //美股持仓收益 |
| | | map.put("usPositionEarningsParent", usPositionEarningsParent + "%");//美股持仓收益率 |
| | | |
| | | map.put("mxMarketValue", String.valueOf(mxMarketValue)); //墨西哥股市值 |
| | | map.put("mxPositionEarnings", String.valueOf(mxPositionEarnings)); //墨西哥持仓收益 |
| | | map.put("mxPositionEarningsParent", mxPositionEarningsParent + "%");//墨西哥持仓收益率 |
| | | return ServerResponse.createBySuccess(map); |
| | | } catch (Exception e) { |
| | | log.error("IUserPositionService getMyPositionProfitAndLose error", e); |
| | | } |
| | | return ServerResponse.createByError(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |