优化
This commit is contained in:
@@ -42,16 +42,16 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun saveCookFood(cookMode: Int, entity: CookFoodEntity) {
|
||||
viewModelScope.launch {
|
||||
val data = rep.getCookFoodById(entity.foodId, cookMode)
|
||||
if (data == null) {
|
||||
rep.insertCookFood(entity)
|
||||
return@launch
|
||||
}
|
||||
rep.updateCookFood(entity)
|
||||
}
|
||||
}
|
||||
// fun saveCookFood(cookMode: Int, entity: CookFoodEntity) {
|
||||
// viewModelScope.launch {
|
||||
// val data = rep.getCookFoodById(entity.foodId, cookMode)
|
||||
// if (data == null) {
|
||||
// rep.insertCookFood(entity)
|
||||
// return@launch
|
||||
// }
|
||||
// rep.updateCookFood(entity)
|
||||
// }
|
||||
// }
|
||||
|
||||
fun saveCookFoodAndGoods(
|
||||
cookMode: Int,
|
||||
@@ -68,7 +68,12 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
|
||||
}
|
||||
//重新保存数据
|
||||
rep.insertCookFood(entity)
|
||||
list?.let { rep.insertGoodsList(it) }
|
||||
list?.let { it ->
|
||||
it.forEach { goods->
|
||||
goods.id = 0
|
||||
}
|
||||
rep.insertGoodsList(it)
|
||||
}
|
||||
onFinish()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user