|
@@ -22,6 +22,7 @@ import com.google.common.collect.Lists;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.apache.shiro.crypto.hash.Hash;
|
|
|
+import org.drools.core.time.SchedulerService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
@@ -66,6 +67,10 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
@Autowired
|
|
|
private User2ThemeService user2ThemeService;
|
|
|
@Autowired
|
|
|
+ private ThemeSchedulerService themeSchedulerService;
|
|
|
+ @Autowired
|
|
|
+ private ThemeStatusService themeStatusService;
|
|
|
+ @Autowired
|
|
|
private PdfService pdfService;
|
|
|
@Autowired
|
|
|
GroupService groupService;
|
|
@@ -94,8 +99,19 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
ThemeDetailVO themeDetailVO = courseVO.getThemeDetailVO();
|
|
|
if (themeDetailVO == null) throw new HttpBadRequestException("主题内容不可为空");;
|
|
|
themeDetailVO.setOwnerId(userId);
|
|
|
-// themeDetailVO.setStatus(ThemeDetail.STATUS_UPCOMING);//??
|
|
|
-// themeDetailVO.setVisibility(CourseVisibility.NONE_OPEN.getVisibility());//??
|
|
|
+ // 设置课程状态
|
|
|
+ if(System.currentTimeMillis() < themeDetailVO.getBeginTime())
|
|
|
+ themeDetailVO.setStatus(ThemeDetail.STATUS_UPCOMING);
|
|
|
+ else
|
|
|
+ themeDetailVO.setStatus(ThemeDetail.STATUS_ONGOING);
|
|
|
+ if(System.currentTimeMillis() > themeDetailVO.getEndTime())
|
|
|
+ themeDetailVO.setStatus(ThemeDetail.STATUS_FINISHED);
|
|
|
+ // 判断可见性
|
|
|
+ boolean admin = SecurityUtils.getSubject().hasRole("admin");
|
|
|
+ if(!admin && themeDetailVO.getVisibility() != CourseVisibility.NONE_OPEN.getVisibility()){
|
|
|
+ throw new HttpBadRequestException("当前用户只能新建自定义课程");
|
|
|
+ }
|
|
|
+ // 检验课程信息
|
|
|
checkThemeInfo(themeDetailVO);
|
|
|
if (themeDetailVO.getGroupId() != null && groupService.getGroupsByOwnerId(themeDetailVO.getOwnerId()).stream()
|
|
|
.map(Group::getId).collect(Collectors.toList()).contains(themeDetailVO.getGroupId())) {
|
|
@@ -106,6 +122,9 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
// 条件符合,可以创建
|
|
|
ThemeDetail themeDetail = themeVOWrapper.unWrapperThemeDetail(themeDetailVO);
|
|
|
themeDetail = themeService.createThemeDetail(themeDetail);
|
|
|
+
|
|
|
+ themeSchedulerService.createNewThemeScheduler(themeDetail);
|
|
|
+
|
|
|
themeDetailVO.setId(themeDetail.getId());
|
|
|
theme2GroupService.create(themeDetailVO.getGroupId(), themeDetailVO.getId());
|
|
|
user2ThemeService.createOperationRelation(userId,themeDetail.getId(),"*");
|
|
@@ -120,8 +139,10 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
// 条件符合,可以创建
|
|
|
ThemeDetail themeDetail = themeVOWrapper.unWrapperThemeDetail(themeDetailVO);
|
|
|
themeDetail = themeService.createThemeDetail(themeDetail);
|
|
|
+ themeSchedulerService.createNewThemeScheduler(themeDetail);
|
|
|
themeDetailVO.setId(themeDetail.getId());
|
|
|
theme2GroupService.create(themeDetailVO.getGroupId(), themeDetailVO.getId());
|
|
|
+ user2ThemeService.createOperationRelation(userId,themeDetail.getId(),"*");
|
|
|
}
|
|
|
} else {
|
|
|
throw new HttpBadRequestException("No right for some group");
|
|
@@ -164,14 +185,17 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
|
|
|
// 课程中的实体信息(课程信息、考试信息、练习信息)
|
|
|
List<EntityVO> entityVOList = courseVO.getEntityVOList();
|
|
|
- // 删除原有的实体
|
|
|
- deleteEntityRelationByThemeId(themeDetailVO.getId());
|
|
|
+
|
|
|
if(entityVOList.size() != 0){
|
|
|
+ // 删除原有的实体
|
|
|
+ deleteEntityRelationByThemeId(themeDetailVO.getId());
|
|
|
checkThemeCourseGroupAndExam(themeDetailVO, entityVOList);
|
|
|
ThemeDetail themeDetail = themeVOWrapper.unWrapperThemeDetail(themeDetailVO);
|
|
|
- Integer status = themeService.updateStatus(themeDetail);
|
|
|
- themeDetail.setStatus(status);
|
|
|
- themeService.updateThemeDetail(themeDetail);
|
|
|
+ Integer updateStatus = themeStatusService.updateStatus(themeDetail);
|
|
|
+ themeDetail.setStatus(updateStatus);
|
|
|
+ ThemeDetail result = themeService.updateThemeDetail(themeDetail);
|
|
|
+ themeSchedulerService.cancelThemeScheduler(themeDetail);
|
|
|
+ themeSchedulerService.createNewThemeScheduler(result);
|
|
|
// 条件符合,可以更新
|
|
|
int index = 0;
|
|
|
for(EntityVO entityVO: entityVOList){
|
|
@@ -182,9 +206,11 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
}
|
|
|
}else{
|
|
|
ThemeDetail themeDetail = themeVOWrapper.unWrapperThemeDetail(themeDetailVO);
|
|
|
- Integer status = themeService.updateStatus(themeDetail);
|
|
|
- themeDetail.setStatus(status);
|
|
|
- themeService.updateThemeDetail(themeDetail);
|
|
|
+ Integer updateStatus = themeStatusService.updateStatus(themeDetail);
|
|
|
+ themeDetail.setStatus(updateStatus);
|
|
|
+ ThemeDetail result = themeService.updateThemeDetail(themeDetail);
|
|
|
+ themeSchedulerService.cancelThemeScheduler(themeDetail);
|
|
|
+ themeSchedulerService.createNewThemeScheduler(result);
|
|
|
}
|
|
|
return courseVO;
|
|
|
}
|
|
@@ -638,8 +664,13 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
|
|
|
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)));
|
|
|
+ if(courseResourceCount != 0){
|
|
|
+ int studyRecordNumber = themeService.getStudyRecord(themeId, studentIds, EntityTypeEnum.COURSE_RESOURCE);
|
|
|
+ themeInfoVO.setLearningCompletedRate((float)(studyRecordNumber/(courseResourceCount*studentNumber*1.0)));
|
|
|
+ }else{
|
|
|
+ themeInfoVO.setLearningCompletedRate(0);
|
|
|
+ }
|
|
|
+
|
|
|
int totalExamCommitNumber = 0;
|
|
|
int examCount = 0;
|
|
|
int totalExerciseCommitNumber = 0;
|