package com.chinaweal.aiccs.aiccs.entbase.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chinaweal.aiccs.aiccs.entbase.entity.TREntPriseType;
import com.chinaweal.aiccs.aiccs.entbase.mapper.TREntPriseTypeMapper;
import com.chinaweal.aiccs.aiccs.entbase.service.TREntPriseTypeService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * <p>
 * 企业类型显示基础数据表 服务实现类
 * </p>
 *
 * @author <a href="https://blog.lroyia.top">lroyia</a>
 * @since 2021-02-07
 */
@Service
public class TREntPriseTypeServiceImpl extends ServiceImpl<TREntPriseTypeMapper, TREntPriseType> implements TREntPriseTypeService {

    private volatile static Map<String, TREntPriseType> CACHE = new ConcurrentHashMap<>();

    @Override
    public TREntPriseType getEntPriseTypeFromCache(String typeCode) {
        return CACHE.get(typeCode);
    }

    @Override
    public void flushCache() {
        synchronized (TREntPriseTypeServiceImpl.class){
            Map<String, TREntPriseType> map = new ConcurrentHashMap<>();
            List<TREntPriseType> list = list();
            list.forEach(each -> {
                map.put(each.getEnttypeid(), each);
            });
            CACHE = map;
        }
    }
}
