From 0b9b3e8988cdcbabd82cb6bb8513ce33c3902d4a Mon Sep 17 00:00:00 2001 From: lvmeng <848755140@qq.com> Date: Mon, 11 May 2026 14:39:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(activity):=20=E4=BF=AE=E5=A4=8D=E8=B0=83?= =?UTF-8?q?=E6=96=99=20foodId=20=E4=B8=BA=E7=A9=BA=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=89=93=E5=BC=80=E7=9C=8B=E4=B8=8D=E5=88=B0?= =?UTF-8?q?=E8=B0=83=E6=96=99=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/shuwei/dish/match/ui/SubmitFoodActivity.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/shuwei/dish/match/ui/SubmitFoodActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/SubmitFoodActivity.kt index 93bf3ea..51ba1b8 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/SubmitFoodActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/SubmitFoodActivity.kt @@ -46,6 +46,9 @@ class SubmitFoodActivity : BaseActivity() { const val TAG = "SubmitFoodActivity" const val FOOD_ITEM = "foodItem" const val GOODS_LIST = "goodsList" + + /** 本地临时 foodId 前缀;以此开头说明菜品尚未在服务器登记,提交时需清空让服务器分配真实 ID */ + const val LOCAL_ID_PREFIX = "localId_" } private lateinit var binding: ActivitySubmitFoodBinding @@ -298,9 +301,11 @@ class SubmitFoodActivity : BaseActivity() { val isSamplingData = food!!.cookMode == 1 if (isSamplingData) { - val tempFoodId = cookFoodEntity.foodId.ifBlank { "${System.currentTimeMillis()}" } + val tempFoodId = cookFoodEntity.foodId + .ifBlank { "$LOCAL_ID_PREFIX${System.currentTimeMillis()}" } cookFoodEntity.foodId = tempFoodId } + // 主辅材统一在此赋 foodId;新加的调料行 foodId 由 buildSeasoningEntity 内部设置 goodsList?.forEach { it.foodId = cookFoodEntity.foodId } lifecycleScope.launch { @@ -337,6 +342,8 @@ class SubmitFoodActivity : BaseActivity() { lifecycleScope.launch { // 先移除 goodsList 中已有的调料数据(materialType==3),再以 adapter 中最新调料覆盖 goodsList?.removeAll { it.materialType == 3 } + // 主辅材 foodId 统一以菜品 foodId 为准;新加调料行的 foodId 由 buildSeasoningEntity 内部设置 + goodsList?.forEach { it.foodId = cookFoodEntity.foodId } seasoningAdapter.items .filter { it.useWeight > 0.0 } .forEach { goodsList?.add(buildSeasoningEntity(it)) } @@ -351,8 +358,8 @@ class SubmitFoodActivity : BaseActivity() { } } - val isSamplingData = food!!.cookMode == 1 - if (isSamplingData) { + // 仅本地生成的临时 foodId 需清空,由服务器分配真实 ID;服务器下发的真实 foodId 直接保留 + if (cookFoodEntity.foodId.startsWith(LOCAL_ID_PREFIX)) { cookFoodEntity.foodId = "" goodsList?.forEach { it.foodId = "" } } @@ -370,6 +377,7 @@ class SubmitFoodActivity : BaseActivity() { private suspend fun buildSeasoningEntity(item: SeasoningWeightAdapter.Item): CookFoodGoodsEntity { val seasoning = appViewModel.getSeasoningByGoodsId(item.goodsId) return CookFoodGoodsEntity().also { entity -> + entity.foodId = cookFoodEntity.foodId entity.goodsId = item.goodsId entity.goodsName = item.goodsName entity.useWeight = item.useWeight