refactor(activity): 统一 cook/submit 中调料数据处理逻辑,先清除 materialType==3 再从 adapter 覆盖写入
This commit is contained in:
@@ -293,11 +293,6 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
toast("未获取到菜品或构成信息")
|
toast("未获取到菜品或构成信息")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val seasoningData = seasoningAdapter.items
|
|
||||||
// if (seasoningData.isEmpty()) {
|
|
||||||
// toast("未获取到调料信息")
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
showLoading()
|
showLoading()
|
||||||
|
|
||||||
val isSamplingData = food!!.cookMode == 1
|
val isSamplingData = food!!.cookMode == 1
|
||||||
@@ -316,23 +311,11 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
else -> it.dinnerType
|
else -> it.dinnerType
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 将调料数据转为 CookFoodGoodsEntity 追加到 goodsList
|
// 先移除 goodsList 中已有的调料数据(materialType==3),再以 adapter 中最新调料覆盖
|
||||||
val tempSeasoningList = seasoningData.map { item ->
|
goodsList?.removeAll { it.materialType == 3 }
|
||||||
val seasoning = appViewModel.getSeasoningByGoodsId(item.goodsId)
|
seasoningAdapter.items
|
||||||
CookFoodGoodsEntity().also { entity ->
|
.filter { it.useWeight > 0.0 }
|
||||||
entity.goodsId = item.goodsId
|
.forEach { goodsList?.add(buildSeasoningEntity(it)) }
|
||||||
entity.goodsName = item.goodsName
|
|
||||||
entity.useWeight = item.useWeight
|
|
||||||
entity.materialType = 3
|
|
||||||
entity.popularName = seasoning?.popularName
|
|
||||||
entity.zjmCode = seasoning?.zjmCode
|
|
||||||
entity.materId = seasoning?.materId
|
|
||||||
entity.relateionType = seasoning?.relateionType ?: 0
|
|
||||||
entity.allEdible = seasoning?.allEdible ?: true
|
|
||||||
entity.goodsOrRelationCode = seasoning?.goodsOrRelationCode
|
|
||||||
}
|
|
||||||
}
|
|
||||||
goodsList?.addAll(tempSeasoningList)
|
|
||||||
appViewModel.saveCookFoodAndGoods(
|
appViewModel.saveCookFoodAndGoods(
|
||||||
cookMode = food!!.cookMode,
|
cookMode = food!!.cookMode,
|
||||||
entity = cookFoodEntity,
|
entity = cookFoodEntity,
|
||||||
@@ -348,28 +331,14 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
toast("未获取到菜品或构成信息")
|
toast("未获取到菜品或构成信息")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val seasoningData = seasoningAdapter.items
|
|
||||||
showLoading()
|
showLoading()
|
||||||
|
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
// 将重量大于0且不重复的调料追加到 goodsList
|
// 先移除 goodsList 中已有的调料数据(materialType==3),再以 adapter 中最新调料覆盖
|
||||||
seasoningData.forEach { item ->
|
goodsList?.removeAll { it.materialType == 3 }
|
||||||
if (item.useWeight > 0.0 && goodsList?.none { it.goodsId == item.goodsId } == true) {
|
seasoningAdapter.items
|
||||||
val seasoning = appViewModel.getSeasoningByGoodsId(item.goodsId)
|
.filter { it.useWeight > 0.0 }
|
||||||
goodsList?.add(CookFoodGoodsEntity().also { entity ->
|
.forEach { goodsList?.add(buildSeasoningEntity(it)) }
|
||||||
entity.goodsId = item.goodsId
|
|
||||||
entity.goodsName = item.goodsName
|
|
||||||
entity.useWeight = item.useWeight
|
|
||||||
entity.materialType = 3
|
|
||||||
entity.popularName = seasoning?.popularName
|
|
||||||
entity.zjmCode = seasoning?.zjmCode
|
|
||||||
entity.materId = seasoning?.materId
|
|
||||||
entity.relateionType = seasoning?.relateionType ?: 0
|
|
||||||
entity.allEdible = seasoning?.allEdible ?: true
|
|
||||||
entity.goodsOrRelationCode = seasoning?.goodsOrRelationCode
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cookFoodEntity.let {
|
cookFoodEntity.let {
|
||||||
it.matchingConstituteInfoList = this@SubmitFoodActivity.goodsList
|
it.matchingConstituteInfoList = this@SubmitFoodActivity.goodsList
|
||||||
@@ -392,6 +361,27 @@ class SubmitFoodActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将 adapter 中的调料 item 转换为 CookFoodGoodsEntity
|
||||||
|
* 从本地 dm_seasoning 表补充完整字段(popularName、zjmCode、materId、goodsCode 等)
|
||||||
|
*/
|
||||||
|
private suspend fun buildSeasoningEntity(item: SeasoningWeightAdapter.Item): CookFoodGoodsEntity {
|
||||||
|
val seasoning = appViewModel.getSeasoningByGoodsId(item.goodsId)
|
||||||
|
return CookFoodGoodsEntity().also { entity ->
|
||||||
|
entity.goodsId = item.goodsId
|
||||||
|
entity.goodsName = item.goodsName
|
||||||
|
entity.useWeight = item.useWeight
|
||||||
|
entity.materialType = 3
|
||||||
|
entity.popularName = seasoning?.popularName
|
||||||
|
entity.zjmCode = seasoning?.zjmCode
|
||||||
|
entity.materId = seasoning?.materId
|
||||||
|
entity.goodsCode = seasoning?.goodsCode
|
||||||
|
entity.relateionType = seasoning?.relateionType ?: 0
|
||||||
|
entity.allEdible = seasoning?.allEdible ?: true
|
||||||
|
entity.goodsOrRelationCode = seasoning?.goodsOrRelationCode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun submitSuccess(isSamplingData: Boolean) {
|
private fun submitSuccess(isSamplingData: Boolean) {
|
||||||
if (food?.foodId.isNullOrBlank()) {
|
if (food?.foodId.isNullOrBlank()) {
|
||||||
dismissLoading()
|
dismissLoading()
|
||||||
|
|||||||
Reference in New Issue
Block a user