package com.qxueyou.scc.school.service.impl; import java.math.BigDecimal; import java.math.BigInteger; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; 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.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.TraceUtils; import com.qxueyou.scc.base.util.UUIDUtils; import com.qxueyou.scc.exercise.model.ExerciseGroup; import com.qxueyou.scc.exercise.service.IExerciseService; import com.qxueyou.scc.media.model.MediaVideo; import com.qxueyou.scc.media.service.IMediaVideoService; import com.qxueyou.scc.org.model.OrgText; import com.qxueyou.scc.org.service.IOrgTextService; import com.qxueyou.scc.school.model.SchArticle; import com.qxueyou.scc.school.model.SchClassSubject; import com.qxueyou.scc.school.model.SchCourseware; import com.qxueyou.scc.school.model.SchHandout; import com.qxueyou.scc.school.service.IArticleService; import com.qxueyou.scc.school.service.ICourseWareService; import com.qxueyou.scc.school.service.IHandoutService; import com.qxueyou.scc.school.service.ILessonService; import com.qxueyou.scc.teach.subject.model.Subject; import com.qxueyou.scc.teach.subject.model.SubjectChapter; /** * 课件管理 * * @author lihanqi * */ @Service public class CoursewareService extends CommonAppService implements ICourseWareService { private static Logger log = LogManager.getLogger("CoursewareService"); @Autowired IArticleService articleService; @Autowired IExerciseService exerciseService; @Autowired IHandoutService handoutService; @Autowired ILessonService lessonService; @Autowired IMediaVideoService mediaVideoService; @Autowired IOrgTextService orgTextService; /** * 新增章节 * * @param name * @param parentChapterId * @return */ public Result addOrUpdateChapter(String chapterId, String subjectId, String name, String parentChapterId){ if(StringUtils.isEmpty(subjectId) || StringUtils.isEmpty(name)){ return new Result(false, "参数错误"); } SubjectChapter objSchChapter = null; if(StringUtils.isEmpty(chapterId)){ objSchChapter = new SubjectChapter(); String uuid = UUIDUtils.generateUUID().replace("-", ""); objSchChapter.setChapterId(uuid); objSchChapter.setParentChapterId(StringUtils.isEmpty(parentChapterId) ? uuid : parentChapterId); objSchChapter.setDeleteFlag(false); TraceUtils.setCreateTrace(objSchChapter); }else{ objSchChapter = this.read(SubjectChapter.class, chapterId); TraceUtils.setUpdateTrace(objSchChapter); } objSchChapter.setName(name); objSchChapter.setParentChapterId(parentChapterId); objSchChapter.setSubjectId(subjectId); this.save(objSchChapter); return new Result(true,"",objSchChapter); } /** * 删除章节 * * @param chapterId * @return */ public Result deleteChapter(String[] chapterIds){ if(chapterIds.length == 0){ return new Result(false, "参数错误"); } int iCount = 0; for(String chapterId : chapterIds){//级联删除课件 SubjectChapter chapter = this.read(SubjectChapter.class, chapterId); if(chapter != null && StringUtils.isEmpty(chapter.getParentChapterId())){ iCount += this.findCount("from SchCourseware where chapterId = ? and cType = ?", CollectionUtils.newList(chapterId, 6)); } this.deleteCourseWare(null, chapterId); } this.bulkUpdateInLoop("update SchChapter set deleteFlag = true where chapterId = ?", chapterIds); return new Result(true, "", iCount); } /** * 拷贝课件 * * @param type 课件类型 * @param id 主键 * @param subjectId 课程 * @param collegeCourseId 科目 * @param chapterId 章节 * @return */ public Result doCopyCourseware(String type, String id, String subjectId, String collegeCourseId, String chapterId){ try { subjectId = StringUtils.isEmpty(subjectId)?null:subjectId; chapterId = StringUtils.isEmpty(chapterId)?null:chapterId; collegeCourseId = StringUtils.isEmpty(collegeCourseId)?null:collegeCourseId; Subject subject = this.read(Subject.class, subjectId); String subjectName = subject == null?null:subject.getName(); if(SchCourseware.COURSEWARE_TYPE_ARTICLE.equals(type)){ SchArticle article = this.read(SchArticle.class, id); SchArticle newArticle = (SchArticle) BeanUtils.cloneBean(article); newArticle.setArticleId(null); newArticle.setChapterId(chapterId); newArticle.setSubjectId(subjectId); newArticle.setSubjectName(subjectName); newArticle.setOrderNum(1000); newArticle.setCollegeCourseId(collegeCourseId); OrgText text = orgTextService.getOrgText(id, OrgText.TABLE_NAME_ARTICLE); newArticle.setContent(text == null?null:text.getContent()); articleService.updateOrgArticle(newArticle, collegeCourseId); }else if(SchCourseware.COURSEWARE_TYPE_EXERCISE.equals(type)){ exerciseService.doCopyExerciseGroup(id, subjectId, collegeCourseId, chapterId); }else if(SchCourseware.COURSEWARE_TYPE_HANDOUT.equals(type)){ handoutService.doCopyHandout(id, subjectId, collegeCourseId, chapterId, subjectName); }else if(SchCourseware.COURSEWARE_TYPE_VIDEO.equals(type)){ MediaVideo video = this.read(MediaVideo.class, id); MediaVideo newVideo = (MediaVideo) BeanUtils.cloneBean(video); newVideo.setVideoId(null); //newVideo.setChapterId(chapterId); newVideo.setSubjectId(subjectId); newVideo.setSubjectName(subjectName); newVideo.setCollegeCourseId(collegeCourseId); newVideo.setVideoOrder(1000); lessonService.insertOrgVideo(newVideo, collegeCourseId, true); } } catch (Exception e) { log.error(e.getMessage(),e); } return new Result(true); } /** * 移动课件 * * @param type 课件类型 * @param id 主键 * @param subjectId 课程 * @param collegeCourseId 科目 * @param chapterId 章节 * @return */ public Result doMoveCourseware(String type, String id, String subjectId, String collegeCourseId, String chapterId){ boolean isOrg = StringUtils.isEmpty(ClientUtils.getClassId()); subjectId = StringUtils.isEmpty(subjectId)?null:subjectId; chapterId = StringUtils.isEmpty(chapterId)?null:chapterId; collegeCourseId = StringUtils.isEmpty(collegeCourseId)?null:collegeCourseId; String subjectName = null; if(StringUtils.isNoneBlank(subjectId)){ if(isOrg){ subjectName = this.read(Subject.class, subjectId).getName(); }else{ subjectName = this.read(SchClassSubject.class, subjectId).getName(); } } if(SchCourseware.COURSEWARE_TYPE_ARTICLE.equals(type)){ SchArticle article = this.read(SchArticle.class, id); article.setSubjectId(subjectId); article.setSubjectName(subjectName); article.setChapterId(chapterId); TraceUtils.setUpdateTrace(article); article.setOrderNum(1000); this.articleService.saveArticle(article); this.bulkUpdate("update SchArticleReCourse set collegeCourseId = ? where articleId = ?", new Object[]{collegeCourseId, id}); }else if(SchCourseware.COURSEWARE_TYPE_EXERCISE.equals(type)){ ExerciseGroup exercise = this.read(ExerciseGroup.class, id); exercise.setSubjectId(subjectId); exercise.setChapterId(chapterId); TraceUtils.setUpdateTrace(exercise); exercise.setOrderNum(BigInteger.valueOf(1000)); this.exerciseService.saveExerciseGroup(exercise); this.bulkUpdate("update ExerciseReCourse set collegeCourseId = ? where groupId = ?", new Object[]{collegeCourseId, id}); }else if(SchCourseware.COURSEWARE_TYPE_HANDOUT.equals(type)){ SchHandout handout = this.read(SchHandout.class, id); handout.setSubjectId(subjectId); handout.setSubjectName(subjectName); handout.setChapterId(chapterId); TraceUtils.setUpdateTrace(handout); handout.setOrderNum(1000); this.handoutService.saveHandout(handout); this.bulkUpdate("update SchHandoutReCourse set collegeCourseId = ? where handoutId = ?", new Object[]{collegeCourseId, id}); }else if(SchCourseware.COURSEWARE_TYPE_VIDEO.equals(type)){ MediaVideo video = this.read(MediaVideo.class, id); video.setSubjectId(subjectId); video.setSubjectName(subjectName); //video.setChapterId(chapterId); TraceUtils.setUpdateTrace(video); video.setVideoOrder(1000); this.mediaVideoService.saveVideo(video); this.bulkUpdate("update MediaVideoReCourse set collegeCourseId = ? where videoId = ?", new Object[]{collegeCourseId, id}); } if(isOrg){ this.bulkUpdate("update SchCourseware set collegeCourseId = ? where id = ? and orgId = ?", new Object[]{collegeCourseId, id, ClientUtils.getOrgId()}); } return new Result(true); } /** * 删除课件 * * @param types * @param ids * @param delAll * @param orgIds * @param classIds * @return */ public Result deleteCourseware(String[] types, String[] ids, Integer delAll, String orgIds[], String classIds[]){ for(String id: ids) { this.bulkUpdate("update SchCourseware set deleteFlag = 1 where id=? ", new Object[] {id}); } Map result = this.coursewareClassify(types, ids); this.articleService.deleteOrgArticleIds(result.get(SchCourseware.COURSEWARE_TYPE_ARTICLE), delAll, orgIds, classIds); String [] groupIds = result.get(SchCourseware.COURSEWARE_TYPE_EXERCISE); if(groupIds != null && groupIds.length > 0){ String [] groupTypes = new String[groupIds.length]; for(int i=0;i 0){ for(int i=0;i result = this.coursewareClassify(types, ids); this.articleService.insertAppointArticle(result.get(SchCourseware.COURSEWARE_TYPE_ARTICLE), orgIds, classIds, collegeCourseId); this.exerciseService.insertAppointExercise(result.get(SchCourseware.COURSEWARE_TYPE_EXERCISE), orgIds, classIds); this.handoutService.insertAppointHandout(result.get(SchCourseware.COURSEWARE_TYPE_HANDOUT), orgIds, classIds, collegeCourseId); this.lessonService.insertAppointOrgVideo(result.get(SchCourseware.COURSEWARE_TYPE_VIDEO), orgIds, classIds); return new Result(true); } /** * 下发课件到子机构 * * @param id * @param sourceOrgId * @param targetOrgId * @param collegeCourseId * @return */ public Result insertOrgCourseware(String id, String sourceOrgId, String targetOrgId, String collegeCourseId){ SchCourseware courseware = this.findUnique("from SchCourseware where id = ? and orgId = ? and deleteFlag is false", CollectionUtils.newList(id, sourceOrgId), SchCourseware.class); if(courseware == null){ return new Result(false, "原课件不存在"); } SchCourseware newCourseware = new SchCourseware(); try { BeanUtils.copyProperties(newCourseware, courseware); newCourseware.setCoursewareId(null); newCourseware.setOrgId(targetOrgId); TraceUtils.setCreateTrace(newCourseware); this.save(newCourseware); } catch (Exception e) { log.error("机构下发课件报错:课件id:"+id+",子机构id:"+targetOrgId, e); } return new Result(true); } /** * 撤回 * * @param id * @param orgId * @return */ public Result deleteOrgCourseware(String id, String orgId){ SchCourseware courseware = this.findUnique("from SchCourseware where id = ? and orgId = ? and deleteFlag is false", CollectionUtils.newList(id, orgId), SchCourseware.class); if(courseware != null){ courseware.setDeleteFlag(true); TraceUtils.setUpdateTrace(courseware); this.save(courseware); } return new Result(true); } /** * 查询已下发的班级 * * @param types * @param ids * @return */ public Result findAlready(String[] types, String[] ids){ Map classify = this.coursewareClassify(types, ids); String[] articleId = classify.get(SchCourseware.COURSEWARE_TYPE_ARTICLE); String[] groupId = classify.get(SchCourseware.COURSEWARE_TYPE_EXERCISE); String[] handoutId = classify.get(SchCourseware.COURSEWARE_TYPE_HANDOUT); String[] videoId = classify.get(SchCourseware.COURSEWARE_TYPE_VIDEO); List lstOrg = new ArrayList(); List lstClass = new ArrayList(); if(articleId.length > 0){ String hql = " select c.orgId from SchArticleReCourse c" + " where c.deleteFlag is false" + " and c.articleId in(:articleId)"; lstOrg.addAll(this.findByComplexHql(hql, CollectionUtils.newObjectMap("articleId", articleId), String.class)); lstClass.addAll(this.findByComplexHql("select distinct classId from SchArticle where deleteFlag is false and originArticleId in(:articleId) and classId is not null", CollectionUtils.newObjectMap("articleId", articleId), String.class)); } if(groupId.length > 0){ String hql = " select c.orgId from ExerciseReCourse c" + " where c.deleteFlag is false" + " and c.groupId in (:groupId)"; lstOrg.addAll(this.findByComplexHql(hql, CollectionUtils.newObjectMap("groupId", groupId), String.class)); lstClass.addAll(this.findByComplexHql("select distinct classId from ExerciseGroup where deleteFlag is false and originExerciseId in (:groupId) and classId is not null", CollectionUtils.newObjectMap("groupId", groupId), String.class)); } if(handoutId.length > 0){ String hql = " select c.orgId from SchHandoutReCourse c" + " where c.deleteFlag is false" + " and c.handoutId in(:handoutId)"; lstOrg.addAll(this.findByComplexHql(hql, CollectionUtils.newObjectMap("handoutId", handoutId), String.class)); lstClass.addAll(this.findByComplexHql("select distinct classId from SchHandout where deleteFlag is false and originHandoutId in(:handoutId) and classId is not null", CollectionUtils.newObjectMap("handoutId", handoutId), String.class)); } if(videoId.length > 0){ String hql = " select c.orgId from MediaVideoReCourse c" + " where c.deleteFlag is false" + " and c.videoId in(:videoId)"; lstOrg.addAll(this.findByComplexHql(hql, CollectionUtils.newObjectMap("videoId", videoId), String.class)); lstClass.addAll(this.findByComplexHql("select distinct classId from MediaVideo where deleteFlag is false and originVideoId in(:videoId) and classId is not null", CollectionUtils.newObjectMap("videoId", videoId), String.class)); } return new Result(true, "", CollectionUtils.newObjectMap("orgs", lstOrg, "classes", lstClass)); } /** * 课件分类 * * @param types * @param ids * @return */ private Map coursewareClassify(String[] types, String[] ids){ List articleId = new ArrayList(); List groupId = new ArrayList(); List handoutId = new ArrayList(); List videoId = new ArrayList(); for(int i=0;i result = new HashMap(); result.put(SchCourseware.COURSEWARE_TYPE_ARTICLE, articleId.toArray(new String[articleId.size()])); result.put(SchCourseware.COURSEWARE_TYPE_EXERCISE, groupId.toArray(new String[groupId.size()])); result.put(SchCourseware.COURSEWARE_TYPE_HANDOUT, handoutId.toArray(new String[handoutId.size()])); result.put(SchCourseware.COURSEWARE_TYPE_VIDEO, videoId.toArray(new String[videoId.size()])); return result; } /** * 课件树排序 * * @param ids[] 排序的id * @param type 排序类型 * @param parentId 父节点id * @return */ public Result doOrder(String[] ids, String type, String parentId){ for(int i=0;i result = this.coursewareClassify(types, ids); for(String id:ids) { bulkUpdate("update SchCourseware set deleteFlag=true where id=?", new Object[] {id}); } this.articleService.deleteArticle(StringUtils.join(result.get(SchCourseware.COURSEWARE_TYPE_ARTICLE), ",")); this.exerciseService.deleteExerciseGroup(StringUtils.join(result.get(SchCourseware.COURSEWARE_TYPE_EXERCISE), ",")); this.handoutService.deleteHandouts(result.get(SchCourseware.COURSEWARE_TYPE_HANDOUT)); this.lessonService.deleteVideos(StringUtils.join(result.get(SchCourseware.COURSEWARE_TYPE_VIDEO), ",")); return new Result(true); } /** * 拷贝课件 * * @param type 课件类型 * @param id 主键 * @param subjectId 课程 * @param collegeCourseId 科目 * @param chapterId 章节 * @return */ public Result doCopyClassCourseware(String type, String id, String subjectId, String chapterId){ try { subjectId = StringUtils.isEmpty(subjectId)?null:subjectId; chapterId = StringUtils.isEmpty(chapterId)?null:chapterId; SchClassSubject subject = this.read(SchClassSubject.class, subjectId); String subjectName = subject == null?null:subject.getName(); if(SchCourseware.COURSEWARE_TYPE_ARTICLE.equals(type)){ SchArticle article = this.read(SchArticle.class, id); SchArticle newArticle = (SchArticle) BeanUtils.cloneBean(article); newArticle.setArticleId(null); newArticle.setChapterId(chapterId); newArticle.setSubjectId(subjectId); newArticle.setSubjectName(subjectName); newArticle.setCollegeCourseId(ClientUtils.getCourseId()); OrgText text = orgTextService.getOrgText(id, OrgText.TABLE_NAME_ARTICLE); newArticle.setContent(text == null?null:text.getContent()); articleService.updateArticle(newArticle); }else if(SchCourseware.COURSEWARE_TYPE_EXERCISE.equals(type)){ exerciseService.doCopyExerciseGroup(id, subjectId, ClientUtils.getCourseId(), chapterId); }else if(SchCourseware.COURSEWARE_TYPE_HANDOUT.equals(type)){ handoutService.doCopyHandout(id, subjectId, ClientUtils.getCourseId(), chapterId, subjectName); }else if(SchCourseware.COURSEWARE_TYPE_VIDEO.equals(type)){ MediaVideo video = this.read(MediaVideo.class, id); MediaVideo newVideo = (MediaVideo) BeanUtils.cloneBean(video); newVideo.setVideoId(null); //newVideo.setChapterId(chapterId); newVideo.setSubjectId(subjectId); newVideo.setSubjectName(subjectName); newVideo.setCollegeCourseId(ClientUtils.getCourseId()); lessonService.insertVideo(newVideo,"", true); } } catch (Exception e) { e.printStackTrace(); } return new Result(true); } /** * 发布和停用 * * @param types * @param ids * @param status * @return */ public Result updateStatus(String[] types, String[] ids, int status){ Map result = this.coursewareClassify(types, ids); if(status == 1){ if(result.get(SchCourseware.COURSEWARE_TYPE_ARTICLE).length > 0){ this.bulkUpdateInLoop("update SchArticle set status = 2 where articleId = ?", result.get(SchCourseware.COURSEWARE_TYPE_ARTICLE)); this.bulkUpdateInLoop("update SchCourseware set status = 2 where id = ?", result.get(SchCourseware.COURSEWARE_TYPE_ARTICLE)); } if(result.get(SchCourseware.COURSEWARE_TYPE_EXERCISE).length > 0){ this.bulkUpdateInLoop("update ExerciseGroup set status = 2 where groupId = ?", result.get(SchCourseware.COURSEWARE_TYPE_EXERCISE)); this.bulkUpdateInLoop("update SchCourseware set status = 2 where id = ?", result.get(SchCourseware.COURSEWARE_TYPE_EXERCISE)); } if(result.get(SchCourseware.COURSEWARE_TYPE_HANDOUT).length > 0){ this.handoutService.doStartHandouts(StringUtils.join(result.get(SchCourseware.COURSEWARE_TYPE_HANDOUT), ",")); } if(result.get(SchCourseware.COURSEWARE_TYPE_VIDEO).length > 0){ this.lessonService.doStartVideos(StringUtils.join(result.get(SchCourseware.COURSEWARE_TYPE_VIDEO), ",")); } }else if(status == 2){ if(result.get(SchCourseware.COURSEWARE_TYPE_ARTICLE).length > 0){ this.bulkUpdateInLoop("update SchArticle set status = 3 where articleId = ?", result.get(SchCourseware.COURSEWARE_TYPE_ARTICLE)); this.bulkUpdateInLoop("update SchCourseware set status = 3 where id = ?", result.get(SchCourseware.COURSEWARE_TYPE_ARTICLE)); } if(result.get(SchCourseware.COURSEWARE_TYPE_EXERCISE).length > 0){ this.bulkUpdateInLoop("update ExerciseGroup set status = 3 where groupId = ?", result.get(SchCourseware.COURSEWARE_TYPE_EXERCISE)); this.bulkUpdateInLoop("update SchCourseware set status = 3 where id = ?", result.get(SchCourseware.COURSEWARE_TYPE_EXERCISE)); } if(result.get(SchCourseware.COURSEWARE_TYPE_HANDOUT).length > 0){ this.handoutService.doStopHandouts(result.get(SchCourseware.COURSEWARE_TYPE_HANDOUT)); } if(result.get(SchCourseware.COURSEWARE_TYPE_VIDEO).length > 0){ this.lessonService.doStopVideos(StringUtils.join(result.get(SchCourseware.COURSEWARE_TYPE_VIDEO), ",")); } } return new Result(true); } /** * 删除课程和章节级联删除课件 * * @param subjectId 机构课程id * @param chapterId 章节id * @param classSubjectId 班级课程id * @return */ public Result deleteCourseWare(String subjectId, String chapterId){ if(StringUtils.isNotEmpty(chapterId)){ SubjectChapter chapter = this.read(SubjectChapter.class, chapterId); String newChapterId = null; if(StringUtils.isNotEmpty(chapter.getParentChapterId())){ newChapterId = chapter.getParentChapterId(); }else{ //删除章节练习 this.bulkUpdate("update ExerciseGroup set deleteFlag = ? where chapterId = ? and type = ?", new Object[]{true, chapterId, ExerciseGroup.TYPE_CHAPTER_ITEM}); this.bulkUpdate("update SchCourseware set deleteFlag = ? where chapterId = ? and cType = ?", new Object[]{true, chapterId, 6}); } this.bulkUpdate("update MediaVideo set chapterId = ? where chapterId = ?", new Object[]{newChapterId, chapterId}); this.bulkUpdate("update SchHandout set chapterId = ? where chapterId = ?", new Object[]{newChapterId, chapterId}); this.bulkUpdate("update ExerciseGroup set chapterId = ? where chapterId = ?", new Object[]{newChapterId, chapterId}); this.bulkUpdate("update SchArticle set chapterId = ? where chapterId = ?", new Object[]{newChapterId, chapterId}); this.bulkUpdate("update SchCourseware set chapterId = ? where chapterId = ?", new Object[]{newChapterId, chapterId}); } if(StringUtils.isNotEmpty(subjectId)){ this.bulkUpdate("update MediaVideo set subjectId = null,subjectName = null where subjectId = ?", new Object[]{subjectId}); this.bulkUpdate("update SchHandout set subjectId = null,subjectName = null where subjectId = ?", new Object[]{subjectId}); this.bulkUpdate("update ExerciseGroup set subjectId = null where subjectId = ?", new Object[]{subjectId}); this.bulkUpdate("update SchArticle set subjectId = null,subjectName = null where subjectId = ?", new Object[]{subjectId}); this.bulkUpdate("update SchCourseware set subjectId = null where subjectId = ?", new Object[]{subjectId}); //删除章节练习 this.bulkUpdate("update ExerciseGroup set deleteFlag = ? where subjectId = ? and type = ?", new Object[]{true, subjectId, ExerciseGroup.TYPE_CHAPTER_ITEM}); this.bulkUpdate("update SchCourseware set deleteFlag = ? where subjectId = ? and cType = ?", new Object[]{true, subjectId, 6}); } return new Result(true); } /** * 同步更新课件课程名称 * * @param subjectId * @param subjectName * @return */ public Result updateCourseWare(String subjectId, String subjectName){ if(StringUtils.isNotEmpty(subjectId)){ this.bulkUpdate("update MediaVideo set subjectName = ? where subjectId = ?", new Object[]{subjectName, subjectId}); this.bulkUpdate("update SchHandout set subjectName = ? where subjectId = ?", new Object[]{subjectName, subjectId}); this.bulkUpdate("update SchArticle set subjectName = ? where subjectId = ?", new Object[]{subjectName, subjectId}); } return new Result(true); } /** * 设置学分 */ public Result updateCoursewareScore(String id, int score) { if(StringUtils.isNotEmpty(id)){ this.bulkUpdate("update Schchapter set score = ? where id = ?", new Object[]{score, id}); } return new Result(true); } /** * 查询课件 */ public List> queryCourseware(String id, String type) { if(type.equals("category")) { List> items=new ArrayList>(); //查询项目列表 String hql1="select collegeCourseId as id from OrgCollegeCourse where courseCategoryId=? and deleteFlag is false "; List courseList =find(hql1, CollectionUtils.newList(id),String.class); //查询机构课程 for (String courseId : courseList) { List> result = queryCoursewareByCourseId(courseId); items.addAll(result); } return items; }else if(type.equals("course")) { return queryCoursewareByCourseId(id); }else { return queryCoursewareById( id ,type); } } /** * 根据项目id查询所有机构课程的课件 * @param id * @return */ public List> queryCoursewareByCourseId(String id){ List> items=new ArrayList>(); String hql="select subjectId from SchSubject where collegeCourseId=? and deleteFlag is false"; List subjectList =find(hql, CollectionUtils.newList(id),String.class); for (String subjectId : subjectList) { List> courseware = queryCoursewareById(subjectId ,"subject"); items.addAll(courseware); } return items; } /** * 根据项目id查询课件 * @param courseId * @return */ public List> queryCoursewareById(String id ,String type ){ String hql="select id as id,name as name, describe as desc,type as type,score as score from SchCourseware " + "where deleteFlag is false"; if(type.equals("course")) { hql+=" and collegeCourseId=:courseId"; return findListWithMapByHql(hql, CollectionUtils.newObjectMap("courseId",id)); } if(type.equals("subject")) { hql+=" and subjectId=:subjectId"; return findListWithMapByHql(hql, CollectionUtils.newObjectMap("subjectId",id)); } if(type.equals("chapter")) { hql+=" and chapterId=:chapterId or parentChapterId=:parentChapterId"; return findListWithMapByHql(hql, CollectionUtils.newObjectMap("chapterId",id,"parentChapterId",id)); } if(type.equals("section")) { hql+=" and chapterId=:chapterId"; return findListWithMapByHql(hql, CollectionUtils.newObjectMap("chapterId",id)); } return null; } @Override public Result updateCoursewareScoreValue(String id,BigDecimal scoreValue) { String hql = "from SchCourseware c where c.id=? and c.deleteFlag is false"; SchCourseware courseWare = this.findUnique(hql, CollectionUtils.newList(id), SchCourseware.class); courseWare.setScoreValue(scoreValue); this.save(courseWare); return new Result(true); } /** * 获取排序 * * @param isOrg * @param subjectId * @param chapterId * @return */ @Override public Map getOrder(boolean isOrg, String subjectId, String chapterId){ Map result = new HashMap<>(); //同步排序 int subjectOrder = 0; int chapterOrder = 0; int partOrder = 0; if(StringUtils.isNoneBlank(subjectId)){ if(isOrg){ Subject subject = this.read(Subject.class, subjectId); subjectOrder = subject.getOrderNum(); }else{ SchClassSubject subject = this.read(SchClassSubject.class, subjectId); subjectOrder = subject.getOrderNum(); } } if(StringUtils.isNoneBlank(chapterId)){ SubjectChapter chapter = this.read(SubjectChapter.class, chapterId); if(StringUtils.isEmpty(chapter.getParentChapterId())){ chapterOrder = chapter.getOrderNum(); }else{ SubjectChapter parentChapter = this.read(SubjectChapter.class, chapter.getParentChapterId()); chapterOrder = parentChapter.getOrderNum(); partOrder = chapter.getOrderNum(); } } result.put("subjectOrder", subjectOrder); result.put("chapterOrder", chapterOrder); result.put("partOrder", partOrder); return result; } }