From 5ce072de78ae263b52dc0e2be5c7391b23c093cf Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Sun, 27 Apr 2025 18:29:22 +0800
Subject: [PATCH] 1
---
src/main/resources/mapper/UserPositionMapper.xml | 6
src/main/java/com/nq/controller/backend/AdminPendingorder.java | 48 --
src/main/java/com/nq/controller/protol/UserController.java | 92 +++-
src/main/java/com/nq/utils/task/stock/StockTask.java | 124 ++++++-
src/main/java/com/nq/service/impl/UserPositionServiceImpl.java | 102 +++--
src/main/java/com/nq/service/IUserPositionService.java | 4
src/main/java/com/nq/service/UserPendingorderService.java | 18
src/main/java/com/nq/service/impl/UserPendingorderServiceImpl.java | 541 ++++++++++---------------------
src/main/java/com/nq/pojo/UserPendingorder.java | 56 ++-
src/main/java/com/nq/controller/protol/UserPositionController.java | 6
src/main/java/com/nq/utils/translate/GoogleTranslateUtil.java | 1
src/main/java/com/nq/common/interceptor/ApiUserAuthorityInterceptor.java | 2
12 files changed, 444 insertions(+), 556 deletions(-)
diff --git a/src/main/java/com/nq/common/interceptor/ApiUserAuthorityInterceptor.java b/src/main/java/com/nq/common/interceptor/ApiUserAuthorityInterceptor.java
index 9a56c8c..8265f41 100644
--- a/src/main/java/com/nq/common/interceptor/ApiUserAuthorityInterceptor.java
+++ b/src/main/java/com/nq/common/interceptor/ApiUserAuthorityInterceptor.java
@@ -184,13 +184,11 @@
public User getCurrentUser(HttpServletRequest request) {
String property = PropertiesUtil.getProperty("user.cookie.name");
- System.out.println(property);
String loginToken = request.getHeader(property);
if (loginToken == null) {
System.out.println("loginToken is null");
return null;
}
- System.out.println(loginToken);
String userJson = RedisShardedPoolUtils.get(loginToken);
if (userJson == null||"".equals(userJson)){
diff --git a/src/main/java/com/nq/controller/backend/AdminPendingorder.java b/src/main/java/com/nq/controller/backend/AdminPendingorder.java
index f330f0a..767812b 100644
--- a/src/main/java/com/nq/controller/backend/AdminPendingorder.java
+++ b/src/main/java/com/nq/controller/backend/AdminPendingorder.java
@@ -18,54 +18,6 @@
@Autowired
UserPendingorderService userPendingorderService;
- /**
- * 管理员获取挂单列表
- * @param pageNum
- * @param pageSize
- * @param keywords
- * @param status
- * @param request
- * @return
- */
- @GetMapping({"orderList.do"})
- public ServerResponse orderList(@RequestParam(value = "pageNum", defaultValue = "1") int pageNum, @RequestParam(value = "pageSize", defaultValue = "10") int pageSize,@RequestParam(value = "keywords", required = false) String keywords,@RequestParam(value = "status", required = false) String status, HttpServletRequest request) {
- return userPendingorderService.orderListByAdmin( pageNum, pageSize, keywords, status, request);
- }
-
- /**
- * 管理员删除挂单
- * @param id
- * @param request
- * @return
- */
- @RequestMapping({"delOrder.do"})
- public ServerResponse delOrder(Integer id, HttpServletRequest request) {
- return userPendingorderService.delOrderByAdmin(id);
- }
-
- /**
- * 管理员修改挂单
- * @param UserPendingorder
- * @param request
- * @return
- */
- @RequestMapping({"updateOrder.do"})
- public ServerResponse updateOrder(UserPendingorder UserPendingorder, HttpServletRequest request) {
- return userPendingorderService.updateOrderByAdmin(UserPendingorder);
- }
-
- @RequestMapping({"addOrder.do"})
- public ServerResponse addOrder(@RequestParam(value = "userPhone")String phone,
- @RequestParam(value = "buyNum")String buyNum,
- @RequestParam(value = "stockCode")String code,
- @RequestParam(value = "buyType")String buyType,
- @RequestParam(value = "lever")String lever,
- @RequestParam(value = "targetPrice")String targetPrice,
- HttpServletRequest request) {
- return userPendingorderService.addOrderByAdmin(phone, buyNum,code, buyType, lever, targetPrice, request);
- }
-
-
diff --git a/src/main/java/com/nq/controller/protol/UserController.java b/src/main/java/com/nq/controller/protol/UserController.java
index 31cf362..dec81eb 100644
--- a/src/main/java/com/nq/controller/protol/UserController.java
+++ b/src/main/java/com/nq/controller/protol/UserController.java
@@ -1,16 +1,19 @@
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.enums.EStockType;
-import com.nq.pojo.ApplyLever;
-import com.nq.pojo.StockSubscribe;
-import com.nq.pojo.UserStockSubscribe;
+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;
@@ -66,6 +69,9 @@
@Autowired
IApplyLeverServices iApplyLeverServices;
+
+ @Autowired
+ StockConfigMapper stockConfigMapper;
private static final ThreadLocal<Boolean> orderCreated = ThreadLocal.withInitial(() -> false);
private final Lock lock = new ReentrantLock();
@@ -147,7 +153,7 @@
return ServerResponse.createByErrorMsg("当前下单人数过多,请稍后重试", request);
}
buyOrderCreated.set(true);
- return this.iUserPositionService.goldCrudeOilbuy(name, buyNum,lever,profitTarget,stopLoss, request);
+ return this.iUserPositionService.goldCrudeOilbuy(name, buyNum,buyType,lever,profitTarget,stopLoss, request);
} catch (Exception e) {
e.printStackTrace();
return ServerResponse.createByErrorMsg("订单异常,请稍后重试", request);
@@ -188,54 +194,70 @@
}
}
-
-
-
-
//挂单操作-添加
@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);
+ }
+ userPendingorderService.updateById(userPendingorder);
+ 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"})
@@ -374,6 +396,14 @@
}
+ @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抢筹 (涨停板买入)
*
diff --git a/src/main/java/com/nq/controller/protol/UserPositionController.java b/src/main/java/com/nq/controller/protol/UserPositionController.java
index 058f0a6..6992e6b 100644
--- a/src/main/java/com/nq/controller/protol/UserPositionController.java
+++ b/src/main/java/com/nq/controller/protol/UserPositionController.java
@@ -29,9 +29,11 @@
@RequestParam(value = "state", required = false) Integer state,
@RequestParam(value = "stockCode", required = false) String stockCode,
@RequestParam(value = "stockSpell", required = false) String stockSpell,
- @RequestParam(value = "stockType", required = false) String stockType
+ @RequestParam(value = "stockType", required = false) String stockType,
+ @RequestParam(value = "pendingStatus", required = false) Integer pendingStatus
+
) {
- return this.iUserPositionService.findMyPositionByCodeAndSpell(stockCode, stockSpell, state, request, pageNum, pageSize,stockType);
+ return this.iUserPositionService.findMyPositionByCodeAndSpell(stockCode, stockSpell, state, request, pageNum, pageSize,stockType, pendingStatus);
}
//根据股票代码查询用户最早入仓股票
diff --git a/src/main/java/com/nq/pojo/UserPendingorder.java b/src/main/java/com/nq/pojo/UserPendingorder.java
index 0066796..c551a3b 100644
--- a/src/main/java/com/nq/pojo/UserPendingorder.java
+++ b/src/main/java/com/nq/pojo/UserPendingorder.java
@@ -17,28 +17,40 @@
public class UserPendingorder implements Serializable {
@TableId(type = IdType.AUTO,value = "id")
private Integer id;
-
+ private Integer positionType;//创位类型 1 挂单中 2撤销 0挂单成功
+ private String positionSn;
private Integer userId;
-
- private String stockId;
-
- private Integer buyNum;
-
- private Integer buyType;
-
- private Integer lever;
-
- private BigDecimal profitTarget;
-
- private BigDecimal stopTarget;
-
- private BigDecimal nowPrice;
-
- private BigDecimal targetPrice;
-
- private Date addTime;
-
- private Integer status;
-
+ private String nickName;
+ private Integer agentId;
+ private String stockName;
+ private String stockCode;
+ private String stockGid;
+ private String stockSpell;
+ private String buyOrderId;
+ private Date buyOrderTime;
+ private BigDecimal buyOrderPrice;
+ private String OrderId;
+ private Date OrderTime;
+ private BigDecimal OrderPrice;
+ private BigDecimal profitTargetPrice;
+ private BigDecimal stopTargetPrice;
+ private String orderDirection;
+ private Integer orderNum;
+ private Integer orderLever;
+ private BigDecimal orderTotalPrice;
+ private BigDecimal orderFee;
+ private BigDecimal orderSpread;
+ private BigDecimal orderStayFee;
+ private Integer orderStayDays;
+ private BigDecimal profitAndLose;
+ private BigDecimal allProfitAndLose;
+ private Integer isLock;
+ private String lockMsg;
+ private String stockPlate;
+ private BigDecimal spreadRatePrice;
+ private BigDecimal marginAdd;
+ private Integer dzId;
+ private String amountToBeCovered;
+ private Integer newId;
private static final long serialVersionUID = 1L;
}
\ No newline at end of file
diff --git a/src/main/java/com/nq/service/IUserPositionService.java b/src/main/java/com/nq/service/IUserPositionService.java
index 936134d..44121e8 100644
--- a/src/main/java/com/nq/service/IUserPositionService.java
+++ b/src/main/java/com/nq/service/IUserPositionService.java
@@ -28,7 +28,7 @@
UserPositionVO findByPostionSn(String positionSn);
ServerResponse<PageInfo> findMyPositionByCodeAndSpell(String paramString1, String paramString2, Integer paramInteger,
HttpServletRequest paramHttpServletRequest,
- int paramInt1, int paramInt2,String stockType);
+ int paramInt1, int paramInt2,String stockType,Integer pendingStatus);
PositionVO findUserPositionAllProfitAndLose(Integer paramInteger);
@@ -86,5 +86,5 @@
void stockConstraint(List<UserPosition> userPositions);
- ServerResponse goldCrudeOilbuy(String name, Integer buyNum, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest requestrequest);
+ ServerResponse goldCrudeOilbuy(String name, Integer buyNum,Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest requestrequest);
}
diff --git a/src/main/java/com/nq/service/UserPendingorderService.java b/src/main/java/com/nq/service/UserPendingorderService.java
index 4c86362..6816d83 100644
--- a/src/main/java/com/nq/service/UserPendingorderService.java
+++ b/src/main/java/com/nq/service/UserPendingorderService.java
@@ -15,20 +15,8 @@
*/
public interface UserPendingorderService extends IService<UserPendingorder> {
- ServerResponse addOrder(String stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, BigDecimal targetPrice, HttpServletRequest request);
+ ServerResponse addOrder(Integer paramInteger1, Integer paramInteger2, Integer paramInteger3,
+ Integer paramInteger4,BigDecimal paramInteger5,BigDecimal paramInteger6,String targetPrice,HttpServletRequest paramHttpServletRequest) ;
- ServerResponse orderList( HttpServletRequest request);
-
- void orderTask();
-
- ServerResponse delOrder(Integer id, HttpServletRequest request);
-
-
- ServerResponse orderListByAdmin(int pageNum, int pageSize, String keywords, String status, HttpServletRequest request);
-
- ServerResponse updateOrderByAdmin(UserPendingorder userPendingorder);
-
- ServerResponse addOrderByAdmin(String phone, String buyNum,String code, String buyType, String lever, String targetPrice, HttpServletRequest request);
-
- ServerResponse delOrderByAdmin(Integer id);
+ ServerResponse hjyyAddOrder(String name, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopLoss, String targetPrice, HttpServletRequest request);
}
diff --git a/src/main/java/com/nq/service/impl/UserPendingorderServiceImpl.java b/src/main/java/com/nq/service/impl/UserPendingorderServiceImpl.java
index f5637cb..85f1f7c 100644
--- a/src/main/java/com/nq/service/impl/UserPendingorderServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserPendingorderServiceImpl.java
@@ -5,6 +5,7 @@
import java.util.Date;
import java.util.List;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -12,8 +13,12 @@
import com.github.pagehelper.PageInfo;
import com.nq.common.ServerResponse;
import com.nq.dao.*;
+import com.nq.enums.EConfigKey;
+import com.nq.enums.EUserAssets;
import com.nq.pojo.*;
import com.nq.service.*;
+import com.nq.utils.KeyUtils;
+import com.nq.utils.stock.GeneratePosition;
import com.nq.utils.timeutil.DateTimeUtil;
import com.nq.utils.PropertiesUtil;
import com.nq.utils.redis.JsonUtil;
@@ -46,390 +51,192 @@
@Autowired
private IUserService iUserService;
@Autowired
- private IUserPositionService iUserPositionService;
+ private IUserAssetsServices iUserAssetsServices;
@Autowired
- private SiteTaskLogMapper siteTaskLogMapper;
+ ISiteProductService iSiteProductService;
@Autowired
- private UserMapper userMapper;
+ IStockConfigServices iStockConfigServices;
@Autowired
- private StockIndexMapper stockIndexMapper;
+ IPriceServices priceServices;
@Autowired
- private IStockIndexService iStockIndexService;
- @Autowired
- private IUserIndexPositionService iUserIndexPositionService;
- @Autowired
- private IStockCoinService iStockCoinService;
- @Autowired
- private IStockFuturesService iStockFuturesService;
- @Autowired
- private ISiteSettingService iSiteSettingService;
- @Autowired
- private UserPositionMapper userPositionMapper;
-
+ ITradingHourService tradingHourService;
@Override
- public ServerResponse addOrder(String stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, BigDecimal targetPrice, HttpServletRequest request) {
+ public ServerResponse addOrder(Integer stockId, Integer buyNum, Integer buyType,
+ Integer lever, BigDecimal profitTarget,
+ BigDecimal stopTarget,String targetPrice, HttpServletRequest request) {
+ SiteProduct siteProduct = iSiteProductService.getProductSetting();
+
User user = this.iUserService.getCurrentRefreshUser(request);
+ synchronized (user.getId()){
+ if (siteProduct.getRealNameDisplay() && user.getIsActive() != 2) {
+ return ServerResponse.createByErrorMsg("订单失败,请先实名认证", request);
+ }
+ // 手续费率
+ BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ;
- if (user == null) {
- return ServerResponse.createByErrorMsg("Please log in first");
- }
- SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
- if (buyNum.intValue() < siteSetting.getBuyMinNum().intValue()) {
- return ServerResponse.createByErrorMsg("The pending order failed, and the purchased quantity was less than" + siteSetting
- .getBuyMinNum() + "stocks");
- }
- if (buyNum.intValue() > siteSetting.getBuyMaxNum().intValue()) {
- return ServerResponse.createByErrorMsg("The pending order failed because the purchased quantity was greater than" + siteSetting
- .getBuyMaxNum() + "stocks");
- }
- UserPendingorder userPendingorder = userPendingorderMapper.selectOne(new QueryWrapper<UserPendingorder>().eq("user_id", user.getId()).eq("stock_id", stockId).eq("status", 0));
- if (userPendingorder != null) {
- return ServerResponse.createByErrorMsg("Please do not repeat the order");
- }
+ if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) {
+ return ServerResponse.createByErrorMsg("订单失败,帐户已被锁定", request);
+ }
- userPendingorder = new UserPendingorder();
- userPendingorder.setUserId(user.getId());
- userPendingorder.setStockId(stockId);
- userPendingorder.setBuyNum(buyNum);
- userPendingorder.setBuyType(buyType);
- userPendingorder.setLever(lever);
- userPendingorder.setProfitTarget(profitTarget);
- userPendingorder.setStopTarget(stopTarget);
- userPendingorder.setNowPrice(new BigDecimal(0));
- userPendingorder.setTargetPrice(targetPrice);
- userPendingorder.setAddTime(new Date());
- userPendingorder.setStatus(0);
- int ret = userPendingorderMapper.insert(userPendingorder);
- if (ret > 0) {
- return ServerResponse.createBySuccessMsg("If the pending order is successfully added, the order will be automatically placed if the order conditions are met");
- }
- return ServerResponse.createByErrorMsg("Add failure");
+ Stock stock = stockMapper.selectByPrimaryKey(stockId);
+ if (stock == null) {
+ return ServerResponse.createByErrorMsg("订单失败,股票代码不存在", request);
+ }
+ //判断股票是否在可交易时间段
+ Boolean b = tradingHourService.timeCheck(stock.getStockCode());
+ if (!b) {
+ return ServerResponse.createByErrorMsg("订单失败,不在交易时间之内", request);
+ }
+
+ StockConfig mainBuyConfig = iStockConfigServices.queryByKey(EConfigKey.MIN_BUY.getCode());
+
+ if(buyNum<Integer.parseInt(mainBuyConfig.getCValue())){
+ return ServerResponse.createByErrorMsg("最低购买数量"+mainBuyConfig.getCValue(), request);
+ }
+
+ UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(stock.getStockType(), user.getId());
+ StockConfig maxBuyConfig = iStockConfigServices.queryByKey(EConfigKey.MAX_BUY.getCode());
+ if(buyNum<Integer.parseInt(mainBuyConfig.getCValue())){
+ return ServerResponse.createByErrorMsg("最高购买数量"+maxBuyConfig.getCValue(), request);
+ }
+ if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
+ return ServerResponse.createByErrorMsg("请先缴清待补资金", request);
+ }
+ if (stock.getIsLock() != 0) {
+ return ServerResponse.createByErrorMsg("订单失败,股票被锁定", request);
+ }
+
+ if (!priceServices.isLimitUpBuy(stock.getStockCode())) {
+ return ServerResponse.createByErrorMsg("暂无配额", request);
+ }
+
+ //股票类型 现价 数据源的处理
+ BigDecimal nowPrice = new BigDecimal(targetPrice);
+
+ if (nowPrice.compareTo(new BigDecimal("0")) == 0) {
+ return ServerResponse.createByErrorMsg("报价0,请稍后再试", request);
+ }
+
+ BigDecimal buyAmt = nowPrice.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever));
+ BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt);
+
+ BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
+ BigDecimal availableBalance = fundratio.multiply(userAssets.getAvailableBalance());
+ if (availableBalance.compareTo(buyAmt.add(orderFree)) < 0) {
+ return ServerResponse.createByErrorMsg("订单失败,配资不足", request);
+ }
+ UserPendingorder userPendingorder = new UserPendingorder();
+ if (profitTarget != null && profitTarget.compareTo(new BigDecimal("0")) > 0) {
+ userPendingorder.setProfitTargetPrice(profitTarget);
+ }
+ if (stopTarget != null && stopTarget.compareTo(new BigDecimal("0")) > 0) {
+ userPendingorder.setStopTargetPrice(stopTarget);
+ }
+ userPendingorder.setPositionType(1);
+ userPendingorder.setPositionSn(KeyUtils.getUniqueKey());
+ userPendingorder.setUserId(user.getId());
+ userPendingorder.setNickName(user.getRealName());
+ userPendingorder.setAgentId(user.getAgentId());
+ userPendingorder.setStockCode(stock.getStockCode());
+ userPendingorder.setStockName(stock.getStockName());
+ userPendingorder.setStockGid(stock.getStockType());
+ userPendingorder.setStockSpell(stock.getStockSpell());
+ userPendingorder.setBuyOrderId(GeneratePosition.getPositionId());
+ userPendingorder.setBuyOrderTime(new Date());
+ userPendingorder.setBuyOrderPrice(nowPrice);
+ userPendingorder.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌");
+ userPendingorder.setOrderNum(buyNum);
+ if (stock.getStockPlate() != null) {
+ userPendingorder.setStockPlate(stock.getStockPlate());
+ }
+ userPendingorder.setIsLock(Integer.valueOf(0));
+ userPendingorder.setOrderLever(lever);
+ userPendingorder.setOrderTotalPrice(buyAmt);
+ // 手续费
+
+ userPendingorder.setOrderFee(orderFree);
+ userPendingorder.setOrderSpread(BigDecimal.ZERO);
+ userPendingorder.setSpreadRatePrice(BigDecimal.ZERO);
+ BigDecimal profit_and_lose = new BigDecimal("0");
+ userPendingorder.setProfitAndLose(profit_and_lose);
+ userPendingorder.setAllProfitAndLose(profit_and_lose.add(orderFree));
+ userPendingorder.setOrderStayDays(Integer.valueOf(0));
+ userPendingorder.setOrderStayFee(BigDecimal.ZERO);
+ userPendingorderMapper.insert(userPendingorder);
+ return ServerResponse.createBySuccessMsg("挂单成功", request);
+ }
}
@Override
- public ServerResponse orderList(HttpServletRequest request) {
+ public ServerResponse hjyyAddOrder(String name, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopLoss, String targetPrice, HttpServletRequest request) {
+ SiteProduct siteProduct = iSiteProductService.getProductSetting();
- String property = PropertiesUtil.getProperty("user.cookie.name");
- String header = request.getHeader(property);
-// log.info("header:{}",header);
- if (header != null) {
- String userJson = RedisShardedPoolUtils.get(header);
- User user = (User) JsonUtil.string2Obj(userJson, User.class);
-// log.info("user:{}",user);
- if (user != null) {
- List<UserPendingorder> userPendingorders = userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("user_id", user.getId()));
-
- List UserPendingorderList = new ArrayList();
-
-
- for (UserPendingorder userPendingorder : userPendingorders) {
- UserPendingorderVO userPendingorderVO = new UserPendingorderVO();
- //挂单-指数
- //挂单-股票
- Stock stock = stockMapper.findStockByCode(userPendingorder.getStockId());
- StockListVO stockListVO = new StockListVO();
- stockListVO = StockApi.getStockRealTime(
- stock);
- String nowPrice = stockListVO.getNowPrice();
- if (nowPrice == null) {
- nowPrice = String.valueOf(0);
- }
- userPendingorderVO.setNowPrice(new BigDecimal(nowPrice));
- userPendingorderVO.setStockName(stock.getStockName());
- userPendingorderVO.setStockId(stock.getStockCode());
- userPendingorderVO.setBuyNum(userPendingorder.getBuyNum());
- userPendingorderVO.setBuyType(userPendingorder.getBuyType());
- userPendingorderVO.setLever(userPendingorder.getLever());
- userPendingorderVO.setProfitTarget(userPendingorder.getProfitTarget());
- userPendingorderVO.setStopTarget(userPendingorder.getStopTarget());
- userPendingorderVO.setTargetPrice(userPendingorder.getTargetPrice());
- userPendingorderVO.setAddTime(userPendingorder.getAddTime());
- userPendingorderVO.setStatus(userPendingorder.getStatus());
- userPendingorderVO.setId(userPendingorder.getId());
- UserPendingorderList.add(userPendingorderVO);
- }
- return ServerResponse.createBySuccess(UserPendingorderList);
+ User user = this.iUserService.getCurrentRefreshUser(request);
+ synchronized (user.getId()){
+ if (siteProduct.getRealNameDisplay() && user.getIsActive() != 2) {
+ return ServerResponse.createByErrorMsg("订单失败,请先实名认证", request);
}
- }
- return ServerResponse.createByErrorMsg("数据异常");
+ // 手续费率
+ BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ;
+ if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) {
+ return ServerResponse.createByErrorMsg("订单失败,帐户已被锁定", request);
+ }
+
+ BigDecimal price = new BigDecimal(targetPrice);
+
+ UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId("USDT", user.getId());
+
+ if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
+ return ServerResponse.createByErrorMsg("挂单失败,请先缴清待补资金", request);
+ }
+
+ if (price.compareTo(new BigDecimal("0")) == 0) {
+ return ServerResponse.createByErrorMsg("报价0,请稍后再试", request);
+ }
+
+ BigDecimal buyAmt = price.multiply(new BigDecimal(buyNum)).divide(new BigDecimal(lever));
+ BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt);
+
+ BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100));
+ BigDecimal availableBalance = fundratio.multiply(userAssets.getAvailableBalance());
+ if (availableBalance.compareTo(buyAmt.add(orderFree)) < 0) {
+ return ServerResponse.createByErrorMsg("订单失败,配资不足", request);
+ }
+ UserPendingorder userPendingorder = new UserPendingorder();
+ userPendingorder.setPositionType(1);
+ userPendingorder.setPositionSn(KeyUtils.getUniqueKey());
+ userPendingorder.setUserId(user.getId());
+ userPendingorder.setNickName(user.getRealName());
+ userPendingorder.setAgentId(user.getAgentId());
+ userPendingorder.setStockCode("HJYY");
+ userPendingorder.setStockName(name);
+ userPendingorder.setStockGid("HJYY");
+ userPendingorder.setStockSpell(name);
+ userPendingorder.setBuyOrderId(GeneratePosition.getPositionId());
+ userPendingorder.setBuyOrderTime(new Date());
+ userPendingorder.setBuyOrderPrice(price);
+ userPendingorder.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌");
+ userPendingorder.setOrderNum(buyNum);
+ userPendingorder.setIsLock(Integer.valueOf(0));
+ userPendingorder.setOrderLever(lever);
+ userPendingorder.setOrderTotalPrice(buyAmt);
+ // 手续费
+ userPendingorder.setOrderFee(orderFree);
+ userPendingorder.setOrderSpread(BigDecimal.ZERO);
+ userPendingorder.setSpreadRatePrice(BigDecimal.ZERO);
+ BigDecimal profit_and_lose = new BigDecimal("0");
+ userPendingorder.setProfitAndLose(profit_and_lose);
+ userPendingorder.setAllProfitAndLose(profit_and_lose.add(orderFree));
+ userPendingorder.setOrderStayDays(Integer.valueOf(0));
+ userPendingorder.setOrderStayFee(BigDecimal.ZERO);
+ userPendingorderMapper.insert(userPendingorder);
+ iUserAssetsServices.availablebalanceChange("USDT", user.getId(), EUserAssets.BUY, buyAmt.negate(), "", "");
+ return ServerResponse.createBySuccessMsg("下单成功", request);
+ }
}
- @Override
- public void orderTask() {
-
- List<UserPendingorder> userPendingorders = userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("status", 0));
- log.info("当前有挂单的用户数量 为 {}", Integer.valueOf(userPendingorders.size()));
- for (int i = 0; i < userPendingorders.size(); i++) {
- Integer userId = (Integer) userPendingorders.get(i).getUserId();
- User user = this.userMapper.selectById(userId);
- if (user == null) {
- continue;
- }
- List<UserPendingorder> userPendingorderList = userPendingorderMapper.selectList(new QueryWrapper<UserPendingorder>().eq("user_id", userId).eq("status", 0));
- if (userPendingorderList == null) {
- continue;
- }
- log.info("用户id = {} 姓名 = {} 已挂单数: {}", new Object[]{userId, user.getRealName(), Integer.valueOf(userPendingorders.size())});
- BigDecimal all_freez_amt = new BigDecimal("0");
- String nowPrice = "";
- String code = "";
- Integer indexId = null;
- StockListVO stockListVO = new StockListVO();
- StockCoin stockCoin = new StockCoin();
- for (UserPendingorder userPendingorder : userPendingorderList) {
- //指数
- if (userPendingorder.getStockId().contains("sh") || userPendingorder.getStockId().contains("sz") || userPendingorder.getStockId().contains("hk") || userPendingorder.getStockId().contains("us")) {
- StockIndex model = stockIndexMapper.selectIndexByCode(userPendingorder.getStockId().replace("sh", "").replace("sz", "").replace("hk", "").replace("us", ""));
- all_freez_amt = (new BigDecimal(model.getDepositAmt().intValue())).multiply(new BigDecimal(userPendingorder.getBuyNum())).divide(new BigDecimal(userPendingorder.getLever())).setScale(4, 2);
-
-// if (){
-//
-// }else {
- MarketVO marketVO = this.iStockIndexService.querySingleIndex(model.getIndexGid());
- nowPrice = marketVO.getNowPrice();
-// }
-
- indexId = model.getId();
-
- } else {
- //股票
- Stock stock = stockMapper.findStockByCode(userPendingorder.getStockId());
- if ("hk".equals(stock.getStockType())) {
- String hk = RedisShardedPoolUtils.get(stock.getStockGid(), 1);
- stockListVO = StockApi.otherStockListVO(hk);
- // stockCoin = iStockCoinService.selectCoinByCode("HKD");
- ExchangeVO exchangeVO = this.iStockFuturesService.queryExchangeVO("HKD").getData();
- nowPrice = String.valueOf(new BigDecimal(stockListVO.getNowPrice()).multiply(new BigDecimal(exchangeVO.getNowPrice())));
- } else if ("us".equals(stock.getStockType())) {
- String us = RedisShardedPoolUtils.get(stock.getStockGid(), 2);
- stockListVO = StockApi.otherStockListVO(us);
- // stockCoin = iStockCoinService.selectCoinByCode("USD");
- ExchangeVO exchangeVO = this.iStockFuturesService.queryExchangeVO("USD").getData();
- nowPrice = String.valueOf(new BigDecimal(stockListVO.getNowPrice()).multiply(new BigDecimal(exchangeVO.getNowPrice())));
- } else {
- stockListVO = StockApi.getStockRealTime(stock);
- nowPrice = stockListVO.getNowPrice();
- }
-
-
- all_freez_amt = new BigDecimal(nowPrice).multiply(new BigDecimal(userPendingorder.getBuyNum())).divide(new BigDecimal(userPendingorder.getLever()), 2, 4);
- code = stock.getStockCode();
- }
- if (nowPrice == null) {
- nowPrice = String.valueOf(0);
- }
- if (userPendingorder.getUserId() != null && userPendingorder.getStockId() != null && userPendingorder.getBuyNum() != null && userPendingorder.getBuyType() != null && userPendingorder.getLever() != null && userPendingorder.getTargetPrice() != null) {
- int ret = userPendingorder.getBuyType().intValue() == 0 ? userPendingorder.getTargetPrice().compareTo(new BigDecimal(nowPrice)) : new BigDecimal(nowPrice).compareTo(userPendingorder.getTargetPrice());
- //当前时间String
- String buyTime = DateTimeUtil.dateToStr(new Date());
- if (ret <= 0) {
- if (code != null && !"".equals(code)) {
- try {
- this.iUserPositionService.create(userPendingorder.getUserId(), code, nowPrice, buyTime, userPendingorder.getBuyNum(), userPendingorder.getBuyType(), userPendingorder.getLever(), userPendingorder.getProfitTarget(), userPendingorder.getStopTarget());
- userPendingorder.setStatus(1);
- this.userPendingorderMapper.updateById(userPendingorder);
- SiteTaskLog siteTaskLog = new SiteTaskLog();
- siteTaskLog.setTaskType("股票挂单转持仓");
- String accountType = (user.getAccountType() == 0) ? "正式用户" : "模拟用户";
- String tasktarget = "此次挂单买入id:" + userPendingorder.getId();
- siteTaskLog.setTaskTarget(tasktarget);
- siteTaskLog.setAddTime(new Date());
- siteTaskLog.setIsSuccess(0);
- siteTaskLog.setErrorMsg("");
- int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
- if (insertTaskCount > 0) {
- log.info("挂单task任务成功");
- } else {
- log.info("挂单task任务失败");
- }
- } catch (Exception e) {
- log.error("股票挂单任务失败...");
- userPendingorder.setStatus(2);
- this.userPendingorderMapper.updateById(userPendingorder);
- }
- } else if (indexId != null) {
- try {
- this.iUserIndexPositionService.buyIndexOrder(indexId, userPendingorder.getBuyNum(), userPendingorder.getBuyType(), userPendingorder.getLever(), userPendingorder.getProfitTarget(), userPendingorder.getStopTarget(), userPendingorder.getUserId());
- userPendingorder.setStatus(1);
- this.userPendingorderMapper.updateById(userPendingorder);
- SiteTaskLog siteTaskLog = new SiteTaskLog();
- siteTaskLog.setTaskType("指数挂单转持仓");
- String accountType = (user.getAccountType() == 0) ? "正式用户" : "模拟用户";
- String tasktarget = "此次挂单买入id:" + userPendingorder.getId();
- siteTaskLog.setTaskTarget(tasktarget);
- siteTaskLog.setAddTime(new Date());
- siteTaskLog.setIsSuccess(0);
- siteTaskLog.setErrorMsg("");
- int insertTaskCount = this.siteTaskLogMapper.insert(siteTaskLog);
- if (insertTaskCount > 0) {
- log.info("挂单task任务成功");
- userPendingorder.setStatus(1);
- } else {
- log.info("挂单task任务失败");
- }
- } catch (Exception e) {
- log.error("指数挂单任务失败...");
- userPendingorder.setStatus(2);
- this.userPendingorderMapper.updateById(userPendingorder);
- }
- }
-
- }
-
- }
-
- }
-
- }
- log.info("===========挂单结束==========");
- }
-
- //删除
- @Override
- public ServerResponse delOrder(Integer id, HttpServletRequest request) {
- String property = PropertiesUtil.getProperty("user.cookie.name");
- String header = request.getHeader(property);
- if (header != null) {
- String userJson = RedisShardedPoolUtils.get(header);
- User user = (User) JsonUtil.string2Obj(userJson, User.class);
- UserPendingorder userPendingorder = this.userPendingorderMapper.selectById(id);
- if (userPendingorder == null) {
- return ServerResponse.createByErrorMsg("The pending order does not exist");
- }
- if (user.getId().intValue() != userPendingorder.getUserId().intValue()) {
- return ServerResponse.createByErrorMsg("The pending order does not belong to you");
- }
- int delCount = this.userPendingorderMapper.deleteById(id);
- if (delCount > 0) {
- return ServerResponse.createByErrorMsg("Successfully deleted");
- }
- return ServerResponse.createByErrorMsg("Deletion failure");
- }
-
- return ServerResponse.createByErrorMsg("Please log in");
- }
-
-
- @Override
- public ServerResponse orderListByAdmin(int pageNum, int pageSize, String keywords, String status, HttpServletRequest request) {
- PageHelper.startPage(pageNum, pageSize);
- QueryWrapper<UserPendingorder> queryWrapper = new QueryWrapper();
- if (keywords != null && !keywords.equals("")) {
- queryWrapper.like("stock_id", keywords).or().like("user_id", keywords);
- }
- if (status != null && !status.equals("")) {
- queryWrapper.eq("status", status);
- }
- queryWrapper.orderByDesc("id");
- List<UserPendingorder> stockSubscribeList = this.userPendingorderMapper.selectList(queryWrapper);
- List UserPendingorderList = new ArrayList();
- for (UserPendingorder userPendingorder : stockSubscribeList) {
- UserPendingorderVO userPendingorderVO = new UserPendingorderVO();
- //挂单-指数
- if (userPendingorder.getStockId().contains("sh") || userPendingorder.getStockId().contains("sz") || userPendingorder.getStockId().contains("hk") || userPendingorder.getStockId().contains("us")) {
- StockIndex model = stockIndexMapper.selectIndexByCode(userPendingorder.getStockId().replace("sh", "").replace("sz", "").replace("hk", "").replace("us", ""));
-
- MarketVO marketVO = this.iStockIndexService.querySingleIndex(model.getIndexGid());
- userPendingorderVO.setNowPrice(new BigDecimal(marketVO.getNowPrice()));
- userPendingorderVO.setStockName(model.getIndexName());
- userPendingorderVO.setStockId(model.getIndexGid());
-
- } else {
- //挂单-股票
- Stock stock = stockMapper.findStockByCode(userPendingorder.getStockId());
- StockListVO stockListVO = new StockListVO();
- if (stock.getStockType().equals("hk")) {
- String hk = RedisShardedPoolUtils.get(stock.getStockGid(), 1);
- stockListVO = StockApi.otherStockListVO(hk);
- } else if (stock.getStockType().equals("us")) {
- String us = RedisShardedPoolUtils.get(stock.getStockGid(), 2);
- stockListVO = StockApi.otherStockListVO(us);
- } else {
- stockListVO = StockApi.getStockRealTime(
- stock);
- }
- String nowPrice = stockListVO.getNowPrice();
- if (nowPrice == null) {
- nowPrice = String.valueOf(0);
- }
- userPendingorderVO.setNowPrice(new BigDecimal(nowPrice));
- userPendingorderVO.setStockName(stock.getStockName());
- userPendingorderVO.setStockId(stock.getStockCode());
- }
- userPendingorderVO.setBuyNum(userPendingorder.getBuyNum());
- userPendingorderVO.setBuyType(userPendingorder.getBuyType());
- userPendingorderVO.setLever(userPendingorder.getLever());
- userPendingorderVO.setProfitTarget(userPendingorder.getProfitTarget());
- userPendingorderVO.setStopTarget(userPendingorder.getStopTarget());
- userPendingorderVO.setTargetPrice(userPendingorder.getTargetPrice());
- userPendingorderVO.setAddTime(userPendingorder.getAddTime());
- userPendingorderVO.setStatus(userPendingorder.getStatus());
- userPendingorderVO.setId(userPendingorder.getId());
- UserPendingorderList.add(userPendingorderVO);
- }
- PageInfo pageInfo = new PageInfo(stockSubscribeList);
- pageInfo.setList(UserPendingorderList);
- return ServerResponse.createBySuccess(pageInfo);
- }
-
- @Override
- public ServerResponse updateOrderByAdmin(UserPendingorder userPendingorder) {
- if (userPendingorder.getId() == null) {
- return ServerResponse.createByErrorMsg("id不能为空");
- }
- int updateCount = this.userPendingorderMapper.updateById(userPendingorder);
- if (updateCount > 0) {
- return ServerResponse.createBySuccessMsg("修改成功");
- }
- return ServerResponse.createByErrorMsg("修改失败");
-
- }
-
- @Override
- public ServerResponse addOrderByAdmin(String phone, String buyNum, String code, String buyType, String lever, String targetPrice, HttpServletRequest request) {
- if (StringUtils.isBlank(phone) || StringUtils.isBlank(buyNum) || StringUtils.isBlank(buyType) || StringUtils.isBlank(lever) || StringUtils.isBlank(targetPrice)) {
- return ServerResponse.createByErrorMsg("参数不能为空");
- }
-
- User user = this.userMapper.selectOne(new QueryWrapper<User>().eq("phone", phone));
- if (user == null) {
- return ServerResponse.createByErrorMsg("用户不存在");
- }
- Stock stock = stockMapper.findStockByCode(code);
- if (stock == null) {
- return ServerResponse.createByErrorMsg("股票不存在");
- }
- UserPendingorder userPendingorder = new UserPendingorder();
- userPendingorder.setUserId(user.getId());
- userPendingorder.setStockId(code);
- userPendingorder.setBuyNum(Integer.valueOf(buyNum));
- userPendingorder.setBuyType(Integer.valueOf(buyType));
- userPendingorder.setLever(Integer.valueOf(lever));
- userPendingorder.setTargetPrice(new BigDecimal(targetPrice));
- userPendingorder.setAddTime(new Date());
- userPendingorder.setStatus(0);
- userPendingorder.setNowPrice(new BigDecimal(0));
- int insert = this.userPendingorderMapper.insert(userPendingorder);
- if (insert > 0) {
- return ServerResponse.createBySuccessMsg("添加成功");
- }
- return ServerResponse.createByErrorMsg("添加失败");
-
- }
-
- @Override
- public ServerResponse delOrderByAdmin(Integer id) {
- if (id == null) {
- return ServerResponse.createByErrorMsg("id不能为空");
- }
- int delete = this.userPendingorderMapper.deleteById(id);
- if (delete > 0) {
- return ServerResponse.createBySuccessMsg("删除成功");
- }
- return ServerResponse.createByErrorMsg("删除失败");
- }
}
diff --git a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
index c117324..1fc5585 100644
--- a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -131,7 +131,8 @@
@Autowired
UserPositionCheckDzService userPositionCheckDzService;
-
+ @Autowired
+ UserPendingorderService userPendingorderService;
@Transactional
public ServerResponse buy(Integer stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) {
@@ -243,7 +244,7 @@
}
@Transactional
- public ServerResponse goldCrudeOilbuy(String name, Integer buyNum, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) {
+ public ServerResponse goldCrudeOilbuy(String name, Integer buyNum, Integer buyType,Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) {
SiteProduct siteProduct = iSiteProductService.getProductSetting();
@@ -303,7 +304,7 @@
userPosition.setBuyOrderId(GeneratePosition.getPositionId());
userPosition.setBuyOrderTime(new Date());
userPosition.setBuyOrderPrice(price);
- userPosition.setOrderDirection("买涨");
+ userPosition.setOrderDirection((buyType.intValue() == 0) ? "买涨" : "买跌");
userPosition.setOrderNum(buyNum);
userPosition.setIsLock(Integer.valueOf(0));
userPosition.setOrderLever(lever);
@@ -725,61 +726,70 @@
public ServerResponse findMyPositionByCodeAndSpell(String stockCode, String stockSpell,
Integer state, HttpServletRequest request,
- int pageNum, int pageSize, String stockType) {
+ int pageNum, int pageSize, String stockType,Integer pendingStatus) {
User user = this.iUserService.getCurrentUser(request);
PageHelper.startPage(pageNum, pageSize);
List<UserPosition> userPositions = null;
+ if(state == 2){
+ List<UserPendingorder> list = userPendingorderService.list(new LambdaQueryWrapper<>(UserPendingorder.class)
+ .eq(UserPendingorder::getUserId, user.getId())
+ .eq(UserPendingorder::getStockGid,(null != stockCode && "HJYY".equals(stockCode)) ? stockCode : stockType)
+ .eq(UserPendingorder::getPositionType,pendingStatus)
+ );
+ PageInfo pageInfo = new PageInfo();
+ pageInfo.setList(list);
+ return ServerResponse.createBySuccess(pageInfo);
+ }else {
+ if (stockCode.equals("HJYY")) {
+ LambdaQueryWrapper<UserPosition> wrapper = getUserPositionLambdaQueryWrapper(stockCode, state, user);
+ userPositions = userPositionMapper.selectList(wrapper);
+ } else {
+ userPositions = userPositionMapper.
+ findMyPositionByCodeAndSpell(user.getId(),
+ stockCode, stockSpell,
+ state, stockType);
+ }
-
- if(stockCode.equals("HJYY")){
- LambdaQueryWrapper<UserPosition> wrapper = getUserPositionLambdaQueryWrapper(stockCode, state, user);
- userPositions = userPositionMapper.selectList(wrapper);
- }else{
- userPositions = userPositionMapper.
- findMyPositionByCodeAndSpell(user.getId(),
- stockCode, stockSpell,
- state, stockType);
- }
-
- List<UserPositionVO> userPositionVOS = Lists.newArrayList();
- if (userPositions.size() > 0) {
- for (UserPosition position : userPositions) {
- BigDecimal nowPrice = BigDecimal.ZERO;
- if(position.getStockSpell().equals("XAUUSD") || position.getStockSpell().equals("USOIL")){
- nowPrice = new BigDecimal(RedisShardedPoolUtils.get(position.getStockSpell()));
- }else{
- if(state == 0){
- nowPrice = priceServices.getNowPrice(position.getStockCode());
- }else{
- nowPrice = position.getSellOrderPrice();
+ List<UserPositionVO> userPositionVOS = Lists.newArrayList();
+ if (userPositions.size() > 0) {
+ for (UserPosition position : userPositions) {
+ BigDecimal nowPrice = BigDecimal.ZERO;
+ if (position.getStockSpell().equals("XAUUSD") || position.getStockSpell().equals("USOIL")) {
+ nowPrice = new BigDecimal(RedisShardedPoolUtils.get(position.getStockSpell()));
+ } else {
+ if (state == 0) {
+ nowPrice = priceServices.getNowPrice(position.getStockCode());
+ } else {
+ nowPrice = position.getSellOrderPrice();
+ }
}
- }
- UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position,nowPrice);
- userPositionVO.setOrderTotalPrice(userPositionVO.getOrderTotalPrice().multiply(new BigDecimal(userPositionVO.getOrderLever())));
+ UserPositionVO userPositionVO = UserPointUtil.assembleUserPositionVO(position, nowPrice);
+ userPositionVO.setOrderTotalPrice(userPositionVO.getOrderTotalPrice().multiply(new BigDecimal(userPositionVO.getOrderLever())));
- StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>()
- .eq(StockSubscribe::getCode, userPositionVO.getStockCode()));
- if(position.getSellOrderId() == null){
- if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) {
- userPositionVO.setProfitAndLose(BigDecimal.ZERO);
- userPositionVO.setProfitAndLoseParent("0%");
- userPositionVO.setIsListed(false);
- }else{
- userPositionVO.setIsListed(true);
+ StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>()
+ .eq(StockSubscribe::getCode, userPositionVO.getStockCode()));
+ if (position.getSellOrderId() == null) {
+ if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) {
+ userPositionVO.setProfitAndLose(BigDecimal.ZERO);
+ userPositionVO.setProfitAndLoseParent("0%");
+ userPositionVO.setIsListed(false);
+ } else {
+ userPositionVO.setIsListed(true);
+ userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever())));
+ }
+ } else {
userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever())));
}
- }else{
- userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever())));
+ userPositionVOS.add(userPositionVO);
}
- userPositionVOS.add(userPositionVO);
}
+
+ PageInfo pageInfo = new PageInfo(userPositions);
+ pageInfo.setList(userPositionVOS);
+
+ return ServerResponse.createBySuccess(pageInfo);
}
-
- PageInfo pageInfo = new PageInfo(userPositions);
- pageInfo.setList(userPositionVOS);
-
- return ServerResponse.createBySuccess(pageInfo);
}
private static LambdaQueryWrapper<UserPosition> getUserPositionLambdaQueryWrapper(String stockCode, Integer state, User user) {
diff --git a/src/main/java/com/nq/utils/task/stock/StockTask.java b/src/main/java/com/nq/utils/task/stock/StockTask.java
index d4a1b6b..08db5ed 100644
--- a/src/main/java/com/nq/utils/task/stock/StockTask.java
+++ b/src/main/java/com/nq/utils/task/stock/StockTask.java
@@ -1,26 +1,32 @@
package com.nq.utils.task.stock;
+import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONArray;
import com.alibaba.fastjson2.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
+import com.nq.common.ServerResponse;
import com.nq.dao.StockMapper;
+import com.nq.dao.UserMapper;
+import com.nq.dao.UserPendingorderMapper;
import com.nq.dao.UserPositionMapper;
+import com.nq.enums.EConfigKey;
import com.nq.enums.EStockType;
-import com.nq.pojo.DataStockBean;
-import com.nq.pojo.ReponseBase;
-import com.nq.pojo.Stock;
-import com.nq.pojo.UserPosition;
+import com.nq.enums.EUserAssets;
+import com.nq.pojo.*;
import com.nq.pojo.reponse.kResponse;
-import com.nq.service.IMandatoryLiquidationService;
-import com.nq.service.IStockService;
-import com.nq.service.IUserPositionService;
+import com.nq.service.*;
import com.nq.service.impl.StockServiceImpl;
+import com.nq.service.impl.UserServiceImpl;
+import com.nq.utils.ConverterUtil;
+import com.nq.utils.KeyUtils;
import com.nq.utils.http.HttpClientRequest;
import com.nq.utils.redis.RedisKeyConstant;
import com.nq.utils.redis.RedisKeyUtil;
import com.nq.utils.redis.RedisShardedPoolUtils;
+import com.nq.utils.stock.GeneratePosition;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,6 +38,8 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
@@ -55,11 +63,20 @@
@Autowired
UserPositionMapper userPositionMapper;
- private final Lock stockConstraintLock = new ReentrantLock();
-
-
+ @Autowired
+ private UserPendingorderService userPendingorderService;
@Autowired
IMandatoryLiquidationService mandatoryLiquidationService;
+ @Autowired
+ IUserAssetsServices iUserAssetsServices;
+ @Autowired
+ IStockConfigServices iStockConfigServices;
+
+ @Autowired
+ IPriceServices priceServices;
+ @Autowired
+ UserMapper userMapper;
+
private static final Logger log = LoggerFactory.getLogger(StockTask.class);
@@ -88,6 +105,78 @@
}
}
}
+
+
+ /**
+ * 挂单
+ */
+ @Scheduled(cron = "0/10 * * * * ?")
+ public void pendingOrder() {
+ ReentrantLock lock = new ReentrantLock();
+ if (lock.tryLock()) { // 尝试获取锁
+ try {
+ pending();
+ }catch (Exception e){
+ e.printStackTrace();
+ log.error("挂单定时任务报错:",e.getMessage());
+ }
+ finally {
+ lock.unlock(); // 释放锁
+ }
+ } else {
+ // 如果锁不可用,可以选择不执行或打印日志等
+ System.out.println("挂单定时任务 任务正在执行,跳过本次执行。");
+ }
+ }
+
+ public void pending(){
+ List<UserPendingorder> list = userPendingorderService.list(new LambdaQueryWrapper<>(UserPendingorder.class).eq(UserPendingorder::getPositionType, 1));
+ if(CollectionUtil.isNotEmpty(list)){
+ list.forEach(f->{
+ if(f.getStockGid().equals("ST")){
+ //获取当前价格
+ //股票类型 现价 数据源的处理
+ BigDecimal nowPrice = priceServices.getNowPrice(f.getStockCode());
+ if(f.getBuyOrderPrice().compareTo(nowPrice) <= 0){
+ stockTransferPositions(f);
+ }
+ }else{
+ String price = RedisShardedPoolUtils.get(RedisKeyConstant.getRedisKey(f.getStockName()));
+ if(f.getBuyOrderPrice().compareTo(new BigDecimal(price)) <= 0){
+ hjTransferPositions(f);
+ }
+ }
+ });
+ }
+ }
+ public void hjTransferPositions(UserPendingorder userPendingorder){
+ User user = userMapper.selectById(userPendingorder.getUserId());
+ BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ;
+ BigDecimal orderFree = siteSettingBuyFee.multiply(userPendingorder.getOrderTotalPrice());
+ UserPosition userPosition = ConverterUtil.convert(userPendingorder, UserPosition.class);
+ userPosition.setPositionType(user.getAccountType());
+ userPosition.setId(null);
+ userPendingorder.setPositionType(0);
+ userPendingorderService.updateById(userPendingorder);
+ userPositionMapper.insert(userPosition);
+ iUserAssetsServices.availablebalanceChange("USDT", user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", "");
+ }
+
+ public void stockTransferPositions(UserPendingorder userPendingorder){
+ // 手续费率
+ BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue()) ;
+ BigDecimal orderFree = siteSettingBuyFee.multiply(userPendingorder.getOrderTotalPrice());
+ User user = userMapper.selectById(userPendingorder.getUserId());
+ UserPosition userPosition = ConverterUtil.convert(userPendingorder, UserPosition.class);
+ userPosition.setPositionType(user.getAccountType());
+ userPosition.setId(null);
+ userPendingorder.setPositionType(0);
+ userPendingorderService.updateById(userPendingorder);
+ userPositionMapper.insert(userPosition);
+ //挂单成功扣除手续费
+ iUserAssetsServices.availablebalanceChange("ST", user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", "");
+ }
+
//最新价格url
private static final String PRICE_URL = "https://quote.alltick.io/quote-b-api/trade-tick?token=794ea65dc03c5af582cddec476fbb0d7-c-app&query=";
//k线url
@@ -140,7 +229,7 @@
if (lock.tryLock()) { // 尝试获取锁
try {
gold();
- Thread.sleep(1000);
+ Thread.sleep(2000);
getKDate();
} finally {
lock.unlock(); // 释放锁
@@ -224,7 +313,7 @@
RedisShardedPoolUtils.set("k_gold_"+entry.getKey(), gold);
}
- Thread.sleep(1000);
+ Thread.sleep(2000);
String c = getResp(K_URL+getKQueryData(entry.getValue(),"USOIL"));
if(StringUtils.isNotEmpty(c)){
if(entry.getKey().equals("d")) {
@@ -232,7 +321,7 @@
}
RedisShardedPoolUtils.set("k_crude_oil_"+entry.getKey(), c);
}
- Thread.sleep(1000);
+ Thread.sleep(2000);
}
}
@@ -264,12 +353,13 @@
kData.setVo(item.getTurnover());
kDataList.add(kData);
}
- DecimalFormat decimalFormat = new DecimalFormat("#.00");
double oneC = Double.valueOf(kDataList.get(kDataList.size() - 1).getC());
double twoC = Double.valueOf(kDataList.get(kDataList.size() - 2).getC());
- String h = String.valueOf(decimalFormat.format(((oneC - twoC) / oneC * 100)));
- RedisShardedPoolUtils.set(key+"_H",h);
- RedisShardedPoolUtils.set(key+"_H",h);
+ String h = String.valueOf(((oneC - twoC) / oneC * 100));
+ BigDecimal bd = new BigDecimal(h);
+ bd = bd.setScale(2, RoundingMode.DOWN); // RoundingMode.DOWN 表示截断而非四舍五入
+ RedisShardedPoolUtils.set(key+"_H",bd.toString());
+ RedisShardedPoolUtils.set(key+"_H",bd.toString());
}
public String getResp(String url){
diff --git a/src/main/java/com/nq/utils/translate/GoogleTranslateUtil.java b/src/main/java/com/nq/utils/translate/GoogleTranslateUtil.java
index e9315e0..353025f 100644
--- a/src/main/java/com/nq/utils/translate/GoogleTranslateUtil.java
+++ b/src/main/java/com/nq/utils/translate/GoogleTranslateUtil.java
@@ -15,7 +15,6 @@
public String translate(String langFrom, String langTo,
String word) throws Exception {
- langTo = "ar-SA";
//不为空则设置代理
// String proxyHost = PropertiesUtil.getProperty("https.proxyHost");
// String proxyPort = PropertiesUtil.getProperty("https.proxyPort");
diff --git a/src/main/resources/mapper/UserPositionMapper.xml b/src/main/resources/mapper/UserPositionMapper.xml
index b3f21b7..ca7b635 100644
--- a/src/main/resources/mapper/UserPositionMapper.xml
+++ b/src/main/resources/mapper/UserPositionMapper.xml
@@ -384,9 +384,9 @@
<if test="stockSpell != null and stockSpell != '' ">
and stock_spell like CONCAT('%','${stockSpell}','%')
</if>
-<!-- <if test="stockType != null and stockType!= ''">-->
-<!-- and stock_gid = #{stockType}-->
-<!-- </if>-->
+ <if test="stockType != null and stockType!= ''">
+ and stock_gid = #{stockType}
+ </if>
</where>
--
Gitblit v1.9.3