解决菜品配比终端接口食堂id、字段类型等变化导致的问题

This commit is contained in:
2025-08-15 18:01:46 +08:00
parent df8eed8869
commit 3a97b718dd
20 changed files with 122 additions and 48 deletions
+2 -2
View File
@@ -4,10 +4,10 @@
<selectionStates> <selectionStates>
<SelectionState runConfigName="app"> <SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" /> <option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2025-07-21T08:50:38.006773Z"> <DropdownSelection timestamp="2025-08-15T07:06:48.695133800Z">
<Target type="DEFAULT_BOOT"> <Target type="DEFAULT_BOOT">
<handle> <handle>
<DeviceId pluginId="LocalEmulator" identifier="path=C:\Users\HUAWEI\.android\avd\Pad_828_1768_New.avd" /> <DeviceId pluginId="Default" identifier="serial=192.168.1.185:5555;connection=66c1b774" />
</handle> </handle>
</Target> </Target>
</DropdownSelection> </DropdownSelection>
@@ -9,6 +9,7 @@ import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.shuwei.dish.match.R import com.shuwei.dish.match.R
import com.shuwei.dish.match.databinding.ListItemDishCookBinding import com.shuwei.dish.match.databinding.ListItemDishCookBinding
import com.shuwei.dish.match.entity.CookFoodGoodsEntity import com.shuwei.dish.match.entity.CookFoodGoodsEntity
import java.text.DecimalFormat
class DishPartAdapter(list: MutableList<CookFoodGoodsEntity>) : class DishPartAdapter(list: MutableList<CookFoodGoodsEntity>) :
BaseQuickAdapter<CookFoodGoodsEntity, DishPartAdapter.VH>(list) { BaseQuickAdapter<CookFoodGoodsEntity, DishPartAdapter.VH>(list) {
@@ -26,7 +27,7 @@ class DishPartAdapter(list: MutableList<CookFoodGoodsEntity>) :
tvDishName.text = item!!.goodsName tvDishName.text = item!!.goodsName
tvDishType.text = if (item.materialType == 1) "主辅材:主材" else if (item.materialType == 2) "主辅材:辅材" else "" tvDishType.text = if (item.materialType == 1) "主辅材:主材" else if (item.materialType == 2) "主辅材:辅材" else ""
tvDishWeight.text = tvDishWeight.text =
if (item.useWeight == null || item.useWeight == 0) "" else "${item.useWeight}" if (item.useWeight == null || item.useWeight == 0.toDouble()) "" else "${DecimalFormat("#").format(item.useWeight)}"
tvDishWeight.setTextColor( tvDishWeight.setTextColor(
ContextCompat.getColor( ContextCompat.getColor(
context, context,
@@ -26,7 +26,7 @@ class DishShowAdapter(list: MutableList<FoodRecord>) :
override fun onBindViewHolder(holder: VH, position: Int, item: FoodRecord?) { override fun onBindViewHolder(holder: VH, position: Int, item: FoodRecord?) {
holder.binding.run { holder.binding.run {
val isCooking = item!!.isCooking val isCooking = item!!.isCooking
val totalWeight = item.totalWeight ?: 0 val totalWeight = item.totalWeight ?: 0.toDouble()
tvDishName.text = item!!.foodName tvDishName.text = item!!.foodName
if (isCooking) { if (isCooking) {
tvDishName.setTextColor( tvDishName.setTextColor(
@@ -36,7 +36,7 @@ class DishShowAdapter(list: MutableList<FoodRecord>) :
tvDishCount.visible() tvDishCount.visible()
tvDishCount.text = "制作统计:-kg" tvDishCount.text = "制作统计:-kg"
tvShowState.text = "烹饪中" tvShowState.text = "烹饪中"
} else if (totalWeight > 0) { } else if (totalWeight > 0.toDouble()) {
tvDishName.setTextColor( tvDishName.setTextColor(
ContextCompat.getColor(holder.itemView.context, R.color.dish_green) ContextCompat.getColor(holder.itemView.context, R.color.dish_green)
) )
@@ -44,7 +44,7 @@ class DishShowAdapter(list: MutableList<FoodRecord>) :
tvDishCount.visible() tvDishCount.visible()
tvDishCount.text = tvDishCount.text =
"累计统计:${totalWeight / 1000.0F}kg(${item.count}次)" "累计统计:${totalWeight / 1000.0F}kg(${item.count}次)"
tvShowState.text = "${(item.foodWeight ?: 0) / 1000.0F}kg" tvShowState.text = "${(item.foodWeight ?: 0.toDouble()) / 1000.0F}kg"
} else { } else {
tvDishName.setTextColor( tvDishName.setTextColor(
ContextCompat.getColor(holder.itemView.context, R.color.black999) ContextCompat.getColor(holder.itemView.context, R.color.black999)
@@ -27,7 +27,7 @@ class SamplingAdapter(list: MutableList<FoodRecord>) :
holder.binding.run { holder.binding.run {
val isCooking = item!!.isCooking val isCooking = item!!.isCooking
clBlock.setBackgroundResource(R.drawable.shape_white_fb_15_corners) clBlock.setBackgroundResource(R.drawable.shape_white_fb_15_corners)
val totalWeight = item!!.totalWeight ?: 0 val totalWeight = item!!.totalWeight ?: 0.toDouble()
tvDishName.run { tvDishName.run {
text = item!!.foodName text = item!!.foodName
setTextColor( setTextColor(
@@ -42,9 +42,9 @@ class SamplingAdapter(list: MutableList<FoodRecord>) :
tvDishCount.text = "制作统计:-kg" tvDishCount.text = "制作统计:-kg"
tvShowState.text = "烹饪中" tvShowState.text = "烹饪中"
} else { } else {
val useWeight = if (totalWeight > 0) totalWeight else (item.foodWeight ?: 0) val useWeight = if (totalWeight > 0.toDouble()) totalWeight else (item.foodWeight ?: 0.toDouble())
tvDishCount.text = "累计统计:${useWeight / 1000.0F}kg(${item.count}次)" tvDishCount.text = "累计统计:${useWeight / 1000.0F}kg(${item.count}次)"
tvShowState.text = "${(item.foodWeight ?: 0) / 1000.0F}kg" tvShowState.text = "${(item.foodWeight ?: 0.toDouble()) / 1000.0F}kg"
} }
} }
} }
@@ -100,7 +100,9 @@ object SeasoningCellTool {
} }
if (initList.isNullOrEmpty().not()) { if (initList.isNullOrEmpty().not()) {
initList.forEach { initList.forEach {
list[it.sort] = it.apply { this.pageType = pageType } if (it.sort < list.size) {
list[it.sort] = it.apply { this.pageType = pageType }
}
} }
var lastItem = initList.firstOrNull { it.sort == 14 } var lastItem = initList.firstOrNull { it.sort == 14 }
lastItem = lastItem ?: list[list.size - 1] lastItem = lastItem ?: list[list.size - 1]
@@ -1,6 +1,7 @@
package com.shuwei.dish.match.adapter package com.shuwei.dish.match.adapter
import android.graphics.Typeface import android.graphics.Typeface
import android.icu.text.DecimalFormat
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import android.text.style.AbsoluteSizeSpan import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan import android.text.style.ForegroundColorSpan
@@ -103,10 +104,10 @@ class TextCellAdapter(var list: MutableList<SeasoningEntity>) :
) )
append("\n") append("\n")
val weight = item.useWeight ?: 0 val weight = item.useWeight ?: 0.toDouble()
val weightColor = if (weight == 0) "#999999" else "#00BC71" val weightColor = if (weight == 0.toDouble()) "#999999" else "#00BC71"
appendText( appendText(
"${weight}g", "${DecimalFormat("#").format(weight)}g",
ForegroundColorSpan(weightColor.toColorInt()), ForegroundColorSpan(weightColor.toColorInt()),
AbsoluteSizeSpan(30, true) AbsoluteSizeSpan(30, true)
) )
@@ -19,6 +19,8 @@ class BaseApp : Application() {
} }
companion object { companion object {
const val canteenId = "1678234139391512577"
@Volatile @Volatile
private var sharedPref: SharedPreferences? = null private var sharedPref: SharedPreferences? = null
@@ -20,7 +20,7 @@ import com.shuwei.dish.match.entity.SeasoningEntity
CookFoodEntity::class, CookFoodEntity::class,
CookFoodGoodsEntity::class, CookFoodGoodsEntity::class,
], ],
version = 6, version = 7,
exportSchema = true exportSchema = true
) )
abstract class AppDatabase : RoomDatabase() { abstract class AppDatabase : RoomDatabase() {
@@ -140,6 +140,58 @@ val MIGRATION_5_6 = MigrationImpl(5, 6) { db ->
db.endTransaction() db.endTransaction()
} }
val MIGRATION_6_7 = MigrationImpl(6, 7) {db ->
runCatching {
// -- 1. 启用外键约束(可选)
db.execSQL("PRAGMA foreign_keys=OFF")
// -- 2. 开始事务
db.execSQL("BEGIN TRANSACTION")
// -- 3. 创建新表结构(将目标字段改为TEXT)
db.execSQL("""
CREATE TABLE `dm_cook_food_2`
(`foodId` TEXT NOT NULL,
`foodName` TEXT,
`canteenId` TEXT,
`foodWeight` INTEGER NOT NULL,
`cookMode` INTEGER NOT NULL,
`isDel` INTEGER NOT NULL,
`createTime` TEXT NOT NULL,
PRIMARY KEY(`foodId`)
)
""".trimIndent())
// -- 4. 从旧表复制数据(自动类型转换)
db.execSQL("""
INSERT INTO dm_cook_food_2
SELECT foodId, foodName, foodWeight, cookMode, isDel, createTime
FROM dm_cook_food
""".trimIndent()
)
// -- 5. 删除旧表
db.execSQL("DROP TABLE dm_cook_food")
// -- 6. 重命名新表
db.execSQL("ALTER TABLE dm_cook_food_2 RENAME TO dm_cook_food")
// -- 7. 重建索引和触发器(如有)
db.execSQL("CREATE UNIQUE INDEX dm_cook_food_foodId_IDX ON dm_cook_food (foodId)")
// -- 重建其他约束...
// -- 8. 提交事务
db.execSQL("COMMIT")
// -- 9. 恢复外键约束
db.execSQL("PRAGMA foreign_keys=ON")
}.onFailure {
it.printStackTrace()
}
}
class DatabaseProvider(private val context: Context) { class DatabaseProvider(private val context: Context) {
// 单例模式确保全局唯一实例‌ // 单例模式确保全局唯一实例‌
val instance: AppDatabase by lazy { val instance: AppDatabase by lazy {
@@ -157,6 +209,7 @@ class DatabaseProvider(private val context: Context) {
// .addMigrations(MIGRATION_3_4) // .addMigrations(MIGRATION_3_4)
// .addMigrations(MIGRATION_4_5) // .addMigrations(MIGRATION_4_5)
// .addMigrations(MIGRATION_5_6) // .addMigrations(MIGRATION_5_6)
// .addMigrations(MIGRATION_6_7)
.build() .build()
} }
} }
@@ -14,6 +14,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
import com.shuwei.dish.match.R import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.GoodsInfoSearchAdapter import com.shuwei.dish.match.adapter.GoodsInfoSearchAdapter
import com.shuwei.dish.match.base.BaseActivity import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.databinding.DialogBottomSheetBinding import com.shuwei.dish.match.databinding.DialogBottomSheetBinding
import com.shuwei.dish.match.entity.CookFoodGoodsEntity import com.shuwei.dish.match.entity.CookFoodGoodsEntity
import com.shuwei.dish.match.entity.GoodsRecordBean import com.shuwei.dish.match.entity.GoodsRecordBean
@@ -135,7 +136,7 @@ class BottomDialog(
// val pathSegmentList = UrlConfig.QUERY_GOODS_LIST.split(delimiters = arrayOf("/"), limit = 1) // val pathSegmentList = UrlConfig.QUERY_GOODS_LIST.split(delimiters = arrayOf("/"), limit = 1)
val queryParams = mutableMapOf( val queryParams = mutableMapOf(
"goodsType" to "$goodsType", "goodsType" to "$goodsType",
"canteenId" to "0", "canteenId" to BaseApp.canteenId,
"pageNo" to "$pageNo", "pageNo" to "$pageNo",
"pageSize" to "$pageSize" "pageSize" to "$pageSize"
) )
@@ -22,6 +22,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
import com.shuwei.dish.match.R import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.SeasoningSearchAdapter import com.shuwei.dish.match.adapter.SeasoningSearchAdapter
import com.shuwei.dish.match.base.BaseActivity import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.databinding.DialogBottomSheet2Binding import com.shuwei.dish.match.databinding.DialogBottomSheet2Binding
import com.shuwei.dish.match.entity.SeasoningEntity import com.shuwei.dish.match.entity.SeasoningEntity
import com.shuwei.dish.match.entity.SeasoningRecordBean import com.shuwei.dish.match.entity.SeasoningRecordBean
@@ -133,7 +134,7 @@ class BottomDialog2(
} }
WeightUtil.addWeightListener { address, state, weight -> WeightUtil.addWeightListener { address, state, weight ->
if (weighAddress == address) { if (weighAddress == address) {
this.currentWeight = weight this.currentWeight = weight.toDouble()
binding.tvWeight.text = getTextSpan(weight) binding.tvWeight.text = getTextSpan(weight)
} }
} }
@@ -156,7 +157,7 @@ class BottomDialog2(
KeyboardUtil.hideKeyboard(v.context, v) KeyboardUtil.hideKeyboard(v.context, v)
} }
private var currentWeight = 0 private var currentWeight = 0.toDouble()
private var pageNo = 1 private var pageNo = 1
private val pageSize = 120 private val pageSize = 120
@@ -166,7 +167,7 @@ class BottomDialog2(
private fun getGoodsList() { private fun getGoodsList() {
val queryParams = mutableMapOf( val queryParams = mutableMapOf(
"goodsType" to "$goodsType", "goodsType" to "$goodsType",
"canteenId" to "0", "canteenId" to BaseApp.canteenId,
"pageNo" to "$pageNo", "pageNo" to "$pageNo",
"pageSize" to "$pageSize" "pageSize" to "$pageSize"
) )
@@ -12,8 +12,8 @@ data class CookFoodEntity(
@PrimaryKey @PrimaryKey
var foodId: String, var foodId: String,
var foodName: String? = null, var foodName: String? = null,
var canteenId: Int? = null, var canteenId: String? = null,
var foodWeight: Int = 0, var foodWeight: Double = 0.0,
//0-制作模式,1-采样模式,2-品控模式 //0-制作模式,1-采样模式,2-品控模式
var cookMode:Int = 0, var cookMode:Int = 0,
var isDel: Int = 0, var isDel: Int = 0,
@@ -15,7 +15,7 @@ class CookFoodGoodsEntity(
/** /**
* 物品id * 物品id
*/ */
var goodsId: Int, var goodsId: String,
/** /**
* 物品名称 * 物品名称
@@ -49,7 +49,7 @@ class CookFoodGoodsEntity(
/** /**
* 物品 用料重量 * 物品 用料重量
*/ */
var useWeight: Int? = 0, var useWeight: Double? = 0.0,
var popularName: String? = "", var popularName: String? = "",
@@ -60,7 +60,7 @@ class CookFoodGoodsEntity(
var isDel: Int = 0, var isDel: Int = 0,
var createTime: String = DateTimeUtil.formatDateTime(LocalDateTime.now()) var createTime: String = DateTimeUtil.formatDateTime(LocalDateTime.now())
) : BaseEntity, Serializable { ) : BaseEntity, Serializable {
constructor() : this(goodsId = -1) // 必需的空构造, constructor() : this(goodsId = "") // 必需的空构造,
@Ignore @Ignore
var isSetFinished: Boolean = false var isSetFinished: Boolean = false
@@ -5,8 +5,8 @@ import java.io.Serializable
data class FoodRecord( data class FoodRecord(
var foodId: String? = null, var foodId: String? = null,
var foodName: String? = null, var foodName: String? = null,
var foodWeight: Int? = null, var foodWeight: Double? = null,
var totalWeight: Int? = null, var totalWeight: Double? = null,
var count: Int? = null, var count: Int? = null,
var isCooking: Boolean = false, var isCooking: Boolean = false,
//0-制作模式,1-采样模式,2-品控模式 //0-制作模式,1-采样模式,2-品控模式
@@ -14,7 +14,7 @@ data class SeasoningEntity(
/** /**
* 物品id * 物品id
*/ */
var goodsId: Int, var goodsId: String,
/** /**
* 物品名称 * 物品名称
@@ -44,7 +44,7 @@ data class SeasoningEntity(
/** /**
* 物品 用料重量 * 物品 用料重量
*/ */
var useWeight: Int? = 0, var useWeight: Double? = 0.0,
var popularName: String? = "", var popularName: String? = "",
@@ -65,5 +65,5 @@ data class SeasoningEntity(
@Ignore @Ignore
var isClicked: Boolean = false var isClicked: Boolean = false
constructor() : this(goodsId = -1) // 必需的空构造 constructor() : this(goodsId = "") // 必需的空构造
} }
@@ -122,6 +122,9 @@ class DishSamplingActivity : BaseActivity() {
onLeftClick = { dismiss() } onLeftClick = { dismiss() }
onRightClick = { onRightClick = {
dismiss() dismiss()
if (pageFrom == HOME) {
startActivity<SamplingListActivity>()
}
finish() finish()
} }
onDismiss = { hideStatusBar() } onDismiss = { hideStatusBar() }
@@ -180,7 +183,7 @@ class DishSamplingActivity : BaseActivity() {
WeightUtil.addWeightListener(getWeight = { address, state, weight -> WeightUtil.addWeightListener(getWeight = { address, state, weight ->
Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight") Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight")
if (address == 2) { if (address == 2) {
tempDishEntity?.useWeight = weight tempDishEntity?.useWeight = weight.toDouble()
binding.tvDishPartWeight.text = "${weight}" binding.tvDishPartWeight.text = "${weight}"
} }
}) })
@@ -8,6 +8,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import com.shuwei.dish.match.R import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.FoodRecordAdapter import com.shuwei.dish.match.adapter.FoodRecordAdapter
import com.shuwei.dish.match.base.BaseActivity import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.databinding.ActivityFoodSearchBinding import com.shuwei.dish.match.databinding.ActivityFoodSearchBinding
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
@@ -138,7 +139,7 @@ class FoodSearchActivity : BaseActivity() {
"foodName" to input.trim(), "foodName" to input.trim(),
"pageNo" to "$pageNo", "pageNo" to "$pageNo",
"pageSize" to "$pageSize", "pageSize" to "$pageSize",
"canteenId" to "0" "canteenId" to BaseApp.canteenId
) )
val sb = StringBuilder(UrlConfig.QUERY_FOOD_LIST).apply { val sb = StringBuilder(UrlConfig.QUERY_FOOD_LIST).apply {
append("?") append("?")
@@ -100,7 +100,7 @@ class PrepareCookActivity : BaseActivity() {
} }
Log.d(TAG, "addViewClickListener->useRealWeight=$weight") Log.d(TAG, "addViewClickListener->useRealWeight=$weight")
clickItem.run { clickItem.run {
useWeight = weight useWeight = weight.toDouble()
isSetFinished = true isSetFinished = true
dishPartAdapter.notifyItemChanged(clickIndex) dishPartAdapter.notifyItemChanged(clickIndex)
} }
@@ -167,7 +167,7 @@ class PrepareCookActivity : BaseActivity() {
allEdible = it.allEdible allEdible = it.allEdible
goodsName = it.goodsName goodsName = it.goodsName
materialType = it.materialType materialType = it.materialType
useWeight = it.useWeight ?: 0 useWeight = it.useWeight ?: 0.toDouble()
goodsOrRelationCode = it.goodsOrRelationCode goodsOrRelationCode = it.goodsOrRelationCode
}) })
} }
@@ -217,7 +217,7 @@ class PrepareCookActivity : BaseActivity() {
//筛选出主材和辅材 //筛选出主材和辅材
val tempDate = voList.filter { it.materialType == 1 || it.materialType == 2 } val tempDate = voList.filter { it.materialType == 1 || it.materialType == 2 }
.apply { .apply {
forEach { it.useWeight = 0 } forEach { it.useWeight = 0.toDouble() }
} }
list.clear() list.clear()
list.addAll(tempDate) list.addAll(tempDate)
@@ -287,7 +287,7 @@ class PrepareCookActivity : BaseActivity() {
saveDataRemindDialog() saveDataRemindDialog()
return return
} }
val filterResult = list.firstOrNull { (it.useWeight ?: 0) > 0 } val filterResult = list.firstOrNull { (it.useWeight ?: 0.toDouble()) > 0.toDouble() }
if (filterResult != null) { if (filterResult != null) {
//说明有称重的数据 //说明有称重的数据
saveDataRemindDialog() saveDataRemindDialog()
@@ -209,7 +209,7 @@ class SamplingListActivity : BaseActivity() {
// "foodName" to input, // "foodName" to input,
"pageNo" to "$pageNo", "pageNo" to "$pageNo",
"pageSize" to "$pageSize", "pageSize" to "$pageSize",
"canteenId" to "0" "canteenId" to BaseApp.canteenId
) )
val sb = StringBuilder(UrlConfig.SAMPLING_LIST).apply { val sb = StringBuilder(UrlConfig.SAMPLING_LIST).apply {
append("?") append("?")
@@ -58,7 +58,7 @@ class SubmitDishActivity : BaseActivity() {
foodName = it.foodName foodName = it.foodName
cookMode = it.cookMode cookMode = it.cookMode
} }
canteenId = 0 canteenId = BaseApp.canteenId
} }
} }
@@ -139,7 +139,7 @@ class SubmitDishActivity : BaseActivity() {
} }
private val seasoningArray by lazy { private val seasoningArray by lazy {
SparseArray<Int>() SparseArray<Double>()
} }
@@ -156,7 +156,7 @@ class SubmitDishActivity : BaseActivity() {
} }
binding.btnSubmit.clickWithDebounce { binding.btnSubmit.clickWithDebounce {
if (cookFoodEntity.foodWeight <= 0) { if (cookFoodEntity.foodWeight <= 0.toDouble()) {
toast("未识别到菜品熟重") toast("未识别到菜品熟重")
return@clickWithDebounce return@clickWithDebounce
} }
@@ -167,7 +167,7 @@ class SubmitDishActivity : BaseActivity() {
private fun addWeightListener() { private fun addWeightListener() {
WeightUtil.addWeightListener(getWeight = { address, state, weight -> WeightUtil.addWeightListener(getWeight = { address, state, weight ->
if (address == 1) { if (address == 1) {
cookFoodEntity.foodWeight = weight cookFoodEntity.foodWeight = weight.toDouble()
binding.tvTotalWeight.text = "${weight / 1000f}" binding.tvTotalWeight.text = "${weight / 1000f}"
} }
// if (state != SensorScale.STATE_STABLE) { // if (state != SensorScale.STATE_STABLE) {
@@ -196,7 +196,7 @@ class SubmitDishActivity : BaseActivity() {
// TAG, // TAG,
// "addViewListener: state=$state,address=$address,总共使用重量:$realUseWeight" // "addViewListener: state=$state,address=$address,总共使用重量:$realUseWeight"
// ) // )
seasoningArray.put(address, realUseWeight) seasoningArray.put(address, realUseWeight.toDouble())
refreshSeasoningWeight() refreshSeasoningWeight()
}) })
@@ -209,7 +209,7 @@ class SubmitDishActivity : BaseActivity() {
adapter.list.let { items -> adapter.list.let { items ->
weightRelateArray.forEach { key, value -> weightRelateArray.forEach { key, value ->
items[key].useWeight = items[key].useWeight =
(seasoningArray.get(value) ?: 0) + getCookingSeasoning(value) (seasoningArray.get(value) ?: 0.toDouble()) + getCookingSeasoning(value)
} }
} }
adapter.notifyDataSetChanged() adapter.notifyDataSetChanged()
@@ -218,10 +218,10 @@ class SubmitDishActivity : BaseActivity() {
} }
} }
private fun getCookingSeasoning(address: Int): Int { private fun getCookingSeasoning(address: Int): Double {
if (isCooking.not()) return 0 if (isCooking.not()) return 0.toDouble()
if (seasoningList.isEmpty()) return 0 if (seasoningList.isEmpty()) return 0.toDouble()
val weight = seasoningList[weightRelateArray2.get(address)].useWeight ?: 0 val weight = seasoningList[weightRelateArray2.get(address)].useWeight ?: 0.toDouble()
//Log.i(TAG, "getCookingSeasoning: weight[${address}]=$weight,seasoningList=${seasoningList.toJsonString()}") //Log.i(TAG, "getCookingSeasoning: weight[${address}]=$weight,seasoningList=${seasoningList.toJsonString()}")
return weight return weight
} }
@@ -263,6 +263,10 @@ class SubmitDishActivity : BaseActivity() {
toast("未获取到调料信息") toast("未获取到调料信息")
return return
} }
if (realSeasoningData.isNotEmpty()&&realSeasoningData[0].goodsId.isNullOrBlank()) {
toast("还未设置调料信息,请去设置页面操作")
return
}
showLoading() showLoading()
//只有制作和采样列表页面才能进入设置页面,提交页面无法进行设置,不存在调料数据被修改的问题 //只有制作和采样列表页面才能进入设置页面,提交页面无法进行设置,不存在调料数据被修改的问题
val seasoningJson = realSeasoningData.toJsonString() val seasoningJson = realSeasoningData.toJsonString()
@@ -303,16 +307,20 @@ class SubmitDishActivity : BaseActivity() {
toast("未获取到调料信息") toast("未获取到调料信息")
return return
} }
if (realSeasoningData.isNotEmpty()&&realSeasoningData[0].goodsId.isNullOrBlank()) {
toast("还未设置调料信息,请去设置页面操作")
return
}
showLoading() showLoading()
//只有制作和采样列表页面才能进入设置页面,提交页面无法进行设置,不存在调料数据被修改的问题 //只有制作和采样列表页面才能进入设置页面,提交页面无法进行设置,不存在调料数据被修改的问题
val seasoningJson = realSeasoningData.toJsonString() val seasoningJson = realSeasoningData.toJsonString()
val typeToken = object : TypeToken<List<CookFoodGoodsEntity>>() {} val typeToken = object : TypeToken<List<CookFoodGoodsEntity>>() {}
val tempSeasoningList = seasoningJson.toType(typeToken = typeToken) val tempSeasoningList = seasoningJson.toType(typeToken = typeToken)
tempSeasoningList.forEach { entity -> tempSeasoningList.forEach { entity ->
val realWeight = entity.useWeight ?: 0 val realWeight = entity.useWeight ?: 0.toDouble()
val filterData = goodsList?.firstOrNull { it.goodsId == entity.goodsId } val filterData = goodsList?.firstOrNull { it.goodsId == entity.goodsId }
//确保重量大于0,且无重复数据 //确保重量大于0,且无重复数据
if (realWeight > 0 && filterData == null) { if (realWeight > 0.toDouble() && filterData == null) {
goodsList?.add(entity) goodsList?.add(entity)
} }
} }
@@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.ItemTouchHelper import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import com.shuwei.dish.match.adapter.DishShowAdapter import com.shuwei.dish.match.adapter.DishShowAdapter
import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.databinding.FragmentDishListBinding import com.shuwei.dish.match.databinding.FragmentDishListBinding
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
@@ -141,7 +142,7 @@ class DishListFragment : Fragment() {
"dinnerType" to activity.dinnerType, "dinnerType" to activity.dinnerType,
"pageNo" to "$pageNo", "pageNo" to "$pageNo",
"pageSize" to "$pageSize", "pageSize" to "$pageSize",
"canteenId" to "0" "canteenId" to BaseApp.canteenId
) )
val sb = StringBuilder(UrlConfig.QUERY_FOOD_LIST).apply { val sb = StringBuilder(UrlConfig.QUERY_FOOD_LIST).apply {
append("?") append("?")