成就等界面接口调整
This commit is contained in:
@@ -2,10 +2,13 @@ package org.xyzh.news.controller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.xyzh.api.news.recommend.ResourceRecommendService;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.dto.resource.TbResource;
|
||||
import org.xyzh.common.dto.resource.TbBanner;
|
||||
import org.xyzh.common.vo.ResourceRecommendVO;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -21,197 +24,23 @@ import java.util.Map;
|
||||
public class HomePageController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(HomePageController.class);
|
||||
|
||||
// ==================== 轮播组件管理 ====================
|
||||
@Autowired
|
||||
private ResourceRecommendService resourceRecommendService;
|
||||
|
||||
/**
|
||||
* 获取轮播组件数据
|
||||
* 获取热门资源列表
|
||||
*/
|
||||
@GetMapping("/banner/list")
|
||||
public ResultDomain<TbBanner> getBannerList() {
|
||||
// TODO: 实现获取轮播组件数据(自动轮播核心新闻,支持手动切换)
|
||||
return null;
|
||||
@GetMapping("/recommend/hot")
|
||||
public ResultDomain<ResourceRecommendVO> getHotResources(@RequestParam(required = false, name = "limit") Integer limit) {
|
||||
return resourceRecommendService.getRecommendsByType(1, limit); // 1-热门资源
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击轮播跳转新闻详情
|
||||
*/
|
||||
@GetMapping("/banner/click/{bannerID}")
|
||||
public ResultDomain<TbResource> getBannerNewsDetail(@PathVariable String bannerID) {
|
||||
// TODO: 实现点击跳转新闻详情
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取活跃轮播列表
|
||||
* 获取思政资源列表
|
||||
*/
|
||||
@GetMapping("/banner/active")
|
||||
public ResultDomain<TbBanner> getActiveBanners() {
|
||||
// TODO: 实现获取活跃轮播列表
|
||||
return null;
|
||||
}
|
||||
|
||||
// ==================== TOP资源推荐 ====================
|
||||
|
||||
/**
|
||||
* 获取TOP资源推荐列表
|
||||
*/
|
||||
@GetMapping("/recommend/top-list")
|
||||
public ResultDomain<TbResource> getTopRecommendList() {
|
||||
// TODO: 实现获取TOP资源推荐列表(按浏览数据展示高热度新闻)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台调控展示顺序
|
||||
*/
|
||||
@PutMapping("/recommend/order")
|
||||
public ResultDomain<Boolean> updateRecommendOrder(@RequestBody Map<String, Object> orderData) {
|
||||
// TODO: 实现后台调控展示顺序与内容
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取高热度新闻
|
||||
*/
|
||||
@GetMapping("/recommend/hot-news")
|
||||
public ResultDomain<TbResource> getHotNews(@RequestParam(required = false) Integer limit) {
|
||||
// TODO: 实现获取高热度新闻
|
||||
return null;
|
||||
}
|
||||
|
||||
// ==================== 思政新闻概览 ====================
|
||||
|
||||
/**
|
||||
* 获取思政新闻概览
|
||||
*/
|
||||
@GetMapping("/news/overview")
|
||||
public ResultDomain<TbResource> getNewsOverview(
|
||||
@RequestParam(required = false) Integer pageNum,
|
||||
@RequestParam(required = false) Integer pageSize) {
|
||||
// TODO: 实现获取思政新闻概览(以卡片形式展示新闻标题、发布时间、简介)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击跳转二级详情页
|
||||
*/
|
||||
@GetMapping("/news/detail/{newsID}")
|
||||
public ResultDomain<TbResource> getNewsDetail(@PathVariable String newsID) {
|
||||
// TODO: 实现点击跳转二级详情页
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最新思政新闻
|
||||
*/
|
||||
@GetMapping("/news/latest")
|
||||
public ResultDomain<TbResource> getLatestNews(@RequestParam(required = false) Integer limit) {
|
||||
// TODO: 实现获取最新思政新闻
|
||||
return null;
|
||||
}
|
||||
|
||||
// ==================== 顶部菜单栏 ====================
|
||||
|
||||
/**
|
||||
* 获取顶部菜单栏配置
|
||||
*/
|
||||
@GetMapping("/menu/top-menu")
|
||||
public ResultDomain<Map<String, Object>> getTopMenuConfig() {
|
||||
// TODO: 实现获取顶部菜单栏(包含首页、资源中心、学习计划、专题活动、红色常信)
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台修改菜单名称
|
||||
*/
|
||||
@PutMapping("/menu/update-name")
|
||||
public ResultDomain<Boolean> updateMenuName(@RequestBody Map<String, Object> menuData) {
|
||||
// TODO: 实现支持后台修改菜单名称
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单项列表
|
||||
*/
|
||||
@GetMapping("/menu/list")
|
||||
public ResultDomain<Map<String, Object>> getMenuList() {
|
||||
// TODO: 实现获取菜单项列表
|
||||
return null;
|
||||
}
|
||||
|
||||
// ==================== 模糊检索 ====================
|
||||
|
||||
/**
|
||||
* 模糊检索资源
|
||||
*/
|
||||
@GetMapping("/search")
|
||||
public ResultDomain<TbResource> searchResources(@RequestParam String keyword) {
|
||||
// TODO: 实现模糊检索(输入关键词实时匹配资源(新闻、课程))
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 实时搜索建议
|
||||
*/
|
||||
@GetMapping("/search/suggestions")
|
||||
public ResultDomain<Map<String, Object>> getSearchSuggestions(@RequestParam String keyword) {
|
||||
// TODO: 实现实时搜索建议
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取热门搜索词
|
||||
*/
|
||||
@GetMapping("/search/hot-keywords")
|
||||
public ResultDomain<Map<String, Object>> getHotKeywords() {
|
||||
// TODO: 实现获取热门搜索词
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索新闻
|
||||
*/
|
||||
@GetMapping("/search/news")
|
||||
public ResultDomain<TbResource> searchNews(@RequestParam String keyword) {
|
||||
// TODO: 实现搜索新闻
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索课程
|
||||
*/
|
||||
@GetMapping("/search/courses")
|
||||
public ResultDomain<Map<String, Object>> searchCourses(@RequestParam String keyword) {
|
||||
// TODO: 实现搜索课程
|
||||
return null;
|
||||
}
|
||||
|
||||
// ==================== 首页统计数据 ====================
|
||||
|
||||
/**
|
||||
* 获取首页统计数据
|
||||
*/
|
||||
@GetMapping("/statistics")
|
||||
public ResultDomain<Map<String, Object>> getHomePageStatistics() {
|
||||
// TODO: 实现获取首页统计数据
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取今日访问量
|
||||
*/
|
||||
@GetMapping("/statistics/today-visits")
|
||||
public ResultDomain<Map<String, Object>> getTodayVisits() {
|
||||
// TODO: 实现获取今日访问量
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资源总数
|
||||
*/
|
||||
@GetMapping("/statistics/total-resources")
|
||||
public ResultDomain<Map<String, Object>> getTotalResources() {
|
||||
// TODO: 实现获取资源总数
|
||||
return null;
|
||||
@GetMapping("/recommend/ideological")
|
||||
public ResultDomain<ResourceRecommendVO> getIdeologicalResources(@RequestParam(required = false, name = "limit") Integer limit) {
|
||||
return resourceRecommendService.getRecommendsByType(2, limit); // 2-思政资源
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,16 @@ public class ResourceController {
|
||||
return resourceService.getResourcePage(filter, pageParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资源分页(按浏览次数排序)
|
||||
*/
|
||||
@PostMapping("/page/view-count")
|
||||
public ResultDomain<TbResource> getResourcePageOrderByViewCount(@RequestBody PageRequest<TbResource> request) {
|
||||
TbResource filter = request.getFilter();
|
||||
PageParam pageParam = request.getPageParam();
|
||||
return resourceService.getResourcePageOrderByViewCount(filter, pageParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取资源详情
|
||||
*/
|
||||
@@ -136,14 +146,6 @@ public class ResourceController {
|
||||
return resourceService.incrementLikeCount(resourceID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加收藏次数
|
||||
*/
|
||||
@PostMapping("/resource/collect")
|
||||
public ResultDomain<TbResource> resourceCollect(@RequestBody TbUserCollection collection) {
|
||||
return resourceService.resourceCollect(collection);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置资源推荐
|
||||
*/
|
||||
|
||||
@@ -6,7 +6,15 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.xyzh.api.news.recommend.ResourceRecommendService;
|
||||
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.TbResourceRecommend;
|
||||
import org.xyzh.common.dto.user.TbSysUser;
|
||||
import org.xyzh.common.vo.ResourceRecommendVO;
|
||||
import org.xyzh.system.utils.LoginUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @description 资源推荐控制器
|
||||
@@ -24,19 +32,36 @@ public class ResourceRecommendController {
|
||||
private ResourceRecommendService resourceRecommendService;
|
||||
|
||||
/**
|
||||
* 获取推荐列表
|
||||
* 获取推荐列表(返回VO,包含权限信息)
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public ResultDomain<TbResourceRecommend> getRecommendList() {
|
||||
return resourceRecommendService.getRecommendList();
|
||||
public ResultDomain<ResourceRecommendVO> getRecommendList() {
|
||||
ResultDomain<ResourceRecommendVO> result = resourceRecommendService.getRecommendList();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取推荐详情
|
||||
* 根据ID获取推荐详情(返回VO,包含权限信息)
|
||||
*/
|
||||
@GetMapping("/recommend/{recommendID}")
|
||||
public ResultDomain<TbResourceRecommend> getRecommendById(@PathVariable String recommendID) {
|
||||
return resourceRecommendService.getRecommendDetail(recommendID);
|
||||
public ResultDomain<ResourceRecommendVO> getRecommendById(@PathVariable("recommendID") String recommendID) {
|
||||
TbResourceRecommend filter = new TbResourceRecommend();
|
||||
filter.setID(recommendID);
|
||||
PageParam pageParam = new PageParam();
|
||||
pageParam.setPageNumber(1);
|
||||
pageParam.setPageSize(1);
|
||||
ResultDomain<ResourceRecommendVO> result = resourceRecommendService.getRecommendPage(filter, pageParam);
|
||||
// 从PageDomain中提取dataList的第一个元素
|
||||
if (result.getCode() == 200 && result.getPageDomain() != null
|
||||
&& result.getPageDomain().getDataList() != null && !result.getPageDomain().getDataList().isEmpty()) {
|
||||
ResultDomain<ResourceRecommendVO> singleResult = new ResultDomain<>();
|
||||
singleResult.setCode(200);
|
||||
singleResult.setMessage(result.getMessage());
|
||||
singleResult.setData(result.getPageDomain().getDataList().get(0));
|
||||
return singleResult;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,6 +69,12 @@ public class ResourceRecommendController {
|
||||
*/
|
||||
@PostMapping("/recommend")
|
||||
public ResultDomain<TbResourceRecommend> createRecommend(@RequestBody TbResourceRecommend recommend) {
|
||||
TbSysUser user = LoginUtil.getCurrentUser();
|
||||
if (user != null) {
|
||||
if (recommend.getCreator() == null) {
|
||||
recommend.setCreator(user.getID());
|
||||
}
|
||||
}
|
||||
return resourceRecommendService.addRecommend(recommend);
|
||||
}
|
||||
|
||||
@@ -59,15 +90,26 @@ public class ResourceRecommendController {
|
||||
* 删除推荐
|
||||
*/
|
||||
@DeleteMapping("/recommend/{recommendID}")
|
||||
public ResultDomain<Boolean> deleteRecommend(@PathVariable String recommendID) {
|
||||
public ResultDomain<Boolean> deleteRecommend(@PathVariable("recommendID") String recommendID) {
|
||||
return resourceRecommendService.deleteRecommend(recommendID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量添加推荐资源
|
||||
*/
|
||||
@PostMapping("/recommend/batch")
|
||||
public ResultDomain<TbResourceRecommend> batchAddRecommends(@RequestBody Map<String, Object> params) {
|
||||
List<String> resourceIDs = (List<String>) params.get("resourceIDs");
|
||||
Integer recommendType = (Integer) params.get("recommendType");
|
||||
String reason = (String) params.get("reason");
|
||||
return resourceRecommendService.batchAddRecommends(resourceIDs, recommendType, reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新推荐状态
|
||||
*/
|
||||
@PutMapping("/recommend/{recommendID}/status")
|
||||
public ResultDomain<TbResourceRecommend> updateRecommendStatus(@PathVariable String recommendID, @RequestParam Integer status) {
|
||||
public ResultDomain<TbResourceRecommend> updateRecommendStatus(@PathVariable("recommendID") String recommendID, @RequestParam("status") Integer status) {
|
||||
return null;
|
||||
// return resourceRecommendService.updateRecommendStatus(recommendID, status);
|
||||
}
|
||||
@@ -76,7 +118,7 @@ public class ResourceRecommendController {
|
||||
* 更新推荐排序
|
||||
*/
|
||||
@PutMapping("/recommend/{recommendID}/order")
|
||||
public ResultDomain<TbResourceRecommend> updateRecommendOrder(@PathVariable String recommendID, @RequestParam Integer orderNum) {
|
||||
public ResultDomain<TbResourceRecommend> updateRecommendOrder(@PathVariable("recommendID") String recommendID, @RequestParam("orderNum") Integer orderNum) {
|
||||
return resourceRecommendService.updateRecommendOrder(recommendID, orderNum);
|
||||
}
|
||||
|
||||
@@ -84,8 +126,46 @@ public class ResourceRecommendController {
|
||||
* 获取活跃推荐
|
||||
*/
|
||||
@GetMapping("/active")
|
||||
public ResultDomain<TbResourceRecommend> getActiveRecommends(@RequestParam(required = false) Integer limit) {
|
||||
public ResultDomain<TbResourceRecommend> getActiveRecommends(@RequestParam(required = false, name = "limit") Integer limit) {
|
||||
return null;
|
||||
// return resourceRecommendService.getActiveRecommends(limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询推荐资源列表
|
||||
*/
|
||||
@PostMapping("/page")
|
||||
public ResultDomain<ResourceRecommendVO> getRecommendPage(@RequestBody PageRequest<TbResourceRecommend> request) {
|
||||
TbResourceRecommend filter = request.getFilter();
|
||||
PageParam pageParam = request.getPageParam();
|
||||
return resourceRecommendService.getRecommendPage(filter, pageParam);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计推荐资源总数
|
||||
*/
|
||||
@PostMapping("/count")
|
||||
public ResultDomain<Long> countRecommends(@RequestBody TbResourceRecommend filter) {
|
||||
return resourceRecommendService.countRecommends(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据推荐类型获取推荐资源列表
|
||||
*/
|
||||
@GetMapping("/type/{recommendType}")
|
||||
public ResultDomain<ResourceRecommendVO> getRecommendsByType(
|
||||
@PathVariable("recommendType") Integer recommendType,
|
||||
@RequestParam(required = false, name = "limit") Integer limit) {
|
||||
return resourceRecommendService.getRecommendsByType(recommendType, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查资源是否已推荐(按类型)
|
||||
*/
|
||||
@GetMapping("/check/{resourceID}")
|
||||
public ResultDomain<Boolean> isResourceRecommendedByType(
|
||||
@PathVariable("resourceID") String resourceID,
|
||||
@RequestParam(required = true, name = "recommendType") Integer recommendType) {
|
||||
return resourceRecommendService.isResourceRecommendedByType(resourceID, recommendType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ public class TagController {
|
||||
* 获取标签列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public ResultDomain<TbTag> getTagList() {
|
||||
return tagService.getAllTags();
|
||||
public ResultDomain<TbTag> getTagList(TbTag filter) {
|
||||
return tagService.getTagList(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -165,6 +165,18 @@ public interface ResourceMapper extends BaseMapper<TbResource> {
|
||||
*/
|
||||
List<TbResource> selectResourcesPage(@Param("filter") TbResource filter, @Param("pageParam") PageParam pageParam, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 分页查询资源
|
||||
* @param filter 过滤条件
|
||||
* @param pageParam 分页参数
|
||||
* @param userDeptRoles 用户部门角色列表
|
||||
* @return List<TbResource> 资源列表
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbResource> selectResourcesPageOrderByViewCount(@Param("filter") TbResource filter, @Param("pageParam") PageParam pageParam, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
|
||||
/**
|
||||
* @description 统计资源总数
|
||||
* @param filter 过滤条件
|
||||
|
||||
@@ -5,6 +5,8 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.dto.resource.TbResourceRecommend;
|
||||
import org.xyzh.common.vo.ResourceRecommendVO;
|
||||
import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,11 +23,12 @@ public interface ResourceRecommendMapper extends BaseMapper<TbResourceRecommend>
|
||||
/**
|
||||
* @description 查询资源推荐列表
|
||||
* @param filter 过滤条件
|
||||
* @return List<TbResourceRecommend> 资源推荐列表
|
||||
* @param userDeptRoles 用户部门角色列表(用于权限过滤)
|
||||
* @return List<ResourceRecommendVO> 资源推荐列表(包含资源信息和权限)
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbResourceRecommend> selectResourceRecommends(TbResourceRecommend filter);
|
||||
List<ResourceRecommendVO> selectResourceRecommends(@Param("filter") TbResourceRecommend filter, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 根据推荐ID查询推荐信息
|
||||
@@ -55,13 +58,25 @@ public interface ResourceRecommendMapper extends BaseMapper<TbResourceRecommend>
|
||||
List<TbResourceRecommend> selectByStatus(@Param("status") Integer status);
|
||||
|
||||
/**
|
||||
* @description 根据类型查询推荐列表
|
||||
* @param type 类型
|
||||
* @return List<TbResourceRecommend> 推荐列表
|
||||
* @description 根据推荐类型查询推荐列表
|
||||
* @param recommendType 推荐类型(1-热门资源,2-思政资源)
|
||||
* @param limit 限制数量
|
||||
* @param userDeptRoles 用户部门角色列表(用于权限过滤)
|
||||
* @return List<ResourceRecommendVO> 推荐列表(包含资源信息和权限)
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbResourceRecommend> selectByType(@Param("type") Integer type);
|
||||
List<ResourceRecommendVO> selectByRecommendType(@Param("recommendType") Integer recommendType, @Param("limit") Integer limit, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 根据资源ID和推荐类型查询
|
||||
* @param resourceId 资源ID
|
||||
* @param recommendType 推荐类型
|
||||
* @return List<TbResourceRecommend> 推荐列表
|
||||
* @author yslg
|
||||
* @since 2025-01-XX
|
||||
*/
|
||||
List<TbResourceRecommend> selectByResourceIdAndType(@Param("resourceId") String resourceId, @Param("recommendType") Integer recommendType);
|
||||
|
||||
/**
|
||||
* @description 查询热门推荐列表
|
||||
@@ -130,18 +145,20 @@ public interface ResourceRecommendMapper extends BaseMapper<TbResourceRecommend>
|
||||
* @description 分页查询资源推荐
|
||||
* @param filter 过滤条件
|
||||
* @param pageParam 分页参数
|
||||
* @return List<TbResourceRecommend> 资源推荐列表
|
||||
* @param userDeptRoles 用户部门角色列表(用于权限过滤)
|
||||
* @return List<ResourceRecommendVO> 资源推荐列表(包含资源信息和权限)
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
List<TbResourceRecommend> selectResourceRecommendsPage(@Param("filter") TbResourceRecommend filter, @Param("pageParam") PageParam pageParam);
|
||||
List<ResourceRecommendVO> selectResourceRecommendsPage(@Param("filter") TbResourceRecommend filter, @Param("pageParam") PageParam pageParam, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
|
||||
/**
|
||||
* @description 统计资源推荐总数
|
||||
* @param filter 过滤条件
|
||||
* @param userDeptRoles 用户部门角色列表(用于权限过滤)
|
||||
* @return long 总数
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
long countResourceRecommends(@Param("filter") TbResourceRecommend filter);
|
||||
long countResourceRecommends(@Param("filter") TbResourceRecommend filter, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
}
|
||||
|
||||
@@ -11,10 +11,15 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.core.page.PageDomain;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.dto.resource.TbResourceRecommend;
|
||||
import org.xyzh.common.utils.IDUtils;
|
||||
import org.xyzh.common.vo.ResourceRecommendVO;
|
||||
import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
import org.xyzh.news.mapper.ResourceRecommendMapper;
|
||||
import org.xyzh.api.news.recommend.ResourceRecommendService;
|
||||
import org.xyzh.system.utils.LoginUtil;
|
||||
|
||||
/**
|
||||
* @description 资源推荐服务实现类
|
||||
@@ -32,11 +37,13 @@ public class NCResourceRecommendServiceImpl implements ResourceRecommendService
|
||||
private ResourceRecommendMapper resourceRecommendMapper;
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbResourceRecommend> getRecommendList() {
|
||||
ResultDomain<TbResourceRecommend> resultDomain = new ResultDomain<>();
|
||||
public ResultDomain<ResourceRecommendVO> getRecommendList() {
|
||||
ResultDomain<ResourceRecommendVO> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
List<TbResourceRecommend> list = resourceRecommendMapper.selectResourceRecommends(new TbResourceRecommend());
|
||||
resultDomain.success("获取推荐列表成功", list);
|
||||
// 获取当前用户的部门角色(用于权限过滤)
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<ResourceRecommendVO> voList = resourceRecommendMapper.selectResourceRecommends(new TbResourceRecommend(), userDeptRoles);
|
||||
resultDomain.success("获取推荐列表成功", voList);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("获取推荐列表异常: {}", e.getMessage(), e);
|
||||
@@ -56,11 +63,21 @@ public class NCResourceRecommendServiceImpl implements ResourceRecommendService
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 检查资源是否已被推荐
|
||||
List<TbResourceRecommend> existingList = resourceRecommendMapper.selectByResourceId(recommend.getResourceID());
|
||||
if (existingList != null && !existingList.isEmpty()) {
|
||||
resultDomain.fail("该资源已被推荐");
|
||||
return resultDomain;
|
||||
// 检查资源是否已在该类型下被推荐
|
||||
if (recommend.getRecommendType() != null) {
|
||||
List<TbResourceRecommend> existingList = resourceRecommendMapper.selectByResourceIdAndType(
|
||||
recommend.getResourceID(), recommend.getRecommendType());
|
||||
if (existingList != null && !existingList.isEmpty()) {
|
||||
resultDomain.fail("该资源已在此类型下被推荐");
|
||||
return resultDomain;
|
||||
}
|
||||
} else {
|
||||
// 如果没有指定类型,检查是否在任何类型下已被推荐
|
||||
List<TbResourceRecommend> existingList = resourceRecommendMapper.selectByResourceId(recommend.getResourceID());
|
||||
if (existingList != null && !existingList.isEmpty()) {
|
||||
resultDomain.fail("该资源已被推荐");
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
// 设置默认值
|
||||
@@ -178,7 +195,7 @@ public class NCResourceRecommendServiceImpl implements ResourceRecommendService
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResultDomain<TbResourceRecommend> batchAddRecommends(List<String> resourceIDs, String reason) {
|
||||
public ResultDomain<TbResourceRecommend> batchAddRecommends(List<String> resourceIDs, Integer recommendType, String reason) {
|
||||
ResultDomain<TbResourceRecommend> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
// 参数验证
|
||||
@@ -195,15 +212,24 @@ public class NCResourceRecommendServiceImpl implements ResourceRecommendService
|
||||
continue;
|
||||
}
|
||||
|
||||
// 检查是否已推荐
|
||||
List<TbResourceRecommend> existingList = resourceRecommendMapper.selectByResourceId(resourceID);
|
||||
if (existingList != null && !existingList.isEmpty()) {
|
||||
continue;
|
||||
// 检查是否已在该类型下推荐
|
||||
if (recommendType != null) {
|
||||
List<TbResourceRecommend> existingList = resourceRecommendMapper.selectByResourceIdAndType(resourceID, recommendType);
|
||||
if (existingList != null && !existingList.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// 如果没有指定类型,检查是否在任何类型下已被推荐
|
||||
List<TbResourceRecommend> existingList = resourceRecommendMapper.selectByResourceId(resourceID);
|
||||
if (existingList != null && !existingList.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
TbResourceRecommend recommend = new TbResourceRecommend();
|
||||
recommend.setID(IDUtils.generateID());
|
||||
recommend.setResourceID(resourceID);
|
||||
recommend.setRecommendType(recommendType);
|
||||
recommend.setReason(reason);
|
||||
recommend.setOrderNum(0);
|
||||
recommend.setCreateTime(now);
|
||||
@@ -416,4 +442,104 @@ public class NCResourceRecommendServiceImpl implements ResourceRecommendService
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<ResourceRecommendVO> getRecommendPage(TbResourceRecommend filter, PageParam pageParam) {
|
||||
ResultDomain<ResourceRecommendVO> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
if (filter == null) {
|
||||
filter = new TbResourceRecommend();
|
||||
}
|
||||
|
||||
// 获取当前用户的部门角色(用于权限过滤)
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
|
||||
// 计算偏移量
|
||||
if (pageParam.getOffset() == 0 && pageParam.getPageNumber() > 0) {
|
||||
pageParam.setOffset((long) (pageParam.getPageNumber() - 1) * pageParam.getPageSize());
|
||||
}
|
||||
|
||||
List<ResourceRecommendVO> voList = resourceRecommendMapper.selectResourceRecommendsPage(filter, pageParam, userDeptRoles);
|
||||
long total = resourceRecommendMapper.countResourceRecommends(filter, userDeptRoles);
|
||||
|
||||
pageParam.setTotalElements(total);
|
||||
pageParam.setTotalPages((int) Math.ceil((double) total / pageParam.getPageSize()));
|
||||
|
||||
resultDomain.success("获取推荐资源分页成功", new PageDomain<ResourceRecommendVO>(pageParam, voList));
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("获取推荐资源分页异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("获取推荐资源分页失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Long> countRecommends(TbResourceRecommend filter) {
|
||||
ResultDomain<Long> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
if (filter == null) {
|
||||
filter = new TbResourceRecommend();
|
||||
}
|
||||
|
||||
// 获取当前用户的部门角色(用于权限过滤)
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
|
||||
long count = resourceRecommendMapper.countResourceRecommends(filter, userDeptRoles);
|
||||
resultDomain.success("统计成功", count);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("统计推荐资源异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("统计失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<ResourceRecommendVO> getRecommendsByType(Integer recommendType, Integer limit) {
|
||||
ResultDomain<ResourceRecommendVO> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
if (recommendType == null) {
|
||||
resultDomain.fail("推荐类型不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
// 获取当前用户的部门角色(用于权限过滤)
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
|
||||
List<ResourceRecommendVO> voList = resourceRecommendMapper.selectByRecommendType(recommendType, limit, userDeptRoles);
|
||||
|
||||
resultDomain.success("获取推荐资源列表成功", voList);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("根据类型获取推荐资源异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("获取推荐资源列表失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Boolean> isResourceRecommendedByType(String resourceID, Integer recommendType) {
|
||||
ResultDomain<Boolean> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
if (!StringUtils.hasText(resourceID)) {
|
||||
resultDomain.fail("资源ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
if (recommendType == null) {
|
||||
resultDomain.fail("推荐类型不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
List<TbResourceRecommend> recommendList = resourceRecommendMapper.selectByResourceIdAndType(resourceID, recommendType);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ 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.usercenter.collection.UserCollectionService;
|
||||
import org.xyzh.api.system.permission.ResourcePermissionService;
|
||||
import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
import org.xyzh.common.core.enums.ResourceType;
|
||||
@@ -49,9 +48,6 @@ public class NCResourceServiceImpl implements ResourceService {
|
||||
@Autowired
|
||||
private ResourceTagMapper resourceTagMapper;
|
||||
|
||||
@Autowired
|
||||
private UserCollectionService userCollectionService;
|
||||
|
||||
@Autowired
|
||||
private ResourcePermissionService resourcePermissionService;
|
||||
|
||||
@@ -98,6 +94,29 @@ public class NCResourceServiceImpl implements ResourceService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbResource> getResourcePageOrderByViewCount(TbResource filter, PageParam pageParam) {
|
||||
ResultDomain<TbResource> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
if (filter == null) {
|
||||
filter = new TbResource();
|
||||
}
|
||||
// 获取当前用户的部门角色
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbResource> list = resourceMapper.selectResourcesPageOrderByViewCount(filter, pageParam, userDeptRoles);
|
||||
long total = resourceMapper.countResources(filter, userDeptRoles);
|
||||
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
|
||||
public ResultDomain<ResourceVO> getResourceById(String resourceID) {
|
||||
ResultDomain<ResourceVO> resultDomain = new ResultDomain<>();
|
||||
@@ -560,54 +579,20 @@ public class NCResourceServiceImpl implements ResourceService {
|
||||
return resultDomain;
|
||||
}
|
||||
collection.setUserID(user.getID());
|
||||
try {
|
||||
// 参数验证
|
||||
if (!StringUtils.hasText(resourceID)) {
|
||||
resultDomain.fail("资源ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
if (collectionValue != 1 && collectionValue != -1) {
|
||||
resultDomain.fail("收藏值错误");
|
||||
return resultDomain;
|
||||
}
|
||||
ResultDomain<Boolean> isCollected = userCollectionService.isCollected(user.getID(), collection.getCollectionType(), resourceID);
|
||||
TbResource resource = new TbResource();
|
||||
resource.setResourceID(resourceID);
|
||||
if (isCollected.isSuccess() && isCollected.getData() && collectionValue == 1) {
|
||||
resultDomain.success("已收藏", resource);
|
||||
return resultDomain;
|
||||
}
|
||||
else if (isCollected.isSuccess() && isCollected.getData() && collectionValue == -1) {
|
||||
ResultDomain<Boolean> removeCollection = userCollectionService.removeCollection(collection);
|
||||
if (removeCollection.isSuccess()) {
|
||||
resourceMapper.updateResourceCollectCount(resourceID, -1);
|
||||
resultDomain.success("已取消收藏", resource);
|
||||
return resultDomain;
|
||||
} else {
|
||||
resultDomain.fail("取消收藏失败");
|
||||
return resultDomain;
|
||||
}
|
||||
}else if (isCollected.isSuccess() && !isCollected.getData() && collectionValue == 1) {
|
||||
collection.setID(IDUtils.generateID());
|
||||
collection.setCreateTime(new Date());
|
||||
ResultDomain<TbUserCollection> addCollection = userCollectionService.addCollection(collection);
|
||||
if (addCollection.isSuccess() && addCollection.getData() != null) {
|
||||
resourceMapper.updateResourceCollectCount(resourceID, 1);
|
||||
resultDomain.success("已收藏", resource);
|
||||
return resultDomain;
|
||||
} else {
|
||||
resultDomain.fail("收藏失败");
|
||||
return resultDomain;
|
||||
}
|
||||
}else {
|
||||
resultDomain.success("未收藏", resource);
|
||||
return resultDomain;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("增加资源收藏次数异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("增加收藏次数失败: " + e.getMessage());
|
||||
// 参数验证
|
||||
if (!StringUtils.hasText(resourceID)) {
|
||||
resultDomain.fail("资源ID不能为空");
|
||||
return resultDomain;
|
||||
}
|
||||
if (collectionValue != 1 && collectionValue != -1) {
|
||||
resultDomain.fail("收藏值错误");
|
||||
return resultDomain;
|
||||
}
|
||||
TbResource resource = new TbResource();
|
||||
resource.setResourceID(resourceID);
|
||||
resourceMapper.updateResourceCollectCount(resourceID, collectionValue);
|
||||
resultDomain.success("更新资源收藏次数成功", resource);
|
||||
return resultDomain;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -215,12 +215,12 @@ public class NCTagServiceImpl implements TagService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbTag> getAllTags() {
|
||||
public ResultDomain<TbTag> getTagList(TbTag filter) {
|
||||
ResultDomain<TbTag> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
// 获取当前用户的部门角色
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TbTag> tags = tagMapper.selectTags(new TbTag(), userDeptRoles);
|
||||
List<TbTag> tags = tagMapper.selectTags(filter, userDeptRoles);
|
||||
resultDomain.success("查询成功", tags);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -336,6 +336,33 @@
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<select id="selectResourcesPageOrderByViewCount" resultMap="BaseResultMap">
|
||||
SELECT DISTINCT r.*
|
||||
FROM tb_resource r
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE r.deleted = 0
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND r.title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.tagID != null and filter.tagID != ''">
|
||||
AND r.tag_id = #{filter.tagID}
|
||||
</if>
|
||||
<if test="filter.author != null and filter.author != ''">
|
||||
AND r.author LIKE CONCAT('%', #{filter.author}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND r.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.isRecommend != null">
|
||||
AND r.is_recommend = #{filter.isRecommend}
|
||||
</if>
|
||||
<if test="filter.isBanner != null">
|
||||
AND r.is_banner = #{filter.isBanner}
|
||||
</if>
|
||||
ORDER BY r.view_count DESC, r.publish_time DESC, r.create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 统计资源总数 - 添加权限过滤 -->
|
||||
<select id="countResources" resultType="long">
|
||||
SELECT COUNT(DISTINCT r.id)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.resource.TbResourceRecommend">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="resource_id" property="resourceID" jdbcType="VARCHAR"/>
|
||||
<result column="recommend_type" property="recommendType" jdbcType="INTEGER"/>
|
||||
<result column="order_num" property="orderNum" jdbcType="INTEGER"/>
|
||||
<result column="reason" property="reason" jdbcType="VARCHAR"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
@@ -16,32 +17,119 @@
|
||||
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- ResourceRecommendVO结果映射(包含资源信息和权限信息) -->
|
||||
<resultMap id="ResourceRecommendVOResultMap" type="org.xyzh.common.vo.ResourceRecommendVO">
|
||||
<!-- 推荐表字段 -->
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="resource_id" property="resourceID" jdbcType="VARCHAR"/>
|
||||
<result column="recommend_type" property="recommendType" jdbcType="INTEGER"/>
|
||||
<result column="order_num" property="orderNum" jdbcType="INTEGER"/>
|
||||
<result column="reason" property="reason" jdbcType="VARCHAR"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
|
||||
<!-- 资源表字段 -->
|
||||
<result column="title" property="title" jdbcType="VARCHAR"/>
|
||||
<result column="summary" property="summary" jdbcType="VARCHAR"/>
|
||||
<result column="cover_image" property="coverImage" jdbcType="VARCHAR"/>
|
||||
<result column="tag_id" property="tagID" jdbcType="VARCHAR"/>
|
||||
<result column="author" property="author" jdbcType="VARCHAR"/>
|
||||
<result column="source" property="source" jdbcType="VARCHAR"/>
|
||||
<result column="source_url" property="sourceUrl" jdbcType="VARCHAR"/>
|
||||
<result column="view_count" property="viewCount" jdbcType="INTEGER"/>
|
||||
<result column="like_count" property="likeCount" jdbcType="INTEGER"/>
|
||||
<result column="collect_count" property="collectCount" jdbcType="INTEGER"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="is_recommend" property="isRecommend" jdbcType="BOOLEAN"/>
|
||||
<result column="is_banner" property="isBanner" jdbcType="BOOLEAN"/>
|
||||
<result column="publish_time" property="publishTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="resource_creator" property="resourceCreator" jdbcType="VARCHAR"/>
|
||||
<result column="resource_updater" property="resourceUpdater" jdbcType="VARCHAR"/>
|
||||
<result column="resource_create_time" property="resourceCreateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="resource_update_time" property="resourceUpdateTime" jdbcType="TIMESTAMP"/>
|
||||
<!-- 权限字段 -->
|
||||
<result column="can_read" property="canRead" jdbcType="TINYINT"/>
|
||||
<result column="can_write" property="canWrite" jdbcType="TINYINT"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, resource_id, order_num, reason, creator, updater, create_time,
|
||||
id, resource_id, recommend_type, order_num, reason, creator, updater, create_time,
|
||||
update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
<sql id="Where_Clause">
|
||||
<where>
|
||||
deleted = 0
|
||||
<if test="resourceID != null and resourceID != ''">
|
||||
AND resource_id = #{resourceID}
|
||||
</if>
|
||||
<if test="reason != null and reason != ''">
|
||||
AND reason LIKE CONCAT('%', #{reason}, '%')
|
||||
rr.deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.id != null and filter.id != ''">
|
||||
AND rr.id = #{filter.id}
|
||||
</if>
|
||||
<if test="filter.resourceID != null and filter.resourceID != ''">
|
||||
AND rr.resource_id = #{filter.resourceID}
|
||||
</if>
|
||||
<if test="filter.recommendType != null">
|
||||
AND rr.recommend_type = #{filter.recommendType}
|
||||
</if>
|
||||
<if test="filter.reason != null and filter.reason != ''">
|
||||
AND rr.reason LIKE CONCAT('%', #{filter.reason}, '%')
|
||||
</if>
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectResourceRecommends -->
|
||||
<select id="selectResourceRecommends" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_resource_recommend
|
||||
<!-- 权限过滤条件(基于dept_path的高效继承,注意:需要先JOIN tb_resource表) -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_resource_permission rp ON r.resource_id = rp.resource_id
|
||||
AND rp.resource_type = 1
|
||||
AND rp.deleted = 0
|
||||
AND rp.can_read = 1
|
||||
AND (
|
||||
-- 全局权限:所有用户可访问
|
||||
(rp.dept_id IS NULL AND rp.role_id IS NULL)
|
||||
<if test="userDeptRoles != null and userDeptRoles.size() > 0">
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM (
|
||||
<foreach collection="userDeptRoles" item="udr" separator=" UNION ALL ">
|
||||
SELECT #{udr.deptID} AS dept_id, #{udr.deptPath} AS dept_path, #{udr.roleID} AS role_id
|
||||
</foreach>
|
||||
) user_roles
|
||||
LEFT JOIN tb_sys_dept perm_dept ON perm_dept.dept_id = rp.dept_id AND perm_dept.deleted = 0
|
||||
WHERE
|
||||
(rp.role_id IS NULL AND rp.dept_id IS NOT NULL
|
||||
AND user_roles.dept_path LIKE CONCAT(perm_dept.dept_path, '%'))
|
||||
OR (rp.dept_id IS NULL AND rp.role_id = user_roles.role_id)
|
||||
OR (rp.dept_id = user_roles.dept_id AND rp.role_id = user_roles.role_id)
|
||||
)
|
||||
</if>
|
||||
)
|
||||
</sql>
|
||||
|
||||
<!-- selectResourceRecommends - 返回VO,包含资源信息和权限 -->
|
||||
<select id="selectResourceRecommends" resultMap="ResourceRecommendVOResultMap">
|
||||
SELECT DISTINCT
|
||||
rr.id, rr.resource_id, rr.recommend_type, rr.order_num, rr.reason,
|
||||
rr.creator, rr.updater, rr.create_time, rr.update_time, rr.delete_time, rr.deleted,
|
||||
r.title, r.summary, r.cover_image, r.tag_id, r.author, r.source, r.source_url,
|
||||
r.view_count, r.like_count, r.collect_count, r.status, r.is_recommend, r.is_banner,
|
||||
r.publish_time, r.creator AS resource_creator, r.updater AS resource_updater,
|
||||
r.create_time AS resource_create_time, r.update_time AS resource_update_time,
|
||||
MAX(rp.can_read) AS can_read, MAX(rp.can_write) AS can_write
|
||||
FROM tb_resource_recommend rr
|
||||
INNER JOIN tb_resource r ON rr.resource_id = r.resource_id AND r.deleted = 0
|
||||
<include refid="Permission_Filter"/>
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
GROUP BY rr.id, rr.resource_id, rr.recommend_type, rr.order_num, rr.reason,
|
||||
rr.creator, rr.updater, rr.create_time, rr.update_time, rr.delete_time, rr.deleted,
|
||||
r.title, r.summary, r.cover_image, r.tag_id, r.author, r.source, r.source_url,
|
||||
r.view_count, r.like_count, r.collect_count, r.status, r.is_recommend, r.is_banner,
|
||||
r.publish_time, r.creator, r.updater, r.create_time, r.update_time
|
||||
ORDER BY rr.order_num ASC, rr.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据推荐ID查询推荐信息 -->
|
||||
@@ -70,12 +158,43 @@
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据类型查询推荐列表 -->
|
||||
<select id="selectByType" resultMap="BaseResultMap">
|
||||
<!-- 根据推荐类型查询推荐列表 - 返回VO,包含资源信息和权限 -->
|
||||
<select id="selectByRecommendType" resultMap="ResourceRecommendVOResultMap">
|
||||
SELECT DISTINCT
|
||||
rr.id, rr.resource_id, rr.recommend_type, rr.order_num, rr.reason,
|
||||
rr.creator, rr.updater, rr.create_time, rr.update_time, rr.delete_time, rr.deleted,
|
||||
r.title, r.summary, r.cover_image, r.tag_id, r.author, r.source, r.source_url,
|
||||
r.view_count, r.like_count, r.collect_count, r.status, r.is_recommend, r.is_banner,
|
||||
r.publish_time, r.creator AS resource_creator, r.updater AS resource_updater,
|
||||
r.create_time AS resource_create_time, r.update_time AS resource_update_time,
|
||||
MAX(rp.can_read) AS can_read, MAX(rp.can_write) AS can_write
|
||||
FROM tb_resource_recommend rr
|
||||
INNER JOIN tb_resource r ON rr.resource_id = r.resource_id AND r.deleted = 0
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE rr.deleted = 0
|
||||
<if test="recommendType != null">
|
||||
AND rr.recommend_type = #{recommendType}
|
||||
</if>
|
||||
GROUP BY rr.id, rr.resource_id, rr.recommend_type, rr.order_num, rr.reason,
|
||||
rr.creator, rr.updater, rr.create_time, rr.update_time, rr.delete_time, rr.deleted,
|
||||
r.title, r.summary, r.cover_image, r.tag_id, r.author, r.source, r.source_url,
|
||||
r.view_count, r.like_count, r.collect_count, r.status, r.is_recommend, r.is_banner,
|
||||
r.publish_time, r.creator, r.updater, r.create_time, r.update_time
|
||||
ORDER BY rr.order_num ASC, rr.create_time DESC
|
||||
<if test="limit != null and limit > 0">
|
||||
LIMIT #{limit}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 根据资源ID和推荐类型查询 -->
|
||||
<select id="selectByResourceIdAndType" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_resource_recommend
|
||||
WHERE deleted = 0
|
||||
WHERE resource_id = #{resourceId} AND deleted = 0
|
||||
<if test="recommendType != null">
|
||||
AND recommend_type = #{recommendType}
|
||||
</if>
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
</select>
|
||||
|
||||
@@ -106,10 +225,10 @@
|
||||
<!-- 插入资源推荐 -->
|
||||
<insert id="insertResourceRecommend" parameterType="org.xyzh.common.dto.resource.TbResourceRecommend">
|
||||
INSERT INTO tb_resource_recommend (
|
||||
id, resource_id, order_num, reason, creator, updater, create_time,
|
||||
id, resource_id, recommend_type, order_num, reason, creator, updater, create_time,
|
||||
update_time, delete_time, deleted
|
||||
) VALUES (
|
||||
#{id}, #{resourceID}, #{orderNum}, #{reason}, #{creator}, #{updater}, #{createTime},
|
||||
#{id}, #{resourceID}, #{recommendType}, #{orderNum}, #{reason}, #{creator}, #{updater}, #{createTime},
|
||||
#{updateTime}, #{deleteTime}, #{deleted}
|
||||
)
|
||||
</insert>
|
||||
@@ -121,6 +240,9 @@
|
||||
<if test="resourceID != null and resourceID != ''">
|
||||
resource_id = #{resourceID},
|
||||
</if>
|
||||
<if test="recommendType != null">
|
||||
recommend_type = #{recommendType},
|
||||
</if>
|
||||
<if test="orderNum != null">
|
||||
order_num = #{orderNum},
|
||||
</if>
|
||||
@@ -152,12 +274,12 @@
|
||||
<!-- 批量插入资源推荐 -->
|
||||
<insert id="batchInsertResourceRecommends" parameterType="java.util.List">
|
||||
INSERT INTO tb_resource_recommend (
|
||||
id, resource_id, order_num, reason, creator, updater, create_time,
|
||||
id, resource_id, recommend_type, order_num, reason, creator, updater, create_time,
|
||||
update_time, delete_time, deleted
|
||||
) VALUES
|
||||
<foreach collection="resourceRecommendList" item="item" separator=",">
|
||||
(
|
||||
#{item.id}, #{item.resourceID}, #{item.orderNum}, #{item.reason}, #{item.creator},
|
||||
#{item.id}, #{item.resourceID}, #{item.recommendType}, #{item.orderNum}, #{item.reason}, #{item.creator},
|
||||
#{item.updater}, #{item.createTime}, #{item.updateTime}, #{item.deleteTime}, #{item.deleted}
|
||||
)
|
||||
</foreach>
|
||||
@@ -172,21 +294,37 @@
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- 分页查询资源推荐 -->
|
||||
<select id="selectResourceRecommendsPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List" />
|
||||
FROM tb_resource_recommend
|
||||
<!-- 分页查询资源推荐 - 返回VO,包含资源信息和权限 -->
|
||||
<select id="selectResourceRecommendsPage" resultMap="ResourceRecommendVOResultMap">
|
||||
SELECT DISTINCT
|
||||
rr.id, rr.resource_id, rr.recommend_type, rr.order_num, rr.reason,
|
||||
rr.creator, rr.updater, rr.create_time, rr.update_time, rr.delete_time, rr.deleted,
|
||||
r.title, r.summary, r.cover_image, r.tag_id, r.author, r.source, r.source_url,
|
||||
r.view_count, r.like_count, r.collect_count, r.status, r.is_recommend, r.is_banner,
|
||||
r.publish_time, r.creator AS resource_creator, r.updater AS resource_updater,
|
||||
r.create_time AS resource_create_time, r.update_time AS resource_update_time,
|
||||
MAX(rp.can_read) AS can_read, MAX(rp.can_write) AS can_write
|
||||
FROM tb_resource_recommend rr
|
||||
INNER JOIN tb_resource r ON rr.resource_id = r.resource_id AND r.deleted = 0
|
||||
<include refid="Permission_Filter"/>
|
||||
<include refid="Where_Clause" />
|
||||
ORDER BY order_num ASC, create_time DESC
|
||||
GROUP BY rr.id, rr.resource_id, rr.recommend_type, rr.order_num, rr.reason,
|
||||
rr.creator, rr.updater, rr.create_time, rr.update_time, rr.delete_time, rr.deleted,
|
||||
r.title, r.summary, r.cover_image, r.tag_id, r.author, r.source, r.source_url,
|
||||
r.view_count, r.like_count, r.collect_count, r.status, r.is_recommend, r.is_banner,
|
||||
r.publish_time, r.creator, r.updater, r.create_time, r.update_time
|
||||
ORDER BY rr.order_num ASC, rr.create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 统计资源推荐总数 -->
|
||||
<!-- 统计资源推荐总数 - 添加权限过滤 -->
|
||||
<select id="countResourceRecommends" resultType="long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_resource_recommend
|
||||
SELECT COUNT(DISTINCT rr.id)
|
||||
FROM tb_resource_recommend rr
|
||||
INNER JOIN tb_resource r ON rr.resource_id = r.resource_id AND r.deleted = 0
|
||||
<include refid="Permission_Filter"/>
|
||||
<include refid="Where_Clause" />
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user