From 9824a7d686583ab4cbdc1f04a3021edba286b574 Mon Sep 17 00:00:00 2001 From: wangys <3401275564@qq.com> Date: Tue, 21 Oct 2025 16:21:19 +0800 Subject: [PATCH] =?UTF-8?q?serv-=E5=AD=A6=E4=B9=A0=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../.bin/mysql/sql/createTableCourse.sql | 32 ++- .../.bin/mysql/sql/initMenuData.sql | 21 +- schoolNewsServ/.gitignore | 2 +- .../admin/src/main/resources/application.yml | 7 + .../api/news/resource/ResourceService.java | 5 +- .../xyzh/api/study/course/CourseService.java | 16 +- .../common/dto/study/TbCourseChapter.java | 54 ++++ .../xyzh/common/dto/study/TbCourseNode.java | 186 ++++++++++++++ .../dto/usercenter/TbUserCollection.java | 14 + .../java/org/xyzh/common/vo/ChapterVO.java | 35 +++ .../java/org/xyzh/common/vo/CourseVO.java | 39 +++ schoolNewsServ/news/pom.xml | 5 + .../news/controller/ResourceController.java | 8 +- .../org/xyzh/news/mapper/ResourceMapper.java | 10 + .../service/impl/NCResourceServiceImpl.java | 66 +++-- .../main/resources/mapper/ResourceMapper.xml | 7 + schoolNewsServ/study/pom.xml | 6 +- .../study/controller/CourseController.java | 77 ++---- .../CourseManagementController.java | 176 ------------- .../xyzh/study/mapper/CourseNodeMapper.java | 166 ++++++++++++ .../service/impl/SCCourseServiceImpl.java | 138 +++++++++- .../resources/mapper/CourseChapterMapper.xml | 44 +++- .../main/resources/mapper/CourseMapper.xml | 35 ++- .../resources/mapper/CourseNodeMapper.xml | 239 ++++++++++++++++++ .../mapper/UserCollectionMapper.java | 8 +- .../impl/UCUserCollectionServiceImpl.java | 78 +++++- .../resources/mapper/UserCollectionMapper.xml | 54 ++-- 27 files changed, 1192 insertions(+), 336 deletions(-) create mode 100644 schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/study/TbCourseNode.java create mode 100644 schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/ChapterVO.java create mode 100644 schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/CourseVO.java delete mode 100644 schoolNewsServ/study/src/main/java/org/xyzh/study/controller/CourseManagementController.java create mode 100644 schoolNewsServ/study/src/main/java/org/xyzh/study/mapper/CourseNodeMapper.java create mode 100644 schoolNewsServ/study/src/main/resources/mapper/CourseNodeMapper.xml diff --git a/schoolNewsServ/.bin/mysql/sql/createTableCourse.sql b/schoolNewsServ/.bin/mysql/sql/createTableCourse.sql index 32659f8..1ed6292 100644 --- a/schoolNewsServ/.bin/mysql/sql/createTableCourse.sql +++ b/schoolNewsServ/.bin/mysql/sql/createTableCourse.sql @@ -29,10 +29,14 @@ CREATE TABLE `tb_course` ( -- 课程章节表 DROP TABLE IF EXISTS `tb_course_chapter`; CREATE TABLE `tb_course_chapter` ( - `id` VARCHAR(50) NOT NULL COMMENT '章节ID', + `id` VARCHAR(50) NOT NULL COMMENT 'ID', + `chapter_id` VARCHAR(50) NOT NULL COMMENT '章节唯一标识', `course_id` VARCHAR(50) NOT NULL COMMENT '课程ID', + `parent_id` VARCHAR(50) DEFAULT NULL COMMENT '父章节ID', `name` VARCHAR(255) NOT NULL COMMENT '章节名称', `content` LONGTEXT COMMENT '章节内容', + `chapter_type` INT(4) DEFAULT 0 COMMENT '章节类型(1视频 2文档 3音频)', + `resource_id` VARCHAR(50) DEFAULT NULL COMMENT '资源ID', `video_url` VARCHAR(500) DEFAULT NULL COMMENT '视频URL', `duration` INT(11) DEFAULT 0 COMMENT '章节时长(分钟)', `order_num` INT(4) DEFAULT 0 COMMENT '排序号', @@ -44,6 +48,7 @@ CREATE TABLE `tb_course_chapter` ( `deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否删除', PRIMARY KEY (`id`), KEY `idx_course` (`course_id`), + KEY `idx_parent` (`parent_id`), KEY `idx_order` (`order_num`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='课程章节表'; @@ -61,3 +66,28 @@ CREATE TABLE `tb_course_tag` ( KEY `idx_tag` (`tag_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='课程标签关联表'; +-- 学习节点表 +DROP TABLE IF EXISTS `tb_course_node`; +CREATE TABLE `tb_course_node` ( + `id` VARCHAR(50) NOT NULL COMMENT '节点ID', + `chapter_id` VARCHAR(50) NOT NULL COMMENT '章节ID', + `node_id` VARCHAR(50) NOT NULL COMMENT '节点唯一标识', + `name` VARCHAR(255) NOT NULL COMMENT '节点名称', + `content` LONGTEXT COMMENT '节点内容', + `node_type` INT(4) DEFAULT 1 COMMENT '节点类型(0文章资源 1富文本 2其他上传文件)', + `resource_id` VARCHAR(50) DEFAULT NULL COMMENT '资源ID', + `video_url` VARCHAR(500) DEFAULT NULL COMMENT '视频URL', + `duration` INT(11) DEFAULT 0 COMMENT '节点时长(分钟)', + `order_num` INT(4) DEFAULT 0 COMMENT '排序号', + `is_required` TINYINT(1) DEFAULT 1 COMMENT '是否必修(1必修 0选修)', + `creator` VARCHAR(50) DEFAULT NULL COMMENT '创建者', + `updater` VARCHAR(50) DEFAULT NULL COMMENT '更新者', + `create_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', + `update_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + `delete_time` TIMESTAMP NULL DEFAULT NULL COMMENT '删除时间', + `deleted` TINYINT(1) NOT NULL DEFAULT 0 COMMENT '是否删除', + PRIMARY KEY (`id`), + KEY `idx_chapter` (`chapter_id`), + KEY `idx_order` (`order_num`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='学习节点表'; + diff --git a/schoolNewsServ/.bin/mysql/sql/initMenuData.sql b/schoolNewsServ/.bin/mysql/sql/initMenuData.sql index adc1952..02cd1cd 100644 --- a/schoolNewsServ/.bin/mysql/sql/initMenuData.sql +++ b/schoolNewsServ/.bin/mysql/sql/initMenuData.sql @@ -122,7 +122,7 @@ INSERT INTO `tb_sys_menu` (id, menu_id, name, parent_id, url, component, icon, o ('5001', 'menu_admin_study', '学习管理', 'menu_admin_study_manage', '/admin/manage/study/study', 'admin/manage/study/StudyManagementView', 'el-icon-reading', 1, 1, 'NavigationLayout', '1', now()), ('5002', 'menu_admin_task_publish', '任务发布', 'menu_admin_study_manage', '/admin/manage/study/task-publish', 'admin/manage/study/TaskPublishView', 'el-icon-s-order', 2, 1, 'NavigationLayout', '1', now()), ('5003', 'menu_admin_study_records', '学习记录', 'menu_admin_study_manage', '/admin/manage/study/study-records', 'admin/manage/study/StudyRecordsView', 'el-icon-document', 3, 1, 'NavigationLayout', '1', now()), - +('5004', 'menu_admin_course_manage', '课程管理', 'menu_admin_study_manage', '/admin/manage/study/course', 'admin/manage/study/CourseManagementView', 'el-icon-video-play', 4, 1, 'NavigationLayout', '1', now()), -- 智能体管理 ('6000', 'menu_admin_ai_manage', '智能体管理', NULL, '', '', 'el-icon-cpu', 6, 1, '', '1', now()), ('6001', 'menu_admin_ai', 'AI管理', 'menu_admin_ai_manage', '/admin/manage/ai/ai', 'admin/manage/ai/AIManagementView', 'el-icon-cpu', 1, 1, 'NavigationLayout', '1', now()), @@ -178,12 +178,13 @@ INSERT INTO `tb_sys_menu_permission` (id, permission_id, menu_id, creator, creat ('219', 'perm_study_manage', 'menu_admin_study', '1', now()), ('220', 'perm_study_manage', 'menu_admin_task_publish', '1', now()), ('221', 'perm_study_manage', 'menu_admin_study_records', '1', now()), -('222', 'perm_ai_manage', 'menu_admin_ai_manage', '1', now()), -('223', 'perm_ai_manage', 'menu_admin_ai', '1', now()), -('224', 'perm_ai_manage', 'menu_admin_ai_config', '1', now()), -('225', 'perm_ai_manage', 'menu_admin_knowledge', '1', now()), -('226', 'perm_system_manage', 'menu_admin_logs_manage', '1', now()), -('227', 'perm_system_manage', 'menu_admin_system_logs', '1', now()), -('228', 'perm_system_manage', 'menu_admin_login_logs', '1', now()), -('229', 'perm_system_manage', 'menu_admin_operation_logs', '1', now()), -('230', 'perm_system_manage', 'menu_admin_system_config', '1', now()); +('222', 'perm_study_manage', 'menu_admin_course_manage', '1', now()), +('223', 'perm_ai_manage', 'menu_admin_ai_manage', '1', now()), +('224', 'perm_ai_manage', 'menu_admin_ai', '1', now()), +('225', 'perm_ai_manage', 'menu_admin_ai_config', '1', now()), +('226', 'perm_ai_manage', 'menu_admin_knowledge', '1', now()), +('227', 'perm_system_manage', 'menu_admin_logs_manage', '1', now()), +('228', 'perm_system_manage', 'menu_admin_system_logs', '1', now()), +('229', 'perm_system_manage', 'menu_admin_login_logs', '1', now()), +('230', 'perm_system_manage', 'menu_admin_operation_logs', '1', now()), +('231', 'perm_system_manage', 'menu_admin_system_config', '1', now()); diff --git a/schoolNewsServ/.gitignore b/schoolNewsServ/.gitignore index c837e95..31558ff 100644 --- a/schoolNewsServ/.gitignore +++ b/schoolNewsServ/.gitignore @@ -9,7 +9,7 @@ HELP.md !**/src/test/**/target/ !**/uploads/** admin/uploads/** - +uploads ### Logs ### **/logs/ *.log diff --git a/schoolNewsServ/admin/src/main/resources/application.yml b/schoolNewsServ/admin/src/main/resources/application.yml index d6f4102..5faa0cb 100644 --- a/schoolNewsServ/admin/src/main/resources/application.yml +++ b/schoolNewsServ/admin/src/main/resources/application.yml @@ -77,6 +77,13 @@ school-news: - "/file/download/**" +# 文件存储配置 +file: + storage: + storages: + - type: local + enabled: true + base-path: ../uploads # MyBatis Plus配置 mybatis-plus: diff --git a/schoolNewsServ/api/api-news/src/main/java/org/xyzh/api/news/resource/ResourceService.java b/schoolNewsServ/api/api-news/src/main/java/org/xyzh/api/news/resource/ResourceService.java index 7eb2e13..cf4ef0e 100644 --- a/schoolNewsServ/api/api-news/src/main/java/org/xyzh/api/news/resource/ResourceService.java +++ b/schoolNewsServ/api/api-news/src/main/java/org/xyzh/api/news/resource/ResourceService.java @@ -3,6 +3,7 @@ package org.xyzh.api.news.resource; import org.xyzh.common.core.domain.ResultDomain; import org.xyzh.common.core.page.PageParam; import org.xyzh.common.dto.resource.TbResource; +import org.xyzh.common.dto.usercenter.TbUserCollection; import org.xyzh.common.vo.ResourceVO; import java.util.List; @@ -117,13 +118,13 @@ public interface ResourceService { ResultDomain incrementLikeCount(String resourceID); /** - * @description 增加收藏次数 + * @description 收藏次数加减 * @param resourceID 资源ID * @return ResultDomain 更新结果 * @author yslg * @since 2025-10-15 */ - ResultDomain incrementCollectCount(String resourceID); + ResultDomain resourceCollect(TbUserCollection collection); /** * @description 设置资源推荐 diff --git a/schoolNewsServ/api/api-study/src/main/java/org/xyzh/api/study/course/CourseService.java b/schoolNewsServ/api/api-study/src/main/java/org/xyzh/api/study/course/CourseService.java index d2b2f58..6ba7941 100644 --- a/schoolNewsServ/api/api-study/src/main/java/org/xyzh/api/study/course/CourseService.java +++ b/schoolNewsServ/api/api-study/src/main/java/org/xyzh/api/study/course/CourseService.java @@ -1,8 +1,11 @@ package org.xyzh.api.study.course; 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.study.TbCourse; import org.xyzh.common.dto.study.TbCourseChapter; +import org.xyzh.common.vo.CourseVO; import java.util.List; @@ -24,6 +27,15 @@ public interface CourseService { */ ResultDomain getCourseList(TbCourse filter); + /** + * @description 分页获取课程列表 + * @param filter 过滤条件 + * @return ResultDomain 课程列表 + * @author yslg + * @since 2025-10-15 + */ + ResultDomain getCoursePage(PageRequest pageRequest); + /** * @description 根据ID获取课程详情 * @param courseID 课程ID @@ -31,7 +43,7 @@ public interface CourseService { * @author yslg * @since 2025-10-15 */ - ResultDomain getCourseById(String courseID); + ResultDomain getCourseById(String courseID); /** * @description 创建课程 @@ -40,7 +52,7 @@ public interface CourseService { * @author yslg * @since 2025-10-15 */ - ResultDomain createCourse(TbCourse course); + ResultDomain createCourse(CourseVO courseVO); /** * @description 更新课程 diff --git a/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/study/TbCourseChapter.java b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/study/TbCourseChapter.java index b7ca3f7..9b65f09 100644 --- a/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/study/TbCourseChapter.java +++ b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/study/TbCourseChapter.java @@ -12,12 +12,19 @@ import org.xyzh.common.dto.BaseDTO; public class TbCourseChapter extends BaseDTO { private static final long serialVersionUID = 1L; + + private String chapterID; /** * @description 课程ID */ private String courseID; + /** + * @description 父章节ID + */ + private String parentID; + /** * @description 章节名称 */ @@ -32,7 +39,17 @@ public class TbCourseChapter extends BaseDTO { * @description 视频URL */ private String videoUrl; + + /** + * @description 章节类型(1视频 2文档 3音频) + */ + private Integer chapterType; + /** + * @description 资源ID + */ + private String resourceID; + /** * @description 章节时长(分钟) */ @@ -53,6 +70,14 @@ public class TbCourseChapter extends BaseDTO { */ private String updater; + public String getChapterID() { + return chapterID; + } + + public void setChapterID(String chapterID) { + this.chapterID = chapterID; + } + public String getCourseID() { return courseID; } @@ -61,6 +86,14 @@ public class TbCourseChapter extends BaseDTO { this.courseID = courseID; } + public String getParentID() { + return parentID; + } + + public void setParentID(String parentID) { + this.parentID = parentID; + } + public String getName() { return name; } @@ -85,6 +118,22 @@ public class TbCourseChapter extends BaseDTO { this.videoUrl = videoUrl; } + public Integer getChapterType() { + return chapterType; + } + + public void setChapterType(Integer chapterType) { + this.chapterType = chapterType; + } + + public String getResourceID() { + return resourceID; + } + + public void setResourceID(String resourceID) { + this.resourceID = resourceID; + } + public Integer getDuration() { return duration; } @@ -121,9 +170,14 @@ public class TbCourseChapter extends BaseDTO { public String toString() { return "TbCourseChapter{" + "id=" + getID() + + ", chapterID='" + chapterID + '\'' + ", courseID='" + courseID + '\'' + + ", parentID='" + parentID + '\'' + ", name='" + name + '\'' + + ", content='" + content + '\'' + ", videoUrl='" + videoUrl + '\'' + + ", chapterType=" + chapterType + + ", resourceID='" + resourceID + '\'' + ", duration=" + duration + ", orderNum=" + orderNum + '}'; diff --git a/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/study/TbCourseNode.java b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/study/TbCourseNode.java new file mode 100644 index 0000000..a49b25e --- /dev/null +++ b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/study/TbCourseNode.java @@ -0,0 +1,186 @@ +package org.xyzh.common.dto.study; + +import org.xyzh.common.dto.BaseDTO; + +/** + * @description 学习节点表 + * @filename TbCourseNode.java + * @author yslg + * @copyright xyzh + * @since 2025-10-21 + */ +public class TbCourseNode extends BaseDTO { + + private static final long serialVersionUID = 1L; + + private String nodeID; + + /** + * @description 章节ID + */ + private String chapterID; + + /** + * @description 节点名称 + */ + private String name; + + /** + * @description 节点内容 + */ + private String content; + + /** + * @description 节点类型(1视频 2文档 3音频 4图片 5链接) + */ + private Integer nodeType; + + /** + * @description 资源ID + */ + private String resourceID; + + /** + * @description 视频URL + */ + private String videoUrl; + + /** + * @description 节点时长(分钟) + */ + private Integer duration; + + /** + * @description 排序号 + */ + private Integer orderNum; + + /** + * @description 是否必修(1必修 0选修) + */ + private Integer isRequired; + + /** + * @description 创建者 + */ + private String creator; + + /** + * @description 更新者 + */ + private String updater; + + public String getNodeID() { + return nodeID; + } + + public void setNodeID(String nodeID) { + this.nodeID = nodeID; + } + + public String getChapterID() { + return chapterID; + } + + public void setChapterID(String chapterID) { + this.chapterID = chapterID; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Integer getNodeType() { + return nodeType; + } + + public void setNodeType(Integer nodeType) { + this.nodeType = nodeType; + } + + public String getResourceID() { + return resourceID; + } + + public void setResourceID(String resourceID) { + this.resourceID = resourceID; + } + + public String getVideoUrl() { + return videoUrl; + } + + public void setVideoUrl(String videoUrl) { + this.videoUrl = videoUrl; + } + + public Integer getDuration() { + return duration; + } + + public void setDuration(Integer duration) { + this.duration = duration; + } + + public Integer getOrderNum() { + return orderNum; + } + + public void setOrderNum(Integer orderNum) { + this.orderNum = orderNum; + } + + public Integer getIsRequired() { + return isRequired; + } + + public void setIsRequired(Integer isRequired) { + this.isRequired = isRequired; + } + + public String getCreator() { + return creator; + } + + public void setCreator(String creator) { + this.creator = creator; + } + + public String getUpdater() { + return updater; + } + + public void setUpdater(String updater) { + this.updater = updater; + } + + @Override + public String toString() { + return "TbCourseNode{" + + "id=" + getID() + + ", nodeID='" + nodeID + '\'' + + ", chapterID='" + chapterID + '\'' + + ", name='" + name + '\'' + + ", content='" + content + '\'' + + ", nodeType=" + nodeType + + ", resourceID='" + resourceID + '\'' + + ", videoUrl='" + videoUrl + '\'' + + ", duration=" + duration + + ", orderNum=" + orderNum + + ", isRequired=" + isRequired + + '}'; + } +} + diff --git a/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/usercenter/TbUserCollection.java b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/usercenter/TbUserCollection.java index f216684..2330c2b 100644 --- a/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/usercenter/TbUserCollection.java +++ b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/dto/usercenter/TbUserCollection.java @@ -28,6 +28,11 @@ public class TbUserCollection extends BaseDTO { */ private String collectionID; + /** + * @description 收藏值 + */ + private Integer collectionValue; + public String getUserID() { return userID; } @@ -52,6 +57,14 @@ public class TbUserCollection extends BaseDTO { this.collectionID = collectionID; } + public Integer getCollectionValue() { + return collectionValue; + } + + public void setCollectionValue(Integer collectionValue) { + this.collectionValue = collectionValue; + } + @Override public String toString() { return "TbUserCollection{" + @@ -60,6 +73,7 @@ public class TbUserCollection extends BaseDTO { ", collectionType=" + collectionType + ", collectionID='" + collectionID + '\'' + ", createTime=" + getCreateTime() + + ", collectionValue=" + collectionValue + '}'; } } diff --git a/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/ChapterVO.java b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/ChapterVO.java new file mode 100644 index 0000000..1510cd4 --- /dev/null +++ b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/ChapterVO.java @@ -0,0 +1,35 @@ +package org.xyzh.common.vo; + +import org.xyzh.common.dto.BaseDTO; +import org.xyzh.common.dto.study.TbCourseNode; +import org.xyzh.common.dto.study.TbCourseChapter; + +import java.util.ArrayList; +import java.util.List; + +public class ChapterVO extends BaseDTO{ + private static final long serialVersionUID = 1L; + + private TbCourseChapter chapter; + private List nodes; + + public TbCourseChapter getChapter() { + return chapter; + } + public void setChapter(TbCourseChapter chapter) { + this.chapter = chapter; + } + public List getNodes() { + return nodes; + } + public void setNodes(List nodes) { + this.nodes = nodes; + } + + public void addNode(TbCourseNode node) { + if (nodes == null) { + nodes = new ArrayList<>(); + } + nodes.add(node); + } +} diff --git a/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/CourseVO.java b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/CourseVO.java new file mode 100644 index 0000000..767f52b --- /dev/null +++ b/schoolNewsServ/common/common-dto/src/main/java/org/xyzh/common/vo/CourseVO.java @@ -0,0 +1,39 @@ +package org.xyzh.common.vo; + +import org.xyzh.common.dto.BaseDTO; +import org.xyzh.common.dto.study.TbCourse; +import org.xyzh.common.dto.study.TbCourseTag; +import org.xyzh.common.vo.ChapterVO; + +import java.util.List; + +public class CourseVO extends BaseDTO{ + private static final long serialVersionUID = 1L; + + private TbCourse course; + private List courseChapters; + private List courseTags; + + + public TbCourse getCourse() { + return course; + } + public void setCourse(TbCourse course) { + this.course = course; + } + public List getCourseChapters() { + return courseChapters; + } + public void setCourseChapters(List courseChapters) { + this.courseChapters = courseChapters; + } + public List getCourseTags() { + return courseTags; + } + public void setCourseTags(List courseTags) { + this.courseTags = courseTags; + } + + + +} diff --git a/schoolNewsServ/news/pom.xml b/schoolNewsServ/news/pom.xml index 51dd753..ae7842d 100644 --- a/schoolNewsServ/news/pom.xml +++ b/schoolNewsServ/news/pom.xml @@ -24,6 +24,11 @@ api-news ${school-news.version} + + org.xyzh + api-usercenter + ${school-news.version} + org.xyzh system diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceController.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceController.java index 63e8fc7..fc89180 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceController.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/controller/ResourceController.java @@ -1,6 +1,7 @@ package org.xyzh.news.controller; import java.util.Date; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,6 +14,7 @@ import org.xyzh.common.core.page.PageParam; import org.xyzh.common.core.page.PageRequest; import org.xyzh.common.dto.resource.TbResource; import org.xyzh.common.dto.user.TbSysUser; +import org.xyzh.common.dto.usercenter.TbUserCollection; import org.xyzh.common.utils.TimeUtils; import org.xyzh.common.vo.ResourceVO; import org.xyzh.system.utils.LoginUtil; @@ -137,9 +139,9 @@ public class ResourceController { /** * 增加收藏次数 */ - @PostMapping("/resource/{resourceID}/collect") - public ResultDomain incrementCollectCount(@PathVariable("resourceID") String resourceID) { - return resourceService.incrementCollectCount(resourceID); + @PostMapping("/resource/collect") + public ResultDomain resourceCollect(@RequestBody TbUserCollection collection) { + return resourceService.resourceCollect(collection); } /** diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/mapper/ResourceMapper.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/mapper/ResourceMapper.java index 8ba3443..7b185c2 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/mapper/ResourceMapper.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/mapper/ResourceMapper.java @@ -163,4 +163,14 @@ public interface ResourceMapper extends BaseMapper { * @since 2025-10-15 */ long countResources(TbResource filter); + + /** + * @description 更新资源收藏次数 + * @param resourceID 资源ID + * @param collectionValue 收藏次数 + * @return int 影响行数 + * @author yslg + * @since 2025-10-15 + */ + int updateResourceCollectCount(@Param("resourceID") String resourceID, @Param("collectionValue") Integer collectionValue); } diff --git a/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceServiceImpl.java b/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceServiceImpl.java index 53d7495..0498ddd 100644 --- a/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceServiceImpl.java +++ b/schoolNewsServ/news/src/main/java/org/xyzh/news/service/impl/NCResourceServiceImpl.java @@ -13,6 +13,7 @@ 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.dto.usercenter.TbUserCollection; import org.xyzh.common.utils.IDUtils; import org.xyzh.common.vo.ResourceVO; import org.xyzh.common.vo.TagVO; @@ -20,6 +21,7 @@ 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 java.util.ArrayList; import java.util.Date; @@ -44,6 +46,9 @@ public class NCResourceServiceImpl implements ResourceService { @Autowired private ResourceTagMapper resourceTagMapper; + @Autowired + private UserCollectionService userCollectionService; + @Override public ResultDomain getResourceList(TbResource filter) { ResultDomain resultDomain = new ResultDomain<>(); @@ -530,36 +535,57 @@ public class NCResourceServiceImpl implements ResourceService { @Override @Transactional(rollbackFor = Exception.class) - public ResultDomain incrementCollectCount(String resourceID) { + public ResultDomain resourceCollect(TbUserCollection collection) { + String resourceID = collection.getCollectionID(); + Integer collectionValue = collection.getCollectionValue(); ResultDomain resultDomain = new ResultDomain<>(); + TbSysUser user = LoginUtil.getCurrentUser(); + if (user == null) { + resultDomain.fail("请先登录"); + return resultDomain; + } + collection.setUserID(user.getID()); try { // 参数验证 if (!StringUtils.hasText(resourceID)) { resultDomain.fail("资源ID不能为空"); return resultDomain; } - - // 查询资源 - TbResource resource = resourceMapper.selectByResourceId(resourceID); - if (resource == null || resource.getDeleted()) { - resultDomain.fail("资源不存在"); + if (collectionValue != 1 && collectionValue != -1) { + 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); + ResultDomain 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 { - resultDomain.fail("增加收藏次数失败"); + } + else if (isCollected.isSuccess() && isCollected.getData() && collectionValue == -1) { + ResultDomain removeCollection = userCollectionService.removeCollection(user.getID(), collection.getCollectionType(), resourceID); + 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 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) { diff --git a/schoolNewsServ/news/src/main/resources/mapper/ResourceMapper.xml b/schoolNewsServ/news/src/main/resources/mapper/ResourceMapper.xml index 6af60d8..b08310e 100644 --- a/schoolNewsServ/news/src/main/resources/mapper/ResourceMapper.xml +++ b/schoolNewsServ/news/src/main/resources/mapper/ResourceMapper.xml @@ -303,4 +303,11 @@ + + + + UPDATE tb_resource + SET collect_count = collect_count + #{collectionValue} + WHERE resource_id = #{resourceID} + diff --git a/schoolNewsServ/study/pom.xml b/schoolNewsServ/study/pom.xml index 5f2c27e..e5eec7e 100644 --- a/schoolNewsServ/study/pom.xml +++ b/schoolNewsServ/study/pom.xml @@ -27,7 +27,11 @@ api-study ${school-news.version} - + + org.xyzh + system + ${school-news.version} + org.xyzh common-all diff --git a/schoolNewsServ/study/src/main/java/org/xyzh/study/controller/CourseController.java b/schoolNewsServ/study/src/main/java/org/xyzh/study/controller/CourseController.java index 00af368..2816642 100644 --- a/schoolNewsServ/study/src/main/java/org/xyzh/study/controller/CourseController.java +++ b/schoolNewsServ/study/src/main/java/org/xyzh/study/controller/CourseController.java @@ -6,8 +6,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.xyzh.api.study.course.CourseService; import org.xyzh.common.core.domain.ResultDomain; +import org.xyzh.common.core.page.PageRequest; import org.xyzh.common.dto.study.TbCourse; import org.xyzh.common.dto.study.TbCourseChapter; +import org.xyzh.common.vo.ChapterVO; +import org.xyzh.common.vo.CourseVO; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; + /** * @description 课程控制器 @@ -17,7 +23,7 @@ import org.xyzh.common.dto.study.TbCourseChapter; * @since 2025-10-15 */ @RestController -@RequestMapping("/study/course") +@RequestMapping("/study/courses") public class CourseController { private static final Logger logger = LoggerFactory.getLogger(CourseController.class); @@ -32,26 +38,34 @@ public class CourseController { return courseService.getCourseList(filter); } + /** + * 分页获取课程列表 + */ + @PostMapping("/page") + public ResultDomain getCoursePage(@RequestBody PageRequest pageRequest) { + return courseService.getCoursePage(pageRequest); + } + /** * 根据ID获取课程详情 */ @GetMapping("/{courseID}") - public ResultDomain getCourseById(@PathVariable String courseID) { + public ResultDomain getCourseById(@PathVariable("courseID") String courseID) { return courseService.getCourseById(courseID); } /** * 创建课程 */ - @PostMapping("/create") - public ResultDomain createCourse(@RequestBody TbCourse course) { - return courseService.createCourse(course); + @PostMapping("/course") + public ResultDomain createCourse(@RequestBody CourseVO courseVO) { + return courseService.createCourse(courseVO); } /** * 更新课程 */ - @PutMapping("/update") + @PutMapping("/course") public ResultDomain updateCourse(@RequestBody TbCourse course) { return courseService.updateCourse(course); } @@ -59,7 +73,7 @@ public class CourseController { /** * 删除课程 */ - @DeleteMapping("/{courseID}") + @DeleteMapping("/course") public ResultDomain deleteCourse(@PathVariable String courseID) { return courseService.deleteCourse(courseID); } @@ -90,53 +104,4 @@ public class CourseController { return courseService.incrementLearnCount(courseID); } - /** - * 获取课程章节列表 - */ - @GetMapping("/{courseID}/chapters") - public ResultDomain getCourseChapters(@PathVariable String courseID) { - return courseService.getCourseChapters(courseID); - } - - /** - * 根据ID获取章节详情 - */ - @GetMapping("/chapter/{chapterID}") - public ResultDomain getChapterById(@PathVariable String chapterID) { - return courseService.getChapterById(chapterID); - } - - /** - * 创建课程章节 - */ - @PostMapping("/chapter/create") - public ResultDomain createChapter(@RequestBody TbCourseChapter chapter) { - return courseService.createChapter(chapter); - } - - /** - * 更新课程章节 - */ - @PutMapping("/chapter/update") - public ResultDomain updateChapter(@RequestBody TbCourseChapter chapter) { - return courseService.updateChapter(chapter); - } - - /** - * 删除课程章节 - */ - @DeleteMapping("/chapter/{chapterID}") - public ResultDomain deleteChapter(@PathVariable String chapterID) { - return courseService.deleteChapter(chapterID); - } - - /** - * 更新章节排序 - */ - @PutMapping("/chapter/{chapterID}/order") - public ResultDomain updateChapterOrder( - @PathVariable String chapterID, - @RequestParam Integer orderNum) { - return courseService.updateChapterOrder(chapterID, orderNum); - } } diff --git a/schoolNewsServ/study/src/main/java/org/xyzh/study/controller/CourseManagementController.java b/schoolNewsServ/study/src/main/java/org/xyzh/study/controller/CourseManagementController.java deleted file mode 100644 index ebdc919..0000000 --- a/schoolNewsServ/study/src/main/java/org/xyzh/study/controller/CourseManagementController.java +++ /dev/null @@ -1,176 +0,0 @@ -package org.xyzh.study.controller; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.bind.annotation.*; -import org.xyzh.common.core.domain.ResultDomain; -import org.xyzh.common.dto.study.TbCourse; - -import java.util.Map; - -/** - * @description 课程管理控制器 - * @filename CourseManagementController.java - * @author yslg - * @copyright xyzh - * @since 2025-10-15 - */ -@RestController -@RequestMapping("/study/course-management") -public class CourseManagementController { - private static final Logger logger = LoggerFactory.getLogger(CourseManagementController.class); - - // ==================== 课程列表管理 ==================== - - /** - * 分页展示所有课程 - */ - @GetMapping("/list") - public ResultDomain getCourseList( - @RequestParam(required = false) String courseName, - @RequestParam(required = false) String tag, - @RequestParam(required = false) Integer pageNum, - @RequestParam(required = false) Integer pageSize) { - // TODO: 实现分页展示所有课程(支持按课程名称/标签筛选) - return null; - } - - /** - * 查看课程详情 - */ - @GetMapping("/detail/{courseID}") - public ResultDomain getCourseDetail(@PathVariable String courseID) { - // TODO: 实现查看课程详情 - return null; - } - - /** - * 按课程名称筛选 - */ - @GetMapping("/filter/name") - public ResultDomain filterByCourseName(@RequestParam String courseName) { - // TODO: 实现按课程名称筛选 - return null; - } - - /** - * 按标签筛选课程 - */ - @GetMapping("/filter/tag") - public ResultDomain filterByTag(@RequestParam String tag) { - // TODO: 实现按标签筛选课程 - return null; - } - - // ==================== 课程添加管理 ==================== - - /** - * 添加课程 - */ - @PostMapping("/add") - public ResultDomain addCourse(@RequestBody Map courseData) { - // TODO: 实现添加课程(录入课程名称、上传课程图片、填写课程描述、选择课程标签、设置课程权限、设置课程状态) - return null; - } - - /** - * 上传课程图片 - */ - @PostMapping("/upload-image") - public ResultDomain uploadCourseImage(@RequestParam("file") String file) { - // TODO: 实现上传课程图片 - return null; - } - - /** - * 设置课程权限 - */ - @PutMapping("/permission/set") - public ResultDomain setCoursePermission(@RequestBody Map params) { - // TODO: 实现设置课程权限(公开/指定部门) - return null; - } - - /** - * 设置课程状态 - */ - @PutMapping("/status/set") - public ResultDomain setCourseStatus(@RequestBody Map params) { - // TODO: 实现设置课程状态(未上线/已上线) - return null; - } - - /** - * 选择课程标签 - */ - @PutMapping("/tag/select") - public ResultDomain selectCourseTags(@RequestBody Map params) { - // TODO: 实现选择课程标签 - return null; - } - - // ==================== 课程维护管理 ==================== - - /** - * 编辑课程信息 - */ - @PutMapping("/edit") - public ResultDomain editCourseInfo(@RequestBody TbCourse course) { - // TODO: 实现编辑课程信息 - return null; - } - - /** - * 更新课程内容 - */ - @PutMapping("/content/update") - public ResultDomain updateCourseContent(@RequestBody Map params) { - // TODO: 实现更新课程内容 - return null; - } - - /** - * 修改课程状态 - */ - @PutMapping("/status/change") - public ResultDomain changeCourseStatus(@RequestBody Map params) { - // TODO: 实现修改课程状态 - return null; - } - - /** - * 删除课程 - */ - @DeleteMapping("/{courseID}") - public ResultDomain deleteCourse(@PathVariable String courseID) { - // TODO: 实现删除课程 - return null; - } - - /** - * 批量更新课程状态 - */ - @PutMapping("/batch-status-update") - public ResultDomain batchUpdateCourseStatus(@RequestBody Map params) { - // TODO: 实现批量更新课程状态 - return null; - } - - /** - * 获取课程统计信息 - */ - @GetMapping("/statistics") - public ResultDomain> getCourseStatistics(@RequestParam String courseID) { - // TODO: 实现获取课程统计信息 - return null; - } - - /** - * 获取课程学习情况 - */ - @GetMapping("/learning-status") - public ResultDomain> getCourseLearningStatus(@RequestParam String courseID) { - // TODO: 实现获取课程学习情况 - return null; - } -} diff --git a/schoolNewsServ/study/src/main/java/org/xyzh/study/mapper/CourseNodeMapper.java b/schoolNewsServ/study/src/main/java/org/xyzh/study/mapper/CourseNodeMapper.java new file mode 100644 index 0000000..1c793f7 --- /dev/null +++ b/schoolNewsServ/study/src/main/java/org/xyzh/study/mapper/CourseNodeMapper.java @@ -0,0 +1,166 @@ +package org.xyzh.study.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.xyzh.common.core.page.PageParam; +import org.xyzh.common.dto.study.TbCourseNode; + +import java.util.List; + +/** + * @description 学习节点数据访问层 + * @filename CourseNodeMapper.java + * @author yslg + * @copyright xyzh + * @since 2025-10-21 + */ +@Mapper +public interface CourseNodeMapper extends BaseMapper { + + /** + * @description 查询学习节点列表 + * @param filter 过滤条件 + * @return List 学习节点列表 + * @author yslg + * @since 2025-10-21 + */ + List selectCourseNodes(TbCourseNode filter); + + /** + * @description 根据章节ID列表查询学习节点列表 + * @param chapterIDs 章节ID列表 + * @return List 学习节点列表 + * @author yslg + * @since 2025-10-21 + */ + List selectCourseNodesByChapterIDs(@Param("chapterIDs") List chapterIDs); + /** + * @description 根据节点ID查询节点信息 + * @param nodeId 节点ID + * @return TbCourseNode 节点信息 + * @author yslg + * @since 2025-10-21 + */ + TbCourseNode selectByNodeId(@Param("nodeId") String nodeId); + + /** + * @description 根据章节ID查询节点列表 + * @param chapterId 章节ID + * @return List 节点列表 + * @author yslg + * @since 2025-10-21 + */ + List selectByChapterId(@Param("chapterId") String chapterId); + + /** + * @description 根据节点名称查询节点 + * @param name 节点名称 + * @return TbCourseNode 节点信息 + * @author yslg + * @since 2025-10-21 + */ + TbCourseNode selectByName(@Param("name") String name); + + /** + * @description 根据节点类型查询节点列表 + * @param nodeType 节点类型 + * @return List 节点列表 + * @author yslg + * @since 2025-10-21 + */ + List selectByNodeType(@Param("nodeType") Integer nodeType); + + /** + * @description 根据章节ID和排序查询节点列表 + * @param chapterId 章节ID + * @return List 节点列表 + * @author yslg + * @since 2025-10-21 + */ + List selectByChapterIdOrderBySort(@Param("chapterId") String chapterId); + + /** + * @description 检查节点名称是否存在 + * @param name 节点名称 + * @param excludeId 排除的节点ID(用于更新时排除自身) + * @return int 存在的数量 + * @author yslg + * @since 2025-10-21 + */ + int countByName(@Param("name") String name, @Param("excludeId") String excludeId); + + /** + * @description 插入学习节点 + * @param courseNode 学习节点 + * @return int 影响行数 + * @author yslg + * @since 2025-10-21 + */ + int insertCourseNode(TbCourseNode courseNode); + + /** + * @description 更新学习节点 + * @param courseNode 学习节点 + * @return int 影响行数 + * @author yslg + * @since 2025-10-21 + */ + int updateCourseNode(TbCourseNode courseNode); + + /** + * @description 删除学习节点 + * @param courseNode 学习节点 + * @return int 影响行数 + * @author yslg + * @since 2025-10-21 + */ + int deleteCourseNode(TbCourseNode courseNode); + + /** + * @description 批量插入学习节点 + * @param courseNodeList 学习节点列表 + * @return int 影响行数 + * @author yslg + * @since 2025-10-21 + */ + int batchInsertCourseNodes(@Param("courseNodeList") List courseNodeList); + + /** + * @description 批量删除学习节点 + * @param ids 节点ID列表 + * @return int 影响行数 + * @author yslg + * @since 2025-10-21 + */ + int batchDeleteCourseNodes(@Param("nodeIDs") List nodeIDs); + + /** + * @description 根据章节ID批量删除节点 + * @param chapterId 章节ID + * @return int 影响行数 + * @author yslg + * @since 2025-10-21 + */ + int deleteByChapterId(@Param("chapterId") String chapterId); + + /** + * @description 分页查询学习节点 + * @param filter 过滤条件 + * @param pageParam 分页参数 + * @return List 学习节点列表 + * @author yslg + * @since 2025-10-21 + */ + List selectCourseNodesPage(@Param("filter") TbCourseNode filter, @Param("pageParam") PageParam pageParam); + + /** + * @description 统计学习节点总数 + * @param filter 过滤条件 + * @return long 总数 + * @author yslg + * @since 2025-10-21 + */ + long countCourseNodes(@Param("filter") TbCourseNode filter); +} + diff --git a/schoolNewsServ/study/src/main/java/org/xyzh/study/service/impl/SCCourseServiceImpl.java b/schoolNewsServ/study/src/main/java/org/xyzh/study/service/impl/SCCourseServiceImpl.java index e3601df..64e779e 100644 --- a/schoolNewsServ/study/src/main/java/org/xyzh/study/service/impl/SCCourseServiceImpl.java +++ b/schoolNewsServ/study/src/main/java/org/xyzh/study/service/impl/SCCourseServiceImpl.java @@ -1,15 +1,33 @@ package org.xyzh.study.service.impl; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; 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.study.TbCourse; import org.xyzh.common.dto.study.TbCourseChapter; +import org.xyzh.common.dto.study.TbCourseNode; +import org.xyzh.common.dto.study.TbCourseTag; +import org.xyzh.common.dto.user.TbSysUser; +import org.xyzh.common.utils.IDUtils; +import org.xyzh.common.vo.ChapterVO; +import org.xyzh.common.vo.CourseVO; import org.xyzh.study.mapper.CourseMapper; +import org.xyzh.study.mapper.CourseTagMapper; import org.xyzh.study.mapper.CourseChapterMapper; +import org.xyzh.study.mapper.CourseNodeMapper; import org.xyzh.study.service.SCCourseService; +import org.xyzh.system.utils.LoginUtil; /** * @description 课程服务实现类 @@ -29,6 +47,12 @@ public class SCCourseServiceImpl implements SCCourseService { @Autowired private CourseChapterMapper courseChapterMapper; + @Autowired + private CourseTagMapper courseTagMapper; + + @Autowired + private CourseNodeMapper courseNodeMapper; + @Override public ResultDomain getCourseList(TbCourse filter) { // TODO: 实现获取课程列表 @@ -36,15 +60,117 @@ public class SCCourseServiceImpl implements SCCourseService { } @Override - public ResultDomain getCourseById(String courseID) { - // TODO: 实现根据ID获取课程详情 - return null; + public ResultDomain getCoursePage(PageRequest pageRequest) { + ResultDomain resultDomain = new ResultDomain<>(); + TbCourse filter = pageRequest.getFilter(); + PageParam pageParam = pageRequest.getPageParam(); + List courses = courseMapper.selectCoursesPage(filter, pageParam); + int total = (int) courseMapper.countCourses(filter); + int totalPages = (int) Math.ceil((double) total / pageParam.getPageSize()); + pageParam.setTotalPages(totalPages); + pageParam.setTotalElements(total); + PageDomain pageDomain = new PageDomain<>(pageParam, courses); + resultDomain.success("获取课程列表成功", pageDomain); + return resultDomain; } @Override - public ResultDomain createCourse(TbCourse course) { - // TODO: 实现创建课程 - return null; + public ResultDomain getCourseById(String courseID) { + ResultDomain resultDomain = new ResultDomain<>(); + // 查询课程 + TbCourse course = courseMapper.selectByCourseId(courseID); + // 查询标签 + List tags = courseTagMapper.selectByCourseId(courseID); + CourseVO courseVO = new CourseVO(); + courseVO.setCourse(course); + courseVO.setCourseTags(tags); + + // 查询课程章节 + TbCourseChapter filter = new TbCourseChapter(); + filter.setCourseID(courseID); + List chapters = courseChapterMapper.selectCourseChapters(filter); + // 查询子节点 + if (chapters.size() > 0) { + List chapterIDs = chapters.stream().map(TbCourseChapter::getChapterID).collect(Collectors.toList()); + List nodes = courseNodeMapper.selectCourseNodesByChapterIDs(chapterIDs); + Map> nodesMap = nodes.stream().collect(Collectors.groupingBy(TbCourseNode::getChapterID)); + List chapterVOs = chapters.stream().map(chapter -> { + ChapterVO chapterVO = new ChapterVO(); + chapterVO.setChapter(chapter); + chapterVO.setNodes(nodesMap.get(chapter.getChapterID())); + return chapterVO; + }).collect(Collectors.toList()); + courseVO.setCourseChapters(chapterVOs); + } + resultDomain.success("获取课程详情成功", courseVO); + return resultDomain; + } + + @Override + public ResultDomain createCourse(CourseVO courseVO) { + ResultDomain resultDomain = new ResultDomain<>(); + TbSysUser user = LoginUtil.getCurrentUser(); + if (user == null) { + resultDomain.fail("请先登录"); + return resultDomain; + } + TbCourse course = courseVO.getCourse(); + String courseID = IDUtils.generateID(); + course.setCreator(user.getID()); + course.setCourseID(courseID); + Date now = new Date(); + course.setCreateTime(now); + course.setStatus(0); + + + courseMapper.insertCourse(course); + + List courseChapters = courseVO.getCourseChapters(); + List chapters = new ArrayList<>(); + List nodes = new ArrayList<>(); + int length = courseChapters.size(); + for (int i=0; i nodesList = chapterVO.getNodes(); + + chapter.setCourseID(courseID); + String chapterID = IDUtils.generateID(); + chapter.setID(IDUtils.generateID()); + chapter.setChapterID(chapterID); + chapter.setCreator(user.getID()); + chapter.setCreateTime(now); + chapter.setOrderNum(i); + chapters.add(chapter); + + for (int j=0; j courseTags = courseVO.getCourseTags(); + length = courseTags.size(); + if (length > 0) { + for (int i=0; i + + + + @@ -21,7 +25,7 @@ - id, course_id, name, content, video_url, duration, order_num, + id, chapter_id, course_id, parent_id, name, content, chapter_type, resource_id, video_url, duration, order_num, creator, updater, create_time, update_time, delete_time, deleted @@ -29,12 +33,21 @@ deleted = 0 + + AND chapter_id = #{chapterID} + AND course_id = #{courseID} + + AND parent_id = #{parentID} + AND name LIKE CONCAT('%', #{name}, '%') + + AND chapter_type = #{chapterType} + @@ -103,10 +116,10 @@ INSERT INTO tb_course_chapter ( - id, course_id, name, content, video_url, duration, order_num, + id, chapter_id, course_id, parent_id, name, content, chapter_type, resource_id, video_url, duration, order_num, creator, updater, create_time, update_time, delete_time, deleted ) VALUES ( - #{id}, #{courseID}, #{name}, #{content}, #{videoUrl}, #{duration}, #{orderNum}, + #{id}, #{chapterID}, #{courseID}, #{parentID}, #{name}, #{content}, #{chapterType}, #{resourceID}, #{videoUrl}, #{duration}, #{orderNum}, #{creator}, #{updater}, #{createTime}, #{updateTime}, #{deleteTime}, #{deleted} ) @@ -115,15 +128,27 @@ UPDATE tb_course_chapter + + chapter_id = #{chapterID}, + course_id = #{courseID}, + + parent_id = #{parentID}, + name = #{name}, content = #{content}, + + chapter_type = #{chapterType}, + + + resource_id = #{resourceID}, + video_url = #{videoUrl}, @@ -146,26 +171,25 @@ deleted = #{deleted}, - WHERE id = #{id} + WHERE chapter_id = #{chapterID} DELETE FROM tb_course_chapter - WHERE id = #{id} + WHERE chapter_id = #{chapterID} INSERT INTO tb_course_chapter ( - id, course_id, name, content, video_url, duration, order_num, - creator, updater, create_time, update_time, delete_time, deleted + id, chapter_id, course_id, parent_id, name, content, chapter_type, resource_id, video_url, duration, order_num, + creator, create_time ) VALUES ( - #{item.id}, #{item.courseID}, #{item.name}, #{item.content}, #{item.videoUrl}, - #{item.duration}, #{item.orderNum}, #{item.creator}, #{item.updater}, - #{item.createTime}, #{item.updateTime}, #{item.deleteTime}, #{item.deleted} + #{item.id}, #{item.chapterID}, #{item.courseID}, #{item.parentID}, #{item.name}, #{item.content}, #{item.chapterType}, + #{item.resourceID}, #{item.videoUrl}, #{item.duration}, #{item.orderNum}, #{item.creator}, #{item.createTime} ) diff --git a/schoolNewsServ/study/src/main/resources/mapper/CourseMapper.xml b/schoolNewsServ/study/src/main/resources/mapper/CourseMapper.xml index f32b59c..8ca7a99 100644 --- a/schoolNewsServ/study/src/main/resources/mapper/CourseMapper.xml +++ b/schoolNewsServ/study/src/main/resources/mapper/CourseMapper.xml @@ -49,6 +49,31 @@ + + + + AND course_id = #{filter.courseID} + + + + AND name LIKE CONCAT('%', #{filter.name}, '%') + + + AND teacher LIKE CONCAT('%', #{filter.teacher}, '%') + + + AND status = #{filter.status} + + + AND order_num = #{filter.orderNum} + + + AND creator = #{filter.creator} + + + AND create_time = #{filter.createTime} + + @@ -261,7 +284,7 @@ diff --git a/schoolNewsServ/study/src/main/resources/mapper/CourseNodeMapper.xml b/schoolNewsServ/study/src/main/resources/mapper/CourseNodeMapper.xml new file mode 100644 index 0000000..9dad5bc --- /dev/null +++ b/schoolNewsServ/study/src/main/resources/mapper/CourseNodeMapper.xml @@ -0,0 +1,239 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + id, node_id, chapter_id, name, content, node_type, resource_id, video_url, duration, order_num, is_required, + creator, updater, create_time, update_time, delete_time, deleted + + + + + + deleted = 0 + + AND node_id = #{nodeID} + + + AND chapter_id = #{chapterID} + + + AND name LIKE CONCAT('%', #{name}, '%') + + + AND node_type = #{nodeType} + + + AND is_required = #{isRequired} + + + + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO tb_course_node ( + id, chapter_id, name, content, node_type, resource_id, video_url, duration, order_num, is_required, + creator, updater, create_time, update_time, delete_time, deleted + ) VALUES ( + #{id}, #{chapterID}, #{name}, #{content}, #{nodeType}, #{resourceID}, #{videoUrl}, #{duration}, #{orderNum}, #{isRequired}, + #{creator}, #{updater}, #{createTime}, #{updateTime}, #{deleteTime}, #{deleted} + ) + + + + + UPDATE tb_course_node + + + chapter_id = #{chapterID}, + + + name = #{name}, + + + content = #{content}, + + + node_type = #{nodeType}, + + + resource_id = #{resourceID}, + + + video_url = #{videoUrl}, + + + duration = #{duration}, + + + order_num = #{orderNum}, + + + is_required = #{isRequired}, + + + updater = #{updater}, + + + update_time = #{updateTime}, + + + delete_time = #{deleteTime}, + + + deleted = #{deleted}, + + + WHERE id = #{id} + + + + + DELETE FROM tb_course_node + WHERE node_id = #{nodeID} + + + + + INSERT INTO tb_course_node ( + id,node_id, chapter_id, name, content, node_type, resource_id, video_url, duration, order_num, is_required, + creator, create_time + ) VALUES + + ( + #{item.id}, #{item.nodeID}, #{item.chapterID}, #{item.name}, #{item.content}, #{item.nodeType}, + #{item.resourceID}, #{item.videoUrl}, #{item.duration}, #{item.orderNum}, #{item.isRequired}, + #{item.creator}, #{item.createTime} + ) + + + + + + DELETE FROM tb_course_node + WHERE node_id IN + + #{nodeID} + + + + + + DELETE FROM tb_course_node + WHERE chapter_id = #{chapterId} + + + + + + + + + + + + diff --git a/schoolNewsServ/usercenter/src/main/java/org/xyzh/usercenter/mapper/UserCollectionMapper.java b/schoolNewsServ/usercenter/src/main/java/org/xyzh/usercenter/mapper/UserCollectionMapper.java index ac69307..9a0ba09 100644 --- a/schoolNewsServ/usercenter/src/main/java/org/xyzh/usercenter/mapper/UserCollectionMapper.java +++ b/schoolNewsServ/usercenter/src/main/java/org/xyzh/usercenter/mapper/UserCollectionMapper.java @@ -34,7 +34,7 @@ public interface UserCollectionMapper extends BaseMapper { * @author yslg * @since 2025-10-15 */ - List selectByUserId(@Param("userId") String userId); + List selectByUserId(@Param("userID") String userID); /** * @description 根据用户ID和类型查询收藏记录 @@ -44,7 +44,7 @@ public interface UserCollectionMapper extends BaseMapper { * @author yslg * @since 2025-10-15 */ - List selectByUserIdAndType(@Param("userId") String userId, @Param("collectionType") Integer collectionType); + List selectByUserIdAndType(@Param("userID") String userID, @Param("collectionType") Integer collectionType); /** * @description 根据用户ID查询收藏记录(包含用户基本信息) @@ -53,7 +53,7 @@ public interface UserCollectionMapper extends BaseMapper { * @author yslg * @since 2025-10-15 */ - List selectUserCollectionsWithUser(@Param("userId") String userId); + List selectUserCollectionsWithUser(@Param("userID") String userID); /** * @description 查询用户收藏统计 @@ -62,7 +62,7 @@ public interface UserCollectionMapper extends BaseMapper { * @author yslg * @since 2025-10-15 */ - TbUserCollection selectCollectionStatistics(@Param("userId") String userId); + TbUserCollection selectCollectionStatistics(@Param("userID") String userID); /** * @description 插入用户收藏 diff --git a/schoolNewsServ/usercenter/src/main/java/org/xyzh/usercenter/service/impl/UCUserCollectionServiceImpl.java b/schoolNewsServ/usercenter/src/main/java/org/xyzh/usercenter/service/impl/UCUserCollectionServiceImpl.java index 485aa74..7cfe9ee 100644 --- a/schoolNewsServ/usercenter/src/main/java/org/xyzh/usercenter/service/impl/UCUserCollectionServiceImpl.java +++ b/schoolNewsServ/usercenter/src/main/java/org/xyzh/usercenter/service/impl/UCUserCollectionServiceImpl.java @@ -1,5 +1,7 @@ package org.xyzh.usercenter.service.impl; +import java.util.List; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -26,38 +28,92 @@ public class UCUserCollectionServiceImpl implements UCUserCollectionService { @Override public ResultDomain addCollection(TbUserCollection userCollection) { - // TODO: 实现添加收藏 - return null; + int result = userCollectionMapper.insertUserCollection(userCollection); + if (result > 0) { + ResultDomain resultDomain = new ResultDomain<>(); + resultDomain.success("添加收藏成功", userCollection); + return resultDomain; + } else { + ResultDomain resultDomain = new ResultDomain<>(); + resultDomain.fail("添加收藏失败"); + return resultDomain; + } } @Override public ResultDomain getCollectionDetail(String userID, Integer collectionType, String collectionID) { - // TODO Auto-generated method stub return null; } @Override public ResultDomain getUserCollections(String userID, Integer collectionType) { - // TODO Auto-generated method stub - return null; + TbUserCollection filter = new TbUserCollection(); + filter.setUserID(userID); + filter.setCollectionType(collectionType); + List list = userCollectionMapper.selectUserCollections(filter); + if (list != null && list.size() > 0) { + ResultDomain resultDomain = new ResultDomain<>(); + resultDomain.success("获取收藏列表成功", list); + return resultDomain; + } else { + ResultDomain resultDomain = new ResultDomain<>(); + resultDomain.fail("获取收藏列表失败"); + return resultDomain; + } } @Override public ResultDomain isCollected(String userID, Integer collectionType, String collectionID) { - // TODO Auto-generated method stub - return null; + TbUserCollection filter = new TbUserCollection(); + filter.setUserID(userID); + filter.setCollectionType(collectionType); + filter.setCollectionID(collectionID); + long count = userCollectionMapper.countUserCollections(filter); + if (count > 0) { + ResultDomain resultDomain = new ResultDomain<>(); + resultDomain.success("已收藏", true); + return resultDomain; + } else { + ResultDomain resultDomain = new ResultDomain<>(); + resultDomain.success("未收藏", false); + return resultDomain; + } } @Override public ResultDomain removeCollection(String userID, Integer collectionType, String collectionID) { - // TODO Auto-generated method stub - return null; + TbUserCollection filter = new TbUserCollection(); + filter.setUserID(userID); + filter.setCollectionType(collectionType); + filter.setCollectionID(collectionID); + int result = userCollectionMapper.deleteUserCollection(filter); + if (result > 0) { + ResultDomain resultDomain = new ResultDomain<>(); + resultDomain.success("删除收藏成功", true); + return resultDomain; + } else { + ResultDomain resultDomain = new ResultDomain<>(); + resultDomain.fail("删除收藏失败"); + return resultDomain; + } } @Override public ResultDomain getCollectionCount(String userID, Integer collectionType, String collectionID) { - // TODO Auto-generated method stub - return null; + TbUserCollection filter = new TbUserCollection(); + filter.setUserID(userID); + filter.setCollectionType(collectionType); + filter.setCollectionID(collectionID); + long count = userCollectionMapper.countUserCollections(filter); + if (count > 0) { + ResultDomain resultDomain = new ResultDomain<>(); + resultDomain.success("获取收藏数量成功", (int)count); + return resultDomain; + } else { + ResultDomain resultDomain = new ResultDomain<>(); + resultDomain.fail("获取收藏数量失败"); + return resultDomain; + } } } \ No newline at end of file diff --git a/schoolNewsServ/usercenter/src/main/resources/mapper/UserCollectionMapper.xml b/schoolNewsServ/usercenter/src/main/resources/mapper/UserCollectionMapper.xml index 45ca23d..9d11d54 100644 --- a/schoolNewsServ/usercenter/src/main/resources/mapper/UserCollectionMapper.xml +++ b/schoolNewsServ/usercenter/src/main/resources/mapper/UserCollectionMapper.xml @@ -5,9 +5,9 @@ - + - + @@ -23,14 +23,14 @@ AND id = #{filter.id} - - AND user_id = #{filter.userId} + + AND user_id = #{filter.userID} AND collection_type = #{filter.collectionType} - - AND collection_id = #{filter.collectionId} + + AND collection_id = #{filter.collectionID} AND create_time = #{filter.createTime} @@ -105,7 +105,7 @@ INSERT INTO tb_user_collection ( id, user_id, collection_type, collection_id, create_time ) VALUES ( - #{entity.id}, #{entity.userId}, #{entity.collectionType}, #{entity.collectionId}, #{entity.createTime} + #{entity.id}, #{entity.userID}, #{entity.collectionType}, #{entity.collectionID}, #{entity.createTime} ) @@ -116,7 +116,7 @@ ) VALUES ( - #{entity.id}, #{entity.userId}, #{entity.collectionType}, #{entity.collectionId}, #{entity.createTime} + #{entity.id}, #{entity.userID}, #{entity.collectionType}, #{entity.collectionID}, #{entity.createTime} ) @@ -125,14 +125,14 @@ UPDATE tb_user_collection - - user_id = #{entity.userId}, + + user_id = #{entity.userID}, collection_type = #{entity.collectionType}, - - collection_id = #{entity.collectionId}, + + collection_id = #{entity.collectionID}, WHERE id = #{entity.id} @@ -142,14 +142,14 @@ UPDATE tb_user_collection - - user_id = #{entity.userId}, + + user_id = #{entity.userID}, collection_type = #{entity.collectionType}, - - collection_id = #{entity.collectionId}, + + collection_id = #{entity.collectionID}, @@ -188,7 +188,7 @@ SELECT FROM tb_user_collection - WHERE user_id = #{userId} + WHERE user_id = #{userID} ORDER BY create_time DESC @@ -197,7 +197,7 @@ SELECT FROM tb_user_collection - WHERE user_id = #{userId} AND collection_type = #{collectionType} + WHERE user_id = #{userID} AND collection_type = #{collectionType} ORDER BY create_time DESC @@ -207,7 +207,7 @@ uc.id, uc.user_id, uc.collection_type, uc.collection_id, uc.create_time FROM tb_user_collection uc LEFT JOIN tb_sys_user u ON uc.user_id = u.id - WHERE uc.user_id = #{userId} + WHERE uc.user_id = #{userID} ORDER BY uc.create_time DESC @@ -218,7 +218,7 @@ COUNT(*) as collection_type, MAX(create_time) as create_time FROM tb_user_collection - WHERE user_id = #{userId} + WHERE user_id = #{userID} GROUP BY user_id @@ -227,7 +227,7 @@ INSERT INTO tb_user_collection ( id, user_id, collection_type, collection_id, create_time ) VALUES ( - #{id}, #{userId}, #{collectionType}, #{collectionId}, #{createTime} + #{id}, #{userID}, #{collectionType}, #{collectionID}, #{createTime} ) @@ -235,14 +235,14 @@ UPDATE tb_user_collection - - user_id = #{userId}, + + user_id = #{userID}, collection_type = #{collectionType}, - - collection_id = #{collectionId}, + + collection_id = #{collectionID}, WHERE id = #{id} @@ -251,7 +251,7 @@ DELETE FROM tb_user_collection - WHERE id = #{id} + WHERE user_id = #{userID} AND collection_type = #{collectionType} AND collection_id = #{collectionID} @@ -261,7 +261,7 @@ ) VALUES ( - #{item.id}, #{item.userId}, #{item.collectionType}, #{item.collectionId}, #{item.createTime} + #{item.id}, #{item.userID}, #{item.collectionType}, #{item.collectionID}, #{item.createTime} )