From 4046f94a57f0c10e9509a49ad0d37d701aeb8186 Mon Sep 17 00:00:00 2001
From: jack <zengjieli93@163.com>
Date: Tue, 02 Apr 2024 23:47:51 +0800
Subject: [PATCH] 修复自选bug 和 增加流水日志

---
 src/main/java/com/nq/service/impl/UserPositionServiceImpl.java |  124 ++++++++++++++---------------------------
 1 files changed, 42 insertions(+), 82 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..8560221 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,14 +102,12 @@
     @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);
-        /*实名认证开关开启*/
         SiteProduct siteProduct = iSiteProductService.getProductSetting();
 
         User user = this.iUserService.getCurrentRefreshUser(request);
@@ -123,6 +119,7 @@
         if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) {
             return ServerResponse.createByErrorMsg("Order failed, account has been locked");
         }
+
         SiteSetting siteSetting = this.iSiteSettingService.getSiteSetting();
         if (siteSetting == null) {
             log.error("下单出错,网站设置表不存在");
@@ -133,68 +130,21 @@
         if (stock == null) {
             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!");
-            }
+        //判断股票是否在可交易时间段
+        Boolean b = tradingHourService.timeCheck();
+        if (!b) {
+            return ServerResponse.createByErrorMsg("Order failed, not in the  stock trading session");
         }
 
 
-        if (stock.getIsLock().intValue() != 0) {
+        if (stock.getIsLock() != 0) {
             return ServerResponse.createByErrorMsg("Order failed, shares cannot be traded at present");
         }
 
-        List dbPosition = findPositionByStockCodeAndTimes(siteSetting.getBuySameTimes().intValue(), stock
-                .getStockCode(), user.getId());
-        if (dbPosition.size() >= siteSetting.getBuySameNums().intValue()) {
-            return ServerResponse.createByErrorMsg("Frequent trading," + siteSetting.getBuySameTimes() + "Hold no more than one stock within a minute" + siteSetting
-                    .getBuySameNums() + "article");
-        }
-
-        Integer transNum = findPositionNumByTimes(siteSetting.getBuyNumTimes().intValue(), user.getId());
-        if (transNum.intValue() / 100 >= siteSetting.getBuyNumLots().intValue()) {
-            return ServerResponse.createByErrorMsg("Frequent trading," + siteSetting
-                    .getBuyNumTimes() + "Hold no more than one stock within a minute" + siteSetting.getBuyNumLots() + "hand");
-        }
-
-        if (buyNum.intValue() < siteSetting.getBuyMinNum().intValue()) {
-            return ServerResponse.createByErrorMsg("Order failed, purchase quantity is less than" + siteSetting
-                    .getBuyMinNum() );
-        }
-        if (buyNum.intValue() > siteSetting.getBuyMaxNum().intValue()) {
-            return ServerResponse.createByErrorMsg("Order failed, purchase quantity is greater than于" + siteSetting
-                    .getBuyMaxNum() + "stocks");
-        }
         BigDecimal now_price;
         //股票类型 现价 数据源的处理
         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 +270,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 +355,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