| | |
| | | import com.yami.trading.bean.data.domain.Realtime; |
| | | 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; |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.Objects; |
| | | import java.math.RoundingMode; |
| | | import java.text.DecimalFormat; |
| | | import java.util.*; |
| | | |
| | | @Service |
| | | @Slf4j |
| | |
| | | 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) { |
| | | if (stockCode == null || stockCode.isEmpty() ||stockNum == null || stockNum.isEmpty() || startTime == null || startTime.isEmpty() ||endTime == null || endTime.isEmpty() || period == null || 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 stockDz = new StockDz(); |
| | | stockDz.setStockName(item.getSymbolFullName()); |
| | | stockDz.setStockCode(item.getSymbol()); |
| | | stockDz.setStockType(item.getType()); |
| | | stockDz.setStockType(stockType); |
| | | stockDz.setStockSpell(item.getSymbolData()); |
| | | 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(item.getType()); |
| | | model.setStockType(stockDz.getStockType()); |
| | | model.setStockSpell(item.getSymbolData()); |
| | | return stockDzMapper.updateById(model) > 0 ? Result.succeed("修改成功") : Result.failed("修改失败"); |
| | | } |
| | |
| | | @Override |
| | | public Result getDzOrderList(int pageNum, int pageSize, String state, String userId, String stockType) { |
| | | try { |
| | | Page page = new Page(pageNum, pageSize); |
| | | stockDzMapper.getDzOrderList(page ,state, userId, stockType); |
| | | Page<ExchangeApplyOrderDzDto> page = new Page<>(pageNum, pageSize); |
| | | page = stockDzMapper.getDzOrderList(page ,state, userId, stockType); |
| | | if (!page.getRecords().isEmpty()) { |
| | | List<ExchangeApplyOrderDzDto> list = page.getRecords(); |
| | | list.forEach(dz -> { |
| | | double closePrice; |
| | | if (state != null) { //持仓 |
| | | Realtime realtime = this.dataService.realtime(dz.getSymbol()).get(0); |
| | | //获取现价 |
| | | closePrice = realtime.getClose(); |
| | | } else { //已结算 |
| | | closePrice = dz.getClosePrice(); |
| | | } |
| | | 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)); |
| | | } 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)); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | return Result.succeed(page); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | |
| | | } |
| | | |
| | | @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_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("购买成功,等待审核"); |
| | | } |
| | | |
| | | order.setState(ExchangeApplyOrderDz.STATE_SUCCEED); |
| | | order.setState(ExchangeApplyOrderDz.STATE_POSITION); |
| | | exchangeApplyOrderDzMapper.insert(order); |
| | | walletService.update(wallet.getUserId(), Arith.sub(0, orderAmt.doubleValue())); |
| | | |
| | | //TODO 转持仓 |
| | | this.intoPosition(order, stockDz.getStockType()); |
| | | //this.intoPosition(order, stockDz.getStockType()); |
| | | |
| | | MoneyLog log = new MoneyLog(); |
| | | log.setCategory(Constants.MONEYLOG_CATEGORY_EXCHANGE); |
| | |
| | | log.setAmountBefore(amountBefore); |
| | | log.setAmount(orderAmt.negate()); |
| | | log.setAmountAfter(amountBefore.subtract(orderAmt)); |
| | | log.setLog(name + type2 + "大宗交易买入" + ",订单号[" + order.getOrderNo() + "]"); |
| | | log.setLog(name + type2 + "大宗交易买入成交" + ",订单号[" + order.getOrderNo() + "]"); |
| | | log.setUserId(order.getPartyId()); |
| | | log.setWalletType(Constants.WALLET); |
| | | log.setSymbol(stockDz.getStockCode()); |
| | |
| | | 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.setSymbolValue(orderNum); |
| | | order.setVolume(buyAmt.doubleValue()); |
| | | order.setFee(orderFree.doubleValue()); |
| | | order.setState(ExchangeApplyOrderDz.STATE_SUCCEED); |
| | | order.setState(ExchangeApplyOrderDz.STATE_POSITION); |
| | | order.setCreateTime(new Date()); |
| | | exchangeApplyOrderDzMapper.updateById(order); |
| | | walletService.update(wallet.getUserId(), Arith.sub(0, orderAmt.doubleValue())); |
| | | |
| | | //TODO 转持仓 |
| | | this.intoPosition(order, stockDz.getStockType()); |
| | | //this.intoPosition(order, stockDz.getStockType()); |
| | | |
| | | MoneyLog log = new MoneyLog(); |
| | | log.setCategory(Constants.MONEYLOG_CATEGORY_EXCHANGE); |
| | |
| | | log.setAmountBefore(amountBefore); |
| | | log.setAmount(orderAmt.negate()); |
| | | log.setAmountAfter(amountBefore.subtract(orderAmt)); |
| | | log.setLog(name + type2 + "大宗交易买入" + ",订单号[" + order.getOrderNo() + "]"); |
| | | log.setLog(name + type2 + "大宗交易买入成交" + ",订单号[" + order.getOrderNo() + "]"); |
| | | log.setUserId(order.getPartyId()); |
| | | log.setWalletType(Constants.WALLET); |
| | | log.setSymbol(stockDz.getStockCode()); |
| | |
| | | log.setCreateTime(new Date()); |
| | | log.setUpdateTime(new Date()); |
| | | moneyLogService.save(log); |
| | | return Result.succeed("审核成功,订单已转客户持仓"); |
| | | return Result.succeed("审核成功,订单已转持仓"); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | return Result.failed("操作失败:" + e.getMessage()); |
| | |
| | | log.setAmountBefore(new BigDecimal(amountBeforeExtend)); |
| | | log.setAmount(BigDecimal.valueOf(realValue)); |
| | | log.setAmountAfter(BigDecimal.valueOf(amountBeforeExtend + realValue)); |
| | | log.setLog(name + type2 + "现货交易买入委托单成交,订单号[" + exOrder.getOrderNo() + "]"); |
| | | log.setLog(name + type2 + "大宗交易买入委托单成交,订单号[" + exOrder.getOrderNo() + "]"); |
| | | log.setUserId(exOrder.getPartyId()); |
| | | log.setSymbol(exOrder.getSymbol()); |
| | | log.setWalletType(exOrder.getSymbol()); |
| | |
| | | exchangeApplyOrderService.save(exOrder); |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public Result closeDz(String id, Double num, String partyId) { |
| | | try { |
| | | ExchangeApplyOrderDz order = exchangeApplyOrderDzMapper.selectById(id); |
| | | if (order == null) { |
| | | throw new YamiShopBindException("订单不存在"); |
| | | } |
| | | if (!order.getState().equals(ExchangeApplyOrderDz.STATE_POSITION)) { |
| | | throw new YamiShopBindException("订单不能平仓"); |
| | | } |
| | | if (num == null) { //不传默认平全部 |
| | | num = order.getSymbolValue(); |
| | | } |
| | | if (num < 0 || num > 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; |
| | | 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 now = new Date(); |
| | | if (stockDz.getPeriod() != null && stockDz.getPeriod() > 0) { |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTime(order.getCreateTime()); |
| | | calendar.add(Calendar.DATE, stockDz.getPeriod()); |
| | | // 锁仓时间 |
| | | Date resultTime = calendar.getTime(); |
| | | |
| | | if(now.getTime() < resultTime.getTime()){ |
| | | 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; |
| | | 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)); |
| | | if (sellAmt.doubleValue() < 300) { |
| | | orderFree = BigDecimal.ONE; |
| | | } |
| | | |
| | | //结算金额 |
| | | 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) { |
| | | return Result.failed("余额不足"); |
| | | } |
| | | |
| | | //拆分订单 |
| | | if (num < order.getSymbolValue()) { |
| | | ExchangeApplyOrderDz newOrder = new ExchangeApplyOrderDz(); |
| | | newOrder.setPartyId(partyId); |
| | | newOrder.setSymbol(symbol); |
| | | newOrder.setSymbolValue(num); |
| | | newOrder.setDzId(stockDz.getUuid()); |
| | | newOrder.setVolume(sellAmt.doubleValue()); |
| | | newOrder.setPrice(nowPrice.doubleValue()); |
| | | newOrder.setOrderNo(com.yami.trading.common.util.DateUtil.getToday("yyMMddHHmmss") + RandomUtil.getRandomNum(8)); |
| | | newOrder.setFee(orderFree.doubleValue()); |
| | | newOrder.setCreateTime(order.getCreateTime()); |
| | | newOrder.setClosePrice(closePrice); |
| | | newOrder.setCloseTime(now); |
| | | newOrder.setState(ExchangeApplyOrderDz.STATE_CLOSED); |
| | | exchangeApplyOrderDzMapper.insert(newOrder); |
| | | |
| | | order.setSymbolValue(order.getSymbolValue() - num); |
| | | order.setVolume(order.getSymbolValue() * order.getPrice()); |
| | | } else { |
| | | order.setClosePrice(closePrice); |
| | | order.setCloseTime(now); |
| | | order.setFee(order.getFee() + orderFree.doubleValue()); |
| | | order.setState(ExchangeApplyOrderDz.STATE_CLOSED); |
| | | } |
| | | exchangeApplyOrderDzMapper.updateById(order); |
| | | |
| | | double amountBefore = wallet.getMoney().doubleValue(); |
| | | this.walletService.update(wallet.getUserId(), closeAmt); |
| | | MoneyLog log = new MoneyLog(); |
| | | log.setCategory(Constants.MONEYLOG_CATEGORY_EXCHANGE); |
| | | String name = Constants.MONEYLOG_MAP.get(stockDz.getStockType()); |
| | | String type2 = Constants.MONEYLOG_MAP_TYPE.get(stockDz.getStockType()); |
| | | log.setAmountBefore(new BigDecimal(amountBefore)); |
| | | log.setAmount(new BigDecimal(closeAmt)); |
| | | log.setAmountAfter(wallet.getMoney().add(BigDecimal.valueOf(closeAmt))); |
| | | log.setLog(name + type2 + "大宗交易卖出成交,订单号[" + order.getOrderNo() + "]"); |
| | | log.setUserId(order.getPartyId()); |
| | | log.setWalletType(Constants.WALLET); |
| | | log.setContentType(type2 + Constants.MONEYLOG_CONTENT_CLOSE); |
| | | log.setSymbol(order.getSymbol()); |
| | | moneyLogService.save(log); |
| | | return Result.succeed("平仓成功"); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | return Result.failed("失败"); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |