From 55777b33a4018429dbc76b450252922166e724c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E8=A3=81?= <14186472+wenyu441069198@user.noreply.gitee.com> Date: Mon, 12 Aug 2024 17:25:32 +0800 Subject: [PATCH 01/23] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E5=AE=9E=E4=BD=93=E7=B1=BB=E5=9E=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/umsAdmin/UmsStudentManageController.java | 2 -- .../teaching/backend/mapper/umsAdmin/UmsStudentMapper.java | 2 +- .../teaching/backend/model/entity/umsAdmin/UmsStudent.java | 2 +- .../backend/model/entity/umsAdmin/UmsStudentManage.java | 2 +- .../service/impl/umsAdmin/UmsStudentManageServiceImpl.java | 2 +- .../backend/service/impl/umsAdmin/UmsUserServiceImpl.java | 6 ++---- 6 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/teaching/backend/controller/umsAdmin/UmsStudentManageController.java b/src/main/java/com/teaching/backend/controller/umsAdmin/UmsStudentManageController.java index 71c47b8..8e66e13 100644 --- a/src/main/java/com/teaching/backend/controller/umsAdmin/UmsStudentManageController.java +++ b/src/main/java/com/teaching/backend/controller/umsAdmin/UmsStudentManageController.java @@ -1,6 +1,5 @@ package com.teaching.backend.controller.umsAdmin; -import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.CommonResult; import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO; import com.teaching.backend.model.entity.umsAdmin.UmsStudentManage; @@ -11,7 +10,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; import java.util.List; import java.util.Map; diff --git a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsStudentMapper.java b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsStudentMapper.java index bd3b04a..fb58d74 100644 --- a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsStudentMapper.java +++ b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsStudentMapper.java @@ -14,6 +14,6 @@ import com.teaching.backend.model.entity.umsAdmin.UmsStudent; public interface UmsStudentMapper extends BaseMapper { boolean updateStudentInfo(UmsStudent umsStudent); - UmsStudent selectByUserId(Integer userId); + UmsStudent selectByUserId(Long userId); } diff --git a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudent.java b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudent.java index ec40634..6608772 100644 --- a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudent.java +++ b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudent.java @@ -60,7 +60,7 @@ public class UmsStudent implements Serializable { private String className; //user_id - private Integer userId; + private Long userId; } diff --git a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudentManage.java b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudentManage.java index 9974bc2..d45e758 100644 --- a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudentManage.java +++ b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudentManage.java @@ -78,7 +78,7 @@ public class UmsStudentManage implements Serializable { private String className; //user_id - private Integer userId; + private Long userId; } diff --git a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java index a81f5f0..12eb47d 100644 --- a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java @@ -91,7 +91,7 @@ public class UmsStudentManageServiceImpl extends ServiceImpl implements UmsUserService { @@ -90,7 +88,7 @@ public class UmsUserServiceImpl extends ServiceImpl impl UmsUser byUsername = lambdaQuery().eq(UmsUser::getUsername, umsUser.getUsername()) .one(); UmsStudent umsStudent = new UmsStudent(); - umsStudent.setUserId(Math.toIntExact(byUsername.getId())); + umsStudent.setUserId(byUsername.getId()); umsStudentMapper.insert(umsStudent); return umsUser; @@ -311,7 +309,7 @@ public class UmsUserServiceImpl extends ServiceImpl impl UmsUser byUsername = lambdaQuery().eq(UmsUser::getPhone, umsUser.getPhone()) .one(); UmsStudent umsStudent = new UmsStudent(); - umsStudent.setUserId(Math.toIntExact(byUsername.getId())); + umsStudent.setUserId(byUsername.getId()); umsStudentMapper.insert(umsStudent); return umsUser; From 3070602cb135c111fc0f0bfdf2e055f402fd3f33 Mon Sep 17 00:00:00 2001 From: Alan <3052806735@qq.com> Date: Mon, 12 Aug 2024 17:31:20 +0800 Subject: [PATCH 02/23] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E4=B8=8B=E9=9D=A2=E7=9A=84=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=EF=BC=8C=E4=BB=A3=E7=A0=81=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/entity/umsAdmin/UmsStudent.java | 2 + .../model/vo/message/CourseUserInfVO.java | 2 - .../impl/courses/CoursesServiceImpl.java | 218 +++++++++++------- .../impl/message/UserInboxServiceImpl.java | 1 - .../backend/utils/Chapter/SheetHandler.java | 7 - 5 files changed, 137 insertions(+), 93 deletions(-) diff --git a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudent.java b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudent.java index 6608772..949204d 100644 --- a/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudent.java +++ b/src/main/java/com/teaching/backend/model/entity/umsAdmin/UmsStudent.java @@ -6,6 +6,8 @@ import java.time.LocalDate; import java.time.LocalDateTime; import com.baomidou.mybatisplus.annotation.TableId; import java.io.Serializable; + +import io.swagger.models.auth.In; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.experimental.Accessors; diff --git a/src/main/java/com/teaching/backend/model/vo/message/CourseUserInfVO.java b/src/main/java/com/teaching/backend/model/vo/message/CourseUserInfVO.java index 364f456..87e7264 100644 --- a/src/main/java/com/teaching/backend/model/vo/message/CourseUserInfVO.java +++ b/src/main/java/com/teaching/backend/model/vo/message/CourseUserInfVO.java @@ -13,8 +13,6 @@ public class CourseUserInfVO { private String courseId; @ApiModelProperty(value = "课程name") private String courseName; - @ApiModelProperty(value = "与课程有关的用户信息集合") private List usersInf; - } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index da9f0dc..0056187 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -52,6 +52,7 @@ import java.io.File; import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.*; +import java.util.function.Function; import java.util.stream.Collectors; import static com.teaching.backend.constant.RoleConstants.TEACHER_ROLE; @@ -640,57 +641,76 @@ public class CoursesServiceImpl extends ServiceImpl impl } private List queryCourseUserForTeacher(Long userId) { - // 查询所有与该教师相关的课程 - List teacherCoursesInf = coursesMapper.selectList( - new LambdaQueryWrapper() - .apply("FIND_IN_SET({0}, teacher)", userId) - .select(Courses::getId, Courses::getTeacher) + // 1. 获取该教师负责的所有课程 + List teacherCoursesInf = coursesMapper.selectList(new LambdaQueryWrapper() + .apply("FIND_IN_SET({0}, teacher)", userId) + .select(Courses::getId, Courses::getTeacher, Courses::getName) ); + // 2. 提取所有课程的ID + Set courseIds = teacherCoursesInf.stream() + .map(Courses::getId) + .collect(Collectors.toSet()); + + // 3. 批量查询所有课程的学生ID + List studentCourses = studentCoursesMapper.selectList( + new LambdaQueryWrapper().in(StudentCourses::getCourse, courseIds) + ); + + // 4. 获取所有的学生ID + Set studentIds = studentCourses.stream() + .map(StudentCourses::getStudent) + .collect(Collectors.toSet()); + + // 5. 批量查询所有学生的信息 + List students = umsStudentMapper.selectList( + new LambdaQueryWrapper().in(UmsStudent::getUserId, studentIds) + ); + + // 6. 将学生信息缓存到Map中,Key为学生ID + Map studentMap = students.stream() + .collect(Collectors.toMap(UmsStudent::getUserId, Function.identity())); + + // 7. 处理教师信息并构建返回结果 List courseUserInfVOS = new ArrayList<>(); - for (Courses courses : teacherCoursesInf) { + for (Courses course : teacherCoursesInf) { CourseUserInfVO courseUserInfVO = new CourseUserInfVO(); + courseUserInfVO.setCourseId(course.getId()); + courseUserInfVO.setCourseName(course.getName()); + List userReadMessageTimeVOS = new ArrayList<>(); - courseUserInfVO.setCourseId(courses.getId()); - - // 查询与课程相关的所有学生 - List studentIds = studentCoursesMapper.selectList( - new LambdaQueryWrapper<>(StudentCourses.class) - .eq(StudentCourses::getCourse, courses.getId()) - ).stream().map(StudentCourses::getStudent).collect(Collectors.toList()); - - // 为每个学生创建一个新的 UserReadMessageTimeVO 对象 - for (Long studentId : studentIds) { - UmsStudent umsStudent = umsStudentMapper.selectOne( - new LambdaQueryWrapper<>(UmsStudent.class) - .eq(UmsStudent::getUserId, studentId) - .select(UmsStudent::getName) - ); - if (umsStudent == null) { - log.error("用户不存在: {}",studentId); - throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); + + // 添加学生信息 + for (StudentCourses sc : studentCourses) { + if (sc.getCourse().equals(course.getId())) { + UmsStudent student = studentMap.get(sc.getStudent()); // 类型转换 + if (student != null) { + UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); + userReadMessageTimeVO.setId(student.getUserId()); + userReadMessageTimeVO.setReceiverName(student.getName()); + userReadMessageTimeVOS.add(userReadMessageTimeVO); + } else { + log.error("学生不存在: {}", sc.getStudent()); + throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); + } } - UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); // 在循环中创建新对象 - userReadMessageTimeVO.setId(studentId); - userReadMessageTimeVO.setReceiverName(umsStudent.getName()); - userReadMessageTimeVOS.add(userReadMessageTimeVO); } - // 为每个教师创建一个新的 UserReadMessageTimeVO 对象 - String[] teacherUserIds = courses.getTeacher().split(","); + // 添加教师信息 + String[] teacherUserIds = course.getTeacher().split(","); for (String teacherId : teacherUserIds) { UmsTeacher umsTeacher = umsTeacherMapper.selectOne( - new LambdaQueryWrapper() - .eq(UmsTeacher::getUserId, teacherId) + new LambdaQueryWrapper().eq(UmsTeacher::getUserId, teacherId) ); - if (umsTeacher == null) { - log.error("教师不存在: {}",teacherId); + if (umsTeacher != null) { + UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); + userReadMessageTimeVO.setId(umsTeacher.getUserId()); + userReadMessageTimeVO.setReceiverName(umsTeacher.getName()); + userReadMessageTimeVOS.add(userReadMessageTimeVO); + } else { + log.error("教师不存在: {}", teacherId); throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); } - UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); // 在循环中创建新对象 - userReadMessageTimeVO.setId(umsTeacher.getUserId()); - userReadMessageTimeVO.setReceiverName(umsTeacher.getName()); - userReadMessageTimeVOS.add(userReadMessageTimeVO); } courseUserInfVO.setUsersInf(userReadMessageTimeVOS); @@ -700,64 +720,94 @@ public class CoursesServiceImpl extends ServiceImpl impl } + + private List queryCourseUserForStudent(Long userId) { - // 查询学生所参与的所有课程 - List studentCoursesList = studentCoursesMapper.selectList( - new LambdaQueryWrapper() - .eq(StudentCourses::getStudent, userId) - .select(StudentCourses::getCourse) + // 1. 获取学生参与的所有课程 + List studentCourses = studentCoursesMapper.selectList( + new LambdaQueryWrapper().eq(StudentCourses::getStudent, userId) + ); + + // 2. 提取所有课程的ID + Set courseIds = studentCourses.stream() + .map(StudentCourses::getCourse) + .collect(Collectors.toSet()); + + // 3. 批量查询所有课程的信息 + List coursesList = coursesMapper.selectBatchIds(courseIds); + + // 4. 获取所有的教师ID + Set teacherIds = coursesList.stream() + .flatMap(course -> Arrays.stream(course.getTeacher().split(","))) + .map(Long::parseLong) + .collect(Collectors.toSet()); + + // 5. 批量查询所有教师的信息 + List teachers = umsTeacherMapper.selectList( + new LambdaQueryWrapper().in(UmsTeacher::getUserId, teacherIds) + ); + + // 6. 将教师信息缓存到Map中,Key为教师ID + Map teacherMap = teachers.stream() + .collect(Collectors.toMap(UmsTeacher::getUserId, Function.identity())); + + // 7. 批量查询所有课程的学生信息 + List allStudentCourses = studentCoursesMapper.selectList( + new LambdaQueryWrapper().in(StudentCourses::getCourse, courseIds) ); + // 8. 提取所有学生的ID + Set allStudentIds = allStudentCourses.stream() + .map(StudentCourses::getStudent) + .collect(Collectors.toSet()); + + // 9. 批量查询所有学生的信息 + List students = umsStudentMapper.selectList( + new LambdaQueryWrapper().in(UmsStudent::getUserId, allStudentIds) + ); + + // 10. 将学生信息缓存到Map中,Key为学生ID + Map studentMap = students.stream() + .collect(Collectors.toMap(UmsStudent::getUserId, Function.identity())); + + // 11. 处理课程信息并构建返回结果 List courseUserInfVOS = new ArrayList<>(); - for (StudentCourses studentCourse : studentCoursesList) { + for (Courses course : coursesList) { CourseUserInfVO courseUserInfVO = new CourseUserInfVO(); + courseUserInfVO.setCourseId(course.getId()); + courseUserInfVO.setCourseName(course.getName()); + List userReadMessageTimeVOS = new ArrayList<>(); - courseUserInfVO.setCourseId(studentCourse.getCourse()); - - // 查询与课程相关的所有学生 - List studentIds = studentCoursesMapper.selectList( - new LambdaQueryWrapper<>(StudentCourses.class) - .eq(StudentCourses::getCourse, studentCourse.getCourse()) - ).stream().map(StudentCourses::getStudent).collect(Collectors.toList()); - - // 为每个学生创建一个新的 UserReadMessageTimeVO 对象 - for (Long studentId : studentIds) { - UmsStudent umsStudent = umsStudentMapper.selectOne( - new LambdaQueryWrapper<>(UmsStudent.class) - .eq(UmsStudent::getUserId, studentId) - .select(UmsStudent::getName) - ); - if (umsStudent == null) { - log.error("用户不存在: {}", studentId); + + // 添加教师信息 + String[] courseTeacherIds = course.getTeacher().split(","); + for (String teacherId : courseTeacherIds) { + UmsTeacher umsTeacher = teacherMap.get(Long.valueOf(teacherId)); + if (umsTeacher != null) { + UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); + userReadMessageTimeVO.setId(umsTeacher.getUserId()); + userReadMessageTimeVO.setReceiverName(umsTeacher.getName()); + userReadMessageTimeVOS.add(userReadMessageTimeVO); + } else { + log.error("教师不存在: {}", teacherId); throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); } - UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); // 在循环中创建新对象 - userReadMessageTimeVO.setId(studentId); - userReadMessageTimeVO.setReceiverName(umsStudent.getName()); - userReadMessageTimeVOS.add(userReadMessageTimeVO); } - // 查询与课程相关的所有教师 - Courses course = coursesMapper.selectById(studentCourse.getCourse()); - if (course != null) { - String[] teacherUserIds = course.getTeacher().split(","); - for (String teacherId : teacherUserIds) { - UmsTeacher umsTeacher = umsTeacherMapper.selectOne( - new LambdaQueryWrapper() - .eq(UmsTeacher::getUserId, teacherId) - ); - if (umsTeacher == null) { - log.error("教师不存在: {}", teacherId); + // 添加学生信息 + for (StudentCourses sc : allStudentCourses) { + if (sc.getCourse().equals(course.getId())) { + UmsStudent student = studentMap.get(sc.getStudent()); // 类型转换 + if (student != null) { + UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); + userReadMessageTimeVO.setId(student.getUserId()); + userReadMessageTimeVO.setReceiverName(student.getName()); + userReadMessageTimeVOS.add(userReadMessageTimeVO); + } else { + log.error("学生不存在: {}", sc.getStudent()); throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); } - UserReadMessageTimeVO userReadMessageTimeVO = new UserReadMessageTimeVO(); // 在循环中创建新对象 - userReadMessageTimeVO.setId(umsTeacher.getUserId()); - userReadMessageTimeVO.setReceiverName(umsTeacher.getName()); - userReadMessageTimeVOS.add(userReadMessageTimeVO); } - } else { - log.error("课程不存在: {}", studentCourse.getCourse()); - throw new BusinessException(ErrorCode.PARAMS_COURSE_NOTEXISTS); } courseUserInfVO.setUsersInf(userReadMessageTimeVOS); @@ -766,6 +816,8 @@ public class CoursesServiceImpl extends ServiceImpl impl return courseUserInfVOS; } + + } diff --git a/src/main/java/com/teaching/backend/service/impl/message/UserInboxServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/message/UserInboxServiceImpl.java index 3dd07ca..654eb61 100644 --- a/src/main/java/com/teaching/backend/service/impl/message/UserInboxServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/message/UserInboxServiceImpl.java @@ -56,7 +56,6 @@ public class UserInboxServiceImpl extends ServiceImpl queryReceiveMessages(MessagesQuery messagesQuery) { // 先按用户的id找到其的消息列表 默认看未删除的,(是否读 作为筛选条件后传进去) diff --git a/src/main/java/com/teaching/backend/utils/Chapter/SheetHandler.java b/src/main/java/com/teaching/backend/utils/Chapter/SheetHandler.java index d791fa6..9b1e47a 100644 --- a/src/main/java/com/teaching/backend/utils/Chapter/SheetHandler.java +++ b/src/main/java/com/teaching/backend/utils/Chapter/SheetHandler.java @@ -5,15 +5,8 @@ import com.teaching.backend.exception.BusinessException; import com.teaching.backend.mapper.chapter.TemporaryChapterMapper; import com.teaching.backend.model.dto.chapter.ChapterExcelDTO; import com.teaching.backend.service.chapter.IChapterService; - -import jdk.nashorn.internal.ir.IfNode; -import org.apache.poi.ss.util.CellRangeAddress; -import org.apache.poi.ss.util.CellReference; import org.apache.poi.xssf.eventusermodel.XSSFSheetXMLHandler; - import org.apache.poi.xssf.usermodel.XSSFComment; - -import org.apache.poi.xssf.usermodel.XSSFSheet; import org.springframework.transaction.annotation.Transactional; import java.util.*; From dd6e7d9dc24cb4f6d98a67151930c1dc9f7a6502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E8=A3=81?= <14186472+wenyu441069198@user.noreply.gitee.com> Date: Mon, 12 Aug 2024 18:51:02 +0800 Subject: [PATCH 03/23] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E6=9F=A5?= =?UTF-8?q?=E8=80=81=E5=B8=88=E6=89=80=E6=95=99=E7=9A=84=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/mapper/umsAdmin/UmsUserMapper.java | 3 +-- .../impl/courses/CoursesServiceImpl.java | 17 ++++++++++------- .../impl/favour/SeCourseFavourServiceImpl.java | 5 +---- .../CourseLearningRecordServiceImpl.java | 4 ++-- .../KnowledgeLearningRecordServiceImpl.java | 8 +------- src/main/resources/mapper/UmsUserMapper.xml | 2 +- 6 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsUserMapper.java b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsUserMapper.java index 7f422de..8ce099d 100644 --- a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsUserMapper.java +++ b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsUserMapper.java @@ -1,7 +1,6 @@ package com.teaching.backend.mapper.umsAdmin; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.teaching.backend.model.entity.courses.StudentCourses; import com.teaching.backend.model.entity.umsAdmin.UmsRole; import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; import com.teaching.backend.model.entity.umsAdmin.UmsUser; @@ -19,5 +18,5 @@ public interface UmsUserMapper extends BaseMapper { UmsStudentVO getByIdStudent(String id); - String getbyIdRoleId(String userId); + String getByIdRoleId(String userId); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index 0056187..24f8d03 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -361,6 +361,7 @@ public class CoursesServiceImpl extends ServiceImpl impl @Override public List queryStudentList(String userId) { LinkedHashSet umsStudentManageList = queryTeacherByStudentList(userId); + System.out.println("1111111"+umsStudentManageList); List personalCenterStudentListVOList = new ArrayList<>(); PersonalCenterStudentListVO personalCenterStudentListVO = null; for (UmsStudentManage umsStudentManage : umsStudentManageList) { @@ -375,7 +376,7 @@ public class CoursesServiceImpl extends ServiceImpl impl @Override public LinkedHashSet queryTeacherByStudentList(String userId) { - String roleId = umsUserMapper.getbyIdRoleId(userId); + String roleId = umsUserMapper.getByIdRoleId(userId); CourseQuery courseQuery = new CourseQuery(); courseQuery.setUserId(userId); LinkedHashSet umsStudentManageList = new LinkedHashSet<>(); @@ -388,13 +389,15 @@ public class CoursesServiceImpl extends ServiceImpl impl List courseLearningRecordList = new ArrayList<>(); for (StudentCourses studentUsername : studentUsernames) { CourseLearningRecord courseLearningRecord = courseLearningRecordMapper.selectNewRecord(String.valueOf(studentUsername.getStudent())); - courseLearningRecordList.add(courseLearningRecord); - } - courseLearningRecordList = courseLearningRecordList.stream().sorted(Comparator.comparing(CourseLearningRecord::getTimes).reversed()).collect(Collectors.toList()); - for (CourseLearningRecord courseLearningRecord : courseLearningRecordList) { - UmsStudentManage umsStudentManage = umsStudentManageMapper.queryStudent(courseLearningRecord.getUserId()); - umsStudentManageList.add(umsStudentManage); + if (courseLearningRecord != null){ + courseLearningRecordList.add(courseLearningRecord); + } } + courseLearningRecordList = courseLearningRecordList.stream().sorted(Comparator.comparing(CourseLearningRecord::getTimes).reversed()).collect(Collectors.toList()); + for (CourseLearningRecord courseLearningRecord : courseLearningRecordList) { + UmsStudentManage umsStudentManage = umsStudentManageMapper.queryStudent(courseLearningRecord.getUserId()); + umsStudentManageList.add(umsStudentManage); + } } return umsStudentManageList; } diff --git a/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java index a260644..5cac41a 100644 --- a/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/favour/SeCourseFavourServiceImpl.java @@ -16,9 +16,6 @@ import com.teaching.backend.mapper.favour.SeCourseFavourMapper; import com.teaching.backend.mapper.umsAdmin.UmsUserMapper; import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.entity.favour.SeCourseFavour; -import com.teaching.backend.model.entity.favour.SeKnowFavour; -import com.teaching.backend.model.entity.favour.SeResourceFavour; -import com.teaching.backend.model.entity.umsAdmin.UmsUser; import com.teaching.backend.model.vo.courses.CoursesVO; import com.teaching.backend.model.vo.favour.CourseFavourDetailVO; import com.teaching.backend.service.courses.ICoursesService; @@ -157,7 +154,7 @@ public class SeCourseFavourServiceImpl extends ServiceImpl queryNewCollect(String userId) { - String roleId = umsUserMapper.getbyIdRoleId(userId); + String roleId = umsUserMapper.getByIdRoleId(userId); List coursesList = new ArrayList<>(); if (roleId.equals("1")){ //老师 diff --git a/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java index 4c9eae5..fb3e253 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java @@ -123,7 +123,7 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl queryCourseList(String userId) { - String roleId = umsUserMapper.getbyIdRoleId(userId); + String roleId = umsUserMapper.getByIdRoleId(userId); List coursesList = new ArrayList<>(); if (roleId.equals("1")){ List courseIds = courseLearningRecordMapper.selectMaxNumber(); @@ -148,7 +148,7 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl queryrecommendCourses(String userId) { - String roleId = umsUserMapper.getbyIdRoleId(userId); + String roleId = umsUserMapper.getByIdRoleId(userId); if (roleId.equals("1")) { diff --git a/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java index cfe8d3e..c392c53 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java @@ -12,18 +12,12 @@ import com.teaching.backend.mapper.umsAdmin.UmsUserMapper; import com.teaching.backend.model.entity.KnowGraph.KnowledgeLearningNumber; -import com.teaching.backend.model.entity.courses.CourseLearningNumber; - -import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.entity.knowtmp.Knowtmp; import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; -import com.teaching.backend.model.vo.courses.CoursesVO; import com.teaching.backend.model.vo.knowGraph.KnowVO; import com.teaching.backend.model.vo.records.KnowledgeLearningRecordVo; -import com.teaching.backend.service.Know.KnowService; -import com.teaching.backend.service.impl.courses.CourseLearningNumberServiceImpl; import com.teaching.backend.service.impl.knowledge.KnowledgeLearningNumberServiceImpl; import com.teaching.backend.service.knowtmp.KnowtmpService; import com.teaching.backend.service.records.IKnowledgeLearningRecordService; @@ -141,7 +135,7 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl queryMaxKnowledge(String userId) { - String roleId = umsUserMapper.getbyIdRoleId(userId); + String roleId = umsUserMapper.getByIdRoleId(userId); List coursesList = new ArrayList<>(); KnowVO knowVO = null; if (roleId.equals("1")){ diff --git a/src/main/resources/mapper/UmsUserMapper.xml b/src/main/resources/mapper/UmsUserMapper.xml index 5b56d4a..6ea4599 100644 --- a/src/main/resources/mapper/UmsUserMapper.xml +++ b/src/main/resources/mapper/UmsUserMapper.xml @@ -76,7 +76,7 @@ WHERE s.user_id = #{id} - SELECT us.role_id roleId FROM From d1da72ad1ab9de09351cdbf55c40065f7da23000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E8=A3=81?= <14186472+wenyu441069198@user.noreply.gitee.com> Date: Mon, 12 Aug 2024 19:24:35 +0800 Subject: [PATCH 04/23] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E6=9F=A5?= =?UTF-8?q?=E8=80=81=E5=B8=88=E6=89=80=E6=95=99=E7=9A=84=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/courses/ICoursesService.java | 2 ++ .../impl/courses/CoursesServiceImpl.java | 27 ++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java index ac2e4c7..6a507d9 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -51,6 +51,8 @@ public interface ICoursesService extends IService { Map getPagePageSize2(int page, int pageSize); List queryStudentList(String userId); + LinkedHashSet queryTeacherByStudentLearningRecordList(String userId); + LinkedHashSet queryTeacherByStudentList(String userId); List getUserInfByCourse(Long userId); diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index 24f8d03..313b3aa 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -360,8 +360,7 @@ public class CoursesServiceImpl extends ServiceImpl impl @Override public List queryStudentList(String userId) { - LinkedHashSet umsStudentManageList = queryTeacherByStudentList(userId); - System.out.println("1111111"+umsStudentManageList); + LinkedHashSet umsStudentManageList = queryTeacherByStudentLearningRecordList(userId); List personalCenterStudentListVOList = new ArrayList<>(); PersonalCenterStudentListVO personalCenterStudentListVO = null; for (UmsStudentManage umsStudentManage : umsStudentManageList) { @@ -375,7 +374,7 @@ public class CoursesServiceImpl extends ServiceImpl impl } @Override - public LinkedHashSet queryTeacherByStudentList(String userId) { + public LinkedHashSet queryTeacherByStudentLearningRecordList(String userId) { String roleId = umsUserMapper.getByIdRoleId(userId); CourseQuery courseQuery = new CourseQuery(); courseQuery.setUserId(userId); @@ -404,7 +403,27 @@ public class CoursesServiceImpl extends ServiceImpl impl throw new BusinessException(400,"只有老师才有此功能"); } - + @Override + public LinkedHashSet queryTeacherByStudentList(String userId) { + String roleId = umsUserMapper.getByIdRoleId(userId); + CourseQuery courseQuery = new CourseQuery(); + courseQuery.setUserId(userId); + LinkedHashSet umsStudentManageList = new LinkedHashSet<>(); + if (roleId.equals("1")){ + PageDTO queryCourses = queryCourses(courseQuery); + List coursesList = queryCourses.getList(); + List courseIds = coursesList.stream().map(CoursesVO::getId).collect(Collectors.toList()); + for (String courseId : courseIds) { + List studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); + for (StudentCourses studentUsername : studentUsernames) { + UmsStudentManage umsStudentManage = umsStudentManageMapper.queryStudent(String.valueOf(studentUsername.getStudent())); + umsStudentManageList.add(umsStudentManage); + } + } + return umsStudentManageList; + } + throw new BusinessException(400,"只有老师才有此功能"); + } @Override public List getPagePageSize(int page, int pageSize) { From ce9cc317365bddd3cc79c11f0a9f85633525d381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E8=A3=81?= <14186472+wenyu441069198@user.noreply.gitee.com> Date: Mon, 12 Aug 2024 22:39:34 +0800 Subject: [PATCH 05/23] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E6=9F=A5?= =?UTF-8?q?=E8=80=81=E5=B8=88=E6=89=80=E6=95=99=E7=9A=84=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/service/impl/courses/CoursesServiceImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index 313b3aa..7d5eab9 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -417,7 +417,9 @@ public class CoursesServiceImpl extends ServiceImpl impl List studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); for (StudentCourses studentUsername : studentUsernames) { UmsStudentManage umsStudentManage = umsStudentManageMapper.queryStudent(String.valueOf(studentUsername.getStudent())); - umsStudentManageList.add(umsStudentManage); + if (umsStudentManage != null){ + umsStudentManageList.add(umsStudentManage); + } } } return umsStudentManageList; From 908d8086817e279fb6b01f8c6809cdd0a0e351a5 Mon Sep 17 00:00:00 2001 From: Alan <3052806735@qq.com> Date: Tue, 13 Aug 2024 10:52:47 +0800 Subject: [PATCH 06/23] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=B6=88=E6=81=AF=EF=BC=88=E5=AD=A6=E7=94=9F=E5=8F=AA=E8=83=BD?= =?UTF-8?q?=E5=8D=95=E5=8F=91=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../teaching/backend/common/ErrorCode.java | 3 +- .../impl/message/MessagesServiceImpl.java | 20 +++++++++++-- .../impl/message/UserInboxServiceImpl.java | 29 ++++++++++++------- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/teaching/backend/common/ErrorCode.java b/src/main/java/com/teaching/backend/common/ErrorCode.java index 4883d57..041682c 100644 --- a/src/main/java/com/teaching/backend/common/ErrorCode.java +++ b/src/main/java/com/teaching/backend/common/ErrorCode.java @@ -26,7 +26,8 @@ public enum ErrorCode { NO_AUTH_ERROR(40101, "无权限"), NOT_FOUND_ERROR(40400, "请求数据不存在"), CONTENT_EXISTS(41000, "内容存在"), - + STUDENT_ROLE_CANT_MULTIPLESEND(41001, "学生用户不能群发,只能单发"), + LEAST_ONE_USER(41002, "最少选择一个用户"), KNOWS_EXISTS(41001, "存在关联的知识点"), ADD_RELATION_FAILED(41002, "添加关系失败"), diff --git a/src/main/java/com/teaching/backend/service/impl/message/MessagesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/message/MessagesServiceImpl.java index 6205d54..6b7b2c4 100644 --- a/src/main/java/com/teaching/backend/service/impl/message/MessagesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/message/MessagesServiceImpl.java @@ -7,9 +7,11 @@ import com.teaching.backend.common.ErrorCode; import com.teaching.backend.exception.BusinessException; import com.teaching.backend.mapper.message.MessagesMapper; import com.teaching.backend.mapper.message.UserInboxMapper; +import com.teaching.backend.mapper.umsAdmin.UmsUserMapper; import com.teaching.backend.model.dto.message.SysMessageDTO; import com.teaching.backend.model.entity.message.SysMessages; import com.teaching.backend.model.entity.message.UserInbox; +import com.teaching.backend.model.entity.umsAdmin.UmsUser; import com.teaching.backend.service.message.IMessagesService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; @@ -38,6 +40,8 @@ public class MessagesServiceImpl extends ServiceImpl receiverIds = Arrays.stream(sysMessageDTO.getReceiverId().split(",")) .map(Long::valueOf) .collect(Collectors.toList()); + if (receiverIds.size()<1){ + throw new BusinessException(ErrorCode.LEAST_ONE_USER); + } + + // 4.判断是什么用户,只有教师可以群发,学生只能单发 + String roleId = umsUserMapper.selectOne(new LambdaQueryWrapper<>(UmsUser.class) + .eq(UmsUser::getId, sysMessageDTO.getSenderId())).getRoleId(); + if(roleId.equals("2")){ + if (receiverIds.size()>1){ + throw new BusinessException(ErrorCode.STUDENT_ROLE_CANT_MULTIPLESEND); + } + } - // 4.数据写入收件箱 + // 5.数据写入收件箱 List userInboxes = receiverIds.stream() .map(receiverId -> { UserInbox userInbox = new UserInbox(); @@ -68,7 +84,7 @@ public class MessagesServiceImpl extends ServiceImpl querySendMessages(MessagesQuery messagesQuery) { - // 初始化一个按发送时间降序排序的Page对象 + // 1. 初始化一个按发送时间降序排序的Page对象 Page page = messagesQuery.toMpPage("send_time", false); - // 根据条件查询SysMessages表 + // 2. 根据条件查询SysMessages表 Page p = messagesService.page(page, new LambdaQueryWrapper() .eq(SysMessages::getSenderId, messagesQuery.getUserId()) @@ -137,7 +137,7 @@ public class UserInboxServiceImpl extends ServiceImpl转换为PageDTO + // 3. 将Page转换为PageDTO PageDTO messages = PageDTO.of(p, SysMessageVO.class); List messagesList = messages.getList(); @@ -145,31 +145,33 @@ public class UserInboxServiceImpl extends ServiceImpl courseIds = messagesList.stream() .map(SysMessageVO::getCourseId) .filter(Objects::nonNull) .collect(Collectors.toSet()); + // 5. 批量查询课程ID对应的课程名称 并把ID:name 对应到一起 Map courseNames = coursesMapper.selectBatchIds(courseIds).stream() .collect(Collectors.toMap(Courses::getId, Courses::getName)); - // 批量查询所有用户收件箱数据 + // 6. 批量查询当前用户对应的消息集合messageIds Set messageIds = messagesList.stream() .map(SysMessageVO::getId) .collect(Collectors.toSet()); + // 在用户邮箱中批量查询 对应消息的 信息(消息id,接受者id,是否已读) List allUserInboxes = userInboxMapper.selectList( new LambdaQueryWrapper() .in(UserInbox::getMessageId, messageIds) .select(UserInbox::getMessageId, UserInbox::getReceiverId, UserInbox::getIsRead) ); - // 将UserInbox数据按消息ID进行分组 + // 7. 将UserInbox数据按消息ID进行分组(已经初步得到了消息的详情) Map> userInboxesByMessageId = allUserInboxes.stream() .collect(Collectors.groupingBy(UserInbox::getMessageId)); - // 缓存用户名称以避免重复查询 + // 8. 缓存用户名称以避免重复查询 Map userNamesCache = new HashMap<>(); for (SysMessageVO sysMessageVO : messagesList) { @@ -200,7 +202,7 @@ public class UserInboxServiceImpl extends ServiceImpl().eq(UmsTeacher::getUserId, id) ); - return umsTeacher != null ? umsTeacher.getName() : null; + return umsTeacher != null ? umsTeacher.getName() : "教师不存在"; } }); @@ -212,20 +214,27 @@ public class UserInboxServiceImpl extends ServiceImpl(UserInbox.class) + .eq(UserInbox::getMessageId, messagesQuery.getMessageId()) + .eq(UserInbox::getReceiverId, messagesQuery.getUserId())); + if (!(count > 0)){ + throw new BusinessException(ErrorCode.MESSAGE_NO_EXIT); + } SysMessages sysMessage = messagesService.getById(messagesQuery.getMessageId()); SysMessageVO sysMessageVO = new SysMessageVO(); sysMessageVO.setId(messagesQuery.getMessageId()); sysMessageVO.setContent(sysMessage.getContent()); sysMessageVO.setSenderId(messagesQuery.getUserId()); -// 获取发件人信息 + //获取发件人信息 UmsTeacher umsTeacher = umsTeacherMapper.selectOne( new LambdaQueryWrapper() .eq(UmsTeacher::getUserId, sysMessage.getSenderId())); From 07c013a57d88796725763fb823f737c50f1e48a7 Mon Sep 17 00:00:00 2001 From: you hang <2998465706@qq.com> Date: Tue, 13 Aug 2024 11:07:22 +0800 Subject: [PATCH 07/23] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=9B=B4=E6=96=B003?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/teaching/backend/controller/Know/KnowController.java | 2 +- .../teaching/backend/controller/chapter/ChapterController2.java | 2 +- .../backend/controller/resource/ResourceController.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/teaching/backend/controller/Know/KnowController.java b/src/main/java/com/teaching/backend/controller/Know/KnowController.java index 9e3bc6f..c508fc2 100644 --- a/src/main/java/com/teaching/backend/controller/Know/KnowController.java +++ b/src/main/java/com/teaching/backend/controller/Know/KnowController.java @@ -22,7 +22,7 @@ import java.util.Set; @RestController -@RequestMapping("/knowNeo") +@RequestMapping("/api/knowNeo") public class KnowController { @Autowired diff --git a/src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java b/src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java index d77e609..6f0229d 100644 --- a/src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java +++ b/src/main/java/com/teaching/backend/controller/chapter/ChapterController2.java @@ -30,7 +30,7 @@ import java.util.List; */ @Api(tags = "课程章节管理接口2") @RestController -@RequestMapping("/chapter2") +@RequestMapping("/api/chapter2") public class ChapterController2 { @Autowired diff --git a/src/main/java/com/teaching/backend/controller/resource/ResourceController.java b/src/main/java/com/teaching/backend/controller/resource/ResourceController.java index 1dc7cc1..29cdfd4 100644 --- a/src/main/java/com/teaching/backend/controller/resource/ResourceController.java +++ b/src/main/java/com/teaching/backend/controller/resource/ResourceController.java @@ -22,7 +22,7 @@ import java.util.Set; @RestController -@RequestMapping("/resource") +@RequestMapping("/api/resource") public class ResourceController { @Autowired From 9735c0e1bdfc692d70c7c36c357982891cc75d85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E8=A3=81?= <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 13 Aug 2024 11:09:16 +0800 Subject: [PATCH 08/23] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E6=9F=A5?= =?UTF-8?q?=E8=80=81=E5=B8=88=E6=89=80=E6=95=99=E7=9A=84=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/service/courses/ICoursesService.java | 1 + .../service/impl/courses/CoursesServiceImpl.java | 13 ++++++++----- .../impl/umsAdmin/UmsStudentManageServiceImpl.java | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java index 6a507d9..e08a348 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -4,6 +4,7 @@ package com.teaching.backend.service.courses; import com.baomidou.mybatisplus.extension.service.IService; import com.teaching.backend.model.dto.courses.CoursesDTO; import com.teaching.backend.model.dto.courses.PageDTO; +import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO; import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.entity.umsAdmin.UmsStudent; import com.teaching.backend.model.entity.umsAdmin.UmsStudentManage; diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index 7d5eab9..005414f 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -20,6 +20,7 @@ import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; import com.teaching.backend.mapper.umsAdmin.UmsUserMapper; import com.teaching.backend.model.dto.courses.CoursesDTO; import com.teaching.backend.model.dto.courses.PageDTO; +import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO; import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.entity.courses.*; import com.teaching.backend.model.entity.records.CourseLearningRecord; @@ -364,11 +365,13 @@ public class CoursesServiceImpl extends ServiceImpl impl List personalCenterStudentListVOList = new ArrayList<>(); PersonalCenterStudentListVO personalCenterStudentListVO = null; for (UmsStudentManage umsStudentManage : umsStudentManageList) { - personalCenterStudentListVO = new PersonalCenterStudentListVO(); - personalCenterStudentListVO.setIcon(umsStudentManage.getIcon()); - personalCenterStudentListVO.setName(umsStudentManage.getName()); - personalCenterStudentListVO.setNumber(umsStudentManage.getNumber()); - personalCenterStudentListVOList.add(personalCenterStudentListVO); + if (umsStudentManage != null){ + personalCenterStudentListVO = new PersonalCenterStudentListVO(); + personalCenterStudentListVO.setIcon(umsStudentManage.getIcon()); + personalCenterStudentListVO.setName(umsStudentManage.getName()); + personalCenterStudentListVO.setNumber(umsStudentManage.getNumber()); + personalCenterStudentListVOList.add(personalCenterStudentListVO); + } } return personalCenterStudentListVOList; } diff --git a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java index 12eb47d..410f1bd 100644 --- a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java @@ -53,7 +53,7 @@ public class UmsStudentManageServiceImpl extends ServiceImpl pageQuery(UmsStudentPageQueryDTO umsStudentPageQueryDTO) { - LinkedHashSet umsStudentManages = coursesService.queryTeacherByStudentList(umsStudentPageQueryDTO.getUserId()); + LinkedHashSet umsStudentManages = coursesService.queryTeacherByStudentList(umsStudentPageQueryDTO.getName()); //总记录数 int totalCount = umsStudentManages.size(); From 531c440b1366176b17febe678a47b4c994ff9522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E8=A3=81?= <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 13 Aug 2024 15:50:16 +0800 Subject: [PATCH 09/23] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E7=AE=A1=E7=90=86=E6=A8=A1=E7=B3=8A=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../umsAdmin/UmsStudentManageServiceImpl.java | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java index 410f1bd..5e5ae6c 100644 --- a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java @@ -53,7 +53,7 @@ public class UmsStudentManageServiceImpl extends ServiceImpl pageQuery(UmsStudentPageQueryDTO umsStudentPageQueryDTO) { - LinkedHashSet umsStudentManages = coursesService.queryTeacherByStudentList(umsStudentPageQueryDTO.getName()); + LinkedHashSet umsStudentManages = coursesService.queryTeacherByStudentList(umsStudentPageQueryDTO.getUserId()); //总记录数 int totalCount = umsStudentManages.size(); @@ -61,17 +61,34 @@ public class UmsStudentManageServiceImpl extends ServiceImpl umsStudentManageList = umsStudentManages.stream() - .skip((umsStudentPageQueryDTO.getPage() - 1) * umsStudentPageQueryDTO.getPageSize()) - .limit(umsStudentPageQueryDTO.getPageSize()) - .collect(Collectors.toList()); - Map result = new HashMap<>(); - result.put("Records", umsStudentManageList); result.put("totalCount", totalCount); result.put("totalPages", totalPages); result.put("currentPage", umsStudentPageQueryDTO.getPage()); + //对集合里的数据进行模糊和分页查询 + if (umsStudentPageQueryDTO.getName() != null){ + List umsStudentManageList = umsStudentManages.stream() + .filter(studentManage -> studentManage.getName().contains(umsStudentPageQueryDTO.getName())) + .skip((umsStudentPageQueryDTO.getPage() - 1) * umsStudentPageQueryDTO.getPageSize()) + .limit(umsStudentPageQueryDTO.getPageSize()) + .collect(Collectors.toList()); + result.put("Records", umsStudentManageList); + }else if (umsStudentPageQueryDTO.getNumber() != null){ + List umsStudentManageList = umsStudentManages.stream() + .filter(studentManage -> studentManage.getNumber().contains(umsStudentPageQueryDTO.getNumber())) + .skip((umsStudentPageQueryDTO.getPage() - 1) * umsStudentPageQueryDTO.getPageSize()) + .limit(umsStudentPageQueryDTO.getPageSize()) + .collect(Collectors.toList()); + result.put("Records", umsStudentManageList); + }else { + List umsStudentManageList = umsStudentManages.stream() + .skip((umsStudentPageQueryDTO.getPage() - 1) * umsStudentPageQueryDTO.getPageSize()) + .limit(umsStudentPageQueryDTO.getPageSize()) + .collect(Collectors.toList()); + result.put("Records", umsStudentManageList); + } + return result; } From 3c979067cb022fcbb059f7fa436459407d309964 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 13 Aug 2024 17:39:19 +0800 Subject: [PATCH 10/23] =?UTF-8?q?=E8=B5=84=E8=AE=AF=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/cms/CmsCategoryController.java | 64 ++++++++++++++++ .../controller/cms/CmsEssayController.java | 70 +++++++++++++++++ .../backend/mapper/cms/CmsCategoryMapper.java | 17 +++++ .../backend/mapper/cms/CmsEssayMapper.java | 17 +++++ .../backend/model/entity/cms/CmsCategory.java | 61 +++++++++++++++ .../backend/model/entity/cms/CmsEssay.java | 75 +++++++++++++++++++ .../service/cms/ICmsCategoryService.java | 27 +++++++ .../backend/service/cms/ICmsEssayService.java | 27 +++++++ .../impl/cms/CmsCategoryServiceImpl.java | 72 ++++++++++++++++++ .../service/impl/cms/CmsEssayServiceImpl.java | 48 ++++++++++++ .../backend/utils/MyMetaObjectHandler.java | 26 +++++++ 11 files changed, 504 insertions(+) create mode 100644 src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java create mode 100644 src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java create mode 100644 src/main/java/com/teaching/backend/mapper/cms/CmsCategoryMapper.java create mode 100644 src/main/java/com/teaching/backend/mapper/cms/CmsEssayMapper.java create mode 100644 src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java create mode 100644 src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java create mode 100644 src/main/java/com/teaching/backend/service/cms/ICmsCategoryService.java create mode 100644 src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java create mode 100644 src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java create mode 100644 src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java create mode 100644 src/main/java/com/teaching/backend/utils/MyMetaObjectHandler.java diff --git a/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java b/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java new file mode 100644 index 0000000..8477b2a --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java @@ -0,0 +1,64 @@ +package com.teaching.backend.controller.cms; + + +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.model.entity.cms.CmsCategory; +import com.teaching.backend.service.impl.cms.CmsCategoryServiceImpl; +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + *

+ * 前端控制器 + *

+ * + * @author author + * @since 2024-08-13 + */ +@Api(tags = "栏目管理") +@RestController +@RequestMapping("/api/cms-category") +public class CmsCategoryController { + + @Resource + private CmsCategoryServiceImpl cmsCategoryService; + /** + * 添加栏目 + * @param cmsCategory + * @return + */ + @PostMapping("/add") + public BaseResponse addCategory(CmsCategory cmsCategory){ + return cmsCategoryService.addCategory(cmsCategory); + } + /**' + * 删除栏目 + * @param ids + * @return + */ + @DeleteMapping("/delete") + public BaseResponse deleteCategory(@RequestParam List ids){ + return cmsCategoryService.deleteCategory(ids); + } + /** + * 编辑栏目 + * @param cmsCategory + * @return + */ + @PutMapping("/edit") + public BaseResponse editCategory(CmsCategory cmsCategory){ + return cmsCategoryService.editCategory(cmsCategory); + } + /** + * 查询栏目 + * @return + */ + @GetMapping("/query") + public BaseResponse> queryCategory(){ + return cmsCategoryService.queryCategory(); + } + +} diff --git a/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java b/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java new file mode 100644 index 0000000..b89fa48 --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java @@ -0,0 +1,70 @@ +package com.teaching.backend.controller.cms; + + +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.model.entity.cms.CmsCategory; +import com.teaching.backend.model.entity.cms.CmsEssay; +import com.teaching.backend.service.impl.cms.CmsEssayServiceImpl; +import io.swagger.annotations.Api; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import java.util.List; + +/** + *

+ * 前端控制器 + *

+ * + * @author author + * @since 2024-08-13 + */ +@Api(tags = "文章管理") +@RestController +@RequestMapping("/api/cms-essay") +public class CmsEssayController { + + @Resource + private CmsEssayServiceImpl cmsEssayService; + + /** + * 添加文章 + * @param cmsEssay + * @return + */ + @PostMapping("/add") + public BaseResponse addEssay(CmsEssay cmsEssay){ + return cmsEssayService.addEssay(cmsEssay); + } + + /** + * 删除文章 + * @param ids + * @return + */ + @DeleteMapping("/delete") + public BaseResponse deleteEssay(@RequestParam List ids){ + return cmsEssayService.deleteEssay(ids); + } + + /** + * 编辑文章 + * @param cmsEssay + * @return + */ + @PutMapping("/edit") + public BaseResponse editEssay(CmsEssay cmsEssay){ + return cmsEssayService.editEssay(cmsEssay); + } + + /** + * 查询文章 + * @param category_id + * @return + */ + @GetMapping("/query") + public BaseResponse> queryEssay(Integer category_id){ + return cmsEssayService.queryEssay(category_id); + } + +} diff --git a/src/main/java/com/teaching/backend/mapper/cms/CmsCategoryMapper.java b/src/main/java/com/teaching/backend/mapper/cms/CmsCategoryMapper.java new file mode 100644 index 0000000..17f75d4 --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/cms/CmsCategoryMapper.java @@ -0,0 +1,17 @@ +package com.teaching.backend.mapper.cms; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.teaching.backend.model.entity.cms.CmsCategory; + +/** + *

+ * Mapper 接口 + *

+ * + * @author author + * @since 2024-08-13 + */ +public interface CmsCategoryMapper extends BaseMapper { + +} diff --git a/src/main/java/com/teaching/backend/mapper/cms/CmsEssayMapper.java b/src/main/java/com/teaching/backend/mapper/cms/CmsEssayMapper.java new file mode 100644 index 0000000..5ccce85 --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/cms/CmsEssayMapper.java @@ -0,0 +1,17 @@ +package com.teaching.backend.mapper.cms; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.teaching.backend.model.entity.cms.CmsEssay; + +/** + *

+ * Mapper 接口 + *

+ * + * @author author + * @since 2024-08-13 + */ +public interface CmsEssayMapper extends BaseMapper { + +} diff --git a/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java b/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java new file mode 100644 index 0000000..c4b91e7 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java @@ -0,0 +1,61 @@ +package com.teaching.backend.model.entity.cms; + +import com.baomidou.mybatisplus.annotation.*; + +import java.time.LocalDateTime; +import java.io.Serializable; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.springframework.format.annotation.DateTimeFormat; + +/** + *

+ * + *

+ * + * @author author + * @since 2024-08-13 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("cms_category") +@ApiModel(value="CmsCategory对象", description="") +public class CmsCategory implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "栏目id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "栏目名称") + private String categoryName; + + @ApiModelProperty(value = "创建该栏目的用户id") + private String creatorId; + + @ApiModelProperty(value = "栏目父id(若为一级栏目则父id等于栏目id)") + private Integer categoryPid; + + @ApiModelProperty(value = "创建时间") + @TableField(fill = FieldFill.INSERT) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime createTime; + + @ApiModelProperty(value = "更新时间") + @TableField(fill = FieldFill.INSERT_UPDATE) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime updateTime; + + @TableField(exist = false) + private List childrenNode; +} diff --git a/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java b/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java new file mode 100644 index 0000000..5038816 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java @@ -0,0 +1,75 @@ +package com.teaching.backend.model.entity.cms; + +import com.baomidou.mybatisplus.annotation.*; + +import java.time.LocalDateTime; +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; +import org.springframework.format.annotation.DateTimeFormat; + +/** + *

+ * + *

+ * + * @author author + * @since 2024-08-13 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("cms_essay") +@ApiModel(value="CmsEssay对象", description="") +public class CmsEssay implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "文章id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "文章标题") + private String title; + + @ApiModelProperty(value = "标题图片") + private String pic; + + @ApiModelProperty(value = "文章内容") + private String content; + + @ApiModelProperty(value = "发布时间") + private LocalDateTime publishTime; + + @ApiModelProperty(value = "浏览次数") + private Integer readingNumber; + + @ApiModelProperty(value = "评论条数") + private Integer commentCount; + + @ApiModelProperty(value = "所属栏目id") + private Integer categoryId; + + @ApiModelProperty(value = "发布文章的用户id") + private Integer userId; + + @ApiModelProperty(value = "文章文件") + private String file; + + @ApiModelProperty(value = "发布状态: 1: 已发布; 2未发布") + private Integer status; + + + @ApiModelProperty(value = "更新时间") + @TableField(fill = FieldFill.INSERT_UPDATE) + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai") + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + private LocalDateTime updateTime; + + +} diff --git a/src/main/java/com/teaching/backend/service/cms/ICmsCategoryService.java b/src/main/java/com/teaching/backend/service/cms/ICmsCategoryService.java new file mode 100644 index 0000000..ebc31c8 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/cms/ICmsCategoryService.java @@ -0,0 +1,27 @@ +package com.teaching.backend.service.cms; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.model.entity.cms.CmsCategory; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author author + * @since 2024-08-13 + */ +public interface ICmsCategoryService extends IService { + + BaseResponse addCategory(CmsCategory cmsCategory); + + BaseResponse deleteCategory(List ids); + + BaseResponse editCategory(CmsCategory cmsCategory); + + BaseResponse> queryCategory(); +} diff --git a/src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java b/src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java new file mode 100644 index 0000000..f122edb --- /dev/null +++ b/src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java @@ -0,0 +1,27 @@ +package com.teaching.backend.service.cms; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.model.entity.cms.CmsEssay; + +import java.util.List; + +/** + *

+ * 服务类 + *

+ * + * @author author + * @since 2024-08-13 + */ +public interface ICmsEssayService extends IService { + + BaseResponse addEssay(CmsEssay cmsEssay); + + BaseResponse deleteEssay(List ids); + + BaseResponse editEssay(CmsEssay cmsEssay); + + BaseResponse> queryEssay(Integer category_id); +} diff --git a/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java new file mode 100644 index 0000000..e5f7e3a --- /dev/null +++ b/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java @@ -0,0 +1,72 @@ +package com.teaching.backend.service.impl.cms; + + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.mapper.cms.CmsCategoryMapper; +import com.teaching.backend.model.entity.cms.CmsCategory; +import com.teaching.backend.service.cms.ICmsCategoryService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author author + * @since 2024-08-13 + */ +@Service +public class CmsCategoryServiceImpl extends ServiceImpl implements ICmsCategoryService { + + /** + * 添加栏目 + * @param cmsCategory + * @return + */ + @Override + public BaseResponse addCategory(CmsCategory cmsCategory) { + save(cmsCategory); + return ResultUtils.success("添加成功"); + } + + /**' + * 删除栏目 + * @param ids + * @return + */ + @Override + public BaseResponse deleteCategory(List ids) { + removeByIds(ids); + return ResultUtils.success("删除成功"); + } + + /** + * 编辑栏目 + * @param cmsCategory + * @return + */ + @Override + public BaseResponse editCategory(CmsCategory cmsCategory) { + updateById(cmsCategory); + return ResultUtils.success("编辑成功!"); + } + + /** + * 查询栏目 + * @return + */ + @Override + public BaseResponse> queryCategory() { + List categoryPid = query().eq("category_pid", 0).list(); + for (int i = 0; i < categoryPid.size(); i++) { + //查孩子 + categoryPid.get(i).setChildrenNode(query().eq("category_pid", categoryPid.get(i).getId()).list()); + } + return ResultUtils.success(categoryPid); + } + +} diff --git a/src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java new file mode 100644 index 0000000..633b553 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java @@ -0,0 +1,48 @@ +package com.teaching.backend.service.impl.cms; + + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.mapper.cms.CmsEssayMapper; +import com.teaching.backend.model.entity.cms.CmsEssay; +import com.teaching.backend.service.cms.ICmsEssayService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + *

+ * 服务实现类 + *

+ * + * @author author + * @since 2024-08-13 + */ +@Service +public class CmsEssayServiceImpl extends ServiceImpl implements ICmsEssayService { + + @Override + public BaseResponse addEssay(CmsEssay cmsEssay) { + save(cmsEssay); + return ResultUtils.success("添加成功"); + } + + @Override + public BaseResponse deleteEssay(List ids) { + removeByIds(ids); + return ResultUtils.success("删除成功"); + } + + @Override + public BaseResponse editEssay(CmsEssay cmsEssay) { + updateById(cmsEssay); + return ResultUtils.success("编辑成功!"); + } + + @Override + public BaseResponse> queryEssay(Integer category_id) { + List list = query().eq("category_id", category_id).list(); + return ResultUtils.success(list); + } +} diff --git a/src/main/java/com/teaching/backend/utils/MyMetaObjectHandler.java b/src/main/java/com/teaching/backend/utils/MyMetaObjectHandler.java new file mode 100644 index 0000000..601b816 --- /dev/null +++ b/src/main/java/com/teaching/backend/utils/MyMetaObjectHandler.java @@ -0,0 +1,26 @@ +package com.teaching.backend.utils; + +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import org.apache.ibatis.reflection.MetaObject; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.util.Date; + +/** + * 自动填充时间 + */ +@Component +public class MyMetaObjectHandler implements MetaObjectHandler { + @Override + public void insertFill(MetaObject metaObject) { + this.setFieldValByName("createTime", LocalDateTime.now(), metaObject); + this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject); + } + + @Override + public void updateFill(MetaObject metaObject) { + this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject); + + } +} From cd290a76620e36afaebf06cf99e001bb1a538585 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 13 Aug 2024 18:17:36 +0800 Subject: [PATCH 11/23] =?UTF-8?q?=E8=B5=84=E8=AE=AF=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/controller/cms/CmsCategoryController.java | 1 + .../backend/controller/cms/CmsEssayController.java | 9 +++++++++ .../backend/model/entity/cms/CmsCategory.java | 3 +++ .../backend/service/cms/ICmsEssayService.java | 2 ++ .../service/impl/cms/CmsCategoryServiceImpl.java | 11 ++++++++--- .../backend/service/impl/cms/CmsEssayServiceImpl.java | 7 +++++++ 6 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java b/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java index 8477b2a..d87ddb6 100644 --- a/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java +++ b/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java @@ -61,4 +61,5 @@ public class CmsCategoryController { return cmsCategoryService.queryCategory(); } + } diff --git a/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java b/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java index b89fa48..cc45502 100644 --- a/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java +++ b/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java @@ -67,4 +67,13 @@ public class CmsEssayController { return cmsEssayService.queryEssay(category_id); } + /** + * 取消发布 + * @param cmsEssay + * @return + */ + @PutMapping("/edit/status") + public BaseResponse editStatus(CmsEssay cmsEssay){ + return cmsEssayService.editStatus(cmsEssay); + } } diff --git a/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java b/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java index c4b91e7..1005dba 100644 --- a/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java +++ b/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java @@ -44,6 +44,9 @@ public class CmsCategory implements Serializable { @ApiModelProperty(value = "栏目父id(若为一级栏目则父id等于栏目id)") private Integer categoryPid; + @ApiModelProperty(value = "排序") + private Integer sort; + @ApiModelProperty(value = "创建时间") @TableField(fill = FieldFill.INSERT) @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai") diff --git a/src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java b/src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java index f122edb..56e2bb1 100644 --- a/src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java +++ b/src/main/java/com/teaching/backend/service/cms/ICmsEssayService.java @@ -24,4 +24,6 @@ public interface ICmsEssayService extends IService { BaseResponse editEssay(CmsEssay cmsEssay); BaseResponse> queryEssay(Integer category_id); + + BaseResponse editStatus(CmsEssay cmsEssay); } diff --git a/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java index e5f7e3a..8caac74 100644 --- a/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java @@ -61,10 +61,15 @@ public class CmsCategoryServiceImpl extends ServiceImpl> queryCategory() { - List categoryPid = query().eq("category_pid", 0).list(); + //先查父栏目并排序 + List categoryPid = query() + .eq("category_pid", 0) + .orderByAsc("sort").list(); for (int i = 0; i < categoryPid.size(); i++) { - //查孩子 - categoryPid.get(i).setChildrenNode(query().eq("category_pid", categoryPid.get(i).getId()).list()); + //查孩子并排序 + categoryPid.get(i).setChildrenNode(query() + .eq("category_pid", categoryPid.get(i).getId()) + .orderByAsc("sort").list()); } return ResultUtils.success(categoryPid); } diff --git a/src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java index 633b553..5e091fc 100644 --- a/src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/cms/CmsEssayServiceImpl.java @@ -45,4 +45,11 @@ public class CmsEssayServiceImpl extends ServiceImpl i List list = query().eq("category_id", category_id).list(); return ResultUtils.success(list); } + + @Override + public BaseResponse editStatus(CmsEssay cmsEssay) { + cmsEssay.setStatus(cmsEssay.getStatus() & 1); + updateById(cmsEssay); + return ResultUtils.success("修改成功"); + } } From 79ce69b993a8a9eee741970f4ff229eb7f19c449 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Wed, 14 Aug 2024 11:44:59 +0800 Subject: [PATCH 12/23] =?UTF-8?q?=E6=A0=8F=E7=9B=AE=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/controller/cms/CmsCategoryController.java | 11 +++++++++++ .../backend/model/entity/cms/CmsCategory.java | 3 +++ .../backend/service/cms/ICmsCategoryService.java | 2 ++ .../service/impl/cms/CmsCategoryServiceImpl.java | 7 +++++++ 4 files changed, 23 insertions(+) diff --git a/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java b/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java index d87ddb6..b35cad2 100644 --- a/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java +++ b/src/main/java/com/teaching/backend/controller/cms/CmsCategoryController.java @@ -3,6 +3,7 @@ package com.teaching.backend.controller.cms; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.model.entity.cms.CmsCategory; +import com.teaching.backend.model.entity.cms.CmsEssay; import com.teaching.backend.service.impl.cms.CmsCategoryServiceImpl; import io.swagger.annotations.Api; import org.springframework.web.bind.annotation.*; @@ -62,4 +63,14 @@ public class CmsCategoryController { } + /** + * 修改显示状态 + * @param cmsCategory + * @return + */ + @PutMapping("/edit/status") + public BaseResponse editStatus(CmsCategory cmsCategory){ + return cmsCategoryService.editStatus(cmsCategory); + } + } diff --git a/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java b/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java index 1005dba..39eace1 100644 --- a/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java +++ b/src/main/java/com/teaching/backend/model/entity/cms/CmsCategory.java @@ -47,6 +47,9 @@ public class CmsCategory implements Serializable { @ApiModelProperty(value = "排序") private Integer sort; + @ApiModelProperty(value = "是否显示") + private Integer status; + @ApiModelProperty(value = "创建时间") @TableField(fill = FieldFill.INSERT) @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "Asia/Shanghai") diff --git a/src/main/java/com/teaching/backend/service/cms/ICmsCategoryService.java b/src/main/java/com/teaching/backend/service/cms/ICmsCategoryService.java index ebc31c8..f121f1f 100644 --- a/src/main/java/com/teaching/backend/service/cms/ICmsCategoryService.java +++ b/src/main/java/com/teaching/backend/service/cms/ICmsCategoryService.java @@ -24,4 +24,6 @@ public interface ICmsCategoryService extends IService { BaseResponse editCategory(CmsCategory cmsCategory); BaseResponse> queryCategory(); + + BaseResponse editStatus(CmsCategory cmsCategory); } diff --git a/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java index 8caac74..25bda38 100644 --- a/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/cms/CmsCategoryServiceImpl.java @@ -74,4 +74,11 @@ public class CmsCategoryServiceImpl extends ServiceImpl editStatus(CmsCategory cmsCategory) { + cmsCategory.setStatus(cmsCategory.getStatus() & 1); + updateById(cmsCategory); + return ResultUtils.success("修改成功"); + } + } From 1daff442b4d778856f32bebe3879d766da972818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E8=A3=81?= <14186472+wenyu441069198@user.noreply.gitee.com> Date: Wed, 14 Aug 2024 16:18:31 +0800 Subject: [PATCH 13/23] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=AF=86=E7=A0=81=E5=8A=9F=E8=83=BD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/service/impl/umsAdmin/UmsUserServiceImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsUserServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsUserServiceImpl.java index 7f10c50..39ae7b4 100644 --- a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsUserServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsUserServiceImpl.java @@ -244,7 +244,7 @@ public class UmsUserServiceImpl extends ServiceImpl impl } UmsUser umsUser = userList.get(0); if(!passwordEncoder.matches(param.getOldPassword(),umsUser.getPassword())){ - throw new BusinessException(400,"密码重复"); + throw new BusinessException(400,"原密码错误"); } umsUser.setPassword(passwordEncoder.encode(param.getNewPassword())); updateById(umsUser); From 53f7dc9bdaff04aca958cf0ede5d9ec1087d09fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E8=A3=81?= <14186472+wenyu441069198@user.noreply.gitee.com> Date: Wed, 14 Aug 2024 16:51:37 +0800 Subject: [PATCH 14/23] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E7=AE=A1=E7=90=86=E6=A8=A1=E7=B3=8A=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/umsAdmin/UmsStudentManageServiceImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java index 5e5ae6c..23cff82 100644 --- a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java @@ -69,14 +69,20 @@ public class UmsStudentManageServiceImpl extends ServiceImpl umsStudentManageList = umsStudentManages.stream() - .filter(studentManage -> studentManage.getName().contains(umsStudentPageQueryDTO.getName())) + .filter(studentManage -> + studentManage != null && + studentManage.getName() != null && + studentManage.getName().contains(umsStudentPageQueryDTO.getName())) .skip((umsStudentPageQueryDTO.getPage() - 1) * umsStudentPageQueryDTO.getPageSize()) .limit(umsStudentPageQueryDTO.getPageSize()) .collect(Collectors.toList()); result.put("Records", umsStudentManageList); }else if (umsStudentPageQueryDTO.getNumber() != null){ List umsStudentManageList = umsStudentManages.stream() - .filter(studentManage -> studentManage.getNumber().contains(umsStudentPageQueryDTO.getNumber())) + .filter(studentManage -> + studentManage != null && + studentManage.getNumber() != null && + studentManage.getNumber().contains(umsStudentPageQueryDTO.getNumber())) .skip((umsStudentPageQueryDTO.getPage() - 1) * umsStudentPageQueryDTO.getPageSize()) .limit(umsStudentPageQueryDTO.getPageSize()) .collect(Collectors.toList()); From 2c6cea9aa32f276843c84d6f6bafcb27507764a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E8=A3=81?= <14186472+wenyu441069198@user.noreply.gitee.com> Date: Wed, 14 Aug 2024 18:08:46 +0800 Subject: [PATCH 15/23] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E7=AE=A1=E7=90=86=E6=A8=A1=E7=B3=8A=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/umsAdmin/UmsStudentManageController.java | 2 ++ .../service/impl/umsAdmin/UmsStudentManageServiceImpl.java | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/teaching/backend/controller/umsAdmin/UmsStudentManageController.java b/src/main/java/com/teaching/backend/controller/umsAdmin/UmsStudentManageController.java index 8e66e13..b36cebf 100644 --- a/src/main/java/com/teaching/backend/controller/umsAdmin/UmsStudentManageController.java +++ b/src/main/java/com/teaching/backend/controller/umsAdmin/UmsStudentManageController.java @@ -1,6 +1,7 @@ package com.teaching.backend.controller.umsAdmin; import com.teaching.backend.common.CommonResult; +import com.teaching.backend.filter.ValidateParams; import com.teaching.backend.model.dto.umsAdmin.UmsStudentPageQueryDTO; import com.teaching.backend.model.entity.umsAdmin.UmsStudentManage; import com.teaching.backend.service.umsAdmin.UmsStudentManageService; @@ -28,6 +29,7 @@ public class UmsStudentManageController { * @return */ @GetMapping("/page") + @ValidateParams({"page","pageSize", "userId"}) // 需要校验的参数 @ApiOperation("学生管理分页查询") public CommonResult> page(UmsStudentPageQueryDTO umsStudentPageQueryDTO){ Map pageResult = umsStudentManageService.pageQuery(umsStudentPageQueryDTO); diff --git a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java index 23cff82..a865c84 100644 --- a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java @@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import java.sql.Connection; import java.sql.DriverManager; @@ -67,7 +68,7 @@ public class UmsStudentManageServiceImpl extends ServiceImpl umsStudentManageList = umsStudentManages.stream() .filter(studentManage -> studentManage != null && @@ -77,7 +78,7 @@ public class UmsStudentManageServiceImpl extends ServiceImpl umsStudentManageList = umsStudentManages.stream() .filter(studentManage -> studentManage != null && From 9701771c4504b9357b0d97bc463d033de35ba7b6 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Fri, 16 Aug 2024 16:12:25 +0800 Subject: [PATCH 16/23] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=AD=A6=E4=B9=A0?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=8A=A0=E4=BA=86teacher=5Fuser=5Fid?= =?UTF-8?q?=E7=9A=84=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/teaching/backend/model/entity/cms/CmsEssay.java | 3 --- .../backend/model/entity/courses/CourseLearningNumber.java | 4 ++++ .../backend/model/entity/records/CourseLearningRecord.java | 4 ++++ .../service/impl/records/CourseLearningRecordServiceImpl.java | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java b/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java index 5038816..cc381f2 100644 --- a/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java +++ b/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java @@ -49,9 +49,6 @@ public class CmsEssay implements Serializable { @ApiModelProperty(value = "浏览次数") private Integer readingNumber; - @ApiModelProperty(value = "评论条数") - private Integer commentCount; - @ApiModelProperty(value = "所属栏目id") private Integer categoryId; diff --git a/src/main/java/com/teaching/backend/model/entity/courses/CourseLearningNumber.java b/src/main/java/com/teaching/backend/model/entity/courses/CourseLearningNumber.java index 72566b0..e462f90 100644 --- a/src/main/java/com/teaching/backend/model/entity/courses/CourseLearningNumber.java +++ b/src/main/java/com/teaching/backend/model/entity/courses/CourseLearningNumber.java @@ -36,6 +36,10 @@ public class CourseLearningNumber implements Serializable { @TableField("course_id") private String courseId; + @ApiModelProperty(value = "老师用户id") + @TableField("teacher_user_id") + private String teacherUserId; + @ApiModelProperty(value = "课程学习人数") @TableField("number") private Integer number; diff --git a/src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java b/src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java index 1617d15..7afccf3 100644 --- a/src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java +++ b/src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java @@ -54,6 +54,10 @@ public class CourseLearningRecord implements Serializable { @TableField("img") private String img; + @ApiModelProperty(value = "老师用户id") + @TableField("teacher_user_id") + private String teacherUserId; + @ApiModelProperty(value = "最近学习时间") @TableField("times") private LocalDateTime times; diff --git a/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java index fb3e253..1193803 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java @@ -74,6 +74,7 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl Date: Sat, 17 Aug 2024 17:23:12 +0800 Subject: [PATCH 17/23] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=B8=AD=E5=BF=83=E8=AF=BE=E7=A8=8B=E6=8E=A8=E8=8D=90?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CourseLearningRecordController.java | 3 --- .../KnowledgeLearningRecordController.java | 11 +++++++++ .../records/CourseLearningRecordMapper.java | 2 +- .../entity/umsAdmin/AdminUserDetails.java | 2 +- .../CourseLearningRecordServiceImpl.java | 23 ++++++++----------- .../KnowledgeLearningRecordServiceImpl.java | 21 +++++++++++++++++ .../umsAdmin/UmsStudentManageServiceImpl.java | 15 ++++++------ .../impl/umsAdmin/UmsUserServiceImpl.java | 2 +- .../IKnowledgeLearningRecordService.java | 3 +++ .../mapper/CourseLearningRecordMapper.xml | 4 +++- 10 files changed, 59 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java b/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java index 32be4d1..f9ad0f0 100644 --- a/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/CourseLearningRecordController.java @@ -79,9 +79,6 @@ public class CourseLearningRecordController { @PostMapping("/recommendCourses") public CommonResult> recommendCourses(@RequestParam String userId) { List coursesVOList = courseLearningRecordService.queryrecommendCourses(userId); - if (coursesVOList == null){ - CommonResult.failed("用户或角色错误"); - } return CommonResult.success(coursesVOList); } diff --git a/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java b/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java index f723a2d..8c132cb 100644 --- a/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java +++ b/src/main/java/com/teaching/backend/controller/records/KnowledgeLearningRecordController.java @@ -8,6 +8,7 @@ import com.teaching.backend.filter.ValidateParams; import com.teaching.backend.mapper.records.KnowledgeLearningRecordMapper; import com.teaching.backend.model.entity.records.CourseLearningRecord; import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; +import com.teaching.backend.model.vo.courses.CoursesVO; import com.teaching.backend.model.vo.knowGraph.KnowVO; import com.teaching.backend.service.impl.records.KnowledgeLearningRecordServiceImpl; import io.swagger.annotations.ApiOperation; @@ -84,5 +85,15 @@ public class KnowledgeLearningRecordController { return CommonResult.success(knowVO); } + /** + * 推荐知识点 + * @return + */ + @ApiOperation("推荐知识点") + @PostMapping("/recommendKnowledge") + public CommonResult> recommendCourses(@RequestParam String userId) { + List coursesVOList = knowledgeLearningRecordService.queryRecommendKnowledge(userId); + return CommonResult.success(coursesVOList); + } } diff --git a/src/main/java/com/teaching/backend/mapper/records/CourseLearningRecordMapper.java b/src/main/java/com/teaching/backend/mapper/records/CourseLearningRecordMapper.java index 602a416..56fd7d9 100644 --- a/src/main/java/com/teaching/backend/mapper/records/CourseLearningRecordMapper.java +++ b/src/main/java/com/teaching/backend/mapper/records/CourseLearningRecordMapper.java @@ -18,7 +18,7 @@ public interface CourseLearningRecordMapper extends BaseMapper selectMaxNumber(); + List selectMaxNumber(String userId); List selectMaxCourseId(String userId); } diff --git a/src/main/java/com/teaching/backend/model/entity/umsAdmin/AdminUserDetails.java b/src/main/java/com/teaching/backend/model/entity/umsAdmin/AdminUserDetails.java index ffb8ff4..a244453 100644 --- a/src/main/java/com/teaching/backend/model/entity/umsAdmin/AdminUserDetails.java +++ b/src/main/java/com/teaching/backend/model/entity/umsAdmin/AdminUserDetails.java @@ -59,6 +59,6 @@ public class AdminUserDetails implements UserDetails { @Override public boolean isEnabled() { - return umsAdmin.getStatus().equals(1); + return umsAdmin.getStatus().equals("1"); } } diff --git a/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java index 1193803..017d625 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java @@ -127,7 +127,7 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl coursesList = new ArrayList<>(); if (roleId.equals("1")){ - List courseIds = courseLearningRecordMapper.selectMaxNumber(); + List courseIds = courseLearningRecordMapper.selectMaxNumber(userId); for (String courseId : courseIds) { Courses courses = coursesMapper.selectById(courseId); coursesList.add(courses); @@ -149,18 +149,15 @@ public class CourseLearningRecordServiceImpl extends ServiceImpl queryrecommendCourses(String userId) { - String roleId = umsUserMapper.getByIdRoleId(userId); - - if (roleId.equals("1")) { - - return null; - } else if (roleId.equals("2")) { - - return null; - }else { - - return null; + List coursesList = new ArrayList<>(); + List courseIds = courseLearningRecordMapper.selectMaxNumber(userId); + for (String courseId : courseIds) { + Courses courses = coursesMapper.selectById(courseId); + if (courses != null){ + coursesList.add(courses); + } } + List coursesVOList = BeanUtil.copyToList(coursesList, CoursesVO.class); + return coursesVOList; } - } diff --git a/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java index c392c53..5e673eb 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java @@ -171,4 +171,25 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl queryRecommendKnowledge(String userId) { + + List coursesList = new ArrayList<>(); + + KnowVO knowVO = null; + + List knowledgeIdList = knowledgeLearningRecordMapper.queryStudyKnowledgeMaxNumber(); + for (String knowledgeId : knowledgeIdList) { + BaseResponse knowledge = knowtmpService.query(Long.valueOf(knowledgeId)); + if (knowledge.getData() != null) { + knowVO = new KnowVO(); + knowVO.setId(knowledge.getData().getId()); + knowVO.setLabel(knowledge.getData().getName()); + knowVO.setColor(knowledge.getData().getInfo()); + coursesList.add(knowVO); + } + } + return coursesList; + } + } diff --git a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java index a865c84..c8b5c32 100644 --- a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java @@ -124,13 +124,14 @@ public class UmsStudentManageServiceImpl extends ServiceImpl impl if(!passwordEncoder.matches(password,userDetails.getPassword())){ throw new BusinessException(400,"密码错误"); } - if(userDetails.isEnabled()){ + if(!userDetails.isEnabled()){ throw new BusinessException(400,"帐号已被禁用"); } UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities()); diff --git a/src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java b/src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java index 4e320e0..a90f9c4 100644 --- a/src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java +++ b/src/main/java/com/teaching/backend/service/records/IKnowledgeLearningRecordService.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.IService; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; +import com.teaching.backend.model.vo.courses.CoursesVO; import io.swagger.models.auth.In; import com.teaching.backend.model.vo.knowGraph.KnowVO; @@ -28,5 +29,7 @@ public interface IKnowledgeLearningRecordService extends IService queryMaxKnowledge(String userId); + + List queryRecommendKnowledge(String userId); } diff --git a/src/main/resources/mapper/CourseLearningRecordMapper.xml b/src/main/resources/mapper/CourseLearningRecordMapper.xml index d117fc7..7ec9971 100644 --- a/src/main/resources/mapper/CourseLearningRecordMapper.xml +++ b/src/main/resources/mapper/CourseLearningRecordMapper.xml @@ -12,11 +12,13 @@ times DESC LIMIT 1; - SELECT cln.course_id courseId FROM course_learning_number cln + WHERE + CONCAT(',', cln.teacher_user_id, ',') LIKE CONCAT('%,', #{userId}, ',%') ORDER BY number DESC; From c3bf152cb087bf3219b12700d990937787663d38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E8=A3=81?= <14186472+wenyu441069198@user.noreply.gitee.com> Date: Sat, 17 Aug 2024 17:44:37 +0800 Subject: [PATCH 18/23] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97DOT=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=B1=BB=E5=9E=8B=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/model/dto/umsAdmin/UmsStudentAndTeacherDTO.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/teaching/backend/model/dto/umsAdmin/UmsStudentAndTeacherDTO.java b/src/main/java/com/teaching/backend/model/dto/umsAdmin/UmsStudentAndTeacherDTO.java index 42011e6..b5089c6 100644 --- a/src/main/java/com/teaching/backend/model/dto/umsAdmin/UmsStudentAndTeacherDTO.java +++ b/src/main/java/com/teaching/backend/model/dto/umsAdmin/UmsStudentAndTeacherDTO.java @@ -10,6 +10,7 @@ import lombok.experimental.Accessors; import java.io.Serializable; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.List; /** *

@@ -122,5 +123,5 @@ public class UmsStudentAndTeacherDTO implements Serializable { /** * role_id */ - private Integer roleId; + private List roleId; } From 5c9061d8dffc0288b62310ccc015e024ac9e9a00 Mon Sep 17 00:00:00 2001 From: Alan <3052806735@qq.com> Date: Mon, 19 Aug 2024 21:50:09 +0800 Subject: [PATCH 19/23] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=80=BB=E7=9B=AE?= =?UTF-8?q?=E6=A0=87/=E6=80=9D=E6=94=BF=E7=9B=AE=E6=A0=87=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96=EF=BC=88=E5=8F=AA?= =?UTF-8?q?=E8=83=BD=E5=A1=AB=E4=B8=80=E4=B8=AA=E5=86=85=E5=AE=B9=EF=BC=89?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E7=9F=A5=E8=AF=86=E7=82=B9--=E5=85=B3?= =?UTF-8?q?=E8=81=94=E7=9B=AE=E6=A0=87=E5=86=85=E5=AE=B9=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E7=9B=AE=E6=A0=87=E5=86=85=E5=AE=B9--?= =?UTF-8?q?=E7=9F=A5=E8=AF=86=E7=82=B9=20=20=E6=95=B0=E6=8D=AE=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=8E=A5=E5=8F=A3=EF=BC=8C=E7=8E=B0=E5=9C=A8=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=8B=BF=E5=88=B0=E7=9F=A5=E8=AF=86=E7=82=B9=E4=B8=AA?= =?UTF-8?q?=E6=95=B0=EF=BC=8C=E6=80=BB=E5=AD=A6=E6=97=B6=EF=BC=8C=E5=8D=A0?= =?UTF-8?q?=E6=AF=94=EF=BC=8C=E4=BB=A5=E5=8F=8A=E7=9B=B8=E5=85=B3=E7=9F=A5?= =?UTF-8?q?=E8=AF=86=E7=82=B9=E7=9A=84=E8=AF=A6=E7=BB=86=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=EF=BC=88id=EF=BC=8Cname=EF=BC=8C=E5=AD=A6=E6=97=B6=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../teaching/backend/common/ErrorCode.java | 2 +- .../courses/CourseObjectivesController.java | 8 + .../ObjectiveContentKnowController.java | 8 +- .../courses/ObjectiveContentsController.java | 4 +- .../dto/courses/ObjectiveContentKnowDTO.java | 2 +- .../entity/courses/ObjectiveContentKnow.java | 6 +- .../entity/courses/ObjectiveContents.java | 4 +- .../backend/model/entity/knowtmp/Knowtmp.java | 1 - .../model/vo/courses/CourseObjectivesVO.java | 23 +++ .../vo/courses/ObjectiveContentKnowVO.java | 11 +- .../backend/model/vo/knowtmp/KnowTmpVO.java | 29 +++ .../courses/ICourseObjectivesService.java | 3 + .../courses/IObjectiveContentKnowService.java | 2 +- .../courses/IObjectiveContentsService.java | 2 + .../courses/CourseObjectivesServiceImpl.java | 34 +++- .../impl/courses/CoursesServiceImpl.java | 2 +- .../ObjectiveContentKnowServiceImpl.java | 168 +++++++++--------- .../courses/ObjectiveContentsServiceImpl.java | 34 +++- 18 files changed, 233 insertions(+), 110 deletions(-) create mode 100644 src/main/java/com/teaching/backend/model/vo/courses/CourseObjectivesVO.java create mode 100644 src/main/java/com/teaching/backend/model/vo/knowtmp/KnowTmpVO.java diff --git a/src/main/java/com/teaching/backend/common/ErrorCode.java b/src/main/java/com/teaching/backend/common/ErrorCode.java index 041682c..a67b684 100644 --- a/src/main/java/com/teaching/backend/common/ErrorCode.java +++ b/src/main/java/com/teaching/backend/common/ErrorCode.java @@ -10,7 +10,7 @@ public enum ErrorCode { SUCCESS(200, "ok"), PARAMS_ERROR(40000, "请求参数错误"), - OBJECTIVE_OR_CONTENT_NOT_EXIT(40001, "目标或内容id不存在"), + OBJECTIVE_CONTENT_NOT_EXIT(40001, "目标内容不存在"), KONWID_NOT_EXIT(40002, "没有选择知识点"), OBJECTIVE_OR_CONTENT_EXIT(40003, "该记录已存在"), KNOW_NOT_EXIT(40004, "知识点不存在"), diff --git a/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java b/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java index c6ca203..3383eff 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CourseObjectivesController.java @@ -9,6 +9,7 @@ import com.teaching.backend.mapper.courses.CourseObjectivesMapper; import com.teaching.backend.model.dto.courses.CourseObjectivesDTO; import com.teaching.backend.model.entity.courses.CourseObjectives; import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; +import com.teaching.backend.model.vo.courses.CourseObjectivesVO; import com.teaching.backend.service.courses.ICourseObjectivesService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -76,5 +77,12 @@ public class CourseObjectivesController { return ResultUtils.success(courseObjectivesTreeVO); } + @ApiOperation("列表显示分项目标(用于添加目标内容时选择)") + @GetMapping("/objectiveslist/{courseId}") + public BaseResponse> queryCourseObjectivesForAdd(@PathVariable String courseId){ + List courseObjectivesVOS = courseObjectivesService.queryCourseObjectivesForAdd(courseId); + return ResultUtils.success(courseObjectivesVOS); + } + } diff --git a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentKnowController.java b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentKnowController.java index d3fc4d7..bd3497b 100644 --- a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentKnowController.java +++ b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentKnowController.java @@ -31,11 +31,11 @@ public class ObjectiveContentKnowController { IObjectiveContentKnowService objectiveContentKnowService; - @ApiOperation("给分项目标或者是内容添加知识点") -// @ValidateParams({"objectiveId","know"}) + @ApiOperation("给知识点关联--目标内容") + @ValidateParams({"objectiveContentId","knowId"}) @PostMapping("/addknows") - public BaseResponse saveKnowsWithObjectiveOrContent(@RequestBody ObjectiveContentKnowDTO objectiveContentKnowDTO){ - String data = objectiveContentKnowService.saveKnowsWithObjectiveOrContent(objectiveContentKnowDTO); + public BaseResponse saveKnowsWithObjectiveContent(@RequestBody ObjectiveContentKnowDTO objectiveContentKnowDTO){ + String data = objectiveContentKnowService.saveKnowsWithObjectiveContent(objectiveContentKnowDTO); return ResultUtils.success(data); } diff --git a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java index cbe1c5e..b18112f 100644 --- a/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java +++ b/src/main/java/com/teaching/backend/controller/courses/ObjectiveContentsController.java @@ -31,8 +31,8 @@ public class ObjectiveContentsController { @ValidateParams({"objectiveId"}) @PostMapping("/addcontent") public BaseResponse saveContent(@RequestBody ObjectiveContents objectiveContents){ - objectiveContentsService.save(objectiveContents); - return ResultUtils.success("添加成功"); + String data = objectiveContentsService.saveWithCheck(objectiveContents); + return ResultUtils.success(data); } @ApiOperation("删除目标内容") diff --git a/src/main/java/com/teaching/backend/model/dto/courses/ObjectiveContentKnowDTO.java b/src/main/java/com/teaching/backend/model/dto/courses/ObjectiveContentKnowDTO.java index f0eb4ef..fd46c10 100644 --- a/src/main/java/com/teaching/backend/model/dto/courses/ObjectiveContentKnowDTO.java +++ b/src/main/java/com/teaching/backend/model/dto/courses/ObjectiveContentKnowDTO.java @@ -20,7 +20,7 @@ import java.io.Serializable; * @since 2024-06-13 */ @Data -@ApiModel(description = "分项目标或内容添加知识点") +@ApiModel(description = "目标内容添加知识点") public class ObjectiveContentKnowDTO extends ObjectiveContentKnow { } diff --git a/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java b/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java index fb91204..023b03b 100644 --- a/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java +++ b/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContentKnow.java @@ -38,12 +38,14 @@ public class ObjectiveContentKnow implements Serializable { /** * 分项目标或内容 的 id */ - private String objectiveOrContent; +// private String objectiveOrContent; + private String objectiveContentId; /** * 关联的知识点 */ - private String know; +// private String know; + private Integer knowId; } diff --git a/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContents.java b/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContents.java index 8ccd7ef..ab1a339 100644 --- a/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContents.java +++ b/src/main/java/com/teaching/backend/model/entity/courses/ObjectiveContents.java @@ -36,8 +36,6 @@ public class ObjectiveContents implements Serializable { @ApiModelProperty(value = "内容",required = true) private String content; - @ApiModelProperty(value = "排序字段",required = true) + @ApiModelProperty(value = "排序字段") private Float orderNum; - - } diff --git a/src/main/java/com/teaching/backend/model/entity/knowtmp/Knowtmp.java b/src/main/java/com/teaching/backend/model/entity/knowtmp/Knowtmp.java index 978d8e4..1e3a0ab 100644 --- a/src/main/java/com/teaching/backend/model/entity/knowtmp/Knowtmp.java +++ b/src/main/java/com/teaching/backend/model/entity/knowtmp/Knowtmp.java @@ -36,5 +36,4 @@ public class Knowtmp implements Serializable { private double hour; - } diff --git a/src/main/java/com/teaching/backend/model/vo/courses/CourseObjectivesVO.java b/src/main/java/com/teaching/backend/model/vo/courses/CourseObjectivesVO.java new file mode 100644 index 0000000..4647a83 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/vo/courses/CourseObjectivesVO.java @@ -0,0 +1,23 @@ +package com.teaching.backend.model.vo.courses; + +import com.teaching.backend.model.entity.courses.CourseObjectives; +import com.teaching.backend.model.entity.courses.ObjectiveContents; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.List; + +@Data +@ApiModel(description = "课程目标详情(简略)") +public class CourseObjectivesVO implements Serializable { + + @ApiModelProperty(value = "目标id") + private String id; + + @ApiModelProperty(value = "目标名称") + private String name; + + +} diff --git a/src/main/java/com/teaching/backend/model/vo/courses/ObjectiveContentKnowVO.java b/src/main/java/com/teaching/backend/model/vo/courses/ObjectiveContentKnowVO.java index d3b6a35..0460cd4 100644 --- a/src/main/java/com/teaching/backend/model/vo/courses/ObjectiveContentKnowVO.java +++ b/src/main/java/com/teaching/backend/model/vo/courses/ObjectiveContentKnowVO.java @@ -1,5 +1,6 @@ package com.teaching.backend.model.vo.courses; +import com.teaching.backend.model.vo.knowtmp.KnowTmpVO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -12,7 +13,7 @@ import java.util.List; public class ObjectiveContentKnowVO { /** - * 分项目标或内容 的 id + * 目标内容 的 id */ private String objectiveOrContent; @@ -26,17 +27,17 @@ public class ObjectiveContentKnowVO { * 关联的知识点学时合计 */ @ApiModelProperty(value = "关联的知识点学时合计") - private BigDecimal knowsTime; + private Double knowsTime; /** * 关联的知识点学时占比 */ @ApiModelProperty(value = "关联的知识点学时占比") - private String persent; + private Double persent; /** - * 分项目标下面的内容对应的知识点数据 + * 知识点的展示数据 */ - List contentKnowsData; + List knowTmpVOList; } diff --git a/src/main/java/com/teaching/backend/model/vo/knowtmp/KnowTmpVO.java b/src/main/java/com/teaching/backend/model/vo/knowtmp/KnowTmpVO.java new file mode 100644 index 0000000..b0aaab0 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/vo/knowtmp/KnowTmpVO.java @@ -0,0 +1,29 @@ +package com.teaching.backend.model.vo.knowtmp; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; + +/** + *

+ * + *

+ * + * @author author + * @since 2024-05-31 + */ +@Data +@TableName(value = "knowtmp") +public class KnowTmpVO implements Serializable { + + private Long id; + + private String name; + + private double hour; + +} diff --git a/src/main/java/com/teaching/backend/service/courses/ICourseObjectivesService.java b/src/main/java/com/teaching/backend/service/courses/ICourseObjectivesService.java index 3d3c753..55c1783 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICourseObjectivesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICourseObjectivesService.java @@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.teaching.backend.model.dto.courses.CourseObjectivesDTO; import com.teaching.backend.model.entity.courses.CourseObjectives; import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; +import com.teaching.backend.model.vo.courses.CourseObjectivesVO; import java.util.List; @@ -37,4 +38,6 @@ public interface ICourseObjectivesService extends IService { * @return */ List queryCourseObjectivesTree(String id); + + List queryCourseObjectivesForAdd(String courseId); } diff --git a/src/main/java/com/teaching/backend/service/courses/IObjectiveContentKnowService.java b/src/main/java/com/teaching/backend/service/courses/IObjectiveContentKnowService.java index 18c2809..b6b1207 100644 --- a/src/main/java/com/teaching/backend/service/courses/IObjectiveContentKnowService.java +++ b/src/main/java/com/teaching/backend/service/courses/IObjectiveContentKnowService.java @@ -15,7 +15,7 @@ import com.teaching.backend.model.vo.courses.ObjectiveContentKnowVO; */ public interface IObjectiveContentKnowService extends IService { - String saveKnowsWithObjectiveOrContent(ObjectiveContentKnowDTO objectiveContentKnowDTO); + String saveKnowsWithObjectiveContent(ObjectiveContentKnowDTO objectiveContentKnowDTO); ObjectiveContentKnowVO getCountData(String objectiveId); } diff --git a/src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java b/src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java index b031659..b1f3c7c 100644 --- a/src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java +++ b/src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java @@ -16,4 +16,6 @@ public interface IObjectiveContentsService extends IService { String deleteById(String id); + + String saveWithCheck(ObjectiveContents objectiveContents); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java index 435f710..1ce4255 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java @@ -14,8 +14,10 @@ import com.teaching.backend.model.entity.courses.CourseObjectives; import com.teaching.backend.model.entity.courses.ObjectiveContentKnow; import com.teaching.backend.model.entity.courses.ObjectiveContents; import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; +import com.teaching.backend.model.vo.courses.CourseObjectivesVO; import com.teaching.backend.service.courses.ICourseObjectivesService; import com.teaching.backend.utils.CourseCode; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -26,6 +28,7 @@ import java.util.List; import java.util.Map; import static com.teaching.backend.utils.CourseCode.TOTAL_OBJECTIVE_HAS_NO_CHILD; +import static com.teaching.backend.utils.CourseCode.TOTAL_OBJECTIVE_TYPE; /** *

@@ -36,6 +39,7 @@ import static com.teaching.backend.utils.CourseCode.TOTAL_OBJECTIVE_HAS_NO_CHILD * @since 2024-05-31 */ @Service +@Slf4j public class CourseObjectivesServiceImpl extends ServiceImpl implements ICourseObjectivesService { @@ -109,12 +113,12 @@ public class CourseObjectivesServiceImpl extends ServiceImpl() - .eq(ObjectiveContentKnow::getObjectiveOrContent, id)); + .eq(ObjectiveContentKnow::getObjectiveContentId, id)); if(count > CourseCode.KNOWS_EXIT.getValue()){ throw new BusinessException(ErrorCode.KNOWS_EXIT); } @@ -204,6 +208,30 @@ public class CourseObjectivesServiceImpl extends ServiceImpl queryCourseObjectivesForAdd(String courseId) { + CourseObjectives courseObjectives = courseObjectivesMapper.selectOne(new LambdaQueryWrapper<>(CourseObjectives.class) + .eq(CourseObjectives::getCourseId, courseId)); + if (courseObjectives == null){ + log.error("课程相关数据不存在:{}",courseId); + throw new BusinessException(ErrorCode.NOT_FOUND_ERROR); + } + String courseTotalObjectiveId = courseObjectives.getId(); + List objectivesLists = courseObjectivesMapper.selectList(new LambdaQueryWrapper<>(CourseObjectives.class) + .eq(CourseObjectives::getPid, courseTotalObjectiveId) + .select(CourseObjectives::getId,CourseObjectives::getType) + .orderByAsc(CourseObjectives::getType) + ); + List courseObjectivesVOS = new ArrayList<>(objectivesLists.size()); + for (CourseObjectives objectives : objectivesLists) { + CourseObjectivesVO courseObjectivesVO = new CourseObjectivesVO(); + courseObjectivesVO.setId(objectives.getId()); + courseObjectivesVO.setName(objectivesTypeMapper.selectById(objectives.getType()).getTypeName()); + courseObjectivesVOS.add(courseObjectivesVO); + } + return courseObjectivesVOS; + } + // 获取目标的内容列表 private List fetchContentsForObjective(String objectiveId) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index 005414f..ee9f974 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -283,7 +283,7 @@ public class CoursesServiceImpl extends ServiceImpl impl contents+=content; Long know = objectiveContentKnowMapper.selectCount(new LambdaQueryWrapper() - .eq(ObjectiveContentKnow::getObjectiveOrContent, objectiveId)); + .eq(ObjectiveContentKnow::getObjectiveContentId, objectiveId)); knows+=know; } if(contents > 0){ diff --git a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java index 13720df..c1ee035 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.common.ErrorCode; import com.teaching.backend.exception.BusinessException; +import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper; import com.teaching.backend.mapper.courses.CourseObjectivesMapper; import com.teaching.backend.mapper.courses.CoursesMapper; import com.teaching.backend.mapper.courses.ObjectiveContentKnowMapper; @@ -13,7 +14,9 @@ import com.teaching.backend.model.dto.courses.ObjectiveContentKnowDTO; import com.teaching.backend.model.entity.courses.CourseObjectives; import com.teaching.backend.model.entity.courses.ObjectiveContentKnow; import com.teaching.backend.model.entity.courses.ObjectiveContents; +import com.teaching.backend.model.entity.knowtmp.Knowtmp; import com.teaching.backend.model.vo.courses.ObjectiveContentKnowVO; +import com.teaching.backend.model.vo.knowtmp.KnowTmpVO; import com.teaching.backend.service.courses.IObjectiveContentKnowService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -40,8 +43,8 @@ public class ObjectiveContentKnowServiceImpl extends ServiceImpl knowIds = new ArrayList<>(Arrays.asList(knows.split(","))); - List objectiveContentKnowList = new ArrayList<>(); - for (String knowId : knowIds) { - ObjectiveContentKnow objectiveContentKnow = new ObjectiveContentKnow(); -// objectiveContentKnow.setId(snowflakeGenerator.next()); - objectiveContentKnow.setObjectiveOrContent(objectiveOrContent); - objectiveContentKnow.setKnow(knowId); - objectiveContentKnowList.add(objectiveContentKnow); - } - try { - objectiveContentKnowMapper.insertBatchSomeColumn(objectiveContentKnowList); - } catch (Exception e) { - e.printStackTrace(); - throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_EXIT); +// String knows = objectiveContentKnowDTO.getKnow(); +// if (knows == null || knows.equals("")){ +// throw new BusinessException(ErrorCode.KONWID_NOT_EXIT); +// } +// List knowIds = new ArrayList<>(Arrays.asList(knows.split(","))); +// List objectiveContentKnowList = new ArrayList<>(); +// for (String knowId : knowIds) { +// ObjectiveContentKnow objectiveContentKnow = new ObjectiveContentKnow(); +//// objectiveContentKnow.setId(snowflakeGenerator.next()); +// objectiveContentKnow.setObjectiveOrContent(objectiveOrContent); +// objectiveContentKnow.setKnow(knowId); +// objectiveContentKnowList.add(objectiveContentKnow); +// } +// try { +// objectiveContentKnowMapper.insertBatchSomeColumn(objectiveContentKnowList); +// } catch (Exception e) { +// e.printStackTrace(); +// throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_EXIT); +// } + + //添加逻辑变了 变成了给知识点添加关联的--课程目标 + ObjectiveContents objectiveContents = objectiveContentsMapper.selectById(objectiveContentKnowDTO.getObjectiveContentId()); + if (objectiveContents == null) { + throw new BusinessException(ErrorCode.OBJECTIVE_CONTENT_NOT_EXIT); } + int insert = objectiveContentKnowMapper.insert(objectiveContentKnowDTO); - return "添加成功"; + return insert > 0 ? "添加成功" : "添加失败"; } @Override - public ObjectiveContentKnowVO getCountData(String objectiveOrContentId) { - // 查询分项目标或者是下面的内容关联的知识点数据(按设计要求,这个传的就是分项目标的id) - List objectiveContentKnows = objectiveContentKnowMapper.selectList( - new LambdaQueryWrapper() - .eq(ObjectiveContentKnow::getObjectiveOrContent, objectiveOrContentId)); + public ObjectiveContentKnowVO getCountData(String objectiveContentId) { + // 创建ObjectiveContentKnowVO对象,用于存储和返回计算结果 + ObjectiveContentKnowVO objectiveContentKnowVO = new ObjectiveContentKnowVO(); - // 创建ObjectiveContentKnowVO对象,并计算相关数据 - ObjectiveContentKnowVO objectiveContentKnowVO = createObjectiveContentKnowVO(objectiveOrContentId, objectiveContentKnows); - - // 根据分项目标找到课程id + // 根据传入的目标内容ID找到课程ID和总学时 + String objectiveID = objectiveContentsMapper.selectOne(new LambdaQueryWrapper() + .eq(ObjectiveContents::getId, objectiveContentId)).getObjectiveId(); String pid = courseObjectivesMapper.selectOne(new LambdaQueryWrapper() - .eq(CourseObjectives::getId, objectiveOrContentId)).getPid(); + .eq(CourseObjectives::getId, objectiveID)).getPid(); String courseId = courseObjectivesMapper.selectOne(new LambdaQueryWrapper() - .eq(CourseObjectives::getId, pid)).getCourseId(); + .eq(CourseObjectives::getId, pid)).getCourseId(); Integer classhours = coursesMapper.selectById(courseId).getClasshours(); - // 计算并设置比例(百分比) -// BigDecimal percentage = calculatePercentage(objectiveContentKnowVO.getKnowsTime(), classhours); - -// objectiveContentKnowVO.setPersent(percentage + "%"); - - // 查找分项目标下的内容 - List objectiveContents = objectiveContentsMapper.selectList(new LambdaQueryWrapper() - .eq(ObjectiveContents::getObjectiveId, objectiveOrContentId)); + // 获取当前目标内容下关联的知识点数据 + List objectiveContentKnows = objectiveContentKnowMapper.selectList( + new LambdaQueryWrapper() + .eq(ObjectiveContentKnow::getObjectiveContentId, objectiveContentId) + ); - // 如果存在分项目标内容,处理并计算每个内容的相关数据 - if (!CollectionUtils.isEmpty(objectiveContents)) { - List contentKnowVOs = objectiveContents.stream() - .map(content -> createObjectiveContentKnowVO(content.getId(), objectiveContentKnowMapper.selectList( - new LambdaQueryWrapper() - .eq(ObjectiveContentKnow::getObjectiveOrContent, content.getId()) - ))) - .collect(Collectors.toList()); + // 创建并设置ObjectiveContentKnowVO对象的属性 + objectiveContentKnowVO = createObjectiveContentKnowVO(objectiveContentId, objectiveContentKnows); - // 计算每个内容的知识点总学时的比例(百分比) -// contentKnowVOs.forEach(contentKnowVO -> { -// BigDecimal contentPercentage = calculatePercentage(contentKnowVO.getKnowsTime(), classhours); -// contentKnowVO.setPersent(contentPercentage + "%"); -// }); + // 计算并设置该内容的知识点总学时的比例(百分比) + Double contentPercentage = calculatePercentage(objectiveContentKnowVO.getKnowsTime(), classhours); + objectiveContentKnowVO.setPersent(contentPercentage); - // 设置内容的知识点数据 - objectiveContentKnowVO.setContentKnowsData(contentKnowVOs); - } - - // 返回计算结果 + // 返回最终结果 return objectiveContentKnowVO; } - // 创建ObjectiveContentKnowVO对象,并计算知识点数量和总时间 + // 创建ObjectiveContentKnowVO对象,并计算知识点数量、总时间和关联的知识点部分数据 private ObjectiveContentKnowVO createObjectiveContentKnowVO(String objectiveOrContentId, List objectiveContentKnows) { ObjectiveContentKnowVO vo = new ObjectiveContentKnowVO(); vo.setObjectiveOrContent(objectiveOrContentId); vo.setKnowsNumber(objectiveContentKnows.size()); - // 计算知识点的总时间 -// BigDecimal knowsTime = objectiveContentKnows.stream() -// .map(contentKnow -> { -// Know know = knowMapper.selectOne(new LambdaQueryWrapper() -// .eq(Know::getId, contentKnow.getKnow())); -// if (know == null) { -// throw new BusinessException(ErrorCode.KNOW_NOT_EXIT); -// } -// return know.getHour(); -// }) -// .reduce(BigDecimal.ZERO, BigDecimal::add); - -// vo.setKnowsTime(knowsTime); + // 计算知识点的总时间,并收集关联的知识点部分数据 + Double knowsTime = 0.0; + List knowTmpVOList = new ArrayList<>(); + + for (ObjectiveContentKnow contentKnow : objectiveContentKnows) { + Knowtmp know = knowtmpMapper.selectOne(new LambdaQueryWrapper() + .eq(Knowtmp::getId, contentKnow.getKnowId())); + if (know == null) { + throw new BusinessException(ErrorCode.KNOW_NOT_EXIT); + } + knowsTime += know.getHour(); + + // 将当前知识点数据添加到knowTmpVOList中 + KnowTmpVO knowTmpVO = new KnowTmpVO(); + knowTmpVO.setId(know.getId()); + knowTmpVO.setName(know.getName()); + knowTmpVO.setHour(know.getHour()); + knowTmpVOList.add(knowTmpVO); + } + + vo.setKnowsTime(knowsTime); + vo.setKnowTmpVOList(knowTmpVOList); // 设置知识点的部分数据列表 return vo; } - // 计算知识点时间占总学时的比例,并转换为百分比 - private BigDecimal calculatePercentage(BigDecimal knowsTime, Integer classhours) { + // 计算知识点学时占总学时的比例,并返回百分比形式的结果 + private Double calculatePercentage(Double knowsTime, Integer classhours) { if (classhours == null || classhours == 0) { - return BigDecimal.ZERO; + return 0.0; } - // 将classhours转换为BigDecimal类型,以便进行精确计算 - BigDecimal classHoursBigDecimal = new BigDecimal(classhours); - // 计算knowsTime占classhours的比例,先除以classhours再乘以100,保留两位小数,并四舍五入 - return knowsTime.divide(classHoursBigDecimal, 4, RoundingMode.HALF_UP).multiply(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP); + return new BigDecimal(knowsTime) + .divide(new BigDecimal(classhours), 4, RoundingMode.HALF_UP) + .multiply(new BigDecimal(100)) + .setScale(2, RoundingMode.HALF_UP) + .doubleValue(); } -} +} \ No newline at end of file diff --git a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentsServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentsServiceImpl.java index b44668e..98e90de 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentsServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentsServiceImpl.java @@ -5,16 +5,21 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.common.ErrorCode; import com.teaching.backend.exception.BusinessException; +import com.teaching.backend.mapper.courses.CourseObjectivesMapper; import com.teaching.backend.mapper.courses.ObjectiveContentKnowMapper; import com.teaching.backend.mapper.courses.ObjectiveContentsMapper; +import com.teaching.backend.model.entity.courses.CourseObjectives; import com.teaching.backend.model.entity.courses.ObjectiveContentKnow; import com.teaching.backend.model.entity.courses.ObjectiveContents; import com.teaching.backend.service.courses.IObjectiveContentsService; import com.teaching.backend.utils.CourseCode; import io.swagger.annotations.Api; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import static com.teaching.backend.utils.CourseCode.*; + /** *

* 服务实现类 @@ -24,23 +29,50 @@ import org.springframework.stereotype.Service; * @since 2024-06-05 */ @Service +@Slf4j public class ObjectiveContentsServiceImpl extends ServiceImpl implements IObjectiveContentsService { @Autowired ObjectiveContentKnowMapper objectiveContentKnowMapper; @Autowired ObjectiveContentsMapper objectiveContentsMapper; + @Autowired + CourseObjectivesMapper courseObjectivesMapper; @Override public String deleteById(String id) { if (id == null){ throw new BusinessException(ErrorCode.CONTENT_NOT_EXIT); } Long count = objectiveContentKnowMapper.selectCount(new LambdaQueryWrapper() - .eq(ObjectiveContentKnow::getObjectiveOrContent, id)); + .eq(ObjectiveContentKnow::getObjectiveContentId, id)); if(count > CourseCode.KNOWS_EXIT.getValue()){ throw new BusinessException(ErrorCode.KNOWS_EXIT); } int delete = objectiveContentsMapper.deleteById(id); return delete > 0 ? "删除成功!" : "删除失败!"; } + + /** + * 在添加内容的时候需要校验,总目标和思政目标只有一个内容 + * @param objectiveContents + * @return + */ + @Override + public String saveWithCheck(ObjectiveContents objectiveContents) { + CourseObjectives courseObjective = courseObjectivesMapper.selectOne(new LambdaQueryWrapper<>(CourseObjectives.class) + .eq(CourseObjectives::getId, objectiveContents.getObjectiveId())); + if (courseObjective == null){ + log.error("课程目标数据不存在:{}",objectiveContents.getObjectiveId()); + throw new BusinessException(ErrorCode.NOT_FOUND_ERROR); + } + if (courseObjective.getType() == SI_ZHENG_TYPE.getValue() || courseObjective.getType() == TOTAL_OBJECTIVE_TYPE.getValue()){ + Long count = objectiveContentsMapper.selectCount(new LambdaQueryWrapper<>(ObjectiveContents.class) + .eq(ObjectiveContents::getObjectiveId, objectiveContents.getObjectiveId())); + if (count>CONTENT_EXIT.getValue()){ + throw new BusinessException(ErrorCode.CONTENT_EXISTS,"该目标下面已存在一条内容,无需再次添加"); + } + } + int insert = objectiveContentsMapper.insert(objectiveContents); + return insert > 0 ? "添加内容成功" : "添加内容失败"; + } } From 395d4b00786e20c0c731799a4874d8fc2de4d7b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=80=BB=E8=A3=81?= <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 20 Aug 2024 11:30:11 +0800 Subject: [PATCH 20/23] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E7=AE=A1=E7=90=86=E5=88=86=E9=A1=B5=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/courses/ICoursesService.java | 2 +- .../impl/courses/CoursesServiceImpl.java | 31 ++++++++++--------- .../umsAdmin/UmsStudentManageServiceImpl.java | 2 +- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java index e08a348..5f3d7d5 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -54,7 +54,7 @@ public interface ICoursesService extends IService { List queryStudentList(String userId); LinkedHashSet queryTeacherByStudentLearningRecordList(String userId); - LinkedHashSet queryTeacherByStudentList(String userId); + List queryTeacherByStudentList(String userId); List getUserInfByCourse(Long userId); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java index ee9f974..f6d9ba7 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CoursesServiceImpl.java @@ -407,25 +407,28 @@ public class CoursesServiceImpl extends ServiceImpl impl } @Override - public LinkedHashSet queryTeacherByStudentList(String userId) { + public List queryTeacherByStudentList(String userId) { String roleId = umsUserMapper.getByIdRoleId(userId); CourseQuery courseQuery = new CourseQuery(); courseQuery.setUserId(userId); - LinkedHashSet umsStudentManageList = new LinkedHashSet<>(); if (roleId.equals("1")){ - PageDTO queryCourses = queryCourses(courseQuery); + PageDTO queryCourses = queryForTeacher(courseQuery); List coursesList = queryCourses.getList(); - List courseIds = coursesList.stream().map(CoursesVO::getId).collect(Collectors.toList()); - for (String courseId : courseIds) { - List studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); - for (StudentCourses studentUsername : studentUsernames) { - UmsStudentManage umsStudentManage = umsStudentManageMapper.queryStudent(String.valueOf(studentUsername.getStudent())); - if (umsStudentManage != null){ - umsStudentManageList.add(umsStudentManage); - } - } - } - return umsStudentManageList; + + // 首先,收集所有需要查询的学生ID + Set studentIds = coursesList.stream() + .map(CoursesVO::getId) + .flatMap(courseId -> studentCoursesMapper.selectBatchSomeStudent(courseId).stream() + .map(StudentCourses::getStudent)) // 假设getStudent返回Long类型 + .collect(Collectors.toSet()); // 使用Set去重 + + // 然后,一次性查询所有学生信息 + List umsStudentManageLists = studentIds.stream() + .map(studentId -> umsStudentManageMapper.queryStudent(String.valueOf(studentId))) // 假设queryStudent接受Long类型参数 + .filter(Objects::nonNull) + .collect(Collectors.toList()); + + return umsStudentManageLists; } throw new BusinessException(400,"只有老师才有此功能"); } diff --git a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java index c8b5c32..2d4b5c2 100644 --- a/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsStudentManageServiceImpl.java @@ -54,7 +54,7 @@ public class UmsStudentManageServiceImpl extends ServiceImpl pageQuery(UmsStudentPageQueryDTO umsStudentPageQueryDTO) { - LinkedHashSet umsStudentManages = coursesService.queryTeacherByStudentList(umsStudentPageQueryDTO.getUserId()); + List umsStudentManages = coursesService.queryTeacherByStudentList(umsStudentPageQueryDTO.getUserId()); //总记录数 int totalCount = umsStudentManages.size(); From 04df7b2cc3080ed469d3f82a262860cfe5e39951 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 20 Aug 2024 16:24:20 +0800 Subject: [PATCH 21/23] wy --- .../controller/cms/CmsEssayController.java | 3 +- .../KnowledgeLearningNumberMapper.java | 2 +- .../courses/CourseLearningNumberMapper.java | 2 +- .../records/RecordKnowledgeFinishMapper.java | 17 +++++++ .../records/RecordResourceFinishMapper.java | 17 +++++++ .../backend/model/entity/cms/CmsEssay.java | 5 +- .../CourseLearningNumber.java | 4 +- .../entity/records/CourseLearningRecord.java | 2 +- .../KnowledgeLearningNumber.java | 4 +- .../records/KnowledgeLearningRecord.java | 6 ++- .../entity/records/RecordKnowledgeFinish.java | 47 +++++++++++++++++ .../entity/records/RecordResourceFinish.java | 50 +++++++++++++++++++ .../records/ResourceLearningNumber.java | 2 +- .../records/ResourceLearningRecord.java | 15 +++--- .../vo/records/KnowledgeLearningRecordVo.java | 4 ++ .../vo/records/ResourceLearingRecordVo.java | 6 +++ .../IKnowledgeLearningNumberService.java | 2 +- .../courses/ICourseLearningNumberService.java | 2 +- .../CourseLearningNumberServiceImpl.java | 2 +- .../KnowledgeLearningNumberServiceImpl.java | 2 +- .../CourseLearningRecordServiceImpl.java | 2 +- .../KnowledgeLearningRecordServiceImpl.java | 4 +- .../RecordKnowledgeFinishServiceImpl.java | 21 ++++++++ .../RecordResourceFinishServiceImpl.java | 21 ++++++++ .../ResourceLearningRecordServiceImpl.java | 20 +++++++- .../IRecordKnowledgeFinishService.java | 17 +++++++ .../records/IRecordResourceFinishService.java | 17 +++++++ 27 files changed, 272 insertions(+), 24 deletions(-) create mode 100644 src/main/java/com/teaching/backend/mapper/records/RecordKnowledgeFinishMapper.java create mode 100644 src/main/java/com/teaching/backend/mapper/records/RecordResourceFinishMapper.java rename src/main/java/com/teaching/backend/model/entity/{courses => records}/CourseLearningNumber.java (93%) rename src/main/java/com/teaching/backend/model/entity/{KnowGraph => records}/KnowledgeLearningNumber.java (92%) create mode 100644 src/main/java/com/teaching/backend/model/entity/records/RecordKnowledgeFinish.java create mode 100644 src/main/java/com/teaching/backend/model/entity/records/RecordResourceFinish.java create mode 100644 src/main/java/com/teaching/backend/service/impl/records/RecordKnowledgeFinishServiceImpl.java create mode 100644 src/main/java/com/teaching/backend/service/impl/records/RecordResourceFinishServiceImpl.java create mode 100644 src/main/java/com/teaching/backend/service/records/IRecordKnowledgeFinishService.java create mode 100644 src/main/java/com/teaching/backend/service/records/IRecordResourceFinishService.java diff --git a/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java b/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java index cc45502..8b3621c 100644 --- a/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java +++ b/src/main/java/com/teaching/backend/controller/cms/CmsEssayController.java @@ -53,7 +53,8 @@ public class CmsEssayController { * @return */ @PutMapping("/edit") - public BaseResponse editEssay(CmsEssay cmsEssay){ + public BaseResponse editEssay(@RequestBody CmsEssay cmsEssay){ + System.out.println(cmsEssay); return cmsEssayService.editEssay(cmsEssay); } diff --git a/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowledgeLearningNumberMapper.java b/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowledgeLearningNumberMapper.java index 0f66e8e..deedf99 100644 --- a/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowledgeLearningNumberMapper.java +++ b/src/main/java/com/teaching/backend/mapper/KnowGraph/KnowledgeLearningNumberMapper.java @@ -2,7 +2,7 @@ package com.teaching.backend.mapper.KnowGraph; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.teaching.backend.model.entity.KnowGraph.KnowledgeLearningNumber; +import com.teaching.backend.model.entity.records.KnowledgeLearningNumber; /** *

diff --git a/src/main/java/com/teaching/backend/mapper/courses/CourseLearningNumberMapper.java b/src/main/java/com/teaching/backend/mapper/courses/CourseLearningNumberMapper.java index e30dc6d..181b591 100644 --- a/src/main/java/com/teaching/backend/mapper/courses/CourseLearningNumberMapper.java +++ b/src/main/java/com/teaching/backend/mapper/courses/CourseLearningNumberMapper.java @@ -2,7 +2,7 @@ package com.teaching.backend.mapper.courses; import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.teaching.backend.model.entity.courses.CourseLearningNumber; +import com.teaching.backend.model.entity.records.CourseLearningNumber; /** *

diff --git a/src/main/java/com/teaching/backend/mapper/records/RecordKnowledgeFinishMapper.java b/src/main/java/com/teaching/backend/mapper/records/RecordKnowledgeFinishMapper.java new file mode 100644 index 0000000..5d8ebb0 --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/records/RecordKnowledgeFinishMapper.java @@ -0,0 +1,17 @@ +package com.teaching.backend.mapper.records; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.teaching.backend.model.entity.records.RecordKnowledgeFinish; + +/** + *

+ * Mapper 接口 + *

+ * + * @author author + * @since 2024-08-20 + */ +public interface RecordKnowledgeFinishMapper extends BaseMapper { + +} diff --git a/src/main/java/com/teaching/backend/mapper/records/RecordResourceFinishMapper.java b/src/main/java/com/teaching/backend/mapper/records/RecordResourceFinishMapper.java new file mode 100644 index 0000000..b8444ce --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/records/RecordResourceFinishMapper.java @@ -0,0 +1,17 @@ +package com.teaching.backend.mapper.records; + + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.teaching.backend.model.entity.records.RecordResourceFinish; + +/** + *

+ * Mapper 接口 + *

+ * + * @author author + * @since 2024-08-20 + */ +public interface RecordResourceFinishMapper extends BaseMapper { + +} diff --git a/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java b/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java index cc381f2..845f681 100644 --- a/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java +++ b/src/main/java/com/teaching/backend/model/entity/cms/CmsEssay.java @@ -2,8 +2,10 @@ package com.teaching.backend.model.entity.cms; import com.baomidou.mybatisplus.annotation.*; +import java.time.LocalDate; import java.time.LocalDateTime; import java.io.Serializable; +import java.time.LocalTime; import com.fasterxml.jackson.annotation.JsonFormat; import io.swagger.annotations.ApiModel; @@ -44,7 +46,8 @@ public class CmsEssay implements Serializable { private String content; @ApiModelProperty(value = "发布时间") - private LocalDateTime publishTime; + @JsonFormat (locale= "zh", timezone= "GMT+8", pattern= "yyyy-MM-dd") + private LocalDate publishTime; @ApiModelProperty(value = "浏览次数") private Integer readingNumber; diff --git a/src/main/java/com/teaching/backend/model/entity/courses/CourseLearningNumber.java b/src/main/java/com/teaching/backend/model/entity/records/CourseLearningNumber.java similarity index 93% rename from src/main/java/com/teaching/backend/model/entity/courses/CourseLearningNumber.java rename to src/main/java/com/teaching/backend/model/entity/records/CourseLearningNumber.java index e462f90..3816b81 100644 --- a/src/main/java/com/teaching/backend/model/entity/courses/CourseLearningNumber.java +++ b/src/main/java/com/teaching/backend/model/entity/records/CourseLearningNumber.java @@ -1,4 +1,4 @@ -package com.teaching.backend.model.entity.courses; +package com.teaching.backend.model.entity.records; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; @@ -22,7 +22,7 @@ import lombok.experimental.Accessors; @Data @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) -@TableName("course_learning_number") +@TableName("record_course_number") @ApiModel(value="CourseLearningNumber对象", description="") public class CourseLearningNumber implements Serializable { diff --git a/src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java b/src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java index 7afccf3..08b6326 100644 --- a/src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java +++ b/src/main/java/com/teaching/backend/model/entity/records/CourseLearningRecord.java @@ -23,7 +23,7 @@ import lombok.experimental.Accessors; @Data @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) -@TableName("course_learning_record") +@TableName("record_course_learning") @ApiModel(value="CourseLearningRecord对象", description="") public class CourseLearningRecord implements Serializable { diff --git a/src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowledgeLearningNumber.java b/src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningNumber.java similarity index 92% rename from src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowledgeLearningNumber.java rename to src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningNumber.java index 7fea27b..e5fc9a5 100644 --- a/src/main/java/com/teaching/backend/model/entity/KnowGraph/KnowledgeLearningNumber.java +++ b/src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningNumber.java @@ -1,4 +1,4 @@ -package com.teaching.backend.model.entity.KnowGraph; +package com.teaching.backend.model.entity.records; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableName; @@ -22,7 +22,7 @@ import lombok.experimental.Accessors; @Data @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) -@TableName("knowledge_learning_number") +@TableName("record_knowledge_number") @ApiModel(value="KnowledgeLearningNumber对象", description="") public class KnowledgeLearningNumber implements Serializable { diff --git a/src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningRecord.java b/src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningRecord.java index 37b4cab..7ae9fb2 100644 --- a/src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningRecord.java +++ b/src/main/java/com/teaching/backend/model/entity/records/KnowledgeLearningRecord.java @@ -23,7 +23,7 @@ import lombok.experimental.Accessors; @Data @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) -@TableName("knowledge_learning_record") +@TableName("record_knowledge_learning") @ApiModel(value="KnowledgeLearningRecord对象", description="") public class KnowledgeLearningRecord implements Serializable { @@ -61,5 +61,9 @@ public class KnowledgeLearningRecord implements Serializable { @TableField("times") private LocalDateTime times; + @ApiModelProperty(value = "完成状态") + @TableField("finish") + private Integer finish; + } diff --git a/src/main/java/com/teaching/backend/model/entity/records/RecordKnowledgeFinish.java b/src/main/java/com/teaching/backend/model/entity/records/RecordKnowledgeFinish.java new file mode 100644 index 0000000..12f1f23 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/entity/records/RecordKnowledgeFinish.java @@ -0,0 +1,47 @@ +package com.teaching.backend.model.entity.records; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.io.Serializable; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + *

+ * + *

+ * + * @author author + * @since 2024-08-20 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("record_knowledge_finish") +@ApiModel(value="RecordKnowledgeFinish对象", description="") +public class RecordKnowledgeFinish implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "知识点完成状态id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "用户id") + private String userId; + + @ApiModelProperty(value = "课程id") + private String courseId; + + @ApiModelProperty(value = "知识点id") + private String knowledgeId; + + @ApiModelProperty(value = "完成状态") + private Integer finish; + + +} diff --git a/src/main/java/com/teaching/backend/model/entity/records/RecordResourceFinish.java b/src/main/java/com/teaching/backend/model/entity/records/RecordResourceFinish.java new file mode 100644 index 0000000..e021550 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/entity/records/RecordResourceFinish.java @@ -0,0 +1,50 @@ +package com.teaching.backend.model.entity.records; + +import com.baomidou.mybatisplus.annotation.TableName; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import java.io.Serializable; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + *

+ * + *

+ * + * @author author + * @since 2024-08-20 + */ +@Data +@EqualsAndHashCode(callSuper = false) +@Accessors(chain = true) +@TableName("record_resource_finish") +@ApiModel(value="RecordResourceFinish对象", description="") +public class RecordResourceFinish implements Serializable { + + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "资源学习状态id") + @TableId(value = "id", type = IdType.AUTO) + private Integer id; + + @ApiModelProperty(value = "用户id") + private String userId; + + @ApiModelProperty(value = "课程id") + private String courseId; + + @ApiModelProperty(value = "知识点id") + private String knowledgeId; + + @ApiModelProperty(value = "资源id") + private String resourceId; + + @ApiModelProperty(value = "是否完成:1已完成;2;未完成") + private Integer finish; + + +} diff --git a/src/main/java/com/teaching/backend/model/entity/records/ResourceLearningNumber.java b/src/main/java/com/teaching/backend/model/entity/records/ResourceLearningNumber.java index 57638e2..8f63d59 100644 --- a/src/main/java/com/teaching/backend/model/entity/records/ResourceLearningNumber.java +++ b/src/main/java/com/teaching/backend/model/entity/records/ResourceLearningNumber.java @@ -21,7 +21,7 @@ import lombok.experimental.Accessors; @Data @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) -@TableName("resource_learning_number") +@TableName("record_resource_number") @ApiModel(value="ResourceLearningNumber对象", description="") public class ResourceLearningNumber implements Serializable { diff --git a/src/main/java/com/teaching/backend/model/entity/records/ResourceLearningRecord.java b/src/main/java/com/teaching/backend/model/entity/records/ResourceLearningRecord.java index d7dd115..738605c 100644 --- a/src/main/java/com/teaching/backend/model/entity/records/ResourceLearningRecord.java +++ b/src/main/java/com/teaching/backend/model/entity/records/ResourceLearningRecord.java @@ -23,7 +23,7 @@ import lombok.experimental.Accessors; @Data @EqualsAndHashCode(callSuper = false) @Accessors(chain = true) -@TableName("resource_learning_record") +@TableName("record_resource_learning") @ApiModel(value="ResourceLearningRecord对象", description="") public class ResourceLearningRecord implements Serializable { @@ -67,19 +67,22 @@ public class ResourceLearningRecord implements Serializable { @ApiModelProperty(value = "学习时长") @TableField("duration") - private Integer duration; + private double duration; + + @ApiModelProperty(value = "总时长") + @TableField("total_duration") + private double totalDuration; @ApiModelProperty(value = "是否完成观看") @TableField("finish") private Integer finish; - @ApiModelProperty(value = "记录封面") - @TableField("img") - private String img; @ApiModelProperty(value = "最近学习时间") @TableField("times") private LocalDateTime times; - + @ApiModelProperty(value = "资源类型: 1:视频, 2:音频,3:文本资源,4:pdf,5:文件,6:压缩文件") + @TableField("type") + private Integer type; } diff --git a/src/main/java/com/teaching/backend/model/vo/records/KnowledgeLearningRecordVo.java b/src/main/java/com/teaching/backend/model/vo/records/KnowledgeLearningRecordVo.java index c550f19..216885e 100644 --- a/src/main/java/com/teaching/backend/model/vo/records/KnowledgeLearningRecordVo.java +++ b/src/main/java/com/teaching/backend/model/vo/records/KnowledgeLearningRecordVo.java @@ -34,4 +34,8 @@ public class KnowledgeLearningRecordVo { * 学习时间 */ private String time; + /** + * 完成状态 + */ + private Integer finish; } diff --git a/src/main/java/com/teaching/backend/model/vo/records/ResourceLearingRecordVo.java b/src/main/java/com/teaching/backend/model/vo/records/ResourceLearingRecordVo.java index 09a738e..de81f2e 100644 --- a/src/main/java/com/teaching/backend/model/vo/records/ResourceLearingRecordVo.java +++ b/src/main/java/com/teaching/backend/model/vo/records/ResourceLearingRecordVo.java @@ -26,4 +26,10 @@ public class ResourceLearingRecordVo { * 学习时间 */ private String time; + + /** + * 完成状态 + */ + private Integer finish; + } diff --git a/src/main/java/com/teaching/backend/service/KnowGraph/IKnowledgeLearningNumberService.java b/src/main/java/com/teaching/backend/service/KnowGraph/IKnowledgeLearningNumberService.java index 5d6864c..0196709 100644 --- a/src/main/java/com/teaching/backend/service/KnowGraph/IKnowledgeLearningNumberService.java +++ b/src/main/java/com/teaching/backend/service/KnowGraph/IKnowledgeLearningNumberService.java @@ -2,7 +2,7 @@ package com.teaching.backend.service.KnowGraph; import com.baomidou.mybatisplus.extension.service.IService; -import com.teaching.backend.model.entity.KnowGraph.KnowledgeLearningNumber; +import com.teaching.backend.model.entity.records.KnowledgeLearningNumber; /** *

diff --git a/src/main/java/com/teaching/backend/service/courses/ICourseLearningNumberService.java b/src/main/java/com/teaching/backend/service/courses/ICourseLearningNumberService.java index ba882e1..a0b0c74 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICourseLearningNumberService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICourseLearningNumberService.java @@ -2,7 +2,7 @@ package com.teaching.backend.service.courses; import com.baomidou.mybatisplus.extension.service.IService; -import com.teaching.backend.model.entity.courses.CourseLearningNumber; +import com.teaching.backend.model.entity.records.CourseLearningNumber; /** *

diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CourseLearningNumberServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CourseLearningNumberServiceImpl.java index ce62b53..137e847 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/CourseLearningNumberServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/CourseLearningNumberServiceImpl.java @@ -3,7 +3,7 @@ package com.teaching.backend.service.impl.courses; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.mapper.courses.CourseLearningNumberMapper; -import com.teaching.backend.model.entity.courses.CourseLearningNumber; +import com.teaching.backend.model.entity.records.CourseLearningNumber; import com.teaching.backend.service.courses.ICourseLearningNumberService; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/teaching/backend/service/impl/knowledge/KnowledgeLearningNumberServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/knowledge/KnowledgeLearningNumberServiceImpl.java index 2a1d42f..9ce4508 100644 --- a/src/main/java/com/teaching/backend/service/impl/knowledge/KnowledgeLearningNumberServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/knowledge/KnowledgeLearningNumberServiceImpl.java @@ -3,7 +3,7 @@ package com.teaching.backend.service.impl.knowledge; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.mapper.KnowGraph.KnowledgeLearningNumberMapper; -import com.teaching.backend.model.entity.KnowGraph.KnowledgeLearningNumber; +import com.teaching.backend.model.entity.records.KnowledgeLearningNumber; import com.teaching.backend.service.KnowGraph.IKnowledgeLearningNumberService; import org.springframework.stereotype.Service; diff --git a/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java index 017d625..0d25f53 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/CourseLearningRecordServiceImpl.java @@ -7,7 +7,7 @@ import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ResultUtils; import com.teaching.backend.mapper.courses.CoursesMapper; import com.teaching.backend.mapper.records.CourseLearningRecordMapper; -import com.teaching.backend.model.entity.courses.CourseLearningNumber; +import com.teaching.backend.model.entity.records.CourseLearningNumber; import com.teaching.backend.mapper.umsAdmin.UmsUserMapper; import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.entity.records.CourseLearningRecord; diff --git a/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java index 5e673eb..04ba60b 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java @@ -10,7 +10,7 @@ import com.teaching.backend.common.ResultUtils; import com.teaching.backend.mapper.records.KnowledgeLearningRecordMapper; import com.teaching.backend.mapper.umsAdmin.UmsUserMapper; -import com.teaching.backend.model.entity.KnowGraph.KnowledgeLearningNumber; +import com.teaching.backend.model.entity.records.KnowledgeLearningNumber; import com.teaching.backend.model.entity.knowtmp.Knowtmp; import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; @@ -111,6 +111,7 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl(pagenum, pagesize)); Page page1 = new Page<>(); List records = page.getRecords(); + //System.out.println(records); BeanUtil.copyProperties(page, page1); List recordsVos = new ArrayList<>(); //copy集合 @@ -123,6 +124,7 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl + * 服务实现类 + *

+ * + * @author author + * @since 2024-08-20 + */ +@Service +public class RecordKnowledgeFinishServiceImpl extends ServiceImpl implements IRecordKnowledgeFinishService { + +} diff --git a/src/main/java/com/teaching/backend/service/impl/records/RecordResourceFinishServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/RecordResourceFinishServiceImpl.java new file mode 100644 index 0000000..ba72c52 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/impl/records/RecordResourceFinishServiceImpl.java @@ -0,0 +1,21 @@ +package com.teaching.backend.service.impl.records; + + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.teaching.backend.mapper.records.RecordResourceFinishMapper; +import com.teaching.backend.model.entity.records.RecordResourceFinish; +import com.teaching.backend.service.records.IRecordResourceFinishService; +import org.springframework.stereotype.Service; + +/** + *

+ * 服务实现类 + *

+ * + * @author author + * @since 2024-08-20 + */ +@Service +public class RecordResourceFinishServiceImpl extends ServiceImpl implements IRecordResourceFinishService { + +} diff --git a/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java index 293c056..b5121d8 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ResultUtils; import com.teaching.backend.mapper.records.ResourceLearningRecordMapper; +import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; import com.teaching.backend.model.entity.records.ResourceLearningNumber; import com.teaching.backend.model.entity.records.ResourceLearningRecord; @@ -35,6 +36,8 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) { @@ -81,6 +84,21 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl getPage(int pagenum, int pagesize, String userId, String knowledgeId, String courseId) { -//格式化时间 + //格式化时间 String strDateFormat = "yyyy-MM-dd HH:mm:ss"; SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat); //分页查询 diff --git a/src/main/java/com/teaching/backend/service/records/IRecordKnowledgeFinishService.java b/src/main/java/com/teaching/backend/service/records/IRecordKnowledgeFinishService.java new file mode 100644 index 0000000..2437e18 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/records/IRecordKnowledgeFinishService.java @@ -0,0 +1,17 @@ +package com.teaching.backend.service.records; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.teaching.backend.model.entity.records.RecordKnowledgeFinish; + +/** + *

+ * 服务类 + *

+ * + * @author author + * @since 2024-08-20 + */ +public interface IRecordKnowledgeFinishService extends IService { + +} diff --git a/src/main/java/com/teaching/backend/service/records/IRecordResourceFinishService.java b/src/main/java/com/teaching/backend/service/records/IRecordResourceFinishService.java new file mode 100644 index 0000000..bd6666e --- /dev/null +++ b/src/main/java/com/teaching/backend/service/records/IRecordResourceFinishService.java @@ -0,0 +1,17 @@ +package com.teaching.backend.service.records; + + +import com.baomidou.mybatisplus.extension.service.IService; +import com.teaching.backend.model.entity.records.RecordResourceFinish; + +/** + *

+ * 服务类 + *

+ * + * @author author + * @since 2024-08-20 + */ +public interface IRecordResourceFinishService extends IService { + +} From fa0ff84bf9bc2934364ee1569a2d1b71f6b2e52f Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Tue, 20 Aug 2024 17:55:54 +0800 Subject: [PATCH 22/23] =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../KnowledgeLearningRecordMapper.java | 2 +- .../KnowledgeLearningRecordServiceImpl.java | 23 +++++++++- .../RecordKnowledgeFinishServiceImpl.java | 43 +++++++++++++++++++ .../RecordResourceFinishServiceImpl.java | 32 ++++++++++++++ .../ResourceLearningRecordServiceImpl.java | 32 +++++++------- .../IRecordKnowledgeFinishService.java | 7 +++ .../records/IRecordResourceFinishService.java | 4 ++ 7 files changed, 124 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java b/src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java index 2ddda90..d02a1f0 100644 --- a/src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java +++ b/src/main/java/com/teaching/backend/mapper/records/KnowledgeLearningRecordMapper.java @@ -20,7 +20,7 @@ import java.util.List; */ public interface KnowledgeLearningRecordMapper extends BaseMapper { - @Select("SELECT knowledge_id FROM knowledge_learning_record WHERE user_id = #{userId} GROUP BY knowledge_id") + @Select("SELECT knowledge_id FROM record_knowledge_learning WHERE user_id = #{userId} GROUP BY knowledge_id") List selectDistinctKnowledgeIdsByUser(@Param("userId") String userId); List queryStudyKnowledgeMaxNumber(); diff --git a/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java index 04ba60b..b120f8a 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/KnowledgeLearningRecordServiceImpl.java @@ -15,6 +15,7 @@ import com.teaching.backend.model.entity.records.KnowledgeLearningNumber; import com.teaching.backend.model.entity.knowtmp.Knowtmp; import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; +import com.teaching.backend.model.entity.records.RecordKnowledgeFinish; import com.teaching.backend.model.vo.knowGraph.KnowVO; import com.teaching.backend.model.vo.records.KnowledgeLearningRecordVo; @@ -50,6 +51,8 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl saveCoursesRecords(KnowledgeLearningRecord knowledgeLearningRecord) { @@ -78,7 +81,14 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl getPage(int pagenum, int pagesize, String userId, String courseId) { //格式化时间 @@ -122,6 +139,8 @@ public class KnowledgeLearningRecordServiceImpl extends ServiceImpl implements IRecordKnowledgeFinishService { + @Override + public void addFinish(KnowledgeLearningRecord knowledgeLearningRecord) { + RecordKnowledgeFinish recordKnowledgeFinish = new RecordKnowledgeFinish(); + recordKnowledgeFinish.setUserId(knowledgeLearningRecord.getUserId()); + recordKnowledgeFinish.setCourseId(knowledgeLearningRecord.getCoursesId()); + recordKnowledgeFinish.setKnowledgeId(knowledgeLearningRecord.getKnowledgeId()); + recordKnowledgeFinish.setFinish(knowledgeLearningRecord.getFinish()); + save(recordKnowledgeFinish); + } + + @Override + public void addFinish(ResourceLearningRecord resourceLearningRecord) { + RecordKnowledgeFinish recordKnowledgeFinish = new RecordKnowledgeFinish(); + recordKnowledgeFinish.setUserId(resourceLearningRecord.getUserId()); + recordKnowledgeFinish.setCourseId(resourceLearningRecord.getCoursesId()); + recordKnowledgeFinish.setKnowledgeId(resourceLearningRecord.getKnowledgeId()); + recordKnowledgeFinish.setFinish(resourceLearningRecord.getFinish()); + save(recordKnowledgeFinish); + } + + @Override + public void editFinish(KnowledgeLearningRecord knowledgeLearningRecord) { + //设置完成状态 + RecordKnowledgeFinish one = query() + .eq("course_id", knowledgeLearningRecord.getCoursesId()) + .eq("knowledge_id", knowledgeLearningRecord.getKnowledgeId()) + .eq("user_id", knowledgeLearningRecord.getUserId()).one(); + one.setFinish(1); + updateById(one); + } + + @Override + public void editFinish(ResourceLearningRecord resourceLearningRecord) { + //设置完成状态 + RecordKnowledgeFinish one = query() + .eq("course_id", resourceLearningRecord.getCoursesId()) + .eq("knowledge_id", resourceLearningRecord.getKnowledgeId()) + .eq("user_id", resourceLearningRecord.getUserId()).one(); + one.setFinish(1); + updateById(one); + } } diff --git a/src/main/java/com/teaching/backend/service/impl/records/RecordResourceFinishServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/RecordResourceFinishServiceImpl.java index ba72c52..6892a5b 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/RecordResourceFinishServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/RecordResourceFinishServiceImpl.java @@ -3,10 +3,14 @@ package com.teaching.backend.service.impl.records; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.mapper.records.RecordResourceFinishMapper; +import com.teaching.backend.model.entity.records.RecordKnowledgeFinish; import com.teaching.backend.model.entity.records.RecordResourceFinish; +import com.teaching.backend.model.entity.records.ResourceLearningRecord; import com.teaching.backend.service.records.IRecordResourceFinishService; import org.springframework.stereotype.Service; +import javax.annotation.Resource; + /** *

* 服务实现类 @@ -18,4 +22,32 @@ import org.springframework.stereotype.Service; @Service public class RecordResourceFinishServiceImpl extends ServiceImpl implements IRecordResourceFinishService { + @Resource + private RecordKnowledgeFinishServiceImpl recordKnowledgeFinishService; + @Override + public void addFinish(ResourceLearningRecord resourceLearningRecord) { + //如果资源学习完成,知识点也改为完成 + if (resourceLearningRecord.getFinish() == 1){ + recordKnowledgeFinishService.editFinish(resourceLearningRecord); + } + RecordResourceFinish recordResourceFinish = new RecordResourceFinish(); + recordResourceFinish.setUserId(resourceLearningRecord.getUserId()); + recordResourceFinish.setCourseId(resourceLearningRecord.getCoursesId()); + recordResourceFinish.setKnowledgeId(resourceLearningRecord.getKnowledgeId()); + recordResourceFinish.setResourceId(resourceLearningRecord.getResourceId()); + recordResourceFinish.setFinish(resourceLearningRecord.getFinish()); + System.out.println(recordResourceFinish); + save(recordResourceFinish); + } + + @Override + public void editFinish(ResourceLearningRecord resourceLearningRecord) { + RecordResourceFinish one = query() + .eq("course_id", resourceLearningRecord.getCoursesId()) + .eq("knowledge_id", resourceLearningRecord.getKnowledgeId()) + .eq("resource_id",resourceLearningRecord.getResourceId()) + .eq("user_id", resourceLearningRecord.getUserId()).one(); + one.setFinish(1); + updateById(one); + } } diff --git a/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java index b5121d8..bf57112 100644 --- a/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/records/ResourceLearningRecordServiceImpl.java @@ -37,7 +37,7 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl saveCoursesRecords(ResourceLearningRecord resourceLearningRecord) { @@ -68,6 +68,13 @@ public class ResourceLearningRecordServiceImpl extends ServiceImpl @@ -13,5 +16,9 @@ import com.teaching.backend.model.entity.records.RecordKnowledgeFinish; * @since 2024-08-20 */ public interface IRecordKnowledgeFinishService extends IService { + void addFinish(KnowledgeLearningRecord knowledgeLearningRecord); + void addFinish(ResourceLearningRecord resourceLearningRecord); + void editFinish(KnowledgeLearningRecord knowledgeLearningRecord); + void editFinish(ResourceLearningRecord resourceLearningRecord); } diff --git a/src/main/java/com/teaching/backend/service/records/IRecordResourceFinishService.java b/src/main/java/com/teaching/backend/service/records/IRecordResourceFinishService.java index bd6666e..5e020f3 100644 --- a/src/main/java/com/teaching/backend/service/records/IRecordResourceFinishService.java +++ b/src/main/java/com/teaching/backend/service/records/IRecordResourceFinishService.java @@ -2,7 +2,9 @@ package com.teaching.backend.service.records; import com.baomidou.mybatisplus.extension.service.IService; +import com.teaching.backend.model.entity.records.KnowledgeLearningRecord; import com.teaching.backend.model.entity.records.RecordResourceFinish; +import com.teaching.backend.model.entity.records.ResourceLearningRecord; /** *

@@ -13,5 +15,7 @@ import com.teaching.backend.model.entity.records.RecordResourceFinish; * @since 2024-08-20 */ public interface IRecordResourceFinishService extends IService { + void addFinish(ResourceLearningRecord resourceLearningRecord); + void editFinish(ResourceLearningRecord resourceLearningRecord); } From f999d4e04a14398f9cc7cf53d034fc1f66218508 Mon Sep 17 00:00:00 2001 From: you hang <2998465706@qq.com> Date: Wed, 21 Aug 2024 14:46:36 +0800 Subject: [PATCH 23/23] 111 --- pom.xml | 6 + .../backend/controller/Know/Edge.java | 21 + .../controller/Know/KnowChapterVO.java | 38 + .../controller/Know/KnowController.java | 56 +- .../backend/controller/Know/KnowCourseVO.java | 33 + .../backend/controller/Know/KnowJson.java | 42 + .../controller/Know/KnowJsonListVO.java | 31 + .../controller/Knowtmp/KnowtmpController.java | 9 + .../resource/ResourceController.java | 6 + .../mapper/Knowtemp/KnowtmpMapper.java | 8 + .../backend/mapper/chapter/ChapterMapper.java | 18 + .../backend/mapper/know/KnowRepository.java | 62 +- .../mapper/resource/ResourcesRepository.java | 4 + .../backend/service/Know/KnowService.java | 15 +- .../service/impl/know/knowServiceImpl.java | 729 +++++++++++++++--- .../impl/knowtmp/KnowtmpServiceImpl.java | 23 +- .../impl/resource/ResourceServiceImpl.java | 7 + .../service/knowtmp/KnowtmpService.java | 4 + .../service/resource/ResourceService.java | 2 + 19 files changed, 995 insertions(+), 119 deletions(-) create mode 100644 src/main/java/com/teaching/backend/controller/Know/Edge.java create mode 100644 src/main/java/com/teaching/backend/controller/Know/KnowChapterVO.java create mode 100644 src/main/java/com/teaching/backend/controller/Know/KnowCourseVO.java create mode 100644 src/main/java/com/teaching/backend/controller/Know/KnowJson.java create mode 100644 src/main/java/com/teaching/backend/controller/Know/KnowJsonListVO.java diff --git a/pom.xml b/pom.xml index f3f4d71..1f52a11 100644 --- a/pom.xml +++ b/pom.xml @@ -243,6 +243,12 @@ httpclient 4.5.6 + + com.google.code.gson + gson + 2.8.9 + + diff --git a/src/main/java/com/teaching/backend/controller/Know/Edge.java b/src/main/java/com/teaching/backend/controller/Know/Edge.java new file mode 100644 index 0000000..12d70cc --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/Know/Edge.java @@ -0,0 +1,21 @@ +package com.teaching.backend.controller.Know; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @Author:youhang + * @Date:2024-08-19-15:41 + * @Description: + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class Edge { + private String source; + private String target; + private String type; + private Integer sta; // 1 课程-章节 2 章节 - 章节 3 章节 - 知识点 4 点 - 点 + +} diff --git a/src/main/java/com/teaching/backend/controller/Know/KnowChapterVO.java b/src/main/java/com/teaching/backend/controller/Know/KnowChapterVO.java new file mode 100644 index 0000000..1c7c577 --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/Know/KnowChapterVO.java @@ -0,0 +1,38 @@ +package com.teaching.backend.controller.Know; + +import lombok.Data; + +import java.io.Serializable; + + +@Data +public class KnowChapterVO implements Serializable { + + + /** + * 章节id + */ + + private Long chapterId; + + + /** + * 知识点名称 + */ + + private String name; + + /** + * 信息 + */ + + private String info; + /** + * 学时 + */ + + private double hour; + + +} + diff --git a/src/main/java/com/teaching/backend/controller/Know/KnowController.java b/src/main/java/com/teaching/backend/controller/Know/KnowController.java index c508fc2..cd67565 100644 --- a/src/main/java/com/teaching/backend/controller/Know/KnowController.java +++ b/src/main/java/com/teaching/backend/controller/Know/KnowController.java @@ -7,6 +7,7 @@ package com.teaching.backend.controller.Know; */ import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.mapper.know.KnowRepository; import com.teaching.backend.model.dto.Know.*; import com.teaching.backend.model.entity.know.Know; import com.teaching.backend.model.entity.know.KnowChapter; @@ -28,6 +29,42 @@ public class KnowController { @Autowired private KnowService knowService; + @Autowired + private KnowRepository knowRepository; + + + + + //返回2层知识点 + @GetMapping("/twoLevelKnows") + BaseResponse getTwoLevelKnows(@RequestParam Long id){ + return knowService.getTwoLevelKnows(id); + } + //返回3层知识点 + @GetMapping("/threeLevelKnows") + BaseResponse getThreeLevelKnows(@RequestParam Long id){ + return knowService.getThreeLevelKnows(id); + } + //返回4层知识点 + @GetMapping("/fourLevelKnows") + BaseResponse getFourLevelKnows(@RequestParam Long id){ + return knowService.getFourLevelKnows(id); + } + + + //通过courseId 显示图的JSON + @GetMapping("/test") + void test(@RequestParam String courseId){ + int res = knowRepository.addCourseRelationship(courseId,932L,"related"); + } + + //通过courseId 显示图的JSON + @GetMapping("/showGraphJson") + BaseResponse showGraphJson(@RequestParam String courseId){ + return knowService.showGraphJson(courseId); + } + + // 添加全部知识点 @PostMapping("/addAllKnow") BaseResponse addAllKnow(@RequestParam String courseId){ @@ -42,11 +79,11 @@ public class KnowController { //=================== - // 添加知识点 - @PostMapping("/addKnow") - BaseResponse addKnow(@RequestBody KnowRequest knowRequest){ - return knowService.addKnow(knowRequest); - } +// // 添加知识点 +// @PostMapping("/addKnow") +// BaseResponse addKnow(@RequestBody KnowRequest knowRequest){ +// return knowService.addKnow(knowRequest); +// } // 修改知识点 @PostMapping("/updateKnow") @@ -129,4 +166,13 @@ public class KnowController { } + //获取二级知识图谱 + @GetMapping("/getsecondKnowsById") + BaseResponse getsecondKnowsById(@RequestParam Long id){ + return knowService.getsecondKnowsById(id); + } + + + + } diff --git a/src/main/java/com/teaching/backend/controller/Know/KnowCourseVO.java b/src/main/java/com/teaching/backend/controller/Know/KnowCourseVO.java new file mode 100644 index 0000000..eff546c --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/Know/KnowCourseVO.java @@ -0,0 +1,33 @@ +package com.teaching.backend.controller.Know; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class KnowCourseVO implements Serializable { + + + /** + * 课程id + */ + + private String courseId; + + + /** + * 知识点名称 + */ + + private String name; + + /** + * 信息 + */ + private String info; + private double hour; + + + +} + diff --git a/src/main/java/com/teaching/backend/controller/Know/KnowJson.java b/src/main/java/com/teaching/backend/controller/Know/KnowJson.java new file mode 100644 index 0000000..09e4911 --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/Know/KnowJson.java @@ -0,0 +1,42 @@ +package com.teaching.backend.controller.Know; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class KnowJson implements Serializable { + + + /** + * mysql 中 知识点id + */ + + private Long knowId; + + + /** + * 知识点名称 + */ + + private String name; + + /** + * 信息 + */ + + private String info; + /** + * 学时 + */ + + private double hour; + + +} + diff --git a/src/main/java/com/teaching/backend/controller/Know/KnowJsonListVO.java b/src/main/java/com/teaching/backend/controller/Know/KnowJsonListVO.java new file mode 100644 index 0000000..421fea8 --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/Know/KnowJsonListVO.java @@ -0,0 +1,31 @@ +package com.teaching.backend.controller.Know; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.List; + + + +public class KnowJsonListVO implements Serializable { + + private List knowJsonList; + public List KnowJsonListVO() { + return knowJsonList; + } + + public void setKnowJsonList(List knowJsonList) { + this.knowJsonList = knowJsonList; + } + + public List getKnowJsonList() { + return this.knowJsonList ; + } + + + + +} + diff --git a/src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java b/src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java index 85ab55d..c71c1a8 100644 --- a/src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java +++ b/src/main/java/com/teaching/backend/controller/Knowtmp/KnowtmpController.java @@ -1,6 +1,7 @@ package com.teaching.backend.controller.Knowtmp; import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.model.dto.Know.BaseKnowReturn; import com.teaching.backend.model.dto.Knowtmp.KnowtempAdd; import com.teaching.backend.model.dto.Knowtmp.KnowtempUpdate; import com.teaching.backend.model.entity.knowtmp.Knowtmp; @@ -22,6 +23,14 @@ public class KnowtmpController { @Autowired private KnowtmpService knowtmpService; + //返回课程下所有知识点 + @GetMapping("/getAllKnows") + BaseResponse getAllKnows(@RequestParam String courseId){ + return knowtmpService.getAllKnows(courseId); + } + + + // 添加知识点 @PostMapping("/addKnow") diff --git a/src/main/java/com/teaching/backend/controller/resource/ResourceController.java b/src/main/java/com/teaching/backend/controller/resource/ResourceController.java index 29cdfd4..9c45bd9 100644 --- a/src/main/java/com/teaching/backend/controller/resource/ResourceController.java +++ b/src/main/java/com/teaching/backend/controller/resource/ResourceController.java @@ -47,6 +47,7 @@ public class ResourceController { public ResponseEntity readFile(@RequestParam String filename) { return resourceService.readFile(filename); } + @GetMapping("/addRelationship/BetweenCourseAndResources") public BaseResponse addResourcesAndKnowByCourseId(@RequestParam String courseId, @RequestParam List resourcesIds){ return resourceService.addResourcesAndKnowByCourseId(courseId,resourcesIds); @@ -77,6 +78,11 @@ public class ResourceController { BaseResponse> queryBesidesKnowToResources(@RequestParam Long KnowId){ return resourceService.queryBesidesKnowToResources(KnowId); } + //查询知识点下资源 + @GetMapping("/queryResourcesByKnowId") + BaseResponse> queryResourcesByKnowId(@RequestParam Long KnowId){ + return resourceService.queryResourcesByKnowId(KnowId); + } diff --git a/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtmpMapper.java b/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtmpMapper.java index 5aee0cb..fd799d1 100644 --- a/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtmpMapper.java +++ b/src/main/java/com/teaching/backend/mapper/Knowtemp/KnowtmpMapper.java @@ -2,7 +2,11 @@ package com.teaching.backend.mapper.Knowtemp; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.teaching.backend.model.entity.knowtmp.Knowtmp; +import io.lettuce.core.dynamic.annotation.Param; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +import java.util.List; /** @@ -11,6 +15,10 @@ import org.apache.ibatis.annotations.Mapper; @Mapper public interface KnowtmpMapper extends BaseMapper { + @Select("SELECT * FROM Knowtmp WHERE chapterid = #{chapterId} ORDER BY ordernum") + List queryIdByChapterId(@Param("chapterid") Long chapterId); + + } diff --git a/src/main/java/com/teaching/backend/mapper/chapter/ChapterMapper.java b/src/main/java/com/teaching/backend/mapper/chapter/ChapterMapper.java index 01859f9..1866cc8 100644 --- a/src/main/java/com/teaching/backend/mapper/chapter/ChapterMapper.java +++ b/src/main/java/com/teaching/backend/mapper/chapter/ChapterMapper.java @@ -21,6 +21,24 @@ public interface ChapterMapper extends BaseMapper { @Select("SELECT * FROM chapter WHERE course_id = #{courseId}") List selectSectionsByCourseId(@Param("courseId") String courseId); + @Select("SELECT id FROM chapter WHERE course_id = #{courseId}") + List selectChapterIdsByCourseId(@Param("courseId") String courseId); + + + @Select("SELECT * FROM chapter WHERE course_id = #{courseId} ORDER BY order_num") + List selectSectionsOrderByNumByCourseId(@Param("courseId") String courseId); + + @Select("SELECT * FROM chapter WHERE course_id = #{courseId} AND pid = 0 ORDER BY order_num") + List selectChapterPIDByCourseId(@Param("courseId") String courseId); + + @Select("SELECT * FROM chapter WHERE pid = #{parentId} ORDER BY order_num") + List selectChapterChildrenOrderByNum(@Param("parentId") Long parentId); + + + @Select("SELECT id FROM chapter WHERE pid = #{chapterId} ORDER BY order_num") + List selectSectionsOrderByNumByChapterId(@Param("pid") Integer chapterId); + + @Select("SELECT * FROM course_chapter WHERE course_id = #{courseId} AND (pid = #{parentId} )") List selectSectionsWithChildren(@Param("courseId") String courseId, @Param("parentId") String parentId); @Select("SELECT * FROM chapter WHERE id = #{excelId}") diff --git a/src/main/java/com/teaching/backend/mapper/know/KnowRepository.java b/src/main/java/com/teaching/backend/mapper/know/KnowRepository.java index e58df2f..958a8ac 100644 --- a/src/main/java/com/teaching/backend/mapper/know/KnowRepository.java +++ b/src/main/java/com/teaching/backend/mapper/know/KnowRepository.java @@ -7,22 +7,31 @@ package com.teaching.backend.mapper.know; */ +import com.teaching.backend.model.entity.courses.Courses; import com.teaching.backend.model.entity.know.Know; import com.teaching.backend.model.entity.know.KnowChapter; import com.teaching.backend.model.entity.know.KnowCourse; import com.teaching.backend.model.entity.resource.Resources; import org.springframework.data.neo4j.repository.Neo4jRepository; import org.springframework.data.neo4j.repository.query.Query; +import org.springframework.data.repository.query.Param; import java.util.List; import java.util.Set; public interface KnowRepository extends Neo4jRepository { + + + @Query("MATCH (p:Know)-[:FatherAndSon]->(n:Know) WHERE p.chapterId = $chapterId RETURN p.id ORDER BY ordernum;") + ListqueryKnowIdByChapterId(Long chapterId); + + + //====================== - @Query("CREATE (n:Know {name: $name,info:$info}) return n;") - Know addKnow(String name,String info); + @Query("CREATE (n:Know {knowId: $KnowId,name: $name,info:$info,hour:$hour}) return ID(n);") + Long addKnow(Long KnowId,String name,String info,double hour); @Query("MATCH ID(p:Know) = $id SET p.name = $name set p.info= $info RETURN count(p);") @@ -36,8 +45,8 @@ public interface KnowRepository extends Neo4jRepository { //============================= - @Query("CREATE (n:Know {name: $name, courseId: $courseId,info:$info,hour:$hour}) return count(n)") - int addCourse(String courseId, String name, String info,double hour); + @Query("CREATE (n:Know {name: $name, courseId: $courseId,info:$info,hour:$hour}) return ID(n) as id") + Long addCourse(String courseId, String name, String info, double hour); @Query("MATCH (p:Know {courseId:$courseId }) SET p.name = $name set p.info= $info RETURN count(p);") int updateCourse(String courseId, String name, String info); @@ -50,8 +59,8 @@ public interface KnowRepository extends Neo4jRepository { //==================== - @Query("CREATE (n:Know {name: $name, chapterId:$chapterId,info:$info,hour:$hour}) return count(n)") - int addChapter(Long chapterId, String name, String info,double hour); + @Query("CREATE (n:Know {name: $name, chapterId:$chapterId,info:$info,hour:$hour}) return ID(n)") + Long addChapter(Long chapterId, String name, String info,double hour); @Query("MATCH (p:Know {chapterId:$chapterId }) SET p.name = $name set p.info= $info RETURN count(p);") int updateChapter(Long chapterId, String name, String info); @@ -67,18 +76,47 @@ public interface KnowRepository extends Neo4jRepository { Set queryBesidesKnowToResources(Long id); //建立关系 课程 - 章节 - @Query("MATCH (p:Know {courseId: $courseId}), (c:Know {chapterId: $chapterId}) CREATE (p)-[r:FatherAndSon]->(c) return count(r);") - int addFatherAndSonWithCourse(String courseId,Long chapterId); + @Query("MATCH (p:Know {courseId: $courseId}), (c:Know {chapterId: $chapterId}) CREATE (p)-[r:contain]->(c) return count(r);") + int addContainWithCourse(String courseId,Long chapterId); //建立关系 章节与章节 - @Query("MATCH (p:Know {chapterId: $chapterId1}), (c:Know {chapterId: $chapterId2}) CREATE (c)-[r:FatherAndSon]->(p) return count(r);") - int addFatherAndSonWithChapter(Long chapterId1,Long chapterId2); + @Query("MATCH (p:Know {chapterId: $chapterId1}), (c:Know {chapterId: $chapterId2}) CREATE (c)-[r:contain]->(p) return count(r);") + int addContainWithChapter(Long chapterId1,Long chapterId2); //建立关系 章节与知识点 - @Query("MATCH (p:Know), (j:Know) WHERE p.chapterId= $chapterId AND ID(j) = $id CREATE (p)-[r:FatherAndSon]->(j) return count(r);") - int addFatherAndSonWithKnow(Long id,Long chapterId); + @Query("MATCH (p:Know), (j:Know) WHERE p.chapterId= $chapterId AND ID(j) = $id CREATE (p)-[r:contain]->(j) return count(r);") + int addContainWithKnow(Long id,Long chapterId); @Query("MATCH (p:Know), (c:Resources) WHERE ID(p) = $id AND ID(c) = $ResourcesId CREATE (p)-[r:resources]->(c) return count(r)") int addResourceResourcesKnow(Long id, Long ResourcesId); + + //建立关系 章节与章节 顺序 Subsequent + @Query("MATCH (p:Know), (j:Know) WHERE ID(p) = $chapterId1 AND ID(j)= $chapterId2 CREATE (p)-[r:Subsequent]->(j) return count(r);") + int addSubsequentByChapterId(Long chapterId1,Long chapterId2); + + //建立关系 章节与章节 顺序 Subsequent + @Query("MATCH (p:Know), (j:Know) WHERE ID(p)= $id1 AND ID(j)= $id2 CREATE (p)-[r:order]->(j) return count(r);") + int addOrderById(Long id1,Long id2); + + //========== + //建立关系 all -课程 + @Query("MATCH (p:Know {courseId: $courseId}), (j:Know {chapterId: $chapterId}) CREATE (p)-[r:顺序]->(j) return count(p);") + int addCourseRelationship(String courseId,Long chapterId,String type); + + //建立关系 all -章节 + @Query("MATCH (p:Know), (j:Know) WHERE p.chapterId= $chapterId1 AND ID(j)= $chapterId2 CREATE (p)-[r: "+"$type"+"]->(j) return count(r);") + int addChapterRelationship(Long chapterId1, Long chapterId2, @Param("type")String type); + + //建立关系 all -节 - 点 + @Query("MATCH (p:Know), (j:Know) WHERE p.chapterId= $chapterId AND j.knowId= $knowId CREATE (p)-[r: $type]->(j) return count(r);") + int addChapterToKnowRelationship(Long chapterId,Long knowId,String type); + + + + //建立关系 all - 知识点 + @Query("MATCH (p:Know), (j:Know) WHERE p.knowId= $knowId1 AND j.knowId = $knowId2 CREATE (p)-[r: $type]->(j) return count(r);") + int addKnowRelationship(Long knowId1,Long knowId2,String type); + + } diff --git a/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java b/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java index ec4ad2e..256b73c 100644 --- a/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java +++ b/src/main/java/com/teaching/backend/mapper/resource/ResourcesRepository.java @@ -45,6 +45,10 @@ public interface ResourcesRepository extends Neo4jRepository { @Query("MATCh (p:Know)-[*0..1]->(n:Know)-[:resources]->(m:Resources) WHERE ID(p) = $KnowId RETURN m") Set queryBesidesKnowToResources(Long KnowId); + // + @Query("MATCH (p)-[r:resources]->(c) WHERE ID(p) = $KnowId RETURN c") + Set queryResourcesByKnowId(Long KnowId); + diff --git a/src/main/java/com/teaching/backend/service/Know/KnowService.java b/src/main/java/com/teaching/backend/service/Know/KnowService.java index f50b2be..064bbc5 100644 --- a/src/main/java/com/teaching/backend/service/Know/KnowService.java +++ b/src/main/java/com/teaching/backend/service/Know/KnowService.java @@ -18,6 +18,14 @@ import java.util.Set; */ public interface KnowService { + BaseResponse getTwoLevelKnows(Long id); + BaseResponse getThreeLevelKnows(Long id); + BaseResponse getFourLevelKnows(Long id); + + //通过courseId 显示图的JSON + BaseResponse showGraphJson(String courseId); + + //通过courseId 添加所有节点 BaseResponse addAllKnow(String courseId); @@ -27,8 +35,8 @@ public interface KnowService { //===================== - // 添加知识点 - BaseResponse addKnow(KnowRequest knowRequest); +// // 添加知识点 +// BaseResponse addKnow(KnowRequest knowRequest); // 修改知识点 BaseResponse updateKnow(KnowUpdateRequest knowUpdateRequest); @@ -73,6 +81,9 @@ public interface KnowService { //获取课程下的所有知识点 BaseResponse getAllKnowByCourseId(String id); + //获取课程下的所有知识点 + BaseResponse getsecondKnowsById(Long id); + //获取课程下的所有资源 BaseResponse> getAllResourcesByCourseId(String id); diff --git a/src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java index c86cbca..8744014 100644 --- a/src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/know/knowServiceImpl.java @@ -1,9 +1,25 @@ package com.teaching.backend.service.impl.know; +import cn.hutool.json.JSONArray; +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonObject; import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ErrorCode; import com.teaching.backend.common.ResultUtils; +import com.teaching.backend.controller.Know.Edge; +import com.teaching.backend.controller.Know.KnowJson; +import com.teaching.backend.controller.Know.KnowJsonListVO; +import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper; import com.teaching.backend.mapper.chapter.ChapterMapper; import com.teaching.backend.mapper.courses.CoursesMapper; import com.teaching.backend.mapper.know.KnowRepository; @@ -29,6 +45,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.io.IOException; import java.util.*; import java.util.stream.Collectors; @@ -43,6 +60,9 @@ public class knowServiceImpl implements KnowService { @Autowired private KnowRepository knowRepository; + @Autowired + private KnowtmpMapper knowtmpMapper; + @Autowired private ChapterMapper chapterMapper; @@ -51,7 +71,6 @@ public class knowServiceImpl implements KnowService { private KnowtmpService knowtmpService; - @Autowired CoursesMapper coursesMapper; @@ -59,107 +78,563 @@ public class knowServiceImpl implements KnowService { private Neo4jClient neo4jClient; - public BaseResponse addRelationshipWithresources(Long id, Long resourceId){ - int f = knowRepository.addResourceResourcesKnow(id,resourceId); - if(f <= 0){ + public BaseResponse addRelationshipWithresources(Long id, Long resourceId) { + int f = knowRepository.addResourceResourcesKnow(id, resourceId); + if (f <= 0) { throw new RuntimeException("添加关系失败"); } return ResultUtils.success("添加关系成功"); } + @Override + public BaseResponse getTwoLevelKnows(Long id) { + Collection> all = + neo4jClient.query("match(n:Know)-[r*0..2]->(p:Know) where ID(n) = " + id + " return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all(); + + Map colorChoose = new + HashMap<>(); + String color[] = new String[10]; + String[] colorList = {"#91CC75", "#5470C6", "#FAC858", "#EE6666", "#73C0DE", "#EA7CCC", "#5577FF", "#5577FF", "#9DBFFF", "#78A7FF"}; + for (int i = 0; i < 10; i++) { + colorChoose.put((long) i, colorList[i]); + } + + Iterator> iterator = all.iterator(); + Set knowList = new HashSet<>(); + Set linksList = new HashSet<>(); + KnowVO knowVO; + List node2 = new ArrayList<>(); + Links links; + int p = 0; + while (iterator.hasNext()) { + Map element = iterator.next(); + knowVO = new KnowVO(); + Node node1 = (Node) element.get("p"); + + Long group = (Long) element.get("d"); + knowVO.setColor(colorChoose.get(group)); + + Long id1 = node1.id(); + String name1 = node1.get("name").asString(); + knowVO.setId(id1); + knowVO.setLabel(name1); + + knowList.add(knowVO); + + node2 = (List) element.get("r"); + for (int i = 0; i < node2.size(); i++) { + InternalRelationship e = (InternalRelationship) node2.get(i); + links = new Links(); + links.setId(e.id()); + links.setSource(e.startNodeId()); + links.setTarget(e.endNodeId()); + if ("contain".equals(e.type())) { + links.setLabel("包含"); + } else if ("order".equals(e.type())) { + links.setLabel("顺序"); + } + linksList.add(links); + } + + + } + BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList, linksList); + return ResultUtils.success(baseKnowReturn); + } + + @Override + public BaseResponse getThreeLevelKnows(Long id) { + Collection> all = + neo4jClient.query("match(n:Know)-[r*0..3]->(p:Know) where ID(n) = " + id + " return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all(); + + Map colorChoose = new + HashMap<>(); + String color[] = new String[10]; + String[] colorList = {"#91CC75", "#5470C6", "#FAC858", "#EE6666", "#73C0DE", "#EA7CCC", "#5577FF", "#5577FF", "#9DBFFF", "#78A7FF"}; + for (int i = 0; i < 10; i++) { + colorChoose.put((long) i, colorList[i]); + } + + Iterator> iterator = all.iterator(); + Set knowList = new HashSet<>(); + Set linksList = new HashSet<>(); + KnowVO knowVO; + List node2 = new ArrayList<>(); + Links links; + int p = 0; + while (iterator.hasNext()) { + Map element = iterator.next(); + knowVO = new KnowVO(); + Node node1 = (Node) element.get("p"); + + Long group = (Long) element.get("d"); + knowVO.setColor(colorChoose.get(group)); + + Long id1 = node1.id(); + String name1 = node1.get("name").asString(); + knowVO.setId(id1); + knowVO.setLabel(name1); + + knowList.add(knowVO); + + node2 = (List) element.get("r"); + for (int i = 0; i < node2.size(); i++) { + InternalRelationship e = (InternalRelationship) node2.get(i); + links = new Links(); + links.setId(e.id()); + links.setSource(e.startNodeId()); + links.setTarget(e.endNodeId()); + if ("contain".equals(e.type())) { + links.setLabel("包含"); + } else if ("order".equals(e.type())) { + links.setLabel("顺序"); + } + linksList.add(links); + } + + + } + BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList, linksList); + return ResultUtils.success(baseKnowReturn); + } + + @Override + public BaseResponse getFourLevelKnows(Long id) { + Collection> all = + neo4jClient.query("match(n:Know)-[r*0..4]->(p:Know) where ID(n) = " + id + " return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all(); + + Map colorChoose = new + HashMap<>(); + String color[] = new String[10]; + String[] colorList = {"#91CC75", "#5470C6", "#FAC858", "#EE6666", "#73C0DE", "#EA7CCC", "#5577FF", "#5577FF", "#9DBFFF", "#78A7FF"}; + for (int i = 0; i < 10; i++) { + colorChoose.put((long) i, colorList[i]); + } + + Iterator> iterator = all.iterator(); + Set knowList = new HashSet<>(); + Set linksList = new HashSet<>(); + KnowVO knowVO; + List node2 = new ArrayList<>(); + Links links; + int p = 0; + while (iterator.hasNext()) { + Map element = iterator.next(); + knowVO = new KnowVO(); + Node node1 = (Node) element.get("p"); + + Long group = (Long) element.get("d"); + knowVO.setColor(colorChoose.get(group)); + + Long id1 = node1.id(); + String name1 = node1.get("name").asString(); + knowVO.setId(id1); + knowVO.setLabel(name1); + + knowList.add(knowVO); + + node2 = (List) element.get("r"); + for (int i = 0; i < node2.size(); i++) { + InternalRelationship e = (InternalRelationship) node2.get(i); + links = new Links(); + links.setId(e.id()); + links.setSource(e.startNodeId()); + links.setTarget(e.endNodeId()); + if ("contain".equals(e.type())) { + links.setLabel("包含"); + } else if ("order".equals(e.type())) { + links.setLabel("顺序"); + } + linksList.add(links); + } + + + } + BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList, linksList); + return ResultUtils.success(baseKnowReturn); + } + + @Override + public BaseResponse showGraphJson(String courseId) { + return addInformation(courseId); + } + @Override public BaseResponse addAllKnow(String courseId) { try { - addAllKnowTransation(courseId) ; - }catch (Exception e){ + addAllKnowTransation(courseId); + } catch (Exception e) { e.printStackTrace(); - return ResultUtils.error(ErrorCode.OPERATION_ERROR,e.getMessage()); + return ResultUtils.error(ErrorCode.OPERATION_ERROR, e.getMessage()); } //6.返回成功信息,关闭事务 return ResultUtils.success("添加成功"); } + private BaseResponse addInformation(String courseId) { + + // 创建 JSON 对象数组 + JSONArray jsonArrayKnowNode = JSONUtil.createArray(); + JSONArray jsonArrayCourseNode = JSONUtil.createArray(); + JSONArray jsonArrayChapterNode = JSONUtil.createArray(); + + + //查询数据库-课程 + Courses courses = coursesMapper.selectById(courseId); + JSONObject obj1 = JSONUtil.createObj(); + obj1.put("courseId", courseId); + obj1.put("name", courses.getName()); + obj1.put("info", courses.getDescription()); + obj1.put("hour", courses.getClasshours()); + jsonArrayCourseNode.add(obj1); + + //查询数据库-章-节 + List chapterList = new ArrayList<>(); + List chapterListPID = chapterMapper.selectChapterPIDByCourseId(courseId); + List chapterOneIds = new ArrayList<>(); + List chapterTwoIds = new ArrayList<>(); + for (int i = 0; i < chapterListPID.size(); i++) { + chapterList.add(chapterListPID.get(i)); + chapterOneIds.add(chapterListPID.get(i).getId()); + List chapterListSecond = chapterMapper.selectChapterChildrenOrderByNum(chapterListPID.get(i).getId()); + for (int j = 0; j < chapterListSecond.size(); j++) { + chapterList.add(chapterListSecond.get(j)); + chapterTwoIds.add(chapterListSecond.get(j).getId()); + } + } + for (int i = 0; i < chapterList.size(); i++) { + Chapter chapter = chapterList.get(i); + JSONObject obj2 = JSONUtil.createObj(); + obj2.put("chapterId", chapter.getId()); + obj2.put("name", chapter.getName()); + obj2.put("info", chapter.getContent()); + obj2.put("hour", chapter.getTotalClassHours()); + jsonArrayChapterNode.add(obj2); + } + + //查询数据库-知识点 + for (int i = 0; i < chapterList.size(); i++) { + Chapter chapter = chapterList.get(i); + if (chapter.getPid() != 0) { + List knowlist = knowtmpService.queryByChapterId(chapter.getId()); + for (int j = 0; j < knowlist.size(); j++) { + Knowtmp knowtmp = knowlist.get(j); + JSONObject obj3 = JSONUtil.createObj(); + obj3.put("knowId", knowtmp.getId()); + obj3.put("name", knowtmp.getName()); + obj3.put("info", knowtmp.getInfo()); + obj3.put("hour", knowtmp.getHour()); + jsonArrayKnowNode.add(obj3); + } + } + + } + + + // =======创建关系 + JSONArray edgesArray = JSONUtil.createArray(); + + + // 创建边列表 + // 课程-章节 父子 + for (int i = 0; i < chapterListPID.size(); i++) { + Chapter chapter = chapterListPID.get(i); + JSONObject edge = JSONUtil.createObj(); + edge.put("source", courses.getId()); + edge.put("target", chapter.getId()); + edge.put("type", "FatherAndSon"); + edge.put("sta", 1); + edgesArray.add(edge); + } + //章-节 父子 + for (int i = 0; i < chapterListPID.size(); i++) { + List chapterListSecond = chapterMapper.selectChapterChildrenOrderByNum(chapterListPID.get(i).getId()); + for (int j = 0; j < chapterListSecond.size(); j++) { + JSONObject edge = JSONUtil.createObj(); + edge.put("source", chapterListPID.get(i).getId()); + edge.put("target", chapterListSecond.get(j).getId()); + edge.put("type", "FatherAndSon"); + edge.put("sta", 2); + edgesArray.add(edge); + } + } + //节与点父子 + List knowIds = new ArrayList<>(); + for (int i = 0; i < chapterTwoIds.size(); i++) { + List knowlist = knowtmpService.queryByChapterId(chapterTwoIds.get(i)); + for (int j = 0; j < knowlist.size(); j++) { + Knowtmp knowtmp = knowlist.get(j); + JSONObject edge = JSONUtil.createObj(); + edge.put("source", chapterTwoIds.get(i)); + edge.put("target", knowtmp.getId()); + edge.put("type", "FatherAndSon"); + edge.put("sta", 3); + edgesArray.add(edge); + knowIds.add(knowtmp.getId()); + } + } + + + //章-章 顺序 + for (int i = 0; i < chapterOneIds.size() - 1; i++) { + JSONObject edge = JSONUtil.createObj(); + edge.put("source", chapterOneIds.get(i)); + edge.put("target", chapterOneIds.get(i + 1)); + edge.put("type", "Subsequence"); + edge.put("sta", 2); + edgesArray.add(edge); + } + + + //节与节 顺序 + for (int i = 0; i < chapterTwoIds.size() - 1; i++) { + JSONObject edge = JSONUtil.createObj(); + edge.put("source", chapterTwoIds.get(i)); + edge.put("target", chapterTwoIds.get(i + 1)); + edge.put("type", "Subsequence"); + edge.put("sta", 2); + edgesArray.add(edge); + } + + + //点-点 顺序 + for (int i = 0; i < knowIds.size() - 1; i++) { + JSONObject edge = JSONUtil.createObj(); + edge.put("source", knowIds.get(i)); + edge.put("target", knowIds.get(i + 1)); + edge.put("type", "Subsequence"); + edge.put("sta", 4); + edgesArray.add(edge); + } + String jsonNodeKnow = jsonArrayKnowNode.toString(); + String jsonNodeChapter = jsonArrayChapterNode.toString(); + String jsonNodeCourse = jsonArrayCourseNode.toString(); + String jsonEdges = edgesArray.toString(); + + System.out.println("json node " + jsonNodeKnow); + System.out.println("json jsonNodeChapter " + jsonNodeChapter); + System.out.println("json edge " + jsonEdges); + return generateGraph(jsonNodeCourse, jsonNodeChapter, jsonNodeKnow, jsonEdges); + //将json保存在mysql表中 + + } + + //todo 根据json串生成 图谱 保证事务 + private BaseResponse generateGraph(String jsonNodeCourse, String jsonNodeChapter, String jsonNodeKnow, String jsonEdges) { + //插入图 + JSONArray jsonArrayCourse = JSONUtil.parseArray(jsonNodeCourse); + for (Object obj : jsonArrayCourse) { + JSONObject jsonObject = (JSONObject) obj; + String courseId = jsonObject.getStr("courseId"); + String name = jsonObject.getStr("name"); + String info = jsonObject.getStr("info"); + Integer hour = jsonObject.getInt("hour"); + //在图数据库中插入 + Long res = knowRepository.addCourse(courseId, name, info, hour); + if (res == null) { + throw new RuntimeException("添加课程失败"); + } + + } + //插入章节 + JSONArray jsonArray = JSONUtil.parseArray(jsonNodeChapter); + for (Object obj : jsonArray) { + JSONObject jsonObject = (JSONObject) obj; + Long chapterId = jsonObject.getLong("chapterId"); + String name = jsonObject.getStr("name"); + String info = jsonObject.getStr("info"); + double hour = jsonObject.getDouble("hour"); + //在图数据库中插入 + Long res = knowRepository.addChapter(chapterId, name, info, hour); + if (res == null) { + throw new RuntimeException("添加章节失败"); + } + + } + //插入知识点 + JSONArray jsonArrayKnow = JSONUtil.parseArray(jsonNodeKnow); + for (Object obj : jsonArrayKnow) { + JSONObject jsonObject = (JSONObject) obj; + Long knowId = jsonObject.getLong("knowId"); + String name = jsonObject.getStr("name"); + String info = jsonObject.getStr("info"); + double hour = jsonObject.getDouble("hour"); + //在图数据库中插入 + Long res = knowRepository.addKnow(knowId, name, info, hour); + if (res == null) { + throw new RuntimeException("添加知识点失败"); + } + + } + + //插入关系 + JSONArray jsonArrayEdges = JSONUtil.parseArray(jsonEdges); + for (Object obj : jsonArrayEdges) { + JSONObject jsonObject = (JSONObject) obj; + String source = jsonObject.getStr("source"); + String target = jsonObject.getStr("target"); + String type = jsonObject.getStr("type"); + Integer sta = jsonObject.getInt("sta"); + //在图数据库中插入 + if (sta != null && sta == 1) { + Long target1 = Long.parseLong(target); + int res = knowRepository.addCourseRelationship(source, target1, type); + if (res <= 0) { + throw new RuntimeException("添加关系 1 失败"); + } + } else if (sta != null && sta == 2) { + Long source1 = Long.parseLong(source); + Long target1 = Long.parseLong(target); + int res = knowRepository.addChapterRelationship(source1, target1, type); + if (res <= 0) { + throw new RuntimeException("添加关系 2 失败"); + } + + } else if (sta != null && sta == 3) { + Long source1 = Long.parseLong(source); + Long target1 = Long.parseLong(target); + int res = knowRepository.addChapterToKnowRelationship(source1, target1, type); + if (res <= 0) { + throw new RuntimeException("添加关系 13失败"); + } + } else if (sta != null && sta == 4) { + Long source1 = Long.parseLong(source); + Long target1 = Long.parseLong(target); + int res = knowRepository.addKnowRelationship(source1, target1, type); + if (res <= 0) { + throw new RuntimeException("添加关系 4 失败"); + } + } else { + throw new RuntimeException("sta 错误"); + } + + } + return ResultUtils.success("添加节点关系成功"); + + + } + + @Transactional - // todo 事务没有正确使用 - public void addAllKnowTransation(String courseId) throws Exception{ + public void addAllKnowTransation(String courseId) throws Exception { + int f; + //验证章节是否存在 + //验证知识点是否存在,避免重复添加 + //先添加节点 + //后赋值关系 + + // 2.从课程表查出课程节点 并添加到 neo Courses courses = coursesMapper.selectById(courseId); - int f = knowRepository.addCourse(courseId,courses.getName(),courses.getDescription(),courses.getClasshours()); - if(f <= 0){ + Long KnowCourseId = knowRepository.addCourse(courseId, courses.getName(), courses.getDescription(), courses.getClasshours()); + + if (KnowCourseId == null) { throw new RuntimeException("添加课程失败"); } // 3 从章节表查出章节节点 并添加到 neo - List chapterList = chapterMapper.selectSectionsByCourseId(courseId); + List chapterList = new ArrayList<>(); + List chapterListPID = chapterMapper.selectChapterPIDByCourseId(courseId); + for (int i = 0; i < chapterListPID.size(); i++) { + chapterList.add(chapterListPID.get(i)); + List chapterListSecond = chapterMapper.selectChapterChildrenOrderByNum(chapterListPID.get(i).getId()); + for (int j = 0; j < chapterListSecond.size(); j++) { + chapterList.add(chapterListSecond.get(j)); + } + } + //添加节点 + List chapterIds = new ArrayList<>(); + List chapterOneIds = new ArrayList<>(); + List chapterTwoIds = new ArrayList<>(); for (int i = 0; i < chapterList.size(); i++) { Chapter chapter = chapterList.get(i); - f =knowRepository.addChapter(chapter.getId(),chapter.getName(),chapter.getContent(),chapter.getTotalClassHours()); - if(f <= 0){ + Long KnowChapterId = knowRepository.addChapter(chapter.getId(), chapter.getName(), chapter.getContent(), chapter.getTotalClassHours()); + if (chapter.getPid() == 0) { + chapterOneIds.add(KnowChapterId); + } else { + chapterTwoIds.add(KnowChapterId); + } + chapterIds.add(chapter.getId()); + if (KnowChapterId == null) { throw new RuntimeException("添加章节失败"); } } - List idList = chapterList.stream() - .map(menu -> menu.getId()) - .collect(Collectors.toList()); //获取chapterId 查询知识点 返回知识点集合 - List knowlist = knowtmpService.queryByChapterIdList(idList); - for (int i = 0; i < idList.size(); i++) { - List knowlist1 = knowtmpService.queryByChapterId(idList.get(i)); - for (int j = 0; j < knowlist1.size(); j++) { - Know know = knowRepository.addKnow(knowlist1.get(j).getName(),knowlist1.get(j).getInfo()); - if(know == null){ - throw new RuntimeException("添加知识点失败"); - } - f = knowRepository.addFatherAndSonWithKnow(know.getId(),idList.get(i)); - if(f <= 0){ - throw new RuntimeException("添加知识点-章节失败"); + List knowIds = new ArrayList<>(); + for (int i = 0; i < chapterList.size(); i++) { + Chapter chapter = chapterList.get(i); + if (chapter.getPid() != 0) { + List knowlist = knowtmpService.queryByChapterId(chapter.getId()); + for (int j = 0; j < knowlist.size(); j++) { + Long knowId = knowRepository.addKnow(knowlist.get(j).getId(), knowlist.get(j).getName(), knowlist.get(j).getInfo(), knowlist.get(j).getHour()); + knowIds.add(knowId); + if (knowId == null) { + throw new RuntimeException("添加知识点失败"); + } + //添加知识点关系 + f = knowRepository.addContainWithKnow(knowId, chapterIds.get(i)); + if (f <= 0) { + throw new RuntimeException("添加知识点-章节失败关系失败"); + } } } + } for (int i = 0; i < chapterList.size(); i++) { Chapter chapter = chapterList.get(i); - if(chapter.getPid()== 0){ - f = knowRepository.addFatherAndSonWithCourse(chapter.getCourseId(),chapter.getId()); - if(f <= 0) throw new RuntimeException("添加课程-章节关系失败"); - }else{ - f = knowRepository.addFatherAndSonWithChapter(chapter.getId(),chapter.getPid()); - if(f <= 0) throw new RuntimeException("添加章节-章节关系失败"); + if (chapter.getPid() == 0) { + f = knowRepository.addContainWithCourse(chapter.getCourseId(), chapter.getId()); + if (f <= 0) throw new RuntimeException("添加课程-章节关系失败"); + } else { + f = knowRepository.addContainWithChapter(chapter.getId(), chapter.getPid()); + if (f <= 0) throw new RuntimeException("添加章节-章节关系失败"); } } -// for (int j = 0; j < knowlist.size(); j++) { -// Knowtmp knowtmp = knowlist.get(j); -// f = knowRepository.addFatherAndSonWithKnow(knowtmp.getId(),knowtmp.getChapterid()); -// if(f <= 0) throw new RuntimeException("添加章节-知识点关系失败"); -// } - + //添加顺序关系 - } + //给章添加顺序关系 + for (int i = 0; i < chapterOneIds.size() - 1; i++) { + f = knowRepository.addOrderById(chapterOneIds.get(i), chapterOneIds.get(i + 1)); + if (f <= 0) throw new RuntimeException("添加章-章 顺序关系失败"); + } - @Override - public BaseResponse addKnow(KnowRequest knowRequest) { - Know know = new Know(); - BeanUtils.copyProperties(knowRequest,know); - Know know1 = knowRepository.addKnow(know.getName(),know.getInfo()); - if(know1 != null){ - return ResultUtils.success("添加知识点成功"); - }else{ - return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加知识点失败"); + //给节添加顺序关系 + for (int i = 0; i < chapterTwoIds.size() - 1; i++) { + f = knowRepository.addOrderById(chapterTwoIds.get(i), chapterTwoIds.get(i + 1)); + if (f <= 0) throw new RuntimeException("添加节-节 顺序关系失败"); + } + //给知识点添加顺序关系 + for (int i = 0; i < knowIds.size() - 1; i++) { + f = knowRepository.addOrderById(knowIds.get(i), knowIds.get(i + 1)); + if (f <= 0) throw new RuntimeException("添加知识点-知识点 顺序关系失败"); } } +// @Override +// public BaseResponse addKnow(KnowRequest knowRequest) { +// Know know = new Know(); +// BeanUtils.copyProperties(knowRequest,know); +// Long know1 = knowRepository.addKnow(know.getName(),know.getInfo()); +// if(know1 != null){ +// return ResultUtils.success("添加知识点成功"); +// }else{ +// return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加知识点失败"); +// } +// } + @Override public BaseResponse updateKnow(KnowUpdateRequest knowUpdateRequest) { Know know = new Know(); - BeanUtils.copyProperties(knowUpdateRequest,know); - int f = knowRepository.updateKnow(know.getId(),know.getName(),know.getInfo()); - if(f > 0){ + BeanUtils.copyProperties(knowUpdateRequest, know); + int f = knowRepository.updateKnow(know.getId(), know.getName(), know.getInfo()); + if (f > 0) { return ResultUtils.success("修改知识点成功"); - }else{ - return ResultUtils.error(ErrorCode.OPERATION_ERROR,"修改知识点失败"); + } else { + return ResultUtils.error(ErrorCode.OPERATION_ERROR, "修改知识点失败"); } } @@ -167,10 +642,10 @@ public class knowServiceImpl implements KnowService { public BaseResponse deleteKnow(Long id) { // todo 判断知识点存在否 int f = knowRepository.deleteKnow(id); - if(f > 0){ + if (f > 0) { return ResultUtils.success("删除知识点成功"); - }else{ - return ResultUtils.error(ErrorCode.OPERATION_ERROR,"删除知识点失败"); + } else { + return ResultUtils.error(ErrorCode.OPERATION_ERROR, "删除知识点失败"); } } @@ -186,24 +661,24 @@ public class knowServiceImpl implements KnowService { @Override public BaseResponse addCourse(KnowCourseCreateRequest knowCourseCreateRequest) { KnowCourse knowCourse = new KnowCourse(); - BeanUtils.copyProperties(knowCourseCreateRequest,knowCourse); - int f = knowRepository.addCourse(knowCourse.getCourseId(),knowCourse.getName(),knowCourse.getInfo(),knowCourse.getHour()); - if(f >0){ + BeanUtils.copyProperties(knowCourseCreateRequest, knowCourse); + Long knowCourse1 = knowRepository.addCourse(knowCourse.getCourseId(), knowCourse.getName(), knowCourse.getInfo(), knowCourse.getHour()); + if (knowCourse1 != null) { return ResultUtils.success("添加知识点成功"); - }else{ - return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加知识点失败"); + } else { + return ResultUtils.error(ErrorCode.OPERATION_ERROR, "添加知识点失败"); } } @Override public BaseResponse updateCourse(KnowCourseCreateRequest knowCourseCreateRequest) { KnowCourse knowCourse = new KnowCourse(); - BeanUtils.copyProperties(knowCourseCreateRequest,knowCourse); - int f = knowRepository.updateCourse(knowCourse.getCourseId(),knowCourse.getName(),knowCourse.getInfo()); - if(f > 0){ + BeanUtils.copyProperties(knowCourseCreateRequest, knowCourse); + int f = knowRepository.updateCourse(knowCourse.getCourseId(), knowCourse.getName(), knowCourse.getInfo()); + if (f > 0) { return ResultUtils.success("修改知识点成功"); - }else{ - return ResultUtils.error(ErrorCode.OPERATION_ERROR,"修改知识点失败"); + } else { + return ResultUtils.error(ErrorCode.OPERATION_ERROR, "修改知识点失败"); } } @@ -211,10 +686,10 @@ public class knowServiceImpl implements KnowService { public BaseResponse deleteCourse(String courseId) { int f = knowRepository.deleteCourse(courseId); - if(f > 0){ + if (f > 0) { return ResultUtils.success("删除知识点成功"); - }else{ - return ResultUtils.error(ErrorCode.OPERATION_ERROR,"删除知识点失败"); + } else { + return ResultUtils.error(ErrorCode.OPERATION_ERROR, "删除知识点失败"); } } @@ -227,44 +702,43 @@ public class knowServiceImpl implements KnowService { //========================= - @Override public BaseResponse addChapter(KnowChapterCreateRequest knowChapterCreateRequest) { KnowChapter knowChapter = new KnowChapter(); - BeanUtils.copyProperties(knowChapterCreateRequest,knowChapter); - int f = knowRepository.addChapter(knowChapter.getChapterId(),knowChapter.getName(),knowChapter.getInfo(),knowChapter.getHour()); - if(f>0){ + BeanUtils.copyProperties(knowChapterCreateRequest, knowChapter); + Long f = knowRepository.addChapter(knowChapter.getChapterId(), knowChapter.getName(), knowChapter.getInfo(), knowChapter.getHour()); + if (f > 0) { return ResultUtils.success("添加章节成功"); - }else{ - return ResultUtils.error(ErrorCode.OPERATION_ERROR,"添加章节失败"); + } else { + return ResultUtils.error(ErrorCode.OPERATION_ERROR, "添加章节失败"); } } @Override public BaseResponse updateChapter(KnowChapterCreateRequest knowChapterCreateRequest) { KnowChapter knowChapter = new KnowChapter(); - BeanUtils.copyProperties(knowChapterCreateRequest,knowChapter); - int f = knowRepository.updateChapter(knowChapter.getChapterId(),knowChapter.getName(),knowChapter.getInfo()); - if(f > 0){ + BeanUtils.copyProperties(knowChapterCreateRequest, knowChapter); + int f = knowRepository.updateChapter(knowChapter.getChapterId(), knowChapter.getName(), knowChapter.getInfo()); + if (f > 0) { return ResultUtils.success("修改知识点成功"); - }else{ - return ResultUtils.error(ErrorCode.OPERATION_ERROR,"修改知识点失败"); + } else { + return ResultUtils.error(ErrorCode.OPERATION_ERROR, "修改知识点失败"); } } @Override public BaseResponse deleteChapter(Long chapterId) { int f = knowRepository.deleteChapter(chapterId); - if(f > 0){ + if (f > 0) { return ResultUtils.success("删除知识点成功"); - }else{ - return ResultUtils.error(ErrorCode.OPERATION_ERROR,"删除知识点失败"); + } else { + return ResultUtils.error(ErrorCode.OPERATION_ERROR, "删除知识点失败"); } } @Override public BaseResponse queryChapter(Long chapterId) { - KnowChapter knowChapter = knowRepository.queryChapter(chapterId); + KnowChapter knowChapter = knowRepository.queryChapter(chapterId); return ResultUtils.success(knowChapter); } @@ -274,18 +748,18 @@ public class knowServiceImpl implements KnowService { @Override public BaseResponse getAllKnowByCourseId(String id) { Collection> all = - neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where n.courseId = '"+id+"' return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all(); + neo4jClient.query("match(n:Know)-[r:contain*0..4]->(p:Know) where n.courseId = '" + id + "' return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all(); - MapcolorChoose = new HashMap<>(); + Map colorChoose = new HashMap<>(); String color[] = new String[10]; String[] colorList = {"#91CC75", "#5470C6", "#FAC858", "#EE6666", "#73C0DE", "#EA7CCC", "#5577FF", "#5577FF", "#9DBFFF", "#78A7FF"}; for (int i = 0; i < 10; i++) { - colorChoose.put((long) i,colorList[i]); + colorChoose.put((long) i, colorList[i]); } Iterator> iterator = all.iterator(); Set knowList = new HashSet<>(); - SetlinksList = new HashSet<>(); + Set linksList = new HashSet<>(); KnowVO knowVO; List node2 = new ArrayList<>(); Links links; @@ -296,14 +770,73 @@ public class knowServiceImpl implements KnowService { Node node1 = (Node) element.get("p"); Long group = (Long) element.get("d"); - knowVO.setColor(colorChoose.get(group)); +// knowVO.setColor(colorChoose.get(group)); + if (node1 != null) { + Long id1 = node1.id(); + String name1 = node1.get("name").asString(); + knowVO.setId(id1); + knowVO.setLabel(name1); + knowList.add(knowVO); + knowVO.setColor(colorChoose.get(group)); + + } + + node2 = (List) element.get("r"); + if (!node2.isEmpty()) { + for (int i = 0; i < node2.size(); i++) { + InternalRelationship e = (InternalRelationship) node2.get(i); + links = new Links(); + links.setId(e.id()); + links.setSource(e.startNodeId()); + links.setTarget(e.endNodeId()); + if ("contain".equals(e.type())) { + links.setLabel("包含"); + } else if ("order".equals(e.type())) { + links.setLabel("顺序"); + } + linksList.add(links); + } + } + + } + + BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList, linksList); + return ResultUtils.success(baseKnowReturn); + } + + @Override + public BaseResponse getsecondKnowsById(Long id) { + Collection> all = + neo4jClient.query("match(n:Know)-[r*0..2]->(p:Know) where ID(n) = " + id + " return n as `n`,r as `r`,p as `p`,length(r) as `d`").fetch().all(); + + Map colorChoose = new HashMap<>(); + String color[] = new String[10]; + String[] colorList = {"#91CC75", "#5470C6", "#FAC858", "#EE6666", "#73C0DE", "#EA7CCC", "#5577FF", "#5577FF", "#9DBFFF", "#78A7FF"}; + for (int i = 0; i < 10; i++) { + colorChoose.put((long) i, colorList[i]); + } + + Iterator> iterator = all.iterator(); + Set knowList = new HashSet<>(); + Set linksList = new HashSet<>(); + KnowVO knowVO; + List node2 = new ArrayList<>(); + Links links; + int p = 0; + while (iterator.hasNext()) { + Map element = iterator.next(); + knowVO = new KnowVO(); + Node node1 = (Node) element.get("p"); + + Long group = (Long) element.get("d"); Long id1 = node1.id(); + String name1 = node1.get("name").asString(); knowVO.setId(id1); knowVO.setLabel(name1); + knowVO.setColor(colorChoose.get(group)); - knowList.add(knowVO); node2 = (List) element.get("r"); for (int i = 0; i < node2.size(); i++) { @@ -312,13 +845,18 @@ public class knowServiceImpl implements KnowService { links.setId(e.id()); links.setSource(e.startNodeId()); links.setTarget(e.endNodeId()); - links.setLabel(e.type()); + if ("contain".equals(e.type())) { + links.setLabel("包含"); + } else if ("order".equals(e.type())) { + links.setLabel("顺序"); + } linksList.add(links); } } - BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList,linksList); + + BaseKnowReturn baseKnowReturn = new BaseKnowReturn(knowList, linksList); return ResultUtils.success(baseKnowReturn); } @@ -326,7 +864,7 @@ public class knowServiceImpl implements KnowService { @Override public BaseResponse> getAllResourcesByCourseId(String id) { Collection> all = - neo4jClient.query( "match(n:Know)-[r*0..]->(p:Know) where n.courseId = '"+id+"' return p as `p`").fetch().all(); + neo4jClient.query("match(n:Know)-[r*0..]->(p:Know) where n.courseId = '" + id + "' return p as `p`").fetch().all(); Iterator> iterator = all.iterator(); Set knowList = new HashSet<>(); KnowVO1 knowVO; @@ -344,5 +882,4 @@ public class knowServiceImpl implements KnowService { } - } diff --git a/src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java index ab78ee0..968c903 100644 --- a/src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/knowtmp/KnowtmpServiceImpl.java @@ -5,8 +5,10 @@ import com.teaching.backend.common.BaseResponse; import com.teaching.backend.common.ErrorCode; import com.teaching.backend.common.ResultUtils; import com.teaching.backend.mapper.Knowtemp.KnowtmpMapper; +import com.teaching.backend.mapper.chapter.ChapterMapper; import com.teaching.backend.model.dto.Knowtmp.KnowtempAdd; import com.teaching.backend.model.dto.Knowtmp.KnowtempUpdate; +import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.entity.knowtmp.Knowtmp; import com.teaching.backend.service.knowtmp.KnowtmpService; import org.checkerframework.checker.units.qual.A; @@ -14,6 +16,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; /** @@ -24,9 +27,24 @@ import java.util.List; @Service public class KnowtmpServiceImpl implements KnowtmpService { + @Autowired + private ChapterMapper chapterMapper; + + @Autowired private KnowtmpMapper knowtmpMapper; + @Override + public BaseResponse getAllKnows(String courseId) { + // 3 从章节表查出章节节点 并添加到 neo + List chapterIds = chapterMapper.selectChapterIdsByCourseId(courseId); + //获取chapterId 查询知识点 返回知识点集合 + QueryWrapper objectQueryWrapper = new QueryWrapper<>(); + objectQueryWrapper.in("chapterid",chapterIds); + Long count = knowtmpMapper.selectCount(objectQueryWrapper); + return ResultUtils.success(count); + } + @Override public BaseResponse add(KnowtempAdd knowtempAdd) { Knowtmp knowtmp = new Knowtmp(); @@ -70,10 +88,7 @@ public class KnowtmpServiceImpl implements KnowtmpService { @Override public List queryByChapterId(Long chapterId) { - Knowtmp knowtmp = new Knowtmp(); - QueryWrapper knowtmpQueryWrapper = new QueryWrapper<>(); - knowtmpQueryWrapper.eq("chapterId",chapterId); - List knowtmps = knowtmpMapper.selectList(knowtmpQueryWrapper); + List knowtmps = knowtmpMapper.queryIdByChapterId(chapterId); return knowtmps; } diff --git a/src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java index 53378a0..a8708af 100644 --- a/src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/resource/ResourceServiceImpl.java @@ -164,6 +164,13 @@ public class ResourceServiceImpl implements ResourceService { return ResultUtils.success(resourcesSet); } + @Override + public BaseResponse> queryResourcesByKnowId(Long KnowId) { + // todo 判空,查询 + SetresourcesSet ; + resourcesSet = resourcesRepository.queryResourcesByKnowId(KnowId); + return ResultUtils.success(resourcesSet); + } } diff --git a/src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java b/src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java index e8ab344..3468a16 100644 --- a/src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java +++ b/src/main/java/com/teaching/backend/service/knowtmp/KnowtmpService.java @@ -13,6 +13,10 @@ import java.util.List; * @Description: */ public interface KnowtmpService { + //查询 + BaseResponse getAllKnows(String courseId); + + // 添加知识点 BaseResponse add(KnowtempAdd knowtempAdd); diff --git a/src/main/java/com/teaching/backend/service/resource/ResourceService.java b/src/main/java/com/teaching/backend/service/resource/ResourceService.java index d44a7ba..570a74e 100644 --- a/src/main/java/com/teaching/backend/service/resource/ResourceService.java +++ b/src/main/java/com/teaching/backend/service/resource/ResourceService.java @@ -40,5 +40,7 @@ public interface ResourceService { //查询二级节点下资源 BaseResponse> queryBesidesKnowToResources(Long KnowId); + BaseResponse> queryResourcesByKnowId(Long KnowId); + }