Merge branch 'master' of https://gitee.com/y_project/RuoYi-Vue into dev

 Conflicts:
	ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
	ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictDataController.java
	ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysDictTypeController.java
	ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/DataScopeAspect.java
	ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
	ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictDataService.java
	ruoyi-system/src/main/java/com/ruoyi/system/service/ISysDictTypeService.java
	ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
	ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictDataServiceImpl.java
	ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDictTypeServiceImpl.java
	ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
	ruoyi-ui/src/api/system/config.js
	ruoyi-ui/src/api/system/dict/type.js
	ruoyi-ui/src/views/system/config/index.vue
	ruoyi-ui/src/views/system/dict/index.vue
This commit is contained in:
疯狂的狮子li 2021-05-28 10:07:15 +08:00
commit d0b2166525
16 changed files with 201 additions and 107 deletions

View File

@ -110,18 +110,19 @@ public class SysConfigController extends BaseController
@DeleteMapping("/{configIds}") @DeleteMapping("/{configIds}")
public AjaxResult remove(@PathVariable Long[] configIds) public AjaxResult remove(@PathVariable Long[] configIds)
{ {
return toAjax(configService.deleteConfigByIds(configIds)); configService.deleteConfigByIds(configIds);
return success();
} }
/** /**
* 清空缓存 * 刷新参数缓存
*/ */
@PreAuthorize("@ss.hasPermi('system:config:remove')") @PreAuthorize("@ss.hasPermi('system:config:remove')")
@Log(title = "参数管理", businessType = BusinessType.CLEAN) @Log(title = "参数管理", businessType = BusinessType.CLEAN)
@DeleteMapping("/clearCache") @DeleteMapping("/refreshCache")
public AjaxResult clearCache() public AjaxResult refreshCache()
{ {
configService.clearCache(); configService.resetConfigCache();
return AjaxResult.success(); return AjaxResult.success();
} }
} }

View File

@ -107,6 +107,7 @@ public class SysDictDataController extends BaseController
@DeleteMapping("/{dictCodes}") @DeleteMapping("/{dictCodes}")
public AjaxResult remove(@PathVariable Long[] dictCodes) public AjaxResult remove(@PathVariable Long[] dictCodes)
{ {
return toAjax(dictDataService.deleteDictDataByIds(dictCodes)); dictDataService.deleteDictDataByIds(dictCodes);
return success();
} }
} }

View File

@ -96,18 +96,19 @@ public class SysDictTypeController extends BaseController
@DeleteMapping("/{dictIds}") @DeleteMapping("/{dictIds}")
public AjaxResult remove(@PathVariable Long[] dictIds) public AjaxResult remove(@PathVariable Long[] dictIds)
{ {
return toAjax(dictTypeService.deleteDictTypeByIds(dictIds)); dictTypeService.deleteDictTypeByIds(dictIds);
return success();
} }
/** /**
* 清空缓存 * 刷新字典缓存
*/ */
@PreAuthorize("@ss.hasPermi('system:dict:remove')") @PreAuthorize("@ss.hasPermi('system:dict:remove')")
@Log(title = "字典类型", businessType = BusinessType.CLEAN) @Log(title = "字典类型", businessType = BusinessType.CLEAN)
@DeleteMapping("/clearCache") @DeleteMapping("/refreshCache")
public AjaxResult clearCache() public AjaxResult refreshCache()
{ {
dictTypeService.clearCache(); dictTypeService.resetDictCache();
return AjaxResult.success(); return AjaxResult.success();
} }

View File

@ -155,6 +155,16 @@ public class DictUtils
return StrUtil.strip(propertyString.toString(), null, separator); return StrUtil.strip(propertyString.toString(), null, separator);
} }
/**
* 删除指定字典缓存
*
* @param key 字典键
*/
public static void removeDictCache(String key)
{
SpringUtils.getBean(RedisCache.class).deleteObject(getCacheKey(key));
}
/** /**
* 清空字典缓存 * 清空字典缓存
*/ */

View File

@ -68,6 +68,7 @@ public class DataScopeAspect
@Before("dataScopePointCut()") @Before("dataScopePointCut()")
public void doBefore(JoinPoint point) throws Throwable public void doBefore(JoinPoint point) throws Throwable
{ {
clearDataScope(point);
handleDataScope(point); handleDataScope(point);
} }
@ -173,4 +174,17 @@ public class DataScopeAspect
} }
return null; return null;
} }
/**
* 拼接权限sql前先清空params.dataScope参数防止注入
*/
private void clearDataScope(final JoinPoint joinPoint)
{
Object params = joinPoint.getArgs()[0];
if (StringUtils.isNotNull(params) && params instanceof BaseEntity)
{
BaseEntity baseEntity = (BaseEntity) params;
baseEntity.getParams().put(DATA_SCOPE, "");
}
}
} }

View File

@ -62,12 +62,22 @@ public interface ISysConfigService extends IServicePlus<SysConfig> {
* @param configIds 需要删除的参数ID * @param configIds 需要删除的参数ID
* @return 结果 * @return 结果
*/ */
public int deleteConfigByIds(Long[] configIds); public void deleteConfigByIds(Long[] configIds);
/** /**
* 清空缓存数据 * 加载参数缓存数据
*/ */
public void clearCache(); public void loadingConfigCache();
/**
* 清空参数缓存数据
*/
public void clearConfigCache();
/**
* 重置参数缓存数据
*/
public void resetConfigCache();
/** /**
* 校验参数键名是否唯一 * 校验参数键名是否唯一

View File

@ -47,7 +47,7 @@ public interface ISysDictDataService extends IServicePlus<SysDictData> {
* @param dictCodes 需要删除的字典数据ID * @param dictCodes 需要删除的字典数据ID
* @return 结果 * @return 结果
*/ */
public int deleteDictDataByIds(Long[] dictCodes); public void deleteDictDataByIds(Long[] dictCodes);
/** /**
* 新增保存字典数据信息 * 新增保存字典数据信息

View File

@ -62,12 +62,22 @@ public interface ISysDictTypeService extends IServicePlus<SysDictType> {
* @param dictIds 需要删除的字典ID * @param dictIds 需要删除的字典ID
* @return 结果 * @return 结果
*/ */
public int deleteDictTypeByIds(Long[] dictIds); public void deleteDictTypeByIds(Long[] dictIds);
/** /**
* 清空缓存数据 * 加载字典缓存数据
*/ */
public void clearCache(); public void loadingDictCache();
/**
* 清空字典缓存数据
*/
public void clearDictCache();
/**
* 重置字典缓存数据
*/
public void resetDictCache();
/** /**
* 新增保存字典类型信息 * 新增保存字典类型信息

View File

@ -33,6 +33,9 @@ import java.util.Map;
@Service @Service
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService { public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements ISysConfigService {
@Autowired
private SysConfigMapper configMapper;
@Autowired @Autowired
private RedisCache redisCache; private RedisCache redisCache;
@ -41,10 +44,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
*/ */
@PostConstruct @PostConstruct
public void init() { public void init() {
List<SysConfig> configsList = baseMapper.selectList(new LambdaQueryWrapper<>()); loadingConfigCache();
for (SysConfig config : configsList) {
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
} }
@Override @Override
@ -155,30 +155,50 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteConfigByIds(Long[] configIds) { public void deleteConfigByIds(Long[] configIds) {
for (Long configId : configIds) { for (Long configId : configIds) {
SysConfig config = selectConfigById(configId); SysConfig config = selectConfigById(configId);
if (StrUtil.equals(UserConstants.YES, config.getConfigType())) { if (StrUtil.equals(UserConstants.YES, config.getConfigType())) {
throw new CustomException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey())); throw new CustomException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
} }
configMapper.deleteConfigById(configId);
redisCache.deleteObject(getCacheKey(config.getConfigKey()));
} }
int count = baseMapper.deleteBatchIds(Arrays.asList(configIds));
if (count > 0) {
Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
redisCache.deleteObject(keys);
}
return count;
} }
/** /**
* 清空缓存数据 * 加载参数缓存数据
*/ */
@Override @Override
public void clearCache() { public void loadingConfigCache()
{
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
for (SysConfig config : configsList)
{
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
}
/**
* 清空参数缓存数据
*/
@Override
public void clearConfigCache()
{
Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*"); Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
redisCache.deleteObject(keys); redisCache.deleteObject(keys);
} }
/**
* 重置参数缓存数据
*/
@Override
public void resetConfigCache()
{
clearConfigCache();
loadingConfigCache();
}
/** /**
* 校验参数键名是否唯一 * 校验参数键名是否唯一
* *

View File

@ -22,6 +22,9 @@ import java.util.List;
@Service @Service
public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData> implements ISysDictDataService { public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDictData> implements ISysDictDataService {
@Autowired
private SysDictDataMapper dictDataMapper;
@Override @Override
public TableDataInfo<SysDictData> selectPageDictDataList(SysDictData dictData) { public TableDataInfo<SysDictData> selectPageDictDataList(SysDictData dictData) {
LambdaQueryWrapper<SysDictData> lqw = new LambdaQueryWrapper<SysDictData>() LambdaQueryWrapper<SysDictData> lqw = new LambdaQueryWrapper<SysDictData>()
@ -81,25 +84,31 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteDictDataByIds(Long[] dictCodes) { public void deleteDictDataByIds(Long[] dictCodes)
int row = baseMapper.deleteBatchIds(Arrays.asList(dictCodes)); {
if (row > 0) { for (Long dictCode : dictCodes)
DictUtils.clearDictCache(); {
SysDictData data = selectDictDataById(dictCode);
dictDataMapper.deleteDictDataById(dictCode);
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
DictUtils.setDictCache(data.getDictType(), dictDatas);
} }
return row;
} }
/** /**
* 新增保存字典数据信息 * 新增保存字典数据信息
* *
* @param dictData 字典数据信息 * @param data 字典数据信息
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertDictData(SysDictData dictData) { public int insertDictData(SysDictData data)
int row = baseMapper.insert(dictData); {
if (row > 0) { int row = baseMapper.insert(data);
DictUtils.clearDictCache(); if (row > 0)
{
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
DictUtils.setDictCache(data.getDictType(), dictDatas);
} }
return row; return row;
} }
@ -107,14 +116,17 @@ public class SysDictDataServiceImpl extends ServiceImpl<SysDictDataMapper, SysDi
/** /**
* 修改保存字典数据信息 * 修改保存字典数据信息
* *
* @param dictData 字典数据信息 * @param data 字典数据信息
* @return 结果 * @return 结果
*/ */
@Override @Override
public int updateDictData(SysDictData dictData) { public int updateDictData(SysDictData data)
int row = baseMapper.updateById(dictData); {
if (row > 0) { int row = baseMapper.updateById(data);
DictUtils.clearDictCache(); if (row > 0)
{
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
DictUtils.setDictCache(data.getDictType(), dictDatas);
} }
return row; return row;
} }

View File

@ -33,6 +33,9 @@ import java.util.Map;
@Service @Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService { public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService {
@Autowired
private SysDictTypeMapper dictTypeMapper;
@Autowired @Autowired
private SysDictDataMapper dictDataMapper; private SysDictDataMapper dictDataMapper;
@ -41,15 +44,7 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
*/ */
@PostConstruct @PostConstruct
public void init() { public void init() {
List<SysDictType> dictTypeList = list(); loadingDictCache();
for (SysDictType dictType : dictTypeList) {
List<SysDictData> dictDatas = dictDataMapper.selectList(
new LambdaQueryWrapper<SysDictData>()
.eq(SysDictData::getStatus, 0)
.eq(SysDictData::getDictType, dictType.getDictType())
.orderByAsc(SysDictData::getDictSort));
DictUtils.setDictCache(dictType.getDictType(), dictDatas);
}
} }
@Override @Override
@ -151,60 +146,81 @@ public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDi
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteDictTypeByIds(Long[] dictIds) { public void deleteDictTypeByIds(Long[] dictIds) {
for (Long dictId : dictIds) { for (Long dictId : dictIds) {
SysDictType dictType = selectDictTypeById(dictId); SysDictType dictType = selectDictTypeById(dictId);
if (dictDataMapper.selectCount(new LambdaQueryWrapper<SysDictData>() if (dictDataMapper.selectCount(new LambdaQueryWrapper<SysDictData>()
.eq(SysDictData::getDictType, dictType.getDictType())) > 0) { .eq(SysDictData::getDictType, dictType.getDictType())) > 0) {
throw new CustomException(String.format("%1$s已分配,不能删除", dictType.getDictName())); throw new CustomException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
} }
dictTypeMapper.deleteDictTypeById(dictId);
DictUtils.removeDictCache(dictType.getDictType());
} }
int count = baseMapper.deleteBatchIds(Arrays.asList(dictIds));
if (count > 0) {
DictUtils.clearDictCache();
}
return count;
} }
/** /**
* 清空缓存数据 * 加载字典缓存数据
*/ */
@Override public void loadingDictCache()
public void clearCache() { {
List<SysDictType> dictTypeList = dictTypeMapper.selectDictTypeAll();
for (SysDictType dictType : dictTypeList)
{
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType());
DictUtils.setDictCache(dictType.getDictType(), dictDatas);
}
}
/**
* 清空字典缓存数据
*/
public void clearDictCache()
{
DictUtils.clearDictCache(); DictUtils.clearDictCache();
} }
/**
* 重置字典缓存数据
*/
public void resetDictCache()
{
clearDictCache();
loadingDictCache();
}
/** /**
* 新增保存字典类型信息 * 新增保存字典类型信息
* *
* @param dictType 字典类型信息 * @param dict 字典类型信息
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertDictType(SysDictType dictType) { public int insertDictType(SysDictType dict) {
int row = baseMapper.insert(dictType); int row = baseMapper.insert(dict);
if (row > 0) { if (row > 0) {
DictUtils.clearDictCache(); DictUtils.setDictCache(dict.getDictType(), null);
} }
return row; return row;
} }
/** /**
* 修改保存字典类型信息 * 修改保存字典类型信息
* * @param dict 字典类型信息
* @param dictType 字典类型信息
* @return 结果 * @return 结果
*/ */
@Override @Override
@Transactional @Transactional
public int updateDictType(SysDictType dictType) { public int updateDictType(SysDictType dict)
SysDictType oldDict = getById(dictType.getDictId()); {
SysDictType oldDict = getById(dict.getDictId());
dictDataMapper.update(null, new LambdaUpdateWrapper<SysDictData>() dictDataMapper.update(null, new LambdaUpdateWrapper<SysDictData>()
.set(SysDictData::getDictType, dictType.getDictType()) .set(SysDictData::getDictType, dict.getDictType())
.eq(SysDictData::getDictType, oldDict.getDictType())); .eq(SysDictData::getDictType, oldDict.getDictType()));
int row = baseMapper.updateById(dictType); int row = baseMapper.updateById(dict);
if (row > 0) { if (row > 0)
DictUtils.clearDictCache(); {
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType());
DictUtils.setDictCache(dict.getDictType(), dictDatas);
} }
return row; return row;
} }

View File

@ -50,8 +50,7 @@
left join sys_role_dept rd on d.dept_id = rd.dept_id left join sys_role_dept rd on d.dept_id = rd.dept_id
where rd.role_id = #{roleId} where rd.role_id = #{roleId}
<if test="deptCheckStrictly"> <if test="deptCheckStrictly">
and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = and d.dept_id not in (select d.parent_id from sys_dept d inner join sys_role_dept rd on d.dept_id = rd.dept_id and rd.role_id = #{roleId})
rd.dept_id and rd.role_id = #{roleId})
</if> </if>
order by d.parent_id, d.order_num order by d.parent_id, d.order_num
</select> </select>

View File

@ -51,10 +51,10 @@ export function delConfig(configId) {
}) })
} }
// 清理参数缓存 // 刷新参数缓存
export function clearCache() { export function refreshCache() {
return request({ return request({
url: '/system/config/clearCache', url: '/system/config/refreshCache',
method: 'delete' method: 'delete'
}) })
} }

View File

@ -43,10 +43,10 @@ export function delType(dictId) {
}) })
} }
// 清理参数缓存 // 刷新字典缓存
export function clearCache() { export function refreshCache() {
return request({ return request({
url: '/system/dict/type/clearCache', url: '/system/dict/type/refreshCache',
method: 'delete' method: 'delete'
}) })
} }

View File

@ -99,9 +99,9 @@
plain plain
icon="el-icon-refresh" icon="el-icon-refresh"
size="mini" size="mini"
@click="handleClearCache" @click="handleRefreshCache"
v-hasPermi="['system:config:remove']" v-hasPermi="['system:config:remove']"
>清理缓存</el-button> >刷新缓存</el-button>
</el-col> </el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
@ -181,7 +181,7 @@
</template> </template>
<script> <script>
import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig, clearCache } from "@/api/system/config"; import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig, refreshCache } from "@/api/system/config";
export default { export default {
name: "Config", name: "Config",
@ -355,10 +355,10 @@ export default {
this.exportLoading = false; this.exportLoading = false;
}) })
}, },
/** 清理缓存按钮操作 */ /** 刷新缓存按钮操作 */
handleClearCache() { handleRefreshCache() {
clearCache().then(response => { refreshCache().then(() => {
this.msgSuccess("清理成功"); this.msgSuccess("刷新成功");
}); });
} }
} }

View File

@ -105,9 +105,9 @@
plain plain
icon="el-icon-refresh" icon="el-icon-refresh"
size="mini" size="mini"
@click="handleClearCache" @click="handleRefreshCache"
v-hasPermi="['system:dict:remove']" v-hasPermi="['system:dict:remove']"
>清理缓存</el-button> >刷新缓存</el-button>
</el-col> </el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
@ -189,7 +189,7 @@
</template> </template>
<script> <script>
import { listType, getType, delType, addType, updateType, exportType, clearCache } from "@/api/system/dict/type"; import { listType, getType, delType, addType, updateType, exportType, refreshCache } from "@/api/system/dict/type";
export default { export default {
name: "Dict", name: "Dict",
@ -359,10 +359,10 @@ export default {
this.exportLoading = false; this.exportLoading = false;
}) })
}, },
/** 清理缓存按钮操作 */ /** 刷新缓存按钮操作 */
handleClearCache() { handleRefreshCache() {
clearCache().then(response => { refreshCache().then(() => {
this.msgSuccess("清理成功"); this.msgSuccess("刷新成功");
}); });
} }
} }