| | |
| | | package com.nq.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.google.gson.Gson; |
| | | import com.nq.dao.*; |
| | | import com.nq.pojo.*; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.sql.Timestamp; |
| | | import java.time.LocalDate; |
| | | import java.time.YearMonth; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | } |
| | | |
| | | |
| | | public ServerResponse fee(Integer buyNum,BigDecimal nowPrice){ |
| | | BigDecimal buy_amt = nowPrice.multiply(new BigDecimal(buyNum.intValue())); |
| | | SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting(); |
| | | BigDecimal buy_fee_amt = buy_amt.multiply(siteSetting.getBuyFee()).setScale(2, 4); |
| | | return ServerResponse.createBySuccess(buy_fee_amt); |
| | | } |
| | | @Transactional |
| | | public ServerResponse pending(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); |
| | | /*实名认证开关开启*/ |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | |
| | | if (siteProduct.getRealNameDisplay() && (StringUtils.isBlank(user.getRealName()) || StringUtils.isBlank(user.getIdCard()))) { |
| | | return ServerResponse.createByErrorMsg("挂单失败,请先实名认证"); |
| | | } |
| | | BigDecimal user_enable_amt = user.getEnableAmt(); |
| | | BigDecimal user_enable_withdraw_amt = user.getEnaleWithdrawAmt(); |
| | | log.info("用户 {} 下单,股票id = {} ,数量 = {} , 方向 = {} , 杠杆 = {}", new Object[]{user |
| | | .getId(), stockId, buyNum, buyType, lever}); |
| | | if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) { |
| | | return ServerResponse.createByErrorMsg("挂单失败,账户已被锁定"); |
| | | } |
| | | |
| | | SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting(); |
| | | if (siteSetting == null) { |
| | | log.error("下单出错,网站设置表不存在"); |
| | | return ServerResponse.createByErrorMsg("挂单失败,系统设置错误"); |
| | | } |
| | | Stock stock = null; |
| | | ServerResponse stock_res = this.iStockService.findStockById(stockId); |
| | | if (!stock_res.isSuccess()) { |
| | | return ServerResponse.createByErrorMsg("挂单失败,股票代码错误"); |
| | | } |
| | | stock = (Stock) stock_res.getData(); |
| | | log.info("--------------购买逻辑股票数据 buy stock------" + new Gson().toJson(stock)); |
| | | |
| | | 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); |
| | | log.info("是否在上午交易时间 = {} 是否在下午交易时间 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag)); |
| | | //TODO |
| | | // if (!siteProduct.getTranWithdrawDisplay()) { |
| | | // return ServerResponse.createByErrorMsg("当前交易关闭"); |
| | | // } |
| | | if (!am_flag && !pm_flag && siteProduct.getTranWithdrawDisplay()) { |
| | | return ServerResponse.createByErrorMsg("挂单失败,不在交易时段内"); |
| | | } |
| | | if (siteProduct.getHolidayDisplay() && siteProduct.getTranWithdrawDisplay()) { |
| | | return ServerResponse.createByErrorMsg("周末或节假日不能交易!"); |
| | | } |
| | | |
| | | |
| | | if (stock.getIsLock().intValue() != 0) { |
| | | return ServerResponse.createByErrorMsg("挂单失败,当前股票不能交易"); |
| | | } |
| | | |
| | | List dbPosition = findPositionByStockCodeAndTimes(siteSetting.getBuySameTimes().intValue(), stock |
| | | .getStockCode(), user.getId()); |
| | | if (dbPosition.size() >= siteSetting.getBuySameNums().intValue() && siteProduct.getTranWithdrawDisplay()) { |
| | | return ServerResponse.createByErrorMsg("频繁交易," + siteSetting.getBuySameTimes() + "分钟内同一股票持仓不得超过" + siteSetting |
| | | .getBuySameNums() + "条"); |
| | | } |
| | | |
| | | |
| | | if (buyNum.intValue() < siteSetting.getBuyMinNum().intValue()) { |
| | | return ServerResponse.createByErrorMsg("挂单失败,购买数量小于" + siteSetting |
| | | .getBuyMinNum() + "股"); |
| | | } |
| | | if (buyNum.intValue() > siteSetting.getBuyMaxNum().intValue()) { |
| | | return ServerResponse.createByErrorMsg("挂单失败,购买数量大于" + siteSetting |
| | | .getBuyMaxNum() + "股"); |
| | | } |
| | | BigDecimal now_price; |
| | | StockListVO stockListVO = new StockListVO(); |
| | | //股票类型 现价 数据源的处理 |
| | | stockListVO = SinaStockApi.assembleLideStockListVO(LiDeDataUtils.getStock(stock.getStockCode())); |
| | | if (ObjectUtils.isEmpty(stockListVO)) { |
| | | stockListVO = SinaStockApi.assembleStockListVO(SinaStockApi.getSinaStock(stock.getStockGid())); |
| | | } |
| | | now_price = new BigDecimal(stockListVO.getNowPrice()); |
| | | if (now_price.compareTo(new BigDecimal("0")) == 0) { |
| | | return ServerResponse.createByErrorMsg("报价0,请稍后再试"); |
| | | } |
| | | double stock_crease = stockListVO.getHcrate().doubleValue(); |
| | | BigDecimal maxRisePercent = new BigDecimal("0"); |
| | | if (stock.getStockPlate() != null) { |
| | | |
| | | maxRisePercent = new BigDecimal("0.2"); |
| | | log.info("【科创股票】"); |
| | | } else { |
| | | maxRisePercent = new BigDecimal("0.1"); |
| | | log.info("【普通A股】"); |
| | | } |
| | | |
| | | // if (stockListVO.getName().startsWith("ST") || stockListVO.getName().endsWith("退")) { |
| | | // return ServerResponse.createByErrorMsg("ST和已退市的股票不能入仓"); |
| | | // } |
| | | |
| | | BigDecimal zsPrice = new BigDecimal(stockListVO.getPreclose_px()); |
| | | |
| | | BigDecimal ztPrice = zsPrice.multiply(maxRisePercent).add(zsPrice); |
| | | ztPrice = ztPrice.setScale(2, 4); |
| | | BigDecimal chaPrice = ztPrice.subtract(zsPrice); |
| | | |
| | | BigDecimal ztRate = chaPrice.multiply(new BigDecimal("100")).divide(zsPrice, 2, 4); |
| | | |
| | | // log.info("当前涨跌幅 = {} % , 涨停幅度 = {} %", Double.valueOf(stock_crease), ztRate); |
| | | // if ((new BigDecimal(String.valueOf(stock_crease))).compareTo(ztRate) == 0 && buyType |
| | | // .intValue() == 0 && siteProduct.getTranWithdrawDisplay()) { |
| | | // return ServerResponse.createByErrorMsg("当前股票已涨停不能买涨"); |
| | | // } |
| | | // if (stock.getStockPlate() == null || StringUtils.isEmpty(stock.getStockPlate())) { |
| | | // |
| | | // int maxcrease = siteSetting.getCreaseMaxPercent().intValue(); |
| | | // if (stock_crease > 0.0D && |
| | | // stock_crease >= maxcrease && siteProduct.getTranWithdrawDisplay()) { |
| | | // return ServerResponse.createByErrorMsg("挂单失败,股票当前涨幅:" + stock_crease + ",大于最大涨幅:" + maxcrease); |
| | | // } |
| | | // |
| | | // |
| | | // if (stock_crease < 0.0D && |
| | | // -stock_crease > maxcrease && siteProduct.getTranWithdrawDisplay()) { |
| | | // return ServerResponse.createByErrorMsg("挂单失败,股票当前跌幅:" + stock_crease + ",大于最大跌幅:" + maxcrease); |
| | | // |
| | | // } |
| | | // |
| | | // } else if ("创业".equals(stock.getStockPlate())) { |
| | | // |
| | | // int maxcrease = siteSetting.getCyCreaseMaxPercent().intValue(); |
| | | // if (stock_crease > 0.0D && |
| | | // stock_crease >= maxcrease && siteProduct.getTranWithdrawDisplay()) { |
| | | // return ServerResponse.createByErrorMsg("挂单失败,创业股当前涨幅:" + stock_crease + ",大于最大涨幅:" + maxcrease); |
| | | // } |
| | | // |
| | | // |
| | | // if (stock_crease < 0.0D && |
| | | // -stock_crease > maxcrease && siteProduct.getTranWithdrawDisplay()) { |
| | | // return ServerResponse.createByErrorMsg("挂单失败,创业股当前跌幅:" + stock_crease + ",大于最大跌幅:" + maxcrease); |
| | | // } |
| | | // } else { |
| | | // |
| | | // int maxcrease = siteSetting.getKcCreaseMaxPercent().intValue(); |
| | | // if (stock_crease > 0.0D && |
| | | // stock_crease >= maxcrease && siteProduct.getTranWithdrawDisplay()) { |
| | | // return ServerResponse.createByErrorMsg("挂单失败,科创股当前涨幅:" + stock_crease + ",大于最大涨幅:" + maxcrease); |
| | | // } |
| | | // |
| | | // |
| | | // if (stock_crease < 0.0D && |
| | | // -stock_crease > maxcrease && siteProduct.getTranWithdrawDisplay()) { |
| | | // return ServerResponse.createByErrorMsg("挂单失败,科创股当前跌幅:" + stock_crease + ",大于最大跌幅:" + maxcrease); |
| | | // } |
| | | // } |
| | | ServerResponse serverResponse = this.iStockService.selectRateByDaysAndStockCode(stock |
| | | .getStockCode(), siteSetting.getStockDays().intValue()); |
| | | if (!serverResponse.isSuccess()) { |
| | | return serverResponse; |
| | | } |
| | | BigDecimal daysRate = (BigDecimal) serverResponse.getData(); |
| | | // log.info("股票 {} , {} 天内 涨幅 {} , 设置的涨幅 = {}", new Object[]{stock.getStockCode(), siteSetting |
| | | // .getStockDays(), daysRate, siteSetting.getStockRate()}); |
| | | // |
| | | // if (daysRate != null && |
| | | // siteSetting.getStockRate().compareTo(daysRate) == -1 && siteProduct.getTranWithdrawDisplay()) { |
| | | // return serverResponse.createByErrorMsg(siteSetting.getStockDays() + "天内涨幅超过 " + siteSetting |
| | | // .getStockRate() + "不能交易"); |
| | | // } |
| | | |
| | | BigDecimal buy_amt = now_price.multiply(new BigDecimal(buyNum.intValue())); |
| | | |
| | | BigDecimal buy_amt_autual = buy_amt.divide(new BigDecimal(lever.intValue()), 2, 4); |
| | | |
| | | |
| | | int compareInt = buy_amt_autual.compareTo(new BigDecimal(siteSetting.getBuyMinAmt().intValue())); |
| | | if (compareInt == -1) { |
| | | return ServerResponse.createByErrorMsg("挂单失败,购买金额小于" + siteSetting |
| | | .getBuyMinAmt() + "元"); |
| | | } |
| | | |
| | | BigDecimal max_buy_amt = user_enable_amt.multiply(siteSetting.getBuyMaxAmtPercent()); |
| | | int compareCwInt = buy_amt_autual.compareTo(max_buy_amt); |
| | | if (compareCwInt == 1) { |
| | | return ServerResponse.createByErrorMsg("挂单失败,不能超过可用资金的" + siteSetting |
| | | .getBuyMaxAmtPercent().multiply(new BigDecimal("100")) + "%"); |
| | | } |
| | | |
| | | int compareUserAmtInt = user_enable_amt.compareTo(buy_amt_autual); |
| | | log.info("用户可用金额 = {} 实际购买金额 = {}", user_enable_amt, buy_amt_autual); |
| | | log.info("比较 用户金额 和 实际 购买金额 = {}", Integer.valueOf(compareUserAmtInt)); |
| | | if (compareUserAmtInt == -1) { |
| | | return ServerResponse.createByErrorMsg("挂单失败,融资可用金额小于" + buy_amt_autual + "元"); |
| | | } |
| | | if (user.getUserIndexAmt().compareTo(new BigDecimal("0")) == -1) { |
| | | return ServerResponse.createByErrorMsg("失败,指数总资金小于0"); |
| | | } |
| | | UserPosition userPosition = new UserPosition(); |
| | | //挂单 |
| | | userPosition.setStatus(0); |
| | | if (profitTarget != null && profitTarget.compareTo(new BigDecimal("0")) > 0) { |
| | | userPosition.setProfitTargetPrice(profitTarget); |
| | | } |
| | | if (stopTarget != null && stopTarget.compareTo(new BigDecimal("0")) > 0) { |
| | | userPosition.setStopTargetPrice(stopTarget); |
| | | } |
| | | userPosition.setPositionType(user.getAccountType()); |
| | | userPosition.setPositionSn(KeyUtils.getUniqueKey()); |
| | | userPosition.setUserId(user.getId()); |
| | | userPosition.setNickName(user.getRealName()); |
| | | userPosition.setAgentId(user.getAgentId()); |
| | | userPosition.setStockCode(stock.getStockCode()); |
| | | userPosition.setStockName(stock.getStockName()); |
| | | userPosition.setStockGid(stock.getStockGid()); |
| | | userPosition.setStockSpell(stock.getStockSpell()); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(now_price); |
| | | userPosition.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌"); |
| | | userPosition.setOrderNum(buyNum); |
| | | if (stock.getStockPlate() != null) { |
| | | userPosition.setStockPlate(stock.getStockPlate()); |
| | | } |
| | | userPosition.setIsLock(Integer.valueOf(0)); |
| | | userPosition.setOrderLever(lever); |
| | | userPosition.setOrderTotalPrice(buy_amt); |
| | | //递延费特殊处理 |
| | | BigDecimal stayFee = userPosition.getOrderTotalPrice().multiply(siteSetting.getStayFee()); |
| | | BigDecimal allStayFee = stayFee.multiply(new BigDecimal(1)); |
| | | userPosition.setOrderStayFee(allStayFee); |
| | | userPosition.setOrderStayDays(1); |
| | | BigDecimal buy_fee_amt = buy_amt.multiply(siteSetting.getBuyFee()).setScale(2, 4); |
| | | log.info("用户购买手续费(配资后总资金 * 百分比) = {}", buy_fee_amt); |
| | | userPosition.setOrderFee(buy_fee_amt); |
| | | BigDecimal buy_yhs_amt = buy_amt.multiply(siteSetting.getDutyFee()).setScale(2, 4); |
| | | log.info("用户购买印花税(配资后总资金 * 百分比) = {}", buy_yhs_amt); |
| | | userPosition.setOrderSpread(buy_yhs_amt); |
| | | SiteSpread siteSpread = iSiteSpreadService.findSpreadRateOne(new BigDecimal(stock_crease), buy_amt, stock.getStockCode(), now_price); |
| | | BigDecimal spread_rate_amt = new BigDecimal("0"); |
| | | if (siteSpread != null) { |
| | | spread_rate_amt = buy_amt.multiply(siteSpread.getSpreadRate()).setScale(2, 4); |
| | | log.info("用户购买点差费(配资后总资金 * 百分比{}) = {}", siteSpread.getSpreadRate(), spread_rate_amt); |
| | | } else { |
| | | log.info("用户购买点差费(配资后总资金 * 百分比{}) = {}", "设置异常", spread_rate_amt); |
| | | } |
| | | userPosition.setSpreadRatePrice(spread_rate_amt); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPosition.setProfitAndLose(profit_and_lose); |
| | | BigDecimal all_profit_and_lose = profit_and_lose.subtract(buy_fee_amt).subtract(buy_yhs_amt).subtract(spread_rate_amt); |
| | | userPosition.setAllProfitAndLose(all_profit_and_lose); |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(new BigDecimal("0")); |
| | | int insertPositionCount = 0; |
| | | this.userPositionMapper.insert(userPosition); |
| | | insertPositionCount = userPosition.getId(); |
| | | if (insertPositionCount > 0) { |
| | | //修改用户可用余额= 当前余额-下单金额-买入手续费-印花税-点差费 |
| | | //BigDecimal reckon_enable = user_enable_amt.subtract(buy_amt_autual).subtract(buy_fee_amt).subtract(buy_yhs_amt).subtract(spread_rate_amt); |
| | | //修改用户可用余额= 当前余额-下单总金额 |
| | | BigDecimal reckon_enable = user_enable_amt.subtract(buy_amt_autual); |
| | | //修改用户可取余额=当前可取余额-下单总金额 |
| | | int compareUserWithdrawAmtInt = user_enable_withdraw_amt.compareTo(buy_amt_autual); |
| | | if (compareUserWithdrawAmtInt == -1) { |
| | | //若可取余额小于下单总额,但是可用余额充足,令可取余额为0 |
| | | user.setEnaleWithdrawAmt(BigDecimal.ZERO); |
| | | } else { |
| | | user_enable_withdraw_amt = user_enable_withdraw_amt.subtract(buy_amt_autual); |
| | | user.setEnaleWithdrawAmt(user_enable_withdraw_amt); |
| | | } |
| | | user.setEnableAmt(reckon_enable); |
| | | // user.setDjzj(user.getDjzj().subtract(buy_amt_autual)); |
| | | int updateUserCount = this.userMapper.updateByPrimaryKeySelective(user); |
| | | if (updateUserCount > 0) { |
| | | log.info("【用户交易下单】修改用户金额成功"); |
| | | } else { |
| | | log.error("用户交易下单】修改用户金额出错"); |
| | | throw new Exception("用户交易下单】修改用户金额出错"); |
| | | } |
| | | //核算代理收入-入仓手续费 |
| | | // iAgentAgencyFeeService.AgencyFeeIncome(1, userPosition.getPositionSn()); |
| | | log.info("【用户交易下单】保存持仓记录成功"); |
| | | } else { |
| | | log.error("用户交易下单】保存持仓记录出错"); |
| | | throw new Exception("用户交易下单】保存持仓记录出错"); |
| | | } |
| | | return ServerResponse.createBySuccess("挂单成功"); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 用户修改止盈止损 |
| | | */ |
| | |
| | | log.error("平倉出錯,網站設置表不存在"); |
| | | return ServerResponse.createByErrorMsg("下单失败,系统设置错误"); |
| | | } |
| | | |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | |
| | | UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn); |
| | | if (doType != 0) { |
| | | if (userPosition.getStockGid().contains("us")) { |
| | |
| | | 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) { |
| | | |
| | | if (!am_flag && !pm_flag && siteProduct.getTranWithdrawDisplay()) { |
| | | return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内"); |
| | | } |
| | | } |
| | | if (siteProduct.getHolidayDisplay()) { |
| | | if (siteProduct.getHolidayDisplay() && siteProduct.getTranWithdrawDisplay()) { |
| | | return ServerResponse.createByErrorMsg("周末或节假日不能交易!"); |
| | | } |
| | | |
| | |
| | | return ServerResponse.createByErrorMsg("平仓失败,此订单已平仓"); |
| | | } |
| | | |
| | | if (1 == userPosition.getIsLock().intValue()) { |
| | | return ServerResponse.createByErrorMsg("平仓失败 " + userPosition.getLockMsg()); |
| | | } |
| | | |
| | | if (!DateTimeUtil.isCanSell(userPosition.getBuyOrderTime(), siteSetting.getCantSellTimes().intValue())) { |
| | | if (DateTimeUtil.isCanSellOneday(userPosition.getBuyOrderTime(), siteSetting.getCantSellTimes().intValue()) && siteProduct.getTranWithdrawDisplay()) { |
| | | // return ServerResponse.createByErrorMsg(siteSetting.getCantSellTimes() + "分鐘內不能平倉"); |
| | | |
| | | return ServerResponse.createByErrorMsg("当日成交不可平仓"); |
| | | } |
| | | |
| | | if (1 == userPosition.getIsLock().intValue()) { |
| | | if (DateTimeUtil.isCanSellOneday(userPosition.getBuyOrderTime(), userPosition.getLockDays())) { |
| | | return ServerResponse.createByErrorMsg("平仓失败 " + userPosition.getLockMsg()); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // if (DateTimeUtil.sameDate(DateTimeUtil.getCurrentDate(),userPosition.getBuyOrderTime())) { |
| | | // return ServerResponse.createByErrorMsg("當天入倉的股票需要隔天才能出倉"); |
| | | // return ServerResponse.createByErrorMsg("当天入仓的股票需要隔天才能出仓"); |
| | | // } |
| | | BigDecimal now_price; |
| | | StockListVO stockListVO = new StockListVO(); |
| | |
| | | |
| | | BigDecimal all_profit = profitLoss.subtract(all_fee_amt); |
| | | userPosition.setAllProfitAndLose(all_profit); |
| | | userPosition.setStatus(2); |
| | | |
| | | int updatePositionCount = this.userPositionMapper.updateByPrimaryKeySelective(userPosition); |
| | | if (updatePositionCount > 0) { |
| | |
| | | |
| | | return ServerResponse.createBySuccessMsg("平仓成功!"); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse calendar(String yearMonth,HttpServletRequest request) throws Exception { |
| | | |
| | | // 获取指定月份的所有日期 |
| | | List<String> allDays = MarketUtils.getAllDaysInMonth(yearMonth); |
| | | |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | |
| | | List<Map<String, String>> dailyProfitMap = userPositionMapper.getDailyProfitByMonth(yearMonth, user.getId()); |
| | | List<DailyRecord> dailyProfits = new ArrayList<>(); |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | for (String day : allDays) { |
| | | if(null == dailyProfitMap){ |
| | | LocalDate date = LocalDate.parse(day, formatter); |
| | | dailyProfits.add(new DailyRecord(day, BigDecimal.ZERO, MarketUtils.isMarketClosed(date))); |
| | | }else { |
| | | BigDecimal profit = BigDecimal.ZERO; |
| | | for (Map<String, String> record : dailyProfitMap) { |
| | | if(record.get("recordDate").equals(day)){ |
| | | profit = new BigDecimal(record.get("profit")); |
| | | } |
| | | } |
| | | LocalDate date = LocalDate.parse(day, formatter); |
| | | dailyProfits.add(new DailyRecord(day, profit, MarketUtils.isMarketClosed(date))); |
| | | } |
| | | } |
| | | return ServerResponse.createBySuccess(dailyProfits); |
| | | } |
| | | |
| | | |
| | | |
| | | public ServerResponse sellbf(String positionSn, Integer quantity) throws Exception { |
| | | log.info("【用戶交易部分平倉】 positionSn = {} , dotype = {}", positionSn, Integer.valueOf(quantity)); |
| | |
| | | |
| | | BigDecimal all_profit = profitLoss.subtract(all_fee_amt); |
| | | userPositionNew.setAllProfitAndLose(all_profit); |
| | | userPositionNew.setStatus(2); |
| | | userPositionMapper.insert(userPositionNew); |
| | | //修改原订单 |
| | | userPosition.setOrderNum(userPosition.getOrderNum() - userPositionNew.getOrderNum()); |
| | |
| | | } |
| | | |
| | | |
| | | public ServerResponse lock(Integer positionId, Integer state, String lockMsg) { |
| | | public ServerResponse lock(Integer positionId, Integer state, String lockMsg,Integer lockDays) { |
| | | if (positionId == null || state == null) { |
| | | return ServerResponse.createByErrorMsg("参数不能为空"); |
| | | } |
| | |
| | | if (state.intValue() == 1) { |
| | | position.setIsLock(Integer.valueOf(1)); |
| | | position.setLockMsg(lockMsg); |
| | | position.setLockDays(lockDays); |
| | | } else { |
| | | position.setIsLock(Integer.valueOf(0)); |
| | | } |
| | |
| | | return ServerResponse.createBySuccess(agentIncomeVO); |
| | | } |
| | | |
| | | |
| | | public ServerResponse listByAdmin(Integer agentId, Integer positionType, Integer state, Integer userId, String positionSn, String beginTime, String endTime, int pageNum, int pageSize) { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | |
| | |
| | | pageInfo.setList(adminPositionVOS); |
| | | |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse transferPositions(String positionId) { |
| | | if(StringUtils.isBlank(positionId)){ |
| | | return ServerResponse.createByErrorMsg("参数错误"); |
| | | } |
| | | List<String> positionIds = Arrays.asList(positionId.split(",")); |
| | | UpdateWrapper<UserPosition> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.in("id", positionIds); |
| | | updateWrapper.eq("status", 0); |
| | | updateWrapper.set("status", 1); |
| | | int updateCount = userPositionMapper.update(null, updateWrapper); |
| | | if (updateCount > 0) { |
| | | return ServerResponse.createBySuccessMsg("转持仓成功"); |
| | | } else { |
| | | return ServerResponse.createByErrorMsg("转持仓失败"); |
| | | } |
| | | } |
| | | |
| | | public int CountPositionNum(Integer state, Integer accountType) { |
| | |
| | | userPositionVO.setOrderStayFee(position.getOrderStayFee()); |
| | | userPositionVO.setOrderStayDays(position.getOrderStayDays()); |
| | | userPositionVO.setMarginAdd(position.getMarginAdd()); |
| | | userPositionVO.setStatus(position.getStatus()); |
| | | |
| | | userPositionVO.setStockPlate(position.getStockPlate()); |
| | | userPositionVO.setSpreadRatePrice(position.getSpreadRatePrice()); |
| | |
| | | pageInfo.setList(userPositionVOS); |
| | | |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse findPositionBySn(String positionSn) { |
| | | UserPosition userPosition = userPositionMapper.findPositionBySn(positionSn); |
| | | UserPositionVO userPositionVO = assembleUserPositionVO(userPosition); |
| | | return ServerResponse.createBySuccess(userPositionVO); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse stockDzDisplay(HttpServletRequest request) { |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | return ServerResponse.createBySuccess(siteProduct.getStockDzDisplay()); |
| | | } |
| | | |
| | | /** |
| | | * 大宗下單 |
| | | * |
| | |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | if (siteProduct.getRealNameDisplay() && (StringUtils.isBlank(user.getRealName()) || StringUtils.isBlank(user.getIdCard()))) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,請先實名認證"); |
| | | return ServerResponse.createByErrorMsg("下单失败,请先实名认证"); |
| | | } |
| | | BigDecimal user_enable_amt = user.getEnableAmt(); |
| | | BigDecimal user_enable_withdraw_amt = user.getEnaleWithdrawAmt(); |
| | | log.info("用戶 {} 下單,股票code = {} ,數量 = {}", new Object[]{user |
| | | .getId(), stockCode, num}); |
| | | if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,賬戶已被鎖定"); |
| | | return ServerResponse.createByErrorMsg("下单失败,账户已被锁定"); |
| | | } |
| | | |
| | | SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting(); |
| | | if (siteSetting == null) { |
| | | log.error("下單出錯,網站設置表不存在"); |
| | | return ServerResponse.createByErrorMsg("下單失敗,系統設置錯誤"); |
| | | return ServerResponse.createByErrorMsg("下单失败,系统设置错误"); |
| | | } |
| | | StockDz stockDz = null; |
| | | stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("stock_code", stockCode)); |
| | |
| | | boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end); |
| | | boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end); |
| | | log.info("是否在大宗交易時間 = {}", Boolean.valueOf(pm_flag)); |
| | | //TODO |
| | | //15-15:30 |
| | | // if (!pm_flag) { |
| | | // return ServerResponse.createByErrorMsg("下單失敗,不在交易時段內"); |
| | | // } |
| | | if (siteProduct.getHolidayDisplay()) { |
| | | return ServerResponse.createByErrorMsg("周末或節假日不能交易!"); |
| | | return ServerResponse.createByErrorMsg("周末或节假日不能交易!"); |
| | | } |
| | | if (!Objects.equals(stockDz.getPassword(), password)) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,密鑰錯誤"); |
| | | } |
| | | // if (!Objects.equals(stockDz.getPassword(), password)) { |
| | | // return ServerResponse.createByErrorMsg("下单失败,密钥错误"); |
| | | // } |
| | | |
| | | if (stockDz.getIsLock().intValue() != 0) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,當前股票不能交易"); |
| | | return ServerResponse.createByErrorMsg("下单失败,当前股票不能交易"); |
| | | } |
| | | |
| | | List dbPosition = findPositionByStockCodeAndTimes(siteSetting.getBuySameTimes().intValue(), stockDz.getStockCode(), user.getId()); |
| | | if (dbPosition.size() >= siteSetting.getBuySameNums().intValue()) { |
| | | return ServerResponse.createByErrorMsg("頻繁交易," + siteSetting.getBuySameTimes() + "分鐘內同一股票持倉不得超過" + siteSetting |
| | | .getBuySameNums() + "條"); |
| | | } |
| | | // List dbPosition = findPositionByStockCodeAndTimes(siteSetting.getBuySameTimes().intValue(), stockDz.getStockCode(), user.getId()); |
| | | // if (dbPosition.size() >= siteSetting.getBuySameNums().intValue()) { |
| | | // return ServerResponse.createByErrorMsg("频繁交易," + siteSetting.getBuySameTimes() + "分钟内同一股票持仓不得超过" + siteSetting |
| | | // .getBuySameNums() + "条"); |
| | | // } |
| | | |
| | | Integer transNum = findPositionNumByTimes(siteSetting.getBuyNumTimes().intValue(), user.getId()); |
| | | if (transNum.intValue() / 100 >= siteSetting.getBuyNumLots().intValue()) { |
| | | return ServerResponse.createByErrorMsg("頻繁交易," + siteSetting |
| | | .getBuyNumTimes() + "分鐘內不能超過" + siteSetting.getBuyNumLots() + "手"); |
| | | } |
| | | // Integer transNum = findPositionNumByTimes(siteSetting.getBuyNumTimes().intValue(), user.getId()); |
| | | // if (transNum.intValue() / 100 >= siteSetting.getBuyNumLots().intValue()) { |
| | | // return ServerResponse.createByErrorMsg("频繁交易," + siteSetting |
| | | // .getBuyNumTimes() + "分钟内不能超过" + siteSetting.getBuyNumLots() + "手"); |
| | | // } |
| | | |
| | | if (num < stockDz.getStockNum().intValue()) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,購買數量最小為" + stockDz.getStockNum() + "股"); |
| | | return ServerResponse.createByErrorMsg("下单失败,购买数量最小为" + stockDz.getStockNum() + "股"); |
| | | } |
| | | if (num > stockDz.getStockShare().intValue()) { |
| | | return ServerResponse.createByErrorMsg("下单失败,购买数量大于" + stockDz.getStockNum() + "股"); |
| | | } |
| | | if (num > siteSetting.getBuyMaxNum()) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,購買數量大於" + siteSetting.getBuyMaxNum() + "股"); |
| | | return ServerResponse.createByErrorMsg("下单失败,购买数量大于" + siteSetting.getBuyMaxNum() + "股"); |
| | | } |
| | | BigDecimal now_price; |
| | | StockListVO stockListVO = new StockListVO(); |
| | |
| | | now_price = new BigDecimal(stockListVO.getNowPrice()).multiply(stockDz.getDiscount()); |
| | | |
| | | if (now_price.compareTo(new BigDecimal("0")) == 0) { |
| | | return ServerResponse.createByErrorMsg("報價0,請稍後再試"); |
| | | return ServerResponse.createByErrorMsg("报价0,请稍后再试"); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | if (stockListVO.getName().startsWith("ST") || stockListVO.getName().endsWith("退")) { |
| | | return ServerResponse.createByErrorMsg("ST和已退市的股票不能入倉"); |
| | | return ServerResponse.createByErrorMsg("ST和已退市的股票不能入仓"); |
| | | } |
| | | |
| | | BigDecimal zsPrice = new BigDecimal(stockListVO.getPreclose_px()); |
| | |
| | | log.info("當前漲跌幅 = {} % , 漲停幅度 = {} %", Double.valueOf(stock_crease), ztRate); |
| | | |
| | | |
| | | if (stockDz.getStockPlate() == null || StringUtils.isEmpty(stockDz.getStockPlate())) { |
| | | |
| | | int maxcrease = siteSetting.getCreaseMaxPercent().intValue(); |
| | | if (stock_crease > 0.0D && |
| | | stock_crease >= maxcrease) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,股票當前漲幅:" + stock_crease + ",大於最大漲幅:" + maxcrease); |
| | | } |
| | | |
| | | if (stock_crease < 0.0D && |
| | | -stock_crease > maxcrease) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,股票當前跌幅:" + stock_crease + ",大於最大跌幅:" + maxcrease); |
| | | |
| | | } |
| | | |
| | | } else if ("創業".equals(stockDz.getStockPlate())) { |
| | | |
| | | int maxcrease = siteSetting.getCyCreaseMaxPercent().intValue(); |
| | | if (stock_crease > 0.0D && |
| | | stock_crease >= maxcrease) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,創業股當前漲幅:" + stock_crease + ",大於最大漲幅:" + maxcrease); |
| | | } |
| | | |
| | | if (stock_crease < 0.0D && |
| | | -stock_crease > maxcrease) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,創業股當前跌幅:" + stock_crease + ",大於最大跌幅:" + maxcrease); |
| | | } |
| | | } else { |
| | | |
| | | int maxcrease = siteSetting.getKcCreaseMaxPercent().intValue(); |
| | | if (stock_crease > 0.0D && |
| | | stock_crease >= maxcrease) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,科創股當前漲幅:" + stock_crease + ",大於最大漲幅:" + maxcrease); |
| | | } |
| | | |
| | | if (stock_crease < 0.0D && |
| | | -stock_crease > maxcrease) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,科創股當前跌幅:" + stock_crease + ",大於最大跌幅:" + maxcrease); |
| | | } |
| | | } |
| | | // if (stockDz.getStockPlate() == null || StringUtils.isEmpty(stockDz.getStockPlate())) { |
| | | // |
| | | // int maxcrease = siteSetting.getCreaseMaxPercent().intValue(); |
| | | // if (stock_crease > 0.0D && |
| | | // stock_crease >= maxcrease) { |
| | | // return ServerResponse.createByErrorMsg("下单失败,股票当前涨幅:" + stock_crease + ",大于最大涨幅:" + maxcrease); |
| | | // } |
| | | // |
| | | // if (stock_crease < 0.0D && |
| | | // -stock_crease > maxcrease) { |
| | | // return ServerResponse.createByErrorMsg("下单失败,股票当前跌幅:" + stock_crease + ",大于最大跌幅:" + maxcrease); |
| | | // |
| | | // } |
| | | // |
| | | // } else if ("创业".equals(stockDz.getStockPlate())) { |
| | | // |
| | | // int maxcrease = siteSetting.getCyCreaseMaxPercent().intValue(); |
| | | // if (stock_crease > 0.0D && |
| | | // stock_crease >= maxcrease) { |
| | | // return ServerResponse.createByErrorMsg("下单失败,创业股当前涨幅:" + stock_crease + ",大于最大涨幅:" + maxcrease); |
| | | // } |
| | | // |
| | | // if (stock_crease < 0.0D && |
| | | // -stock_crease > maxcrease) { |
| | | // return ServerResponse.createByErrorMsg("下单失败,创业股当前跌幅:" + stock_crease + ",大于最大跌幅:" + maxcrease); |
| | | // } |
| | | // } else { |
| | | // |
| | | // int maxcrease = siteSetting.getKcCreaseMaxPercent().intValue(); |
| | | // if (stock_crease > 0.0D && |
| | | // stock_crease >= maxcrease) { |
| | | // return ServerResponse.createByErrorMsg("下单失败,科创股当前涨幅:" + stock_crease + ",大于最大涨幅:" + maxcrease); |
| | | // } |
| | | // |
| | | // if (stock_crease < 0.0D && |
| | | // -stock_crease > maxcrease) { |
| | | // return ServerResponse.createByErrorMsg("下单失败,科创股当前跌幅:" + stock_crease + ",大于最大跌幅:" + maxcrease); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | ServerResponse serverResponse = this.iStockService.selectRateByDaysAndStockCode(stockDz.getStockCode(), siteSetting.getStockDays().intValue()); |
| | |
| | | log.info("股票 {} , {} 天內 漲幅 {} , 設置的漲幅 = {}", new Object[]{stockDz.getStockCode(), siteSetting |
| | | .getStockDays(), daysRate, siteSetting.getStockRate()}); |
| | | |
| | | if (daysRate != null && siteSetting.getStockRate().compareTo(daysRate) == -1) { |
| | | return serverResponse.createByErrorMsg(siteSetting.getStockDays() + "天內漲幅超過 " + siteSetting |
| | | .getStockRate() + "不能交易"); |
| | | } |
| | | // if (daysRate != null && siteSetting.getStockRate().compareTo(daysRate) == -1) { |
| | | // return serverResponse.createByErrorMsg(siteSetting.getStockDays() + "天内涨幅超过 " + siteSetting |
| | | // .getStockRate() + "不能交易"); |
| | | // } |
| | | |
| | | |
| | | //BigDecimal buy_amt = now_price.multiply(new BigDecimal(buyNum.intValue())).divide(new BigDecimal(lever.intValue())).setScale(2, 4); |
| | |
| | | |
| | | int compareInt = buy_amt_autual.compareTo(new BigDecimal(siteSetting.getBuyMinAmt().intValue())); |
| | | if (compareInt == -1) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,購買金額小於" + siteSetting |
| | | return ServerResponse.createByErrorMsg("下单失败,购买金额小于" + siteSetting |
| | | .getBuyMinAmt() + "元"); |
| | | } |
| | | |
| | |
| | | BigDecimal max_buy_amt = user_enable_amt.multiply(siteSetting.getBuyMaxAmtPercent()); |
| | | int compareCwInt = buy_amt_autual.compareTo(max_buy_amt); |
| | | if (compareCwInt == 1) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,不能超過可用資金的" + siteSetting |
| | | return ServerResponse.createByErrorMsg("下单失败,不能超过可用资金的" + siteSetting |
| | | .getBuyMaxAmtPercent().multiply(new BigDecimal("100")) + "%"); |
| | | } |
| | | |
| | |
| | | log.info("用戶可用金額 = {} 實際購買金額 = {}", user_enable_amt, buy_amt_autual); |
| | | log.info("比較 用戶金額 和 實際 購買金額 = {}", Integer.valueOf(compareUserAmtInt)); |
| | | if (compareUserAmtInt == -1) { |
| | | return ServerResponse.createByErrorMsg("下單失敗,融資可用金額小於" + buy_amt_autual + "元"); |
| | | return ServerResponse.createByErrorMsg("下单失败,融资可用金额小于" + buy_amt_autual + "元"); |
| | | } |
| | | |
| | | // if (user.getUserIndexAmt().compareTo(new BigDecimal("0")) == -1) { |
| | |
| | | // } |
| | | // |
| | | UserPosition userPosition = new UserPosition(); |
| | | userPosition.setStatus(0); |
| | | userPosition.setPositionType(3); |
| | | userPosition.setPositionSn(KeyUtils.getUniqueKey()); |
| | | userPosition.setUserId(user.getId()); |
| | |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(now_price); |
| | | userPosition.setOrderDirection("買漲"); |
| | | userPosition.setOrderDirection("买涨"); |
| | | userPosition.setOrderNum(num); |
| | | if (stockDz.getStockPlate() != null) { |
| | | userPosition.setStockPlate(stockDz.getStockPlate()); |
| | |
| | | this.userPositionMapper.insert(userPosition); |
| | | insertPositionCount = userPosition.getId(); |
| | | if (insertPositionCount > 0) { |
| | | //修改大宗剩余 |
| | | stockDz.setStockShare(stockDz.getStockShare() - num); |
| | | stockDz.setStockSurplus(stockDz.getStockSurplus() + num); |
| | | stockDzMapper.updateById(stockDz); |
| | | //修改用戶可用余額= 當前余額-下單金額-買入手續費-印花稅-點差費 |
| | | //BigDecimal reckon_enable = user_enable_amt.subtract(buy_amt_autual).subtract(buy_fee_amt).subtract(buy_yhs_amt).subtract(spread_rate_amt); |
| | | //修改用戶可用余額= 當前余額-下單總金額 |
| | |
| | | throw new Exception("用戶交易下單】保存持倉記錄出錯"); |
| | | } |
| | | |
| | | return ServerResponse.createBySuccess("大宗交易下單成功"); |
| | | return ServerResponse.createBySuccess("大宗交易下单成功"); |
| | | } |
| | | |
| | | /** |
| | | * vip抢筹 |
| | | * |
| | | * @param stockId |
| | | * @param stockCode |
| | | * @param buyNum |
| | | * @param buyType |
| | | * @param lever |