派生自 projectDept/qhighschool

胡仁荣
2022-10-31 fe7381d6e8ec1f427408de0297ac7f41533202f6
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
package com.qxueyou.scc.admin.progress.dao;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
 
import com.qxueyou.scc.admin.progress.model.Progress;
import com.qxueyou.scc.admin.progress.model.SubjectLectureProgressDetail;
import com.qxueyou.scc.admin.progress.model.view.SubjectProgressTreeV;
import com.qxueyou.scc.admin.progress.service.impl.StudyProgressUtils;
import com.qxueyou.scc.base.dao.BaseDAO;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.teach.subject.model.Subject;
 
@Repository
public class ProgressDAO extends BaseDAO {
 
    public Progress getProgress(String progressTypeLecture, String targetId, String learnerId) {
 
        String hql = "from Progress where type=:type and learnerId=:learnerId and targetId=:targetId";
        Progress progress = findUniqueByHql(hql, CollectionUtils.newObjectMap("type", Progress.PROGRESS_TYPE_LECTURE,
                "learnerId", learnerId, "targetId", targetId));
 
        return progress;
    }
 
    /**
     * ¸ù¾ÝtargetIdºÍlearnerId»ñÈ¡½ø¶È
     * 
     * @param targetId
     *            targetId
     * @param learnerId
     *            Ñ§Ï°Õßid
     * @return
     */
    @Cacheable(value = "progress", key = "#targetId+#learnerId")
    public int[][] getProgress(String targetId, String learnerId) {
        List<SubjectLectureProgressDetail> lstDetail = this.find("from SubjectLectureProgressDetail where targetId = ? and learnerId = ? and deleteFlag is false", CollectionUtils.newList(targetId, learnerId), SubjectLectureProgressDetail.class);
        if(lstDetail == null || lstDetail.isEmpty()) {
            return new int[][] {};
        }else {
             int[][] progress = new  int[lstDetail.size()][2];
             int i = 0;
             for(SubjectLectureProgressDetail objDetail : lstDetail) {
                 progress[i++] = new int[] {objDetail.getStart(), objDetail.getEnd()};
             }
             
             return progress;
        }
    }
 
    @CachePut(value = "progress", key = "#targetId+#learnerId")
    public int[][] mergeProgress(String targetId, String learnerId, int start, int end, int[][] origProgress) {
        return StudyProgressUtils.merge(origProgress, start, end);
    }
 
    /**
     * »ñȡѧÉúµÄ¸÷¸ö½ÚµãµÄѧϰ½ø¶È,½ø¶ÈÖµ
     * 
     * @param parentId
     * @param userId
     * @return
     */
    public Map<String, Object> getItemProgress(String parentId, String userId) {
        String getProgressAvgByHql = "select avg(percent) as progressPercent , sum(progressValue) as progressValue"
                + "  from  SubjectProgressTreeV  where  parentId =:parentId and id.userId =:userId";
        List<Map<String, Object>> mapLst = findListWithMapByHql(getProgressAvgByHql,
                CollectionUtils.newObjectMap("parentId", parentId, "userId", userId));
        Map<String, Object> map = mapLst.get(0);
        return map;
    }
 
    /**
     * »ñÈ¡µ±Ç°½Úµãϵĸ¸½Úµã
     * 
     * @param nodeId
     * @return
     */
    public SubjectProgressTreeV getSubjectProgressTreeV(String nodeId, String userId) {
        String hql = "from SubjectProgressTreeV where  id.nodeId =:nodeId and id.userId =:userId";
        SubjectProgressTreeV subjectProgressTreeV = findUniqueByHql(hql,
                CollectionUtils.newObjectMap("nodeId", nodeId, "userId", userId));
        return subjectProgressTreeV;
    }
 
    /**
     * ¸ù¾ÝsubjectId»ñȡսÚÁбí
     * 
     * @param parentId
     * @param userId
     * @return
     */
    public List<SubjectProgressTreeV> getSubjectChapterTreeVList(String parentId, String userId) {
        String hql = "from SubjectProgressTreeV where  parentId =:parentId and id.userId =:userId and nodeType='chapter' order by createTime asc";
        return findByComplexHql(hql, CollectionUtils.newObjectMap("parentId", parentId, "userId", userId),
                SubjectProgressTreeV.class);
    }
 
    /**
     * »ñÈ¡progress ¶ÔÏó
     */
    public Progress getProgressObject(String targetId, String userId) {
        return findUniqueByHql(
                "from Progress where targetId =:targetId and learnerId =:userId  and deleteFlag is false",
                CollectionUtils.newObjectMap("targetId", targetId, "userId", userId));
    }
 
    /**
     * ¼Ç¼Óû§Ã¿¸ö¿Î³ÌѧϰµÄλÖÃ
     */
    @CachePut(value = "lastStudied", key = "#userId + #subjectId + #classId")
    public Map<String, Object> putStudyById(String userId, String subjectId, String lectureId, String lectureParentId,
            String classId) {
        Map<String, Object> map = new HashMap<String, Object>(4);
        Subject subject = this.read(Subject.class, subjectId);
        map.put("subjectId", subjectId);
        map.put("lectureId", lectureId);
        map.put("lectureParentId", lectureParentId);
        map.put("classId", classId);
        map.put("subjectName", subject.getName());
        return map;
    }
 
    @CachePut(value = "lastStudied", key = "#userId")
    public Map<String, Object> putStudyByUserId(String userId, String subjectId, String lectureId,
            String lectureParentId, String classId) {
        Map<String, Object> map = new HashMap<String, Object>(4);
        map.put("subjectId", subjectId);
        map.put("lectureId", lectureId);
        map.put("lectureParentId", lectureParentId);
        map.put("classId", classId);
        return map;
    }
 
    /**
     * »ñÈ¡Óû§Ã¿¸ö¿Î³ÌÉÏ´ÎѧϰµÄÊý¾Ý
     */
    @Cacheable(value = "lastStudied", key = "#userId + #subjectId +#classId")
    public Map<String, Object> getStudyById(String userId, String subjectId, String classId) {
        return new HashMap<String, Object>();
    }
 
    /**
     * »ñÈ¡Óû§ÉÏ´ÎѧϰµÄÊý¾Ý
     */
    @Cacheable(value = "lastStudied", key = "#userId")
    public Map<String, Object> getStudyByUserId(String userId) {
        return new HashMap<String, Object>();
    }
 
}