缓存增加

master
rong.liu 1 month ago
parent 849eb7f5f7
commit dd99db1a79
  1. 32
      src/main/java/com/huoran/iasf/controller/SysColumnController.java
  2. 22
      src/main/java/com/huoran/iasf/controller/SysContentController.java

@ -20,6 +20,7 @@ import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -101,8 +102,8 @@ public class SysColumnController {
@NoRepeatSubmit @NoRepeatSubmit
@PostMapping("/save") @PostMapping("/save")
@CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar", @CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar","redis_listWithTreeMenuVisible",
"redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails","redis_listWithTreeMenuVisible"}, "redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails", "redis_controlDisplayNavigationMenu"},
allEntries = true) allEntries = true)
@ApiOperation(value = "新增", response = SysColumn.class) @ApiOperation(value = "新增", response = SysColumn.class)
public R save(@RequestBody @Valid SysColumn sysColumn) { public R save(@RequestBody @Valid SysColumn sysColumn) {
@ -114,10 +115,11 @@ public class SysColumnController {
return addState ? R.success(sysColumn.getId()) : R.fail("新增失败"); return addState ? R.success(sysColumn.getId()) : R.fail("新增失败");
} }
@CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar", @CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar","redis_listWithTreeMenuVisible",
"redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails","redis_listWithTreeMenuVisible"}, "redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails", "redis_controlDisplayNavigationMenu"},
allEntries = true) allEntries = true)
@ApiOperation(value = "修改", response = SysColumn.class) @ApiOperation(value = "修改", response = SysColumn.class)
@PostMapping("/update")
public R update(@RequestBody SysColumn sysColumn) { public R update(@RequestBody SysColumn sysColumn) {
boolean updateState = service.updateById(sysColumn); boolean updateState = service.updateById(sysColumn);
return updateState ? R.success() : R.fail("编辑失败"); return updateState ? R.success() : R.fail("编辑失败");
@ -193,13 +195,20 @@ public class SysColumnController {
} }
@PostMapping("/controlDisplayNavigationMenu") @PostMapping("/controlDisplayNavigationMenu")
@ApiOperation(value = "控制显示导航菜单", response = SysColumn.class) @ApiOperation(value = "控制显示导航菜单", response = SysColumn.class)
public R controlDisplayNavigationMenu(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id, @CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar","redis_listWithTreeMenuVisible",
@ApiParam(name = "menuVisible", value = "菜单是否可见(默认0可见 1不可见)", required = true) @RequestParam Integer menuVisible) { "redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails", "redis_controlDisplayNavigationMenu"},
allEntries = true)
@CachePut(value = "redis_controlDisplayNavigationMenu", key = "#id + ':' + #menuVisible")
public R controlDisplayNavigationMenu(
@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id,
@ApiParam(name = "menuVisible", value = "菜单是否可见(默认0可见 1不可见)", required = true) @RequestParam Integer menuVisible) {
SysColumn column = new SysColumn(); SysColumn column = new SysColumn();
column.setId(id); column.setId(id);
column.setMenuVisible(menuVisible);//菜单是否可见(默认0可见 1不可见) column.setMenuVisible(menuVisible); // 菜单是否可见(默认0可见 1不可见)
boolean updateState = service.updateById(column); boolean updateState = service.updateById(column);
return updateState ? R.success() : R.fail("编辑失败"); return updateState ? R.success() : R.fail("编辑失败");
@ -220,8 +229,8 @@ public class SysColumnController {
*/ */
@NoRepeatSubmit @NoRepeatSubmit
@PostMapping("/batchDeletion") @PostMapping("/batchDeletion")
@CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar", @CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar","redis_listWithTreeMenuVisible",
"redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails"}, "redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails", "redis_controlDisplayNavigationMenu"},
allEntries = true) allEntries = true)
@ApiOperation(value = "批量删除栏目", response = SysColumn.class) @ApiOperation(value = "批量删除栏目", response = SysColumn.class)
public R batchDeletion(@ApiParam(name = "ids", value = "栏目ID列表", required = true) @RequestParam List<Integer> ids) { public R batchDeletion(@ApiParam(name = "ids", value = "栏目ID列表", required = true) @RequestParam List<Integer> ids) {
@ -271,6 +280,9 @@ public class SysColumnController {
*/ */
@PostMapping("/sortByColumn") @PostMapping("/sortByColumn")
@ApiOperation(value = "栏目排序(依据id更改)", response = SysColumn.class) @ApiOperation(value = "栏目排序(依据id更改)", response = SysColumn.class)
@CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar","redis_listWithTreeMenuVisible",
"redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails", "redis_controlDisplayNavigationMenu"},
allEntries = true)
public R sortByColumn(@RequestBody List<SortColumnRespVO> sortColumnRespVOList) { public R sortByColumn(@RequestBody List<SortColumnRespVO> sortColumnRespVOList) {
for (SortColumnRespVO sortInfo : sortColumnRespVOList) { for (SortColumnRespVO sortInfo : sortColumnRespVOList) {
// 获取当前要排序的栏目信息 // 获取当前要排序的栏目信息
@ -399,7 +411,7 @@ public class SysColumnController {
*/ */
@ApiOperation("查询栏目下的文章(若选中栏目与子级全部栏目类型一致返回全部文章,反之查询选中栏目下的文章)") @ApiOperation("查询栏目下的文章(若选中栏目与子级全部栏目类型一致返回全部文章,反之查询选中栏目下的文章)")
@PostMapping("/queryArticlesByColumnType") @PostMapping("/queryArticlesByColumnType")
@Cacheable(value = "redis_articlesByColumnType", key = "#ids + '-' + #id") @Cacheable(value = "redis_articlesByColumnType", key = "#columnId")
public R queryArticlesByColumnType(@ApiParam(name = "columnId", value = "栏目id", required = true) @RequestParam Integer columnId) { public R queryArticlesByColumnType(@ApiParam(name = "columnId", value = "栏目id", required = true) @RequestParam Integer columnId) {
String ids = this.getIds(columnId); String ids = this.getIds(columnId);
if (StrUtil.isBlank(ids)) { if (StrUtil.isBlank(ids)) {

@ -23,6 +23,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -92,6 +93,9 @@ public class SysContentController {
} }
@PostMapping("/save") @PostMapping("/save")
@CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar","redis_listWithTreeMenuVisible",
"redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails", "redis_controlDisplayNavigationMenu"},
allEntries = true)
@ApiOperation(value = "新增", response = SysContent.class) @ApiOperation(value = "新增", response = SysContent.class)
public R save(@RequestBody @Valid @ApiParam(name = "文章管理对象", value = "传入json格式", required = true) SysContent sysContent) { public R save(@RequestBody @Valid @ApiParam(name = "文章管理对象", value = "传入json格式", required = true) SysContent sysContent) {
@ -111,6 +115,9 @@ public class SysContentController {
@PostMapping("/update") @PostMapping("/update")
@CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar","redis_listWithTreeMenuVisible",
"redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails", "redis_controlDisplayNavigationMenu"},
allEntries = true)
@ApiOperation(value = "修改", response = SysContent.class) @ApiOperation(value = "修改", response = SysContent.class)
public R update(@RequestBody @ApiParam(name = "文章管理对象", value = "传入json格式", required = true) SysContent sysContent) { public R update(@RequestBody @ApiParam(name = "文章管理对象", value = "传入json格式", required = true) SysContent sysContent) {
boolean updateState = service.updateById(sysContent); boolean updateState = service.updateById(sysContent);
@ -119,6 +126,9 @@ public class SysContentController {
@PostMapping("/delete") @PostMapping("/delete")
@CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar","redis_listWithTreeMenuVisible",
"redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails", "redis_controlDisplayNavigationMenu"},
allEntries = true)
@ApiOperation(value = "删除", response = SysContent.class) @ApiOperation(value = "删除", response = SysContent.class)
public R delete(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) { public R delete(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) {
UpdateWrapper<SysFilesEntity> queryWrapper = new UpdateWrapper<>(); UpdateWrapper<SysFilesEntity> queryWrapper = new UpdateWrapper<>();
@ -132,6 +142,9 @@ public class SysContentController {
@PostMapping("/batchDeletion") @PostMapping("/batchDeletion")
@CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar","redis_listWithTreeMenuVisible",
"redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails", "redis_controlDisplayNavigationMenu"},
allEntries = true)
@ApiOperation(value = "批量删除文章", response = SysContent.class) @ApiOperation(value = "批量删除文章", response = SysContent.class)
public R batchDeletion(@ApiParam(name = "ids", value = "主键", required = true) @RequestParam List<Integer> ids) { public R batchDeletion(@ApiParam(name = "ids", value = "主键", required = true) @RequestParam List<Integer> ids) {
for (Integer id : ids) { for (Integer id : ids) {
@ -154,6 +167,9 @@ public class SysContentController {
@PostMapping("/newlyPublishedArticles") @PostMapping("/newlyPublishedArticles")
@ApiOperation(value = "站点最新发布的文章", response = PageContentReqVO.class) @ApiOperation(value = "站点最新发布的文章", response = PageContentReqVO.class)
@Cacheable(value = "redis_newlyPublishedArticles", key = "#content.toString()") @Cacheable(value = "redis_newlyPublishedArticles", key = "#content.toString()")
@CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar","redis_listWithTreeMenuVisible",
"redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails", "redis_controlDisplayNavigationMenu"},
allEntries = true)
public R newlyPublishedArticles(@Valid @RequestBody PageContentReqVO content) { public R newlyPublishedArticles(@Valid @RequestBody PageContentReqVO content) {
return service.newlyPublishedArticles(content); return service.newlyPublishedArticles(content);
} }
@ -185,6 +201,9 @@ public class SysContentController {
@PostMapping("/articleEnableOrDisable") @PostMapping("/articleEnableOrDisable")
@CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar","redis_listWithTreeMenuVisible",
"redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails", "redis_controlDisplayNavigationMenu"},
allEntries = true)
@ApiOperation(value = "文章启用禁用", response = SysContent.class) @ApiOperation(value = "文章启用禁用", response = SysContent.class)
public R articleEnableOrDisable(@ApiParam(name = "id", value = "文章id", required = true) @RequestParam Integer id, @ApiParam(name = "isDisable", value = "是否禁用(0默认,0启用 1禁用)", required = true) @RequestParam Integer isDisable) { public R articleEnableOrDisable(@ApiParam(name = "id", value = "文章id", required = true) @RequestParam Integer id, @ApiParam(name = "isDisable", value = "是否禁用(0默认,0启用 1禁用)", required = true) @RequestParam Integer isDisable) {
UpdateWrapper<SysContent> updateWrapper = new UpdateWrapper<>(); UpdateWrapper<SysContent> updateWrapper = new UpdateWrapper<>();
@ -218,6 +237,9 @@ public class SysContentController {
@PostMapping("/articleTopOperation") @PostMapping("/articleTopOperation")
@CacheEvict(value = {"redis_listWithTree", "redis_columnDisplayFloatingBar","redis_listWithTreeMenuVisible",
"redis_showTheFooterAccordingToTheColumn", "redis_articlesByColumnType", "redis_columnDetails", "redis_controlDisplayNavigationMenu"},
allEntries = true)
@ApiOperation(value = "文章置顶/取消置顶", response = SysContent.class) @ApiOperation(value = "文章置顶/取消置顶", response = SysContent.class)
public R articleTopOperation(@ApiParam(name = "isTop", value = "是否置顶(默认为0 不置顶 1为置顶)", required = true) @RequestParam Integer isTop, @ApiParam(name = "articleId", value = "文章Id", required = true) @RequestParam Integer articleId) { public R articleTopOperation(@ApiParam(name = "isTop", value = "是否置顶(默认为0 不置顶 1为置顶)", required = true) @RequestParam Integer isTop, @ApiParam(name = "articleId", value = "文章Id", required = true) @RequestParam Integer articleId) {
//是否置顶(默认为0 不置顶 1为置顶) //是否置顶(默认为0 不置顶 1为置顶)

Loading…
Cancel
Save