serv\web-侧边栏 标签统一
This commit is contained in:
@@ -1,90 +0,0 @@
|
||||
package org.xyzh.news.controller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.xyzh.api.news.category.ResourceCategoryService;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.resource.TbResourceCategory;
|
||||
|
||||
/**
|
||||
* @description 资源分类控制器
|
||||
* @filename ResourceCategoryController.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/news/categorys")
|
||||
public class ResourceCategoryController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ResourceCategoryController.class);
|
||||
|
||||
@Autowired
|
||||
private ResourceCategoryService resourceCategoryService;
|
||||
|
||||
/**
|
||||
* 获取分类列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public ResultDomain<TbResourceCategory> getCategoryList() {
|
||||
return resourceCategoryService.getAllCategories();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取分类详情
|
||||
*/
|
||||
@GetMapping("/category/{categoryID}")
|
||||
public ResultDomain<TbResourceCategory> getCategoryById(@PathVariable String categoryID) {
|
||||
return resourceCategoryService.getCategoryById(categoryID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建分类
|
||||
*/
|
||||
@PostMapping("/category")
|
||||
public ResultDomain<TbResourceCategory> createCategory(@RequestBody TbResourceCategory category) {
|
||||
return resourceCategoryService.createCategory(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新分类
|
||||
*/
|
||||
@PutMapping("/category")
|
||||
public ResultDomain<TbResourceCategory> updateCategory(@RequestBody TbResourceCategory category) {
|
||||
return resourceCategoryService.updateCategory(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
*/
|
||||
@DeleteMapping("/category/{categoryID}")
|
||||
public ResultDomain<Boolean> deleteCategory(@PathVariable String categoryID) {
|
||||
return resourceCategoryService.deleteCategory(categoryID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新分类状态
|
||||
*/
|
||||
@PutMapping("/category/{categoryID}/status")
|
||||
public ResultDomain<TbResourceCategory> updateCategoryStatus(@PathVariable String categoryID, @RequestParam Integer status) {
|
||||
return null;
|
||||
// return resourceCategoryService.updateCategoryStatus(categoryID, status);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类树
|
||||
*/
|
||||
@GetMapping("/tree")
|
||||
public ResultDomain<TbResourceCategory> getCategoryTree() {
|
||||
return resourceCategoryService.getCategoryTree();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取子分类
|
||||
*/
|
||||
@GetMapping("/category/{parentID}/children")
|
||||
public ResultDomain<TbResourceCategory> getChildCategories(@PathVariable String parentID) {
|
||||
return resourceCategoryService.getCategoriesByParent(parentID);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.resource.TbResource;
|
||||
import org.xyzh.common.dto.resource.TbResourceCategory;
|
||||
import org.xyzh.common.dto.resource.TbTag;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -24,11 +24,11 @@ public class ResourceCenterController {
|
||||
// ==================== 专项分栏管理 ====================
|
||||
|
||||
/**
|
||||
* 获取专项分栏列表
|
||||
* 获取专项分栏列表(使用标签 tag_type=1)
|
||||
*/
|
||||
@GetMapping("/categories")
|
||||
public ResultDomain<TbResourceCategory> getSpecialCategories() {
|
||||
// TODO: 实现获取专项分栏(包含党史学习、领导讲话、政策解读、红色经典、专题报告、思政案例6个分栏)
|
||||
public ResultDomain<TbTag> getSpecialCategories() {
|
||||
// TODO: 实现获取专项分栏,使用 TagService.getTagsByType(1) 获取文章分类标签
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -101,9 +101,9 @@ public class ResourceCenterController {
|
||||
/**
|
||||
* 根据分类ID获取资源
|
||||
*/
|
||||
@GetMapping("/category/{categoryID}/resources")
|
||||
@GetMapping("/category/{tagID}/resources")
|
||||
public ResultDomain<TbResource> getResourcesByCategory(
|
||||
@PathVariable String categoryID,
|
||||
@PathVariable String tagID,
|
||||
@RequestParam(required = false) Integer pageNum,
|
||||
@RequestParam(required = false) Integer pageSize) {
|
||||
// TODO: 实现根据分类ID获取资源
|
||||
@@ -118,7 +118,7 @@ public class ResourceCenterController {
|
||||
@GetMapping("/search")
|
||||
public ResultDomain<TbResource> searchResources(
|
||||
@RequestParam String keyword,
|
||||
@RequestParam(required = false) String categoryID,
|
||||
@RequestParam(required = false) String tagID,
|
||||
@RequestParam(required = false) Integer pageNum,
|
||||
@RequestParam(required = false) Integer pageSize) {
|
||||
// TODO: 实现支持模糊关键词检索,快速定位资源
|
||||
@@ -238,11 +238,11 @@ public class ResourceCenterController {
|
||||
// ==================== 资源分类管理 ====================
|
||||
|
||||
/**
|
||||
* 获取所有资源分类
|
||||
* 获取所有资源分类(使用标签 tag_type=1)
|
||||
*/
|
||||
@GetMapping("/categories/all")
|
||||
public ResultDomain<TbResourceCategory> getAllCategories() {
|
||||
// TODO: 实现获取所有资源分类
|
||||
public ResultDomain<TbTag> getAllCategories() {
|
||||
// TODO: 实现获取所有资源分类,使用 TagService.getTagsByType(1) 获取文章分类标签
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -186,8 +186,8 @@ public class ResourceController {
|
||||
@GetMapping("/search")
|
||||
public ResultDomain<TbResource> searchResources(
|
||||
@RequestParam("keyword") String keyword,
|
||||
@RequestParam(value = "categoryID", required = false) String categoryID,
|
||||
@RequestParam(value = "tagID", required = false) String tagID,
|
||||
@RequestParam(value = "status", required = false) Integer status) {
|
||||
return resourceService.searchResources(keyword, categoryID, status);
|
||||
return resourceService.searchResources(keyword, tagID, status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TagController {
|
||||
* 根据ID获取标签详情
|
||||
*/
|
||||
@GetMapping("/tag/{tagID}")
|
||||
public ResultDomain<TbTag> getTagById(@PathVariable String tagID) {
|
||||
public ResultDomain<TbTag> getTagById(@PathVariable("tagID") String tagID) {
|
||||
return tagService.getTagById(tagID);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class TagController {
|
||||
* 删除标签
|
||||
*/
|
||||
@DeleteMapping("/tag/{tagID}")
|
||||
public ResultDomain<Boolean> deleteTag(@PathVariable String tagID) {
|
||||
public ResultDomain<Boolean> deleteTag(@PathVariable("tagID") String tagID) {
|
||||
return tagService.deleteTag(tagID);
|
||||
}
|
||||
|
||||
@@ -70,17 +70,26 @@ public class TagController {
|
||||
* 搜索标签
|
||||
*/
|
||||
@GetMapping("/search")
|
||||
public ResultDomain<TbTag> searchTags(@RequestParam String keyword) {
|
||||
public ResultDomain<TbTag> searchTags(@RequestParam("keyword") String keyword) {
|
||||
return tagService.searchTagsByName(keyword);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标签类型获取标签列表
|
||||
* @param tagType 标签类型(1-文章分类标签 2-课程分类标签 3-学习任务分类标签)
|
||||
*/
|
||||
@GetMapping("/type/{tagType}")
|
||||
public ResultDomain<TbTag> getTagsByType(@PathVariable("tagType") Integer tagType) {
|
||||
return tagService.getTagsByType(tagType);
|
||||
}
|
||||
|
||||
// ----------------资源标签关联相关--------------------------------
|
||||
|
||||
/**
|
||||
* 获取资源的标签列表
|
||||
*/
|
||||
@GetMapping("/resource/{resourceID}")
|
||||
public ResultDomain<TbTag> getResourceTags(@PathVariable String resourceID) {
|
||||
public ResultDomain<TbTag> getResourceTags(@PathVariable("resourceID") String resourceID) {
|
||||
return tagService.getResourceTags(resourceID);
|
||||
}
|
||||
|
||||
@@ -89,8 +98,8 @@ public class TagController {
|
||||
*/
|
||||
@PostMapping("/resource/{resourceID}/tag/{tagID}")
|
||||
public ResultDomain<TbResourceTag> addResourceTag(
|
||||
@PathVariable String resourceID,
|
||||
@PathVariable String tagID) {
|
||||
@PathVariable("resourceID") String resourceID,
|
||||
@PathVariable("tagID") String tagID) {
|
||||
return tagService.addResourceTag(resourceID, tagID);
|
||||
}
|
||||
|
||||
@@ -109,8 +118,8 @@ public class TagController {
|
||||
*/
|
||||
@DeleteMapping("/resource/{resourceID}/tag/{tagID}")
|
||||
public ResultDomain<Boolean> removeResourceTag(
|
||||
@PathVariable String resourceID,
|
||||
@PathVariable String tagID) {
|
||||
@PathVariable("resourceID") String resourceID,
|
||||
@PathVariable("tagID") String tagID) {
|
||||
return tagService.removeResourceTag(resourceID, tagID);
|
||||
}
|
||||
|
||||
@@ -118,7 +127,7 @@ public class TagController {
|
||||
* 清空资源的所有标签
|
||||
*/
|
||||
@DeleteMapping("/resource/{resourceID}/tags")
|
||||
public ResultDomain<Boolean> clearResourceTags(@PathVariable String resourceID) {
|
||||
public ResultDomain<Boolean> clearResourceTags(@PathVariable("resourceID") String resourceID) {
|
||||
return tagService.clearResourceTags(resourceID);
|
||||
}
|
||||
|
||||
@@ -126,7 +135,7 @@ public class TagController {
|
||||
* 根据标签获取资源列表
|
||||
*/
|
||||
@GetMapping("/tag/{tagID}/resources")
|
||||
public ResultDomain<String> getResourcesByTag(@PathVariable String tagID) {
|
||||
public ResultDomain<String> getResourcesByTag(@PathVariable("tagID") String tagID) {
|
||||
return tagService.getResourcesByTag(tagID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,138 +1 @@
|
||||
package org.xyzh.news.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.dto.resource.TbResourceCategory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description ResourceCategoryMapper.java文件描述 资源分类数据访问层
|
||||
* @filename ResourceCategoryMapper.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
@Mapper
|
||||
public interface ResourceCategoryMapper extends BaseMapper<TbResourceCategory> {
|
||||
|
||||
/**
|
||||
* @description 查询资源分类列表
|
||||
* @param filter 过滤条件
|
||||
* @return List<TbResourceCategory> 资源分类列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbResourceCategory> selectResourceCategories(TbResourceCategory filter);
|
||||
|
||||
/**
|
||||
* @description 根据分类ID查询分类信息
|
||||
* @param categoryId 分类ID
|
||||
* @return TbResourceCategory 分类信息
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
TbResourceCategory selectByCategoryId(@Param("categoryId") String categoryId);
|
||||
|
||||
/**
|
||||
* @description 根据父分类ID查询子分类列表
|
||||
* @param parentId 父分类ID
|
||||
* @return List<TbResourceCategory> 子分类列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbResourceCategory> selectByParentId(@Param("parentId") String parentId);
|
||||
|
||||
/**
|
||||
* @description 根据状态查询分类列表
|
||||
* @param status 状态
|
||||
* @return List<TbResourceCategory> 分类列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbResourceCategory> selectByStatus(@Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* @description 查询分类树结构
|
||||
* @return List<TbResourceCategory> 分类树
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbResourceCategory> selectCategoryTree();
|
||||
|
||||
/**
|
||||
* @description 检查分类名称是否存在
|
||||
* @param name 分类名称
|
||||
* @param excludeId 排除的分类ID(用于更新时排除自身)
|
||||
* @return int 存在的数量
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
int countByName(@Param("name") String name, @Param("excludeId") String excludeId);
|
||||
|
||||
/**
|
||||
* @description 插入资源分类
|
||||
* @param resourceCategory 资源分类
|
||||
* @return int 影响行数
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
int insertResourceCategory(TbResourceCategory resourceCategory);
|
||||
|
||||
/**
|
||||
* @description 更新资源分类
|
||||
* @param resourceCategory 资源分类
|
||||
* @return int 影响行数
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
int updateResourceCategory(TbResourceCategory resourceCategory);
|
||||
|
||||
/**
|
||||
* @description 删除资源分类
|
||||
* @param resourceCategory 资源分类
|
||||
* @return int 影响行数
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
int deleteResourceCategory(TbResourceCategory resourceCategory);
|
||||
|
||||
/**
|
||||
* @description 批量插入资源分类
|
||||
* @param resourceCategoryList 资源分类列表
|
||||
* @return int 影响行数
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
int batchInsertResourceCategories(@Param("resourceCategoryList") List<TbResourceCategory> resourceCategoryList);
|
||||
|
||||
/**
|
||||
* @description 批量删除资源分类
|
||||
* @param ids 分类ID列表
|
||||
* @return int 影响行数
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
int batchDeleteResourceCategories(@Param("ids") List<String> ids);
|
||||
|
||||
/**
|
||||
* @description 分页查询资源分类
|
||||
* @param filter 过滤条件
|
||||
* @param pageParam 分页参数
|
||||
* @return List<TbResourceCategory> 资源分类列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbResourceCategory> selectResourceCategoriesPage(@Param("filter") TbResourceCategory filter, @Param("pageParam") PageParam pageParam);
|
||||
|
||||
/**
|
||||
* @description 统计资源分类总数
|
||||
* @param filter 过滤条件
|
||||
* @return long 总数
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
long countResourceCategories(@Param("filter") TbResourceCategory filter);
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ public interface ResourceMapper extends BaseMapper<TbResource> {
|
||||
TbResource selectByResourceId(@Param("resourceId") String resourceId);
|
||||
|
||||
/**
|
||||
* @description 根据分类ID查询资源列表
|
||||
* @param categoryId 分类ID
|
||||
* @description 根据标签ID查询资源列表
|
||||
* @param tagId 标签ID(文章分类标签,tagType=1)
|
||||
* @return List<TbResource> 资源列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbResource> selectByCategoryId(@Param("categoryId") String categoryId);
|
||||
List<TbResource> selectByTagId(@Param("tagId") String tagId);
|
||||
|
||||
/**
|
||||
* @description 根据状态查询资源列表
|
||||
|
||||
@@ -55,13 +55,13 @@ public interface TagMapper extends BaseMapper<TbTag> {
|
||||
List<TbTag> selectByStatus(@Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* @description 根据类型查询标签列表
|
||||
* @param type 类型
|
||||
* @description 根据标签类型查询标签列表
|
||||
* @param tagType 标签类型(1-文章分类标签 2-课程分类标签 3-学习任务分类标签)
|
||||
* @return List<TbTag> 标签列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
* @since 2025-10-27
|
||||
*/
|
||||
List<TbTag> selectByType(@Param("type") Integer type);
|
||||
List<TbTag> selectByTagType(@Param("tagType") Integer tagType);
|
||||
|
||||
/**
|
||||
* @description 查询热门标签列表
|
||||
@@ -73,14 +73,15 @@ public interface TagMapper extends BaseMapper<TbTag> {
|
||||
List<TbTag> selectHotTags(@Param("limit") Integer limit);
|
||||
|
||||
/**
|
||||
* @description 检查标签名称是否存在
|
||||
* @description 检查标签名称是否存在(同类型下)
|
||||
* @param name 标签名称
|
||||
* @param tagType 标签类型
|
||||
* @param excludeId 排除的标签ID(用于更新时排除自身)
|
||||
* @return int 存在的数量
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
* @since 2025-10-27
|
||||
*/
|
||||
int countByName(@Param("name") String name, @Param("excludeId") String excludeId);
|
||||
int countByNameAndType(@Param("name") String name, @Param("tagType") Integer tagType, @Param("excludeId") String excludeId);
|
||||
|
||||
/**
|
||||
* @description 插入标签
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.xyzh.news.service;
|
||||
|
||||
import org.xyzh.api.news.category.ResourceCategoryService;
|
||||
|
||||
/**
|
||||
* @description 资源分类服务接口
|
||||
* @filename NCResourceCategoryService.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
public interface NCResourceCategoryService extends ResourceCategoryService {
|
||||
|
||||
}
|
||||
@@ -1,360 +0,0 @@
|
||||
package org.xyzh.news.service.impl;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.resource.TbResourceCategory;
|
||||
import org.xyzh.common.utils.IDUtils;
|
||||
import org.xyzh.news.mapper.ResourceCategoryMapper;
|
||||
import org.xyzh.api.news.category.ResourceCategoryService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @description 资源分类服务实现类
|
||||
* @filename NCResourceCategoryServiceImpl.java
|
||||
* @author yslg
|
||||
* @copyright xyzh
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
@Service
|
||||
public class NCResourceCategoryServiceImpl implements ResourceCategoryService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(NCResourceCategoryServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private ResourceCategoryMapper resourceCategoryMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResultDomain<TbResourceCategory> createCategory(TbResourceCategory category) {
|
||||
ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
// 参数验证
|
||||
if (category == null || !StringUtils.hasText(category.getName())) {
|
||||
resultDomain.fail("分类名称不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查分类名称是否已存在
|
||||
int count = resourceCategoryMapper.countByName(category.getName(), null);
|
||||
if (count > 0) {
|
||||
resultDomain.fail("分类名称已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
if (category.getID() == null) {
|
||||
category.setID(IDUtils.generateID());
|
||||
}
|
||||
if (category.getCategoryID() == null) {
|
||||
category.setCategoryID(IDUtils.generateID());
|
||||
}
|
||||
if (category.getOrderNum() == null) {
|
||||
category.setOrderNum(0);
|
||||
}
|
||||
|
||||
category.setCreateTime(new Date());
|
||||
category.setUpdateTime(new Date());
|
||||
category.setDeleted(false);
|
||||
|
||||
// 插入数据库
|
||||
int result = resourceCategoryMapper.insertResourceCategory(category);
|
||||
if (result > 0) {
|
||||
logger.info("创建分类成功: {}", category.getName());
|
||||
resultDomain.success("创建分类成功", category);
|
||||
return resultDomain;
|
||||
} else {
|
||||
resultDomain.fail("创建分类失败");
|
||||
return resultDomain;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("创建分类异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("创建分类失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResultDomain<TbResourceCategory> updateCategory(TbResourceCategory category) {
|
||||
ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
// 参数验证
|
||||
if (category == null || !StringUtils.hasText(category.getID())) {
|
||||
resultDomain.fail("分类ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查分类是否存在
|
||||
TbResourceCategory existingCategory = resourceCategoryMapper.selectById(category.getID());
|
||||
if (existingCategory == null || existingCategory.getDeleted()) {
|
||||
resultDomain.fail("分类不存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查分类名称是否重复(排除自身)
|
||||
if (StringUtils.hasText(category.getName())) {
|
||||
int count = resourceCategoryMapper.countByName(category.getName(), category.getID());
|
||||
if (count > 0) {
|
||||
resultDomain.fail("分类名称已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新时间
|
||||
category.setUpdateTime(new Date());
|
||||
|
||||
// 更新数据库
|
||||
int result = resourceCategoryMapper.updateResourceCategory(category);
|
||||
if (result > 0) {
|
||||
logger.info("更新分类成功: {}", category.getID());
|
||||
// 重新查询返回完整数据
|
||||
TbResourceCategory updated = resourceCategoryMapper.selectById(category.getID());
|
||||
resultDomain.success("更新分类成功", updated);
|
||||
return resultDomain;
|
||||
} else {
|
||||
resultDomain.fail("更新分类失败");
|
||||
return resultDomain;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("更新分类异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("更新分类失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResultDomain<Boolean> deleteCategory(String categoryID) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
// 参数验证
|
||||
if (!StringUtils.hasText(categoryID)) {
|
||||
resultDomain.fail("分类ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查分类是否存在
|
||||
TbResourceCategory category = resourceCategoryMapper.selectByCategoryId(categoryID);
|
||||
if (category == null || category.getDeleted()) {
|
||||
resultDomain.fail("分类不存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查是否有子分类
|
||||
ResultDomain<Boolean> hasChildResult = hasChildCategories(categoryID);
|
||||
if (hasChildResult.isSuccess() && Boolean.TRUE.equals(hasChildResult.getData())) {
|
||||
resultDomain.fail("该分类下存在子分类,无法删除");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查是否有关联资源
|
||||
ResultDomain<Boolean> hasResourceResult = hasResources(categoryID);
|
||||
if (hasResourceResult.isSuccess() && Boolean.TRUE.equals(hasResourceResult.getData())) {
|
||||
resultDomain.fail("该分类下存在资源,无法删除");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 物理删除
|
||||
int result = resourceCategoryMapper.deleteResourceCategory(category);
|
||||
if (result > 0) {
|
||||
logger.info("删除分类成功: {}", categoryID);
|
||||
resultDomain.success("删除分类成功", true);
|
||||
return resultDomain;
|
||||
} else {
|
||||
resultDomain.fail("删除分类失败");
|
||||
return resultDomain;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("删除分类异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("删除分类失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbResourceCategory> getCategoryById(String categoryID) {
|
||||
ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
if (!StringUtils.hasText(categoryID)) {
|
||||
resultDomain.fail("分类ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
TbResourceCategory category = resourceCategoryMapper.selectByCategoryId(categoryID);
|
||||
if (category == null || category.getDeleted()) {
|
||||
resultDomain.fail("分类不存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
resultDomain.success("查询成功", category);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("查询分类异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("查询分类失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbResourceCategory> getAllCategories() {
|
||||
ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
List<TbResourceCategory> categories = resourceCategoryMapper.selectResourceCategories(new TbResourceCategory());
|
||||
resultDomain.success("查询成功", categories);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("查询分类列表异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("查询分类列表失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbResourceCategory> getCategoriesByParent(String parentID) {
|
||||
ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
if (!StringUtils.hasText(parentID)) {
|
||||
resultDomain.fail("父分类ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
List<TbResourceCategory> categories = resourceCategoryMapper.selectByParentId(parentID);
|
||||
resultDomain.success("查询成功", categories);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("查询子分类列表异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("查询子分类列表失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbResourceCategory> getCategoryTree() {
|
||||
ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
// 查询所有分类
|
||||
List<TbResourceCategory> allCategories = resourceCategoryMapper.selectCategoryTree();
|
||||
|
||||
// 构建树形结构
|
||||
List<TbResourceCategory> tree = buildCategoryTree(allCategories, null);
|
||||
|
||||
resultDomain.success("查询成功", tree);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("查询分类树异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("查询分类树失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> hasChildCategories(String categoryID) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
if (!StringUtils.hasText(categoryID)) {
|
||||
resultDomain.fail("分类ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
List<TbResourceCategory> children = resourceCategoryMapper.selectByParentId(categoryID);
|
||||
resultDomain.success("查询成功", !children.isEmpty());
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("检查子分类异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("检查子分类失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> hasResources(String categoryID) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
if (!StringUtils.hasText(categoryID)) {
|
||||
resultDomain.fail("分类ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// TODO: 需要查询资源表判断是否有关联资源
|
||||
// 这里暂时返回false,需要在ResourceMapper中添加相应方法
|
||||
resultDomain.success("查询成功", false);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("检查分类资源异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("检查分类资源失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResultDomain<TbResourceCategory> updateCategoryOrder(String categoryID, Integer orderNum) {
|
||||
ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
if (!StringUtils.hasText(categoryID) || orderNum == null) {
|
||||
resultDomain.fail("参数不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
TbResourceCategory category = resourceCategoryMapper.selectByCategoryId(categoryID);
|
||||
if (category == null || category.getDeleted()) {
|
||||
resultDomain.fail("分类不存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
TbResourceCategory updateCategory = new TbResourceCategory();
|
||||
updateCategory.setID(category.getID());
|
||||
updateCategory.setOrderNum(orderNum);
|
||||
updateCategory.setUpdateTime(new Date());
|
||||
|
||||
int result = resourceCategoryMapper.updateResourceCategory(updateCategory);
|
||||
if (result > 0) {
|
||||
logger.info("更新分类排序成功: {}", categoryID);
|
||||
TbResourceCategory updated = resourceCategoryMapper.selectById(category.getID());
|
||||
resultDomain.success("更新排序成功", updated);
|
||||
return resultDomain;
|
||||
} else {
|
||||
resultDomain.fail("更新排序失败");
|
||||
return resultDomain;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("更新分类排序异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("更新排序失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建分类树形结构
|
||||
* @param allCategories 所有分类列表
|
||||
* @param parentID 父分类ID
|
||||
* @return 树形结构列表
|
||||
*/
|
||||
private List<TbResourceCategory> buildCategoryTree(List<TbResourceCategory> allCategories, String parentID) {
|
||||
List<TbResourceCategory> result = new ArrayList<>();
|
||||
|
||||
for (TbResourceCategory category : allCategories) {
|
||||
// 找出当前父级下的子分类
|
||||
if ((parentID == null && category.getParentID() == null) ||
|
||||
(parentID != null && parentID.equals(category.getParentID()))) {
|
||||
|
||||
// 递归查找子分类(如果TbResourceCategory有children字段,可以在这里设置)
|
||||
// List<TbResourceCategory> children = buildCategoryTree(allCategories, category.getCategoryID());
|
||||
// category.setChildren(children);
|
||||
|
||||
result.add(category);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -721,7 +721,7 @@ public class NCResourceServiceImpl implements ResourceService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbResource> searchResources(String keyword, String categoryID, Integer status) {
|
||||
public ResultDomain<TbResource> searchResources(String keyword, String tagID, Integer status) {
|
||||
ResultDomain<TbResource> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
// 参数验证
|
||||
@@ -734,8 +734,8 @@ public class NCResourceServiceImpl implements ResourceService {
|
||||
List<TbResource> list = resourceMapper.searchByKeyword(keyword);
|
||||
|
||||
// 如果指定了分类ID,进行过滤
|
||||
if (StringUtils.hasText(categoryID) && list != null) {
|
||||
list.removeIf(resource -> !categoryID.equals(resource.getCategoryID()));
|
||||
if (StringUtils.hasText(tagID) && list != null) {
|
||||
list.removeIf(resource -> !tagID.equals(resource.getTagID()));
|
||||
}
|
||||
|
||||
// 如果指定了状态,进行过滤
|
||||
|
||||
@@ -49,10 +49,10 @@ public class NCTagServiceImpl implements TagService {
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查标签名称是否已存在
|
||||
int count = tagMapper.countByName(tag.getName(), null);
|
||||
// 检查标签名称是否已存在(同类型下)
|
||||
int count = tagMapper.countByNameAndType(tag.getName(), tag.getTagType(), null);
|
||||
if (count > 0) {
|
||||
resultDomain.fail("标签名称已存在");
|
||||
resultDomain.fail("该类型下标签名称已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
@@ -103,11 +103,12 @@ public class NCTagServiceImpl implements TagService {
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查标签名称是否重复(排除自身)
|
||||
// 检查标签名称是否重复(排除自身,同类型下)
|
||||
if (StringUtils.hasText(tag.getName())) {
|
||||
int count = tagMapper.countByName(tag.getName(), tag.getID());
|
||||
Integer tagType = tag.getTagType() != null ? tag.getTagType() : existingTag.getTagType();
|
||||
int count = tagMapper.countByNameAndType(tag.getName(), tagType, tag.getID());
|
||||
if (count > 0) {
|
||||
resultDomain.fail("标签名称已存在");
|
||||
resultDomain.fail("该类型下标签名称已存在");
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
@@ -460,4 +461,29 @@ public class NCTagServiceImpl implements TagService {
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbTag> getTagsByType(Integer tagType) {
|
||||
ResultDomain<TbTag> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
if (tagType == null) {
|
||||
resultDomain.fail("标签类型不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 验证标签类型是否有效(1-文章分类标签 2-课程分类标签 3-学习任务分类标签)
|
||||
if (tagType < 1 || tagType > 3) {
|
||||
resultDomain.fail("无效的标签类型");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
List<TbTag> tags = tagMapper.selectByTagType(tagType);
|
||||
resultDomain.success("查询成功", tags);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("根据类型查询标签异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("根据类型查询标签失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<result column="source_url" property="sourceUrl" jdbcType="VARCHAR"/>
|
||||
<result column="source_type" property="sourceType" jdbcType="VARCHAR"/>
|
||||
<result column="frequency" property="frequency" jdbcType="VARCHAR"/>
|
||||
<result column="category_id" property="categoryID" jdbcType="VARCHAR"/>
|
||||
<result column="tag_id" property="tagID" jdbcType="VARCHAR"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="last_collect_time" property="lastCollectTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, name, source_url, source_type, frequency, category_id, status,
|
||||
id, name, source_url, source_type, frequency, tag_id, status,
|
||||
last_collect_time, creator, updater, create_time, update_time,
|
||||
delete_time, deleted
|
||||
</sql>
|
||||
@@ -40,8 +40,8 @@
|
||||
<if test="frequency != null and frequency != ''">
|
||||
AND frequency = #{frequency}
|
||||
</if>
|
||||
<if test="categoryID != null and categoryID != ''">
|
||||
AND category_id = #{categoryID}
|
||||
<if test="tagID != null and tagID != ''">
|
||||
AND tag_id = #{tagID}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
@@ -114,11 +114,11 @@
|
||||
<!-- 插入数据采集配置 -->
|
||||
<insert id="insertDataCollectionConfig" parameterType="org.xyzh.common.dto.resource.TbDataCollectionConfig">
|
||||
INSERT INTO tb_data_collection_config (
|
||||
id, name, source_url, source_type, frequency, category_id, status,
|
||||
id, name, source_url, source_type, frequency, tag_id, status,
|
||||
last_collect_time, creator, updater, create_time, update_time,
|
||||
delete_time, deleted
|
||||
) VALUES (
|
||||
#{id}, #{name}, #{sourceUrl}, #{sourceType}, #{frequency}, #{categoryID}, #{status},
|
||||
#{id}, #{name}, #{sourceUrl}, #{sourceType}, #{frequency}, #{tagID}, #{status},
|
||||
#{lastCollectTime}, #{creator}, #{updater}, #{createTime}, #{updateTime},
|
||||
#{deleteTime}, #{deleted}
|
||||
)
|
||||
@@ -140,8 +140,8 @@
|
||||
<if test="frequency != null and frequency != ''">
|
||||
frequency = #{frequency},
|
||||
</if>
|
||||
<if test="categoryID != null and categoryID != ''">
|
||||
category_id = #{categoryID},
|
||||
<if test="tagID != null and tagID != ''">
|
||||
tag_id = #{tagID},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status = #{status},
|
||||
@@ -174,14 +174,14 @@
|
||||
<!-- 批量插入数据采集配置 -->
|
||||
<insert id="batchInsertDataCollectionConfigs" parameterType="java.util.List">
|
||||
INSERT INTO tb_data_collection_config (
|
||||
id, name, source_url, source_type, frequency, category_id, status,
|
||||
id, name, source_url, source_type, frequency, tag_id, status,
|
||||
last_collect_time, creator, updater, create_time, update_time,
|
||||
delete_time, deleted
|
||||
) VALUES
|
||||
<foreach collection="dataCollectionConfigList" item="item" separator=",">
|
||||
(
|
||||
#{item.id}, #{item.name}, #{item.sourceUrl}, #{item.sourceType}, #{item.frequency},
|
||||
#{item.categoryID}, #{item.status}, #{item.lastCollectTime}, #{item.creator},
|
||||
#{item.tagID}, #{item.status}, #{item.lastCollectTime}, #{item.creator},
|
||||
#{item.updater}, #{item.createTime}, #{item.updateTime}, #{item.deleteTime}, #{item.deleted}
|
||||
)
|
||||
</foreach>
|
||||
|
||||
@@ -1,194 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.xyzh.news.mapper.ResourceCategoryMapper">
|
||||
|
||||
<!-- 基础结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.resource.TbResourceCategory">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="category_id" property="categoryID" jdbcType="VARCHAR"/>
|
||||
<result column="name" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="parent_id" property="parentID" jdbcType="VARCHAR"/>
|
||||
<result column="description" property="description" jdbcType="VARCHAR"/>
|
||||
<result column="icon" property="icon" jdbcType="VARCHAR"/>
|
||||
<result column="order_num" property="orderNum" jdbcType="INTEGER"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, category_id, name, parent_id, description, icon, order_num,
|
||||
creator, updater, create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
<sql id="Where_Clause">
|
||||
<where>
|
||||
deleted = 0
|
||||
<if test="categoryID != null and categoryID != ''">
|
||||
AND category_id = #{categoryID}
|
||||
</if>
|
||||
<if test="name != null and name != ''">
|
||||
AND name LIKE CONCAT('%', #{name}, '%')
|
||||
</if>
|
||||
<if test="parentID != null and parentID != ''">
|
||||
AND parent_id = #{parentID}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectResourceCategories -->
|
||||
<select id="selectResourceCategories" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_resource_category
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY order_num ASC, create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 根据分类ID查询分类信息 -->
|
||||
<select id="selectByCategoryId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_resource_category
|
||||
WHERE category_id = #{categoryId} AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 根据父分类ID查询子分类列表 -->
|
||||
<select id="selectByParentId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_resource_category
|
||||
WHERE parent_id = #{parentId} AND deleted = 0
|
||||
ORDER BY order_num ASC, create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 根据状态查询分类列表 -->
|
||||
<select id="selectByStatus" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_resource_category
|
||||
WHERE deleted = 0
|
||||
ORDER BY order_num ASC, create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 查询分类树结构 -->
|
||||
<select id="selectCategoryTree" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_resource_category
|
||||
WHERE deleted = 0
|
||||
ORDER BY order_num ASC, create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 检查分类名称是否存在 -->
|
||||
<select id="countByName" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_resource_category
|
||||
WHERE name = #{name} AND deleted = 0
|
||||
<if test="excludeId != null and excludeId != ''">
|
||||
AND id != #{excludeId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 插入资源分类 -->
|
||||
<insert id="insertResourceCategory" parameterType="org.xyzh.common.dto.resource.TbResourceCategory">
|
||||
INSERT INTO tb_resource_category (
|
||||
id, category_id, name, parent_id, description, icon, order_num,
|
||||
creator, updater, create_time, update_time, delete_time, deleted
|
||||
) VALUES (
|
||||
#{id}, #{categoryID}, #{name}, #{parentID}, #{description}, #{icon}, #{orderNum},
|
||||
#{creator}, #{updater}, #{createTime}, #{updateTime}, #{deleteTime}, #{deleted}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 更新资源分类 -->
|
||||
<update id="updateResourceCategory" parameterType="org.xyzh.common.dto.resource.TbResourceCategory">
|
||||
UPDATE tb_resource_category
|
||||
<set>
|
||||
<if test="categoryID != null and categoryID != ''">
|
||||
category_id = #{categoryID},
|
||||
</if>
|
||||
<if test="name != null and name != ''">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="parentID != null and parentID != ''">
|
||||
parent_id = #{parentID},
|
||||
</if>
|
||||
<if test="description != null and description != ''">
|
||||
description = #{description},
|
||||
</if>
|
||||
<if test="icon != null and icon != ''">
|
||||
icon = #{icon},
|
||||
</if>
|
||||
<if test="orderNum != null">
|
||||
order_num = #{orderNum},
|
||||
</if>
|
||||
<if test="updater != null and updater != ''">
|
||||
updater = #{updater},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime},
|
||||
</if>
|
||||
<if test="deleteTime != null">
|
||||
delete_time = #{deleteTime},
|
||||
</if>
|
||||
<if test="deleted != null">
|
||||
deleted = #{deleted},
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 删除资源分类 -->
|
||||
<delete id="deleteResourceCategory" parameterType="org.xyzh.common.dto.resource.TbResourceCategory">
|
||||
DELETE FROM tb_resource_category
|
||||
WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- 批量插入资源分类 -->
|
||||
<insert id="batchInsertResourceCategories" parameterType="java.util.List">
|
||||
INSERT INTO tb_resource_category (
|
||||
id, category_id, name, parent_id, description, icon, order_num,
|
||||
creator, updater, create_time, update_time, delete_time, deleted
|
||||
) VALUES
|
||||
<foreach collection="resourceCategoryList" item="item" separator=",">
|
||||
(
|
||||
#{item.id}, #{item.categoryID}, #{item.name}, #{item.parentID}, #{item.description},
|
||||
#{item.icon}, #{item.orderNum}, #{item.creator}, #{item.updater},
|
||||
#{item.createTime}, #{item.updateTime}, #{item.deleteTime}, #{item.deleted}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<!-- 批量删除资源分类 -->
|
||||
<delete id="batchDeleteResourceCategories">
|
||||
DELETE FROM tb_resource_category
|
||||
WHERE id IN
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- 分页查询资源分类 -->
|
||||
<select id="selectResourceCategoriesPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_resource_category
|
||||
<include refid="Where_Clause" />
|
||||
ORDER BY order_num ASC, create_time ASC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 统计资源分类总数 -->
|
||||
<select id="countResourceCategories" resultType="long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_resource_category
|
||||
<include refid="Where_Clause" />
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -10,7 +10,7 @@
|
||||
<result column="content" property="content" jdbcType="LONGVARCHAR"/>
|
||||
<result column="summary" property="summary" jdbcType="VARCHAR"/>
|
||||
<result column="cover_image" property="coverImage" jdbcType="VARCHAR"/>
|
||||
<result column="category_id" property="categoryID" jdbcType="VARCHAR"/>
|
||||
<result column="tag_id" property="tagID" jdbcType="VARCHAR"/>
|
||||
<result column="author" property="author" jdbcType="VARCHAR"/>
|
||||
<result column="source" property="source" jdbcType="VARCHAR"/>
|
||||
<result column="source_url" property="sourceUrl" jdbcType="VARCHAR"/>
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, resource_id, title, content, summary, cover_image, category_id, author, source,
|
||||
id, resource_id, title, content, summary, cover_image, tag_id, author, source,
|
||||
source_url, view_count, like_count, collect_count, status, is_recommend,
|
||||
is_banner, publish_time, creator, updater, create_time, update_time,
|
||||
delete_time, deleted
|
||||
@@ -44,8 +44,8 @@
|
||||
<if test="title != null and title != ''">
|
||||
AND title LIKE CONCAT('%', #{title}, '%')
|
||||
</if>
|
||||
<if test="categoryID != null and categoryID != ''">
|
||||
AND category_id = #{categoryID}
|
||||
<if test="tagID != null and tagID != ''">
|
||||
AND tag_id = #{tagID}
|
||||
</if>
|
||||
<if test="author != null and author != ''">
|
||||
AND author LIKE CONCAT('%', #{author}, '%')
|
||||
@@ -79,12 +79,12 @@
|
||||
WHERE resource_id = #{resourceId} AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 根据分类ID查询资源列表 -->
|
||||
<select id="selectByCategoryId" resultMap="BaseResultMap">
|
||||
<!-- 根据标签ID查询资源列表 -->
|
||||
<select id="selectByTagId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_resource
|
||||
WHERE category_id = #{categoryId} AND deleted = 0
|
||||
WHERE tag_id = #{tagId} AND deleted = 0
|
||||
ORDER BY publish_time DESC, create_time DESC
|
||||
</select>
|
||||
|
||||
@@ -97,12 +97,12 @@
|
||||
ORDER BY publish_time DESC, create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据类型查询资源列表 -->
|
||||
<!-- 根据标签类型查询资源列表 -->
|
||||
<select id="selectByType" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_resource
|
||||
WHERE category_id = #{type} AND deleted = 0
|
||||
WHERE tag_id = #{type} AND deleted = 0
|
||||
ORDER BY publish_time DESC, create_time DESC
|
||||
</select>
|
||||
|
||||
@@ -155,12 +155,12 @@
|
||||
<!-- 插入资源 -->
|
||||
<insert id="insertResource" parameterType="org.xyzh.common.dto.resource.TbResource">
|
||||
INSERT INTO tb_resource (
|
||||
id, resource_id, title, content, summary, cover_image, category_id, author, source,
|
||||
id, resource_id, title, content, summary, cover_image, tag_id, author, source,
|
||||
source_url, view_count, like_count, collect_count, status, is_recommend,
|
||||
is_banner, publish_time, creator, updater, create_time, update_time,
|
||||
delete_time, deleted
|
||||
) VALUES (
|
||||
#{id}, #{resourceID}, #{title}, #{content}, #{summary}, #{coverImage}, #{categoryID}, #{author}, #{source},
|
||||
#{id}, #{resourceID}, #{title}, #{content}, #{summary}, #{coverImage}, #{tagID}, #{author}, #{source},
|
||||
#{sourceUrl}, #{viewCount}, #{likeCount}, #{collectCount}, #{status}, #{isRecommend},
|
||||
#{isBanner}, #{publishTime}, #{creator}, #{updater}, #{createTime}, #{updateTime},
|
||||
#{deleteTime}, #{deleted}
|
||||
@@ -183,8 +183,8 @@
|
||||
<if test="coverImage != null and coverImage != ''">
|
||||
cover_image = #{coverImage},
|
||||
</if>
|
||||
<if test="categoryID != null and categoryID != ''">
|
||||
category_id = #{categoryID},
|
||||
<if test="tagID != null and tagID != ''">
|
||||
tag_id = #{tagID},
|
||||
</if>
|
||||
<if test="author != null and author != ''">
|
||||
author = #{author},
|
||||
@@ -241,7 +241,7 @@
|
||||
<!-- 批量插入资源 -->
|
||||
<insert id="batchInsertResources" parameterType="java.util.List">
|
||||
INSERT INTO tb_resource (
|
||||
id, resource_id, title, content, summary, cover_image, category_id, author, source,
|
||||
id, resource_id, title, content, summary, cover_image, tag_id, author, source,
|
||||
source_url, view_count, like_count, collect_count, status, is_recommend,
|
||||
is_banner, publish_time, creator, updater, create_time, update_time,
|
||||
delete_time, deleted
|
||||
@@ -249,7 +249,7 @@
|
||||
<foreach collection="resourceList" item="item" separator=",">
|
||||
(
|
||||
#{item.id}, #{item.resourceID}, #{item.title}, #{item.content}, #{item.summary}, #{item.coverImage},
|
||||
#{item.categoryID}, #{item.author}, #{item.source}, #{item.sourceUrl},
|
||||
#{item.tagID}, #{item.author}, #{item.source}, #{item.sourceUrl},
|
||||
#{item.viewCount}, #{item.likeCount}, #{item.collectCount}, #{item.status},
|
||||
#{item.isRecommend}, #{item.isBanner}, #{item.publishTime}, #{item.creator},
|
||||
#{item.updater}, #{item.createTime}, #{item.updateTime}, #{item.deleteTime}, #{item.deleted}
|
||||
@@ -276,8 +276,8 @@
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.categoryID != null and filter.categoryID != ''">
|
||||
AND category_id = #{filter.categoryID}
|
||||
<if test="filter.tagID != null and filter.tagID != ''">
|
||||
AND tag_id = #{filter.tagID}
|
||||
</if>
|
||||
<if test="filter.author != null and filter.author != ''">
|
||||
AND author LIKE CONCAT('%', #{filter.author}, '%')
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<result column="name" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="color" property="color" jdbcType="VARCHAR"/>
|
||||
<result column="description" property="description" jdbcType="VARCHAR"/>
|
||||
<result column="tag_type" property="tagType" jdbcType="INTEGER"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
@@ -19,7 +20,7 @@
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, tag_id, name, color, description, creator, updater, create_time,
|
||||
id, tag_id, name, color, description, tag_type, creator, updater, create_time,
|
||||
update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
@@ -36,6 +37,9 @@
|
||||
<if test="color != null and color != ''">
|
||||
AND color = #{color}
|
||||
</if>
|
||||
<if test="tagType != null">
|
||||
AND tag_type = #{tagType}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
@@ -73,12 +77,15 @@
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据类型查询标签列表 -->
|
||||
<select id="selectByType" resultMap="BaseResultMap">
|
||||
<!-- 根据标签类型查询标签列表 -->
|
||||
<select id="selectByTagType" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_tag
|
||||
WHERE deleted = 0
|
||||
<if test="tagType != null">
|
||||
AND tag_type = #{tagType}
|
||||
</if>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
@@ -94,11 +101,14 @@
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 检查标签名称是否存在 -->
|
||||
<select id="countByName" resultType="int">
|
||||
<!-- 检查标签名称是否存在(同类型下) -->
|
||||
<select id="countByNameAndType" resultType="int">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_tag
|
||||
WHERE name = #{name} AND deleted = 0
|
||||
<if test="tagType != null">
|
||||
AND tag_type = #{tagType}
|
||||
</if>
|
||||
<if test="excludeId != null and excludeId != ''">
|
||||
AND id != #{excludeId}
|
||||
</if>
|
||||
@@ -107,10 +117,10 @@
|
||||
<!-- 插入标签 -->
|
||||
<insert id="insertTag" parameterType="org.xyzh.common.dto.resource.TbTag">
|
||||
INSERT INTO tb_tag (
|
||||
id, tag_id, name, color, description, creator, updater, create_time,
|
||||
id, tag_id, name, color, description, tag_type, creator, updater, create_time,
|
||||
update_time, delete_time, deleted
|
||||
) VALUES (
|
||||
#{id}, #{tagID}, #{name}, #{color}, #{description}, #{creator}, #{updater}, #{createTime},
|
||||
#{id}, #{tagID}, #{name}, #{color}, #{description}, #{tagType}, #{creator}, #{updater}, #{createTime},
|
||||
#{updateTime}, #{deleteTime}, #{deleted}
|
||||
)
|
||||
</insert>
|
||||
@@ -131,6 +141,9 @@
|
||||
<if test="description != null and description != ''">
|
||||
description = #{description},
|
||||
</if>
|
||||
<if test="tagType != null">
|
||||
tag_type = #{tagType},
|
||||
</if>
|
||||
<if test="updater != null and updater != ''">
|
||||
updater = #{updater},
|
||||
</if>
|
||||
@@ -156,13 +169,13 @@
|
||||
<!-- 批量插入标签 -->
|
||||
<insert id="batchInsertTags" parameterType="java.util.List">
|
||||
INSERT INTO tb_tag (
|
||||
id, tag_id, name, color, description, creator, updater, create_time,
|
||||
id, tag_id, name, color, description, tag_type, creator, updater, create_time,
|
||||
update_time, delete_time, deleted
|
||||
) VALUES
|
||||
<foreach collection="tagList" item="item" separator=",">
|
||||
(
|
||||
#{item.id}, #{item.tagID}, #{item.name}, #{item.color}, #{item.description},
|
||||
#{item.creator}, #{item.updater}, #{item.createTime}, #{item.updateTime},
|
||||
#{item.tagType}, #{item.creator}, #{item.updater}, #{item.createTime}, #{item.updateTime},
|
||||
#{item.deleteTime}, #{item.deleted}
|
||||
)
|
||||
</foreach>
|
||||
|
||||
Reference in New Issue
Block a user