| | |
| | | import com.yami.trading.bean.dz.ExchangeApplyOrderDz; |
| | | import com.yami.trading.bean.dz.StockDz; |
| | | import com.yami.trading.bean.dz.dto.ExchangeApplyOrderDzDto; |
| | | import com.yami.trading.bean.dz.dto.StockDzDto; |
| | | import com.yami.trading.bean.exchange.ExchangeApplyOrder; |
| | | import com.yami.trading.bean.item.domain.Item; |
| | | import com.yami.trading.bean.model.MoneyLog; |
| | |
| | | import com.yami.trading.common.domain.Result; |
| | | import com.yami.trading.common.exception.YamiShopBindException; |
| | | import com.yami.trading.common.util.Arith; |
| | | import com.yami.trading.common.util.DateUtils; |
| | | import com.yami.trading.common.util.RandomUtil; |
| | | import com.yami.trading.dao.dz.ExchangeApplyOrderDzMapper; |
| | | import com.yami.trading.dao.dz.StockDzMapper; |
| | | import com.yami.trading.service.MarketOpenChecker; |
| | | import com.yami.trading.service.MoneyLogService; |
| | | import com.yami.trading.service.WalletService; |
| | | import com.yami.trading.service.data.DataService; |
| | |
| | | public Result getDzList(int pageNum, int pageSize, String orderBy, String keyWords, String stockType) { |
| | | try { |
| | | String formatDate = DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN); |
| | | Page page = new Page(pageNum, pageSize); |
| | | stockDzMapper.findStockTypeDz(page,orderBy,keyWords,formatDate, stockType); |
| | | Page<StockDzDto> page = new Page<>(pageNum, pageSize); |
| | | page = stockDzMapper.findStockTypeDz(page,orderBy,keyWords,formatDate, stockType); |
| | | page.getRecords().forEach(stockDzDto -> { |
| | | Realtime realtime = this.dataService.realtime(stockDzDto.getStockCode()).get(0); |
| | | if (realtime != null) { |
| | | stockDzDto.setCurrentPrice(realtime.getClose()); |
| | | } |
| | | }); |
| | | return Result.succeed(page); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result addByAdmin(String stockCode, String stockNum, String password, String startTime, String endTime, String discount,Integer period,String nowPrice,Integer switchType, String stockType) { |
| | | if (stockCode == null || stockCode.isEmpty() ||stockNum == null || stockNum.isEmpty() || startTime == null || startTime.isEmpty() ||endTime == null || endTime.isEmpty() || nowPrice == null){ |
| | | public Result addByAdmin(String stockCode, String stockNum, String password, String startTime, String endTime, String discount,Integer period,String nowPrice,Integer switchType, String stockType, double dayRate) { |
| | | if (stockCode == null || stockCode.isEmpty() || startTime == null || startTime.isEmpty() ||endTime == null || endTime.isEmpty() || nowPrice == null){ |
| | | return Result.failed("参数不能为空"); |
| | | } |
| | | if (stockType.equalsIgnoreCase(Item.indices) && dayRate == 0) { |
| | | return Result.failed("请输入日收益率"); |
| | | } |
| | | |
| | | //该类型是否已添加 |
| | | Long count = stockDzMapper.selectCount(new LambdaQueryWrapper<StockDz>() |
| | | .eq(StockDz::getStockCode,stockCode)); |
| | | .eq(StockDz::getStockCode,stockCode) |
| | | .eq(StockDz::getStockType,stockType)); |
| | | if(count > 0){ |
| | | return Result.failed("股票代码已存在"); |
| | | } |
| | |
| | | stockDz.setIsLock(0); |
| | | stockDz.setIsShow(1); |
| | | stockDz.setAddTime(new Date()); |
| | | stockDz.setStockNum(Integer.valueOf(stockNum)); |
| | | if (stockNum != null && !stockNum.isEmpty()){ |
| | | stockDz.setStockNum(Integer.valueOf(stockNum)); |
| | | } |
| | | stockDz.setPassword(password); |
| | | stockDz.setStartTime(DateUtil.parseDateTime(startTime)); |
| | | stockDz.setEndTime(DateUtil.parseDateTime(endTime)); |
| | |
| | | stockDz.setPeriod(period); |
| | | stockDz.setSwitchType(switchType); |
| | | stockDz.setNowPrice(new BigDecimal(nowPrice)); |
| | | stockDz.setDayRate(dayRate); |
| | | if (save(stockDz)) { |
| | | return Result.succeed("添加成功"); |
| | | } |
| | |
| | | if(stockDz == null){ |
| | | return Result.failed("不存在该大宗信息"); |
| | | } |
| | | model.setStockName(item.getSymbolFullName()); |
| | | //model.setStockName(item.getSymbolFullName()); |
| | | model.setStockCode(item.getSymbol()); |
| | | model.setStockType(stockDz.getStockType()); |
| | | model.setStockSpell(item.getSymbolData()); |
| | |
| | | } else { //已结算 |
| | | closePrice = dz.getClosePrice(); |
| | | } |
| | | //盈亏 |
| | | double profitLoss = (closePrice - dz.getPrice()) * dz.getSymbolValue(); |
| | | DecimalFormat df = new DecimalFormat("#.##"); |
| | | String resultStr = df.format(profitLoss); |
| | | dz.setProfitLoss(Double.parseDouble(resultStr)); |
| | | if (dz.getDayRate() > 0) { |
| | | Date startTime = dz.getCreateTime(); |
| | | // 计算相差天数 |
| | | int num = com.yami.trading.common.util.DateUtil.dateNum(startTime, new Date()); |
| | | num = Math.max(1, Math.min(num, dz.getPeriod())); |
| | | double dayEarnings = dz.getDayRate() * dz.getVolume(); |
| | | double profitLoss = dayEarnings * num; |
| | | DecimalFormat df = new DecimalFormat("#.##"); |
| | | String resultStr = df.format(profitLoss); |
| | | String resultStr2 = df.format(dayEarnings); |
| | | dz.setProfitLoss(Double.parseDouble(resultStr)); |
| | | dz.setDayEarnings(Double.parseDouble(resultStr2)); |
| | | |
| | | double profitPercentage = (profitLoss / dz.getVolume()) * 100; |
| | | String resultPer = df.format(profitPercentage); |
| | | dz.setProfitLossPercentage(Double.parseDouble(resultPer)); |
| | | double profitPercentage = (profitLoss / dz.getVolume()) * 100; |
| | | String resultPer = df.format(profitPercentage); |
| | | dz.setProfitLossPercentage(Double.parseDouble(resultPer)); |
| | | } else { |
| | | //盈亏 |
| | | double profitLoss = (closePrice - dz.getPrice()) * dz.getSymbolValue(); |
| | | DecimalFormat df = new DecimalFormat("#.##"); |
| | | String resultStr = df.format(profitLoss); |
| | | dz.setProfitLoss(Double.parseDouble(resultStr)); |
| | | |
| | | double profitPercentage = (profitLoss / dz.getVolume()) * 100; |
| | | String resultPer = df.format(profitPercentage); |
| | | dz.setProfitLossPercentage(Double.parseDouble(resultPer)); |
| | | } |
| | | }); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Result getDzCheckList(int pageNum, int pageSize, String state, String stockCode, String stockType) { |
| | | public Result getDzCheckList(int pageNum, int pageSize, String state, String stockCode, String stockType, List<String> checkedList) { |
| | | try { |
| | | Page page = new Page(pageNum, pageSize); |
| | | stockDzMapper.getDzCheckList(page ,state, stockCode, stockType); |
| | | |
| | | stockDzMapper.getDzCheckList(page ,state, stockCode, stockType, checkedList); |
| | | return Result.succeed(page); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | |
| | | public Result buyDz(String dzId, String password, double num, String partyId) { |
| | | try { |
| | | if (num <= 0) { |
| | | throw new YamiShopBindException("请输入正确的货币数量"); |
| | | throw new YamiShopBindException("请输入"); |
| | | } |
| | | User party = userService.getById(partyId); |
| | | if (!party.isEnabled()) { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("uuid", dzId)); |
| | | if (stockDz == null) { |
| | | throw new YamiShopBindException("大宗不存在"); |
| | |
| | | } |
| | | |
| | | if(stockDz.getStartTime().getTime() > new Date().getTime() || stockDz.getEndTime().getTime() < new Date().getTime()){ |
| | | throw new YamiShopBindException("不在内幕交易时间之内"); |
| | | return Result.failed("不在内幕交易时间之内"); |
| | | } |
| | | BigDecimal nowPrice = stockDz.getNowPrice(); |
| | | |
| | | if (nowPrice.compareTo(new BigDecimal("0")) == 0) { |
| | | throw new YamiShopBindException("股票价格0,请重试"); |
| | | } |
| | | if (stockDz.getStockNum() > num) { |
| | | throw new YamiShopBindException("最小购买数量" + stockDz.getStockNum()); |
| | | boolean isETF = stockDz.getStockType().equalsIgnoreCase(Item.indices); |
| | | if (isETF) { |
| | | if (stockDz.getNowPrice().doubleValue() > num) { |
| | | return Result.failed("请输入最小购买金额"); |
| | | } |
| | | } else { |
| | | if (stockDz.getStockNum() > num) { |
| | | return Result.failed("请购买最小数量"); |
| | | } |
| | | } |
| | | boolean isOpen = MarketOpenChecker.isMarketOpenBuyDz(Item.US_STOCKS); |
| | | if (!isOpen) { |
| | | return Result.failed("当前股市休市"); |
| | | } |
| | | |
| | | |
| | | Wallet wallet = this.walletService.saveWalletByPartyId(partyId); |
| | | BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(num)); |
| | | BigDecimal buyAmt; |
| | | if (isETF) { |
| | | buyAmt = new BigDecimal(num); |
| | | } else { |
| | | buyAmt = nowPrice.multiply(new BigDecimal(num)); |
| | | } |
| | | //手续费比率 |
| | | Double feeRate = sysparaService.find("exchange_apply_order_buy_fee").getDouble(); |
| | | Double feeRate = sysparaService.find("exchange_apply_order_dz_buy_fee").getDouble(); |
| | | BigDecimal orderFree = buyAmt.multiply(BigDecimal.valueOf(feeRate)); |
| | | if (buyAmt.doubleValue() < 300) { |
| | | orderFree = BigDecimal.ONE; |
| | | } |
| | | BigDecimal orderAmt = buyAmt.add(orderFree); |
| | | if (wallet.getMoney().compareTo(orderAmt) < 0) { |
| | | throw new YamiShopBindException("订单失败,资金不足"); |
| | | return Result.failed("余额不足"); |
| | | } |
| | | |
| | | BigDecimal amountBefore = wallet.getMoney(); |
| | |
| | | return Result.succeed("购买成功"); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | return Result.failed("操作失败:" + e.getMessage()); |
| | | return Result.failed("失败"); |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public Result dzCheck(String id, Integer checkType, Double orderNum) { |
| | | public Result dzCheck(String id, Integer checkType, Double orderNum, double price) { |
| | | try { |
| | | ExchangeApplyOrderDz order = exchangeApplyOrderDzMapper.selectById(id); |
| | | if (order == null) { |
| | |
| | | exchangeApplyOrderDzMapper.updateById(order); |
| | | return Result.succeed("操作成功"); |
| | | } |
| | | if (orderNum > order.getSymbolValue()) { |
| | | throw new YamiShopBindException("输入数量大于用户买入数量"); |
| | | } |
| | | |
| | | StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("uuid", order.getDzId())); |
| | | if (stockDz == null) { |
| | | throw new YamiShopBindException("大宗不存在"); |
| | | } |
| | | |
| | | BigDecimal nowPrice = stockDz.getNowPrice(); |
| | | BigDecimal nowPrice; |
| | | boolean isETF = stockDz.getStockType().equalsIgnoreCase(Item.indices); |
| | | if (isETF) { |
| | | if (orderNum > order.getPrice()) { |
| | | throw new YamiShopBindException("输入金额大于用户买入金额"); |
| | | } |
| | | nowPrice = new BigDecimal(orderNum); |
| | | order.setPrice(nowPrice.doubleValue()); |
| | | } else { |
| | | if (orderNum > order.getSymbolValue()) { |
| | | throw new YamiShopBindException("输入数量大于用户买入数量"); |
| | | } |
| | | nowPrice = stockDz.getNowPrice(); |
| | | } |
| | | |
| | | if (price > 0) { |
| | | nowPrice = BigDecimal.valueOf(price); |
| | | order.setPrice(price); |
| | | } |
| | | if (nowPrice.compareTo(new BigDecimal("0")) == 0) { |
| | | throw new YamiShopBindException("股票价格0,请重试"); |
| | | } |
| | | |
| | | Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId()); |
| | | BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(orderNum)); |
| | | BigDecimal buyAmt = nowPrice; |
| | | if (!isETF) { |
| | | buyAmt = nowPrice.multiply(new BigDecimal(orderNum)); |
| | | } |
| | | //手续费比率 |
| | | Double feeRate = sysparaService.find("exchange_apply_order_dz_buy_fee").getDouble(); |
| | | BigDecimal orderFree = buyAmt.multiply(BigDecimal.valueOf(feeRate)); |
| | | if (buyAmt.doubleValue() < 300) { |
| | | orderFree = BigDecimal.ONE; |
| | | } |
| | | |
| | | |
| | | BigDecimal orderAmt = buyAmt.add(orderFree); |
| | | if (wallet.getMoney().compareTo(orderAmt) < 0) { |
| | | throw new YamiShopBindException("订单失败,资金不足"); |
| | |
| | | order.setVolume(buyAmt.doubleValue()); |
| | | order.setFee(orderFree.doubleValue()); |
| | | order.setState(ExchangeApplyOrderDz.STATE_POSITION); |
| | | order.setCreateTime(new Date()); |
| | | exchangeApplyOrderDzMapper.updateById(order); |
| | | walletService.update(wallet.getUserId(), Arith.sub(0, orderAmt.doubleValue())); |
| | | |
| | |
| | | throw new YamiShopBindException("大宗不存在"); |
| | | } |
| | | |
| | | BigDecimal nowPrice = stockDz.getNowPrice(); |
| | | BigDecimal nowPrice; |
| | | boolean isETF = stockDz.getStockType().equalsIgnoreCase(Item.indices); |
| | | if (isETF) { |
| | | nowPrice = BigDecimal.valueOf(order.getPrice()); |
| | | } else { |
| | | nowPrice = stockDz.getNowPrice(); |
| | | } |
| | | if (nowPrice.compareTo(new BigDecimal("0")) == 0) { |
| | | throw new YamiShopBindException("股票价格0,请重试"); |
| | | } |
| | |
| | | Date resultTime = calendar.getTime(); |
| | | |
| | | if(now.getTime() < resultTime.getTime()){ |
| | | throw new YamiShopBindException("锁仓中"); |
| | | return Result.failed("未到平仓时间"); |
| | | } |
| | | } |
| | | if (stockDz.getStockName().contains("测试")) { |
| | | |
| | | } else { |
| | | boolean isOpen = MarketOpenChecker.isMarketOpenByItemCloseType(Item.US_STOCKS); |
| | | if (!isOpen) { |
| | | return Result.failed("当前股市休市"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | Wallet wallet = this.walletService.saveWalletByPartyId(order.getPartyId()); |
| | | BigDecimal sellAmt = nowPrice.multiply(new BigDecimal(num)); |
| | | BigDecimal sellAmt; |
| | | if (isETF) { |
| | | sellAmt = nowPrice; |
| | | } else { |
| | | sellAmt = nowPrice.multiply(new BigDecimal(num)); |
| | | } |
| | | //手续费比率 |
| | | Double feeRate = sysparaService.find("exchange_apply_order_dz_sell_fee").getDouble(); |
| | | BigDecimal orderFree = sellAmt.multiply(BigDecimal.valueOf(feeRate)); |
| | | |
| | | String symbol = stockDz.getStockCode(); |
| | | Realtime realtime = this.dataService.realtime(symbol).get(0); |
| | | double closePrice = realtime.getClose(); |
| | | if (sellAmt.doubleValue() < 300) { |
| | | orderFree = BigDecimal.ONE; |
| | | } |
| | | |
| | | //结算金额 |
| | | double closeAmt = closePrice * num - orderFree.doubleValue(); |
| | | double closeAmt; |
| | | String symbol = stockDz.getStockCode(); |
| | | |
| | | double closePrice; |
| | | if (isETF) { |
| | | //按日收益率结算 |
| | | closeAmt = order.getPrice(); |
| | | closeAmt = closeAmt + stockDz.getDayRate() * closeAmt * stockDz.getPeriod(); |
| | | closePrice = closeAmt; |
| | | closeAmt = closeAmt - orderFree.doubleValue(); |
| | | } else { |
| | | Realtime realtime = this.dataService.realtime(symbol).get(0); |
| | | closePrice = realtime.getClose(); |
| | | closeAmt = closePrice * num - orderFree.doubleValue(); |
| | | } |
| | | if (closeAmt < 0) { |
| | | throw new YamiShopBindException("手续费资金不足"); |
| | | return Result.failed("余额不足"); |
| | | } |
| | | |
| | | //拆分订单 |
| | |
| | | return Result.succeed("平仓成功"); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | return Result.failed(e.getMessage()); |
| | | return Result.failed("失败"); |
| | | } |
| | | } |
| | | |