fix(activity): 修复调料 foodId 为空导致重新打开看不到调料数据
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user