| | |
| | | package org.dromara.system.service.impl; |
| | | |
| | | import cn.dev33.satoken.context.SaHolder; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import org.dromara.common.core.constant.CacheConstants; |
| | | import org.dromara.common.core.constant.CacheNames; |
| | | import org.dromara.common.core.context.ThreadLocalHolder; |
| | | import org.dromara.common.core.exception.ServiceException; |
| | | import org.dromara.common.core.service.DictService; |
| | | import org.dromara.common.core.utils.MapstructUtils; |
| | |
| | | LambdaQueryWrapper<SysDictType> lqw = Wrappers.lambdaQuery(); |
| | | lqw.like(StringUtils.isNotBlank(bo.getDictName()), SysDictType::getDictName, bo.getDictName()); |
| | | lqw.like(StringUtils.isNotBlank(bo.getDictType()), SysDictType::getDictType, bo.getDictType()); |
| | | lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysDictType::getStatus, bo.getStatus()); |
| | | lqw.between(params.get("beginTime") != null && params.get("endTime") != null, |
| | | SysDictType::getCreateTime, params.get("beginTime"), params.get("endTime")); |
| | | lqw.orderByAsc(SysDictType::getDictId); |
| | | return lqw; |
| | | } |
| | | |
| | |
| | | * @param dictType 字典类型 |
| | | * @return 字典类型 |
| | | */ |
| | | @Cacheable(cacheNames = CacheNames.SYS_DICT, key = "#dictType") |
| | | @Override |
| | | public SysDictTypeVo selectDictTypeByType(String dictType) { |
| | | return baseMapper.selectVoById(new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getDictType, dictType)); |
| | | return baseMapper.selectVoOne(new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getDictType, dictType)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#bo.dictType") |
| | | @Override |
| | | public List<SysDictTypeVo> insertDictType(SysDictTypeBo bo) { |
| | | public List<SysDictDataVo> insertDictType(SysDictTypeBo bo) { |
| | | SysDictType dict = MapstructUtils.convert(bo, SysDictType.class); |
| | | int row = baseMapper.insert(dict); |
| | | if (row > 0) { |
| | | // 新增 type 下无 data 数据 返回空防止缓存穿透 |
| | | return new ArrayList<>(); |
| | | } |
| | | throw new ServiceException("操作失败"); |
| | |
| | | @Override |
| | | public String getDictLabel(String dictType, String dictValue, String separator) { |
| | | // 优先从本地缓存获取 |
| | | List<SysDictDataVo> datas = (List<SysDictDataVo>) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType); |
| | | List<SysDictDataVo> datas = ThreadLocalHolder.get(CacheConstants.SYS_DICT_KEY + dictType); |
| | | if (ObjectUtil.isNull(datas)) { |
| | | datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); |
| | | SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas); |
| | | ThreadLocalHolder.set(CacheConstants.SYS_DICT_KEY + dictType, datas); |
| | | } |
| | | |
| | | Map<String, String> map = StreamUtils.toMap(datas, SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel); |
| | |
| | | @Override |
| | | public String getDictValue(String dictType, String dictLabel, String separator) { |
| | | // 优先从本地缓存获取 |
| | | List<SysDictDataVo> datas = (List<SysDictDataVo>) SaHolder.getStorage().get(CacheConstants.SYS_DICT_KEY + dictType); |
| | | List<SysDictDataVo> datas = ThreadLocalHolder.get(CacheConstants.SYS_DICT_KEY + dictType); |
| | | if (ObjectUtil.isNull(datas)) { |
| | | datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); |
| | | SaHolder.getStorage().set(CacheConstants.SYS_DICT_KEY + dictType, datas); |
| | | ThreadLocalHolder.set(CacheConstants.SYS_DICT_KEY + dictType, datas); |
| | | } |
| | | |
| | | Map<String, String> map = StreamUtils.toMap(datas, SysDictDataVo::getDictLabel, SysDictDataVo::getDictValue); |
| | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, String> getAllDictByDictType(String dictType) { |
| | | List<SysDictDataVo> list = selectDictDataByType(dictType); |
| | | return StreamUtils.toMap(list, SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel); |
| | | } |
| | | |
| | | } |