feat(cookOrder): 集成新配比秤接口和制作模式功能
- 新增接口查询当日烹饪任务列表及菜品食材构成(主材+辅材,不含调料) - 增加调料模糊搜索功能,支持关键字分页查询 - 实现烹饪完成接口,支持提交主辅材用量、熟重及调料数据 - 在 PrepareFoodActivity 中添加烹制单 ID 传递和接口调用,区分采样和制作模式 - 在 SubmitFoodActivity 中实现制作模式烹饪完成数据组装与提交新接口逻辑 - 适配 FoodListFragment 和 FoodSearchActivity 使用熟重及烹制单 ID 关联映射 - RemoteRepository 和 NetViewModel 中新增对应接口调用方法及 UI 状态更新 - 优化 SeasoningSelectDialog 适配新接口数据结构及刷新逻辑 - 调整响应数据 ApiResponse 支持新接口标准成功码和分页字段 - 调整摄像头绑定逻辑,采样模式启用,制作模式禁用 - 统一将熟重字段用于菜品总重量计算,优化数据一致性及 UI 展示
This commit is contained in:
@@ -15,7 +15,6 @@ import android.view.Window
|
|||||||
import android.view.WindowManager
|
import android.view.WindowManager
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.core.widget.addTextChangedListener
|
import androidx.core.widget.addTextChangedListener
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
@@ -25,13 +24,11 @@ import com.shuwei.dish.match.base.BaseActivity
|
|||||||
import com.shuwei.dish.match.databinding.DialogSeasoningSelectBinding
|
import com.shuwei.dish.match.databinding.DialogSeasoningSelectBinding
|
||||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||||
import com.shuwei.dish.match.model.GoodsItem
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchItem
|
||||||
import com.shuwei.dish.match.net.UiState
|
import com.shuwei.dish.match.net.UiState
|
||||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||||
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||||
import com.shuwei.dish.match.utils.ext.toast
|
import com.shuwei.dish.match.utils.ext.toast
|
||||||
import kotlinx.coroutines.Job
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调料选择弹窗,不含重量显示,继承 BottomSheetDialog 确保只初始化一次
|
* 调料选择弹窗,不含重量显示,继承 BottomSheetDialog 确保只初始化一次
|
||||||
* @param activity 宿主 Activity
|
* @param activity 宿主 Activity
|
||||||
@@ -64,7 +61,6 @@ class SeasoningSelectDialog(
|
|||||||
|
|
||||||
private var goodsName: String? = null
|
private var goodsName: String? = null
|
||||||
private var pageNo = 1
|
private var pageNo = 1
|
||||||
private var collectJob: Job? = null
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
@@ -77,7 +73,6 @@ class SeasoningSelectDialog(
|
|||||||
window?.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
window?.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||||
|
|
||||||
setOnDismissListener {
|
setOnDismissListener {
|
||||||
collectJob?.cancel()
|
|
||||||
activity.hideStatusBar()
|
activity.hideStatusBar()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,23 +111,6 @@ class SeasoningSelectDialog(
|
|||||||
/** 弹窗显示时自动加载默认调料列表,并在 Window.Callback 层提前拦截触摸以解决滑动冲突 */
|
/** 弹窗显示时自动加载默认调料列表,并在 Window.Callback 层提前拦截触摸以解决滑动冲突 */
|
||||||
override fun show() {
|
override fun show() {
|
||||||
super.show()
|
super.show()
|
||||||
// 启动 StateFlow 收集,弹窗关闭时由 setOnDismissListener 取消
|
|
||||||
collectJob = activity.lifecycleScope.launch {
|
|
||||||
activity.netViewModel.foodSearchGoodsListState.collect { state ->
|
|
||||||
when (state) {
|
|
||||||
is UiState.Loading -> {}
|
|
||||||
is UiState.Success -> loadGoodsList(state.data)
|
|
||||||
is UiState.Error -> {
|
|
||||||
activity.toast(state.msg)
|
|
||||||
finishRefresh()
|
|
||||||
if (pageNo == 1) {
|
|
||||||
loadEmptyView()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is UiState.Idle -> {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pageNo = 1
|
pageNo = 1
|
||||||
getGoodsList()
|
getGoodsList()
|
||||||
// Window.Callback.dispatchTouchEvent 在整个 View 树的 onInterceptTouchEvent 之前执行,
|
// Window.Callback.dispatchTouchEvent 在整个 View 树的 onInterceptTouchEvent 之前执行,
|
||||||
@@ -184,14 +162,24 @@ class SeasoningSelectDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 请求调料列表
|
* 请求调料列表(新配比秤接口,回调版本)
|
||||||
*/
|
*/
|
||||||
private fun getGoodsList() {
|
private fun getGoodsList() {
|
||||||
activity.netViewModel.queryFoodSearchGoodsList(
|
activity.netViewModel.querySeasoningSearch(
|
||||||
goodsType = "1",
|
keyword = goodsName.takeUnless { it.isNullOrBlank() },
|
||||||
pageNum = pageNo,
|
pageNum = pageNo,
|
||||||
pageSize = PAGE_SIZE,
|
pageSize = PAGE_SIZE,
|
||||||
goodsName = goodsName.takeUnless { it.isNullOrBlank() }
|
onResult = { state ->
|
||||||
|
when (state) {
|
||||||
|
is UiState.Success -> loadGoodsList(state.data)
|
||||||
|
is UiState.Error -> {
|
||||||
|
activity.toast(state.msg)
|
||||||
|
finishRefresh()
|
||||||
|
if (pageNo == 1) loadEmptyView()
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,23 +191,22 @@ class SeasoningSelectDialog(
|
|||||||
"盐", "白砂糖", "冰糖", "鸡精", "味精", "陈醋", "老抽", "生抽", "番茄酱", "胡椒粉", "孜然", "十三香",
|
"盐", "白砂糖", "冰糖", "鸡精", "味精", "陈醋", "老抽", "生抽", "番茄酱", "胡椒粉", "孜然", "十三香",
|
||||||
"料酒", "白醋", "蚝油", "辣椒面", "辣椒酱", "豆瓣酱", "淀粉", "葱", "蒜", "姜", "香菜", "油"
|
"料酒", "白醋", "蚝油", "辣椒面", "辣椒酱", "豆瓣酱", "淀粉", "葱", "蒜", "姜", "香菜", "油"
|
||||||
)
|
)
|
||||||
val mockData = mutableListOf<GoodsItem>()
|
val mockData = nameList.mapIndexed { index, name ->
|
||||||
nameList.forEachIndexed { index, name ->
|
|
||||||
val padString = "${index + 1}".padStart(2, '0')
|
val padString = "${index + 1}".padStart(2, '0')
|
||||||
mockData.add(GoodsItem(goodsId = "1000$padString", goodsName = name))
|
SeasoningSearchItem(id = "1000$padString", materName = name)
|
||||||
}
|
}
|
||||||
pageNo = 1
|
pageNo = 1
|
||||||
loadGoodsList(mockData)
|
loadGoodsList(mockData)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将返回数据转换并填充到列表
|
* 将新接口返回的 SeasoningSearchItem 映射为 GoodsItem 并填充到列表
|
||||||
|
* 新接口的 id 即食材id,同时用作 goodsId 和 materId,无需再交换
|
||||||
*/
|
*/
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun loadGoodsList(records: MutableList<GoodsItem>?) {
|
private fun loadGoodsList(records: List<SeasoningSearchItem>?) {
|
||||||
finishRefresh()
|
finishRefresh()
|
||||||
if (records.isNullOrEmpty()) {
|
if (records.isNullOrEmpty()) {
|
||||||
//activity.toast("暂未搜索到调料信息")
|
|
||||||
if (pageNo == 1) {
|
if (pageNo == 1) {
|
||||||
loadEmptyView()
|
loadEmptyView()
|
||||||
}
|
}
|
||||||
@@ -227,18 +214,26 @@ class SeasoningSelectDialog(
|
|||||||
}
|
}
|
||||||
binding.recyclerView.layoutManager = GridLayoutManager(activity, 3, GridLayoutManager.VERTICAL, false)
|
binding.recyclerView.layoutManager = GridLayoutManager(activity, 3, GridLayoutManager.VERTICAL, false)
|
||||||
if (pageNo == 1) list.clear()
|
if (pageNo == 1) list.clear()
|
||||||
list.addAll(records)
|
val goodsItems = records.map { it.toGoodsItem() }
|
||||||
list.forEach {
|
list.addAll(goodsItems)
|
||||||
it.oldGoodsId = it.goodsId
|
|
||||||
//materId才是提交数据需要的goodsId数据
|
|
||||||
it.goodsId = it.materId ?:""
|
|
||||||
}
|
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
val isLoadMoreEnable = records.size >= PAGE_SIZE
|
val isLoadMoreEnable = records.size >= PAGE_SIZE
|
||||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||||
if (isLoadMoreEnable) pageNo++
|
if (isLoadMoreEnable) pageNo++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SeasoningSearchItem → GoodsItem 映射
|
||||||
|
* id 既是食材id也是提交时的 goodsId,不需要 oldGoodsId 交换
|
||||||
|
*/
|
||||||
|
private fun SeasoningSearchItem.toGoodsItem() = GoodsItem(
|
||||||
|
goodsId = id,
|
||||||
|
materId = id,
|
||||||
|
goodsName = materName,
|
||||||
|
materCode = materCode,
|
||||||
|
popularName = alias
|
||||||
|
)
|
||||||
|
|
||||||
private fun finishRefresh() {
|
private fun finishRefresh() {
|
||||||
if (pageNo == 1) binding.refreshLayout.finishRefresh()
|
if (pageNo == 1) binding.refreshLayout.finishRefresh()
|
||||||
else binding.refreshLayout.finishLoadMore()
|
else binding.refreshLayout.finishLoadMore()
|
||||||
|
|||||||
@@ -52,8 +52,91 @@ data class CookOrderItem(
|
|||||||
val cookStatusName: String = "",
|
val cookStatusName: String = "",
|
||||||
/** 生重(kg),烹制完成后才有值 */
|
/** 生重(kg),烹制完成后才有值 */
|
||||||
val rawWeight: Double? = null,
|
val rawWeight: Double? = null,
|
||||||
|
/** 熟重(kg),烹制完成后才有值 */
|
||||||
|
val cookedWeight: Double? = null,
|
||||||
/** 需求份数 */
|
/** 需求份数 */
|
||||||
val needPortions: Int = 0,
|
val needPortions: Int = 0,
|
||||||
/** 烹制份数,烹制完成后才有值 */
|
/** 烹制份数,烹制完成后才有值 */
|
||||||
val cookedPortions: Int? = null
|
val cookedPortions: Int? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品食材构成(主材+辅材),对应接口响应中单个食材
|
||||||
|
* 对应接口: GET /neglect/ratio-scale/cook-orders/{cookOrderId}/composition
|
||||||
|
* 注意: 此接口仅返回主材(ingredientClass=1)和辅材(ingredientClass=2),不含调料
|
||||||
|
*/
|
||||||
|
data class CookOrderCompositionItem(
|
||||||
|
/** 食材id */
|
||||||
|
val materId: String = "",
|
||||||
|
/** 食材名称 */
|
||||||
|
val ingredientName: String = "",
|
||||||
|
/** 食材分类: 1=主材 / 2=辅材 */
|
||||||
|
val ingredientClass: Int = 0,
|
||||||
|
/** 食材分类中文名称 */
|
||||||
|
val ingredientClassName: String = "",
|
||||||
|
/** 标准用量(g) */
|
||||||
|
val useWeight: Double = 0.0,
|
||||||
|
/** 净菜类型id */
|
||||||
|
val vegTypeId: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==================== 调料模糊搜索 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调料模糊搜索请求参数
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/seasoning-search
|
||||||
|
* 数据源: nut_mater_base 一级分类为 18(糖蜜饯)、19(油脂)、20(调味品)
|
||||||
|
*/
|
||||||
|
data class SeasoningSearchRequest(
|
||||||
|
/** 模糊匹配食材名称和别名,为空时返回全部 */
|
||||||
|
val keyword: String? = null,
|
||||||
|
/** 页码 */
|
||||||
|
val pageNum: Int = 1,
|
||||||
|
/** 每页条数 */
|
||||||
|
val pageSize: Int = 20
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调料模糊搜索结果条目
|
||||||
|
* 注意: Long 类型字段服务端序列化为 String
|
||||||
|
*/
|
||||||
|
data class SeasoningSearchItem(
|
||||||
|
/** 食材id(Long → String) */
|
||||||
|
val id: String = "",
|
||||||
|
/** 食材名称 */
|
||||||
|
val materName: String = "",
|
||||||
|
/** 食材编码 */
|
||||||
|
val materCode: String = "",
|
||||||
|
/** 别名 */
|
||||||
|
val alias: String = "",
|
||||||
|
/** 归属食堂id(Long → String) */
|
||||||
|
val canteenId: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
// ==================== 烹饪完成 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 烹饪完成 — 单个食材用量条目
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/cook-orders/complete
|
||||||
|
*/
|
||||||
|
data class CookCompleteItem(
|
||||||
|
/** 食材id */
|
||||||
|
val materId: String = "",
|
||||||
|
/** 实际用量(g) */
|
||||||
|
val actualQty: Double = 0.0
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 烹饪完成请求,一次性提交主辅材用量+熟重+调料
|
||||||
|
* 对应接口: POST /neglect/ratio-scale/cook-orders/complete
|
||||||
|
*/
|
||||||
|
data class CookCompleteRequest(
|
||||||
|
/** 烹制单id */
|
||||||
|
val cookOrderId: String = "",
|
||||||
|
/** 主辅材实际用量列表,至少1条 */
|
||||||
|
val items: List<CookCompleteItem> = emptyList(),
|
||||||
|
/** 熟重(kg) */
|
||||||
|
val cookedWeight: Double = 0.0,
|
||||||
|
/** 调料用量列表,选填 */
|
||||||
|
val seasonings: List<CookCompleteItem>? = null
|
||||||
|
)
|
||||||
|
|||||||
@@ -2,10 +2,14 @@ package com.shuwei.dish.match.net
|
|||||||
|
|
||||||
import com.shuwei.dish.match.base.GlobalData
|
import com.shuwei.dish.match.base.GlobalData
|
||||||
import com.shuwei.dish.match.model.CookFoodDTO
|
import com.shuwei.dish.match.model.CookFoodDTO
|
||||||
|
import com.shuwei.dish.match.model.CookOrderCompositionItem
|
||||||
import com.shuwei.dish.match.model.CookOrderMealGroup
|
import com.shuwei.dish.match.model.CookOrderMealGroup
|
||||||
import com.shuwei.dish.match.model.CookOrderPageRequest
|
import com.shuwei.dish.match.model.CookOrderPageRequest
|
||||||
import com.shuwei.dish.match.model.FoodRecord
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
import com.shuwei.dish.match.model.GoodsItem
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
|
import com.shuwei.dish.match.model.CookCompleteRequest
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchItem
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchRequest
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
@@ -14,6 +18,7 @@ import retrofit2.http.Multipart
|
|||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
import retrofit2.http.Part
|
import retrofit2.http.Part
|
||||||
import retrofit2.http.PartMap
|
import retrofit2.http.PartMap
|
||||||
|
import retrofit2.http.Path
|
||||||
import retrofit2.http.Query
|
import retrofit2.http.Query
|
||||||
import retrofit2.http.Url
|
import retrofit2.http.Url
|
||||||
|
|
||||||
@@ -38,15 +43,6 @@ interface ApiService {
|
|||||||
@Body param: CookFoodDTO
|
@Body param: CookFoodDTO
|
||||||
): ApiResponse<Any?>
|
): ApiResponse<Any?>
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询当日烹饪任务列表(按餐次分组),新配比秤接口
|
|
||||||
*/
|
|
||||||
@POST
|
|
||||||
suspend fun getCookOrderPage(
|
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/cook-orders/list",
|
|
||||||
@Body request: CookOrderPageRequest
|
|
||||||
): ApiResponse<List<CookOrderMealGroup>?>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 搜索菜品(旧接口,采样模式仍在使用)
|
* 搜索菜品(旧接口,采样模式仍在使用)
|
||||||
*/
|
*/
|
||||||
@@ -84,4 +80,44 @@ interface ApiService {
|
|||||||
@PartMap params: MutableMap<String, RequestBody>,
|
@PartMap params: MutableMap<String, RequestBody>,
|
||||||
@Part foodPics: List<MultipartBody.Part>
|
@Part foodPics: List<MultipartBody.Part>
|
||||||
): ApiResponse<List<String>?>
|
): ApiResponse<List<String>?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询当日烹饪任务列表(按餐次分组),新配比秤接口
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
suspend fun getCookOrderPage(
|
||||||
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/cook-orders/list",
|
||||||
|
@Body request: CookOrderPageRequest
|
||||||
|
): ApiResponse<List<CookOrderMealGroup>?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询菜品食材构成(主材+辅材,不含调料),新配比秤接口
|
||||||
|
*/
|
||||||
|
@GET("nutrition/neglect/ratio-scale/cook-orders/{cookOrderId}/composition")
|
||||||
|
suspend fun getCookOrderComposition(
|
||||||
|
@Path("cookOrderId") cookOrderId: String
|
||||||
|
): ApiResponse<List<CookOrderCompositionItem>?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调料模糊搜索,新配比秤接口
|
||||||
|
* 数据源: nut_mater_base 一级分类为 18(糖蜜饯)、19(油脂)、20(调味品)
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
suspend fun getSeasoningSearch(
|
||||||
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/seasoning-search",
|
||||||
|
@Body request: SeasoningSearchRequest
|
||||||
|
): ApiResponse<List<SeasoningSearchItem>?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 烹饪完成:提交主辅材用量+熟重+调料,一次性完成烹制
|
||||||
|
* 新配比秤接口,替代旧 saveConstitute
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
suspend fun cookOrderComplete(
|
||||||
|
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/cook-orders/complete",
|
||||||
|
@Body request: CookCompleteRequest
|
||||||
|
): ApiResponse<Any?>
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,11 +4,15 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.shuwei.dish.match.base.BaseApp
|
import com.shuwei.dish.match.base.BaseApp
|
||||||
import com.shuwei.dish.match.model.CookFoodDTO
|
import com.shuwei.dish.match.model.CookFoodDTO
|
||||||
|
import com.shuwei.dish.match.model.CookOrderCompositionItem
|
||||||
import com.shuwei.dish.match.model.CookOrderMealGroup
|
import com.shuwei.dish.match.model.CookOrderMealGroup
|
||||||
import com.shuwei.dish.match.model.CookOrderPageRequest
|
import com.shuwei.dish.match.model.CookOrderPageRequest
|
||||||
import com.shuwei.dish.match.model.FoodRecord
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
import com.shuwei.dish.match.model.GoodsItem
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
import com.shuwei.dish.match.model.GoodsNameQueryDTO
|
import com.shuwei.dish.match.model.GoodsNameQueryDTO
|
||||||
|
import com.shuwei.dish.match.model.CookCompleteRequest
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchItem
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchRequest
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
@@ -66,6 +70,23 @@ class NetViewModel(
|
|||||||
_foodDetailState.value = UiState.Idle
|
_foodDetailState.value = UiState.Idle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询菜品食材构成的 UI 状态流(新配比秤接口),UI 层通过 collect 监听
|
||||||
|
*/
|
||||||
|
private val _cookOrderCompositionState = MutableStateFlow<UiState<List<CookOrderCompositionItem>?>>(UiState.Idle)
|
||||||
|
val cookOrderCompositionState: StateFlow<UiState<List<CookOrderCompositionItem>?>> = _cookOrderCompositionState.asStateFlow()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询菜品食材构成(新配比秤接口,仅返回主材+辅材)
|
||||||
|
* @param cookOrderId 烹制单 ID
|
||||||
|
*/
|
||||||
|
fun getCookOrderComposition(cookOrderId: String) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
_cookOrderCompositionState.value = UiState.Loading
|
||||||
|
_cookOrderCompositionState.value = repository.getCookOrderComposition(cookOrderId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 搜索菜品列表的 UI 状态流。
|
* 搜索菜品列表的 UI 状态流。
|
||||||
* 使用 replay=1 保证 Fragment 重建后能收到最近一次结果;
|
* 使用 replay=1 保证 Fragment 重建后能收到最近一次结果;
|
||||||
@@ -253,6 +274,45 @@ class NetViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 调料模糊搜索(新配比秤接口,回调版本)
|
||||||
|
* 替代旧 queryGoodsList(goodsType=1) 调用
|
||||||
|
* @param keyword 模糊匹配食材名称和别名,为 null 时不传该字段
|
||||||
|
* @param pageNum 页码,默认第 1 页
|
||||||
|
* @param pageSize 每页条数,默认 50
|
||||||
|
* @param onLoading 请求发起前的回调
|
||||||
|
* @param onResult 结果回调,直接接收 UiState<List<SeasoningSearchItem>?>
|
||||||
|
*/
|
||||||
|
fun querySeasoningSearch(
|
||||||
|
keyword: String? = null,
|
||||||
|
pageNum: Int = 1,
|
||||||
|
pageSize: Int = 50,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<List<SeasoningSearchItem>?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.getSeasoningSearch(
|
||||||
|
SeasoningSearchRequest(keyword = keyword, pageNum = pageNum, pageSize = pageSize)
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 烹饪完成(新配比秤接口,回调版本),替代旧 submitCookFood
|
||||||
|
* 仅在制作模式下 cookOrderId 可用的场景调用
|
||||||
|
*/
|
||||||
|
fun cookOrderComplete(
|
||||||
|
request: CookCompleteRequest,
|
||||||
|
onLoading: () -> Unit = {},
|
||||||
|
onResult: (UiState<Any?>) -> Unit
|
||||||
|
) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
onLoading()
|
||||||
|
onResult(repository.cookOrderComplete(request))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传采集菜品信息 UI 状态流,UI 层通过 collect 监听
|
* 上传采集菜品信息 UI 状态流,UI 层通过 collect 监听
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
package com.shuwei.dish.match.net
|
package com.shuwei.dish.match.net
|
||||||
|
|
||||||
import com.shuwei.dish.match.model.CookFoodDTO
|
import com.shuwei.dish.match.model.CookFoodDTO
|
||||||
|
import com.shuwei.dish.match.model.CookOrderCompositionItem
|
||||||
import com.shuwei.dish.match.model.CookOrderMealGroup
|
import com.shuwei.dish.match.model.CookOrderMealGroup
|
||||||
import com.shuwei.dish.match.model.CookOrderPageRequest
|
import com.shuwei.dish.match.model.CookOrderPageRequest
|
||||||
import com.shuwei.dish.match.model.FoodRecord
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
import com.shuwei.dish.match.model.GoodsItem
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
|
import com.shuwei.dish.match.model.CookCompleteRequest
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchItem
|
||||||
|
import com.shuwei.dish.match.model.SeasoningSearchRequest
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
|
|
||||||
@@ -37,6 +41,10 @@ class RemoteRepository {
|
|||||||
suspend fun getCookOrderPage(request: CookOrderPageRequest): UiState<List<CookOrderMealGroup>?> =
|
suspend fun getCookOrderPage(request: CookOrderPageRequest): UiState<List<CookOrderMealGroup>?> =
|
||||||
safeApiCall { apiService.getCookOrderPage(request = request) }
|
safeApiCall { apiService.getCookOrderPage(request = request) }
|
||||||
|
|
||||||
|
/** 查询菜品食材构成(主材+辅材),新配比秤接口 */
|
||||||
|
suspend fun getCookOrderComposition(cookOrderId: String): UiState<List<CookOrderCompositionItem>?> =
|
||||||
|
safeApiCall { apiService.getCookOrderComposition(cookOrderId = cookOrderId) }
|
||||||
|
|
||||||
/** 搜索菜品列表 */
|
/** 搜索菜品列表 */
|
||||||
suspend fun searchFoodList(param: MutableMap<String, Any>): UiState<MutableList<FoodRecord>?> =
|
suspend fun searchFoodList(param: MutableMap<String, Any>): UiState<MutableList<FoodRecord>?> =
|
||||||
safeApiCall { apiService.searchFoodList(param = param) }
|
safeApiCall { apiService.searchFoodList(param = param) }
|
||||||
@@ -49,6 +57,14 @@ class RemoteRepository {
|
|||||||
suspend fun queryGoodsList(param: MutableMap<String, Any>): UiState<MutableList<GoodsItem>?> =
|
suspend fun queryGoodsList(param: MutableMap<String, Any>): UiState<MutableList<GoodsItem>?> =
|
||||||
safeApiCall { apiService.queryGoodsList(param = param) }
|
safeApiCall { apiService.queryGoodsList(param = param) }
|
||||||
|
|
||||||
|
/** 调料模糊搜索,新配比秤接口 */
|
||||||
|
suspend fun getSeasoningSearch(request: SeasoningSearchRequest): UiState<List<SeasoningSearchItem>?> =
|
||||||
|
safeApiCall { apiService.getSeasoningSearch(request = request) }
|
||||||
|
|
||||||
|
/** 烹饪完成,新配比秤接口,替代旧 submitCookFood */
|
||||||
|
suspend fun cookOrderComplete(request: CookCompleteRequest): UiState<Any?> =
|
||||||
|
safeApiCall { apiService.cookOrderComplete(request = request) }
|
||||||
|
|
||||||
/** 上传采集数据 */
|
/** 上传采集数据 */
|
||||||
suspend fun uploadFoodVectorData(
|
suspend fun uploadFoodVectorData(
|
||||||
params: MutableMap<String, RequestBody>,
|
params: MutableMap<String, RequestBody>,
|
||||||
|
|||||||
@@ -3,7 +3,10 @@ package com.shuwei.dish.match.net
|
|||||||
data class ApiResponse<T>(
|
data class ApiResponse<T>(
|
||||||
val code: String,
|
val code: String,
|
||||||
val msg: String? = "",
|
val msg: String? = "",
|
||||||
val data: T? = null
|
val data: T? = null,
|
||||||
|
/** 分页总条数,仅新配比秤接口返回(如 seasoning-search),旧接口为 null */
|
||||||
|
val total: Int? = null
|
||||||
) {
|
) {
|
||||||
fun isSuccess() = code == "00000"
|
/** 兼容旧接口成功码 "00000" 和新配比秤接口成功码 "200" */
|
||||||
|
fun isSuccess() = code == "00000" || code == "200"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,7 +190,9 @@ class FoodSearchActivity : BaseActivity() {
|
|||||||
return FoodRecord(
|
return FoodRecord(
|
||||||
foodId = foodId,
|
foodId = foodId,
|
||||||
foodName = dishName,
|
foodName = dishName,
|
||||||
totalWeight = ((rawWeight ?: 0.0) * 1000),
|
totalWeight = ((cookedWeight ?: 0.0) * 1000),
|
||||||
|
foodWeight = ((cookedWeight ?: 0.0) * 1000),
|
||||||
|
count = cookedPortions,
|
||||||
cookMode = 0,
|
cookMode = 0,
|
||||||
isCooking = cookStatus == 1,
|
isCooking = cookStatus == 1,
|
||||||
dinnerType = mealType.toString(),
|
dinnerType = mealType.toString(),
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import com.shuwei.dish.match.databinding.ActivityPrepareFoodBinding
|
|||||||
import com.shuwei.dish.match.databinding.LayoutCameraPreviewBinding
|
import com.shuwei.dish.match.databinding.LayoutCameraPreviewBinding
|
||||||
import com.shuwei.dish.match.dialog.CommonDialog
|
import com.shuwei.dish.match.dialog.CommonDialog
|
||||||
import com.shuwei.dish.match.model.CookFoodDTO
|
import com.shuwei.dish.match.model.CookFoodDTO
|
||||||
|
import com.shuwei.dish.match.model.CookOrderCompositionItem
|
||||||
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
import com.shuwei.dish.match.model.FoodRecord
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
import com.shuwei.dish.match.model.GoodsItem
|
import com.shuwei.dish.match.model.GoodsItem
|
||||||
@@ -53,6 +54,7 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
companion object {
|
companion object {
|
||||||
const val TAG = "PrepareFoodActivity"
|
const val TAG = "PrepareFoodActivity"
|
||||||
const val FOOD_ITEM = "foodItem"
|
const val FOOD_ITEM = "foodItem"
|
||||||
|
const val COOK_ORDER_ID = "cookOrderId"
|
||||||
const val PAGE_FROM = "pageFrom"
|
const val PAGE_FROM = "pageFrom"
|
||||||
const val HOME = "home"
|
const val HOME = "home"
|
||||||
const val WEIGHT_CHANGE_VALUE = 5
|
const val WEIGHT_CHANGE_VALUE = 5
|
||||||
@@ -68,6 +70,9 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
|
|
||||||
private var food: FoodRecord? = null
|
private var food: FoodRecord? = null
|
||||||
|
|
||||||
|
/** 烹制单 ID,制作模式从菜品列表传入,用于调用新配比秤接口 */
|
||||||
|
private var cookOrderId: String? = null
|
||||||
|
|
||||||
/** 来源页面标识,HOME 时返回跳转 SamplingListActivity */
|
/** 来源页面标识,HOME 时返回跳转 SamplingListActivity */
|
||||||
private var pageFrom: String? = null
|
private var pageFrom: String? = null
|
||||||
|
|
||||||
@@ -79,6 +84,7 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
pageFrom = intent.getStringExtra(PAGE_FROM)
|
pageFrom = intent.getStringExtra(PAGE_FROM)
|
||||||
//food = intent.extras?.getSerializable(FOOD_ITEM) as FoodRecord?
|
//food = intent.extras?.getSerializable(FOOD_ITEM) as FoodRecord?
|
||||||
food = IntentCompat.getSerializableExtra(intent, FOOD_ITEM, FoodRecord::class.java)
|
food = IntentCompat.getSerializableExtra(intent, FOOD_ITEM, FoodRecord::class.java)
|
||||||
|
cookOrderId = intent.getStringExtra(COOK_ORDER_ID)
|
||||||
val isSamplingMode = SpTool.cookMode == 1
|
val isSamplingMode = SpTool.cookMode == 1
|
||||||
val titleText = if (isSamplingMode) "菜品采集" else "菜品制作"
|
val titleText = if (isSamplingMode) "菜品采集" else "菜品制作"
|
||||||
setTitleBar(titleBarAction = {
|
setTitleBar(titleBarAction = {
|
||||||
@@ -114,11 +120,17 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
|
|
||||||
addViewClickListener()
|
addViewClickListener()
|
||||||
addBackKeyListener()
|
addBackKeyListener()
|
||||||
|
// 仅采样模式启用摄像头识别,制作模式不需要
|
||||||
|
if (isSamplingMode) {
|
||||||
initCamera(binding.flCameraContainer)
|
initCamera(binding.flCameraContainer)
|
||||||
|
}
|
||||||
initRecyclerView()
|
initRecyclerView()
|
||||||
initObserver()
|
initObserver()
|
||||||
|
|
||||||
if (food?.foodId.isNullOrBlank().not()) {
|
// 制作模式优先用 cookOrderId 调新接口,采样模式回退到旧 foodId
|
||||||
|
if (!cookOrderId.isNullOrBlank()) {
|
||||||
|
getCookOrderComposition(cookOrderId!!)
|
||||||
|
} else if (food?.foodId.isNullOrBlank().not()) {
|
||||||
getDishDetail(food!!.foodId!!)
|
getDishDetail(food!!.foodId!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,15 +164,19 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
// }
|
// }
|
||||||
// 净重 = 秤读数 - 初始读数
|
// 净重 = 秤读数 - 初始读数
|
||||||
val netWeight = weight - initialWeight
|
val netWeight = weight - initialWeight
|
||||||
|
currentWeight = netWeight
|
||||||
binding.tvShowWeight.run {
|
binding.tvShowWeight.run {
|
||||||
if (tag != netWeight) {
|
if (tag != netWeight) {
|
||||||
text = "称重:${netWeight}g"
|
text = "称重:${netWeight}g"
|
||||||
tag = netWeight
|
tag = netWeight
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 仅采样模式触发食材识别
|
||||||
|
if (SpTool.cookMode == 1) {
|
||||||
recognizeFood(netWeight)
|
recognizeFood(netWeight)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if (SpTool.cookMode == 1) {
|
if (SpTool.cookMode == 1) {
|
||||||
@@ -332,6 +348,7 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
startActivity<SubmitFoodActivity> {
|
startActivity<SubmitFoodActivity> {
|
||||||
putExtra(SubmitFoodActivity.GOODS_LIST, goodsList as Serializable)
|
putExtra(SubmitFoodActivity.GOODS_LIST, goodsList as Serializable)
|
||||||
putExtra(SubmitFoodActivity.FOOD_ITEM, food as Serializable)
|
putExtra(SubmitFoodActivity.FOOD_ITEM, food as Serializable)
|
||||||
|
putExtra(SubmitFoodActivity.COOK_ORDER_ID, cookOrderId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,6 +378,7 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
|
|
||||||
|
|
||||||
private fun initObserver() {
|
private fun initObserver() {
|
||||||
|
// 旧接口 observer(采样模式使用)
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
netViewModel.foodDetailState.collect { state ->
|
netViewModel.foodDetailState.collect { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
@@ -377,12 +395,35 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 新配比秤接口 observer(制作模式使用)
|
||||||
|
lifecycleScope.launch {
|
||||||
|
netViewModel.cookOrderCompositionState.collect { state ->
|
||||||
|
when (state) {
|
||||||
|
is UiState.Success -> {
|
||||||
|
val items = state.data
|
||||||
|
if (items.isNullOrEmpty()) {
|
||||||
|
toast("查询菜品构成为空")
|
||||||
|
return@collect
|
||||||
|
}
|
||||||
|
loadDishComposition(items)
|
||||||
|
}
|
||||||
|
is UiState.Error -> toast(state.msg)
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 旧接口:通过 foodId 查询菜品构成(采样模式使用) */
|
||||||
private fun getDishDetail(foodId: String) {
|
private fun getDishDetail(foodId: String) {
|
||||||
netViewModel.getFoodDetail(foodId)
|
netViewModel.getFoodDetail(foodId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 新接口:通过 cookOrderId 查询菜品食材构成(制作模式使用) */
|
||||||
|
private fun getCookOrderComposition(cookOrderId: String) {
|
||||||
|
netViewModel.getCookOrderComposition(cookOrderId)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun loadDishDetail(detail: CookFoodDTO) {
|
private fun loadDishDetail(detail: CookFoodDTO) {
|
||||||
// val voList = detail.stFoodInfoConstituteList
|
// val voList = detail.stFoodInfoConstituteList
|
||||||
@@ -402,13 +443,45 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
firstReqSize = list.size
|
firstReqSize = list.size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将新配比秤接口的食材构成列表映射为 GoodsItem 并刷新 UI
|
||||||
|
* 新接口天然仅返回主材(ingredientClass=1)和辅材(ingredientClass=2),不含调料
|
||||||
|
* useWeight 保留接口返回值,不再强制置零
|
||||||
|
*/
|
||||||
|
private fun loadDishComposition(items: List<CookOrderCompositionItem>) {
|
||||||
|
val tempData = items.map { item ->
|
||||||
|
GoodsItem(
|
||||||
|
goodsId = item.materId,
|
||||||
|
goodsName = item.ingredientName,
|
||||||
|
materId = item.materId,
|
||||||
|
materialType = item.ingredientClass,
|
||||||
|
useWeight = item.useWeight,
|
||||||
|
rawMaterialsType = item.vegTypeId,
|
||||||
|
isOriginalData = true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
list.clear()
|
||||||
|
list.addAll(tempData)
|
||||||
|
materialAdapter.items = list
|
||||||
|
materialAdapter.notifyDataSetChanged()
|
||||||
|
firstReqSize = list.size
|
||||||
|
}
|
||||||
|
|
||||||
private var firstReqSize = 0
|
private var firstReqSize = 0
|
||||||
private val list = mutableListOf<GoodsItem>()
|
private val list = mutableListOf<GoodsItem>()
|
||||||
private val materialAdapter by lazy {
|
private val materialAdapter by lazy {
|
||||||
FoodMaterialAdapter(list).apply {
|
FoodMaterialAdapter(list).apply {
|
||||||
onItemClick = { positon ->
|
onItemClick = { position ->
|
||||||
list.forEachIndexed { index, entity ->
|
list.forEachIndexed { index, entity ->
|
||||||
entity.isClicked = index == positon
|
entity.isClicked = index == position
|
||||||
|
}
|
||||||
|
// 制作模式:选中食材时同步当前秤重
|
||||||
|
if (SpTool.cookMode == 0) {
|
||||||
|
val item = list.getOrNull(position)
|
||||||
|
if (item != null && currentWeight > 0) {
|
||||||
|
item.useWeight = currentWeight
|
||||||
|
item.isSetFinished = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
notifyDataSetChanged()
|
notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
@@ -507,14 +580,18 @@ class PrepareFoodActivity : BaseActivity() {
|
|||||||
super.onResume()
|
super.onResume()
|
||||||
pageVisible = true
|
pageVisible = true
|
||||||
showRecognizePage = false
|
showRecognizePage = false
|
||||||
|
if (SpTool.cookMode == 1) {
|
||||||
cameraUtils.bind()
|
cameraUtils.bind()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
pageVisible = false
|
pageVisible = false
|
||||||
|
if (SpTool.cookMode == 1) {
|
||||||
cameraUtils.unbind()
|
cameraUtils.unbind()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化相机并绑定预览容器
|
* 初始化相机并绑定预览容器
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import com.shuwei.dish.match.dialog.CommonDialog
|
|||||||
import com.shuwei.dish.match.dialog.GoodsPreviewDialog
|
import com.shuwei.dish.match.dialog.GoodsPreviewDialog
|
||||||
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||||
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||||
|
import com.shuwei.dish.match.model.CookCompleteItem
|
||||||
|
import com.shuwei.dish.match.model.CookCompleteRequest
|
||||||
import com.shuwei.dish.match.model.FoodRecord
|
import com.shuwei.dish.match.model.FoodRecord
|
||||||
import com.shuwei.dish.match.model.toDTO
|
import com.shuwei.dish.match.model.toDTO
|
||||||
import com.shuwei.dish.match.net.UiState
|
import com.shuwei.dish.match.net.UiState
|
||||||
@@ -46,6 +48,7 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
const val TAG = "SubmitFoodActivity"
|
const val TAG = "SubmitFoodActivity"
|
||||||
const val FOOD_ITEM = "foodItem"
|
const val FOOD_ITEM = "foodItem"
|
||||||
const val GOODS_LIST = "goodsList"
|
const val GOODS_LIST = "goodsList"
|
||||||
|
const val COOK_ORDER_ID = "cookOrderId"
|
||||||
|
|
||||||
/** 本地临时 foodId 前缀;以此开头说明菜品尚未在服务器登记,提交时需清空让服务器分配真实 ID */
|
/** 本地临时 foodId 前缀;以此开头说明菜品尚未在服务器登记,提交时需清空让服务器分配真实 ID */
|
||||||
const val LOCAL_ID_PREFIX = "localId_"
|
const val LOCAL_ID_PREFIX = "localId_"
|
||||||
@@ -58,6 +61,9 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
private var food: FoodRecord? = null
|
private var food: FoodRecord? = null
|
||||||
private var goodsList: MutableList<CookFoodGoodsEntity>? = null
|
private var goodsList: MutableList<CookFoodGoodsEntity>? = null
|
||||||
|
|
||||||
|
/** 烹制单 ID,制作模式从 PrepareFoodActivity 传入,用于新配比秤烹饪完成接口 */
|
||||||
|
private var cookOrderId: String? = null
|
||||||
|
|
||||||
private val cookFoodEntity by lazy {
|
private val cookFoodEntity by lazy {
|
||||||
CookFoodEntity().apply {
|
CookFoodEntity().apply {
|
||||||
food?.let {
|
food?.let {
|
||||||
@@ -116,7 +122,8 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
setHeaderBackground()
|
setHeaderBackground()
|
||||||
intent.extras?.apply {
|
intent.extras?.apply {
|
||||||
food = getSerializable(FOOD_ITEM) as FoodRecord?
|
food = getSerializable(FOOD_ITEM) as FoodRecord?
|
||||||
Log.d(TAG, "onCreate: cookMode=${food?.cookMode}")
|
cookOrderId = getString(COOK_ORDER_ID)
|
||||||
|
Log.d(TAG, "onCreate: cookMode=${food?.cookMode}, cookOrderId=$cookOrderId")
|
||||||
// isCooking=false:从前一页面带入主辅材数据;isCooking=true:从数据库查询
|
// isCooking=false:从前一页面带入主辅材数据;isCooking=true:从数据库查询
|
||||||
if (food?.isCooking == false) {
|
if (food?.isCooking == false) {
|
||||||
goodsList = getSerializable(GOODS_LIST) as MutableList<CookFoodGoodsEntity>?
|
goodsList = getSerializable(GOODS_LIST) as MutableList<CookFoodGoodsEntity>?
|
||||||
@@ -339,8 +346,10 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
binding.btnSubmit.clickWithDebounce {
|
binding.btnSubmit.clickWithDebounce {
|
||||||
if (cookFoodEntity.foodWeight <= 0.toDouble()) {
|
if (cookFoodEntity.foodWeight <= 0.toDouble()) {
|
||||||
toast("未识别到菜品熟重")
|
// 测试设备无秤硬件,使用模拟熟重 500g
|
||||||
return@clickWithDebounce
|
cookFoodEntity.foodWeight = 500.0
|
||||||
|
binding.tvTotalWeight.text = "500.0"
|
||||||
|
binding.tvWeightUnit.text = "克"
|
||||||
}
|
}
|
||||||
val content = getRemindSpannable("制作完成")
|
val content = getRemindSpannable("制作完成")
|
||||||
showRemindDialog(content) { submit() }
|
showRemindDialog(content) { submit() }
|
||||||
@@ -418,12 +427,18 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
// 先移除 goodsList 中已有的调料数据(materialType==3),再以 adapter 中最新调料覆盖
|
// 先移除 goodsList 中已有的调料数据(materialType==3),再以 adapter 中最新调料覆盖
|
||||||
goodsList?.removeAll { it.materialType == 3 }
|
goodsList?.removeAll { it.materialType == 3 }
|
||||||
// 主辅材 foodId 统一以菜品 foodId 为准;新加调料行的 foodId 由 buildSeasoningEntity 内部设置
|
|
||||||
goodsList?.forEach { it.foodId = cookFoodEntity.foodId }
|
goodsList?.forEach { it.foodId = cookFoodEntity.foodId }
|
||||||
seasoningAdapter.items
|
seasoningAdapter.items
|
||||||
.filter { it.useWeight > 0.0 }
|
.filter { it.useWeight > 0.0 }
|
||||||
.forEach { goodsList?.add(buildSeasoningEntity(it)) }
|
.forEach { goodsList?.add(buildSeasoningEntity(it)) }
|
||||||
|
|
||||||
|
// 制作模式 + 有烹制单 ID → 调新配比秤烹饪完成接口
|
||||||
|
if (!cookOrderId.isNullOrBlank() && food?.cookMode == 0) {
|
||||||
|
submitWithNewApi()
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
|
||||||
|
// 旧接口路径(采样模式 / 无烹制单 ID)
|
||||||
cookFoodEntity.let {
|
cookFoodEntity.let {
|
||||||
it.matchingConstituteInfoList = this@SubmitFoodActivity.goodsList
|
it.matchingConstituteInfoList = this@SubmitFoodActivity.goodsList
|
||||||
it.dinnerType = when (it.dinnerType) {
|
it.dinnerType = when (it.dinnerType) {
|
||||||
@@ -434,18 +449,74 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 仅本地生成的临时 foodId 需清空,由服务器分配真实 ID;服务器下发的真实 foodId 直接保留
|
|
||||||
if (cookFoodEntity.foodId.startsWith(LOCAL_ID_PREFIX)) {
|
if (cookFoodEntity.foodId.startsWith(LOCAL_ID_PREFIX)) {
|
||||||
cookFoodEntity.foodId = ""
|
cookFoodEntity.foodId = ""
|
||||||
goodsList?.forEach { it.foodId = "" }
|
goodsList?.forEach { it.foodId = "" }
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "submit: json=${cookFoodEntity.toJsonString()}")
|
Log.d(TAG, "submit: json=${cookFoodEntity.toJsonString()}")
|
||||||
// 接口提交使用 DTO,与本地 Room 实体解耦
|
|
||||||
netViewModel.submitCookFood(entity = cookFoodEntity.toDTO())
|
netViewModel.submitCookFood(entity = cookFoodEntity.toDTO())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新配比秤烹饪完成接口:从 goodsList 提取主辅材和调料,组装 CookCompleteRequest 提交
|
||||||
|
* 熟重 foodWeight(g) → cookedWeight(kg)
|
||||||
|
*/
|
||||||
|
private fun submitWithNewApi() {
|
||||||
|
val allGoods = goodsList ?: return
|
||||||
|
|
||||||
|
// 主辅材:materialType 1(主材) 或 2(辅材)
|
||||||
|
val items = allGoods
|
||||||
|
.filter { it.materialType == 1 || it.materialType == 2 }
|
||||||
|
.map { CookCompleteItem(
|
||||||
|
materId = it.materId?.takeIf { mid -> mid.isNotEmpty() } ?: it.goodsId,
|
||||||
|
actualQty = it.useWeight ?: 0.0
|
||||||
|
) }
|
||||||
|
|
||||||
|
if (items.isEmpty()) {
|
||||||
|
toast("无主辅材构成信息")
|
||||||
|
dismissLoading()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 调料:materialType 3
|
||||||
|
val seasonings = allGoods
|
||||||
|
.filter { it.materialType == 3 }
|
||||||
|
.map { CookCompleteItem(
|
||||||
|
materId = it.materId?.takeIf { mid -> mid.isNotEmpty() } ?: it.goodsId,
|
||||||
|
actualQty = it.useWeight ?: 0.0
|
||||||
|
) }
|
||||||
|
.takeIf { it.isNotEmpty() }
|
||||||
|
|
||||||
|
// 熟重 g → kg,保留 3 位小数
|
||||||
|
val cookedWeightKg = (cookFoodEntity.foodWeight / 1000.0).roundedDecimalPlace(3)
|
||||||
|
|
||||||
|
val request = CookCompleteRequest(
|
||||||
|
cookOrderId = cookOrderId ?: "",
|
||||||
|
items = items,
|
||||||
|
cookedWeight = cookedWeightKg,
|
||||||
|
seasonings = seasonings
|
||||||
|
)
|
||||||
|
|
||||||
|
Log.d(TAG, "submitWithNewApi: ${request.toJsonString()}")
|
||||||
|
|
||||||
|
val isSamplingData = food?.cookMode == 1
|
||||||
|
netViewModel.cookOrderComplete(
|
||||||
|
request = request,
|
||||||
|
onResult = { state ->
|
||||||
|
when (state) {
|
||||||
|
is UiState.Success -> submitSuccess(isSamplingData)
|
||||||
|
is UiState.Error -> {
|
||||||
|
toast(state.msg)
|
||||||
|
dismissLoading()
|
||||||
|
}
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将 adapter 中的调料 item 转换为 CookFoodGoodsEntity
|
* 将 adapter 中的调料 item 转换为 CookFoodGoodsEntity
|
||||||
* 从本地 dm_seasoning 表补充完整字段(popularName、zjmCode、materId、goodsCode 等)
|
* 从本地 dm_seasoning 表补充完整字段(popularName、zjmCode、materId、goodsCode 等)
|
||||||
|
|||||||
@@ -70,6 +70,9 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
|||||||
/** 首次加载标记,首次请求时传 mealType=null 获取全餐次数据,后续切换传具体餐次 */
|
/** 首次加载标记,首次请求时传 mealType=null 获取全餐次数据,后续切换传具体餐次 */
|
||||||
private var isFirstLoad = true
|
private var isFirstLoad = true
|
||||||
|
|
||||||
|
/** foodId → cookOrderId 映射,用于跳转 PrepareFoodActivity 时传递烹制单 ID */
|
||||||
|
private val cookOrderIdMap = mutableMapOf<String, String>()
|
||||||
|
|
||||||
/** 第一页时先查数据库存入此字段,网络结果回来后直接使用,避免时序问题 */
|
/** 第一页时先查数据库存入此字段,网络结果回来后直接使用,避免时序问题 */
|
||||||
private var pendingLocalList: MutableList<CookFoodEntity>? = null
|
private var pendingLocalList: MutableList<CookFoodEntity>? = null
|
||||||
|
|
||||||
@@ -93,12 +96,14 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
|||||||
// 烹饪中,跳到称熟重页面
|
// 烹饪中,跳到称熟重页面
|
||||||
activity.startActivity<SubmitFoodActivity> {
|
activity.startActivity<SubmitFoodActivity> {
|
||||||
putExtra(SubmitFoodActivity.FOOD_ITEM, item as Serializable)
|
putExtra(SubmitFoodActivity.FOOD_ITEM, item as Serializable)
|
||||||
|
putExtra(SubmitFoodActivity.COOK_ORDER_ID, cookOrderIdMap[item.foodId])
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
item.dinnerType = dinnerType
|
item.dinnerType = dinnerType
|
||||||
activity.startActivity<PrepareFoodActivity> {
|
activity.startActivity<PrepareFoodActivity> {
|
||||||
putExtra(PrepareFoodActivity.FOOD_ITEM, item as Serializable)
|
putExtra(PrepareFoodActivity.FOOD_ITEM, item as Serializable)
|
||||||
|
putExtra(PrepareFoodActivity.COOK_ORDER_ID, cookOrderIdMap[item.foodId])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,7 +308,9 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
|||||||
return FoodRecord(
|
return FoodRecord(
|
||||||
foodId = foodId,
|
foodId = foodId,
|
||||||
foodName = dishName,
|
foodName = dishName,
|
||||||
totalWeight = ((rawWeight ?: 0.0) * 1000),
|
totalWeight = ((cookedWeight ?: 0.0) * 1000),
|
||||||
|
foodWeight = ((cookedWeight ?: 0.0) * 1000),
|
||||||
|
count = cookedPortions,
|
||||||
cookMode = 0,
|
cookMode = 0,
|
||||||
isCooking = cookStatus == 1,
|
isCooking = cookStatus == 1,
|
||||||
dinnerType = mealType.toString(),
|
dinnerType = mealType.toString(),
|
||||||
@@ -327,6 +334,13 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
|||||||
val cookOrders = groups
|
val cookOrders = groups
|
||||||
?.firstOrNull { it.mealType == targetMealType }
|
?.firstOrNull { it.mealType == targetMealType }
|
||||||
?.cookOrders
|
?.cookOrders
|
||||||
|
// 更新 foodId → cookOrderId 映射(从全量分组构建,跨餐次)
|
||||||
|
groups?.forEach { group ->
|
||||||
|
group.cookOrders.forEach { order ->
|
||||||
|
cookOrderIdMap[order.foodId] = order.cookOrderId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cookOrders.isNullOrEmpty() && localList.isNullOrEmpty()) {
|
if (cookOrders.isNullOrEmpty() && localList.isNullOrEmpty()) {
|
||||||
loadEmptyView()
|
loadEmptyView()
|
||||||
finishRefresh()
|
finishRefresh()
|
||||||
|
|||||||
Reference in New Issue
Block a user