diff --git a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt index d9c9b86..15ded77 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt @@ -3,7 +3,6 @@ import android.graphics.Point import android.os.Bundle import android.os.CountDownTimer -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -29,6 +28,7 @@ import com.casic.smarttube.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior import com.pengxh.kt.lite.extensions.* +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.fragment_home.view.* @@ -61,7 +61,7 @@ /** * 所有设备列表信息集合 * */ - private var deviceModels: MutableList = ArrayList() + private var deviceModels: MutableList = ArrayList() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -133,14 +133,10 @@ allMarkerOptions.add( MarkerOptions() .position(LatLng(latitude, longitude)) - .title(device.wellName) - .snippet(device.wellCode) + .title(device.devcode) + .snippet(device.modelName) ) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -173,7 +169,6 @@ val uiSettings = aMap.uiSettings uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isZoomControlsEnabled = false//不显示+/- uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 uiSettings.isRotateGesturesEnabled = false//不允许地图旋转 @@ -202,6 +197,12 @@ groupViewModel.obtainDeviceListByGroup(dataBeans[position].groupId) } }) + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(requireActivity(), "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) groupViewModel.groupDeviceModel.observe(this, { if (it.code == 200) { val latitudeList: MutableList = ArrayList() @@ -217,11 +218,7 @@ //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -322,7 +319,7 @@ } override fun onMarkerClick(marker: Marker?): Boolean { - //显示闸井信息 + //显示设备基本信息 marker?.showInfoWindow() return true } @@ -333,11 +330,10 @@ } val v = infoWindow!! //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceModelView = v.findViewById(R.id.deviceModelView) + val deviceValueView = v.findViewById(R.id.deviceValueView) + val updateTimeView = v.findViewById(R.id.updateTimeView) val locationView = v.findViewById(R.id.locationView) //绑定数据 @@ -346,11 +342,19 @@ if (clickedLatLng.latitude == device.latGaode!!.toDouble() && clickedLatLng.longitude == device.lngGaode!!.toDouble() ) { - wellCodeView.text = String.format("闸井编号: ${device.wellCode}") - wellNameView.text = String.format("闸井名称: ${device.wellName}") - wellTypeView.text = String.format("闸井类型: ${device.wellType}") - wellStateView.text = String.format("布/撤防状态: ${device.bfzt}") - deepView.text = String.format("闸井深度: ${device.deep}m") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceModelView.text = String.format("设备模型: ${device.modelName}") + //获取设备最新浓度信息 + deviceViewModel.obtainTubeLastData(device.devcode) + deviceViewModel.lastDataModel.observe(requireActivity(), { + if (it.code == 200) { + deviceValueView.text = String.format("最新浓度: ${it.data.strength}") + updateTimeView.text = String.format("更新时间: ${it.data.uptime}") + }else{ + deviceValueView.text = String.format("最新浓度: 未知") + updateTimeView.text = String.format("更新时间: 未知") + } + }) locationView.text = String.format("详细位置: ${device.position}") return infoWindow } diff --git a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt index d9c9b86..15ded77 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt @@ -3,7 +3,6 @@ import android.graphics.Point import android.os.Bundle import android.os.CountDownTimer -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -29,6 +28,7 @@ import com.casic.smarttube.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior import com.pengxh.kt.lite.extensions.* +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.fragment_home.view.* @@ -61,7 +61,7 @@ /** * 所有设备列表信息集合 * */ - private var deviceModels: MutableList = ArrayList() + private var deviceModels: MutableList = ArrayList() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -133,14 +133,10 @@ allMarkerOptions.add( MarkerOptions() .position(LatLng(latitude, longitude)) - .title(device.wellName) - .snippet(device.wellCode) + .title(device.devcode) + .snippet(device.modelName) ) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -173,7 +169,6 @@ val uiSettings = aMap.uiSettings uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isZoomControlsEnabled = false//不显示+/- uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 uiSettings.isRotateGesturesEnabled = false//不允许地图旋转 @@ -202,6 +197,12 @@ groupViewModel.obtainDeviceListByGroup(dataBeans[position].groupId) } }) + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(requireActivity(), "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) groupViewModel.groupDeviceModel.observe(this, { if (it.code == 200) { val latitudeList: MutableList = ArrayList() @@ -217,11 +218,7 @@ //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -322,7 +319,7 @@ } override fun onMarkerClick(marker: Marker?): Boolean { - //显示闸井信息 + //显示设备基本信息 marker?.showInfoWindow() return true } @@ -333,11 +330,10 @@ } val v = infoWindow!! //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceModelView = v.findViewById(R.id.deviceModelView) + val deviceValueView = v.findViewById(R.id.deviceValueView) + val updateTimeView = v.findViewById(R.id.updateTimeView) val locationView = v.findViewById(R.id.locationView) //绑定数据 @@ -346,11 +342,19 @@ if (clickedLatLng.latitude == device.latGaode!!.toDouble() && clickedLatLng.longitude == device.lngGaode!!.toDouble() ) { - wellCodeView.text = String.format("闸井编号: ${device.wellCode}") - wellNameView.text = String.format("闸井名称: ${device.wellName}") - wellTypeView.text = String.format("闸井类型: ${device.wellType}") - wellStateView.text = String.format("布/撤防状态: ${device.bfzt}") - deepView.text = String.format("闸井深度: ${device.deep}m") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceModelView.text = String.format("设备模型: ${device.modelName}") + //获取设备最新浓度信息 + deviceViewModel.obtainTubeLastData(device.devcode) + deviceViewModel.lastDataModel.observe(requireActivity(), { + if (it.code == 200) { + deviceValueView.text = String.format("最新浓度: ${it.data.strength}") + updateTimeView.text = String.format("更新时间: ${it.data.uptime}") + }else{ + deviceValueView.text = String.format("最新浓度: 未知") + updateTimeView.text = String.format("更新时间: 未知") + } + }) locationView.text = String.format("详细位置: ${device.position}") return infoWindow } diff --git a/app/src/main/java/com/casic/smarttube/model/LastDataModel.java b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java new file mode 100644 index 0000000..5d09ef0 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java @@ -0,0 +1,179 @@ +package com.casic.smarttube.model; + +public class LastDataModel { + + private int code; + private DataModel data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataModel { + private String deviceType; + private String responsibleDept; + private String strength; + private String wellCode; + private String groupId; + private String deptid; + private String staff; + private String deviceName; + private String uptime; + private String lngGaode; + private String latGaode; + private String devcode; + private String wellName; + private String tel; + private String data_tube_id; + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getResponsibleDept() { + return responsibleDept; + } + + public void setResponsibleDept(String responsibleDept) { + this.responsibleDept = responsibleDept; + } + + public String getStrength() { + return strength; + } + + public void setStrength(String strength) { + this.strength = strength; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getStaff() { + return staff; + } + + public void setStaff(String staff) { + this.staff = staff; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getWellName() { + return wellName; + } + + public void setWellName(String wellName) { + this.wellName = wellName; + } + + public String getTel() { + return tel; + } + + public void setTel(String tel) { + this.tel = tel; + } + + public String getData_tube_id() { + return data_tube_id; + } + + public void setData_tube_id(String data_tube_id) { + this.data_tube_id = data_tube_id; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt index d9c9b86..15ded77 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt @@ -3,7 +3,6 @@ import android.graphics.Point import android.os.Bundle import android.os.CountDownTimer -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -29,6 +28,7 @@ import com.casic.smarttube.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior import com.pengxh.kt.lite.extensions.* +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.fragment_home.view.* @@ -61,7 +61,7 @@ /** * 所有设备列表信息集合 * */ - private var deviceModels: MutableList = ArrayList() + private var deviceModels: MutableList = ArrayList() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -133,14 +133,10 @@ allMarkerOptions.add( MarkerOptions() .position(LatLng(latitude, longitude)) - .title(device.wellName) - .snippet(device.wellCode) + .title(device.devcode) + .snippet(device.modelName) ) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -173,7 +169,6 @@ val uiSettings = aMap.uiSettings uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isZoomControlsEnabled = false//不显示+/- uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 uiSettings.isRotateGesturesEnabled = false//不允许地图旋转 @@ -202,6 +197,12 @@ groupViewModel.obtainDeviceListByGroup(dataBeans[position].groupId) } }) + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(requireActivity(), "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) groupViewModel.groupDeviceModel.observe(this, { if (it.code == 200) { val latitudeList: MutableList = ArrayList() @@ -217,11 +218,7 @@ //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -322,7 +319,7 @@ } override fun onMarkerClick(marker: Marker?): Boolean { - //显示闸井信息 + //显示设备基本信息 marker?.showInfoWindow() return true } @@ -333,11 +330,10 @@ } val v = infoWindow!! //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceModelView = v.findViewById(R.id.deviceModelView) + val deviceValueView = v.findViewById(R.id.deviceValueView) + val updateTimeView = v.findViewById(R.id.updateTimeView) val locationView = v.findViewById(R.id.locationView) //绑定数据 @@ -346,11 +342,19 @@ if (clickedLatLng.latitude == device.latGaode!!.toDouble() && clickedLatLng.longitude == device.lngGaode!!.toDouble() ) { - wellCodeView.text = String.format("闸井编号: ${device.wellCode}") - wellNameView.text = String.format("闸井名称: ${device.wellName}") - wellTypeView.text = String.format("闸井类型: ${device.wellType}") - wellStateView.text = String.format("布/撤防状态: ${device.bfzt}") - deepView.text = String.format("闸井深度: ${device.deep}m") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceModelView.text = String.format("设备模型: ${device.modelName}") + //获取设备最新浓度信息 + deviceViewModel.obtainTubeLastData(device.devcode) + deviceViewModel.lastDataModel.observe(requireActivity(), { + if (it.code == 200) { + deviceValueView.text = String.format("最新浓度: ${it.data.strength}") + updateTimeView.text = String.format("更新时间: ${it.data.uptime}") + }else{ + deviceValueView.text = String.format("最新浓度: 未知") + updateTimeView.text = String.format("更新时间: 未知") + } + }) locationView.text = String.format("详细位置: ${device.position}") return infoWindow } diff --git a/app/src/main/java/com/casic/smarttube/model/LastDataModel.java b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java new file mode 100644 index 0000000..5d09ef0 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java @@ -0,0 +1,179 @@ +package com.casic.smarttube.model; + +public class LastDataModel { + + private int code; + private DataModel data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataModel { + private String deviceType; + private String responsibleDept; + private String strength; + private String wellCode; + private String groupId; + private String deptid; + private String staff; + private String deviceName; + private String uptime; + private String lngGaode; + private String latGaode; + private String devcode; + private String wellName; + private String tel; + private String data_tube_id; + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getResponsibleDept() { + return responsibleDept; + } + + public void setResponsibleDept(String responsibleDept) { + this.responsibleDept = responsibleDept; + } + + public String getStrength() { + return strength; + } + + public void setStrength(String strength) { + this.strength = strength; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getStaff() { + return staff; + } + + public void setStaff(String staff) { + this.staff = staff; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getWellName() { + return wellName; + } + + public void setWellName(String wellName) { + this.wellName = wellName; + } + + public String getTel() { + return tel; + } + + public void setTel(String tel) { + this.tel = tel; + } + + public String getData_tube_id() { + return data_tube_id; + } + + public void setData_tube_id(String data_tube_id) { + this.data_tube_id = data_tube_id; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java index 7e8a367..75f18f7 100644 --- a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java +++ b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java @@ -5,7 +5,7 @@ public class MapDeviceModel { private int code; - private List data; + private List data; private String message; private String success; @@ -17,11 +17,11 @@ this.code = code; } - public List getData() { + public List getData() { return data; } - public void setData(List data) { + public void setData(List data) { this.data = data; } @@ -41,11 +41,10 @@ this.success = success; } - public static class DataBean { + public static class DataModel { private String area; - private int deep; + private String deep; private String responsibleDept; - private String wellCode; private String groupId; private String deptid; private String staff; @@ -53,9 +52,10 @@ private String wellType; private String valid; private String bfzt; + private String modelName; + private String devcode; private String lngGaode; private String latGaode; - private String wellName; private String tel; private String position; @@ -67,11 +67,11 @@ this.area = area; } - public int getDeep() { + public String getDeep() { return deep; } - public void setDeep(int deep) { + public void setDeep(String deep) { this.deep = deep; } @@ -83,14 +83,6 @@ this.responsibleDept = responsibleDept; } - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - public String getGroupId() { return groupId; } @@ -147,6 +139,22 @@ this.bfzt = bfzt; } + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + public String getLngGaode() { return lngGaode; } @@ -163,14 +171,6 @@ this.latGaode = latGaode; } - public String getWellName() { - return wellName; - } - - public void setWellName(String wellName) { - this.wellName = wellName; - } - public String getTel() { return tel; } diff --git a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt index d9c9b86..15ded77 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt @@ -3,7 +3,6 @@ import android.graphics.Point import android.os.Bundle import android.os.CountDownTimer -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -29,6 +28,7 @@ import com.casic.smarttube.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior import com.pengxh.kt.lite.extensions.* +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.fragment_home.view.* @@ -61,7 +61,7 @@ /** * 所有设备列表信息集合 * */ - private var deviceModels: MutableList = ArrayList() + private var deviceModels: MutableList = ArrayList() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -133,14 +133,10 @@ allMarkerOptions.add( MarkerOptions() .position(LatLng(latitude, longitude)) - .title(device.wellName) - .snippet(device.wellCode) + .title(device.devcode) + .snippet(device.modelName) ) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -173,7 +169,6 @@ val uiSettings = aMap.uiSettings uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isZoomControlsEnabled = false//不显示+/- uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 uiSettings.isRotateGesturesEnabled = false//不允许地图旋转 @@ -202,6 +197,12 @@ groupViewModel.obtainDeviceListByGroup(dataBeans[position].groupId) } }) + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(requireActivity(), "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) groupViewModel.groupDeviceModel.observe(this, { if (it.code == 200) { val latitudeList: MutableList = ArrayList() @@ -217,11 +218,7 @@ //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -322,7 +319,7 @@ } override fun onMarkerClick(marker: Marker?): Boolean { - //显示闸井信息 + //显示设备基本信息 marker?.showInfoWindow() return true } @@ -333,11 +330,10 @@ } val v = infoWindow!! //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceModelView = v.findViewById(R.id.deviceModelView) + val deviceValueView = v.findViewById(R.id.deviceValueView) + val updateTimeView = v.findViewById(R.id.updateTimeView) val locationView = v.findViewById(R.id.locationView) //绑定数据 @@ -346,11 +342,19 @@ if (clickedLatLng.latitude == device.latGaode!!.toDouble() && clickedLatLng.longitude == device.lngGaode!!.toDouble() ) { - wellCodeView.text = String.format("闸井编号: ${device.wellCode}") - wellNameView.text = String.format("闸井名称: ${device.wellName}") - wellTypeView.text = String.format("闸井类型: ${device.wellType}") - wellStateView.text = String.format("布/撤防状态: ${device.bfzt}") - deepView.text = String.format("闸井深度: ${device.deep}m") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceModelView.text = String.format("设备模型: ${device.modelName}") + //获取设备最新浓度信息 + deviceViewModel.obtainTubeLastData(device.devcode) + deviceViewModel.lastDataModel.observe(requireActivity(), { + if (it.code == 200) { + deviceValueView.text = String.format("最新浓度: ${it.data.strength}") + updateTimeView.text = String.format("更新时间: ${it.data.uptime}") + }else{ + deviceValueView.text = String.format("最新浓度: 未知") + updateTimeView.text = String.format("更新时间: 未知") + } + }) locationView.text = String.format("详细位置: ${device.position}") return infoWindow } diff --git a/app/src/main/java/com/casic/smarttube/model/LastDataModel.java b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java new file mode 100644 index 0000000..5d09ef0 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java @@ -0,0 +1,179 @@ +package com.casic.smarttube.model; + +public class LastDataModel { + + private int code; + private DataModel data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataModel { + private String deviceType; + private String responsibleDept; + private String strength; + private String wellCode; + private String groupId; + private String deptid; + private String staff; + private String deviceName; + private String uptime; + private String lngGaode; + private String latGaode; + private String devcode; + private String wellName; + private String tel; + private String data_tube_id; + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getResponsibleDept() { + return responsibleDept; + } + + public void setResponsibleDept(String responsibleDept) { + this.responsibleDept = responsibleDept; + } + + public String getStrength() { + return strength; + } + + public void setStrength(String strength) { + this.strength = strength; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getStaff() { + return staff; + } + + public void setStaff(String staff) { + this.staff = staff; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getWellName() { + return wellName; + } + + public void setWellName(String wellName) { + this.wellName = wellName; + } + + public String getTel() { + return tel; + } + + public void setTel(String tel) { + this.tel = tel; + } + + public String getData_tube_id() { + return data_tube_id; + } + + public void setData_tube_id(String data_tube_id) { + this.data_tube_id = data_tube_id; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java index 7e8a367..75f18f7 100644 --- a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java +++ b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java @@ -5,7 +5,7 @@ public class MapDeviceModel { private int code; - private List data; + private List data; private String message; private String success; @@ -17,11 +17,11 @@ this.code = code; } - public List getData() { + public List getData() { return data; } - public void setData(List data) { + public void setData(List data) { this.data = data; } @@ -41,11 +41,10 @@ this.success = success; } - public static class DataBean { + public static class DataModel { private String area; - private int deep; + private String deep; private String responsibleDept; - private String wellCode; private String groupId; private String deptid; private String staff; @@ -53,9 +52,10 @@ private String wellType; private String valid; private String bfzt; + private String modelName; + private String devcode; private String lngGaode; private String latGaode; - private String wellName; private String tel; private String position; @@ -67,11 +67,11 @@ this.area = area; } - public int getDeep() { + public String getDeep() { return deep; } - public void setDeep(int deep) { + public void setDeep(String deep) { this.deep = deep; } @@ -83,14 +83,6 @@ this.responsibleDept = responsibleDept; } - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - public String getGroupId() { return groupId; } @@ -147,6 +139,22 @@ this.bfzt = bfzt; } + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + public String getLngGaode() { return lngGaode; } @@ -163,14 +171,6 @@ this.latGaode = latGaode; } - public String getWellName() { - return wellName; - } - - public void setWellName(String wellName) { - this.wellName = wellName; - } - public String getTel() { return tel; } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..e22936c 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -26,7 +26,7 @@ * */ const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 - const val RADIUS_SIZE = 50 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 30 //相距多少米才聚合,单位:米 /** * ============================================================================================= diff --git a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt index d9c9b86..15ded77 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt @@ -3,7 +3,6 @@ import android.graphics.Point import android.os.Bundle import android.os.CountDownTimer -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -29,6 +28,7 @@ import com.casic.smarttube.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior import com.pengxh.kt.lite.extensions.* +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.fragment_home.view.* @@ -61,7 +61,7 @@ /** * 所有设备列表信息集合 * */ - private var deviceModels: MutableList = ArrayList() + private var deviceModels: MutableList = ArrayList() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -133,14 +133,10 @@ allMarkerOptions.add( MarkerOptions() .position(LatLng(latitude, longitude)) - .title(device.wellName) - .snippet(device.wellCode) + .title(device.devcode) + .snippet(device.modelName) ) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -173,7 +169,6 @@ val uiSettings = aMap.uiSettings uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isZoomControlsEnabled = false//不显示+/- uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 uiSettings.isRotateGesturesEnabled = false//不允许地图旋转 @@ -202,6 +197,12 @@ groupViewModel.obtainDeviceListByGroup(dataBeans[position].groupId) } }) + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(requireActivity(), "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) groupViewModel.groupDeviceModel.observe(this, { if (it.code == 200) { val latitudeList: MutableList = ArrayList() @@ -217,11 +218,7 @@ //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -322,7 +319,7 @@ } override fun onMarkerClick(marker: Marker?): Boolean { - //显示闸井信息 + //显示设备基本信息 marker?.showInfoWindow() return true } @@ -333,11 +330,10 @@ } val v = infoWindow!! //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceModelView = v.findViewById(R.id.deviceModelView) + val deviceValueView = v.findViewById(R.id.deviceValueView) + val updateTimeView = v.findViewById(R.id.updateTimeView) val locationView = v.findViewById(R.id.locationView) //绑定数据 @@ -346,11 +342,19 @@ if (clickedLatLng.latitude == device.latGaode!!.toDouble() && clickedLatLng.longitude == device.lngGaode!!.toDouble() ) { - wellCodeView.text = String.format("闸井编号: ${device.wellCode}") - wellNameView.text = String.format("闸井名称: ${device.wellName}") - wellTypeView.text = String.format("闸井类型: ${device.wellType}") - wellStateView.text = String.format("布/撤防状态: ${device.bfzt}") - deepView.text = String.format("闸井深度: ${device.deep}m") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceModelView.text = String.format("设备模型: ${device.modelName}") + //获取设备最新浓度信息 + deviceViewModel.obtainTubeLastData(device.devcode) + deviceViewModel.lastDataModel.observe(requireActivity(), { + if (it.code == 200) { + deviceValueView.text = String.format("最新浓度: ${it.data.strength}") + updateTimeView.text = String.format("更新时间: ${it.data.uptime}") + }else{ + deviceValueView.text = String.format("最新浓度: 未知") + updateTimeView.text = String.format("更新时间: 未知") + } + }) locationView.text = String.format("详细位置: ${device.position}") return infoWindow } diff --git a/app/src/main/java/com/casic/smarttube/model/LastDataModel.java b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java new file mode 100644 index 0000000..5d09ef0 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java @@ -0,0 +1,179 @@ +package com.casic.smarttube.model; + +public class LastDataModel { + + private int code; + private DataModel data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataModel { + private String deviceType; + private String responsibleDept; + private String strength; + private String wellCode; + private String groupId; + private String deptid; + private String staff; + private String deviceName; + private String uptime; + private String lngGaode; + private String latGaode; + private String devcode; + private String wellName; + private String tel; + private String data_tube_id; + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getResponsibleDept() { + return responsibleDept; + } + + public void setResponsibleDept(String responsibleDept) { + this.responsibleDept = responsibleDept; + } + + public String getStrength() { + return strength; + } + + public void setStrength(String strength) { + this.strength = strength; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getStaff() { + return staff; + } + + public void setStaff(String staff) { + this.staff = staff; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getWellName() { + return wellName; + } + + public void setWellName(String wellName) { + this.wellName = wellName; + } + + public String getTel() { + return tel; + } + + public void setTel(String tel) { + this.tel = tel; + } + + public String getData_tube_id() { + return data_tube_id; + } + + public void setData_tube_id(String data_tube_id) { + this.data_tube_id = data_tube_id; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java index 7e8a367..75f18f7 100644 --- a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java +++ b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java @@ -5,7 +5,7 @@ public class MapDeviceModel { private int code; - private List data; + private List data; private String message; private String success; @@ -17,11 +17,11 @@ this.code = code; } - public List getData() { + public List getData() { return data; } - public void setData(List data) { + public void setData(List data) { this.data = data; } @@ -41,11 +41,10 @@ this.success = success; } - public static class DataBean { + public static class DataModel { private String area; - private int deep; + private String deep; private String responsibleDept; - private String wellCode; private String groupId; private String deptid; private String staff; @@ -53,9 +52,10 @@ private String wellType; private String valid; private String bfzt; + private String modelName; + private String devcode; private String lngGaode; private String latGaode; - private String wellName; private String tel; private String position; @@ -67,11 +67,11 @@ this.area = area; } - public int getDeep() { + public String getDeep() { return deep; } - public void setDeep(int deep) { + public void setDeep(String deep) { this.deep = deep; } @@ -83,14 +83,6 @@ this.responsibleDept = responsibleDept; } - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - public String getGroupId() { return groupId; } @@ -147,6 +139,22 @@ this.bfzt = bfzt; } + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + public String getLngGaode() { return lngGaode; } @@ -163,14 +171,6 @@ this.latGaode = latGaode; } - public String getWellName() { - return wellName; - } - - public void setWellName(String wellName) { - this.wellName = wellName; - } - public String getTel() { return tel; } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..e22936c 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -26,7 +26,7 @@ * */ const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 - const val RADIUS_SIZE = 50 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 30 //相距多少米才聚合,单位:米 /** * ============================================================================================= diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index c1205c8..f6c50be 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -19,7 +19,7 @@ * @param secretKey 加密后的密码 */ @FormUrlEncoded - @POST("/user/appLogin") + @POST("/user/login") suspend fun obtainLoginResult( @Field("sid") sid: String, @Field("username") account: String, @@ -187,4 +187,15 @@ @Query("offset") offset: Int, @Query("limit") limit: Int ): String + + /** + * 获取设备最新数据 + * + * @param devcode 管盯设备编号 + */ + @GET("/tube/latestdata/{devcode}") + suspend fun obtainTubeLastData( + @Header("token") token: String, + @Path("devcode") devcode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt index d9c9b86..15ded77 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt @@ -3,7 +3,6 @@ import android.graphics.Point import android.os.Bundle import android.os.CountDownTimer -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -29,6 +28,7 @@ import com.casic.smarttube.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior import com.pengxh.kt.lite.extensions.* +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.fragment_home.view.* @@ -61,7 +61,7 @@ /** * 所有设备列表信息集合 * */ - private var deviceModels: MutableList = ArrayList() + private var deviceModels: MutableList = ArrayList() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -133,14 +133,10 @@ allMarkerOptions.add( MarkerOptions() .position(LatLng(latitude, longitude)) - .title(device.wellName) - .snippet(device.wellCode) + .title(device.devcode) + .snippet(device.modelName) ) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -173,7 +169,6 @@ val uiSettings = aMap.uiSettings uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isZoomControlsEnabled = false//不显示+/- uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 uiSettings.isRotateGesturesEnabled = false//不允许地图旋转 @@ -202,6 +197,12 @@ groupViewModel.obtainDeviceListByGroup(dataBeans[position].groupId) } }) + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(requireActivity(), "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) groupViewModel.groupDeviceModel.observe(this, { if (it.code == 200) { val latitudeList: MutableList = ArrayList() @@ -217,11 +218,7 @@ //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -322,7 +319,7 @@ } override fun onMarkerClick(marker: Marker?): Boolean { - //显示闸井信息 + //显示设备基本信息 marker?.showInfoWindow() return true } @@ -333,11 +330,10 @@ } val v = infoWindow!! //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceModelView = v.findViewById(R.id.deviceModelView) + val deviceValueView = v.findViewById(R.id.deviceValueView) + val updateTimeView = v.findViewById(R.id.updateTimeView) val locationView = v.findViewById(R.id.locationView) //绑定数据 @@ -346,11 +342,19 @@ if (clickedLatLng.latitude == device.latGaode!!.toDouble() && clickedLatLng.longitude == device.lngGaode!!.toDouble() ) { - wellCodeView.text = String.format("闸井编号: ${device.wellCode}") - wellNameView.text = String.format("闸井名称: ${device.wellName}") - wellTypeView.text = String.format("闸井类型: ${device.wellType}") - wellStateView.text = String.format("布/撤防状态: ${device.bfzt}") - deepView.text = String.format("闸井深度: ${device.deep}m") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceModelView.text = String.format("设备模型: ${device.modelName}") + //获取设备最新浓度信息 + deviceViewModel.obtainTubeLastData(device.devcode) + deviceViewModel.lastDataModel.observe(requireActivity(), { + if (it.code == 200) { + deviceValueView.text = String.format("最新浓度: ${it.data.strength}") + updateTimeView.text = String.format("更新时间: ${it.data.uptime}") + }else{ + deviceValueView.text = String.format("最新浓度: 未知") + updateTimeView.text = String.format("更新时间: 未知") + } + }) locationView.text = String.format("详细位置: ${device.position}") return infoWindow } diff --git a/app/src/main/java/com/casic/smarttube/model/LastDataModel.java b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java new file mode 100644 index 0000000..5d09ef0 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java @@ -0,0 +1,179 @@ +package com.casic.smarttube.model; + +public class LastDataModel { + + private int code; + private DataModel data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataModel { + private String deviceType; + private String responsibleDept; + private String strength; + private String wellCode; + private String groupId; + private String deptid; + private String staff; + private String deviceName; + private String uptime; + private String lngGaode; + private String latGaode; + private String devcode; + private String wellName; + private String tel; + private String data_tube_id; + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getResponsibleDept() { + return responsibleDept; + } + + public void setResponsibleDept(String responsibleDept) { + this.responsibleDept = responsibleDept; + } + + public String getStrength() { + return strength; + } + + public void setStrength(String strength) { + this.strength = strength; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getStaff() { + return staff; + } + + public void setStaff(String staff) { + this.staff = staff; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getWellName() { + return wellName; + } + + public void setWellName(String wellName) { + this.wellName = wellName; + } + + public String getTel() { + return tel; + } + + public void setTel(String tel) { + this.tel = tel; + } + + public String getData_tube_id() { + return data_tube_id; + } + + public void setData_tube_id(String data_tube_id) { + this.data_tube_id = data_tube_id; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java index 7e8a367..75f18f7 100644 --- a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java +++ b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java @@ -5,7 +5,7 @@ public class MapDeviceModel { private int code; - private List data; + private List data; private String message; private String success; @@ -17,11 +17,11 @@ this.code = code; } - public List getData() { + public List getData() { return data; } - public void setData(List data) { + public void setData(List data) { this.data = data; } @@ -41,11 +41,10 @@ this.success = success; } - public static class DataBean { + public static class DataModel { private String area; - private int deep; + private String deep; private String responsibleDept; - private String wellCode; private String groupId; private String deptid; private String staff; @@ -53,9 +52,10 @@ private String wellType; private String valid; private String bfzt; + private String modelName; + private String devcode; private String lngGaode; private String latGaode; - private String wellName; private String tel; private String position; @@ -67,11 +67,11 @@ this.area = area; } - public int getDeep() { + public String getDeep() { return deep; } - public void setDeep(int deep) { + public void setDeep(String deep) { this.deep = deep; } @@ -83,14 +83,6 @@ this.responsibleDept = responsibleDept; } - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - public String getGroupId() { return groupId; } @@ -147,6 +139,22 @@ this.bfzt = bfzt; } + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + public String getLngGaode() { return lngGaode; } @@ -163,14 +171,6 @@ this.latGaode = latGaode; } - public String getWellName() { - return wellName; - } - - public void setWellName(String wellName) { - this.wellName = wellName; - } - public String getTel() { return tel; } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..e22936c 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -26,7 +26,7 @@ * */ const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 - const val RADIUS_SIZE = 50 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 30 //相距多少米才聚合,单位:米 /** * ============================================================================================= diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index c1205c8..f6c50be 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -19,7 +19,7 @@ * @param secretKey 加密后的密码 */ @FormUrlEncoded - @POST("/user/appLogin") + @POST("/user/login") suspend fun obtainLoginResult( @Field("sid") sid: String, @Field("username") account: String, @@ -187,4 +187,15 @@ @Query("offset") offset: Int, @Query("limit") limit: Int ): String + + /** + * 获取设备最新数据 + * + * @param devcode 管盯设备编号 + */ + @GET("/tube/latestdata/{devcode}") + suspend fun obtainTubeLastData( + @Header("token") token: String, + @Path("devcode") devcode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index a18a820..bb79624 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -174,4 +174,11 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 获取设备最新数据 + */ + suspend fun obtainTubeLastData(devcode: String): String { + return api.obtainTubeLastData(AuthenticationHelper.token!!, devcode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt index d9c9b86..15ded77 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt @@ -3,7 +3,6 @@ import android.graphics.Point import android.os.Bundle import android.os.CountDownTimer -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -29,6 +28,7 @@ import com.casic.smarttube.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior import com.pengxh.kt.lite.extensions.* +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.fragment_home.view.* @@ -61,7 +61,7 @@ /** * 所有设备列表信息集合 * */ - private var deviceModels: MutableList = ArrayList() + private var deviceModels: MutableList = ArrayList() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -133,14 +133,10 @@ allMarkerOptions.add( MarkerOptions() .position(LatLng(latitude, longitude)) - .title(device.wellName) - .snippet(device.wellCode) + .title(device.devcode) + .snippet(device.modelName) ) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -173,7 +169,6 @@ val uiSettings = aMap.uiSettings uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isZoomControlsEnabled = false//不显示+/- uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 uiSettings.isRotateGesturesEnabled = false//不允许地图旋转 @@ -202,6 +197,12 @@ groupViewModel.obtainDeviceListByGroup(dataBeans[position].groupId) } }) + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(requireActivity(), "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) groupViewModel.groupDeviceModel.observe(this, { if (it.code == 200) { val latitudeList: MutableList = ArrayList() @@ -217,11 +218,7 @@ //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -322,7 +319,7 @@ } override fun onMarkerClick(marker: Marker?): Boolean { - //显示闸井信息 + //显示设备基本信息 marker?.showInfoWindow() return true } @@ -333,11 +330,10 @@ } val v = infoWindow!! //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceModelView = v.findViewById(R.id.deviceModelView) + val deviceValueView = v.findViewById(R.id.deviceValueView) + val updateTimeView = v.findViewById(R.id.updateTimeView) val locationView = v.findViewById(R.id.locationView) //绑定数据 @@ -346,11 +342,19 @@ if (clickedLatLng.latitude == device.latGaode!!.toDouble() && clickedLatLng.longitude == device.lngGaode!!.toDouble() ) { - wellCodeView.text = String.format("闸井编号: ${device.wellCode}") - wellNameView.text = String.format("闸井名称: ${device.wellName}") - wellTypeView.text = String.format("闸井类型: ${device.wellType}") - wellStateView.text = String.format("布/撤防状态: ${device.bfzt}") - deepView.text = String.format("闸井深度: ${device.deep}m") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceModelView.text = String.format("设备模型: ${device.modelName}") + //获取设备最新浓度信息 + deviceViewModel.obtainTubeLastData(device.devcode) + deviceViewModel.lastDataModel.observe(requireActivity(), { + if (it.code == 200) { + deviceValueView.text = String.format("最新浓度: ${it.data.strength}") + updateTimeView.text = String.format("更新时间: ${it.data.uptime}") + }else{ + deviceValueView.text = String.format("最新浓度: 未知") + updateTimeView.text = String.format("更新时间: 未知") + } + }) locationView.text = String.format("详细位置: ${device.position}") return infoWindow } diff --git a/app/src/main/java/com/casic/smarttube/model/LastDataModel.java b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java new file mode 100644 index 0000000..5d09ef0 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java @@ -0,0 +1,179 @@ +package com.casic.smarttube.model; + +public class LastDataModel { + + private int code; + private DataModel data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataModel { + private String deviceType; + private String responsibleDept; + private String strength; + private String wellCode; + private String groupId; + private String deptid; + private String staff; + private String deviceName; + private String uptime; + private String lngGaode; + private String latGaode; + private String devcode; + private String wellName; + private String tel; + private String data_tube_id; + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getResponsibleDept() { + return responsibleDept; + } + + public void setResponsibleDept(String responsibleDept) { + this.responsibleDept = responsibleDept; + } + + public String getStrength() { + return strength; + } + + public void setStrength(String strength) { + this.strength = strength; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getStaff() { + return staff; + } + + public void setStaff(String staff) { + this.staff = staff; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getWellName() { + return wellName; + } + + public void setWellName(String wellName) { + this.wellName = wellName; + } + + public String getTel() { + return tel; + } + + public void setTel(String tel) { + this.tel = tel; + } + + public String getData_tube_id() { + return data_tube_id; + } + + public void setData_tube_id(String data_tube_id) { + this.data_tube_id = data_tube_id; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java index 7e8a367..75f18f7 100644 --- a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java +++ b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java @@ -5,7 +5,7 @@ public class MapDeviceModel { private int code; - private List data; + private List data; private String message; private String success; @@ -17,11 +17,11 @@ this.code = code; } - public List getData() { + public List getData() { return data; } - public void setData(List data) { + public void setData(List data) { this.data = data; } @@ -41,11 +41,10 @@ this.success = success; } - public static class DataBean { + public static class DataModel { private String area; - private int deep; + private String deep; private String responsibleDept; - private String wellCode; private String groupId; private String deptid; private String staff; @@ -53,9 +52,10 @@ private String wellType; private String valid; private String bfzt; + private String modelName; + private String devcode; private String lngGaode; private String latGaode; - private String wellName; private String tel; private String position; @@ -67,11 +67,11 @@ this.area = area; } - public int getDeep() { + public String getDeep() { return deep; } - public void setDeep(int deep) { + public void setDeep(String deep) { this.deep = deep; } @@ -83,14 +83,6 @@ this.responsibleDept = responsibleDept; } - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - public String getGroupId() { return groupId; } @@ -147,6 +139,22 @@ this.bfzt = bfzt; } + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + public String getLngGaode() { return lngGaode; } @@ -163,14 +171,6 @@ this.latGaode = latGaode; } - public String getWellName() { - return wellName; - } - - public void setWellName(String wellName) { - this.wellName = wellName; - } - public String getTel() { return tel; } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..e22936c 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -26,7 +26,7 @@ * */ const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 - const val RADIUS_SIZE = 50 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 30 //相距多少米才聚合,单位:米 /** * ============================================================================================= diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index c1205c8..f6c50be 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -19,7 +19,7 @@ * @param secretKey 加密后的密码 */ @FormUrlEncoded - @POST("/user/appLogin") + @POST("/user/login") suspend fun obtainLoginResult( @Field("sid") sid: String, @Field("username") account: String, @@ -187,4 +187,15 @@ @Query("offset") offset: Int, @Query("limit") limit: Int ): String + + /** + * 获取设备最新数据 + * + * @param devcode 管盯设备编号 + */ + @GET("/tube/latestdata/{devcode}") + suspend fun obtainTubeLastData( + @Header("token") token: String, + @Path("devcode") devcode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index a18a820..bb79624 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -174,4 +174,11 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 获取设备最新数据 + */ + suspend fun obtainTubeLastData(devcode: String): String { + return api.obtainTubeLastData(AuthenticationHelper.token!!, devcode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 84e8885..c87c743 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -6,6 +6,7 @@ import com.casic.smarttube.extensions.toErrorMessage import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel +import com.casic.smarttube.model.LastDataModel import com.casic.smarttube.model.MapDeviceModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -21,6 +22,7 @@ val mapDeviceModel = MutableLiveData() val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() + val lastDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ val response = RetrofitServiceManager.obtainMapDeviceList() @@ -66,4 +68,23 @@ }, { it.printStackTrace() }) + + fun obtainTubeLastData(devcode: String) = launch({ + val response = RetrofitServiceManager.obtainTubeLastData(devcode) + when (response.separateResponseCode()) { + 200 -> { + lastDataModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + 500 -> { + lastDataModel.value = LastDataModel() + } + else -> { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt index d9c9b86..15ded77 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt @@ -3,7 +3,6 @@ import android.graphics.Point import android.os.Bundle import android.os.CountDownTimer -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -29,6 +28,7 @@ import com.casic.smarttube.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior import com.pengxh.kt.lite.extensions.* +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.fragment_home.view.* @@ -61,7 +61,7 @@ /** * 所有设备列表信息集合 * */ - private var deviceModels: MutableList = ArrayList() + private var deviceModels: MutableList = ArrayList() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -133,14 +133,10 @@ allMarkerOptions.add( MarkerOptions() .position(LatLng(latitude, longitude)) - .title(device.wellName) - .snippet(device.wellCode) + .title(device.devcode) + .snippet(device.modelName) ) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -173,7 +169,6 @@ val uiSettings = aMap.uiSettings uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isZoomControlsEnabled = false//不显示+/- uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 uiSettings.isRotateGesturesEnabled = false//不允许地图旋转 @@ -202,6 +197,12 @@ groupViewModel.obtainDeviceListByGroup(dataBeans[position].groupId) } }) + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(requireActivity(), "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) groupViewModel.groupDeviceModel.observe(this, { if (it.code == 200) { val latitudeList: MutableList = ArrayList() @@ -217,11 +218,7 @@ //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -322,7 +319,7 @@ } override fun onMarkerClick(marker: Marker?): Boolean { - //显示闸井信息 + //显示设备基本信息 marker?.showInfoWindow() return true } @@ -333,11 +330,10 @@ } val v = infoWindow!! //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceModelView = v.findViewById(R.id.deviceModelView) + val deviceValueView = v.findViewById(R.id.deviceValueView) + val updateTimeView = v.findViewById(R.id.updateTimeView) val locationView = v.findViewById(R.id.locationView) //绑定数据 @@ -346,11 +342,19 @@ if (clickedLatLng.latitude == device.latGaode!!.toDouble() && clickedLatLng.longitude == device.lngGaode!!.toDouble() ) { - wellCodeView.text = String.format("闸井编号: ${device.wellCode}") - wellNameView.text = String.format("闸井名称: ${device.wellName}") - wellTypeView.text = String.format("闸井类型: ${device.wellType}") - wellStateView.text = String.format("布/撤防状态: ${device.bfzt}") - deepView.text = String.format("闸井深度: ${device.deep}m") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceModelView.text = String.format("设备模型: ${device.modelName}") + //获取设备最新浓度信息 + deviceViewModel.obtainTubeLastData(device.devcode) + deviceViewModel.lastDataModel.observe(requireActivity(), { + if (it.code == 200) { + deviceValueView.text = String.format("最新浓度: ${it.data.strength}") + updateTimeView.text = String.format("更新时间: ${it.data.uptime}") + }else{ + deviceValueView.text = String.format("最新浓度: 未知") + updateTimeView.text = String.format("更新时间: 未知") + } + }) locationView.text = String.format("详细位置: ${device.position}") return infoWindow } diff --git a/app/src/main/java/com/casic/smarttube/model/LastDataModel.java b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java new file mode 100644 index 0000000..5d09ef0 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java @@ -0,0 +1,179 @@ +package com.casic.smarttube.model; + +public class LastDataModel { + + private int code; + private DataModel data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataModel { + private String deviceType; + private String responsibleDept; + private String strength; + private String wellCode; + private String groupId; + private String deptid; + private String staff; + private String deviceName; + private String uptime; + private String lngGaode; + private String latGaode; + private String devcode; + private String wellName; + private String tel; + private String data_tube_id; + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getResponsibleDept() { + return responsibleDept; + } + + public void setResponsibleDept(String responsibleDept) { + this.responsibleDept = responsibleDept; + } + + public String getStrength() { + return strength; + } + + public void setStrength(String strength) { + this.strength = strength; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getStaff() { + return staff; + } + + public void setStaff(String staff) { + this.staff = staff; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getWellName() { + return wellName; + } + + public void setWellName(String wellName) { + this.wellName = wellName; + } + + public String getTel() { + return tel; + } + + public void setTel(String tel) { + this.tel = tel; + } + + public String getData_tube_id() { + return data_tube_id; + } + + public void setData_tube_id(String data_tube_id) { + this.data_tube_id = data_tube_id; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java index 7e8a367..75f18f7 100644 --- a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java +++ b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java @@ -5,7 +5,7 @@ public class MapDeviceModel { private int code; - private List data; + private List data; private String message; private String success; @@ -17,11 +17,11 @@ this.code = code; } - public List getData() { + public List getData() { return data; } - public void setData(List data) { + public void setData(List data) { this.data = data; } @@ -41,11 +41,10 @@ this.success = success; } - public static class DataBean { + public static class DataModel { private String area; - private int deep; + private String deep; private String responsibleDept; - private String wellCode; private String groupId; private String deptid; private String staff; @@ -53,9 +52,10 @@ private String wellType; private String valid; private String bfzt; + private String modelName; + private String devcode; private String lngGaode; private String latGaode; - private String wellName; private String tel; private String position; @@ -67,11 +67,11 @@ this.area = area; } - public int getDeep() { + public String getDeep() { return deep; } - public void setDeep(int deep) { + public void setDeep(String deep) { this.deep = deep; } @@ -83,14 +83,6 @@ this.responsibleDept = responsibleDept; } - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - public String getGroupId() { return groupId; } @@ -147,6 +139,22 @@ this.bfzt = bfzt; } + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + public String getLngGaode() { return lngGaode; } @@ -163,14 +171,6 @@ this.latGaode = latGaode; } - public String getWellName() { - return wellName; - } - - public void setWellName(String wellName) { - this.wellName = wellName; - } - public String getTel() { return tel; } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..e22936c 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -26,7 +26,7 @@ * */ const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 - const val RADIUS_SIZE = 50 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 30 //相距多少米才聚合,单位:米 /** * ============================================================================================= diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index c1205c8..f6c50be 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -19,7 +19,7 @@ * @param secretKey 加密后的密码 */ @FormUrlEncoded - @POST("/user/appLogin") + @POST("/user/login") suspend fun obtainLoginResult( @Field("sid") sid: String, @Field("username") account: String, @@ -187,4 +187,15 @@ @Query("offset") offset: Int, @Query("limit") limit: Int ): String + + /** + * 获取设备最新数据 + * + * @param devcode 管盯设备编号 + */ + @GET("/tube/latestdata/{devcode}") + suspend fun obtainTubeLastData( + @Header("token") token: String, + @Path("devcode") devcode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index a18a820..bb79624 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -174,4 +174,11 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 获取设备最新数据 + */ + suspend fun obtainTubeLastData(devcode: String): String { + return api.obtainTubeLastData(AuthenticationHelper.token!!, devcode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 84e8885..c87c743 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -6,6 +6,7 @@ import com.casic.smarttube.extensions.toErrorMessage import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel +import com.casic.smarttube.model.LastDataModel import com.casic.smarttube.model.MapDeviceModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -21,6 +22,7 @@ val mapDeviceModel = MutableLiveData() val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() + val lastDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ val response = RetrofitServiceManager.obtainMapDeviceList() @@ -66,4 +68,23 @@ }, { it.printStackTrace() }) + + fun obtainTubeLastData(devcode: String) = launch({ + val response = RetrofitServiceManager.obtainTubeLastData(devcode) + when (response.separateResponseCode()) { + 200 -> { + lastDataModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + 500 -> { + lastDataModel.value = LastDataModel() + } + else -> { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index a0c6996..c99b861 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -37,13 +37,16 @@ }) fun obtainDeviceListByGroup(wellGroupId: String) = launch({ + loadState.value = LoadState.Loading val response = RetrofitServiceManager.obtainDeviceListByGroup(wellGroupId) val responseCode = response.separateResponseCode() if (responseCode == 200) { + loadState.value = LoadState.Success groupDeviceModel.value = gson.fromJson( response, object : TypeToken() {}.type ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt index d9c9b86..15ded77 100644 --- a/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt +++ b/app/src/main/java/com/casic/smarttube/fragment/HomePageFragment.kt @@ -3,7 +3,6 @@ import android.graphics.Point import android.os.Bundle import android.os.CountDownTimer -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -29,6 +28,7 @@ import com.casic.smarttube.widgets.GaoDeClusterMarkerView import com.google.android.material.bottomsheet.BottomSheetBehavior import com.pengxh.kt.lite.extensions.* +import com.pengxh.kt.lite.vm.LoadState import com.pengxh.kt.lite.widget.EasyPopupWindow import com.pengxh.kt.lite.widget.dialog.AlertControlDialog import kotlinx.android.synthetic.main.fragment_home.view.* @@ -61,7 +61,7 @@ /** * 所有设备列表信息集合 * */ - private var deviceModels: MutableList = ArrayList() + private var deviceModels: MutableList = ArrayList() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -133,14 +133,10 @@ allMarkerOptions.add( MarkerOptions() .position(LatLng(latitude, longitude)) - .title(device.wellName) - .snippet(device.wellCode) + .title(device.devcode) + .snippet(device.modelName) ) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -173,7 +169,6 @@ val uiSettings = aMap.uiSettings uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isZoomControlsEnabled = false//不显示+/- uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 uiSettings.isRotateGesturesEnabled = false//不允许地图旋转 @@ -202,6 +197,12 @@ groupViewModel.obtainDeviceListByGroup(dataBeans[position].groupId) } }) + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(requireActivity(), "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) groupViewModel.groupDeviceModel.observe(this, { if (it.code == 200) { val latitudeList: MutableList = ArrayList() @@ -217,11 +218,7 @@ //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -322,7 +319,7 @@ } override fun onMarkerClick(marker: Marker?): Boolean { - //显示闸井信息 + //显示设备基本信息 marker?.showInfoWindow() return true } @@ -333,11 +330,10 @@ } val v = infoWindow!! //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceModelView = v.findViewById(R.id.deviceModelView) + val deviceValueView = v.findViewById(R.id.deviceValueView) + val updateTimeView = v.findViewById(R.id.updateTimeView) val locationView = v.findViewById(R.id.locationView) //绑定数据 @@ -346,11 +342,19 @@ if (clickedLatLng.latitude == device.latGaode!!.toDouble() && clickedLatLng.longitude == device.lngGaode!!.toDouble() ) { - wellCodeView.text = String.format("闸井编号: ${device.wellCode}") - wellNameView.text = String.format("闸井名称: ${device.wellName}") - wellTypeView.text = String.format("闸井类型: ${device.wellType}") - wellStateView.text = String.format("布/撤防状态: ${device.bfzt}") - deepView.text = String.format("闸井深度: ${device.deep}m") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceModelView.text = String.format("设备模型: ${device.modelName}") + //获取设备最新浓度信息 + deviceViewModel.obtainTubeLastData(device.devcode) + deviceViewModel.lastDataModel.observe(requireActivity(), { + if (it.code == 200) { + deviceValueView.text = String.format("最新浓度: ${it.data.strength}") + updateTimeView.text = String.format("更新时间: ${it.data.uptime}") + }else{ + deviceValueView.text = String.format("最新浓度: 未知") + updateTimeView.text = String.format("更新时间: 未知") + } + }) locationView.text = String.format("详细位置: ${device.position}") return infoWindow } diff --git a/app/src/main/java/com/casic/smarttube/model/LastDataModel.java b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java new file mode 100644 index 0000000..5d09ef0 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java @@ -0,0 +1,179 @@ +package com.casic.smarttube.model; + +public class LastDataModel { + + private int code; + private DataModel data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataModel { + private String deviceType; + private String responsibleDept; + private String strength; + private String wellCode; + private String groupId; + private String deptid; + private String staff; + private String deviceName; + private String uptime; + private String lngGaode; + private String latGaode; + private String devcode; + private String wellName; + private String tel; + private String data_tube_id; + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getResponsibleDept() { + return responsibleDept; + } + + public void setResponsibleDept(String responsibleDept) { + this.responsibleDept = responsibleDept; + } + + public String getStrength() { + return strength; + } + + public void setStrength(String strength) { + this.strength = strength; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getStaff() { + return staff; + } + + public void setStaff(String staff) { + this.staff = staff; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getWellName() { + return wellName; + } + + public void setWellName(String wellName) { + this.wellName = wellName; + } + + public String getTel() { + return tel; + } + + public void setTel(String tel) { + this.tel = tel; + } + + public String getData_tube_id() { + return data_tube_id; + } + + public void setData_tube_id(String data_tube_id) { + this.data_tube_id = data_tube_id; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java index 7e8a367..75f18f7 100644 --- a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java +++ b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java @@ -5,7 +5,7 @@ public class MapDeviceModel { private int code; - private List data; + private List data; private String message; private String success; @@ -17,11 +17,11 @@ this.code = code; } - public List getData() { + public List getData() { return data; } - public void setData(List data) { + public void setData(List data) { this.data = data; } @@ -41,11 +41,10 @@ this.success = success; } - public static class DataBean { + public static class DataModel { private String area; - private int deep; + private String deep; private String responsibleDept; - private String wellCode; private String groupId; private String deptid; private String staff; @@ -53,9 +52,10 @@ private String wellType; private String valid; private String bfzt; + private String modelName; + private String devcode; private String lngGaode; private String latGaode; - private String wellName; private String tel; private String position; @@ -67,11 +67,11 @@ this.area = area; } - public int getDeep() { + public String getDeep() { return deep; } - public void setDeep(int deep) { + public void setDeep(String deep) { this.deep = deep; } @@ -83,14 +83,6 @@ this.responsibleDept = responsibleDept; } - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - public String getGroupId() { return groupId; } @@ -147,6 +139,22 @@ this.bfzt = bfzt; } + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + public String getLngGaode() { return lngGaode; } @@ -163,14 +171,6 @@ this.latGaode = latGaode; } - public String getWellName() { - return wellName; - } - - public void setWellName(String wellName) { - this.wellName = wellName; - } - public String getTel() { return tel; } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..e22936c 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -26,7 +26,7 @@ * */ const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 - const val RADIUS_SIZE = 50 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 30 //相距多少米才聚合,单位:米 /** * ============================================================================================= diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index c1205c8..f6c50be 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -19,7 +19,7 @@ * @param secretKey 加密后的密码 */ @FormUrlEncoded - @POST("/user/appLogin") + @POST("/user/login") suspend fun obtainLoginResult( @Field("sid") sid: String, @Field("username") account: String, @@ -187,4 +187,15 @@ @Query("offset") offset: Int, @Query("limit") limit: Int ): String + + /** + * 获取设备最新数据 + * + * @param devcode 管盯设备编号 + */ + @GET("/tube/latestdata/{devcode}") + suspend fun obtainTubeLastData( + @Header("token") token: String, + @Path("devcode") devcode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index a18a820..bb79624 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -174,4 +174,11 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 获取设备最新数据 + */ + suspend fun obtainTubeLastData(devcode: String): String { + return api.obtainTubeLastData(AuthenticationHelper.token!!, devcode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 84e8885..c87c743 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -6,6 +6,7 @@ import com.casic.smarttube.extensions.toErrorMessage import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel +import com.casic.smarttube.model.LastDataModel import com.casic.smarttube.model.MapDeviceModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -21,6 +22,7 @@ val mapDeviceModel = MutableLiveData() val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() + val lastDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ val response = RetrofitServiceManager.obtainMapDeviceList() @@ -66,4 +68,23 @@ }, { it.printStackTrace() }) + + fun obtainTubeLastData(devcode: String) = launch({ + val response = RetrofitServiceManager.obtainTubeLastData(devcode) + when (response.separateResponseCode()) { + 200 -> { + lastDataModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + 500 -> { + lastDataModel.value = LastDataModel() + } + else -> { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index a0c6996..c99b861 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -37,13 +37,16 @@ }) fun obtainDeviceListByGroup(wellGroupId: String) = launch({ + loadState.value = LoadState.Loading val response = RetrofitServiceManager.obtainDeviceListByGroup(wellGroupId) val responseCode = response.separateResponseCode() if (responseCode == 200) { + loadState.value = LoadState.Success groupDeviceModel.value = gson.fromJson( response, object : TypeToken() {}.type ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/res/layout/item_group_rv.xml b/app/src/main/res/layout/item_group_rv.xml index 27ab86f..a302d67 100644 --- a/app/src/main/res/layout/item_group_rv.xml +++ b/app/src/main/res/layout/item_group_rv.xml @@ -31,7 +31,7 @@ android:id="@+id/groupLocationView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/app_name" /> + android:text="@string/unknown" /> = ArrayList() + private var deviceModels: MutableList = ArrayList() override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? @@ -133,14 +133,10 @@ allMarkerOptions.add( MarkerOptions() .position(LatLng(latitude, longitude)) - .title(device.wellName) - .snippet(device.wellCode) + .title(device.devcode) + .snippet(device.modelName) ) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -173,7 +169,6 @@ val uiSettings = aMap.uiSettings uiSettings.isCompassEnabled = true uiSettings.zoomPosition = AMapOptions.ZOOM_POSITION_RIGHT_CENTER - uiSettings.isZoomControlsEnabled = false//不显示+/- uiSettings.isTiltGesturesEnabled = false//不许地图随手势倾斜角度 uiSettings.isRotateGesturesEnabled = false//不允许地图旋转 @@ -202,6 +197,12 @@ groupViewModel.obtainDeviceListByGroup(dataBeans[position].groupId) } }) + groupViewModel.loadState.observe(this, { + when (it) { + LoadState.Loading -> DialogHelper.showLoadingDialog(requireActivity(), "数据加载中...") + else -> DialogHelper.dismissLoadingDialog() + } + }) groupViewModel.groupDeviceModel.observe(this, { if (it.code == 200) { val latitudeList: MutableList = ArrayList() @@ -217,11 +218,7 @@ //分别缓存经、纬度 latitudeList.add(latitude) longitudeList.add(longitude) - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度不在国内,异常经纬度 ===> [${lng},${lat}]") } - } else { - Log.d(kTag, "${device.wellCode}闸井经纬度异常,异常经纬度 ===> [${lng},${lat}]") } } //计算所有点的中心点位置 @@ -322,7 +319,7 @@ } override fun onMarkerClick(marker: Marker?): Boolean { - //显示闸井信息 + //显示设备基本信息 marker?.showInfoWindow() return true } @@ -333,11 +330,10 @@ } val v = infoWindow!! //反射得到popup里面的控件对象 - val wellNameView = v.findViewById(R.id.wellNameView) - val wellCodeView = v.findViewById(R.id.wellCodeView) - val wellTypeView = v.findViewById(R.id.wellTypeView) - val wellStateView = v.findViewById(R.id.wellStateView) - val deepView = v.findViewById(R.id.deepView) + val deviceCodeView = v.findViewById(R.id.deviceCodeView) + val deviceModelView = v.findViewById(R.id.deviceModelView) + val deviceValueView = v.findViewById(R.id.deviceValueView) + val updateTimeView = v.findViewById(R.id.updateTimeView) val locationView = v.findViewById(R.id.locationView) //绑定数据 @@ -346,11 +342,19 @@ if (clickedLatLng.latitude == device.latGaode!!.toDouble() && clickedLatLng.longitude == device.lngGaode!!.toDouble() ) { - wellCodeView.text = String.format("闸井编号: ${device.wellCode}") - wellNameView.text = String.format("闸井名称: ${device.wellName}") - wellTypeView.text = String.format("闸井类型: ${device.wellType}") - wellStateView.text = String.format("布/撤防状态: ${device.bfzt}") - deepView.text = String.format("闸井深度: ${device.deep}m") + deviceCodeView.text = String.format("设备编号: ${device.devcode}") + deviceModelView.text = String.format("设备模型: ${device.modelName}") + //获取设备最新浓度信息 + deviceViewModel.obtainTubeLastData(device.devcode) + deviceViewModel.lastDataModel.observe(requireActivity(), { + if (it.code == 200) { + deviceValueView.text = String.format("最新浓度: ${it.data.strength}") + updateTimeView.text = String.format("更新时间: ${it.data.uptime}") + }else{ + deviceValueView.text = String.format("最新浓度: 未知") + updateTimeView.text = String.format("更新时间: 未知") + } + }) locationView.text = String.format("详细位置: ${device.position}") return infoWindow } diff --git a/app/src/main/java/com/casic/smarttube/model/LastDataModel.java b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java new file mode 100644 index 0000000..5d09ef0 --- /dev/null +++ b/app/src/main/java/com/casic/smarttube/model/LastDataModel.java @@ -0,0 +1,179 @@ +package com.casic.smarttube.model; + +public class LastDataModel { + + private int code; + private DataModel data; + private String message; + private String success; + + public int getCode() { + return code; + } + + public void setCode(int code) { + this.code = code; + } + + public DataModel getData() { + return data; + } + + public void setData(DataModel data) { + this.data = data; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public String getSuccess() { + return success; + } + + public void setSuccess(String success) { + this.success = success; + } + + public static class DataModel { + private String deviceType; + private String responsibleDept; + private String strength; + private String wellCode; + private String groupId; + private String deptid; + private String staff; + private String deviceName; + private String uptime; + private String lngGaode; + private String latGaode; + private String devcode; + private String wellName; + private String tel; + private String data_tube_id; + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public String getResponsibleDept() { + return responsibleDept; + } + + public void setResponsibleDept(String responsibleDept) { + this.responsibleDept = responsibleDept; + } + + public String getStrength() { + return strength; + } + + public void setStrength(String strength) { + this.strength = strength; + } + + public String getWellCode() { + return wellCode; + } + + public void setWellCode(String wellCode) { + this.wellCode = wellCode; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getDeptid() { + return deptid; + } + + public void setDeptid(String deptid) { + this.deptid = deptid; + } + + public String getStaff() { + return staff; + } + + public void setStaff(String staff) { + this.staff = staff; + } + + public String getDeviceName() { + return deviceName; + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public String getUptime() { + return uptime; + } + + public void setUptime(String uptime) { + this.uptime = uptime; + } + + public String getLngGaode() { + return lngGaode; + } + + public void setLngGaode(String lngGaode) { + this.lngGaode = lngGaode; + } + + public String getLatGaode() { + return latGaode; + } + + public void setLatGaode(String latGaode) { + this.latGaode = latGaode; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + + public String getWellName() { + return wellName; + } + + public void setWellName(String wellName) { + this.wellName = wellName; + } + + public String getTel() { + return tel; + } + + public void setTel(String tel) { + this.tel = tel; + } + + public String getData_tube_id() { + return data_tube_id; + } + + public void setData_tube_id(String data_tube_id) { + this.data_tube_id = data_tube_id; + } + } +} diff --git a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java index 7e8a367..75f18f7 100644 --- a/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java +++ b/app/src/main/java/com/casic/smarttube/model/MapDeviceModel.java @@ -5,7 +5,7 @@ public class MapDeviceModel { private int code; - private List data; + private List data; private String message; private String success; @@ -17,11 +17,11 @@ this.code = code; } - public List getData() { + public List getData() { return data; } - public void setData(List data) { + public void setData(List data) { this.data = data; } @@ -41,11 +41,10 @@ this.success = success; } - public static class DataBean { + public static class DataModel { private String area; - private int deep; + private String deep; private String responsibleDept; - private String wellCode; private String groupId; private String deptid; private String staff; @@ -53,9 +52,10 @@ private String wellType; private String valid; private String bfzt; + private String modelName; + private String devcode; private String lngGaode; private String latGaode; - private String wellName; private String tel; private String position; @@ -67,11 +67,11 @@ this.area = area; } - public int getDeep() { + public String getDeep() { return deep; } - public void setDeep(int deep) { + public void setDeep(String deep) { this.deep = deep; } @@ -83,14 +83,6 @@ this.responsibleDept = responsibleDept; } - public String getWellCode() { - return wellCode; - } - - public void setWellCode(String wellCode) { - this.wellCode = wellCode; - } - public String getGroupId() { return groupId; } @@ -147,6 +139,22 @@ this.bfzt = bfzt; } + public String getModelName() { + return modelName; + } + + public void setModelName(String modelName) { + this.modelName = modelName; + } + + public String getDevcode() { + return devcode; + } + + public void setDevcode(String devcode) { + this.devcode = devcode; + } + public String getLngGaode() { return lngGaode; } @@ -163,14 +171,6 @@ this.latGaode = latGaode; } - public String getWellName() { - return wellName; - } - - public void setWellName(String wellName) { - this.wellName = wellName; - } - public String getTel() { return tel; } diff --git a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt index 4908afb..e22936c 100644 --- a/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt +++ b/app/src/main/java/com/casic/smarttube/utils/LocaleConstant.kt @@ -26,7 +26,7 @@ * */ const val PERMISSIONS_CODE = 999 const val PAGE_LIMIT = 20 - const val RADIUS_SIZE = 50 //相距多少米才聚合,单位:米 + const val RADIUS_SIZE = 30 //相距多少米才聚合,单位:米 /** * ============================================================================================= diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt index c1205c8..f6c50be 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitService.kt @@ -19,7 +19,7 @@ * @param secretKey 加密后的密码 */ @FormUrlEncoded - @POST("/user/appLogin") + @POST("/user/login") suspend fun obtainLoginResult( @Field("sid") sid: String, @Field("username") account: String, @@ -187,4 +187,15 @@ @Query("offset") offset: Int, @Query("limit") limit: Int ): String + + /** + * 获取设备最新数据 + * + * @param devcode 管盯设备编号 + */ + @GET("/tube/latestdata/{devcode}") + suspend fun obtainTubeLastData( + @Header("token") token: String, + @Path("devcode") devcode: String + ): String } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt index a18a820..bb79624 100644 --- a/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/smarttube/utils/retrofit/RetrofitServiceManager.kt @@ -174,4 +174,11 @@ val imagePart = MultipartBody.Part.createFormData("file", image.name, requestBody) return api.uploadImage(AuthenticationHelper.token!!, imagePart) } + + /** + * 获取设备最新数据 + */ + suspend fun obtainTubeLastData(devcode: String): String { + return api.obtainTubeLastData(AuthenticationHelper.token!!, devcode) + } } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt index 84e8885..c87c743 100644 --- a/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/DeviceViewModel.kt @@ -6,6 +6,7 @@ import com.casic.smarttube.extensions.toErrorMessage import com.casic.smarttube.model.DeviceDetailModel import com.casic.smarttube.model.DeviceHistoryDataModel +import com.casic.smarttube.model.LastDataModel import com.casic.smarttube.model.MapDeviceModel import com.casic.smarttube.utils.retrofit.RetrofitServiceManager import com.google.gson.Gson @@ -21,6 +22,7 @@ val mapDeviceModel = MutableLiveData() val deviceDetailModel = MutableLiveData() val historyDataModel = MutableLiveData() + val lastDataModel = MutableLiveData() fun obtainMapDeviceList() = launch({ val response = RetrofitServiceManager.obtainMapDeviceList() @@ -66,4 +68,23 @@ }, { it.printStackTrace() }) + + fun obtainTubeLastData(devcode: String) = launch({ + val response = RetrofitServiceManager.obtainTubeLastData(devcode) + when (response.separateResponseCode()) { + 200 -> { + lastDataModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } + 500 -> { + lastDataModel.value = LastDataModel() + } + else -> { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } + } + }, { + it.printStackTrace() + }) } \ No newline at end of file diff --git a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt index a0c6996..c99b861 100644 --- a/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt +++ b/app/src/main/java/com/casic/smarttube/vm/ProjectGroupViewModel.kt @@ -37,13 +37,16 @@ }) fun obtainDeviceListByGroup(wellGroupId: String) = launch({ + loadState.value = LoadState.Loading val response = RetrofitServiceManager.obtainDeviceListByGroup(wellGroupId) val responseCode = response.separateResponseCode() if (responseCode == 200) { + loadState.value = LoadState.Success groupDeviceModel.value = gson.fromJson( response, object : TypeToken() {}.type ) } else { + loadState.value = LoadState.Fail response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { diff --git a/app/src/main/res/layout/item_group_rv.xml b/app/src/main/res/layout/item_group_rv.xml index 27ab86f..a302d67 100644 --- a/app/src/main/res/layout/item_group_rv.xml +++ b/app/src/main/res/layout/item_group_rv.xml @@ -31,7 +31,7 @@ android:id="@+id/groupLocationView" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/app_name" /> + android:text="@string/unknown" /> + android:text="最新浓:数据加载中..." /> - - + android:text="设备模型:数据加载中..." />