From c1da086cb0e816d8c87303689554ff766e982e57 Mon Sep 17 00:00:00 2001 From: Alan <3052806735@qq.com> Date: Fri, 26 Jul 2024 16:44:39 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/courses/CoursesController.java | 2 +- .../backend/model/query/CourseQuery.java | 4 +-- .../impl/courses/CoursesServiceImpl.java | 33 ++++++++++--------- .../courses/StudentCoursesServiceImpl.java | 6 ++-- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java index 28fa366..4768bd4 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -66,7 +66,7 @@ public class CoursesController { @ApiOperation("查询课程列表") - @ValidateParams({"username"}) + @ValidateParams({"userId"}) @GetMapping("/page") // @PostMapping("/page") public BaseResponse> getCourses(CourseQuery courseQuery){ diff --git a/src/main/java/com/teaching/backend/model/query/CourseQuery.java b/src/main/java/com/teaching/backend/model/query/CourseQuery.java index a8901a3..b8d1e73 100644 --- a/src/main/java/com/teaching/backend/model/query/CourseQuery.java +++ b/src/main/java/com/teaching/backend/model/query/CourseQuery.java @@ -15,8 +15,8 @@ public class CourseQuery extends PageQuery { @ApiModelProperty("课程名称关键字") private String name; - @ApiModelProperty(value = "用户的username",required = true) - private String username; + @ApiModelProperty(value = "用户的userId",required = true) + private String userId; // @ApiModelProperty(value = "用户的角色id",required = true) // private List roleId; 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 07efd11..ebc2af3 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 @@ -140,10 +140,14 @@ public class CoursesServiceImpl extends ServiceImpl impl @Override public PageDTO queryCourses(CourseQuery courseQuery) { - int roleId = Integer.parseInt(umsUserMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsUser::getUsername, courseQuery.getUsername())).getRoleId()); +// int roleId = Integer.parseInt(umsUserMapper.selectOne(new LambdaQueryWrapper() +// .eq(UmsUser::getUsername, courseQuery.getUsername())).getRoleId()); + UmsUser umsUser = umsUserMapper.selectById(courseQuery.getUserId()); + if (umsUser == null){ + throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); + } + int roleId = Integer.parseInt(umsUser.getRoleId()); PageDTO coursesVOPageDTO; - switch (roleId) { //教师--也是管理员--但是只能看自己的课程,有搜索功能 case 1: @@ -168,7 +172,7 @@ public class CoursesServiceImpl extends ServiceImpl impl Page page = courseQuery.toMpPageDefaultSortByCreateTime(); Page p = lambdaQuery() .like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) - .apply("FIND_IN_SET({0}, teacher)", courseQuery.getUsername()) + .apply("FIND_IN_SET({0}, teacher)", courseQuery.getUserId()) .eq(courseQuery.getCategory() != null && !courseQuery.getCategory().isEmpty(), Courses::getCategory, courseQuery.getCategory()) .eq(courseQuery.getNature() != null && !courseQuery.getNature().isEmpty(), Courses::getNature, courseQuery.getNature()) .eq(courseQuery.getAssessmenttype() != null &&!courseQuery.getAssessmenttype().isEmpty(), Courses::getAssessmenttype, courseQuery.getAssessmenttype()) @@ -178,11 +182,10 @@ public class CoursesServiceImpl extends ServiceImpl impl private PageDTO queryForStudent(CourseQuery courseQuery) { List studentCourses = studentCoursesMapper.selectList(new LambdaQueryWrapper() - .eq(StudentCourses::getStudent, courseQuery.getUsername())); + .eq(StudentCourses::getStudent, courseQuery.getUserId())); List coursesList = studentCourses.stream() .map(StudentCourses::getCourse) .collect(Collectors.toList()); - Page page = courseQuery.toMpPageDefaultSortByCreateTime(); Page p = lambdaQuery() .like(courseQuery.getName() != null, Courses::getName, courseQuery.getName()) @@ -190,7 +193,6 @@ public class CoursesServiceImpl extends ServiceImpl impl .page(page); return PageDTO.of(p, CoursesVO.class); } - private PageDTO queryForAdmin(CourseQuery courseQuery) { Page page = courseQuery.toMpPageDefaultSortByCreateTime(); Page p = lambdaQuery() @@ -206,17 +208,16 @@ public class CoursesServiceImpl extends ServiceImpl impl private void populateTeacherNames(List courseList) { for (CoursesVO coursesVO : courseList) { List teacherNameList = new ArrayList<>(); - String[] teacherIds = coursesVO.getTeacher().split(","); - for (String teacherId : teacherIds) { - UmsUser umsUserTea = umsUserMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsUser::getUsername, teacherId)); - if (umsUserTea == null) { - throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); - } + String[] teacherUserIds = coursesVO.getTeacher().split(","); + for (String teacherId : teacherUserIds) { +// UmsUser umsUserTea = umsUserMapper.selectOne(new LambdaQueryWrapper() +// .eq(UmsUser::getUsername, teacherId)); +// if (umsUserTea == null) { +// throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); +// } // System.out.println(umsAdminTea); UmsTeacher umsTeacher = umsTeacherMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsTeacher::getUserId, umsUserTea.getId())); -// System.out.println(umsTeacher); + .eq(UmsTeacher::getUserId,teacherId)); if (umsTeacher == null){ throw new BusinessException(ErrorCode.PARAMS_USER_NOTEXISTS); } diff --git a/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java index 7b83c8a..4a92433 100644 --- a/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java @@ -84,12 +84,12 @@ public class StudentCoursesServiceImpl extends ServiceImpl queryCourses(CourseQuery courseQuery) { - String username = courseQuery.getUsername(); - if (username == null || username.equals("")) { + String userId = courseQuery.getUserId(); + if (userId == null || userId.equals("")) { throw new BusinessException(ErrorCode.STUDENT_NOT_EXIT); } List studentCourses = studentCoursesMapper.selectList(new LambdaQueryWrapper() - .eq(StudentCourses::getStudent, username)); + .eq(StudentCourses::getStudent, userId)); List coursesList = studentCourses.stream() .map(StudentCourses::getCourse) .collect(Collectors.toList()); From 7437cf33efac561c8ec2e0fc5811ade0aea917a4 Mon Sep 17 00:00:00 2001 From: wenyu441069198 <14186472+wenyu441069198@user.noreply.gitee.com> Date: Fri, 26 Jul 2024 17:23:27 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E8=82=96=E6=B5=B7=E5=8D=97=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E6=95=B0=E6=8D=AE=E3=80=81=E5=AD=A6=E7=94=9F=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 9 ++- .../controller/courses/CoursesController.java | 12 +++ .../controller/umsAdmin/ReportController.java | 47 ++++++++++++ .../umsAdmin/UmsUserController.java | 27 ++++--- .../umsStudent/UmsStudentController.java | 13 ++++ .../mapper/courses/StudentCoursesMapper.java | 3 + .../backend/mapper/report/ReportMapper.java | 14 ++++ .../mapper/umsAdmin/UmsUserMapper.java | 2 + .../backend/model/dto/report/ReportDTO.java | 21 ++++++ .../dto/umsAdmin/UmsStudentAndTeacherDTO.java | 2 +- .../backend/model/entity/report/Report.java | 24 ++++++ .../model/vo/report/BrowseReportVO.java | 20 +++++ .../service/courses/ICoursesService.java | 5 ++ .../impl/courses/CoursesServiceImpl.java | 21 ++++++ .../impl/report/ReportServiceImpl.java | 73 +++++++++++++++++++ .../umsAdmin}/UmsRoleServiceImpl.java | 3 +- .../umsAdmin}/UmsUserServiceImpl.java | 2 +- .../backend/service/report/ReportService.java | 21 ++++++ src/main/resources/mapper/ReportMapper.xml | 18 +++++ .../resources/mapper/StudentCoursesMapper.xml | 8 ++ src/main/resources/mapper/UmsUserMapper.xml | 1 + 21 files changed, 326 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java create mode 100644 src/main/java/com/teaching/backend/controller/umsStudent/UmsStudentController.java create mode 100644 src/main/java/com/teaching/backend/mapper/report/ReportMapper.java create mode 100644 src/main/java/com/teaching/backend/model/dto/report/ReportDTO.java create mode 100644 src/main/java/com/teaching/backend/model/entity/report/Report.java create mode 100644 src/main/java/com/teaching/backend/model/vo/report/BrowseReportVO.java create mode 100644 src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java rename src/main/java/com/teaching/backend/service/{umsAdmin/impl => impl/umsAdmin}/UmsRoleServiceImpl.java (95%) rename src/main/java/com/teaching/backend/service/{umsAdmin/impl => impl/umsAdmin}/UmsUserServiceImpl.java (99%) create mode 100644 src/main/java/com/teaching/backend/service/report/ReportService.java create mode 100644 src/main/resources/mapper/ReportMapper.xml diff --git a/pom.xml b/pom.xml index 4e0f3ce..af309d8 100644 --- a/pom.xml +++ b/pom.xml @@ -117,10 +117,6 @@ 4.4.0 - - org.apache.commons - commons-lang3 - cn.hutool hutool-all @@ -206,6 +202,11 @@ redisson 3.13.6 + + commons-lang + commons-lang + 2.6 + diff --git a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java index 4768bd4..ca4298d 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -2,6 +2,7 @@ package com.teaching.backend.controller.courses; import com.teaching.backend.common.BaseResponse; +import com.teaching.backend.common.CommonResult; import com.teaching.backend.common.ErrorCode; import com.teaching.backend.common.ResultUtils; import com.teaching.backend.exception.BusinessException; @@ -11,8 +12,10 @@ import com.teaching.backend.model.dto.courses.CoursesDTO; import com.teaching.backend.model.dto.courses.PageDTO; import com.teaching.backend.model.entity.courses.Courses; +import com.teaching.backend.model.entity.umsAdmin.UmsStudent; import com.teaching.backend.model.query.CourseQuery; import com.teaching.backend.model.vo.courses.CoursesVO; +import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO; import com.teaching.backend.service.courses.ICoursesService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -120,4 +123,13 @@ public class CoursesController { String id = "de3100cad98f76be3176dd39aa748a9e"; coursesService.down(response, id); } + + @ApiOperation("查询学生列表") +// @ValidateParams({"username"}) + @PostMapping("/studentList") + public CommonResult> getStudentList(CourseQuery courseQuery){ + HashSet umsStudentList = coursesService.queryStudentList(courseQuery); + return CommonResult.success(umsStudentList); + } + } diff --git a/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java b/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java new file mode 100644 index 0000000..99a7d8c --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/umsAdmin/ReportController.java @@ -0,0 +1,47 @@ +package com.teaching.backend.controller.umsAdmin; + +import com.teaching.backend.common.CommonResult; +import com.teaching.backend.model.dto.report.ReportDTO; +import com.teaching.backend.model.vo.report.BrowseReportVO; +import com.teaching.backend.service.report.ReportService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@Api(tags = "ReportController") +@RequestMapping("/api/report") +@Slf4j +public class ReportController { + + @Autowired + private ReportService reportService; + + /** + * 浏览统计 + * @return + */ + @GetMapping("/browseStatistics") + @ApiOperation("浏览统计") + public CommonResult browseStatistics(){ + return CommonResult.success(reportService.getBrowseStatistics()); + } + + /** + * 接收每日浏览量 + * @return + */ + @PostMapping("/receptionBrowse") + @ApiOperation("接收每日浏览量") + public CommonResult receptionBrowse(@RequestBody ReportDTO reportDTO){ + + boolean receptionBrowse = reportService.getReceptionBrowse(reportDTO); + if (receptionBrowse == false){ + return CommonResult.failed(); + } + return CommonResult.success(receptionBrowse); + } + +} diff --git a/src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java b/src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java index 7a46257..530f25f 100644 --- a/src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java +++ b/src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java @@ -30,7 +30,7 @@ import java.util.Map; * @Description:login */ @RestController -@Api(tags = "UmsAdminController") +@Api(tags = "UmsUserController") @RequestMapping("/api/user") @Slf4j public class UmsUserController { @@ -145,17 +145,6 @@ public class UmsUserController { return CommonResult.failed(); } - @ApiOperation("修改指定用户密码") - @PostMapping("/updatePassword") - public CommonResult updatePassword(@Validated @RequestBody UpdateUserPasswordParam updatePasswordParam) { - int status = umsUserService.updatePassword(updatePasswordParam); - if (status == 1) { - return CommonResult.success(status); - } else { - return CommonResult.failed(); - } - } - @ApiOperation("获取指定个人信息") @PostMapping("/personal/info") public CommonResult getByIdPersonalInfo(@RequestParam String id) { @@ -179,6 +168,19 @@ public class UmsUserController { return CommonResult.failed(); } + @ApiOperation("修改指定用户密码") + @PostMapping("/updatePassword") + public CommonResult updatePassword(@Validated @RequestBody UpdateUserPasswordParam updatePasswordParam) { + int status = umsUserService.updatePassword(updatePasswordParam); + if (status == 1) { + return CommonResult.success(status); + } else { + return CommonResult.failed(); + } + } + + + @ApiOperation("获取教师信息列表,关联教师的username和name") @GetMapping("/get_teacherinf_list") public BaseResponse> getTeacherInfList(){ @@ -186,4 +188,5 @@ public class UmsUserController { return ResultUtils.success(teacherInfVO); } + } diff --git a/src/main/java/com/teaching/backend/controller/umsStudent/UmsStudentController.java b/src/main/java/com/teaching/backend/controller/umsStudent/UmsStudentController.java new file mode 100644 index 0000000..a2db786 --- /dev/null +++ b/src/main/java/com/teaching/backend/controller/umsStudent/UmsStudentController.java @@ -0,0 +1,13 @@ +package com.teaching.backend.controller.umsStudent; + +import io.swagger.annotations.Api; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@Api(tags = "UmsStudentController") +@RequestMapping("/api/student") +@Slf4j +public class UmsStudentController { +} diff --git a/src/main/java/com/teaching/backend/mapper/courses/StudentCoursesMapper.java b/src/main/java/com/teaching/backend/mapper/courses/StudentCoursesMapper.java index b6042f9..8a57f24 100644 --- a/src/main/java/com/teaching/backend/mapper/courses/StudentCoursesMapper.java +++ b/src/main/java/com/teaching/backend/mapper/courses/StudentCoursesMapper.java @@ -17,4 +17,7 @@ import java.util.List; public interface StudentCoursesMapper extends BaseMapper { void insertBatchSomeColumn(List studentCoursesList); + + + List selectBatchSomeStudent(String courseId); } diff --git a/src/main/java/com/teaching/backend/mapper/report/ReportMapper.java b/src/main/java/com/teaching/backend/mapper/report/ReportMapper.java new file mode 100644 index 0000000..6da6396 --- /dev/null +++ b/src/main/java/com/teaching/backend/mapper/report/ReportMapper.java @@ -0,0 +1,14 @@ +package com.teaching.backend.mapper.report; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.teaching.backend.model.dto.report.ReportDTO; +import com.teaching.backend.model.entity.report.Report; + +import java.time.LocalDate; + +public interface ReportMapper extends BaseMapper { + + String getBrowseByTime(LocalDate day); + + boolean addTodayBrowse(ReportDTO reportDTO); +} 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 c1d1a74..ca18264 100644 --- a/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsUserMapper.java +++ b/src/main/java/com/teaching/backend/mapper/umsAdmin/UmsUserMapper.java @@ -1,6 +1,7 @@ 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; @@ -17,4 +18,5 @@ public interface UmsUserMapper extends BaseMapper { UmsTeacher getByIdTeacher(String id); UmsStudentVO getByIdStudent(String id); + } diff --git a/src/main/java/com/teaching/backend/model/dto/report/ReportDTO.java b/src/main/java/com/teaching/backend/model/dto/report/ReportDTO.java new file mode 100644 index 0000000..26bb311 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/dto/report/ReportDTO.java @@ -0,0 +1,21 @@ +package com.teaching.backend.model.dto.report; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDate; + +@Data +@TableName("report") +public class ReportDTO implements Serializable { + + //时间 + private LocalDate createTime; + + //浏览量 + private String pageView; + +} 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 4d8d3b5..42011e6 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 @@ -117,7 +117,7 @@ public class UmsStudentAndTeacherDTO implements Serializable { /** * user_id */ - private Integer userId; + private Long userId; /** * role_id diff --git a/src/main/java/com/teaching/backend/model/entity/report/Report.java b/src/main/java/com/teaching/backend/model/entity/report/Report.java new file mode 100644 index 0000000..83b4272 --- /dev/null +++ b/src/main/java/com/teaching/backend/model/entity/report/Report.java @@ -0,0 +1,24 @@ +package com.teaching.backend.model.entity.report; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDate; + +@Data +@TableName("report") +public class Report implements Serializable { + //主键 + @TableId(type = IdType.AUTO) + private Long id; + + //时间 + private LocalDate createTime; + + //浏览量 + private String pageView; + +} diff --git a/src/main/java/com/teaching/backend/model/vo/report/BrowseReportVO.java b/src/main/java/com/teaching/backend/model/vo/report/BrowseReportVO.java new file mode 100644 index 0000000..202690a --- /dev/null +++ b/src/main/java/com/teaching/backend/model/vo/report/BrowseReportVO.java @@ -0,0 +1,20 @@ +package com.teaching.backend.model.vo.report; + +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +@Data +@Builder +public class BrowseReportVO implements Serializable { + + //日期,以逗号分隔,例如:2022-10-01,2022-10-02,2022-10-03 + private String dateList; + + //本月浏览量,以逗号分隔,例如:200,210,220 + private String ThisMonthBrowseList; + + //上月浏览量,以逗号分隔,例如:20,21,10 + private String LastMonthBrowseList; +} 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 7d3014b..11156c8 100644 --- a/src/main/java/com/teaching/backend/service/courses/ICoursesService.java +++ b/src/main/java/com/teaching/backend/service/courses/ICoursesService.java @@ -5,10 +5,13 @@ 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.entity.courses.Courses; +import com.teaching.backend.model.entity.umsAdmin.UmsStudent; import com.teaching.backend.model.query.CourseQuery; import com.teaching.backend.model.vo.courses.CoursesVO; +import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO; import javax.servlet.http.HttpServletResponse; +import java.util.HashSet; import java.util.List; import java.util.Map; @@ -41,4 +44,6 @@ public interface ICoursesService extends IService { CoursesVO getByIdCourseVo(String courseid); Map getPagePageSize2(int page, int pageSize); + + HashSet queryStudentList(CourseQuery courseQuery); } 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 ebc2af3..3e9b28a 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 @@ -13,6 +13,7 @@ import com.teaching.backend.exception.BusinessException; import com.teaching.backend.mapper.chapter.ChapterMapper; import com.teaching.backend.mapper.courses.*; import com.teaching.backend.mapper.records.LearningRecordsMapper; +import com.teaching.backend.mapper.umsAdmin.UmsStudentMapper; import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper; import com.teaching.backend.mapper.umsAdmin.UmsUserMapper; import com.teaching.backend.model.dto.courses.CoursesDTO; @@ -20,11 +21,13 @@ import com.teaching.backend.model.dto.courses.PageDTO; import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.entity.courses.*; import com.teaching.backend.model.entity.records.LearningRecords; +import com.teaching.backend.model.entity.umsAdmin.UmsStudent; import com.teaching.backend.model.entity.umsAdmin.UmsTeacher; import com.teaching.backend.model.entity.umsAdmin.UmsUser; import com.teaching.backend.model.query.CourseQuery; import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO; import com.teaching.backend.model.vo.courses.CoursesVO; +import com.teaching.backend.model.vo.umsAdmin.UmsStudentVO; import com.teaching.backend.service.courses.ICoursesService; import com.teaching.backend.utils.CourseCode; import org.apache.poi.xwpf.usermodel.*; @@ -75,6 +78,8 @@ public class CoursesServiceImpl extends ServiceImpl impl @Autowired UmsTeacherMapper umsTeacherMapper; @Autowired + UmsStudentMapper umsStudentMapper; + @Autowired StudentCoursesMapper studentCoursesMapper; @Autowired ObjectiveContentKnowMapper objectiveContentKnowMapper; @@ -327,6 +332,22 @@ public class CoursesServiceImpl extends ServiceImpl impl } + @Override + public HashSet queryStudentList(CourseQuery courseQuery) { + PageDTO queryCourses = queryCourses(courseQuery); + List coursesList = queryCourses.getList(); + List courseIds = coursesList.stream().map(CoursesVO::getId).collect(Collectors.toList()); + HashSet studentNameList = new HashSet<>(); + for (String courseId : courseIds) { + List studentUsernames = studentCoursesMapper.selectBatchSomeStudent(courseId); + for (StudentCourses studentUsername : studentUsernames) { + UmsStudent umsStudent = umsStudentMapper.selectByUserId(Integer.valueOf(studentUsername.getStudent())); + studentNameList.add(umsStudent); + } + } + return studentNameList; + } + @Override public List getPagePageSize(int page, int pageSize) { int startIndex = (page-1) * pageSize; diff --git a/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java new file mode 100644 index 0000000..3cabf56 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/impl/report/ReportServiceImpl.java @@ -0,0 +1,73 @@ +package com.teaching.backend.service.impl.report; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.teaching.backend.mapper.report.ReportMapper; +import com.teaching.backend.model.dto.report.ReportDTO; +import com.teaching.backend.model.entity.report.Report; +import com.teaching.backend.model.vo.report.BrowseReportVO; +import com.teaching.backend.service.report.ReportService; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +@Service +@Slf4j +public class ReportServiceImpl extends ServiceImpl implements ReportService { + + @Autowired + private ReportMapper reportMapper; + + @Override + public BrowseReportVO getBrowseStatistics() { + //存放访问的前一天至前七天的每天对应的日期 + List dateList = new ArrayList<>(); + //存放这个月访问的前一天至前七天的每天对应的浏览量 + List ThisMonthBrowseList = new ArrayList<>(); + //存放上个月访问的前一天至前七天的每天对应的浏览量 + List LastMonthBrowseList = new ArrayList<>(); + + //获取今天的日期 + LocalDate end = LocalDate.now(); + + // 获取前七天的日期 + for (int i = 1; i <= 7; i++) { + LocalDate day = end.minusDays(i); + dateList.add(day); + + //查询今天对应的浏览量 + String browse = reportMapper.getBrowseByTime(day); + ThisMonthBrowseList.add(browse); + + //获取上个月的今天 + LocalDate lastMonthToday = end.minusMonths(1); + LocalDate lastMonth = lastMonthToday.minusDays(i); + //查询上个月的今天对应的浏览量 + String lastMonthBrowse = reportMapper.getBrowseByTime(lastMonth); + LastMonthBrowseList.add(lastMonthBrowse); + + } + return BrowseReportVO + .builder() + .dateList(StringUtils.join(dateList,",")) + .ThisMonthBrowseList(StringUtils.join(ThisMonthBrowseList,",")) + .LastMonthBrowseList(StringUtils.join(LastMonthBrowseList,",")) + .build(); + } + + @Override + public boolean getReceptionBrowse(ReportDTO reportDTO) { + if (reportDTO.getCreateTime() == null || reportDTO.getPageView() == null){ + return false; + } + boolean todayBrowse = reportMapper.addTodayBrowse(reportDTO); + if (todayBrowse == false){ + return false; + } + return true; + } + +} diff --git a/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsRoleServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsRoleServiceImpl.java similarity index 95% rename from src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsRoleServiceImpl.java rename to src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsRoleServiceImpl.java index 8b65d65..e1209d5 100644 --- a/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsRoleServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsRoleServiceImpl.java @@ -1,4 +1,4 @@ -package com.teaching.backend.service.umsAdmin.impl; +package com.teaching.backend.service.impl.umsAdmin; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.teaching.backend.mapper.umsAdmin.UmsPermissionMapper; @@ -10,7 +10,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.*; -import java.util.stream.Collectors; /** diff --git a/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsUserServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsUserServiceImpl.java similarity index 99% rename from src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsUserServiceImpl.java rename to src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsUserServiceImpl.java index 410378a..8d715d4 100644 --- a/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsUserServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/umsAdmin/UmsUserServiceImpl.java @@ -1,4 +1,4 @@ -package com.teaching.backend.service.umsAdmin.impl; +package com.teaching.backend.service.impl.umsAdmin; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; diff --git a/src/main/java/com/teaching/backend/service/report/ReportService.java b/src/main/java/com/teaching/backend/service/report/ReportService.java new file mode 100644 index 0000000..5fbe678 --- /dev/null +++ b/src/main/java/com/teaching/backend/service/report/ReportService.java @@ -0,0 +1,21 @@ +package com.teaching.backend.service.report; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.teaching.backend.model.dto.report.ReportDTO; +import com.teaching.backend.model.entity.report.Report; +import com.teaching.backend.model.vo.report.BrowseReportVO; + +public interface ReportService extends IService { + + /** + * 浏览统计 + * @return + */ + BrowseReportVO getBrowseStatistics(); + + /** + * 接收每日浏览量 + * @return + */ + boolean getReceptionBrowse(ReportDTO reportDTO); +} diff --git a/src/main/resources/mapper/ReportMapper.xml b/src/main/resources/mapper/ReportMapper.xml new file mode 100644 index 0000000..163d2d2 --- /dev/null +++ b/src/main/resources/mapper/ReportMapper.xml @@ -0,0 +1,18 @@ + + + + + INSERT INTO report (create_time, page_view) + VALUES + (#{createTime}, #{pageView}) + + + + diff --git a/src/main/resources/mapper/StudentCoursesMapper.xml b/src/main/resources/mapper/StudentCoursesMapper.xml index dfd2bba..cf56d3f 100644 --- a/src/main/resources/mapper/StudentCoursesMapper.xml +++ b/src/main/resources/mapper/StudentCoursesMapper.xml @@ -9,4 +9,12 @@ (#{item.student}, #{item.course}) + diff --git a/src/main/resources/mapper/UmsUserMapper.xml b/src/main/resources/mapper/UmsUserMapper.xml index 3b5dd71..7c422c1 100644 --- a/src/main/resources/mapper/UmsUserMapper.xml +++ b/src/main/resources/mapper/UmsUserMapper.xml @@ -76,4 +76,5 @@ WHERE s.user_id = #{id} + From 5c998392963fb5f3e5b9fc02a95f6334ec8ae4bd Mon Sep 17 00:00:00 2001 From: Alan <3052806735@qq.com> Date: Fri, 26 Jul 2024 17:30:30 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=99=E5=B8=88?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=A7=92=E8=89=B2=E9=9D=99=E6=80=81=E5=B8=B8?= =?UTF-8?q?=E9=87=8F=E7=B1=BBRoleConstants?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/constant/RoleConstants.java | 7 +++++++ .../controller/umsAdmin/UmsUserController.java | 2 +- .../backend/model/vo/courses/TeacherInfVO.java | 4 ++-- .../impl/courses/CoursesServiceImpl.java | 2 ++ .../umsAdmin/impl/UmsUserServiceImpl.java | 17 +++++++++-------- 5 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/teaching/backend/constant/RoleConstants.java diff --git a/src/main/java/com/teaching/backend/constant/RoleConstants.java b/src/main/java/com/teaching/backend/constant/RoleConstants.java new file mode 100644 index 0000000..4e393bc --- /dev/null +++ b/src/main/java/com/teaching/backend/constant/RoleConstants.java @@ -0,0 +1,7 @@ +package com.teaching.backend.constant; + +public class RoleConstants { + public static final Long TEACHER_ROLE = 1L; + public static final Long STUDENT_ROLE = 2L; + public static final Long ADMIN_ROLE = 3L; +} diff --git a/src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java b/src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java index 7a46257..0db9cb4 100644 --- a/src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java +++ b/src/main/java/com/teaching/backend/controller/umsAdmin/UmsUserController.java @@ -179,7 +179,7 @@ public class UmsUserController { return CommonResult.failed(); } - @ApiOperation("获取教师信息列表,关联教师的username和name") + @ApiOperation("获取教师信息列表,关联教师的userId和name") @GetMapping("/get_teacherinf_list") public BaseResponse> getTeacherInfList(){ List teacherInfVO = umsUserService.getTeacherInfList(); diff --git a/src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java b/src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java index 66a317e..a99a24f 100644 --- a/src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java +++ b/src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java @@ -12,8 +12,8 @@ public class TeacherInfVO { /** * 教师username */ - @ApiModelProperty("教师username") - private String username; + @ApiModelProperty("教师userId") + private 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 ebc2af3..7dfebdb 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 @@ -42,6 +42,8 @@ import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; +import static com.teaching.backend.constant.RoleConstants.TEACHER_ROLE; + /** *

* 服务实现类 diff --git a/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsUserServiceImpl.java b/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsUserServiceImpl.java index 410378a..2c496f8 100644 --- a/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsUserServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/umsAdmin/impl/UmsUserServiceImpl.java @@ -42,6 +42,8 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; +import static com.teaching.backend.constant.RoleConstants.TEACHER_ROLE; + @Service @Slf4j public class UmsUserServiceImpl extends ServiceImpl implements UmsUserService { @@ -377,18 +379,17 @@ public class UmsUserServiceImpl extends ServiceImpl impl } throw new UsernameNotFoundException("用户名或密码错误"); } - @Override public List getTeacherInfList() { - List umsTeachers = umsTeacherMapper.selectList(new LambdaQueryWrapper()); + List umsUserTeachers = query().eq("role_id", TEACHER_ROLE).list(); TeacherInfVO teacherInfVO = null; - List teacherInfList = new ArrayList<>();; - for (UmsTeacher umsTeacher : umsTeachers) { + List teacherInfList = new ArrayList<>(); + for (UmsUser umsUserTeacher : umsUserTeachers) { teacherInfVO = new TeacherInfVO(); - UmsUser umsUser = umsUserMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsUser::getId, umsTeacher.getUserId())); - teacherInfVO.setName(umsTeacher.getName()); - teacherInfVO.setUsername(umsUser.getUsername()); + String teacherName = umsTeacherMapper.selectOne(new LambdaQueryWrapper<>(UmsTeacher.class) + .eq(UmsTeacher::getUserId, umsUserTeacher.getId())).getName(); + teacherInfVO.setName(teacherName); + teacherInfVO.setUserId(umsUserTeacher.getId()); teacherInfList.add(teacherInfVO); } return teacherInfList; From fa9571e2c59dab7880810db9742281be4692b793 Mon Sep 17 00:00:00 2001 From: Alan <3052806735@qq.com> Date: Fri, 26 Jul 2024 17:39:22 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=95=99=E5=B8=88?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/model/vo/courses/TeacherInfVO.java | 2 +- .../service/impl/umsAdmin/UmsUserServiceImpl.java | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java b/src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java index a99a24f..65f75ef 100644 --- a/src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java +++ b/src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java @@ -10,7 +10,7 @@ import lombok.Data; public class TeacherInfVO { /** - * 教师username + * 教师userId */ @ApiModelProperty("教师userId") private Long userId; 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 5ac3301..ef82ab9 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 @@ -381,15 +381,13 @@ public class UmsUserServiceImpl extends ServiceImpl impl } @Override public List getTeacherInfList() { - List umsUserTeachers = query().eq("role_id", TEACHER_ROLE).list(); + List umsTeachers = umsTeacherMapper.selectList(new LambdaQueryWrapper<>(UmsTeacher.class)); TeacherInfVO teacherInfVO = null; List teacherInfList = new ArrayList<>(); - for (UmsUser umsUserTeacher : umsUserTeachers) { + for (UmsTeacher umsTeacher : umsTeachers) { teacherInfVO = new TeacherInfVO(); - String teacherName = umsTeacherMapper.selectOne(new LambdaQueryWrapper<>(UmsTeacher.class) - .eq(UmsTeacher::getUserId, umsUserTeacher.getId())).getName(); - teacherInfVO.setName(teacherName); - teacherInfVO.setUserId(umsUserTeacher.getId()); + teacherInfVO.setName(umsTeacher.getName()); + teacherInfVO.setUserId(umsTeacher.getUserId()); teacherInfList.add(teacherInfVO); } return teacherInfList; From 414b11ac24bfa2132bbf5bf6e7c15146ef5e8d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=90=8C=E6=96=B0?= <13658798+jjhyyds@user.noreply.gitee.com> Date: Fri, 26 Jul 2024 20:50:52 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=B0=86=E7=9F=A5=E8=AF=86=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=BF=9B=E5=AD=90=E7=AB=A0=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/courses/CoursesController.java | 34 ++++++++++++++----- .../courses/CoursesController2.java | 4 +-- .../backend/model/dto/chapter/ChapterDTO.java | 9 ----- .../backend/model/entity/chapter/Chapter.java | 13 ++++--- .../impl/chapter/ChapterServiceImpl.java | 29 ++++++++++++++-- 5 files changed, 59 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java index ca4298d..b193a11 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java @@ -44,21 +44,37 @@ public class CoursesController { +// @ApiOperation("网站首页") +// @GetMapping("/index") +// public BaseResponse> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) { +// List coursesVo = coursesService.getPagePageSize(page, pageSize); +//// System.out.println(coursesVo); +// long totalcount = coursesService.count(); +// long toatlPages = (int) Math.ceil((double)totalcount / pageSize); +// Map objectMap = new HashMap<>(); +// objectMap.put("content",coursesVo); +// objectMap.put("totalcount", totalcount); +// objectMap.put("totalPages", toatlPages); +// objectMap.put("currentPage", page); +// return ResultUtils.success(objectMap); +// } + @ApiOperation("网站首页") @GetMapping("/index") public BaseResponse> getData(@RequestParam("page") int page, @RequestParam("pageSize") int pageSize) { - List coursesVo = coursesService.getPagePageSize(page, pageSize); -// System.out.println(coursesVo); - long totalcount = coursesService.count(); - long toatlPages = (int) Math.ceil((double)totalcount / pageSize); - Map objectMap = new HashMap<>(); - objectMap.put("content",coursesVo); - objectMap.put("totalcount", totalcount); - objectMap.put("totalPages", toatlPages); - objectMap.put("currentPage", page); + Map result = coursesService.getPagePageSize2(page, pageSize); + + // 将结果放入新的Map对象中返回 + Map objectMap = new HashMap<>(); + objectMap.put("content", result.get("courses")); + objectMap.put("totalcount", result.get("totalcount")); + objectMap.put("totalPages", result.get("totalPages")); + objectMap.put("currentPage", result.get("currentPage")); + return ResultUtils.success(objectMap); } + @ApiOperation("新增课程--同步新增课程的总体目标并同时添加所有的分项目标") @ValidateParams({"teacher","img", "category", "nature","name","code","credit","classhours","assessmenttype","assessmentway"}) // 需要校验的参数 @PostMapping("/addcourse") diff --git a/src/main/java/com/teaching/backend/controller/courses/CoursesController2.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController2.java index 7d8d005..3b4ef97 100644 --- a/src/main/java/com/teaching/backend/controller/courses/CoursesController2.java +++ b/src/main/java/com/teaching/backend/controller/courses/CoursesController2.java @@ -6,7 +6,6 @@ //import com.teaching.backend.exception.BusinessException; //import com.teaching.backend.filter.ValidateParams; //import com.teaching.backend.model.dto.courses.CoursesDTO; -//import com.teaching.backend.model.entity.resource.CourseResources; //import com.teaching.backend.model.entity.courses.Courses; //import com.teaching.backend.service.courses.ICoursesService; //import io.swagger.annotations.ApiOperation; @@ -32,8 +31,6 @@ //public class CoursesController2 { // @Autowired // ICoursesService coursesService; -// @Autowired -// ResourcesRelationshipService resourcesRelationshipService; // // @ApiOperation("网站首页2") // @GetMapping("/index2") @@ -78,6 +75,7 @@ // return ResultUtils.success(relatedResources); // } // +// // } // // diff --git a/src/main/java/com/teaching/backend/model/dto/chapter/ChapterDTO.java b/src/main/java/com/teaching/backend/model/dto/chapter/ChapterDTO.java index bff9e24..9581382 100644 --- a/src/main/java/com/teaching/backend/model/dto/chapter/ChapterDTO.java +++ b/src/main/java/com/teaching/backend/model/dto/chapter/ChapterDTO.java @@ -1,14 +1,10 @@ package com.teaching.backend.model.dto.chapter; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -import javax.xml.soap.Text; import java.io.Serializable; import java.time.LocalDateTime; @@ -74,11 +70,6 @@ public class ChapterDTO implements Serializable { @ApiModelProperty(value = "周次") private String zc; - @ApiModelProperty(value = "资源") - private String ziyuan; - - @ApiModelProperty(value = "资源文件") - private String zywj; @ApiModelProperty(value = "内部序号显示") private String numshow; diff --git a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java index 0606c87..37fb576 100644 --- a/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java +++ b/src/main/java/com/teaching/backend/model/entity/chapter/Chapter.java @@ -4,7 +4,7 @@ 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 io.swagger.annotations.ApiModel; +import com.teaching.backend.model.entity.KnowGraph.Know; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.EqualsAndHashCode; @@ -80,12 +80,6 @@ public class Chapter implements Serializable { @ApiModelProperty(value = "周次") private String zc; - @ApiModelProperty(value = "资源") - private String ziyuan; - - @ApiModelProperty(value = "资源文件") - private String zywj; - @ApiModelProperty(value = "内部序号显示") private String numshow; @@ -93,4 +87,9 @@ public class Chapter implements Serializable { @TableField(exist = false) private List children; // 用于存储子章节 + @ApiModelProperty(value = "知识点") + @TableField(exist = false) + private List knowledgePoints; // 用于存储章节下的知识点 + + } diff --git a/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java index 573f920..153eb8b 100644 --- a/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java +++ b/src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java @@ -8,8 +8,10 @@ import com.teaching.backend.common.ErrorCode; import com.teaching.backend.exception.BusinessException; import com.teaching.backend.mapper.chapter.ChapterMapper; import com.teaching.backend.model.dto.chapter.ChapterDTO; +import com.teaching.backend.model.entity.KnowGraph.Know; import com.teaching.backend.model.entity.chapter.Chapter; import com.teaching.backend.model.vo.chapter.ChapterVo; +import com.teaching.backend.service.KnowGraph.KnowService; import com.teaching.backend.service.chapter.IChapterService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -31,6 +33,8 @@ public class ChapterServiceImpl extends ServiceImpl impl // private int count=0; List list=new ArrayList<>(); + @Autowired + private KnowService knowService; @Override public String updateNumShow(Chapter chapter) { @@ -155,7 +159,6 @@ public class ChapterServiceImpl extends ServiceImpl impl @Override public List getChapterTree(String courseId) { - List chapters=baseMapper.selectSectionsByCourseId(courseId); Map chapterMap=new HashMap<>(); @@ -165,6 +168,7 @@ public class ChapterServiceImpl extends ServiceImpl impl for (Chapter chapter:chapters){ chapter.setChildren(new ArrayList<>()); + chapter.setKnowledgePoints(new ArrayList<>()); // 初始化知识点列表 chapterMap.put(chapter.getId(),chapter); } @@ -182,9 +186,23 @@ public class ChapterServiceImpl extends ServiceImpl impl } } - return roots; + for (Chapter root : roots) { + loadKnowledgePointsRecursively(root); } + return roots; + } + + private void loadKnowledgePointsRecursively(Chapter chapter) { + + for (Chapter child : chapter.getChildren()) { + + Set knows = knowService.queryByChapterId(child.getId()); + child.setKnowledgePoints(new ArrayList<>(knows)); + + loadKnowledgePointsRecursively(child); + } + } @Override public void saveChapter(ChapterDTO chapterDTO) { @@ -235,9 +253,16 @@ public class ChapterServiceImpl extends ServiceImpl impl lambdaQueryWrapper.eq(Chapter::getPid,id); Long count= this.count(lambdaQueryWrapper); + if (count>0){ throw new BusinessException(ErrorCode.OPERATION_ERROR,"存在子章节,无法删除"); } + + Set knows = knowService.queryByChapterId(id); + + if (!knows.isEmpty()) { + throw new BusinessException(ErrorCode.OPERATION_ERROR, "子章节下存在知识点,无法删除"); + } this.remove(queryWrapper);