| | |
| | | package com.nq.service.impl; |
| | | |
| | | import cn.hutool.core.collection.CollectionUtil; |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.nq.dao.*; |
| | |
| | | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.sql.Timestamp; |
| | | import java.time.LocalDateTime; |
| | | import java.time.ZoneId; |
| | |
| | | @Autowired |
| | | UserPositionCheckDzService userPositionCheckDzService; |
| | | |
| | | @Autowired |
| | | UserPendingorderService userPendingorderService; |
| | | |
| | | @Autowired |
| | | UserPendingorderMapper userPendingorderMapper; |
| | | |
| | | @Transactional |
| | | public ServerResponse buy(Integer stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) { |
| | |
| | | //股票类型 现价 数据源的处理 |
| | | BigDecimal nowPrice = priceServices.getNowPrice(stock.getStockCode()); |
| | | |
| | | |
| | | if (nowPrice.compareTo(new BigDecimal("0")) == 0) { |
| | | return ServerResponse.createByErrorMsg("报价0,请稍后再试", request); |
| | | } |
| | |
| | | if (availableBalance.compareTo(buyAmt.add(orderFree)) < 0) { |
| | | return ServerResponse.createByErrorMsg("订单失败,配资不足", request); |
| | | } |
| | | UserPosition userPosition = new UserPosition(); |
| | | 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.getStockType()); |
| | | userPosition.setStockSpell(stock.getStockSpell()); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(nowPrice); |
| | | 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(buyAmt); |
| | | // 手续费 |
| | | UserPosition position = userPositionMapper.selectOne(new LambdaQueryWrapper<>(UserPosition.class) |
| | | .eq(UserPosition::getUserId, user.getId()) |
| | | .eq(UserPosition::getStockCode, stock.getStockCode()) |
| | | .eq(UserPosition::getOrderDirection,(buyType.intValue() == 0) ? "买涨" : "买跌") |
| | | .isNull(UserPosition::getSellOrderId) |
| | | ); |
| | | if(ObjectUtil.isEmpty(position)){ |
| | | UserPosition userPosition = new UserPosition(); |
| | | 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.getStockType()); |
| | | userPosition.setStockSpell(stock.getStockSpell()); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(nowPrice); |
| | | 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(buyAmt); |
| | | // 手续费 |
| | | |
| | | userPosition.setOrderFee(orderFree); |
| | | userPosition.setOrderSpread(BigDecimal.ZERO); |
| | | userPosition.setSpreadRatePrice(BigDecimal.ZERO); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPosition.setProfitAndLose(profit_and_lose); |
| | | userPosition.setAllProfitAndLose(profit_and_lose.add(orderFree)); |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(BigDecimal.ZERO); |
| | | userPositionMapper.insert(userPosition); |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", ""); |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | return ServerResponse.createBySuccessMsg("下单成功", request); |
| | | userPosition.setOrderFee(orderFree); |
| | | userPosition.setOrderSpread(BigDecimal.ZERO); |
| | | userPosition.setSpreadRatePrice(BigDecimal.ZERO); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPosition.setProfitAndLose(profit_and_lose); |
| | | userPosition.setAllProfitAndLose(profit_and_lose.add(orderFree)); |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(BigDecimal.ZERO); |
| | | userPositionMapper.insert(userPosition); |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", ""); |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | return ServerResponse.createBySuccessMsg("下单成功", request); |
| | | }else{ |
| | | position.setOrderNum(position.getOrderNum()+buyNum); |
| | | position.setOrderTotalPrice(position.getOrderTotalPrice().add(buyAmt)); |
| | | position.setOrderFee(position.getOrderFee().add(orderFree)); |
| | | double divide = position.getOrderTotalPrice().doubleValue() / position.getOrderNum(); |
| | | position.setBuyOrderPrice(new BigDecimal(divide)); |
| | | position.setAllProfitAndLose(position.getAllProfitAndLose().add(orderFree)); |
| | | userPositionMapper.updateById(position); |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, buyAmt.negate(), "", ""); |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | return ServerResponse.createBySuccessMsg("下单成功", request); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Transactional |
| | | public ServerResponse goldCrudeOilbuy(String name, Integer buyNum, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) { |
| | | public ServerResponse goldCrudeOilbuy(String name, Integer buyNum, Integer buyType,Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) { |
| | | |
| | | SiteProduct siteProduct = iSiteProductService.getProductSetting(); |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("USDT", user.getId()); |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("USD", user.getId()); |
| | | |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | |
| | | if (availableBalance.compareTo(buyAmt.add(orderFree)) < 0) { |
| | | return ServerResponse.createByErrorMsg("订单失败,配资不足", request); |
| | | } |
| | | UserPosition userPosition = new UserPosition(); |
| | | 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(name); |
| | | userPosition.setStockName(name); |
| | | userPosition.setStockGid(name); |
| | | userPosition.setStockSpell(name); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(price); |
| | | userPosition.setOrderDirection("买涨"); |
| | | userPosition.setOrderNum(buyNum); |
| | | userPosition.setIsLock(Integer.valueOf(0)); |
| | | userPosition.setOrderLever(lever); |
| | | userPosition.setOrderTotalPrice(buyAmt); |
| | | // 手续费 |
| | | UserPosition position = userPositionMapper.selectOne(new LambdaQueryWrapper<>(UserPosition.class) |
| | | .eq(UserPosition::getUserId, user.getId()) |
| | | .eq(UserPosition::getStockCode, "HJYY") |
| | | .eq(UserPosition::getStockName,name) |
| | | .eq(UserPosition::getOrderDirection,(buyType.intValue() == 0) ? "买涨" : "买跌") |
| | | .isNull(UserPosition::getSellOrderId) |
| | | ); |
| | | if(ObjectUtil.isEmpty(position)) { |
| | | UserPosition userPosition = new UserPosition(); |
| | | 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("HJYY"); |
| | | userPosition.setStockName(name); |
| | | userPosition.setStockGid("HJYY"); |
| | | userPosition.setStockSpell(name); |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(price); |
| | | userPosition.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌"); |
| | | userPosition.setOrderNum(buyNum); |
| | | userPosition.setIsLock(Integer.valueOf(0)); |
| | | userPosition.setOrderLever(lever); |
| | | userPosition.setOrderTotalPrice(buyAmt); |
| | | // 手续费 |
| | | |
| | | userPosition.setOrderFee(orderFree); |
| | | userPosition.setOrderSpread(BigDecimal.ZERO); |
| | | userPosition.setSpreadRatePrice(BigDecimal.ZERO); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPosition.setProfitAndLose(profit_and_lose); |
| | | userPosition.setAllProfitAndLose(profit_and_lose.add(orderFree)); |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(BigDecimal.ZERO); |
| | | userPositionMapper.insert(userPosition); |
| | | iUserAssetsServices.availablebalanceChange("USDT", user.getId(), EUserAssets.BUY, buyAmt.negate(), "", ""); |
| | | iUserAssetsServices.availablebalanceChange("USDT", user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | return ServerResponse.createBySuccessMsg("下单成功", request); |
| | | userPosition.setOrderFee(orderFree); |
| | | userPosition.setOrderSpread(BigDecimal.ZERO); |
| | | userPosition.setSpreadRatePrice(BigDecimal.ZERO); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | | userPosition.setProfitAndLose(profit_and_lose); |
| | | userPosition.setAllProfitAndLose(profit_and_lose.add(orderFree)); |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(BigDecimal.ZERO); |
| | | userPositionMapper.insert(userPosition); |
| | | iUserAssetsServices.availablebalanceChange("USD", user.getId(), EUserAssets.BUY, buyAmt.negate(), "", ""); |
| | | iUserAssetsServices.availablebalanceChange("USD", user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | return ServerResponse.createBySuccessMsg("下单成功", request); |
| | | }else{ |
| | | position.setOrderNum(position.getOrderNum()+buyNum); |
| | | position.setOrderTotalPrice(position.getOrderTotalPrice().add(buyAmt)); |
| | | position.setOrderFee(position.getOrderFee().add(orderFree)); |
| | | double divide = position.getOrderTotalPrice().doubleValue() / position.getOrderNum(); |
| | | position.setBuyOrderPrice(new BigDecimal(divide*position.getOrderLever())); |
| | | position.setAllProfitAndLose(position.getAllProfitAndLose().add(orderFree)); |
| | | userPositionMapper.updateById(position); |
| | | iUserAssetsServices.availablebalanceChange("USD", user.getId(), EUserAssets.BUY, buyAmt.negate(), "", ""); |
| | | iUserAssetsServices.availablebalanceChange("USD", user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | return ServerResponse.createBySuccessMsg("下单成功", request); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | if (1 == userPosition.getIsLock().intValue()) { |
| | | return ServerResponse.createByErrorMsg("this order is closed " + userPosition.getLockMsg()); |
| | | } |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode())); |
| | | BigDecimal nowPrice = priceServices.getNowPrice(userPosition.getStockCode()); |
| | | |
| | | BigDecimal nowPrice = BigDecimal.ZERO; |
| | | String stockType; |
| | | if(userPosition.getStockSpell().equals("XAUUSD") || userPosition.getStockSpell().equals("USOIL")){ |
| | | nowPrice = new BigDecimal(RedisShardedPoolUtils.get(userPosition.getStockSpell())); |
| | | stockType = "USD"; |
| | | }else{ |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode())); |
| | | nowPrice = priceServices.getNowPrice(userPosition.getStockCode()); |
| | | stockType = stock.getStockType(); |
| | | } |
| | | |
| | | if (nowPrice.compareTo(new BigDecimal("0")) != 1) { |
| | | return ServerResponse.createByErrorMsg("报价0,平仓失败,请稍后再试"); |
| | | } |
| | |
| | | BigDecimal sellOrderTotel = nowPrice.multiply(new BigDecimal(userPosition.getOrderNum())); |
| | | BigDecimal xsPrice = sellOrderTotel.multiply(siitteBuyFee); |
| | | userPositionMapper.updateById(userPosition); |
| | | userAssetsServices.availablebalanceChange(stock.getStockType(), |
| | | userAssetsServices.availablebalanceChange(stockType, |
| | | userPosition.getUserId(), EUserAssets.CLOSE_POSITION_RETURN_SECURITY_DEPOSIT, |
| | | userPosition.getOrderTotalPrice(), "", ""); |
| | | userAssetsServices.availablebalanceChange(stock.getStockType(), |
| | | userAssetsServices.availablebalanceChange(stockType, |
| | | userPosition.getUserId(), EUserAssets.HANDLING_CHARGE, |
| | | xsPrice, "", ""); |
| | | |
| | | PositionProfitVO profitVO = UserPointUtil.getPositionProfitVO(userPosition, priceServices.getNowPrice(userPosition.getStockCode())); |
| | | userAssetsServices.availablebalanceChange(stock.getStockType(), userPosition.getUserId(), EUserAssets.CLOSE_POSITION, |
| | | userAssetsServices.availablebalanceChange(stockType, userPosition.getUserId(), EUserAssets.CLOSE_POSITION, |
| | | profitVO.getAllProfitAndLose(), "", ""); |
| | | return ServerResponse.createBySuccessMsg("平仓成功!"); |
| | | } |
| | | |
| | | |
| | | @Transactional |
| | | public ServerResponse sell(String positionSn, int doType, Integer number,HttpServletRequest request) { |
| | | public ServerResponse sell(String positionSn, int doType, Integer number,String salePrice,HttpServletRequest request) { |
| | | UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn); |
| | | if(null == number || number <= 0 || number > userPosition.getOrderNum()){ |
| | | return ServerResponse.createByErrorMsg("请输入正确的平仓数", request); |
| | | } |
| | | List<UserPendingorder> list = userPendingorderService.list(new LambdaQueryWrapper<>(UserPendingorder.class) |
| | | .eq(UserPendingorder::getPositionType, 1) |
| | | .eq(UserPendingorder::getPositionSn,positionSn) |
| | | .eq(UserPendingorder::getHangingOrderType,2) |
| | | ); |
| | | if(CollectionUtil.isNotEmpty(list)){ |
| | | return ServerResponse.createByErrorMsg("当前有平仓挂单未成交,禁止平仓。",request); |
| | | } |
| | | // 手续费率 |
| | | BigDecimal siitteBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.SELL_HANDLING_CHARGE.getCode()).getCValue()); |
| | |
| | | if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) { |
| | | return ServerResponse.createByErrorMsg("股票未上市,不能平仓", request); |
| | | } |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode())); |
| | | if(null == stock){ |
| | | return ServerResponse.createByErrorMsg("股票不存在,平仓失败", request); |
| | | } |
| | | Boolean b = tradingHourService.timeCheck(userPosition.getStockCode()); |
| | | if (!b) { |
| | | return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内", request); |
| | | BigDecimal nowPrice = BigDecimal.ZERO; |
| | | String stockType = null; |
| | | if(userPosition.getStockSpell().equals("XAUUSD") || userPosition.getStockSpell().equals("USOIL")){ |
| | | nowPrice = new BigDecimal(RedisShardedPoolUtils.get(userPosition.getStockSpell())); |
| | | stockType = "USD"; |
| | | }else{ |
| | | Stock stock = stockMapper.selectOne(new QueryWrapper<Stock>().eq("stock_code", userPosition.getStockCode())); |
| | | |
| | | stockType = stock.getStockType(); |
| | | |
| | | if(null == stock){ |
| | | return ServerResponse.createByErrorMsg("股票不存在,平仓失败", request); |
| | | } |
| | | Boolean b = tradingHourService.timeCheck(userPosition.getStockCode()); |
| | | if (!b) { |
| | | return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内", request); |
| | | } |
| | | if (!priceServices.isLimitDownSell(stock.getStockCode())) { |
| | | return ServerResponse.createByErrorMsg("股票跌停,无法平仓", request); |
| | | } |
| | | nowPrice = priceServices.getNowPrice(userPosition.getStockCode()); |
| | | if (nowPrice.compareTo(new BigDecimal("0")) != 1) { |
| | | return ServerResponse.createByErrorMsg("报价0,平仓失败,请稍后再试", request); |
| | | } |
| | | } |
| | | if(userPosition.getPositionType() == 3){ |
| | | StockDz stockDz = stockDzMapper.selectOne(new LambdaQueryWrapper<StockDz>().eq(StockDz::getId, userPosition.getDzId())); |
| | |
| | | if (1 == userPosition.getIsLock().intValue()) { |
| | | return ServerResponse.createByErrorMsg("this order is closed " + userPosition.getLockMsg()); |
| | | } |
| | | if (!priceServices.isLimitDownSell(stock.getStockCode())) { |
| | | return ServerResponse.createByErrorMsg("股票跌停,无法平仓", request); |
| | | } |
| | | BigDecimal nowPrice = priceServices.getNowPrice(userPosition.getStockCode()); |
| | | if (nowPrice.compareTo(new BigDecimal("0")) != 1) { |
| | | return ServerResponse.createByErrorMsg("报价0,平仓失败,请稍后再试", request); |
| | | } |
| | | |
| | | //部分平仓 |
| | | if(number < userPosition.getOrderNum()){ |
| | | //拆分订单 |
| | | UserPosition position = ConverterUtil.convert(userPosition,UserPosition.class); |
| | | position.setId(null); |
| | | position.setPositionSn(KeyUtils.getUniqueKey()); |
| | | position.setOrderNum(number); |
| | | position.setOrderTotalPrice(position.getBuyOrderPrice().multiply(new BigDecimal(number))); |
| | | position.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | //修改拆分订单手续费 |
| | | BigDecimal BuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()); |
| | | BigDecimal buyPrice = position.getBuyOrderPrice().multiply(new BigDecimal(position.getOrderNum())); |
| | | BigDecimal xsPrice = buyPrice.multiply(BuyFee); |
| | | position.setOrderFee(xsPrice); |
| | | if(StringUtils.isEmpty(salePrice)){ |
| | | //部分平仓 |
| | | if(number < userPosition.getOrderNum()){ |
| | | //拆分订单 |
| | | UserPosition position = ConverterUtil.convert(userPosition,UserPosition.class); |
| | | position.setId(null); |
| | | position.setPositionSn(KeyUtils.getUniqueKey()); |
| | | //得到均价 |
| | | double buyOrderPrice = position.getOrderTotalPrice().doubleValue() / position.getOrderNum().doubleValue() * position.getOrderLever(); |
| | | position.setOrderNum(userPosition.getOrderNum()-number); |
| | | BigDecimal positionBuyAmt = new BigDecimal(buyOrderPrice).multiply(new BigDecimal(position.getOrderNum())).divide(new BigDecimal(position.getOrderLever())); |
| | | position.setOrderTotalPrice(positionBuyAmt); |
| | | position.setBuyOrderPrice(new BigDecimal(buyOrderPrice)); |
| | | position.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | //修改拆分订单手续费 |
| | | BigDecimal BuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()); |
| | | BigDecimal buyPrice = position.getBuyOrderPrice().multiply(new BigDecimal(position.getOrderNum())); |
| | | BigDecimal xsPrice = buyPrice.multiply(BuyFee); |
| | | position.setOrderFee(xsPrice); |
| | | userPositionMapper.insert(position); |
| | | //得到均价 |
| | | double orderPrice = userPosition.getOrderTotalPrice().doubleValue() / userPosition.getOrderNum().doubleValue() * position.getOrderLever(); |
| | | //修改原订单 |
| | | userPosition.setOrderNum(number); |
| | | BigDecimal buyAmt = new BigDecimal(orderPrice).multiply(new BigDecimal(userPosition.getOrderNum())).divide(new BigDecimal(userPosition.getOrderLever())); |
| | | userPosition.setOrderTotalPrice(buyAmt); |
| | | userPosition.setOrderFee(userPosition.getOrderFee().subtract(position.getOrderFee())); |
| | | |
| | | //修改原订单 |
| | | userPosition.setOrderNum(userPosition.getOrderNum()-number); |
| | | userPosition.setOrderTotalPrice(userPosition.getBuyOrderPrice().multiply(new BigDecimal(userPosition.getOrderNum()))); |
| | | userPosition.setOrderFee(userPosition.getOrderFee().subtract(position.getOrderFee())); |
| | | userPositionMapper.insert(position); |
| | | userPositionMapper.updateById(userPosition); |
| | | userPositionMapper.updateById(userPosition); |
| | | |
| | | return getObjectServerResponse(request, position, nowPrice, siitteBuyFee, stock); |
| | | return getObjectServerResponse(request, userPosition, nowPrice, siitteBuyFee, stockType); |
| | | } |
| | | return getObjectServerResponse(request, userPosition, nowPrice, siitteBuyFee, stockType); |
| | | }else{ |
| | | UserPendingorder userPendingorder = ConverterUtil.convert(userPosition,UserPendingorder.class); |
| | | userPendingorder.setId(null); |
| | | userPendingorder.setOrderNum(number); |
| | | userPendingorder.setHangingOrderType(2); |
| | | userPendingorder.setPositionType(1); |
| | | userPendingorder.setStockType(stockType); |
| | | userPendingorder.setSellOrderPrice(new BigDecimal(salePrice)); |
| | | userPendingorderMapper.insert(userPendingorder); |
| | | } |
| | | return getObjectServerResponse(request, userPosition, nowPrice, siitteBuyFee, stock); |
| | | return ServerResponse.createBySuccess("操作成功",request); |
| | | } |
| | | |
| | | private ServerResponse<Object> getObjectServerResponse(HttpServletRequest request, UserPosition userPosition, BigDecimal nowPrice, BigDecimal siitteBuyFee, Stock stock) { |
| | | public ServerResponse<Object> getObjectServerResponse(HttpServletRequest request, UserPosition userPosition, BigDecimal nowPrice, BigDecimal siitteBuyFee,String stockType) { |
| | | userPosition.setSellOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setSellOrderPrice(nowPrice); |
| | | userPosition.setSellOrderTime(new Date()); |
| | |
| | | BigDecimal xsPrice = sellOrderTotel.multiply(siitteBuyFee); |
| | | userPosition.setOrderFee(userPosition.getOrderFee().add(xsPrice)); |
| | | userPositionMapper.updateById(userPosition); |
| | | userAssetsServices.availablebalanceChange(stock.getStockType(), |
| | | |
| | | userAssetsServices.availablebalanceChange(stockType, |
| | | userPosition.getUserId(), |
| | | EUserAssets.CLOSE_POSITION_RETURN_SECURITY_DEPOSIT, |
| | | userPosition.getOrderTotalPrice(), "", ""); |
| | | userAssetsServices.availablebalanceChange(stock.getStockType(), |
| | | userAssetsServices.availablebalanceChange(stockType, |
| | | userPosition.getUserId(), EUserAssets.HANDLING_CHARGE, |
| | | xsPrice, "", ""); |
| | | |
| | | PositionProfitVO profitVO = UserPointUtil.getPositionProfitVO(userPosition, |
| | | priceServices.getNowPrice(userPosition.getStockCode())); |
| | | |
| | | userAssetsServices.availablebalanceChange(stock.getStockType(), |
| | | userAssetsServices.availablebalanceChange(stockType, |
| | | userPosition.getUserId(), EUserAssets.CLOSE_POSITION, |
| | | profitVO.getAllProfitAndLose(), "", ""); |
| | | return ServerResponse.createBySuccessMsg("平仓成功!", request); |
| | |
| | | |
| | | public ServerResponse findMyPositionByCodeAndSpell(String stockCode, String stockSpell, |
| | | Integer state, HttpServletRequest request, |
| | | int pageNum, int pageSize, String stockType) { |
| | | int pageNum, int pageSize, String stockType,Integer pendingStatus) { |
| | | User user = this.iUserService.getCurrentUser(request); |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<UserPosition> userPositions; |
| | | List<UserPosition> userPositions = null; |
| | | if(state == 2){ |
| | | List<UserPendingorder> list = userPendingorderService.list(new LambdaQueryWrapper<>(UserPendingorder.class) |
| | | .eq(UserPendingorder::getUserId, user.getId()) |
| | | .eq(UserPendingorder::getStockGid,(null != stockCode && "HJYY".equals(stockCode)) ? stockCode : stockType) |
| | | .eq(UserPendingorder::getPositionType,pendingStatus) |
| | | ); |
| | | PageInfo pageInfo = new PageInfo(); |
| | | pageInfo.setList(list); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | }else if(state == 3){ |
| | | List<UserPositionCheckDz> list = userPositionCheckDzService.list(new LambdaQueryWrapper<UserPositionCheckDz>() |
| | | .eq(UserPositionCheckDz::getUserId, user.getId()) |
| | | .orderByDesc(UserPositionCheckDz::getBuyOrderTime) |
| | | ); |
| | | PageInfo pageInfo = new PageInfo(); |
| | | pageInfo.setList(list); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | }else { |
| | | if (null != stockCode && stockCode.equals("HJYY")) { |
| | | LambdaQueryWrapper<UserPosition> wrapper = getUserPositionLambdaQueryWrapper(stockCode, state, user); |
| | | userPositions = userPositionMapper.selectList(wrapper); |
| | | } else { |
| | | userPositions = userPositionMapper. |
| | | findMyPositionByCodeAndSpell(user.getId(), |
| | | stockCode, stockSpell, |
| | | state, stockType); |
| | | } |
| | | |
| | | |
| | | |
| | | userPositions = userPositionMapper. |
| | | findMyPositionByCodeAndSpell(user.getId(), |
| | | stockCode, stockSpell, |
| | | state, stockType); |
| | | |
| | | |
| | | List<UserPositionVO> userPositionVOS = Lists.newArrayList(); |
| | | if (userPositions.size() > 0) { |
| | | for (UserPosition position : userPositions) { |
| | | BigDecimal nowPrice = BigDecimal.ZERO; |
| | | if(state == 0){ |
| | | nowPrice = priceServices.getNowPrice(position.getStockCode()); |
| | | }else{ |
| | | nowPrice = position.getSellOrderPrice(); |
| | | } |
| | | //// if(state == 1){ |
| | | //// nowPrice = position.getSellOrderPrice(); |
| | | //// }else{ |
| | | //// nowPrice = priceServices.getNowPrice(position.getStockCode()); |
| | | //// } |
| | | UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position,nowPrice); |
| | | userPositionVO.setOrderTotalPrice(userPositionVO.getOrderTotalPrice().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | |
| | | StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>() |
| | | .eq(StockSubscribe::getCode, userPositionVO.getStockCode())); |
| | | if(position.getSellOrderId() == null){ |
| | | if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) { |
| | | userPositionVO.setProfitAndLose(BigDecimal.ZERO); |
| | | userPositionVO.setProfitAndLoseParent("0%"); |
| | | userPositionVO.setIsListed(false); |
| | | }else{ |
| | | userPositionVO.setIsListed(true); |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | List<UserPositionVO> userPositionVOS = Lists.newArrayList(); |
| | | if (userPositions.size() > 0) { |
| | | for (UserPosition position : userPositions) { |
| | | BigDecimal nowPrice = BigDecimal.ZERO; |
| | | if (position.getStockSpell().equals("XAUUSD") || position.getStockSpell().equals("USOIL")) { |
| | | nowPrice = new BigDecimal(RedisShardedPoolUtils.get(position.getStockSpell())); |
| | | } else { |
| | | if (state == 0) { |
| | | nowPrice = priceServices.getNowPrice(position.getStockCode()); |
| | | } else { |
| | | nowPrice = position.getSellOrderPrice(); |
| | | } |
| | | } |
| | | }else{ |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | |
| | | UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position, nowPrice); |
| | | userPositionVO.setOrderTotalPrice(userPositionVO.getOrderTotalPrice().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | userPositionVO.setBuyOrderPrice(userPositionVO.getBuyOrderPrice().setScale(2, BigDecimal.ROUND_DOWN)); |
| | | StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>() |
| | | .eq(StockSubscribe::getCode, userPositionVO.getStockCode())); |
| | | if (position.getSellOrderId() == null) { |
| | | if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) { |
| | | userPositionVO.setProfitAndLose(BigDecimal.ZERO); |
| | | userPositionVO.setProfitAndLoseParent("0%"); |
| | | userPositionVO.setIsListed(false); |
| | | } else { |
| | | userPositionVO.setIsListed(true); |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose()); |
| | | } |
| | | } else { |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose()); |
| | | } |
| | | userPositionVOS.add(userPositionVO); |
| | | } |
| | | userPositionVOS.add(userPositionVO); |
| | | } |
| | | |
| | | PageInfo pageInfo = new PageInfo(userPositions); |
| | | pageInfo.setList(userPositionVOS); |
| | | |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } |
| | | } |
| | | |
| | | private static LambdaQueryWrapper<UserPosition> getUserPositionLambdaQueryWrapper(String stockCode, Integer state, User user) { |
| | | LambdaQueryWrapper<UserPosition> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(UserPosition::getUserId, user.getId()); |
| | | wrapper.eq(UserPosition::getStockCode, stockCode); |
| | | wrapper.eq(UserPosition::getStockGid, stockCode); |
| | | if (state != null) { |
| | | if (state == 0) { |
| | | wrapper.isNull(UserPosition::getSellOrderId); |
| | | } else if (state == 1) { |
| | | wrapper.isNotNull(UserPosition::getSellOrderId); |
| | | } |
| | | } |
| | | |
| | | PageInfo pageInfo = new PageInfo(userPositions); |
| | | pageInfo.setList(userPositionVOS); |
| | | |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | wrapper.orderByDesc(UserPosition::getId); |
| | | return wrapper; |
| | | } |
| | | |
| | | public PositionVO findUserPositionAllProfitAndLose(Integer userId) { |
| | |
| | | } |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<UserPosition> userPositions = this.userPositionMapper.listByAgent(positionType, state, |
| | | userId, ids, positionSn, begin_time, end_time,null); |
| | | userId, ids, positionSn, begin_time, end_time,null,null); |
| | | |
| | | List<AgentPositionVO> agentPositionVOS = Lists.newArrayList(); |
| | | for (UserPosition position : userPositions) { |
| | |
| | | } |
| | | |
| | | List<UserPosition> userPositions = this.userPositionMapper.listByAgent(positionType, Integer.valueOf(1), |
| | | null, ids, null, begin_time, end_time,null); |
| | | null, ids, null, begin_time, end_time,null,null); |
| | | |
| | | |
| | | BigDecimal order_fee_amt = new BigDecimal("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,String phone) { |
| | | public ServerResponse listByAdmin(Integer agentId, Integer positionType, Integer state, Integer userId, String positionSn, String beginTime, String endTime, int pageNum, int pageSize,String phone,String productType) { |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | |
| | | List<UserPosition> userPositions = this.userPositionMapper.listByAgent(positionType, state, userId, ids, positionSn, begin_time, end_time,phone); |
| | | List<UserPosition> userPositions = this.userPositionMapper.listByAgent(positionType, state, userId, ids, positionSn, begin_time, end_time,phone,productType); |
| | | List<AdminPositionVO> adminPositionVOS = Lists.newArrayList(); |
| | | for (UserPosition position : userPositions) { |
| | | AdminPositionVO adminPositionVO = assembleAdminPositionVO(position); |
| | |
| | | adminPositionVO.setLockMsg(position.getLockMsg()); |
| | | |
| | | adminPositionVO.setStockPlate(position.getStockPlate()); |
| | | |
| | | PositionProfitVO positionProfitVO = UserPointUtil.getPositionProfitVO(position, priceServices.getNowPrice(position.getStockCode())); |
| | | BigDecimal nowPrice = BigDecimal.ZERO; |
| | | if(position.getStockSpell().equals("XAUUSD") || position.getStockSpell().equals("USOIL")){ |
| | | nowPrice = new BigDecimal(RedisShardedPoolUtils.get(position.getStockSpell())); |
| | | }else{ |
| | | nowPrice = priceServices.getNowPrice(position.getStockCode()); |
| | | } |
| | | PositionProfitVO positionProfitVO = UserPointUtil.getPositionProfitVO(position,nowPrice ); |
| | | adminPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose()); |
| | | adminPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose()); |
| | | adminPositionVO.setNow_price(positionProfitVO.getNowPrice()); |