Преглед на файлове

Add search result and detail saving function -- 添加查询结果和detail的保存功能(issue50: #28) 完成了查询结果保存
Add public functions that generates the current date and datetime -- 添加生成当前日期和时间的公共函数(resolve: #14298)

Ray Zhang преди 4 години
родител
ревизия
d59482b837

+ 19 - 0
ApexDrivers/RAUtilsLibrary/src/main/java/com/usai/redant/rautils/utils/RAUtil.java

@@ -22,6 +22,7 @@ import androidx.core.app.ActivityCompat;
 import androidx.core.content.PermissionChecker;
 import androidx.appcompat.app.AlertDialog;
 import android.text.TextUtils;
+import android.text.format.DateFormat;
 import android.util.DisplayMetrics;
 import android.util.Log;
 
@@ -40,6 +41,7 @@ import java.lang.reflect.Array;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -63,8 +65,25 @@ public class RAUtil {
         return jsobj;
 
     }
+    public static String getCurrentDateTime()
+    {
+        Calendar c = Calendar.getInstance();
+        String date= DateFormat.format(
+                "yyyy-MM-dd HH:mm:ss",
+                c.getTime()).toString();
+        return date;
+    }
 
+    public static String getCurrentDate()
+    {
+        Calendar c = Calendar.getInstance();
 
+
+        String date= DateFormat.format(
+                "yyyy-MM-dd",
+                c.getTime()).toString();
+        return date;
+    }
     public static String getStringFromAsset(Context context, String fileName) {
         // 将json数据变成字符串
         StringBuilder stringBuilder = new StringBuilder();

+ 47 - 47
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/dataprovider/OnlineDataProvider.java

@@ -1648,56 +1648,56 @@ public class OnlineDataProvider extends com.usai.redant.rautils.utils.Network
 //		return json;
 
 	}
-
-	public static JSONObject saveSearchParametersForModuleWithName(String intentStr, String paramStr, String module, String name) {
-
-
-		if(true)
-			throw new AssertionError("OnlinedataProvider::saveSearchParametersForModuleWithName not impl");
-		return null;
 //
-//		boolean success = true;
-//		try {
-//			SQLiteDatabase db = dbUtil.OpenDB(TradeFilingApplication.get_instance(), null, true);
-//
-//			db.execSQL("insert into history(params,name,criterion,module_name,user,create_time) values('"
-//					+ intentStr
-//					+ "','"
-//					+ name
-//					+ "','"
-//					+ paramStr
-//					+ "','"
-//					+ module
-//					+ "','"
-//					+ TradeFilingApplication.get_user()
-//					+ "',"
-//					+ System.currentTimeMillis() + ")");
-//			dbUtil.CloseDB(db);
-//
-//		} catch (Exception e) {
-//			e.printStackTrace();
-//			success = false;
-//		}
+//	public static JSONObject saveSearchParametersForModuleWithName(String intentStr, String paramStr, String module, String name) {
 //
-//		JSONObject json = new JSONObject();
 //
-//		try {
-//			if (success) {
-//
-//				json.put("result", RESULT_TRUE);
-//				json.put("err_msg", "save success.");
-//
-//			} else {
-//
-//				json.put("result", RESULT_FALSE);
-//				json.put("err_msg", "Sorry, something is wrong.");
-//			}
-//		} catch (JSONException e) {
-//			e.printStackTrace();
-//		}
-//
-//		return json;
-	}
+//		if(true)
+//			throw new AssertionError("OnlinedataProvider::saveSearchParametersForModuleWithName not impl");
+//		return null;
+////
+////		boolean success = true;
+////		try {
+////			SQLiteDatabase db = dbUtil.OpenDB(TradeFilingApplication.get_instance(), null, true);
+////
+////			db.execSQL("insert into history(params,name,criterion,module_name,user,create_time) values('"
+////					+ intentStr
+////					+ "','"
+////					+ name
+////					+ "','"
+////					+ paramStr
+////					+ "','"
+////					+ module
+////					+ "','"
+////					+ TradeFilingApplication.get_user()
+////					+ "',"
+////					+ System.currentTimeMillis() + ")");
+////			dbUtil.CloseDB(db);
+////
+////		} catch (Exception e) {
+////			e.printStackTrace();
+////			success = false;
+////		}
+////
+////		JSONObject json = new JSONObject();
+////
+////		try {
+////			if (success) {
+////
+////				json.put("result", RESULT_TRUE);
+////				json.put("err_msg", "save success.");
+////
+////			} else {
+////
+////				json.put("result", RESULT_FALSE);
+////				json.put("err_msg", "Sorry, something is wrong.");
+////			}
+////		} catch (JSONException e) {
+////			e.printStackTrace();
+////		}
+////
+////		return json;
+//	}
 
 	public static String getDisplayFieldsForFunction(String function) {
 

+ 71 - 2
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/dataprovider/RADataProvider.java

@@ -1,6 +1,7 @@
 package com.usai.ratradefiling.dataprovider;
 
 import android.os.Bundle;
+import android.text.TextUtils;
 
 import com.usai.ratradefiling.TradeFilingApplication;
 import com.usai.redant.rautils.utils.FileManager;
@@ -30,8 +31,76 @@ public class RADataProvider {
     {
         return 0;
     }
-    public static JSONObject saveSearchParametersForModuleWithName(String intentStr, String paramStr, String module, String name) {
-        return null;
+    public static boolean saveSearchParametersForModuleWithName(String intentStr, JSONObject param, String module, String name) {
+
+
+
+        String userfilePath = TradeFilingApplication.get_instance().getFilesDir().getPath()+"/saved_search_"+TradeFilingApplication.get_instance().get_user()+".json";
+        String  json_user=FileManager.readJson(userfilePath);
+
+
+        JSONArray array=null;
+        if(TextUtils.isEmpty(json_user))
+        {
+            array = new JSONArray();
+
+        }
+        else
+        {
+            try
+            {
+                array = new JSONArray(json_user) ;
+            } catch (JSONException e)
+            {
+                array = new JSONArray();
+                e.printStackTrace();
+            }
+
+        }
+
+        if(array.length()>=20)
+        {
+            array.remove(0);
+        }
+
+        JSONObject item = new JSONObject();
+        try
+        {
+        if(TradeFilingApplication.get_company_list().length()>0)
+        {
+
+
+                param.put("company",TradeFilingApplication.get_company_list().optJSONObject(TradeFilingApplication.get_current_company_index()).optString("id"));
+
+
+            item.put("company_name",TradeFilingApplication.get_company_list().optJSONObject(TradeFilingApplication.get_current_company_index()).optString("name"));
+
+        }
+
+            item.put("module",module);
+            item.put("name",name);
+            item.put("param",param);
+            item.put("current_date",RAUtil.getCurrentDateTime());
+
+
+            array.put(item);
+
+        } catch (JSONException e)
+        {
+            e.printStackTrace();
+            return false;
+        }
+
+
+
+
+
+        FileManager.writeJson(array.toString(),userfilePath);
+
+        return true;
+
+
+
     }
     public static File downloadFile(Bundle params, String download_url,String dir) {
         return null;

+ 49 - 36
ApexDrivers/ratradefiling/src/main/java/com/usai/ratradefiling/result/ResultPresenter.java

@@ -471,8 +471,9 @@ public class ResultPresenter implements ResultAdapter.ApexResultAdapterDataSourc
             getDelegate().onStartLoading();
         }
 
+
         JSONObject json = RAUtil.Bundle2Json(mParams);
-        if (mFields != null) {
+        if (!TextUtils.isEmpty(mFields)) {
             try {
                 json.put("columns", mFields);
             } catch (JSONException e) {
@@ -481,47 +482,59 @@ public class ResultPresenter implements ResultAdapter.ApexResultAdapterDataSourc
         }
 
 
-        final String paramStr = json.toString();
-        final String module_name = mParams.getString("module_name");
-
-        OperationQueue.sharedQueue().addOperationTask(new OperationQueue.OperationBackgroundCallBack() {
-            @Override
-            public Object operationDoInBackground() {
-                return RADataProvider.saveSearchParametersForModuleWithName(intentStr, paramStr, module_name, name);
-            }
-        }, new OperationQueue.OperationCompletionCallBack() {
-            @Override
-            public void operationCompletion(Object object) {
-
-                if (getDelegate() != null) {
-
-                    getDelegate().onStopLoading();
-
-                    JSONObject json = (JSONObject)object;
-
-                    int result = OnlineDataProvider.RESULT_FALSE;
-                    String msg = "Sorry, something is wrong.";
-                    if (json != null) {
+//        final String paramStr = json.toString();
 
-                        result = json.optInt("result", OnlineDataProvider.RESULT_FALSE);
-                        if (result != OnlineDataProvider.RESULT_TRUE) {
-                            String err_msg = json.optString("err_msg");
-                            if (!TextUtils.isEmpty(err_msg)) {
-                                msg = err_msg;
-                            }
-                        }
-                    } // json
+        final String module_name = mParams.getString("sub_type");
 
-                    if (result != OnlineDataProvider.RESULT_TRUE) {
-                        getDelegate().onFailed(msg);
-                    }
+        boolean bsuccessful=RADataProvider.saveSearchParametersForModuleWithName(intentStr, json, module_name, name);
 
-                } // != null
+        getDelegate().onStopLoading();
 
+        if(!bsuccessful)
+            getDelegate().onFailed("Sorry, something is wrong.");
 
 
-            }
-        }, null);
+//
+//        OperationQueue.sharedQueue().addOperationTask(new OperationQueue.OperationBackgroundCallBack() {
+//            @Override
+//            public Object operationDoInBackground() {
+//                return
+//            }
+//        }, new OperationQueue.OperationCompletionCallBack() {
+//            @Override
+//            public void operationCompletion(Object object) {
+//
+//
+//                boolean b=object;
+//                if (getDelegate() != null) {
+//
+//                    getDelegate().onStopLoading();
+//
+//                    JSONObject json = (JSONObject)object;
+//
+//                    int result = OnlineDataProvider.RESULT_FALSE;
+//                    String msg = "Sorry, something is wrong.";
+//                    if (json != null) {
+//
+//                        result = json.optInt("result", OnlineDataProvider.RESULT_FALSE);
+//                        if (result != OnlineDataProvider.RESULT_TRUE) {
+//                            String err_msg = json.optString("err_msg");
+//                            if (!TextUtils.isEmpty(err_msg)) {
+//                                msg = err_msg;
+//                            }
+//                        }
+//                    } // json
+//
+//                    if (result != OnlineDataProvider.RESULT_TRUE) {
+//
+//                    }
+//
+//                } // != null
+//
+//
+//
+//            }
+//        }, null);
     }
 
     // endregion