派生自 projectDept/qhighschool

yn147
2023-11-24 26780c533f2c2af6b9216306f649c1bcede94e4a
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
package com.qxueyou.scc.admin.attendance.impl;
 
import com.qxueyou.scc.admin.attendance.AttendanceService;
import com.qxueyou.scc.base.model.Pager;
import com.qxueyou.scc.base.model.Result;
import com.qxueyou.scc.base.service.impl.CommonAppService;
import com.qxueyou.scc.base.util.CollectionUtils;
import com.qxueyou.scc.teach.student.model.StuStudent;
import com.qxueyou.scc.teach.subject.model.Subject;
import org.springframework.stereotype.Service;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
 
@Service
public class AttendanceServiceImpl extends CommonAppService implements AttendanceService {
 
    @Override
    public String attendanceUpAndAdd(String userId, String subjectId, String subjectName) {
        String s="";
 
        StringBuffer hql=new StringBuffer("from StuStudent where userId=? and deleteFlag is false");
 
        List<Object> args = CollectionUtils.newList(userId);
 
        StuStudent stuStudent = findUnique(hql.toString(), args, StuStudent.class);
 
        try{
            String hqlTwo = "from Subject where name = ?";
            List<Object> argsTwo = CollectionUtils.newList(subjectName);
            Subject subject = findUnique(hqlTwo,argsTwo,Subject.class);
            //结束时间
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String classTime = sdf.format(subject.getEndTime());
            //当前时间
            String currentTime = sdf.format(new Date());
            //添加subjectId
            if(subject.getSubjectId() == subjectId){
                stuStudent.setSubjectId(subjectId);
            }else {
                stuStudent.setSubjectId(subject.getSubjectId());
            }
            //结束时间 >当前时间
            int compareTo = classTime.compareTo(currentTime);
            if(compareTo>0)
            {
                s="签到时间已过";
                stuStudent.setAttendanceStatus(stuStudent.STATUS_TRUANCY);
            }
            else
            {
                //打卡时间
                String clockTime = sdf.format(subject.getStartTime());
                compareTo = currentTime.compareTo(clockTime);
                if(compareTo<0)
                {
                    s="未到签到时间";
                    stuStudent.setAttendanceStatus(stuStudent.STATUS_NO_CLOCKING);
                }
                else
                {
                    if(stuStudent!=null && subjectId!=null){
                        stuStudent.setAttendanceStatus(stuStudent.STATUS_PUNCHE);
                        s = "成功签到";
                    }
                }
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        save(stuStudent);
        return s;
    }
 
    @Override
    public List<StuStudent> findAttendanceList(Integer limit, Integer pageNum, String keyword, String classId) {
        StringBuffer hql=new StringBuffer("from StuStudent where name like ? and classId = ? and deleteFlag is false");
 
        List<Object> args = CollectionUtils.newList(keyword + "%",classId);
 
        hql.append(" order by createTime desc");
 
        List<StuStudent> list = findList(hql.toString(), new Pager(limit, pageNum), args, StuStudent.class);
 
        return list;
    }
 
    @Override
    public Result updateAttendanceStatus(String[] studentId, String attendanceStatus) {
        boolean pd = true;
        for (String studentIds: studentId){
            StringBuffer hql=new StringBuffer("from StuStudent where studentId=? and deleteFlag is false");
 
            List<Object> args = CollectionUtils.newList(studentIds);
 
            StuStudent stuStudent = findUnique(hql.toString(), args, StuStudent.class);
 
            if(stuStudent!=null && attendanceStatus!=null){
                stuStudent.setAttendanceStatus(attendanceStatus);
                save(stuStudent);
                pd = true;
            }else {
                pd = false;
            }
        }
        return new Result(pd);
    }
 
    @Override
    public int findAttendanceListCount(String keyword, String subjectId) {
        StringBuffer hql=new StringBuffer("from StuStudent where name like ? and subjectId = ? and deleteFlag is false");
 
        List<Object> args = CollectionUtils.newList(keyword + "%",subjectId);
 
        return findCount(hql.toString(),args);
    }
}