派生自 projectDept/qhighschool

Administrator
2022-12-12 888af852af74ecd24f4f4370b61427771e60d314
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
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;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
 
import com.qxueyou.scc.admin.classes.model.ClsSubjectLecture;
import com.qxueyou.scc.admin.progress.model.Progress;
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.ICacheService;
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.teach.res.model.Res;
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.service.ILectureService;
import com.qxueyou.scc.teach.subject.service.ISubjectService;
import org.springframework.transaction.annotation.Transactional;
 
@Service
public class SubjectLectureService extends CommonAppService implements ILectureService {
 
    public static final String RES_LECTURE_CONVER_LST = "RES_LECTURE_CONVER_LST";
 
    @Autowired
    ISubjectService subjectService;
 
    @Autowired
    IResService resService;
 
    @Autowired
    ICacheService cacheService;
 
    @Autowired
    IProgressService progressService;
 
    @Autowired
    IClassLectureService clsLectureService;
 
    @Override
    public Result addChapter(String subjectId, String parentChapterId, String name) {
 
        SubjectChapter chapter = new SubjectChapter();
 
        TraceUtils.setCreateTrace(chapter);
        chapter.setName(name);
        chapter.setParentChapterId(parentChapterId);
        chapter.setSubjectId(subjectId);
 
        save(chapter);
 
        return new Result(true, "success", CollectionUtils.newObjectMap("id", chapter.getChapterId(), "name", name));
 
    }
 
    @Override
    public Result updateChapter(String chapterId, String name) {
 
        SubjectChapter chapter = read(SubjectChapter.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) {
 
        SubjectChapter chapter = read(SubjectChapter.class, chapterId);
 
        TraceUtils.setUpdateTrace(chapter);
        chapter.setDeleteFlag(true);
 
        save(chapter);
        Result result = this.deleteCourseware4Chapter(chapterId);
        if (!result.isSuccess()) {
            return result;
        }
        return new Result(true, "success");
    }
 
    private Result deleteCourseware4Chapter(String chapterId) {
 
        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) {
 
        List<SubjectChapter> result = getListChapter(subjectId, parentChapterId);
 
        if (result.isEmpty() && StringUtils.isEmpty(parentChapterId)) {
            return CollectionUtils.newList(SubjectChapter.class, initLectureChapter(subjectId));
        }
 
        return result;
    }
 
    @Override
    public List<SubjectProgressTreeV> getChapterTreeVList(String subjectId, String parentChapterId) {
 
        if (parentChapterId == null) {
            return progressService.getSubjectChapterTreeVList(subjectId, ClientUtils.getUserId());
        }
 
        return progressService.getSubjectChapterTreeVList(parentChapterId, ClientUtils.getUserId());
    }
 
    /**
     * 初始化
     *
     * @param subjectId
     * @return
     */
    private SubjectChapter initLectureChapter(String subjectId) {
 
        SubjectChapter chapter = new SubjectChapter();
 
        TraceUtils.setCreateTrace(chapter);
        chapter.setName("根节点");
        chapter.setSubjectId(subjectId);
        chapter.setParentChapterId(SubjectChapter.ROOT_CHAPTER_ID);
 
        save(chapter);
 
        return chapter;
    }
 
    @Override
    public Result addLecture(String chapterId, String resId) {
 
        SubjectChapter chapter = read(SubjectChapter.class, chapterId);
 
        Res res = resService.read(resId);
 
        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);
 
        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 List<SubjectLecture> listLecture(String chapterId, String keyword, Integer pageSize, Integer pageNum,
                                            String type) {
 
        StringBuffer hql = new StringBuffer("from SubjectLecture where chapterId=? and name like ? and deleteFlag is false");
        List<Object> args = CollectionUtils.newList(chapterId, '%' + keyword.trim() + '%');
 
        if (StringUtils.isNotEmpty(type)) {
            hql.append(" and lectureType=?");
            args.add(type);
        }
 
        List<SubjectLecture> result = findList(hql.toString(), new Pager(pageSize, 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);
 
        if (StringUtils.isNotEmpty(type)) {
            hql.append(" and lectureType=?");
            args.add(type);
        }
 
        List<MyLectureV> result = findList(hql.toString(), new Pager(pageSize, pageNum), args, MyLectureV.class);
 
        return result;
    }
 
    @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);
        }
 
        List<MyLectureV> result = findList(hql.toString(), new Pager(pageSize, pageNum), args, MyLectureV.class);
 
        return result;
    }
 
    @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);
 
        if (StringUtils.isNotEmpty(type)) {
            hql.append(" and lectureType=?");
            args.add(type);
        }
 
        List<MyOpenLectureV> result = findList(hql.toString(), new Pager(pageSize, pageNum), args, MyOpenLectureV.class);
 
        return result;
    }
 
    @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);
 
        List<SubjectLecture> result = findList(hql.toString(), new Pager(limit, pageNum), args, SubjectLecture.class);
        return result;
    }
 
    @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);
 
        List<MyOpenLectureV> result = findList(hql.toString(), new Pager(limit, pageNum), args, MyOpenLectureV.class);
        return result;
    }
 
    @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");
 
        List<Object> args = CollectionUtils.newList(chapterId, '%' + keyword.trim() + '%');
 
        if (StringUtils.isNotEmpty(type)) {
            hql.append(" and lectureType=?");
            args.add(type);
        }
 
        return findCount(hql.toString(), args);
 
    }
 
    @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 SubjectLecture readLecture(String lectureId) {
        return read(SubjectLecture.class, lectureId);
    }
 
    @Override
    public SubjectChapter readChapter(String chapterId) {
        return read(SubjectChapter.class, chapterId);
    }
 
    @Override
    public List<SubjectChapter> getListChapter(String subjectId, String parentChapterId) {
 
        StringBuffer hql = new StringBuffer(
                "from SubjectChapter where subjectId=? and deleteFlag is false and parentChapterId=?");
 
        List<Object> args = CollectionUtils.newList(subjectId);
 
        if (StringUtils.isEmpty(parentChapterId)) {
            args.add(SubjectChapter.ROOT_CHAPTER_ID);
        } else {
            args.add(parentChapterId);
        }
 
        List<SubjectChapter> result = find(hql.toString(), args, SubjectChapter.class);
 
        return result;
    }
 
    @Override
    public List<SubjectLecture> listLectureBySubjectId(String subjectId) {
        String hql = "from SubjectLecture where subjectId=? and deleteFlag is false";
 
        List<SubjectLecture> result = find(hql, CollectionUtils.newList(subjectId), SubjectLecture.class);
 
        return result;
    }
 
    /**
     * 监控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);
    }
 
    @Cacheable(value = "LectureVideoV", key = "#lectureId")
    @Override
    public LectureVideoV readVideoLecture(String lectureId) {
        return read(LectureVideoV.class, lectureId);
    }
 
    @Cacheable(value = "LectureAudioV", key = "#lectureId")
    @Override
    public LectureAudioV readAudioLecture(String lectureId) {
        return read(LectureAudioV.class, lectureId);
    }
 
    @Override
    public List<SubjectChapter> getAllChapterBySubjectId(String subjectId) {
 
        String hql = "from SubjectChapter where deleteFlag is false and subjectId = ? order by createTime";
        return find(hql, CollectionUtils.newList(subjectId), SubjectChapter.class);
 
    }
 
    @Override
    public LectureDocV readDocLecture(String lectureId) {
 
        return read(LectureDocV.class, lectureId);
    }
 
    public Result updateLecturetime(String targetId) {
 
        SubjectLecture lecture = read(SubjectLecture.class, targetId);
 
 
        TraceUtils.setUpdateTrace(lecture);
 
        lecture.setUpdateTime(new Date());
        lecture.setUpdator(ClientUtils.getUserId());
        save(lecture);
 
        return new Result(true, "success");
    }
 
}