制作模式、采样模式数据保存支持多食堂模式,制作模式查询菜品列表和搜索菜品增加餐次字段,设置页面增加隐藏默认数据导入功能
This commit is contained in:
@@ -1,15 +1,11 @@
|
||||
package com.shuwei.dish.match.viewmodel
|
||||
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.db.AppRepository
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.collections.forEach
|
||||
|
||||
@@ -28,9 +24,13 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun getCookFoodList(cookMode: Int, action: (MutableList<CookFoodEntity>?) -> Unit) {
|
||||
fun getCookFoodList(
|
||||
cookMode: Int,
|
||||
dinnerType: String = "0",
|
||||
action: (MutableList<CookFoodEntity>?) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
val data = rep.getCookFoodList(cookMode)
|
||||
val data = rep.getCookFoodList(cookMode, dinnerType)
|
||||
action(data)
|
||||
}
|
||||
}
|
||||
@@ -64,13 +64,15 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
|
||||
if (data != null) {
|
||||
//存在数据删除
|
||||
rep.deleteCookFood(entity.foodId, cookMode)
|
||||
rep.deleteCookFoodGoodsList(entity.foodId)
|
||||
rep.deleteCookFoodGoodsList(data.id, entity.foodId)
|
||||
}
|
||||
//重新保存数据
|
||||
rep.insertCookFood(entity)
|
||||
val newData = rep.getCookFoodById(entity.foodId, cookMode)
|
||||
list?.let { it ->
|
||||
it.forEach { goods->
|
||||
it.forEach { goods ->
|
||||
goods.id = 0
|
||||
goods.pid = newData?.id?:0
|
||||
}
|
||||
rep.insertGoodsList(it)
|
||||
}
|
||||
@@ -84,8 +86,11 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
|
||||
onFinish: () -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
rep.deleteCookFood(foodId = foodId, cookMode = cookMode)
|
||||
rep.deleteCookFoodGoodsList(foodId)
|
||||
val data = rep.getCookFoodById(foodId, cookMode)
|
||||
if (data != null) {
|
||||
rep.deleteCookFood(foodId = foodId, cookMode = cookMode)
|
||||
rep.deleteCookFoodGoodsList(pid = data.id, foodId = foodId)
|
||||
}
|
||||
onFinish()
|
||||
}
|
||||
}
|
||||
@@ -95,50 +100,54 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
|
||||
|
||||
fun getCookFoodGoodsList(
|
||||
foodId: String,
|
||||
cookMode: Int,
|
||||
action: (list: MutableList<CookFoodGoodsEntity>) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
val list = rep.getCookFoodGoodsList(foodId)
|
||||
action(list)
|
||||
val cookFood = rep.getCookFoodById(foodId, cookMode)
|
||||
cookFood?.let {
|
||||
val list = rep.getCookFoodGoodsList(pid = it.id, foodId = it.foodId)
|
||||
action(list)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun updateGoods(entity: CookFoodGoodsEntity) {
|
||||
viewModelScope.launch {
|
||||
rep.updateGoods(entity)
|
||||
}
|
||||
}
|
||||
// fun updateGoods(entity: CookFoodGoodsEntity) {
|
||||
// viewModelScope.launch {
|
||||
// rep.updateGoods(entity)
|
||||
// }
|
||||
// }
|
||||
|
||||
fun saveCookFoodGoods(list: MutableList<CookFoodGoodsEntity>) {
|
||||
viewModelScope.launch {
|
||||
val foodId = list[0].foodId
|
||||
val data: MutableList<CookFoodGoodsEntity>? =
|
||||
rep.getCookFoodGoodsList(foodId!!)
|
||||
if (data.isNullOrEmpty()) {
|
||||
rep.insertGoodsList(list)
|
||||
return@launch
|
||||
}
|
||||
val localDbSeasoningList = rep.getCookFoodGoodsListByType(foodId, 3)
|
||||
localDbSeasoningList.forEach {
|
||||
it.isDel = 1
|
||||
//更新本地调料数据为已删除的状态
|
||||
rep.updateGoods(it)
|
||||
}
|
||||
//筛选出调料数据保存,主辅材不会变更不需要再次处理
|
||||
val saveSeasoningList = list.filter { it.materialType == 3 }
|
||||
rep.insertGoodsList(saveSeasoningList.toMutableList())
|
||||
}
|
||||
}
|
||||
// fun saveCookFoodGoods(list: MutableList<CookFoodGoodsEntity>) {
|
||||
// viewModelScope.launch {
|
||||
// val foodId = list[0].foodId
|
||||
// val data: MutableList<CookFoodGoodsEntity>? =
|
||||
// rep.getCookFoodGoodsList(foodId!!)
|
||||
// if (data.isNullOrEmpty()) {
|
||||
// rep.insertGoodsList(list)
|
||||
// return@launch
|
||||
// }
|
||||
// val localDbSeasoningList = rep.getCookFoodGoodsListByType(foodId, 3)
|
||||
// localDbSeasoningList.forEach {
|
||||
// it.isDel = 1
|
||||
// //更新本地调料数据为已删除的状态
|
||||
// rep.updateGoods(it)
|
||||
// }
|
||||
// //筛选出调料数据保存,主辅材不会变更不需要再次处理
|
||||
// val saveSeasoningList = list.filter { it.materialType == 3 }
|
||||
// rep.insertGoodsList(saveSeasoningList.toMutableList())
|
||||
// }
|
||||
// }
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------
|
||||
|
||||
fun addSeasoning(list: MutableList<SeasoningEntity>, callback: () -> Unit) {
|
||||
viewModelScope.launch {
|
||||
rep.deleteBatch()
|
||||
rep.insertSeasoningList(items = list)
|
||||
callback()
|
||||
}
|
||||
}
|
||||
// fun addSeasoning(list: MutableList<SeasoningEntity>, callback: () -> Unit) {
|
||||
// viewModelScope.launch {
|
||||
// rep.deleteBatch()
|
||||
// rep.insertSeasoningList(items = list)
|
||||
// callback()
|
||||
// }
|
||||
// }
|
||||
|
||||
private var isProcessing = false
|
||||
fun loadSeasoning(action: (list: MutableList<SeasoningEntity>) -> Unit) {
|
||||
@@ -157,9 +166,11 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
|
||||
rep.deleteEmptySeasoning()
|
||||
}
|
||||
}
|
||||
fun deleteAll() {
|
||||
|
||||
fun clearAllSeasoning(action:()->Unit) {
|
||||
viewModelScope.launch {
|
||||
rep.deleteBatch()
|
||||
rep.clearAllSeasoning()
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +182,7 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun saveSeasoning(entity: SeasoningEntity, block:()-> Unit) {
|
||||
fun saveSeasoning(entity: SeasoningEntity, block: () -> Unit) {
|
||||
viewModelScope.launch {
|
||||
val seasoning = rep.getSeasoningBySort(entity.sort)
|
||||
if (seasoning == null) {
|
||||
|
||||
Reference in New Issue
Block a user