greendao实现本地分页查询和模糊查询

	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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值