页脚设置commit以及栏目、文章列表字段缓存

master
rong.liu 6 months ago
parent f44903e256
commit 3780777762
  1. 105
      src/main/java/com/huoran/iasf/controller/SysColumnController.java
  2. 85
      src/main/java/com/huoran/iasf/controller/SysContentController.java
  3. 13
      src/main/java/com/huoran/iasf/service/impl/SysFooterSetupServiceImpl.java
  4. 15
      src/main/java/com/huoran/iasf/vo/req/FieldCacheReq.java

@ -6,31 +6,25 @@ import com.huoran.iasf.common.aop.annotation.NoRepeatSubmit;
import com.huoran.iasf.common.exception.NotFoundException;
import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.common.utils.Constant;
import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.*;
import com.huoran.iasf.service.*;
import com.huoran.iasf.vo.req.ColumnWeightReqVO;
import com.huoran.iasf.vo.req.PaginationColumnReqVO;
import com.huoran.iasf.vo.resp.SortColumnRespVO;
import io.swagger.annotations.*;
import com.huoran.iasf.common.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestParam;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
/**
@ -63,6 +57,8 @@ public class SysColumnController {
@Autowired
public SysFilesService sysFilesService;
@Autowired
public RedisTemplate redisTemplate;
@PostMapping("/listWithTree")
@ApiOperation(value = "栏目树结构", response = SysColumn.class)
@ -112,10 +108,72 @@ public class SysColumnController {
return updateState ? R.success() : R.fail("编辑失败");
}
/**
* 缓存用户已选择或操作过的字段
*
* @param userId 用户唯一标识必须为正整数用于定位特定用户的缓存字段
* @param fields 以逗号分隔的字段列表字符串表示用户操作或关注的字段不能为空字符串
* @return 成功时返回成功消息失败时返回错误描述
*/
@PostMapping("/cacheField")
@ApiOperation(value = "缓存用户存过的字段")
public R cacheField(@ApiParam(name = "userId", value = "用户id", required = true) @RequestParam Integer userId,
@ApiParam(name = "fields", required = true, value = "字段(逗号隔开)") @RequestParam String fields,
@ApiParam(name = "siteId", required = true, value = "站点id") @RequestParam Integer siteId
) {
try {
String key = "fieldCache_" +"siteId_" +siteId +"userId_"+ userId;
redisTemplate.opsForValue().set(key, fields);
return R.success("字段缓存成功");
} catch (RedisConnectionFailureException e) {
return R.fail("由于Redis连接问题,缓存字段失败");
}
}
/**
* 获取用户已缓存的字段列表
* 将Redis中存储的字符串以逗号分隔的字段直接转换为字符串列表并返回
*
* @param userId 用户唯一标识用于查询该用户在Redis中的缓存字段
* @return 如果用户有缓存的字段返回一个以逗号分隔的字段字符串不包含任何额外符号
* 如果用户没有缓存的字段则返回特定的消息提示
* 遇到Redis连接问题时返回错误信息
*/
@GetMapping("/getCacheField")
@ApiOperation(value = "获取用户已缓存的字段列表")
public R getCacheField(@ApiParam(name = "userId", value = "用户id", required = true) @RequestParam Integer userId,
@ApiParam(name = "siteId", required = true, value = "站点id") @RequestParam Integer siteId) {
try {
String key = "fieldCache_" +"siteId_" +siteId +"userId_"+ userId;
Object cachedFieldsObj = redisTemplate.opsForValue().get(key);
if (cachedFieldsObj == null) {
return null;
}
if (!(cachedFieldsObj instanceof String)) {
return R.fail("缓存数据类型不匹配,预期为String类型");
}
// 直接将字符串分割成列表
String cachedFieldsStr = (String) cachedFieldsObj;
if (cachedFieldsStr.isEmpty()){
return R.success();
}
List<String> fields = Arrays.asList(cachedFieldsStr.split(","));
return R.success(fields); // 直接返回分割后的字段列表
} catch (RedisConnectionFailureException e) {
return R.fail("由于Redis连接问题,获取字段失败");
}
}
@PostMapping("/controlDisplayNavigationMenu")
@ApiOperation(value = "控制显示导航菜单", response = SysColumn.class)
public R controlDisplayNavigationMenu(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id,
@ApiParam(name = "menuVisible", value = "菜单是否可见(默认0可见 1不可见)", required = true) @RequestParam Integer 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();
column.setId(id);
column.setMenuVisible(menuVisible);//菜单是否可见(默认0可见 1不可见)
@ -217,20 +275,18 @@ public class SysColumnController {
@ApiOperation("获取一级下的子级栏目")
@PostMapping("/getsTheSubColumn")
public R getsTheSubColumn(@ApiParam(name = "id", value = "id", required = true) @RequestParam Integer id,
@ApiParam(name = "siteId", value = "站点id", required = true) @RequestParam Integer siteId) {
public R getsTheSubColumn(@ApiParam(name = "id", value = "id", required = true) @RequestParam Integer id, @ApiParam(name = "siteId", value = "站点id", required = true) @RequestParam Integer siteId) {
String ids = this.getIds(id);
return service.getsTheSubColumn(id, ids,siteId);
return service.getsTheSubColumn(id, ids, siteId);
}
@ApiOperation("获取某层级下的子级栏目")
@PostMapping("/getsSublevelColumnsUnderALevel")
public R getsSublevelColumnsUnderALevel(@ApiParam(name = "id", value = "id", required = true) @RequestParam Integer id,
@ApiParam(name = "siteId", value = "站点id", required = true) @RequestParam Integer siteId) {
public R getsSublevelColumnsUnderALevel(@ApiParam(name = "id", value = "id", required = true) @RequestParam Integer id, @ApiParam(name = "siteId", value = "站点id", required = true) @RequestParam Integer siteId) {
String ids = this.getIds(id);
return service.getsTheSubColumn(id, ids,siteId);
return service.getsTheSubColumn(id, ids, siteId);
}
@ -293,14 +349,11 @@ public class SysColumnController {
@ApiOperation("某一级查全部")
@PostMapping("/oneLevelChecksThemAll")
public R oneLevelChecksThemAll(@ApiParam(name = "id", value = "栏目id", required = true) @RequestParam Integer id,
@ApiParam(name = "isSort", value = "判断是否为排序接口调用(1为排序接口调用 0我栏目管理列表调用)", required = true) @RequestParam Integer isSort,
@ApiParam(name = "ids", value = "主键", required = true) @RequestParam Integer siteId
) {
public R oneLevelChecksThemAll(@ApiParam(name = "id", value = "栏目id", required = true) @RequestParam Integer id, @ApiParam(name = "isSort", value = "判断是否为排序接口调用(1为排序接口调用 0我栏目管理列表调用)", required = true) @RequestParam Integer isSort, @ApiParam(name = "ids", value = "主键", required = true) @RequestParam Integer siteId) {
Integer pid = service.oneLevelChecksThemAll(id);
String ids = this.getIds(pid);
return service.getSubColumn(pid, ids, isSort,siteId);
return service.getSubColumn(pid, ids, isSort, siteId);
}

@ -3,41 +3,34 @@ package com.huoran.iasf.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.huoran.iasf.common.exception.NotFoundException;
import com.huoran.iasf.common.exception.code.BaseResponseCode;
import com.huoran.iasf.common.utils.R;
import com.huoran.iasf.entity.SysColumn;
import com.huoran.iasf.entity.SysContent;
import com.huoran.iasf.entity.SysContentFile;
import com.huoran.iasf.entity.SysFilesEntity;
import com.huoran.iasf.service.SysColumnService;
import com.huoran.iasf.service.SysContentFileService;
import com.huoran.iasf.service.SysContentService;
import com.huoran.iasf.service.SysFilesService;
import com.huoran.iasf.vo.req.ArticleModifiedSortReq;
import com.huoran.iasf.vo.req.ContentHeavyTitleReqVO;
import com.huoran.iasf.vo.req.ContentReq;
import com.huoran.iasf.vo.req.PageContentReqVO;
import com.huoran.iasf.vo.resp.PageContentRespVO;
import io.swagger.annotations.*;
import com.huoran.iasf.common.utils.R;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestParam;
import io.swagger.annotations.ApiOperation;
import com.huoran.iasf.service.SysContentService;
import com.huoran.iasf.entity.SysContent;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
@ -60,7 +53,8 @@ public class SysContentController {
@Autowired
public SysFilesService sysFilesService;
@Autowired
public RedisTemplate redisTemplate;
@PostMapping("/pagingQuery")
@ApiOperation(value = "分页查询文章列表", response = PageContentRespVO.class)
@ -248,7 +242,60 @@ public class SysContentController {
return service.queryArticleColumnParent(articleId);
}
@PostMapping("/cacheField")
@ApiOperation(value = "缓存用户存过的字段")
public R cacheField(@ApiParam(name = "userId", value = "用户id", required = true) @RequestParam Integer userId,
@ApiParam(name = "fields", required = true, value = "字段(逗号隔开)") @RequestParam String fields,
@ApiParam(name = "siteId", required = true, value = "站点id") @RequestParam Integer siteId
) {
try {
String key = "articleFieldCache_" + "siteId_" + siteId + "userId_" + userId;
redisTemplate.opsForValue().set(key, fields);
return R.success("字段缓存成功");
} catch (RedisConnectionFailureException e) {
return R.fail("由于Redis连接问题,缓存字段失败");
}
}
/**
* 获取用户已缓存的字段列表
* 将Redis中存储的字符串以逗号分隔的字段直接转换为字符串列表并返回
*
* @param userId 用户唯一标识用于查询该用户在Redis中的缓存字段
* @return 如果用户有缓存的字段返回一个以逗号分隔的字段字符串不包含任何额外符号
* 如果用户没有缓存的字段则返回特定的消息提示
* 遇到Redis连接问题时返回错误信息
*/
@GetMapping("/getCacheField")
@ApiOperation(value = "获取用户已缓存的字段列表")
public R getCacheField(@ApiParam(name = "userId", value = "用户id", required = true) @RequestParam Integer userId,
@ApiParam(name = "siteId", required = true, value = "站点id") @RequestParam Integer siteId) {
try {
String key = "articleFieldCache_" + "siteId_" + siteId + "userId_" + userId;
Object cachedFieldsObj = redisTemplate.opsForValue().get(key);
if (cachedFieldsObj == null) {
return null;
}
if (!(cachedFieldsObj instanceof String)) {
return R.fail("缓存数据类型不匹配,预期为String类型");
}
// 直接将字符串分割成列表
String cachedFieldsStr = (String) cachedFieldsObj;
if (cachedFieldsStr.isEmpty()){
return R.success();
}
List<String> fields = Arrays.asList(cachedFieldsStr.split(","));
return R.success(fields); // 直接返回分割后的字段列表
} catch (RedisConnectionFailureException e) {
return R.fail("由于Redis连接问题,获取字段失败");
}
}
}

@ -102,12 +102,14 @@ public class SysFooterSetupServiceImpl extends ServiceImpl<SysFooterSetupMapper,
// 查询当前站点下已启用且已发布的悬浮栏方案
List<SysFooterSetup> floatingColumnSchemeList = baseMapper.selectList(queryWrapper);
// 检查是否存在全局启用的悬浮栏方案,存在则直接返回
Optional<SysFooterSetup> globalSetupOptional = floatingColumnSchemeList.stream()
// 检查是否存在全局启用的悬浮栏方案
List<SysFooterSetup> globalSetupList = floatingColumnSchemeList.stream()
.filter(setup -> setup.getIsGlobal() == 1)
.findFirst();
if (globalSetupOptional.isPresent()) {
return R.success(globalSetupOptional.get());
.collect(Collectors.toList());
if (!globalSetupList.isEmpty()) {
// 即使是全局方案,也包装成单元素的集合返回,以保持返回类型的统一
return R.success(globalSetupList);
}
// 如果没有全局方案,检查当前栏目绑定的悬浮栏方案
@ -121,6 +123,7 @@ public class SysFooterSetupServiceImpl extends ServiceImpl<SysFooterSetupMapper,
);
return R.success(setupsForColumn);
}
return R.success(Collections.emptyList());
}

@ -0,0 +1,15 @@
package com.huoran.iasf.vo.req;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
@Data
public class FieldCacheReq {
@ApiModelProperty(value = "字段")
private List<String> fields;
@ApiModelProperty(value = "用户id")
private Integer userId;
}
Loading…
Cancel
Save