| | |
| | | package cn.com.basic.face.service.sqlite;
|
| | |
|
| | | import android.content.Context;
|
| | | import android.database.Cursor;
|
| | | import android.database.sqlite.SQLiteDatabase;
|
| | | import android.database.sqlite.SQLiteOpenHelper;
|
| | |
|
| | | import com.awsle.aibatis.client.SqlMapClient;
|
| | | import com.awsle.aibatis.client.SqlMapClientBuilder;
|
| | | import com.awsle.aibatis.exception.IdNotFoundException;
|
| | | import com.lidroid.xutils.DbUtils;
|
| | |
|
| | | import org.xutils.http.RequestParams;
|
| | | import org.xutils.x;
|
| | |
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | |
|
| | | import cn.com.basic.face.base.BaseApplication;
|
| | | import cn.com.basic.face.base.Config;
|
| | | import cn.com.basic.face.base.MainActivity;
|
| | | import cn.com.basic.face.discern.common.BaseCommonCallBack;
|
| | | import cn.com.basic.face.discern.common.CommonVariables;
|
| | | import cn.com.basic.face.discern.common.ResultBean;
|
| | | import cn.com.basic.face.discern.query.condition.AttendanceDetailQueryCondition;
|
| | | import cn.com.basic.face.discern.query.condition.AttendanceQueryCondition;
|
| | | import cn.com.basic.face.discern.query.item.AttendanceDetailQueryItem;
|
| | | import cn.com.basic.face.discern.query.item.AttendanceQueryItem;
|
| | | import cn.com.basic.face.fragment.AttendanceFragment;
|
| | | import cn.com.basic.face.util.AppApi;
|
| | | import cn.com.basic.face.util.DateUtil;
|
| | |
|
| | | /**
|
| | | * 考勤记录
|
| | |
| | | */
|
| | | public ResultBean reloadLeftList(String searchText, final int pageNum, final boolean append) {
|
| | | ResultBean resultBean = new ResultBean();
|
| | | SQLiteDatabase db = Config.sqlMap.getDb();
|
| | | db.beginTransaction();
|
| | | try {
|
| | | SQLiteDatabase db = Config.sqlMap.getDb();
|
| | | String sql = "SELECT b.register_id," +
|
| | | " b.username," +
|
| | | " b.surveillance_photo," +
|
| | | " b.identify_num," +
|
| | | " e.post_name," +
|
| | | " d.`name` gender," +
|
| | | " f.dept_name" +
|
| | | " FROM " +
|
| | | " employee a " +
|
| | | " LEFT JOIN register b ON a.register_id = b.register_id " +
|
| | | " LEFT JOIN dictionary d ON d.dict_id = b.gender_id " +
|
| | | " LEFT JOIN post e ON e.post_id = b.post_id " +
|
| | | " LEFT JOIN department f ON f.dept_id = b.department_id " +
|
| | | " WHERE " +
|
| | | " 1 = 1 " +
|
| | | " GROUP BY b.register_id " +
|
| | | " ORDER BY b.username ";
|
| | | StringBuilder sb = new StringBuilder(40);
|
| | | sb.append("SELECT b.register_id,").append(" b.username,").append(" b.surveillance_photo,")
|
| | | .append(" b.identify_num,").append(" e.post_name,").append(" d.`name` gender,")
|
| | | .append(" f.dept_name").append(" FROM ").append(" employee a ")
|
| | | .append(" LEFT JOIN register b ON a.register_id = b.register_id ")
|
| | | .append(" LEFT JOIN dictionary d ON d.dict_id = b.gender_id ")
|
| | | .append(" LEFT JOIN post e ON e.post_id = b.post_id ")
|
| | | .append(" LEFT JOIN post e ON e.post_id = b.post_id ")
|
| | | .append(" LEFT JOIN department f ON f.dept_id = b.department_id ")
|
| | | .append(" WHERE ").append(" 1 = 1 ").append(" GROUP BY b.register_id ")
|
| | | .append(" ORDER BY b.username ");
|
| | | String deviceCompanyId = BaseApplication.getInstance().getAndroidDevice().getCompanyId();
|
| | | if(deviceCompanyId != null && !deviceCompanyId.trim().isEmpty()) {
|
| | | sql += " AND a.device_company_id = " + deviceCompanyId;
|
| | | sb.append(" AND a.device_company_id = ").append(deviceCompanyId);
|
| | | }
|
| | | if(searchText != null && !searchText.trim().isEmpty()) {
|
| | | sql += " AND b.username LIKE '%"+ searchText + "%'";
|
| | | sb.append(" AND b.username LIKE '%").append(searchText).append("%'");
|
| | | }
|
| | | String count = "select count(*) as count from (" + sql + " ) _table";
|
| | | sql += " LIMIT " + getStartIndex(pageNum) + "," + CommonVariables.Page.DEFAULT_PAGE_SIZE;
|
| | | StringBuilder count = new StringBuilder(sb.length());
|
| | | count.append("select count(*) as count from (").append(sb).append(" ) _table");
|
| | | sb.append(" LIMIT ").append(getStartIndex(pageNum)).append(",").append(CommonVariables.Page.DEFAULT_PAGE_SIZE);
|
| | | List<AttendanceQueryItem> list = new ArrayList<AttendanceQueryItem>();
|
| | | int b = list.size();
|
| | | AttendanceQueryItem aqi = null;
|
| | | Cursor c = db.rawQuery(sql,new String[]{});
|
| | | Cursor c_count = db.rawQuery(count,new String[]{});
|
| | | Cursor c = db.rawQuery(sb.toString(),new String[]{});
|
| | | Cursor c_count = db.rawQuery(count.toString(),new String[]{});
|
| | | while (c.moveToNext()) {
|
| | | aqi = new AttendanceQueryItem();
|
| | | aqi.setRegisterId(c.getString(c.getColumnIndex("register_id")));
|
| | |
| | | resultBean.setPageNum(pageNum);
|
| | | resultBean.setData(list);
|
| | | c.close();
|
| | | return resultBean;
|
| | | c_count.close();
|
| | | db.setTransactionSuccessful();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | db.endTransaction();
|
| | | }
|
| | | return resultBean;
|
| | | }
|
| | |
| | | */
|
| | | public List<AttendanceDetailQueryItem> reloadAttendanceDetail(AttendanceQueryItem item) {
|
| | | List<AttendanceDetailQueryItem> list = new ArrayList();
|
| | | SQLiteDatabase db = Config.sqlMap.getDb();
|
| | | db.beginTransaction();
|
| | | try {
|
| | |
|
| | | StringBuilder sb = new StringBuilder(40);
|
| | | sb.append("SELECT a.time,").append(" b.device_name,").append(" case when a.attendance_type_id=305 then '签到'")
|
| | | .append(" when a.attendance_type_id=306 then '签退'").append(" else '' end attendance_type")
|
| | | .append(" FROM ").append(" attendance a ")
|
| | | .append(" LEFT JOIN device b ON b.device_id = a.device_id ")
|
| | | .append(" WHERE 1=1 ");
|
| | | String registerId = item.getRegisterId();
|
| | | if(registerId != null && !registerId.trim().isEmpty()) {
|
| | | sb.append(" AND a.register_id= ").append(registerId);
|
| | | }
|
| | | String deviceId = BaseApplication.getInstance().getAndroidDevice().getDeviceId();
|
| | | if(deviceId != null && !deviceId.trim().isEmpty()) {
|
| | | sb.append(" AND b.device_id=").append(deviceId);
|
| | | }
|
| | | String deviceCompanyId = BaseApplication.getInstance().getAndroidDevice().getCompanyId();
|
| | | if(deviceCompanyId != null && !deviceCompanyId.trim().isEmpty()) {
|
| | | sb.append(" AND a.device_company_id = ").append(deviceCompanyId);
|
| | | }
|
| | | sb.append("ORDER BY a.time DESC");
|
| | | StringBuilder count = new StringBuilder(sb.length());
|
| | | count.append("select count(*) as count from (").append(sb).append(" ) _table");
|
| | | sb.append(" LIMIT ").append("0").append(",").append(100);
|
| | | AttendanceDetailQueryItem aqi = null;
|
| | | Cursor c = db.rawQuery(sb.toString(),new String[]{});
|
| | | Cursor c_count = db.rawQuery(count.toString(),new String[]{});
|
| | | while (c.moveToNext()) {
|
| | | aqi = new AttendanceDetailQueryItem();
|
| | | aqi.setTime(c.getString(c.getColumnIndex("time")));
|
| | | aqi.setDeviceName(c.getString(c.getColumnIndex("device_name")));
|
| | | aqi.setAttendanceType(c.getString(c.getColumnIndex("attendance_type")));
|
| | | list.add(aqi);
|
| | | }
|
| | | Integer total = null;
|
| | | while (c_count.moveToNext()) {
|
| | | total = c.getInt(c.getColumnIndex("register_id"));
|
| | | }
|
| | | c.close();
|
| | | c_count.close();
|
| | | db.setTransactionSuccessful();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | db.endTransaction();
|
| | | }
|
| | | return list;
|
| | | }
|