From d2a4dd9c837f8df2a19e58f7fb4c81a91c114b67 Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期五, 15 八月 2025 13:15:32 +0800
Subject: [PATCH] 自动加想接口

---
 code_attribute/gpcode_manager.py |   73 +++++++++++++++++++++++++++---------
 1 files changed, 54 insertions(+), 19 deletions(-)

diff --git a/code_attribute/gpcode_manager.py b/code_attribute/gpcode_manager.py
index 9ab6e76..8209c38 100644
--- a/code_attribute/gpcode_manager.py
+++ b/code_attribute/gpcode_manager.py
@@ -8,7 +8,7 @@
 from db import redis_manager_delegate as redis_manager
 from db.mysql_data_delegate import Mysqldb
 from db.redis_manager_delegate import RedisUtils
-from log_module import log_export
+from log_module import log_export, async_log_util
 from log_module.log import logger_pre_close_price, logger_debug
 from trade import trade_record_log_util
 from utils import tool
@@ -285,7 +285,6 @@
         return code in self.__codes_cache
 
 
-
 # 鏆傚仠涓嬪崟浠g爜绠$悊
 # 涓庨粦鍚嶅崟鐨勫尯鍒槸鏆傚仠浜ゆ槗浠g爜鍙槸涓嶄氦鏄擄紝涓嶈兘绉婚櫎L2鐩戞帶浣�
 class PauseBuyCodesManager:
@@ -401,6 +400,7 @@
 class WhiteListCodeManager:
     __instance = None
     __redis_manager = redis_manager.RedisManager(2)
+    __human_remove_codes = set()
 
     def __new__(cls, *args, **kwargs):
         if not cls.__instance:
@@ -421,14 +421,21 @@
         if data:
             self.__white_codes_cache |= data
 
-    def add_code(self, code):
+    def add_code(self, code, is_human=False):
+
+        if not is_human and code in self.__human_remove_codes:
+            # 鏈哄櫒鍔犵櫧锛屼笖琚汉涓虹Щ鐧戒簡灏变笉鑳藉啀鍔犵櫧
+            return
+
         self.__white_codes_cache.add(code)
         RedisUtils.sadd(self.__get_redis(), "white_list_codes", code)
         RedisUtils.expire(self.__get_redis(), "white_list_codes", tool.get_expire())
 
-    def remove_code(self, code):
+    def remove_code(self, code, is_human=False):
         self.__white_codes_cache.discard(code)
         RedisUtils.srem(self.__get_redis(), "white_list_codes", code)
+        if is_human:
+            self.human_remove(code)
 
     def is_in(self, code):
         return RedisUtils.sismember(self.__get_redis(), "white_list_codes", code)
@@ -445,6 +452,23 @@
     def clear(self):
         self.__white_codes_cache.clear()
         RedisUtils.delete(self.__get_redis(), "white_list_codes")
+
+    def human_remove(self, code):
+        """
+        浜轰负绉荤櫧
+        @param code:
+        @return:
+        """
+        self.__human_remove_codes.add(code)
+
+    def clear_huamn_info(self, code):
+        """
+        绉婚櫎浜轰负骞查淇℃伅
+        @param code:
+        @return:
+        """
+        if code in self.__human_remove_codes:
+            self.__human_remove_codes.discard(code)
 
 
 class BlackListCodeManager:
@@ -743,36 +767,42 @@
     return list
 
 
+@tool.singleton
 class CodePrePriceManager:
     __price_pre_cache = {}
     __redisManager = redis_manager.RedisManager(0)
 
+    def __init__(self):
+        fdatas = log_export.load_pre_close_price()
+        for code, v in fdatas.items():
+            self.__price_pre_cache[code] = round(float(v), 2)
+
     # 鑾峰彇鏀剁洏浠�
-    @classmethod
-    def get_price_pre(cls, code):
+    def get_price_pre(self, code):
         fdatas = log_export.load_pre_close_price()
         if code in fdatas:
             return round(float(fdatas.get(code)), 2)
         return None
 
     # 鑾峰彇缂撳瓨
-    @classmethod
-    def get_price_pre_cache(cls, code):
-        if code in cls.__price_pre_cache:
-            return float(cls.__price_pre_cache[code])
-        val = cls.get_price_pre(code)
+    def get_price_pre_cache(self, code):
+        if code in self.__price_pre_cache:
+            return float(self.__price_pre_cache[code])
+        val = self.get_price_pre(code)
         if val:
-            cls.__price_pre_cache[code] = val
+            self.__price_pre_cache[code] = val
         return val
 
     # 璁剧疆鏀剁洏浠�
-    @classmethod
-    def set_price_pre(cls, code, price, force=False):
-        if code in cls.__price_pre_cache and not force:
+    def set_price_pre(self, code, price, force=False):
+        if float(price) > 1000:
+            async_log_util.info(logger_debug, f"鑾峰彇鏄ㄦ棩鏀剁洏浠峰紓甯革細{code}-{price}")
+            return
+        if code in self.__price_pre_cache and not force:
             return
         price = round(float(price), 2)
         logger_pre_close_price.info(f"{code}-{price}")
-        cls.__price_pre_cache[code] = price
+        self.__price_pre_cache[code] = price
 
 
 __limit_up_price_dict = {}
@@ -783,12 +813,17 @@
     # 璇诲彇鍐呭瓨涓殑鍊�
     if code in __limit_up_price_dict:
         return __limit_up_price_dict[code]
-    price = CodePrePriceManager.get_price_pre_cache(code)
+    price = CodePrePriceManager().get_price_pre_cache(code)
     if price is None:
         return None
     limit_up_price = tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal(tool.get_limit_up_rate(code)))
     __limit_up_price_dict[code] = limit_up_price
     return limit_up_price
+
+
+def clear_limit_up_price_cache(code):
+    if code in __limit_up_price_dict:
+        __limit_up_price_dict.pop(code)
 
 
 def get_limit_up_price_as_num(code):
@@ -818,7 +853,7 @@
 
 # 鑾峰彇璺屽仠浠�
 def get_limit_down_price(code):
-    price = CodePrePriceManager.get_price_pre_cache(code)
+    price = CodePrePriceManager().get_price_pre_cache(code)
     if price is None:
         return None
     return tool.to_price(decimal.Decimal(str(price)) * decimal.Decimal(f"{tool.get_limit_down_rate(code)}"))
@@ -945,4 +980,4 @@
         RedisUtils.delete(redis_instance, "first_code_record", auto_free=False)
         RedisUtils.delete(redis_instance, "first_code_limited_up_record", auto_free=False)
     finally:
-        RedisUtils.realse(redis_instance)
\ No newline at end of file
+        RedisUtils.realse(redis_instance)

--
Gitblit v1.8.0