|
@@ -1,6 +1,7 @@
|
|
|
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.*;
|
|
@@ -9,12 +10,15 @@ 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;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+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;
|
|
@@ -74,6 +78,7 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
private OSSLogic ossLogic;
|
|
|
@Autowired
|
|
|
private CourseResourceService courseResourceService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private CourseResourceVOWrapper courseResourceVOWrapper;
|
|
|
@Autowired
|
|
@@ -220,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);
|
|
@@ -242,9 +252,18 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Page<ThemeDetailVO> getThemeList(Pageable pageable, String keyword, int type) {
|
|
|
- Page<ThemeDetail> themeDetails = themeService.getThemeDetails(pageable, keyword, type);
|
|
|
- return themeDetails.map(themeVOWrapper::wrapperThemeDetail);
|
|
|
+ public List<ThemeDetailVO> getThemeList(Pageable pageable, String keyword) {
|
|
|
+ Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
|
+ List<ThemeDetail> themeDetailList = themeService.getPlatformThemeDetails();
|
|
|
+ themeDetailList.addAll(themeService.getCourseByParticipant(userId).stream()
|
|
|
+ .filter(themeDetail -> themeDetail.getVisibility()== CourseVisibility.NONE_OPEN.getVisibility())
|
|
|
+ .collect(Collectors.toList()));
|
|
|
+ List<ThemeDetailVO> result = themeDetailList.stream()
|
|
|
+ .filter(themeDetail -> themeDetail.getTitle().contains(keyword))
|
|
|
+ .map(themeVOWrapper::wrapperThemeDetail)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -343,6 +362,15 @@ 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();
|
|
@@ -367,6 +395,38 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
return courseVO;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public CourseVO getCourse(Long id) {
|
|
|
+ ThemeDetail themeDetail = themeService.getThemeDetailById(id);
|
|
|
+ Long 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return themeVOWrapper.wrapTheme2CourseVO(theme,themeEntityRelations);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// 获取themeIds的所有主题课程信息
|
|
|
@Override
|
|
|
public Page<CourseVO> getCoursesByThemeIds(Long[] ids, Pageable pageable, long total, int type) {
|
|
@@ -454,8 +514,12 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
|
|
|
@Override
|
|
|
public List<CourseVO> getCourses() {
|
|
|
+ Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
|
List<CourseVO> courseVOList = Lists.newArrayList();
|
|
|
- Iterable<ThemeDetail> themeDetailList = themeService.getThemeDetails();
|
|
|
+ List<ThemeDetail> themeDetailList = themeService.getPlatformThemeDetails();
|
|
|
+ themeDetailList.addAll(themeService.getCourseByParticipant(userId).stream()
|
|
|
+ .filter(themeDetail -> themeDetail.getVisibility()== CourseVisibility.NONE_OPEN.getVisibility())
|
|
|
+ .collect(Collectors.toList()));
|
|
|
for (ThemeDetail t: themeDetailList) {
|
|
|
//主题课程类型 存储 exam或者
|
|
|
List<Exam> examList = themeService.getThemeEntityRelations(t.getId(),EntityTypeEnum.EXAM).
|
|
@@ -482,6 +546,19 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public CourseResourceVO getCourseResource(long courseId, long resourceId) {
|
|
|
+ ThemeEntityRelations themeEntityRelations = themeService
|
|
|
+ .checkRelationBetweenThemeAndEntity(courseId, resourceId, EntityTypeEnum.COURSE_RESOURCE);
|
|
|
+ if (themeEntityRelations == null)
|
|
|
+ throw new HttpNotFoundException("This Course does't contain this resource");
|
|
|
+ if(themeVOWrapper.checkIfProduct(courseId) && !themeVOWrapper.varifyIfPurchase(courseId) && !themeEntityRelations.isPreviewable()){
|
|
|
+ throw new HttpForbiddenException("This Course should buy and resource can't preview");
|
|
|
+ }
|
|
|
+ CourseResource courseResource = courseResourceService.getCourseResourceByResourceId(resourceId);
|
|
|
+ return courseResourceVOWrapper.wrap(courseResource);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public ThemeInfoVO getThemeInfoByThemeId(Long themeId) {
|
|
|
ThemeInfoVO themeInfoVO = new ThemeInfoVO();
|
|
|
ThemeDetail themeDetail = themeService.getThemeDetailById(themeId);
|