提交 | 用户 | 时间
|
722af2
|
1 |
package com.dl.system.service.impl; |
X |
2 |
|
|
3 |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
4 |
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
5 |
import com.dl.common.constant.CacheNames; |
|
6 |
import com.dl.common.core.domain.PageQuery; |
|
7 |
import com.dl.common.core.domain.entity.SysDictData; |
|
8 |
import com.dl.common.core.page.TableDataInfo; |
|
9 |
import com.dl.common.exception.ServiceException; |
|
10 |
import com.dl.common.utils.StringUtils; |
|
11 |
import com.dl.common.utils.redis.CacheUtils; |
|
12 |
import com.dl.system.mapper.SysDictDataMapper; |
|
13 |
import com.dl.system.service.ISysDictDataService; |
|
14 |
import lombok.RequiredArgsConstructor; |
|
15 |
import org.springframework.cache.annotation.CachePut; |
|
16 |
import org.springframework.stereotype.Service; |
|
17 |
|
|
18 |
import java.util.List; |
|
19 |
|
|
20 |
/** |
|
21 |
* 字典 业务层处理 |
|
22 |
* |
|
23 |
* @author Lion Li |
|
24 |
*/ |
|
25 |
@RequiredArgsConstructor |
|
26 |
@Service |
|
27 |
public class SysDictDataServiceImpl implements ISysDictDataService { |
|
28 |
|
|
29 |
private final SysDictDataMapper baseMapper; |
|
30 |
|
|
31 |
@Override |
|
32 |
public TableDataInfo<SysDictData> selectPageDictDataList(SysDictData dictData, PageQuery pageQuery) { |
|
33 |
LambdaQueryWrapper<SysDictData> lqw = new LambdaQueryWrapper<SysDictData>() |
|
34 |
.eq(StringUtils.isNotBlank(dictData.getDictType()), SysDictData::getDictType, dictData.getDictType()) |
|
35 |
.like(StringUtils.isNotBlank(dictData.getDictLabel()), SysDictData::getDictLabel, dictData.getDictLabel()) |
|
36 |
.eq(StringUtils.isNotBlank(dictData.getStatus()), SysDictData::getStatus, dictData.getStatus()) |
|
37 |
.orderByAsc(SysDictData::getDictSort); |
|
38 |
Page<SysDictData> page = baseMapper.selectPage(pageQuery.build(), lqw); |
|
39 |
return TableDataInfo.build(page); |
|
40 |
} |
|
41 |
|
|
42 |
/** |
|
43 |
* 根据条件分页查询字典数据 |
|
44 |
* |
|
45 |
* @param dictData 字典数据信息 |
|
46 |
* @return 字典数据集合信息 |
|
47 |
*/ |
|
48 |
@Override |
|
49 |
public List<SysDictData> selectDictDataList(SysDictData dictData) { |
|
50 |
return baseMapper.selectList(new LambdaQueryWrapper<SysDictData>() |
|
51 |
.eq(StringUtils.isNotBlank(dictData.getDictType()), SysDictData::getDictType, dictData.getDictType()) |
|
52 |
.like(StringUtils.isNotBlank(dictData.getDictLabel()), SysDictData::getDictLabel, dictData.getDictLabel()) |
|
53 |
.eq(StringUtils.isNotBlank(dictData.getStatus()), SysDictData::getStatus, dictData.getStatus()) |
|
54 |
.orderByAsc(SysDictData::getDictSort)); |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* 根据字典类型和字典键值查询字典数据信息 |
|
59 |
* |
|
60 |
* @param dictType 字典类型 |
|
61 |
* @param dictValue 字典键值 |
|
62 |
* @return 字典标签 |
|
63 |
*/ |
|
64 |
@Override |
|
65 |
public String selectDictLabel(String dictType, String dictValue) { |
|
66 |
return baseMapper.selectOne(new LambdaQueryWrapper<SysDictData>() |
|
67 |
.select(SysDictData::getDictLabel) |
|
68 |
.eq(SysDictData::getDictType, dictType) |
|
69 |
.eq(SysDictData::getDictValue, dictValue)) |
|
70 |
.getDictLabel(); |
|
71 |
} |
|
72 |
|
|
73 |
/** |
|
74 |
* 根据字典数据ID查询信息 |
|
75 |
* |
|
76 |
* @param dictCode 字典数据ID |
|
77 |
* @return 字典数据 |
|
78 |
*/ |
|
79 |
@Override |
|
80 |
public SysDictData selectDictDataById(String dictCode) { |
|
81 |
return baseMapper.selectById(dictCode); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* 批量删除字典数据信息 |
|
86 |
* |
|
87 |
* @param dictCodes 需要删除的字典数据ID |
|
88 |
*/ |
|
89 |
@Override |
|
90 |
public void deleteDictDataByIds(String[] dictCodes) { |
|
91 |
for (String dictCode : dictCodes) { |
|
92 |
SysDictData data = selectDictDataById(dictCode); |
|
93 |
baseMapper.deleteById(dictCode); |
|
94 |
CacheUtils.evict(CacheNames.SYS_DICT, data.getDictType()); |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* 新增保存字典数据信息 |
|
100 |
* |
|
101 |
* @param data 字典数据信息 |
|
102 |
* @return 结果 |
|
103 |
*/ |
|
104 |
@CachePut(cacheNames = CacheNames.SYS_DICT, key = "#data.dictType") |
|
105 |
@Override |
|
106 |
public List<SysDictData> insertDictData(SysDictData data) { |
|
107 |
int row = baseMapper.insert(data); |
|
108 |
if (row > 0) { |
|
109 |
return baseMapper.selectDictDataByType(data.getDictType()); |
|
110 |
} |
|
111 |
throw new ServiceException("操作失败"); |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* 修改保存字典数据信息 |
|
116 |
* |
|
117 |
* @param data 字典数据信息 |
|
118 |
* @return 结果 |
|
119 |
*/ |
|
120 |
@CachePut(cacheNames = CacheNames.SYS_DICT, key = "#data.dictType") |
|
121 |
@Override |
|
122 |
public List<SysDictData> updateDictData(SysDictData data) { |
|
123 |
int row = baseMapper.updateById(data); |
|
124 |
if (row > 0) { |
|
125 |
return baseMapper.selectDictDataByType(data.getDictType()); |
|
126 |
} |
|
127 |
throw new ServiceException("操作失败"); |
|
128 |
} |
|
129 |
|
|
130 |
} |