From 41b107ba7acd40fa32ce9ec8f103dfe1061ecf4e Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Wed, 03 Sep 2025 16:52:33 +0800
Subject: [PATCH] 初始化修改

---
 trading-order-service/src/main/java/com/yami/trading/service/item/ItemService.java |   55 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/trading-order-service/src/main/java/com/yami/trading/service/item/ItemService.java b/trading-order-service/src/main/java/com/yami/trading/service/item/ItemService.java
index 577f5c6..c3230f7 100644
--- a/trading-order-service/src/main/java/com/yami/trading/service/item/ItemService.java
+++ b/trading-order-service/src/main/java/com/yami/trading/service/item/ItemService.java
@@ -49,7 +49,6 @@
 
     private Map<String, Integer> symbolDecimal = Maps.newHashMap();
 
-
     @Autowired
     private CacheManager cacheManager;
     private Cache<String, List<Item>> itemCache;
@@ -162,7 +161,7 @@
     @Cached(name = ITEM_CACHE, key = "'all'", expire = 3600)
     @Override
     public List<Item> list() {
-        List<Item> list = super.list();
+        List<Item> list = super.list(new LambdaQueryWrapper<>(Item.class).eq(Item::getType,Item.cryptos));
         symbolDecimal = list.stream()
                 .collect(Collectors.toMap(Item::getSymbol, Item::getDecimals, (s1, s2) -> s2));
         return list;
@@ -180,6 +179,23 @@
         return super.removeById(id);
     }
 
+    // 清除 list() 方法的缓存(关键:与@Cached的name和key一致)
+    /*@CacheEvict(cacheNames = ITEM_CACHE, key = "'all'")
+    public void clearListCache() {
+        log.info("已清除 list() 方法的缓存");
+    }*/
+
+    public void reloadListAndCache() {
+        // 步骤1:清除 list() 方法的原有缓存(确保重新查询)
+        //clearListCache();
+
+        // 步骤2:重新调用 list() 方法,此时会执行数据库查询,且@Cached会自动更新缓存
+        //List<Item> freshList = list();
+
+        // 步骤3(可选):如果需要同步更新 init() 方法中的 itemCache,重新调用 init()
+        init();
+        log.info("初始化init()");
+    }
 
     /**
      * 获取品种精度
@@ -203,7 +219,7 @@
     }
 
     public List<Item> cacheGetAll() {
-        return ApplicationContextUtils.getApplicationContext().getBean(ItemService.class).list();
+        return ApplicationContextUtils.getApplicationContext().getBean(ItemService.class).list(new LambdaQueryWrapper<>(Item.class).eq(Item::getType,Item.cryptos));
     }
 
 
@@ -229,4 +245,37 @@
         Item bySymbol = findBySymbol(symbol);
         return MarketOpenChecker.isMarketOpenByItemCloseType(bySymbol.getOpenCloseType());
     }
+
+    /**
+     * 是否开放合约
+     * @param item
+     * @return
+     */
+    public boolean isContractTrading(Item item) {
+        item = getById(item.getUuid());
+        //虚拟币新币才判断
+        if (item.getType().equals(Item.cryptos) && (item.getCurrencyType() != null && item.getCurrencyType() == 1)) {
+            if (item.getTradeType() != null && item.getTradeType().equals("0")) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    /**
+     * 是否停牌状态
+     * @param item
+     * @return
+     */
+    public boolean isSuspended(Item item) {
+        item = getById(item.getUuid());
+        //虚拟币新币才判断
+        if (item.getType().equals(Item.cryptos) && (item.getCurrencyType() != null && item.getCurrencyType() == 1)) {
+            if (item.getStatus() != null && item.getStatus() == 0) {
+                return true;
+            }
+        }
+        return false;
+    }
+
 }

--
Gitblit v1.9.3