派生自 projectDept/qhighschool

EricsHu
2022-12-05 068fc7f2e81178e55fa191a13709af64b1a163f6
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>();
    }
 
}