| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.domain.entity.SysDictData; |
| | | import com.ruoyi.common.utils.DictUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.constant.CacheNames; |
| | | import com.ruoyi.common.core.domain.PageQuery; |
| | | import com.ruoyi.system.domain.SysDictData; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.redis.CacheUtils; |
| | | import com.ruoyi.system.mapper.SysDictDataMapper; |
| | | import com.ruoyi.system.service.ISysDictDataService; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.cache.annotation.CachePut; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 字典 业务层处理 |
| | | * |
| | | * @author ruoyi |
| | | * @author Lion Li |
| | | */ |
| | | @RequiredArgsConstructor |
| | | @Service |
| | | public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData> implements ISysDictDataService { |
| | | public class SysDictDataServiceImpl implements ISysDictDataService { |
| | | |
| | | private final SysDictDataMapper baseMapper; |
| | | |
| | | @Override |
| | | public TableDataInfo<SysDictData> selectPageDictDataList(SysDictData dictData, PageQuery pageQuery) { |
| | | LambdaQueryWrapper<SysDictData> lqw = new LambdaQueryWrapper<SysDictData>() |
| | | .eq(StringUtils.isNotBlank(dictData.getDictType()), SysDictData::getDictType, dictData.getDictType()) |
| | | .like(StringUtils.isNotBlank(dictData.getDictLabel()), SysDictData::getDictLabel, dictData.getDictLabel()) |
| | | .eq(StringUtils.isNotBlank(dictData.getStatus()), SysDictData::getStatus, dictData.getStatus()) |
| | | .orderByAsc(SysDictData::getDictSort); |
| | | Page<SysDictData> page = baseMapper.selectPage(pageQuery.build(), lqw); |
| | | return TableDataInfo.build(page); |
| | | } |
| | | |
| | | /** |
| | | * 根据条件分页查询字典数据 |
| | |
| | | */ |
| | | @Override |
| | | public List<SysDictData> selectDictDataList(SysDictData dictData) { |
| | | return list(new LambdaQueryWrapper<SysDictData>().eq(StrUtil.isNotBlank(dictData.getDictType()), SysDictData::getDictType, dictData.getDictType()) |
| | | .like(StrUtil.isNotBlank(dictData.getDictLabel()), SysDictData::getDictLabel, dictData.getDictLabel()) |
| | | .eq(StrUtil.isNotBlank(dictData.getStatus()), SysDictData::getStatus, dictData.getStatus()) |
| | | .orderByAsc(SysDictData::getDictSort)); |
| | | return baseMapper.selectList(new LambdaQueryWrapper<SysDictData>() |
| | | .eq(StringUtils.isNotBlank(dictData.getDictType()), SysDictData::getDictType, dictData.getDictType()) |
| | | .like(StringUtils.isNotBlank(dictData.getDictLabel()), SysDictData::getDictLabel, dictData.getDictLabel()) |
| | | .eq(StringUtils.isNotBlank(dictData.getStatus()), SysDictData::getStatus, dictData.getStatus()) |
| | | .orderByAsc(SysDictData::getDictSort)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public String selectDictLabel(String dictType, String dictValue) { |
| | | return getOne(new LambdaQueryWrapper<SysDictData>() |
| | | return baseMapper.selectOne(new LambdaQueryWrapper<SysDictData>() |
| | | .select(SysDictData::getDictLabel) |
| | | .eq(SysDictData::getDictType, dictType) |
| | | .eq(SysDictData::getDictValue, dictValue)) |
| | | .getDictLabel(); |
| | | .getDictLabel(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public SysDictData selectDictDataById(Long dictCode) { |
| | | return getById(dictCode); |
| | | return baseMapper.selectById(dictCode); |
| | | } |
| | | |
| | | /** |
| | | * 批量删除字典数据信息 |
| | | * |
| | | * @param dictCodes 需要删除的字典数据ID |
| | | * @return 结果 |
| | | */ |
| | | @Override |
| | | public int deleteDictDataByIds(Long[] dictCodes) { |
| | | int row = baseMapper.deleteBatchIds(Arrays.asList(dictCodes)); |
| | | if (row > 0) { |
| | | DictUtils.clearDictCache(); |
| | | public void deleteDictDataByIds(Long[] dictCodes) { |
| | | for (Long dictCode : dictCodes) { |
| | | SysDictData data = selectDictDataById(dictCode); |
| | | baseMapper.deleteById(dictCode); |
| | | CacheUtils.evict(CacheNames.SYS_DICT, data.getDictType()); |
| | | } |
| | | return row; |
| | | } |
| | | |
| | | /** |
| | | * 新增保存字典数据信息 |
| | | * |
| | | * @param dictData 字典数据信息 |
| | | * @param data 字典数据信息 |
| | | * @return 结果 |
| | | */ |
| | | @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#data.dictType") |
| | | @Override |
| | | public int insertDictData(SysDictData dictData) { |
| | | int row = baseMapper.insert(dictData); |
| | | public List<SysDictData> insertDictData(SysDictData data) { |
| | | int row = baseMapper.insert(data); |
| | | if (row > 0) { |
| | | DictUtils.clearDictCache(); |
| | | return baseMapper.selectDictDataByType(data.getDictType()); |
| | | } |
| | | return row; |
| | | throw new ServiceException("操作失败"); |
| | | } |
| | | |
| | | /** |
| | | * 修改保存字典数据信息 |
| | | * |
| | | * @param dictData 字典数据信息 |
| | | * @param data 字典数据信息 |
| | | * @return 结果 |
| | | */ |
| | | @CachePut(cacheNames = CacheNames.SYS_DICT, key = "#data.dictType") |
| | | @Override |
| | | public int updateDictData(SysDictData dictData) { |
| | | int row = baseMapper.updateById(dictData); |
| | | public List<SysDictData> updateDictData(SysDictData data) { |
| | | int row = baseMapper.updateById(data); |
| | | if (row > 0) { |
| | | DictUtils.clearDictCache(); |
| | | return baseMapper.selectDictDataByType(data.getDictType()); |
| | | } |
| | | return row; |
| | | throw new ServiceException("操作失败"); |
| | | } |
| | | |
| | | } |