| | |
| | | |
| | | |
| | | public static <T> ServerResponse<T> createBySuccessMsg(String msg,HttpServletRequest request) { |
| | | return new ServerResponse(ResponseCode.SUCCESS.getCode(), new GoogleTranslateUtil().translate(msg,request.getHeader(LANG))); |
| | | //return new ServerResponse(ResponseCode.SUCCESS.getCode(), new GoogleTranslateUtil().translate(msg,request.getHeader(LANG))); |
| | | return new ServerResponse(ResponseCode.SUCCESS.getCode(), msg); |
| | | } |
| | | |
| | | public static <T> ServerResponse<T> createBySuccess(T data) { |
| | |
| | | |
| | | |
| | | public static <T> ServerResponse<T> createBySuccess(String data,HttpServletRequest request) { |
| | | return new ServerResponse(ResponseCode.SUCCESS.getCode(), new GoogleTranslateUtil().translate(data,request.getHeader(LANG))); |
| | | //return new ServerResponse(ResponseCode.SUCCESS.getCode(), new GoogleTranslateUtil().translate(data,request.getHeader(LANG))); |
| | | return new ServerResponse(ResponseCode.SUCCESS.getCode(), data); |
| | | } |
| | | |
| | | public static <T> ServerResponse<T> createBySuccess(String msg, T data) { |
| | |
| | | return new ServerResponse(ResponseCode.ERROR.getCode(), errormsg); |
| | | } |
| | | public static <T> ServerResponse<T> createByErrorMsg(String errormsg, HttpServletRequest request) { |
| | | return new ServerResponse(ResponseCode.ERROR.getCode(), new GoogleTranslateUtil().translate(errormsg,request.getHeader(LANG))); |
| | | //return new ServerResponse(ResponseCode.ERROR.getCode(), new GoogleTranslateUtil().translate(errormsg,request.getHeader(LANG))); |
| | | return new ServerResponse(ResponseCode.ERROR.getCode(), errormsg); |
| | | } |
| | | |
| | | |
| | |
| | | return true; |
| | | } |
| | | |
| | | /*SiteAdmin siteAdmin = null; |
| | | SiteAdmin siteAdmin = null; |
| | | String loginToken = httpServletRequest.getHeader(PropertiesUtil.getProperty("admin.cookie.name")); |
| | | if (StringUtils.isNotEmpty(loginToken)) { |
| | | String adminJsonStr = RedisShardedPoolUtils.get(loginToken); |
| | |
| | | writer.flush(); |
| | | writer.close(); |
| | | return false; |
| | | }*/ |
| | | } |
| | | |
| | | // 194.26.73.150, 172.70.34.195 |
| | | // String ip = IpUtils.getIp(httpServletRequest); |
| | |
| | | httpServletResponse.setCharacterEncoding("UTF-8"); |
| | | httpServletResponse.setContentType("application/json;charset=UTF-8"); |
| | | PrintWriter writer = httpServletResponse.getWriter(); |
| | | writer.print( new Gson().toJson(ServerResponse.createByErrorCodeMsg(401,googleTranslateUtil.translate("请登录",lang )))); |
| | | //writer.print( new Gson().toJson(ServerResponse.createByErrorCodeMsg(401,googleTranslateUtil.translate("请登录",lang )))); |
| | | writer.print( new Gson().toJson(ServerResponse.createByErrorCodeMsg(401,"请登录"))); |
| | | writer.flush(); |
| | | writer.close(); |
| | | return false; |
| | |
| | | return this.iUserStockSubscribeService.del(id, request); |
| | | } |
| | | |
| | | //大宗交易 |
| | | |
| | | } |
| | |
| | | |
| | | UserPosition findUserPositionByCode(@Param("userId") Integer paramInteger,@Param("stockCode") String stockCode); |
| | | |
| | | List<UserPosition> getUserPositionDzList(@Param("userId") Integer userId,@Param("checkType") Integer checkType); |
| | | } |
| | |
| | | |
| | | /** |
| | | * ai交易 |
| | | * @param userAssets |
| | | * @param accetType |
| | | * @param userId |
| | | * @param eUserAssets |
| | | * @param amount |
| | | * @param buyAmount |
| | | * @return |
| | | */ |
| | | Boolean aiAvailableBalanceChange(UserAssets userAssets, EUserAssets eUserAssets, BigDecimal amount, BigDecimal buyAmount); |
| | | Boolean aiAvailableBalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount, BigDecimal buyAmount); |
| | | |
| | | /** |
| | | * 根据汇率转换金额 |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional |
| | | public ServerResponse buyStockAi(Long id, BigDecimal buyNum, HttpServletRequest request) { |
| | | try { |
| | | User user = iUserService.getCurrentUser(request); |
| | | if (user == null ){ |
| | | return ServerResponse.createBySuccessMsg("请先登录"); |
| | | return ServerResponse.createByErrorCodeMsg(401,"请先登录"); |
| | | } |
| | | Object lock = locks.computeIfAbsent(Long.valueOf(user.getId()), k -> new Object()); |
| | | synchronized (lock){ |
| | |
| | | } |
| | | //获取用户账户 |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(EStockType.MX.getCode(), user.getId()); |
| | | BigDecimal finalBuyNum = buyNum; //购买金额 |
| | | /*BigDecimal finalBuyNum = buyNum; //购买金额 |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!stockAI.getStockType().equals(EStockType.MX.getCode())) { |
| | | EStockType stockType = EStockType.getEStockTypeByCode(stockAI.getStockType()); |
| | |
| | | } |
| | | //转换为墨西哥币 |
| | | buyNum = iUserAssetsServices.exchangeAmountByRate(buyNum, exchangeRate.getRata()); |
| | | } |
| | | }*/ |
| | | if(buyNum.compareTo(userAssets.getAvailableBalance()) > 0){ |
| | | return ServerResponse.createByErrorMsg("可用余额不足" + userAssets.getAvailableBalance()); |
| | | } |
| | |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金"); |
| | | } |
| | | |
| | | Boolean flag = iUserAssetsServices.aiAvailableBalanceChange(stockAI.getStockType(), user.getId(), EUserAssets.BUY_AI, buyNum, null); |
| | | if (!flag) { |
| | | return ServerResponse.createByErrorMsg("扣款失败,无法转换货币"); |
| | | } |
| | | StockAIOrder stockAIOrder = new StockAIOrder(); |
| | | stockAIOrder.setUserId(user.getId()); |
| | | stockAIOrder.setStockAiId(id); |
| | | stockAIOrder.setBuyDate(new Date()); |
| | | stockAIOrder.setBuyAmount(finalBuyNum); |
| | | stockAIOrder.setRemainAmount(finalBuyNum); |
| | | stockAIOrder.setBuyAmount(buyNum); |
| | | stockAIOrder.setRemainAmount(buyNum); |
| | | stockAIOrder.setRealEarning(BigDecimal.valueOf(0)); |
| | | stockAIOrder.setStatus(EStockAIOrderStatus.wait.getStatus()); //等待审核 |
| | | stockAiOrderMapper.insert(stockAIOrder); |
| | | iUserAssetsServices.aiAvailableBalanceChange(userAssets, EUserAssets.BUY_AI, buyNum, null); |
| | | return ServerResponse.createBySuccessMsg("下单成功"); |
| | | } |
| | | } catch (Exception e) { |
| | |
| | | try { |
| | | User user = iUserService.getCurrentUser(request); |
| | | if (user == null ){ |
| | | return ServerResponse.createBySuccessMsg("请先登录"); |
| | | return ServerResponse.createByErrorCodeMsg(401,"请先登录"); |
| | | } |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<StockAiOrderTypeVO> stockAIOrders = stockAiOrderMapper.getStockAiOrderList(user.getId(), status); |
| | |
| | | StockAI stockAI = stockAiMapper.selectById(stockAIOrder.getStockAiId()); |
| | | //买入金额 |
| | | BigDecimal buyNum = stockAIOrder.getBuyAmount(); |
| | | //如果不是墨西哥币需要转换金额 |
| | | /*//如果不是墨西哥币需要转换金额 |
| | | if (!stockAI.getStockType().equals(EStockType.MX.getCode())) { |
| | | EStockType stockType = EStockType.getEStockTypeByCode(stockAI.getStockType()); |
| | | ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurrencyAndConversionCurrency(stockType.getSymbol(), EStockType.MX.getSymbol()) |
| | |
| | | } |
| | | //转换为墨西哥币 |
| | | buyNum = iUserAssetsServices.exchangeAmountByRate(buyNum, exchangeRate.getRata()); |
| | | }*/ |
| | | Boolean flag = iUserAssetsServices.aiAvailableBalanceChange(stockAI.getStockType(), stockAIOrder.getUserId(), EUserAssets.BUY_AI_REJECT, buyNum, null); |
| | | if (!flag) { |
| | | return ServerResponse.createByErrorMsg("扣款失败,无法转换货币"); |
| | | } |
| | | //获取用户账户 |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(EStockType.MX.getCode(), stockAIOrder.getUserId()); |
| | | iUserAssetsServices.aiAvailableBalanceChange(userAssets, EUserAssets.BUY_AI_REJECT, buyNum, null); |
| | | } else if (status.equals(EStockAIOrderStatus.finished.getStatus())) { |
| | | if (!stockAIOrder.getStatus().equals(EStockAIOrderStatus.passed.getStatus())) { |
| | | return ServerResponse.createByErrorMsg("只能结算申请通过订单"); |
| | |
| | | amount = amount.add(earningsSUM); |
| | | }*/ |
| | | StockAI stockAI = stockAiMapper.selectById(stockAIOrder.getStockAiId()); |
| | | //收益 |
| | | //收益+本金 |
| | | BigDecimal amount = stockAIOrder.getBuyAmount().add(stockAIOrder.getRealEarning()); |
| | | //需要解冻金额 |
| | | BigDecimal buyAmount = stockAIOrder.getBuyAmount(); |
| | | //如果不是墨西哥币需要转换金额 |
| | | /*//如果不是墨西哥币需要转换金额 |
| | | if (!stockAI.getStockType().equals(EStockType.MX.getCode())) { |
| | | EStockType stockType = EStockType.getEStockTypeByCode(stockAI.getStockType()); |
| | | ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurrencyAndConversionCurrency(stockType.getSymbol(), EStockType.MX.getSymbol()) |
| | |
| | | //转换为墨西哥币 |
| | | amount = iUserAssetsServices.exchangeAmountByRate(amount, exchangeRate.getRata()); |
| | | buyAmount = iUserAssetsServices.exchangeAmountByRate(buyAmount, exchangeRate.getRata()); |
| | | }*/ |
| | | Boolean flag = iUserAssetsServices.aiAvailableBalanceChange(stockAI.getStockType(), stockAIOrder.getUserId(), EUserAssets.AI_SETTLEMENT, amount, buyAmount); |
| | | if (!flag) { |
| | | return ServerResponse.createByErrorMsg("扣款失败,无法转换货币"); |
| | | } |
| | | //获取用户账户 |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(EStockType.MX.getCode(), stockAIOrder.getUserId()); |
| | | iUserAssetsServices.aiAvailableBalanceChange(userAssets, EUserAssets.AI_SETTLEMENT, amount, buyAmount); |
| | | } |
| | | stockAIOrder.setStatus(status); |
| | | stockAIOrder.setAuditDate(new Date()); |
| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.nq.Repository.ExchangeRateRepository; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.dao.*; |
| | | import com.nq.enums.EStockType; |
| | |
| | | |
| | | @Autowired |
| | | UserPositionMapper userPositionMapper; |
| | | |
| | | @Autowired |
| | | ExchangeRateRepository exchangeRateRepository; |
| | | |
| | | |
| | | @Override |
| | | public UserAssets assetsByTypeAndUserId(String accetType, Integer userId) { |
| | |
| | | |
| | | @Override |
| | | public Boolean availablebalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount, String desc, String descType) { |
| | | |
| | | UserAssets userAssets = assetsByTypeAndUserId(accetType,userId); |
| | | //UserAssets userAssets = assetsByTypeAndUserId(accetType,userId); |
| | | //查询墨西哥账户 |
| | | UserAssets userAssets = assetsByTypeAndUserId(EStockType.MX.getCode(), userId); |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!accetType.equals(EStockType.MX.getCode())) { |
| | | EStockType stockType = EStockType.getEStockTypeByCode(accetType); |
| | | ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurrencyAndConversionCurrency( |
| | | stockType.getSymbol(), EStockType.MX.getSymbol()).orElse(null); |
| | | if (exchangeRate != null) { |
| | | //转换为墨西哥币 |
| | | amount = exchangeAmountByRate(amount, exchangeRate.getRata()); |
| | | } |
| | | } |
| | | UserPosition userPosition = userPositionMapper.selectOne(new LambdaQueryWrapper<UserPosition>().gt(UserPosition::getAmountToBeCovered, BigDecimal.ZERO).eq(UserPosition::getUserId,userAssets.getUserId())); |
| | | String type = eUserAssets.getDesc(); |
| | | String before = userAssets.getAvailableBalance().toString(); |
| | |
| | | } |
| | | |
| | | |
| | | public Boolean aiAvailableBalanceChange(UserAssets userAssets, EUserAssets eUserAssets, BigDecimal amount, BigDecimal buyAmount) { |
| | | public Boolean aiAvailableBalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount, BigDecimal buyAmount) { |
| | | //查询墨西哥账户 |
| | | UserAssets userAssets = assetsByTypeAndUserId(EStockType.MX.getCode(), userId); |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!accetType.equals(EStockType.MX.getCode())) { |
| | | EStockType stockType = EStockType.getEStockTypeByCode(accetType); |
| | | ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurrencyAndConversionCurrency( |
| | | stockType.getSymbol(), EStockType.MX.getSymbol()).orElse(null); |
| | | if (exchangeRate != null) { |
| | | //转换为墨西哥币 |
| | | amount = exchangeAmountByRate(amount, exchangeRate.getRata()); |
| | | buyAmount = exchangeAmountByRate(buyAmount, exchangeRate.getRata()); |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | String before = userAssets.getAvailableBalance().toString(); |
| | | if (eUserAssets.getCode().equals(EUserAssets.BUY_AI.getCode())) { |
| | | //冻结金额 |
| | |
| | | //归还可用金额 |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount)); |
| | | } else if (eUserAssets.getCode().equals(EUserAssets.AI_SETTLEMENT.getCode())) { |
| | | //解除冻结金额 |
| | | //解除购买冻结金额 |
| | | userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(buyAmount.negate())); |
| | | //归还可用金额(买入金额+收益) |
| | | //归还可用金额(购买金额+收益) |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(amount)); |
| | | } |
| | | String after = userAssets.getAvailableBalance().toString(); |
| | |
| | | try { |
| | | User user = iUserService.getCurrentUser(request); |
| | | if (user == null ){ |
| | | return ServerResponse.createBySuccessMsg("请先登录"); |
| | | return ServerResponse.createByErrorCodeMsg(401,"请先登录"); |
| | | } |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<UserPosition> userPositions = userPositionMapper.getUserPositionDzList(user.getId(), status); |
| | | List<UserPositionCheckDz> userPositionCheckDzs = userPositionCheckDzService.list( |
| | | new QueryWrapper<UserPositionCheckDz>() |
| | | .eq("user_id", user.getId()).eq(status != null,"check_type", status)); |
| | | // 获取分页信息 |
| | | PageInfo<UserPosition> pageInfo = new PageInfo<>(userPositions); |
| | | PageInfo<UserPositionCheckDz> pageInfo = new PageInfo<>(userPositionCheckDzs); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } catch (Exception e) { |
| | | log.error("StockAiService getStockAiOrderList error", e); |
| | |
| | | } |
| | | return ServerResponse.createBySuccess(list); |
| | | } |
| | | return ServerResponse.createByErrorMsg("请先登录",request); |
| | | return ServerResponse.createByErrorCodeMsg(401,"请先登录"); |
| | | } |
| | | /** |
| | | * 新股申购-用户提交金额 |
| | |
| | | return ServerResponse.createByErrorMsg("新股认购订单不存在!",request); |
| | | } |
| | | } |
| | | return ServerResponse.createByErrorMsg("请先登录",request); |
| | | return ServerResponse.createByErrorCodeMsg(401,"请先登录"); |
| | | } |
| | | /** |
| | | * 新股申购-删除 |
| | |
| | | limit 1 |
| | | </select> |
| | | |
| | | <select id="getUserPositionDzList" resultType="com.nq.pojo.UserPosition"> |
| | | SELECT u.* |
| | | FROM user_position u |
| | | LEFT JOIN user_position_check_dz dz ON dz.id = u.dz_id |
| | | |
| | | <where> |
| | | <if test="userId != null "> |
| | | and u.user_id = #{userId} |
| | | </if> |
| | | <if test="checkType != null "> |
| | | and dz.check_type = #{checkType} |
| | | </if> |
| | | </where> |
| | | ORDER BY u.buy_order_time DESC |
| | | </select> |
| | | |
| | | </mapper> |
| | | |