package com.qxueyou.scc.admin.classes.service.impl; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.querydsl.core.QueryResults; import com.querydsl.core.types.Order; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.jpa.impl.JPAQuery; import com.qxueyou.scc.admin.classes.model.ClsSubjectChapter; import com.qxueyou.scc.admin.classes.model.ClsSubjectLecture; import com.qxueyou.scc.admin.classes.service.IClassLectureService; import com.qxueyou.scc.admin.progress.dao.ProgressDAO; import com.qxueyou.scc.admin.progress.model.Progress; import com.qxueyou.scc.admin.progress.model.QProgress; import com.qxueyou.scc.admin.progress.model.view.SubjectProgressTreeV; import com.qxueyou.scc.admin.progress.service.IProgressService; import com.qxueyou.scc.base.model.Pager; import com.qxueyou.scc.base.model.Result; import com.qxueyou.scc.base.service.impl.CommonAppService; import com.qxueyou.scc.base.util.ClientUtils; import com.qxueyou.scc.base.util.CollectionUtils; import com.qxueyou.scc.base.util.QBeanUtils; import com.qxueyou.scc.base.util.QueryDslOptionBuilder; import com.qxueyou.scc.base.util.TraceUtils; import com.qxueyou.scc.msg.model.MsgInfo; import com.qxueyou.scc.msg.service.IMsgInfoService; import com.qxueyou.scc.school.model.SchHandout; import com.qxueyou.scc.teach.res.model.Res; import com.qxueyou.scc.teach.res.model.ResItemDoc; import com.qxueyou.scc.teach.res.service.IResService; import com.qxueyou.scc.teach.subject.model.QSubjectLecture; import com.qxueyou.scc.teach.subject.model.Subject; import com.qxueyou.scc.teach.subject.model.SubjectChapter; import com.qxueyou.scc.teach.subject.model.SubjectLecture; import com.qxueyou.scc.teach.subject.model.view.MyLectureV; import com.qxueyou.scc.teach.subject.model.view.QMyLectureV; import com.qxueyou.scc.teach.subject.service.ILectureService; import com.qxueyou.scc.teach.subject.service.ISubjectService; @Service public class ClassLectureService extends CommonAppService implements IClassLectureService { private final Logger log = LogManager.getLogger(ClassLectureService.class); @Autowired IResService resService; @Autowired ILectureService lectureService; @Autowired IProgressService progressService; @Autowired ISubjectService subjectService; @Autowired ProgressDAO progressDao; @Autowired IMsgInfoService msgInfoService; @Override public Result addChapter(String parentChapterId, String name) { ClsSubjectChapter parent = read(ClsSubjectChapter.class, parentChapterId); ClsSubjectChapter chapter = new ClsSubjectChapter(); TraceUtils.setCreateTrace(chapter); chapter.setName(name); chapter.setParentChapterId(parentChapterId); chapter.setSubjectId(parent.getSubjectId()); chapter.setClassId(parent.getClassId()); save(chapter); return new Result(true, "success", CollectionUtils.newObjectMap("id", chapter.getChapterId(), "name", chapter.getName())); } @Override public List listLectureV(String learnerId, String chapterId, String keyword, Integer pageSize, Integer pageNum, String type) { StringBuffer hql = new StringBuffer("from MyLectureV where subjectId=? and id.userId=?"); List args = CollectionUtils.newList(chapterId, learnerId); List myLectureVList = findList(hql.toString(), new Pager(pageSize, pageNum), args, MyLectureV.class); if(myLectureVList.size() < 1){ }else { hql = new StringBuffer("from MyLectureV where chapterId=? and id.userId=? order by lectureCreateTime desc"); args = CollectionUtils.newList(myLectureVList.get(0).getChapterId(), learnerId); } if (StringUtils.isNotEmpty(type)) { hql.append(" and lectureType=?"); args.add(type); } List result = findList(hql.toString(), new Pager(pageSize, pageNum), args, MyLectureV.class); return result; } /** * 课程课件 * */ @Override public Map listLectureBySubjectOrderCreateTime(String subjectId, String classId, String sort, Pager pager) { Subject subject = this.read(Subject.class, subjectId); if(Subject.TYPE_PUBLIC_SUBJECT == subject.getType()) {//公开课课件 return this.listOpenLectureBySubjectOrderCreateTime(subjectId, sort, pager); } QMyLectureV qMyLectureV = QMyLectureV.myLectureV; OrderSpecifier order = "desc".equals(sort)?new OrderSpecifier(Order.DESC, qMyLectureV.lectureCreateTime): new OrderSpecifier(Order.ASC, qMyLectureV.lectureCreateTime); JPAQuery query = this.getQueryFactory().selectFrom(qMyLectureV) .where(qMyLectureV.subjectId.eq(subjectId). and(qMyLectureV.classId.eq(classId)).and(qMyLectureV.id.userId.eq(ClientUtils.getUserId()))); long count = query.fetchCount(); return CollectionUtils.newObjectMap("count", count, "listData", query.limit(pager.getPageSize()).offset(pager.getOffset()) .orderBy(order) .fetch().stream() .map(tuple -> { Map map = new HashMap(); map.put("lectureName", tuple.getLectureName()); map.put("chapterId", tuple.getChapterId()); map.put("lectureType", tuple.getLectureType()); map.put("progressPercent", tuple.getPercent()); map.put("lectureId", tuple.getId().getLectureId()); map.put("createTime", tuple.getLectureCreateTime()); return map; }).collect(Collectors.toList())); } /** * 公开课课件 * * @param subjectId * @param sort * @param pager * @return */ @Override public Map listOpenLectureBySubjectOrderCreateTime(String subjectId, String sort, Pager pager) { QSubjectLecture qSubjectLecture = QSubjectLecture.subjectLecture; QProgress qProgress = QProgress.progress; OrderSpecifier order = "desc".equals(sort)?new OrderSpecifier(Order.DESC, qSubjectLecture.createTime): new OrderSpecifier(Order.ASC, qSubjectLecture.createTime); JPAQuery query = this.getQueryFactory().selectFrom(qSubjectLecture).where(qSubjectLecture.subjectId.eq(subjectId).and(qSubjectLecture.deleteFlag.isFalse()).and(qSubjectLecture.status.eq(SubjectLecture.STATUS_DRAFT))); long count = query.fetchCount(); return CollectionUtils.newObjectMap("count", count, "listData", query.limit(pager.getPageSize()).offset(pager.getOffset()) .orderBy(order) .fetch().stream() .map(tuple -> { Map map = new HashMap(); map.put("lectureName", tuple.getName()); map.put("chapterId", tuple.getChapterId()); map.put("lectureType", tuple.getLectureType()); map.put("progressPercent", this.getQueryFactory().select(qProgress.progressPercent).from(qProgress).where( qProgress.deleteFlag.isFalse().and(qProgress.targetId.eq(tuple.getLectureId()) .and(qProgress.learnerId.eq(ClientUtils.getUserId())))).fetchFirst()); map.put("lectureId", tuple.getLectureId()); map.put("createTime", tuple.getCreateTime()); return map; }).collect(Collectors.toList())); } @Override public Result updateChapter(String chapterId, String name) { ClsSubjectChapter chapter = read(ClsSubjectChapter.class, chapterId); TraceUtils.setUpdateTrace(chapter); chapter.setName(name); save(chapter); return new Result(true, "success", CollectionUtils.newObjectMap("id", chapter.getChapterId(), "name", name)); } @Override public Result deleteChapter(String[] chapterIds) { for (String chapterId : chapterIds) { deleteChapter(chapterId); } return new Result(true, "success"); } /** * 删除单个章节 * * @param chapterId 章节id * @return */ private Result deleteChapter(String chapterId) { ClsSubjectChapter chapter = read(ClsSubjectChapter.class, chapterId); TraceUtils.setUpdateTrace(chapter); chapter.setDeleteFlag(true); save(chapter); Result result = deleteCourseware4Chapter(chapterId); if (!result.isSuccess()) { return result; } return new Result(true, "success"); } @Override public Result addClsLecture(String chapterId, String resId) { ClsSubjectChapter chapter = read(ClsSubjectChapter.class, chapterId); Res res = resService.read(resId); ClsSubjectLecture lecture = new ClsSubjectLecture(); TraceUtils.setCreateTrace(lecture); lecture.setChapterId(chapterId); lecture.setLectureType(res.getType()); lecture.setName(res.getName()); lecture.setRemark(res.getRemark()); lecture.setSubjectId(chapter.getSubjectId()); lecture.setResItemId(res.getResId()); lecture.setClassId(chapter.getClassId()); lecture.setStatus(res.getStatus()); save(lecture); // 发送消息 doPublishMsg(lecture); return new Result(true, "success"); } //添加课程,发送消息 private void doPublishMsg(ClsSubjectLecture lecture){ Subject subject = this.read(Subject.class, lecture.getSubjectId()); if(!subject.getStatus().equals(Subject.STATUS_ISSUED)){ return ; } //查询直播关联的班级 String hql = "select userId from StuStudent where classId =:classId and deleteFlag is false "; List lstUserIds = this.findByComplexHql(hql, CollectionUtils.newObjectMap("classId",lecture.getClassId()), String.class); if(lstUserIds!=null && lstUserIds.size()>0){ Map attrs = CollectionUtils.newStringMap("lectureId",lecture.getLectureId(),"lectureName",lecture.getName(),"subjectId",subject.getSubjectId(), "lectureType",lecture.getLectureType(),"subjectName",subject.getName()); msgInfoService.doSendTextMsgToUsers(lstUserIds.toArray(new String[lstUserIds.size()]),MsgInfo.TYPE_COURSEWARE,"发布了课件",attrs); } } public Result updateLecturetime(String targetId) { ClsSubjectLecture lecture = read(ClsSubjectLecture.class, targetId); if(lecture == null){ SubjectLecture lecture1 = read(SubjectLecture.class,targetId); TraceUtils.setUpdateTrace(lecture1); lecture1.setUpdateTime(new Date()); lecture1.setUpdator(ClientUtils.getUserId()); save(lecture1); }else { TraceUtils.setUpdateTrace(lecture); lecture.setUpdateTime(new Date()); lecture.setUpdator(ClientUtils.getUserId()); save(lecture); } return new Result(true, "success"); } @Override public Result updateLecture(String lectureId, String resId) { ClsSubjectLecture lecture = read(ClsSubjectLecture.class, lectureId); Res res = resService.read(resId); TraceUtils.setUpdateTrace(lecture); lecture.setLectureType(res.getType()); lecture.setName(res.getName()); lecture.setRemark(res.getRemark()); lecture.setResItemId(res.getResId()); save(lecture); return new Result(true, "success"); } @Override public Result deleteLecture(String[] lectureIds) { for (String lectureId : lectureIds) { deleteLecture(lectureId); } return new Result(true, "success"); } /** * @param lectureId 课件id * @return */ private Result deleteLecture(String lectureId) { ClsSubjectLecture lecture = read(ClsSubjectLecture.class, lectureId); TraceUtils.setUpdateTrace(lecture); lecture.setDeleteFlag(true); save(lecture); deleteProgress(lectureId);// 删除对应的进度 return new Result(true, "success"); } /** * */ private Result deleteProgress(String targetId) { String hql = "update Progress set deleteFlag = true where deleteFlag is false and targetId = ?"; bulkUpdate(hql, new String[]{targetId}); return new Result(true); } @Override public Result doCopyLecture(String lectureId, String destChapterId, String name) { return null; } @Override public Result doMoveLecture(String lectureId, String destChapterId, String name) { return null; } @Override public List listLecture(String chapterId, String keyword, Integer pageSize, Integer pageNum, String type, String classId) { StringBuffer hql = new StringBuffer("from ClsSubjectLecture where chapterId = ? and deleteFlag is false"); List args = CollectionUtils.newList(chapterId); if (StringUtils.isNotEmpty(type)) { hql.append(" and lectureType=? order by createTime desc"); args.add(type); } else { hql.append(" order by createTime desc"); } List result = findList(hql.toString(), new Pager(pageSize, pageNum), args, ClsSubjectLecture.class); return result; } @Override public List> listLectureBySubject(String subjectId, String type, String classId) { StringBuffer hql = new StringBuffer("select name as lectureName, " + " lectureId as lectureId, " + " lectureType as lectureType, " + " chapterId as chapterId, " + " status as status, " + " updateTime as updateTime " + " from ClsSubjectLecture where subjectId = :subjectId and classId = :classId and deleteFlag is false and status = :status"); Map args = CollectionUtils.newObjectMap("subjectId", subjectId, "classId", classId, "status", Res.STATUS_DRAFT); if (StringUtils.isNotEmpty(type)) { hql.append(" and lectureType= :lectureType"); args.put("lectureType", type); } hql.append(" order by createTime desc"); return this.findListWithMapByHql(hql.toString(), args); } @Override public List> listStuLectureBySubject(String subjectId, String classId) { if(StringUtils.isEmpty(subjectId) || StringUtils.isEmpty(classId)) { return new ArrayList<>(); } QMyLectureV qMyLectureV = QMyLectureV.myLectureV; return this.getQueryFactory().selectFrom(qMyLectureV) .where(qMyLectureV.classId.eq(classId).and( qMyLectureV.subjectId.eq(subjectId).and(qMyLectureV.id.userId.eq(ClientUtils.getUserId())))) .orderBy(qMyLectureV.lectureCreateTime.desc()).fetch().stream().map(tuple -> { Map map = new HashMap(6); map.put("lectureName", tuple.getLectureName()); map.put("lectureId", tuple.getId().getLectureId()); map.put("lectureType", tuple.getLectureType()); map.put("chapterId", tuple.getChapterId()); map.put("subjectId", tuple.getSubjectId()); map.put("progressPercent", tuple.getPercent()); map.put("createTime", tuple.getLectureCreateTime()); return map; }).collect(Collectors.toList()); } /** * 我的公开课课件查询 * * @param subjectId * @return */ public List> listStuLectureByOpenSubject(String subjectId) { QSubjectLecture qSubjectLecture = QSubjectLecture.subjectLecture; QProgress qProgress = QProgress.progress; return this.getQueryFactory().selectFrom(qSubjectLecture) .where(qSubjectLecture.subjectId.eq(subjectId).and(qSubjectLecture.status.eq(SubjectLecture.STATUS_DRAFT)).and(qSubjectLecture.deleteFlag.isFalse())) .orderBy(qSubjectLecture.createTime.desc()).fetch().stream().map(tuple -> { Map map = new HashMap(6); map.put("lectureName", tuple.getName()); map.put("lectureId", tuple.getLectureId()); map.put("lectureType", tuple.getLectureType()); map.put("chapterId", tuple.getChapterId()); map.put("subjectId", tuple.getSubjectId()); map.put("progressPercent", this.getQueryFactory().select(qProgress.progressPercent).from(qProgress).where( qProgress.deleteFlag.isFalse().and(qProgress.targetId.eq(tuple.getLectureId()) .and(qProgress.learnerId.eq(ClientUtils.getUserId())))).fetchFirst()); map.put("createTime", tuple.getCreateTime()); map.put("updateTime", tuple.getUpdateTime()); return map; }).collect(Collectors.toList()); } /** * 查询数量 * * @param subjectId * @param classId * @return */ @Override public long stuLectureCountBySubject(String subjectId, String classId) { QMyLectureV qMyLectureV = QMyLectureV.myLectureV; return this.getQueryFactory().selectFrom(qMyLectureV) .where(qMyLectureV.classId.eq(classId).and( qMyLectureV.subjectId.eq(subjectId).and(qMyLectureV.id.userId.eq(ClientUtils.getUserId())))).fetchCount(); } @Override public Result readLectureAccessPath(String lectureId, String attribute) { ClsSubjectLecture lecture = read(ClsSubjectLecture.class, lectureId); String resItemId = null; if(lecture == null) { resItemId = read(SubjectLecture.class, lectureId).getResItemId();//班级课件 }else { resItemId = lecture.getResItemId(); } return resService.readAccessPath(resItemId, attribute); } @Override public ClsSubjectLecture readClsLecture(String id) { return read(ClsSubjectLecture.class, id); } @Override public ClsSubjectChapter readChapter(String chapterId) { return read(ClsSubjectChapter.class, chapterId); } @Override public int listLectureCount(String chapterId, String keyword, String type) { String hql = "from ClsSubjectLecture where deleteFlag is false and chapterId =:chapterId "; Map args = CollectionUtils.newObjectMap("chapterId", chapterId); if (StringUtils.isNotBlank(type)) { hql = hql.concat(" and lectureType =:type"); args.put("type", type); } int count = findCountByComplexHql(hql, args); return count; } @Override public List getListChapter(String classId, String subjectId, String parentChapterId) { StringBuffer hql = new StringBuffer( "from ClsSubjectChapter where classId=? and subjectId=? and deleteFlag is false "); List args = CollectionUtils.newList(classId,subjectId); if (StringUtils.isNotEmpty(parentChapterId)) { hql = hql.append(" and parentChapterId=? "); args.add(parentChapterId); } List result = find(hql.toString(), args, ClsSubjectChapter.class); return result; } public List getListOpenChapter(String subjectId) { StringBuffer hql = new StringBuffer( "from SubjectChapter where subjectId=? and deleteFlag is false "); List args = CollectionUtils.newList(subjectId); return find(hql.toString(), args, SubjectChapter.class); } @Override public List doGetListChapter(String classId,String subjectId, String parentChapterId) { List result = getListChapter(classId,subjectId, StringUtils.isEmpty(parentChapterId)?ClsSubjectChapter.ROOT_CHAPTER_ID:parentChapterId); return result; } @Override public Result doClearLecturesToClass( String classId,String subjectId) { this.bulkUpdate("update ClsSubjectLecture set deleteFlag = true where classId=? and subjectId = ? ", new String[]{classId,subjectId}); this.bulkUpdate("update ClsSubjectChapter set deleteFlag = true where classId=? and subjectId = ? ", new String[]{classId,subjectId}); return new Result(true); } @Override public Result doCopyLecturesToClass(String origSubjectId, String subjectId, String classId) { Map subjectIdMap = CollectionUtils.newStringMap(SubjectChapter.ROOT_CHAPTER_ID, SubjectChapter.ROOT_CHAPTER_ID); List chapterLst = lectureService.getAllChapterBySubjectId(origSubjectId); ClsSubjectChapter clsChapter = null; for (SubjectChapter subjectChapter : chapterLst) { clsChapter = new ClsSubjectChapter(); clsChapter.setClassId(classId); clsChapter.setName(subjectChapter.getName()); clsChapter.setOrderNum(subjectChapter.getOrderNum()); clsChapter.setParentChapterId(subjectIdMap.get(subjectChapter.getParentChapterId())); clsChapter.setSubjectId(subjectId); TraceUtils.setCreateTrace(clsChapter); clsChapter.setCreateTime(subjectChapter.getCreateTime()); save(clsChapter); subjectIdMap.put(subjectChapter.getChapterId(), clsChapter.getChapterId()); } List lectureLst = lectureService.listLectureBySubjectId(origSubjectId); ClsSubjectLecture clsLecture = null; for (SubjectLecture lecture : lectureLst) { clsLecture = new ClsSubjectLecture(); clsLecture.setChapterId(subjectIdMap.get(lecture.getChapterId())); clsLecture.setClassId(classId); clsLecture.setLectureType(lecture.getLectureType()); clsLecture.setName(lecture.getName()); clsLecture.setRemark(lecture.getRemark()); clsLecture.setResItemId(lecture.getResItemId()); clsLecture.setSubjectId(subjectId); clsLecture.setDeleteFlag(false); clsLecture.setStatus(lecture.getStatus()); TraceUtils.setCreateTrace(clsLecture); save(clsLecture); } return new Result(true); } @Override public Result doStudy(String clsLectureId, Double from, Double to) { return progressService.addProgress(Progress.PROGRESS_TYPE_LECTURE, clsLectureId, from.intValue(), to.intValue(), ClientUtils.getUserId()); } @Override public List listLecture(String subjectId) { StringBuffer hql = new StringBuffer("from ClsSubjectLecture where subjectId = ? and deleteFlag is false"); List args = CollectionUtils.newList(subjectId); return find(hql.toString(), args, ClsSubjectLecture.class); } @Override public Result listSubjectLecture(String classId, String sort, Pager pager) { if(StringUtils.isEmpty(classId)) { return new Result(false, "班级id不能为空"); } QMyLectureV qMyLectureV = QMyLectureV.myLectureV; OrderSpecifier order = "desc".equals(sort)?new OrderSpecifier(Order.DESC, qMyLectureV.lectureCreateTime): new OrderSpecifier(Order.ASC, qMyLectureV.lectureCreateTime); JPAQuery query = this.getQueryFactory() .selectFrom(qMyLectureV) .where(new QueryDslOptionBuilder() .and(qMyLectureV.classId::eq, classId).and(qMyLectureV.id.userId::eq,ClientUtils.getUserId()) .build() ); long count = query.fetchCount(); // 获取查询结果集合 QueryResults results = query.limit(pager.getPageSize()).offset(pager.getOffset()).orderBy(order).fetchResults(); List> resultLst = results.getResults() .stream() .map(tuple -> { Map map = new HashMap(8); map.put("lectureName", tuple.getLectureName()); map.put("lectureId", tuple.getId().getLectureId()); map.put("lectureType", tuple.getLectureType()); map.put("chapterId", tuple.getChapterId()); map.put("subjectName", tuple.getSubjectName()); map.put("subjectId", tuple.getSubjectId()); map.put("progressPercent", tuple.getPercent()); map.put("createTime", tuple.getLectureCreateTime()); return map; }).collect(Collectors.toList()); return new Result(true, "", CollectionUtils.newObjectMap("count", count, "listData", resultLst)); } @Override public List getChapterTreeVList(String subjectId, String parentChapterId) { if (parentChapterId == null) { return progressService.getSubjectChapterTreeVList(subjectId, ClientUtils.getUserId()); } return progressService.getSubjectChapterTreeVList(parentChapterId, ClientUtils.getUserId()); } /** * 删除对应的课件 * * @param chapterId * @return */ private Result deleteCourseware4Chapter(String chapterId) { this.bulkUpdate("update ClsSubjectLecture set deleteFlag = true where chapterId = ?", new String[]{chapterId}); return new Result(true); } /** * 获取章节下的课件 * * @param chapterLst * @param lectures * @return */ public List getChapterLectures(List chapterLst, List> lectures){ if (chapterLst != null && chapterLst.size() > 0 && lectures != null) { for (ClsSubjectChapter objClsSubjectChapter : chapterLst) { for (Map objClsSubjectLecture : lectures) { if (objClsSubjectChapter.getChapterId().equals(objClsSubjectLecture.get("chapterId"))) { objClsSubjectChapter.getLectures().add(objClsSubjectLecture); } } } this.getTopChapters(chapterLst); for (int i=chapterLst.size()-1;i>=0;i--) { ClsSubjectChapter objClsSubjectChapter = chapterLst.get(i); if(objClsSubjectChapter.getLectures() == null || objClsSubjectChapter.getLectures().isEmpty()) { chapterLst.remove(i); } } } return chapterLst; } /** * 获取章节的第一层数据 * * @param chapterLst * @return */ private List getTopChapters(List chapterLst){ int count = 0; if (chapterLst != null && chapterLst.size() > 0) { for (int i=chapterLst.size()-1;i>=0;i--) { ClsSubjectChapter objClsSubjectChapter = chapterLst.get(i); for (ClsSubjectChapter objClsSubjectChapter2 : chapterLst) { if(StringUtils.isNotBlank(objClsSubjectChapter.getChapterId()) && !ClsSubjectChapter.ROOT_CHAPTER_ID.equals(objClsSubjectChapter.getParentChapterId()) && objClsSubjectChapter.getChapterId().equals(objClsSubjectChapter2.getParentChapterId()) && objClsSubjectChapter2.getLectures() != null) { if(objClsSubjectChapter.getLectures() == null) { objClsSubjectChapter.setLectures(new ArrayList>()); } objClsSubjectChapter.getLectures().addAll(objClsSubjectChapter2.getLectures()); count++; objClsSubjectChapter2.setLectures(null); break; } } } if(count != 0) { chapterLst = this.getTopChapters(chapterLst); } } return chapterLst; } @Override public int readDocPageCount(String resItemId) { ResItemDoc resItemDoc = read(ResItemDoc.class, resItemId); if (resItemDoc == null || ResItemDoc.STATUS_DRAFT != resItemDoc.getStatus()) { return 0; } SchHandout schHandout = read(SchHandout.class, resItemDoc.getHandoutId()); if (schHandout == null) { return 0; } return schHandout.getPageCount(); } /** * 课件按目录分类 * * @param classId * @param subjectId * @param type * @return */ public Result coursewareChapterList(String classId,String subjectId, String type) { Subject subject = this.read(Subject.class, subjectId); if(Subject.TYPE_PUBLIC_SUBJECT == subject.getType() || Subject.TYPE_ORG_SUBJECT == subject.getType()) {//公开课和管理员课程 QSubjectLecture qSubjectLecture = QSubjectLecture.subjectLecture; //课件 List> lectures = this.listStuLectureByOpenSubject(subjectId); List lstSubjectChapterLst = this.getListOpenChapter(subjectId); List lstClsSubjectChapter = new ArrayList<>(); if(lstSubjectChapterLst != null && !lstSubjectChapterLst.isEmpty()) { ClsSubjectChapter objClsSubjectChapter = null; for(SubjectChapter objSubjectChapter : lstSubjectChapterLst) { objClsSubjectChapter = new ClsSubjectChapter(); try { BeanUtils.copyProperties(objClsSubjectChapter, objSubjectChapter); } catch (IllegalAccessException e) { log.error("拷贝属性失败BeanUtils.copyProperties(objClsSubjectChapter, objSubjectChapter)", e); } catch (InvocationTargetException e) { log.error("拷贝属性失败BeanUtils.copyProperties(objClsSubjectChapter, objSubjectChapter)", e); } lstClsSubjectChapter.add(objClsSubjectChapter); } } //章节 List chapterLst = this.getChapterLectures(lstClsSubjectChapter, lectures); long count = this.getQueryFactory().selectFrom(qSubjectLecture) .where(qSubjectLecture.subjectId.eq(subjectId).and(qSubjectLecture.deleteFlag.isFalse()). and(qSubjectLecture.status.eq(SubjectLecture.STATUS_DRAFT))).fetchCount(); return new Result(true, "success", CollectionUtils.newObjectMap("count",count, "listData", QBeanUtils.listBean2ListMap(chapterLst, CollectionUtils.newStringMap("name", "name", "chapterId", "chapterId", "lectures", "lectures")))); }else{ //课件 List> lectures = this.listStuLectureBySubject(subjectId, classId); //章节 List chapterLst = this.getChapterLectures(this.getListChapter(classId, subjectId, null), lectures); return new Result(true, "success", CollectionUtils.newObjectMap("count",this.stuLectureCountBySubject(subjectId, classId), "listData", QBeanUtils.listBean2ListMap(chapterLst, CollectionUtils.newStringMap("name", "name", "chapterId", "chapterId", "lectures", "lectures")))); } } }