serv-资源修改

This commit is contained in:
2025-10-20 15:08:20 +08:00
parent 2f1835bdbf
commit 16824537d1
50 changed files with 2657 additions and 353 deletions

View File

@@ -7,7 +7,8 @@ HELP.md
.mvn/wrapper/maven-wrapper.jar .mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/ !**/src/main/**/target/
!**/src/test/**/target/ !**/src/test/**/target/
!**/upload/** !**/uploads/**
admin/uploads/**
### Logs ### ### Logs ###
**/logs/ **/logs/

View File

@@ -13,7 +13,7 @@ spring:
# 数据源配置 # 数据源配置
datasource: datasource:
driver-class-name: com.mysql.cj.jdbc.Driver 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 username: root
password: 123456 password: 123456
hikari: hikari:

View File

@@ -1,7 +0,0 @@
package org.xyzh;
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
}
}

View File

@@ -31,6 +31,23 @@ public interface ResourceRecommendService {
*/ */
ResultDomain<TbResourceRecommend> addRecommend(TbResourceRecommend recommend); ResultDomain<TbResourceRecommend> addRecommend(TbResourceRecommend recommend);
/**
* @description 更新推荐资源
* @param recommend 推荐信息
* @return ResultDomain<TbResourceRecommend> 更新结果
* @author yslg
* @since 2025-10-15
*/
ResultDomain<TbResourceRecommend> updateRecommend(TbResourceRecommend recommend);
/**
* @description 删除推荐资源
* @param resourceID 资源ID
* @return ResultDomain<Boolean> 删除结果
* @author yslg
* @since 2025-10-15
*/
ResultDomain<Boolean> deleteRecommend(String resourceID);
/** /**
* @description 移除推荐资源 * @description 移除推荐资源
* @param resourceID 资源ID * @param resourceID 资源ID
@@ -90,10 +107,10 @@ public interface ResourceRecommendService {
/** /**
* @description 获取推荐资源详情 * @description 获取推荐资源详情
* @param resourceID 资源ID * @param recommendID 推荐ID
* @return ResultDomain<TbResourceRecommend> 推荐详情 * @return ResultDomain<TbResourceRecommend> 推荐详情
* @author yslg * @author yslg
* @since 2025-10-15 * @since 2025-10-15
*/ */
ResultDomain<TbResourceRecommend> getRecommendDetail(String resourceID); ResultDomain<TbResourceRecommend> getRecommendDetail(String recommendID);
} }

View File

@@ -1,7 +1,9 @@
package org.xyzh.api.news.resource; package org.xyzh.api.news.resource;
import org.xyzh.common.core.domain.ResultDomain; 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.dto.resource.TbResource;
import org.xyzh.common.vo.ResourceVO;
import java.util.List; import java.util.List;
@@ -23,6 +25,15 @@ public interface ResourceService {
*/ */
ResultDomain<TbResource> getResourceList(TbResource filter); ResultDomain<TbResource> getResourceList(TbResource filter);
/**
* @description 获取资源分页
* @param filter 过滤条件
* @return ResultDomain<TbResource> 资源分页
* @author yslg
* @since 2025-10-15
*/
ResultDomain<TbResource> getResourcePage(TbResource filter, PageParam pageParam);
/** /**
* @description 根据ID获取资源详情 * @description 根据ID获取资源详情
* @param resourceID 资源ID * @param resourceID 资源ID
@@ -30,7 +41,7 @@ public interface ResourceService {
* @author yslg * @author yslg
* @since 2025-10-15 * @since 2025-10-15
*/ */
ResultDomain<TbResource> getResourceById(String resourceID); ResultDomain<ResourceVO> getResourceById(String resourceID);
/** /**
* @description 创建资源 * @description 创建资源
@@ -39,7 +50,7 @@ public interface ResourceService {
* @author yslg * @author yslg
* @since 2025-10-15 * @since 2025-10-15
*/ */
ResultDomain<TbResource> createResource(TbResource resource); ResultDomain<ResourceVO> createResource(ResourceVO resource);
/** /**
* @description 更新资源 * @description 更新资源
@@ -48,7 +59,7 @@ public interface ResourceService {
* @author yslg * @author yslg
* @since 2025-10-15 * @since 2025-10-15
*/ */
ResultDomain<TbResource> updateResource(TbResource resource); ResultDomain<ResourceVO> updateResource(ResourceVO resource);
/** /**
* @description 删除资源 * @description 删除资源

View File

@@ -40,16 +40,25 @@ public class PageParam implements Serializable {
*/ */
private long totalElements; private long totalElements;
/**
* @description 偏移量
* @author yslg
* @since 2025-10-20
*/
private long offset;
public PageParam() { public PageParam() {
this.pageNumber = 1; this.pageNumber = 1;
this.pageSize = 10; this.pageSize = 10;
this.totalPages = 0; this.totalPages = 0;
this.totalElements = 0; this.totalElements = 0;
this.offset = 0;
} }
public PageParam(int pageNumber, int pageSize) { public PageParam(int pageNumber, int pageSize) {
this.pageNumber = pageNumber; this.pageNumber = pageNumber;
this.pageSize = pageSize; this.pageSize = pageSize;
this.offset = (pageNumber - 1) * pageSize;
} }
public PageParam(int pageNumber, int pageSize, int totalPages, long totalElements) { public PageParam(int pageNumber, int pageSize, int totalPages, long totalElements) {
@@ -57,6 +66,7 @@ public class PageParam implements Serializable {
this.pageSize = pageSize; this.pageSize = pageSize;
this.totalPages = totalPages; this.totalPages = totalPages;
this.totalElements = totalElements; this.totalElements = totalElements;
this.offset = (pageNumber - 1) * pageSize;
} }
/** /**
* @description 设置当前页码 * @description 设置当前页码
@@ -147,5 +157,24 @@ public class PageParam implements Serializable {
return totalElements; 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;
}
} }

View File

@@ -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<T> {
/**
* 过滤条件
*/
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;
}
}

View File

@@ -14,6 +14,11 @@ public class TbResource extends BaseDTO {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/**
* @description 资源ID
*/
private String resourceID;
/** /**
* @description 资源标题 * @description 资源标题
*/ */
@@ -99,6 +104,14 @@ public class TbResource extends BaseDTO {
*/ */
private String updater; private String updater;
public String getResourceID() {
return resourceID;
}
public void setResourceID(String resourceID) {
this.resourceID = resourceID;
}
public String getTitle() { public String getTitle() {
return title; return title;
} }
@@ -239,6 +252,7 @@ public class TbResource extends BaseDTO {
public String toString() { public String toString() {
return "TbResource{" + return "TbResource{" +
"id=" + getID() + "id=" + getID() +
", resourceID='" + resourceID + '\'' +
", title='" + title + '\'' + ", title='" + title + '\'' +
", categoryID='" + categoryID + '\'' + ", categoryID='" + categoryID + '\'' +
", author='" + author + '\'' + ", author='" + author + '\'' +

View File

@@ -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<TbTag> 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<TbTag> getTags() {
return tags;
}
public void setTags(List<TbTag> tags) {
this.tags = tags;
}
}

View File

@@ -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;
}
}

View File

@@ -24,6 +24,11 @@
<artifactId>api-news</artifactId> <artifactId>api-news</artifactId>
<version>${school-news.version}</version> <version>${school-news.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.xyzh</groupId>
<artifactId>system</artifactId>
<version>${school-news.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.xyzh</groupId> <groupId>org.xyzh</groupId>
<artifactId>common-all</artifactId> <artifactId>common-all</artifactId>

View File

@@ -16,7 +16,7 @@ import org.xyzh.common.dto.resource.TbBanner;
* @since 2025-10-15 * @since 2025-10-15
*/ */
@RestController @RestController
@RequestMapping("/news/banner") @RequestMapping("/news/banners")
public class BannerController { public class BannerController {
private static final Logger logger = LoggerFactory.getLogger(BannerController.class); private static final Logger logger = LoggerFactory.getLogger(BannerController.class);
@@ -27,15 +27,14 @@ public class BannerController {
* 获取横幅列表 * 获取横幅列表
*/ */
@GetMapping("/list") @GetMapping("/list")
public ResultDomain<TbBanner> getBannerList(TbBanner filter) { public ResultDomain<TbBanner> getBannerList() {
return null; return bannerService.getBannerList(null);
// return bannerService.getBannerList(filter);
} }
/** /**
* 根据ID获取横幅详情 * 根据ID获取横幅详情
*/ */
@GetMapping("/{bannerID}") @GetMapping("/banner/{bannerID}")
public ResultDomain<TbBanner> getBannerById(@PathVariable String bannerID) { public ResultDomain<TbBanner> getBannerById(@PathVariable String bannerID) {
return bannerService.getBannerById(bannerID); return bannerService.getBannerById(bannerID);
} }
@@ -43,7 +42,7 @@ public class BannerController {
/** /**
* 创建横幅 * 创建横幅
*/ */
@PostMapping("/create") @PostMapping("/banner")
public ResultDomain<TbBanner> createBanner(@RequestBody TbBanner banner) { public ResultDomain<TbBanner> createBanner(@RequestBody TbBanner banner) {
return bannerService.createBanner(banner); return bannerService.createBanner(banner);
} }
@@ -51,7 +50,7 @@ public class BannerController {
/** /**
* 更新横幅 * 更新横幅
*/ */
@PutMapping("/update") @PutMapping("/banner")
public ResultDomain<TbBanner> updateBanner(@RequestBody TbBanner banner) { public ResultDomain<TbBanner> updateBanner(@RequestBody TbBanner banner) {
return bannerService.updateBanner(banner); return bannerService.updateBanner(banner);
} }
@@ -59,7 +58,7 @@ public class BannerController {
/** /**
* 删除横幅 * 删除横幅
*/ */
@DeleteMapping("/{bannerID}") @DeleteMapping("/banner/{bannerID}")
public ResultDomain<Boolean> deleteBanner(@PathVariable String bannerID) { public ResultDomain<Boolean> deleteBanner(@PathVariable String bannerID) {
return bannerService.deleteBanner(bannerID); return bannerService.deleteBanner(bannerID);
} }
@@ -67,7 +66,7 @@ public class BannerController {
/** /**
* 更新横幅状态 * 更新横幅状态
*/ */
@PutMapping("/{bannerID}/status") @PutMapping("/banner/{bannerID}/status")
public ResultDomain<TbBanner> updateBannerStatus( public ResultDomain<TbBanner> updateBannerStatus(
@PathVariable String bannerID, @PathVariable String bannerID,
@RequestParam Integer status) { @RequestParam Integer status) {
@@ -77,7 +76,7 @@ public class BannerController {
/** /**
* 更新横幅排序 * 更新横幅排序
*/ */
@PutMapping("/{bannerID}/order") @PutMapping("/banner/{bannerID}/order")
public ResultDomain<TbBanner> updateBannerOrder( public ResultDomain<TbBanner> updateBannerOrder(
@PathVariable String bannerID, @PathVariable String bannerID,
@RequestParam Integer orderNum) { @RequestParam Integer orderNum) {

View File

@@ -16,7 +16,7 @@ import org.xyzh.common.dto.resource.TbResourceCategory;
* @since 2025-10-15 * @since 2025-10-15
*/ */
@RestController @RestController
@RequestMapping("/news/category") @RequestMapping("/news/categorys")
public class ResourceCategoryController { public class ResourceCategoryController {
private static final Logger logger = LoggerFactory.getLogger(ResourceCategoryController.class); private static final Logger logger = LoggerFactory.getLogger(ResourceCategoryController.class);
@@ -27,15 +27,14 @@ public class ResourceCategoryController {
* 获取分类列表 * 获取分类列表
*/ */
@GetMapping("/list") @GetMapping("/list")
public ResultDomain<TbResourceCategory> getCategoryList(TbResourceCategory filter) { public ResultDomain<TbResourceCategory> getCategoryList() {
return null; return resourceCategoryService.getAllCategories();
// return resourceCategoryService.getCategoryList(filter);
} }
/** /**
* 根据ID获取分类详情 * 根据ID获取分类详情
*/ */
@GetMapping("/{categoryID}") @GetMapping("/category/{categoryID}")
public ResultDomain<TbResourceCategory> getCategoryById(@PathVariable String categoryID) { public ResultDomain<TbResourceCategory> getCategoryById(@PathVariable String categoryID) {
return resourceCategoryService.getCategoryById(categoryID); return resourceCategoryService.getCategoryById(categoryID);
} }
@@ -43,7 +42,7 @@ public class ResourceCategoryController {
/** /**
* 创建分类 * 创建分类
*/ */
@PostMapping("/create") @PostMapping("/category")
public ResultDomain<TbResourceCategory> createCategory(@RequestBody TbResourceCategory category) { public ResultDomain<TbResourceCategory> createCategory(@RequestBody TbResourceCategory category) {
return resourceCategoryService.createCategory(category); return resourceCategoryService.createCategory(category);
} }
@@ -51,7 +50,7 @@ public class ResourceCategoryController {
/** /**
* 更新分类 * 更新分类
*/ */
@PutMapping("/update") @PutMapping("/category")
public ResultDomain<TbResourceCategory> updateCategory(@RequestBody TbResourceCategory category) { public ResultDomain<TbResourceCategory> updateCategory(@RequestBody TbResourceCategory category) {
return resourceCategoryService.updateCategory(category); return resourceCategoryService.updateCategory(category);
} }
@@ -59,7 +58,7 @@ public class ResourceCategoryController {
/** /**
* 删除分类 * 删除分类
*/ */
@DeleteMapping("/{categoryID}") @DeleteMapping("/category/{categoryID}")
public ResultDomain<Boolean> deleteCategory(@PathVariable String categoryID) { public ResultDomain<Boolean> deleteCategory(@PathVariable String categoryID) {
return resourceCategoryService.deleteCategory(categoryID); return resourceCategoryService.deleteCategory(categoryID);
} }
@@ -67,7 +66,7 @@ public class ResourceCategoryController {
/** /**
* 更新分类状态 * 更新分类状态
*/ */
@PutMapping("/{categoryID}/status") @PutMapping("/category/{categoryID}/status")
public ResultDomain<TbResourceCategory> updateCategoryStatus(@PathVariable String categoryID, @RequestParam Integer status) { public ResultDomain<TbResourceCategory> updateCategoryStatus(@PathVariable String categoryID, @RequestParam Integer status) {
return null; return null;
// return resourceCategoryService.updateCategoryStatus(categoryID, status); // return resourceCategoryService.updateCategoryStatus(categoryID, status);
@@ -84,9 +83,8 @@ public class ResourceCategoryController {
/** /**
* 获取子分类 * 获取子分类
*/ */
@GetMapping("/{parentID}/children") @GetMapping("/category/{parentID}/children")
public ResultDomain<TbResourceCategory> getChildCategories(@PathVariable String parentID) { public ResultDomain<TbResourceCategory> getChildCategories(@PathVariable String parentID) {
return null; return resourceCategoryService.getCategoriesByParent(parentID);
// return resourceCategoryService.getChildCategories(parentID);
} }
} }

View File

@@ -1,13 +1,21 @@
package org.xyzh.news.controller; package org.xyzh.news.controller;
import java.util.Date;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.xyzh.api.news.resource.ResourceService; import org.xyzh.api.news.resource.ResourceService;
import org.xyzh.common.core.domain.ResultDomain; 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.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 资源控制器 * @description 资源控制器
* @filename ResourceController.java * @filename ResourceController.java
@@ -16,7 +24,7 @@ import org.xyzh.common.dto.resource.TbResource;
* @since 2025-10-15 * @since 2025-10-15
*/ */
@RestController @RestController
@RequestMapping("/news/resource") @RequestMapping("/news/resources")
public class ResourceController { public class ResourceController {
private static final Logger logger = LoggerFactory.getLogger(ResourceController.class); private static final Logger logger = LoggerFactory.getLogger(ResourceController.class);
@@ -27,109 +35,130 @@ public class ResourceController {
* 获取资源列表 * 获取资源列表
*/ */
@GetMapping("/list") @GetMapping("/list")
public ResultDomain<TbResource> getResourceList(TbResource filter) { public ResultDomain<TbResource> getResourceList(@RequestParam("filter") TbResource filter) {
return resourceService.getResourceList(filter); return resourceService.getResourceList(filter);
} }
/**
* 获取资源分页
*/
@PostMapping("/page")
public ResultDomain<TbResource> getResourcePage(@RequestBody PageRequest<TbResource> request) {
TbResource filter = request.getFilter();
PageParam pageParam = request.getPageParam();
return resourceService.getResourcePage(filter, pageParam);
}
/** /**
* 根据ID获取资源详情 * 根据ID获取资源详情
*/ */
@GetMapping("/{resourceID}") @GetMapping("/resource/{resourceID}")
public ResultDomain<TbResource> getResourceById(@PathVariable String resourceID) { public ResultDomain<ResourceVO> getResourceById(@PathVariable("resourceID") String resourceID) {
return resourceService.getResourceById(resourceID); return resourceService.getResourceById(resourceID);
} }
/** /**
* 创建资源 * 创建资源
*/ */
@PostMapping("/create") @PostMapping("/resource")
public ResultDomain<TbResource> createResource(@RequestBody TbResource resource) { public ResultDomain<ResourceVO> createResource(@RequestBody ResourceVO resourceVO) {
return resourceService.createResource(resource); TbSysUser user = LoginUtil.getCurrentUser();
if (user == null) {
ResultDomain<ResourceVO> result = new ResultDomain<ResourceVO>();
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") @PutMapping("/resource")
public ResultDomain<TbResource> updateResource(@RequestBody TbResource resource) { public ResultDomain<ResourceVO> updateResource(@RequestBody ResourceVO resource) {
return resourceService.updateResource(resource); return resourceService.updateResource(resource);
} }
/** /**
* 删除资源 * 删除资源
*/ */
@DeleteMapping("/{resourceID}") @DeleteMapping("/resource/{resourceID}")
public ResultDomain<Boolean> deleteResource(@PathVariable String resourceID) { public ResultDomain<Boolean> deleteResource(@PathVariable("resourceID") String resourceID) {
return resourceService.deleteResource(resourceID); return resourceService.deleteResource(resourceID);
} }
/** /**
* 更新资源状态 * 更新资源状态
*/ */
@PutMapping("/{resourceID}/status") @PutMapping("/resource/{resourceID}/status")
public ResultDomain<TbResource> updateResourceStatus( public ResultDomain<TbResource> updateResourceStatus(
@PathVariable String resourceID, @PathVariable("resourceID") String resourceID,
@RequestParam Integer status) { @RequestParam("status") Integer status) {
return resourceService.updateResourceStatus(resourceID, status); return resourceService.updateResourceStatus(resourceID, status);
} }
/** /**
* 发布资源 * 发布资源
*/ */
@PostMapping("/{resourceID}/publish") @PostMapping("/resource/{resourceID}/publish")
public ResultDomain<TbResource> publishResource(@PathVariable String resourceID) { public ResultDomain<TbResource> publishResource(@PathVariable("resourceID") String resourceID) {
return resourceService.publishResource(resourceID); return resourceService.publishResource(resourceID);
} }
/** /**
* 下架资源 * 下架资源
*/ */
@PostMapping("/{resourceID}/unpublish") @PostMapping("/resource/{resourceID}/unpublish")
public ResultDomain<TbResource> unpublishResource(@PathVariable String resourceID) { public ResultDomain<TbResource> unpublishResource(@PathVariable("resourceID") String resourceID) {
return resourceService.unpublishResource(resourceID); return resourceService.unpublishResource(resourceID);
} }
/** /**
* 增加浏览次数 * 增加浏览次数
*/ */
@PostMapping("/{resourceID}/view") @PostMapping("/resource/{resourceID}/view")
public ResultDomain<TbResource> incrementViewCount(@PathVariable String resourceID) { public ResultDomain<TbResource> incrementViewCount(@PathVariable("resourceID") String resourceID) {
return resourceService.incrementViewCount(resourceID); return resourceService.incrementViewCount(resourceID);
} }
/** /**
* 增加点赞次数 * 增加点赞次数
*/ */
@PostMapping("/{resourceID}/like") @PostMapping("/resource/{resourceID}/like")
public ResultDomain<TbResource> incrementLikeCount(@PathVariable String resourceID) { public ResultDomain<TbResource> incrementLikeCount(@PathVariable("resourceID") String resourceID) {
return resourceService.incrementLikeCount(resourceID); return resourceService.incrementLikeCount(resourceID);
} }
/** /**
* 增加收藏次数 * 增加收藏次数
*/ */
@PostMapping("/{resourceID}/collect") @PostMapping("/resource/{resourceID}/collect")
public ResultDomain<TbResource> incrementCollectCount(@PathVariable String resourceID) { public ResultDomain<TbResource> incrementCollectCount(@PathVariable("resourceID") String resourceID) {
return resourceService.incrementCollectCount(resourceID); return resourceService.incrementCollectCount(resourceID);
} }
/** /**
* 设置资源推荐 * 设置资源推荐
*/ */
@PutMapping("/{resourceID}/recommend") @PutMapping("/resource/{resourceID}/recommend")
public ResultDomain<TbResource> setResourceRecommend( public ResultDomain<TbResource> setResourceRecommend(
@PathVariable String resourceID, @PathVariable("resourceID") String resourceID,
@RequestParam Boolean isRecommend) { @RequestParam("isRecommend") Boolean isRecommend) {
return resourceService.setResourceRecommend(resourceID, isRecommend); return resourceService.setResourceRecommend(resourceID, isRecommend);
} }
/** /**
* 设置资源轮播 * 设置资源轮播
*/ */
@PutMapping("/{resourceID}/banner") @PutMapping("/resource/{resourceID}/banner")
public ResultDomain<TbResource> setResourceBanner( public ResultDomain<TbResource> setResourceBanner(
@PathVariable String resourceID, @PathVariable("resourceID") String resourceID,
@RequestParam Boolean isBanner) { @RequestParam("isBanner") Boolean isBanner) {
return resourceService.setResourceBanner(resourceID, isBanner); return resourceService.setResourceBanner(resourceID, isBanner);
} }
@@ -154,9 +183,9 @@ public class ResourceController {
*/ */
@GetMapping("/search") @GetMapping("/search")
public ResultDomain<TbResource> searchResources( public ResultDomain<TbResource> searchResources(
@RequestParam String keyword, @RequestParam("keyword") String keyword,
@RequestParam(required = false) String categoryID, @RequestParam(value = "categoryID", required = false) String categoryID,
@RequestParam(required = false) Integer status) { @RequestParam(value = "status", required = false) Integer status) {
return resourceService.searchResources(keyword, categoryID, status); return resourceService.searchResources(keyword, categoryID, status);
} }
} }

View File

@@ -16,7 +16,7 @@ import org.xyzh.common.dto.resource.TbResourceRecommend;
* @since 2025-10-15 * @since 2025-10-15
*/ */
@RestController @RestController
@RequestMapping("/news/recommend") @RequestMapping("/news/recommends")
public class ResourceRecommendController { public class ResourceRecommendController {
private static final Logger logger = LoggerFactory.getLogger(ResourceRecommendController.class); private static final Logger logger = LoggerFactory.getLogger(ResourceRecommendController.class);
@@ -27,51 +27,46 @@ public class ResourceRecommendController {
* 获取推荐列表 * 获取推荐列表
*/ */
@GetMapping("/list") @GetMapping("/list")
public ResultDomain<TbResourceRecommend> getRecommendList(TbResourceRecommend filter) { public ResultDomain<TbResourceRecommend> getRecommendList() {
return null; return resourceRecommendService.getRecommendList();
// return resourceRecommendService.getRecommendList(filter);
} }
/** /**
* 根据ID获取推荐详情 * 根据ID获取推荐详情
*/ */
@GetMapping("/{recommendID}") @GetMapping("/recommend/{recommendID}")
public ResultDomain<TbResourceRecommend> getRecommendById(@PathVariable String recommendID) { public ResultDomain<TbResourceRecommend> getRecommendById(@PathVariable String recommendID) {
return null; return resourceRecommendService.getRecommendDetail(recommendID);
// return resourceRecommendService.getRecommendById(recommendID);
} }
/** /**
* 创建推荐 * 创建推荐
*/ */
@PostMapping("/create") @PostMapping("/recommend")
public ResultDomain<TbResourceRecommend> createRecommend(@RequestBody TbResourceRecommend recommend) { public ResultDomain<TbResourceRecommend> createRecommend(@RequestBody TbResourceRecommend recommend) {
return null; return resourceRecommendService.addRecommend(recommend);
// return resourceRecommendService.createRecommend(recommend);
} }
/** /**
* 更新推荐 * 更新推荐
*/ */
@PutMapping("/update") @PutMapping("/recommend")
public ResultDomain<TbResourceRecommend> updateRecommend(@RequestBody TbResourceRecommend recommend) { public ResultDomain<TbResourceRecommend> updateRecommend(@RequestBody TbResourceRecommend recommend) {
return null; return resourceRecommendService.updateRecommend(recommend);
// return resourceRecommendService.updateRecommend(recommend);
} }
/** /**
* 删除推荐 * 删除推荐
*/ */
@DeleteMapping("/{recommendID}") @DeleteMapping("/recommend/{recommendID}")
public ResultDomain<Boolean> deleteRecommend(@PathVariable String recommendID) { public ResultDomain<Boolean> deleteRecommend(@PathVariable String recommendID) {
return null; return resourceRecommendService.deleteRecommend(recommendID);
// return resourceRecommendService.deleteRecommend(recommendID);
} }
/** /**
* 更新推荐状态 * 更新推荐状态
*/ */
@PutMapping("/{recommendID}/status") @PutMapping("/recommend/{recommendID}/status")
public ResultDomain<TbResourceRecommend> updateRecommendStatus(@PathVariable String recommendID, @RequestParam Integer status) { public ResultDomain<TbResourceRecommend> updateRecommendStatus(@PathVariable String recommendID, @RequestParam Integer status) {
return null; return null;
// return resourceRecommendService.updateRecommendStatus(recommendID, status); // return resourceRecommendService.updateRecommendStatus(recommendID, status);
@@ -80,7 +75,7 @@ public class ResourceRecommendController {
/** /**
* 更新推荐排序 * 更新推荐排序
*/ */
@PutMapping("/{recommendID}/order") @PutMapping("/recommend/{recommendID}/order")
public ResultDomain<TbResourceRecommend> updateRecommendOrder(@PathVariable String recommendID, @RequestParam Integer orderNum) { public ResultDomain<TbResourceRecommend> updateRecommendOrder(@PathVariable String recommendID, @RequestParam Integer orderNum) {
return resourceRecommendService.updateRecommendOrder(recommendID, orderNum); return resourceRecommendService.updateRecommendOrder(recommendID, orderNum);
} }

View File

@@ -7,6 +7,9 @@ import org.springframework.web.bind.annotation.*;
import org.xyzh.api.news.tag.TagService; import org.xyzh.api.news.tag.TagService;
import org.xyzh.common.core.domain.ResultDomain; import org.xyzh.common.core.domain.ResultDomain;
import org.xyzh.common.dto.resource.TbTag; import org.xyzh.common.dto.resource.TbTag;
import org.xyzh.common.dto.resource.TbResourceTag;
import java.util.List;
/** /**
* @description 标签控制器 * @description 标签控制器
@@ -16,7 +19,7 @@ import org.xyzh.common.dto.resource.TbTag;
* @since 2025-10-15 * @since 2025-10-15
*/ */
@RestController @RestController
@RequestMapping("/news/tag") @RequestMapping("/news/tags")
public class TagController { public class TagController {
private static final Logger logger = LoggerFactory.getLogger(TagController.class); private static final Logger logger = LoggerFactory.getLogger(TagController.class);
@@ -27,15 +30,14 @@ public class TagController {
* 获取标签列表 * 获取标签列表
*/ */
@GetMapping("/list") @GetMapping("/list")
public ResultDomain<TbTag> getTagList(TbTag filter) { public ResultDomain<TbTag> getTagList() {
return null; return tagService.getAllTags();
// return tagService.getTagList(filter);
} }
/** /**
* 根据ID获取标签详情 * 根据ID获取标签详情
*/ */
@GetMapping("/{tagID}") @GetMapping("/tag/{tagID}")
public ResultDomain<TbTag> getTagById(@PathVariable String tagID) { public ResultDomain<TbTag> getTagById(@PathVariable String tagID) {
return tagService.getTagById(tagID); return tagService.getTagById(tagID);
} }
@@ -43,7 +45,7 @@ public class TagController {
/** /**
* 创建标签 * 创建标签
*/ */
@PostMapping("/create") @PostMapping("/tag")
public ResultDomain<TbTag> createTag(@RequestBody TbTag tag) { public ResultDomain<TbTag> createTag(@RequestBody TbTag tag) {
return tagService.createTag(tag); return tagService.createTag(tag);
} }
@@ -51,7 +53,7 @@ public class TagController {
/** /**
* 更新标签 * 更新标签
*/ */
@PutMapping("/update") @PutMapping("/tag")
public ResultDomain<TbTag> updateTag(@RequestBody TbTag tag) { public ResultDomain<TbTag> updateTag(@RequestBody TbTag tag) {
return tagService.updateTag(tag); return tagService.updateTag(tag);
} }
@@ -59,35 +61,72 @@ public class TagController {
/** /**
* 删除标签 * 删除标签
*/ */
@DeleteMapping("/{tagID}") @DeleteMapping("/tag/{tagID}")
public ResultDomain<Boolean> deleteTag(@PathVariable String tagID) { public ResultDomain<Boolean> deleteTag(@PathVariable String tagID) {
return tagService.deleteTag(tagID); return tagService.deleteTag(tagID);
} }
/**
* 更新标签状态
*/
@PutMapping("/{tagID}/status")
public ResultDomain<TbTag> updateTagStatus(@PathVariable String tagID, @RequestParam Integer status) {
return null;
// return tagService.updateTagStatus(tagID, status);
}
/**
* 获取热门标签
*/
@GetMapping("/hot")
public ResultDomain<TbTag> getHotTags(@RequestParam(required = false) Integer limit) {
return null;
// return tagService.getHotTags(limit);
}
/** /**
* 搜索标签 * 搜索标签
*/ */
@GetMapping("/search") @GetMapping("/search")
public ResultDomain<TbTag> searchTags(@RequestParam String keyword) { public ResultDomain<TbTag> searchTags(@RequestParam String keyword) {
return null; return tagService.searchTagsByName(keyword);
// return tagService.searchTags(keyword); }
// ----------------资源标签关联相关--------------------------------
/**
* 获取资源的标签列表
*/
@GetMapping("/resource/{resourceID}")
public ResultDomain<TbTag> getResourceTags(@PathVariable String resourceID) {
return tagService.getResourceTags(resourceID);
}
/**
* 为资源添加单个标签
*/
@PostMapping("/resource/{resourceID}/tag/{tagID}")
public ResultDomain<TbResourceTag> addResourceTag(
@PathVariable String resourceID,
@PathVariable String tagID) {
return tagService.addResourceTag(resourceID, tagID);
}
/**
* 批量为资源添加标签
*/
@PostMapping("/resource/{resourceID}/tags")
public ResultDomain<TbResourceTag> batchAddResourceTags(
@PathVariable String resourceID,
@RequestBody List<String> tagIDs) {
return tagService.batchAddResourceTags(resourceID, tagIDs);
}
/**
* 移除资源的标签
*/
@DeleteMapping("/resource/{resourceID}/tag/{tagID}")
public ResultDomain<Boolean> removeResourceTag(
@PathVariable String resourceID,
@PathVariable String tagID) {
return tagService.removeResourceTag(resourceID, tagID);
}
/**
* 清空资源的所有标签
*/
@DeleteMapping("/resource/{resourceID}/tags")
public ResultDomain<Boolean> clearResourceTags(@PathVariable String resourceID) {
return tagService.clearResourceTags(resourceID);
}
/**
* 根据标签获取资源列表
*/
@GetMapping("/tag/{tagID}/resources")
public ResultDomain<String> getResourcesByTag(@PathVariable String tagID) {
return tagService.getResourcesByTag(tagID);
} }
} }

View File

@@ -162,5 +162,5 @@ public interface ResourceMapper extends BaseMapper<TbResource> {
* @author yslg * @author yslg
* @since 2025-10-15 * @since 2025-10-15
*/ */
long countResources(@Param("filter") TbResource filter); long countResources(TbResource filter);
} }

View File

@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.xyzh.common.core.page.PageParam; import org.xyzh.common.core.page.PageParam;
import org.xyzh.common.dto.resource.TbResourceTag; import org.xyzh.common.dto.resource.TbResourceTag;
import org.xyzh.common.vo.TagVO;
import java.util.List; import java.util.List;
@@ -25,7 +26,7 @@ public interface ResourceTagMapper extends BaseMapper<TbResourceTag> {
* @author yslg * @author yslg
* @since 2025-10-15 * @since 2025-10-15
*/ */
List<TbResourceTag> selectResourceTags(TbResourceTag filter); List<TagVO> selectResourceTags(TbResourceTag filter);
/** /**
* @description 根据关联ID查询关联信息 * @description 根据关联ID查询关联信息

View File

@@ -1,13 +1,18 @@
package org.xyzh.news.service.impl; package org.xyzh.news.service.impl;
import java.util.Date;
import java.util.List;
import java.util.Map; import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 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.domain.ResultDomain;
import org.xyzh.common.dto.resource.TbBanner; import org.xyzh.common.dto.resource.TbBanner;
import org.xyzh.common.utils.IDUtils;
import org.xyzh.news.mapper.BannerMapper; import org.xyzh.news.mapper.BannerMapper;
import org.xyzh.api.news.banner.BannerService; import org.xyzh.api.news.banner.BannerService;
@@ -27,59 +32,349 @@ public class NCBannerServiceImpl implements BannerService {
private BannerMapper bannerMapper; private BannerMapper bannerMapper;
@Override @Override
public ResultDomain<Boolean> batchUpdateBannerOrder(Map<String, Integer> bannerOrders) { public ResultDomain<TbBanner> getBannerList(Integer status) {
// TODO Auto-generated method stub ResultDomain<TbBanner> resultDomain = new ResultDomain<>();
return null; try {
List<TbBanner> list;
if (status != null) {
list = bannerMapper.selectByStatus(status);
} else {
TbBanner filter = new TbBanner();
list = bannerMapper.selectBanners(filter);
} }
resultDomain.success("获取横幅列表成功", list);
@Override return resultDomain;
public ResultDomain<TbBanner> createBanner(TbBanner banner) { } catch (Exception e) {
// TODO Auto-generated method stub logger.error("获取横幅列表异常: {}", e.getMessage(), e);
return null; resultDomain.fail("获取横幅列表失败: " + e.getMessage());
return resultDomain;
} }
@Override
public ResultDomain<Boolean> deleteBanner(String bannerID) {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultDomain<TbBanner> getActiveBanners(Integer limit) {
// TODO Auto-generated method stub
return null;
} }
@Override @Override
public ResultDomain<TbBanner> getBannerById(String bannerID) { public ResultDomain<TbBanner> getBannerById(String bannerID) {
// TODO Auto-generated method stub ResultDomain<TbBanner> resultDomain = new ResultDomain<>();
return null; 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 @Override
public ResultDomain<TbBanner> getBannerList(Integer status) { @Transactional(rollbackFor = Exception.class)
// TODO Auto-generated method stub public ResultDomain<TbBanner> createBanner(TbBanner banner) {
return null; ResultDomain<TbBanner> 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbBanner> updateBanner(TbBanner banner) { public ResultDomain<TbBanner> updateBanner(TbBanner banner) {
// TODO Auto-generated method stub ResultDomain<TbBanner> resultDomain = new ResultDomain<>();
return null; 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 @Override
public ResultDomain<TbBanner> updateBannerOrder(String bannerID, Integer orderNum) { @Transactional(rollbackFor = Exception.class)
// TODO Auto-generated method stub public ResultDomain<Boolean> deleteBanner(String bannerID) {
return null; ResultDomain<Boolean> 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbBanner> updateBannerStatus(String bannerID, Integer status) { public ResultDomain<TbBanner> updateBannerStatus(String bannerID, Integer status) {
// TODO Auto-generated method stub ResultDomain<TbBanner> resultDomain = new ResultDomain<>();
return null; 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<TbBanner> updateBannerOrder(String bannerID, Integer orderNum) {
ResultDomain<TbBanner> 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<TbBanner> getActiveBanners(Integer limit) {
ResultDomain<TbBanner> resultDomain = new ResultDomain<>();
try {
List<TbBanner> 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<Boolean> batchUpdateBannerOrder(Map<String, Integer> bannerOrders) {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
try {
// 参数验证
if (bannerOrders == null || bannerOrders.isEmpty()) {
resultDomain.fail("横幅排序信息不能为空");
return resultDomain;
}
Date now = new Date();
int successCount = 0;
for (Map.Entry<String, Integer> 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;
}
}
} }

View File

@@ -4,11 +4,19 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 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.domain.ResultDomain;
import org.xyzh.common.dto.resource.TbResourceCategory; import org.xyzh.common.dto.resource.TbResourceCategory;
import org.xyzh.common.utils.IDUtils;
import org.xyzh.news.mapper.ResourceCategoryMapper; import org.xyzh.news.mapper.ResourceCategoryMapper;
import org.xyzh.api.news.category.ResourceCategoryService; import org.xyzh.api.news.category.ResourceCategoryService;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/** /**
* @description 资源分类服务实现类 * @description 资源分类服务实现类
* @filename NCResourceCategoryServiceImpl.java * @filename NCResourceCategoryServiceImpl.java
@@ -25,64 +33,328 @@ public class NCResourceCategoryServiceImpl implements ResourceCategoryService {
private ResourceCategoryMapper resourceCategoryMapper; private ResourceCategoryMapper resourceCategoryMapper;
@Override @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResourceCategory> createCategory(TbResourceCategory category) { public ResultDomain<TbResourceCategory> createCategory(TbResourceCategory category) {
// TODO Auto-generated method stub ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
return null; 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResourceCategory> updateCategory(TbResourceCategory category) {
ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
try {
// 参数验证
if (category == null || !StringUtils.hasText(category.getID())) {
resultDomain.fail("分类ID不能为空");
return resultDomain;
}
// 检查分类是否存在
TbResourceCategory existingCategory = resourceCategoryMapper.selectById(category.getID());
if (existingCategory == null || existingCategory.getDeleted()) {
resultDomain.fail("分类不存在");
return resultDomain;
}
// 检查分类名称是否重复(排除自身)
if (StringUtils.hasText(category.getName())) {
int count = resourceCategoryMapper.countByName(category.getName(), category.getID());
if (count > 0) {
resultDomain.fail("分类名称已存在");
return resultDomain;
}
}
// 更新时间
category.setUpdateTime(new Date());
// 更新数据库
int result = resourceCategoryMapper.updateResourceCategory(category);
if (result > 0) {
logger.info("更新分类成功: {}", category.getID());
// 重新查询返回完整数据
TbResourceCategory updated = resourceCategoryMapper.selectById(category.getID());
resultDomain.success("更新分类成功", updated);
return resultDomain;
} else {
resultDomain.fail("更新分类失败");
return resultDomain;
}
} catch (Exception e) {
logger.error("更新分类异常: {}", e.getMessage(), e);
resultDomain.fail("更新分类失败: " + e.getMessage());
return resultDomain;
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<Boolean> deleteCategory(String categoryID) { public ResultDomain<Boolean> deleteCategory(String categoryID) {
// TODO Auto-generated method stub ResultDomain<Boolean> resultDomain = new ResultDomain<>();
return null; try {
// 参数验证
if (!StringUtils.hasText(categoryID)) {
resultDomain.fail("分类ID不能为空");
return resultDomain;
} }
@Override // 检查分类是否存在
public ResultDomain<TbResourceCategory> getAllCategories() { TbResourceCategory category = resourceCategoryMapper.selectByCategoryId(categoryID);
// TODO Auto-generated method stub if (category == null || category.getDeleted()) {
return null; resultDomain.fail("分类不存在");
return resultDomain;
} }
@Override // 检查是否有子分类
public ResultDomain<TbResourceCategory> getCategoriesByParent(String parentID) { ResultDomain<Boolean> hasChildResult = hasChildCategories(categoryID);
// TODO Auto-generated method stub if (hasChildResult.isSuccess() && Boolean.TRUE.equals(hasChildResult.getData())) {
return null; resultDomain.fail("该分类下存在子分类,无法删除");
return resultDomain;
}
// 检查是否有关联资源
ResultDomain<Boolean> hasResourceResult = hasResources(categoryID);
if (hasResourceResult.isSuccess() && Boolean.TRUE.equals(hasResourceResult.getData())) {
resultDomain.fail("该分类下存在资源,无法删除");
return resultDomain;
}
// 物理删除
int result = resourceCategoryMapper.deleteResourceCategory(category);
if (result > 0) {
logger.info("删除分类成功: {}", categoryID);
resultDomain.success("删除分类成功", true);
return resultDomain;
} else {
resultDomain.fail("删除分类失败");
return resultDomain;
}
} catch (Exception e) {
logger.error("删除分类异常: {}", e.getMessage(), e);
resultDomain.fail("删除分类失败: " + e.getMessage());
return resultDomain;
}
} }
@Override @Override
public ResultDomain<TbResourceCategory> getCategoryById(String categoryID) { public ResultDomain<TbResourceCategory> getCategoryById(String categoryID) {
// TODO Auto-generated method stub ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
return null; try {
if (!StringUtils.hasText(categoryID)) {
resultDomain.fail("分类ID不能为空");
return resultDomain;
}
TbResourceCategory category = resourceCategoryMapper.selectByCategoryId(categoryID);
if (category == null || category.getDeleted()) {
resultDomain.fail("分类不存在");
return resultDomain;
}
resultDomain.success("查询成功", category);
return resultDomain;
} catch (Exception e) {
logger.error("查询分类异常: {}", e.getMessage(), e);
resultDomain.fail("查询分类失败: " + e.getMessage());
return resultDomain;
}
}
@Override
public ResultDomain<TbResourceCategory> getAllCategories() {
ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
try {
List<TbResourceCategory> categories = resourceCategoryMapper.selectResourceCategories(new TbResourceCategory());
resultDomain.success("查询成功", categories);
return resultDomain;
} catch (Exception e) {
logger.error("查询分类列表异常: {}", e.getMessage(), e);
resultDomain.fail("查询分类列表失败: " + e.getMessage());
return resultDomain;
}
}
@Override
public ResultDomain<TbResourceCategory> getCategoriesByParent(String parentID) {
ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
try {
if (!StringUtils.hasText(parentID)) {
resultDomain.fail("父分类ID不能为空");
return resultDomain;
}
List<TbResourceCategory> categories = resourceCategoryMapper.selectByParentId(parentID);
resultDomain.success("查询成功", categories);
return resultDomain;
} catch (Exception e) {
logger.error("查询子分类列表异常: {}", e.getMessage(), e);
resultDomain.fail("查询子分类列表失败: " + e.getMessage());
return resultDomain;
}
} }
@Override @Override
public ResultDomain<TbResourceCategory> getCategoryTree() { public ResultDomain<TbResourceCategory> getCategoryTree() {
// TODO Auto-generated method stub ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
return null; try {
// 查询所有分类
List<TbResourceCategory> allCategories = resourceCategoryMapper.selectCategoryTree();
// 构建树形结构
List<TbResourceCategory> tree = buildCategoryTree(allCategories, null);
resultDomain.success("查询成功", tree);
return resultDomain;
} catch (Exception e) {
logger.error("查询分类树异常: {}", e.getMessage(), e);
resultDomain.fail("查询分类树失败: " + e.getMessage());
return resultDomain;
}
} }
@Override @Override
public ResultDomain<Boolean> hasChildCategories(String categoryID) { public ResultDomain<Boolean> hasChildCategories(String categoryID) {
// TODO Auto-generated method stub ResultDomain<Boolean> resultDomain = new ResultDomain<>();
return null; try {
if (!StringUtils.hasText(categoryID)) {
resultDomain.fail("分类ID不能为空");
return resultDomain;
}
List<TbResourceCategory> children = resourceCategoryMapper.selectByParentId(categoryID);
resultDomain.success("查询成功", !children.isEmpty());
return resultDomain;
} catch (Exception e) {
logger.error("检查子分类异常: {}", e.getMessage(), e);
resultDomain.fail("检查子分类失败: " + e.getMessage());
return resultDomain;
}
} }
@Override @Override
public ResultDomain<Boolean> hasResources(String categoryID) { public ResultDomain<Boolean> hasResources(String categoryID) {
// TODO Auto-generated method stub ResultDomain<Boolean> resultDomain = new ResultDomain<>();
return null; try {
} if (!StringUtils.hasText(categoryID)) {
resultDomain.fail("分类ID不能为空");
@Override return resultDomain;
public ResultDomain<TbResourceCategory> updateCategory(TbResourceCategory category) { }
// TODO Auto-generated method stub
return null; // TODO: 需要查询资源表判断是否有关联资源
// 这里暂时返回false需要在ResourceMapper中添加相应方法
resultDomain.success("查询成功", false);
return resultDomain;
} catch (Exception e) {
logger.error("检查分类资源异常: {}", e.getMessage(), e);
resultDomain.fail("检查分类资源失败: " + e.getMessage());
return resultDomain;
}
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResourceCategory> updateCategoryOrder(String categoryID, Integer orderNum) { public ResultDomain<TbResourceCategory> updateCategoryOrder(String categoryID, Integer orderNum) {
// TODO Auto-generated method stub ResultDomain<TbResourceCategory> resultDomain = new ResultDomain<>();
return null; try {
if (!StringUtils.hasText(categoryID) || orderNum == null) {
resultDomain.fail("参数不能为空");
return resultDomain;
} }
TbResourceCategory category = resourceCategoryMapper.selectByCategoryId(categoryID);
if (category == null || category.getDeleted()) {
resultDomain.fail("分类不存在");
return resultDomain;
}
TbResourceCategory updateCategory = new TbResourceCategory();
updateCategory.setID(category.getID());
updateCategory.setOrderNum(orderNum);
updateCategory.setUpdateTime(new Date());
int result = resourceCategoryMapper.updateResourceCategory(updateCategory);
if (result > 0) {
logger.info("更新分类排序成功: {}", categoryID);
TbResourceCategory updated = resourceCategoryMapper.selectById(category.getID());
resultDomain.success("更新排序成功", updated);
return resultDomain;
} else {
resultDomain.fail("更新排序失败");
return resultDomain;
}
} catch (Exception e) {
logger.error("更新分类排序异常: {}", e.getMessage(), e);
resultDomain.fail("更新排序失败: " + e.getMessage());
return resultDomain;
}
}
/**
* 构建分类树形结构
* @param allCategories 所有分类列表
* @param parentID 父分类ID
* @return 树形结构列表
*/
private List<TbResourceCategory> buildCategoryTree(List<TbResourceCategory> allCategories, String parentID) {
List<TbResourceCategory> result = new ArrayList<>();
for (TbResourceCategory category : allCategories) {
// 找出当前父级下的子分类
if ((parentID == null && category.getParentID() == null) ||
(parentID != null && parentID.equals(category.getParentID()))) {
// 递归查找子分类如果TbResourceCategory有children字段可以在这里设置
// List<TbResourceCategory> children = buildCategoryTree(allCategories, category.getCategoryID());
// category.setChildren(children);
result.add(category);
}
}
return result;
}
} }

View File

@@ -1,13 +1,18 @@
package org.xyzh.news.service.impl; package org.xyzh.news.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 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.domain.ResultDomain;
import org.xyzh.common.dto.resource.TbResourceRecommend; import org.xyzh.common.dto.resource.TbResourceRecommend;
import org.xyzh.common.utils.IDUtils;
import org.xyzh.news.mapper.ResourceRecommendMapper; import org.xyzh.news.mapper.ResourceRecommendMapper;
import org.xyzh.api.news.recommend.ResourceRecommendService; import org.xyzh.api.news.recommend.ResourceRecommendService;
@@ -26,59 +31,389 @@ public class NCResourceRecommendServiceImpl implements ResourceRecommendService
@Autowired @Autowired
private ResourceRecommendMapper resourceRecommendMapper; private ResourceRecommendMapper resourceRecommendMapper;
@Override
public ResultDomain<TbResourceRecommend> addRecommend(TbResourceRecommend recommend) {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultDomain<TbResourceRecommend> batchAddRecommends(List<String> resourceIDs, String reason) {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultDomain<Boolean> batchRemoveRecommends(List<String> resourceIDs) {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultDomain<TbResourceRecommend> getRecommendDetail(String resourceID) {
// TODO Auto-generated method stub
return null;
}
@Override @Override
public ResultDomain<TbResourceRecommend> getRecommendList() { public ResultDomain<TbResourceRecommend> getRecommendList() {
// TODO Auto-generated method stub ResultDomain<TbResourceRecommend> resultDomain = new ResultDomain<>();
return null; try {
List<TbResourceRecommend> 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<TbResourceRecommend> addRecommend(TbResourceRecommend recommend) {
ResultDomain<TbResourceRecommend> resultDomain = new ResultDomain<>();
try {
// 参数验证
if (recommend == null || !StringUtils.hasText(recommend.getResourceID())) {
resultDomain.fail("资源ID不能为空");
return resultDomain;
}
// 检查资源是否已被推荐
List<TbResourceRecommend> 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<TbResourceRecommend> updateRecommend(TbResourceRecommend recommend) {
ResultDomain<TbResourceRecommend> 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<Boolean> deleteRecommend(String resourceID) {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
try {
// 参数验证
if (!StringUtils.hasText(resourceID)) {
resultDomain.fail("资源ID不能为空");
return resultDomain;
}
// 查询推荐
List<TbResourceRecommend> 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<Boolean> removeRecommend(String resourceID) {
return deleteRecommend(resourceID);
}
@Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResourceRecommend> batchAddRecommends(List<String> resourceIDs, String reason) {
ResultDomain<TbResourceRecommend> resultDomain = new ResultDomain<>();
try {
// 参数验证
if (resourceIDs == null || resourceIDs.isEmpty()) {
resultDomain.fail("资源ID列表不能为空");
return resultDomain;
}
List<TbResourceRecommend> recommendList = new ArrayList<>();
Date now = new Date();
for (String resourceID : resourceIDs) {
if (!StringUtils.hasText(resourceID)) {
continue;
}
// 检查是否已推荐
List<TbResourceRecommend> 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<Boolean> batchRemoveRecommends(List<String> resourceIDs) {
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
try {
// 参数验证
if (resourceIDs == null || resourceIDs.isEmpty()) {
resultDomain.fail("资源ID列表不能为空");
return resultDomain;
}
List<String> recommendIDs = new ArrayList<>();
for (String resourceID : resourceIDs) {
if (!StringUtils.hasText(resourceID)) {
continue;
}
List<TbResourceRecommend> 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<TbResourceRecommend> getRecommendDetail(String recommendID) {
ResultDomain<TbResourceRecommend> 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 @Override
public ResultDomain<Boolean> isResourceRecommended(String resourceID) { public ResultDomain<Boolean> isResourceRecommended(String resourceID) {
// TODO Auto-generated method stub ResultDomain<Boolean> resultDomain = new ResultDomain<>();
return null; try {
} // 参数验证
if (!StringUtils.hasText(resourceID)) {
@Override resultDomain.fail("资源ID不能为空");
public ResultDomain<Boolean> removeRecommend(String resourceID) { return resultDomain;
// TODO Auto-generated method stub }
return null;
// 查询推荐
List<TbResourceRecommend> 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResourceRecommend> updateRecommendOrder(String resourceID, Integer orderNum) { public ResultDomain<TbResourceRecommend> updateRecommendOrder(String resourceID, Integer orderNum) {
// TODO Auto-generated method stub ResultDomain<TbResourceRecommend> resultDomain = new ResultDomain<>();
return null; try {
// 参数验证
if (!StringUtils.hasText(resourceID)) {
resultDomain.fail("资源ID不能为空");
return resultDomain;
}
if (orderNum == null) {
resultDomain.fail("排序号不能为空");
return resultDomain;
}
// 查询推荐
List<TbResourceRecommend> 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResourceRecommend> updateRecommendReason(String resourceID, String reason) { public ResultDomain<TbResourceRecommend> updateRecommendReason(String resourceID, String reason) {
// TODO Auto-generated method stub ResultDomain<TbResourceRecommend> resultDomain = new ResultDomain<>();
return null; try {
// 参数验证
if (!StringUtils.hasText(resourceID)) {
resultDomain.fail("资源ID不能为空");
return resultDomain;
} }
// 查询推荐
List<TbResourceRecommend> 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;
}
}
} }

View File

@@ -4,11 +4,28 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 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.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.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.ResourceMapper;
import org.xyzh.news.mapper.ResourceTagMapper;
import org.xyzh.system.utils.LoginUtil;
import org.xyzh.api.news.resource.ResourceService; 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 资源服务实现类 * @description 资源服务实现类
* @filename NCResourceServiceImpl.java * @filename NCResourceServiceImpl.java
@@ -24,99 +41,699 @@ public class NCResourceServiceImpl implements ResourceService {
@Autowired @Autowired
private ResourceMapper resourceMapper; private ResourceMapper resourceMapper;
@Autowired
private ResourceTagMapper resourceTagMapper;
@Override @Override
public ResultDomain<TbResource> getResourceList(TbResource filter) { public ResultDomain<TbResource> getResourceList(TbResource filter) {
// TODO: 实现获取资源列表 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; try {
if (filter == null) {
filter = new TbResource();
}
List<TbResource> list = resourceMapper.selectResources(filter);
resultDomain.success("获取资源列表成功", list);
return resultDomain;
} catch (Exception e) {
logger.error("获取资源列表异常: {}", e.getMessage(), e);
resultDomain.fail("获取资源列表失败: " + e.getMessage());
return resultDomain;
}
} }
@Override @Override
public ResultDomain<TbResource> getResourceById(String resourceID) { public ResultDomain<TbResource> getResourcePage(TbResource filter, PageParam pageParam) {
// TODO: 实现根据ID获取资源详情 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; try {
if (filter == null) {
filter = new TbResource();
}
List<TbResource> 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<TbResource>(pageParam, list));
return resultDomain;
}
catch (Exception e) {
logger.error("获取资源分页异常: {}", e.getMessage(), e);
resultDomain.fail("获取资源分页失败: " + e.getMessage());
return resultDomain;
}
} }
@Override @Override
public ResultDomain<TbResource> createResource(TbResource resource) { public ResultDomain<ResourceVO> getResourceById(String resourceID) {
// TODO: 实现创建资源 ResultDomain<ResourceVO> resultDomain = new ResultDomain<>();
return null; 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<TagVO> 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 @Override
public ResultDomain<TbResource> updateResource(TbResource resource) { @Transactional(rollbackFor = Exception.class)
// TODO: 实现更新资源 public ResultDomain<ResourceVO> createResource(ResourceVO resourceVO) {
return null; ResultDomain<ResourceVO> 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<TbResourceTag> 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<ResourceVO> updateResource(ResourceVO resourceVO) {
ResultDomain<ResourceVO> 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<TagVO> originalTagVOs = resourceTagMapper.selectResourceTags(filter);
List<TbResourceTag> originalTags = originalTagVOs.stream().map(TagVO::getResourceTag).collect(Collectors.toList());
// 当前tags
List<TbTag> currentTags = resourceVO.getTags();
// 新增tags
List<TbTag> tagsToAdd = currentTags.stream()
.filter(tag -> originalTags.stream().noneMatch(originalTag -> originalTag.getTagID().equals(tag.getID())))
.collect(Collectors.toList());
// 删除tags
List<TbResourceTag> 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<Boolean> deleteResource(String resourceID) { public ResultDomain<Boolean> deleteResource(String resourceID) {
// TODO: 实现删除资源 ResultDomain<Boolean> resultDomain = new ResultDomain<>();
return null; 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResource> updateResourceStatus(String resourceID, Integer status) { public ResultDomain<TbResource> updateResourceStatus(String resourceID, Integer status) {
// TODO: 实现更新资源状态 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResource> publishResource(String resourceID) { public ResultDomain<TbResource> publishResource(String resourceID) {
// TODO: 实现发布资源 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResource> unpublishResource(String resourceID) { public ResultDomain<TbResource> unpublishResource(String resourceID) {
// TODO: 实现下架资源 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResource> incrementViewCount(String resourceID) { public ResultDomain<TbResource> incrementViewCount(String resourceID) {
// TODO: 实现增加浏览次数 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResource> incrementLikeCount(String resourceID) { public ResultDomain<TbResource> incrementLikeCount(String resourceID) {
// TODO: 实现增加点赞次数 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResource> incrementCollectCount(String resourceID) { public ResultDomain<TbResource> incrementCollectCount(String resourceID) {
// TODO: 实现增加收藏次数 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResource> setResourceRecommend(String resourceID, Boolean isRecommend) { public ResultDomain<TbResource> setResourceRecommend(String resourceID, Boolean isRecommend) {
// TODO: 实现设置资源推荐 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbResource> setResourceBanner(String resourceID, Boolean isBanner) { public ResultDomain<TbResource> setResourceBanner(String resourceID, Boolean isBanner) {
// TODO: 实现设置资源轮播 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; 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 @Override
public ResultDomain<TbResource> getRecommendResources(Integer limit) { public ResultDomain<TbResource> getRecommendResources(Integer limit) {
// TODO: 实现获取推荐资源列表 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; try {
// 创建过滤条件,查询推荐资源
TbResource filter = new TbResource();
filter.setIsRecommend(true);
filter.setStatus(1); // 只查询已发布的
List<TbResource> 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 @Override
public ResultDomain<TbResource> getBannerResources(Integer limit) { public ResultDomain<TbResource> getBannerResources(Integer limit) {
// TODO: 实现获取轮播资源列表 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; try {
// 创建过滤条件,查询轮播资源
TbResource filter = new TbResource();
filter.setIsBanner(true);
filter.setStatus(1); // 只查询已发布的
List<TbResource> 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 @Override
public ResultDomain<TbResource> searchResources(String keyword, String categoryID, Integer status) { public ResultDomain<TbResource> searchResources(String keyword, String categoryID, Integer status) {
// TODO: 实现搜索资源 ResultDomain<TbResource> resultDomain = new ResultDomain<>();
return null; try {
// 参数验证
if (!StringUtils.hasText(keyword)) {
resultDomain.fail("搜索关键词不能为空");
return resultDomain;
}
// 先按关键词搜索
List<TbResource> 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;
}
} }
} }

View File

@@ -1,14 +1,20 @@
package org.xyzh.news.service.impl; package org.xyzh.news.service.impl;
import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 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.domain.ResultDomain;
import org.xyzh.common.dto.resource.TbResourceTag; import org.xyzh.common.dto.resource.TbResourceTag;
import org.xyzh.common.dto.resource.TbTag; 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.news.mapper.TagMapper;
import org.xyzh.api.news.tag.TagService; import org.xyzh.api.news.tag.TagService;
@@ -27,77 +33,431 @@ public class NCTagServiceImpl implements TagService {
@Autowired @Autowired
private TagMapper tagMapper; private TagMapper tagMapper;
@Override @Autowired
public ResultDomain<TbResourceTag> addResourceTag(String resourceID, String tagID) { private ResourceTagMapper resourceTagMapper;
// TODO Auto-generated method stub
return null; // ----------------标签管理相关--------------------------------
}
@Override
public ResultDomain<TbResourceTag> batchAddResourceTags(String resourceID, List<String> tagIDs) {
// TODO Auto-generated method stub
return null;
}
@Override
public ResultDomain<Boolean> clearResourceTags(String resourceID) {
// TODO Auto-generated method stub
return null;
}
@Override @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbTag> createTag(TbTag tag) { public ResultDomain<TbTag> createTag(TbTag tag) {
// TODO Auto-generated method stub ResultDomain<TbTag> resultDomain = new ResultDomain<>();
return null; 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 @Override
@Transactional(rollbackFor = Exception.class)
public ResultDomain<TbTag> updateTag(TbTag tag) {
ResultDomain<TbTag> 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<Boolean> deleteTag(String tagID) { public ResultDomain<Boolean> deleteTag(String tagID) {
// TODO Auto-generated method stub ResultDomain<Boolean> resultDomain = new ResultDomain<>();
return null; try {
// 参数验证
if (!StringUtils.hasText(tagID)) {
resultDomain.fail("标签ID不能为空");
return resultDomain;
} }
@Override // 检查标签是否存在
public ResultDomain<TbTag> getAllTags() { TbTag tag = tagMapper.selectByTagId(tagID);
// TODO Auto-generated method stub if (tag == null || tag.getDeleted()) {
return null; resultDomain.fail("标签不存在");
return resultDomain;
} }
@Override // 检查是否有关联资源
public ResultDomain<TbTag> getResourceTags(String resourceID) { List<TbResourceTag> resourceTags = resourceTagMapper.selectByTagId(tagID);
// TODO Auto-generated method stub if (resourceTags != null && !resourceTags.isEmpty()) {
return null; resultDomain.fail("该标签下存在关联资源,无法删除");
return resultDomain;
} }
@Override // 物理删除
public ResultDomain<String> getResourcesByTag(String tagID) { int result = tagMapper.deleteTag(tag);
// TODO Auto-generated method stub if (result > 0) {
return null; 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 @Override
public ResultDomain<TbTag> getTagById(String tagID) { public ResultDomain<TbTag> getTagById(String tagID) {
// TODO Auto-generated method stub ResultDomain<TbTag> resultDomain = new ResultDomain<>();
return null; 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 @Override
public ResultDomain<Boolean> removeResourceTag(String resourceID, String tagID) { public ResultDomain<TbTag> getAllTags() {
// TODO Auto-generated method stub ResultDomain<TbTag> resultDomain = new ResultDomain<>();
return null; try {
List<TbTag> 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 @Override
public ResultDomain<TbTag> searchTagsByName(String name) { public ResultDomain<TbTag> searchTagsByName(String name) {
// TODO Auto-generated method stub ResultDomain<TbTag> resultDomain = new ResultDomain<>();
return null; try {
if (!StringUtils.hasText(name)) {
resultDomain.fail("搜索关键词不能为空");
return resultDomain;
}
TbTag filter = new TbTag();
filter.setName(name);
List<TbTag> 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<TbTag> getResourceTags(String resourceID) {
ResultDomain<TbTag> resultDomain = new ResultDomain<>();
try {
if (!StringUtils.hasText(resourceID)) {
resultDomain.fail("资源ID不能为空");
return resultDomain;
}
// 查询资源标签关联
List<TbResourceTag> resourceTags = resourceTagMapper.selectByResourceId(resourceID);
// 根据标签ID查询标签详情
List<TbTag> 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 @Override
public ResultDomain<TbTag> updateTag(TbTag tag) { @Transactional(rollbackFor = Exception.class)
// TODO Auto-generated method stub public ResultDomain<TbResourceTag> addResourceTag(String resourceID, String tagID) {
return null; ResultDomain<TbResourceTag> 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<TbResourceTag> batchAddResourceTags(String resourceID, List<String> tagIDs) {
ResultDomain<TbResourceTag> resultDomain = new ResultDomain<>();
try {
// 参数验证
if (!StringUtils.hasText(resourceID) || tagIDs == null || tagIDs.isEmpty()) {
resultDomain.fail("资源ID和标签ID列表不能为空");
return resultDomain;
}
List<TbResourceTag> 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<Boolean> removeResourceTag(String resourceID, String tagID) {
ResultDomain<Boolean> 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<Boolean> clearResourceTags(String resourceID) {
ResultDomain<Boolean> 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<String> getResourcesByTag(String tagID) {
ResultDomain<String> resultDomain = new ResultDomain<>();
try {
if (!StringUtils.hasText(tagID)) {
resultDomain.fail("标签ID不能为空");
return resultDomain;
}
// 查询标签关联的资源
List<TbResourceTag> resourceTags = resourceTagMapper.selectByTagId(tagID);
// 提取资源ID列表
List<String> 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;
}
}
} }

View File

@@ -188,7 +188,7 @@
FROM tb_banner FROM tb_banner
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY order_num ASC, create_time DESC ORDER BY order_num ASC, create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计Banner总数 --> <!-- 统计Banner总数 -->

View File

@@ -203,7 +203,7 @@
FROM tb_data_collection_config FROM tb_data_collection_config
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY create_time DESC ORDER BY create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计数据采集配置总数 --> <!-- 统计数据采集配置总数 -->

View File

@@ -175,7 +175,7 @@
FROM tb_data_collection_log FROM tb_data_collection_log
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY collect_time DESC ORDER BY collect_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计数据采集记录总数 --> <!-- 统计数据采集记录总数 -->

View File

@@ -181,7 +181,7 @@
FROM tb_resource_category FROM tb_resource_category
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY order_num ASC, create_time ASC ORDER BY order_num ASC, create_time ASC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计资源分类总数 --> <!-- 统计资源分类总数 -->

View File

@@ -5,6 +5,7 @@
<!-- 基础结果映射 --> <!-- 基础结果映射 -->
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.resource.TbResource"> <resultMap id="BaseResultMap" type="org.xyzh.common.dto.resource.TbResource">
<id column="id" property="id" jdbcType="VARCHAR"/> <id column="id" property="id" jdbcType="VARCHAR"/>
<result column="resource_id" property="resourceID" jdbcType="VARCHAR"/>
<result column="title" property="title" jdbcType="VARCHAR"/> <result column="title" property="title" jdbcType="VARCHAR"/>
<result column="content" property="content" jdbcType="LONGVARCHAR"/> <result column="content" property="content" jdbcType="LONGVARCHAR"/>
<result column="summary" property="summary" jdbcType="VARCHAR"/> <result column="summary" property="summary" jdbcType="VARCHAR"/>
@@ -30,7 +31,7 @@
<!-- 基础字段 --> <!-- 基础字段 -->
<sql id="Base_Column_List"> <sql id="Base_Column_List">
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, source_url, view_count, like_count, collect_count, status, is_recommend,
is_banner, publish_time, creator, updater, create_time, update_time, is_banner, publish_time, creator, updater, create_time, update_time,
delete_time, deleted delete_time, deleted
@@ -75,7 +76,7 @@
SELECT SELECT
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM tb_resource FROM tb_resource
WHERE id = #{resourceId} AND deleted = 0 WHERE resource_id = #{resourceId} AND deleted = 0
</select> </select>
<!-- 根据分类ID查询资源列表 --> <!-- 根据分类ID查询资源列表 -->
@@ -147,19 +148,19 @@
FROM tb_resource FROM tb_resource
WHERE title = #{title} AND deleted = 0 WHERE title = #{title} AND deleted = 0
<if test="excludeId != null and excludeId != ''"> <if test="excludeId != null and excludeId != ''">
AND id != #{excludeId} AND resource_id != #{excludeId}
</if> </if>
</select> </select>
<!-- 插入资源 --> <!-- 插入资源 -->
<insert id="insertResource" parameterType="org.xyzh.common.dto.resource.TbResource"> <insert id="insertResource" parameterType="org.xyzh.common.dto.resource.TbResource">
INSERT INTO tb_resource ( 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, source_url, view_count, like_count, collect_count, status, is_recommend,
is_banner, publish_time, creator, updater, create_time, update_time, is_banner, publish_time, creator, updater, create_time, update_time,
delete_time, deleted delete_time, deleted
) VALUES ( ) VALUES (
#{id}, #{title}, #{content}, #{summary}, #{coverImage}, #{categoryID}, #{author}, #{source}, #{id}, #{resourceID}, #{title}, #{content}, #{summary}, #{coverImage}, #{categoryID}, #{author}, #{source},
#{sourceUrl}, #{viewCount}, #{likeCount}, #{collectCount}, #{status}, #{isRecommend}, #{sourceUrl}, #{viewCount}, #{likeCount}, #{collectCount}, #{status}, #{isRecommend},
#{isBanner}, #{publishTime}, #{creator}, #{updater}, #{createTime}, #{updateTime}, #{isBanner}, #{publishTime}, #{creator}, #{updater}, #{createTime}, #{updateTime},
#{deleteTime}, #{deleted} #{deleteTime}, #{deleted}
@@ -228,26 +229,26 @@
deleted = #{deleted}, deleted = #{deleted},
</if> </if>
</set> </set>
WHERE id = #{id} WHERE resource_id = #{resourceID}
</update> </update>
<!-- 删除资源 --> <!-- 删除资源 -->
<delete id="deleteResource" parameterType="org.xyzh.common.dto.resource.TbResource"> <delete id="deleteResource" parameterType="org.xyzh.common.dto.resource.TbResource">
DELETE FROM tb_resource DELETE FROM tb_resource
WHERE id = #{id} WHERE resource_id = #{resourceID}
</delete> </delete>
<!-- 批量插入资源 --> <!-- 批量插入资源 -->
<insert id="batchInsertResources" parameterType="java.util.List"> <insert id="batchInsertResources" parameterType="java.util.List">
INSERT INTO tb_resource ( 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, source_url, view_count, like_count, collect_count, status, is_recommend,
is_banner, publish_time, creator, updater, create_time, update_time, is_banner, publish_time, creator, updater, create_time, update_time,
delete_time, deleted delete_time, deleted
) VALUES ) VALUES
<foreach collection="resourceList" item="item" separator=","> <foreach collection="resourceList" item="item" separator=",">
( (
#{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.categoryID}, #{item.author}, #{item.source}, #{item.sourceUrl},
#{item.viewCount}, #{item.likeCount}, #{item.collectCount}, #{item.status}, #{item.viewCount}, #{item.likeCount}, #{item.collectCount}, #{item.status},
#{item.isRecommend}, #{item.isBanner}, #{item.publishTime}, #{item.creator}, #{item.isRecommend}, #{item.isBanner}, #{item.publishTime}, #{item.creator},
@@ -259,9 +260,9 @@
<!-- 批量删除资源 --> <!-- 批量删除资源 -->
<delete id="batchDeleteResources"> <delete id="batchDeleteResources">
DELETE FROM tb_resource DELETE FROM tb_resource
WHERE id IN WHERE resource_id IN
<foreach collection="ids" item="id" open="(" separator="," close=")"> <foreach collection="ids" item="id" open="(" separator="," close=")">
#{id} #{resourceID}
</foreach> </foreach>
</delete> </delete>
@@ -270,9 +271,29 @@
SELECT SELECT
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
FROM tb_resource FROM tb_resource
<include refid="Where_Clause" /> <where>
deleted = 0
<if test="filter.title != null and filter.title != ''">
AND title LIKE CONCAT('%', #{filter.title}, '%')
</if>
<if test="filter.categoryID != null and filter.categoryID != ''">
AND category_id = #{filter.categoryID}
</if>
<if test="filter.author != null and filter.author != ''">
AND author LIKE CONCAT('%', #{filter.author}, '%')
</if>
<if test="filter.status != null">
AND status = #{filter.status}
</if>
<if test="filter.isRecommend != null">
AND is_recommend = #{filter.isRecommend}
</if>
<if test="filter.isBanner != null">
AND is_banner = #{filter.isBanner}
</if>
</where>
ORDER BY publish_time DESC, create_time DESC ORDER BY publish_time DESC, create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计资源总数 --> <!-- 统计资源总数 -->

View File

@@ -179,7 +179,7 @@
FROM tb_resource_recommend FROM tb_resource_recommend
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY order_num ASC, create_time DESC ORDER BY order_num ASC, create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计资源推荐总数 --> <!-- 统计资源推荐总数 -->

View File

@@ -11,6 +11,16 @@
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/> <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap> </resultMap>
<resultMap id="TagResultMap" type="org.xyzh.common.vo.TagVO">
<id column="id" property="id" jdbcType="VARCHAR"/>
<result column="resource_id" property="resourceID" jdbcType="VARCHAR"/>
<result column="tag_id" property="tagID" jdbcType="VARCHAR"/>
<result column="tag_name" property="tagName" jdbcType="VARCHAR"/>
<result column="tag_color" property="tagColor" jdbcType="VARCHAR"/>
<result column="creator" property="creator" jdbcType="VARCHAR"/>
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
</resultMap>
<!-- 基础字段 --> <!-- 基础字段 -->
<sql id="Base_Column_List"> <sql id="Base_Column_List">
id, resource_id, tag_id, creator, create_time id, resource_id, tag_id, creator, create_time
@@ -29,12 +39,25 @@
</sql> </sql>
<!-- selectResourceTags --> <!-- selectResourceTags -->
<select id="selectResourceTags" resultMap="BaseResultMap"> <select id="selectResourceTags" resultMap="TagResultMap">
SELECT SELECT
<include refid="Base_Column_List"/> 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 FROM tb_resource_tag rt
<include refid="Where_Clause"/> LEFT JOIN tb_tag t ON rt.tag_id = t.id
ORDER BY create_time DESC WHERE 1=1
<if test="resourceID != null and resourceID != ''">
AND rt.resource_id = #{resourceID}
</if>
<if test="tagID != null and tagID != ''">
AND rt.tag_id = #{tagID}
</if>
<if test="creator != null and creator != ''">
AND rt.creator = #{creator}
</if>
<if test="createTime != null">
AND rt.create_time = #{createTime}
</if>
ORDER BY rt.create_time DESC
</select> </select>
<!-- 根据关联ID查询关联信息 --> <!-- 根据关联ID查询关联信息 -->
@@ -156,7 +179,7 @@
FROM tb_resource_tag FROM tb_resource_tag
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY create_time DESC ORDER BY create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计资源标签关联总数 --> <!-- 统计资源标签关联总数 -->

View File

@@ -184,7 +184,7 @@
FROM tb_tag FROM tb_tag
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY create_time DESC ORDER BY create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计标签总数 --> <!-- 统计标签总数 -->

View File

@@ -192,7 +192,7 @@
FROM tb_course_chapter FROM tb_course_chapter
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY order_num ASC, create_time ASC ORDER BY order_num ASC, create_time ASC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计课程章节总数 --> <!-- 统计课程章节总数 -->

View File

@@ -254,7 +254,7 @@
FROM tb_course FROM tb_course
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY order_num ASC, create_time DESC ORDER BY order_num ASC, create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计课程总数 --> <!-- 统计课程总数 -->

View File

@@ -156,7 +156,7 @@
FROM tb_course_tag FROM tb_course_tag
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY create_time DESC ORDER BY create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计课程标签关联总数 --> <!-- 统计课程标签关联总数 -->

View File

@@ -196,7 +196,7 @@
FROM tb_learning_record FROM tb_learning_record
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY last_learn_time DESC, create_time DESC ORDER BY last_learn_time DESC, create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计学习记录总数 --> <!-- 统计学习记录总数 -->

View File

@@ -172,7 +172,7 @@
FROM tb_learning_statistics FROM tb_learning_statistics
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY stat_date DESC ORDER BY stat_date DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计学习统计总数 --> <!-- 统计学习统计总数 -->

View File

@@ -207,7 +207,7 @@
FROM tb_learning_task FROM tb_learning_task
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY create_time DESC ORDER BY create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计学习任务总数 --> <!-- 统计学习任务总数 -->

View File

@@ -168,7 +168,7 @@
FROM tb_task_course FROM tb_task_course
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY order_num ASC, create_time ASC ORDER BY order_num ASC, create_time ASC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计任务课程关联总数 --> <!-- 统计任务课程关联总数 -->

View File

@@ -168,7 +168,7 @@
FROM tb_task_resource FROM tb_task_resource
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY order_num ASC, create_time ASC ORDER BY order_num ASC, create_time ASC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计任务资源关联总数 --> <!-- 统计任务资源关联总数 -->

View File

@@ -205,7 +205,7 @@
FROM tb_task_user FROM tb_task_user
<include refid="Where_Clause" /> <include refid="Where_Clause" />
ORDER BY create_time DESC ORDER BY create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计任务用户关联总数 --> <!-- 统计任务用户关联总数 -->

View File

@@ -125,6 +125,15 @@ public interface UserMapper extends BaseMapper<TbSysUser> {
*/ */
int updateUserInfo(@Param("userInfo") TbSysUserInfo userInfo); 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 获取用户信息总览 * @description 获取用户信息总览
* @param userId 用户ID * @param userId 用户ID

View File

@@ -719,8 +719,9 @@ public class SysUserServiceImpl implements SysUserService {
ResultDomain<UserVO> resultDomain = new ResultDomain<>(); ResultDomain<UserVO> resultDomain = new ResultDomain<>();
try { try {
logger.info("开始获取用户信息总览:{}", userId); logger.info("开始获取用户信息总览:{}", userId);
String deptPath = userMapper.getUserDeptPath(userId);
UserVO userVO = userMapper.selectUserInfoTotal(userId); UserVO userVO = userMapper.selectUserInfoTotal(userId);
userVO.setDeptName(deptPath);
resultDomain.success("获取用户信息总览成功", userVO); resultDomain.success("获取用户信息总览成功", userVO);
return resultDomain; return resultDomain;
} catch (Exception e) { } catch (Exception e) {

View File

@@ -180,7 +180,7 @@
FROM tb_sys_module FROM tb_sys_module
<include refid="Base_Where_Clause" /> <include refid="Base_Where_Clause" />
ORDER BY order_num ASC, create_time DESC ORDER BY order_num ASC, create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计模块数量 --> <!-- 统计模块数量 -->

View File

@@ -245,9 +245,69 @@
WHERE user_id = #{userInfo.userID} AND deleted = 0 WHERE user_id = #{userInfo.userID} AND deleted = 0
</update> </update>
<!-- 获取用户完整部门路径 -->
<select id="getUserDeptPath" resultType="java.lang.String">
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 dh.dept_path
FROM dept_hierarchy dh
WHERE dh.parent_id IS NULL -- 只取最顶层的部门路径
LIMIT 1
</select>
<!-- selectUserInfoTotal --> <!-- selectUserInfoTotal -->
<select id="selectUserInfoTotal" resultMap="UserInfoTotalResultMap"> <select id="selectUserInfoTotal" resultMap="UserInfoTotalResultMap">
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 SELECT
tus.id as user_id, tus.id as user_id,
tus.username, tus.username,
@@ -255,7 +315,7 @@
tus.email, tus.email,
tsui.avatar, tsui.avatar,
tsui.gender, tsui.gender,
tsd.name as dept_name, dh.dept_path as dept_name,
tsr.name as role_name, tsr.name as role_name,
tsui.level, tsui.level,
tsui.id_card, tsui.id_card,
@@ -263,8 +323,10 @@
FROM tb_sys_user_info tsui FROM tb_sys_user_info tsui
INNER JOIN tb_sys_user tus ON tsui.user_id = tus.id 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_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 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 -- 只取最顶层的部门路径
</select> </select>
</mapper> </mapper>

View File

@@ -450,7 +450,7 @@
FROM tb_achievement FROM tb_achievement
<include refid="Base_Where_Clause" /> <include refid="Base_Where_Clause" />
ORDER BY order_num ASC, create_time DESC ORDER BY order_num ASC, create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计成就总数 --> <!-- 统计成就总数 -->

View File

@@ -327,7 +327,7 @@
FROM tb_points_record FROM tb_points_record
<include refid="Base_Where_Clause" /> <include refid="Base_Where_Clause" />
ORDER BY create_time DESC ORDER BY create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计积分记录总数 --> <!-- 统计积分记录总数 -->

View File

@@ -278,7 +278,7 @@
FROM tb_user_achievement FROM tb_user_achievement
<include refid="Base_Where_Clause" /> <include refid="Base_Where_Clause" />
ORDER BY obtain_time DESC ORDER BY obtain_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计用户成就总数 --> <!-- 统计用户成就总数 -->

View File

@@ -307,7 +307,7 @@
FROM tb_user_browse_record FROM tb_user_browse_record
<include refid="Base_Where_Clause" /> <include refid="Base_Where_Clause" />
ORDER BY browse_time DESC ORDER BY browse_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计用户浏览记录总数 --> <!-- 统计用户浏览记录总数 -->

View File

@@ -282,7 +282,7 @@
FROM tb_user_collection FROM tb_user_collection
<include refid="Base_Where_Clause" /> <include refid="Base_Where_Clause" />
ORDER BY create_time DESC ORDER BY create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计用户收藏总数 --> <!-- 统计用户收藏总数 -->

View File

@@ -156,7 +156,7 @@
FROM tb_user_points FROM tb_user_points
<include refid="Base_Where_Clause" /> <include refid="Base_Where_Clause" />
ORDER BY create_time DESC ORDER BY create_time DESC
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.pageNumber} LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
</select> </select>
<!-- 统计用户积分总数 --> <!-- 统计用户积分总数 -->