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>();
|
}
|
|
}
|