| | |
| | | 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.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import org.dromara.common.core.constant.CacheConstants; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.dromara.common.core.constant.CacheNames; |
| | | import org.dromara.common.core.exception.ServiceException; |
| | | import org.dromara.common.core.service.DictService; |
| | |
| | | import org.dromara.system.mapper.SysDictDataMapper; |
| | | import org.dromara.system.mapper.SysDictTypeMapper; |
| | | import org.dromara.system.service.ISysDictTypeService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.cache.annotation.CachePut; |
| | | import org.springframework.cache.annotation.Cacheable; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | */ |
| | | @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)); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | CacheUtils.evict(CacheNames.SYS_DICT, dictType.getDictType()); |
| | | } |
| | | baseMapper.deleteBatchIds(Arrays.asList(dictIds)); |
| | | baseMapper.deleteByIds(Arrays.asList(dictIds)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param separator 分隔符 |
| | | * @return 字典标签 |
| | | */ |
| | | @SuppressWarnings("unchecked cast") |
| | | @Override |
| | | public String getDictLabel(String dictType, String dictValue, String separator) { |
| | | // 优先从本地缓存获取 |
| | | List<SysDictDataVo> datas = (List<SysDictDataVo>) SaHolder.getStorage().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); |
| | | } |
| | | |
| | | List<SysDictDataVo> datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); |
| | | Map<String, String> map = StreamUtils.toMap(datas, SysDictDataVo::getDictValue, SysDictDataVo::getDictLabel); |
| | | if (StringUtils.containsAny(dictValue, separator)) { |
| | | return Arrays.stream(dictValue.split(separator)) |
| | |
| | | * @param separator 分隔符 |
| | | * @return 字典值 |
| | | */ |
| | | @SuppressWarnings("unchecked cast") |
| | | @Override |
| | | public String getDictValue(String dictType, String dictLabel, String separator) { |
| | | // 优先从本地缓存获取 |
| | | List<SysDictDataVo> datas = (List<SysDictDataVo>) SaHolder.getStorage().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); |
| | | } |
| | | |
| | | List<SysDictDataVo> datas = SpringUtils.getAopProxy(this).selectDictDataByType(dictType); |
| | | Map<String, String> map = StreamUtils.toMap(datas, SysDictDataVo::getDictLabel, SysDictDataVo::getDictValue); |
| | | if (StringUtils.containsAny(dictLabel, separator)) { |
| | | return Arrays.stream(dictLabel.split(separator)) |