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{
|
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
//上课时间
|
String s1 = "9:00:00";
|
//当前时间
|
String s2 = sdf.format(new Date());
|
String hqlTwo = "from Subject where name = ?";
|
List<Object> argsTwo = CollectionUtils.newList(subjectName);
|
Subject subject = findUnique(hqlTwo,argsTwo,Subject.class);
|
//添加subjectId
|
if(subject.getSubjectId() == subjectId){
|
stuStudent.setSubjectId(subjectId);
|
}else {
|
stuStudent.setSubjectId(subject.getSubjectId());
|
}
|
//如果上课时间(9点)>当前时间
|
int compareTo = s1.compareTo(s2);
|
if(compareTo>0)
|
{
|
s="签到时间已过,本节课按照旷课处理";
|
stuStudent.setAttendanceStatus("旷课");
|
}
|
else
|
{
|
String s3 = "8:50:00";
|
compareTo = s2.compareTo(s3);
|
if(compareTo<0)
|
{
|
s="未到签到时间,请与上课时间前10分钟签到";
|
stuStudent.setAttendanceStatus("未打卡");
|
}
|
else
|
{
|
if(stuStudent!=null && subjectId!=null){
|
stuStudent.setAttendanceStatus("已打卡");
|
s = "成功签到";
|
}
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
e.printStackTrace();
|
}
|
save(stuStudent);
|
return s;
|
}
|
|
@Override
|
public List<StuStudent> findAttendanceList(Integer limit, Integer pageNum, 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);
|
|
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);
|
}
|
}
|