package com.qxueyou.scc.school.service.impl; import java.math.BigDecimal; import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import com.qxueyou.scc.base.model.Result; 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.school.model.SchStudentScore; import com.qxueyou.scc.school.service.IStudentScoreService; /** * 学员学分服务层 * * @author junliang * @createTime 2017-12-10 */ @Service public class StudentsScoreService extends CommonAppService implements IStudentScoreService { @Override public Result addStudentScore(String classId, String videoId, Integer score) { if (StringUtils.isBlank(videoId) || StringUtils.isBlank(classId) || score == null) { return new Result(false, "failed"); } // 判断班级是否已经加入过学分; String hql = "from SchStudentScore where classId = ? and studentId =? and videoId = ?"; SchStudentScore findUnique = findUnique(hql, CollectionUtils.newList(classId, ClientUtils.getUserId(), videoId), SchStudentScore.class); if (findUnique != null) { return new Result(false, "此课程已添加过学分"); } // 保存学分; SchStudentScore schStudentScore = new SchStudentScore(); TraceUtils.setCreateTrace(schStudentScore); schStudentScore.setClassId(classId); schStudentScore.setVideoId(videoId); BigDecimal scoreValue = new BigDecimal(score); schStudentScore.setScoreValue(scoreValue); schStudentScore.setStudentId(ClientUtils.getUserId()); schStudentScore.setDeleteFlag(false); save(schStudentScore); return new Result(true, "success"); } /** * 获取学员学分 */ @Override public Result getStudentScore() { String hql="select c.classId as classId,c.name as name,s.createTime as createTime,c.studyTime as studyTime,c.score as score," + "c.approveStatus as approveStatus from ClsClass c,SchStudentScore s " + " where c.classId=s.classId and c.mode=1 and c.deleteFlag is false and s.studentId=:userId "; List> result = findListWithMapByHql(hql, CollectionUtils.newObjectMap("userId",ClientUtils.getUserId())); return new Result(true, "success", result); } @Override public Result checkStudyStatus(String classId) { String hql = "from SchStudentScore where classId = ? and studentId =? "; SchStudentScore result = findUnique(hql, CollectionUtils.newList(classId,ClientUtils.getUserId()), SchStudentScore.class); if(result!=null) { return new Result(true); } return new Result(false); } }