{
+
+ String saveKnowsWithObjectiveOrContent(ObjectiveContentKnowDTO objectiveContentKnowDTO);
+
+ ObjectiveContentKnowVO getCountData(String objectiveId);
+}
diff --git a/src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java b/src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java
index 02d08f2..c3a75d1 100644
--- a/src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java
+++ b/src/main/java/com/teaching/backend/service/courses/IObjectiveContentsService.java
@@ -3,7 +3,6 @@ package com.teaching.backend.service.courses;
import com.baomidou.mybatisplus.extension.service.IService;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
-import com.teaching.backend.model.vo.CourseObjectivesTreeVO;
/**
*
diff --git a/src/main/java/com/teaching/backend/service/courses/IStudentCoursesService.java b/src/main/java/com/teaching/backend/service/courses/IStudentCoursesService.java
new file mode 100644
index 0000000..34873e4
--- /dev/null
+++ b/src/main/java/com/teaching/backend/service/courses/IStudentCoursesService.java
@@ -0,0 +1,23 @@
+package com.teaching.backend.service.courses;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.teaching.backend.model.dto.courses.PageDTO;
+import com.teaching.backend.model.dto.courses.StudentCoursesDTO;
+import com.teaching.backend.model.entity.courses.StudentCourses;
+import com.teaching.backend.model.query.CourseQuery;
+import com.teaching.backend.model.vo.courses.CoursesVO;
+
+/**
+ *
+ * 服务类
+ *
+ *
+ * @author zjh
+ * @since 2024-06-13
+ */
+public interface IStudentCoursesService extends IService {
+
+ String saveCoursesToStudents(StudentCoursesDTO studentCoursesDTO);
+
+ PageDTO queryCourses(CourseQuery courseQuery);
+}
diff --git a/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java
index ac0a01e..88c4816 100644
--- a/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java
+++ b/src/main/java/com/teaching/backend/service/impl/courses/CourseObjectivesServiceImpl.java
@@ -10,15 +10,13 @@ import com.teaching.backend.mapper.courses.ObjectiveContentsMapper;
import com.teaching.backend.model.dto.courses.CourseObjectivesDTO;
import com.teaching.backend.model.entity.courses.CourseObjectives;
import com.teaching.backend.model.entity.courses.ObjectiveContents;
-import com.teaching.backend.model.vo.CourseObjectivesTreeVO;
+import com.teaching.backend.model.vo.courses.CourseObjectivesTreeVO;
import com.teaching.backend.service.courses.ICourseObjectivesService;
import com.teaching.backend.utils.CourseCode;
-import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -101,7 +99,7 @@ public class CourseObjectivesServiceImpl extends ServiceImpl impl
@Override
@Transactional
public String saveCourseWithObjective(CoursesDTO coursesDTO) {
+ String teacher = coursesDTO.getTeacher();
+ if (teacher == null || teacher.equals("")) {
+ throw new BusinessException(ErrorCode.TEACHER_NOT_EXIT);
+ }
Courses courses = new Courses();
CourseObjectives courseObjectives = new CourseObjectives();
BeanUtils.copyProperties(coursesDTO, courses);
@@ -109,7 +116,11 @@ public class CoursesServiceImpl extends ServiceImpl impl
}
@Override
- public PageDTO queryCourses(CourseQuery courseQuery, String teacherId) {
+ public PageDTO queryCourses(CourseQuery courseQuery) {
+ String username = courseQuery.getUsername();
+ if (username==null || username.equals("")){
+ throw new BusinessException(ErrorCode.TEACHER_NOT_EXIT);
+ }
//要搜索的课程名字
String name = courseQuery.getName();
// 1.1构建分页条件
@@ -119,7 +130,7 @@ public class CoursesServiceImpl extends ServiceImpl impl
.like(name != null, Courses::getName, name)
// .eq(Courses::getTeacher,teacherId)
// .apply("JSON_CONTAINS(teacher, JSON_QUOTE({0}))", teacherId)
- .apply("FIND_IN_SET({0}, teacher)", teacherId)
+ .apply("FIND_IN_SET({0}, teacher)", username)
.page(page);
PageDTO coursesVOPageDTO = PageDTO.of(p, CoursesVO.class);
List pageDTOList = coursesVOPageDTO.getList();
@@ -147,6 +158,9 @@ public class CoursesServiceImpl extends ServiceImpl impl
@Override
public void deleteBatchByIds(String id) {
+ if(id==null){
+ throw new BusinessException(ErrorCode.PARAMS_ERROR,"课程id为空");
+ }
CourseObjectives courseObjectives= courseObjectivesMapper.selectOne
(new LambdaQueryWrapper().eq(CourseObjectives::getCourseId, id));
if(courseObjectives == null){
@@ -226,6 +240,7 @@ public class CoursesServiceImpl extends ServiceImpl impl
return total;
}
+
/**
* 修改课程信息
* @param coursesDTO
@@ -244,5 +259,34 @@ public class CoursesServiceImpl extends ServiceImpl impl
coursesMapper.updateById(course);
}
+ @Override
+ public void down(HttpServletResponse response, String id) throws Exception {
+ File rootPath = new File(ResourceUtils.getURL("classpath:").getPath()); //SpringBoot项目获取根目录的方式
+ File templatePath = new File(rootPath.getAbsolutePath(),"/templates/courses.docx");//------------------需要模板的地址
+ //准备导出数据
+ //查询课程通过课程id查--课程简介
+ Courses courses = this.getById(id);
+ System.out.println("课程:"+courses);
+ Map params = new HashMap();
+ params.put("name",courses.getName());
+ params.put("code",courses.getCode());
+ params.put("nature",courses.getNature());
+ params.put("credit",courses.getCredit());
+ params.put("classhour",courses.getClasshours());
+ params.put("description",courses.getDescription());
+ //查询课程目标
+
+ //根据模板+数据 导出文档
+ XWPFDocument xwpfDocument = WordExportUtil.exportWord07(templatePath.getPath(), params);
+
+
+ //文件名=课程名+课程标准
+ String filename= courses.getName()+"课程标准.docx";
+ //设置文件的打开方式和mime类型
+ ServletOutputStream outputStream = response.getOutputStream();
+ response.setHeader( "Content-Disposition", "attachment;filename=" + new String(filename.getBytes(),"ISO8859-1"));
+ response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
+ xwpfDocument.write(outputStream);
+ }
}
diff --git a/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java
new file mode 100644
index 0000000..6b42b66
--- /dev/null
+++ b/src/main/java/com/teaching/backend/service/impl/courses/ObjectiveContentKnowServiceImpl.java
@@ -0,0 +1,169 @@
+package com.teaching.backend.service.impl.courses;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.teaching.backend.common.ErrorCode;
+import com.teaching.backend.exception.BusinessException;
+import com.teaching.backend.mapper.courses.CourseObjectivesMapper;
+import com.teaching.backend.mapper.courses.CoursesMapper;
+import com.teaching.backend.mapper.courses.ObjectiveContentKnowMapper;
+import com.teaching.backend.mapper.courses.ObjectiveContentsMapper;
+import com.teaching.backend.mapper.know.KnowMapper;
+import com.teaching.backend.model.dto.courses.ObjectiveContentKnowDTO;
+import com.teaching.backend.model.entity.courses.CourseObjectives;
+import com.teaching.backend.model.entity.courses.ObjectiveContentKnow;
+import com.teaching.backend.model.entity.courses.ObjectiveContents;
+import com.teaching.backend.model.entity.know.Know;
+import com.teaching.backend.model.vo.courses.ObjectiveContentKnowVO;
+import com.teaching.backend.service.courses.IObjectiveContentKnowService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.sql.SQLIntegrityConstraintViolationException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ *
+ * 服务实现类
+ *
+ *
+ * @author zjh
+ * @since 2024-06-13
+ */
+@Service
+public class ObjectiveContentKnowServiceImpl extends ServiceImpl implements IObjectiveContentKnowService {
+
+ @Autowired
+ ObjectiveContentKnowMapper objectiveContentKnowMapper;
+ @Autowired
+ KnowMapper knowMapper;
+ @Autowired
+ CourseObjectivesMapper courseObjectivesMapper;
+ @Autowired
+ CoursesMapper coursesMapper;
+ @Autowired
+ ObjectiveContentsMapper objectiveContentsMapper;
+
+ @Override
+ @Transactional
+ public String saveKnowsWithObjectiveOrContent(ObjectiveContentKnowDTO objectiveContentKnowDTO) {
+ String objectiveOrContent = objectiveContentKnowDTO.getObjectiveOrContent();
+ if (objectiveOrContent == null || objectiveOrContent.equals("")){
+ throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_NOT_EXIT);
+ }
+ //暂时约定前端传过来的的knows是“1,2,3” 用 , 隔开的
+ String knows = objectiveContentKnowDTO.getKnow();
+ if (knows == null || knows.equals("")){
+ throw new BusinessException(ErrorCode.KONWID_NOT_EXIT);
+ }
+ List knowIds = new ArrayList<>(Arrays.asList(knows.split(",")));
+ ObjectiveContentKnow objectiveContentKnow = null;
+ try {
+ for (String knowId : knowIds) {
+ objectiveContentKnow = new ObjectiveContentKnow();
+ objectiveContentKnow.setObjectiveOrContent(objectiveOrContent);
+ objectiveContentKnow.setKnow(knowId);
+ objectiveContentKnowMapper.insert(objectiveContentKnow);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_EXIT);
+ }
+ return "添加成功";
+ }
+
+ @Override
+ public ObjectiveContentKnowVO getCountData(String objectiveOrContentId) {
+ // 检查objectiveOrContentId是否为空,如果为空则抛出异常
+ if (objectiveOrContentId == null) {
+ throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_NOT_EXIT);
+ }
+
+ // 查询分项目标关联的知识点数据
+ List objectiveContentKnows = objectiveContentKnowMapper.selectList(
+ new LambdaQueryWrapper()
+ .eq(ObjectiveContentKnow::getObjectiveOrContent, objectiveOrContentId));
+
+ // 创建ObjectiveContentKnowVO对象,并计算相关数据
+ ObjectiveContentKnowVO objectiveContentKnowVO = createObjectiveContentKnowVO(objectiveOrContentId, objectiveContentKnows);
+
+ // 根据分项目标找到课程id
+ String pid = courseObjectivesMapper.selectOne(new LambdaQueryWrapper()
+ .eq(CourseObjectives::getId, objectiveOrContentId)).getPid();
+ String courseId = courseObjectivesMapper.selectOne(new LambdaQueryWrapper()
+ .eq(CourseObjectives::getId, pid)).getCourseId();
+ Integer classhours = coursesMapper.selectById(courseId).getClasshours();
+
+ // 计算并设置比例(百分比)
+ BigDecimal percentage = calculatePercentage(objectiveContentKnowVO.getKnowsTime(), classhours);
+ objectiveContentKnowVO.setPersent(percentage + "%");
+
+ // 查找分项目标下的内容
+ List objectiveContents = objectiveContentsMapper.selectList(
+ new LambdaQueryWrapper()
+ .eq(ObjectiveContents::getObjectiveId, objectiveOrContentId));
+
+ // 如果存在分项目标内容,处理并计算每个内容的相关数据
+ if (objectiveContents != null && !objectiveContents.isEmpty()) {
+ List contentKnowVOs = objectiveContents.stream()
+ .map(content -> createObjectiveContentKnowVO(content.getId(), objectiveContentKnowMapper.selectList(
+ new LambdaQueryWrapper()
+ .eq(ObjectiveContentKnow::getObjectiveOrContent, content.getId())
+ )))
+ .collect(Collectors.toList());
+
+ // 计算每个内容的比例(百分比)
+ contentKnowVOs.forEach(contentKnowVO -> {
+ BigDecimal contentPercentage = calculatePercentage(contentKnowVO.getKnowsTime(), classhours);
+ contentKnowVO.setPersent(contentPercentage + "%");
+ });
+
+ // 设置内容的知识点数据
+ objectiveContentKnowVO.setContentKnowsData(contentKnowVOs);
+ }
+
+ // 返回计算结果
+ return objectiveContentKnowVO;
+ }
+
+ // 创建ObjectiveContentKnowVO对象,并计算知识点数量和总时间
+ private ObjectiveContentKnowVO createObjectiveContentKnowVO(String objectiveOrContentId, List objectiveContentKnows) {
+ ObjectiveContentKnowVO vo = new ObjectiveContentKnowVO();
+ vo.setObjectiveOrContent(objectiveOrContentId);
+ vo.setKnowsNumber(objectiveContentKnows.size());
+
+ // 计算知识点的总时间
+ BigDecimal knowsTime = objectiveContentKnows.stream()
+ .map(contentKnow -> {
+ Know know = knowMapper.selectOne(new LambdaQueryWrapper()
+ .eq(Know::getId, contentKnow.getKnow()));
+ if (know == null) {
+ throw new BusinessException(ErrorCode.KNOW_NOT_EXIT);
+ }
+ return know.getHour();
+ })
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+ vo.setKnowsTime(knowsTime);
+ return vo;
+ }
+
+ // 计算知识点时间占总学时的比例,并转换为百分比
+ private BigDecimal calculatePercentage(BigDecimal knowsTime, Integer classhours) {
+ if (classhours == null || classhours == 0) {
+ return BigDecimal.ZERO;
+ }
+ // 将classhours转换为BigDecimal类型,以便进行精确计算
+ BigDecimal classHoursBigDecimal = new BigDecimal(classhours);
+ // 计算knowsTime占classhours的比例,保留两位小数,并四舍五入
+ return knowsTime.divide(classHoursBigDecimal, 2, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
+ }
+
+
+}
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
new file mode 100644
index 0000000..63e6b64
--- /dev/null
+++ b/src/main/java/com/teaching/backend/service/impl/courses/StudentCoursesServiceImpl.java
@@ -0,0 +1,124 @@
+package com.teaching.backend.service.impl.courses;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.teaching.backend.common.ErrorCode;
+import com.teaching.backend.exception.BusinessException;
+import com.teaching.backend.mapper.courses.CoursesMapper;
+import com.teaching.backend.mapper.courses.StudentCoursesMapper;
+import com.teaching.backend.mapper.umsAdmin.UmsAdminMapper;
+import com.teaching.backend.mapper.umsAdmin.UmsTeacherMapper;
+import com.teaching.backend.model.dto.courses.ObjectiveContentKnowDTO;
+import com.teaching.backend.model.dto.courses.PageDTO;
+import com.teaching.backend.model.dto.courses.StudentCoursesDTO;
+import com.teaching.backend.model.entity.courses.Courses;
+import com.teaching.backend.model.entity.courses.ObjectiveContentKnow;
+import com.teaching.backend.model.entity.courses.StudentCourses;
+import com.teaching.backend.model.entity.umsAdmin.UmsAdmin;
+import com.teaching.backend.model.entity.umsAdmin.UmsTeacher;
+import com.teaching.backend.model.query.CourseQuery;
+import com.teaching.backend.model.vo.courses.CoursesVO;
+import com.teaching.backend.service.courses.IStudentCoursesService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ *
+ * 服务实现类
+ *
+ *
+ * @author zjh
+ * @since 2024-06-13
+ */
+@Service
+public class StudentCoursesServiceImpl extends ServiceImpl implements IStudentCoursesService {
+
+ @Autowired
+ StudentCoursesMapper studentCoursesMapper;
+ @Autowired
+ UmsAdminMapper umsAdminMapper;
+ @Autowired
+ UmsTeacherMapper umsTeacherMapper;
+ @Autowired
+ CoursesMapper coursesMapper;
+ @Override
+ public String saveCoursesToStudents(StudentCoursesDTO studentCoursesDTO) {
+ String studentId = studentCoursesDTO.getStudent();
+ if (studentId == null || studentId.equals("")) {
+ throw new BusinessException(ErrorCode.STUDENT_NOT_EXIT);
+ }
+ //暂时约定前端传过来的的knows是“1,2,3” 用 , 隔开的
+ String courses = studentCoursesDTO.getCourse();
+ if (courses == null || courses.equals("")) {
+ throw new BusinessException(ErrorCode.COURSES_NOT_EXIT);
+ }
+ List coursesIds = new ArrayList<>(Arrays.asList(courses.split(",")));
+ StudentCourses studentCourses = null;
+ try {
+ for (String course : coursesIds) {
+ studentCourses = new StudentCourses();
+ studentCourses.setStudent(studentId);
+ studentCourses.setCourse(course);
+ studentCoursesMapper.insert(studentCourses);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new BusinessException(ErrorCode.OBJECTIVE_OR_CONTENT_EXIT);
+ }
+ return "添加成功";
+ }
+
+ @Override
+ public PageDTO queryCourses(CourseQuery courseQuery) {
+ String username = courseQuery.getUsername();
+ if (username==null || username.equals("")){
+ throw new BusinessException(ErrorCode.STUDENT_NOT_EXIT);
+ }
+ List studentCourses = studentCoursesMapper.selectList(new LambdaQueryWrapper()
+ .eq(StudentCourses::getStudent, username));
+ List coursesList = studentCourses.stream()
+ .map(StudentCourses::getCourse)
+ .collect(Collectors.toList());
+ //要搜索的课程名字
+ String name = courseQuery.getName();
+ // 1.1构建分页条件
+ Page page = courseQuery.toMpPageDefaultSortByCreateTime();
+ // 2.分页查询
+ LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper()
+ .like(name != null, Courses::getName, name)
+ .in(Courses::getId, coursesList);
+ // 3. 执行分页查询
+ Page p = this.coursesMapper.selectPage(page, queryWrapper);
+
+ PageDTO coursesVOPageDTO = PageDTO.of(p, CoursesVO.class);
+ List pageDTOList = coursesVOPageDTO.getList();
+ List teachers = null;
+
+ for (CoursesVO coursesVO : pageDTOList) {
+ List teacherNameList = new ArrayList<>();
+ String teacherIds = coursesVO.getTeacher();
+ teachers = new ArrayList<>(Arrays.asList(teacherIds.split(",")));
+ for (String teacher : teachers) {
+ UmsAdmin umsAdmin = umsAdminMapper.selectOne(new LambdaQueryWrapper().
+ eq(UmsAdmin::getUsername, teacher));
+ if (umsAdmin==null){
+ throw new BusinessException(ErrorCode.OPERATION_ERROR);
+ }
+ Long adminId = umsAdmin.getId();
+ UmsTeacher umsTeacher = umsTeacherMapper.selectOne(new LambdaQueryWrapper()
+ .eq(UmsTeacher::getUserId, adminId));
+ teacherNameList.add(umsTeacher.getName());
+ }
+ coursesVO.setTeacher(String.join(",", teacherNameList));
+ }
+ return coursesVOPageDTO;
+ }
+}
diff --git a/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java b/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java
index e27a638..52da01f 100644
--- a/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java
+++ b/src/main/java/com/teaching/backend/service/impl/records/LearningRecordsServiceImpl.java
@@ -170,11 +170,11 @@ public class LearningRecordsServiceImpl extends ServiceImpl
+
+
+
+
diff --git a/src/main/resources/mapper/CourseObjectivesMapper.xml b/src/main/resources/mapper/CourseObjectivesMapper.xml
index 347ebec..1204030 100644
--- a/src/main/resources/mapper/CourseObjectivesMapper.xml
+++ b/src/main/resources/mapper/CourseObjectivesMapper.xml
@@ -2,7 +2,7 @@
-