package com.vincent.rsf.server.manager.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.vincent.rsf.server.manager.enums.OrderWorkType; import com.vincent.rsf.server.manager.service.OrderWorkTypeService; import com.vincent.rsf.server.system.constant.DictTypeCode; import com.vincent.rsf.server.system.entity.DictData; import com.vincent.rsf.server.system.service.DictDataService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; /** * 订单业务类型:优先从字典表读取(可配置),无则回退到 OrderWorkType 枚举。 */ @Slf4j @Service public class OrderWorkTypeServiceImpl implements OrderWorkTypeService { @Resource private DictDataService dictDataService; private volatile List cache; private static final Object CACHE_LOCK = new Object(); @Override public List listAll() { if (cache != null && !cache.isEmpty()) { return cache; } synchronized (CACHE_LOCK) { if (cache != null && !cache.isEmpty()) { return cache; } List list = dictDataService.list(new LambdaQueryWrapper() .eq(DictData::getDictTypeCode, DictTypeCode.DICT_ORDER_WORK_TYPE) .eq(DictData::getStatus, 1) .orderByAsc(DictData::getSort)); cache = list; return cache; } } @Override public String getTypeByLabel(String label) { if (label == null || label.isEmpty()) { return null; } for (DictData d : listAll()) { if (label.equals(d.getLabel())) { return d.getValue(); } } // 回退到枚举 return OrderWorkType.getWorkType(label); } @Override public String getLabelByType(String type) { if (type == null || type.isEmpty()) { return null; } for (DictData d : listAll()) { if (type.equals(d.getValue())) { return d.getLabel(); } } // 回退到枚举 return OrderWorkType.getWorkDesc(type); } @Override public void refreshCache() { synchronized (CACHE_LOCK) { cache = null; } log.info("订单业务类型字典缓存已刷新"); } }