diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index 4d0c818..d137800 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -21,7 +21,10 @@ import com.casic.app.smartwell.sanxi.extensions.toTypeName import com.casic.app.smartwell.sanxi.model.WellListModel import com.casic.app.smartwell.sanxi.utils.Constant +import com.casic.app.smartwell.sanxi.vm.AlarmViewModel +import com.casic.app.smartwell.sanxi.vm.DeviceViewModel import com.casic.app.smartwell.sanxi.vm.WellViewModel +import com.casic.app.smartwell.sanxi.vm.WorkOrderViewModel import com.casic.app.smartwell.sanxi.widgets.EasyPopupWindow import com.casic.app.smartwell.sanxi.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -36,6 +39,9 @@ private lateinit var homeView: View private lateinit var aMap: AMap private lateinit var wellViewModel: WellViewModel + private lateinit var deviceViewModel: DeviceViewModel + private lateinit var alarmViewModel: AlarmViewModel + private lateinit var workOrderViewModel: WorkOrderViewModel /** * 所有窨井列表信息集合 @@ -91,6 +97,9 @@ //初始化vm wellViewModel = ViewModelProvider(this).get(WellViewModel::class.java) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + alarmViewModel = ViewModelProvider(this).get(AlarmViewModel::class.java) + workOrderViewModel = ViewModelProvider(this).get(WorkOrderViewModel::class.java) //获取所有窨井数据 wellViewModel.obtainAllWell() @@ -140,6 +149,32 @@ //地图初始化 initMap(savedInstanceState) + + //获取窨井总数数据 + wellViewModel.countWellByState() + wellViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.wellTotalView.text = it["total"] + }) + + //获取设备总数数据 + deviceViewModel.countDeviceByState() + deviceViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.deviceTotalView.text = it["total"] + }) + + //获取当前报警数据 + alarmViewModel.alarmCountModel.observe(viewLifecycleOwner, { + homeView.currentAlarmView.text = it.toString() + }) + + //获取当前未完工单数据 + workOrderViewModel.orderCountModel.observe(viewLifecycleOwner, { + val beforeGet = it["beforeGet"]!! + val beforeConfirm = it["beforeConfirm"]!! + val inHandle = it["inHandle"]!! + + homeView.unCompleteOrderView.text = (beforeGet + beforeConfirm + inHandle).toString() + }) return homeView } @@ -304,9 +339,9 @@ override fun onResume() { super.onResume() homeView.mapView.onResume() - //每次页面切换都需要重新刷新不同状态的窨井数量 -// wellViewModel.countWellByState() -// workOrderViewModel.countWorkOrderByState() + //每次页面切换都需要重新刷新报警和工单数 + alarmViewModel.obtainAlarmNow() + workOrderViewModel.countWorkOrderByState() } override fun onPause() { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index 4d0c818..d137800 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -21,7 +21,10 @@ import com.casic.app.smartwell.sanxi.extensions.toTypeName import com.casic.app.smartwell.sanxi.model.WellListModel import com.casic.app.smartwell.sanxi.utils.Constant +import com.casic.app.smartwell.sanxi.vm.AlarmViewModel +import com.casic.app.smartwell.sanxi.vm.DeviceViewModel import com.casic.app.smartwell.sanxi.vm.WellViewModel +import com.casic.app.smartwell.sanxi.vm.WorkOrderViewModel import com.casic.app.smartwell.sanxi.widgets.EasyPopupWindow import com.casic.app.smartwell.sanxi.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -36,6 +39,9 @@ private lateinit var homeView: View private lateinit var aMap: AMap private lateinit var wellViewModel: WellViewModel + private lateinit var deviceViewModel: DeviceViewModel + private lateinit var alarmViewModel: AlarmViewModel + private lateinit var workOrderViewModel: WorkOrderViewModel /** * 所有窨井列表信息集合 @@ -91,6 +97,9 @@ //初始化vm wellViewModel = ViewModelProvider(this).get(WellViewModel::class.java) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + alarmViewModel = ViewModelProvider(this).get(AlarmViewModel::class.java) + workOrderViewModel = ViewModelProvider(this).get(WorkOrderViewModel::class.java) //获取所有窨井数据 wellViewModel.obtainAllWell() @@ -140,6 +149,32 @@ //地图初始化 initMap(savedInstanceState) + + //获取窨井总数数据 + wellViewModel.countWellByState() + wellViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.wellTotalView.text = it["total"] + }) + + //获取设备总数数据 + deviceViewModel.countDeviceByState() + deviceViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.deviceTotalView.text = it["total"] + }) + + //获取当前报警数据 + alarmViewModel.alarmCountModel.observe(viewLifecycleOwner, { + homeView.currentAlarmView.text = it.toString() + }) + + //获取当前未完工单数据 + workOrderViewModel.orderCountModel.observe(viewLifecycleOwner, { + val beforeGet = it["beforeGet"]!! + val beforeConfirm = it["beforeConfirm"]!! + val inHandle = it["inHandle"]!! + + homeView.unCompleteOrderView.text = (beforeGet + beforeConfirm + inHandle).toString() + }) return homeView } @@ -304,9 +339,9 @@ override fun onResume() { super.onResume() homeView.mapView.onResume() - //每次页面切换都需要重新刷新不同状态的窨井数量 -// wellViewModel.countWellByState() -// workOrderViewModel.countWorkOrderByState() + //每次页面切换都需要重新刷新报警和工单数 + alarmViewModel.obtainAlarmNow() + workOrderViewModel.countWorkOrderByState() } override fun onPause() { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 3c6fea3..7b63a83 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -165,6 +165,18 @@ suspend fun countWellByState(@Header("token") token: String): String /** + * 获取设备数量接口 + */ + @GET("/statics/deviceStaticsByStatus") + suspend fun countDeviceByState(@Header("token") token: String): String + + /** + * 获取当前报警数量接口 + */ + @GET("/statics/alarmsNow") + suspend fun obtainAlarmNow(@Header("token") token: String): String + + /** * 根据工单状态统计工单数量 */ @GET("/job/countByJobStatus") diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index 4d0c818..d137800 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -21,7 +21,10 @@ import com.casic.app.smartwell.sanxi.extensions.toTypeName import com.casic.app.smartwell.sanxi.model.WellListModel import com.casic.app.smartwell.sanxi.utils.Constant +import com.casic.app.smartwell.sanxi.vm.AlarmViewModel +import com.casic.app.smartwell.sanxi.vm.DeviceViewModel import com.casic.app.smartwell.sanxi.vm.WellViewModel +import com.casic.app.smartwell.sanxi.vm.WorkOrderViewModel import com.casic.app.smartwell.sanxi.widgets.EasyPopupWindow import com.casic.app.smartwell.sanxi.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -36,6 +39,9 @@ private lateinit var homeView: View private lateinit var aMap: AMap private lateinit var wellViewModel: WellViewModel + private lateinit var deviceViewModel: DeviceViewModel + private lateinit var alarmViewModel: AlarmViewModel + private lateinit var workOrderViewModel: WorkOrderViewModel /** * 所有窨井列表信息集合 @@ -91,6 +97,9 @@ //初始化vm wellViewModel = ViewModelProvider(this).get(WellViewModel::class.java) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + alarmViewModel = ViewModelProvider(this).get(AlarmViewModel::class.java) + workOrderViewModel = ViewModelProvider(this).get(WorkOrderViewModel::class.java) //获取所有窨井数据 wellViewModel.obtainAllWell() @@ -140,6 +149,32 @@ //地图初始化 initMap(savedInstanceState) + + //获取窨井总数数据 + wellViewModel.countWellByState() + wellViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.wellTotalView.text = it["total"] + }) + + //获取设备总数数据 + deviceViewModel.countDeviceByState() + deviceViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.deviceTotalView.text = it["total"] + }) + + //获取当前报警数据 + alarmViewModel.alarmCountModel.observe(viewLifecycleOwner, { + homeView.currentAlarmView.text = it.toString() + }) + + //获取当前未完工单数据 + workOrderViewModel.orderCountModel.observe(viewLifecycleOwner, { + val beforeGet = it["beforeGet"]!! + val beforeConfirm = it["beforeConfirm"]!! + val inHandle = it["inHandle"]!! + + homeView.unCompleteOrderView.text = (beforeGet + beforeConfirm + inHandle).toString() + }) return homeView } @@ -304,9 +339,9 @@ override fun onResume() { super.onResume() homeView.mapView.onResume() - //每次页面切换都需要重新刷新不同状态的窨井数量 -// wellViewModel.countWellByState() -// workOrderViewModel.countWorkOrderByState() + //每次页面切换都需要重新刷新报警和工单数 + alarmViewModel.obtainAlarmNow() + workOrderViewModel.countWorkOrderByState() } override fun onPause() { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 3c6fea3..7b63a83 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -165,6 +165,18 @@ suspend fun countWellByState(@Header("token") token: String): String /** + * 获取设备数量接口 + */ + @GET("/statics/deviceStaticsByStatus") + suspend fun countDeviceByState(@Header("token") token: String): String + + /** + * 获取当前报警数量接口 + */ + @GET("/statics/alarmsNow") + suspend fun obtainAlarmNow(@Header("token") token: String): String + + /** * 根据工单状态统计工单数量 */ @GET("/job/countByJobStatus") diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index f67ccb6..0d19361 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -158,19 +158,34 @@ return api.obtainAllWell(AuthenticationHelper.token!!) } -// /** -// * 根据布防状态统计闸井数量接口 -// */ -// suspend fun countWellByState(): String { -// return api.countWellByState(AuthenticationHelper.token!!) -// } -// -// /** -// * 根据工单状态统计工单数量 -// */ -// suspend fun countWorkOrderByState(): String { -// return api.countWorkOrderByState(AuthenticationHelper.token!!) -// } + /** + * 根据布防状态统计闸井数量接口 + */ + suspend fun countWellByState(): String { + return api.countWellByState(AuthenticationHelper.token!!) + } + + /** + * 获取设备数量接口 + */ + suspend fun countDeviceByState(): String { + return api.countDeviceByState(AuthenticationHelper.token!!) + } + + /** + * 获取当前报警数量接口 + */ + suspend fun obtainAlarmNow(): String { + return api.obtainAlarmNow(AuthenticationHelper.token!!) + } + + + /** + * 根据工单状态统计工单数量 + */ + suspend fun countWorkOrderByState(): String { + return api.countWorkOrderByState(AuthenticationHelper.token!!) + } // // /** // * 获取闸井类别 diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index 4d0c818..d137800 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -21,7 +21,10 @@ import com.casic.app.smartwell.sanxi.extensions.toTypeName import com.casic.app.smartwell.sanxi.model.WellListModel import com.casic.app.smartwell.sanxi.utils.Constant +import com.casic.app.smartwell.sanxi.vm.AlarmViewModel +import com.casic.app.smartwell.sanxi.vm.DeviceViewModel import com.casic.app.smartwell.sanxi.vm.WellViewModel +import com.casic.app.smartwell.sanxi.vm.WorkOrderViewModel import com.casic.app.smartwell.sanxi.widgets.EasyPopupWindow import com.casic.app.smartwell.sanxi.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -36,6 +39,9 @@ private lateinit var homeView: View private lateinit var aMap: AMap private lateinit var wellViewModel: WellViewModel + private lateinit var deviceViewModel: DeviceViewModel + private lateinit var alarmViewModel: AlarmViewModel + private lateinit var workOrderViewModel: WorkOrderViewModel /** * 所有窨井列表信息集合 @@ -91,6 +97,9 @@ //初始化vm wellViewModel = ViewModelProvider(this).get(WellViewModel::class.java) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + alarmViewModel = ViewModelProvider(this).get(AlarmViewModel::class.java) + workOrderViewModel = ViewModelProvider(this).get(WorkOrderViewModel::class.java) //获取所有窨井数据 wellViewModel.obtainAllWell() @@ -140,6 +149,32 @@ //地图初始化 initMap(savedInstanceState) + + //获取窨井总数数据 + wellViewModel.countWellByState() + wellViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.wellTotalView.text = it["total"] + }) + + //获取设备总数数据 + deviceViewModel.countDeviceByState() + deviceViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.deviceTotalView.text = it["total"] + }) + + //获取当前报警数据 + alarmViewModel.alarmCountModel.observe(viewLifecycleOwner, { + homeView.currentAlarmView.text = it.toString() + }) + + //获取当前未完工单数据 + workOrderViewModel.orderCountModel.observe(viewLifecycleOwner, { + val beforeGet = it["beforeGet"]!! + val beforeConfirm = it["beforeConfirm"]!! + val inHandle = it["inHandle"]!! + + homeView.unCompleteOrderView.text = (beforeGet + beforeConfirm + inHandle).toString() + }) return homeView } @@ -304,9 +339,9 @@ override fun onResume() { super.onResume() homeView.mapView.onResume() - //每次页面切换都需要重新刷新不同状态的窨井数量 -// wellViewModel.countWellByState() -// workOrderViewModel.countWorkOrderByState() + //每次页面切换都需要重新刷新报警和工单数 + alarmViewModel.obtainAlarmNow() + workOrderViewModel.countWorkOrderByState() } override fun onPause() { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 3c6fea3..7b63a83 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -165,6 +165,18 @@ suspend fun countWellByState(@Header("token") token: String): String /** + * 获取设备数量接口 + */ + @GET("/statics/deviceStaticsByStatus") + suspend fun countDeviceByState(@Header("token") token: String): String + + /** + * 获取当前报警数量接口 + */ + @GET("/statics/alarmsNow") + suspend fun obtainAlarmNow(@Header("token") token: String): String + + /** * 根据工单状态统计工单数量 */ @GET("/job/countByJobStatus") diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index f67ccb6..0d19361 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -158,19 +158,34 @@ return api.obtainAllWell(AuthenticationHelper.token!!) } -// /** -// * 根据布防状态统计闸井数量接口 -// */ -// suspend fun countWellByState(): String { -// return api.countWellByState(AuthenticationHelper.token!!) -// } -// -// /** -// * 根据工单状态统计工单数量 -// */ -// suspend fun countWorkOrderByState(): String { -// return api.countWorkOrderByState(AuthenticationHelper.token!!) -// } + /** + * 根据布防状态统计闸井数量接口 + */ + suspend fun countWellByState(): String { + return api.countWellByState(AuthenticationHelper.token!!) + } + + /** + * 获取设备数量接口 + */ + suspend fun countDeviceByState(): String { + return api.countDeviceByState(AuthenticationHelper.token!!) + } + + /** + * 获取当前报警数量接口 + */ + suspend fun obtainAlarmNow(): String { + return api.obtainAlarmNow(AuthenticationHelper.token!!) + } + + + /** + * 根据工单状态统计工单数量 + */ + suspend fun countWorkOrderByState(): String { + return api.countWorkOrderByState(AuthenticationHelper.token!!) + } // // /** // * 获取闸井类别 diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt index b8af9b4..3ee2f6f 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt @@ -12,6 +12,7 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class AlarmViewModel : BaseViewModel() { @@ -19,6 +20,7 @@ val listModel = MutableLiveData() val typeModel = MutableLiveData() val contentModel = MutableLiveData() + val alarmCountModel = MutableLiveData() fun obtainAlarmType() = launch({ val response = RetrofitServiceManager.obtainAlarmType() @@ -88,4 +90,18 @@ }, { it.printStackTrace() }) + + fun obtainAlarmNow() = launch({ + val response = RetrofitServiceManager.obtainAlarmNow() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + alarmCountModel.value = data.getInt("total") + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index 4d0c818..d137800 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -21,7 +21,10 @@ import com.casic.app.smartwell.sanxi.extensions.toTypeName import com.casic.app.smartwell.sanxi.model.WellListModel import com.casic.app.smartwell.sanxi.utils.Constant +import com.casic.app.smartwell.sanxi.vm.AlarmViewModel +import com.casic.app.smartwell.sanxi.vm.DeviceViewModel import com.casic.app.smartwell.sanxi.vm.WellViewModel +import com.casic.app.smartwell.sanxi.vm.WorkOrderViewModel import com.casic.app.smartwell.sanxi.widgets.EasyPopupWindow import com.casic.app.smartwell.sanxi.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -36,6 +39,9 @@ private lateinit var homeView: View private lateinit var aMap: AMap private lateinit var wellViewModel: WellViewModel + private lateinit var deviceViewModel: DeviceViewModel + private lateinit var alarmViewModel: AlarmViewModel + private lateinit var workOrderViewModel: WorkOrderViewModel /** * 所有窨井列表信息集合 @@ -91,6 +97,9 @@ //初始化vm wellViewModel = ViewModelProvider(this).get(WellViewModel::class.java) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + alarmViewModel = ViewModelProvider(this).get(AlarmViewModel::class.java) + workOrderViewModel = ViewModelProvider(this).get(WorkOrderViewModel::class.java) //获取所有窨井数据 wellViewModel.obtainAllWell() @@ -140,6 +149,32 @@ //地图初始化 initMap(savedInstanceState) + + //获取窨井总数数据 + wellViewModel.countWellByState() + wellViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.wellTotalView.text = it["total"] + }) + + //获取设备总数数据 + deviceViewModel.countDeviceByState() + deviceViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.deviceTotalView.text = it["total"] + }) + + //获取当前报警数据 + alarmViewModel.alarmCountModel.observe(viewLifecycleOwner, { + homeView.currentAlarmView.text = it.toString() + }) + + //获取当前未完工单数据 + workOrderViewModel.orderCountModel.observe(viewLifecycleOwner, { + val beforeGet = it["beforeGet"]!! + val beforeConfirm = it["beforeConfirm"]!! + val inHandle = it["inHandle"]!! + + homeView.unCompleteOrderView.text = (beforeGet + beforeConfirm + inHandle).toString() + }) return homeView } @@ -304,9 +339,9 @@ override fun onResume() { super.onResume() homeView.mapView.onResume() - //每次页面切换都需要重新刷新不同状态的窨井数量 -// wellViewModel.countWellByState() -// workOrderViewModel.countWorkOrderByState() + //每次页面切换都需要重新刷新报警和工单数 + alarmViewModel.obtainAlarmNow() + workOrderViewModel.countWorkOrderByState() } override fun onPause() { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 3c6fea3..7b63a83 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -165,6 +165,18 @@ suspend fun countWellByState(@Header("token") token: String): String /** + * 获取设备数量接口 + */ + @GET("/statics/deviceStaticsByStatus") + suspend fun countDeviceByState(@Header("token") token: String): String + + /** + * 获取当前报警数量接口 + */ + @GET("/statics/alarmsNow") + suspend fun obtainAlarmNow(@Header("token") token: String): String + + /** * 根据工单状态统计工单数量 */ @GET("/job/countByJobStatus") diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index f67ccb6..0d19361 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -158,19 +158,34 @@ return api.obtainAllWell(AuthenticationHelper.token!!) } -// /** -// * 根据布防状态统计闸井数量接口 -// */ -// suspend fun countWellByState(): String { -// return api.countWellByState(AuthenticationHelper.token!!) -// } -// -// /** -// * 根据工单状态统计工单数量 -// */ -// suspend fun countWorkOrderByState(): String { -// return api.countWorkOrderByState(AuthenticationHelper.token!!) -// } + /** + * 根据布防状态统计闸井数量接口 + */ + suspend fun countWellByState(): String { + return api.countWellByState(AuthenticationHelper.token!!) + } + + /** + * 获取设备数量接口 + */ + suspend fun countDeviceByState(): String { + return api.countDeviceByState(AuthenticationHelper.token!!) + } + + /** + * 获取当前报警数量接口 + */ + suspend fun obtainAlarmNow(): String { + return api.obtainAlarmNow(AuthenticationHelper.token!!) + } + + + /** + * 根据工单状态统计工单数量 + */ + suspend fun countWorkOrderByState(): String { + return api.countWorkOrderByState(AuthenticationHelper.token!!) + } // // /** // * 获取闸井类别 diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt index b8af9b4..3ee2f6f 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt @@ -12,6 +12,7 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class AlarmViewModel : BaseViewModel() { @@ -19,6 +20,7 @@ val listModel = MutableLiveData() val typeModel = MutableLiveData() val contentModel = MutableLiveData() + val alarmCountModel = MutableLiveData() fun obtainAlarmType() = launch({ val response = RetrofitServiceManager.obtainAlarmType() @@ -88,4 +90,18 @@ }, { it.printStackTrace() }) + + fun obtainAlarmNow() = launch({ + val response = RetrofitServiceManager.obtainAlarmNow() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + alarmCountModel.value = data.getInt("total") + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt new file mode 100644 index 0000000..10be999 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt @@ -0,0 +1,36 @@ +package com.casic.app.smartwell.sanxi.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.sanxi.base.BaseViewModel +import com.casic.app.smartwell.sanxi.extensions.launch +import com.casic.app.smartwell.sanxi.extensions.separateResponseCode +import com.casic.app.smartwell.sanxi.extensions.show +import com.casic.app.smartwell.sanxi.extensions.toErrorMessage +import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import org.json.JSONObject + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val countResultModel = MutableLiveData>() + + fun countDeviceByState() = launch({ + val response = RetrofitServiceManager.countDeviceByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val map = HashMap(3) + + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + map["offline"] = data.getString("offline") + map["online"] = data.getString("online") + map["total"] = data.getString("total") + countResultModel.value = map + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index 4d0c818..d137800 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -21,7 +21,10 @@ import com.casic.app.smartwell.sanxi.extensions.toTypeName import com.casic.app.smartwell.sanxi.model.WellListModel import com.casic.app.smartwell.sanxi.utils.Constant +import com.casic.app.smartwell.sanxi.vm.AlarmViewModel +import com.casic.app.smartwell.sanxi.vm.DeviceViewModel import com.casic.app.smartwell.sanxi.vm.WellViewModel +import com.casic.app.smartwell.sanxi.vm.WorkOrderViewModel import com.casic.app.smartwell.sanxi.widgets.EasyPopupWindow import com.casic.app.smartwell.sanxi.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -36,6 +39,9 @@ private lateinit var homeView: View private lateinit var aMap: AMap private lateinit var wellViewModel: WellViewModel + private lateinit var deviceViewModel: DeviceViewModel + private lateinit var alarmViewModel: AlarmViewModel + private lateinit var workOrderViewModel: WorkOrderViewModel /** * 所有窨井列表信息集合 @@ -91,6 +97,9 @@ //初始化vm wellViewModel = ViewModelProvider(this).get(WellViewModel::class.java) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + alarmViewModel = ViewModelProvider(this).get(AlarmViewModel::class.java) + workOrderViewModel = ViewModelProvider(this).get(WorkOrderViewModel::class.java) //获取所有窨井数据 wellViewModel.obtainAllWell() @@ -140,6 +149,32 @@ //地图初始化 initMap(savedInstanceState) + + //获取窨井总数数据 + wellViewModel.countWellByState() + wellViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.wellTotalView.text = it["total"] + }) + + //获取设备总数数据 + deviceViewModel.countDeviceByState() + deviceViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.deviceTotalView.text = it["total"] + }) + + //获取当前报警数据 + alarmViewModel.alarmCountModel.observe(viewLifecycleOwner, { + homeView.currentAlarmView.text = it.toString() + }) + + //获取当前未完工单数据 + workOrderViewModel.orderCountModel.observe(viewLifecycleOwner, { + val beforeGet = it["beforeGet"]!! + val beforeConfirm = it["beforeConfirm"]!! + val inHandle = it["inHandle"]!! + + homeView.unCompleteOrderView.text = (beforeGet + beforeConfirm + inHandle).toString() + }) return homeView } @@ -304,9 +339,9 @@ override fun onResume() { super.onResume() homeView.mapView.onResume() - //每次页面切换都需要重新刷新不同状态的窨井数量 -// wellViewModel.countWellByState() -// workOrderViewModel.countWorkOrderByState() + //每次页面切换都需要重新刷新报警和工单数 + alarmViewModel.obtainAlarmNow() + workOrderViewModel.countWorkOrderByState() } override fun onPause() { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 3c6fea3..7b63a83 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -165,6 +165,18 @@ suspend fun countWellByState(@Header("token") token: String): String /** + * 获取设备数量接口 + */ + @GET("/statics/deviceStaticsByStatus") + suspend fun countDeviceByState(@Header("token") token: String): String + + /** + * 获取当前报警数量接口 + */ + @GET("/statics/alarmsNow") + suspend fun obtainAlarmNow(@Header("token") token: String): String + + /** * 根据工单状态统计工单数量 */ @GET("/job/countByJobStatus") diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index f67ccb6..0d19361 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -158,19 +158,34 @@ return api.obtainAllWell(AuthenticationHelper.token!!) } -// /** -// * 根据布防状态统计闸井数量接口 -// */ -// suspend fun countWellByState(): String { -// return api.countWellByState(AuthenticationHelper.token!!) -// } -// -// /** -// * 根据工单状态统计工单数量 -// */ -// suspend fun countWorkOrderByState(): String { -// return api.countWorkOrderByState(AuthenticationHelper.token!!) -// } + /** + * 根据布防状态统计闸井数量接口 + */ + suspend fun countWellByState(): String { + return api.countWellByState(AuthenticationHelper.token!!) + } + + /** + * 获取设备数量接口 + */ + suspend fun countDeviceByState(): String { + return api.countDeviceByState(AuthenticationHelper.token!!) + } + + /** + * 获取当前报警数量接口 + */ + suspend fun obtainAlarmNow(): String { + return api.obtainAlarmNow(AuthenticationHelper.token!!) + } + + + /** + * 根据工单状态统计工单数量 + */ + suspend fun countWorkOrderByState(): String { + return api.countWorkOrderByState(AuthenticationHelper.token!!) + } // // /** // * 获取闸井类别 diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt index b8af9b4..3ee2f6f 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt @@ -12,6 +12,7 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class AlarmViewModel : BaseViewModel() { @@ -19,6 +20,7 @@ val listModel = MutableLiveData() val typeModel = MutableLiveData() val contentModel = MutableLiveData() + val alarmCountModel = MutableLiveData() fun obtainAlarmType() = launch({ val response = RetrofitServiceManager.obtainAlarmType() @@ -88,4 +90,18 @@ }, { it.printStackTrace() }) + + fun obtainAlarmNow() = launch({ + val response = RetrofitServiceManager.obtainAlarmNow() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + alarmCountModel.value = data.getInt("total") + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt new file mode 100644 index 0000000..10be999 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt @@ -0,0 +1,36 @@ +package com.casic.app.smartwell.sanxi.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.sanxi.base.BaseViewModel +import com.casic.app.smartwell.sanxi.extensions.launch +import com.casic.app.smartwell.sanxi.extensions.separateResponseCode +import com.casic.app.smartwell.sanxi.extensions.show +import com.casic.app.smartwell.sanxi.extensions.toErrorMessage +import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import org.json.JSONObject + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val countResultModel = MutableLiveData>() + + fun countDeviceByState() = launch({ + val response = RetrofitServiceManager.countDeviceByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val map = HashMap(3) + + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + map["offline"] = data.getString("offline") + map["online"] = data.getString("online") + map["total"] = data.getString("total") + countResultModel.value = map + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt index 6a80a92..80df905 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt @@ -12,12 +12,14 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class WellViewModel : BaseViewModel() { private val gson = Gson() val detailModel = MutableLiveData() val allWellModel = MutableLiveData() + val countResultModel = MutableLiveData>() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading @@ -50,4 +52,23 @@ }, { it.printStackTrace() }) + + fun countWellByState() = launch({ + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val map = HashMap(3) + + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + map["bfWell"] = data.getString("bfWell") + map["cfWell"] = data.getString("cfWell") + map["total"] = data.getString("total") + countResultModel.value = map + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index 4d0c818..d137800 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -21,7 +21,10 @@ import com.casic.app.smartwell.sanxi.extensions.toTypeName import com.casic.app.smartwell.sanxi.model.WellListModel import com.casic.app.smartwell.sanxi.utils.Constant +import com.casic.app.smartwell.sanxi.vm.AlarmViewModel +import com.casic.app.smartwell.sanxi.vm.DeviceViewModel import com.casic.app.smartwell.sanxi.vm.WellViewModel +import com.casic.app.smartwell.sanxi.vm.WorkOrderViewModel import com.casic.app.smartwell.sanxi.widgets.EasyPopupWindow import com.casic.app.smartwell.sanxi.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -36,6 +39,9 @@ private lateinit var homeView: View private lateinit var aMap: AMap private lateinit var wellViewModel: WellViewModel + private lateinit var deviceViewModel: DeviceViewModel + private lateinit var alarmViewModel: AlarmViewModel + private lateinit var workOrderViewModel: WorkOrderViewModel /** * 所有窨井列表信息集合 @@ -91,6 +97,9 @@ //初始化vm wellViewModel = ViewModelProvider(this).get(WellViewModel::class.java) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + alarmViewModel = ViewModelProvider(this).get(AlarmViewModel::class.java) + workOrderViewModel = ViewModelProvider(this).get(WorkOrderViewModel::class.java) //获取所有窨井数据 wellViewModel.obtainAllWell() @@ -140,6 +149,32 @@ //地图初始化 initMap(savedInstanceState) + + //获取窨井总数数据 + wellViewModel.countWellByState() + wellViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.wellTotalView.text = it["total"] + }) + + //获取设备总数数据 + deviceViewModel.countDeviceByState() + deviceViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.deviceTotalView.text = it["total"] + }) + + //获取当前报警数据 + alarmViewModel.alarmCountModel.observe(viewLifecycleOwner, { + homeView.currentAlarmView.text = it.toString() + }) + + //获取当前未完工单数据 + workOrderViewModel.orderCountModel.observe(viewLifecycleOwner, { + val beforeGet = it["beforeGet"]!! + val beforeConfirm = it["beforeConfirm"]!! + val inHandle = it["inHandle"]!! + + homeView.unCompleteOrderView.text = (beforeGet + beforeConfirm + inHandle).toString() + }) return homeView } @@ -304,9 +339,9 @@ override fun onResume() { super.onResume() homeView.mapView.onResume() - //每次页面切换都需要重新刷新不同状态的窨井数量 -// wellViewModel.countWellByState() -// workOrderViewModel.countWorkOrderByState() + //每次页面切换都需要重新刷新报警和工单数 + alarmViewModel.obtainAlarmNow() + workOrderViewModel.countWorkOrderByState() } override fun onPause() { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 3c6fea3..7b63a83 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -165,6 +165,18 @@ suspend fun countWellByState(@Header("token") token: String): String /** + * 获取设备数量接口 + */ + @GET("/statics/deviceStaticsByStatus") + suspend fun countDeviceByState(@Header("token") token: String): String + + /** + * 获取当前报警数量接口 + */ + @GET("/statics/alarmsNow") + suspend fun obtainAlarmNow(@Header("token") token: String): String + + /** * 根据工单状态统计工单数量 */ @GET("/job/countByJobStatus") diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index f67ccb6..0d19361 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -158,19 +158,34 @@ return api.obtainAllWell(AuthenticationHelper.token!!) } -// /** -// * 根据布防状态统计闸井数量接口 -// */ -// suspend fun countWellByState(): String { -// return api.countWellByState(AuthenticationHelper.token!!) -// } -// -// /** -// * 根据工单状态统计工单数量 -// */ -// suspend fun countWorkOrderByState(): String { -// return api.countWorkOrderByState(AuthenticationHelper.token!!) -// } + /** + * 根据布防状态统计闸井数量接口 + */ + suspend fun countWellByState(): String { + return api.countWellByState(AuthenticationHelper.token!!) + } + + /** + * 获取设备数量接口 + */ + suspend fun countDeviceByState(): String { + return api.countDeviceByState(AuthenticationHelper.token!!) + } + + /** + * 获取当前报警数量接口 + */ + suspend fun obtainAlarmNow(): String { + return api.obtainAlarmNow(AuthenticationHelper.token!!) + } + + + /** + * 根据工单状态统计工单数量 + */ + suspend fun countWorkOrderByState(): String { + return api.countWorkOrderByState(AuthenticationHelper.token!!) + } // // /** // * 获取闸井类别 diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt index b8af9b4..3ee2f6f 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt @@ -12,6 +12,7 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class AlarmViewModel : BaseViewModel() { @@ -19,6 +20,7 @@ val listModel = MutableLiveData() val typeModel = MutableLiveData() val contentModel = MutableLiveData() + val alarmCountModel = MutableLiveData() fun obtainAlarmType() = launch({ val response = RetrofitServiceManager.obtainAlarmType() @@ -88,4 +90,18 @@ }, { it.printStackTrace() }) + + fun obtainAlarmNow() = launch({ + val response = RetrofitServiceManager.obtainAlarmNow() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + alarmCountModel.value = data.getInt("total") + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt new file mode 100644 index 0000000..10be999 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt @@ -0,0 +1,36 @@ +package com.casic.app.smartwell.sanxi.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.sanxi.base.BaseViewModel +import com.casic.app.smartwell.sanxi.extensions.launch +import com.casic.app.smartwell.sanxi.extensions.separateResponseCode +import com.casic.app.smartwell.sanxi.extensions.show +import com.casic.app.smartwell.sanxi.extensions.toErrorMessage +import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import org.json.JSONObject + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val countResultModel = MutableLiveData>() + + fun countDeviceByState() = launch({ + val response = RetrofitServiceManager.countDeviceByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val map = HashMap(3) + + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + map["offline"] = data.getString("offline") + map["online"] = data.getString("online") + map["total"] = data.getString("total") + countResultModel.value = map + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt index 6a80a92..80df905 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt @@ -12,12 +12,14 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class WellViewModel : BaseViewModel() { private val gson = Gson() val detailModel = MutableLiveData() val allWellModel = MutableLiveData() + val countResultModel = MutableLiveData>() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading @@ -50,4 +52,23 @@ }, { it.printStackTrace() }) + + fun countWellByState() = launch({ + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val map = HashMap(3) + + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + map["bfWell"] = data.getString("bfWell") + map["cfWell"] = data.getString("cfWell") + map["total"] = data.getString("total") + countResultModel.value = map + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WorkOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WorkOrderViewModel.kt index ba81e06..2d2f78c 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WorkOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WorkOrderViewModel.kt @@ -11,12 +11,14 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class WorkOrderViewModel : BaseViewModel() { private val gson = Gson() val orderListModel = MutableLiveData() val orderStatusModel = MutableLiveData() + val orderCountModel = MutableLiveData>() fun obtainWorkOrderListByState( keywords: String, alarmType: String, alarmContentType: String, jobStatus: String, page: Int @@ -49,4 +51,25 @@ }, { it.printStackTrace() }) + + fun countWorkOrderByState() = launch({ + val response = RetrofitServiceManager.countWorkOrderByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val map = HashMap(4) + + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + map["beforeGet"] = data.getInt("beforeGet") + map["beforeConfirm"] = data.getInt("beforeConfirm") + map["inHandle"] = data.getInt("inHandle") + map["over"] = data.getInt("over") + map["cancel"] = data.getInt("cancel") + orderCountModel.value = map + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index 4d0c818..d137800 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -21,7 +21,10 @@ import com.casic.app.smartwell.sanxi.extensions.toTypeName import com.casic.app.smartwell.sanxi.model.WellListModel import com.casic.app.smartwell.sanxi.utils.Constant +import com.casic.app.smartwell.sanxi.vm.AlarmViewModel +import com.casic.app.smartwell.sanxi.vm.DeviceViewModel import com.casic.app.smartwell.sanxi.vm.WellViewModel +import com.casic.app.smartwell.sanxi.vm.WorkOrderViewModel import com.casic.app.smartwell.sanxi.widgets.EasyPopupWindow import com.casic.app.smartwell.sanxi.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -36,6 +39,9 @@ private lateinit var homeView: View private lateinit var aMap: AMap private lateinit var wellViewModel: WellViewModel + private lateinit var deviceViewModel: DeviceViewModel + private lateinit var alarmViewModel: AlarmViewModel + private lateinit var workOrderViewModel: WorkOrderViewModel /** * 所有窨井列表信息集合 @@ -91,6 +97,9 @@ //初始化vm wellViewModel = ViewModelProvider(this).get(WellViewModel::class.java) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + alarmViewModel = ViewModelProvider(this).get(AlarmViewModel::class.java) + workOrderViewModel = ViewModelProvider(this).get(WorkOrderViewModel::class.java) //获取所有窨井数据 wellViewModel.obtainAllWell() @@ -140,6 +149,32 @@ //地图初始化 initMap(savedInstanceState) + + //获取窨井总数数据 + wellViewModel.countWellByState() + wellViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.wellTotalView.text = it["total"] + }) + + //获取设备总数数据 + deviceViewModel.countDeviceByState() + deviceViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.deviceTotalView.text = it["total"] + }) + + //获取当前报警数据 + alarmViewModel.alarmCountModel.observe(viewLifecycleOwner, { + homeView.currentAlarmView.text = it.toString() + }) + + //获取当前未完工单数据 + workOrderViewModel.orderCountModel.observe(viewLifecycleOwner, { + val beforeGet = it["beforeGet"]!! + val beforeConfirm = it["beforeConfirm"]!! + val inHandle = it["inHandle"]!! + + homeView.unCompleteOrderView.text = (beforeGet + beforeConfirm + inHandle).toString() + }) return homeView } @@ -304,9 +339,9 @@ override fun onResume() { super.onResume() homeView.mapView.onResume() - //每次页面切换都需要重新刷新不同状态的窨井数量 -// wellViewModel.countWellByState() -// workOrderViewModel.countWorkOrderByState() + //每次页面切换都需要重新刷新报警和工单数 + alarmViewModel.obtainAlarmNow() + workOrderViewModel.countWorkOrderByState() } override fun onPause() { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 3c6fea3..7b63a83 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -165,6 +165,18 @@ suspend fun countWellByState(@Header("token") token: String): String /** + * 获取设备数量接口 + */ + @GET("/statics/deviceStaticsByStatus") + suspend fun countDeviceByState(@Header("token") token: String): String + + /** + * 获取当前报警数量接口 + */ + @GET("/statics/alarmsNow") + suspend fun obtainAlarmNow(@Header("token") token: String): String + + /** * 根据工单状态统计工单数量 */ @GET("/job/countByJobStatus") diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index f67ccb6..0d19361 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -158,19 +158,34 @@ return api.obtainAllWell(AuthenticationHelper.token!!) } -// /** -// * 根据布防状态统计闸井数量接口 -// */ -// suspend fun countWellByState(): String { -// return api.countWellByState(AuthenticationHelper.token!!) -// } -// -// /** -// * 根据工单状态统计工单数量 -// */ -// suspend fun countWorkOrderByState(): String { -// return api.countWorkOrderByState(AuthenticationHelper.token!!) -// } + /** + * 根据布防状态统计闸井数量接口 + */ + suspend fun countWellByState(): String { + return api.countWellByState(AuthenticationHelper.token!!) + } + + /** + * 获取设备数量接口 + */ + suspend fun countDeviceByState(): String { + return api.countDeviceByState(AuthenticationHelper.token!!) + } + + /** + * 获取当前报警数量接口 + */ + suspend fun obtainAlarmNow(): String { + return api.obtainAlarmNow(AuthenticationHelper.token!!) + } + + + /** + * 根据工单状态统计工单数量 + */ + suspend fun countWorkOrderByState(): String { + return api.countWorkOrderByState(AuthenticationHelper.token!!) + } // // /** // * 获取闸井类别 diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt index b8af9b4..3ee2f6f 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt @@ -12,6 +12,7 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class AlarmViewModel : BaseViewModel() { @@ -19,6 +20,7 @@ val listModel = MutableLiveData() val typeModel = MutableLiveData() val contentModel = MutableLiveData() + val alarmCountModel = MutableLiveData() fun obtainAlarmType() = launch({ val response = RetrofitServiceManager.obtainAlarmType() @@ -88,4 +90,18 @@ }, { it.printStackTrace() }) + + fun obtainAlarmNow() = launch({ + val response = RetrofitServiceManager.obtainAlarmNow() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + alarmCountModel.value = data.getInt("total") + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt new file mode 100644 index 0000000..10be999 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt @@ -0,0 +1,36 @@ +package com.casic.app.smartwell.sanxi.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.sanxi.base.BaseViewModel +import com.casic.app.smartwell.sanxi.extensions.launch +import com.casic.app.smartwell.sanxi.extensions.separateResponseCode +import com.casic.app.smartwell.sanxi.extensions.show +import com.casic.app.smartwell.sanxi.extensions.toErrorMessage +import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import org.json.JSONObject + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val countResultModel = MutableLiveData>() + + fun countDeviceByState() = launch({ + val response = RetrofitServiceManager.countDeviceByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val map = HashMap(3) + + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + map["offline"] = data.getString("offline") + map["online"] = data.getString("online") + map["total"] = data.getString("total") + countResultModel.value = map + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt index 6a80a92..80df905 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt @@ -12,12 +12,14 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class WellViewModel : BaseViewModel() { private val gson = Gson() val detailModel = MutableLiveData() val allWellModel = MutableLiveData() + val countResultModel = MutableLiveData>() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading @@ -50,4 +52,23 @@ }, { it.printStackTrace() }) + + fun countWellByState() = launch({ + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val map = HashMap(3) + + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + map["bfWell"] = data.getString("bfWell") + map["cfWell"] = data.getString("cfWell") + map["total"] = data.getString("total") + countResultModel.value = map + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WorkOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WorkOrderViewModel.kt index ba81e06..2d2f78c 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WorkOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WorkOrderViewModel.kt @@ -11,12 +11,14 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class WorkOrderViewModel : BaseViewModel() { private val gson = Gson() val orderListModel = MutableLiveData() val orderStatusModel = MutableLiveData() + val orderCountModel = MutableLiveData>() fun obtainWorkOrderListByState( keywords: String, alarmType: String, alarmContentType: String, jobStatus: String, page: Int @@ -49,4 +51,25 @@ }, { it.printStackTrace() }) + + fun countWorkOrderByState() = launch({ + val response = RetrofitServiceManager.countWorkOrderByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val map = HashMap(4) + + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + map["beforeGet"] = data.getInt("beforeGet") + map["beforeConfirm"] = data.getInt("beforeConfirm") + map["inHandle"] = data.getInt("inHandle") + map["over"] = data.getInt("over") + map["cancel"] = data.getInt("cancel") + orderCountModel.value = map + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 071a1fa..2fe5769 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -59,6 +59,108 @@ android:layout_centerInParent="true" android:background="@drawable/bottom_short_line" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt index 4d0c818..d137800 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/fragment/HomePageFragment.kt @@ -21,7 +21,10 @@ import com.casic.app.smartwell.sanxi.extensions.toTypeName import com.casic.app.smartwell.sanxi.model.WellListModel import com.casic.app.smartwell.sanxi.utils.Constant +import com.casic.app.smartwell.sanxi.vm.AlarmViewModel +import com.casic.app.smartwell.sanxi.vm.DeviceViewModel import com.casic.app.smartwell.sanxi.vm.WellViewModel +import com.casic.app.smartwell.sanxi.vm.WorkOrderViewModel import com.casic.app.smartwell.sanxi.widgets.EasyPopupWindow import com.casic.app.smartwell.sanxi.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior @@ -36,6 +39,9 @@ private lateinit var homeView: View private lateinit var aMap: AMap private lateinit var wellViewModel: WellViewModel + private lateinit var deviceViewModel: DeviceViewModel + private lateinit var alarmViewModel: AlarmViewModel + private lateinit var workOrderViewModel: WorkOrderViewModel /** * 所有窨井列表信息集合 @@ -91,6 +97,9 @@ //初始化vm wellViewModel = ViewModelProvider(this).get(WellViewModel::class.java) + deviceViewModel = ViewModelProvider(this).get(DeviceViewModel::class.java) + alarmViewModel = ViewModelProvider(this).get(AlarmViewModel::class.java) + workOrderViewModel = ViewModelProvider(this).get(WorkOrderViewModel::class.java) //获取所有窨井数据 wellViewModel.obtainAllWell() @@ -140,6 +149,32 @@ //地图初始化 initMap(savedInstanceState) + + //获取窨井总数数据 + wellViewModel.countWellByState() + wellViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.wellTotalView.text = it["total"] + }) + + //获取设备总数数据 + deviceViewModel.countDeviceByState() + deviceViewModel.countResultModel.observe(viewLifecycleOwner, { + homeView.deviceTotalView.text = it["total"] + }) + + //获取当前报警数据 + alarmViewModel.alarmCountModel.observe(viewLifecycleOwner, { + homeView.currentAlarmView.text = it.toString() + }) + + //获取当前未完工单数据 + workOrderViewModel.orderCountModel.observe(viewLifecycleOwner, { + val beforeGet = it["beforeGet"]!! + val beforeConfirm = it["beforeConfirm"]!! + val inHandle = it["inHandle"]!! + + homeView.unCompleteOrderView.text = (beforeGet + beforeConfirm + inHandle).toString() + }) return homeView } @@ -304,9 +339,9 @@ override fun onResume() { super.onResume() homeView.mapView.onResume() - //每次页面切换都需要重新刷新不同状态的窨井数量 -// wellViewModel.countWellByState() -// workOrderViewModel.countWorkOrderByState() + //每次页面切换都需要重新刷新报警和工单数 + alarmViewModel.obtainAlarmNow() + workOrderViewModel.countWorkOrderByState() } override fun onPause() { diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt index 3c6fea3..7b63a83 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitService.kt @@ -165,6 +165,18 @@ suspend fun countWellByState(@Header("token") token: String): String /** + * 获取设备数量接口 + */ + @GET("/statics/deviceStaticsByStatus") + suspend fun countDeviceByState(@Header("token") token: String): String + + /** + * 获取当前报警数量接口 + */ + @GET("/statics/alarmsNow") + suspend fun obtainAlarmNow(@Header("token") token: String): String + + /** * 根据工单状态统计工单数量 */ @GET("/job/countByJobStatus") diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt index f67ccb6..0d19361 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/utils/retrofit/RetrofitServiceManager.kt @@ -158,19 +158,34 @@ return api.obtainAllWell(AuthenticationHelper.token!!) } -// /** -// * 根据布防状态统计闸井数量接口 -// */ -// suspend fun countWellByState(): String { -// return api.countWellByState(AuthenticationHelper.token!!) -// } -// -// /** -// * 根据工单状态统计工单数量 -// */ -// suspend fun countWorkOrderByState(): String { -// return api.countWorkOrderByState(AuthenticationHelper.token!!) -// } + /** + * 根据布防状态统计闸井数量接口 + */ + suspend fun countWellByState(): String { + return api.countWellByState(AuthenticationHelper.token!!) + } + + /** + * 获取设备数量接口 + */ + suspend fun countDeviceByState(): String { + return api.countDeviceByState(AuthenticationHelper.token!!) + } + + /** + * 获取当前报警数量接口 + */ + suspend fun obtainAlarmNow(): String { + return api.obtainAlarmNow(AuthenticationHelper.token!!) + } + + + /** + * 根据工单状态统计工单数量 + */ + suspend fun countWorkOrderByState(): String { + return api.countWorkOrderByState(AuthenticationHelper.token!!) + } // // /** // * 获取闸井类别 diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt index b8af9b4..3ee2f6f 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/AlarmViewModel.kt @@ -12,6 +12,7 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class AlarmViewModel : BaseViewModel() { @@ -19,6 +20,7 @@ val listModel = MutableLiveData() val typeModel = MutableLiveData() val contentModel = MutableLiveData() + val alarmCountModel = MutableLiveData() fun obtainAlarmType() = launch({ val response = RetrofitServiceManager.obtainAlarmType() @@ -88,4 +90,18 @@ }, { it.printStackTrace() }) + + fun obtainAlarmNow() = launch({ + val response = RetrofitServiceManager.obtainAlarmNow() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + alarmCountModel.value = data.getInt("total") + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt new file mode 100644 index 0000000..10be999 --- /dev/null +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/DeviceViewModel.kt @@ -0,0 +1,36 @@ +package com.casic.app.smartwell.sanxi.vm + +import androidx.lifecycle.MutableLiveData +import com.casic.app.smartwell.sanxi.base.BaseViewModel +import com.casic.app.smartwell.sanxi.extensions.launch +import com.casic.app.smartwell.sanxi.extensions.separateResponseCode +import com.casic.app.smartwell.sanxi.extensions.show +import com.casic.app.smartwell.sanxi.extensions.toErrorMessage +import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import org.json.JSONObject + +class DeviceViewModel : BaseViewModel() { + + private val gson = Gson() + val countResultModel = MutableLiveData>() + + fun countDeviceByState() = launch({ + val response = RetrofitServiceManager.countDeviceByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val map = HashMap(3) + + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + map["offline"] = data.getString("offline") + map["online"] = data.getString("online") + map["total"] = data.getString("total") + countResultModel.value = map + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt index 6a80a92..80df905 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WellViewModel.kt @@ -12,12 +12,14 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class WellViewModel : BaseViewModel() { private val gson = Gson() val detailModel = MutableLiveData() val allWellModel = MutableLiveData() + val countResultModel = MutableLiveData>() fun obtainWellDetail(id: String) = launch({ loadState.value = LoadState.Loading @@ -50,4 +52,23 @@ }, { it.printStackTrace() }) + + fun countWellByState() = launch({ + val response = RetrofitServiceManager.countWellByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val map = HashMap(3) + + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + map["bfWell"] = data.getString("bfWell") + map["cfWell"] = data.getString("cfWell") + map["total"] = data.getString("total") + countResultModel.value = map + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WorkOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WorkOrderViewModel.kt index ba81e06..2d2f78c 100644 --- a/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WorkOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/sanxi/vm/WorkOrderViewModel.kt @@ -11,12 +11,14 @@ import com.casic.app.smartwell.sanxi.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import org.json.JSONObject class WorkOrderViewModel : BaseViewModel() { private val gson = Gson() val orderListModel = MutableLiveData() val orderStatusModel = MutableLiveData() + val orderCountModel = MutableLiveData>() fun obtainWorkOrderListByState( keywords: String, alarmType: String, alarmContentType: String, jobStatus: String, page: Int @@ -49,4 +51,25 @@ }, { it.printStackTrace() }) + + fun countWorkOrderByState() = launch({ + val response = RetrofitServiceManager.countWorkOrderByState() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + val map = HashMap(4) + + val jsonObject = JSONObject(response) + val data = jsonObject.getJSONObject("data") + map["beforeGet"] = data.getInt("beforeGet") + map["beforeConfirm"] = data.getInt("beforeConfirm") + map["inHandle"] = data.getInt("inHandle") + map["over"] = data.getInt("over") + map["cancel"] = data.getInt("cancel") + orderCountModel.value = map + } else { + response.toErrorMessage().show() + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 071a1fa..2fe5769 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -59,6 +59,108 @@ android:layout_centerInParent="true" android:background="@drawable/bottom_short_line" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index dd0459a..c5a28d9 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -117,4 +117,15 @@ @color/white @dimen/sp_16 + + +