| | |
| | | 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.setStockQuantity(vo.getStockQuantity()); |
| | | intradayOrder.setPriceType(vo.getPriceType()); |
| | | intradayOrder.setStockPrice(new BigDecimal(vo.getStockPrice())); |
| | | intradayOrder.setAuditStatus(vo.getAuditStatus()); |
| | | intradayOrder.setAuditStatus(1); |
| | | intradayOrder.setOrderTime(DateUtil.parse(vo.getOrderTime(),"yyyy-MM-dd HH:mm:ss")); |
| | | intradayOrder.setIsLocked(vo.getIsLocked()); |
| | | intradayOrder.setStockId(stock.getId()); |
| | | |
| | | if(vo.getAuditStatus() == 2){ |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(EStockType.JP.getCode(), intradayOrder.getUserId()); |
| | | BigDecimal orderAmount = vo.getOrderAmount(); |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(orderAmount)); |
| | | userAssetsMapper.updateById(userAssets); |
| | | return ServerResponse.createBySuccessMsg("操作成功"); |
| | | } |
| | | // 手续费率 |
| | | BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ; |
| | | |
| | | 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.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(userAssets.getFreezeMoney().add(userPosition.getOrderTotalPrice())); |
| | | userAssetsMapper.updateById(userAssets); |
| | | intradayOrder.setPositionOrder(userPosition.getId()); |
| | | intradayOrder.setPurchaseAmount(totalPrice); |
| | | intradayOrderMapper.updateById(intradayOrder); |
| | | return ServerResponse.createBySuccessMsg("操作成功"); |
| | | } |
| | | |
| | | /** |
| | | * 驳回订单 |
| | | * @return |
| | | */ |
| | | @RequestMapping(value = {"rejectIntraday.do"}, method = {RequestMethod.POST}) |
| | | @ResponseBody |
| | | @Transactional(rollbackFor = Exception.class) // 异常时回滚 |
| | | public ServerResponse rejectIntraday(@RequestParam("id") Integer id) { |
| | | IntradayOrder intradayOrder = intradayOrderSerivce.getById(id); |
| | | if(intradayOrder.getAuditStatus() != 0){ |
| | | return ServerResponse.createByErrorMsg("订单已操作"); |
| | | } |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(EStockType.JP.getCode(), intradayOrder.getUserId()); |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(intradayOrder.getOrderAmount())); |
| | | userAssetsMapper.updateById(userAssets); |
| | | intradayOrder.setAuditStatus(2); |
| | | intradayOrderMapper.updateById(intradayOrder); |
| | | return ServerResponse.createBySuccessMsg("操作成功"); |
| | | } |
| | |
| | | @RequestMapping(value = {"deleteIntraday.do"}, method = {RequestMethod.POST}) |
| | | @ResponseBody |
| | | public ServerResponse deleteIntraday( @RequestParam("id") Integer id) { |
| | | IntradayOrder orderSerivceById = intradayOrderSerivce.getById(id); |
| | | if(orderSerivceById.getAuditStatus() == 0){ |
| | | return ServerResponse.createByErrorMsg("订单状态未审核,不允许删除"); |
| | | } |
| | | intradayOrderSerivce.removeById(id); |
| | | return ServerResponse.createBySuccessMsg("删除成功"); |
| | | } |