|
|
@@ -27,8 +27,12 @@ import com.common.data.ListUtils;
|
|
|
import com.common.data.StringUtil;
|
|
|
import com.core.app.MyApplication;
|
|
|
import com.core.base.OABaseActivity;
|
|
|
+import com.core.net.http.http.OAHttpHelper;
|
|
|
+import com.core.net.http.http.OnHttpResultListener;
|
|
|
+import com.core.net.http.http.Request;
|
|
|
import com.core.utils.CommonUtil;
|
|
|
import com.core.utils.ToastUtil;
|
|
|
+import com.core.widget.EmptyLayout;
|
|
|
import com.core.widget.VoiceSearchView;
|
|
|
import com.core.widget.listener.EditChangeListener;
|
|
|
import com.handmark.pulltorefresh.library.PullToRefreshBase;
|
|
|
@@ -52,13 +56,18 @@ import java.util.Map;
|
|
|
public class SelectNetAcitivty extends OABaseActivity {
|
|
|
private HttpClient httpClient;
|
|
|
private String lastKey;
|
|
|
+ private int page = 1;
|
|
|
+
|
|
|
|
|
|
+ //intent
|
|
|
+ private String caller;//传进来的主表caller
|
|
|
+ private String gCaller;//传进来的附表caller,当是明细表时候存在
|
|
|
private String fieldKey;
|
|
|
- private String caller;
|
|
|
- private int page = 1;
|
|
|
- private boolean isForm = true;
|
|
|
+ private String corekey;
|
|
|
+
|
|
|
|
|
|
private PullToRefreshListView refreshListView;
|
|
|
+ private EmptyLayout mEmptyLayout;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
@@ -68,9 +77,14 @@ public class SelectNetAcitivty extends OABaseActivity {
|
|
|
}
|
|
|
|
|
|
private void initView() {
|
|
|
- VoiceSearchView voiceSearchView = (VoiceSearchView) findViewById(R.id.voiceSearchView);
|
|
|
+ VoiceSearchView voiceSearchView = (VoiceSearchView) findViewById(R.id.voiceSearchView);
|
|
|
refreshListView = (PullToRefreshListView) findViewById(R.id.refreshListView);
|
|
|
refreshListView.setMode(PullToRefreshBase.Mode.BOTH);
|
|
|
+ mEmptyLayout = new EmptyLayout(this, refreshListView.getRefreshableView());
|
|
|
+ mEmptyLayout.setShowLoadingButton(false);
|
|
|
+ mEmptyLayout.setShowEmptyButton(false);
|
|
|
+ mEmptyLayout.setShowErrorButton(false);
|
|
|
+ mEmptyLayout.setEmptyMessage("请输入条件查询");
|
|
|
voiceSearchView.addTextChangedListener(new EditChangeListener() {
|
|
|
@Override
|
|
|
public void afterTextChanged(Editable editable) {
|
|
|
@@ -94,12 +108,12 @@ public class SelectNetAcitivty extends OABaseActivity {
|
|
|
if (intent != null) {
|
|
|
fieldKey = intent.getStringExtra("fieldKey");
|
|
|
caller = intent.getStringExtra("caller");
|
|
|
- isForm = intent.getBooleanExtra("isForm",true);
|
|
|
+ gCaller = intent.getStringExtra("gCaller");
|
|
|
+ corekey = intent.getStringExtra("corekey");
|
|
|
}
|
|
|
String baseUrl = CommonUtil.getAppBaseUrl(this);
|
|
|
String sessionId = CommonUtil.getSharedPreferences(this, "sessionId");
|
|
|
Log.i("gongpengming", "baseUrl=" + baseUrl);
|
|
|
- baseUrl = "https://218.17.158.219:9443/uas_test/";
|
|
|
httpClient = new HttpClient.Builder(baseUrl)
|
|
|
.isDebug(true)
|
|
|
// .header("Cookie", "JSESSIONID=" + sessionId)
|
|
|
@@ -110,16 +124,21 @@ public class SelectNetAcitivty extends OABaseActivity {
|
|
|
.readTimeout(5000)
|
|
|
.build();
|
|
|
loadSearch(page = 1, lastKey = "");
|
|
|
+ showLoading();
|
|
|
}
|
|
|
|
|
|
private void loadSearch(int page, final String keyWork) {
|
|
|
- String condition = "upper(" + fieldKey + ") like '%" + keyWork.toUpperCase() + "%'";
|
|
|
- Log.i("gongpengming", "condition=" + condition);
|
|
|
-// condition = "1=1";
|
|
|
- httpClient.Api().send(new HttpClient.Builder()
|
|
|
- .url("common/dbfind.action")
|
|
|
+ String condition = null;
|
|
|
+ if (StringUtil.isEmpty(keyWork)) {
|
|
|
+ condition = "1=1";
|
|
|
+ } else {
|
|
|
+ condition = "upper(" + (StringUtil.isEmpty(corekey) ? fieldKey : corekey) + ") like '%" + keyWork.toUpperCase() + "%'";
|
|
|
+ }
|
|
|
+ HttpClient.Builder builder = new HttpClient.Builder();
|
|
|
+ boolean isForm = StringUtil.isEmpty(gCaller);
|
|
|
+ builder.url("mobile/common/dbfind.action")
|
|
|
.add("which", isForm ? "form" : "grid")
|
|
|
- .add("caller", caller)
|
|
|
+ .add("caller", isForm ? caller : gCaller)
|
|
|
.add("field", fieldKey)
|
|
|
.header("Cookie", "JSESSIONID=" + CommonUtil.getSharedPreferences(this, "sessionId"))
|
|
|
.add("condition", condition)
|
|
|
@@ -127,44 +146,49 @@ public class SelectNetAcitivty extends OABaseActivity {
|
|
|
.add("_config", "")
|
|
|
.add("page", page)
|
|
|
.add("pageSize", 20)
|
|
|
- .method(Method.GET)
|
|
|
- .build(), new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
+ .method(Method.GET);
|
|
|
+ if (!isForm) {
|
|
|
+ builder.add("gridField", fieldKey)
|
|
|
+ .add("gridCaller", caller);
|
|
|
+ }
|
|
|
+ httpClient.Api().send(builder.build(), new ResultSubscriber<>(new ResultListener<Object>() {
|
|
|
@Override
|
|
|
public void onResponse(Object o) {
|
|
|
if (!lastKey.equals(keyWork)) return;
|
|
|
try {
|
|
|
handleData(o.toString());
|
|
|
+ dimssLoading();
|
|
|
} catch (Exception e) {
|
|
|
- if (e != null && !StringUtil.isEmpty(e.getMessage())) {
|
|
|
- Log.i("gongpengming", e.getMessage());
|
|
|
+ dimssLoading();
|
|
|
+ if (mAdapter == null || ListUtils.isEmpty(mAdapter.models)) {
|
|
|
+ mEmptyLayout.showEmpty();
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
refreshListView.onRefreshComplete();
|
|
|
}
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private ListAdapter mAdapter = null;
|
|
|
|
|
|
private void handleData(String messgae) throws Exception {
|
|
|
- LogUtil.prinlnLongMsg("gongpengming", messgae);
|
|
|
+ LogUtil.prinlnLongMsg("gongpengming", "messgae=" + messgae);
|
|
|
JSONObject object = JSON.parseObject(messgae);
|
|
|
- JSONArray dbfinds = JSONUtil.getJSONArray(object, "dbfinds");
|
|
|
- Log.i("gongpengming", "dbfinds=" + dbfinds.size());
|
|
|
+ JSONArray dbfinds = JSONUtil.getJSONArray(object, "dbfinds","gridDbfinds");
|
|
|
String dataStr = JSONUtil.getText(object, "data");
|
|
|
- LogUtil.prinlnLongMsg("gongpengming", "dataStr=" + dataStr);
|
|
|
JSONArray data = JSON.parseArray(dataStr);
|
|
|
- LogUtil.prinlnLongMsg("gongpengming", "data=" + data.size());
|
|
|
+ setData2Adapter(data, dbfinds);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setData2Adapter(JSONArray data, JSONArray dbfinds) throws Exception {
|
|
|
Map<String, String> configMap = new HashMap<>();
|
|
|
//获取配置
|
|
|
JSONObject config = null;
|
|
|
String fieldKeyLike = null;
|
|
|
for (int i = 0; i < dbfinds.size(); i++) {
|
|
|
config = dbfinds.getJSONObject(i);
|
|
|
- String dbGridField = JSONUtil.getText(config, "dbGridField");
|
|
|
- String field = JSONUtil.getText(config, "field");
|
|
|
+ String dbGridField = JSONUtil.getText(config, "dbGridField","ds_dbfindfield");
|
|
|
+ String field = JSONUtil.getText(config, "field","ds_gridfield");
|
|
|
if (!StringUtil.isEmpty(dbGridField) && !StringUtil.isEmpty(field)) {
|
|
|
if (field.equals(fieldKey)) {
|
|
|
fieldKeyLike = dbGridField;
|
|
|
@@ -172,7 +196,6 @@ public class SelectNetAcitivty extends OABaseActivity {
|
|
|
configMap.put(dbGridField, field);
|
|
|
}
|
|
|
}
|
|
|
- Log.i("gongpengming", "configMap=" + JSONUtil.map2JSON(configMap));
|
|
|
JSONObject o = null;
|
|
|
Bean b = null;
|
|
|
List<Bean> models = new ArrayList<>();
|
|
|
@@ -186,11 +209,9 @@ public class SelectNetAcitivty extends OABaseActivity {
|
|
|
jsonMap.put(e.getValue(), JSONUtil.getText(o, e.getKey()));
|
|
|
}
|
|
|
b.json = JSONUtil.map2JSON(jsonMap);
|
|
|
- Log.i("gongpengming", "b.json=" + b.json);
|
|
|
- models.add(b);
|
|
|
+ if (!StringUtil.isEmpty(b.name))
|
|
|
+ models.add(b);
|
|
|
}
|
|
|
-
|
|
|
- Log.i("gongpengming", "models=" + models.size());
|
|
|
if (mAdapter == null) {
|
|
|
mAdapter = new ListAdapter(models);
|
|
|
refreshListView.setAdapter(mAdapter);
|
|
|
@@ -207,10 +228,16 @@ public class SelectNetAcitivty extends OABaseActivity {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+ if (ListUtils.isEmpty(models)) {
|
|
|
+ mEmptyLayout.showEmpty();
|
|
|
+ }
|
|
|
} else {
|
|
|
- if (page==1){
|
|
|
+ if (page == 1) {
|
|
|
mAdapter.setModels(models);
|
|
|
- }else{
|
|
|
+ if (ListUtils.isEmpty(models)) {
|
|
|
+ mEmptyLayout.showEmpty();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
mAdapter.addModls(models);
|
|
|
}
|
|
|
}
|
|
|
@@ -283,7 +310,6 @@ public class SelectNetAcitivty extends OABaseActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
private class Bean {
|
|
|
String name;
|
|
|
String json;
|