From b1be47f0a03b52b8df7971fc8174364aa1cc32a0 Mon Sep 17 00:00:00 2001
From: 疯狂的狮子Li <15040126243@163.com>
Date: 星期五, 26 十一月 2021 15:06:54 +0800
Subject: [PATCH] !114 接口重复鉴权BUG修复: ResourceConfig中已经配置鉴权拦截器, 添加sa-token-spring-aop会导致重复鉴权BUG Merge pull request !114 from dawn9117/N/A
---
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java | 128 +++++++++++++++++++++++++++++-------------
1 files changed, 89 insertions(+), 39 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..bb940c2 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.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.common.utils.StringUtils;
import com.ruoyi.system.mapper.SysDictDataMapper;
import com.ruoyi.system.mapper.SysDictTypeMapper;
import com.ruoyi.system.service.ISysDictTypeService;
@@ -16,17 +20,17 @@
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
+import java.util.Arrays;
import java.util.List;
+import java.util.Map;
/**
* 瀛楀吀 涓氬姟灞傚鐞�
*
- * @author ruoyi
+ * @author Lion Li
*/
@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;
@@ -36,11 +40,23 @@
*/
@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);
- }
+ loadingDictCache();
+ }
+
+ @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));
}
/**
@@ -51,7 +67,17 @@
*/
@Override
public List<SysDictType> selectDictTypeList(SysDictType dictType) {
- return dictTypeMapper.selectDictTypeList(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")));
}
/**
@@ -61,7 +87,7 @@
*/
@Override
public List<SysDictType> selectDictTypeAll() {
- return dictTypeMapper.selectDictTypeAll();
+ return list();
}
/**
@@ -92,7 +118,7 @@
*/
@Override
public SysDictType selectDictTypeById(Long dictId) {
- return dictTypeMapper.selectDictTypeById(dictId);
+ return getById(dictId);
}
/**
@@ -103,7 +129,7 @@
*/
@Override
public SysDictType selectDictTypeByType(String dictType) {
- return dictTypeMapper.selectDictTypeByType(dictType);
+ return getOne(new LambdaQueryWrapper<SysDictType>().eq(SysDictType::getDictType, dictType));
}
/**
@@ -113,39 +139,58 @@
* @return 缁撴灉
*/
@Override
- public int deleteDictTypeByIds(Long[] dictIds) {
+ public void 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()));
+ 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());
}
- int count = dictTypeMapper.deleteDictTypeByIds(dictIds);
- if (count > 0) {
- DictUtils.clearDictCache();
- }
- return count;
+ baseMapper.deleteBatchIds(Arrays.asList(dictIds));
}
/**
- * 娓呯┖缂撳瓨鏁版嵁
+ * 鍔犺浇瀛楀吀缂撳瓨鏁版嵁
*/
@Override
- public void clearCache() {
+ public void loadingDictCache() {
+ List<SysDictType> dictTypeList = list();
+ for (SysDictType dictType : dictTypeList) {
+ List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType());
+ DictUtils.setDictCache(dictType.getDictType(), dictDatas);
+ }
+ }
+
+ /**
+ * 娓呯┖瀛楀吀缂撳瓨鏁版嵁
+ */
+ @Override
+ public void clearDictCache() {
DictUtils.clearDictCache();
+ }
+
+ /**
+ * 閲嶇疆瀛楀吀缂撳瓨鏁版嵁
+ */
+ @Override
+ public void resetDictCache() {
+ clearDictCache();
+ loadingDictCache();
}
/**
* 鏂板淇濆瓨瀛楀吀绫诲瀷淇℃伅
*
- * @param dictType 瀛楀吀绫诲瀷淇℃伅
+ * @param dict 瀛楀吀绫诲瀷淇℃伅
* @return 缁撴灉
*/
@Override
- public int insertDictType(SysDictType dictType) {
- int row = dictTypeMapper.insertDictType(dictType);
+ public int insertDictType(SysDictType dict) {
+ int row = baseMapper.insert(dict);
if (row > 0) {
- DictUtils.clearDictCache();
+ DictUtils.setDictCache(dict.getDictType(), null);
}
return row;
}
@@ -153,17 +198,20 @@
/**
* 淇敼淇濆瓨瀛楀吀绫诲瀷淇℃伅
*
- * @param dictType 瀛楀吀绫诲瀷淇℃伅
+ * @param dict 瀛楀吀绫诲瀷淇℃伅
* @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);
+ 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) {
- DictUtils.clearDictCache();
+ List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType());
+ DictUtils.setDictCache(dict.getDictType(), dictDatas);
}
return row;
}
@@ -176,9 +224,11 @@
*/
@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()) {
+ 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