fix(prepareCook): 修复食材选择和数据处理逻辑
- 修复了食材选择回调中的变量命名问题,统一使用 entity 替代 item - 改进了食材名称解析逻辑,正确提取 WP 标识符和食材名称 - 为食材 ID 提取添加了边界情况处理,避免数组越界异常 - 添加了调试日志以便追踪食材查询结果 - 优化了食材列表数据结构的构建过程
This commit is contained in:
@@ -209,14 +209,14 @@ class PrepareCookActivity : BaseActivity() {
|
|||||||
* - list 中不含该 goodsId:直接新增,isNewDishType = true
|
* - list 中不含该 goodsId:直接新增,isNewDishType = true
|
||||||
* - list 中已含该 goodsId:累加 useWeight
|
* - list 中已含该 goodsId:累加 useWeight
|
||||||
*/
|
*/
|
||||||
private val foodSelectCallback: (CookFoodGoodsEntity) -> Unit = { item ->
|
private val foodSelectCallback: (CookFoodGoodsEntity) -> Unit = { entity ->
|
||||||
val existing = list.firstOrNull { it.goodsId == item.goodsId }
|
val existing = list.firstOrNull { it.goodsId == entity.goodsId }
|
||||||
if (existing != null) {
|
if (existing != null) {
|
||||||
existing.useWeight = (existing.useWeight ?: 0.0) + (item.useWeight ?: 0.0)
|
existing.useWeight = (existing.useWeight ?: 0.0) + (entity.useWeight ?: 0.0)
|
||||||
existing.isSetFinished = true
|
existing.isSetFinished = true
|
||||||
dishPartAdapter.notifyItemChanged(list.indexOf(existing))
|
dishPartAdapter.notifyItemChanged(list.indexOf(existing))
|
||||||
} else {
|
} else {
|
||||||
list.add(item.also {
|
list.add(entity.also {
|
||||||
it.isNewDishType = true
|
it.isNewDishType = true
|
||||||
it.isSetFinished = true
|
it.isSetFinished = true
|
||||||
})
|
})
|
||||||
@@ -477,10 +477,19 @@ class PrepareCookActivity : BaseActivity() {
|
|||||||
//调用接口成功,返回食材列表设置isTakingPhoto.set(false),暂时写死数据
|
//调用接口成功,返回食材列表设置isTakingPhoto.set(false),暂时写死数据
|
||||||
val foodList = mutableListOf<CookFoodGoodsEntity>()
|
val foodList = mutableListOf<CookFoodGoodsEntity>()
|
||||||
list.forEachIndexed { index, food ->
|
list.forEachIndexed { index, food ->
|
||||||
val foodName = food.name.split("WP").first()
|
var foodName = ""
|
||||||
|
var foodId = ""
|
||||||
|
food.name.split("WP").let {
|
||||||
|
foodName = it[0]
|
||||||
|
foodId = if (it.size > 1) {
|
||||||
|
"WP${it[1]}"
|
||||||
|
} else {
|
||||||
|
food.name
|
||||||
|
}
|
||||||
|
}
|
||||||
foodList.add(
|
foodList.add(
|
||||||
CookFoodGoodsEntity(
|
CookFoodGoodsEntity(
|
||||||
goodsId = "${food.id}",
|
goodsId = foodId,
|
||||||
goodsName = foodName,
|
goodsName = foodName,
|
||||||
foodId = index.toString()
|
foodId = index.toString()
|
||||||
).also {
|
).also {
|
||||||
@@ -493,12 +502,13 @@ class PrepareCookActivity : BaseActivity() {
|
|||||||
activity = this,
|
activity = this,
|
||||||
imageUri = lastPhotoUri?.toString(),
|
imageUri = lastPhotoUri?.toString(),
|
||||||
goodsList = ArrayList(foodList),
|
goodsList = ArrayList(foodList),
|
||||||
finishCallback = { isManualCancel, item ->
|
finishCallback = { isManualCancel, entity ->
|
||||||
|
Log.d(TAG, "queryFood: isManualCancel=$isManualCancel, entity=${entity.toJsonString()}")
|
||||||
manualCancelFlag = isManualCancel
|
manualCancelFlag = isManualCancel
|
||||||
if (isManualCancel) {
|
if (isManualCancel) {
|
||||||
return@start
|
return@start
|
||||||
}
|
}
|
||||||
item?.let {
|
entity?.let {
|
||||||
foodSelectCallback(it)
|
foodSelectCallback(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user