| | |
| | | import com.google.common.collect.Maps; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.dao.StockConfigMapper; |
| | | import com.nq.dao.UserPositionMapper; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.enums.EUserAssets; |
| | | import com.nq.pojo.*; |
| | | import com.nq.service.*; |
| | | import com.nq.utils.PropertiesUtil; |
| | |
| | | import java.util.Map; |
| | | import java.util.concurrent.locks.Lock; |
| | | import java.util.concurrent.locks.ReentrantLock; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpSession; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | StockConfigMapper stockConfigMapper; |
| | | |
| | | @Autowired |
| | | UserPositionMapper userPositionMapper; |
| | | |
| | | private static final ThreadLocal<Boolean> orderCreated = ThreadLocal.withInitial(() -> false); |
| | | private final Lock lock = new ReentrantLock(); |
| | |
| | | //用户平仓操作 |
| | | @RequestMapping({"sell.do"}) |
| | | @ResponseBody |
| | | public ServerResponse sell(HttpServletRequest request, @RequestParam("positionSn") String positionSn,@RequestParam("number") Integer number) { |
| | | return this.iUserPositionService.sell(positionSn,1,number,request); |
| | | public ServerResponse sell(HttpServletRequest request, @RequestParam("positionSn") String positionSn, |
| | | @RequestParam("number") Integer number, |
| | | @RequestParam(value = "targetPrice", required = false) String targetPrice |
| | | |
| | | ) { |
| | | return this.iUserPositionService.sell(positionSn,1,number,targetPrice,request); |
| | | } |
| | | |
| | | //用户仓位查询 |
| | | @RequestMapping({"getPosition.do"}) |
| | | @ResponseBody |
| | | public ServerResponse getPosition(HttpServletRequest request, @RequestParam("stock") String stock, |
| | | @RequestParam("stockType") Integer stockType) { |
| | | User user = this.iUserService.getCurrentRefreshUser(request); |
| | | if (user == null) { |
| | | return ServerResponse.createByErrorMsg("请重新登录",request); |
| | | } |
| | | LambdaQueryWrapper<UserPosition> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(UserPosition::getUserId, user.getId()); |
| | | queryWrapper.isNull(UserPosition::getSellOrderId); |
| | | if (stockType == 1) { |
| | | queryWrapper.eq(UserPosition::getStockName, stock); |
| | | } else { |
| | | queryWrapper.eq(UserPosition::getStockCode, stock); |
| | | } |
| | | try { |
| | | UserPosition userPosition = userPositionMapper.selectOne(queryWrapper); |
| | | return ServerResponse.createBySuccess(userPosition); |
| | | }catch (Exception e){ |
| | | log.error("用户仓位查询失败",e.getMessage()); |
| | | } |
| | | return ServerResponse.createByErrorMsg("当前产品有多个持仓方向,不支持挂单操作!",request); |
| | | } |
| | | |
| | | //一键用户平仓操作 |
| | | @RequestMapping({"allsell.do"}) |
| | |
| | | if(ObjectUtil.isNotEmpty(userPendingorder)){ |
| | | userPendingorder.setPositionType(2); |
| | | } |
| | | if(userPendingorder.getHangingOrderType() == 2){ |
| | | userPendingorderService.updateById(userPendingorder); |
| | | return ServerResponse.createBySuccess("撤销挂单成功",request); |
| | | } |
| | | userPendingorderService.updateById(userPendingorder); |
| | | iUserAssetsServices.availablebalanceChange(userPendingorder.getStockGid().equals("ST") ? userPendingorder.getStockGid() : "USD", |
| | | userPendingorder.getUserId(), |
| | | EUserAssets.CLOSE_POSITION_RETURN_SECURITY_DEPOSIT, |
| | | userPendingorder.getOrderTotalPrice(), "", ""); |
| | | return ServerResponse.createBySuccess("撤销挂单成功",request); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("挂单操作-列表 = {}", e); |
| | | } |