From ef1765cfa8a1d9ab65b35143eeb762a8c62e652c Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Mon, 20 Oct 2025 16:30:52 +0800
Subject: [PATCH] C2C
---
trading-order-service/src/main/java/com/yami/trading/service/item/ItemService.java | 64 +++++++++++++++++++++++++++++---
1 files changed, 58 insertions(+), 6 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..5e626e4 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
@@ -41,14 +41,13 @@
@Transactional
@Slf4j
public class ItemService extends ServiceImpl<ItemMapper, Item> {
- public static final String ITEM_CACHE = "itemCache";
- public static final String ALL = "all";
+ public static final String ITEM_CACHE = "syItemCache";
+ public static final String ALL = "syAll";
@Autowired
private ItemLeverageService itemLeverageService;
private Map<String, Integer> symbolDecimal = Maps.newHashMap();
-
@Autowired
private CacheManager cacheManager;
@@ -159,10 +158,10 @@
return baseMapper.findList(page, queryWrapper);
}
- @Cached(name = ITEM_CACHE, key = "'all'", expire = 3600)
+ @Cached(name = ITEM_CACHE, key = "'syAll'", 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,40 @@
Item bySymbol = findBySymbol(symbol);
return MarketOpenChecker.isMarketOpenByItemCloseType(bySymbol.getOpenCloseType());
}
+
+ /**
+ * 是否开放合约
+ * @param item
+ * @return
+ */
+ public boolean isContractTrading(Item item) {
+ item = findBySymbol(item.getSymbol());
+ //虚拟币新币才判断
+ if (item.getType().equals(Item.cryptos) && (item.getCurrencyType() != null && item.getCurrencyType() == 1)) {
+ if (item.getTradeType() != null && item.getTradeType().equals("0")) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * 是否停牌状态
+ * @return
+ */
+ public boolean isSuspended(String symbol) {
+ //Item item = findBySymbol(symbol);
+ Item item = getOne(new LambdaQueryWrapper<Item>().eq(Item::getSymbol, symbol));
+ if (item != null) {
+ //虚拟币新币才判断
+ if (item.getType().equals(Item.cryptos) /*&& (item.getCurrencyType() != null && item.getCurrencyType() == 1)*/) {
+ //item = getById(item.getUuid());
+ if (item.getStatus() != null && item.getStatus() == 0) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
}
--
Gitblit v1.9.3