派生自 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
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<Map<String, Object>> 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);
    }
 
}