派生自 projectDept/qhighschool

Administrator
2022-11-16 83c795e9d040110973df19a9a3d953518d27b35d
src/main/java/com/qxueyou/scc/admin/classes/service/impl/ClassLectureService.java
@@ -52,7 +52,7 @@
@Service
public class ClassLectureService extends CommonAppService implements IClassLectureService {
   private final Logger log = LogManager.getLogger(ClassLectureService.class);
    @Autowired
@@ -69,7 +69,7 @@
    @Autowired
    ProgressDAO progressDao;
   @Autowired
   IMsgInfoService msgInfoService;
@@ -95,8 +95,12 @@
    @Override
    public List<MyLectureV> listLectureV(String learnerId, String chapterId, String keyword, Integer pageSize,
                                         Integer pageNum, String type) {
        StringBuffer hql = new StringBuffer("from MyLectureV where chapterId=? and id.userId=? and status=? order by lectureCreateTime desc");
        List<Object> args = CollectionUtils.newList(chapterId, learnerId,ClsSubjectLecture.STATUS_DRAFT);
        StringBuffer hql = new StringBuffer("from MyLectureV where subjectId=? and id.userId=? order by lectureCreateTime desc");
//        StringBuffer hql = new StringBuffer("from MyLectureV where chapterId=? and id.userId=? and status=? order by lectureCreateTime desc");
//        List<Object> args = CollectionUtils.newList(chapterId, learnerId,ClsSubjectLecture.STATUS_DRAFT);
        List<Object> args = CollectionUtils.newList(chapterId, learnerId);
        if (StringUtils.isNotEmpty(type)) {
            hql.append(" and lectureType=?");
@@ -107,10 +111,10 @@
        return result;
    }
    /**
     * 课程课件
     *
     *
     */
    @Override
    public Map<String,Object> listLectureBySubjectOrderCreateTime(String subjectId, String classId, String sort, Pager pager) {
@@ -118,18 +122,18 @@
       if(Subject.TYPE_PUBLIC_SUBJECT == subject.getType()) {//公开课课件
          return this.listOpenLectureBySubjectOrderCreateTime(subjectId, sort, pager);
       }
       QMyLectureV qMyLectureV = QMyLectureV.myLectureV;
       OrderSpecifier<Date> order = "desc".equals(sort)?new OrderSpecifier<Date>(Order.DESC, qMyLectureV.lectureCreateTime):
         new OrderSpecifier<Date>(Order.ASC, qMyLectureV.lectureCreateTime);
       JPAQuery<MyLectureV> 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()
@@ -144,10 +148,10 @@
                 return map;
              }).collect(Collectors.toList()));
    }
    /**
    * 公开课课件
    *
    *
    * @param subjectId
    * @param sort
    * @param pager
@@ -157,14 +161,14 @@
    public Map<String,Object> listOpenLectureBySubjectOrderCreateTime(String subjectId, String sort, Pager pager) {
       QSubjectLecture qSubjectLecture = QSubjectLecture.subjectLecture;
       QProgress qProgress = QProgress.progress;
       OrderSpecifier<Date> order = "desc".equals(sort)?new OrderSpecifier<Date>(Order.DESC, qSubjectLecture.createTime):
         new OrderSpecifier<Date>(Order.ASC, qSubjectLecture.createTime);
       JPAQuery<SubjectLecture> 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()
@@ -236,30 +240,30 @@
        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<String> lstUserIds = this.findByComplexHql(hql, CollectionUtils.newObjectMap("classId",lecture.getClassId()), String.class);
      if(lstUserIds!=null && lstUserIds.size()>0){
         Map<String,String> 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);
      }
   }
@@ -345,7 +349,7 @@
        return result;
    }
    @Override
    public List<Map<String, Object>> listLectureBySubject(String subjectId, String type, String classId) {
        StringBuffer hql = new StringBuffer("select name as lectureName, "
@@ -366,8 +370,8 @@
        return this.findListWithMapByHql(hql.toString(), args);
    }
    @Override
    public List<Map<String, Object>> listStuLectureBySubject(String subjectId, String classId) {
       if(StringUtils.isEmpty(subjectId) || StringUtils.isEmpty(classId)) {
@@ -390,10 +394,10 @@
               return map;
            }).collect(Collectors.toList());
    }
    /**
     * 我的公开课课件查询
     *
     *
     * @param subjectId
     * @return
     */
@@ -418,10 +422,10 @@
               return map;
            }).collect(Collectors.toList());
    }
    /**
     * 查询数量
     *
     *
     * @param subjectId
     * @param classId
     * @return
@@ -488,7 +492,7 @@
        return result;
    }
    public List<SubjectChapter> getListOpenChapter(String subjectId) {
        StringBuffer hql = new StringBuffer(
@@ -506,18 +510,18 @@
        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<String, String> subjectIdMap = CollectionUtils.newStringMap(SubjectChapter.ROOT_CHAPTER_ID,
@@ -567,7 +571,7 @@
    @Override
    public List<ClsSubjectLecture> listLecture(String subjectId) {
        StringBuffer hql = new StringBuffer("from ClsSubjectLecture where subjectId = ? and deleteFlag is false");
        List<Object> args = CollectionUtils.newList(subjectId);
@@ -575,30 +579,30 @@
        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<Date> order = "desc".equals(sort)?new OrderSpecifier<Date>(Order.DESC, qMyLectureV.lectureCreateTime):
         new OrderSpecifier<Date>(Order.ASC, qMyLectureV.lectureCreateTime);
       JPAQuery<MyLectureV> 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<MyLectureV> results = query.limit(pager.getPageSize()).offset(pager.getOffset()).orderBy(order).fetchResults();
      List<Map<String,Object>> resultLst =
      List<Map<String,Object>> resultLst =
            results.getResults()
            .stream()
             .map(tuple -> {
@@ -641,11 +645,11 @@
        return new Result(true);
    }
    /**
     * 获取章节下的课件
     *
     *
     * @param chapterLst
     * @param lectures
     * @return
@@ -659,9 +663,9 @@
               }
            }
         }
         this.getTopChapters(chapterLst);
         for (int i=chapterLst.size()-1;i>=0;i--) {
            ClsSubjectChapter objClsSubjectChapter = chapterLst.get(i);
            if(objClsSubjectChapter.getLectures() == null || objClsSubjectChapter.getLectures().isEmpty()) {
@@ -669,13 +673,13 @@
            }
         }
      }
       return chapterLst;
    }
    /**
     * 获取章节的第一层数据
     *
     *
     * @param chapterLst
     * @return
     */
@@ -702,11 +706,11 @@
             chapterLst = this.getTopChapters(chapterLst);
          }
      }
       return chapterLst;
    }
   @Override
   public int readDocPageCount(String resItemId) {
      ResItemDoc resItemDoc = read(ResItemDoc.class, resItemId);
@@ -721,10 +725,10 @@
      return schHandout.getPageCount();
   }
    /**
     * 课件按目录分类
     *
     *
     * @param classId
     * @param subjectId
     * @param type
@@ -732,12 +736,12 @@
     */
    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<Map<String, Object>> lectures = this.listStuLectureByOpenSubject(subjectId);
          List<SubjectChapter> lstSubjectChapterLst = this.getListOpenChapter(subjectId);
          List<ClsSubjectChapter> lstClsSubjectChapter = new ArrayList<>();
          if(lstSubjectChapterLst != null && !lstSubjectChapterLst.isEmpty()) {
@@ -751,20 +755,20 @@
               } catch (InvocationTargetException e) {
                  log.error("拷贝属性失败BeanUtils.copyProperties(objClsSubjectChapter, objSubjectChapter)", e);
               }
                lstClsSubjectChapter.add(objClsSubjectChapter);
             }
          }
          //章节
          List<ClsSubjectChapter> 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<Map<String, Object>> lectures = this.listStuLectureBySubject(subjectId, classId);