package com.ischoolbar.programmer.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.ischoolbar.programmer.model.Attendance;
import com.ischoolbar.programmer.model.Page;
import com.ischoolbar.programmer.model.SelectedCourse;
import com.ischoolbar.programmer.util.StringUtil;
/**
* 考勤信息数据库操作
* @author llq
*
*/
public class AttendanceDao extends BaseDao {
/**
* 添加考勤信息
* @param attendance
* @return
*/
public boolean addAttendance(Attendance attendance){
String sql = "insert into s_attendance values(null,"+attendance.getCourseId()+","+attendance.getStudentId()+",'"+attendance.getType()+"','"+attendance.getDate()+"')";
return update(sql);
}
/**
* 判断当前是否已签到
* @param studentId
* @param courseId
* @param type
* @return
*/
public boolean isAttendanced(int studentId,int courseId,String type,String date){
boolean ret = false;
String sql = "select * from s_attendance where student_id = " + studentId + " and course_id = " + courseId + " and type = '" + type + "' and date = '" + date + "'";
ResultSet query = query(sql);
try {
if(query.next()){
return true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ret;
}
/**
* 获取指定的考勤信息列表
* @param attendace
* @param page
* @return
*/
public List<Attendance> getSelectedCourseList(Attendance attendace,Page page){
List<Attendance> ret = new ArrayList<Attendance>();
String sql = "select * from s_attendance ";
if(attendace.getStudentId() != 0){
sql += " and student_id = " + attendace.getStudentId();
}
if(attendace.getCourseId() != 0){
sql += " and course_id = " + attendace.getCourseId();
}
if(!StringUtil.isEmpty(attendace.getType())){
sql += " and type = '" + attendace.getType() + "'";
}
if(!StringUtil.isEmpty(attendace.getDate())){
sql += " and date = '" + attendace.getDate() + "'";
}
sql += " limit " + page.getStart() + "," + page.getPageSize();
sql = sql.replaceFirst("and", "where");
ResultSet resultSet = query(sql);
try {
while(resultSet.next()){
Attendance a = new Attendance();
a.setId(resultSet.getInt("id"));
a.setCourseId(resultSet.getInt("course_id"));
a.setStudentId(resultSet.getInt("student_id"));
a.setType(resultSet.getString("type"));
a.setDate(resultSet.getString("date"));
ret.add(a);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ret;
}
/**
* 获取符合条件记录总数
* @param attendance
* @return
*/
public int getAttendanceListTotal(Attendance attendance){
int total = 0;
String sql = "select count(*)as total from s_attendance ";
if(attendance.getStudentId() != 0){
sql += " and student_id = " + attendance.getStudentId();
}
if(attendance.getCourseId() != 0){
sql += " and course_id = " + attendance.getCourseId();
}
ResultSet resultSet = query(sql.replaceFirst("and", "where"));
try {
while(resultSet.next()){
total = resultSet.getInt("total");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return total;
}
/**
* 删除
* @param id
* @return
*/
public boolean deleteAttendance(int id){
String sql = "delete from s_attendance where id = " + id;
return update(sql);
}
}
最近下载更多
李清清 LV2
2024年11月6日
lxm2440226414 LV2
2024年6月10日
云着殇 LV9
2024年6月5日
lzx602 LV3
2024年4月15日
微信网友_6906962132258816 LV7
2024年3月16日
zhangjilu LV18
2024年1月1日
磊哥哥哥哥 LV13
2023年12月26日
heweimin LV13
2023年12月12日
hapilong LV6
2023年12月11日
蹇金金 LV7
2023年10月31日
最近浏览更多
Maomaoyun
6月10日
暂无贡献等级
zxy111111
6月8日
暂无贡献等级
微信网友_7520905278033920 LV1
5月22日
xianyu091012 LV5
2024年12月26日
言123456
2024年12月24日
暂无贡献等级
3375276400
2024年12月24日
暂无贡献等级
TTThai LV1
2024年12月17日
微信网友_7298641941385216 LV1
2024年12月16日
Daima000 LV4
2024年12月5日
李清清 LV2
2024年11月6日

