制作模式、采样模式数据保存支持多食堂模式,制作模式查询菜品列表和搜索菜品增加餐次字段,设置页面增加隐藏默认数据导入功能

This commit is contained in:
2025-08-18 16:26:13 +08:00
parent 3a97b718dd
commit 59c15271d9
24 changed files with 618 additions and 223 deletions
+2 -2
View File
@@ -4,10 +4,10 @@
<selectionStates>
<SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2025-08-15T07:06:48.695133800Z">
<DropdownSelection timestamp="2025-08-18T06:18:22.594579400Z">
<Target type="DEFAULT_BOOT">
<handle>
<DeviceId pluginId="Default" identifier="serial=192.168.1.185:5555;connection=66c1b774" />
<DeviceId pluginId="Default" identifier="serial=192.168.1.185:5555;connection=2158168e" />
</handle>
</Target>
</DropdownSelection>
@@ -0,0 +1,208 @@
{
"list": [
{
"id" : 1,
"goodsId" : "17899",
"goodsName" : "精盐",
"foodId" : "",
"goodsOrRelationCode" : "WP0278",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "食盐、精制盐",
"canteenId" : "1678234139391512577",
"relateionType_dictText" : "食材原材料",
"sort" : 0,
"isDel" : 0,
"createTime" : "2025-08-18 10:16:17"
},
{
"id" : 2,
"goodsId" : "17901",
"goodsName" : "鸡精",
"foodId" : "",
"goodsOrRelationCode" : "WP0280",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "鸡精、家乐鸡精",
"canteenId" : "1678234139391512577",
"relateionType_dictText" : "食材原材料",
"sort" : 1,
"isDel" : 0,
"createTime" : "2025-08-18 10:17:02"
},
{
"id" : 3,
"goodsId" : "17752",
"goodsName" : "味精",
"foodId" : "",
"goodsOrRelationCode" : "WP0131",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "双桥味精,莲花味精、味精",
"canteenId" : "1678234139391512577",
"relateionType_dictText" : "食材原材料",
"sort" : 2,
"isDel" : 0,
"createTime" : "2025-08-18 10:17:16"
},
{
"id" : 4,
"goodsId" : "17800",
"goodsName" : "老抽",
"foodId" : "",
"goodsOrRelationCode" : "WP0179",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "老抽",
"canteenId" : "1678234139391512577",
"relateionType_dictText" : "食材原材料",
"sort" : 3,
"isDel" : 0,
"createTime" : "2025-08-18 10:17:26"
},
{
"id" : 5,
"goodsId" : "17749",
"goodsName" : "白醋",
"foodId" : "",
"goodsOrRelationCode" : "WP0128",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "白醋,唯加白醋",
"canteenId" : "1678234139391512577",
"relateionType_dictText" : "食材原材料",
"sort" : 4,
"isDel" : 0,
"createTime" : "2025-08-18 10:17:38"
},
{
"id" : 6,
"goodsId" : "17895",
"goodsName" : "胡椒粉",
"foodId" : "",
"goodsOrRelationCode" : "WP0274",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "胡椒粉",
"canteenId" : "1678234139391512577",
"relateionType_dictText" : "食材原材料",
"sort" : 5,
"isDel" : 0,
"createTime" : "2025-08-18 10:17:47"
},
{
"id" : 7,
"goodsId" : "329",
"goodsName" : "酱油",
"foodId" : "",
"goodsOrRelationCode" : "WP0329",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "酱油",
"canteenId" : "1678234139391512577",
"relateionType_dictText" : "食材原材料",
"sort" : 6,
"isDel" : 0,
"createTime" : "2025-08-18 10:17:55"
},
{
"id" : 8,
"goodsId" : "17733",
"goodsName" : "料酒",
"foodId" : "",
"goodsOrRelationCode" : "WP0112",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "料酒",
"canteenId" : "1678234139391512577",
"relateionType_dictText" : "食材原材料",
"sort" : 7,
"isDel" : 0,
"createTime" : "2025-08-18 10:18:14"
},
{
"id" : 9,
"goodsId" : "17889",
"goodsName" : "五香粉",
"foodId" : "",
"goodsOrRelationCode" : "WP0268",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "五香粉",
"canteenId" : "1678234139391512577",
"relateionType_dictText" : "食材原材料",
"sort" : 8,
"isDel" : 0,
"createTime" : "2025-08-18 10:18:23"
},
{
"id" : 10,
"goodsId" : "17815",
"goodsName" : "豆瓣酱",
"foodId" : "",
"goodsOrRelationCode" : "WP0194",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "豆瓣酱、郫县豆瓣酱",
"canteenId" : "1678234139391512577",
"relateionType_dictText" : "食材原材料",
"sort" : 9,
"isDel" : 0,
"createTime" : "2025-08-18 10:18:31"
},
{
"id" : 11,
"goodsId" : "17803",
"goodsName" : "生抽",
"foodId" : "",
"goodsOrRelationCode" : "WP0182",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "生抽",
"canteenId" : "1678234139391512577",
"relateionType_dictText" : "食材原材料",
"sort" : 12,
"isDel" : 0,
"createTime" : "2025-08-18 10:19:08"
},
{
"id" : 12,
"goodsId" : "18032",
"goodsName" : "菜籽油[青油]",
"foodId" : "",
"goodsOrRelationCode" : "WP0411",
"relateionType" : 1,
"materialType" : 3,
"allEdible" : 1,
"useWeight" : 0.0,
"popularName" : "菜籽油,爱菊菜籽油",
"canteenId" : "1678234139391512577",
"relateionType_dictText" : "食材原材料",
"sort" : 14,
"isDel" : 0,
"createTime" : "2025-08-18 10:19:19"
}
]
}
@@ -20,7 +20,8 @@ class BaseApp : Application() {
companion object {
const val canteenId = "1678234139391512577"
// const val canteenId = "1678234139391512577"
const val canteenId = "0"
@Volatile
private var sharedPref: SharedPreferences? = null
@@ -1,5 +1,6 @@
package com.shuwei.dish.match.db
import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.db.dao.AppDao
import com.shuwei.dish.match.entity.CookFoodEntity
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
@@ -19,41 +20,41 @@ class AppRepository(val appDao: AppDao) {
}
suspend fun getCookFoodById(foodId: String, cookMode: Int) = withContext(Dispatchers.IO) {
appDao.getCookFoodById(foodId, cookMode)
appDao.getCookFoodById(BaseApp.canteenId, foodId, cookMode)
}
suspend fun getCookFoodList(cookMode: Int) = withContext(Dispatchers.IO) {
appDao.getCookFoodList(cookMode)
suspend fun getCookFoodList(cookMode: Int, dinnerType: String) = withContext(Dispatchers.IO) {
appDao.getCookFoodList(BaseApp.canteenId, cookMode, dinnerType)
}
suspend fun countCookFood(cookMode: Int) = withContext(Dispatchers.IO) {
appDao.countCookFood(cookMode)
appDao.countCookFood(BaseApp.canteenId, cookMode)
}
suspend fun deleteCookFood(foodId: String, cookMode: Int) = withContext(Dispatchers.IO) {
appDao.deleteCookFood(foodId, cookMode)
appDao.deleteCookFood(BaseApp.canteenId, foodId, cookMode)
}
suspend fun deleteCookFoodGoodsList(foodId: String) = withContext(Dispatchers.IO) {
appDao.deleteCookFoodGoodsList(foodId)
suspend fun deleteCookFoodGoodsList(pid:Long, foodId: String) = withContext(Dispatchers.IO) {
appDao.deleteCookFoodGoodsList(pid, foodId)
}
//--------------------------------------------------------------------------------------------
suspend fun insertGoods(item: CookFoodGoodsEntity) = withContext(Dispatchers.IO) {
appDao.insertGoods(item)
}
// suspend fun insertGoods(item: CookFoodGoodsEntity) = withContext(Dispatchers.IO) {
// appDao.insertGoods(item)
// }
suspend fun insertGoodsList(items: MutableList<CookFoodGoodsEntity>) =
withContext(Dispatchers.IO) {
appDao.insertGoodsList(items)
}
suspend fun updateGoods(item: CookFoodGoodsEntity) = withContext(Dispatchers.IO) {
appDao.updateGoods(item)
}
// suspend fun updateGoods(item: CookFoodGoodsEntity) = withContext(Dispatchers.IO) {
// appDao.updateGoods(item)
// }
suspend fun getCookFoodGoodsList(foodId: String) = withContext(Dispatchers.IO) {
appDao.getCookFoodGoodsList(foodId)
suspend fun getCookFoodGoodsList(pid:Long, foodId: String) = withContext(Dispatchers.IO) {
appDao.getCookFoodGoodsList(pid, foodId)
}
suspend fun getCookFoodGoodsListByType(
@@ -84,8 +85,8 @@ class AppRepository(val appDao: AppDao) {
appDao.search(query)
}
suspend fun deleteBatch() = withContext(Dispatchers.IO) {
appDao.deleteBatch()
suspend fun clearAllSeasoning() = withContext(Dispatchers.IO) {
appDao.clearAllSeasoning()
}
suspend fun deleteEmptySeasoning() = withContext(Dispatchers.IO) {
@@ -1,7 +1,6 @@
package com.shuwei.dish.match.db.dao
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
@@ -20,17 +19,17 @@ interface AppDao {
@Update
suspend fun updateCookFood(item: CookFoodEntity)
@Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND foodId = :foodId AND cookMode = :cookMode")
suspend fun getCookFoodById(foodId: String, cookMode: Int): CookFoodEntity?
@Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND foodId = :foodId AND cookMode = :cookMode")
suspend fun getCookFoodById(canteenId:String, foodId: String, cookMode: Int): CookFoodEntity?
@Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND cookMode = :cookMode ORDER BY createTime DESC")
suspend fun getCookFoodList(cookMode: Int): MutableList<CookFoodEntity>?
@Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND cookMode = :cookMode AND dinnerType = :dinnerType ORDER BY createTime DESC")
suspend fun getCookFoodList(canteenId:String, cookMode: Int, dinnerType:String): MutableList<CookFoodEntity>?
@Query("SELECT count(1) FROM dm_cook_food WHERE isDel = 0 AND cookMode = :cookMode")
suspend fun countCookFood(cookMode: Int): Int
@Query("SELECT count(1) FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND cookMode = :cookMode")
suspend fun countCookFood(canteenId:String, cookMode: Int): Int
@Query("DELETE FROM dm_cook_food WHERE foodId = :foodId AND cookMode = :cookMode")
suspend fun deleteCookFood(foodId: String, cookMode: Int)
@Query("DELETE FROM dm_cook_food WHERE canteenId = :canteenId AND foodId = :foodId AND cookMode = :cookMode")
suspend fun deleteCookFood(canteenId:String, foodId: String, cookMode: Int)
//--------------------------------------------------------------------------------------------
@@ -43,8 +42,8 @@ interface AppDao {
@Update
suspend fun updateGoods(item: CookFoodGoodsEntity)
@Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND foodId = :foodId")
suspend fun getCookFoodGoodsList(foodId: String): MutableList<CookFoodGoodsEntity>
@Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND pid = :pid AND foodId = :foodId")
suspend fun getCookFoodGoodsList(pid:Long, foodId: String): MutableList<CookFoodGoodsEntity>
@Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND foodId = :foodId AND materialType = :materialType")
suspend fun getCookFoodGoodsListByType(
@@ -52,8 +51,8 @@ interface AppDao {
materialType: Int
): MutableList<CookFoodGoodsEntity>
@Query("DELETE FROM dm_cook_food_goods WHERE foodId = :foodId")
suspend fun deleteCookFoodGoodsList(foodId: String)
@Query("DELETE FROM dm_cook_food_goods WHERE pid = :pid AND foodId = :foodId")
suspend fun deleteCookFoodGoodsList(pid:Long, foodId: String)
//--------------------------------------------------------------------------------------------
@@ -76,7 +75,7 @@ interface AppDao {
suspend fun deleteEmptySeasoning(): Int
@Query("DELETE FROM dm_seasoning WHERE isDel = 0")
suspend fun deleteBatch(): Int
suspend fun clearAllSeasoning(): Int
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertSeasoningList(items: MutableList<SeasoningEntity>): Array<Long>
@@ -9,7 +9,8 @@ import java.time.LocalDateTime
@Entity(tableName = "dm_cook_food")
data class CookFoodEntity(
@PrimaryKey
@PrimaryKey(autoGenerate = true)
var id: Long = 0,
var foodId: String,
var foodName: String? = null,
var canteenId: String? = null,
@@ -18,6 +19,7 @@ data class CookFoodEntity(
var cookMode:Int = 0,
var isDel: Int = 0,
var createTime: String = DateTimeUtil.formatDateTime(LocalDateTime.now()),
var dinnerType: String? = "0",
) : BaseEntity {
@Ignore
var stFoodInfoConstituteList: MutableList<CookFoodGoodsEntity>? = null
@@ -12,6 +12,8 @@ import java.time.LocalDateTime
class CookFoodGoodsEntity(
@PrimaryKey(autoGenerate = true)
var id: Long = 0,
//多个食堂存在同一个foodId,使用piddm_cook_food表主键)对应父记录数据
var pid: Long = 0,
/**
* 物品id
*/
@@ -64,10 +66,13 @@ class CookFoodGoodsEntity(
@Ignore
var isSetFinished: Boolean = false
@Ignore
var isItemClicked: Boolean = false
@Ignore
var isSamplingPage: Boolean = false
@Ignore
var isNewDishType: Boolean = false
@@ -34,6 +34,10 @@ data class SeasoningRecordBean(
var page: Int
)
data class ResetReasoningRecord(
val list: MutableList<SeasoningEntity>
)
//data class DishDetailEntity(
// var foodId: String? = null,
// var foodWeight: Double? = null,
@@ -11,6 +11,8 @@ data class FoodRecord(
var isCooking: Boolean = false,
//0-制作模式,1-采样模式,2-品控模式
var cookMode: Int = 0,
//1-早餐,2-午餐,3-晚餐
var dinnerType: String = "0",
var sort: Int = 0
) : Serializable
@@ -7,27 +7,30 @@ import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan
import android.text.style.LineHeightSpan
import android.text.style.StyleSpan
import android.util.Log
import androidx.core.graphics.toColorInt
import androidx.lifecycle.ViewModelProvider
import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.SeasoningCellTool
import com.shuwei.dish.match.adapter.TextCellAdapter
import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.databinding.ActivityDeviceSettingBinding
import com.shuwei.dish.match.databinding.LayoutFoodRemindBinding
import com.shuwei.dish.match.db.AppRepository
import com.shuwei.dish.match.dialog.CommonDialog
import com.shuwei.dish.match.entity.SeasoningEntity
import com.shuwei.dish.match.entity.ResetReasoningRecord
import com.shuwei.dish.match.utils.DataUtil
import com.shuwei.dish.match.utils.JsonAssetsLoader
import com.shuwei.dish.match.utils.MultiClickDetector
import com.shuwei.dish.match.utils.WeightUtil
import com.shuwei.dish.match.utils.ext.appendText
import com.shuwei.dish.match.utils.ext.buildSpannableString
import com.shuwei.dish.match.utils.ext.dp
import com.shuwei.dish.match.utils.ext.startActivity
import com.shuwei.dish.match.utils.ext.toJsonString
import com.shuwei.dish.match.utils.ext.toast
import com.shuwei.dish.match.utils.ext.visible
import com.shuwei.dish.match.viewmodel.AppViewModel
import com.shuwei.dish.match.viewmodel.factory.AppFactory
import com.shuwei.dish.match.R
class DeviceSettingActivity : BaseActivity() {
@@ -53,8 +56,6 @@ class DeviceSettingActivity : BaseActivity() {
private lateinit var appViewModel: AppViewModel
// public lateinit var list: MutableList<SeasoningEntity>
private var cookMode: Int = 0
override fun onCreate(savedInstanceState: Bundle?) {
@@ -68,10 +69,20 @@ class DeviceSettingActivity : BaseActivity() {
it.visible()
}, titleAction = {
it.text = "设备配置"
}, rightIconActon = {
it.visible()
it.alpha = 0.0F
it.setImageResource(R.drawable.ic_setting)
it.setOnClickListener {
// appViewModel.clearAllSeasoning{
// loadSeasoning()
// }
detector.setOnDelayedMultiClickListener(it) {
defaultDataSettingDialog()
}
}
})
addListener()
loadQualitySpan(isEnable = false)
when (cookMode) {
1 -> {
@@ -80,12 +91,14 @@ class DeviceSettingActivity : BaseActivity() {
loadCookSpan(isClicked = true)
loadSamplingSpan()
}
2 -> {
binding.rbModeCook.isChecked = false
binding.rbModeSampling.isChecked = true
loadCookSpan()
loadSamplingSpan(isClicked = true)
}
else -> 0
}
@@ -107,6 +120,40 @@ class DeviceSettingActivity : BaseActivity() {
}
}
val detector = MultiClickDetector(targetCount = 10, intervalMs = 800)
private fun defaultDataSettingDialog() {
val remindBinding = LayoutFoodRemindBinding.inflate(layoutInflater)
remindBinding.tvDialogTitle.text = "温馨提示"
remindBinding.tvDialogContent.text = "您好,使用默认配置作为您的调料数据,则已有配置将被清除,确认吗?"
CommonDialog(this).apply {
messageView = remindBinding.root
leftText = "取消"
rightText = "确认"
onLeftClick = { dismiss() }
onRightClick = {
dismiss()
resetList()
}
onDismiss = { hideStatusBar() }
}.show()
}
private fun resetList() {
runCatching {
val record = JsonAssetsLoader.parseJsonFromAssets<ResetReasoningRecord>(this,"default_seasoning_list.json")
val addressArray = DataUtil.getWeighAddressArray()
val weightArray = WeightUtil.weightArray
appViewModel.clearAllSeasoning {
record?.list?.forEach { entity ->
entity.useWeight = weightArray[addressArray[entity.sort]].toDouble()
appViewModel.saveSeasoning(entity){}
}
loadSeasoning()
}
}.onFailure { it.printStackTrace() }
}
private fun initViewModel() {
val db = BaseApp.instance!!.database
val factory =
@@ -117,6 +164,10 @@ class DeviceSettingActivity : BaseActivity() {
override fun onResume() {
super.onResume()
loadSeasoning()
}
private fun loadSeasoning() {
appViewModel.loadSeasoning { it ->
SeasoningCellTool.loadData(
activity = this,
@@ -125,79 +176,9 @@ class DeviceSettingActivity : BaseActivity() {
tvCell = binding.tvRightBottomCell,
pageType = 1
)
// (binding.rvSeasoning.adapter as TextCellAdapter).let { adapter ->
// list = adapter.list
// }
}
}
// private var isCookMode: Boolean = true
private fun addListener() {
// binding.modeRadioGroup.setOnCheckedChangeListener { _, checkedId ->
// when (checkedId) {
// R.id.rbModeCook -> {
// isCookMode = true
// loadCookSpan(isClicked = true)
// loadSamplingSpan()
// loadQualitySpan(isEnable = false)
// }
//
// R.id.rbModeSampling -> {
// isCookMode = false
// loadCookSpan()
// loadSamplingSpan(isClicked = true)
// loadQualitySpan(isEnable = false)
// }
//
// R.id.rbModeQuality -> {
// loadCookSpan()
// loadSamplingSpan()
// loadQualitySpan(isEnable = false)
// }
// }
// }
// binding.btnCancel.setOnClickListener { finish() }
// binding.btnConfirm.setOnClickListener { confirmSetting() }
}
private fun confirmSetting() {
// runCatching {
// showLoading()
//// list.forEachIndexed { index, entity ->
//// entity.sort = index
//// }
//// val list2 = mutableListOf<SeasoningEntity>()
//// list2.addAll(list)
//// val array = arrayOf(10, 11, 13)
//// list.forEachIndexed { index, entity ->
//// if (entity.sort == 14 && array.contains(index)) {
//// list2.remove(entity)
//// }
//// }
// Log.d(TAG, "addListener->Click: ${list.toJsonString()}")
//
// appViewModel.addSeasoning(list) {
// dismissLoading()
// if (isCookMode) {
// startActivity<SelectDishActivity> { }
// } else {
// startActivity<SamplingListActivity> { }
// }
//// val activityStack = ActivityManager.getActivityStack()
//// activityStack.forEach {
//// if (it !is SelectDishActivity && it !is SamplingListActivity) {
//// it.finish()
//// }
//// }
// }
// }.onFailure {
// it.printStackTrace()
// toast("数据提交失败")
// }
}
private fun loadQualitySpan(isClicked: Boolean = false, isEnable: Boolean = true) {
binding.rbModeQuality.text =
@@ -257,7 +238,7 @@ class DeviceSettingActivity : BaseActivity() {
}
fun saveSeasoning(entity: SeasoningEntity) {
appViewModel.saveSeasoning(entity){
appViewModel.saveSeasoning(entity) {
toast("保存成功")
}
}
@@ -33,19 +33,22 @@ class FoodSearchActivity : BaseActivity() {
const val PAGE_TYPE = "pageType"
const val FOOD_ID = "foodId"
const val FOOD_NAME = "foodName"
const val DINNER_TYPE = "dinnerType"
}
private lateinit var binding: ActivityFoodSearchBinding
private var list: MutableList<FoodRecord> = mutableListOf()
private var pageType = 0
private var dinnerType = "0"
private val recordAdapter by lazy {
FoodRecordAdapter(list).apply {
isStateViewEnable = true
setOnItemClickListener { adapter, view, position ->
if (pageType == 1) {
val jumpItem = list[position].also { it.dinnerType = dinnerType }
startActivity<PrepareCookActivity> {
putExtra(PrepareCookActivity.FOOD_ITEM, list[position] as Serializable)
putExtra(PrepareCookActivity.FOOD_ITEM, jumpItem as Serializable)
}
return@setOnItemClickListener
}
@@ -65,6 +68,7 @@ class FoodSearchActivity : BaseActivity() {
binding = ActivityFoodSearchBinding.inflate(layoutInflater)
setContentView(binding.root)
pageType = intent.getIntExtra(PAGE_TYPE, 0)
dinnerType = intent.getStringExtra(DINNER_TYPE)?:"0"
setHeaderBackground()
foodName = intent.getStringExtra(FOOD_NAME)
binding.etInputDish.setText(foodName)
@@ -131,16 +135,26 @@ class FoodSearchActivity : BaseActivity() {
private var pageNo = 1
private var pageSize = 100
fun getDinnerTypeText(): String {
return when (dinnerType) {
"1" -> "早餐"
"2" -> "午餐"
"3" -> "晚餐"
else -> "早餐"
}
}
@SuppressLint("NotifyDataSetChanged")
private fun queryListInfo(input: String) {
showLoading()
val map = mapOf(
val map = mutableMapOf(
"foodName" to input.trim(),
"pageNo" to "$pageNo",
"pageSize" to "$pageSize",
"canteenId" to BaseApp.canteenId
)
if (dinnerType.toInt() > 0) {
map["dinnerType"] = getDinnerTypeText()
}
val sb = StringBuilder(UrlConfig.QUERY_FOOD_LIST).apply {
append("?")
map.forEach { (key, value) -> append("$key=$value&") }
@@ -68,7 +68,7 @@ class HomeActivity : BaseActivity() {
// appViewModel.updateGoods(it)
// }
// }
// appViewModel.deleteAll()
// appViewModel.clearAllSeasoning()
}
@@ -24,6 +24,7 @@ import com.shuwei.dish.match.utils.SwipeCallback
import com.shuwei.dish.match.utils.WeightUtil
import com.shuwei.dish.match.utils.ext.clickWithDebounce
import com.shuwei.dish.match.utils.ext.gone
import com.shuwei.dish.match.utils.ext.startActivity
import com.shuwei.dish.match.utils.ext.toJsonString
import com.shuwei.dish.match.utils.ext.toObject
import com.shuwei.dish.match.utils.ext.toast
@@ -147,11 +148,10 @@ class PrepareCookActivity : BaseActivity() {
return
}
Log.d(TAG, "goToSubmit: goodsList:${goodsList?.toJsonString()}")
startActivity(
Intent(this, SubmitDishActivity::class.java)
.putExtra(SubmitDishActivity.GOODS_LIST, goodsList as Serializable)
.putExtra(SubmitDishActivity.FOOD_ITEM, food as Serializable)
)
startActivity<SubmitDishActivity> {
putExtra(SubmitDishActivity.GOODS_LIST, goodsList as Serializable)
putExtra(SubmitDishActivity.FOOD_ITEM, food as Serializable)
}
}
private fun getGoodsList() {
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProvider
import com.shuwei.dish.match.R
import com.shuwei.dish.match.base.BaseActivity
@@ -25,10 +26,20 @@ class SelectDishActivity : BaseActivity() {
companion object {
const val IS_COOKING = "isCooking"
const val DINNER_TYPE = "dinnerType"
}
private lateinit var binding: ActivitySelectDishBinding
private var dishListFragment: DishListFragment? = null
private lateinit var appViewModel: AppViewModel
private var dinnerType: String = "1"
private val fragmentList = mutableListOf<DishListFragment>().apply {
add(DishListFragment.instance("1"))
add(DishListFragment.instance("2"))
add(DishListFragment.instance("3"))
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -55,10 +66,6 @@ class SelectDishActivity : BaseActivity() {
loadFragment()
}
private lateinit var appViewModel: AppViewModel
var dinnerType: String = "早餐"
private fun initViewModel() {
val db = BaseApp.instance!!.database
val factory =
@@ -68,24 +75,19 @@ class SelectDishActivity : BaseActivity() {
}
fun getCookFoodList(action: (MutableList<CookFoodEntity>?) -> Unit) {
appViewModel.getCookFoodList(cookMode = 0) { action(it) }
appViewModel.getCookFoodList(cookMode = 0, dinnerType = dinnerType) { action(it) }
}
fun addViewListener() {
binding.dishRadioGroup.setOnCheckedChangeListener { _, checkedId ->
dinnerType = when (checkedId) {
R.id.rbBreakfast -> "早餐"
R.id.rbLunch -> "午餐"
R.id.rbDinner -> "晚餐"
else -> ""
}
dishListFragment?.getDishList(1, false)
dinnerType = when (checkedId) {
R.id.rbBreakfast -> "1"
R.id.rbLunch -> "2"
R.id.rbDinner -> "3"
else -> "1"
}
loadFragment()
}
// binding.llSearchBar.setOnClickListener {
// startActivity<FoodSearchActivity> {
// putExtra(FoodSearchActivity.PAGE_TYPE, 1)
// }
// }
binding.etInputDish.addOnActionSearchListener {
jumpSearch()
}
@@ -102,18 +104,26 @@ class SelectDishActivity : BaseActivity() {
}
startActivity<FoodSearchActivity> {
putExtra(FoodSearchActivity.PAGE_TYPE, 1)
putExtra(FoodSearchActivity.DINNER_TYPE, dinnerType)
putExtra(FoodSearchActivity.FOOD_NAME, searchText)
}
KeyboardUtil.hideKeyboard(this, binding.etInputDish)
}
private fun loadFragment() {
DishListFragment.instance().let {
dishListFragment = it
supportFragmentManager.beginTransaction().apply {
replace(R.id.flSubPage, it)
commit()
runCatching {
fragmentList[dinnerType.toInt() - 1].let {
supportFragmentManager.beginTransaction().apply {
if (fragmentList.contains(it)) {
replace(R.id.flSubPage, it)
} else {
add(R.id.flSubPage, it)
}
commit()
}
}
}.onFailure {
it.printStackTrace()
}
}
@@ -123,8 +133,20 @@ class SelectDishActivity : BaseActivity() {
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
dishListFragment?.getDishList(1, isCooking)
runCatching {
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
val lastDinnerType = intent?.getStringExtra(DINNER_TYPE) ?: "0"
if (lastDinnerType == "1" || lastDinnerType == "2" || lastDinnerType == "3") {
fragmentList[lastDinnerType.toInt() - 1].getDishList(1, lastDinnerType)
}
when(lastDinnerType) {
"1"->binding.dishRadioGroup.check(R.id.rbBreakfast)
"2"->binding.dishRadioGroup.check(R.id.rbLunch)
"3"->binding.dishRadioGroup.check(R.id.rbDinner)
}
}.onFailure {
it.printStackTrace()
}
}
@Deprecated("Deprecated in Java")
@@ -57,6 +57,7 @@ class SubmitDishActivity : BaseActivity() {
foodId = it.foodId ?: ""
foodName = it.foodName
cookMode = it.cookMode
dinnerType = it.dinnerType
}
canteenId = BaseApp.canteenId
}
@@ -96,7 +97,7 @@ class SubmitDishActivity : BaseActivity() {
}
private fun loadSeasoningFromLocal() {
appViewModel.getCookFoodGoodsList(food?.foodId!!) { it ->
appViewModel.getCookFoodGoodsList(foodId = food!!.foodId!!, cookMode = food!!.cookMode) { it ->
goodsList = mutableListOf()
//设置主辅材数据
goodsList?.addAll(it.filter { goods -> goods.materialType != 3 })
@@ -174,12 +175,12 @@ class SubmitDishActivity : BaseActivity() {
// return@addWeightListener
// }
val firstWeight = firstGoodsArray.get(address, null)
if (firstWeight != weight) {
Log.d(
TAG,
"addViewListener: state=$state,address=$address,weight=$weight,firstWeight=$firstWeight"
)
}
// if (firstWeight != weight) {
// Log.d(
// TAG,
// "addViewListener: state=$state,address=$address,weight=$weight,firstWeight=$firstWeight"
// )
// }
if (firstWeight == null) {
//未设置数据
firstGoodsArray.put(address, weight)
@@ -273,7 +274,14 @@ class SubmitDishActivity : BaseActivity() {
val typeToken = object : TypeToken<List<CookFoodGoodsEntity>>() {}
val tempSeasoningList = seasoningJson.toType(typeToken = typeToken)
goodsList?.addAll(tempSeasoningList)
cookFoodEntity.let {
it.dinnerType = when (it.dinnerType) {
"早餐" -> "1"
"午餐" -> "2"
"晚餐" -> "3"
else -> it.dinnerType
}
}
val isSamplingData = food!!.cookMode == 1
if (isSamplingData) {
//生成临时foodId,解决采样模式没有foodId,无法关联数据的问题
@@ -325,7 +333,16 @@ class SubmitDishActivity : BaseActivity() {
}
}
cookFoodEntity.stFoodInfoConstituteList = this@SubmitDishActivity.goodsList
cookFoodEntity.let {
it.stFoodInfoConstituteList = this@SubmitDishActivity.goodsList
it.dinnerType = when(it.dinnerType) {
"1" -> "早餐"
"2" -> "午餐"
"3" -> "晚餐"
else -> null
}
}
val isSamplingData = food!!.cookMode == 1
if (isSamplingData) {
//采样模式没有foodId
@@ -373,6 +390,7 @@ class SubmitDishActivity : BaseActivity() {
}
startActivity<SelectDishActivity> {
putExtra(SelectDishActivity.IS_COOKING, isCooking)
putExtra(SelectDishActivity.DINNER_TYPE, food?.dinnerType)
}
}
@@ -8,6 +8,7 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter4.util.setOnDebouncedItemClick
import com.shuwei.dish.match.adapter.DishShowAdapter
import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.databinding.FragmentDishListBinding
@@ -32,27 +33,29 @@ class DishListFragment : Fragment() {
companion object {
private const val TAG = "DishListFragment"
// const val DINNER_TYPE = "dinnerType"
public fun instance(): DishListFragment {
const val DINNER_TYPE = "dinnerType"
public fun instance(dinnerType: String): DishListFragment {
return DishListFragment().apply {
// arguments = Bundle().apply {
// putInt(DINNER_TYPE, type)
// }
arguments = Bundle().apply {
putString(DINNER_TYPE, dinnerType)
}
}
}
}
// private var dinnerType = ""
private var pageNo = 1
private val pageSize = 30
private lateinit var activity: SelectDishActivity
private lateinit var binding: FragmentDishListBinding
private var dinnerType = "0"
private var list: MutableList<FoodRecord> = mutableListOf()
private val dishAdapter by lazy {
DishShowAdapter(list = list).apply {
isStateViewEnable = true
setOnItemClickListener { adapter, view, position ->
setOnDebouncedItemClick { adapter, view, position ->
val item = list[position]
if (item.isCooking) {
//烹饪中,跳到称熟重页面
@@ -62,8 +65,9 @@ class DishListFragment : Fragment() {
item as Serializable
)
}
return@setOnItemClickListener
return@setOnDebouncedItemClick
}
item.dinnerType = dinnerType
context.startActivity<PrepareCookActivity> {
putExtra(
SubmitDishActivity.FOOD_ITEM,
@@ -75,8 +79,6 @@ class DishListFragment : Fragment() {
}
}
private lateinit var binding: FragmentDishListBinding
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
@@ -89,7 +91,7 @@ class DishListFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity = requireActivity() as SelectDishActivity
//toast("type=$type")
dinnerType = arguments?.getString(DINNER_TYPE, "0")?:"0"
binding.rvDishList.run {
layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
@@ -127,19 +129,28 @@ class DishListFragment : Fragment() {
}
}
}
fun getDishList(pageNo: Int, isCooking: Boolean) {
fun getDishList(pageNo: Int, dinnerType: String) {
this.pageNo = pageNo
this.dinnerType = dinnerType
getDishList()
}
fun getDinnerTypeText(): String {
return when (dinnerType) {
"1" -> "早餐"
"2" -> "午餐"
"3" -> "晚餐"
else -> "早餐"
}
}
@SuppressLint("NotifyDataSetChanged")
@Suppress("unchecked_cast")
fun getDishList() {
activity.showLoading()
val map = mapOf(
// "foodName" to input,
"dinnerType" to activity.dinnerType,
"dinnerType" to getDinnerTypeText(),
"pageNo" to "$pageNo",
"pageSize" to "$pageSize",
"canteenId" to BaseApp.canteenId
@@ -231,6 +242,7 @@ class DishListFragment : Fragment() {
if (food != null) {
food.isCooking = true
food.sort = index
food.dinnerType = entity.dinnerType?:"0"
tempList.add(food)
} else {
//当前查询到的list不包括本地数据id,可能数据在很多页以后了,暂时只能直接构造数据
@@ -239,6 +251,7 @@ class DishListFragment : Fragment() {
foodId = entity.foodId,
foodName = entity.foodName,
sort = index,
dinnerType = entity.dinnerType?:"0",
isCooking = true
)
)
@@ -0,0 +1,55 @@
package com.shuwei.dish.match.utils
import android.content.Context
import com.google.gson.Gson
import org.json.JSONObject
import java.io.BufferedReader
import java.io.InputStreamReader
object JsonAssetsLoader {
// 方法1:使用BufferedReader逐行读取(适合大文件)
fun loadJsonFromAssets(context: Context, fileName: String): String {
val stringBuilder = StringBuilder()
try {
context.assets.open(fileName).use { inputStream ->
BufferedReader(InputStreamReader(inputStream)).use { reader ->
var line: String?
while (reader.readLine().also { line = it } != null) {
stringBuilder.append(line)
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
return stringBuilder.toString()
}
// 方法2:使用Gson解析到数据类
inline fun <reified T> parseJsonFromAssets(
context: Context,
fileName: String
): T? {
return try {
Gson().fromJson(
loadJsonFromAssets(context, fileName),
T::class.java
)
} catch (e: Exception) {
null
}
}
// 方法3:使用原生JSONObject解析
fun getJsonObjectFromAssets(
context: Context,
fileName: String
): JSONObject? {
return try {
JSONObject(loadJsonFromAssets(context, fileName))
} catch (e: Exception) {
null
}
}
}
@@ -0,0 +1,49 @@
package com.shuwei.dish.match.utils
import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import android.view.View
import java.util.Arrays
class MultiClickDetector(private val targetCount: Int = 10,
private val intervalMs: Long = 500) {
private var clickCount = 0
private val clickTimestamps = LongArray(targetCount)
private val handler = Handler(Looper.getMainLooper())
private lateinit var callback: () -> Unit
fun setOnMultiClickListener(view: View, action: () -> Unit) {
callback = action
view.setOnClickListener {
System.arraycopy(clickTimestamps, 1, clickTimestamps, 0, targetCount - 1)
clickTimestamps[targetCount - 1] = SystemClock.uptimeMillis()
if (clickTimestamps[0] >= SystemClock.uptimeMillis() - intervalMs) {
callback.invoke()
resetCount()
}
}
}
// 使用Handler的延迟检测方案
fun setOnDelayedMultiClickListener(view: View, action: () -> Unit) {
callback = action
view.setOnClickListener {
clickCount++
handler.removeCallbacks(resetTask)
handler.postDelayed(resetTask, intervalMs)
if (clickCount >= targetCount) {
callback.invoke()
resetCount()
}
}
}
private val resetTask = Runnable { resetCount() }
private fun resetCount() {
clickCount = 0
Arrays.fill(clickTimestamps, 0L)
}
}
@@ -32,6 +32,9 @@ class SwipeCallback(
viewHolder: RecyclerView.ViewHolder
): Int {
val position = viewHolder.getBindingAdapterPosition()
if (position < 0) {
return makeMovementFlags(0, 0)
}
// 默认的拖动和滑动方向
val dragFlags = 0
// ItemTouchHelper.UP or ItemTouchHelper.DOWN
@@ -4,6 +4,7 @@ import android.os.Build
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.util.SparseIntArray
import com.aithings.Weigher
import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.utils.ext.toast
@@ -11,6 +12,8 @@ import com.wabon.wbintelligenthardwaresdk.api.SensorScale
object WeightUtil {
val weightArray = SparseIntArray()
fun connect(initCallback: (connect: Boolean) -> Unit) {
Weigher.setListener(object : WeightListenerImpl() {
override fun onInit(connect: Boolean) {
@@ -39,7 +42,8 @@ object WeightUtil {
else -> ""
}
val result1 = String.format("$stateStr 重量:%s kg", weight / 1000f)
Log.d("WeightUtil", "ttlReturn, address:$address,$result1")
//Log.d("WeightUtil", "ttlReturn, address:$address,$result1")
weightArray.put(address, weight)
}
}
@@ -163,7 +163,7 @@ fun EditText.addOnActionSearchListener(searchCallback: () -> Unit) {
}
fun View.clickWithDebounce(delay: Long = 500, action: () -> Unit) {
fun View.clickWithDebounce(delay: Long = 300, action: () -> Unit) {
var job: Job? = null
setOnClickListener {
job?.cancel()
@@ -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) {
@@ -31,6 +31,7 @@
android:textSize="28sp" />
<TextView
android:id="@+id/tvSetting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
@@ -122,7 +123,6 @@
android:layout_marginEnd="30dp">
<TextView
android:id="@+id/tvSetting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
@@ -20,6 +20,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginStart="20dp"
android:gravity="center_horizontal"
android:layout_marginEnd="20dp"
android:text="@string/food_remind_02"
android:textColor="@color/black999"
android:layout_marginBottom="60dp"