From 16824537d18dc101c5cd878089467ac9059519ce Mon Sep 17 00:00:00 2001 From: wangys <3401275564@qq.com> Date: Mon, 20 Oct 2025 15:08:20 +0800 Subject: [PATCH] =?UTF-8?q?serv-=E8=B5=84=E6=BA=90=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- schoolNewsServ/.gitignore | 3 +- .../admin/src/main/resources/application.yml | 2 +- .../api-news/src/main/java/org/xyzh/Main.java | 7 - .../recommend/ResourceRecommendService.java | 21 +- .../api/news/resource/ResourceService.java | 17 +- .../org/xyzh/common/core/page/PageParam.java | 29 + .../xyzh/common/core/page/PageRequest.java | 40 + .../xyzh/common/dto/resource/TbResource.java | 14 + .../java/org/xyzh/common/vo/ResourceVO.java | 49 ++ .../main/java/org/xyzh/common/vo/TagVO.java | 89 +++ schoolNewsServ/news/pom.xml | 7 +- .../news/controller/BannerController.java | 19 +- .../ResourceCategoryController.java | 22 +- .../news/controller/ResourceController.java | 97 ++- .../ResourceRecommendController.java | 31 +- .../xyzh/news/controller/TagController.java | 95 ++- .../org/xyzh/news/mapper/ResourceMapper.java | 2 +- .../xyzh/news/mapper/ResourceTagMapper.java | 3 +- .../service/impl/NCBannerServiceImpl.java | 363 ++++++++- .../impl/NCResourceCategoryServiceImpl.java | 334 ++++++++- .../impl/NCResourceRecommendServiceImpl.java | 415 ++++++++++- .../service/impl/NCResourceServiceImpl.java | 687 +++++++++++++++++- .../news/service/impl/NCTagServiceImpl.java | 454 ++++++++++-- .../main/resources/mapper/BannerMapper.xml | 2 +- .../mapper/DataCollectionConfigMapper.xml | 2 +- .../mapper/DataCollectionLogMapper.xml | 2 +- .../mapper/ResourceCategoryMapper.xml | 2 +- .../main/resources/mapper/ResourceMapper.xml | 47 +- .../mapper/ResourceRecommendMapper.xml | 2 +- .../resources/mapper/ResourceTagMapper.xml | 35 +- .../src/main/resources/mapper/TagMapper.xml | 2 +- .../resources/mapper/CourseChapterMapper.xml | 2 +- .../main/resources/mapper/CourseMapper.xml | 2 +- .../main/resources/mapper/CourseTagMapper.xml | 2 +- .../resources/mapper/LearningRecordMapper.xml | 2 +- .../mapper/LearningStatisticsMapper.xml | 2 +- .../resources/mapper/LearningTaskMapper.xml | 2 +- .../resources/mapper/TaskCourseMapper.xml | 2 +- .../resources/mapper/TaskResourceMapper.xml | 2 +- .../main/resources/mapper/TaskUserMapper.xml | 2 +- .../org/xyzh/system/mapper/UserMapper.java | 9 + .../user/service/impl/SysUserServiceImpl.java | 3 +- .../main/resources/mapper/ModuleMapper.xml | 2 +- .../src/main/resources/mapper/UserMapper.xml | 72 +- .../resources/mapper/AchievementMapper.xml | 2 +- .../resources/mapper/PointsRecordMapper.xml | 2 +- .../mapper/UserAchievementMapper.xml | 2 +- .../mapper/UserBrowseRecordMapper.xml | 2 +- .../resources/mapper/UserCollectionMapper.xml | 2 +- .../resources/mapper/UserPointsMapper.xml | 2 +- 50 files changed, 2657 insertions(+), 353 deletions(-) delete mode 100644 schoolNewsServ/api/api-news/src/main/java/org/xyzh/Main.java create mode 100644 schoolNewsServ/common/common-core/src/main/java/org/xyzh/common/core/page/PageRequest.java create mode 100644 schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/ResourceVO.java create mode 100644 schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/TagVO.java diff --git a/schoolNewsServ/.gitignore b/schoolNewsServ/.gitignore index 7b657af..c837e95 100644 --- a/schoolNewsServ/.gitignore +++ b/schoolNewsServ/.gitignore @@ -7,7 +7,8 @@ HELP.md .mvn/wrapper/maven-wrapper.jar !**/src/main/**/target/ !**/src/test/**/target/ -!**/upload/** +!**/uploads/** +admin/uploads/** ### Logs ### **/logs/ diff --git a/schoolNewsServ/admin/src/main/resources/application.yml b/schoolNewsServ/admin/src/main/resources/application.yml index 3e6e5dd..d6f4102 100644 --- a/schoolNewsServ/admin/src/main/resources/application.yml +++ b/schoolNewsServ/admin/src/main/resources/application.yml @@ -13,7 +13,7 @@ spring: # 数据源配置 datasource: driver-class-name: com.mysql.cj.jdbc.Driver - url: jdbc:mysql://localhost:3306/school_news?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8 + url: jdbc:mysql://localhost:3306/school_news?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true username: root password: 123456 hikari: diff --git a/schoolNewsServ/api/api-news/src/main/java/org/xyzh/Main.java b/schoolNewsServ/api/api-news/src/main/java/org/xyzh/Main.java deleted file mode 100644 index f660b7a..0000000 --- a/schoolNewsServ/api/api-news/src/main/java/org/xyzh/Main.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.xyzh; - -public class Main { - public static void main(String[] args) { - System.out.println("Hello world!"); - } -} \ No newline at end of file diff --git a/schoolNewsServ/api/api-news/src/main/java/org/xyzh/api/news/recommend/ResourceRecommendService.java b/schoolNewsServ/api/api-news/src/main/java/org/xyzh/api/news/recommend/ResourceRecommendService.java index 5ccb163..72ebf47 100644 --- a/schoolNewsServ/api/api-news/src/main/java/org/xyzh/api/news/recommend/ResourceRecommendService.java +++ b/schoolNewsServ/api/api-news/src/main/java/org/xyzh/api/news/recommend/ResourceRecommendService.java @@ -31,6 +31,23 @@ public interface ResourceRecommendService { */ ResultDomain addRecommend(TbResourceRecommend recommend); + /** + * @description 更新推荐资源 + * @param recommend 推荐信息 + * @return ResultDomain 更新结果 + * @author yslg + * @since 2025-10-15 + */ + ResultDomain updateRecommend(TbResourceRecommend recommend); + + /** + * @description 删除推荐资源 + * @param resourceID 资源ID + * @return ResultDomain 删除结果 + * @author yslg + * @since 2025-10-15 + */ + ResultDomain deleteRecommend(String resourceID); /** * @description 移除推荐资源 * @param resourceID 资源ID @@ -90,10 +107,10 @@ public interface ResourceRecommendService { /** * @description 获取推荐资源详情 - * @param resourceID 资源ID + * @param recommendID 推荐ID * @return ResultDomain 推荐详情 * @author yslg * @since 2025-10-15 */ - ResultDomain getRecommendDetail(String resourceID); + ResultDomain getRecommendDetail(String recommendID); } diff --git a/schoolNewsServ/api/api-news/src/main/java/org/xyzh/api/news/resource/ResourceService.java b/schoolNewsServ/api/api-news/src/main/java/org/xyzh/api/news/resource/ResourceService.java index 96c644f..7eb2e13 100644 --- a/schoolNewsServ/api/api-news/src/main/java/org/xyzh/api/news/resource/ResourceService.java +++ b/schoolNewsServ/api/api-news/src/main/java/org/xyzh/api/news/resource/ResourceService.java @@ -1,7 +1,9 @@ package org.xyzh.api.news.resource; import org.xyzh.common.core.domain.ResultDomain; +import org.xyzh.common.core.page.PageParam; import org.xyzh.common.dto.resource.TbResource; +import org.xyzh.common.vo.ResourceVO; import java.util.List; @@ -23,6 +25,15 @@ public interface ResourceService { */ ResultDomain getResourceList(TbResource filter); + /** + * @description 获取资源分页 + * @param filter 过滤条件 + * @return ResultDomain 资源分页 + * @author yslg + * @since 2025-10-15 + */ + ResultDomain getResourcePage(TbResource filter, PageParam pageParam); + /** * @description 根据ID获取资源详情 * @param resourceID 资源ID @@ -30,7 +41,7 @@ public interface ResourceService { * @author yslg * @since 2025-10-15 */ - ResultDomain getResourceById(String resourceID); + ResultDomain getResourceById(String resourceID); /** * @description 创建资源 @@ -39,7 +50,7 @@ public interface ResourceService { * @author yslg * @since 2025-10-15 */ - ResultDomain createResource(TbResource resource); + ResultDomain createResource(ResourceVO resource); /** * @description 更新资源 @@ -48,7 +59,7 @@ public interface ResourceService { * @author yslg * @since 2025-10-15 */ - ResultDomain updateResource(TbResource resource); + ResultDomain updateResource(ResourceVO resource); /** * @description 删除资源 diff --git a/schoolNewsServ/common/common-core/src/main/java/org/xyzh/common/core/page/PageParam.java b/schoolNewsServ/common/common-core/src/main/java/org/xyzh/common/core/page/PageParam.java index ec664c5..9b243f2 100644 --- a/schoolNewsServ/common/common-core/src/main/java/org/xyzh/common/core/page/PageParam.java +++ b/schoolNewsServ/common/common-core/src/main/java/org/xyzh/common/core/page/PageParam.java @@ -40,16 +40,25 @@ public class PageParam implements Serializable { */ private long totalElements; + /** + * @description 偏移量 + * @author yslg + * @since 2025-10-20 + */ + private long offset; + public PageParam() { this.pageNumber = 1; this.pageSize = 10; this.totalPages = 0; this.totalElements = 0; + this.offset = 0; } public PageParam(int pageNumber, int pageSize) { this.pageNumber = pageNumber; this.pageSize = pageSize; + this.offset = (pageNumber - 1) * pageSize; } public PageParam(int pageNumber, int pageSize, int totalPages, long totalElements) { @@ -57,6 +66,7 @@ public class PageParam implements Serializable { this.pageSize = pageSize; this.totalPages = totalPages; this.totalElements = totalElements; + this.offset = (pageNumber - 1) * pageSize; } /** * @description 设置当前页码 @@ -147,5 +157,24 @@ public class PageParam implements Serializable { return totalElements; } + /** + * @description 设置偏移量 + * @param offset 偏移量 + * @return void + * @author yslg + * @since 2025-10-20 + */ + public void setOffset(long offset) { + this.offset = offset; + } + /** + * @description 获取偏移量 + * @return 偏移量 + * @author yslg + * @since 2025-10-20 + */ + public long getOffset() { + return offset; + } } diff --git a/schoolNewsServ/common/common-core/src/main/java/org/xyzh/common/core/page/PageRequest.java b/schoolNewsServ/common/common-core/src/main/java/org/xyzh/common/core/page/PageRequest.java new file mode 100644 index 0000000..f607bf4 --- /dev/null +++ b/schoolNewsServ/common/common-core/src/main/java/org/xyzh/common/core/page/PageRequest.java @@ -0,0 +1,40 @@ +package org.xyzh.common.core.page; + +import org.xyzh.common.core.page.PageParam; + +/** + * @description 分页查询请求 + * @filename PageRequest.java + * @author yslg + * @copyright xyzh + * @since 2025-10-20 + */ +public class PageRequest { + + /** + * 过滤条件 + */ + private T filter; + + /** + * 分页参数 + */ + private PageParam pageParam; + + public T getFilter() { + return filter; + } + + public void setFilter(T filter) { + this.filter = filter; + } + + public PageParam getPageParam() { + return pageParam; + } + + public void setPageParam(PageParam pageParam) { + this.pageParam = pageParam; + } +} + diff --git a/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/resource/TbResource.java b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/resource/TbResource.java index 3eb6db1..5ad3b0c 100644 --- a/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/resource/TbResource.java +++ b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/resource/TbResource.java @@ -13,6 +13,11 @@ import java.util.Date; public class TbResource extends BaseDTO { private static final long serialVersionUID = 1L; + + /** + * @description 资源ID + */ + private String resourceID; /** * @description 资源标题 @@ -99,6 +104,14 @@ public class TbResource extends BaseDTO { */ private String updater; + public String getResourceID() { + return resourceID; + } + + public void setResourceID(String resourceID) { + this.resourceID = resourceID; + } + public String getTitle() { return title; } @@ -239,6 +252,7 @@ public class TbResource extends BaseDTO { public String toString() { return "TbResource{" + "id=" + getID() + + ", resourceID='" + resourceID + '\'' + ", title='" + title + '\'' + ", categoryID='" + categoryID + '\'' + ", author='" + author + '\'' + diff --git a/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/ResourceVO.java b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/ResourceVO.java new file mode 100644 index 0000000..bafaeee --- /dev/null +++ b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/ResourceVO.java @@ -0,0 +1,49 @@ +package org.xyzh.common.vo; + +import java.io.Serializable; + +import org.xyzh.common.dto.resource.TbResource; +import org.xyzh.common.dto.resource.TbResourceCategory; +import org.xyzh.common.dto.resource.TbTag; + +import java.util.List; + +/** + * @description 资源VO + * @filename ResourceVO.java + * @author yslg + * @copyright xyzh + * @since 2025-10-20 + */ +public class ResourceVO implements Serializable{ + private static final long serialVersionUID = 1L; + + private TbResource resource; + + private TbResourceCategory resourceCategory; + + private List tags; + + public TbResource getResource() { + return resource; + } + + public void setResource(TbResource resource) { + this.resource = resource; + } + + public TbResourceCategory getResourceCategory() { + return resourceCategory; + } + + public void setResourceCategory(TbResourceCategory resourceCategory) { + this.resourceCategory = resourceCategory; + } + public List getTags() { + return tags; + } + + public void setTags(List tags) { + this.tags = tags; + } +} diff --git a/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/TagVO.java b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/TagVO.java new file mode 100644 index 0000000..67bbb45 --- /dev/null +++ b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/TagVO.java @@ -0,0 +1,89 @@ +package org.xyzh.common.vo; + +import org.xyzh.common.dto.BaseDTO; +import org.xyzh.common.dto.resource.TbResourceTag; +import org.xyzh.common.dto.resource.TbTag; + +/** + * @description 标签VO + * @filename TagVO.java + * @author yslg + * @copyright xyzh + * @since 2025-10-15 + */ +public class TagVO extends BaseDTO { + private static final long serialVersionUID = 1L; + + /** + * @description 资源ID + */ + private String resourceID; + + /** + * @description 标签ID + */ + private String tagID; + + private String tagName; + + private String tagColor; + + /** + * @description 创建者 + */ + private String creator; + + public String getResourceID() { + return resourceID; + } + + public void setResourceID(String resourceID) { + this.resourceID = resourceID; + } + + public String getTagID() { + return tagID; + } + + public void setTagID(String tagID) { + this.tagID = tagID; + } + + public String getTagName() { + return tagName; + } + + public void setTagName(String tagName) { + this.tagName = tagName; + } + + public String getTagColor() { + return tagColor; + } + + public void setTagColor(String tagColor) { + this.tagColor = tagColor; + } + + public String getCreator() { + return creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public TbResourceTag getResourceTag() { + TbResourceTag resourceTag = new TbResourceTag(); + resourceTag.setResourceID(resourceID); + resourceTag.setTagID(tagID); + return resourceTag; + } + public TbTag getTag() { + TbTag tag = new TbTag(); + tag.setID(tagID); + tag.setName(tagName); + tag.setColor(tagColor); + return tag; + } +} diff --git a/schoolNewsServ/news/pom.xml b/schoolNewsServ/news/pom.xml index 9c94033..51dd753 100644 --- a/schoolNewsServ/news/pom.xml +++ b/schoolNewsServ/news/pom.xml @@ -23,7 +23,12 @@ org.xyzh api-news ${school-news.version} - + + + org.xyzh + system + ${school-news.version} + org.xyzh common-all diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/BannerController.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/BannerController.java index 167d44e..21084f5 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/BannerController.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/BannerController.java @@ -16,7 +16,7 @@ import org.xyzh.common.dto.resource.TbBanner; * @since 2025-10-15 */ @RestController -@RequestMapping("/news/banner") +@RequestMapping("/news/banners") public class BannerController { private static final Logger logger = LoggerFactory.getLogger(BannerController.class); @@ -27,15 +27,14 @@ public class BannerController { * 获取横幅列表 */ @GetMapping("/list") - public ResultDomain getBannerList(TbBanner filter) { - return null; - // return bannerService.getBannerList(filter); + public ResultDomain getBannerList() { + return bannerService.getBannerList(null); } /** * 根据ID获取横幅详情 */ - @GetMapping("/{bannerID}") + @GetMapping("/banner/{bannerID}") public ResultDomain getBannerById(@PathVariable String bannerID) { return bannerService.getBannerById(bannerID); } @@ -43,7 +42,7 @@ public class BannerController { /** * 创建横幅 */ - @PostMapping("/create") + @PostMapping("/banner") public ResultDomain createBanner(@RequestBody TbBanner banner) { return bannerService.createBanner(banner); } @@ -51,7 +50,7 @@ public class BannerController { /** * 更新横幅 */ - @PutMapping("/update") + @PutMapping("/banner") public ResultDomain updateBanner(@RequestBody TbBanner banner) { return bannerService.updateBanner(banner); } @@ -59,7 +58,7 @@ public class BannerController { /** * 删除横幅 */ - @DeleteMapping("/{bannerID}") + @DeleteMapping("/banner/{bannerID}") public ResultDomain deleteBanner(@PathVariable String bannerID) { return bannerService.deleteBanner(bannerID); } @@ -67,7 +66,7 @@ public class BannerController { /** * 更新横幅状态 */ - @PutMapping("/{bannerID}/status") + @PutMapping("/banner/{bannerID}/status") public ResultDomain updateBannerStatus( @PathVariable String bannerID, @RequestParam Integer status) { @@ -77,7 +76,7 @@ public class BannerController { /** * 更新横幅排序 */ - @PutMapping("/{bannerID}/order") + @PutMapping("/banner/{bannerID}/order") public ResultDomain updateBannerOrder( @PathVariable String bannerID, @RequestParam Integer orderNum) { diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceCategoryController.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceCategoryController.java index c0617da..0fbebbd 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceCategoryController.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceCategoryController.java @@ -16,7 +16,7 @@ import org.xyzh.common.dto.resource.TbResourceCategory; * @since 2025-10-15 */ @RestController -@RequestMapping("/news/category") +@RequestMapping("/news/categorys") public class ResourceCategoryController { private static final Logger logger = LoggerFactory.getLogger(ResourceCategoryController.class); @@ -27,15 +27,14 @@ public class ResourceCategoryController { * 获取分类列表 */ @GetMapping("/list") - public ResultDomain getCategoryList(TbResourceCategory filter) { - return null; - // return resourceCategoryService.getCategoryList(filter); + public ResultDomain getCategoryList() { + return resourceCategoryService.getAllCategories(); } /** * 根据ID获取分类详情 */ - @GetMapping("/{categoryID}") + @GetMapping("/category/{categoryID}") public ResultDomain getCategoryById(@PathVariable String categoryID) { return resourceCategoryService.getCategoryById(categoryID); } @@ -43,7 +42,7 @@ public class ResourceCategoryController { /** * 创建分类 */ - @PostMapping("/create") + @PostMapping("/category") public ResultDomain createCategory(@RequestBody TbResourceCategory category) { return resourceCategoryService.createCategory(category); } @@ -51,7 +50,7 @@ public class ResourceCategoryController { /** * 更新分类 */ - @PutMapping("/update") + @PutMapping("/category") public ResultDomain updateCategory(@RequestBody TbResourceCategory category) { return resourceCategoryService.updateCategory(category); } @@ -59,7 +58,7 @@ public class ResourceCategoryController { /** * 删除分类 */ - @DeleteMapping("/{categoryID}") + @DeleteMapping("/category/{categoryID}") public ResultDomain deleteCategory(@PathVariable String categoryID) { return resourceCategoryService.deleteCategory(categoryID); } @@ -67,7 +66,7 @@ public class ResourceCategoryController { /** * 更新分类状态 */ - @PutMapping("/{categoryID}/status") + @PutMapping("/category/{categoryID}/status") public ResultDomain updateCategoryStatus(@PathVariable String categoryID, @RequestParam Integer status) { return null; // return resourceCategoryService.updateCategoryStatus(categoryID, status); @@ -84,9 +83,8 @@ public class ResourceCategoryController { /** * 获取子分类 */ - @GetMapping("/{parentID}/children") + @GetMapping("/category/{parentID}/children") public ResultDomain getChildCategories(@PathVariable String parentID) { - return null; - // return resourceCategoryService.getChildCategories(parentID); + return resourceCategoryService.getCategoriesByParent(parentID); } } diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceController.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceController.java index d782596..63e8fc7 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceController.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceController.java @@ -1,13 +1,21 @@ package org.xyzh.news.controller; +import java.util.Date; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.*; import org.xyzh.api.news.resource.ResourceService; import org.xyzh.common.core.domain.ResultDomain; +import org.xyzh.common.core.page.PageParam; +import org.xyzh.common.core.page.PageRequest; import org.xyzh.common.dto.resource.TbResource; - +import org.xyzh.common.dto.user.TbSysUser; +import org.xyzh.common.utils.TimeUtils; +import org.xyzh.common.vo.ResourceVO; +import org.xyzh.system.utils.LoginUtil; /** * @description 资源控制器 * @filename ResourceController.java @@ -16,7 +24,7 @@ import org.xyzh.common.dto.resource.TbResource; * @since 2025-10-15 */ @RestController -@RequestMapping("/news/resource") +@RequestMapping("/news/resources") public class ResourceController { private static final Logger logger = LoggerFactory.getLogger(ResourceController.class); @@ -27,109 +35,130 @@ public class ResourceController { * 获取资源列表 */ @GetMapping("/list") - public ResultDomain getResourceList(TbResource filter) { + public ResultDomain getResourceList(@RequestParam("filter") TbResource filter) { return resourceService.getResourceList(filter); } + /** + * 获取资源分页 + */ + @PostMapping("/page") + public ResultDomain getResourcePage(@RequestBody PageRequest request) { + TbResource filter = request.getFilter(); + PageParam pageParam = request.getPageParam(); + return resourceService.getResourcePage(filter, pageParam); + } + /** * 根据ID获取资源详情 */ - @GetMapping("/{resourceID}") - public ResultDomain getResourceById(@PathVariable String resourceID) { + @GetMapping("/resource/{resourceID}") + public ResultDomain getResourceById(@PathVariable("resourceID") String resourceID) { return resourceService.getResourceById(resourceID); } /** * 创建资源 */ - @PostMapping("/create") - public ResultDomain createResource(@RequestBody TbResource resource) { - return resourceService.createResource(resource); + @PostMapping("/resource") + public ResultDomain createResource(@RequestBody ResourceVO resourceVO) { + TbSysUser user = LoginUtil.getCurrentUser(); + if (user == null) { + ResultDomain result = new ResultDomain(); + result.fail("请先登录"); + return result; + } + resourceVO.getResource().setCreator(user.getID()); + resourceVO.getResource().setAuthor(user.getUsername()); + Date now = new Date(); + resourceVO.getResource().setCreateTime(now); + resourceVO.getResource().setPublishTime(now); + return resourceService.createResource(resourceVO); } /** * 更新资源 */ - @PutMapping("/update") - public ResultDomain updateResource(@RequestBody TbResource resource) { + @PutMapping("/resource") + public ResultDomain updateResource(@RequestBody ResourceVO resource) { return resourceService.updateResource(resource); } /** * 删除资源 */ - @DeleteMapping("/{resourceID}") - public ResultDomain deleteResource(@PathVariable String resourceID) { + @DeleteMapping("/resource/{resourceID}") + public ResultDomain deleteResource(@PathVariable("resourceID") String resourceID) { return resourceService.deleteResource(resourceID); } /** * 更新资源状态 */ - @PutMapping("/{resourceID}/status") + @PutMapping("/resource/{resourceID}/status") public ResultDomain updateResourceStatus( - @PathVariable String resourceID, - @RequestParam Integer status) { + @PathVariable("resourceID") String resourceID, + @RequestParam("status") Integer status) { return resourceService.updateResourceStatus(resourceID, status); } /** * 发布资源 */ - @PostMapping("/{resourceID}/publish") - public ResultDomain publishResource(@PathVariable String resourceID) { + @PostMapping("/resource/{resourceID}/publish") + public ResultDomain publishResource(@PathVariable("resourceID") String resourceID) { return resourceService.publishResource(resourceID); } /** * 下架资源 */ - @PostMapping("/{resourceID}/unpublish") - public ResultDomain unpublishResource(@PathVariable String resourceID) { + @PostMapping("/resource/{resourceID}/unpublish") + public ResultDomain unpublishResource(@PathVariable("resourceID") String resourceID) { return resourceService.unpublishResource(resourceID); } /** * 增加浏览次数 */ - @PostMapping("/{resourceID}/view") - public ResultDomain incrementViewCount(@PathVariable String resourceID) { + @PostMapping("/resource/{resourceID}/view") + public ResultDomain incrementViewCount(@PathVariable("resourceID") String resourceID) { return resourceService.incrementViewCount(resourceID); } /** * 增加点赞次数 */ - @PostMapping("/{resourceID}/like") - public ResultDomain incrementLikeCount(@PathVariable String resourceID) { + @PostMapping("/resource/{resourceID}/like") + public ResultDomain incrementLikeCount(@PathVariable("resourceID") String resourceID) { return resourceService.incrementLikeCount(resourceID); } /** * 增加收藏次数 */ - @PostMapping("/{resourceID}/collect") - public ResultDomain incrementCollectCount(@PathVariable String resourceID) { + @PostMapping("/resource/{resourceID}/collect") + public ResultDomain incrementCollectCount(@PathVariable("resourceID") String resourceID) { return resourceService.incrementCollectCount(resourceID); } /** * 设置资源推荐 */ - @PutMapping("/{resourceID}/recommend") + @PutMapping("/resource/{resourceID}/recommend") public ResultDomain setResourceRecommend( - @PathVariable String resourceID, - @RequestParam Boolean isRecommend) { + @PathVariable("resourceID") String resourceID, + @RequestParam("isRecommend") Boolean isRecommend) { return resourceService.setResourceRecommend(resourceID, isRecommend); } /** * 设置资源轮播 */ - @PutMapping("/{resourceID}/banner") + @PutMapping("/resource/{resourceID}/banner") public ResultDomain setResourceBanner( - @PathVariable String resourceID, - @RequestParam Boolean isBanner) { + @PathVariable("resourceID") String resourceID, + @RequestParam("isBanner") Boolean isBanner) { return resourceService.setResourceBanner(resourceID, isBanner); } @@ -154,9 +183,9 @@ public class ResourceController { */ @GetMapping("/search") public ResultDomain searchResources( - @RequestParam String keyword, - @RequestParam(required = false) String categoryID, - @RequestParam(required = false) Integer status) { + @RequestParam("keyword") String keyword, + @RequestParam(value = "categoryID", required = false) String categoryID, + @RequestParam(value = "status", required = false) Integer status) { return resourceService.searchResources(keyword, categoryID, status); } } diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceRecommendController.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceRecommendController.java index 28a3e2f..daf6ec5 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceRecommendController.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceRecommendController.java @@ -16,7 +16,7 @@ import org.xyzh.common.dto.resource.TbResourceRecommend; * @since 2025-10-15 */ @RestController -@RequestMapping("/news/recommend") +@RequestMapping("/news/recommends") public class ResourceRecommendController { private static final Logger logger = LoggerFactory.getLogger(ResourceRecommendController.class); @@ -27,51 +27,46 @@ public class ResourceRecommendController { * 获取推荐列表 */ @GetMapping("/list") - public ResultDomain getRecommendList(TbResourceRecommend filter) { - return null; - // return resourceRecommendService.getRecommendList(filter); + public ResultDomain getRecommendList() { + return resourceRecommendService.getRecommendList(); } /** * 根据ID获取推荐详情 */ - @GetMapping("/{recommendID}") + @GetMapping("/recommend/{recommendID}") public ResultDomain getRecommendById(@PathVariable String recommendID) { - return null; - // return resourceRecommendService.getRecommendById(recommendID); + return resourceRecommendService.getRecommendDetail(recommendID); } /** * 创建推荐 */ - @PostMapping("/create") + @PostMapping("/recommend") public ResultDomain createRecommend(@RequestBody TbResourceRecommend recommend) { - return null; - // return resourceRecommendService.createRecommend(recommend); + return resourceRecommendService.addRecommend(recommend); } /** * 更新推荐 */ - @PutMapping("/update") + @PutMapping("/recommend") public ResultDomain updateRecommend(@RequestBody TbResourceRecommend recommend) { - return null; - // return resourceRecommendService.updateRecommend(recommend); + return resourceRecommendService.updateRecommend(recommend); } /** * 删除推荐 */ - @DeleteMapping("/{recommendID}") + @DeleteMapping("/recommend/{recommendID}") public ResultDomain deleteRecommend(@PathVariable String recommendID) { - return null; - // return resourceRecommendService.deleteRecommend(recommendID); + return resourceRecommendService.deleteRecommend(recommendID); } /** * 更新推荐状态 */ - @PutMapping("/{recommendID}/status") + @PutMapping("/recommend/{recommendID}/status") public ResultDomain updateRecommendStatus(@PathVariable String recommendID, @RequestParam Integer status) { return null; // return resourceRecommendService.updateRecommendStatus(recommendID, status); @@ -80,7 +75,7 @@ public class ResourceRecommendController { /** * 更新推荐排序 */ - @PutMapping("/{recommendID}/order") + @PutMapping("/recommend/{recommendID}/order") public ResultDomain updateRecommendOrder(@PathVariable String recommendID, @RequestParam Integer orderNum) { return resourceRecommendService.updateRecommendOrder(recommendID, orderNum); } diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/TagController.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/TagController.java index 29c87e7..bc341a2 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/TagController.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/TagController.java @@ -7,6 +7,9 @@ import org.springframework.web.bind.annotation.*; import org.xyzh.api.news.tag.TagService; import org.xyzh.common.core.domain.ResultDomain; import org.xyzh.common.dto.resource.TbTag; +import org.xyzh.common.dto.resource.TbResourceTag; + +import java.util.List; /** * @description 标签控制器 @@ -16,7 +19,7 @@ import org.xyzh.common.dto.resource.TbTag; * @since 2025-10-15 */ @RestController -@RequestMapping("/news/tag") +@RequestMapping("/news/tags") public class TagController { private static final Logger logger = LoggerFactory.getLogger(TagController.class); @@ -27,15 +30,14 @@ public class TagController { * 获取标签列表 */ @GetMapping("/list") - public ResultDomain getTagList(TbTag filter) { - return null; - // return tagService.getTagList(filter); + public ResultDomain getTagList() { + return tagService.getAllTags(); } /** * 根据ID获取标签详情 */ - @GetMapping("/{tagID}") + @GetMapping("/tag/{tagID}") public ResultDomain getTagById(@PathVariable String tagID) { return tagService.getTagById(tagID); } @@ -43,7 +45,7 @@ public class TagController { /** * 创建标签 */ - @PostMapping("/create") + @PostMapping("/tag") public ResultDomain createTag(@RequestBody TbTag tag) { return tagService.createTag(tag); } @@ -51,7 +53,7 @@ public class TagController { /** * 更新标签 */ - @PutMapping("/update") + @PutMapping("/tag") public ResultDomain updateTag(@RequestBody TbTag tag) { return tagService.updateTag(tag); } @@ -59,35 +61,72 @@ public class TagController { /** * 删除标签 */ - @DeleteMapping("/{tagID}") + @DeleteMapping("/tag/{tagID}") public ResultDomain deleteTag(@PathVariable String tagID) { return tagService.deleteTag(tagID); } - /** - * 更新标签状态 - */ - @PutMapping("/{tagID}/status") - public ResultDomain updateTagStatus(@PathVariable String tagID, @RequestParam Integer status) { - return null; - // return tagService.updateTagStatus(tagID, status); - } - - /** - * 获取热门标签 - */ - @GetMapping("/hot") - public ResultDomain getHotTags(@RequestParam(required = false) Integer limit) { - return null; - // return tagService.getHotTags(limit); - } - /** * 搜索标签 */ @GetMapping("/search") public ResultDomain searchTags(@RequestParam String keyword) { - return null; - // return tagService.searchTags(keyword); + return tagService.searchTagsByName(keyword); + } + + // ----------------资源标签关联相关-------------------------------- + + /** + * 获取资源的标签列表 + */ + @GetMapping("/resource/{resourceID}") + public ResultDomain getResourceTags(@PathVariable String resourceID) { + return tagService.getResourceTags(resourceID); + } + + /** + * 为资源添加单个标签 + */ + @PostMapping("/resource/{resourceID}/tag/{tagID}") + public ResultDomain addResourceTag( + @PathVariable String resourceID, + @PathVariable String tagID) { + return tagService.addResourceTag(resourceID, tagID); + } + + /** + * 批量为资源添加标签 + */ + @PostMapping("/resource/{resourceID}/tags") + public ResultDomain batchAddResourceTags( + @PathVariable String resourceID, + @RequestBody List tagIDs) { + return tagService.batchAddResourceTags(resourceID, tagIDs); + } + + /** + * 移除资源的标签 + */ + @DeleteMapping("/resource/{resourceID}/tag/{tagID}") + public ResultDomain removeResourceTag( + @PathVariable String resourceID, + @PathVariable String tagID) { + return tagService.removeResourceTag(resourceID, tagID); + } + + /** + * 清空资源的所有标签 + */ + @DeleteMapping("/resource/{resourceID}/tags") + public ResultDomain clearResourceTags(@PathVariable String resourceID) { + return tagService.clearResourceTags(resourceID); + } + + /** + * 根据标签获取资源列表 + */ + @GetMapping("/tag/{tagID}/resources") + public ResultDomain getResourcesByTag(@PathVariable String tagID) { + return tagService.getResourcesByTag(tagID); } } diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/mapper/ResourceMapper.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/mapper/ResourceMapper.java index b3ec576..8ba3443 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/mapper/ResourceMapper.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/mapper/ResourceMapper.java @@ -162,5 +162,5 @@ public interface ResourceMapper extends BaseMapper { * @author yslg * @since 2025-10-15 */ - long countResources(@Param("filter") TbResource filter); + long countResources(TbResource filter); } diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/mapper/ResourceTagMapper.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/mapper/ResourceTagMapper.java index 7f56caf..cb5a721 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/mapper/ResourceTagMapper.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/mapper/ResourceTagMapper.java @@ -5,6 +5,7 @@ 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.TbResourceTag; +import org.xyzh.common.vo.TagVO; import java.util.List; @@ -25,7 +26,7 @@ public interface ResourceTagMapper extends BaseMapper { * @author yslg * @since 2025-10-15 */ - List selectResourceTags(TbResourceTag filter); + List selectResourceTags(TbResourceTag filter); /** * @description 根据关联ID查询关联信息 diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCBannerServiceImpl.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCBannerServiceImpl.java index ae96e05..b9c1c2f 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCBannerServiceImpl.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCBannerServiceImpl.java @@ -1,13 +1,18 @@ package org.xyzh.news.service.impl; +import java.util.Date; +import java.util.List; import java.util.Map; 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.TbBanner; +import org.xyzh.common.utils.IDUtils; import org.xyzh.news.mapper.BannerMapper; import org.xyzh.api.news.banner.BannerService; @@ -27,59 +32,349 @@ public class NCBannerServiceImpl implements BannerService { private BannerMapper bannerMapper; @Override - public ResultDomain batchUpdateBannerOrder(Map bannerOrders) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ResultDomain createBanner(TbBanner banner) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ResultDomain deleteBanner(String bannerID) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ResultDomain getActiveBanners(Integer limit) { - // TODO Auto-generated method stub - return null; + public ResultDomain getBannerList(Integer status) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + List list; + if (status != null) { + list = bannerMapper.selectByStatus(status); + } else { + TbBanner filter = new TbBanner(); + list = bannerMapper.selectBanners(filter); + } + resultDomain.success("获取横幅列表成功", list); + return resultDomain; + } catch (Exception e) { + logger.error("获取横幅列表异常: {}", e.getMessage(), e); + resultDomain.fail("获取横幅列表失败: " + e.getMessage()); + return resultDomain; + } } @Override public ResultDomain getBannerById(String bannerID) { - // TODO Auto-generated method stub - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(bannerID)) { + resultDomain.fail("横幅ID不能为空"); + return resultDomain; + } + + // 查询横幅 + TbBanner banner = bannerMapper.selectByBannerId(bannerID); + if (banner == null || banner.getDeleted()) { + resultDomain.fail("横幅不存在"); + return resultDomain; + } + + resultDomain.success("获取横幅详情成功", banner); + return resultDomain; + } catch (Exception e) { + logger.error("获取横幅详情异常: {}", e.getMessage(), e); + resultDomain.fail("获取横幅详情失败: " + e.getMessage()); + return resultDomain; + } } @Override - public ResultDomain getBannerList(Integer status) { - // TODO Auto-generated method stub - return null; + @Transactional(rollbackFor = Exception.class) + public ResultDomain createBanner(TbBanner banner) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (banner == null || !StringUtils.hasText(banner.getTitle())) { + resultDomain.fail("横幅标题不能为空"); + return resultDomain; + } + if (!StringUtils.hasText(banner.getImageUrl())) { + resultDomain.fail("横幅图片不能为空"); + return resultDomain; + } + + // 检查标题是否已存在 + int count = bannerMapper.countByTitle(banner.getTitle(), null); + if (count > 0) { + resultDomain.fail("横幅标题已存在"); + return resultDomain; + } + + // 设置默认值 + if (banner.getID() == null) { + banner.setID(IDUtils.generateID()); + } + + banner.setCreateTime(new Date()); + banner.setUpdateTime(new Date()); + banner.setDeleted(false); + + // 设置默认状态和排序号 + if (banner.getStatus() == null) { + banner.setStatus(1); // 默认启用 + } + if (banner.getOrderNum() == null) { + banner.setOrderNum(0); + } + + // 插入数据库 + int result = bannerMapper.insertBanner(banner); + if (result > 0) { + logger.info("创建横幅成功: {}", banner.getTitle()); + resultDomain.success("创建横幅成功", banner); + 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 updateBanner(TbBanner banner) { - // TODO Auto-generated method stub - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (banner == null || !StringUtils.hasText(banner.getID())) { + resultDomain.fail("横幅ID不能为空"); + return resultDomain; + } + + // 检查横幅是否存在 + TbBanner existing = bannerMapper.selectById(banner.getID()); + if (existing == null || existing.getDeleted()) { + resultDomain.fail("横幅不存在"); + return resultDomain; + } + + // 如果修改了标题,检查标题是否已被使用 + if (StringUtils.hasText(banner.getTitle()) && !banner.getTitle().equals(existing.getTitle())) { + int count = bannerMapper.countByTitle(banner.getTitle(), banner.getID()); + if (count > 0) { + resultDomain.fail("横幅标题已存在"); + return resultDomain; + } + } + + // 更新时间 + banner.setUpdateTime(new Date()); + + // 更新数据库 + int result = bannerMapper.updateBanner(banner); + if (result > 0) { + logger.info("更新横幅成功: {}", banner.getID()); + // 重新查询返回完整数据 + TbBanner updated = bannerMapper.selectById(banner.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 - public ResultDomain updateBannerOrder(String bannerID, Integer orderNum) { - // TODO Auto-generated method stub - return null; + @Transactional(rollbackFor = Exception.class) + public ResultDomain deleteBanner(String bannerID) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(bannerID)) { + resultDomain.fail("横幅ID不能为空"); + return resultDomain; + } + + // 查询横幅 + TbBanner banner = bannerMapper.selectByBannerId(bannerID); + if (banner == null || banner.getDeleted()) { + resultDomain.fail("横幅不存在"); + return resultDomain; + } + + // 物理删除 + int result = bannerMapper.deleteBanner(banner); + if (result > 0) { + logger.info("删除横幅成功: {}", bannerID); + 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 + @Transactional(rollbackFor = Exception.class) public ResultDomain updateBannerStatus(String bannerID, Integer status) { - // TODO Auto-generated method stub - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(bannerID)) { + resultDomain.fail("横幅ID不能为空"); + return resultDomain; + } + if (status == null) { + resultDomain.fail("状态不能为空"); + return resultDomain; + } + + // 查询横幅 + TbBanner banner = bannerMapper.selectByBannerId(bannerID); + if (banner == null || banner.getDeleted()) { + resultDomain.fail("横幅不存在"); + return resultDomain; + } + + // 更新状态 + banner.setStatus(status); + banner.setUpdateTime(new Date()); + + int result = bannerMapper.updateBanner(banner); + if (result > 0) { + logger.info("更新横幅状态成功: {}", bannerID); + // 重新查询返回完整数据 + TbBanner updated = bannerMapper.selectById(banner.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 updateBannerOrder(String bannerID, Integer orderNum) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(bannerID)) { + resultDomain.fail("横幅ID不能为空"); + return resultDomain; + } + if (orderNum == null) { + resultDomain.fail("排序号不能为空"); + return resultDomain; + } - + // 查询横幅 + TbBanner banner = bannerMapper.selectByBannerId(bannerID); + if (banner == null || banner.getDeleted()) { + resultDomain.fail("横幅不存在"); + return resultDomain; + } + + // 更新排序号 + banner.setOrderNum(orderNum); + banner.setUpdateTime(new Date()); + + int result = bannerMapper.updateBanner(banner); + if (result > 0) { + logger.info("更新横幅排序成功: {}", bannerID); + // 重新查询返回完整数据 + TbBanner updated = bannerMapper.selectById(banner.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 + public ResultDomain getActiveBanners(Integer limit) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + List list = bannerMapper.selectActiveBanners(); + + // 如果指定了limit,截取列表 + if (limit != null && limit > 0 && list != null && list.size() > limit) { + list = list.subList(0, limit); + } + + resultDomain.success("获取活跃横幅列表成功", list); + return resultDomain; + } catch (Exception e) { + logger.error("获取活跃横幅列表异常: {}", e.getMessage(), e); + resultDomain.fail("获取活跃横幅列表失败: " + e.getMessage()); + return resultDomain; + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public ResultDomain batchUpdateBannerOrder(Map bannerOrders) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (bannerOrders == null || bannerOrders.isEmpty()) { + resultDomain.fail("横幅排序信息不能为空"); + return resultDomain; + } + + Date now = new Date(); + int successCount = 0; + + for (Map.Entry entry : bannerOrders.entrySet()) { + String bannerID = entry.getKey(); + Integer orderNum = entry.getValue(); + + if (!StringUtils.hasText(bannerID) || orderNum == null) { + continue; + } + + // 查询横幅 + TbBanner banner = bannerMapper.selectByBannerId(bannerID); + if (banner == null || banner.getDeleted()) { + continue; + } + + // 更新排序号 + banner.setOrderNum(orderNum); + banner.setUpdateTime(now); + + int result = bannerMapper.updateBanner(banner); + if (result > 0) { + successCount++; + } + } + + if (successCount > 0) { + logger.info("批量更新横幅排序成功,数量: {}", successCount); + resultDomain.success("批量更新横幅排序成功", true); + return resultDomain; + } else { + resultDomain.fail("批量更新横幅排序失败"); + return resultDomain; + } + } catch (Exception e) { + logger.error("批量更新横幅排序异常: {}", e.getMessage(), e); + resultDomain.fail("批量更新横幅排序失败: " + e.getMessage()); + return resultDomain; + } + } } diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceCategoryServiceImpl.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceCategoryServiceImpl.java index cda2783..0a00937 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceCategoryServiceImpl.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceCategoryServiceImpl.java @@ -4,11 +4,19 @@ 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 @@ -25,64 +33,328 @@ public class NCResourceCategoryServiceImpl implements ResourceCategoryService { private ResourceCategoryMapper resourceCategoryMapper; @Override + @Transactional(rollbackFor = Exception.class) public ResultDomain createCategory(TbResourceCategory category) { - // TODO Auto-generated method stub - return null; + ResultDomain 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 updateCategory(TbResourceCategory category) { + ResultDomain 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 deleteCategory(String categoryID) { - // TODO Auto-generated method stub - return null; - } + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(categoryID)) { + resultDomain.fail("分类ID不能为空"); + return resultDomain; + } - @Override - public ResultDomain getAllCategories() { - // TODO Auto-generated method stub - return null; - } + // 检查分类是否存在 + TbResourceCategory category = resourceCategoryMapper.selectByCategoryId(categoryID); + if (category == null || category.getDeleted()) { + resultDomain.fail("分类不存在"); + return resultDomain; + } - @Override - public ResultDomain getCategoriesByParent(String parentID) { - // TODO Auto-generated method stub - return null; + // 检查是否有子分类 + ResultDomain hasChildResult = hasChildCategories(categoryID); + if (hasChildResult.isSuccess() && Boolean.TRUE.equals(hasChildResult.getData())) { + resultDomain.fail("该分类下存在子分类,无法删除"); + return resultDomain; + } + + // 检查是否有关联资源 + ResultDomain 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 getCategoryById(String categoryID) { - // TODO Auto-generated method stub - return null; + ResultDomain 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 getAllCategories() { + ResultDomain resultDomain = new ResultDomain<>(); + try { + List 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 getCategoriesByParent(String parentID) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + if (!StringUtils.hasText(parentID)) { + resultDomain.fail("父分类ID不能为空"); + return resultDomain; + } + + List 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 getCategoryTree() { - // TODO Auto-generated method stub - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 查询所有分类 + List allCategories = resourceCategoryMapper.selectCategoryTree(); + + // 构建树形结构 + List 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 hasChildCategories(String categoryID) { - // TODO Auto-generated method stub - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + if (!StringUtils.hasText(categoryID)) { + resultDomain.fail("分类ID不能为空"); + return resultDomain; + } + + List 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 hasResources(String categoryID) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ResultDomain updateCategory(TbResourceCategory category) { - // TODO Auto-generated method stub - return null; + ResultDomain 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 updateCategoryOrder(String categoryID, Integer orderNum) { - // TODO Auto-generated method stub - return null; + ResultDomain 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 buildCategoryTree(List allCategories, String parentID) { + List result = new ArrayList<>(); + + for (TbResourceCategory category : allCategories) { + // 找出当前父级下的子分类 + if ((parentID == null && category.getParentID() == null) || + (parentID != null && parentID.equals(category.getParentID()))) { + + // 递归查找子分类(如果TbResourceCategory有children字段,可以在这里设置) + // List children = buildCategoryTree(allCategories, category.getCategoryID()); + // category.setChildren(children); + + result.add(category); + } + } + + return result; + } } diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceRecommendServiceImpl.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceRecommendServiceImpl.java index b6bb4db..063d5b3 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceRecommendServiceImpl.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceRecommendServiceImpl.java @@ -1,13 +1,18 @@ package org.xyzh.news.service.impl; +import java.util.ArrayList; +import java.util.Date; import java.util.List; 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.TbResourceRecommend; +import org.xyzh.common.utils.IDUtils; import org.xyzh.news.mapper.ResourceRecommendMapper; import org.xyzh.api.news.recommend.ResourceRecommendService; @@ -26,59 +31,389 @@ public class NCResourceRecommendServiceImpl implements ResourceRecommendService @Autowired private ResourceRecommendMapper resourceRecommendMapper; - @Override - public ResultDomain addRecommend(TbResourceRecommend recommend) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ResultDomain batchAddRecommends(List resourceIDs, String reason) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ResultDomain batchRemoveRecommends(List resourceIDs) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ResultDomain getRecommendDetail(String resourceID) { - // TODO Auto-generated method stub - return null; - } - @Override public ResultDomain getRecommendList() { - // TODO Auto-generated method stub - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + List list = resourceRecommendMapper.selectResourceRecommends(new TbResourceRecommend()); + resultDomain.success("获取推荐列表成功", list); + return resultDomain; + } catch (Exception e) { + logger.error("获取推荐列表异常: {}", e.getMessage(), e); + resultDomain.fail("获取推荐列表失败: " + e.getMessage()); + return resultDomain; + } + } + + @Override + @Transactional(rollbackFor = Exception.class) + public ResultDomain addRecommend(TbResourceRecommend recommend) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (recommend == null || !StringUtils.hasText(recommend.getResourceID())) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 检查资源是否已被推荐 + List existingList = resourceRecommendMapper.selectByResourceId(recommend.getResourceID()); + if (existingList != null && !existingList.isEmpty()) { + resultDomain.fail("该资源已被推荐"); + return resultDomain; + } + + // 设置默认值 + if (recommend.getID() == null) { + recommend.setID(IDUtils.generateID()); + } + + recommend.setCreateTime(new Date()); + recommend.setUpdateTime(new Date()); + recommend.setDeleted(false); + + // 如果没有设置排序号,默认为最大排序号+1 + if (recommend.getOrderNum() == null) { + recommend.setOrderNum(0); + } + + // 插入数据库 + int result = resourceRecommendMapper.insertResourceRecommend(recommend); + if (result > 0) { + logger.info("添加推荐成功: {}", recommend.getResourceID()); + resultDomain.success("添加推荐成功", recommend); + 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 updateRecommend(TbResourceRecommend recommend) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (recommend == null || !StringUtils.hasText(recommend.getID())) { + resultDomain.fail("推荐ID不能为空"); + return resultDomain; + } + + // 检查推荐是否存在 + TbResourceRecommend existing = resourceRecommendMapper.selectById(recommend.getID()); + if (existing == null || existing.getDeleted()) { + resultDomain.fail("推荐不存在"); + return resultDomain; + } + + // 更新时间 + recommend.setUpdateTime(new Date()); + + // 更新数据库 + int result = resourceRecommendMapper.updateResourceRecommend(recommend); + if (result > 0) { + logger.info("更新推荐成功: {}", recommend.getID()); + // 重新查询返回完整数据 + TbResourceRecommend updated = resourceRecommendMapper.selectById(recommend.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 deleteRecommend(String resourceID) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 查询推荐 + List recommendList = resourceRecommendMapper.selectByResourceId(resourceID); + if (recommendList == null || recommendList.isEmpty()) { + resultDomain.fail("推荐不存在"); + return resultDomain; + } + + // 物理删除 + TbResourceRecommend recommend = recommendList.get(0); + int result = resourceRecommendMapper.deleteResourceRecommend(recommend); + if (result > 0) { + logger.info("删除推荐成功: {}", resourceID); + 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 + @Transactional(rollbackFor = Exception.class) + public ResultDomain removeRecommend(String resourceID) { + return deleteRecommend(resourceID); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public ResultDomain batchAddRecommends(List resourceIDs, String reason) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (resourceIDs == null || resourceIDs.isEmpty()) { + resultDomain.fail("资源ID列表不能为空"); + return resultDomain; + } + + List recommendList = new ArrayList<>(); + Date now = new Date(); + + for (String resourceID : resourceIDs) { + if (!StringUtils.hasText(resourceID)) { + continue; + } + + // 检查是否已推荐 + List existingList = resourceRecommendMapper.selectByResourceId(resourceID); + if (existingList != null && !existingList.isEmpty()) { + continue; + } + + TbResourceRecommend recommend = new TbResourceRecommend(); + recommend.setID(IDUtils.generateID()); + recommend.setResourceID(resourceID); + recommend.setReason(reason); + recommend.setOrderNum(0); + recommend.setCreateTime(now); + recommend.setUpdateTime(now); + recommend.setDeleted(false); + + recommendList.add(recommend); + } + + if (recommendList.isEmpty()) { + resultDomain.fail("没有可添加的推荐资源"); + return resultDomain; + } + + // 批量插入 + int result = resourceRecommendMapper.batchInsertResourceRecommends(recommendList); + if (result > 0) { + logger.info("批量添加推荐成功,数量: {}", result); + resultDomain.success("批量添加推荐成功", recommendList); + 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 batchRemoveRecommends(List resourceIDs) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (resourceIDs == null || resourceIDs.isEmpty()) { + resultDomain.fail("资源ID列表不能为空"); + return resultDomain; + } + + List recommendIDs = new ArrayList<>(); + for (String resourceID : resourceIDs) { + if (!StringUtils.hasText(resourceID)) { + continue; + } + + List recommendList = resourceRecommendMapper.selectByResourceId(resourceID); + if (recommendList != null && !recommendList.isEmpty()) { + for (TbResourceRecommend recommend : recommendList) { + recommendIDs.add(recommend.getID()); + } + } + } + + if (recommendIDs.isEmpty()) { + resultDomain.fail("没有可移除的推荐"); + return resultDomain; + } + + // 批量删除 + int result = resourceRecommendMapper.batchDeleteResourceRecommends(recommendIDs); + if (result > 0) { + logger.info("批量移除推荐成功,数量: {}", result); + 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 getRecommendDetail(String recommendID) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(recommendID)) { + resultDomain.fail("推荐ID不能为空"); + return resultDomain; + } + + // 查询推荐 + TbResourceRecommend recommend = resourceRecommendMapper.selectByRecommendId(recommendID); + if (recommend == null || recommend.getDeleted()) { + resultDomain.fail("推荐不存在"); + return resultDomain; + } + + resultDomain.success("获取推荐详情成功", recommend); + return resultDomain; + } catch (Exception e) { + logger.error("获取推荐详情异常: {}", e.getMessage(), e); + resultDomain.fail("获取推荐详情失败: " + e.getMessage()); + return resultDomain; + } } @Override public ResultDomain isResourceRecommended(String resourceID) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ResultDomain removeRecommend(String resourceID) { - // TODO Auto-generated method stub - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 查询推荐 + List recommendList = resourceRecommendMapper.selectByResourceId(resourceID); + boolean isRecommended = recommendList != null && !recommendList.isEmpty(); + + resultDomain.success("检查成功", isRecommended); + return resultDomain; + } catch (Exception e) { + logger.error("检查资源是否推荐异常: {}", e.getMessage(), e); + resultDomain.fail("检查失败: " + e.getMessage()); + return resultDomain; + } } @Override + @Transactional(rollbackFor = Exception.class) public ResultDomain updateRecommendOrder(String resourceID, Integer orderNum) { - // TODO Auto-generated method stub - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + if (orderNum == null) { + resultDomain.fail("排序号不能为空"); + return resultDomain; + } + + // 查询推荐 + List recommendList = resourceRecommendMapper.selectByResourceId(resourceID); + if (recommendList == null || recommendList.isEmpty()) { + resultDomain.fail("推荐不存在"); + return resultDomain; + } + + TbResourceRecommend recommend = recommendList.get(0); + recommend.setOrderNum(orderNum); + recommend.setUpdateTime(new Date()); + + // 更新数据库 + int result = resourceRecommendMapper.updateResourceRecommend(recommend); + if (result > 0) { + logger.info("更新推荐排序成功: {}", resourceID); + // 重新查询返回完整数据 + TbResourceRecommend updated = resourceRecommendMapper.selectById(recommend.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 updateRecommendReason(String resourceID, String reason) { - // TODO Auto-generated method stub - return null; - } + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } - + // 查询推荐 + List recommendList = resourceRecommendMapper.selectByResourceId(resourceID); + if (recommendList == null || recommendList.isEmpty()) { + resultDomain.fail("推荐不存在"); + return resultDomain; + } + + TbResourceRecommend recommend = recommendList.get(0); + recommend.setReason(reason); + recommend.setUpdateTime(new Date()); + + // 更新数据库 + int result = resourceRecommendMapper.updateResourceRecommend(recommend); + if (result > 0) { + logger.info("更新推荐理由成功: {}", resourceID); + // 重新查询返回完整数据 + TbResourceRecommend updated = resourceRecommendMapper.selectById(recommend.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; + } + } } diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceServiceImpl.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceServiceImpl.java index 7957a65..0054e98 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceServiceImpl.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceServiceImpl.java @@ -4,11 +4,28 @@ 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.core.page.PageDomain; +import org.xyzh.common.core.page.PageParam; import org.xyzh.common.dto.resource.TbResource; +import org.xyzh.common.dto.resource.TbResourceTag; +import org.xyzh.common.dto.resource.TbTag; +import org.xyzh.common.dto.user.TbSysUser; +import org.xyzh.common.utils.IDUtils; +import org.xyzh.common.vo.ResourceVO; +import org.xyzh.common.vo.TagVO; import org.xyzh.news.mapper.ResourceMapper; +import org.xyzh.news.mapper.ResourceTagMapper; +import org.xyzh.system.utils.LoginUtil; import org.xyzh.api.news.resource.ResourceService; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + /** * @description 资源服务实现类 * @filename NCResourceServiceImpl.java @@ -24,99 +41,699 @@ public class NCResourceServiceImpl implements ResourceService { @Autowired private ResourceMapper resourceMapper; + @Autowired + private ResourceTagMapper resourceTagMapper; + @Override public ResultDomain getResourceList(TbResource filter) { - // TODO: 实现获取资源列表 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + if (filter == null) { + filter = new TbResource(); + } + List list = resourceMapper.selectResources(filter); + resultDomain.success("获取资源列表成功", list); + return resultDomain; + } catch (Exception e) { + logger.error("获取资源列表异常: {}", e.getMessage(), e); + resultDomain.fail("获取资源列表失败: " + e.getMessage()); + return resultDomain; + } } @Override - public ResultDomain getResourceById(String resourceID) { - // TODO: 实现根据ID获取资源详情 - return null; + public ResultDomain getResourcePage(TbResource filter, PageParam pageParam) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + if (filter == null) { + filter = new TbResource(); + } + + List list = resourceMapper.selectResourcesPage(filter, pageParam); + long total = resourceMapper.countResources(filter); + pageParam.setTotalElements(total); + pageParam.setTotalPages((int) Math.ceil((double) total / pageParam.getPageSize())); + resultDomain.success("获取资源分页成功", new PageDomain(pageParam, list)); + return resultDomain; + } + catch (Exception e) { + logger.error("获取资源分页异常: {}", e.getMessage(), e); + resultDomain.fail("获取资源分页失败: " + e.getMessage()); + return resultDomain; + } } @Override - public ResultDomain createResource(TbResource resource) { - // TODO: 实现创建资源 - return null; + public ResultDomain getResourceById(String resourceID) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 查询资源 + TbResource resource = resourceMapper.selectByResourceId(resourceID); + if (resource == null || resource.getDeleted()) { + resultDomain.fail("资源不存在"); + return resultDomain; + } + ResourceVO resourceVO = new ResourceVO(); + resourceVO.setResource(resource); + TbResourceTag filter = new TbResourceTag(); + filter.setResourceID(resourceID); + List tags = resourceTagMapper.selectResourceTags(filter); + if (tags != null && !tags.isEmpty()) { + resourceVO.setTags(tags.stream().map(TagVO::getTag).collect(Collectors.toList())); + } else { + resourceVO.setTags(new ArrayList<>()); + } + + resultDomain.success("获取资源详情成功", resourceVO); + return resultDomain; + } catch (Exception e) { + logger.error("获取资源详情异常: {}", e.getMessage(), e); + resultDomain.fail("获取资源详情失败: " + e.getMessage()); + return resultDomain; + } } @Override - public ResultDomain updateResource(TbResource resource) { - // TODO: 实现更新资源 - return null; + @Transactional(rollbackFor = Exception.class) + public ResultDomain createResource(ResourceVO resourceVO) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (resourceVO == null || !StringUtils.hasText(resourceVO.getResource().getTitle())) { + resultDomain.fail("资源标题不能为空"); + return resultDomain; + } + + // 检查标题是否已存在 + int count = resourceMapper.countByTitle(resourceVO.getResource().getTitle(), null); + if (count > 0) { + resultDomain.fail("资源标题已存在"); + return resultDomain; + } + + // 设置默认值 + if (resourceVO.getResource().getID() == null) { + resourceVO.getResource().setID(IDUtils.generateID()); + } + + resourceVO.getResource().setCreateTime(new Date()); + resourceVO.getResource().setUpdateTime(new Date()); + resourceVO.getResource().setDeleted(false); + + // 设置默认状态和计数 + if (resourceVO.getResource().getStatus() == null) { + resourceVO.getResource().setStatus(0); // 默认草稿状态 + } + if (resourceVO.getResource().getViewCount() == null) { + resourceVO.getResource().setViewCount(0); + } + if (resourceVO.getResource().getLikeCount() == null) { + resourceVO.getResource().setLikeCount(0); + } + if (resourceVO.getResource().getCollectCount() == null) { + resourceVO.getResource().setCollectCount(0); + } + if (resourceVO.getResource().getIsRecommend() == null) { + resourceVO.getResource().setIsRecommend(false); + } + if (resourceVO.getResource().getIsBanner() == null) { + resourceVO.getResource().setIsBanner(false); + } + + // 插入数据库 + int result = resourceMapper.insertResource(resourceVO.getResource()); + // 插入资源标签 + if (resourceVO.getTags() != null && resourceVO.getTags().size() > 0) { + List resourceTagList = new ArrayList<>(); + for (TbTag tag : resourceVO.getTags()) { + TbResourceTag resourceTag = new TbResourceTag(); + resourceTag.setResourceID(resourceVO.getResource().getID()); + resourceTag.setTagID(tag.getID()); + resourceTagList.add(resourceTag); + } + int resourceTagResult = resourceTagMapper.batchInsertResourceTags(resourceTagList); + if (resourceTagResult <= 0) { + result = 0; + } + } + + if (result > 0) { + logger.info("创建资源成功: {}", resourceVO.getResource().getTitle()); + resultDomain.success("创建资源成功", resourceVO); + 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 updateResource(ResourceVO resourceVO) { + ResultDomain resultDomain = new ResultDomain<>(); + TbResource resource = resourceVO.getResource(); + TbSysUser user = LoginUtil.getCurrentUser(); + if (user == null) { + resultDomain.fail("请先登录"); + return resultDomain; + } + resource.setUpdater(user.getID()); + try { + // 参数验证 + if (resource == null || !StringUtils.hasText(resource.getResourceID())) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 检查资源是否存在 + TbResource existing = resourceMapper.selectById(resource.getResourceID()); + if (existing == null || existing.getDeleted()) { + resultDomain.fail("资源不存在"); + return resultDomain; + } + + // 如果修改了标题,检查标题是否已被使用 + if (StringUtils.hasText(resource.getTitle()) && !resource.getTitle().equals(existing.getTitle())) { + int count = resourceMapper.countByTitle(resource.getTitle(), resource.getResourceID()); + if (count > 0) { + resultDomain.fail("资源标题已存在"); + return resultDomain; + } + } + Date now = new Date(); + // 原始tags + TbResourceTag filter = new TbResourceTag(); + filter.setResourceID(resource.getResourceID()); + List originalTagVOs = resourceTagMapper.selectResourceTags(filter); + List originalTags = originalTagVOs.stream().map(TagVO::getResourceTag).collect(Collectors.toList()); + // 当前tags + List currentTags = resourceVO.getTags(); + // 新增tags + List tagsToAdd = currentTags.stream() + .filter(tag -> originalTags.stream().noneMatch(originalTag -> originalTag.getTagID().equals(tag.getID()))) + .collect(Collectors.toList()); + // 删除tags + List tagsToDelete = originalTags.stream() + .filter(originalTag -> currentTags.stream().noneMatch(tag -> tag.getID().equals(originalTag.getTagID()))) + .collect(Collectors.toList()); + + resourceTagMapper.batchDeleteResourceTags(tagsToDelete.stream().map(TbResourceTag::getID).collect(Collectors.toList())); + resourceTagMapper.batchInsertResourceTags(tagsToAdd.stream().map(tag -> { + TbResourceTag resourceTag = new TbResourceTag(); + resourceTag.setResourceID(resource.getResourceID()); + resourceTag.setTagID(tag.getID()); + resourceTag.setID(IDUtils.generateID()); + resourceTag.setCreator(user.getID()); + resourceTag.setCreateTime(now); + return resourceTag; + }).collect(Collectors.toList())); + + // 更新时间 + resource.setUpdateTime(now); + + // 更新数据库 + int result = resourceMapper.updateResource(resource); + if (result > 0) { + logger.info("更新资源成功: {}", resource.getResourceID()); + // 重新查询返回完整数据 + TbResource updated = resourceMapper.selectById(resource.getResourceID()); + ResourceVO updatedResourceVO = new ResourceVO(); + updatedResourceVO.setResource(updated); + updatedResourceVO.setTags(currentTags); + resultDomain.success("更新资源成功", updatedResourceVO); + 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 deleteResource(String resourceID) { - // TODO: 实现删除资源 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 查询资源 + TbResource resource = resourceMapper.selectByResourceId(resourceID); + if (resource == null || resource.getDeleted()) { + resultDomain.fail("资源不存在"); + return resultDomain; + } + + // 物理删除 + int result = resourceMapper.deleteResource(resource); + if (result > 0) { + logger.info("删除资源成功: {}", resourceID); + 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 + @Transactional(rollbackFor = Exception.class) public ResultDomain updateResourceStatus(String resourceID, Integer status) { - // TODO: 实现更新资源状态 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + if (status == null) { + resultDomain.fail("状态不能为空"); + return resultDomain; + } + + // 查询资源 + TbResource resource = resourceMapper.selectByResourceId(resourceID); + if (resource == null || resource.getDeleted()) { + resultDomain.fail("资源不存在"); + return resultDomain; + } + + // 更新状态 + resource.setStatus(status); + resource.setUpdateTime(new Date()); + + int result = resourceMapper.updateResource(resource); + if (result > 0) { + logger.info("更新资源状态成功: {}", resourceID); + // 重新查询返回完整数据 + TbResource updated = resourceMapper.selectById(resource.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 publishResource(String resourceID) { - // TODO: 实现发布资源 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 查询资源 + TbResource resource = resourceMapper.selectByResourceId(resourceID); + if (resource == null || resource.getDeleted()) { + resultDomain.fail("资源不存在"); + return resultDomain; + } + + // 更新状态为已发布 + resource.setStatus(1); + resource.setPublishTime(new Date()); + resource.setUpdateTime(new Date()); + + int result = resourceMapper.updateResource(resource); + if (result > 0) { + logger.info("发布资源成功: {}", resourceID); + // 重新查询返回完整数据 + TbResource updated = resourceMapper.selectById(resource.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 unpublishResource(String resourceID) { - // TODO: 实现下架资源 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 查询资源 + TbResource resource = resourceMapper.selectByResourceId(resourceID); + if (resource == null || resource.getDeleted()) { + resultDomain.fail("资源不存在"); + return resultDomain; + } + + // 更新状态为下架 + resource.setStatus(2); + resource.setUpdateTime(new Date()); + + int result = resourceMapper.updateResource(resource); + if (result > 0) { + logger.info("下架资源成功: {}", resourceID); + // 重新查询返回完整数据 + TbResource updated = resourceMapper.selectById(resource.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 incrementViewCount(String resourceID) { - // TODO: 实现增加浏览次数 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 查询资源 + TbResource resource = resourceMapper.selectByResourceId(resourceID); + if (resource == null || resource.getDeleted()) { + resultDomain.fail("资源不存在"); + return resultDomain; + } + + // 增加浏览次数 + Integer currentCount = resource.getViewCount() != null ? resource.getViewCount() : 0; + resource.setViewCount(currentCount + 1); + resource.setUpdateTime(new Date()); + + int result = resourceMapper.updateResource(resource); + if (result > 0) { + logger.info("增加资源浏览次数成功: {}", resourceID); + // 重新查询返回完整数据 + TbResource updated = resourceMapper.selectById(resource.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 incrementLikeCount(String resourceID) { - // TODO: 实现增加点赞次数 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 查询资源 + TbResource resource = resourceMapper.selectByResourceId(resourceID); + if (resource == null || resource.getDeleted()) { + resultDomain.fail("资源不存在"); + return resultDomain; + } + + // 增加点赞次数 + Integer currentCount = resource.getLikeCount() != null ? resource.getLikeCount() : 0; + resource.setLikeCount(currentCount + 1); + resource.setUpdateTime(new Date()); + + int result = resourceMapper.updateResource(resource); + if (result > 0) { + logger.info("增加资源点赞次数成功: {}", resourceID); + // 重新查询返回完整数据 + TbResource updated = resourceMapper.selectById(resource.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 incrementCollectCount(String resourceID) { - // TODO: 实现增加收藏次数 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 查询资源 + TbResource resource = resourceMapper.selectByResourceId(resourceID); + if (resource == null || resource.getDeleted()) { + resultDomain.fail("资源不存在"); + return resultDomain; + } + + // 增加收藏次数 + Integer currentCount = resource.getCollectCount() != null ? resource.getCollectCount() : 0; + resource.setCollectCount(currentCount + 1); + resource.setUpdateTime(new Date()); + + int result = resourceMapper.updateResource(resource); + if (result > 0) { + logger.info("增加资源收藏次数成功: {}", resourceID); + // 重新查询返回完整数据 + TbResource updated = resourceMapper.selectById(resource.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 setResourceRecommend(String resourceID, Boolean isRecommend) { - // TODO: 实现设置资源推荐 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + if (isRecommend == null) { + resultDomain.fail("推荐状态不能为空"); + return resultDomain; + } + + // 查询资源 + TbResource resource = resourceMapper.selectByResourceId(resourceID); + if (resource == null || resource.getDeleted()) { + resultDomain.fail("资源不存在"); + return resultDomain; + } + + // 更新推荐状态 + resource.setIsRecommend(isRecommend); + resource.setUpdateTime(new Date()); + + int result = resourceMapper.updateResource(resource); + if (result > 0) { + logger.info("设置资源推荐状态成功: {} -> {}", resourceID, isRecommend); + // 重新查询返回完整数据 + TbResource updated = resourceMapper.selectById(resource.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 setResourceBanner(String resourceID, Boolean isBanner) { - // TODO: 实现设置资源轮播 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + if (isBanner == null) { + resultDomain.fail("轮播状态不能为空"); + return resultDomain; + } + + // 查询资源 + TbResource resource = resourceMapper.selectByResourceId(resourceID); + if (resource == null || resource.getDeleted()) { + resultDomain.fail("资源不存在"); + return resultDomain; + } + + // 更新轮播状态 + resource.setIsBanner(isBanner); + resource.setUpdateTime(new Date()); + + int result = resourceMapper.updateResource(resource); + if (result > 0) { + logger.info("设置资源轮播状态成功: {} -> {}", resourceID, isBanner); + // 重新查询返回完整数据 + TbResource updated = resourceMapper.selectById(resource.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 public ResultDomain getRecommendResources(Integer limit) { - // TODO: 实现获取推荐资源列表 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 创建过滤条件,查询推荐资源 + TbResource filter = new TbResource(); + filter.setIsRecommend(true); + filter.setStatus(1); // 只查询已发布的 + + List list = resourceMapper.selectResources(filter); + + // 如果指定了limit,截取列表 + if (limit != null && limit > 0 && list != null && list.size() > limit) { + list = list.subList(0, limit); + } + + resultDomain.success("获取推荐资源列表成功", list); + return resultDomain; + } catch (Exception e) { + logger.error("获取推荐资源列表异常: {}", e.getMessage(), e); + resultDomain.fail("获取推荐资源列表失败: " + e.getMessage()); + return resultDomain; + } } @Override public ResultDomain getBannerResources(Integer limit) { - // TODO: 实现获取轮播资源列表 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 创建过滤条件,查询轮播资源 + TbResource filter = new TbResource(); + filter.setIsBanner(true); + filter.setStatus(1); // 只查询已发布的 + + List list = resourceMapper.selectResources(filter); + + // 如果指定了limit,截取列表 + if (limit != null && limit > 0 && list != null && list.size() > limit) { + list = list.subList(0, limit); + } + + resultDomain.success("获取轮播资源列表成功", list); + return resultDomain; + } catch (Exception e) { + logger.error("获取轮播资源列表异常: {}", e.getMessage(), e); + resultDomain.fail("获取轮播资源列表失败: " + e.getMessage()); + return resultDomain; + } } @Override public ResultDomain searchResources(String keyword, String categoryID, Integer status) { - // TODO: 实现搜索资源 - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(keyword)) { + resultDomain.fail("搜索关键词不能为空"); + return resultDomain; + } + + // 先按关键词搜索 + List list = resourceMapper.searchByKeyword(keyword); + + // 如果指定了分类ID,进行过滤 + if (StringUtils.hasText(categoryID) && list != null) { + list.removeIf(resource -> !categoryID.equals(resource.getCategoryID())); + } + + // 如果指定了状态,进行过滤 + if (status != null && list != null) { + list.removeIf(resource -> !status.equals(resource.getStatus())); + } + + resultDomain.success("搜索资源成功", list); + return resultDomain; + } catch (Exception e) { + logger.error("搜索资源异常: {}", e.getMessage(), e); + resultDomain.fail("搜索资源失败: " + e.getMessage()); + return resultDomain; + } } } diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCTagServiceImpl.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCTagServiceImpl.java index 6ad6c13..f704108 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCTagServiceImpl.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCTagServiceImpl.java @@ -1,14 +1,20 @@ package org.xyzh.news.service.impl; +import java.util.ArrayList; +import java.util.Date; import java.util.List; 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.TbResourceTag; import org.xyzh.common.dto.resource.TbTag; +import org.xyzh.common.utils.IDUtils; +import org.xyzh.news.mapper.ResourceTagMapper; import org.xyzh.news.mapper.TagMapper; import org.xyzh.api.news.tag.TagService; @@ -27,77 +33,431 @@ public class NCTagServiceImpl implements TagService { @Autowired private TagMapper tagMapper; - @Override - public ResultDomain addResourceTag(String resourceID, String tagID) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ResultDomain batchAddResourceTags(String resourceID, List tagIDs) { - // TODO Auto-generated method stub - return null; - } - - @Override - public ResultDomain clearResourceTags(String resourceID) { - // TODO Auto-generated method stub - return null; - } + @Autowired + private ResourceTagMapper resourceTagMapper; + + // ----------------标签管理相关-------------------------------- @Override + @Transactional(rollbackFor = Exception.class) public ResultDomain createTag(TbTag tag) { - // TODO Auto-generated method stub - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (tag == null || !StringUtils.hasText(tag.getName())) { + resultDomain.fail("标签名称不能为空"); + return resultDomain; + } + + // 检查标签名称是否已存在 + int count = tagMapper.countByName(tag.getName(), null); + if (count > 0) { + resultDomain.fail("标签名称已存在"); + return resultDomain; + } + + // 设置默认值 + if (tag.getID() == null) { + tag.setID(IDUtils.generateID()); + } + if (tag.getTagID() == null) { + tag.setTagID(IDUtils.generateID()); + } + + tag.setCreateTime(new Date()); + tag.setUpdateTime(new Date()); + tag.setDeleted(false); + + // 插入数据库 + int result = tagMapper.insertTag(tag); + if (result > 0) { + logger.info("创建标签成功: {}", tag.getName()); + resultDomain.success("创建标签成功", tag); + 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 updateTag(TbTag tag) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (tag == null || !StringUtils.hasText(tag.getID())) { + resultDomain.fail("标签ID不能为空"); + return resultDomain; + } + + // 检查标签是否存在 + TbTag existingTag = tagMapper.selectById(tag.getID()); + if (existingTag == null || existingTag.getDeleted()) { + resultDomain.fail("标签不存在"); + return resultDomain; + } + + // 检查标签名称是否重复(排除自身) + if (StringUtils.hasText(tag.getName())) { + int count = tagMapper.countByName(tag.getName(), tag.getID()); + if (count > 0) { + resultDomain.fail("标签名称已存在"); + return resultDomain; + } + } + + // 更新时间 + tag.setUpdateTime(new Date()); + + // 更新数据库 + int result = tagMapper.updateTag(tag); + if (result > 0) { + logger.info("更新标签成功: {}", tag.getID()); + // 重新查询返回完整数据 + TbTag updated = tagMapper.selectById(tag.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 deleteTag(String tagID) { - // TODO Auto-generated method stub - return null; - } + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(tagID)) { + resultDomain.fail("标签ID不能为空"); + return resultDomain; + } - @Override - public ResultDomain getAllTags() { - // TODO Auto-generated method stub - return null; - } + // 检查标签是否存在 + TbTag tag = tagMapper.selectByTagId(tagID); + if (tag == null || tag.getDeleted()) { + resultDomain.fail("标签不存在"); + return resultDomain; + } - @Override - public ResultDomain getResourceTags(String resourceID) { - // TODO Auto-generated method stub - return null; - } + // 检查是否有关联资源 + List resourceTags = resourceTagMapper.selectByTagId(tagID); + if (resourceTags != null && !resourceTags.isEmpty()) { + resultDomain.fail("该标签下存在关联资源,无法删除"); + return resultDomain; + } - @Override - public ResultDomain getResourcesByTag(String tagID) { - // TODO Auto-generated method stub - return null; + // 物理删除 + int result = tagMapper.deleteTag(tag); + if (result > 0) { + logger.info("删除标签成功: {}", tagID); + 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 getTagById(String tagID) { - // TODO Auto-generated method stub - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + if (!StringUtils.hasText(tagID)) { + resultDomain.fail("标签ID不能为空"); + return resultDomain; + } + + TbTag tag = tagMapper.selectByTagId(tagID); + if (tag == null || tag.getDeleted()) { + resultDomain.fail("标签不存在"); + return resultDomain; + } + + resultDomain.success("查询成功", tag); + return resultDomain; + } catch (Exception e) { + logger.error("查询标签异常: {}", e.getMessage(), e); + resultDomain.fail("查询标签失败: " + e.getMessage()); + return resultDomain; + } } @Override - public ResultDomain removeResourceTag(String resourceID, String tagID) { - // TODO Auto-generated method stub - return null; + public ResultDomain getAllTags() { + ResultDomain resultDomain = new ResultDomain<>(); + try { + List tags = tagMapper.selectTags(new TbTag()); + resultDomain.success("查询成功", tags); + return resultDomain; + } catch (Exception e) { + logger.error("查询标签列表异常: {}", e.getMessage(), e); + resultDomain.fail("查询标签列表失败: " + e.getMessage()); + return resultDomain; + } } @Override public ResultDomain searchTagsByName(String name) { - // TODO Auto-generated method stub - return null; + ResultDomain resultDomain = new ResultDomain<>(); + try { + if (!StringUtils.hasText(name)) { + resultDomain.fail("搜索关键词不能为空"); + return resultDomain; + } + + TbTag filter = new TbTag(); + filter.setName(name); + List tags = tagMapper.selectTags(filter); + + resultDomain.success("查询成功", tags); + return resultDomain; + } catch (Exception e) { + logger.error("搜索标签异常: {}", e.getMessage(), e); + resultDomain.fail("搜索标签失败: " + e.getMessage()); + return resultDomain; + } + } + + // ----------------资源标签关联相关-------------------------------- + + @Override + public ResultDomain getResourceTags(String resourceID) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 查询资源标签关联 + List resourceTags = resourceTagMapper.selectByResourceId(resourceID); + + // 根据标签ID查询标签详情 + List tags = new ArrayList<>(); + for (TbResourceTag resourceTag : resourceTags) { + TbTag tag = tagMapper.selectByTagId(resourceTag.getTagID()); + if (tag != null && !tag.getDeleted()) { + tags.add(tag); + } + } + + resultDomain.success("查询成功", tags); + return resultDomain; + } catch (Exception e) { + logger.error("查询资源标签异常: {}", e.getMessage(), e); + resultDomain.fail("查询资源标签失败: " + e.getMessage()); + return resultDomain; + } } @Override - public ResultDomain updateTag(TbTag tag) { - // TODO Auto-generated method stub - return null; + @Transactional(rollbackFor = Exception.class) + public ResultDomain addResourceTag(String resourceID, String tagID) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID) || !StringUtils.hasText(tagID)) { + resultDomain.fail("资源ID和标签ID不能为空"); + return resultDomain; + } + + // 检查标签是否存在 + TbTag tag = tagMapper.selectByTagId(tagID); + if (tag == null || tag.getDeleted()) { + resultDomain.fail("标签不存在"); + return resultDomain; + } + + // 检查是否已经关联 + int count = resourceTagMapper.countByResourceIdAndTagId(resourceID, tagID, null); + if (count > 0) { + resultDomain.fail("该资源已关联此标签"); + return resultDomain; + } + + // 创建关联 + TbResourceTag resourceTag = new TbResourceTag(); + resourceTag.setID(IDUtils.generateID()); + resourceTag.setResourceID(resourceID); + resourceTag.setTagID(tagID); + resourceTag.setCreateTime(new Date()); + resourceTag.setUpdateTime(new Date()); + resourceTag.setDeleted(false); + + int result = resourceTagMapper.insertResourceTag(resourceTag); + if (result > 0) { + logger.info("添加资源标签成功: resourceID={}, tagID={}", resourceID, tagID); + resultDomain.success("添加标签成功", resourceTag); + 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 batchAddResourceTags(String resourceID, List tagIDs) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID) || tagIDs == null || tagIDs.isEmpty()) { + resultDomain.fail("资源ID和标签ID列表不能为空"); + return resultDomain; + } + + List resourceTags = new ArrayList<>(); + for (String tagID : tagIDs) { + // 检查标签是否存在 + TbTag tag = tagMapper.selectByTagId(tagID); + if (tag == null || tag.getDeleted()) { + continue; + } + + // 检查是否已经关联 + int count = resourceTagMapper.countByResourceIdAndTagId(resourceID, tagID, null); + if (count > 0) { + continue; + } + + // 创建关联 + TbResourceTag resourceTag = new TbResourceTag(); + resourceTag.setID(IDUtils.generateID()); + resourceTag.setResourceID(resourceID); + resourceTag.setTagID(tagID); + resourceTag.setCreateTime(new Date()); + resourceTag.setUpdateTime(new Date()); + resourceTag.setDeleted(false); + + resourceTags.add(resourceTag); + } + + if (resourceTags.isEmpty()) { + resultDomain.fail("没有可添加的标签"); + return resultDomain; + } + + int result = resourceTagMapper.batchInsertResourceTags(resourceTags); + if (result > 0) { + logger.info("批量添加资源标签成功: resourceID={}, count={}", resourceID, result); + resultDomain.success("批量添加标签成功", resourceTags); + 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 removeResourceTag(String resourceID, String tagID) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID) || !StringUtils.hasText(tagID)) { + resultDomain.fail("资源ID和标签ID不能为空"); + return resultDomain; + } + + // 查找关联 + TbResourceTag resourceTag = resourceTagMapper.selectByResourceIdAndTagId(resourceID, tagID); + if (resourceTag == null) { + resultDomain.fail("资源标签关联不存在"); + return resultDomain; + } + + // 物理删除 + int result = resourceTagMapper.deleteResourceTag(resourceTag); + if (result > 0) { + logger.info("移除资源标签成功: resourceID={}, tagID={}", resourceID, tagID); + 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 + @Transactional(rollbackFor = Exception.class) + public ResultDomain clearResourceTags(String resourceID) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + // 参数验证 + if (!StringUtils.hasText(resourceID)) { + resultDomain.fail("资源ID不能为空"); + return resultDomain; + } + + // 删除所有关联 + int result = resourceTagMapper.deleteByResourceId(resourceID); + logger.info("清空资源标签成功: resourceID={}, count={}", resourceID, result); + resultDomain.success("清空标签成功", true); + return resultDomain; + } catch (Exception e) { + logger.error("清空资源标签异常: {}", e.getMessage(), e); + resultDomain.fail("清空标签失败: " + e.getMessage()); + return resultDomain; + } + } + + @Override + public ResultDomain getResourcesByTag(String tagID) { + ResultDomain resultDomain = new ResultDomain<>(); + try { + if (!StringUtils.hasText(tagID)) { + resultDomain.fail("标签ID不能为空"); + return resultDomain; + } + + // 查询标签关联的资源 + List resourceTags = resourceTagMapper.selectByTagId(tagID); + + // 提取资源ID列表 + List resourceIDs = new ArrayList<>(); + for (TbResourceTag resourceTag : resourceTags) { + resourceIDs.add(resourceTag.getResourceID()); + } + + resultDomain.success("查询成功", resourceIDs); + return resultDomain; + } catch (Exception e) { + logger.error("查询标签资源异常: {}", e.getMessage(), e); + resultDomain.fail("查询标签资源失败: " + e.getMessage()); + return resultDomain; + } + } } diff --git a/schoolNewsServ/news/src/main/resources/mapper/BannerMapper.xml b/schoolNewsServ/news/src/main/resources/mapper/BannerMapper.xml index 801c96e..acce3ed 100644 --- a/schoolNewsServ/news/src/main/resources/mapper/BannerMapper.xml +++ b/schoolNewsServ/news/src/main/resources/mapper/BannerMapper.xml @@ -188,7 +188,7 @@ FROM tb_banner ORDER BY order_num ASC, create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/news/src/main/resources/mapper/DataCollectionConfigMapper.xml b/schoolNewsServ/news/src/main/resources/mapper/DataCollectionConfigMapper.xml index e150af9..3884ce2 100644 --- a/schoolNewsServ/news/src/main/resources/mapper/DataCollectionConfigMapper.xml +++ b/schoolNewsServ/news/src/main/resources/mapper/DataCollectionConfigMapper.xml @@ -203,7 +203,7 @@ FROM tb_data_collection_config ORDER BY create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/news/src/main/resources/mapper/DataCollectionLogMapper.xml b/schoolNewsServ/news/src/main/resources/mapper/DataCollectionLogMapper.xml index 8598032..b5926c2 100644 --- a/schoolNewsServ/news/src/main/resources/mapper/DataCollectionLogMapper.xml +++ b/schoolNewsServ/news/src/main/resources/mapper/DataCollectionLogMapper.xml @@ -175,7 +175,7 @@ FROM tb_data_collection_log ORDER BY collect_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/news/src/main/resources/mapper/ResourceCategoryMapper.xml b/schoolNewsServ/news/src/main/resources/mapper/ResourceCategoryMapper.xml index 289607c..1f95602 100644 --- a/schoolNewsServ/news/src/main/resources/mapper/ResourceCategoryMapper.xml +++ b/schoolNewsServ/news/src/main/resources/mapper/ResourceCategoryMapper.xml @@ -181,7 +181,7 @@ FROM tb_resource_category ORDER BY order_num ASC, create_time ASC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/news/src/main/resources/mapper/ResourceMapper.xml b/schoolNewsServ/news/src/main/resources/mapper/ResourceMapper.xml index d7191f5..6af60d8 100644 --- a/schoolNewsServ/news/src/main/resources/mapper/ResourceMapper.xml +++ b/schoolNewsServ/news/src/main/resources/mapper/ResourceMapper.xml @@ -5,6 +5,7 @@ + @@ -30,7 +31,7 @@ - id, title, content, summary, cover_image, category_id, author, source, + id, resource_id, title, content, summary, cover_image, category_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 @@ -75,7 +76,7 @@ SELECT FROM tb_resource - WHERE id = #{resourceId} AND deleted = 0 + WHERE resource_id = #{resourceId} AND deleted = 0 @@ -147,19 +148,19 @@ FROM tb_resource WHERE title = #{title} AND deleted = 0 - AND id != #{excludeId} + AND resource_id != #{excludeId} INSERT INTO tb_resource ( - id, title, content, summary, cover_image, category_id, author, source, + id, resource_id, title, content, summary, cover_image, category_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}, #{title}, #{content}, #{summary}, #{coverImage}, #{categoryID}, #{author}, #{source}, + #{id}, #{resourceID}, #{title}, #{content}, #{summary}, #{coverImage}, #{categoryID}, #{author}, #{source}, #{sourceUrl}, #{viewCount}, #{likeCount}, #{collectCount}, #{status}, #{isRecommend}, #{isBanner}, #{publishTime}, #{creator}, #{updater}, #{createTime}, #{updateTime}, #{deleteTime}, #{deleted} @@ -228,26 +229,26 @@ deleted = #{deleted}, - WHERE id = #{id} + WHERE resource_id = #{resourceID} DELETE FROM tb_resource - WHERE id = #{id} + WHERE resource_id = #{resourceID} INSERT INTO tb_resource ( - id, title, content, summary, cover_image, category_id, author, source, + id, resource_id, title, content, summary, cover_image, category_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 ( - #{item.id}, #{item.title}, #{item.content}, #{item.summary}, #{item.coverImage}, + #{item.id}, #{item.resourceID}, #{item.title}, #{item.content}, #{item.summary}, #{item.coverImage}, #{item.categoryID}, #{item.author}, #{item.source}, #{item.sourceUrl}, #{item.viewCount}, #{item.likeCount}, #{item.collectCount}, #{item.status}, #{item.isRecommend}, #{item.isBanner}, #{item.publishTime}, #{item.creator}, @@ -259,9 +260,9 @@ DELETE FROM tb_resource - WHERE id IN + WHERE resource_id IN - #{id} + #{resourceID} @@ -270,9 +271,29 @@ SELECT FROM tb_resource - + + deleted = 0 + + AND title LIKE CONCAT('%', #{filter.title}, '%') + + + AND category_id = #{filter.categoryID} + + + AND author LIKE CONCAT('%', #{filter.author}, '%') + + + AND status = #{filter.status} + + + AND is_recommend = #{filter.isRecommend} + + + AND is_banner = #{filter.isBanner} + + ORDER BY publish_time DESC, create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/news/src/main/resources/mapper/ResourceRecommendMapper.xml b/schoolNewsServ/news/src/main/resources/mapper/ResourceRecommendMapper.xml index e7047da..18e5be3 100644 --- a/schoolNewsServ/news/src/main/resources/mapper/ResourceRecommendMapper.xml +++ b/schoolNewsServ/news/src/main/resources/mapper/ResourceRecommendMapper.xml @@ -179,7 +179,7 @@ FROM tb_resource_recommend ORDER BY order_num ASC, create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/news/src/main/resources/mapper/ResourceTagMapper.xml b/schoolNewsServ/news/src/main/resources/mapper/ResourceTagMapper.xml index f5c550f..b1b99c6 100644 --- a/schoolNewsServ/news/src/main/resources/mapper/ResourceTagMapper.xml +++ b/schoolNewsServ/news/src/main/resources/mapper/ResourceTagMapper.xml @@ -11,6 +11,16 @@ + + + + + + + + + + id, resource_id, tag_id, creator, create_time @@ -29,12 +39,25 @@ - SELECT - - FROM tb_resource_tag - - ORDER BY create_time DESC + rt.id, rt.resource_id, rt.tag_id, t.name as tag_name, t.color as tag_color, rt.creator, rt.create_time + FROM tb_resource_tag rt + LEFT JOIN tb_tag t ON rt.tag_id = t.id + WHERE 1=1 + + AND rt.resource_id = #{resourceID} + + + AND rt.tag_id = #{tagID} + + + AND rt.creator = #{creator} + + + AND rt.create_time = #{createTime} + + ORDER BY rt.create_time DESC @@ -156,7 +179,7 @@ FROM tb_resource_tag ORDER BY create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/news/src/main/resources/mapper/TagMapper.xml b/schoolNewsServ/news/src/main/resources/mapper/TagMapper.xml index a2605c2..569423d 100644 --- a/schoolNewsServ/news/src/main/resources/mapper/TagMapper.xml +++ b/schoolNewsServ/news/src/main/resources/mapper/TagMapper.xml @@ -184,7 +184,7 @@ FROM tb_tag ORDER BY create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/study/src/main/resources/mapper/CourseChapterMapper.xml b/schoolNewsServ/study/src/main/resources/mapper/CourseChapterMapper.xml index 08dd136..4a383de 100644 --- a/schoolNewsServ/study/src/main/resources/mapper/CourseChapterMapper.xml +++ b/schoolNewsServ/study/src/main/resources/mapper/CourseChapterMapper.xml @@ -192,7 +192,7 @@ FROM tb_course_chapter ORDER BY order_num ASC, create_time ASC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/study/src/main/resources/mapper/CourseMapper.xml b/schoolNewsServ/study/src/main/resources/mapper/CourseMapper.xml index b45155f..f32b59c 100644 --- a/schoolNewsServ/study/src/main/resources/mapper/CourseMapper.xml +++ b/schoolNewsServ/study/src/main/resources/mapper/CourseMapper.xml @@ -254,7 +254,7 @@ FROM tb_course ORDER BY order_num ASC, create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/study/src/main/resources/mapper/CourseTagMapper.xml b/schoolNewsServ/study/src/main/resources/mapper/CourseTagMapper.xml index 36ea40a..7c69902 100644 --- a/schoolNewsServ/study/src/main/resources/mapper/CourseTagMapper.xml +++ b/schoolNewsServ/study/src/main/resources/mapper/CourseTagMapper.xml @@ -156,7 +156,7 @@ FROM tb_course_tag ORDER BY create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/study/src/main/resources/mapper/LearningRecordMapper.xml b/schoolNewsServ/study/src/main/resources/mapper/LearningRecordMapper.xml index a0e2737..3dbf439 100644 --- a/schoolNewsServ/study/src/main/resources/mapper/LearningRecordMapper.xml +++ b/schoolNewsServ/study/src/main/resources/mapper/LearningRecordMapper.xml @@ -196,7 +196,7 @@ FROM tb_learning_record ORDER BY last_learn_time DESC, create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/study/src/main/resources/mapper/LearningStatisticsMapper.xml b/schoolNewsServ/study/src/main/resources/mapper/LearningStatisticsMapper.xml index 1ddeb79..1d2b81f 100644 --- a/schoolNewsServ/study/src/main/resources/mapper/LearningStatisticsMapper.xml +++ b/schoolNewsServ/study/src/main/resources/mapper/LearningStatisticsMapper.xml @@ -172,7 +172,7 @@ FROM tb_learning_statistics ORDER BY stat_date DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/study/src/main/resources/mapper/LearningTaskMapper.xml b/schoolNewsServ/study/src/main/resources/mapper/LearningTaskMapper.xml index 75f16ed..399e347 100644 --- a/schoolNewsServ/study/src/main/resources/mapper/LearningTaskMapper.xml +++ b/schoolNewsServ/study/src/main/resources/mapper/LearningTaskMapper.xml @@ -207,7 +207,7 @@ FROM tb_learning_task ORDER BY create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/study/src/main/resources/mapper/TaskCourseMapper.xml b/schoolNewsServ/study/src/main/resources/mapper/TaskCourseMapper.xml index 88d8111..3792249 100644 --- a/schoolNewsServ/study/src/main/resources/mapper/TaskCourseMapper.xml +++ b/schoolNewsServ/study/src/main/resources/mapper/TaskCourseMapper.xml @@ -168,7 +168,7 @@ FROM tb_task_course ORDER BY order_num ASC, create_time ASC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/study/src/main/resources/mapper/TaskResourceMapper.xml b/schoolNewsServ/study/src/main/resources/mapper/TaskResourceMapper.xml index 32b71e7..62d2ae6 100644 --- a/schoolNewsServ/study/src/main/resources/mapper/TaskResourceMapper.xml +++ b/schoolNewsServ/study/src/main/resources/mapper/TaskResourceMapper.xml @@ -168,7 +168,7 @@ FROM tb_task_resource ORDER BY order_num ASC, create_time ASC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/study/src/main/resources/mapper/TaskUserMapper.xml b/schoolNewsServ/study/src/main/resources/mapper/TaskUserMapper.xml index e10d048..170123d 100644 --- a/schoolNewsServ/study/src/main/resources/mapper/TaskUserMapper.xml +++ b/schoolNewsServ/study/src/main/resources/mapper/TaskUserMapper.xml @@ -205,7 +205,7 @@ FROM tb_task_user ORDER BY create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/system/src/main/java/org/xyzh/system/mapper/UserMapper.java b/schoolNewsServ/system/src/main/java/org/xyzh/system/mapper/UserMapper.java index 6629b89..4962746 100644 --- a/schoolNewsServ/system/src/main/java/org/xyzh/system/mapper/UserMapper.java +++ b/schoolNewsServ/system/src/main/java/org/xyzh/system/mapper/UserMapper.java @@ -125,6 +125,15 @@ public interface UserMapper extends BaseMapper { */ int updateUserInfo(@Param("userInfo") TbSysUserInfo userInfo); + /** + * @description 获取用户完整部门路径 + * @param userId 用户ID + * @return String 部门路径(如:公司总部/技术部/前端组) + * @author yslg + * @since 2025-10-18 + */ + String getUserDeptPath(@Param("userId") String userId); + /** * @description 获取用户信息总览 * @param userId 用户ID diff --git a/schoolNewsServ/system/src/main/java/org/xyzh/system/user/service/impl/SysUserServiceImpl.java b/schoolNewsServ/system/src/main/java/org/xyzh/system/user/service/impl/SysUserServiceImpl.java index 26a8873..65ac61f 100644 --- a/schoolNewsServ/system/src/main/java/org/xyzh/system/user/service/impl/SysUserServiceImpl.java +++ b/schoolNewsServ/system/src/main/java/org/xyzh/system/user/service/impl/SysUserServiceImpl.java @@ -719,8 +719,9 @@ public class SysUserServiceImpl implements SysUserService { ResultDomain resultDomain = new ResultDomain<>(); try { logger.info("开始获取用户信息总览:{}", userId); + String deptPath = userMapper.getUserDeptPath(userId); UserVO userVO = userMapper.selectUserInfoTotal(userId); - + userVO.setDeptName(deptPath); resultDomain.success("获取用户信息总览成功", userVO); return resultDomain; } catch (Exception e) { diff --git a/schoolNewsServ/system/src/main/resources/mapper/ModuleMapper.xml b/schoolNewsServ/system/src/main/resources/mapper/ModuleMapper.xml index 62fc1c0..3d4ca51 100644 --- a/schoolNewsServ/system/src/main/resources/mapper/ModuleMapper.xml +++ b/schoolNewsServ/system/src/main/resources/mapper/ModuleMapper.xml @@ -180,7 +180,7 @@ FROM tb_sys_module ORDER BY order_num ASC, create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/system/src/main/resources/mapper/UserMapper.xml b/schoolNewsServ/system/src/main/resources/mapper/UserMapper.xml index c452200..fd4cba3 100644 --- a/schoolNewsServ/system/src/main/resources/mapper/UserMapper.xml +++ b/schoolNewsServ/system/src/main/resources/mapper/UserMapper.xml @@ -245,9 +245,69 @@ WHERE user_id = #{userInfo.userID} AND deleted = 0 - + + - + WITH RECURSIVE dept_hierarchy AS ( + -- 基础查询:获取用户直接所属的部门 + SELECT + tsd.dept_id, + tsd.name, + tsd.parent_id, + tsd.name as dept_path, + 1 as level + FROM tb_sys_user_info tsui + INNER JOIN tb_sys_user_dept_role tsudr ON tsui.user_id = tsudr.user_id + INNER JOIN tb_sys_dept tsd ON tsudr.dept_id = tsd.dept_id + WHERE tsui.user_id = #{userId} AND tsui.deleted = 0 + + UNION ALL + + -- 递归查询:向上查找父部门 + SELECT + p.dept_id, + p.name, + p.parent_id, + CONCAT(p.name, '/', dh.dept_path) as dept_path, + dh.level + 1 as level + FROM tb_sys_dept p + INNER JOIN dept_hierarchy dh ON p.dept_id = dh.parent_id + WHERE p.deleted = 0 + ) SELECT tus.id as user_id, tus.username, @@ -255,7 +315,7 @@ tus.email, tsui.avatar, tsui.gender, - tsd.name as dept_name, + dh.dept_path as dept_name, tsr.name as role_name, tsui.level, tsui.id_card, @@ -263,8 +323,10 @@ FROM tb_sys_user_info tsui INNER JOIN tb_sys_user tus ON tsui.user_id = tus.id INNER JOIN tb_sys_user_dept_role tsudr ON tsui.user_id = tsudr.user_id - INNER JOIN tb_sys_dept tsd ON tsudr.dept_id = tsd.dept_id + INNER JOIN dept_hierarchy dh ON tsudr.dept_id = dh.dept_id INNER JOIN tb_sys_role tsr ON tsudr.role_id = tsr.role_id - WHERE tsui.user_id = #{userId} AND tsui.deleted = 0 + WHERE tsui.user_id = #{userId} + AND tsui.deleted = 0 + AND dh.parent_id IS NULL -- 只取最顶层的部门路径 diff --git a/schoolNewsServ/usercenter/src/main/resources/mapper/AchievementMapper.xml b/schoolNewsServ/usercenter/src/main/resources/mapper/AchievementMapper.xml index 1a3198f..a2f3a74 100644 --- a/schoolNewsServ/usercenter/src/main/resources/mapper/AchievementMapper.xml +++ b/schoolNewsServ/usercenter/src/main/resources/mapper/AchievementMapper.xml @@ -450,7 +450,7 @@ FROM tb_achievement ORDER BY order_num ASC, create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/usercenter/src/main/resources/mapper/PointsRecordMapper.xml b/schoolNewsServ/usercenter/src/main/resources/mapper/PointsRecordMapper.xml index 8b8d823..6f2b7e3 100644 --- a/schoolNewsServ/usercenter/src/main/resources/mapper/PointsRecordMapper.xml +++ b/schoolNewsServ/usercenter/src/main/resources/mapper/PointsRecordMapper.xml @@ -327,7 +327,7 @@ FROM tb_points_record ORDER BY create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/usercenter/src/main/resources/mapper/UserAchievementMapper.xml b/schoolNewsServ/usercenter/src/main/resources/mapper/UserAchievementMapper.xml index 3a10153..80f13fe 100644 --- a/schoolNewsServ/usercenter/src/main/resources/mapper/UserAchievementMapper.xml +++ b/schoolNewsServ/usercenter/src/main/resources/mapper/UserAchievementMapper.xml @@ -278,7 +278,7 @@ FROM tb_user_achievement ORDER BY obtain_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/usercenter/src/main/resources/mapper/UserBrowseRecordMapper.xml b/schoolNewsServ/usercenter/src/main/resources/mapper/UserBrowseRecordMapper.xml index 4546037..620295a 100644 --- a/schoolNewsServ/usercenter/src/main/resources/mapper/UserBrowseRecordMapper.xml +++ b/schoolNewsServ/usercenter/src/main/resources/mapper/UserBrowseRecordMapper.xml @@ -307,7 +307,7 @@ FROM tb_user_browse_record ORDER BY browse_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/usercenter/src/main/resources/mapper/UserCollectionMapper.xml b/schoolNewsServ/usercenter/src/main/resources/mapper/UserCollectionMapper.xml index e644c54..45ca23d 100644 --- a/schoolNewsServ/usercenter/src/main/resources/mapper/UserCollectionMapper.xml +++ b/schoolNewsServ/usercenter/src/main/resources/mapper/UserCollectionMapper.xml @@ -282,7 +282,7 @@ FROM tb_user_collection ORDER BY create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset} diff --git a/schoolNewsServ/usercenter/src/main/resources/mapper/UserPointsMapper.xml b/schoolNewsServ/usercenter/src/main/resources/mapper/UserPointsMapper.xml index 903db5b..117e87f 100644 --- a/schoolNewsServ/usercenter/src/main/resources/mapper/UserPointsMapper.xml +++ b/schoolNewsServ/usercenter/src/main/resources/mapper/UserPointsMapper.xml @@ -156,7 +156,7 @@ FROM tb_user_points ORDER BY create_time DESC - LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} + LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}