fix(activity): 修复调料 foodId 为空导致重新打开看不到调料数据
This commit is contained in:
@@ -46,6 +46,9 @@ 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"
|
||||||
|
|
||||||
|
/** 本地临时 foodId 前缀;以此开头说明菜品尚未在服务器登记,提交时需清空让服务器分配真实 ID */
|
||||||
|
const val LOCAL_ID_PREFIX = "localId_"
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var binding: ActivitySubmitFoodBinding
|
private lateinit var binding: ActivitySubmitFoodBinding
|
||||||
@@ -298,9 +301,11 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
|
|
||||||
val isSamplingData = food!!.cookMode == 1
|
val isSamplingData = food!!.cookMode == 1
|
||||||
if (isSamplingData) {
|
if (isSamplingData) {
|
||||||
val tempFoodId = cookFoodEntity.foodId.ifBlank { "${System.currentTimeMillis()}" }
|
val tempFoodId = cookFoodEntity.foodId
|
||||||
|
.ifBlank { "$LOCAL_ID_PREFIX${System.currentTimeMillis()}" }
|
||||||
cookFoodEntity.foodId = tempFoodId
|
cookFoodEntity.foodId = tempFoodId
|
||||||
}
|
}
|
||||||
|
// 主辅材统一在此赋 foodId;新加的调料行 foodId 由 buildSeasoningEntity 内部设置
|
||||||
goodsList?.forEach { it.foodId = cookFoodEntity.foodId }
|
goodsList?.forEach { it.foodId = cookFoodEntity.foodId }
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
@@ -337,6 +342,8 @@ 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 }
|
||||||
seasoningAdapter.items
|
seasoningAdapter.items
|
||||||
.filter { it.useWeight > 0.0 }
|
.filter { it.useWeight > 0.0 }
|
||||||
.forEach { goodsList?.add(buildSeasoningEntity(it)) }
|
.forEach { goodsList?.add(buildSeasoningEntity(it)) }
|
||||||
@@ -351,8 +358,8 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val isSamplingData = food!!.cookMode == 1
|
// 仅本地生成的临时 foodId 需清空,由服务器分配真实 ID;服务器下发的真实 foodId 直接保留
|
||||||
if (isSamplingData) {
|
if (cookFoodEntity.foodId.startsWith(LOCAL_ID_PREFIX)) {
|
||||||
cookFoodEntity.foodId = ""
|
cookFoodEntity.foodId = ""
|
||||||
goodsList?.forEach { it.foodId = "" }
|
goodsList?.forEach { it.foodId = "" }
|
||||||
}
|
}
|
||||||
@@ -370,6 +377,7 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
private suspend fun buildSeasoningEntity(item: SeasoningWeightAdapter.Item): CookFoodGoodsEntity {
|
private suspend fun buildSeasoningEntity(item: SeasoningWeightAdapter.Item): CookFoodGoodsEntity {
|
||||||
val seasoning = appViewModel.getSeasoningByGoodsId(item.goodsId)
|
val seasoning = appViewModel.getSeasoningByGoodsId(item.goodsId)
|
||||||
return CookFoodGoodsEntity().also { entity ->
|
return CookFoodGoodsEntity().also { entity ->
|
||||||
|
entity.foodId = cookFoodEntity.foodId
|
||||||
entity.goodsId = item.goodsId
|
entity.goodsId = item.goodsId
|
||||||
entity.goodsName = item.goodsName
|
entity.goodsName = item.goodsName
|
||||||
entity.useWeight = item.useWeight
|
entity.useWeight = item.useWeight
|
||||||
|
|||||||
Reference in New Issue
Block a user