| | |
| | | package com.nq.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.google.gson.Gson; |
| | | import com.nq.dao.*; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.enums.EUserAssets; |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.*; |
| | |
| | | @Autowired |
| | | IUserAssetsServices iUserAssetsServices; |
| | | |
| | | @Autowired |
| | | TradingHourServiceImpl tradingHourService; |
| | | |
| | | @Transactional |
| | | public ServerResponse buy(Integer stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) throws Exception { |
| | | |
| | | // 判断周末不能买 |
| | | Date today = new Date(); |
| | | Calendar c = Calendar.getInstance(); |
| | | c.setTime(today); |
| | | // Date today = new Date(); |
| | | // Calendar c = Calendar.getInstance(); |
| | | // c.setTime(today); |
| | | /*实名认证开关开启*/ |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | |
| | |
| | | return ServerResponse.createByErrorMsg("Order failed, stock code error"); |
| | | } |
| | | |
| | | if (Objects.equals(stock.getStockType(), EStockType.US.getCode())) { |
| | | if (buyNum < siteSetting.getDzMinByCount()) { |
| | | return ServerResponse.createByErrorMsg("Minimum purchase for bulk commodities " + siteSetting.getDzMinByCount()); |
| | | } |
| | | |
| | | String am_begin = siteSetting.getTransAmBeginUs(); |
| | | String am_end = siteSetting.getTransAmEndUs(); |
| | | String pm_begin = siteSetting.getTransPmBeginUs(); |
| | | String pm_end = siteSetting.getTransPmEndUs(); |
| | | boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); |
| | | boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); |
| | | log.info("是否在上午交易时间 = {} 是否在下午交易时间 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag)); |
| | | if (!am_flag && !pm_flag) { |
| | | return ServerResponse.createByErrorMsg("Order failed, not in the stock trading session"); |
| | | } |
| | | } else { |
| | | String am_begin = siteSetting.getTransAmBegin(); |
| | | String am_end = siteSetting.getTransAmEnd(); |
| | | String pm_begin = siteSetting.getTransPmBegin(); |
| | | String pm_end = siteSetting.getTransPmEnd(); |
| | | boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); |
| | | boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); |
| | | if (!am_flag && !pm_flag) { |
| | | return ServerResponse.createByErrorMsg("Order failed, out of trading hours"); |
| | | } |
| | | if (siteProduct.getHolidayDisplay()) { |
| | | return ServerResponse.createByErrorMsg("No trading on weekends or holidays!"); |
| | | } |
| | | // if (Objects.equals(stock.getStockType(), EStockType.US.getCode())) { |
| | | // if (buyNum < siteSetting.getDzMinByCount()) { |
| | | // return ServerResponse.createByErrorMsg("Minimum purchase for bulk commodities " + siteSetting.getDzMinByCount()); |
| | | // } |
| | | // String am_begin = siteSetting.getTransAmBeginUs(); |
| | | // String am_end = siteSetting.getTransAmEndUs(); |
| | | // String pm_begin = siteSetting.getTransPmBeginUs(); |
| | | // String pm_end = siteSetting.getTransPmEndUs(); |
| | | // boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); |
| | | // boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); |
| | | // log.info("是否在上午交易时间 = {} 是否在下午交易时间 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag)); |
| | | // if (!am_flag && !pm_flag) { |
| | | // return ServerResponse.createByErrorMsg("Order failed, not in the stock trading session"); |
| | | // } |
| | | // } else { |
| | | // String am_begin = siteSetting.getTransAmBegin(); |
| | | // String am_end = siteSetting.getTransAmEnd(); |
| | | // String pm_begin = siteSetting.getTransPmBegin(); |
| | | // String pm_end = siteSetting.getTransPmEnd(); |
| | | // boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); |
| | | // boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); |
| | | // if (!am_flag && !pm_flag) { |
| | | // return ServerResponse.createByErrorMsg("Order failed, out of trading hours"); |
| | | // } |
| | | // if (siteProduct.getHolidayDisplay()) { |
| | | // return ServerResponse.createByErrorMsg("No trading on weekends or holidays!"); |
| | | // } |
| | | // } |
| | | //判断股票是否在可交易时间段 |
| | | Boolean b = tradingHourService.timeCheck(); |
| | | if (!b) { |
| | | return ServerResponse.createByErrorMsg("Order failed, not in the stock trading session"); |
| | | } |
| | | |
| | | |
| | |
| | | //股票类型 现价 数据源的处理 |
| | | StockListVO stockListVO = StockApi.getStockRealTime(stock); |
| | | now_price = new BigDecimal(stockListVO.getNowPrice()); |
| | | |
| | | |
| | | if (now_price.compareTo(new BigDecimal("0")) == 0) { |
| | | return ServerResponse.createByErrorMsg("Quote 0, please try again later"); |
| | |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn); |
| | | if (doType != 0) { |
| | | if (userPosition.getStockGid().contains(EStockType.US.getCode())) { |
| | | String am_begin = siteSetting.getTransAmBeginUs(); |
| | | String am_end = siteSetting.getTransAmEndUs(); |
| | | String pm_begin = siteSetting.getTransPmBeginUs(); |
| | | String pm_end = siteSetting.getTransPmEndUs(); |
| | | boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); |
| | | boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); |
| | | if (!am_flag && !pm_flag) { |
| | | return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内"); |
| | | } |
| | | } else { |
| | | String am_begin = siteSetting.getTransAmBegin(); |
| | | String am_end = siteSetting.getTransAmEnd(); |
| | | String pm_begin = siteSetting.getTransPmBegin(); |
| | | String pm_end = siteSetting.getTransPmEnd(); |
| | | boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); |
| | | boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); |
| | | if (!am_flag && !pm_flag) { |
| | | return ServerResponse.createByErrorMsg("Order failed,Out of trading hours"); |
| | | } |
| | | } |
| | | if (siteProduct.getHolidayDisplay()) { |
| | | return ServerResponse.createByErrorMsg("No trading on weekends or holidays!"); |
| | | // if (userPosition.getStockGid().contains(EStockType.US.getCode())) { |
| | | // String am_begin = siteSetting.getTransAmBeginUs(); |
| | | // String am_end = siteSetting.getTransAmEndUs(); |
| | | // String pm_begin = siteSetting.getTransPmBeginUs(); |
| | | // String pm_end = siteSetting.getTransPmEndUs(); |
| | | // boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); |
| | | // boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); |
| | | // if (!am_flag && !pm_flag) { |
| | | // return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内"); |
| | | // } |
| | | // } else { |
| | | // String am_begin = siteSetting.getTransAmBegin(); |
| | | // String am_end = siteSetting.getTransAmEnd(); |
| | | // String pm_begin = siteSetting.getTransPmBegin(); |
| | | // String pm_end = siteSetting.getTransPmEnd(); |
| | | // boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); |
| | | // boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); |
| | | // if (!am_flag && !pm_flag) { |
| | | // return ServerResponse.createByErrorMsg("Order failed,Out of trading hours"); |
| | | // } |
| | | // } |
| | | // if (siteProduct.getHolidayDisplay()) { |
| | | // return ServerResponse.createByErrorMsg("No trading on weekends or holidays!"); |
| | | // } |
| | | //判断股票是否在可交易时间段 |
| | | Boolean b = tradingHourService.timeCheck(); |
| | | if (!b) { |
| | | return ServerResponse.createByErrorMsg("Order failed, not in the stock trading session"); |
| | | } |
| | | |
| | | } |
| | |
| | | @Transactional |
| | | @Override |
| | | public ServerResponse allSell(HttpServletRequest request,String stockType) throws Exception{ |
| | | //判断股票是否在可交易时间段 |
| | | Boolean b = tradingHourService.timeCheck(); |
| | | if (!b) { |
| | | return ServerResponse.createByErrorMsg("Order failed, not in the stock trading session"); |
| | | } |
| | | User user = iUserService.getCurrentUser(request); |
| | | if(user == null){ |
| | | return ServerResponse.createByErrorMsg("Please login"); |