From 553c29ab8a46c9a07e3657fdd36a81a6bfde1afe Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期四, 23 九月 2021 19:13:58 +0800 Subject: [PATCH] update 整合 satoken 权限、鉴权一体化框架 --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java | 350 +++++++++++++++++++++++++++++++++------------------------- 1 files changed, 200 insertions(+), 150 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java index 19d9652..e334158 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java @@ -1,13 +1,17 @@ package com.ruoyi.system.service.impl; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.lang.Validator; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.ruoyi.common.utils.StringUtils; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.entity.SysDictData; import com.ruoyi.common.core.domain.entity.SysDictType; -import com.ruoyi.common.exception.CustomException; +import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.DictUtils; +import com.ruoyi.common.utils.PageUtils; import com.ruoyi.system.mapper.SysDictDataMapper; import com.ruoyi.system.mapper.SysDictTypeMapper; import com.ruoyi.system.service.ISysDictTypeService; @@ -16,7 +20,9 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.PostConstruct; +import java.util.Arrays; import java.util.List; +import java.util.Map; /** * 瀛楀吀 涓氬姟灞傚鐞� @@ -24,163 +30,207 @@ * @author ruoyi */ @Service -public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService { - @Autowired - private SysDictTypeMapper dictTypeMapper; +public class SysDictTypeServiceImpl extends ServicePlusImpl<SysDictTypeMapper, SysDictType, SysDictType> implements ISysDictTypeService { - @Autowired - private SysDictDataMapper dictDataMapper; + @Autowired + private SysDictDataMapper dictDataMapper; - /** - * 椤圭洰鍚姩鏃讹紝鍒濆鍖栧瓧鍏稿埌缂撳瓨 - */ - @PostConstruct - public void init() { - List<SysDictType> dictTypeList = dictTypeMapper.selectDictTypeAll(); - for (SysDictType dictType : dictTypeList) { - List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType()); - DictUtils.setDictCache(dictType.getDictType(), dictDatas); - } - } + /** + * 椤圭洰鍚姩鏃讹紝鍒濆鍖栧瓧鍏稿埌缂撳瓨 + */ + @PostConstruct + public void init() { + loadingDictCache(); + } - /** - * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瀛楀吀绫诲瀷 - * - * @param dictType 瀛楀吀绫诲瀷淇℃伅 - * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅 - */ - @Override - public List<SysDictType> selectDictTypeList(SysDictType dictType) { - return dictTypeMapper.selectDictTypeList(dictType); - } + @Override + public TableDataInfo<SysDictType> selectPageDictTypeList(SysDictType dictType) { + Map<String, Object> params = dictType.getParams(); + LambdaQueryWrapper<SysDictType> lqw = new LambdaQueryWrapper<SysDictType>() + .like(StringUtils.isNotBlank(dictType.getDictName()), SysDictType::getDictName, dictType.getDictName()) + .eq(StringUtils.isNotBlank(dictType.getStatus()), SysDictType::getStatus, dictType.getStatus()) + .like(StringUtils.isNotBlank(dictType.getDictType()), SysDictType::getDictType, dictType.getDictType()) + .apply(StringUtils.isNotEmpty(params.get("beginTime")), + "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')", + params.get("beginTime")) + .apply(StringUtils.isNotEmpty(params.get("endTime")), + "date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')", + params.get("endTime")); + return PageUtils.buildDataInfo(page(PageUtils.buildPage(), lqw)); + } - /** - * 鏍规嵁鎵�鏈夊瓧鍏哥被鍨� - * - * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅 - */ - @Override - public List<SysDictType> selectDictTypeAll() { - return dictTypeMapper.selectDictTypeAll(); - } + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ瀛楀吀绫诲瀷 + * + * @param dictType 瀛楀吀绫诲瀷淇℃伅 + * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅 + */ + @Override + public List<SysDictType> selectDictTypeList(SysDictType dictType) { + Map<String, Object> params = dictType.getParams(); + return list(new LambdaQueryWrapper<SysDictType>() + .like(StringUtils.isNotBlank(dictType.getDictName()), SysDictType::getDictName, dictType.getDictName()) + .eq(StringUtils.isNotBlank(dictType.getStatus()), SysDictType::getStatus, dictType.getStatus()) + .like(StringUtils.isNotBlank(dictType.getDictType()), SysDictType::getDictType, dictType.getDictType()) + .apply(StringUtils.isNotEmpty(params.get("beginTime")), + "date_format(create_time,'%y%m%d') >= date_format({0},'%y%m%d')", + params.get("beginTime")) + .apply(StringUtils.isNotEmpty(params.get("endTime")), + "date_format(create_time,'%y%m%d') <= date_format({0},'%y%m%d')", + params.get("endTime"))); + } - /** - * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ瀛楀吀鏁版嵁 - * - * @param dictType 瀛楀吀绫诲瀷 - * @return 瀛楀吀鏁版嵁闆嗗悎淇℃伅 - */ - @Override - public List<SysDictData> selectDictDataByType(String dictType) { - List<SysDictData> dictDatas = DictUtils.getDictCache(dictType); - if (CollUtil.isNotEmpty(dictDatas)) { - return dictDatas; - } - dictDatas = dictDataMapper.selectDictDataByType(dictType); - if (CollUtil.isNotEmpty(dictDatas)) { - DictUtils.setDictCache(dictType, dictDatas); - return dictDatas; - } - return null; - } + /** + * 鏍规嵁鎵�鏈夊瓧鍏哥被鍨� + * + * @return 瀛楀吀绫诲瀷闆嗗悎淇℃伅 + */ + @Override + public List<SysDictType> selectDictTypeAll() { + return list(); + } - /** - * 鏍规嵁瀛楀吀绫诲瀷ID鏌ヨ淇℃伅 - * - * @param dictId 瀛楀吀绫诲瀷ID - * @return 瀛楀吀绫诲瀷 - */ - @Override - public SysDictType selectDictTypeById(Long dictId) { - return dictTypeMapper.selectDictTypeById(dictId); - } + /** + * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ瀛楀吀鏁版嵁 + * + * @param dictType 瀛楀吀绫诲瀷 + * @return 瀛楀吀鏁版嵁闆嗗悎淇℃伅 + */ + @Override + public List<SysDictData> selectDictDataByType(String dictType) { + List<SysDictData> dictDatas = DictUtils.getDictCache(dictType); + if (CollUtil.isNotEmpty(dictDatas)) { + return dictDatas; + } + dictDatas = dictDataMapper.selectDictDataByType(dictType); + if (CollUtil.isNotEmpty(dictDatas)) { + DictUtils.setDictCache(dictType, dictDatas); + return dictDatas; + } + return null; + } - /** - * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ淇℃伅 - * - * @param dictType 瀛楀吀绫诲瀷 - * @return 瀛楀吀绫诲瀷 - */ - @Override - public SysDictType selectDictTypeByType(String dictType) { - return dictTypeMapper.selectDictTypeByType(dictType); - } + /** + * 鏍规嵁瀛楀吀绫诲瀷ID鏌ヨ淇℃伅 + * + * @param dictId 瀛楀吀绫诲瀷ID + * @return 瀛楀吀绫诲瀷 + */ + @Override + public SysDictType selectDictTypeById(Long dictId) { + return getById(dictId); + } - /** - * 鎵归噺鍒犻櫎瀛楀吀绫诲瀷淇℃伅 - * - * @param dictIds 闇�瑕佸垹闄ょ殑瀛楀吀ID - * @return 缁撴灉 - */ - @Override - public int deleteDictTypeByIds(Long[] dictIds) { - for (Long dictId : dictIds) { - SysDictType dictType = selectDictTypeById(dictId); - if (dictDataMapper.countDictDataByType(dictType.getDictType()) > 0) { - throw new CustomException(String.format("%1$s宸插垎閰�,涓嶈兘鍒犻櫎", dictType.getDictName())); - } - } - int count = dictTypeMapper.deleteDictTypeByIds(dictIds); - if (count > 0) { - DictUtils.clearDictCache(); - } - return count; - } + /** + * 鏍规嵁瀛楀吀绫诲瀷鏌ヨ淇℃伅 + * + * @param dictType 瀛楀吀绫诲瀷 + * @return 瀛楀吀绫诲瀷 + */ + @Override + public SysDictType selectDictTypeByType(String dictType) { + return getOne(new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getDictType, dictType)); + } - /** - * 娓呯┖缂撳瓨鏁版嵁 - */ - @Override - public void clearCache() { - DictUtils.clearDictCache(); - } + /** + * 鎵归噺鍒犻櫎瀛楀吀绫诲瀷淇℃伅 + * + * @param dictIds 闇�瑕佸垹闄ょ殑瀛楀吀ID + * @return 缁撴灉 + */ + @Override + public void deleteDictTypeByIds(Long[] dictIds) { + for (Long dictId : dictIds) { + SysDictType dictType = selectDictTypeById(dictId); + if (dictDataMapper.selectCount(new LambdaQueryWrapper<SysDictData>() + .eq(SysDictData::getDictType, dictType.getDictType())) > 0) { + throw new ServiceException(String.format("%1$s宸插垎閰�,涓嶈兘鍒犻櫎", dictType.getDictName())); + } + DictUtils.removeDictCache(dictType.getDictType()); + } + baseMapper.deleteBatchIds(Arrays.asList(dictIds)); + } - /** - * 鏂板淇濆瓨瀛楀吀绫诲瀷淇℃伅 - * - * @param dictType 瀛楀吀绫诲瀷淇℃伅 - * @return 缁撴灉 - */ - @Override - public int insertDictType(SysDictType dictType) { - int row = dictTypeMapper.insertDictType(dictType); - if (row > 0) { - DictUtils.clearDictCache(); - } - return row; - } + /** + * 鍔犺浇瀛楀吀缂撳瓨鏁版嵁 + */ + @Override + public void loadingDictCache() { + List<SysDictType> dictTypeList = list(); + for (SysDictType dictType : dictTypeList) { + List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType()); + DictUtils.setDictCache(dictType.getDictType(), dictDatas); + } + } - /** - * 淇敼淇濆瓨瀛楀吀绫诲瀷淇℃伅 - * - * @param dictType 瀛楀吀绫诲瀷淇℃伅 - * @return 缁撴灉 - */ - @Override - @Transactional - public int updateDictType(SysDictType dictType) { - SysDictType oldDict = dictTypeMapper.selectDictTypeById(dictType.getDictId()); - dictDataMapper.updateDictDataType(oldDict.getDictType(), dictType.getDictType()); - int row = dictTypeMapper.updateDictType(dictType); - if (row > 0) { - DictUtils.clearDictCache(); - } - return row; - } + /** + * 娓呯┖瀛楀吀缂撳瓨鏁版嵁 + */ + @Override + public void clearDictCache() { + DictUtils.clearDictCache(); + } - /** - * 鏍¢獙瀛楀吀绫诲瀷绉版槸鍚﹀敮涓� - * - * @param dict 瀛楀吀绫诲瀷 - * @return 缁撴灉 - */ - @Override - public String checkDictTypeUnique(SysDictType dict) { - Long dictId = Validator.isNull(dict.getDictId()) ? -1L : dict.getDictId(); - SysDictType dictType = dictTypeMapper.checkDictTypeUnique(dict.getDictType()); - if (Validator.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) { - return UserConstants.NOT_UNIQUE; - } - return UserConstants.UNIQUE; - } + /** + * 閲嶇疆瀛楀吀缂撳瓨鏁版嵁 + */ + @Override + public void resetDictCache() { + clearDictCache(); + loadingDictCache(); + } + + /** + * 鏂板淇濆瓨瀛楀吀绫诲瀷淇℃伅 + * + * @param dict 瀛楀吀绫诲瀷淇℃伅 + * @return 缁撴灉 + */ + @Override + public int insertDictType(SysDictType dict) { + int row = baseMapper.insert(dict); + if (row > 0) { + DictUtils.setDictCache(dict.getDictType(), null); + } + return row; + } + + /** + * 淇敼淇濆瓨瀛楀吀绫诲瀷淇℃伅 + * + * @param dict 瀛楀吀绫诲瀷淇℃伅 + * @return 缁撴灉 + */ + @Override + @Transactional + public int updateDictType(SysDictType dict) { + SysDictType oldDict = getById(dict.getDictId()); + dictDataMapper.update(null, new LambdaUpdateWrapper<SysDictData>() + .set(SysDictData::getDictType, dict.getDictType()) + .eq(SysDictData::getDictType, oldDict.getDictType())); + int row = baseMapper.updateById(dict); + if (row > 0) { + List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType()); + DictUtils.setDictCache(dict.getDictType(), dictDatas); + } + return row; + } + + /** + * 鏍¢獙瀛楀吀绫诲瀷绉版槸鍚﹀敮涓� + * + * @param dict 瀛楀吀绫诲瀷 + * @return 缁撴灉 + */ + @Override + public String checkDictTypeUnique(SysDictType dict) { + Long dictId = StringUtils.isNull(dict.getDictId()) ? -1L : dict.getDictId(); + SysDictType dictType = getOne(new LambdaQueryWrapper<SysDictType>() + .eq(SysDictType::getDictType, dict.getDictType()) + .last("limit 1")); + if (StringUtils.isNotNull(dictType) && dictType.getDictId().longValue() != dictId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } } -- Gitblit v1.9.3