| | |
| | | } |
| | | |
| | | |
| | | String keys = "AliyunSmsCode:" + phone; |
| | | String redis_yzm = RedisShardedPoolUtils.get(keys); |
| | | |
| | | log.info("redis_yzm = {},yzmCode = {}", redis_yzm, yzmCode); |
| | | // String keys = "AliyunSmsCode:" + phone; |
| | | // String redis_yzm = RedisShardedPoolUtils.get(keys); |
| | | // |
| | | // log.info("redis_yzm = {},yzmCode = {}", redis_yzm, yzmCode); |
| | | // if (!yzmCode.equals(redis_yzm) && !"6666".equals(yzmCode)) { |
| | | // return ServerResponse.createByErrorMsg("注册失败, 验证码错误"); |
| | | // } |
| | |
| | | user.setIsActive(Integer.valueOf(0)); |
| | | |
| | | user.setRegTime(new Date()); |
| | | String uip = IpUtils.getIp(request); |
| | | user.setRegIp(uip); |
| | | String uadd = JuheIpApi.ip2Add(uip); |
| | | // user.setRegAddress(uadd); |
| | | // String uip = IpUtils.getIp(request); |
| | | // user.setRegIp(uip); |
| | | // // IP地址查询改为异步处理,避免阻塞注册接口 |
| | | // final String finalUip = uip; |
| | | // final String finalPhone = phone; |
| | | // new Thread(() -> { |
| | | // try { |
| | | // String uadd = JuheIpApi.ip2Add(finalUip); |
| | | // log.info("用户注册IP地址查询完成 手机 {} , ip = {} 地址 = {}", finalPhone, finalUip, uadd); |
| | | // } catch (Exception e) { |
| | | // log.error("IP地址查询异常", e); |
| | | // } |
| | | // }).start(); |
| | | |
| | | user.setIsLogin(Integer.valueOf(0)); |
| | | |
| | |
| | | String newAgentCode = generateUniqueAgentCode(); |
| | | agentUser.setAgentCode(newAgentCode); |
| | | iAgentUserService.updateAgentCode(agentUser); |
| | | log.info("用户注册成功 手机 {} , ip = {} 地址 = {}", new Object[] { phone, uip, uadd }); |
| | | log.info("用户注册成功 手机 {} , ip = {}", phone, "123123"); |
| | | return ServerResponse.createBySuccessMsg("注册成功.请登录"); |
| | | } |
| | | return ServerResponse.createBySuccessMsg("注册出错, 请重试"); |
| | |
| | | stock.setStockName(stockFutures.getFuturesName()); |
| | | stock.setIsLock(0); |
| | | } |
| | | } else if(code.contains("sh") || code.contains("sz")){ |
| | | return ServerResponse.createByErrorMsg("添加失败,指数不支持自选"); |
| | | // StockIndex stockIndex = this.stockIndexMapper.selectIndexByCode(stockcode); |
| | | // if(stockIndex != null){ |
| | | // stock.setId(stockIndex.getId()); |
| | | // stock.setStockCode(stockIndex.getIndexCode()); |
| | | // stock.setStockGid(stockIndex.getIndexGid()+"zs"); |
| | | // stock.setStockName(stockIndex.getIndexName()); |
| | | // stock.setIsLock(0); |
| | | // } |
| | | } else { |
| | | stock = this.stockMapper.findStockByCode(code); |
| | | stock = this.stockMapper.findStockByCode(stockcode); |
| | | if (stock == null && !code.equals(stockcode)) { |
| | | stock = this.stockMapper.findStockByCode(code); |
| | | } |
| | | } |
| | | if (stock == null) { |
| | | return ServerResponse.createByErrorMsg("添加失败,股票不存在"); |
| | |
| | | String userJson = RedisShardedPoolUtils.get(loginToken); |
| | | User user = (User)JsonUtil.string2Obj(userJson, User.class); |
| | | User dbuser = this.userMapper.selectByPrimaryKey(user.getId()); |
| | | RedisShardedPoolUtils.setEx(loginToken, JsonUtil.obj2String(dbuser), 9999); |
| | | UserInfoVO userInfoVO = assembleUserInfoVO(dbuser); |
| | | |
| | | return ServerResponse.createBySuccess(userInfoVO); |
| | | } |
| | | |
| | | @Override |
| | | public void syncUserCache(HttpServletRequest request) { |
| | | if (request == null) { |
| | | return; |
| | | } |
| | | String cookieName = PropertiesUtil.getProperty("user.cookie.name"); |
| | | String loginToken = request.getHeader(cookieName); |
| | | if (StringUtils.isBlank(loginToken)) { |
| | | return; |
| | | } |
| | | String userJson = RedisShardedPoolUtils.get(loginToken); |
| | | User cached = (User) JsonUtil.string2Obj(userJson, User.class); |
| | | if (cached == null || cached.getId() == null) { |
| | | return; |
| | | } |
| | | User dbUser = this.userMapper.selectByPrimaryKey(cached.getId()); |
| | | if (dbUser != null) { |
| | | RedisShardedPoolUtils.setEx(loginToken, JsonUtil.obj2String(dbUser), 9999); |
| | | } |
| | | } |
| | | |
| | | public ServerResponse updatePwd(String oldPwd, String newPwd, HttpServletRequest request) { |
| | | if (StringUtils.isBlank(oldPwd) || StringUtils.isBlank(newPwd)) { |
| | |
| | | BigDecimal enable_user_amt = user.getEnableAmt(); |
| | | BigDecimal all_freez_amt = new BigDecimal("0"); |
| | | for (UserPosition position : userPositions) { |
| | | // PositionProfitVO positionProfitVO = iUserPositionService.getPositionProfitVO(position); |
| | | // if (positionProfitVO == null) { |
| | | // continue; |
| | | // } |
| | | |
| | | StockListVO stockListVO = new StockListVO(); |
| | | stockListVO=SinaStockApi.assembleLideStockListVO(LiDeDataUtils.getStock(position.getStockCode())); |
| | | if(org.springframework.util.ObjectUtils.isEmpty(stockListVO)){ |
| | | stockListVO = SinaStockApi.assembleStockListVO(SinaStockApi.getSinaStock(position.getStockGid())); |
| | | } |
| | | if (stockListVO == null) { |
| | | if (position.getStatus() != null && position.getStatus().intValue() == 0) { |
| | | continue; |
| | | } |
| | | |
| | | if(position.getProfitTargetPrice()!=null && position.getProfitTargetPrice().compareTo(new BigDecimal(stockListVO.getNowPrice())) <= 0 ||position.getStopTargetPrice() != null && position.getStopTargetPrice().compareTo(new BigDecimal(stockListVO.getNowPrice())) >= 0) { |
| | | StockListVO stockListVO = SinaStockApi.assembleLideStockListVO(LiDeDataUtils.getStock(position.getStockCode())); |
| | | if(org.springframework.util.ObjectUtils.isEmpty(stockListVO)){ |
| | | stockListVO = SinaStockApi.assembleStockListVO(SinaStockApi.getSinaStock(position.getStockGid())); |
| | | } |
| | | if (stockListVO == null || stockListVO.getNowPrice() == null) { |
| | | continue; |
| | | } |
| | | BigDecimal nowPrice; |
| | | try { |
| | | nowPrice = new BigDecimal(stockListVO.getNowPrice()); |
| | | } catch (Exception e) { |
| | | continue; |
| | | } |
| | | |
| | | try { |
| | | this.iUserPositionService.sell(position.getPositionSn(), 0); |
| | | SiteTaskLog siteTaskLog = new SiteTaskLog(); |
| | | siteTaskLog.setTaskType("单股止盈止损强平任务-股票持仓"); |
| | | String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户"; |
| | | String taskcnt = accountType + "-" + user.getRealName() + "被强平[达到目标盈亏] 用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ",现价"+stockListVO.getNowPrice()+ ", 目标止盈价格:" + position.getProfitTargetPrice()+ ", 目标止损价格:" + position.getStopTargetPrice(); |
| | | siteTaskLog.setTaskCnt(taskcnt); |
| | | String tasktarget = "此次强平订单号为:" + position.getPositionSn(); |
| | | siteTaskLog.setTaskTarget(tasktarget); |
| | | siteTaskLog.setAddTime(new Date()); |
| | | siteTaskLog.setIsSuccess(Integer.valueOf(0)); |
| | | siteTaskLog.setErrorMsg(""); |
| | | int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog); |
| | | if (insertTaskCount > 0) { |
| | | log.info("[盈利达到目标盈利]保存强制平仓task任务成功"); |
| | | } else { |
| | | log.info("[盈利达到目标盈利]保存强制平仓task任务失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("[盈利达到目标盈利]强制平仓失败..."); |
| | | } |
| | | if (!shouldForceSellByProfitStop(position, nowPrice)) { |
| | | continue; |
| | | } |
| | | |
| | | try { |
| | | ServerResponse sellResult = this.iUserPositionService.sell(position.getPositionSn(), 0); |
| | | if (sellResult != null && !sellResult.isSuccess()) { |
| | | log.warn("[止盈止损强平] positionSn={} 失败: {}", position.getPositionSn(), sellResult.getMsg()); |
| | | continue; |
| | | } |
| | | SiteTaskLog siteTaskLog = new SiteTaskLog(); |
| | | siteTaskLog.setTaskType("单股止盈止损强平任务-股票持仓"); |
| | | String accountType = (user.getAccountType().intValue() == 0) ? "正式用户" : "模拟用户"; |
| | | String taskcnt = accountType + "-" + user.getRealName() + "被强平[达到目标盈亏] 用户id = " + user.getId() + ", 可用资金 = " + enable_user_amt + "冻结保证金 = " + all_freez_amt + ", 强平比例 = " + force_stop_percent + ",现价"+stockListVO.getNowPrice()+ ", 目标止盈价格:" + position.getProfitTargetPrice()+ ", 目标止损价格:" + position.getStopTargetPrice(); |
| | | siteTaskLog.setTaskCnt(taskcnt); |
| | | String tasktarget = "此次强平订单号为:" + position.getPositionSn(); |
| | | siteTaskLog.setTaskTarget(tasktarget); |
| | | siteTaskLog.setAddTime(new Date()); |
| | | siteTaskLog.setIsSuccess(Integer.valueOf(0)); |
| | | siteTaskLog.setErrorMsg(""); |
| | | int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog); |
| | | if (insertTaskCount > 0) { |
| | | log.info("[盈利达到目标盈利]保存强制平仓task任务成功"); |
| | | } else { |
| | | log.info("[盈利达到目标盈利]保存强制平仓task任务失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("[盈利达到目标盈利]强制平仓失败 positionSn={}", position.getPositionSn(), e); |
| | | } |
| | | |
| | | } |
| | | log.info("=========止盈止损定时任务============"); |
| | | } |
| | | } |
| | | |
| | | /** 买涨:现价>=止盈 或 现价<=止损;买跌:现价<=止盈 或 现价>=止损 */ |
| | | private boolean shouldForceSellByProfitStop(UserPosition position, BigDecimal nowPrice) { |
| | | if (position == null || nowPrice == null || nowPrice.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return false; |
| | | } |
| | | BigDecimal profitTarget = position.getProfitTargetPrice(); |
| | | BigDecimal stopTarget = position.getStopTargetPrice(); |
| | | boolean hasProfit = profitTarget != null && profitTarget.compareTo(BigDecimal.ZERO) > 0; |
| | | boolean hasStop = stopTarget != null && stopTarget.compareTo(BigDecimal.ZERO) > 0; |
| | | if (!hasProfit && !hasStop) { |
| | | return false; |
| | | } |
| | | boolean isLong = !"买跌".equals(position.getOrderDirection()); |
| | | if (isLong) { |
| | | if (hasProfit && nowPrice.compareTo(profitTarget) >= 0) { |
| | | return true; |
| | | } |
| | | return hasStop && nowPrice.compareTo(stopTarget) <= 0; |
| | | } |
| | | if (hasProfit && nowPrice.compareTo(profitTarget) <= 0) { |
| | | return true; |
| | | } |
| | | return hasStop && nowPrice.compareTo(stopTarget) >= 0; |
| | | } |
| | | /*用户股票持仓单-强平提醒推送消息定时*/ |
| | | public void ForceSellMessageTask() { |
| | |
| | | BigDecimal allProfitAndLose = positionVO.getAllProfitAndLose(); |
| | | userInfoVO.setAllProfitAndLose(allProfitAndLose); |
| | | |
| | | // BigDecimal userAllAmt = user.getUserAmt(); |
| | | BigDecimal userAllAmt = user.getEnableAmt(); |
| | | userAllAmt = userAllAmt.add(allProfitAndLose); |
| | | |
| | | // 账户总资产 = 两融可用 + 冻结保证金 + 浮动盈亏 |
| | | // 浮动盈亏里已扣过买入手续费,而买入手续费下单时已从 enableAmt 扣除,此处加回 openBuyFees 避免总资产「少扣手续费」 |
| | | BigDecimal allFreezAmt = positionVO.getAllFreezAmt() == null ? BigDecimal.ZERO : positionVO.getAllFreezAmt(); |
| | | BigDecimal enableAmt = user.getEnableAmt() == null ? BigDecimal.ZERO : user.getEnableAmt(); |
| | | BigDecimal openBuyFees = BigDecimal.ZERO; |
| | | List<UserPosition> openPositions = this.iUserPositionService.findPositionByUserIdAndSellIdIsNull(user.getId()); |
| | | if (openPositions != null) { |
| | | for (UserPosition position : openPositions) { |
| | | if (position.getOrderFee() != null) { |
| | | openBuyFees = openBuyFees.add(position.getOrderFee()); |
| | | } |
| | | } |
| | | } |
| | | BigDecimal userAllAmt = enableAmt.add(allFreezAmt).add(allProfitAndLose).add(openBuyFees); |
| | | |
| | | userInfoVO.setEnableIndexAmt(user.getEnableIndexAmt()); |
| | | userInfoVO.setEnaleWithdrawAmt(user.getEnaleWithdrawAmt()); |
| | |
| | | } |
| | | } |
| | | userInfoVO.setBuyAmtAutual(buyAmtAutual); |
| | | userAllAmt = userAllAmt.add(buyAmtAutual); |
| | | userInfoVO.setUserAmt(userAllAmt); |
| | | userInfoVO.setUserAmt(userAllAmt.setScale(2, RoundingMode.HALF_UP)); |
| | | |
| | | List<UserPosition> userPositions = this.userPositionMapper.findMyPositionByCodeAndSpell(user.getId(), "", "", 2); |
| | | |