package cn.service.system.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import cn.orm.abs.ISqlToyDao;
import cn.orm.sqltoy.plus.Wrappers;
import cn.orm.sqltoy.plus.query.LambdaQueryWrapper;
import cn.orm.util.cache.DictCacheUtil;
import cn.pojo.entity.TSysDictData;
import cn.service.system.ICacheService;
import cn.util.core.IsKit;

@Repository("ICacheService")
public class CacheServiceImpl implements ICacheService
{
	@Autowired
	private ISqlToyDao daoService;
	
	/**
	 * dictType字典类型的值：t_sys_dict_type.dict_type
	 * 字典数据集合信息
	 */
	@Override
	public List<TSysDictData> getDictDataByType(String dictType)
	{
		/*List<TSysDictData> dictDatas = DictCacheUtil.getDictCache(dictType);
		if (IsKit.isNotNullOrEmpty(dictDatas)) {
			return dictDatas;
		}*/
		//临时用  由于启动后 如已保存 而代码有所改动后会报错 为了方便调试 暂时用此语句替换上边
		//List<Map<String, Object>> dictDatas = new ArrayList<Map<String, Object>>();
		
		LambdaQueryWrapper<TSysDictData> queryUserWrapper = Wrappers.lambdaWrapper(TSysDictData.class)
				 .select(TSysDictData::getDictLabel)
				 .select(TSysDictData::getDictValue)
				 .eq(TSysDictData::getStatus,0)
                 .eq(TSysDictData::getDictType,dictType);
		List<TSysDictData> entityList = daoService.findList(queryUserWrapper);
		return entityList;
		/*
		if (IsKit.isNotNullOrEmpty(entityList)) {
			DictCacheUtil.setDictCache(dictType, entityList);
			return dictDatas;
		}
		return dictDatas;*/
	}
	
	/**清空缓存数据
	 * @param dictType 字典类型
	 */
	@Override
	public void clearCache(String dictType) {
		DictCacheUtil.clearDictCache(dictType);
	}
	/**
	 * 清空缓存数据
	 */
	@Override
	public void clearCache() {
		DictCacheUtil.clearDictCache();
	}
}
