refactor(api): 更新净菜包和餐品净菜包接口支持分页请求
- 使用 POST 请求和 JSON Body 替换 GET 请求,支持分页参数传递 - 更新接口返回类型为分页结构 PageData - 在对应数据模型中新增分页请求参数类 PageOptionsReq 引入 - 增加 CleanPackageOption 和 MealPackageOption 模型字段以支持新需求 - 调整 NetViewModelV2 中调用接口逻辑,传递分页参数 - 修改 ShelfV2Activity 中数据处理逻辑,适配分页返回数据结构 - 更新全局常量 PROD_BASE_URL 地址
This commit is contained in:
@@ -20,7 +20,7 @@ object GlobalData {
|
|||||||
// const val LOCAL_BASE_URL = "http://192.168.1.201:14801"
|
// const val LOCAL_BASE_URL = "http://192.168.1.201:14801"
|
||||||
const val LOCAL_BASE_URL = "http://192.168.10.101:24801"
|
const val LOCAL_BASE_URL = "http://192.168.10.101:24801"
|
||||||
const val TEST_BASE_URL = "https://dev.yixiong-tech.com:8081"
|
const val TEST_BASE_URL = "https://dev.yixiong-tech.com:8081"
|
||||||
const val PROD_BASE_URL = "https://api.dm.yixiong-tech.com:8443"
|
const val PROD_BASE_URL = "https://platform-api.uat.shuziweidao.com"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import com.shuwei.intelligent.shelves.base.BaseActivity
|
|||||||
import com.shuwei.intelligent.shelves.databinding.ActivityShelfV2Binding
|
import com.shuwei.intelligent.shelves.databinding.ActivityShelfV2Binding
|
||||||
import com.shuwei.intelligent.shelves.model.CleanPackageOption
|
import com.shuwei.intelligent.shelves.model.CleanPackageOption
|
||||||
import com.shuwei.intelligent.shelves.model.MealPackageOption
|
import com.shuwei.intelligent.shelves.model.MealPackageOption
|
||||||
|
import com.shuwei.intelligent.shelves.model.PageData
|
||||||
import com.shuwei.intelligent.shelves.model.ShelfModelV2
|
import com.shuwei.intelligent.shelves.model.ShelfModelV2
|
||||||
import com.shuwei.intelligent.shelves.model.SendWeightEvent
|
import com.shuwei.intelligent.shelves.model.SendWeightEvent
|
||||||
import com.shuwei.intelligent.shelves.net.Loading
|
import com.shuwei.intelligent.shelves.net.Loading
|
||||||
@@ -280,7 +281,7 @@ class ShelfV2Activity : BaseActivity() {
|
|||||||
binding.include?.root?.gone()
|
binding.include?.root?.gone()
|
||||||
binding.root.postDelayed({ Loading.dismiss() }, 200)
|
binding.root.postDelayed({ Loading.dismiss() }, 200)
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val items = data.data as? List<CleanPackageOption>
|
val items = (data.data as? PageData<*>)?.list as? List<CleanPackageOption>
|
||||||
if (items.isNullOrEmpty()) {
|
if (items.isNullOrEmpty()) {
|
||||||
loadEmptyView(); return
|
loadEmptyView(); return
|
||||||
}
|
}
|
||||||
@@ -295,7 +296,7 @@ class ShelfV2Activity : BaseActivity() {
|
|||||||
binding.include?.root?.gone()
|
binding.include?.root?.gone()
|
||||||
binding.root.postDelayed({ Loading.dismiss() }, 200)
|
binding.root.postDelayed({ Loading.dismiss() }, 200)
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val items = data.data as? List<MealPackageOption>
|
val items = (data.data as? PageData<*>)?.list as? List<MealPackageOption>
|
||||||
if (items.isNullOrEmpty()) {
|
if (items.isNullOrEmpty()) {
|
||||||
loadEmptyView(); return
|
loadEmptyView(); return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ data class CleanPackageOption(
|
|||||||
val needQtyKg: BigDecimal? = null,
|
val needQtyKg: BigDecimal? = null,
|
||||||
/** 保质期至,格式 yyyy-MM-dd */
|
/** 保质期至,格式 yyyy-MM-dd */
|
||||||
val expiryDate: String? = null,
|
val expiryDate: String? = null,
|
||||||
|
/** 申领时间,格式 yyyy-MM-dd HH:mm:ss,仅订单有 */
|
||||||
|
val applyTime: String? = null,
|
||||||
|
/** 数据来源:1=净菜订单,2=食材库 */
|
||||||
|
val source: Short? = null,
|
||||||
|
/** 净菜类型 id,仅订单有 */
|
||||||
|
val vegTypeId: Long? = null,
|
||||||
|
/** 食材库 id,source=2 时有值,sync 时回传 materId */
|
||||||
|
val materId: Long? = null,
|
||||||
var isSelected: Boolean = false
|
var isSelected: Boolean = false
|
||||||
) {
|
) {
|
||||||
/** 将净菜包选项转换为格口记录 */
|
/** 将净菜包选项转换为格口记录 */
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ data class MealPackageOption(
|
|||||||
val needQtyKg: BigDecimal? = null,
|
val needQtyKg: BigDecimal? = null,
|
||||||
/** 保质期至,格式 yyyy-MM-dd(包装完成后有值) */
|
/** 保质期至,格式 yyyy-MM-dd(包装完成后有值) */
|
||||||
val expiryDate: String? = null,
|
val expiryDate: String? = null,
|
||||||
|
/** 数据来源:1=净菜订单,2=餐品库 */
|
||||||
|
val source: Short? = null,
|
||||||
var isSelected: Boolean = false
|
var isSelected: Boolean = false
|
||||||
) {
|
) {
|
||||||
/** 将餐品净菜包选项转换为格口记录 */
|
/** 将餐品净菜包选项转换为格口记录 */
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package com.shuwei.intelligent.shelves.net
|
|||||||
import com.shuwei.intelligent.shelves.model.CabinetInitResult
|
import com.shuwei.intelligent.shelves.model.CabinetInitResult
|
||||||
import com.shuwei.intelligent.shelves.model.CleanPackageOption
|
import com.shuwei.intelligent.shelves.model.CleanPackageOption
|
||||||
import com.shuwei.intelligent.shelves.model.MealPackageOption
|
import com.shuwei.intelligent.shelves.model.MealPackageOption
|
||||||
|
import com.shuwei.intelligent.shelves.model.PageData
|
||||||
|
import com.shuwei.intelligent.shelves.model.PageOptionsReq
|
||||||
import com.shuwei.intelligent.shelves.model.SyncBody
|
import com.shuwei.intelligent.shelves.model.SyncBody
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
@@ -24,21 +26,23 @@ interface ApiServiceV2 {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 4.2.1 净菜包下拉列表(itemType=1)
|
* 4.2.1 净菜包下拉列表(itemType=1)
|
||||||
|
* POST + JSON Body 分页请求,返回分页结构 PageData
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
suspend fun getCleanPackageOptions(
|
suspend fun getCleanPackageOptions(
|
||||||
@Url url: String = UrlConfig.CLEAN_PACKAGE_OPTIONS,
|
@Url url: String = UrlConfig.CLEAN_PACKAGE_OPTIONS,
|
||||||
@Query("keyword") keyword: String? = null
|
@Body body: PageOptionsReq
|
||||||
): RespData<List<CleanPackageOption>>
|
): RespData<PageData<CleanPackageOption>>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 4.2.2 餐品净菜包下拉列表(itemType=2)
|
* 4.2.2 餐品净菜包下拉列表(itemType=2)
|
||||||
|
* POST + JSON Body 分页请求,返回分页结构 PageData
|
||||||
*/
|
*/
|
||||||
@GET
|
@POST
|
||||||
suspend fun getMealPackageOptions(
|
suspend fun getMealPackageOptions(
|
||||||
@Url url: String = UrlConfig.MEAL_PACKAGE_OPTIONS,
|
@Url url: String = UrlConfig.MEAL_PACKAGE_OPTIONS,
|
||||||
@Query("keyword") keyword: String? = null
|
@Body body: PageOptionsReq
|
||||||
): RespData<List<MealPackageOption>>
|
): RespData<PageData<MealPackageOption>>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 4.3 全量同步整柜数据(定时上报)
|
* 4.3 全量同步整柜数据(定时上报)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import com.shuwei.intelligent.shelves.model.CabinetInitResult
|
import com.shuwei.intelligent.shelves.model.CabinetInitResult
|
||||||
import com.shuwei.intelligent.shelves.model.CleanPackageOption
|
import com.shuwei.intelligent.shelves.model.CleanPackageOption
|
||||||
import com.shuwei.intelligent.shelves.model.MealPackageOption
|
import com.shuwei.intelligent.shelves.model.MealPackageOption
|
||||||
|
import com.shuwei.intelligent.shelves.model.PageOptionsReq
|
||||||
import com.shuwei.intelligent.shelves.model.SyncBody
|
import com.shuwei.intelligent.shelves.model.SyncBody
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
@@ -47,7 +48,9 @@ class NetViewModelV2 : ViewModel() {
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_cleanPackageOptionsUiState.value = UiState.Loading
|
_cleanPackageOptionsUiState.value = UiState.Loading
|
||||||
runCatching {
|
runCatching {
|
||||||
val response = apiServiceV2.getCleanPackageOptions(keyword = keyword)
|
val response = apiServiceV2.getCleanPackageOptions(
|
||||||
|
body = PageOptionsReq(pageNum = 1, pageSize = 50, keyword = keyword)
|
||||||
|
)
|
||||||
if (response.isSuccess()) {
|
if (response.isSuccess()) {
|
||||||
_cleanPackageOptionsUiState.value = UiState.Success(response)
|
_cleanPackageOptionsUiState.value = UiState.Success(response)
|
||||||
} else {
|
} else {
|
||||||
@@ -64,7 +67,9 @@ class NetViewModelV2 : ViewModel() {
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_mealPackageOptionsUiState.value = UiState.Loading
|
_mealPackageOptionsUiState.value = UiState.Loading
|
||||||
runCatching {
|
runCatching {
|
||||||
val response = apiServiceV2.getMealPackageOptions(keyword = keyword)
|
val response = apiServiceV2.getMealPackageOptions(
|
||||||
|
body = PageOptionsReq(pageNum = 1, pageSize = 50, keyword = keyword)
|
||||||
|
)
|
||||||
if (response.isSuccess()) {
|
if (response.isSuccess()) {
|
||||||
_mealPackageOptionsUiState.value = UiState.Success(response)
|
_mealPackageOptionsUiState.value = UiState.Success(response)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user