master
rong.liu 6 months ago
parent 3780777762
commit 47757ba059
  1. 212
      src/main/java/com/huoran/iasf/controller/SysColumnController.java

@ -132,31 +132,37 @@ public class SysColumnController {
} }
/** /**
* 获取用户已缓存的字段列表 * 根据用户ID和站点ID获取缓存的字段列表
* 将Redis中存储的字符串以逗号分隔的字段直接转换为字符串列表并返回 * 该接口通过组合用户ID和站点ID作为键从Redis缓存中获取字段列表如果缓存中不存在相应的数据
* 或者数据的类型不匹配则返回相应的错误信息如果数据存在且类型匹配则返回缓存的字段列表
* *
* @param userId 用户唯一标识用于查询该用户在Redis中的缓存字段 * @param userId 用户ID用于构造缓存键标识特定用户的缓存数据
* @return 如果用户有缓存的字段返回一个以逗号分隔的字段字符串不包含任何额外符号 * @param siteId 站点ID用于构造缓存键标识特定站点的缓存数据
* 如果用户没有缓存的字段则返回特定的消息提示 * @return 如果缓存中存在数据且数据类型为String则返回缓存的字段列表否则返回空或错误信息
* 遇到Redis连接问题时返回错误信息
*/ */
@GetMapping("/getCacheField") @GetMapping("/getCacheField")
@ApiOperation(value = "获取用户已缓存的字段列表") @ApiOperation(value = "获取用户已缓存的字段列表")
public R getCacheField(@ApiParam(name = "userId", value = "用户id", required = true) @RequestParam Integer userId, public R getCacheField(@ApiParam(name = "userId", value = "用户id", required = true) @RequestParam Integer userId,
@ApiParam(name = "siteId", required = true, value = "站点id") @RequestParam Integer siteId) { @ApiParam(name = "siteId", required = true, value = "站点id") @RequestParam Integer siteId) {
try { try {
// 组合键名,用于在Redis中查找缓存数据。
String key = "fieldCache_" +"siteId_" +siteId +"userId_"+ userId; String key = "fieldCache_" +"siteId_" +siteId +"userId_"+ userId;
// 从Redis中获取缓存数据。
Object cachedFieldsObj = redisTemplate.opsForValue().get(key); Object cachedFieldsObj = redisTemplate.opsForValue().get(key);
// 检查缓存数据是否存在。
if (cachedFieldsObj == null) { if (cachedFieldsObj == null) {
return null; return null;
} }
// 检查缓存数据类型是否为String。
if (!(cachedFieldsObj instanceof String)) { if (!(cachedFieldsObj instanceof String)) {
return R.fail("缓存数据类型不匹配,预期为String类型"); return R.fail("缓存数据类型不匹配,预期为String类型");
} }
// 将缓存的字符串转换为字段列表。
// 直接将字符串分割成列表 // 直接将字符串分割成列表
String cachedFieldsStr = (String) cachedFieldsObj; String cachedFieldsStr = (String) cachedFieldsObj;
if (cachedFieldsStr.isEmpty()){ if (cachedFieldsStr.isEmpty()){
@ -167,10 +173,12 @@ public class SysColumnController {
return R.success(fields); // 直接返回分割后的字段列表 return R.success(fields); // 直接返回分割后的字段列表
} catch (RedisConnectionFailureException e) { } catch (RedisConnectionFailureException e) {
// 如果Redis连接失败,返回错误信息。
return R.fail("由于Redis连接问题,获取字段失败"); return R.fail("由于Redis连接问题,获取字段失败");
} }
} }
@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, @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) {
@ -182,97 +190,102 @@ public class SysColumnController {
return updateState ? R.success() : R.fail("编辑失败"); return updateState ? R.success() : R.fail("编辑失败");
} }
/*@NoRepeatSubmit
@PostMapping("/delete")
@ApiOperation(value = "删除", response = SysContent.class)
public R delete(@ApiParam(name = "id", value = "主键", required = true) @RequestParam Integer id) {
UpdateWrapper<SysFilesEntity> filesEntityUpdateWrapper = new UpdateWrapper<>();
filesEntityUpdateWrapper.eq("quote_id", id);
filesEntityUpdateWrapper.eq("quote_type", 1);
filesEntityUpdateWrapper.set("is_del", 1);
sysFilesService.update(filesEntityUpdateWrapper);
boolean delState = service.removeById(id);
QueryWrapper<SysContent> queryWrapper = new QueryWrapper<>();
queryWrapper.in("column_id", id);
//删除栏目后删除栏目下的文章
List<SysContent> contentId = contentService.list(queryWrapper);
contentService.removeByIds(contentId);
return delState ? R.success() : R.fail("删除失败");
}*/
/**
* 批量删除栏目及其关联的内容和长页信息
* 接收一个包含栏目ID的列表遍历这些ID以执行以下操作
* 1. 更新与栏目关联的文件记录为已删除状态
* 2. 递归收集每个栏目的子栏目ID至一个列表中并包含当前栏目ID
* 3. 使用收集到的ID列表删除关联的文章记录
* 4. 删除关联的长页栏目记录
* 5. 最后根据ID列表删除栏目本身
*
* @param ids 主键列表标识需要删除的栏目ID
* @return 成功响应无论实际删除操作是否成功均返回成功消息
*/
@NoRepeatSubmit @NoRepeatSubmit
@PostMapping("/batchDeletion") @PostMapping("/batchDeletion")
@ApiOperation(value = "批量删除栏目", response = SysColumn.class) @ApiOperation(value = "批量删除栏目", response = SysColumn.class)
public R batchDeletion(@ApiParam(name = "ids", value = "主键", required = true) @RequestParam List<Integer> ids) { public R batchDeletion(@ApiParam(name = "ids", value = "栏目ID列表", required = true) @RequestParam List<Integer> ids) {
boolean ret = false;
for (Integer id : ids) { for (Integer id : ids) {
UpdateWrapper<SysFilesEntity> filesEntityUpdateWrapper = new UpdateWrapper<>(); // 更新与栏目相关的文件记录为已删除
filesEntityUpdateWrapper.eq("quote_id", id); UpdateWrapper<SysFilesEntity> filesUpdateWrapper = new UpdateWrapper<>();
filesEntityUpdateWrapper.eq("quote_type", 1); filesUpdateWrapper.eq("quote_id", id).eq("quote_type", 1).set("is_del", 1);
filesEntityUpdateWrapper.set("is_del", 1); sysFilesService.update(filesUpdateWrapper);
sysFilesService.update(filesEntityUpdateWrapper);
//1 创建list集合,用于封装所有删除菜单id值 // 收集当前栏目及其子栏目的ID
List<Integer> idList = new ArrayList<>(); List<Integer> idList = new ArrayList<>();
//2 向idList集合设置删除菜单id this.selectCategoryChildById(id.toString(), idList);
//找到当前菜单的子菜单 把结果id封装到idlist里面去 // 添加当前栏目ID到待处理列表
this.selectCategoryChildById(id + "", idList);
//把当前id封装到list里面 //现在把当前id封装进去 之前都是子菜单的id
idList.add(id); idList.add(id);
//删除当前栏目以及栏目下的文章 // 删除栏目下所有文章
QueryWrapper<SysContent> queryWrapper = new QueryWrapper<>(); QueryWrapper<SysContent> contentQueryWrapper = new QueryWrapper<>();
queryWrapper.in("column_id", idList); contentQueryWrapper.in("column_id", idList);
//删除栏目后删除栏目下的文章 contentService.remove(contentQueryWrapper);
contentService.remove(queryWrapper);
// 删除关联的长页栏目信息
QueryWrapper<SysColumnLongPage> longPageQueryWrapper = new QueryWrapper<>();
longPageQueryWrapper.in("column_id", idList);
sysColumnLongPageService.remove(longPageQueryWrapper);
//删除长页栏目 // 删除栏目
QueryWrapper<SysColumnLongPage> queryWrapper1 = new QueryWrapper<SysColumnLongPage>(); service.removeByIds(idList);
queryWrapper1.in("column_id", idList);
//删除栏目后删除栏目下的文章
sysColumnLongPageService.remove(queryWrapper1);
ret = service.removeByIds(idList);
}
}
return R.success(); return R.success();
} }
@PostMapping("/sameLevelJudgment") @PostMapping("/sameLevelJudgment")
@ApiOperation(value = "同级判重", response = ColumnWeightReqVO.class) @ApiOperation(value = "同级判重", response = ColumnWeightReqVO.class)
public R sameLevelJudgment(@RequestBody @Valid ColumnWeightReqVO sysColumn) { public R sameLevelJudgment(@RequestBody @Valid ColumnWeightReqVO sysColumn) {
return service.sameLevelJudgment(sysColumn) ? R.success() : R.fail("同级下已存在重复栏目!"); return service.sameLevelJudgment(sysColumn) ? R.success() : R.fail("同级下已存在重复栏目!");
} }
/**
* 根据传入的栏目排序信息更新栏目顺序
* 遍历接收到的排序信息列表针对每个栏目验证同级下是否有名称相同的栏目存在排除自身
* 若无冲突则更新该栏目的排序信息
*
* @param sortColumnRespVOList 包含栏目ID父栏目ID等排序信息的列表
* @return 如果更新成功或无冲突则返回操作成功的响应若检测到同级下存在名称重复的栏目则返回失败信息
*/
@PostMapping("/sortByColumn") @PostMapping("/sortByColumn")
@ApiOperation(value = "栏目排序(依据id更改)", response = SysColumn.class) @ApiOperation(value = "栏目排序(依据id更改)", response = SysColumn.class)
public R sortByColumn(@RequestBody List<SortColumnRespVO> sortColumnRespVOList) { public R sortByColumn(@RequestBody List<SortColumnRespVO> sortColumnRespVOList) {
for (SortColumnRespVO sort : sortColumnRespVOList) { for (SortColumnRespVO sortInfo : sortColumnRespVOList) {
// 获取当前要排序的栏目信息
SysColumn column = service.getById(sort.getId()); SysColumn existingColumn = service.getById(sortInfo.getId());
// 构建查询条件,检查同级下是否有名称相同的其他栏目(排除自己)
QueryWrapper<SysColumn> queryWrapper = new QueryWrapper<>(); QueryWrapper<SysColumn> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("column_name", column.getColumnName()); queryWrapper.eq("column_name", existingColumn.getColumnName())
queryWrapper.eq("site_id", column.getSiteId()); .eq("site_id", existingColumn.getSiteId())
queryWrapper.eq("father_id", sort.getFatherId()); .eq("father_id", sortInfo.getFatherId())
queryWrapper.last(" and id <> " + sort.getId()); .ne("id", sortInfo.getId()); // 确保不包括当前正在处理的栏目
List<SysColumn> columnList = service.list(queryWrapper);
if (columnList.size() > 0) { // 执行查询
return R.fail("同级下已存在重复栏目:" + column.getColumnName()); List<SysColumn> conflictingColumns = service.list(queryWrapper);
// 检查是否有冲突
if (!conflictingColumns.isEmpty()) {
return R.fail("同级下已存在重复栏目:" + existingColumn.getColumnName());
} }
SysColumn sysColumn = new SysColumn(); // 无冲突,复制排序信息并更新数据库
BeanUtils.copyProperties(sort, sysColumn); SysColumn updateColumn = new SysColumn();
service.updateById(sysColumn); BeanUtils.copyProperties(sortInfo, updateColumn);
service.updateById(updateColumn);
} }
// 全部处理完毕,返回成功响应
return R.success(); return R.success();
} }
@ApiOperation("获取一级下的子级栏目") @ApiOperation("获取一级下的子级栏目")
@PostMapping("/getsTheSubColumn") @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) {
@ -372,46 +385,53 @@ public class SysColumnController {
} }
/**
* 删除标记为无用的数据包括相关联的文件引用文章以及长页栏目条目
* 此方法首先查询所有未被标记为删除的栏目然后对每个栏目执行以下操作
* 1. 更新与栏目关联的文件记录为已删除状态
* 2. 收集当前栏目及其所有子栏目的ID
* 3. 使用收集到的ID列表删除关联的文章记录和长页栏目记录
* 4. 最后删除这些栏目本身
*
* @return 成功响应表示删除无用数据的操作已完成
*/
@NoRepeatSubmit @NoRepeatSubmit
@PostMapping("/deleteUselessData") @PostMapping("/deleteUselessData")
@ApiOperation(value = "删除无用数据", response = SysColumn.class) @ApiOperation(value = "删除无用数据", response = SysColumn.class)
public R deleteUselessData() { public R deleteUselessData() {
// 查询未被标记为删除的栏目ID
QueryWrapper<SysColumn> queryWrapper = new QueryWrapper<>(); QueryWrapper<SysColumn> columnQueryWrapper = new QueryWrapper<>();
queryWrapper.eq("deleted", 0).select("id"); columnQueryWrapper.eq("deleted", 0).select("id");
List<SysColumn> list = service.list(queryWrapper); List<SysColumn> columnsToProcess = service.list(columnQueryWrapper);
for (SysColumn column : list) { for (SysColumn column : columnsToProcess) {
UpdateWrapper<SysFilesEntity> filesEntityUpdateWrapper = new UpdateWrapper<>(); // 标记与栏目关联的文件为已删除
filesEntityUpdateWrapper.eq("quote_id", column.getId()); UpdateWrapper<SysFilesEntity> fileUpdateWrapper = new UpdateWrapper<>();
filesEntityUpdateWrapper.eq("quote_type", 1); fileUpdateWrapper.eq("quote_id", column.getId()).eq("quote_type", 1).set("is_del", 1);
filesEntityUpdateWrapper.set("is_del", 1); sysFilesService.update(fileUpdateWrapper);
sysFilesService.update(filesEntityUpdateWrapper);
//1 创建list集合,用于封装所有删除菜单id值 // 收集当前栏目及其子栏目ID
List<Integer> idList = new ArrayList<>(); List<Integer> relatedIds = new ArrayList<>();
//2 向idList集合设置删除菜单id this.selectCategoryChildById(column.getId().toString(), relatedIds);
//找到当前菜单的子菜单 把结果id封装到idlist里面去 relatedIds.add(column.getId()); // 包含当前栏目ID
this.selectCategoryChildById(column.getId() + "", idList);
//把当前id封装到list里面 //现在把当前id封装进去 之前都是子菜单的id // 删除关联的文章
idList.add(column.getId()); QueryWrapper<SysContent> contentQueryWrapper = new QueryWrapper<>();
contentQueryWrapper.in("column_id", relatedIds);
//删除当前栏目以及栏目下的文章 contentService.remove(contentQueryWrapper);
QueryWrapper<SysContent> queryWrapper1 = new QueryWrapper<>();
queryWrapper1.in("column_id", idList); // 删除关联的长页栏目
//删除栏目后删除栏目下的文章 QueryWrapper<SysColumnLongPage> longPageQueryWrapper = new QueryWrapper<>();
contentService.remove(queryWrapper1); longPageQueryWrapper.in("column_id", relatedIds);
sysColumnLongPageService.remove(longPageQueryWrapper);
//删除长页栏目 // 删除栏目
QueryWrapper<SysColumnLongPage> queryWrapper2 = new QueryWrapper<SysColumnLongPage>(); service.removeByIds(relatedIds);
queryWrapper2.in("column_id", idList);
//删除栏目后删除栏目下的文章
sysColumnLongPageService.remove(queryWrapper2);
service.removeByIds(idList);
} }
// 全部处理完成后返回成功响应
return R.success(); return R.success();
} }
} }

Loading…
Cancel
Save