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/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/courses/CoursesController.java b/src/main/java/com/teaching/backend/controller/courses/CoursesController.java index 28fa366..b193a11 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; @@ -41,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") @@ -66,7 +85,7 @@ public class CoursesController { @ApiOperation("查询课程列表") - @ValidateParams({"username"}) + @ValidateParams({"userId"}) @GetMapping("/page") // @PostMapping("/page") public BaseResponse> getCourses(CourseQuery courseQuery){ @@ -120,4 +139,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/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/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/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/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/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/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/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/model/vo/courses/TeacherInfVO.java b/src/main/java/com/teaching/backend/model/vo/courses/TeacherInfVO.java index 66a317e..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,10 +10,10 @@ import lombok.Data; public class TeacherInfVO { /** - * 教师username + * 教师userId */ - @ApiModelProperty("教师username") - private String username; + @ApiModelProperty("教师userId") + private Long userId; /** * 课程封面 */ 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/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); 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 5cd8d7f..f815edd 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 com.teaching.backend.utils.knowGraph.AddNeoKnowByCourse; @@ -43,6 +46,8 @@ import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; +import static com.teaching.backend.constant.RoleConstants.TEACHER_ROLE; + /** *

* 服务实现类 @@ -76,6 +81,8 @@ public class CoursesServiceImpl extends ServiceImpl impl @Autowired UmsTeacherMapper umsTeacherMapper; @Autowired + UmsStudentMapper umsStudentMapper; + @Autowired StudentCoursesMapper studentCoursesMapper; @Autowired ObjectiveContentKnowMapper objectiveContentKnowMapper; @@ -146,10 +153,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: @@ -174,7 +185,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()) @@ -184,11 +195,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()) @@ -196,7 +206,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() @@ -212,17 +221,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); } @@ -332,6 +340,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/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()); 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 97% 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..ef82ab9 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; @@ -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,15 @@ public class UmsUserServiceImpl extends ServiceImpl impl } throw new UsernameNotFoundException("用户名或密码错误"); } - @Override public List getTeacherInfList() { - List umsTeachers = umsTeacherMapper.selectList(new LambdaQueryWrapper()); + List umsTeachers = umsTeacherMapper.selectList(new LambdaQueryWrapper<>(UmsTeacher.class)); TeacherInfVO teacherInfVO = null; - List teacherInfList = new ArrayList<>();; + List teacherInfList = new ArrayList<>(); for (UmsTeacher umsTeacher : umsTeachers) { teacherInfVO = new TeacherInfVO(); - UmsUser umsUser = umsUserMapper.selectOne(new LambdaQueryWrapper() - .eq(UmsUser::getId, umsTeacher.getUserId())); teacherInfVO.setName(umsTeacher.getName()); - teacherInfVO.setUsername(umsUser.getUsername()); + teacherInfVO.setUserId(umsTeacher.getUserId()); teacherInfList.add(teacherInfVO); } return teacherInfList; 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} +