package com.ycl.service.dict.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ycl.entity.dict.DatabaseDictionary; import com.ycl.mapper.dict.DatabaseDictionaryMapper; import com.ycl.service.dict.IDatabaseDictionaryService; import com.ycl.service.redis.RedisService; import com.ycl.utils.common.LiveTimeMillisecond; import com.ycl.utils.redis.RedisKey; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.List; /** *

* 服务实现类 *

* * @author lyq * @since 2022-09-15 */ @Service public class DatabaseDictionaryServiceImpl extends ServiceImpl implements IDatabaseDictionaryService { @Resource private DatabaseDictionaryMapper databaseDictionaryMapper; @Resource private RedisService redisService; @Override public List getAll() { String key = RedisKey.DICT; String result = (String) redisService.get(key.concat("all")); if (StringUtils.isBlank(result)) { List dictList = databaseDictionaryMapper.selectList(null); redisService.set(key.concat("all"), JSON.toJSONString(dictList), LiveTimeMillisecond.s86400.time); return dictList; } List list = JSONArray.parseArray(result, DatabaseDictionary.class); return list; } @Override public DatabaseDictionary queryByCode(String code) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper().eq(DatabaseDictionary::getTypeCode, code); DatabaseDictionary databaseDictionary = databaseDictionaryMapper.selectOne(queryWrapper); return databaseDictionary; } }