|
@@ -1,15 +1,19 @@
|
|
|
package cn.iselab.mooctest.site.web.logic.impl;
|
|
|
|
|
|
+import cn.iselab.mooctest.site.common.enums.EntityType;
|
|
|
import cn.iselab.mooctest.site.common.enums.CourseVisibility;
|
|
|
import cn.iselab.mooctest.site.common.enums.EntityTypeEnum;
|
|
|
import cn.iselab.mooctest.site.models.*;
|
|
|
import cn.iselab.mooctest.site.service.*;
|
|
|
import cn.iselab.mooctest.site.service.common.PdfService;
|
|
|
import cn.iselab.mooctest.site.web.data.*;
|
|
|
+import cn.iselab.mooctest.site.web.data.response.ResponseVO;
|
|
|
+import cn.iselab.mooctest.site.web.data.response.ServerCode;
|
|
|
import cn.iselab.mooctest.site.web.data.wrapper.*;
|
|
|
import cn.iselab.mooctest.site.web.exception.HttpForbiddenException;
|
|
|
import cn.iselab.mooctest.site.web.exception.HttpNotFoundException;
|
|
|
import cn.iselab.mooctest.site.web.exception.HttpBadRequestException;
|
|
|
+import cn.iselab.mooctest.site.web.exception.HttpNotFoundException;
|
|
|
import cn.iselab.mooctest.site.web.logic.OSSLogic;
|
|
|
import cn.iselab.mooctest.site.web.logic.ThemeLogic;
|
|
|
import com.google.common.collect.Lists;
|
|
@@ -18,6 +22,7 @@ import org.apache.shiro.SecurityUtils;
|
|
|
import org.apache.shiro.crypto.hash.Hash;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -26,10 +31,7 @@ import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
@@ -49,7 +51,9 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
@Autowired
|
|
|
private PaperVOWrapper paperVOWrapper;
|
|
|
@Autowired
|
|
|
- private ExamVOWrapper themeDetailVOWrapper;
|
|
|
+ private ThemeVOWrapper themeDetailVOWrapper;
|
|
|
+ @Autowired
|
|
|
+ ExamVOWrapper examVOWrapper;
|
|
|
@Autowired
|
|
|
private ThemeService themeService;
|
|
|
@Autowired
|
|
@@ -69,6 +73,8 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
@Autowired
|
|
|
Theme2GroupService theme2GroupService;
|
|
|
@Autowired
|
|
|
+ SubmitRecordService submitRecordService;
|
|
|
+ @Autowired
|
|
|
private OSSLogic ossLogic;
|
|
|
@Autowired
|
|
|
private CourseResourceService courseResourceService;
|
|
@@ -80,9 +86,49 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
|
|
|
|
|
|
private static final String BASE_DIR = "theme";
|
|
|
+
|
|
|
@Override
|
|
|
- public ThemeDetailVO newThemeDetail(ThemeDetailVO themeDetailVO) {
|
|
|
+ public CourseVO newThemeCourse(CourseVO courseVO, Long userId) {
|
|
|
+ // 主题信息
|
|
|
+ ThemeDetailVO themeDetailVO = courseVO.getThemeDetailVO();
|
|
|
+ if (themeDetailVO == null) throw new HttpBadRequestException("主题内容为空");;
|
|
|
+ themeDetailVO.setOwnerId(userId);
|
|
|
+ themeDetailVO.setStatus(ThemeDetail.STATUS_UPCOMING);
|
|
|
+ checkThemeInfo(themeDetailVO);
|
|
|
+ if (themeDetailVO.getGroupId() != null && groupService.getGroupsByOwnerId(themeDetailVO.getOwnerId()).stream()
|
|
|
+ .map(Group::getId).collect(Collectors.toList()).contains(themeDetailVO.getGroupId())) {
|
|
|
+ // 课程中的实体信息(课程信息、考试信息、练习信息) 可否为空
|
|
|
+ List<EntityVO> entityVOList = courseVO.getEntityVOList();
|
|
|
+ if(entityVOList.size() != 0){
|
|
|
+ checkThemeCourseGroupAndExam(themeDetailVO, entityVOList);
|
|
|
+ // 条件符合,可以创建
|
|
|
+ ThemeDetail themeDetail = themeVOWrapper.unWrapperThemeDetail(themeDetailVO);
|
|
|
+ themeDetail = themeService.createThemeDetail(themeDetail);
|
|
|
+ themeDetailVO.setId(themeDetail.getId());
|
|
|
+ theme2GroupService.create(themeDetailVO.getGroupId(), themeDetailVO.getId());
|
|
|
+ int index = 0;
|
|
|
+ for(EntityVO entityVO: entityVOList){
|
|
|
+ index++;
|
|
|
+ entityVO.setThemeId(themeDetailVO.getId());
|
|
|
+ ThemeEntityRelationsVO entityRelation = createEntityRelation(themeDetailVO.getId(), entityVO.getEntityId(), entityVO.getEntityType(), index);
|
|
|
+ entityVO.setSortedId(entityRelation.getSortId());
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ // 条件符合,可以创建
|
|
|
+ ThemeDetail themeDetail = themeVOWrapper.unWrapperThemeDetail(themeDetailVO);
|
|
|
+ themeDetail = themeService.createThemeDetail(themeDetail);
|
|
|
+ themeDetailVO.setId(themeDetail.getId());
|
|
|
+ theme2GroupService.create(themeDetailVO.getGroupId(), themeDetailVO.getId());
|
|
|
+ log.info("课程中没有实体信息");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new HttpBadRequestException("No right for some group");
|
|
|
+ }
|
|
|
+ return courseVO;
|
|
|
+ }
|
|
|
|
|
|
+ private void checkThemeInfo(ThemeDetailVO themeDetailVO) {
|
|
|
+ // 检查主题信息
|
|
|
long currTime = System.currentTimeMillis();
|
|
|
boolean isThemeTimeInvalid = currTime > themeDetailVO.getBeginTime() || themeDetailVO.getBeginTime() > themeDetailVO.getEndTime();
|
|
|
if (isThemeTimeInvalid) {
|
|
@@ -99,21 +145,68 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
throw new HttpBadRequestException("主题课程名称已存在");
|
|
|
}
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- if (themeDetailVO.getGroupId() != null && groupService.getGroupsByOwnerId(themeDetailVO.getOwnerId()).stream()
|
|
|
- .map(Group::getId).collect(Collectors.toList()).contains(themeDetailVO.getGroupId())) {
|
|
|
|
|
|
+ @Override
|
|
|
+ public CourseVO updateThemeCourse(CourseVO courseVO, Long userId) {
|
|
|
+ // 主题信息
|
|
|
+ ThemeDetailVO themeDetailVO = courseVO.getThemeDetailVO();
|
|
|
+ if (!themeDetailVO.getOwnerId().equals(userId)) throw new HttpBadRequestException("当前用户无修改此课程的权限");
|
|
|
+ if (themeDetailVO == null) throw new HttpBadRequestException("主题内容为空");
|
|
|
+// long currTime = System.currentTimeMillis();
|
|
|
+// boolean isThemeTimeInvalid = currTime > themeDetailVO.getBeginTime() || themeDetailVO.getBeginTime() > themeDetailVO.getEndTime();
|
|
|
+// if (isThemeTimeInvalid) {
|
|
|
+// throw new HttpBadRequestException("主题课程时间无效");
|
|
|
+// }
|
|
|
+
|
|
|
+ // 课程中的实体信息(课程信息、考试信息、练习信息)
|
|
|
+ List<EntityVO> entityVOList = courseVO.getEntityVOList();
|
|
|
+ // 删除原有的实体
|
|
|
+ deleteEntityRelationByThemeId(themeDetailVO.getId());
|
|
|
+ if(entityVOList.size() != 0){
|
|
|
+ checkThemeCourseGroupAndExam(themeDetailVO, entityVOList);
|
|
|
+ ThemeDetail themeDetail = themeVOWrapper.unWrapperThemeDetail(themeDetailVO);
|
|
|
+ Integer status = themeService.updateStatus(themeDetail);
|
|
|
+ themeDetail.setStatus(status);
|
|
|
+ themeService.updateThemeDetail(themeDetail);
|
|
|
+ // 条件符合,可以更新
|
|
|
+ int index = 0;
|
|
|
+ for(EntityVO entityVO: entityVOList){
|
|
|
+ index++;
|
|
|
+ entityVO.setThemeId(themeDetailVO.getId());
|
|
|
+ ThemeEntityRelationsVO entityRelation = createEntityRelation(themeDetailVO.getId(), entityVO.getEntityId(), entityVO.getEntityType(), index);
|
|
|
+ entityVO.setSortedId(entityRelation.getSortId());
|
|
|
+ }
|
|
|
+ }else{
|
|
|
ThemeDetail themeDetail = themeVOWrapper.unWrapperThemeDetail(themeDetailVO);
|
|
|
- themeDetail = themeService.createThemeDetail(themeDetail);
|
|
|
- themeDetailVO.setId(themeDetail.getId());
|
|
|
- theme2GroupService.create(themeDetailVO.getGroupId(), themeDetailVO.getId());
|
|
|
+ Integer status = themeService.updateStatus(themeDetail);
|
|
|
+ themeDetail.setStatus(status);
|
|
|
+ themeService.updateThemeDetail(themeDetail);
|
|
|
+ log.info("课程中没有实体信息");
|
|
|
+ }
|
|
|
+ return courseVO;
|
|
|
+ }
|
|
|
|
|
|
- return themeVOWrapper.wrapperThemeDetail(themeDetail);
|
|
|
- } else {
|
|
|
- throw new HttpBadRequestException("No right for some group");
|
|
|
+ private void checkThemeCourseGroupAndExam(ThemeDetailVO themeDetailVO, List<EntityVO> entityVOList) {
|
|
|
+ List<Long> examIdList = entityVOList.stream().filter(entityVO -> entityVO.getEntityType() == EntityTypeEnum.EXAM).map(EntityVO::getEntityId).collect(Collectors.toList());
|
|
|
+ for (Long examId : examIdList) {
|
|
|
+ Exam exam = examService.getTask(examId);
|
|
|
+ // 判断考试所属班级是否一致
|
|
|
+ if (!groupService.getByExamId(examId).get(0).getId().equals(themeDetailVO.getGroupId())) {
|
|
|
+ throw new HttpBadRequestException(exam.getName() + "不属于当前班级");
|
|
|
+ } else {
|
|
|
+ //判断考试的时间段在课程时间段之间
|
|
|
+ if (themeDetailVO.getBeginTime() < exam.getBeginTime().getTime() && themeDetailVO.getEndTime() > exam.getEndTime().getTime()) {
|
|
|
+ continue;
|
|
|
+ } else {
|
|
|
+ throw new HttpBadRequestException(exam.getName() + "考试时间不在课程时间范围内");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public ThemeDetailVO updateThemeDetail(ThemeDetailVO themeDetailVO) {
|
|
|
long currTime = System.currentTimeMillis();
|
|
@@ -132,6 +225,11 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public Page<ThemeDetailVO> getThemeList(Pageable pageable, String keyword, int type) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
@Async("generateUpload2Oss")
|
|
|
protected void uploadImages2Oss(String localDir,String parentDir){
|
|
|
File file = new File(localDir);
|
|
@@ -181,7 +279,7 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Object[] getThemeListByCourse(Pageable pageable, String keyword) {
|
|
|
+ public Long[] getThemeListByCourse(Pageable pageable, String keyword) {
|
|
|
Page<CourseResource> courseResources = themeService.getThemeCourseResources(pageable, keyword);
|
|
|
List<CourseResource> content = courseResources.getContent();
|
|
|
// Set<Stream<Long>> listSet = content.stream().map(courseResource -> themeService.getThemeEntityRelationsByEntityId(courseResource.getId(), EntityTypeEnum.COURSE_RESOURCE)
|
|
@@ -194,7 +292,8 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
themeIdSet.add(themeEntityRelations.getThemeId());
|
|
|
}
|
|
|
}
|
|
|
- return themeIdSet.toArray();
|
|
|
+ Long[] themeIdArray = Arrays.stream(themeIdSet.toArray()).map(themeId -> Long.valueOf(themeId.toString())).toArray(Long[]::new);
|
|
|
+ return themeIdArray;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -261,6 +360,42 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public CourseVO getCourse(Long id, Long userId) {
|
|
|
+ ThemeDetail themeDetail = themeService.getThemeDetailById(id);
|
|
|
+ userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
|
+ //检查用户查看权限
|
|
|
+ if (themeDetail.getVisibility()==CourseVisibility.NONE_OPEN.getVisibility()){
|
|
|
+ Theme2Group t2g = theme2GroupService.findByThemeId(themeDetail.getId());
|
|
|
+ if (!groupService.isUserInGroup(userId,t2g.getGroupId())
|
|
|
+ && !userId.equals(themeDetail.getOwnerId())){
|
|
|
+ throw new HttpForbiddenException(String.format("User Cannot Access This Course, UserId: %s", userId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //根据id查询,然后过滤存map
|
|
|
+ List<ThemeEntityRelations> themeEntityRelations = themeService.getThemeEntityRelations(id);
|
|
|
+ Theme theme = new Theme();
|
|
|
+ theme.setThemeDetail(themeDetail);
|
|
|
+ Map<EntityTypeEnum, List<ThemeEntityRelations>> map = themeEntityRelations.stream().collect(Collectors.groupingBy(ThemeEntityRelations::getEntityType));
|
|
|
+ for (EntityTypeEnum key: map.keySet()) {
|
|
|
+ List<ThemeEntityRelations> tmp = map.get(key);
|
|
|
+ if (key == EntityTypeEnum.EXAM) {
|
|
|
+ List<Exam> examList = examService.getTasks(map.get(key).stream().map(ThemeEntityRelations::getEntityId).collect(Collectors.toList()));
|
|
|
+ theme.setExamList(examList);
|
|
|
+ } else if (key == EntityTypeEnum.COURSE_RESOURCE) {
|
|
|
+ List<Long> courseIds = map.get(key).stream().map(ThemeEntityRelations::getEntityId).collect(Collectors.toList());
|
|
|
+ List<CourseResource> courseResourceList = courseResourceService.getCourseResourceById(courseIds);
|
|
|
+ theme.setCourseResourceList(courseResourceList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CourseVO courseVO = themeVOWrapper.wrapTheme2CourseVO(theme, themeEntityRelations);
|
|
|
+ List<StudyRecord> studyCompletenessByThemeId = themeService.getStudyCompletenessByThemeId(id, userId, EntityTypeEnum.COURSE_RESOURCE);
|
|
|
+ List<ThemeEntityRelations> entityRelationsList = themeService.getThemeEntityRelations(id).stream().filter(entityRelations -> entityRelations.getEntityType() == EntityTypeEnum.COURSE_RESOURCE).collect(Collectors.toList());
|
|
|
+ courseVO.setCompleteCourseRecourseId(studyCompletenessByThemeId.stream().map(StudyRecord::getEntityId).collect(Collectors.toList()));
|
|
|
+ courseVO.setTotalCourseRecourseId(entityRelationsList.stream().map(ThemeEntityRelations::getEntityId).collect(Collectors.toList()));
|
|
|
+ return courseVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public CourseVO getCourse(Long id) {
|
|
|
ThemeDetail themeDetail = themeService.getThemeDetailById(id);
|
|
|
Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
@@ -291,6 +426,41 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
return themeVOWrapper.wrapTheme2CourseVO(theme,themeEntityRelations);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ // 获取themeIds的所有主题课程信息
|
|
|
+ @Override
|
|
|
+ public Page<CourseVO> getCoursesByThemeIds(Long[] ids, Pageable pageable, long total, int type) {
|
|
|
+ List<ThemeDetail> themeDetailList = themeService.getThemeDetailByIds(ids);
|
|
|
+ if(type > 0){
|
|
|
+ themeDetailList = themeDetailList.stream().filter(themeDetail -> themeDetail.getCourseType() == type).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ List<CourseVO> courseVOS = themeDetailList.stream().map(themeDetail -> getCourseOfCourseResource(themeDetail.getId())).collect(Collectors.toList());
|
|
|
+ courseVOS = courseVOS.stream().filter(courseVO -> courseVO.getEntityVOList() != null).peek(courseVO -> courseVO.getThemeDetailVO().setEntityVOList(courseVO.getEntityVOList())).collect(Collectors.toList());
|
|
|
+ return new PageImpl<CourseVO>(courseVOS, pageable, total);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CourseVO getCourseOfCourseResource(Long id) {
|
|
|
+ ThemeDetail themeDetail = themeService.getThemeDetailById(id);
|
|
|
+ //根据id查询,然后过滤存map
|
|
|
+ List<ThemeEntityRelations> themeEntityRelations = themeService.getThemeEntityRelations(id);
|
|
|
+ Theme theme = new Theme();
|
|
|
+ theme.setThemeDetail(themeDetail);
|
|
|
+ Map<EntityTypeEnum, List<ThemeEntityRelations>> map = themeEntityRelations.stream().collect(Collectors.groupingBy(ThemeEntityRelations::getEntityType));
|
|
|
+ for (EntityTypeEnum key: map.keySet()) {
|
|
|
+ List<ThemeEntityRelations> tmp = map.get(key);
|
|
|
+// if (key == EntityTypeEnum.EXAM) {
|
|
|
+// List<Exam> examList = examService.getTasks(map.get(key).stream().map(ThemeEntityRelations::getEntityId).collect(Collectors.toList()));
|
|
|
+// theme.setExamList(examList);
|
|
|
+// }
|
|
|
+ if (key == EntityTypeEnum.COURSE_RESOURCE) {
|
|
|
+ List<Long> courseIds = map.get(key).stream().map(ThemeEntityRelations::getEntityId).collect(Collectors.toList());
|
|
|
+ List<CourseResource> courseResourceList = courseResourceService.getCourseResourceById(courseIds);
|
|
|
+ theme.setCourseResourceList(courseResourceList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return themeVOWrapper.wrapTheme2CourseVO(theme,themeEntityRelations);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 创建主题相关的实体
|
|
|
* @param themeId
|
|
@@ -299,8 +469,8 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public ThemeEntityRelationsVO createEntityRelation(long themeId, long entityId, EntityTypeEnum entityType) {
|
|
|
- ThemeEntityRelations themeEntityRelations = themeService.createEntityRelation(themeId, entityId, entityType);
|
|
|
+ public ThemeEntityRelationsVO createEntityRelation(long themeId, long entityId, EntityTypeEnum entityType, int sortId) {
|
|
|
+ ThemeEntityRelations themeEntityRelations = themeService.createEntityRelation(themeId, entityId, entityType, sortId);
|
|
|
return themeEntityRelationsVOWrapper.wrapperThemeEntityRelations(themeEntityRelations);
|
|
|
}
|
|
|
|
|
@@ -334,7 +504,7 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
@Override
|
|
|
public ExamVO createRelationBetweenThemeAndExam(long themeId, long caseId) {
|
|
|
ThemeEntityRelations themeEntityRelations = themeService.createRelationBetweenThemeAndEntity(themeId,caseId,EntityTypeEnum.EXAM);
|
|
|
- return themeDetailVOWrapper.wrap(examService.getTask(themeEntityRelations.getEntityId()));
|
|
|
+ return examVOWrapper.wrap(examService.getTask(themeEntityRelations.getEntityId()));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -370,6 +540,12 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public CourseResourceVO getCourseResourceById(long resourceId) {
|
|
|
+ CourseResource courseResource = courseResourceService.getCourseResourceByResourceId(resourceId);
|
|
|
+ return courseResourceVOWrapper.wrap(courseResource);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public CourseResourceVO getCourseResource(long courseId, long resourceId) {
|
|
|
ThemeEntityRelations themeEntityRelations = themeService
|
|
|
.checkRelationBetweenThemeAndEntity(courseId, resourceId, EntityTypeEnum.COURSE_RESOURCE);
|
|
@@ -381,4 +557,92 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
CourseResource courseResource = courseResourceService.getCourseResourceByResourceId(resourceId);
|
|
|
return courseResourceVOWrapper.wrap(courseResource);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ThemeInfoVO getThemeInfoByThemeId(Long themeId) {
|
|
|
+ ThemeInfoVO themeInfoVO = new ThemeInfoVO();
|
|
|
+ ThemeDetail themeDetail = themeService.getThemeDetailById(themeId);
|
|
|
+ ThemeDetailVO themeDetailVO = themeVOWrapper.wrapperThemeDetail(themeDetail);
|
|
|
+ themeInfoVO.setThemeDetailVO(themeDetailVO);
|
|
|
+ long restTime = System.currentTimeMillis() - themeDetailVO.getBeginTime();
|
|
|
+ long totalTime = themeDetailVO.getEndTime() - themeDetailVO.getBeginTime();
|
|
|
+ themeInfoVO.setTeacherCompletedRate((float) restTime / totalTime);
|
|
|
+
|
|
|
+ int studentNumber = groupService.getWorkerCount(themeDetailVO.getGroupId());
|
|
|
+ themeInfoVO.setStudentNum(studentNumber);
|
|
|
+ List<User> studentList = groupService.getUserByGroupId(themeDetailVO.getGroupId());
|
|
|
+ List<Long> studentIds = new ArrayList<>();
|
|
|
+ for(User student : studentList){
|
|
|
+ studentIds.add(student.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ CourseVO resource = getCourseOfCourseResource(themeId);
|
|
|
+ int courseResourceCount = resource.getEntityVOList().size();
|
|
|
+ int studyRecordNumber = themeService.getStudyRecord(themeId, studentIds, EntityTypeEnum.COURSE_RESOURCE);
|
|
|
+ themeInfoVO.setLearningCompletedRate((float)(studyRecordNumber/(courseResourceCount*studentNumber*1.0)));
|
|
|
+ int totalExamCommitNumber = 0;
|
|
|
+ int examCount = 0;
|
|
|
+ int totalExerciseCommitNumber = 0;
|
|
|
+ int exerciseCount = 0;
|
|
|
+
|
|
|
+ // 获取练习和考试结果信息
|
|
|
+ List<ExamResultVO> examResultVOS = new ArrayList<>();
|
|
|
+ List<ThemeEntityRelations> themeEntityRelations = themeService.getThemeEntityRelations(themeId).stream()
|
|
|
+ .filter(entityRelation -> entityRelation.getEntityType() == EntityTypeEnum.EXAM).collect(Collectors.toList());
|
|
|
+ for(ThemeEntityRelations relation : themeEntityRelations){
|
|
|
+ List<Double> scoreList = submitRecordService.getScoreList(relation.getEntityId());
|
|
|
+ Exam exam = examService.getTask(relation.getEntityId());
|
|
|
+ if (exam == null) {
|
|
|
+ throw new HttpNotFoundException("exam doesn't exists");
|
|
|
+ }
|
|
|
+ ExamVO examVO = examVOWrapper.wrapExamFrom(exam);
|
|
|
+ examResultVOS.add(new ExamResultVO(examVO, scoreList));
|
|
|
+ if(examVO.getType() == 0){
|
|
|
+ totalExamCommitNumber += scoreList.size();
|
|
|
+ examCount++;
|
|
|
+ }else{
|
|
|
+ totalExerciseCommitNumber += scoreList.size();
|
|
|
+ exerciseCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ themeInfoVO.setExamResultVOList(examResultVOS);
|
|
|
+ if(examCount == 0){
|
|
|
+ themeInfoVO.setExamCompletedRate(-1);
|
|
|
+ }else{
|
|
|
+ themeInfoVO.setExamCompletedRate(totalExamCommitNumber/examCount*studentNumber);
|
|
|
+ }
|
|
|
+ if(exerciseCount == 0){
|
|
|
+ themeInfoVO.setExerciseCompletedRate(-1);
|
|
|
+ }else{
|
|
|
+ themeInfoVO.setExerciseCompletedRate((float) (totalExerciseCommitNumber/(exerciseCount*studentNumber*1.0)));
|
|
|
+ }
|
|
|
+
|
|
|
+ return themeInfoVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void createStudyRecord(Long themeId, Long courseId, Long userId) {
|
|
|
+ StudyRecord studyRecord = themeService.getStudyRecordByThemeId(themeId, courseId, userId, EntityTypeEnum.COURSE_RESOURCE);
|
|
|
+ if(studyRecord == null){
|
|
|
+ themeService.createStudyViewRecord(themeId, courseId, userId, EntityTypeEnum.COURSE_RESOURCE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Theme2Group> getThemeListByGroup(Long groupId) {
|
|
|
+ return theme2GroupService.findByGroupId(groupId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ThemeDetailVO getThemeDetailByThemeId(Long themeId) {
|
|
|
+ return themeVOWrapper.wrapperThemeDetail(themeService.getThemeDetailById(themeId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ThemeDetailVO deleteThemeDetailById(Long themeId) {
|
|
|
+ if(!themeService.canBeDeleted(themeId)){
|
|
|
+ throw new HttpBadRequestException("Cannot delete this themeCourse.");
|
|
|
+ }
|
|
|
+ return themeVOWrapper.wrapperThemeDetail(themeService.deleteThemeDetailById(themeId));
|
|
|
+ }
|
|
|
}
|