派生自 projectDept/qhighschool

yn147
2023-11-24 d7963a84282c548fee3595b3343e6ae6ca49bb29
src/main/java/com/qxueyou/scc/teach/subject/service/impl/SubjectLectureService.java
@@ -1,10 +1,14 @@
package com.qxueyou.scc.teach.subject.service.impl;
import java.util.Date;
import java.util.List;
import com.qxueyou.scc.admin.classes.model.ClsClassReSubject;
import com.qxueyou.scc.admin.classes.model.ClsSubjectChapter;
import com.qxueyou.scc.admin.classes.service.IClassLectureService;
import com.qxueyou.scc.teach.subject.model.Subject;
import com.qxueyou.scc.teach.subject.model.view.*;
import com.qxueyou.scc.user.model.UserTeacher;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
@@ -26,10 +30,6 @@
import com.qxueyou.scc.teach.res.service.IResService;
import com.qxueyou.scc.teach.subject.model.SubjectChapter;
import com.qxueyou.scc.teach.subject.model.SubjectLecture;
import com.qxueyou.scc.teach.subject.model.view.LectureAudioV;
import com.qxueyou.scc.teach.subject.model.view.LectureDocV;
import com.qxueyou.scc.teach.subject.model.view.LectureVideoV;
import com.qxueyou.scc.teach.subject.model.view.MyLectureV;
import com.qxueyou.scc.teach.subject.service.ILectureService;
import com.qxueyou.scc.teach.subject.service.ISubjectService;
import org.springframework.transaction.annotation.Transactional;
@@ -37,415 +37,510 @@
@Service
public class SubjectLectureService extends CommonAppService implements ILectureService {
   public static final String RES_LECTURE_CONVER_LST = "RES_LECTURE_CONVER_LST";
    public static final String RES_LECTURE_CONVER_LST = "RES_LECTURE_CONVER_LST";
   @Autowired
   ISubjectService subjectService;
    @Autowired
    ISubjectService subjectService;
   @Autowired
   IResService resService;
    @Autowired
    IResService resService;
   @Autowired
   ICacheService cacheService;
    @Autowired
    ICacheService cacheService;
   @Autowired
   IProgressService progressService;
    @Autowired
    IProgressService progressService;
   @Autowired
   IClassLectureService clsLectureService;
    @Autowired
    IClassLectureService clsLectureService;
   @Override
   public Result addChapter(String subjectId, String parentChapterId, String name) {
    @Override
    public Result addChapter(String subjectId, String parentChapterId, String name) {
      SubjectChapter chapter = new SubjectChapter();
        SubjectChapter chapter = new SubjectChapter();
      TraceUtils.setCreateTrace(chapter);
      chapter.setName(name);
      chapter.setParentChapterId(parentChapterId);
      chapter.setSubjectId(subjectId);
        TraceUtils.setCreateTrace(chapter);
        chapter.setName(name);
        chapter.setParentChapterId(parentChapterId);
        chapter.setSubjectId(subjectId);
      save(chapter);
        save(chapter);
      return new Result(true, "success", CollectionUtils.newObjectMap("id", chapter.getChapterId(), "name", name));
        return new Result(true, "success", CollectionUtils.newObjectMap("id", chapter.getChapterId(), "name", name));
   }
    }
   @Override
   public Result updateChapter(String chapterId, String name) {
    @Override
    public Result updateChapter(String chapterId, String name) {
      SubjectChapter chapter = read(SubjectChapter.class, chapterId);
        SubjectChapter chapter = read(SubjectChapter.class, chapterId);
      TraceUtils.setUpdateTrace(chapter);
      chapter.setName(name);
        TraceUtils.setUpdateTrace(chapter);
        chapter.setName(name);
      save(chapter);
        save(chapter);
      return new Result(true, "success", CollectionUtils.newObjectMap("id", chapter.getChapterId(), "name", name));
   }
        return new Result(true, "success", CollectionUtils.newObjectMap("id", chapter.getChapterId(), "name", name));
    }
   @Override
   public Result deleteChapter(String[] chapterIds) {
      for (String chapterId : chapterIds) {
         deleteChapter(chapterId);
      }
    @Override
    public Result deleteChapter(String[] chapterIds) {
        for (String chapterId : chapterIds) {
            deleteChapter(chapterId);
        }
      return new Result(true, "success");
   }
        return new Result(true, "success");
    }
   /**
    * 删除单个章节
    *
    * @param chapterId
    *            章节id
    * @return
    */
   private Result deleteChapter(String chapterId) {
    /**
     * 删除单个章节
     *
     * @param chapterId 章节id
     * @return
     */
    private Result deleteChapter(String chapterId) {
      SubjectChapter chapter = read(SubjectChapter.class, chapterId);
        SubjectChapter chapter = read(SubjectChapter.class, chapterId);
      TraceUtils.setUpdateTrace(chapter);
      chapter.setDeleteFlag(true);
        TraceUtils.setUpdateTrace(chapter);
        chapter.setDeleteFlag(true);
      save(chapter);
      Result result = this.deleteCourseware4Chapter(chapterId);
      if (!result.isSuccess()) {
         return result;
      }
      return new Result(true, "success");
   }
        save(chapter);
        Result result = this.deleteCourseware4Chapter(chapterId);
        if (!result.isSuccess()) {
            return result;
        }
        return new Result(true, "success");
    }
   private Result deleteCourseware4Chapter(String chapterId) {
    private Result deleteCourseware4Chapter(String chapterId) {
      this.bulkUpdate("update SubjectLecture set deleteFlag = true where chapterId = ?", new String[] { chapterId });
      return new Result(true);
        this.bulkUpdate("update SubjectLecture set deleteFlag = true where chapterId = ?", new String[]{chapterId});
        return new Result(true);
   }
    }
   @Override
   public List<SubjectChapter> doGetListChapter(String subjectId, String parentChapterId) {
    @Override
    public List<SubjectChapter> doGetListChapter(String subjectId, String parentChapterId) {
      List<SubjectChapter> result = getListChapter(subjectId, parentChapterId);
        List<SubjectChapter> result = getListChapter(subjectId, parentChapterId);
      if (result.isEmpty() && StringUtils.isEmpty(parentChapterId)) {
         return CollectionUtils.newList(SubjectChapter.class, initLectureChapter(subjectId));
      }
        if (result.isEmpty() && StringUtils.isEmpty(parentChapterId)) {
            return CollectionUtils.newList(SubjectChapter.class, initLectureChapter(subjectId));
        }
      return result;
   }
        return result;
    }
   @Override
   public List<SubjectProgressTreeV> getChapterTreeVList(String subjectId, String parentChapterId) {
    @Override
    public List<SubjectProgressTreeV> getChapterTreeVList(String subjectId, String parentChapterId) {
      if (parentChapterId == null) {
         return progressService.getSubjectChapterTreeVList(subjectId, ClientUtils.getUserId());
      }
        if (parentChapterId == null) {
            return progressService.getSubjectChapterTreeVList(subjectId, ClientUtils.getUserId());
        }
      return progressService.getSubjectChapterTreeVList(parentChapterId, ClientUtils.getUserId());
   }
        return progressService.getSubjectChapterTreeVList(parentChapterId, ClientUtils.getUserId());
    }
   /**
    * 初始化
    *
    * @param subjectId
    * @return
    */
   private SubjectChapter initLectureChapter(String subjectId) {
    /**
     * 初始化
     *
     * @param subjectId
     * @return
     */
    private SubjectChapter initLectureChapter(String subjectId) {
      SubjectChapter chapter = new SubjectChapter();
        SubjectChapter chapter = new SubjectChapter();
      TraceUtils.setCreateTrace(chapter);
      chapter.setName("根节点");
      chapter.setSubjectId(subjectId);
      chapter.setParentChapterId(SubjectChapter.ROOT_CHAPTER_ID);
        TraceUtils.setCreateTrace(chapter);
        chapter.setName("根节点");
        chapter.setSubjectId(subjectId);
        chapter.setParentChapterId(SubjectChapter.ROOT_CHAPTER_ID);
      save(chapter);
        save(chapter);
      return chapter;
   }
        return chapter;
    }
   @Override
   public Result addLecture(String chapterId, String resId) {
    @Override
    public Result addLecture(String chapterId, String resId) {
      SubjectChapter chapter = read(SubjectChapter.class, chapterId);
        SubjectChapter chapter = read(SubjectChapter.class, chapterId);
      Res res = resService.read(resId);
        Res res = resService.read(resId);
      SubjectLecture lecture = new SubjectLecture();
        SubjectLecture lecture = new SubjectLecture();
      TraceUtils.setCreateTrace(lecture);
      lecture.setChapterId(chapterId);
      lecture.setLectureType(res.getType());
      lecture.setName(res.getName());
      lecture.setStatus(res.getStatus());
      lecture.setRemark(res.getRemark());
      lecture.setSubjectId(chapter.getSubjectId());
      lecture.setResItemId(res.getResId());
      save(lecture);
      subjectService.addLectureCount(lecture.getSubjectId(), 1);
      return new Result(true, "success");
   }
        TraceUtils.setCreateTrace(lecture);
        lecture.setChapterId(chapterId);
        lecture.setLectureType(res.getType());
        lecture.setName(res.getName());
        lecture.setStatus(res.getStatus());
        lecture.setRemark(res.getRemark());
        lecture.setSubjectId(chapter.getSubjectId());
        lecture.setResItemId(res.getResId());
        save(lecture);
        subjectService.addLectureCount(lecture.getSubjectId(), 1);
   @Override
   public Result addLectureLoad(String sectionId){
      SubjectChapter chapter = read(SubjectChapter.class, sectionId);
      String hql = "from Subject where subjectId = ? and deleteFlag is false";
      String subjectId = chapter.getSubjectId();
      Subject subjectOne = findUnique(hql,CollectionUtils.newList(subjectId),Subject.class);
      String hqlOne = "from Subject where name = ? and deleteFlag is false";
      List<Subject> subjectTwo = find(hqlOne,CollectionUtils.newList(subjectOne.getName()),Subject.class);
      for (Subject s : subjectTwo){
         String hqlTwo = "from ClsClassReSubject where subjectId = ? and deleteFlag is false";
         ClsClassReSubject subject = findUnique(hqlTwo,CollectionUtils.newList(s.getSubjectId()),ClsClassReSubject.class);
         if(subject != null){
            subjectService.updateClsSubject(subject.getClassId(),s.getSubjectId(),s.getOrigSubjectId(),s.getTeacherId(),s.getSchoolYear(),s.getTerm());
         }
      }
      return new Result(true, "success");
   }
        String hql = "from Subject where subjectId = ? and deleteFlag is false";
        Subject subject = findUnique(hql, CollectionUtils.newList(chapter.getSubjectId()), Subject.class);
        String hql1 = "from Subject where name = ? and deleteFlag is false and type = 2";
        List<Subject> subjects = find(hql1, CollectionUtils.newList(subject.getName()), Subject.class);
        for (Subject subjectv : subjects) {
            String hql2 = "from ClsSubjectChapter where subjectId = ? and deleteFlag is false and Name = ? ";
            ClsSubjectChapter clsSubjectChapter = findUnique(hql2, CollectionUtils.newList(subjectv.getSubjectId(), chapter.getName()), ClsSubjectChapter.class);
            String hql3 = "from ClsClassReSubject where subjectId = ? and deleteFlag is false";
            List<ClsClassReSubject> reSubject = find(hql3, CollectionUtils.newList(subjectv.getSubjectId()), ClsClassReSubject.class);
            for (ClsClassReSubject classReSubject : reSubject) {
                ClsSubjectLecture clsLecture = new ClsSubjectLecture();
                TraceUtils.setCreateTrace(clsLecture);
                clsLecture.setChapterId(clsSubjectChapter.getChapterId());
                clsLecture.setLectureType(res.getType());
                clsLecture.setName(res.getName());
                clsLecture.setStatus(res.getStatus());
                clsLecture.setRemark(res.getRemark());
                clsLecture.setSubjectId(clsSubjectChapter.getSubjectId());
                clsLecture.setResItemId(res.getResId());
                clsLecture.setClassId(classReSubject.getClassId());
                save(clsLecture);
            }
        }
        return new Result(true, "success");
    }
//   @Override
//   public Result addLectureLoad(String sectionId){
//      SubjectChapter chapter = read(SubjectChapter.class, sectionId);
//      String hql = "from Subject where subjectId = ? and deleteFlag is false";
//      String subjectId = chapter.getSubjectId();
//      Subject subjectOne = findUnique(hql,CollectionUtils.newList(subjectId),Subject.class);
//      String hqlOne = "from Subject where name = ? and deleteFlag is false";
//      List<Subject> subjectTwo = find(hqlOne,CollectionUtils.newList(subjectOne.getName()),Subject.class);
//      for (Subject s : subjectTwo){
//         String hqlTwo = "from ClsClassReSubject where subjectId = ? and deleteFlag is false";
//         ClsClassReSubject subject2 = findUnique(hqlTwo,CollectionUtils.newList(s.getSubjectId()),ClsClassReSubject.class);
//         if(subject2 != null){
//            subjectService.updateClsSubject(subject2.getClassId(),s.getSubjectId(),s.getOrigSubjectId(),s.getTeacherId(),s.getSchoolYear(),s.getTerm());
//                Subject subject = read(Subject.class,s.getSubjectId());
//
//
//                clsLectureService.doCopyLecturesToClass(s.getSubjectId(), subjectId, subject2.getClassId());
//
//
//         }
//      }
//      return new Result(true, "success");
//   }
    @Override
    public Result updateLecture(String lectureId, String resId) {
        SubjectLecture lecture = read(SubjectLecture.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");
    }
//    @Override
//    public Result deleteLectureLoad(String[] lectureIds){
//        SubjectLecture lecture = read(SubjectLecture.class, lectureIds[0]);
//        String hql = "from Subject where subjectId = ? and deleteFlag is false";
//        String subjectId = lecture.getSubjectId();
//        Subject subjectOne = findUnique(hql,CollectionUtils.newList(subjectId),Subject.class);
//        String hqlOne = "from Subject where name = ? and deleteFlag is false";
//        List<Subject> subjectTwo = find(hqlOne,CollectionUtils.newList(subjectOne.getName()),Subject.class);
//        for (Subject s : subjectTwo){
//            String hqlTwo = "from ClsClassReSubject where subjectId = ? and deleteFlag is false";
//            ClsClassReSubject subject = findUnique(hqlTwo,CollectionUtils.newList(s.getSubjectId()),ClsClassReSubject.class);
//            if(subject != null){
//                subjectService.updateClsSubject(subject.getClassId(),s.getSubjectId(),s.getOrigSubjectId(),s.getTeacherId(),s.getSchoolYear(),s.getTerm());
//            }
//        }
//        return new Result(true, "success");
//    }
    /**
     * @param lectureId 课件id
     * @return
     */
    private Result deleteLecture(String lectureId) {
        SubjectLecture lecture = read(SubjectLecture.class, lectureId);
        TraceUtils.setUpdateTrace(lecture);
        lecture.setDeleteFlag(true);
        save(lecture);
        subjectService.addLectureCount(lecture.getSubjectId(), -1);
        String hql = "from Subject where subjectId = ? and deleteFlag is false";
        Subject subject = findUnique(hql, CollectionUtils.newList(lecture.getSubjectId()), Subject.class);
        String hql1 = "from Subject where name = ? and deleteFlag is false and type = 2";
        List<Subject> subjects = find(hql1, CollectionUtils.newList(subject.getName()), Subject.class);
        for (Subject subjectv : subjects) {
            String hql2 = "from ClsSubjectLecture where subjectId = ? and deleteFlag is false and Name = ? ";
            ClsSubjectLecture clsSubjectLecture = findUnique(hql2, CollectionUtils.newList(subjectv.getSubjectId(), lecture.getName()), ClsSubjectLecture.class);
            if(clsSubjectLecture != null){
                TraceUtils.setUpdateTrace(clsSubjectLecture);
                clsSubjectLecture.setDeleteFlag(true);
                save(clsSubjectLecture);
            }
        }
        return new Result(true, "success");
    }
    @Override
    public Result doCopyLecture(String lectureId, String destChapterId, String name) {
        // TODO Auto-generated method stub
        return null;
    }
    @Override
    public Result doMoveLecture(String lectureId, String destChapterId, String name) {
        // TODO Auto-generated method stub
        return null;
    }
   @Override
   public Result updateLecture(String lectureId, String resId) {
    @Override
    public List<SubjectLecture> listLecture(String chapterId, String keyword, Integer pageSize, Integer pageNum,
                                            String type) {
      SubjectLecture lecture = read(SubjectLecture.class, lectureId);
        StringBuffer hql = new StringBuffer("from SubjectLecture where chapterId=? and name like ? and deleteFlag is false");
        List<Object> args = CollectionUtils.newList(chapterId, '%' + keyword.trim() + '%');
      Res res = resService.read(resId);
        if (StringUtils.isNotEmpty(type)) {
            hql.append(" and lectureType=?");
            args.add(type);
        }
      TraceUtils.setUpdateTrace(lecture);
      lecture.setLectureType(res.getType());
      lecture.setName(res.getName());
      lecture.setRemark(res.getRemark());
      lecture.setResItemId(res.getResId());
        List<SubjectLecture> result = findList(hql.toString(), new Pager(pageSize, pageNum), args,
                SubjectLecture.class);
      save(lecture);
        return result;
    }
      return new Result(true, "success");
   }
    @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=?");
        List<Object> args = CollectionUtils.newList(chapterId, learnerId);
   @Override
   public Result deleteLecture(String[] lectureIds) {
      for (String lectureId : lectureIds) {
         deleteLecture(lectureId);
      }
      return new Result(true, "success");
   }
   @Override
   public Result deleteLectureLoad(String[] lectureIds){
      SubjectLecture lecture = read(SubjectLecture.class, lectureIds[0]);
      String hql = "from Subject where subjectId = ? and deleteFlag is false";
      String subjectId = lecture.getSubjectId();
      Subject subjectOne = findUnique(hql,CollectionUtils.newList(subjectId),Subject.class);
      String hqlOne = "from Subject where name = ? and deleteFlag is false";
      List<Subject> subjectTwo = find(hqlOne,CollectionUtils.newList(subjectOne.getName()),Subject.class);
      for (Subject s : subjectTwo){
         String hqlTwo = "from ClsClassReSubject where subjectId = ? and deleteFlag is false";
         ClsClassReSubject subject = findUnique(hqlTwo,CollectionUtils.newList(s.getSubjectId()),ClsClassReSubject.class);
         if(subject != null){
            subjectService.updateClsSubject(subject.getClassId(),s.getSubjectId(),s.getOrigSubjectId(),s.getTeacherId(),s.getSchoolYear(),s.getTerm());
         }
      }
      return new Result(true, "success");
   }
        if (StringUtils.isNotEmpty(type)) {
            hql.append(" and lectureType=?");
            args.add(type);
        }
   /**
    *
    * @param lectureId
    *            课件id
    * @return
    */
   private Result deleteLecture(String lectureId) {
        List<MyLectureV> result = findList(hql.toString(), new Pager(pageSize, pageNum), args, MyLectureV.class);
      SubjectLecture lecture = read(SubjectLecture.class, lectureId);
        return result;
    }
      TraceUtils.setUpdateTrace(lecture);
      lecture.setDeleteFlag(true);
      save(lecture);
    @Override
    public List<MyLectureV> listLectureVBySubjectId(String learnerId, String subjectId, String keyword, Integer pageSize,
                                                    Integer pageNum, String type) {
        StringBuffer hql = new StringBuffer("from MyLectureV where subjectId=? and id.userId=? order by lectureUpdateTime desc");
        List<Object> args = CollectionUtils.newList(subjectId, learnerId);
      subjectService.addLectureCount(lecture.getSubjectId(), -1);
        if (StringUtils.isNotEmpty(type)) {
            hql.append(" and lectureType=?");
            args.add(type);
        }
      return new Result(true, "success");
   }
        List<MyLectureV> result = findList(hql.toString(), new Pager(pageSize, pageNum), args, MyLectureV.class);
   @Override
   public Result doCopyLecture(String lectureId, String destChapterId, String name) {
      // TODO Auto-generated method stub
      return null;
   }
        return result;
    }
   @Override
   public Result doMoveLecture(String lectureId, String destChapterId, String name) {
      // TODO Auto-generated method stub
      return null;
   }
    @Override
    public List<MyOpenLectureV> listOpenLectureVBySubjectId(String learnerId, String subjectId, String keyword, Integer pageSize,
                                                            Integer pageNum, String type) {
        StringBuffer hql = new StringBuffer("from MyOpenLectureV where subjectId=? and userId = ? order by lectureUpdateTime desc");
        List<Object> args = CollectionUtils.newList(subjectId, learnerId);
   @Override
   public List<SubjectLecture> listLecture(String chapterId, String keyword, Integer pageSize, Integer pageNum,
         String type) {
        if (StringUtils.isNotEmpty(type)) {
            hql.append(" and lectureType=?");
            args.add(type);
        }
      StringBuffer hql = new StringBuffer("from SubjectLecture where chapterId=? and name like ? and deleteFlag is false");
      List<Object> args = CollectionUtils.newList(chapterId,'%' + keyword.trim() + '%');
        List<MyOpenLectureV> result = findList(hql.toString(), new Pager(pageSize, pageNum), args, MyOpenLectureV.class);
      if (StringUtils.isNotEmpty(type)) {
         hql.append(" and lectureType=?");
         args.add(type);
      }
        return result;
    }
      List<SubjectLecture> result = findList(hql.toString(), new Pager(pageSize, pageNum), args,
            SubjectLecture.class);
    @Override
    public List<SubjectLecture> getSubjectLectureVByChapterId(String chapterId, String keyword, Integer limit, Integer pageNum) {
        StringBuffer hql = new StringBuffer("from SubjectLecture where chapterId=? and deleteFlag is false");
        List<Object> args = CollectionUtils.newList(chapterId);
      return result;
   }
        List<SubjectLecture> result = findList(hql.toString(), new Pager(limit, pageNum), args, SubjectLecture.class);
        return result;
    }
   @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=?");
      List<Object> args = CollectionUtils.newList(chapterId, learnerId);
    @Override
    public List<MyOpenLectureV> getMyOpenLectureVByChapterId(String userId, String chapterId, String keyword, Integer limit, Integer pageNum) {
        StringBuffer hql = new StringBuffer("from MyOpenLectureV where userId=? and chapterId = ?");
        List<Object> args = CollectionUtils.newList(userId, chapterId);
      if (StringUtils.isNotEmpty(type)) {
         hql.append(" and lectureType=?");
         args.add(type);
      }
        List<MyOpenLectureV> result = findList(hql.toString(), new Pager(limit, pageNum), args, MyOpenLectureV.class);
        return result;
    }
      List<MyLectureV> result = findList(hql.toString(), new Pager(pageSize, pageNum), args, MyLectureV.class);
    @Override
    public int listLectureCount(String chapterId, String keyword, String type) {
        StringBuffer hql = new StringBuffer("from SubjectLecture where chapterId=? and name like ? and deleteFlag is false");
      return result;
   }
        List<Object> args = CollectionUtils.newList(chapterId, '%' + keyword.trim() + '%');
   @Override
   public List<MyLectureV> listLectureVBySubjectId(String learnerId, String subjectId, String keyword, Integer pageSize,
                               Integer pageNum, String type) {
      StringBuffer hql = new StringBuffer("from MyLectureV where subjectId=? and id.userId=? order by lectureUpdateTime desc");
      List<Object> args = CollectionUtils.newList(subjectId, learnerId);
        if (StringUtils.isNotEmpty(type)) {
            hql.append(" and lectureType=?");
            args.add(type);
        }
      if (StringUtils.isNotEmpty(type)) {
         hql.append(" and lectureType=?");
         args.add(type);
      }
        return findCount(hql.toString(), args);
      List<MyLectureV> result = findList(hql.toString(), new Pager(pageSize, pageNum), args, MyLectureV.class);
    }
      return result;
   }
    @Override
    public Result readLectureAccessPath(String lectureId, String attribute) {
        SubjectLecture lecture = read(SubjectLecture.class, lectureId);
        String resItemId = null;
        if (lecture == null) {
            resItemId = read(ClsSubjectLecture.class, lectureId).getResItemId();//班级课件
        } else {
            resItemId = lecture.getResItemId();
        }
        return resService.readAccessPath(resItemId, attribute);
    }
   @Override
   public int listLectureCount(String chapterId, String keyword, String type) {
      StringBuffer hql = new StringBuffer("from SubjectLecture where chapterId=? and name like ? and deleteFlag is false");
    @Override
    public SubjectLecture readLecture(String lectureId) {
        return read(SubjectLecture.class, lectureId);
    }
      List<Object> args = CollectionUtils.newList(chapterId,'%' + keyword.trim() + '%');
    @Override
    public SubjectChapter readChapter(String chapterId) {
        return read(SubjectChapter.class, chapterId);
    }
      if (StringUtils.isNotEmpty(type)) {
         hql.append(" and lectureType=?");
         args.add(type);
      }
    @Override
    public List<SubjectChapter> getListChapter(String subjectId, String parentChapterId) {
      return findCount(hql.toString(),args);
        StringBuffer hql = new StringBuffer(
                "from SubjectChapter where subjectId=? and deleteFlag is false and parentChapterId=?");
   }
        List<Object> args = CollectionUtils.newList(subjectId);
   @Override
   public Result readLectureAccessPath(String lectureId, String attribute) {
      SubjectLecture lecture = read(SubjectLecture.class, lectureId);
      String resItemId = null;
      if(lecture == null) {
         resItemId = read(ClsSubjectLecture.class, lectureId).getResItemId();//班级课件
      }else {
         resItemId = lecture.getResItemId();
      }
      return resService.readAccessPath(resItemId, attribute);
   }
        if (StringUtils.isEmpty(parentChapterId)) {
            args.add(SubjectChapter.ROOT_CHAPTER_ID);
        } else {
            args.add(parentChapterId);
        }
   @Override
   public SubjectLecture readLecture(String lectureId) {
      return read(SubjectLecture.class, lectureId);
   }
        List<SubjectChapter> result = find(hql.toString(), args, SubjectChapter.class);
   @Override
   public SubjectChapter readChapter(String chapterId) {
      return read(SubjectChapter.class, chapterId);
   }
        return result;
    }
   @Override
   public List<SubjectChapter> getListChapter(String subjectId, String parentChapterId) {
    @Override
    public List<SubjectLecture> listLectureBySubjectId(String subjectId) {
        String hql = "from SubjectLecture where subjectId=? and deleteFlag is false";
      StringBuffer hql = new StringBuffer(
            "from SubjectChapter where subjectId=? and deleteFlag is false and parentChapterId=?");
        List<SubjectLecture> result = find(hql, CollectionUtils.newList(subjectId), SubjectLecture.class);
      List<Object> args = CollectionUtils.newList(subjectId);
        return result;
    }
      if (StringUtils.isEmpty(parentChapterId)) {
         args.add(SubjectChapter.ROOT_CHAPTER_ID);
      } else {
         args.add(parentChapterId);
      }
    /**
     * 监控resId转码状态同步Lecture的状态
     */
    @Scheduled(cron = "0/2 * * * * ?") // 每2秒执行一次
    public void doTimer() {
        String resId = cacheService.lstLeftPop(RES_LECTURE_CONVER_LST);
        if (StringUtils.isBlank(resId)) {
            return;
        }
        Res res = read(Res.class, resId);
        if (res.getStatus().equals(Res.STATUS_DRAFT)) {
            String[] resIds = resId.split(",");
            bulkUpdate(
                    "update  SubjectLecture set status = 'draft' where deleteFlag is false and status = 'conver' and resItemId = ?",
                    resIds);
            bulkUpdate(
                    "update  ClsSubjectLecture set status = 'draft' where deleteFlag is false and status = 'conver' and resItemId = ?",
                    resIds);
            return;
        }
        cacheService.lstRightPush(RES_LECTURE_CONVER_LST, resId);
    }
      List<SubjectChapter> result = find(hql.toString(), args, SubjectChapter.class);
    @Override
    public Result doStudy(String lectureId, Double from, Double to) {
        String userId = null;
        return progressService.addProgress(Progress.PROGRESS_TYPE_LECTURE, lectureId, from.intValue(), to.intValue(),
                userId);
    }
      return result;
   }
    @Cacheable(value = "LectureVideoV", key = "#lectureId")
    @Override
    public LectureVideoV readVideoLecture(String lectureId) {
        return read(LectureVideoV.class, lectureId);
    }
   @Override
   public List<SubjectLecture> listLectureBySubjectId(String subjectId) {
      String hql = "from SubjectLecture where subjectId=? and deleteFlag is false";
    @Cacheable(value = "LectureAudioV", key = "#lectureId")
    @Override
    public LectureAudioV readAudioLecture(String lectureId) {
        return read(LectureAudioV.class, lectureId);
    }
      List<SubjectLecture> result = find(hql, CollectionUtils.newList(subjectId), SubjectLecture.class);
    @Override
    public List<SubjectChapter> getAllChapterBySubjectId(String subjectId) {
      return result;
   }
        String hql = "from SubjectChapter where deleteFlag is false and subjectId = ? order by createTime";
        return find(hql, CollectionUtils.newList(subjectId), SubjectChapter.class);
   /**
    * 监控resId转码状态同步Lecture的状态
    */
   @Scheduled(cron = "0/2 * * * * ?") // 每2秒执行一次
   public void doTimer() {
      String resId = cacheService.lstLeftPop(RES_LECTURE_CONVER_LST);
      if (StringUtils.isBlank(resId)) {
         return;
      }
      Res res = read(Res.class, resId);
      if (res.getStatus().equals(Res.STATUS_DRAFT)) {
         String[] resIds = resId.split(",");
         bulkUpdate(
               "update  SubjectLecture set status = 'draft' where deleteFlag is false and status = 'conver' and resItemId = ?",
               resIds);
         bulkUpdate(
               "update  ClsSubjectLecture set status = 'draft' where deleteFlag is false and status = 'conver' and resItemId = ?",
               resIds);
         return;
      }
      cacheService.lstRightPush(RES_LECTURE_CONVER_LST, resId);
   }
    }
   @Override
   public Result doStudy(String lectureId, Double from, Double to) {
      String userId = null;
      return progressService.addProgress(Progress.PROGRESS_TYPE_LECTURE, lectureId, from.intValue(), to.intValue(),
            userId);
   }
    @Override
    public LectureDocV readDocLecture(String lectureId) {
   @Cacheable(value = "LectureVideoV", key = "#lectureId")
   @Override
   public LectureVideoV readVideoLecture(String lectureId) {
      return read(LectureVideoV.class, lectureId);
   }
        return read(LectureDocV.class, lectureId);
    }
   @Cacheable(value = "LectureAudioV", key = "#lectureId")
   @Override
   public LectureAudioV readAudioLecture(String lectureId) {
      return read(LectureAudioV.class, lectureId);
   }
    public Result updateLecturetime(String targetId) {
   @Override
   public List<SubjectChapter> getAllChapterBySubjectId(String subjectId) {
        SubjectLecture lecture = read(SubjectLecture.class, targetId);
      String hql = "from SubjectChapter where deleteFlag is false and subjectId = ? order by createTime";
      return find(hql, CollectionUtils.newList(subjectId), SubjectChapter.class);
   }
        TraceUtils.setUpdateTrace(lecture);
   @Override
   public LectureDocV readDocLecture(String lectureId) {
        lecture.setUpdateTime(new Date());
        lecture.setUpdator(ClientUtils.getUserId());
        save(lecture);
      return read(LectureDocV.class, lectureId);
   }
        return new Result(true, "success");
    }
}