public static int PageSize = 15; //分页加载
//无网络本地
QueryBuilder<VisitorModel> builder = MyApplication.getInstance().getDaoSession().getVisitorModelDao()
.queryBuilder();
List<WhereCondition> coditions = buildQuery();
if (coditions != null && coditions.size() > 0) {
WhereCondition[] conditions2 = new WhereCondition[coditions.size()];
for (int i = 0; i < coditions.size(); i++) {
conditions2[i] = coditions.get(i);
}
builder.where(new WhereCondition.StringCondition("1=1"), conditions2);
}
long totalCount = builder.count();
List<VisitorModel> list = builder.orderAsc(VisitorModelDao.Properties.State)
.orderDesc(VisitorModelDao.Properties.BeginDate)
.offset((pageIndex - 1) * Constant.PageSize).limit(Constant.PageSize).list();
Log.e("TTTT", "getData: " + list.size());
for (int i = 0; i < list.size(); i++) {
VisitorModel v = list.get(i);
Log.d("visitorModel", " " + v.VisitorName + " " + v.getStaffName() + " " + v.getOrginazitionName()
+ " " + v.BeginDate + " " + v.LastTime);
}
if (list != null && list.size() > 0) {
pager.setTotalCount((int) totalCount);
adapter.setList(list);
mTvNumber.setText((int) totalCount + "");
dataSetObserver.onChanged();
} else {
adapter.setList(null);
pager.setTotalCount(0);
dataSetObserver.onChanged();
}
//
private List<WhereCondition> buildQuery() {
String BeginDate = mTvLaiTime.getText().toString().trim();
String EndDate = mTvJshuTime.getText().toString().trim();
String VisitorName = mEdtComeName.getText().toString().trim();
String StaffName = mEdtBeName.getText().toString().trim();
String OrginazitionName = mEdtBeDemp.getText().toString().trim();
int state = FormStatus.VistorStatus(mSpStatus.getSelectedItem().toString());
List<WhereCondition> coditions = new ArrayList<>();
if (!TextUtils.isEmpty(BeginDate)) {
BeginDate += " 00:00:00";
}
if (!TextUtils.isEmpty(EndDate)) {
EndDate += " 23:59:59";
}
coditions.add(VisitorModelDao.Properties.BeginDate.ge(getTime(BeginDate)));
coditions.add(VisitorModelDao.Properties.BeginDate.le(getTime(EndDate)));
if (!TextUtils.isEmpty(VisitorName)) {
coditions.add(VisitorModelDao.Properties.VisitorName.like("%" + VisitorName + "%"));
}
if (!TextUtils.isEmpty(StaffName)) {
coditions.add(VisitorModelDao.Properties.StaffName.like("%" + StaffName + "%"));
}
if (!TextUtils.isEmpty(OrginazitionName)) {
coditions.add(VisitorModelDao.Properties.OrginazitionName.like("%" + OrginazitionName + "%"));
}
if (state > 0) {
coditions.add(VisitorModelDao.Properties.State.eq(state));
}
return coditions;
}
//
private Date getTime(String time) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = null;
try {
date = sdf.parse(time);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
greendao实现本地分页查询和模糊查询
最新推荐文章于 2023-09-14 15:24:18 发布