diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 66135e5..b4c719a 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import okhttp3.MultipartBody import retrofit2.http.* @@ -45,7 +45,7 @@ * 获取闸井类别 */ @GET("/dict/code/sluicewellType") - suspend fun obtainWellType(@Header("token") token: String): WellTypeModel + suspend fun obtainWellType(@Header("token") token: String): String /** * 获取获取闸井列表 @@ -66,13 +66,13 @@ @Query("isAlarm") isAlarm: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WellListModel + ): String /** * 获取获取闸井列表-不分页,地图用 */ @GET("/well/list") - suspend fun obtainAllWell(@Header("token") token: String): WellListModel + suspend fun obtainAllWell(@Header("token") token: String): String /** * 获取闸井详情 @@ -123,7 +123,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WorkOrderListModel + ): String /** * 获取工单详情 @@ -172,7 +172,7 @@ @Header("token") token: String, @Field("hasMine") hasMine: String?, @Field("roleTips") roleTips: String? - ): SubordinateModel + ): String /** * 转单 @@ -229,7 +229,7 @@ suspend fun obtainAlarmContentType( @Header("token") token: String, @Query("alarmType") alarmType: String - ): AlarmContentTypeModel + ): String /** * 工单状态 @@ -237,7 +237,7 @@ @GET("/dict/code/jobStatus") suspend fun obtainOrderStatus( @Header("token") token: String - ): OrderStatusModel + ): String /** * 查询工单 @@ -264,7 +264,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): UnacceptedOrderModel + ): String /** * 获取用户信息 diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 66135e5..b4c719a 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import okhttp3.MultipartBody import retrofit2.http.* @@ -45,7 +45,7 @@ * 获取闸井类别 */ @GET("/dict/code/sluicewellType") - suspend fun obtainWellType(@Header("token") token: String): WellTypeModel + suspend fun obtainWellType(@Header("token") token: String): String /** * 获取获取闸井列表 @@ -66,13 +66,13 @@ @Query("isAlarm") isAlarm: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WellListModel + ): String /** * 获取获取闸井列表-不分页,地图用 */ @GET("/well/list") - suspend fun obtainAllWell(@Header("token") token: String): WellListModel + suspend fun obtainAllWell(@Header("token") token: String): String /** * 获取闸井详情 @@ -123,7 +123,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WorkOrderListModel + ): String /** * 获取工单详情 @@ -172,7 +172,7 @@ @Header("token") token: String, @Field("hasMine") hasMine: String?, @Field("roleTips") roleTips: String? - ): SubordinateModel + ): String /** * 转单 @@ -229,7 +229,7 @@ suspend fun obtainAlarmContentType( @Header("token") token: String, @Query("alarmType") alarmType: String - ): AlarmContentTypeModel + ): String /** * 工单状态 @@ -237,7 +237,7 @@ @GET("/dict/code/jobStatus") suspend fun obtainOrderStatus( @Header("token") token: String - ): OrderStatusModel + ): String /** * 查询工单 @@ -264,7 +264,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): UnacceptedOrderModel + ): String /** * 获取用户信息 diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index f7317ff..5f67945 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -22,7 +22,6 @@ /** * 登录并获取Token - * 暂时不转为Model,因为密码错误返回的数据结构和密码正确返回的数据结构不一样 */ suspend fun login(account: String, secretKey: String): String { return api.obtainLoginResult(account, secretKey) @@ -45,7 +44,7 @@ /** * 获取闸井类别 */ - suspend fun obtainWellType(): WellTypeModel { + suspend fun obtainWellType(): String { return api.obtainWellType(AuthenticationHelper.token!!) } @@ -54,7 +53,7 @@ */ suspend fun obtainWellList( keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int - ): WellListModel { + ): String { return api.obtainWellList( AuthenticationHelper.token!!, keywords, @@ -69,7 +68,7 @@ /** * 获取获取闸井列表-不分页 */ - suspend fun obtainAllWell(): WellListModel { + suspend fun obtainAllWell(): String { return api.obtainAllWell(AuthenticationHelper.token!!) } @@ -97,7 +96,7 @@ /** * 根据工单状态获取工单列表 */ - suspend fun obtainWorkOrderList(jobStatus: String, page: Int): WorkOrderListModel { + suspend fun obtainWorkOrderList(jobStatus: String, page: Int): String { return api.obtainWorkOrderList( AuthenticationHelper.token!!, jobStatus, @@ -132,7 +131,7 @@ /** * 查找同一单位下的用户 */ - suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): SubordinateModel { + suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): String { return api.obtainSubordinate(AuthenticationHelper.token!!, hasMine, roleTips) } @@ -170,14 +169,14 @@ /** * 告警内容列表 */ - suspend fun obtainAlarmContentType(alarmType: String): AlarmContentTypeModel { + suspend fun obtainAlarmContentType(alarmType: String): String { return api.obtainAlarmContentType(AuthenticationHelper.token!!, alarmType) } /** * 工单状态 */ - suspend fun obtainOrderStatus(): OrderStatusModel { + suspend fun obtainOrderStatus(): String { return api.obtainOrderStatus(AuthenticationHelper.token!!) } @@ -209,7 +208,7 @@ /** * 获取超时工单列表 */ - suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): UnacceptedOrderModel { + suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): String { return api.obtainOvertimeOderList( AuthenticationHelper.token!!, jobStatus, diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 66135e5..b4c719a 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import okhttp3.MultipartBody import retrofit2.http.* @@ -45,7 +45,7 @@ * 获取闸井类别 */ @GET("/dict/code/sluicewellType") - suspend fun obtainWellType(@Header("token") token: String): WellTypeModel + suspend fun obtainWellType(@Header("token") token: String): String /** * 获取获取闸井列表 @@ -66,13 +66,13 @@ @Query("isAlarm") isAlarm: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WellListModel + ): String /** * 获取获取闸井列表-不分页,地图用 */ @GET("/well/list") - suspend fun obtainAllWell(@Header("token") token: String): WellListModel + suspend fun obtainAllWell(@Header("token") token: String): String /** * 获取闸井详情 @@ -123,7 +123,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WorkOrderListModel + ): String /** * 获取工单详情 @@ -172,7 +172,7 @@ @Header("token") token: String, @Field("hasMine") hasMine: String?, @Field("roleTips") roleTips: String? - ): SubordinateModel + ): String /** * 转单 @@ -229,7 +229,7 @@ suspend fun obtainAlarmContentType( @Header("token") token: String, @Query("alarmType") alarmType: String - ): AlarmContentTypeModel + ): String /** * 工单状态 @@ -237,7 +237,7 @@ @GET("/dict/code/jobStatus") suspend fun obtainOrderStatus( @Header("token") token: String - ): OrderStatusModel + ): String /** * 查询工单 @@ -264,7 +264,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): UnacceptedOrderModel + ): String /** * 获取用户信息 diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index f7317ff..5f67945 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -22,7 +22,6 @@ /** * 登录并获取Token - * 暂时不转为Model,因为密码错误返回的数据结构和密码正确返回的数据结构不一样 */ suspend fun login(account: String, secretKey: String): String { return api.obtainLoginResult(account, secretKey) @@ -45,7 +44,7 @@ /** * 获取闸井类别 */ - suspend fun obtainWellType(): WellTypeModel { + suspend fun obtainWellType(): String { return api.obtainWellType(AuthenticationHelper.token!!) } @@ -54,7 +53,7 @@ */ suspend fun obtainWellList( keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int - ): WellListModel { + ): String { return api.obtainWellList( AuthenticationHelper.token!!, keywords, @@ -69,7 +68,7 @@ /** * 获取获取闸井列表-不分页 */ - suspend fun obtainAllWell(): WellListModel { + suspend fun obtainAllWell(): String { return api.obtainAllWell(AuthenticationHelper.token!!) } @@ -97,7 +96,7 @@ /** * 根据工单状态获取工单列表 */ - suspend fun obtainWorkOrderList(jobStatus: String, page: Int): WorkOrderListModel { + suspend fun obtainWorkOrderList(jobStatus: String, page: Int): String { return api.obtainWorkOrderList( AuthenticationHelper.token!!, jobStatus, @@ -132,7 +131,7 @@ /** * 查找同一单位下的用户 */ - suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): SubordinateModel { + suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): String { return api.obtainSubordinate(AuthenticationHelper.token!!, hasMine, roleTips) } @@ -170,14 +169,14 @@ /** * 告警内容列表 */ - suspend fun obtainAlarmContentType(alarmType: String): AlarmContentTypeModel { + suspend fun obtainAlarmContentType(alarmType: String): String { return api.obtainAlarmContentType(AuthenticationHelper.token!!, alarmType) } /** * 工单状态 */ - suspend fun obtainOrderStatus(): OrderStatusModel { + suspend fun obtainOrderStatus(): String { return api.obtainOrderStatus(AuthenticationHelper.token!!) } @@ -209,7 +208,7 @@ /** * 获取超时工单列表 */ - suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): UnacceptedOrderModel { + suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): String { return api.obtainOvertimeOderList( AuthenticationHelper.token!!, jobStatus, diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index b64edb1..cb14d1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class AlarmContentTypeViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainAlarmContentType(alarmType: String) = launch({ - listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val response = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 66135e5..b4c719a 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import okhttp3.MultipartBody import retrofit2.http.* @@ -45,7 +45,7 @@ * 获取闸井类别 */ @GET("/dict/code/sluicewellType") - suspend fun obtainWellType(@Header("token") token: String): WellTypeModel + suspend fun obtainWellType(@Header("token") token: String): String /** * 获取获取闸井列表 @@ -66,13 +66,13 @@ @Query("isAlarm") isAlarm: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WellListModel + ): String /** * 获取获取闸井列表-不分页,地图用 */ @GET("/well/list") - suspend fun obtainAllWell(@Header("token") token: String): WellListModel + suspend fun obtainAllWell(@Header("token") token: String): String /** * 获取闸井详情 @@ -123,7 +123,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WorkOrderListModel + ): String /** * 获取工单详情 @@ -172,7 +172,7 @@ @Header("token") token: String, @Field("hasMine") hasMine: String?, @Field("roleTips") roleTips: String? - ): SubordinateModel + ): String /** * 转单 @@ -229,7 +229,7 @@ suspend fun obtainAlarmContentType( @Header("token") token: String, @Query("alarmType") alarmType: String - ): AlarmContentTypeModel + ): String /** * 工单状态 @@ -237,7 +237,7 @@ @GET("/dict/code/jobStatus") suspend fun obtainOrderStatus( @Header("token") token: String - ): OrderStatusModel + ): String /** * 查询工单 @@ -264,7 +264,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): UnacceptedOrderModel + ): String /** * 获取用户信息 diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index f7317ff..5f67945 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -22,7 +22,6 @@ /** * 登录并获取Token - * 暂时不转为Model,因为密码错误返回的数据结构和密码正确返回的数据结构不一样 */ suspend fun login(account: String, secretKey: String): String { return api.obtainLoginResult(account, secretKey) @@ -45,7 +44,7 @@ /** * 获取闸井类别 */ - suspend fun obtainWellType(): WellTypeModel { + suspend fun obtainWellType(): String { return api.obtainWellType(AuthenticationHelper.token!!) } @@ -54,7 +53,7 @@ */ suspend fun obtainWellList( keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int - ): WellListModel { + ): String { return api.obtainWellList( AuthenticationHelper.token!!, keywords, @@ -69,7 +68,7 @@ /** * 获取获取闸井列表-不分页 */ - suspend fun obtainAllWell(): WellListModel { + suspend fun obtainAllWell(): String { return api.obtainAllWell(AuthenticationHelper.token!!) } @@ -97,7 +96,7 @@ /** * 根据工单状态获取工单列表 */ - suspend fun obtainWorkOrderList(jobStatus: String, page: Int): WorkOrderListModel { + suspend fun obtainWorkOrderList(jobStatus: String, page: Int): String { return api.obtainWorkOrderList( AuthenticationHelper.token!!, jobStatus, @@ -132,7 +131,7 @@ /** * 查找同一单位下的用户 */ - suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): SubordinateModel { + suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): String { return api.obtainSubordinate(AuthenticationHelper.token!!, hasMine, roleTips) } @@ -170,14 +169,14 @@ /** * 告警内容列表 */ - suspend fun obtainAlarmContentType(alarmType: String): AlarmContentTypeModel { + suspend fun obtainAlarmContentType(alarmType: String): String { return api.obtainAlarmContentType(AuthenticationHelper.token!!, alarmType) } /** * 工单状态 */ - suspend fun obtainOrderStatus(): OrderStatusModel { + suspend fun obtainOrderStatus(): String { return api.obtainOrderStatus(AuthenticationHelper.token!!) } @@ -209,7 +208,7 @@ /** * 获取超时工单列表 */ - suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): UnacceptedOrderModel { + suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): String { return api.obtainOvertimeOderList( AuthenticationHelper.token!!, jobStatus, diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index b64edb1..cb14d1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class AlarmContentTypeViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainAlarmContentType(alarmType: String) = launch({ - listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val response = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index b9c5eb1..7ffd854 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OrderStatusViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainOrderStatus() = launch({ - listModel.value = RetrofitServiceManager.obtainOrderStatus() + val response = RetrofitServiceManager.obtainOrderStatus() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 66135e5..b4c719a 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import okhttp3.MultipartBody import retrofit2.http.* @@ -45,7 +45,7 @@ * 获取闸井类别 */ @GET("/dict/code/sluicewellType") - suspend fun obtainWellType(@Header("token") token: String): WellTypeModel + suspend fun obtainWellType(@Header("token") token: String): String /** * 获取获取闸井列表 @@ -66,13 +66,13 @@ @Query("isAlarm") isAlarm: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WellListModel + ): String /** * 获取获取闸井列表-不分页,地图用 */ @GET("/well/list") - suspend fun obtainAllWell(@Header("token") token: String): WellListModel + suspend fun obtainAllWell(@Header("token") token: String): String /** * 获取闸井详情 @@ -123,7 +123,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WorkOrderListModel + ): String /** * 获取工单详情 @@ -172,7 +172,7 @@ @Header("token") token: String, @Field("hasMine") hasMine: String?, @Field("roleTips") roleTips: String? - ): SubordinateModel + ): String /** * 转单 @@ -229,7 +229,7 @@ suspend fun obtainAlarmContentType( @Header("token") token: String, @Query("alarmType") alarmType: String - ): AlarmContentTypeModel + ): String /** * 工单状态 @@ -237,7 +237,7 @@ @GET("/dict/code/jobStatus") suspend fun obtainOrderStatus( @Header("token") token: String - ): OrderStatusModel + ): String /** * 查询工单 @@ -264,7 +264,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): UnacceptedOrderModel + ): String /** * 获取用户信息 diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index f7317ff..5f67945 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -22,7 +22,6 @@ /** * 登录并获取Token - * 暂时不转为Model,因为密码错误返回的数据结构和密码正确返回的数据结构不一样 */ suspend fun login(account: String, secretKey: String): String { return api.obtainLoginResult(account, secretKey) @@ -45,7 +44,7 @@ /** * 获取闸井类别 */ - suspend fun obtainWellType(): WellTypeModel { + suspend fun obtainWellType(): String { return api.obtainWellType(AuthenticationHelper.token!!) } @@ -54,7 +53,7 @@ */ suspend fun obtainWellList( keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int - ): WellListModel { + ): String { return api.obtainWellList( AuthenticationHelper.token!!, keywords, @@ -69,7 +68,7 @@ /** * 获取获取闸井列表-不分页 */ - suspend fun obtainAllWell(): WellListModel { + suspend fun obtainAllWell(): String { return api.obtainAllWell(AuthenticationHelper.token!!) } @@ -97,7 +96,7 @@ /** * 根据工单状态获取工单列表 */ - suspend fun obtainWorkOrderList(jobStatus: String, page: Int): WorkOrderListModel { + suspend fun obtainWorkOrderList(jobStatus: String, page: Int): String { return api.obtainWorkOrderList( AuthenticationHelper.token!!, jobStatus, @@ -132,7 +131,7 @@ /** * 查找同一单位下的用户 */ - suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): SubordinateModel { + suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): String { return api.obtainSubordinate(AuthenticationHelper.token!!, hasMine, roleTips) } @@ -170,14 +169,14 @@ /** * 告警内容列表 */ - suspend fun obtainAlarmContentType(alarmType: String): AlarmContentTypeModel { + suspend fun obtainAlarmContentType(alarmType: String): String { return api.obtainAlarmContentType(AuthenticationHelper.token!!, alarmType) } /** * 工单状态 */ - suspend fun obtainOrderStatus(): OrderStatusModel { + suspend fun obtainOrderStatus(): String { return api.obtainOrderStatus(AuthenticationHelper.token!!) } @@ -209,7 +208,7 @@ /** * 获取超时工单列表 */ - suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): UnacceptedOrderModel { + suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): String { return api.obtainOvertimeOderList( AuthenticationHelper.token!!, jobStatus, diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index b64edb1..cb14d1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class AlarmContentTypeViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainAlarmContentType(alarmType: String) = launch({ - listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val response = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index b9c5eb1..7ffd854 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OrderStatusViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainOrderStatus() = launch({ - listModel.value = RetrofitServiceManager.obtainOrderStatus() + val response = RetrofitServiceManager.obtainOrderStatus() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index 5a24195..c5cd5d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OvertimeOderListViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ - resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val response = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 66135e5..b4c719a 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import okhttp3.MultipartBody import retrofit2.http.* @@ -45,7 +45,7 @@ * 获取闸井类别 */ @GET("/dict/code/sluicewellType") - suspend fun obtainWellType(@Header("token") token: String): WellTypeModel + suspend fun obtainWellType(@Header("token") token: String): String /** * 获取获取闸井列表 @@ -66,13 +66,13 @@ @Query("isAlarm") isAlarm: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WellListModel + ): String /** * 获取获取闸井列表-不分页,地图用 */ @GET("/well/list") - suspend fun obtainAllWell(@Header("token") token: String): WellListModel + suspend fun obtainAllWell(@Header("token") token: String): String /** * 获取闸井详情 @@ -123,7 +123,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WorkOrderListModel + ): String /** * 获取工单详情 @@ -172,7 +172,7 @@ @Header("token") token: String, @Field("hasMine") hasMine: String?, @Field("roleTips") roleTips: String? - ): SubordinateModel + ): String /** * 转单 @@ -229,7 +229,7 @@ suspend fun obtainAlarmContentType( @Header("token") token: String, @Query("alarmType") alarmType: String - ): AlarmContentTypeModel + ): String /** * 工单状态 @@ -237,7 +237,7 @@ @GET("/dict/code/jobStatus") suspend fun obtainOrderStatus( @Header("token") token: String - ): OrderStatusModel + ): String /** * 查询工单 @@ -264,7 +264,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): UnacceptedOrderModel + ): String /** * 获取用户信息 diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index f7317ff..5f67945 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -22,7 +22,6 @@ /** * 登录并获取Token - * 暂时不转为Model,因为密码错误返回的数据结构和密码正确返回的数据结构不一样 */ suspend fun login(account: String, secretKey: String): String { return api.obtainLoginResult(account, secretKey) @@ -45,7 +44,7 @@ /** * 获取闸井类别 */ - suspend fun obtainWellType(): WellTypeModel { + suspend fun obtainWellType(): String { return api.obtainWellType(AuthenticationHelper.token!!) } @@ -54,7 +53,7 @@ */ suspend fun obtainWellList( keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int - ): WellListModel { + ): String { return api.obtainWellList( AuthenticationHelper.token!!, keywords, @@ -69,7 +68,7 @@ /** * 获取获取闸井列表-不分页 */ - suspend fun obtainAllWell(): WellListModel { + suspend fun obtainAllWell(): String { return api.obtainAllWell(AuthenticationHelper.token!!) } @@ -97,7 +96,7 @@ /** * 根据工单状态获取工单列表 */ - suspend fun obtainWorkOrderList(jobStatus: String, page: Int): WorkOrderListModel { + suspend fun obtainWorkOrderList(jobStatus: String, page: Int): String { return api.obtainWorkOrderList( AuthenticationHelper.token!!, jobStatus, @@ -132,7 +131,7 @@ /** * 查找同一单位下的用户 */ - suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): SubordinateModel { + suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): String { return api.obtainSubordinate(AuthenticationHelper.token!!, hasMine, roleTips) } @@ -170,14 +169,14 @@ /** * 告警内容列表 */ - suspend fun obtainAlarmContentType(alarmType: String): AlarmContentTypeModel { + suspend fun obtainAlarmContentType(alarmType: String): String { return api.obtainAlarmContentType(AuthenticationHelper.token!!, alarmType) } /** * 工单状态 */ - suspend fun obtainOrderStatus(): OrderStatusModel { + suspend fun obtainOrderStatus(): String { return api.obtainOrderStatus(AuthenticationHelper.token!!) } @@ -209,7 +208,7 @@ /** * 获取超时工单列表 */ - suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): UnacceptedOrderModel { + suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): String { return api.obtainOvertimeOderList( AuthenticationHelper.token!!, jobStatus, diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index b64edb1..cb14d1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class AlarmContentTypeViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainAlarmContentType(alarmType: String) = launch({ - listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val response = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index b9c5eb1..7ffd854 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OrderStatusViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainOrderStatus() = launch({ - listModel.value = RetrofitServiceManager.obtainOrderStatus() + val response = RetrofitServiceManager.obtainOrderStatus() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index 5a24195..c5cd5d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OvertimeOderListViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ - resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val response = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index bcec54b..5540d7b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -4,19 +4,32 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken /** * 转单下一级人员 * */ class SubordinateViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ - listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + val response = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 66135e5..b4c719a 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import okhttp3.MultipartBody import retrofit2.http.* @@ -45,7 +45,7 @@ * 获取闸井类别 */ @GET("/dict/code/sluicewellType") - suspend fun obtainWellType(@Header("token") token: String): WellTypeModel + suspend fun obtainWellType(@Header("token") token: String): String /** * 获取获取闸井列表 @@ -66,13 +66,13 @@ @Query("isAlarm") isAlarm: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WellListModel + ): String /** * 获取获取闸井列表-不分页,地图用 */ @GET("/well/list") - suspend fun obtainAllWell(@Header("token") token: String): WellListModel + suspend fun obtainAllWell(@Header("token") token: String): String /** * 获取闸井详情 @@ -123,7 +123,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WorkOrderListModel + ): String /** * 获取工单详情 @@ -172,7 +172,7 @@ @Header("token") token: String, @Field("hasMine") hasMine: String?, @Field("roleTips") roleTips: String? - ): SubordinateModel + ): String /** * 转单 @@ -229,7 +229,7 @@ suspend fun obtainAlarmContentType( @Header("token") token: String, @Query("alarmType") alarmType: String - ): AlarmContentTypeModel + ): String /** * 工单状态 @@ -237,7 +237,7 @@ @GET("/dict/code/jobStatus") suspend fun obtainOrderStatus( @Header("token") token: String - ): OrderStatusModel + ): String /** * 查询工单 @@ -264,7 +264,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): UnacceptedOrderModel + ): String /** * 获取用户信息 diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index f7317ff..5f67945 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -22,7 +22,6 @@ /** * 登录并获取Token - * 暂时不转为Model,因为密码错误返回的数据结构和密码正确返回的数据结构不一样 */ suspend fun login(account: String, secretKey: String): String { return api.obtainLoginResult(account, secretKey) @@ -45,7 +44,7 @@ /** * 获取闸井类别 */ - suspend fun obtainWellType(): WellTypeModel { + suspend fun obtainWellType(): String { return api.obtainWellType(AuthenticationHelper.token!!) } @@ -54,7 +53,7 @@ */ suspend fun obtainWellList( keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int - ): WellListModel { + ): String { return api.obtainWellList( AuthenticationHelper.token!!, keywords, @@ -69,7 +68,7 @@ /** * 获取获取闸井列表-不分页 */ - suspend fun obtainAllWell(): WellListModel { + suspend fun obtainAllWell(): String { return api.obtainAllWell(AuthenticationHelper.token!!) } @@ -97,7 +96,7 @@ /** * 根据工单状态获取工单列表 */ - suspend fun obtainWorkOrderList(jobStatus: String, page: Int): WorkOrderListModel { + suspend fun obtainWorkOrderList(jobStatus: String, page: Int): String { return api.obtainWorkOrderList( AuthenticationHelper.token!!, jobStatus, @@ -132,7 +131,7 @@ /** * 查找同一单位下的用户 */ - suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): SubordinateModel { + suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): String { return api.obtainSubordinate(AuthenticationHelper.token!!, hasMine, roleTips) } @@ -170,14 +169,14 @@ /** * 告警内容列表 */ - suspend fun obtainAlarmContentType(alarmType: String): AlarmContentTypeModel { + suspend fun obtainAlarmContentType(alarmType: String): String { return api.obtainAlarmContentType(AuthenticationHelper.token!!, alarmType) } /** * 工单状态 */ - suspend fun obtainOrderStatus(): OrderStatusModel { + suspend fun obtainOrderStatus(): String { return api.obtainOrderStatus(AuthenticationHelper.token!!) } @@ -209,7 +208,7 @@ /** * 获取超时工单列表 */ - suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): UnacceptedOrderModel { + suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): String { return api.obtainOvertimeOderList( AuthenticationHelper.token!!, jobStatus, diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index b64edb1..cb14d1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class AlarmContentTypeViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainAlarmContentType(alarmType: String) = launch({ - listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val response = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index b9c5eb1..7ffd854 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OrderStatusViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainOrderStatus() = launch({ - listModel.value = RetrofitServiceManager.obtainOrderStatus() + val response = RetrofitServiceManager.obtainOrderStatus() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index 5a24195..c5cd5d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OvertimeOderListViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ - resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val response = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index bcec54b..5540d7b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -4,19 +4,32 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken /** * 转单下一级人员 * */ class SubordinateViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ - listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + val response = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index 498db8b..0df853e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -1,18 +1,17 @@ package com.casic.app.smartwell.vm -import android.util.Log import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject class WellCountViewModel : BaseViewModel() { - private val kTag = "WellCountViewModel" val resultModel = MutableLiveData>() fun countWellByState() = launch({ @@ -28,7 +27,7 @@ map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "countWellByState: 错误码===>${responseCode}") + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { "服务器异常".show(BaseApplication.obtainInstance()) diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 66135e5..b4c719a 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import okhttp3.MultipartBody import retrofit2.http.* @@ -45,7 +45,7 @@ * 获取闸井类别 */ @GET("/dict/code/sluicewellType") - suspend fun obtainWellType(@Header("token") token: String): WellTypeModel + suspend fun obtainWellType(@Header("token") token: String): String /** * 获取获取闸井列表 @@ -66,13 +66,13 @@ @Query("isAlarm") isAlarm: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WellListModel + ): String /** * 获取获取闸井列表-不分页,地图用 */ @GET("/well/list") - suspend fun obtainAllWell(@Header("token") token: String): WellListModel + suspend fun obtainAllWell(@Header("token") token: String): String /** * 获取闸井详情 @@ -123,7 +123,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WorkOrderListModel + ): String /** * 获取工单详情 @@ -172,7 +172,7 @@ @Header("token") token: String, @Field("hasMine") hasMine: String?, @Field("roleTips") roleTips: String? - ): SubordinateModel + ): String /** * 转单 @@ -229,7 +229,7 @@ suspend fun obtainAlarmContentType( @Header("token") token: String, @Query("alarmType") alarmType: String - ): AlarmContentTypeModel + ): String /** * 工单状态 @@ -237,7 +237,7 @@ @GET("/dict/code/jobStatus") suspend fun obtainOrderStatus( @Header("token") token: String - ): OrderStatusModel + ): String /** * 查询工单 @@ -264,7 +264,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): UnacceptedOrderModel + ): String /** * 获取用户信息 diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index f7317ff..5f67945 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -22,7 +22,6 @@ /** * 登录并获取Token - * 暂时不转为Model,因为密码错误返回的数据结构和密码正确返回的数据结构不一样 */ suspend fun login(account: String, secretKey: String): String { return api.obtainLoginResult(account, secretKey) @@ -45,7 +44,7 @@ /** * 获取闸井类别 */ - suspend fun obtainWellType(): WellTypeModel { + suspend fun obtainWellType(): String { return api.obtainWellType(AuthenticationHelper.token!!) } @@ -54,7 +53,7 @@ */ suspend fun obtainWellList( keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int - ): WellListModel { + ): String { return api.obtainWellList( AuthenticationHelper.token!!, keywords, @@ -69,7 +68,7 @@ /** * 获取获取闸井列表-不分页 */ - suspend fun obtainAllWell(): WellListModel { + suspend fun obtainAllWell(): String { return api.obtainAllWell(AuthenticationHelper.token!!) } @@ -97,7 +96,7 @@ /** * 根据工单状态获取工单列表 */ - suspend fun obtainWorkOrderList(jobStatus: String, page: Int): WorkOrderListModel { + suspend fun obtainWorkOrderList(jobStatus: String, page: Int): String { return api.obtainWorkOrderList( AuthenticationHelper.token!!, jobStatus, @@ -132,7 +131,7 @@ /** * 查找同一单位下的用户 */ - suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): SubordinateModel { + suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): String { return api.obtainSubordinate(AuthenticationHelper.token!!, hasMine, roleTips) } @@ -170,14 +169,14 @@ /** * 告警内容列表 */ - suspend fun obtainAlarmContentType(alarmType: String): AlarmContentTypeModel { + suspend fun obtainAlarmContentType(alarmType: String): String { return api.obtainAlarmContentType(AuthenticationHelper.token!!, alarmType) } /** * 工单状态 */ - suspend fun obtainOrderStatus(): OrderStatusModel { + suspend fun obtainOrderStatus(): String { return api.obtainOrderStatus(AuthenticationHelper.token!!) } @@ -209,7 +208,7 @@ /** * 获取超时工单列表 */ - suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): UnacceptedOrderModel { + suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): String { return api.obtainOvertimeOderList( AuthenticationHelper.token!!, jobStatus, diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index b64edb1..cb14d1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class AlarmContentTypeViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainAlarmContentType(alarmType: String) = launch({ - listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val response = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index b9c5eb1..7ffd854 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OrderStatusViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainOrderStatus() = launch({ - listModel.value = RetrofitServiceManager.obtainOrderStatus() + val response = RetrofitServiceManager.obtainOrderStatus() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index 5a24195..c5cd5d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OvertimeOderListViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ - resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val response = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index bcec54b..5540d7b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -4,19 +4,32 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken /** * 转单下一级人员 * */ class SubordinateViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ - listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + val response = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index 498db8b..0df853e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -1,18 +1,17 @@ package com.casic.app.smartwell.vm -import android.util.Log import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject class WellCountViewModel : BaseViewModel() { - private val kTag = "WellCountViewModel" val resultModel = MutableLiveData>() fun countWellByState() = launch({ @@ -28,7 +27,7 @@ map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "countWellByState: 错误码===>${responseCode}") + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { "服务器异常".show(BaseApplication.obtainInstance()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt index 9a2f1d1..053d6c3 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -4,12 +4,17 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellListViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainWellList( @@ -19,15 +24,31 @@ isAlarm: String?, page: Int ) = launch({ - listModel.value = RetrofitServiceManager.obtainWellList( + val response = RetrofitServiceManager.obtainWellList( keywords, wellType, deptid, isAlarm, page ) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) fun obtainAllWell() = launch({ - listModel.value = RetrofitServiceManager.obtainAllWell() + val response = RetrofitServiceManager.obtainAllWell() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 66135e5..b4c719a 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import okhttp3.MultipartBody import retrofit2.http.* @@ -45,7 +45,7 @@ * 获取闸井类别 */ @GET("/dict/code/sluicewellType") - suspend fun obtainWellType(@Header("token") token: String): WellTypeModel + suspend fun obtainWellType(@Header("token") token: String): String /** * 获取获取闸井列表 @@ -66,13 +66,13 @@ @Query("isAlarm") isAlarm: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WellListModel + ): String /** * 获取获取闸井列表-不分页,地图用 */ @GET("/well/list") - suspend fun obtainAllWell(@Header("token") token: String): WellListModel + suspend fun obtainAllWell(@Header("token") token: String): String /** * 获取闸井详情 @@ -123,7 +123,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WorkOrderListModel + ): String /** * 获取工单详情 @@ -172,7 +172,7 @@ @Header("token") token: String, @Field("hasMine") hasMine: String?, @Field("roleTips") roleTips: String? - ): SubordinateModel + ): String /** * 转单 @@ -229,7 +229,7 @@ suspend fun obtainAlarmContentType( @Header("token") token: String, @Query("alarmType") alarmType: String - ): AlarmContentTypeModel + ): String /** * 工单状态 @@ -237,7 +237,7 @@ @GET("/dict/code/jobStatus") suspend fun obtainOrderStatus( @Header("token") token: String - ): OrderStatusModel + ): String /** * 查询工单 @@ -264,7 +264,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): UnacceptedOrderModel + ): String /** * 获取用户信息 diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index f7317ff..5f67945 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -22,7 +22,6 @@ /** * 登录并获取Token - * 暂时不转为Model,因为密码错误返回的数据结构和密码正确返回的数据结构不一样 */ suspend fun login(account: String, secretKey: String): String { return api.obtainLoginResult(account, secretKey) @@ -45,7 +44,7 @@ /** * 获取闸井类别 */ - suspend fun obtainWellType(): WellTypeModel { + suspend fun obtainWellType(): String { return api.obtainWellType(AuthenticationHelper.token!!) } @@ -54,7 +53,7 @@ */ suspend fun obtainWellList( keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int - ): WellListModel { + ): String { return api.obtainWellList( AuthenticationHelper.token!!, keywords, @@ -69,7 +68,7 @@ /** * 获取获取闸井列表-不分页 */ - suspend fun obtainAllWell(): WellListModel { + suspend fun obtainAllWell(): String { return api.obtainAllWell(AuthenticationHelper.token!!) } @@ -97,7 +96,7 @@ /** * 根据工单状态获取工单列表 */ - suspend fun obtainWorkOrderList(jobStatus: String, page: Int): WorkOrderListModel { + suspend fun obtainWorkOrderList(jobStatus: String, page: Int): String { return api.obtainWorkOrderList( AuthenticationHelper.token!!, jobStatus, @@ -132,7 +131,7 @@ /** * 查找同一单位下的用户 */ - suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): SubordinateModel { + suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): String { return api.obtainSubordinate(AuthenticationHelper.token!!, hasMine, roleTips) } @@ -170,14 +169,14 @@ /** * 告警内容列表 */ - suspend fun obtainAlarmContentType(alarmType: String): AlarmContentTypeModel { + suspend fun obtainAlarmContentType(alarmType: String): String { return api.obtainAlarmContentType(AuthenticationHelper.token!!, alarmType) } /** * 工单状态 */ - suspend fun obtainOrderStatus(): OrderStatusModel { + suspend fun obtainOrderStatus(): String { return api.obtainOrderStatus(AuthenticationHelper.token!!) } @@ -209,7 +208,7 @@ /** * 获取超时工单列表 */ - suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): UnacceptedOrderModel { + suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): String { return api.obtainOvertimeOderList( AuthenticationHelper.token!!, jobStatus, diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index b64edb1..cb14d1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class AlarmContentTypeViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainAlarmContentType(alarmType: String) = launch({ - listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val response = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index b9c5eb1..7ffd854 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OrderStatusViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainOrderStatus() = launch({ - listModel.value = RetrofitServiceManager.obtainOrderStatus() + val response = RetrofitServiceManager.obtainOrderStatus() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index 5a24195..c5cd5d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OvertimeOderListViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ - resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val response = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index bcec54b..5540d7b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -4,19 +4,32 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken /** * 转单下一级人员 * */ class SubordinateViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ - listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + val response = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index 498db8b..0df853e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -1,18 +1,17 @@ package com.casic.app.smartwell.vm -import android.util.Log import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject class WellCountViewModel : BaseViewModel() { - private val kTag = "WellCountViewModel" val resultModel = MutableLiveData>() fun countWellByState() = launch({ @@ -28,7 +27,7 @@ map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "countWellByState: 错误码===>${responseCode}") + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { "服务器异常".show(BaseApplication.obtainInstance()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt index 9a2f1d1..053d6c3 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -4,12 +4,17 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellListViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainWellList( @@ -19,15 +24,31 @@ isAlarm: String?, page: Int ) = launch({ - listModel.value = RetrofitServiceManager.obtainWellList( + val response = RetrofitServiceManager.obtainWellList( keywords, wellType, deptid, isAlarm, page ) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) fun obtainAllWell() = launch({ - listModel.value = RetrofitServiceManager.obtainAllWell() + val response = RetrofitServiceManager.obtainAllWell() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt index e9da747..a55151c 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellTypeViewModel : BaseViewModel() { + private val gson = Gson() val wellTypeModel = MutableLiveData() fun obtainWellType() = launch({ - wellTypeModel.value = RetrofitServiceManager.obtainWellType() + val response = RetrofitServiceManager.obtainWellType() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + wellTypeModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 66135e5..b4c719a 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import okhttp3.MultipartBody import retrofit2.http.* @@ -45,7 +45,7 @@ * 获取闸井类别 */ @GET("/dict/code/sluicewellType") - suspend fun obtainWellType(@Header("token") token: String): WellTypeModel + suspend fun obtainWellType(@Header("token") token: String): String /** * 获取获取闸井列表 @@ -66,13 +66,13 @@ @Query("isAlarm") isAlarm: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WellListModel + ): String /** * 获取获取闸井列表-不分页,地图用 */ @GET("/well/list") - suspend fun obtainAllWell(@Header("token") token: String): WellListModel + suspend fun obtainAllWell(@Header("token") token: String): String /** * 获取闸井详情 @@ -123,7 +123,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WorkOrderListModel + ): String /** * 获取工单详情 @@ -172,7 +172,7 @@ @Header("token") token: String, @Field("hasMine") hasMine: String?, @Field("roleTips") roleTips: String? - ): SubordinateModel + ): String /** * 转单 @@ -229,7 +229,7 @@ suspend fun obtainAlarmContentType( @Header("token") token: String, @Query("alarmType") alarmType: String - ): AlarmContentTypeModel + ): String /** * 工单状态 @@ -237,7 +237,7 @@ @GET("/dict/code/jobStatus") suspend fun obtainOrderStatus( @Header("token") token: String - ): OrderStatusModel + ): String /** * 查询工单 @@ -264,7 +264,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): UnacceptedOrderModel + ): String /** * 获取用户信息 diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index f7317ff..5f67945 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -22,7 +22,6 @@ /** * 登录并获取Token - * 暂时不转为Model,因为密码错误返回的数据结构和密码正确返回的数据结构不一样 */ suspend fun login(account: String, secretKey: String): String { return api.obtainLoginResult(account, secretKey) @@ -45,7 +44,7 @@ /** * 获取闸井类别 */ - suspend fun obtainWellType(): WellTypeModel { + suspend fun obtainWellType(): String { return api.obtainWellType(AuthenticationHelper.token!!) } @@ -54,7 +53,7 @@ */ suspend fun obtainWellList( keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int - ): WellListModel { + ): String { return api.obtainWellList( AuthenticationHelper.token!!, keywords, @@ -69,7 +68,7 @@ /** * 获取获取闸井列表-不分页 */ - suspend fun obtainAllWell(): WellListModel { + suspend fun obtainAllWell(): String { return api.obtainAllWell(AuthenticationHelper.token!!) } @@ -97,7 +96,7 @@ /** * 根据工单状态获取工单列表 */ - suspend fun obtainWorkOrderList(jobStatus: String, page: Int): WorkOrderListModel { + suspend fun obtainWorkOrderList(jobStatus: String, page: Int): String { return api.obtainWorkOrderList( AuthenticationHelper.token!!, jobStatus, @@ -132,7 +131,7 @@ /** * 查找同一单位下的用户 */ - suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): SubordinateModel { + suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): String { return api.obtainSubordinate(AuthenticationHelper.token!!, hasMine, roleTips) } @@ -170,14 +169,14 @@ /** * 告警内容列表 */ - suspend fun obtainAlarmContentType(alarmType: String): AlarmContentTypeModel { + suspend fun obtainAlarmContentType(alarmType: String): String { return api.obtainAlarmContentType(AuthenticationHelper.token!!, alarmType) } /** * 工单状态 */ - suspend fun obtainOrderStatus(): OrderStatusModel { + suspend fun obtainOrderStatus(): String { return api.obtainOrderStatus(AuthenticationHelper.token!!) } @@ -209,7 +208,7 @@ /** * 获取超时工单列表 */ - suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): UnacceptedOrderModel { + suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): String { return api.obtainOvertimeOderList( AuthenticationHelper.token!!, jobStatus, diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index b64edb1..cb14d1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class AlarmContentTypeViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainAlarmContentType(alarmType: String) = launch({ - listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val response = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index b9c5eb1..7ffd854 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OrderStatusViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainOrderStatus() = launch({ - listModel.value = RetrofitServiceManager.obtainOrderStatus() + val response = RetrofitServiceManager.obtainOrderStatus() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index 5a24195..c5cd5d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OvertimeOderListViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ - resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val response = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index bcec54b..5540d7b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -4,19 +4,32 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken /** * 转单下一级人员 * */ class SubordinateViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ - listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + val response = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index 498db8b..0df853e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -1,18 +1,17 @@ package com.casic.app.smartwell.vm -import android.util.Log import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject class WellCountViewModel : BaseViewModel() { - private val kTag = "WellCountViewModel" val resultModel = MutableLiveData>() fun countWellByState() = launch({ @@ -28,7 +27,7 @@ map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "countWellByState: 错误码===>${responseCode}") + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { "服务器异常".show(BaseApplication.obtainInstance()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt index 9a2f1d1..053d6c3 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -4,12 +4,17 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellListViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainWellList( @@ -19,15 +24,31 @@ isAlarm: String?, page: Int ) = launch({ - listModel.value = RetrofitServiceManager.obtainWellList( + val response = RetrofitServiceManager.obtainWellList( keywords, wellType, deptid, isAlarm, page ) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) fun obtainAllWell() = launch({ - listModel.value = RetrofitServiceManager.obtainAllWell() + val response = RetrofitServiceManager.obtainAllWell() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt index e9da747..a55151c 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellTypeViewModel : BaseViewModel() { + private val gson = Gson() val wellTypeModel = MutableLiveData() fun obtainWellType() = launch({ - wellTypeModel.value = RetrofitServiceManager.obtainWellType() + val response = RetrofitServiceManager.obtainWellType() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + wellTypeModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt index cb56baa..ce3e0b2 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WorkOrderListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WorkOrderListViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun obtainWorkOrderListByState(jobStatus: String, page: Int) = launch({ - resultModel.value = RetrofitServiceManager.obtainWorkOrderList(jobStatus, page) + val response = RetrofitServiceManager.obtainWorkOrderList(jobStatus, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt index 66135e5..b4c719a 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitService.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import okhttp3.MultipartBody import retrofit2.http.* @@ -45,7 +45,7 @@ * 获取闸井类别 */ @GET("/dict/code/sluicewellType") - suspend fun obtainWellType(@Header("token") token: String): WellTypeModel + suspend fun obtainWellType(@Header("token") token: String): String /** * 获取获取闸井列表 @@ -66,13 +66,13 @@ @Query("isAlarm") isAlarm: String?, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WellListModel + ): String /** * 获取获取闸井列表-不分页,地图用 */ @GET("/well/list") - suspend fun obtainAllWell(@Header("token") token: String): WellListModel + suspend fun obtainAllWell(@Header("token") token: String): String /** * 获取闸井详情 @@ -123,7 +123,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): WorkOrderListModel + ): String /** * 获取工单详情 @@ -172,7 +172,7 @@ @Header("token") token: String, @Field("hasMine") hasMine: String?, @Field("roleTips") roleTips: String? - ): SubordinateModel + ): String /** * 转单 @@ -229,7 +229,7 @@ suspend fun obtainAlarmContentType( @Header("token") token: String, @Query("alarmType") alarmType: String - ): AlarmContentTypeModel + ): String /** * 工单状态 @@ -237,7 +237,7 @@ @GET("/dict/code/jobStatus") suspend fun obtainOrderStatus( @Header("token") token: String - ): OrderStatusModel + ): String /** * 查询工单 @@ -264,7 +264,7 @@ @Query("jobStatus") jobStatus: String, @Query("limit") limit: Int, @Query("offset") offset: Int - ): UnacceptedOrderModel + ): String /** * 获取用户信息 diff --git a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt index f7317ff..5f67945 100644 --- a/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt +++ b/app/src/main/java/com/casic/app/smartwell/utils/retrofit/RetrofitServiceManager.kt @@ -1,6 +1,6 @@ package com.casic.app.smartwell.utils.retrofit -import com.casic.app.smartwell.model.* +import com.casic.app.smartwell.model.PublicKeyModel import com.casic.app.smartwell.utils.AuthenticationHelper import com.casic.app.smartwell.utils.Constant import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -22,7 +22,6 @@ /** * 登录并获取Token - * 暂时不转为Model,因为密码错误返回的数据结构和密码正确返回的数据结构不一样 */ suspend fun login(account: String, secretKey: String): String { return api.obtainLoginResult(account, secretKey) @@ -45,7 +44,7 @@ /** * 获取闸井类别 */ - suspend fun obtainWellType(): WellTypeModel { + suspend fun obtainWellType(): String { return api.obtainWellType(AuthenticationHelper.token!!) } @@ -54,7 +53,7 @@ */ suspend fun obtainWellList( keywords: String?, wellType: String?, deptid: String?, isAlarm: String?, page: Int - ): WellListModel { + ): String { return api.obtainWellList( AuthenticationHelper.token!!, keywords, @@ -69,7 +68,7 @@ /** * 获取获取闸井列表-不分页 */ - suspend fun obtainAllWell(): WellListModel { + suspend fun obtainAllWell(): String { return api.obtainAllWell(AuthenticationHelper.token!!) } @@ -97,7 +96,7 @@ /** * 根据工单状态获取工单列表 */ - suspend fun obtainWorkOrderList(jobStatus: String, page: Int): WorkOrderListModel { + suspend fun obtainWorkOrderList(jobStatus: String, page: Int): String { return api.obtainWorkOrderList( AuthenticationHelper.token!!, jobStatus, @@ -132,7 +131,7 @@ /** * 查找同一单位下的用户 */ - suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): SubordinateModel { + suspend fun obtainSubordinate(hasMine: String?, roleTips: String?): String { return api.obtainSubordinate(AuthenticationHelper.token!!, hasMine, roleTips) } @@ -170,14 +169,14 @@ /** * 告警内容列表 */ - suspend fun obtainAlarmContentType(alarmType: String): AlarmContentTypeModel { + suspend fun obtainAlarmContentType(alarmType: String): String { return api.obtainAlarmContentType(AuthenticationHelper.token!!, alarmType) } /** * 工单状态 */ - suspend fun obtainOrderStatus(): OrderStatusModel { + suspend fun obtainOrderStatus(): String { return api.obtainOrderStatus(AuthenticationHelper.token!!) } @@ -209,7 +208,7 @@ /** * 获取超时工单列表 */ - suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): UnacceptedOrderModel { + suspend fun obtainOvertimeOderList(jobStatus: String, page: Int): String { return api.obtainOvertimeOderList( AuthenticationHelper.token!!, jobStatus, diff --git a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt index b64edb1..cb14d1e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/AlarmContentTypeViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.AlarmContentTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class AlarmContentTypeViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainAlarmContentType(alarmType: String) = launch({ - listModel.value = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val response = RetrofitServiceManager.obtainAlarmContentType(alarmType) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt index b9c5eb1..7ffd854 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OrderStatusViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.OrderStatusModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OrderStatusViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainOrderStatus() = launch({ - listModel.value = RetrofitServiceManager.obtainOrderStatus() + val response = RetrofitServiceManager.obtainOrderStatus() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt index 5a24195..c5cd5d9 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/OvertimeOderListViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.UnacceptedOrderModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class OvertimeOderListViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun obtainOvertimeOderList(jobStatus: String, page: Int) = launch({ - resultModel.value = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val response = RetrofitServiceManager.obtainOvertimeOderList(jobStatus, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt index bcec54b..5540d7b 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/SubordinateViewModel.kt @@ -4,19 +4,32 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.SubordinateModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken /** * 转单下一级人员 * */ class SubordinateViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainSubordinate(hasMine: String?, roleTips: String?) = launch({ - listModel.value = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + val response = RetrofitServiceManager.obtainSubordinate(hasMine, roleTips) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt index 498db8b..0df853e 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellCountViewModel.kt @@ -1,18 +1,17 @@ package com.casic.app.smartwell.vm -import android.util.Log import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject class WellCountViewModel : BaseViewModel() { - private val kTag = "WellCountViewModel" val resultModel = MutableLiveData>() fun countWellByState() = launch({ @@ -28,7 +27,7 @@ map["total"] = data.getString("total") resultModel.value = map } else { - Log.d(kTag, "countWellByState: 错误码===>${responseCode}") + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { "服务器异常".show(BaseApplication.obtainInstance()) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt index 9a2f1d1..053d6c3 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellListViewModel.kt @@ -4,12 +4,17 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellListViewModel : BaseViewModel() { + private val gson = Gson() val listModel = MutableLiveData() fun obtainWellList( @@ -19,15 +24,31 @@ isAlarm: String?, page: Int ) = launch({ - listModel.value = RetrofitServiceManager.obtainWellList( + val response = RetrofitServiceManager.obtainWellList( keywords, wellType, deptid, isAlarm, page ) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) fun obtainAllWell() = launch({ - listModel.value = RetrofitServiceManager.obtainAllWell() + val response = RetrofitServiceManager.obtainAllWell() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + listModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt index e9da747..a55151c 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WellTypeViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WellTypeModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WellTypeViewModel : BaseViewModel() { + private val gson = Gson() val wellTypeModel = MutableLiveData() fun obtainWellType() = launch({ - wellTypeModel.value = RetrofitServiceManager.obtainWellType() + val response = RetrofitServiceManager.obtainWellType() + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + wellTypeModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt index cb56baa..ce3e0b2 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderListViewModel.kt @@ -4,16 +4,29 @@ import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch +import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.model.WorkOrderListModel import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager +import com.google.gson.Gson +import com.google.gson.reflect.TypeToken class WorkOrderListViewModel : BaseViewModel() { + private val gson = Gson() val resultModel = MutableLiveData() fun obtainWorkOrderListByState(jobStatus: String, page: Int) = launch({ - resultModel.value = RetrofitServiceManager.obtainWorkOrderList(jobStatus, page) + val response = RetrofitServiceManager.obtainWorkOrderList(jobStatus, page) + val responseCode = response.separateResponseCode() + if (responseCode == 200) { + resultModel.value = gson.fromJson( + response, object : TypeToken() {}.type + ) + } else { + response.toErrorMessage().show(BaseApplication.obtainInstance()) + } }, { "服务器异常".show(BaseApplication.obtainInstance()) }) diff --git a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderViewModel.kt b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderViewModel.kt index 36a154c..ecfa565 100644 --- a/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderViewModel.kt +++ b/app/src/main/java/com/casic/app/smartwell/vm/WorkOrderViewModel.kt @@ -1,18 +1,17 @@ package com.casic.app.smartwell.vm -import android.util.Log import androidx.lifecycle.MutableLiveData import com.casic.app.smartwell.base.BaseApplication import com.casic.app.smartwell.base.BaseViewModel import com.casic.app.smartwell.extensions.launch import com.casic.app.smartwell.extensions.separateResponseCode import com.casic.app.smartwell.extensions.show +import com.casic.app.smartwell.extensions.toErrorMessage import com.casic.app.smartwell.utils.retrofit.RetrofitServiceManager import org.json.JSONObject class WorkOrderViewModel : BaseViewModel() { - private val kTag = "WorkOrderViewModel" val resultModel = MutableLiveData>() fun countWorkOrderByState() = launch({ @@ -29,7 +28,7 @@ map["over"] = data.getString("over") resultModel.value = map } else { - Log.d(kTag, "countWorkOrderByState: 错误码===>${responseCode}") + response.toErrorMessage().show(BaseApplication.obtainInstance()) } }, { "服务器异常".show(BaseApplication.obtainInstance())