private void queryLocomotiveList() {
List<Locomotive> locomotiveList = new ArrayList<>();
String locomotiveModeName = tvEngineMode.getText().toString().trim();
String locomotive = tvEngineNo.getText().toString().trim();
try {
//请求参数
ArrayList<String> strParamLt = new ArrayList<String>();
String queryString =
"SELECT DISTINCT * FROM " + LocomotiveDao.TABLENAME + " where 1==1 ";
if (!TextUtils.isEmpty(locomotiveModeName)) {
queryString = queryString + " and " + LocomotiveDao.Properties.TrainModelName.columnName + " = ?";
strParamLt.add(locomotiveModeName);
}
if (!TextUtils.isEmpty(locomotive)) {
queryString = queryString + " and " + LocomotiveDao.Properties.TrainNo.columnName + " like '%" + locomotive + "%' ";
}
if (!TextUtils.isEmpty(healthy) || !TextUtils.isEmpty(attention) || !TextUtils.isEmpty(repair)){
String healthyTypeStr = " and " + "(";
if (!TextUtils.isEmpty(healthy)) {
healthyTypeStr += LocomotiveDao.Properties.HealthAnalysisLevel.columnName + " = ?" + " or ";
strParamLt.add(healthy);
}
if (!TextUtils.isEmpty(attention)) {
healthyTypeStr += LocomotiveDao.Properties.HealthAnalysisLevel.columnName + " = ?" + " or ";
strParamLt.add(attention);
}
if (!TextUtils.isEmpty(repair)) {
healthyTypeStr += LocomotiveDao.Properties.HealthAnalysisLevel.columnName + " = ?";
strParamLt.add(repair);
}
if (healthyTypeStr.endsWith("or ")){
healthyTypeStr = healthyTypeStr.substring(0,healthyTypeStr.length() - 3);
}
healthyTypeStr += ")";
queryString = queryString + healthyTypeStr;
}
Log.e("queryString",queryString);
Object[] objs = strParamLt.toArray();
String[] strs = new String[objs.length];
for (int i = 0; i < objs.length; i++) {
strs[i] = objs[i].toString();
}
Log.e("strs",new Gson().toJson(strs));
Cursor cursor = DaoManager.getInstance().getDaoSession().getDatabase().rawQuery(queryString, strs);
int trainNoIndex = cursor.getColumnIndex(LocomotiveDao.Properties.TrainNo.columnName);
int trainModeNameIndex = cursor.getColumnIndex(LocomotiveDao.Properties.TrainModelName.columnName);
int healthIndex = cursor.getColumnIndex(LocomotiveDao.Properties.HealthAnalysisLevel.columnName);
while (cursor.moveToNext()) {
Locomotive bean = new Locomotive();
bean.setTrainNo(cursor.getString(trainNoIndex));
bean.setTrainModelName(cursor.getString(trainModeNameIndex));
bean.setHealthAnalysisLevel(cursor.getString(healthIndex));
locomotiveList.add(bean);
}
Log.e("locomotiveList",new Gson().toJson(locomotiveList));
} catch (Exception e) {
e.printStackTrace();
}
mAdapter.setNewData(locomotiveList);
}