增加室内整理工具更新接口
This commit is contained in:
parent
a970ca1992
commit
d3fc05adad
@ -0,0 +1,11 @@
|
|||||||
|
package com.navinfo.omqs.bean
|
||||||
|
|
||||||
|
data class IndoorConnectionInfoBean(
|
||||||
|
var username: String = "",
|
||||||
|
var uname: String = "",
|
||||||
|
var userid: String = "",
|
||||||
|
var token: String = "",
|
||||||
|
var baseurl: String = "",
|
||||||
|
var plate: String = "",
|
||||||
|
var platform: String = "Android",
|
||||||
|
)
|
@ -2,6 +2,7 @@ package com.navinfo.omqs.http
|
|||||||
|
|
||||||
import com.navinfo.omqs.bean.OfflineMapCityBean
|
import com.navinfo.omqs.bean.OfflineMapCityBean
|
||||||
import com.navinfo.collect.library.data.entity.TaskBean
|
import com.navinfo.collect.library.data.entity.TaskBean
|
||||||
|
import com.navinfo.omqs.bean.IndoorConnectionInfoBean
|
||||||
import com.navinfo.omqs.bean.LoginUserBean
|
import com.navinfo.omqs.bean.LoginUserBean
|
||||||
import com.navinfo.omqs.bean.QRCodeBean
|
import com.navinfo.omqs.bean.QRCodeBean
|
||||||
import com.navinfo.omqs.bean.SysUserBean
|
import com.navinfo.omqs.bean.SysUserBean
|
||||||
@ -32,4 +33,9 @@ interface NetworkService {
|
|||||||
* 连接室内整理工具
|
* 连接室内整理工具
|
||||||
*/
|
*/
|
||||||
suspend fun connectIndoorTools(url: String): NetResult<QRCodeBean>
|
suspend fun connectIndoorTools(url: String): NetResult<QRCodeBean>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新用户信息
|
||||||
|
*/
|
||||||
|
suspend fun updateServerInfo(url: String,indoorConnectionInfoBean: IndoorConnectionInfoBean): NetResult<QRCodeBean>
|
||||||
}
|
}
|
@ -2,6 +2,7 @@ package com.navinfo.omqs.http
|
|||||||
|
|
||||||
import com.navinfo.omqs.bean.OfflineMapCityBean
|
import com.navinfo.omqs.bean.OfflineMapCityBean
|
||||||
import com.navinfo.collect.library.data.entity.TaskBean
|
import com.navinfo.collect.library.data.entity.TaskBean
|
||||||
|
import com.navinfo.omqs.bean.IndoorConnectionInfoBean
|
||||||
import com.navinfo.omqs.bean.LoginUserBean
|
import com.navinfo.omqs.bean.LoginUserBean
|
||||||
import com.navinfo.omqs.bean.QRCodeBean
|
import com.navinfo.omqs.bean.QRCodeBean
|
||||||
import com.navinfo.omqs.bean.SysUserBean
|
import com.navinfo.omqs.bean.SysUserBean
|
||||||
@ -95,4 +96,23 @@ class NetworkServiceImpl @Inject constructor(
|
|||||||
NetResult.Error<Any>(e)
|
NetResult.Error<Any>(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun updateServerInfo(url: String,indoorConnectionInfoBean: IndoorConnectionInfoBean): NetResult<QRCodeBean> =
|
||||||
|
//在IO线程中运行
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
return@withContext try {
|
||||||
|
val result = netApi.retrofitUpdateServerInfo(url,indoorConnectionInfoBean)
|
||||||
|
if (result.isSuccessful) {
|
||||||
|
if (result.code() == 200) {
|
||||||
|
NetResult.Success(result.body())
|
||||||
|
} else {
|
||||||
|
NetResult.Failure<Any>(result.code(), result.message())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
NetResult.Failure<Any>(result.code(), result.message())
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
NetResult.Error<Any>(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,6 +3,7 @@ package com.navinfo.omqs.http
|
|||||||
import com.navinfo.omqs.bean.EvaluationInfo
|
import com.navinfo.omqs.bean.EvaluationInfo
|
||||||
import com.navinfo.omqs.bean.OfflineMapCityBean
|
import com.navinfo.omqs.bean.OfflineMapCityBean
|
||||||
import com.navinfo.collect.library.data.entity.TaskBean
|
import com.navinfo.collect.library.data.entity.TaskBean
|
||||||
|
import com.navinfo.omqs.bean.IndoorConnectionInfoBean
|
||||||
import com.navinfo.omqs.bean.LoginUserBean
|
import com.navinfo.omqs.bean.LoginUserBean
|
||||||
import com.navinfo.omqs.bean.QRCodeBean
|
import com.navinfo.omqs.bean.QRCodeBean
|
||||||
import com.navinfo.omqs.bean.SysUserBean
|
import com.navinfo.omqs.bean.SysUserBean
|
||||||
@ -74,6 +75,13 @@ interface RetrofitNetworkServiceAPI {
|
|||||||
@GET
|
@GET
|
||||||
suspend fun retrofitConnectIndoorTools(@Url url: String): Response<QRCodeBean>
|
suspend fun retrofitConnectIndoorTools(@Url url: String): Response<QRCodeBean>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录接口
|
||||||
|
*/
|
||||||
|
@Headers("Content-Type: application/json")
|
||||||
|
@POST
|
||||||
|
suspend fun retrofitUpdateServerInfo(@Url url: String,@Body indoorConnectionInfoBean: IndoorConnectionInfoBean): Response<QRCodeBean>
|
||||||
|
|
||||||
@Headers("Content-Type: application/json")
|
@Headers("Content-Type: application/json")
|
||||||
@POST("/devcp/uploadSceneProblem")
|
@POST("/devcp/uploadSceneProblem")
|
||||||
suspend fun postRequest(@Body listEvaluationInfo: List<EvaluationInfo>?): Response<DefaultResponse<*>>
|
suspend fun postRequest(@Body listEvaluationInfo: List<EvaluationInfo>?): Response<DefaultResponse<*>>
|
||||||
|
@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData
|
|||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.navinfo.omqs.Constant
|
import com.navinfo.omqs.Constant
|
||||||
|
import com.navinfo.omqs.bean.IndoorConnectionInfoBean
|
||||||
import com.navinfo.omqs.bean.QRCodeBean
|
import com.navinfo.omqs.bean.QRCodeBean
|
||||||
import com.navinfo.omqs.bean.SysUserBean
|
import com.navinfo.omqs.bean.SysUserBean
|
||||||
import com.navinfo.omqs.http.DefaultResponse
|
import com.navinfo.omqs.http.DefaultResponse
|
||||||
@ -26,12 +27,17 @@ enum class QrCodeStatus {
|
|||||||
* 网络访问失败
|
* 网络访问失败
|
||||||
*/
|
*/
|
||||||
QR_CODE_STATUS_NET_FAILURE,
|
QR_CODE_STATUS_NET_FAILURE,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 成功
|
* 成功
|
||||||
*/
|
*/
|
||||||
QR_CODE_STATUS_SUCCESS
|
QR_CODE_STATUS_SUCCESS,
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 信息更新成功
|
||||||
|
*/
|
||||||
|
QR_CODE_STATUS_SERVER_INFO_SUCCESS,
|
||||||
|
}
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class QrCodeViewModel @Inject constructor(
|
class QrCodeViewModel @Inject constructor(
|
||||||
@ -80,7 +86,7 @@ class QrCodeViewModel @Inject constructor(
|
|||||||
|
|
||||||
val defaultUserResponse = result.data as QRCodeBean
|
val defaultUserResponse = result.data as QRCodeBean
|
||||||
|
|
||||||
if (defaultUserResponse.errcode==0) {
|
if (defaultUserResponse.errcode == 0) {
|
||||||
|
|
||||||
Constant.INDOOR_IP = ipTemp
|
Constant.INDOOR_IP = ipTemp
|
||||||
|
|
||||||
@ -147,6 +153,102 @@ class QrCodeViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 扫一扫按钮
|
||||||
|
*/
|
||||||
|
fun updateServerInfo(context: Context) {
|
||||||
|
|
||||||
|
if (TextUtils.isEmpty(Constant.INDOOR_IP)) {
|
||||||
|
Toast.makeText(context, "获取ip失败!", Toast.LENGTH_LONG).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModelScope.launch(Dispatchers.Default) {
|
||||||
|
val url = "http://${Constant.INDOOR_IP}:8080/sensor/service/connection"
|
||||||
|
when (val result = networkService.updateServerInfo(
|
||||||
|
url = url,
|
||||||
|
indoorConnectionInfoBean = IndoorConnectionInfoBean(
|
||||||
|
Constant.USER_ID,
|
||||||
|
Constant.USER_ID,
|
||||||
|
Constant.USER_ID,
|
||||||
|
Constant.USER_ID,
|
||||||
|
com.navinfo.collect.library.system.Constant.SERVER_ADDRESS,
|
||||||
|
Constant.USER_ID,
|
||||||
|
"Android"
|
||||||
|
)
|
||||||
|
)) {
|
||||||
|
is NetResult.Success<*> -> {
|
||||||
|
|
||||||
|
if (result.data != null) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
val defaultUserResponse = result.data as QRCodeBean
|
||||||
|
|
||||||
|
if (defaultUserResponse.errcode == 0) {
|
||||||
|
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
"信息更新成功。",
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
qrCodeStatus.postValue(QrCodeStatus.QR_CODE_STATUS_SERVER_INFO_SUCCESS)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
"${defaultUserResponse.msg}",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (e: IOException) {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
"${e.message}",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
is NetResult.Error<*> -> {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
"${result.exception.message}",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
qrCodeStatus.postValue(QrCodeStatus.QR_CODE_STATUS_NET_FAILURE)
|
||||||
|
}
|
||||||
|
|
||||||
|
is NetResult.Failure<*> -> {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
"${result.code}:${result.msg}",
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
)
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
qrCodeStatus.postValue(QrCodeStatus.QR_CODE_STATUS_NET_FAILURE)
|
||||||
|
}
|
||||||
|
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun onCleared() {
|
override fun onCleared() {
|
||||||
super.onCleared()
|
super.onCleared()
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,9 @@ class QrCodeActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
QrCodeStatus.QR_CODE_STATUS_NET_FAILURE -> {
|
QrCodeStatus.QR_CODE_STATUS_NET_FAILURE -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
QrCodeStatus.QR_CODE_STATUS_SERVER_INFO_SUCCESS -> {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user