From 09991e316ce092d0b05a198aad9d58e78e06f69b Mon Sep 17 00:00:00 2001
From: Administrator <admin@example.com>
Date: 星期四, 23 五月 2024 10:55:13 +0800
Subject: [PATCH] bug修复

---
 code_attribute/target_codes_manager.py |   46 ++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/code_attribute/target_codes_manager.py b/code_attribute/target_codes_manager.py
index 0964f40..1dcec7b 100644
--- a/code_attribute/target_codes_manager.py
+++ b/code_attribute/target_codes_manager.py
@@ -12,6 +12,10 @@
 __valid_codes_cache = {}
 # 姝h偂鍒板彲杞�轰唬鐮佺殑绱㈠紩
 __valid_underlying_code_map_cache = {}
+
+# 鍙浆鍊轰唬鐮佸埌姝h偂浠g爜鐨勭储寮�
+__valid_cb_to_underlying_code_map_cache = {}
+
 # 鍙浆鍊烘槰鏃ユ敹鐩樹环
 __valid_pre_close_price_map_cache = {}
 
@@ -60,14 +64,16 @@
         __valid_codes_cache[day] = results
         __valid_underlying_code_map_cache[day] = {}
         __valid_pre_close_price_map_cache[day] = {}
+        __valid_cb_to_underlying_code_map_cache[day] = {}
         for r in results:
             __valid_underlying_code_map_cache[day][r['underlying_symbol'].split('.')[1]] = r['sec_id']
+            __valid_cb_to_underlying_code_map_cache[day][r['sec_id']] = r['underlying_symbol'].split('.')[1]
             __valid_pre_close_price_map_cache[day][r['sec_id']] = r['pre_close']
 
 
-def get_subscript_codes():
+def get_subscript_underlying_codes():
     """
-    鑾峰彇闇�瑕佽闃呯殑浠g爜
+    鑾峰彇闇�瑕佽闃呯殑姝h偂浠g爜
     :return:
     """
     day = tool.get_now_date_str()
@@ -77,7 +83,19 @@
     return [x['underlying_symbol'].split('.')[1] for x in ffresults]
 
 
-def get_underlying_code_map():
+def get_subscript_cb_codes():
+    """
+    鑾峰彇闇�瑕佽闃呯殑浠g爜
+    :return:
+    """
+    day = tool.get_now_date_str()
+    if not __valid_codes_cache.get(day):
+        load_valid_codes_info(tool.get_now_date_str())
+    ffresults = __valid_codes_cache.get(tool.get_now_date_str())
+    return [x['sec_id'] for x in ffresults]
+
+
+def get_underlying_to_cb_code_map():
     """
     鑾峰彇鑲$エ浠g爜-鍙浆鍊轰唬鐮佺殑map
     :param code:
@@ -90,13 +108,33 @@
     return __valid_underlying_code_map_cache.get(day)
 
 
+def get_cb_to_underlying_code_map():
+    """
+    鑾峰彇鍙浆鍊轰唬鐮�-鑲$エ浠g爜鐨刴ap
+    :param code:
+    :return:
+    """
+    day = tool.get_now_date_str()
+    if day not in __valid_cb_to_underlying_code_map_cache:
+        load_valid_codes_info(day)
+
+    return __valid_cb_to_underlying_code_map_cache.get(day)
+
+
 def get_cb_code(code):
     """
     鑾峰彇鍙浆鍊轰唬鐮�
     :param code:
     :return:
     """
-    map = get_underlying_code_map()
+    map = get_underlying_to_cb_code_map()
+    if map:
+        return map.get(code)
+    return None
+
+
+def get_underlying_code(code):
+    map = get_cb_to_underlying_code_map()
     if map:
         return map.get(code)
     return None

--
Gitblit v1.8.0