| | |
| | | import com.nq.dao.*; |
| | | import com.nq.enums.EConfigKey; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.enums.EUserAssets; |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.*; |
| | | import com.nq.service.impl.IntradayOrderSerivceImpl; |
| | |
| | | |
| | | @Autowired |
| | | private UserPositionMapper userPositionMapper; |
| | | |
| | | @Autowired |
| | | IStockConfigServices iStockConfigServices; |
| | | |
| | | /** |
| | | * 添加智能日内 |
| | |
| | | intradayOrder.setIsLocked(vo.getIsLocked()); |
| | | intradayOrder.setStockId(stock.getId()); |
| | | |
| | | // 手续费率 |
| | | BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ; |
| | | |
| | | if(vo.getAuditStatus() == 2){ |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(EStockType.JP.getCode(), intradayOrder.getUserId()); |
| | | BigDecimal orderAmount = vo.getOrderAmount(); |
| | |
| | | return ServerResponse.createBySuccessMsg("操作成功"); |
| | | } |
| | | BigDecimal stockQuantity = new BigDecimal(intradayOrder.getStockQuantity());//股票数量 |
| | | BigDecimal totalPrice = intradayOrder.getStockPrice().multiply(stockQuantity);//订单总价 |
| | | BigDecimal orderTotalPrice = intradayOrder.getStockPrice().multiply(stockQuantity);//订单总价 |
| | | |
| | | //手续费 |
| | | BigDecimal orderFree = siteSettingBuyFee.multiply(orderTotalPrice); |
| | | BigDecimal totalPrice = orderFree.add(orderTotalPrice); |
| | | |
| | | if(intradayOrder.getOrderAmount().compareTo(totalPrice) < 0){ |
| | | return ServerResponse.createByErrorMsg("股票总价超过订单金额!"); |
| | | } |
| | | |
| | | |
| | | User user = userMapper.selectById(intradayOrder.getUserId()); |
| | | |
| | | |
| | | //结余资金返还账户 |
| | | BigDecimal surplusAmount = intradayOrder.getOrderAmount().subtract(totalPrice);//结余 |
| | |
| | | userPosition.setBuyOrderId(GeneratePosition.getPositionId()); |
| | | userPosition.setBuyOrderTime(new Date()); |
| | | userPosition.setBuyOrderPrice(intradayOrder.getStockPrice()); |
| | | userPosition.setOrderDirection((intradayOrder.getPriceType() == 0) ? "买涨" : "买跌"); |
| | | userPosition.setOrderDirection((intradayOrder.getPriceType() == 1) ? "买涨" : "买跌"); |
| | | userPosition.setOrderNum(intradayOrder.getStockQuantity()); |
| | | if (stock.getStockPlate() != null) { |
| | | userPosition.setStockPlate(stock.getStockPlate()); |
| | | } |
| | | userPosition.setIsLock(intradayOrder.getIsLocked()); |
| | | userPosition.setOrderLever(1); |
| | | userPosition.setOrderTotalPrice(totalPrice); |
| | | userPosition.setOrderTotalPrice(orderTotalPrice); |
| | | // 手续费 |
| | | userPosition.setOrderFee(BigDecimal.ZERO); |
| | | userPosition.setOrderFee(orderFree); |
| | | userPosition.setOrderSpread(BigDecimal.ZERO); |
| | | userPosition.setSpreadRatePrice(BigDecimal.ZERO); |
| | | BigDecimal profit_and_lose = new BigDecimal("0"); |
| | |
| | | userPosition.setOrderStayFee(BigDecimal.ZERO); |
| | | userPositionMapper.insert(userPosition); |
| | | |
| | | //结余资金返还账户 |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(EStockType.JP.getCode(), intradayOrder.getUserId()); |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(surplusAmount)); |
| | | userAssets.setFreezeMoney(userPosition.getOrderTotalPrice()); |
| | | userAssetsMapper.updateById(userAssets); |
| | | intradayOrder.setPositionOrder(userPosition.getId()); |
| | | intradayOrder.setPurchaseAmount(totalPrice); |