|
@@ -23,12 +23,10 @@ import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import javax.mail.Session;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
-import java.sql.Time;
|
|
|
import java.sql.Timestamp;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -81,6 +79,8 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
@Autowired
|
|
|
private User2RoleService user2RoleService;
|
|
|
@Autowired
|
|
|
+ private OperationRecourseService operationRecourseService;
|
|
|
+ @Autowired
|
|
|
private RoleService roleService;
|
|
|
@Autowired
|
|
|
private OSSLogic ossLogic;
|
|
@@ -109,11 +109,65 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
|
|
|
@Override
|
|
|
public List<GroupVO> getForkCourseGroups(long themeId) {
|
|
|
- Theme2Group theme2Group = theme2GroupService.findByThemeId(themeId);
|
|
|
+ // 判断对被fork课程的使用权限
|
|
|
Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
|
+ List<User2Theme> user2ThemeList = user2ThemeService.findAllByUserIdAndThemeId(userId, themeId);
|
|
|
+ // 使用权限要为* 或者 use
|
|
|
+ List<User2Theme> user2Themes = user2ThemeList.stream().filter(user2Theme -> user2Theme.getOperation() != User2Theme.AUTH_VIEW).collect(Collectors.toList());
|
|
|
+ if(user2Themes.size() <= 0){
|
|
|
+ throw new HttpBadRequestException("fork失败,当前用户并无对此课程的使用权限!");
|
|
|
+ }
|
|
|
+ // 判断对被fork课程的章节是否是 已授权的非自定义课程中的章节
|
|
|
+ // 获取被fork课程的所有章节 -> 所有公开的章节
|
|
|
+ List<Long> courseResourceIdList = themeService.getThemeEntityRelations(themeId, EntityTypeEnum.COURSE_RESOURCE).stream().map(ThemeEntityRelations::getEntityId).collect(Collectors.toList());
|
|
|
+ boolean canFork = true;
|
|
|
+ String message = "";
|
|
|
+ // 如果存在章节则需要判断
|
|
|
+ if(courseResourceIdList.size() > 0){
|
|
|
+ List<Long> publicResourceIdList = courseResourceService.getCourseResourceById(courseResourceIdList).stream()
|
|
|
+ .filter(resource -> resource.getPublicStatus() == CourseResource.IS_PUBLIC)
|
|
|
+ .map(CourseResource::getId).collect(Collectors.toList());
|
|
|
+ // 如果存在公开的章节则需要判断
|
|
|
+ if(publicResourceIdList.size() > 0){
|
|
|
+ // 根据这些公开章节获取所有已使用当前章节的 公开课程
|
|
|
+ for(Long resourceId : publicResourceIdList){
|
|
|
+ List<OperationResource> operationRecourseList = operationRecourseService.getOperationRecourseList(userId, User2Theme.AUTH_VIEW, resourceId, CourseResource.NOT_Deleted, CourseResource.IS_PUBLIC, ThemeDetail.IS_PUBLIC, ThemeDetail.COURSE, ThemeDetail.NOT_DELETED);
|
|
|
+ if(operationRecourseList.size() <= 0){
|
|
|
+ canFork = false;
|
|
|
+ message += " \"" + courseResourceService.getCourseResourceByResourceId(resourceId).getTitle() + "\"";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!canFork){
|
|
|
+ throw new HttpBadRequestException("fork失败,被fork的课程中含有未授权的课程中的章节:" + message + "!");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 允许被fork
|
|
|
+ Theme2Group theme2Group = theme2GroupService.findByThemeId(themeId);
|
|
|
List<Group> groups = groupService.getGroupsByOwnerId(userId);
|
|
|
List<GroupVO> groupVOs = groupVOWrapper.wrap(groups);
|
|
|
return groupVOs.stream().filter(groupVO -> !groupVO.getId().equals(theme2Group.getGroupId())).collect(Collectors.toList());
|
|
|
+
|
|
|
+// List<List<Boolean>> flagBooleanList = publicResourceIdList.stream().map(publicResourceId -> {
|
|
|
+// List<Long> themeDetailIdList = themeService.getThemeEntityRelationsByEntityId(publicResourceId, EntityTypeEnum.COURSE_RESOURCE)
|
|
|
+// .stream().map(ThemeEntityRelations::getThemeId).collect(Collectors.toList());
|
|
|
+// // 根据这些公开章节获取所有已使用当前章节的公开课程,判断是否具有这些公开课程的使用权限
|
|
|
+// return themeDetailIdList.stream().map(themeDetailId -> {
|
|
|
+// // 获取公开课程,判断使用去哪些
|
|
|
+// if(themeService.getThemeDetailById(themeDetailId)!=null && themeService.getThemeDetailById(themeDetailId).getPublicStatus() == ThemeDetail.IS_PUBLIC){
|
|
|
+// if (user2ThemeService.findByUserIdAndThemeIdAndOperationNot(userId, themeDetailId, User2Theme.AUTH_VIEW).size() > 0) {
|
|
|
+// return true;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return false;
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+// }).collect(Collectors.toList());
|
|
|
+// for(List<Boolean> flags : flagBooleanList){
|
|
|
+// if(flags.contains(true)){
|
|
|
+// canFork = true;
|
|
|
+// }
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -896,6 +950,24 @@ public class ThemeLogicImpl implements ThemeLogic {
|
|
|
Long userId = (Long) SecurityUtils.getSubject().getSession().getAttribute("userId");
|
|
|
// 章节实体
|
|
|
List<CourseResourceVO> courseResourceVOS = entityVOList.stream().filter(entityVO -> entityVO.getEntityType().equals(EntityTypeEnum.COURSE_RESOURCE)).map(entityVO -> {
|
|
|
+ // 判断对add的章节是否是 已授权的非自定义课程中的章节
|
|
|
+ boolean canAdd = true;
|
|
|
+ String message = "";
|
|
|
+ CourseResource resource = courseResourceService.getCourseResourceByResourceId(entityVO.getEntityId());
|
|
|
+ // 如果存在公开的章节则需要判断
|
|
|
+ if(resource.getPublicStatus() == CourseResource.IS_PUBLIC){
|
|
|
+ // 根据这些公开章节获取所有已使用当前章节的 公开课程
|
|
|
+ List<OperationResource> operationRecourseList = operationRecourseService.getOperationRecourseList(userId, User2Theme.AUTH_VIEW, resource.getId(), CourseResource.NOT_Deleted, CourseResource.IS_PUBLIC, ThemeDetail.IS_PUBLIC, ThemeDetail.COURSE, ThemeDetail.NOT_DELETED);
|
|
|
+ if(operationRecourseList.size() <= 0){
|
|
|
+ canAdd = false;
|
|
|
+ message += " \"" + resource.getTitle() + "\"";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(!canAdd){
|
|
|
+ throw new HttpBadRequestException("添加"+message+"章节失败,您未此章节所属公开课程的使用权限!");
|
|
|
+ }
|
|
|
+
|
|
|
// entityVO.getThemeId()此时entityVO中传了当前课程的id
|
|
|
ThemeDetail themeDetail = themeService.getThemeDetailById(entityVO.getThemeId());
|
|
|
// 根据课程的公开类型 设置章节的默认预览状态
|