| | |
| | | package com.nq.controller; |
| | | |
| | | import cn.hutool.core.convert.Convert; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.dao.*; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.enums.EUserAssets; |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.IPriceServices; |
| | | import com.nq.service.IUserService; |
| | | import com.nq.service.IUserPositionService; |
| | | import com.nq.service.UserPositionCheckDzService; |
| | | import com.nq.service.impl.UserAssetsServices; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * @program: dabaogp |
| | |
| | | UserPositionCheckDzService service; |
| | | |
| | | @Autowired |
| | | UserPositionCheckDzMapper mapper; |
| | | |
| | | @Autowired |
| | | UserPositionMapper userPositionMapper; |
| | | |
| | | @Autowired |
| | | UserAssetsServices userAssetsServices; |
| | | |
| | | @Autowired |
| | | UserMapper userMapper; |
| | | |
| | | @Autowired |
| | | IPriceServices priceServices; |
| | | |
| | | @Autowired |
| | | StockDzMapper stockDzMapper; |
| | | IUserPositionService userPositionService; |
| | | |
| | | //大宗交易审核列表 |
| | | @RequestMapping({"getList.do"}) |
| | |
| | | @ResponseBody |
| | | public ServerResponse check(@RequestParam(value = "id") Integer id, |
| | | @RequestParam(value = "checkType") Integer checkType, |
| | | @RequestParam(value = "orderNum") Integer orderNum) { |
| | | @RequestParam(value = "orderNum", required = false) Integer orderNum, HttpServletRequest request) { |
| | | if(checkType != 2 && (id == null || checkType == null || orderNum == null)){ |
| | | return ServerResponse.createByErrorMsg("参数不能为空"); |
| | | return ServerResponse.createByErrorMsg("参数不能为空", request); |
| | | } |
| | | UserPositionCheckDz userPositionCheckDz = service.getById(id); |
| | | if(userPositionCheckDz == null){ |
| | | return ServerResponse.createByErrorMsg("订单不存在"); |
| | | } |
| | | if(userPositionCheckDz.getCheckType() != 0){ |
| | | return ServerResponse.createByErrorMsg("订单已审核"); |
| | | } |
| | | if(checkType == 2){ |
| | | userPositionCheckDz.setCheckType(checkType); |
| | | service.updateById(userPositionCheckDz); |
| | | return ServerResponse.createBySuccess("审核成功"); |
| | | } |
| | | User user = userMapper.selectById(userPositionCheckDz.getUserId()); |
| | | |
| | | StockDz stockDz = this.stockDzMapper.selectOne(new QueryWrapper<StockDz>().eq("id", userPositionCheckDz.getDzId())); |
| | | |
| | | UserAssets userAssets = userAssetsServices.assetsByTypeAndUserId(stockDz.getStockType(), user.getId()); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("用户账户有待补资金未补齐,审核失败"); |
| | | } |
| | | |
| | | BigDecimal nowPrice = stockDz.getNowPrice(); |
| | | |
| | | if (nowPrice.compareTo(new BigDecimal("0")) == 0) { |
| | | return ServerResponse.createByErrorMsg("股票价格0,请重试"); |
| | | } |
| | | userPositionCheckDz.setOrderNum(orderNum); |
| | | userPositionCheckDz.setOrderTotalPrice(nowPrice.multiply(new BigDecimal(orderNum.intValue()))); |
| | | BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(userPositionCheckDz.getOrderNum())); |
| | | BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100)); |
| | | BigDecimal availableBalance = fundratio.multiply(userAssets.getAvailableBalance()); |
| | | if (buyAmt.compareTo(availableBalance) > 0) { |
| | | return ServerResponse.createByErrorMsg("订单失败,配资不足"); |
| | | } |
| | | userPositionCheckDz.setCheckType(checkType); |
| | | service.updateById(userPositionCheckDz); |
| | | UserPosition userPosition = Convert.convert(UserPosition.class, userPositionCheckDz); |
| | | userPosition.setBuyOrderPrice(nowPrice); |
| | | userPosition.setId(null); |
| | | userPosition.setDzId(stockDz.getId()); |
| | | userPositionMapper.insert(userPosition); |
| | | userAssetsServices.availablebalanceChange(userAssets.getAccectType(), user.getId(), EUserAssets.BUY, buyAmt.negate(),"",""); |
| | | return ServerResponse.createBySuccessMsg("审核成功,订单已转客户持仓"); |
| | | return userPositionService.checkDz(id, checkType, orderNum ,request); |
| | | } |
| | | } |