|
@@ -1,5 +1,6 @@
|
|
|
package com.ynfy.buss.course.coursecatalog.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ynfy.buss.course.coursecatalog.entity.CourseCatalog;
|
|
@@ -7,16 +8,17 @@ import com.ynfy.buss.course.coursecatalog.enums.CatalogType;
|
|
|
import com.ynfy.buss.course.coursecatalog.enums.ResourceType;
|
|
|
import com.ynfy.buss.course.coursecatalog.mapper.CourseCatalogMapper;
|
|
|
import com.ynfy.buss.course.coursecatalog.service.ICourseCatalogService;
|
|
|
+import com.ynfy.buss.course.usercoursecatalog.entity.UserCourseCatalog;
|
|
|
+import com.ynfy.buss.course.usercoursecatalog.service.IUserCourseCatalogService;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.jeecg.common.util.CommonUtils;
|
|
|
+import org.apache.shiro.SecurityUtils;
|
|
|
+import org.jeecg.common.system.vo.LoginUser;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Collections;
|
|
|
-import java.util.Comparator;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
@@ -28,6 +30,10 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
public class CourseCatalogServiceImpl extends ServiceImpl<CourseCatalogMapper, CourseCatalog> implements ICourseCatalogService {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IUserCourseCatalogService userCourseCatalogService;
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 删除
|
|
|
*
|
|
@@ -51,6 +57,9 @@ public class CourseCatalogServiceImpl extends ServiceImpl<CourseCatalogMapper, C
|
|
|
//根节点
|
|
|
item.setCourseId(courseId);
|
|
|
item.setSort(sort);
|
|
|
+ if (ResourceType.FILE.getCode().equals(item.getResourceType())) {//如果是文档
|
|
|
+ item.setVideoHour(null);
|
|
|
+ }
|
|
|
sort++;
|
|
|
newCatalogList.add(item);
|
|
|
|
|
@@ -60,6 +69,9 @@ public class CourseCatalogServiceImpl extends ServiceImpl<CourseCatalogMapper, C
|
|
|
for (CourseCatalog child : item.getChildList()) {
|
|
|
child.setCourseId(courseId);
|
|
|
child.setSort(index);
|
|
|
+ if (ResourceType.FILE.getCode().equals(child.getResourceType())) {
|
|
|
+ child.setVideoHour(null);
|
|
|
+ }
|
|
|
newCatalogList.add(child);
|
|
|
index++;
|
|
|
}
|
|
@@ -106,4 +118,83 @@ public class CourseCatalogServiceImpl extends ServiceImpl<CourseCatalogMapper, C
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查上一个任务是否完成
|
|
|
+ *
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public boolean checkPreTaskComplete(String id) {
|
|
|
+ LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ CourseCatalog courseCatalog = getById(id);
|
|
|
+ if (!Objects.isNull(courseCatalog)) {
|
|
|
+ if (StringUtils.isNotBlank(courseCatalog.getParentId())) { //点击了目录下的任务
|
|
|
+ if (courseCatalog.getSort() > 1) { //如果点击的是目录下的第n(n>1)个任务,获取本目录下的点击任务的前一个任务
|
|
|
+ return isComplete(user, getPre(courseCatalog.getParentId(), courseCatalog.getSort() - 1).getId());
|
|
|
+ } else { //sort == 1 //如果点击的是目录下的第一个任务
|
|
|
+ CourseCatalog parent = getParent(courseCatalog.getParentId()); //获取父节点
|
|
|
+ if (!Objects.isNull(parent) && parent.getSort() > 1) {//不是第一个根节点,获取前一个根节点
|
|
|
+ return calcIsFinish(user, parent.getSort() - 1);
|
|
|
+ } else { //是第一个根节点
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else { //点击了根节点的任务
|
|
|
+ if (courseCatalog.getSort() > 1) {
|
|
|
+ return calcIsFinish(user, courseCatalog.getSort() - 1);
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ public CourseCatalog getPre(String parentId, Integer sort) {
|
|
|
+ LambdaQueryWrapper<CourseCatalog> query = new LambdaQueryWrapper<CourseCatalog>().eq(CourseCatalog::getParentId, parentId)
|
|
|
+ .eq(CourseCatalog::getSort, sort);
|
|
|
+ return getOne(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CourseCatalog getParent(String id) {
|
|
|
+ LambdaQueryWrapper<CourseCatalog> query = new LambdaQueryWrapper<CourseCatalog>().eq(CourseCatalog::getId, id);
|
|
|
+ return getOne(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CourseCatalog getRootPre(Integer sort) {
|
|
|
+ LambdaQueryWrapper<CourseCatalog> query = new LambdaQueryWrapper<CourseCatalog>().eq(CourseCatalog::getSort, sort)
|
|
|
+ .isNull(CourseCatalog::getParentId);
|
|
|
+ return getOne(query);
|
|
|
+ }
|
|
|
+
|
|
|
+ public CourseCatalog getLastTaskOfCatalog(String id) {
|
|
|
+ LambdaQueryWrapper<CourseCatalog> query = new LambdaQueryWrapper<CourseCatalog>().eq(CourseCatalog::getParentId, id)
|
|
|
+ .orderByDesc(CourseCatalog::getSort);
|
|
|
+ List<CourseCatalog> courseCatalogList = list(query);
|
|
|
+ return !CollectionUtils.isEmpty(courseCatalogList) ? courseCatalogList.get(0) : null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isComplete(LoginUser user, String courseCatalogId) {
|
|
|
+ UserCourseCatalog rootUCC = userCourseCatalogService.findUserCatalog(user.getId(), courseCatalogId);
|
|
|
+ if (!Objects.isNull(rootUCC) && !Objects.isNull(rootUCC.getLearnProcess()) && rootUCC.getLearnProcess() >= 1) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean calcIsFinish(LoginUser user, Integer sort) {
|
|
|
+ CourseCatalog rootPre = getRootPre(sort);
|
|
|
+ if (!Objects.isNull(rootPre)) {
|
|
|
+ if (CatalogType.TASK.getCode().equals(rootPre.getType())) {//前一个根节点是任务类型
|
|
|
+ return isComplete(user, rootPre.getId());
|
|
|
+ } else { //前一个根节点是目录类型,获取目录下的最后一个任务
|
|
|
+ CourseCatalog lastTaskOfCatalog = getLastTaskOfCatalog(rootPre.getId());
|
|
|
+ return isComplete(user, lastTaskOfCatalog.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|