From 4bb0b890438349a7cfd7ab2dc30999346a5acf58 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Wed, 30 Apr 2025 01:18:10 +0800
Subject: [PATCH] 1
---
src/main/java/com/nq/controller/protol/UserController.java | 186 +++++++++++++++++++++++++++++++++++++---------
1 files changed, 149 insertions(+), 37 deletions(-)
diff --git a/src/main/java/com/nq/controller/protol/UserController.java b/src/main/java/com/nq/controller/protol/UserController.java
index 5f185ee..8fcee31 100644
--- a/src/main/java/com/nq/controller/protol/UserController.java
+++ b/src/main/java/com/nq/controller/protol/UserController.java
@@ -1,19 +1,25 @@
package com.nq.controller.protol;
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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.pojo.ApplyLever;
-import com.nq.pojo.StockSubscribe;
-import com.nq.pojo.UserStockSubscribe;
+import com.nq.enums.EUserAssets;
+import com.nq.pojo.*;
import com.nq.service.*;
import com.nq.utils.PropertiesUtil;
import java.math.BigDecimal;
+import java.util.Collections;
+import java.util.List;
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;
@@ -61,10 +67,17 @@
@Autowired
IUserRechargeService iUserRechargeService;
-
+ @Autowired
+ IUserAssetsServices iUserAssetsServices;
@Autowired
IApplyLeverServices iApplyLeverServices;
+
+ @Autowired
+ StockConfigMapper stockConfigMapper;
+
+ @Autowired
+ UserPositionMapper userPositionMapper;
private static final ThreadLocal<Boolean> orderCreated = ThreadLocal.withInitial(() -> false);
private final Lock lock = new ReentrantLock();
@@ -123,12 +136,39 @@
buyOrderCreated.set(true);
return this.iUserPositionService.buy(stockId, buyNum, buyType, lever,profitTarget,stopLoss, request);
} catch (Exception e) {
+ e.printStackTrace();
return ServerResponse.createByErrorMsg("订单异常,请稍后重试", request);
} finally{
buyLock.unlock();
buyOrderCreated.set(false);
}
}
+
+ //用户下单买入股票
+ @RequestMapping({"goldCrudeOilbuy.do"})
+ @ResponseBody
+ public ServerResponse goldCrudeOilbuy(@RequestParam("name") String name,
+ @RequestParam("buyNum") Integer buyNum,
+ @RequestParam("buyType") Integer buyType,
+ @RequestParam("lever") Integer lever,
+ @RequestParam(value = "profitTarget",required = false)
+ BigDecimal profitTarget,@RequestParam(value = "stopLoss",required = false) BigDecimal stopLoss, HttpServletRequest request) {
+ buyLock.lock();
+ try {
+ if (buyOrderCreated.get()) {
+ return ServerResponse.createByErrorMsg("当前下单人数过多,请稍后重试", request);
+ }
+ buyOrderCreated.set(true);
+ return this.iUserPositionService.goldCrudeOilbuy(name, buyNum,buyType,lever,profitTarget,stopLoss, request);
+ } catch (Exception e) {
+ e.printStackTrace();
+ return ServerResponse.createByErrorMsg("订单异常,请稍后重试", request);
+ } finally{
+ buyLock.unlock();
+ buyOrderCreated.set(false);
+ }
+ }
+
//修改涨跌板
@RequestMapping({"updateProfitTarget.do"})
@ResponseBody
@@ -144,10 +184,39 @@
//用户平仓操作
@RequestMapping({"sell.do"})
@ResponseBody
- public ServerResponse sell(HttpServletRequest request, @RequestParam("positionSn") String positionSn) {
- return this.iUserPositionService.sell(positionSn, 1,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"})
@@ -160,54 +229,78 @@
}
}
-
-
-
-
//挂单操作-添加
@RequestMapping({"addOrder.do"})
@ResponseBody
- public ServerResponse addOrder(HttpServletRequest request,
- @RequestParam("stockId") String stockId,
+ public ServerResponse addOrder(@RequestParam("stockId") Integer stockId,
@RequestParam("buyNum") Integer buyNum,
@RequestParam("buyType") Integer buyType,
@RequestParam("lever") Integer lever,
- @RequestParam(value = "profitTarget",required = false) BigDecimal profitTarget,
- @RequestParam(value = "stopTarget",required = false) BigDecimal stopTarget,
- @RequestParam(value = "targetPrice",required = false) BigDecimal targetPrice) {
+ @RequestParam("targetPrice") String targetPrice,
+ @RequestParam(value = "profitTarget",required = false)
+ BigDecimal profitTarget,@RequestParam(value = "stopLoss",required = false) BigDecimal stopLoss, HttpServletRequest request) {
ServerResponse serverResponse = null;
try {
- serverResponse = this.userPendingorderService.addOrder(stockId, buyNum, buyType, lever,profitTarget,stopTarget,targetPrice, request);
+ serverResponse = this.userPendingorderService.addOrder(stockId, buyNum, buyType, lever,profitTarget,stopLoss,targetPrice, request);
} catch (Exception e) {
log.error("挂单操作-添加 = {}", e);
}
return serverResponse;
}
- //挂单操作-列表
- @RequestMapping({"orderList.do"})
+
+ //挂单操作-添加
+ @RequestMapping({"hjyyAddOrder.do"})
@ResponseBody
- public ServerResponse orderList(HttpServletRequest request) {
+ public ServerResponse hjyyAddOrder(@RequestParam("name") String name,
+ @RequestParam("buyNum") Integer buyNum,
+ @RequestParam("buyType") Integer buyType,
+ @RequestParam("lever") Integer lever,
+ @RequestParam("targetPrice") String targetPrice,
+ @RequestParam(value = "profitTarget",required = false)
+ BigDecimal profitTarget,@RequestParam(value = "stopLoss",required = false) BigDecimal stopLoss, HttpServletRequest request) {
ServerResponse serverResponse = null;
try {
+ serverResponse = this.userPendingorderService.hjyyAddOrder(name, buyNum, buyType, lever,profitTarget,stopLoss,targetPrice, request);
+ } catch (Exception e) {
+ log.error("挂单操作-添加 = {}", e);
+ }
+ return serverResponse;
+ }
- serverResponse = this.userPendingorderService.orderList(request);
+ //挂单操作-撤销
+ @RequestMapping({"revocation.do"})
+ @ResponseBody
+ public ServerResponse revocation(@RequestParam("id") Integer id, HttpServletRequest request) {
+ try {
+ synchronized (id){
+ User user = this.iUserService.getCurrentRefreshUser(request);
+ if(ObjectUtil.isEmpty(user)){
+ return ServerResponse.createByErrorMsg("请重新登录,未找到用户!",request);
+ }
+ UserPendingorder userPendingorder = userPendingorderService.getOne(new LambdaQueryWrapper<>(UserPendingorder.class)
+ .eq(UserPendingorder::getUserId, user.getId())
+ .eq(UserPendingorder::getId, id)
+ );
+ 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);
}
- return serverResponse;
+ return ServerResponse.createByErrorMsg("撤销挂单失败!",request);
}
- //挂单操作-删除
- @RequestMapping({"delOrder.do"})
- @ResponseBody
- public ServerResponse delOrder(HttpServletRequest request, @RequestParam("id") Integer id) {
- ServerResponse serverResponse = null;
- try {
- serverResponse = this.userPendingorderService.delOrder(id, request);
- } catch (Exception e) {
- log.error("挂单操作-删除 = {}", e);
- }
- return serverResponse;
- }
+
//用户追加保证金操作
@RequestMapping({"addmargin.do"})
@@ -327,14 +420,33 @@
return this.iUserStockSubscribeService.userSubmit(id,request);
}
- @RequestMapping({"transfer.do"})
+// @RequestMapping({"transfer.do"})
+// @ResponseBody
+// public ServerResponse transfer(@RequestParam("fromType") String fromType, @RequestParam("toType") String toType,
+// @RequestParam("amt") String amt, HttpServletRequest request) {
+// return iUserService.transfer(fromType, toType, amt,request);
+// }
+
+ @RequestMapping("transfer.do")
@ResponseBody
- public ServerResponse transfer(@RequestParam("fromType") String fromType, @RequestParam("toType") String toType,
- @RequestParam("amt") String amt, HttpServletRequest request) {
- return iUserService.transfer(fromType, toType, amt,request);
+ public ServerResponse transfer(
+ @RequestParam("userId") Integer userId,
+ @RequestParam("disbursementAccount") String disbursementAccount,
+ @RequestParam("depositAccount") String depositAccount,
+ @RequestParam("amt") String amt, HttpServletRequest request
+ ){
+ return iUserAssetsServices.transfer(userId,disbursementAccount,depositAccount,amt,request);
}
+ @RequestMapping("usdtExchangeRate.do")
+ @ResponseBody
+ public ServerResponse usdtExchangeRate(HttpServletRequest request
+ ){
+ StockConfig stockConfig = stockConfigMapper.selectOne(new LambdaQueryWrapper<StockConfig>().eq(StockConfig::getCKey, "usdt_parities"));
+ return ServerResponse.createBySuccess(stockConfig.getCValue());
+ }
+
/**
* vip抢筹 (涨停板买入)
*
--
Gitblit v1.9.3