新版仿ok交易所-后端
1
zyy
2026-03-24 513e5442723f501525bf9ca6210b16561e5d3a2b
trading-order-service/src/main/java/com/yami/trading/service/item/ItemService.java
@@ -16,12 +16,14 @@
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.bean.item.dto.ItemDTO;
import com.yami.trading.bean.item.dto.ItemLeverageDTO;
import com.yami.trading.bean.robot.domain.Robot;
import com.yami.trading.common.util.ApplicationContextUtils;
import com.yami.trading.common.util.MarketOpenChecker;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.dao.item.ItemMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -41,8 +43,8 @@
@Transactional
@Slf4j
public class ItemService extends ServiceImpl<ItemMapper, Item> {
    public static final String ITEM_CACHE = "mdItemCache";
    public static final String ALL = "mdAll";
    public static final String ITEM_CACHE = "itemCache";
    public static final String ALL = "all";
    @Autowired
    private ItemLeverageService itemLeverageService;
@@ -127,6 +129,13 @@
        return super.baseMapper.selectOne(queryWrapper);
    }
    public Item findCurrBySymbol(String symbol) {
        LambdaQueryWrapper<Item> queryWrapper = new LambdaQueryWrapper<Item>()
                .eq(Item::getSymbol, symbol)
                .last("LIMIT 1");
        return super.baseMapper.selectOne(queryWrapper);
    }
    /**
     * 根据id查询
@@ -179,22 +188,8 @@
        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()");
    }
    /**
@@ -267,12 +262,15 @@
     * @return
     */
    public boolean isSuspended(String symbol) {
        Item item = findBySymbol(symbol);
        //虚拟币新币才判断
        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;
        //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;