From 71ac5ea208fb15da401b980fe788d03ed0f086b1 Mon Sep 17 00:00:00 2001
From: zuoxiao <470321431@qq.com>
Date: 星期三, 04 十二月 2024 09:56:14 +0800
Subject: [PATCH] 1.添加退出登录时判断是否开启巡检,开启巡检不可退出登录。 2.添加异常退出后恢复巡检记录的功能。 3.添加统一的提示Dialog

---
 app/src/main/java/com/dayu/pipirrapp/tool/InspectionUtils.java |   72 ++++++++++++++++++++++++++++++++---
 1 files changed, 65 insertions(+), 7 deletions(-)

diff --git a/app/src/main/java/com/dayu/pipirrapp/tool/InspectionUtils.java b/app/src/main/java/com/dayu/pipirrapp/tool/InspectionUtils.java
index f4f3ebb..b14376b 100644
--- a/app/src/main/java/com/dayu/pipirrapp/tool/InspectionUtils.java
+++ b/app/src/main/java/com/dayu/pipirrapp/tool/InspectionUtils.java
@@ -4,10 +4,14 @@
 import android.location.Location;
 import android.util.Log;
 
+import androidx.room.Transaction;
+
+import com.dayu.pipirrapp.MyApplication;
 import com.dayu.pipirrapp.bean.db.InspectionBean;
 import com.dayu.pipirrapp.bean.db.InspectionLocationBean;
 import com.dayu.pipirrapp.bean.db.LatLonBean;
 import com.dayu.pipirrapp.dao.DaoSingleton;
+import com.dayu.pipirrapp.fragment.MapFragment;
 import com.dayu.pipirrapp.utils.DateUtils;
 
 import java.util.UUID;
@@ -26,9 +30,10 @@
     private static final String TAG = "InspectionUtils";
     //鎵撶偣鐨勬渶灏忎袱鐐规渶灏忚窛绂�
     private static final int MinMeters = 10;
-    //0娌℃湁寮�濮嬶紝1寮�濮嬶紝2鏆傚仠,3鍏抽棴
+    //0娌℃湁寮�濮嬶紝1寮�濮嬶紝2鏆傚仠,3鍏抽棴,4鏄偣鍑荤殑寮�濮嬫寜閽�
     public static final int NO_INSPECTION = 0;
     public static final int STAT_INSPECTION = 1;
+    public static final int STAT_INSPECTION_ONCLICK = 4;
     public static final int PAUSE_INSPECTION = 2;
     public static final int STOP_INSPECTION = 3;
 
@@ -36,13 +41,31 @@
     /**
      * 鑾峰彇褰撳墠宸℃璁板綍ID
      *
-     * @param context
+     * @param fragment
      * @return
      */
-    public static String getInspectionId(Context context) {
+    public static String getInspectionId(MapFragment fragment) {
+        DaoSingleton.getAsynchInstance(fragment.getContext()).inspectionDao().getMostRecentInspectionWithNoStopTime()
+                .subscribeOn(Schedulers.io())
+                .observeOn(Schedulers.io()).subscribe(inspectionBean -> {
 
-
+                });
         return "";
+    }
+
+
+    public static void aginShowLocation(MapFragment fragment) {
+        //鏌ヨ褰撳墠鏈叧闂殑宸℃璁板綍
+        DaoSingleton.getAsynchInstance(fragment.getContext()).inspectionDao().getMostRecentInspectionWithNoStopTime()
+                .subscribeOn(Schedulers.io())
+                .observeOn(Schedulers.io()).subscribe(inspectionBean -> {
+                    fragment.mInspectionBean = inspectionBean;
+                    // 鏌ヨ褰撳墠鏈叧闂殑宸℃璁板綍涓嬫墍鏈夌殑鍧愭爣
+                    DaoSingleton.getAsynchInstance(fragment.getContext()).inspectionLocationDao().findByInspectId(inspectionBean.getmInspectId()).subscribeOn(Schedulers.io())
+                            .observeOn(AndroidSchedulers.mainThread()).subscribe(inspectionLocationBeans -> {
+                                fragment.aginShowLocation(inspectionLocationBeans);
+                            });
+                });
     }
 
 
@@ -57,6 +80,7 @@
         InspectionBean inspectionBean = new InspectionBean();
         inspectionBean.setmInspectId(UUID.randomUUID().toString());
         inspectionBean.setStartTime(DateUtils.getNowDateStr());
+//        inspectionBean.
         // 寮傛鎻掑叆鍒版暟鎹簱
         DaoSingleton.getAsynchInstance(context)
                 .inspectionDao()
@@ -66,7 +90,7 @@
                 .subscribe(() -> {
                     Log.i(TAG, "Inspection started and inserted successfully.");
                 }, throwable -> {
-                    Log.e(TAG, "Error inserting inspection data: ", throwable);
+                    Log.e(TAG, "Error inserting inspection data: "+throwable);
                 });
         // 鑾峰彇Dao骞舵墽琛屾彃鍏ユ搷浣�
         return inspectionBean;  // 鎻掑叆瀹屾垚鍚庡垏鎹㈠埌涓荤嚎绋�
@@ -80,7 +104,15 @@
      * @param locationBean
      */
     public static void addInspectionLocationData(Context context, InspectionLocationBean locationBean) {
-        DaoSingleton.getAsynchInstance(context).inspectionLocationDao().insert(locationBean).subscribeOn(Schedulers.io());
+        DaoSingleton.getAsynchInstance(context).inspectionLocationDao().insert(locationBean).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
+                .subscribe(() -> {
+                    // 鎻掑叆鎴愬姛鐨勫洖璋�
+                    Log.d(TAG, "addInspectionLocationData鏁版嵁鎻掑叆鎴愬姛");
+                }, throwable -> {
+                    // 澶勭悊閿欒
+                    Log.e(TAG, "addInspectionLocationData鏁版嵁鎻掑叆澶辫触", throwable);
+                });
+        ;
     }
 
     /**
@@ -89,8 +121,17 @@
      * @param context
      * @param locationBean
      */
+    @Transaction
     public static void updateInspectionLocationData(Context context, InspectionLocationBean locationBean) {
-        DaoSingleton.getAsynchInstance(context).inspectionLocationDao().update(locationBean).subscribeOn(Schedulers.io());
+        DaoSingleton.getAsynchInstance(context).inspectionLocationDao().update(locationBean).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
+                .subscribe(() -> {
+                    // 鎻掑叆鎴愬姛鐨勫洖璋�
+                    Log.d(TAG, "updateInspectionLocationData鏁版嵁鎻掑叆鎴愬姛");
+                }, throwable -> {
+                    // 澶勭悊閿欒
+                    Log.e(TAG, "updateInspectionLocationData鏁版嵁鎻掑叆澶辫触", throwable);
+                });
+        ;
     }
 
     /**
@@ -115,4 +156,21 @@
         }
 
     }
+
+    /**
+     * 鍒涘缓InspectionLocationBean
+     */
+    public static InspectionLocationBean createInspectionLocation(LatLonBean latLonBean, InspectionBean mInspectionBean) {
+        InspectionLocationBean inspectionLocationBean = new InspectionLocationBean();
+        inspectionLocationBean.setId(UUID.randomUUID().toString());
+        inspectionLocationBean.setInspectId(mInspectionBean.getInspectId());
+        inspectionLocationBean.setmInspectId(mInspectionBean.getmInspectId());
+        inspectionLocationBean.setLocateTime(DateUtils.getNowDateStr());
+        inspectionLocationBean.setPost(false);
+        inspectionLocationBean.setInspectorId(MyApplication.myApplication.userId);
+        inspectionLocationBean.setLng(String.valueOf(latLonBean.getLongitude()));
+        inspectionLocationBean.setLat(String.valueOf(latLonBean.getLatitude()));
+        return inspectionLocationBean;
+    }
+
 }

--
Gitblit v1.8.0