优化参数&字典缓存操作

2.X
RuoYi 4 years ago committed by 疯狂的狮子li
parent bb204fc3b7
commit bdc1773133

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

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

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

@ -57,12 +57,22 @@ public interface ISysConfigService
* @param configIds ID
* @return
*/
public int deleteConfigByIds(Long[] configIds);
public void deleteConfigByIds(Long[] configIds);
/**
*
*
*/
public void clearCache();
public void loadingConfigCache();
/**
*
*/
public void clearConfigCache();
/**
*
*/
public void resetConfigCache();
/**
*

@ -41,7 +41,7 @@ public interface ISysDictDataService
* @param dictCodes ID
* @return
*/
public int deleteDictDataByIds(Long[] dictCodes);
public void deleteDictDataByIds(Long[] dictCodes);
/**
*

@ -56,12 +56,22 @@ public interface ISysDictTypeService
* @param dictIds ID
* @return
*/
public int deleteDictTypeByIds(Long[] dictIds);
public void deleteDictTypeByIds(Long[] dictIds);
/**
*
*
*/
public void clearCache();
public void loadingDictCache();
/**
*
*/
public void clearDictCache();
/**
*
*/
public void resetDictCache();
/**
*

@ -35,11 +35,7 @@ public class SysConfigServiceImpl implements ISysConfigService
@PostConstruct
public void init()
{
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
for (SysConfig config : configsList)
{
redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
loadingConfigCache();
}
/**
@ -134,7 +130,7 @@ public class SysConfigServiceImpl implements ISysConfigService
* @return
*/
@Override
public int deleteConfigByIds(Long[] configIds)
public void deleteConfigByIds(Long[] configIds)
{
for (Long configId : configIds)
{
@ -143,26 +139,44 @@ public class SysConfigServiceImpl implements ISysConfigService
{
throw new CustomException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
}
configMapper.deleteConfigById(configId);
redisService.deleteObject(getCacheKey(config.getConfigKey()));
}
int count = configMapper.deleteConfigByIds(configIds);
if (count > 0)
}
/**
*
*/
@Override
public void loadingConfigCache()
{
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
for (SysConfig config : configsList)
{
Collection<String> keys = redisService.keys(Constants.SYS_CONFIG_KEY + "*");
redisService.deleteObject(keys);
redisService.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
return count;
}
/**
*
*
*/
@Override
public void clearCache()
public void clearConfigCache()
{
Collection<String> keys = redisService.keys(Constants.SYS_CONFIG_KEY + "*");
redisService.deleteObject(keys);
}
/**
*
*/
@Override
public void resetConfigCache()
{
clearConfigCache();
loadingConfigCache();
}
/**
*
*

@ -63,29 +63,31 @@ public class SysDictDataServiceImpl implements ISysDictDataService
* @return
*/
@Override
public int deleteDictDataByIds(Long[] dictCodes)
public void deleteDictDataByIds(Long[] dictCodes)
{
int row = dictDataMapper.deleteDictDataByIds(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
*/
@Override
public int insertDictData(SysDictData dictData)
public int insertDictData(SysDictData data)
{
int row = dictDataMapper.insertDictData(dictData);
int row = dictDataMapper.insertDictData(data);
if (row > 0)
{
DictUtils.clearDictCache();
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
DictUtils.setDictCache(data.getDictType(), dictDatas);
}
return row;
}
@ -93,16 +95,17 @@ public class SysDictDataServiceImpl implements ISysDictDataService
/**
*
*
* @param dictData
* @param data
* @return
*/
@Override
public int updateDictData(SysDictData dictData)
public int updateDictData(SysDictData data)
{
int row = dictDataMapper.updateDictData(dictData);
int row = dictDataMapper.updateDictData(data);
if (row > 0)
{
DictUtils.clearDictCache();
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(data.getDictType());
DictUtils.setDictCache(data.getDictType(), dictDatas);
}
return row;
}

@ -35,12 +35,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
@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();
}
/**
@ -120,7 +115,7 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
* @return
*/
@Override
public int deleteDictTypeByIds(Long[] dictIds)
public void deleteDictTypeByIds(Long[] dictIds)
{
for (Long dictId : dictIds)
{
@ -129,37 +124,54 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
{
throw new CustomException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
}
dictTypeMapper.deleteDictTypeById(dictId);
DictUtils.removeDictCache(dictType.getDictType());
}
int count = dictTypeMapper.deleteDictTypeByIds(dictIds);
if (count > 0)
}
/**
*
*/
public void loadingDictCache()
{
List<SysDictType> dictTypeList = dictTypeMapper.selectDictTypeAll();
for (SysDictType dictType : dictTypeList)
{
DictUtils.clearDictCache();
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dictType.getDictType());
DictUtils.setDictCache(dictType.getDictType(), dictDatas);
}
return count;
}
/**
*
*
*/
@Override
public void clearCache()
public void clearDictCache()
{
DictUtils.clearDictCache();
}
/**
*
*/
public void resetDictCache()
{
clearDictCache();
loadingDictCache();
}
/**
*
*
* @param dictType
* @param dict
* @return
*/
@Override
public int insertDictType(SysDictType dictType)
public int insertDictType(SysDictType dict)
{
int row = dictTypeMapper.insertDictType(dictType);
int row = dictTypeMapper.insertDictType(dict);
if (row > 0)
{
DictUtils.clearDictCache();
DictUtils.setDictCache(dict.getDictType(), null);
}
return row;
}
@ -167,19 +179,20 @@ public class SysDictTypeServiceImpl implements ISysDictTypeService
/**
*
*
* @param dictType
* @param dict
* @return
*/
@Override
@Transactional
public int updateDictType(SysDictType dictType)
public int updateDictType(SysDictType dict)
{
SysDictType oldDict = dictTypeMapper.selectDictTypeById(dictType.getDictId());
dictDataMapper.updateDictDataType(oldDict.getDictType(), dictType.getDictType());
int row = dictTypeMapper.updateDictType(dictType);
SysDictType oldDict = dictTypeMapper.selectDictTypeById(dict.getDictId());
dictDataMapper.updateDictDataType(oldDict.getDictType(), dict.getDictType());
int row = dictTypeMapper.updateDictType(dict);
if (row > 0)
{
DictUtils.clearDictCache();
List<SysDictData> dictDatas = dictDataMapper.selectDictDataByType(dict.getDictType());
DictUtils.setDictCache(dict.getDictType(), dictDatas);
}
return row;
}

@ -43,6 +43,16 @@ public class DictUtils
return null;
}
/**
*
*
* @param key
*/
public static void removeDictCache(String key)
{
SpringUtils.getBean(RedisService.class).deleteObject(getCacheKey(key));
}
/**
*
*/

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

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

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

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

Loading…
Cancel
Save