|
|
@@ -1,6 +1,11 @@
|
|
|
package com.xzjmyk.pm.activity.ui.erp.activity.datainquiry.activity;
|
|
|
|
|
|
+import android.Manifest;
|
|
|
+import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
+import android.content.pm.PackageManager;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
|
import android.os.Message;
|
|
|
@@ -18,6 +23,7 @@ import com.xzjmyk.pm.activity.ui.erp.net.ViewUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.CommonUtil;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.Constants;
|
|
|
import com.xzjmyk.pm.activity.ui.erp.util.LogUtil;
|
|
|
+import com.xzjmyk.pm.activity.util.PermissionUtil;
|
|
|
import com.xzjmyk.pm.activity.view.MyListView;
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
@@ -39,6 +45,7 @@ import java.util.Map;
|
|
|
* Created by RaoMeng on 2017/8/16.
|
|
|
*/
|
|
|
public class ReportQueryCriteriaActivity extends BaseActivity implements View.OnClickListener {
|
|
|
+ private final int REQUEST_WRITE_EXTERNAL_STORAGE = 0X22;
|
|
|
private final int GET_OPTION_DATA = 0X11;
|
|
|
private MyListView mOptionListView;
|
|
|
private TextView mCancelTextView, mResetTextView, mConfirmTextView;
|
|
|
@@ -90,10 +97,7 @@ public class ReportQueryCriteriaActivity extends BaseActivity implements View.On
|
|
|
}
|
|
|
} else {
|
|
|
ArrayList<ReportConditionBean.Property> properties = new ArrayList<>();
|
|
|
- if ("S".equals(type)) {
|
|
|
- ReportConditionBean.Property property = new ReportConditionBean.Property();
|
|
|
- properties.add(property);
|
|
|
- } else if ("N".equals(type)) {
|
|
|
+ if ("N".equals(type)) {
|
|
|
for (int m = 0; m < 2; m++) {
|
|
|
ReportConditionBean.Property property = new ReportConditionBean.Property();
|
|
|
properties.add(property);
|
|
|
@@ -105,6 +109,9 @@ public class ReportQueryCriteriaActivity extends BaseActivity implements View.On
|
|
|
}
|
|
|
} else if ("CBG".equals(type) || "C".equals(type) || "R".equals(type)) {
|
|
|
|
|
|
+ } else {
|
|
|
+ ReportConditionBean.Property property = new ReportConditionBean.Property();
|
|
|
+ properties.add(property);
|
|
|
}
|
|
|
reportConditionBean.setProperties(properties);
|
|
|
}
|
|
|
@@ -197,73 +204,12 @@ public class ReportQueryCriteriaActivity extends BaseActivity implements View.On
|
|
|
public void onClick(View v) {
|
|
|
switch (v.getId()) {
|
|
|
case R.id.report_query_criteria_confirm_btn:
|
|
|
- mCondition = "";
|
|
|
- for (int i = 0; i < mReportConditionBeans.size(); i++) {
|
|
|
- ReportConditionBean reportConditionBean = mReportConditionBeans.get(i);
|
|
|
- if ("S".equals(reportConditionBean.getType()) && reportConditionBean.getProperties().size() == 1) {
|
|
|
- if (!TextUtils.isEmpty(reportConditionBean.getProperties().get(0).getDisplay())) {
|
|
|
- mCondition = mCondition + "(" + reportConditionBean.getField()
|
|
|
- + " = \'" + reportConditionBean.getProperties().get(0).getDisplay() + "\')"
|
|
|
- + " and ";
|
|
|
- }
|
|
|
- } else if ("N".equals(reportConditionBean.getType()) && reportConditionBean.getProperties().size() == 2) {
|
|
|
- if (!TextUtils.isEmpty(reportConditionBean.getProperties().get(0).getDisplay())
|
|
|
- && !TextUtils.isEmpty(reportConditionBean.getProperties().get(1).getDisplay())) {
|
|
|
- mCondition = mCondition + "(" + reportConditionBean.getField()
|
|
|
- + " >= " + reportConditionBean.getProperties().get(0).getDisplay()
|
|
|
- + " and " + reportConditionBean.getField()
|
|
|
- + " <= " + reportConditionBean.getProperties().get(1).getDisplay() + ") and ";
|
|
|
-
|
|
|
- } else if (!TextUtils.isEmpty(reportConditionBean.getProperties().get(0).getDisplay())) {
|
|
|
- mCondition = mCondition + "(" + reportConditionBean.getField()
|
|
|
- + " >= " + reportConditionBean.getProperties().get(0).getDisplay() + ") and ";
|
|
|
- } else if (!TextUtils.isEmpty(reportConditionBean.getProperties().get(1).getDisplay())) {
|
|
|
- mCondition = mCondition + "(" + reportConditionBean.getField()
|
|
|
- + " <= " + reportConditionBean.getProperties().get(1).getDisplay() + ") and ";
|
|
|
- }
|
|
|
-
|
|
|
- } else if (("D".equals(reportConditionBean.getType()) || "CD".equals(reportConditionBean.getType())) && reportConditionBean.getProperties().size() == 2) {
|
|
|
- mCondition = mCondition + "(" + reportConditionBean.getField()
|
|
|
- + " >= to_date(\'" + reportConditionBean.getProperties().get(0).getDisplay()
|
|
|
- + "\',\'yyyy-MM-dd\') and " + reportConditionBean.getField()
|
|
|
- + " <= to_date(\'" + reportConditionBean.getProperties().get(1).getDisplay()
|
|
|
- + "\',\'yyyy-MM-dd\')) and ";
|
|
|
- } else if ("CBG".equals(reportConditionBean.getType()) || "C".equals(reportConditionBean.getType())
|
|
|
- || "R".equals(reportConditionBean.getType()) || "EC".equals(reportConditionBean.getType())) {
|
|
|
- String gridCondition = "";
|
|
|
- int selectedCount = 0;
|
|
|
- for (int j = 0; j < reportConditionBean.getProperties().size(); j++) {
|
|
|
- if (reportConditionBean.getProperties().get(j).isState()) {
|
|
|
- selectedCount++;
|
|
|
- gridCondition = gridCondition + reportConditionBean.getField() + " = \'"
|
|
|
- + reportConditionBean.getProperties().get(j).getValue() + "\' or ";
|
|
|
- }
|
|
|
- }
|
|
|
- if (selectedCount > 0) {
|
|
|
- gridCondition = gridCondition.substring(0, gridCondition.length() - 4);
|
|
|
-
|
|
|
- mCondition = mCondition + "(" + gridCondition + ") and ";
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (mCondition.length() >= 5) {
|
|
|
- mCondition = mCondition.substring(0, mCondition.length() - 5);
|
|
|
- }
|
|
|
-
|
|
|
- Log.d("exactCondition", mCondition);
|
|
|
-
|
|
|
- if (mCondition.length() == 0) {
|
|
|
- ToastMessage("请确认报表查询条件");
|
|
|
+ if (PermissionUtil.lacksPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
|
|
|
+ PermissionUtil.requestPermission(this, REQUEST_WRITE_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
|
|
} else {
|
|
|
- Intent intent = new Intent();
|
|
|
- intent.setClass(this, PDFDownloadActivity.class);
|
|
|
- intent.putExtra("condition", mCondition);
|
|
|
- if (mReportInfo != null)
|
|
|
- intent.putExtra("reportName", mReportInfo.getReportName());
|
|
|
-
|
|
|
- startActivity(intent);
|
|
|
+ gotoPDFLoadActivity();
|
|
|
}
|
|
|
+
|
|
|
break;
|
|
|
case R.id.report_query_criteria_reset_btn:
|
|
|
mReportConditionBeans.clear();
|
|
|
@@ -283,6 +229,103 @@ public class ReportQueryCriteriaActivity extends BaseActivity implements View.On
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
|
|
+ int[] grantResults) {
|
|
|
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
|
|
+ if (requestCode == REQUEST_WRITE_EXTERNAL_STORAGE) {
|
|
|
+ if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
|
+ gotoPDFLoadActivity();
|
|
|
+ } else {
|
|
|
+// new AlertDialog.Builder(this).setTitle(R.string.prompt_title)
|
|
|
+// .setMessage("查看报表文件需要开启读写手机权限")
|
|
|
+// .setPositiveButton("去设置", new DialogInterface.OnClickListener() {
|
|
|
+// @Override
|
|
|
+// public void onClick(DialogInterface dialog, int which) {
|
|
|
+// Intent intent = getAppDetailSettingIntent(ReportQueryCriteriaActivity.this);
|
|
|
+// startActivity(intent);
|
|
|
+// }
|
|
|
+// })
|
|
|
+// .setNegativeButton(R.string.cancel, null)
|
|
|
+// .create().show();
|
|
|
+ ToastMessage("查看报表文件需要开启读写手机权限,请在设置中手动开启");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void gotoPDFLoadActivity() {
|
|
|
+ mCondition = "";
|
|
|
+ for (int i = 0; i < mReportConditionBeans.size(); i++) {
|
|
|
+ ReportConditionBean reportConditionBean = mReportConditionBeans.get(i);
|
|
|
+ if ("N".equals(reportConditionBean.getType()) && reportConditionBean.getProperties().size() == 2) {
|
|
|
+ if (!TextUtils.isEmpty(reportConditionBean.getProperties().get(0).getDisplay())
|
|
|
+ && !TextUtils.isEmpty(reportConditionBean.getProperties().get(1).getDisplay())) {
|
|
|
+ mCondition = mCondition + "(" + reportConditionBean.getField()
|
|
|
+ + " >= " + reportConditionBean.getProperties().get(0).getDisplay()
|
|
|
+ + " and " + reportConditionBean.getField()
|
|
|
+ + " <= " + reportConditionBean.getProperties().get(1).getDisplay() + ") and ";
|
|
|
+
|
|
|
+ } else if (!TextUtils.isEmpty(reportConditionBean.getProperties().get(0).getDisplay())) {
|
|
|
+ mCondition = mCondition + "(" + reportConditionBean.getField()
|
|
|
+ + " >= " + reportConditionBean.getProperties().get(0).getDisplay() + ") and ";
|
|
|
+ } else if (!TextUtils.isEmpty(reportConditionBean.getProperties().get(1).getDisplay())) {
|
|
|
+ mCondition = mCondition + "(" + reportConditionBean.getField()
|
|
|
+ + " <= " + reportConditionBean.getProperties().get(1).getDisplay() + ") and ";
|
|
|
+ }
|
|
|
+
|
|
|
+ } else if (("D".equals(reportConditionBean.getType()) || "CD".equals(reportConditionBean.getType())) && reportConditionBean.getProperties().size() == 2) {
|
|
|
+ mCondition = mCondition + "(" + reportConditionBean.getField()
|
|
|
+ + " >= to_date(\'" + reportConditionBean.getProperties().get(0).getDisplay()
|
|
|
+ + "\',\'yyyy-MM-dd\') and " + reportConditionBean.getField()
|
|
|
+ + " <= to_date(\'" + reportConditionBean.getProperties().get(1).getDisplay()
|
|
|
+ + "\',\'yyyy-MM-dd\')) and ";
|
|
|
+ } else if ("CBG".equals(reportConditionBean.getType()) || "C".equals(reportConditionBean.getType())
|
|
|
+ || "R".equals(reportConditionBean.getType()) || "EC".equals(reportConditionBean.getType())) {
|
|
|
+ String gridCondition = "";
|
|
|
+ int selectedCount = 0;
|
|
|
+ for (int j = 0; j < reportConditionBean.getProperties().size(); j++) {
|
|
|
+ if (reportConditionBean.getProperties().get(j).isState()) {
|
|
|
+ selectedCount++;
|
|
|
+ gridCondition = gridCondition + reportConditionBean.getField() + " = \'"
|
|
|
+ + reportConditionBean.getProperties().get(j).getValue() + "\' or ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (selectedCount > 0) {
|
|
|
+ gridCondition = gridCondition.substring(0, gridCondition.length() - 4);
|
|
|
+
|
|
|
+ mCondition = mCondition + "(" + gridCondition + ") and ";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (reportConditionBean.getProperties().size() == 1) {
|
|
|
+ if (!TextUtils.isEmpty(reportConditionBean.getProperties().get(0).getDisplay())) {
|
|
|
+ mCondition = mCondition + "(" + reportConditionBean.getField()
|
|
|
+ + " = \'" + reportConditionBean.getProperties().get(0).getDisplay() + "\')"
|
|
|
+ + " and ";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mCondition.length() >= 5) {
|
|
|
+ mCondition = mCondition.substring(0, mCondition.length() - 5);
|
|
|
+ }
|
|
|
+
|
|
|
+ Log.d("exactCondition", mCondition);
|
|
|
+
|
|
|
+ if (mCondition.length() == 0) {
|
|
|
+ ToastMessage("请确认报表查询条件");
|
|
|
+ } else {
|
|
|
+ Intent intent = new Intent();
|
|
|
+ intent.setClass(this, PDFDownloadActivity.class);
|
|
|
+ intent.putExtra("condition", mCondition);
|
|
|
+ if (mReportInfo != null)
|
|
|
+ intent.putExtra("reportName", mReportInfo.getReportName());
|
|
|
+
|
|
|
+ startActivity(intent);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public String optStringNotNull(JSONObject json, String key) {
|
|
|
if (json.isNull(key)) {
|
|
|
return "";
|
|
|
@@ -302,4 +345,23 @@ public class ReportQueryCriteriaActivity extends BaseActivity implements View.On
|
|
|
List<T> dest = (List<T>) in.readObject();
|
|
|
return dest;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取应用详情页面intent
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static Intent getAppDetailSettingIntent(Context context) {
|
|
|
+ Intent localIntent = new Intent();
|
|
|
+ localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ if (Build.VERSION.SDK_INT >= 9) {
|
|
|
+ localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
|
|
|
+ localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));
|
|
|
+ } else if (Build.VERSION.SDK_INT <= 8) {
|
|
|
+ localIntent.setAction(Intent.ACTION_VIEW);
|
|
|
+ localIntent.setClassName("com.android.settings", "com.android.settings.InstalledAppDetails");
|
|
|
+ localIntent.putExtra("com.android.settings.ApplicationPkgName", context.getPackageName());
|
|
|
+ }
|
|
|
+ return localIntent;
|
|
|
+ }
|
|
|
}
|