| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.dao.*; |
| | | import com.nq.enums.EConfigKey; |
| | | import com.nq.enums.EUserAssets; |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.*; |
| | | import com.nq.utils.KeyUtils; |
| | | import com.nq.utils.stock.GeneratePosition; |
| | | import com.nq.utils.timeutil.DateTimeUtil; |
| | | import com.nq.utils.PropertiesUtil; |
| | | import com.nq.utils.redis.JsonUtil; |
| | |
| | | @Autowired |
| | | private IUserService iUserService; |
| | | @Autowired |
| | | private IUserPositionService iUserPositionService; |
| | | private IUserAssetsServices iUserAssetsServices; |
| | | @Autowired |
| | | private SiteTaskLogMapper siteTaskLogMapper; |
| | | ISiteProductService iSiteProductService; |
| | | @Autowired |
| | | private UserMapper userMapper; |
| | | IStockConfigServices iStockConfigServices; |
| | | @Autowired |
| | | private StockIndexMapper stockIndexMapper; |
| | | IPriceServices priceServices; |
| | | @Autowired |
| | | private IStockIndexService iStockIndexService; |
| | | @Autowired |
| | | private IUserIndexPositionService iUserIndexPositionService; |
| | | @Autowired |
| | | private IStockCoinService iStockCoinService; |
| | | @Autowired |
| | | private IStockFuturesService iStockFuturesService; |
| | | @Autowired |
| | | private ISiteSettingService iSiteSettingService; |
| | | @Autowired |
| | | private UserPositionMapper userPositionMapper; |
| | | |
| | | ITradingHourService tradingHourService; |
| | | @Override |
| | | public ServerResponse addOrder(String stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, BigDecimal targetPrice, HttpServletRequest request) { |
| | | public ServerResponse addOrder(Integer stockId, Integer buyNum, Integer buyType, |
| | | Integer lever, BigDecimal profitTarget, |
| | | BigDecimal stopTarget,String targetPrice, HttpServletRequest request) { |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | synchronized (user.getId()){ |
| | | if (siteProduct.getRealNameDisplay() && user.getIsActive() != 2) { |
| | | return ServerResponse.createByErrorMsg("订单失败,请先实名认证", request); |
| | | } |
| | | // 手续费率 |
| | | BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ; |
| | | |
| | | if (user == null) { |
| | | return ServerResponse.createByErrorMsg("Please log in first"); |
| | | } |
| | | SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting(); |
| | | if (buyNum.intValue() < siteSetting.getBuyMinNum().intValue()) { |
| | | return ServerResponse.createByErrorMsg("The pending order failed, and the purchased quantity was less than" + siteSetting |
| | | .getBuyMinNum() + "stocks"); |
| | | } |
| | | if (buyNum.intValue() > siteSetting.getBuyMaxNum().intValue()) { |
| | | return ServerResponse.createByErrorMsg("The pending order failed because the purchased quantity was greater than" + siteSetting |
| | | .getBuyMaxNum() + "stocks"); |
| | | } |
| | | UserPendingorder userPendingorder = userPendingorderMapper.selectOne(new QueryWrapper<UserPendingorder>().eq("user_id", user.getId()).eq("stock_id", stockId).eq("status", 0)); |
| | | if (userPendingorder != null) { |
| | | return ServerResponse.createByErrorMsg("Please do not repeat the order"); |
| | | } |
| | | if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) { |
| | | return ServerResponse.createByErrorMsg("订单失败,帐户已被锁定", request); |
| | | } |
| | | |
| | | userPendingorder = new UserPendingorder(); |
| | | userPendingorder.setUserId(user.getId()); |
| | | userPendingorder.setStockId(stockId); |
| | | userPendingorder.setBuyNum(buyNum); |
| | | userPendingorder.setBuyType(buyType); |
| | | userPendingorder.setLever(lever); |
| | | userPendingorder.setProfitTarget(profitTarget); |
| | | userPendingorder.setStopTarget(stopTarget); |
| | | userPendingorder.setNowPrice(new BigDecimal(0)); |
| | | userPendingorder.setTargetPrice(targetPrice); |
| | | userPendingorder.setAddTime(new Date()); |
| | | userPendingorder.setStatus(0); |
| | | int ret = userPendingorderMapper.insert(userPendingorder); |
| | | if (ret > 0) { |
| | | return ServerResponse.createBySuccessMsg("If the pending order is successfully added, the order will be automatically placed if the order conditions are met"); |
| | | } |
| | | return ServerResponse.createByErrorMsg("Add failure"); |
| | | Stock stock = stockMapper.selectByPrimaryKey(stockId); |
| | | if (stock == null) { |
| | | return ServerResponse.createByErrorMsg("订单失败,股票代码不存在", request); |
| | | } |
| | | //判断股票是否在可交易时间段 |
| | | Boolean b = tradingHourService.timeCheck(stock.getStockCode()); |
| | | if (!b) { |
| | | return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内", request); |
| | | } |
| | | |
| | | |
| | | StockConfig mainBuyConfig = iStockConfigServices.queryByKey(EConfigKey.MIN_BUY.getCode()); |
| | | |
| | | if(buyNum<Integer.parseInt(mainBuyConfig.getCValue())){ |
| | | return ServerResponse.createByErrorMsg("最低购买数量"+mainBuyConfig.getCValue(), request); |
| | | } |
| | | |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(stock.getStockType(), user.getId()); |
| | | StockConfig maxBuyConfig = iStockConfigServices.queryByKey(EConfigKey.MAX_BUY.getCode()); |
| | | if(buyNum<Integer.parseInt(mainBuyConfig.getCValue())){ |
| | | return ServerResponse.createByErrorMsg("最高购买数量"+maxBuyConfig.getCValue(), request); |
| | | } |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | | } |
| | | if (stock.getIsLock() != 0) { |
| | | return ServerResponse.createByErrorMsg("订单失败,股票被锁定", request); |
| | | } |
| | | |
| | | if (!priceServices.isLimitUpBuy(stock.getStockCode())) { |
| | | return ServerResponse.createByErrorMsg("暂无配额", request); |
| | | } |
| | | |
| | | //股票类型 现价 数据源的处理 |
| | | BigDecimal nowPrice = new BigDecimal(targetPrice); |
| | | |
| | | if (nowPrice.compareTo(new BigDecimal("0")) == 0) { |
| | | return ServerResponse.createByErrorMsg("报价0,请稍后再试", request); |
| | | } |
| | | |
| | | BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever)); |
| | | BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt); |
| | | |
| | | 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); |
| | | } |
| | | UserPendingorder userPendingorder = new UserPendingorder(); |
| | | if (profitTarget != null && profitTarget.compareTo(new BigDecimal("0")) > 0) { |
| | | userPendingorder.setProfitTargetPrice(profitTarget); |
| | | } |
| | | if (stopTarget != null && stopTarget.compareTo(new BigDecimal("0")) > 0) { |
| | | userPendingorder.setStopTargetPrice(stopTarget); |
| | | } |
| | | userPendingorder.setPositionType(1); |
| | | userPendingorder.setPositionSn(KeyUtils.getUniqueKey()); |
| | | userPendingorder.setUserId(user.getId()); |
| | | userPendingorder.setNickName(user.getRealName()); |
| | | userPendingorder.setAgentId(user.getAgentId()); |
| | | userPendingorder.setStockCode(stock.getStockCode()); |
| | | userPendingorder.setStockName(stock.getStockName()); |
| | | userPendingorder.setStockGid(stock.getStockType()); |
| | | userPendingorder.setStockSpell(stock.getStockSpell()); |
| | | userPendingorder.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPendingorder.setBuyOrderTime(new Date()); |
| | | userPendingorder.setBuyOrderPrice(nowPrice); |
| | | userPendingorder.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌"); |
| | | userPendingorder.setOrderNum(buyNum); |
| | | if (stock.getStockPlate() != null) { |
| | | userPendingorder.setStockPlate(stock.getStockPlate()); |
| | | } |
| | | userPendingorder.setIsLock(Integer.valueOf(0)); |
| | | userPendingorder.setOrderLever(lever); |
| | | userPendingorder.setOrderTotalPrice(buyAmt); |
| | | // 手续费 |
| | | |
| | | userPendingorder.setOrderFee(orderFree); |
| | | userPendingorder.setOrderSpread(BigDecimal.ZERO); |
| | | userPendingorder.setSpreadRatePrice(BigDecimal.ZERO); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPendingorder.setProfitAndLose(profit_and_lose); |
| | | userPendingorder.setAllProfitAndLose(profit_and_lose.add(orderFree)); |
| | | userPendingorder.setOrderStayDays(Integer.valueOf(0)); |
| | | userPendingorder.setOrderStayFee(BigDecimal.ZERO); |
| | | userPendingorderMapper.insert(userPendingorder); |
| | | return ServerResponse.createBySuccessMsg("挂单成功", request); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse orderList(HttpServletRequest request) { |
| | | public ServerResponse hjyyAddOrder(String name, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopLoss, String targetPrice, HttpServletRequest request) { |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | |
| | | String property = PropertiesUtil.getProperty("user.cookie.name"); |
| | | String header = request.getHeader(property); |
| | | // log.info("header:{}",header); |
| | | if (header != null) { |
| | | String userJson = RedisShardedPoolUtils.get(header); |
| | | User user = (User) JsonUtil.string2Obj(userJson, User.class); |
| | | // log.info("user:{}",user); |
| | | if (user != null) { |
| | | List<UserPendingorder> userPendingorders = userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("user_id", user.getId())); |
| | | |
| | | List UserPendingorderList = new ArrayList(); |
| | | |
| | | |
| | | for (UserPendingorder userPendingorder : userPendingorders) { |
| | | UserPendingorderVO userPendingorderVO = new UserPendingorderVO(); |
| | | //挂单-指数 |
| | | //挂单-股票 |
| | | Stock stock = stockMapper.findStockByCode(userPendingorder.getStockId()); |
| | | StockListVO stockListVO = new StockListVO(); |
| | | stockListVO = StockApi.getStockRealTime( |
| | | stock); |
| | | String nowPrice = stockListVO.getNowPrice(); |
| | | if (nowPrice == null) { |
| | | nowPrice = String.valueOf(0); |
| | | } |
| | | userPendingorderVO.setNowPrice(new BigDecimal(nowPrice)); |
| | | userPendingorderVO.setStockName(stock.getStockName()); |
| | | userPendingorderVO.setStockId(stock.getStockCode()); |
| | | userPendingorderVO.setBuyNum(userPendingorder.getBuyNum()); |
| | | userPendingorderVO.setBuyType(userPendingorder.getBuyType()); |
| | | userPendingorderVO.setLever(userPendingorder.getLever()); |
| | | userPendingorderVO.setProfitTarget(userPendingorder.getProfitTarget()); |
| | | userPendingorderVO.setStopTarget(userPendingorder.getStopTarget()); |
| | | userPendingorderVO.setTargetPrice(userPendingorder.getTargetPrice()); |
| | | userPendingorderVO.setAddTime(userPendingorder.getAddTime()); |
| | | userPendingorderVO.setStatus(userPendingorder.getStatus()); |
| | | userPendingorderVO.setId(userPendingorder.getId()); |
| | | UserPendingorderList.add(userPendingorderVO); |
| | | } |
| | | return ServerResponse.createBySuccess(UserPendingorderList); |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | synchronized (user.getId()){ |
| | | if (siteProduct.getRealNameDisplay() && user.getIsActive() != 2) { |
| | | return ServerResponse.createByErrorMsg("订单失败,请先实名认证", request); |
| | | } |
| | | } |
| | | return ServerResponse.createByErrorMsg("数据异常"); |
| | | // 手续费率 |
| | | BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ; |
| | | |
| | | if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) { |
| | | return ServerResponse.createByErrorMsg("订单失败,帐户已被锁定", request); |
| | | } |
| | | |
| | | BigDecimal price = new BigDecimal(targetPrice); |
| | | |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("USDT", user.getId()); |
| | | |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("挂单失败,请先缴清待补资金", request); |
| | | } |
| | | |
| | | if (price.compareTo(new BigDecimal("0")) == 0) { |
| | | return ServerResponse.createByErrorMsg("报价0,请稍后再试", request); |
| | | } |
| | | |
| | | BigDecimal buyAmt = price.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever)); |
| | | BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt); |
| | | |
| | | 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); |
| | | } |
| | | UserPendingorder userPendingorder = new UserPendingorder(); |
| | | userPendingorder.setPositionType(1); |
| | | userPendingorder.setPositionSn(KeyUtils.getUniqueKey()); |
| | | userPendingorder.setUserId(user.getId()); |
| | | userPendingorder.setNickName(user.getRealName()); |
| | | userPendingorder.setAgentId(user.getAgentId()); |
| | | userPendingorder.setStockCode("HJYY"); |
| | | userPendingorder.setStockName(name); |
| | | userPendingorder.setStockGid("HJYY"); |
| | | userPendingorder.setStockSpell(name); |
| | | userPendingorder.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPendingorder.setBuyOrderTime(new Date()); |
| | | userPendingorder.setBuyOrderPrice(price); |
| | | userPendingorder.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌"); |
| | | userPendingorder.setOrderNum(buyNum); |
| | | userPendingorder.setIsLock(Integer.valueOf(0)); |
| | | userPendingorder.setOrderLever(lever); |
| | | userPendingorder.setOrderTotalPrice(buyAmt); |
| | | // 手续费 |
| | | userPendingorder.setOrderFee(orderFree); |
| | | userPendingorder.setOrderSpread(BigDecimal.ZERO); |
| | | userPendingorder.setSpreadRatePrice(BigDecimal.ZERO); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPendingorder.setProfitAndLose(profit_and_lose); |
| | | userPendingorder.setAllProfitAndLose(profit_and_lose.add(orderFree)); |
| | | userPendingorder.setOrderStayDays(Integer.valueOf(0)); |
| | | userPendingorder.setOrderStayFee(BigDecimal.ZERO); |
| | | userPendingorderMapper.insert(userPendingorder); |
| | | iUserAssetsServices.availablebalanceChange("USDT", user.getId(), EUserAssets.BUY, buyAmt.negate(), "", ""); |
| | | return ServerResponse.createBySuccessMsg("下单成功", request); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void orderTask() { |
| | | |
| | | List<UserPendingorder> userPendingorders = userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("status", 0)); |
| | | log.info("当前有挂单的用户数量 为 {}", Integer.valueOf(userPendingorders.size())); |
| | | for (int i = 0; i < userPendingorders.size(); i++) { |
| | | Integer userId = (Integer) userPendingorders.get(i).getUserId(); |
| | | User user = this.userMapper.selectById(userId); |
| | | if (user == null) { |
| | | continue; |
| | | } |
| | | List<UserPendingorder> userPendingorderList = userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("user_id", userId).eq("status", 0)); |
| | | if (userPendingorderList == null) { |
| | | continue; |
| | | } |
| | | log.info("用户id = {} 姓名 = {} 已挂单数: {}", new Object[]{userId, user.getRealName(), Integer.valueOf(userPendingorders.size())}); |
| | | BigDecimal all_freez_amt = new BigDecimal("0"); |
| | | String nowPrice = ""; |
| | | String code = ""; |
| | | Integer indexId = null; |
| | | StockListVO stockListVO = new StockListVO(); |
| | | StockCoin stockCoin = new StockCoin(); |
| | | for (UserPendingorder userPendingorder : userPendingorderList) { |
| | | //指数 |
| | | if (userPendingorder.getStockId().contains("sh") || userPendingorder.getStockId().contains("sz") || userPendingorder.getStockId().contains("hk") || userPendingorder.getStockId().contains("us")) { |
| | | StockIndex model = stockIndexMapper.selectIndexByCode(userPendingorder.getStockId().replace("sh", "").replace("sz", "").replace("hk", "").replace("us", "")); |
| | | all_freez_amt = (new BigDecimal(model.getDepositAmt().intValue())).multiply(new BigDecimal(userPendingorder.getBuyNum())).divide(new BigDecimal(userPendingorder.getLever())).setScale(4, 2); |
| | | |
| | | // if (){ |
| | | // |
| | | // }else { |
| | | MarketVO marketVO = this.iStockIndexService.querySingleIndex(model.getIndexGid()); |
| | | nowPrice = marketVO.getNowPrice(); |
| | | // } |
| | | |
| | | indexId = model.getId(); |
| | | |
| | | } else { |
| | | //股票 |
| | | Stock stock = stockMapper.findStockByCode(userPendingorder.getStockId()); |
| | | if ("hk".equals(stock.getStockType())) { |
| | | String hk = RedisShardedPoolUtils.get(stock.getStockGid(), 1); |
| | | stockListVO = StockApi.otherStockListVO(hk); |
| | | // stockCoin = iStockCoinService.selectCoinByCode("HKD"); |
| | | ExchangeVO exchangeVO = this.iStockFuturesService.queryExchangeVO("HKD").getData(); |
| | | nowPrice = String.valueOf(new BigDecimal(stockListVO.getNowPrice()).multiply(new BigDecimal(exchangeVO.getNowPrice()))); |
| | | } else if ("us".equals(stock.getStockType())) { |
| | | String us = RedisShardedPoolUtils.get(stock.getStockGid(), 2); |
| | | stockListVO = StockApi.otherStockListVO(us); |
| | | // stockCoin = iStockCoinService.selectCoinByCode("USD"); |
| | | ExchangeVO exchangeVO = this.iStockFuturesService.queryExchangeVO("USD").getData(); |
| | | nowPrice = String.valueOf(new BigDecimal(stockListVO.getNowPrice()).multiply(new BigDecimal(exchangeVO.getNowPrice()))); |
| | | } else { |
| | | stockListVO = StockApi.getStockRealTime(stock); |
| | | nowPrice = stockListVO.getNowPrice(); |
| | | } |
| | | |
| | | |
| | | all_freez_amt = new BigDecimal(nowPrice).multiply(new BigDecimal(userPendingorder.getBuyNum())).divide(new BigDecimal(userPendingorder.getLever()), 2, 4); |
| | | code = stock.getStockCode(); |
| | | } |
| | | if (nowPrice == null) { |
| | | nowPrice = String.valueOf(0); |
| | | } |
| | | if (userPendingorder.getUserId() != null && userPendingorder.getStockId() != null && userPendingorder.getBuyNum() != null && userPendingorder.getBuyType() != null && userPendingorder.getLever() != null && userPendingorder.getTargetPrice() != null) { |
| | | int ret = userPendingorder.getBuyType().intValue() == 0 ? userPendingorder.getTargetPrice().compareTo(new BigDecimal(nowPrice)) : new BigDecimal(nowPrice).compareTo(userPendingorder.getTargetPrice()); |
| | | //当前时间String |
| | | String buyTime = DateTimeUtil.dateToStr(new Date()); |
| | | if (ret <= 0) { |
| | | if (code != null && !"".equals(code)) { |
| | | try { |
| | | this.iUserPositionService.create(userPendingorder.getUserId(), code, nowPrice, buyTime, userPendingorder.getBuyNum(), userPendingorder.getBuyType(), userPendingorder.getLever(), userPendingorder.getProfitTarget(), userPendingorder.getStopTarget()); |
| | | userPendingorder.setStatus(1); |
| | | this.userPendingorderMapper.updateById(userPendingorder); |
| | | SiteTaskLog siteTaskLog = new SiteTaskLog(); |
| | | siteTaskLog.setTaskType("股票挂单转持仓"); |
| | | String accountType = (user.getAccountType() == 0) ? "正式用户" : "模拟用户"; |
| | | String tasktarget = "此次挂单买入id:" + userPendingorder.getId(); |
| | | siteTaskLog.setTaskTarget(tasktarget); |
| | | siteTaskLog.setAddTime(new Date()); |
| | | siteTaskLog.setIsSuccess(0); |
| | | siteTaskLog.setErrorMsg(""); |
| | | int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog); |
| | | if (insertTaskCount > 0) { |
| | | log.info("挂单task任务成功"); |
| | | } else { |
| | | log.info("挂单task任务失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("股票挂单任务失败..."); |
| | | userPendingorder.setStatus(2); |
| | | this.userPendingorderMapper.updateById(userPendingorder); |
| | | } |
| | | } else if (indexId != null) { |
| | | try { |
| | | this.iUserIndexPositionService.buyIndexOrder(indexId, userPendingorder.getBuyNum(), userPendingorder.getBuyType(), userPendingorder.getLever(), userPendingorder.getProfitTarget(), userPendingorder.getStopTarget(), userPendingorder.getUserId()); |
| | | userPendingorder.setStatus(1); |
| | | this.userPendingorderMapper.updateById(userPendingorder); |
| | | SiteTaskLog siteTaskLog = new SiteTaskLog(); |
| | | siteTaskLog.setTaskType("指数挂单转持仓"); |
| | | String accountType = (user.getAccountType() == 0) ? "正式用户" : "模拟用户"; |
| | | String tasktarget = "此次挂单买入id:" + userPendingorder.getId(); |
| | | siteTaskLog.setTaskTarget(tasktarget); |
| | | siteTaskLog.setAddTime(new Date()); |
| | | siteTaskLog.setIsSuccess(0); |
| | | siteTaskLog.setErrorMsg(""); |
| | | int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog); |
| | | if (insertTaskCount > 0) { |
| | | log.info("挂单task任务成功"); |
| | | userPendingorder.setStatus(1); |
| | | } else { |
| | | log.info("挂单task任务失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("指数挂单任务失败..."); |
| | | userPendingorder.setStatus(2); |
| | | this.userPendingorderMapper.updateById(userPendingorder); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | log.info("===========挂单结束=========="); |
| | | } |
| | | |
| | | //删除 |
| | | @Override |
| | | public ServerResponse delOrder(Integer id, HttpServletRequest request) { |
| | | String property = PropertiesUtil.getProperty("user.cookie.name"); |
| | | String header = request.getHeader(property); |
| | | if (header != null) { |
| | | String userJson = RedisShardedPoolUtils.get(header); |
| | | User user = (User) JsonUtil.string2Obj(userJson, User.class); |
| | | UserPendingorder userPendingorder = this.userPendingorderMapper.selectById(id); |
| | | if (userPendingorder == null) { |
| | | return ServerResponse.createByErrorMsg("The pending order does not exist"); |
| | | } |
| | | if (user.getId().intValue() != userPendingorder.getUserId().intValue()) { |
| | | return ServerResponse.createByErrorMsg("The pending order does not belong to you"); |
| | | } |
| | | int delCount = this.userPendingorderMapper.deleteById(id); |
| | | if (delCount > 0) { |
| | | return ServerResponse.createByErrorMsg("Successfully deleted"); |
| | | } |
| | | return ServerResponse.createByErrorMsg("Deletion failure"); |
| | | } |
| | | |
| | | return ServerResponse.createByErrorMsg("Please log in"); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public ServerResponse orderListByAdmin(int pageNum, int pageSize, String keywords, String status, HttpServletRequest request) { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | QueryWrapper<UserPendingorder> queryWrapper = new QueryWrapper(); |
| | | if (keywords != null && !keywords.equals("")) { |
| | | queryWrapper.like("stock_id", keywords).or().like("user_id", keywords); |
| | | } |
| | | if (status != null && !status.equals("")) { |
| | | queryWrapper.eq("status", status); |
| | | } |
| | | queryWrapper.orderByDesc("id"); |
| | | List<UserPendingorder> stockSubscribeList = this.userPendingorderMapper.selectList(queryWrapper); |
| | | List UserPendingorderList = new ArrayList(); |
| | | for (UserPendingorder userPendingorder : stockSubscribeList) { |
| | | UserPendingorderVO userPendingorderVO = new UserPendingorderVO(); |
| | | //挂单-指数 |
| | | if (userPendingorder.getStockId().contains("sh") || userPendingorder.getStockId().contains("sz") || userPendingorder.getStockId().contains("hk") || userPendingorder.getStockId().contains("us")) { |
| | | StockIndex model = stockIndexMapper.selectIndexByCode(userPendingorder.getStockId().replace("sh", "").replace("sz", "").replace("hk", "").replace("us", "")); |
| | | |
| | | MarketVO marketVO = this.iStockIndexService.querySingleIndex(model.getIndexGid()); |
| | | userPendingorderVO.setNowPrice(new BigDecimal(marketVO.getNowPrice())); |
| | | userPendingorderVO.setStockName(model.getIndexName()); |
| | | userPendingorderVO.setStockId(model.getIndexGid()); |
| | | |
| | | } else { |
| | | //挂单-股票 |
| | | Stock stock = stockMapper.findStockByCode(userPendingorder.getStockId()); |
| | | StockListVO stockListVO = new StockListVO(); |
| | | if (stock.getStockType().equals("hk")) { |
| | | String hk = RedisShardedPoolUtils.get(stock.getStockGid(), 1); |
| | | stockListVO = StockApi.otherStockListVO(hk); |
| | | } else if (stock.getStockType().equals("us")) { |
| | | String us = RedisShardedPoolUtils.get(stock.getStockGid(), 2); |
| | | stockListVO = StockApi.otherStockListVO(us); |
| | | } else { |
| | | stockListVO = StockApi.getStockRealTime( |
| | | stock); |
| | | } |
| | | String nowPrice = stockListVO.getNowPrice(); |
| | | if (nowPrice == null) { |
| | | nowPrice = String.valueOf(0); |
| | | } |
| | | userPendingorderVO.setNowPrice(new BigDecimal(nowPrice)); |
| | | userPendingorderVO.setStockName(stock.getStockName()); |
| | | userPendingorderVO.setStockId(stock.getStockCode()); |
| | | } |
| | | userPendingorderVO.setBuyNum(userPendingorder.getBuyNum()); |
| | | userPendingorderVO.setBuyType(userPendingorder.getBuyType()); |
| | | userPendingorderVO.setLever(userPendingorder.getLever()); |
| | | userPendingorderVO.setProfitTarget(userPendingorder.getProfitTarget()); |
| | | userPendingorderVO.setStopTarget(userPendingorder.getStopTarget()); |
| | | userPendingorderVO.setTargetPrice(userPendingorder.getTargetPrice()); |
| | | userPendingorderVO.setAddTime(userPendingorder.getAddTime()); |
| | | userPendingorderVO.setStatus(userPendingorder.getStatus()); |
| | | userPendingorderVO.setId(userPendingorder.getId()); |
| | | UserPendingorderList.add(userPendingorderVO); |
| | | } |
| | | PageInfo pageInfo = new PageInfo(stockSubscribeList); |
| | | pageInfo.setList(UserPendingorderList); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse updateOrderByAdmin(UserPendingorder userPendingorder) { |
| | | if (userPendingorder.getId() == null) { |
| | | return ServerResponse.createByErrorMsg("id不能为空"); |
| | | } |
| | | int updateCount = this.userPendingorderMapper.updateById(userPendingorder); |
| | | if (updateCount > 0) { |
| | | return ServerResponse.createBySuccessMsg("修改成功"); |
| | | } |
| | | return ServerResponse.createByErrorMsg("修改失败"); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse addOrderByAdmin(String phone, String buyNum, String code, String buyType, String lever, String targetPrice, HttpServletRequest request) { |
| | | if (StringUtils.isBlank(phone) || StringUtils.isBlank(buyNum) || StringUtils.isBlank(buyType) || StringUtils.isBlank(lever) || StringUtils.isBlank(targetPrice)) { |
| | | return ServerResponse.createByErrorMsg("参数不能为空"); |
| | | } |
| | | |
| | | User user = this.userMapper.selectOne(new QueryWrapper<User>().eq("phone", phone)); |
| | | if (user == null) { |
| | | return ServerResponse.createByErrorMsg("用户不存在"); |
| | | } |
| | | Stock stock = stockMapper.findStockByCode(code); |
| | | if (stock == null) { |
| | | return ServerResponse.createByErrorMsg("股票不存在"); |
| | | } |
| | | UserPendingorder userPendingorder = new UserPendingorder(); |
| | | userPendingorder.setUserId(user.getId()); |
| | | userPendingorder.setStockId(code); |
| | | userPendingorder.setBuyNum(Integer.valueOf(buyNum)); |
| | | userPendingorder.setBuyType(Integer.valueOf(buyType)); |
| | | userPendingorder.setLever(Integer.valueOf(lever)); |
| | | userPendingorder.setTargetPrice(new BigDecimal(targetPrice)); |
| | | userPendingorder.setAddTime(new Date()); |
| | | userPendingorder.setStatus(0); |
| | | userPendingorder.setNowPrice(new BigDecimal(0)); |
| | | int insert = this.userPendingorderMapper.insert(userPendingorder); |
| | | if (insert > 0) { |
| | | return ServerResponse.createBySuccessMsg("添加成功"); |
| | | } |
| | | return ServerResponse.createByErrorMsg("添加失败"); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse delOrderByAdmin(Integer id) { |
| | | if (id == null) { |
| | | return ServerResponse.createByErrorMsg("id不能为空"); |
| | | } |
| | | int delete = this.userPendingorderMapper.deleteById(id); |
| | | if (delete > 0) { |
| | | return ServerResponse.createBySuccessMsg("删除成功"); |
| | | } |
| | | return ServerResponse.createByErrorMsg("删除失败"); |
| | | } |
| | | } |
| | | |
| | | |