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}
+