| | |
| | | public ResultBean reloadLeftList(String searchText, final int pageNum, final boolean append) {
|
| | | ResultBean resultBean = new ResultBean();
|
| | | try {
|
| | | List<AttendanceQueryItem> list = Config.sqlMap.queryForList("selectPersons");
|
| | | 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 ";
|
| | | String deviceCompanyId = BaseApplication.getInstance().getAndroidDevice().getCompanyId();
|
| | | if(deviceCompanyId != null && !deviceCompanyId.trim().isEmpty()) {
|
| | | sql += " AND a.device_company_id = " + deviceCompanyId;
|
| | | }
|
| | | if(searchText != null && !searchText.trim().isEmpty()) {
|
| | | sql += " AND b.username LIKE '%"+ searchText + "%'";
|
| | | }
|
| | | String count = "select count(*) as count from (" + sql + " ) _table";
|
| | | sql += " LIMIT " + getStartIndex(pageNum) + "," + 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[]{});
|
| | | while (c.moveToNext()) {
|
| | | aqi = new AttendanceQueryItem();
|
| | | aqi.setRegisterId(c.getString(c.getColumnIndex("register_id")));
|
| | | aqi.setUsername(c.getString(c.getColumnIndex("username")));
|
| | | aqi.setSurveillancePhoto(c.getString(c.getColumnIndex("surveillance_photo")));
|
| | | aqi.setIdentifyNum(c.getString(c.getColumnIndex("identify_num")));
|
| | | aqi.setPostName(c.getString(c.getColumnIndex("post_name")));
|
| | | aqi.setGender(c.getString(c.getColumnIndex("gender")));
|
| | | aqi.setDeptName(c.getString(c.getColumnIndex("dept_name")));
|
| | | list.add(aqi);
|
| | | }
|
| | | Integer total = null;
|
| | | while (c_count.moveToNext()) {
|
| | | total = c.getInt(c.getColumnIndex("register_id"));
|
| | | }
|
| | | resultBean.setTotalPages(getTotalPageSize(total));
|
| | | resultBean.setPageNum(pageNum);
|
| | | resultBean.setData(list);
|
| | | c.close();
|
| | | return resultBean;
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | |
| | | return list;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取分页开始行
|
| | | * @param pageNum
|
| | | * @return
|
| | | */
|
| | | private int getStartIndex(Integer pageNum){
|
| | | if(pageNum == null || pageNum <= 0){
|
| | | return 0;
|
| | | }
|
| | | return (pageNum-1)*Integer.parseInt(CommonVariables.Page.DEFAULT_PAGE_SIZE);
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取总页数
|
| | | * @param total
|
| | | * @return
|
| | | */
|
| | | private int getTotalPageSize(Integer total){
|
| | | if(total == null || total <= 0){
|
| | | return 1;
|
| | | }
|
| | | int pageSize = Integer.parseInt(CommonVariables.Page.DEFAULT_PAGE_SIZE);
|
| | | return total%pageSize == 0 ? total/pageSize : total/pageSize + 1;
|
| | | }
|
| | |
|
| | | }
|