feat(service): 新增字典管理业务逻辑层
- 新增SysDictTypeService字典类型业务接口和实现 - 新增SysDictDataService字典数据业务接口和实现 - 实现完整的CRUD操作和分页查询 - 集成Redis缓存机制和缓存同步 - 支持字典数据的缓存预热和刷新
This commit is contained in:
parent
c53be83c20
commit
f887d73063
@ -0,0 +1,17 @@
|
|||||||
|
package org.leocoder.thin.system.service.dictdata;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.leocoder.thin.domain.pojo.system.SysDictData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [字典数据表-服务实现层接口]
|
||||||
|
*/
|
||||||
|
public interface SysDictDataService extends IService<SysDictData> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [字典数据同步Redis进行缓存]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
void listDictCacheRedis();
|
||||||
|
}
|
||||||
@ -0,0 +1,62 @@
|
|||||||
|
package org.leocoder.thin.system.service.dictdata;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.leocoder.thin.common.constants.CoderCacheConstants;
|
||||||
|
import org.leocoder.thin.common.constants.CoderConstants;
|
||||||
|
import org.leocoder.thin.common.utils.cache.RedisUtil;
|
||||||
|
import org.leocoder.thin.domain.pojo.system.SysDictData;
|
||||||
|
import org.leocoder.thin.domain.pojo.system.SysDictType;
|
||||||
|
import org.leocoder.thin.mybatisplus.mapper.system.SysDictDataMapper;
|
||||||
|
import org.leocoder.thin.mybatisplus.mapper.system.SysDictTypeMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [字典数据表-服务实现层]
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData> implements SysDictDataService {
|
||||||
|
|
||||||
|
private final SysDictDataMapper sysDictDataMapper;
|
||||||
|
|
||||||
|
private final SysDictTypeMapper sysDictTypeMapper;
|
||||||
|
|
||||||
|
private final RedisUtil redisUtil;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description [字典数据同步Redis进行缓存]
|
||||||
|
* @author Leocoder
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void listDictCacheRedis() {
|
||||||
|
// 1、查询所有可用的字典数据
|
||||||
|
LambdaQueryWrapper<SysDictType> dictTypeWrapper = new LambdaQueryWrapper<>();
|
||||||
|
dictTypeWrapper.select(SysDictType::getDictType, SysDictType::getDictStatus);
|
||||||
|
List<SysDictType> dictTypeList = sysDictTypeMapper.selectList(dictTypeWrapper);
|
||||||
|
if (CollectionUtil.isNotEmpty(dictTypeList)) {
|
||||||
|
// 2、根据字典类型查询字典数据
|
||||||
|
for (SysDictType sysDictType : dictTypeList) {
|
||||||
|
if (sysDictType.getDictStatus().equals(CoderConstants.ZERO_STRING)) {
|
||||||
|
LambdaQueryWrapper<SysDictData> dictDataWrapper = new LambdaQueryWrapper<>();
|
||||||
|
dictDataWrapper.eq(SysDictData::getDictStatus, CoderConstants.ZERO_STRING);
|
||||||
|
dictDataWrapper.eq(SysDictData::getDictType, sysDictType.getDictType());
|
||||||
|
dictDataWrapper.orderByAsc(SysDictData::getSorted);
|
||||||
|
List<SysDictData> dictDataList = sysDictDataMapper.selectList(dictDataWrapper);
|
||||||
|
// 3、把字典数据循环存到Redis,设计Redis的key:CoderDict:dictType -> [{},{},{}]
|
||||||
|
redisUtil.setCacheObject(CoderCacheConstants.DICT_REDIS_KEY + sysDictType.getDictType(), dictDataList);
|
||||||
|
} else {
|
||||||
|
redisUtil.deleteKey(CoderCacheConstants.DICT_REDIS_KEY + sysDictType.getDictType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
package org.leocoder.thin.system.service.dicttype;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import org.leocoder.thin.domain.pojo.system.SysDictType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [字典类型表-服务实现层接口]
|
||||||
|
*/
|
||||||
|
public interface SysDictTypeService extends IService<SysDictType> {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
package org.leocoder.thin.system.service.dicttype;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.leocoder.thin.domain.pojo.system.SysDictType;
|
||||||
|
import org.leocoder.thin.mybatisplus.mapper.system.SysDictTypeMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Leocoder
|
||||||
|
* @description [字典类型表-服务实现层]
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Service
|
||||||
|
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements SysDictTypeService {
|
||||||
|
|
||||||
|
private final SysDictTypeMapper sysDictTypeMapper;
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user