From 6912d597b0ed44d36af5e26077cce111936fc7f2 Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Sun, 31 Mar 2024 17:27:07 +0800
Subject: [PATCH] 1

---
 src/main/java/com/nq/service/impl/UserPositionServiceImpl.java |  128 +++++++++++++++++++++++-------------------
 1 files changed, 71 insertions(+), 57 deletions(-)

diff --git a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
index 487dbbd..e4cf5b9 100644
--- a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -1,9 +1,7 @@
 package com.nq.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.google.gson.Gson;
 import com.nq.dao.*;
-import com.nq.enums.EStockType;
 import com.nq.enums.EUserAssets;
 import com.nq.pojo.*;
 import com.nq.service.*;
@@ -104,13 +102,16 @@
     @Autowired
     IUserAssetsServices iUserAssetsServices;
 
+    @Autowired
+    TradingHourServiceImpl tradingHourService;
+
     @Transactional
     public ServerResponse buy(Integer stockId, Integer buyNum, Integer buyType, Integer lever, BigDecimal profitTarget, BigDecimal stopTarget, HttpServletRequest request) throws Exception {
 
         // 判断周末不能买
-        Date today = new Date();
-        Calendar c = Calendar.getInstance();
-        c.setTime(today);
+//        Date today = new Date();
+//        Calendar c = Calendar.getInstance();
+//        c.setTime(today);
         /*实名认证开关开启*/
         SiteProduct siteProduct = iSiteProductService.getProductSetting();
 
@@ -134,34 +135,38 @@
             return ServerResponse.createByErrorMsg("Order failed, stock code error");
         }
 
-        if (Objects.equals(stock.getStockType(), EStockType.US.getCode())) {
-            if (buyNum < siteSetting.getDzMinByCount()) {
-                return ServerResponse.createByErrorMsg("Minimum purchase for bulk commodities " + siteSetting.getDzMinByCount());
-            }
-
-            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("Order failed, not in the  stock trading session");
-            }
-        } 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);
-            if (!am_flag && !pm_flag) {
-                return ServerResponse.createByErrorMsg("Order failed, out of trading hours");
-            }
-            if (siteProduct.getHolidayDisplay()) {
-                return ServerResponse.createByErrorMsg("No trading on weekends or holidays!");
-            }
+//        if (Objects.equals(stock.getStockType(), EStockType.US.getCode())) {
+//            if (buyNum < siteSetting.getDzMinByCount()) {
+//                return ServerResponse.createByErrorMsg("Minimum purchase for bulk commodities " + siteSetting.getDzMinByCount());
+//            }
+//            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("Order failed, not in the  stock trading session");
+//            }
+//        } 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);
+//            if (!am_flag && !pm_flag) {
+//                return ServerResponse.createByErrorMsg("Order failed, out of trading hours");
+//            }
+//            if (siteProduct.getHolidayDisplay()) {
+//                return ServerResponse.createByErrorMsg("No trading on weekends or holidays!");
+//            }
+//        }
+        //判断股票是否在可交易时间段
+        Boolean b = tradingHourService.timeCheck();
+        if (!b) {
+            return ServerResponse.createByErrorMsg("Order failed, not in the  stock trading session");
         }
 
 
@@ -194,7 +199,6 @@
         //股票类型 现价 数据源的处理
         StockListVO  stockListVO = StockApi.getStockRealTime(stock);
         now_price = new BigDecimal(stockListVO.getNowPrice());
-
 
         if (now_price.compareTo(new BigDecimal("0")) == 0) {
             return ServerResponse.createByErrorMsg("Quote 0, please try again later");
@@ -320,29 +324,34 @@
         SiteProduct siteProduct = iSiteProductService.getProductSetting();
         UserPosition userPosition = this.userPositionMapper.findPositionBySn(positionSn);
         if (doType != 0) {
-            if (userPosition.getStockGid().contains(EStockType.US.getCode())) {
-                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);
-                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);
-                if (!am_flag && !pm_flag) {
-                    return ServerResponse.createByErrorMsg("Order failed,Out of trading hours");
-                }
-            }
-            if (siteProduct.getHolidayDisplay()) {
-                return ServerResponse.createByErrorMsg("No trading on weekends or holidays!");
+//            if (userPosition.getStockGid().contains(EStockType.US.getCode())) {
+//                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);
+//                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);
+//                if (!am_flag && !pm_flag) {
+//                    return ServerResponse.createByErrorMsg("Order failed,Out of trading hours");
+//                }
+//            }
+//            if (siteProduct.getHolidayDisplay()) {
+//                return ServerResponse.createByErrorMsg("No trading on weekends or holidays!");
+//            }
+            //判断股票是否在可交易时间段
+            Boolean b = tradingHourService.timeCheck();
+            if (!b) {
+                return ServerResponse.createByErrorMsg("Order failed, not in the  stock trading session");
             }
 
         }
@@ -400,6 +409,11 @@
     @Transactional
     @Override
     public ServerResponse allSell(HttpServletRequest request,String stockType) throws Exception{
+        //判断股票是否在可交易时间段
+        Boolean b = tradingHourService.timeCheck();
+        if (!b) {
+            return ServerResponse.createByErrorMsg("Order failed, not in the  stock trading session");
+        }
         User user =    iUserService.getCurrentUser(request);
         if(user == null){
             return ServerResponse.createByErrorMsg("Please login");

--
Gitblit v1.9.3