From 1b5faa64dbb22935de1ff33a2bd01a41446f857b Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Tue, 02 Jun 2026 11:22:52 +0800
Subject: [PATCH] 1
---
src/main/java/com/nq/service/impl/UserPositionServiceImpl.java | 101 +++++++++++++++++++++-----------------------------
1 files changed, 43 insertions(+), 58 deletions(-)
diff --git a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
index 2da1050..aced777 100644
--- a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -966,6 +966,35 @@
return null;
}
+ private ServerResponse validateTransTimeBeforeSell(UserPosition userPosition, SiteSetting siteSetting) throws Exception {
+ if (userPosition == null || siteSetting == null) {
+ return null;
+ }
+ String stockGid = userPosition.getStockGid();
+ boolean inSession;
+ if (stockGid != null && stockGid.contains("us")) {
+ inSession = BuyAndSellUtils.isInTransSession(
+ siteSetting.getTransAmBeginUs(), siteSetting.getTransAmEndUs(),
+ siteSetting.getTransPmBeginUs(), siteSetting.getTransPmEndUs());
+ } else if (stockGid != null && stockGid.contains("hk")) {
+ inSession = BuyAndSellUtils.isInTransSession(
+ siteSetting.getTransAmBeginhk(), siteSetting.getTransAmEndhk(),
+ siteSetting.getTransPmBeginhk(), siteSetting.getTransPmEndhk());
+ } else {
+ inSession = BuyAndSellUtils.isInTransSession(
+ siteSetting.getTransAmBegin(), siteSetting.getTransAmEnd(),
+ siteSetting.getTransPmBegin(), siteSetting.getTransPmEnd());
+ }
+ if (!inSession) {
+ return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内");
+ }
+ SiteProduct siteProduct = iSiteProductService.getProductSetting();
+ if (siteProduct != null && siteProduct.getHolidayDisplay()) {
+ return ServerResponse.createByErrorMsg("周末或节假日不能交易!");
+ }
+ return null;
+ }
+
public ServerResponse sell(String positionSn, int doType) throws Exception {
log.info("【用戶交易平倉】 positionSn = {} , dotype = {}", positionSn, Integer.valueOf(doType));
@@ -978,54 +1007,17 @@
SiteProduct siteProduct = iSiteProductService.getProductSetting();
UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn);
- if (doType != 0) {
- if (userPosition.getStockGid().contains("us")) {
- String am_begin = siteSetting.getTransAmBeginUs();
- String am_end = siteSetting.getTransAmEndUs();
- String pm_begin = siteSetting.getTransPmBeginUs();
- String pm_end = siteSetting.getTransPmEndUs();
- boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end);
- boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end);
- log.info("是否在上午交易時間 = {} 是否在下午交易時間 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag));
-
- if (!am_flag && !pm_flag) {
- return ServerResponse.createByErrorMsg("下单失败,系统设置错误");
- }
- } else if (userPosition.getStockGid().contains("hk")) {
- String am_begin = siteSetting.getTransAmBeginhk();
- String am_end = siteSetting.getTransAmEndhk();
- String pm_begin = siteSetting.getTransPmBeginhk();
- String pm_end = siteSetting.getTransPmEndhk();
- boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end);
- boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end);
- log.info("是否在上午交易時間 = {} 是否在下午交易時間 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag));
-
- if (!am_flag && !pm_flag) {
- return ServerResponse.createByErrorMsg("下單失敗,不在港股股交易時段內");
- }
- } else {
- String am_begin = siteSetting.getTransAmBegin();
- String am_end = siteSetting.getTransAmEnd();
- String pm_begin = siteSetting.getTransPmBegin();
- String pm_end = siteSetting.getTransPmEnd();
- boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end);
- boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end);
- log.info("是否在上午交易時間 = {} 是否在下午交易時間 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag));
-
- if (!am_flag && !pm_flag && siteProduct.getTranWithdrawDisplay()) {
- return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内");
- }
- }
- if (siteProduct.getHolidayDisplay() && siteProduct.getTranWithdrawDisplay()) {
- return ServerResponse.createByErrorMsg("周末或节假日不能交易!");
- }
-
- }
-
-
if (userPosition == null) {
return ServerResponse.createByErrorMsg("平仓失败,订单不存在");
}
+
+ if (doType != 0) {
+ ServerResponse timeCheck = validateTransTimeBeforeSell(userPosition, siteSetting);
+ if (timeCheck != null) {
+ return timeCheck;
+ }
+ }
+
User user = this.userMapper.selectByPrimaryKey(userPosition.getUserId());
if (user == null) {
@@ -1280,23 +1272,16 @@
}
SiteProduct siteProduct = iSiteProductService.getProductSetting();
UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn);
+ if (userPosition == null) {
+ return ServerResponse.createByErrorMsg("平仓失败,订单不存在");
+ }
//部分平仓数量等于订单总数量,则调用全平接口
if(quantity.equals(userPosition.getOrderNum())){
return sell(positionSn,1);
}
- //校验时间
- String am_begin = siteSetting.getTransAmBegin();
- String am_end = siteSetting.getTransAmEnd();
- String pm_begin = siteSetting.getTransPmBegin();
- String pm_end = siteSetting.getTransPmEnd();
- boolean am_flag = BuyAndSellUtils.isTransTime(am_begin, am_end);
- boolean pm_flag = BuyAndSellUtils.isTransTime(pm_begin, pm_end);
- log.info("是否在上午交易時間 = {} 是否在下午交易時間 = {}", Boolean.valueOf(am_flag), Boolean.valueOf(pm_flag));
- if (!am_flag && !pm_flag) {
- return ServerResponse.createByErrorMsg("平仓失败,不在交易时段内");
- }
- if (userPosition == null) {
- return ServerResponse.createByErrorMsg("平仓失败,订单不存在");
+ ServerResponse timeCheck = validateTransTimeBeforeSell(userPosition, siteSetting);
+ if (timeCheck != null) {
+ return timeCheck;
}
User user = this.userMapper.selectByPrimaryKey(userPosition.getUserId());
if (user == null) {
--
Gitblit v1.9.3