搜索、小助手推荐位
This commit is contained in:
@@ -131,6 +131,7 @@ INSERT INTO `tb_sys_menu` VALUES
|
||||
('500', 'menu_profile', '账号中心', 'menu_user_dropdown', '/profile', 'user/profile/ProfileView', NULL, 5, 1, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:49:56', NULL, 0),
|
||||
('501', 'menu_personal_info', '个人信息', 'menu_profile', '/profile/personal-info', 'user/profile/PersonalInfoView', NULL, 1, 0, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:48:39', NULL, 0),
|
||||
('502', 'menu_account_settings', '账号设置', 'menu_profile', '/profile/account-settings', 'user/profile/AccountSettingsView', NULL, 2, 0, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:48:39', NULL, 0),
|
||||
('503', 'menu_search', '搜索', NULL, '/search', 'user/resource-center/SearchView', NULL, 3, 0, 'NavigationLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:48:39', NULL, 0),
|
||||
-- 管理后台菜单 (1000-8999)
|
||||
('1000', 'menu_admin_overview', '系统总览', NULL, '/admin/overview', 'admin/overview/SystemOverviewView', 'admin/overview.svg', 1, 0, 'SidebarLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:52:32', NULL, 0),
|
||||
('2000', 'menu_sys_manage', '系统管理', NULL, '', '', 'admin/settings.svg', 2, 0, 'SidebarLayout', '1', NULL, '2025-10-27 17:26:06', '2025-10-29 11:52:35', NULL, 0),
|
||||
@@ -191,7 +192,7 @@ INSERT INTO `tb_sys_menu_permission` (id, permission_id, menu_id, creator, creat
|
||||
('122', 'perm_default', 'menu_course_detail', '1', now()),
|
||||
('123', 'perm_default', 'menu_course_study', '1', now()),
|
||||
('124', 'perm_default', 'menu_article_show', '1', now()),
|
||||
|
||||
('125', 'perm_default', 'menu_search', '1', now()),
|
||||
|
||||
-- 后端管理菜单权限关联
|
||||
('200', 'perm_system_manage', 'menu_admin_overview', '1', now()),
|
||||
|
||||
@@ -2,9 +2,11 @@ package org.xyzh.api.news.resource;
|
||||
|
||||
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.usercenter.TbUserCollection;
|
||||
import org.xyzh.common.vo.ResourceVO;
|
||||
import org.xyzh.common.vo.TaskItemVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -186,4 +188,12 @@ public interface ResourceService {
|
||||
|
||||
ResultDomain<Integer> getResourceCount(TbResource filter);
|
||||
|
||||
/**
|
||||
* @description 搜索资源
|
||||
* @param filter 过滤条件
|
||||
* @return ResultDomain<TaskItemVO> 搜索结果
|
||||
* @author yslg
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
ResultDomain<TaskItemVO> searchItem(PageRequest<TbResource> filter);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,13 @@ public class TaskItemVO extends TbLearningTask {
|
||||
private Integer status;
|
||||
private BigDecimal progress;
|
||||
private Date completeTime;
|
||||
|
||||
// 搜索结果展示字段
|
||||
private String coverImage;
|
||||
private String summary;
|
||||
private String author;
|
||||
private Integer viewCount;
|
||||
private Date publishTime;
|
||||
|
||||
public String getDeptID() {
|
||||
return deptID;
|
||||
@@ -183,5 +190,35 @@ public class TaskItemVO extends TbLearningTask {
|
||||
this.completeTime = completeTime;
|
||||
}
|
||||
|
||||
|
||||
// 搜索结果展示字段的 getter 和 setter
|
||||
public String getCoverImage() {
|
||||
return coverImage;
|
||||
}
|
||||
public void setCoverImage(String coverImage) {
|
||||
this.coverImage = coverImage;
|
||||
}
|
||||
public String getSummary() {
|
||||
return summary;
|
||||
}
|
||||
public void setSummary(String summary) {
|
||||
this.summary = summary;
|
||||
}
|
||||
public String getAuthor() {
|
||||
return author;
|
||||
}
|
||||
public void setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
public Integer getViewCount() {
|
||||
return viewCount;
|
||||
}
|
||||
public void setViewCount(Integer viewCount) {
|
||||
this.viewCount = viewCount;
|
||||
}
|
||||
public Date getPublishTime() {
|
||||
return publishTime;
|
||||
}
|
||||
public void setPublishTime(Date publishTime) {
|
||||
this.publishTime = publishTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.xyzh.common.dto.user.TbSysUser;
|
||||
import org.xyzh.common.dto.usercenter.TbUserCollection;
|
||||
import org.xyzh.common.utils.TimeUtils;
|
||||
import org.xyzh.common.vo.ResourceVO;
|
||||
import org.xyzh.common.vo.TaskItemVO;
|
||||
import org.xyzh.system.utils.LoginUtil;
|
||||
/**
|
||||
* @description 资源控制器
|
||||
@@ -192,4 +193,9 @@ public class ResourceController {
|
||||
@RequestParam(value = "status", required = false) Integer status) {
|
||||
return resourceService.searchResources(keyword, tagID, status);
|
||||
}
|
||||
|
||||
@PostMapping("/search")
|
||||
public ResultDomain<TaskItemVO> searchResources(@RequestBody PageRequest<TbResource> filter) {
|
||||
return resourceService.searchItem(filter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.dto.resource.TbResource;
|
||||
import org.xyzh.common.vo.ResourceVO;
|
||||
import org.xyzh.common.vo.TaskItemVO;
|
||||
import org.xyzh.common.vo.UserDeptRoleVO;
|
||||
|
||||
import java.util.List;
|
||||
@@ -205,4 +206,6 @@ public interface ResourceMapper extends BaseMapper<TbResource> {
|
||||
* @since 2025-10-15
|
||||
*/
|
||||
int incrementViewCount(@Param("resourceID") String resourceID);
|
||||
|
||||
List<TaskItemVO> selectItem(@Param("filter") TbResource filter, @Param("pageParam") PageParam pageParam, @Param("userDeptRoles") List<UserDeptRoleVO> userDeptRoles);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ 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.core.page.PageRequest;
|
||||
import org.xyzh.common.dto.resource.TbResource;
|
||||
import org.xyzh.common.dto.resource.TbResourceTag;
|
||||
import org.xyzh.common.dto.resource.TbTag;
|
||||
@@ -17,6 +18,7 @@ import org.xyzh.common.dto.usercenter.TbUserCollection;
|
||||
import org.xyzh.common.utils.IDUtils;
|
||||
import org.xyzh.common.vo.ResourceVO;
|
||||
import org.xyzh.common.vo.TagVO;
|
||||
import org.xyzh.common.vo.TaskItemVO;
|
||||
import org.xyzh.news.mapper.ResourceMapper;
|
||||
import org.xyzh.news.mapper.ResourceTagMapper;
|
||||
import org.xyzh.system.utils.LoginUtil;
|
||||
@@ -771,4 +773,23 @@ public class NCResourceServiceImpl implements ResourceService {
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TaskItemVO> searchItem(PageRequest<TbResource> filter) {
|
||||
ResultDomain<TaskItemVO> resultDomain = new ResultDomain<>();
|
||||
try {
|
||||
List<UserDeptRoleVO> userDeptRoles = LoginUtil.getCurrentDeptRole();
|
||||
List<TaskItemVO> list = resourceMapper.selectItem(filter.getFilter(), filter.getPageParam(), userDeptRoles);
|
||||
if (list == null || list.isEmpty()) {
|
||||
resultDomain.fail("搜索资源失败: 没有找到资源");
|
||||
return resultDomain;
|
||||
}
|
||||
resultDomain.success("搜索资源成功", list);
|
||||
return resultDomain;
|
||||
} catch (Exception e) {
|
||||
logger.error("搜索资源异常: {}", e.getMessage(), e);
|
||||
resultDomain.fail("搜索资源失败: " + e.getMessage());
|
||||
return resultDomain;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,6 +323,9 @@
|
||||
<if test="filter.author != null and filter.author != ''">
|
||||
AND r.author LIKE CONCAT('%', #{filter.author}, '%')
|
||||
</if>
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND r.title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND r.status = #{filter.status}
|
||||
</if>
|
||||
@@ -451,4 +454,116 @@
|
||||
</update>
|
||||
|
||||
|
||||
<!-- selectItem -->
|
||||
<!-- 联合模糊查询文章和课程,时间排序 -->
|
||||
<select id="selectItem" resultType="org.xyzh.common.vo.TaskItemVO">
|
||||
SELECT * FROM (
|
||||
-- 查询文章资源
|
||||
SELECT DISTINCT
|
||||
1 AS itemType,
|
||||
r.resource_id AS resourceID,
|
||||
r.title AS resourceName,
|
||||
NULL AS courseID,
|
||||
NULL AS courseName,
|
||||
r.author,
|
||||
r.cover_image AS coverImage,
|
||||
r.summary,
|
||||
r.view_count AS viewCount,
|
||||
r.publish_time AS publishTime,
|
||||
r.create_time AS createTime
|
||||
FROM tb_resource r
|
||||
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
|
||||
-- 部门级权限:当前部门或父部门(通过dept_path判断继承关系)
|
||||
(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>
|
||||
)
|
||||
WHERE r.deleted = 0
|
||||
<if test="filter.status != null">
|
||||
AND r.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND (r.title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
OR r.summary LIKE CONCAT('%', #{filter.title}, '%'))
|
||||
</if>
|
||||
|
||||
UNION ALL
|
||||
|
||||
-- 查询课程资源
|
||||
SELECT DISTINCT
|
||||
2 AS itemType,
|
||||
NULL AS resourceID,
|
||||
NULL AS resourceName,
|
||||
c.course_id AS courseID,
|
||||
c.name AS courseName,
|
||||
c.teacher AS author,
|
||||
c.cover_image AS coverImage,
|
||||
c.description AS summary,
|
||||
c.view_count AS viewCount,
|
||||
NULL AS publishTime,
|
||||
c.create_time AS createTime
|
||||
FROM tb_course c
|
||||
INNER JOIN tb_resource_permission rp ON c.course_id = rp.resource_id
|
||||
AND rp.resource_type = 2
|
||||
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
|
||||
-- 部门级权限:当前部门或父部门(通过dept_path判断继承关系)
|
||||
(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>
|
||||
)
|
||||
WHERE c.deleted = 0
|
||||
<if test="filter.status != null">
|
||||
AND c.status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND (c.name LIKE CONCAT('%', #{filter.title}, '%')
|
||||
OR c.description LIKE CONCAT('%', #{filter.title}, '%'))
|
||||
</if>
|
||||
) AS combined_results
|
||||
-- 按时间倒序排列,优先使用发布时间,其次使用创建时间
|
||||
ORDER BY COALESCE(publishTime, createTime) DESC
|
||||
<if test="pageParam != null">
|
||||
LIMIT #{pageParam.offset}, #{pageParam.pageSize}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
@@ -237,8 +237,8 @@
|
||||
lr.complete_time AS complete_time
|
||||
FROM tb_learning_record lr
|
||||
LEFT JOIN tb_resource r ON lr.resource_type = 1 AND lr.resource_id = r.resource_id
|
||||
LEFT JOIN tb_course c ON lr.resource_type = 2 AND lr.course_id = c.id
|
||||
LEFT JOIN tb_course_chapter ch ON lr.resource_type = 3 AND lr.chapter_id = ch.id
|
||||
LEFT JOIN tb_course c ON lr.resource_type = 2 AND lr.course_id = c.course_id
|
||||
LEFT JOIN tb_course_chapter ch ON lr.resource_type = 3 AND lr.chapter_id = ch.chapter_id
|
||||
<where>
|
||||
<if test="filter.userID != null and filter.userID != ''">
|
||||
AND lr.user_id = #{filter.userID}
|
||||
|
||||
Reference in New Issue
Block a user