Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b66652c0b | ||
|
|
9e4b2bd009 | ||
|
|
6d3c5490a4 | ||
|
|
45543295e3 | ||
|
|
049c724303 | ||
|
|
acd1dd4605 | ||
|
|
17470bf12c | ||
|
|
0a3185fc9e | ||
|
|
9e41841086 |
@@ -1,4 +1,3 @@
|
||||
|
||||
plugins {
|
||||
// alias(libs.plugins.android.application)
|
||||
// alias(libs.plugins.kotlin.android)
|
||||
@@ -25,7 +24,7 @@ android {
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
ndk {
|
||||
//设置支持的SO库架构;x86_64 仅用于在 Windows 模拟器上调试(秤功能不可用)
|
||||
abiFilters.addAll(listOf("armeabi-v7a", "x86_64"))
|
||||
abiFilters.addAll(listOf("armeabi-v7a"))
|
||||
}
|
||||
|
||||
// 设置输出APK文件名格式
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -9,6 +9,7 @@ import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.databinding.ListItemFoodListBinding
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.model.SampleStatus
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
import java.text.DecimalFormat
|
||||
@@ -88,6 +89,14 @@ class FoodListAdapter(
|
||||
// 非烹饪中,采样模式
|
||||
tvDishName.setTextColor(ContextCompat.getColor(holder.itemView.context, R.color.dish_green))
|
||||
clBlock.setBackgroundResource(R.drawable.shape_white_fb_15_corners)
|
||||
// 已提交采样列表(sample-list):展示实验状态 + 熟重(g)
|
||||
val statusName = item.statusName
|
||||
if (!statusName.isNullOrBlank()) {
|
||||
tvDishCount.text = "熟重:${formatGram(foodWeight)}"
|
||||
tvShowState.text = statusName
|
||||
tvShowState.setTextColor(statusColor(holder, item.status))
|
||||
return@run
|
||||
}
|
||||
val realTotalWeight = if (totalWeight > 0.0) totalWeight else foodWeight
|
||||
val showTotalWeight = if (realTotalWeight == 0.0) "-" else df.format(realTotalWeight / 1000.0F)
|
||||
tvDishCount.text = "累计统计:${showTotalWeight}kg(${item.count ?: "-"}次)"
|
||||
@@ -96,5 +105,21 @@ class FoodListAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
/** 熟重(g)格式化,整数不带小数,小数保留 2 位 */
|
||||
private fun formatGram(weight: Double): String {
|
||||
val gramDf = DecimalFormat("0.##")
|
||||
return "${gramDf.format(weight)}g"
|
||||
}
|
||||
|
||||
/** 实验状态着色:1=实验中(灰) / 2=已评测(绿) / 9=已转化(绿) */
|
||||
private fun statusColor(holder: VH, status: Int?): Int {
|
||||
val context = holder.itemView.context
|
||||
return when (status) {
|
||||
SampleStatus.EVALUATED, SampleStatus.CONVERTED ->
|
||||
ContextCompat.getColor(context, R.color.dish_green)
|
||||
else -> ContextCompat.getColor(context, R.color.black999)
|
||||
}
|
||||
}
|
||||
|
||||
private val df = DecimalFormat("0.000")
|
||||
}
|
||||
|
||||
@@ -8,14 +8,14 @@ package com.shuwei.dish.match.base
|
||||
enum class DeviceRole { MASTER, SLAVE }
|
||||
|
||||
object GlobalData {
|
||||
var appBaseUrl: String = TEST_BASE_URL
|
||||
var appBaseUrl: String = PROD_BASE_URL
|
||||
|
||||
/**
|
||||
* 具体业务 BaseUrl
|
||||
*/
|
||||
const val TEST_BASE_URL = "http://192.168.1.201:14801"
|
||||
const val UAT_BASE_URL = "https://dev.yixiong-tech.com:8083"
|
||||
const val PROD_BASE_URL = "https://api.dm.yixiong-tech.com:8443"
|
||||
const val TEST_BASE_URL = "http://192.168.10.101:24801"
|
||||
const val UAT_BASE_URL = "https://dev.yixiong-tech.com:8081"
|
||||
const val PROD_BASE_URL = "https://platform-api.uat.shuziweidao.com"
|
||||
/**
|
||||
* 设备id
|
||||
*/
|
||||
|
||||
@@ -11,9 +11,6 @@ import android.view.View
|
||||
import android.view.Window
|
||||
import android.widget.FrameLayout
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.chad.library.adapter4.util.setOnDebouncedItemClick
|
||||
@@ -24,6 +21,7 @@ import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.databinding.DialogFoodSearchBinding
|
||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.model.MaterSearchItem
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||
import com.shuwei.dish.match.utils.showRawMaterialsDialog
|
||||
@@ -54,15 +52,23 @@ class FoodSearchDialog(
|
||||
isStateViewEnable = true
|
||||
setOnDebouncedItemClick { _, _, position ->
|
||||
val item = list.getOrNull(position) ?: return@setOnDebouncedItemClick
|
||||
// 弹出净材种类单选弹窗,确认后再回调并关闭弹窗
|
||||
item.isClicked = true
|
||||
notifyItemChanged(position)
|
||||
// mater-search 不返回净材种类,rawMaterialsTypes 为空时直接选中返回,避免卡在净材弹窗
|
||||
if (item.rawMaterialsTypes.isNullOrBlank()) {
|
||||
binding.root.postDelayed({
|
||||
onItemSelected(item)
|
||||
dismiss()
|
||||
}, 300)
|
||||
return@setOnDebouncedItemClick
|
||||
}
|
||||
// 有净材种类时弹出单选弹窗,确认后再回调并关闭弹窗
|
||||
showRawMaterialsDialog(
|
||||
context = activity,
|
||||
types = item.rawMaterialsTypes,
|
||||
checkedType = item.rawMaterialsType
|
||||
) { selectedType ->
|
||||
item.rawMaterialsType = selectedType
|
||||
item.isClicked = true
|
||||
notifyItemChanged(position)
|
||||
binding.root.postDelayed({
|
||||
onItemSelected(item)
|
||||
dismiss()
|
||||
@@ -121,8 +127,6 @@ class FoodSearchDialog(
|
||||
binding.ivSearch.setOnClickListener { searchGoods(it) }
|
||||
binding.root.setOnClickListener { KeyboardUtil.hideKeyboard(it) }
|
||||
|
||||
initObserver()
|
||||
|
||||
// 若有默认食材名称,自动填充并触发搜索
|
||||
//if (!defGoodsName.isNullOrBlank()) {
|
||||
//binding.etSheetInput.setText(defGoodsName)
|
||||
@@ -170,27 +174,6 @@ class FoodSearchDialog(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集 foodSearchGoodsListState,统一处理 Loading / Success / Error 状态
|
||||
* 使用独立的 State,避免与 FoodRecognizeActivity 等页面共用 goodsListState 产生干扰
|
||||
*/
|
||||
private fun initObserver() {
|
||||
activity.lifecycleScope.launch {
|
||||
activity.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
activity.netViewModel.foodSearchGoodsListState.collect { state ->
|
||||
when (state) {
|
||||
is UiState.Success -> loadGoodsList(state.data)
|
||||
is UiState.Error -> {
|
||||
activity.toast(state.msg)
|
||||
finishRefresh()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 触发搜索:校验输入、隐藏键盘、发起请求
|
||||
*/
|
||||
@@ -205,14 +188,24 @@ class FoodSearchDialog(
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求食材列表,使用弹窗专用接口,结果写入 foodSearchGoodsListState
|
||||
* 请求食材列表(采样模式新配比秤接口 mater-search,回调版本)
|
||||
*/
|
||||
private fun getGoodsList() {
|
||||
activity.netViewModel.queryFoodSearchGoodsList(
|
||||
goodsType = "0",
|
||||
activity.netViewModel.materSearch(
|
||||
keyword = goodsName.takeUnless { it.isNullOrBlank() },
|
||||
pageNum = pageNo,
|
||||
pageSize = PAGE_SIZE,
|
||||
goodsName = goodsName.takeUnless { it.isNullOrBlank() }
|
||||
onResult = { state ->
|
||||
when (state) {
|
||||
is UiState.Success -> loadGoodsList(state.data)
|
||||
is UiState.Error -> {
|
||||
activity.toast(state.msg)
|
||||
finishRefresh()
|
||||
if (pageNo == 1) loadEmptyView()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -220,7 +213,7 @@ class FoodSearchDialog(
|
||||
* 将返回数据填充到列表
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun loadGoodsList(records: MutableList<GoodsItem>?) {
|
||||
private fun loadGoodsList(records: List<MaterSearchItem>?) {
|
||||
finishRefresh()
|
||||
if (records.isNullOrEmpty()) {
|
||||
if (pageNo == 1) {
|
||||
@@ -235,20 +228,27 @@ class FoodSearchDialog(
|
||||
}
|
||||
}
|
||||
if (pageNo == 1) list.clear()
|
||||
// 将接口返回的 rawMaterialsType(全部种类)移存到 rawMaterialsTypes,供弹窗使用
|
||||
records.forEach {
|
||||
it.rawMaterialsTypes = it.rawMaterialsType
|
||||
it.rawMaterialsType = null
|
||||
it.oldGoodsId = it.goodsId
|
||||
it.goodsId = it.materId ?: ""
|
||||
}
|
||||
list.addAll(records)
|
||||
// mater-search 不返回净材种类,rawMaterialsTypes 保持 null,点击时直接选中返回
|
||||
val goodsItems = records.map { it.toGoodsItem() }
|
||||
list.addAll(goodsItems)
|
||||
adapter.notifyDataSetChanged()
|
||||
val isLoadMoreEnable = records.size >= PAGE_SIZE
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
if (isLoadMoreEnable) pageNo++
|
||||
}
|
||||
|
||||
/**
|
||||
* MaterSearchItem → GoodsItem 映射
|
||||
* id 即食材id,同时作为 goodsId 和 materId(提交 sample/save 时使用)
|
||||
*/
|
||||
private fun MaterSearchItem.toGoodsItem() = GoodsItem(
|
||||
goodsId = id,
|
||||
materId = id,
|
||||
goodsName = materName,
|
||||
materCode = materCode,
|
||||
popularName = alias
|
||||
)
|
||||
|
||||
private fun finishRefresh() {
|
||||
if (pageNo == 1) binding.refreshLayout.finishRefresh()
|
||||
else binding.refreshLayout.finishLoadMore()
|
||||
|
||||
@@ -15,7 +15,6 @@ import android.view.Window
|
||||
import android.view.WindowManager
|
||||
import android.widget.FrameLayout
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
@@ -25,13 +24,11 @@ import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.databinding.DialogSeasoningSelectBinding
|
||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.model.SeasoningSearchItem
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
* 调料选择弹窗,不含重量显示,继承 BottomSheetDialog 确保只初始化一次
|
||||
* @param activity 宿主 Activity
|
||||
@@ -64,7 +61,6 @@ class SeasoningSelectDialog(
|
||||
|
||||
private var goodsName: String? = null
|
||||
private var pageNo = 1
|
||||
private var collectJob: Job? = null
|
||||
|
||||
init {
|
||||
setContentView(binding.root)
|
||||
@@ -77,7 +73,6 @@ class SeasoningSelectDialog(
|
||||
window?.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
||||
|
||||
setOnDismissListener {
|
||||
collectJob?.cancel()
|
||||
activity.hideStatusBar()
|
||||
}
|
||||
|
||||
@@ -116,23 +111,6 @@ class SeasoningSelectDialog(
|
||||
/** 弹窗显示时自动加载默认调料列表,并在 Window.Callback 层提前拦截触摸以解决滑动冲突 */
|
||||
override fun show() {
|
||||
super.show()
|
||||
// 启动 StateFlow 收集,弹窗关闭时由 setOnDismissListener 取消
|
||||
collectJob = activity.lifecycleScope.launch {
|
||||
activity.netViewModel.foodSearchGoodsListState.collect { state ->
|
||||
when (state) {
|
||||
is UiState.Loading -> {}
|
||||
is UiState.Success -> loadGoodsList(state.data)
|
||||
is UiState.Error -> {
|
||||
activity.toast(state.msg)
|
||||
finishRefresh()
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
}
|
||||
is UiState.Idle -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
pageNo = 1
|
||||
getGoodsList()
|
||||
// Window.Callback.dispatchTouchEvent 在整个 View 树的 onInterceptTouchEvent 之前执行,
|
||||
@@ -184,14 +162,24 @@ class SeasoningSelectDialog(
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求调料列表
|
||||
* 请求调料列表(新配比秤接口,回调版本)
|
||||
*/
|
||||
private fun getGoodsList() {
|
||||
activity.netViewModel.queryFoodSearchGoodsList(
|
||||
goodsType = "1",
|
||||
activity.netViewModel.querySeasoningSearch(
|
||||
keyword = goodsName.takeUnless { it.isNullOrBlank() },
|
||||
pageNum = pageNo,
|
||||
pageSize = PAGE_SIZE,
|
||||
goodsName = goodsName.takeUnless { it.isNullOrBlank() }
|
||||
onResult = { state ->
|
||||
when (state) {
|
||||
is UiState.Success -> loadGoodsList(state.data)
|
||||
is UiState.Error -> {
|
||||
activity.toast(state.msg)
|
||||
finishRefresh()
|
||||
if (pageNo == 1) loadEmptyView()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -203,23 +191,22 @@ class SeasoningSelectDialog(
|
||||
"盐", "白砂糖", "冰糖", "鸡精", "味精", "陈醋", "老抽", "生抽", "番茄酱", "胡椒粉", "孜然", "十三香",
|
||||
"料酒", "白醋", "蚝油", "辣椒面", "辣椒酱", "豆瓣酱", "淀粉", "葱", "蒜", "姜", "香菜", "油"
|
||||
)
|
||||
val mockData = mutableListOf<GoodsItem>()
|
||||
nameList.forEachIndexed { index, name ->
|
||||
val mockData = nameList.mapIndexed { index, name ->
|
||||
val padString = "${index + 1}".padStart(2, '0')
|
||||
mockData.add(GoodsItem(goodsId = "1000$padString", goodsName = name))
|
||||
SeasoningSearchItem(id = "1000$padString", materName = name)
|
||||
}
|
||||
pageNo = 1
|
||||
loadGoodsList(mockData)
|
||||
}
|
||||
|
||||
/**
|
||||
* 将返回数据转换并填充到列表
|
||||
* 将新接口返回的 SeasoningSearchItem 映射为 GoodsItem 并填充到列表
|
||||
* 新接口的 id 即食材id,同时用作 goodsId 和 materId,无需再交换
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun loadGoodsList(records: MutableList<GoodsItem>?) {
|
||||
private fun loadGoodsList(records: List<SeasoningSearchItem>?) {
|
||||
finishRefresh()
|
||||
if (records.isNullOrEmpty()) {
|
||||
//activity.toast("暂未搜索到调料信息")
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
@@ -227,18 +214,26 @@ class SeasoningSelectDialog(
|
||||
}
|
||||
binding.recyclerView.layoutManager = GridLayoutManager(activity, 3, GridLayoutManager.VERTICAL, false)
|
||||
if (pageNo == 1) list.clear()
|
||||
list.addAll(records)
|
||||
list.forEach {
|
||||
it.oldGoodsId = it.goodsId
|
||||
//materId才是提交数据需要的goodsId数据
|
||||
it.goodsId = it.materId ?:""
|
||||
}
|
||||
val goodsItems = records.map { it.toGoodsItem() }
|
||||
list.addAll(goodsItems)
|
||||
adapter.notifyDataSetChanged()
|
||||
val isLoadMoreEnable = records.size >= PAGE_SIZE
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
if (isLoadMoreEnable) pageNo++
|
||||
}
|
||||
|
||||
/**
|
||||
* SeasoningSearchItem → GoodsItem 映射
|
||||
* id 既是食材id也是提交时的 goodsId,不需要 oldGoodsId 交换
|
||||
*/
|
||||
private fun SeasoningSearchItem.toGoodsItem() = GoodsItem(
|
||||
goodsId = id,
|
||||
materId = id,
|
||||
goodsName = materName,
|
||||
materCode = materCode,
|
||||
popularName = alias
|
||||
)
|
||||
|
||||
private fun finishRefresh() {
|
||||
if (pageNo == 1) binding.refreshLayout.finishRefresh()
|
||||
else binding.refreshLayout.finishLoadMore()
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
package com.shuwei.dish.match.model
|
||||
|
||||
/**
|
||||
* 当日烹饪任务列表(按餐次分组)请求参数
|
||||
* 对应接口: POST /neglect/ratio-scale/cook-orders/page
|
||||
*/
|
||||
data class CookOrderPageRequest(
|
||||
/** 计划日期 yyyy-MM-dd,默认当天 */
|
||||
val date: String? = null,
|
||||
/** 餐次筛选: 1=早餐 / 2=午餐 / 3=晚餐 / 4=加餐,不传返回全部 */
|
||||
val mealType: Int? = null,
|
||||
/** 菜品名称模糊搜索 */
|
||||
val keyword: String? = null,
|
||||
/** 保留字段,当前不使用 */
|
||||
val pageNum: Int? = null,
|
||||
/** 保留字段,当前不使用 */
|
||||
val pageSize: Int? = null
|
||||
)
|
||||
|
||||
/**
|
||||
* 餐次分组,包含该餐次下的烹制单列表
|
||||
*/
|
||||
data class CookOrderMealGroup(
|
||||
/** 餐次: 1=早餐 / 2=午餐 / 3=晚餐 / 4=加餐 */
|
||||
val mealType: Int = 0,
|
||||
/** 餐次中文名称 */
|
||||
val mealTypeName: String = "",
|
||||
/** 该餐次下的烹制单列表 */
|
||||
val cookOrders: List<CookOrderItem> = emptyList()
|
||||
)
|
||||
|
||||
/**
|
||||
* 单个烹制单,对应接口响应中 cookOrders 数组的条目
|
||||
* 注意: Long 类型字段服务端序列化为 String
|
||||
*/
|
||||
data class CookOrderItem(
|
||||
/** 烹制单id(Long → String) */
|
||||
val cookOrderId: String = "",
|
||||
/** 烹制单号 */
|
||||
val cookNo: String = "",
|
||||
/** 菜品名称 */
|
||||
val dishName: String = "",
|
||||
/** 菜品id(关联 nut_food) */
|
||||
val foodId: String = "",
|
||||
/** 餐次: 1=早餐 / 2=午餐 / 3=晚餐 / 4=加餐 */
|
||||
val mealType: Int = 0,
|
||||
/** 餐次中文名称 */
|
||||
val mealTypeName: String = "",
|
||||
/** 烹制状态: 0=待烹制 / 1=烹制中 / 2=已完成 / 3=异常 */
|
||||
val cookStatus: Int = 0,
|
||||
/** 烹制状态中文 */
|
||||
val cookStatusName: String = "",
|
||||
/** 生重(kg),烹制完成后才有值 */
|
||||
val rawWeight: Double? = null,
|
||||
/** 熟重(kg),烹制完成后才有值 */
|
||||
val cookedWeight: Double? = null,
|
||||
/** 需求份数 */
|
||||
val needPortions: Int = 0,
|
||||
/** 烹制份数,烹制完成后才有值 */
|
||||
val cookedPortions: Int? = null
|
||||
)
|
||||
|
||||
/**
|
||||
* 菜品食材构成(主材+辅材),对应接口响应中单个食材
|
||||
* 对应接口: GET /neglect/ratio-scale/cook-orders/{cookOrderId}/composition
|
||||
* 注意: 此接口仅返回主材(ingredientClass=1)和辅材(ingredientClass=2),不含调料
|
||||
*/
|
||||
data class CookOrderCompositionItem(
|
||||
/** 食材id */
|
||||
val materId: String = "",
|
||||
/** 食材名称 */
|
||||
val ingredientName: String = "",
|
||||
/** 食材分类: 1=主材 / 2=辅材 */
|
||||
val ingredientClass: Int = 0,
|
||||
/** 食材分类中文名称 */
|
||||
val ingredientClassName: String = "",
|
||||
/** 标准用量(g) */
|
||||
val useWeight: Double = 0.0,
|
||||
/** 净菜类型id */
|
||||
val vegTypeId: String = ""
|
||||
)
|
||||
|
||||
// ==================== 调料模糊搜索 ====================
|
||||
|
||||
/**
|
||||
* 调料模糊搜索请求参数
|
||||
* 对应接口: POST /neglect/ratio-scale/seasoning-search
|
||||
* 数据源: nut_mater_base 一级分类为 18(糖蜜饯)、19(油脂)、20(调味品)
|
||||
*/
|
||||
data class SeasoningSearchRequest(
|
||||
/** 模糊匹配食材名称和别名,为空时返回全部 */
|
||||
val keyword: String? = null,
|
||||
/** 页码 */
|
||||
val pageNum: Int = 1,
|
||||
/** 每页条数 */
|
||||
val pageSize: Int = 20
|
||||
)
|
||||
|
||||
/**
|
||||
* 调料模糊搜索结果条目
|
||||
* 注意: Long 类型字段服务端序列化为 String
|
||||
*/
|
||||
data class SeasoningSearchItem(
|
||||
/** 食材id(Long → String) */
|
||||
val id: String = "",
|
||||
/** 食材名称 */
|
||||
val materName: String = "",
|
||||
/** 食材编码 */
|
||||
val materCode: String = "",
|
||||
/** 别名 */
|
||||
val alias: String = "",
|
||||
/** 归属食堂id(Long → String) */
|
||||
val canteenId: String = ""
|
||||
)
|
||||
|
||||
// ==================== 烹饪完成 ====================
|
||||
|
||||
/**
|
||||
* 烹饪完成 — 单个食材用量条目
|
||||
* 对应接口: POST /neglect/ratio-scale/cook-orders/complete
|
||||
*/
|
||||
data class CookCompleteItem(
|
||||
/** 食材id */
|
||||
val materId: String = "",
|
||||
/** 实际用量(g) */
|
||||
val actualQty: Double = 0.0,
|
||||
/** 调料首次使用时间 yyyy-MM-dd HH:mm:ss,仅调料需要,主辅材留空 */
|
||||
val putTime: String? = null
|
||||
)
|
||||
|
||||
/**
|
||||
* 烹饪完成请求,一次性提交主辅材用量+熟重+调料
|
||||
* 对应接口: POST /neglect/ratio-scale/cook-orders/complete
|
||||
*/
|
||||
data class CookCompleteRequest(
|
||||
/** 烹制单id */
|
||||
val cookOrderId: String = "",
|
||||
/** 烹饪开始时间 yyyy-MM-dd HH:mm:ss,进入提交页面时刻 */
|
||||
val cookStart: String? = null,
|
||||
/** 主辅材实际用量列表,至少1条 */
|
||||
val items: List<CookCompleteItem> = emptyList(),
|
||||
/** 熟重(kg) */
|
||||
val cookedWeight: Double = 0.0,
|
||||
/** 调料用量列表,选填 */
|
||||
val seasonings: List<CookCompleteItem>? = null
|
||||
)
|
||||
@@ -15,5 +15,12 @@ data class FoodRecord(
|
||||
var dinnerType: String = "0",
|
||||
//true-原始数据,false-非原始数据
|
||||
var isOriginalData: Boolean = true,
|
||||
var sort: Int = 0
|
||||
var sort: Int = 0,
|
||||
// ===== 已提交采样列表(sample-list)扩展字段,制作模式不涉及 =====
|
||||
/** 实验编号(innovNo) */
|
||||
var innovNo: String? = null,
|
||||
/** 实验状态: 1=实验中 / 2=已评测 / 9=已转化 */
|
||||
var status: Int? = null,
|
||||
/** 实验状态中文 */
|
||||
var statusName: String? = null
|
||||
) : Serializable
|
||||
|
||||
@@ -32,6 +32,8 @@ data class GoodsItem(
|
||||
var isClicked: Boolean = false,
|
||||
// true-原始数据,false-非原始数据(识图新增)
|
||||
var isOriginalData: Boolean = true,
|
||||
// true-用户手动指定了主辅材,updateMaterialTypes 自动分配时跳过
|
||||
var isMaterialTypeManual: Boolean = false,
|
||||
// 识图匹配分数,-1 表示不显示
|
||||
var foodScore: Int = -1,
|
||||
// 净材种类(当前选中值)
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
package com.shuwei.dish.match.model
|
||||
|
||||
/**
|
||||
* 采样与制作模式相关模型,对应配比秤接口(Controller: NutRatioScaleController)
|
||||
* 路径前缀: /neglect/ratio-scale
|
||||
* 序列化规则: Long 字段服务端返回字符串;请求体字段按后端约定(id 类字段用 String 与现有代码一致)
|
||||
*/
|
||||
|
||||
/** 采样实验状态(味养创新 nut_innovation.status) */
|
||||
object SampleStatus {
|
||||
/** 实验中 */
|
||||
const val EXPERIMENTING = 1
|
||||
/** 已评测 */
|
||||
const val EVALUATED = 2
|
||||
/** 已转化 */
|
||||
const val CONVERTED = 9
|
||||
}
|
||||
|
||||
// ==================== 一、食材模糊搜索 ====================
|
||||
|
||||
/**
|
||||
* 食材模糊搜索请求参数
|
||||
* 对应接口: POST /neglect/ratio-scale/mater-search
|
||||
* 数据源: nut_mater_base,限定设备对应食堂
|
||||
*/
|
||||
data class MaterSearchRequest(
|
||||
/** 模糊匹配食材名称和别名,为空时返回全部 */
|
||||
val keyword: String? = null,
|
||||
/** 页码 */
|
||||
val pageNum: Int = 1,
|
||||
/** 每页条数 */
|
||||
val pageSize: Int = 20
|
||||
)
|
||||
|
||||
/**
|
||||
* 食材模糊搜索结果条目
|
||||
* 注意: id / canteenId 为 Long 类型,服务端序列化为 String
|
||||
*/
|
||||
data class MaterSearchItem(
|
||||
/** 食材id(Long → String,提交构成 items.materId 使用) */
|
||||
val id: String = "",
|
||||
/** 食材名称 */
|
||||
val materName: String = "",
|
||||
/** 食材编码(一级+二级+自编码,全局唯一) */
|
||||
val materCode: String = "",
|
||||
/** 别名,可能为 null */
|
||||
val alias: String? = null,
|
||||
/** 食材一级分类 */
|
||||
val materFirstClass: String? = null,
|
||||
/** 食材二级分类 */
|
||||
val materSecondClass: String? = null,
|
||||
/** 食材图片url */
|
||||
val materUrl: String? = null,
|
||||
/** 归属食堂id(Long → String) */
|
||||
val canteenId: String = ""
|
||||
)
|
||||
|
||||
// ==================== 二、搜菜品 ====================
|
||||
|
||||
/**
|
||||
* 搜菜品请求参数(制作模式选已有菜品)
|
||||
* 对应接口: POST /neglect/ratio-scale/food-search
|
||||
* 数据源: nut_food(status=1 上架)
|
||||
*/
|
||||
data class FoodSearchRequest(
|
||||
/** 菜品名称或编号模糊搜索 */
|
||||
val keyword: String? = null,
|
||||
/** 页码 */
|
||||
val pageNum: Int = 1,
|
||||
/** 每页条数 */
|
||||
val pageSize: Int = 20
|
||||
)
|
||||
|
||||
/**
|
||||
* 搜菜品结果条目
|
||||
* 注意: foodId 为 Long 类型,服务端序列化为 String
|
||||
*/
|
||||
data class FoodSearchItem(
|
||||
/** 菜品id(Long → String) */
|
||||
val foodId: String = "",
|
||||
/** 菜品编号 */
|
||||
val foodCode: String = "",
|
||||
/** 菜品名称 */
|
||||
val foodName: String = ""
|
||||
)
|
||||
|
||||
// ==================== 三、查菜品构成 ====================
|
||||
|
||||
/**
|
||||
* 查菜品构成响应 — 单个食材
|
||||
* 对应接口: GET /neglect/ratio-scale/food/{foodId}/composition
|
||||
*/
|
||||
data class FoodCompositionIngredient(
|
||||
/** 食材id(Long → String) */
|
||||
val materId: String = "",
|
||||
/** 食材名称 */
|
||||
val materName: String = "",
|
||||
/** 用量(g) */
|
||||
val useWeight: Double = 0.0,
|
||||
/** 1=主材 / 2=辅材 / 3=调料 */
|
||||
val isMain: Int = 0,
|
||||
/** 分类中文名 */
|
||||
val isMainName: String = ""
|
||||
)
|
||||
|
||||
/**
|
||||
* 查菜品构成响应(主辅料+调料 + 熟重)
|
||||
* 对应接口: GET /neglect/ratio-scale/food/{foodId}/composition
|
||||
*/
|
||||
data class FoodCompositionResponse(
|
||||
/** 菜品id(Long → String) */
|
||||
val foodId: String = "",
|
||||
/** 菜品名称 */
|
||||
val foodName: String = "",
|
||||
/** 熟重(g),从 nut_food_cook.output_weight 反查 */
|
||||
val foodWeight: Double = 0.0,
|
||||
/** 食材构成列表 */
|
||||
val ingredients: List<FoodCompositionIngredient> = emptyList()
|
||||
)
|
||||
|
||||
// ==================== 四、提交采样 ====================
|
||||
|
||||
/**
|
||||
* 提交采样 — 单个食材构成条目
|
||||
* 对应接口: POST /neglect/ratio-scale/constitute/save
|
||||
*/
|
||||
data class ConstituteSaveItem(
|
||||
/** 食材id(nut_mater_base.id) */
|
||||
val materId: String = "",
|
||||
/** 食材称量用量(g),必须 > 0 */
|
||||
val useWeight: Double = 0.0,
|
||||
/** 食材分类: 1=主材 / 2=辅材 / 3=调料 */
|
||||
val isMain: Int = 0
|
||||
)
|
||||
|
||||
/**
|
||||
* 提交采样请求(落库味养创新实验,status=1 实验中)
|
||||
* 对应接口: POST /neglect/ratio-scale/constitute/save
|
||||
* 制作模式已废弃本接口,统一为提交采样,不再传 cookMode/foodId
|
||||
*/
|
||||
data class ConstituteSaveRequest(
|
||||
/** 菜品名称 */
|
||||
val foodName: String? = null,
|
||||
/** 熟重(g),必须 > 0 */
|
||||
val foodWeight: Double = 0.0,
|
||||
/** 食材构成列表,至少 1 条 */
|
||||
val items: List<ConstituteSaveItem> = emptyList()
|
||||
)
|
||||
|
||||
// ==================== 五、已提交采样列表 ====================
|
||||
|
||||
/**
|
||||
* 已提交采样列表查询请求参数
|
||||
* 对应接口: POST /neglect/ratio-scale/sample-list
|
||||
* 数据源: nut_innovation(source=2 配比秤采样),按提交时间倒序,不分日期
|
||||
*/
|
||||
data class SampleHistoryRequest(
|
||||
/** 页码 */
|
||||
val pageNum: Int = 1,
|
||||
/** 每页条数 */
|
||||
val pageSize: Int = 10
|
||||
)
|
||||
|
||||
/**
|
||||
* 已提交采样列表结果条目
|
||||
* 注意: innovId 为 Long 类型,服务端序列化为 String
|
||||
*/
|
||||
data class SampleHistoryItem(
|
||||
/** 味养创新实验id(Long → String) */
|
||||
val innovId: String = "",
|
||||
/** 实验编号 */
|
||||
val innovNo: String = "",
|
||||
/** 餐品名称 */
|
||||
val foodName: String = "",
|
||||
/** 熟重(g) */
|
||||
val foodWeight: Double = 0.0,
|
||||
/** 状态: 1=实验中 / 2=已评测 / 9=已转化 */
|
||||
val status: Int = 0,
|
||||
/** 状态中文 */
|
||||
val statusName: String = "",
|
||||
/** 提交时间 */
|
||||
val createTime: String = ""
|
||||
)
|
||||
|
||||
// ==================== 六、制作历史 ====================
|
||||
|
||||
/**
|
||||
* 制作历史查询请求参数
|
||||
* 对应接口: POST /neglect/ratio-scale/make/history
|
||||
* 数据源: nut_food_matching_use,按设备过滤
|
||||
*/
|
||||
data class MakeHistoryRequest(
|
||||
/** 页码 */
|
||||
val pageNum: Int = 1,
|
||||
/** 每页条数 */
|
||||
val pageSize: Int = 10,
|
||||
/** 制作日期 yyyy-MM-dd,不传查全部 */
|
||||
val day: String? = null
|
||||
)
|
||||
|
||||
/**
|
||||
* 制作历史结果条目
|
||||
* 注意: id / foodId 为 Long 类型,服务端序列化为 String
|
||||
*/
|
||||
data class MakeHistoryItem(
|
||||
/** 制作记录id(Long → String) */
|
||||
val id: String = "",
|
||||
/** 菜品id(Long → String) */
|
||||
val foodId: String = "",
|
||||
/** 菜品名称 */
|
||||
val foodName: String = "",
|
||||
/** 熟重(g) */
|
||||
val foodWeight: Double = 0.0,
|
||||
/** 餐次: 1=早餐/2=午餐/3=晚餐/4=加餐 */
|
||||
val mealType: Int = 0,
|
||||
/** 餐次中文 */
|
||||
val mealTypeName: String = "",
|
||||
/** 制作日期 */
|
||||
val day: String = "",
|
||||
/** 制作时间 */
|
||||
val createTime: String = ""
|
||||
)
|
||||
|
||||
// ==================== 七、制作历史图表 ====================
|
||||
|
||||
/**
|
||||
* 制作历史图表 — 横轴项
|
||||
* 对应接口: GET /neglect/ratio-scale/make/history/{foodId}
|
||||
*/
|
||||
data class MakeHistoryChartAxis(
|
||||
/** 食材id(时间/熟重项为空字符串) */
|
||||
val goodId: String = "",
|
||||
/** 项名称(时间/熟重/食材名称) */
|
||||
val goodName: String = ""
|
||||
)
|
||||
|
||||
/**
|
||||
* 制作历史图表 — 纵轴值
|
||||
* value 为 String(时间项) 或 Double(数值项)
|
||||
*/
|
||||
data class MakeHistoryChartValue(
|
||||
val value: Any? = null
|
||||
)
|
||||
|
||||
/**
|
||||
* 制作历史图表 — 单条记录(xAxes 与 yAxes 一一对应)
|
||||
*/
|
||||
data class MakeHistoryChartRow(
|
||||
val xAxes: List<MakeHistoryChartAxis> = emptyList(),
|
||||
val yAxes: List<MakeHistoryChartValue> = emptyList()
|
||||
)
|
||||
@@ -2,8 +2,25 @@ package com.shuwei.dish.match.net
|
||||
|
||||
import com.shuwei.dish.match.base.GlobalData
|
||||
import com.shuwei.dish.match.model.CookFoodDTO
|
||||
import com.shuwei.dish.match.model.CookOrderCompositionItem
|
||||
import com.shuwei.dish.match.model.CookOrderMealGroup
|
||||
import com.shuwei.dish.match.model.CookOrderPageRequest
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.model.ConstituteSaveRequest
|
||||
import com.shuwei.dish.match.model.CookCompleteRequest
|
||||
import com.shuwei.dish.match.model.FoodCompositionResponse
|
||||
import com.shuwei.dish.match.model.FoodSearchItem
|
||||
import com.shuwei.dish.match.model.FoodSearchRequest
|
||||
import com.shuwei.dish.match.model.MakeHistoryChartRow
|
||||
import com.shuwei.dish.match.model.MakeHistoryItem
|
||||
import com.shuwei.dish.match.model.MakeHistoryRequest
|
||||
import com.shuwei.dish.match.model.MaterSearchItem
|
||||
import com.shuwei.dish.match.model.MaterSearchRequest
|
||||
import com.shuwei.dish.match.model.SampleHistoryItem
|
||||
import com.shuwei.dish.match.model.SampleHistoryRequest
|
||||
import com.shuwei.dish.match.model.SeasoningSearchItem
|
||||
import com.shuwei.dish.match.model.SeasoningSearchRequest
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.http.Body
|
||||
@@ -12,6 +29,7 @@ import retrofit2.http.Multipart
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.Part
|
||||
import retrofit2.http.PartMap
|
||||
import retrofit2.http.Path
|
||||
import retrofit2.http.Query
|
||||
import retrofit2.http.Url
|
||||
|
||||
@@ -22,7 +40,7 @@ interface ApiService {
|
||||
*/
|
||||
@GET
|
||||
suspend fun getFoodDetail(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/getConstituteByFoodId",
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/matching/app/getConstituteByFoodId",
|
||||
@Query("foodId") foodId: String
|
||||
): ApiResponse<CookFoodDTO?>
|
||||
|
||||
@@ -32,16 +50,16 @@ interface ApiService {
|
||||
*/
|
||||
@POST
|
||||
suspend fun submitCookFood(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/saveConstitute",
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/matching/app/saveConstitute",
|
||||
@Body param: CookFoodDTO
|
||||
): ApiResponse<Any?>
|
||||
|
||||
/**
|
||||
* 搜索菜品
|
||||
* 搜索菜品(旧接口,采样模式仍在使用)
|
||||
*/
|
||||
@POST
|
||||
suspend fun searchFoodList(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryPageList",
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/matching/app/queryPageList",
|
||||
@Body param: MutableMap<String, Any>
|
||||
): ApiResponse<MutableList<FoodRecord>?>
|
||||
|
||||
@@ -50,7 +68,7 @@ interface ApiService {
|
||||
*/
|
||||
@POST
|
||||
suspend fun getSamplingList(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryHistoryGoodsInfoList",
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/matching/app/queryHistoryGoodsInfoList",
|
||||
@Body param: MutableMap<String, Any>
|
||||
): ApiResponse<MutableList<FoodRecord>?>
|
||||
|
||||
@@ -59,7 +77,7 @@ interface ApiService {
|
||||
*/
|
||||
@POST
|
||||
suspend fun queryGoodsList(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/queryGoodsInfoList",
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/matching/app/queryGoodsInfoList",
|
||||
@Body param: MutableMap<String, Any>
|
||||
): ApiResponse<MutableList<GoodsItem>?>
|
||||
|
||||
@@ -69,8 +87,110 @@ interface ApiService {
|
||||
@Multipart
|
||||
@POST
|
||||
suspend fun uploadFoodVectorData(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/matching/app/addWeighingCollectionData",
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/matching/app/addWeighingCollectionData",
|
||||
@PartMap params: MutableMap<String, RequestBody>,
|
||||
@Part foodPics: List<MultipartBody.Part>
|
||||
): ApiResponse<List<String>?>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询当日烹饪任务列表(按餐次分组),新配比秤接口
|
||||
*/
|
||||
@POST
|
||||
suspend fun getCookOrderPage(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/cook-orders/list",
|
||||
@Body request: CookOrderPageRequest
|
||||
): ApiResponse<List<CookOrderMealGroup>?>
|
||||
|
||||
/**
|
||||
* 查询菜品食材构成(主材+辅材,不含调料),新配比秤接口
|
||||
*/
|
||||
@GET("nutrition/neglect/ratio-scale/cook-orders/{cookOrderId}/composition")
|
||||
suspend fun getCookOrderComposition(
|
||||
@Path("cookOrderId") cookOrderId: String
|
||||
): ApiResponse<List<CookOrderCompositionItem>?>
|
||||
|
||||
/**
|
||||
* 调料模糊搜索,新配比秤接口
|
||||
* 数据源: nut_mater_base 一级分类为 18(糖蜜饯)、19(油脂)、20(调味品)
|
||||
*/
|
||||
@POST
|
||||
suspend fun getSeasoningSearch(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/seasoning-search",
|
||||
@Body request: SeasoningSearchRequest
|
||||
): ApiResponse<List<SeasoningSearchItem>?>
|
||||
|
||||
/**
|
||||
* 烹饪完成:提交主辅材用量+熟重+调料,一次性完成烹制
|
||||
* 新配比秤接口,替代旧 saveConstitute
|
||||
*/
|
||||
@POST
|
||||
suspend fun cookOrderComplete(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/cook-orders/complete",
|
||||
@Body request: CookCompleteRequest
|
||||
): ApiResponse<Any?>
|
||||
|
||||
/**
|
||||
* 食材模糊搜索(采样/制作通用,称量前检索食材)
|
||||
* 数据源: nut_mater_base,限定设备对应食堂,模糊匹配名称和别名
|
||||
*/
|
||||
@POST
|
||||
suspend fun materSearch(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/mater-search",
|
||||
@Body request: MaterSearchRequest
|
||||
): ApiResponse<MutableList<MaterSearchItem>?>
|
||||
|
||||
/**
|
||||
* 搜菜品(制作模式选已有上架菜品)
|
||||
*/
|
||||
@POST
|
||||
suspend fun foodSearch(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/food-search",
|
||||
@Body request: FoodSearchRequest
|
||||
): ApiResponse<MutableList<FoodSearchItem>?>
|
||||
|
||||
/**
|
||||
* 查菜品构成(制作模式查看已有菜品主辅料+调料 + 熟重)
|
||||
*/
|
||||
@GET("nutrition/neglect/ratio-scale/food/{foodId}/composition")
|
||||
suspend fun getFoodComposition(
|
||||
@Path("foodId") foodId: String
|
||||
): ApiResponse<FoodCompositionResponse?>
|
||||
|
||||
/**
|
||||
* 提交采样(落库味养创新实验,制作模式已废弃本接口)
|
||||
*/
|
||||
@POST
|
||||
suspend fun constituteSave(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/constitute/save",
|
||||
@Body request: ConstituteSaveRequest
|
||||
): ApiResponse<Any?>
|
||||
|
||||
/**
|
||||
* 已提交采样列表(本食堂 source=2,按提交时间倒序,不分日期)
|
||||
*/
|
||||
@POST
|
||||
suspend fun sampleHistory(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/sample-list",
|
||||
@Body request: SampleHistoryRequest
|
||||
): ApiResponse<MutableList<SampleHistoryItem>?>
|
||||
|
||||
/**
|
||||
* 制作历史(本设备,按日期可选过滤)
|
||||
*/
|
||||
@POST
|
||||
suspend fun makeHistory(
|
||||
@Url url: String = "${GlobalData.appBaseUrl}/nutrition/neglect/ratio-scale/make/history",
|
||||
@Body request: MakeHistoryRequest
|
||||
): ApiResponse<MutableList<MakeHistoryItem>?>
|
||||
|
||||
/**
|
||||
* 制作历史图表(按菜品id)
|
||||
*/
|
||||
@GET("nutrition/neglect/ratio-scale/make/history/{foodId}")
|
||||
suspend fun makeHistoryChart(
|
||||
@Path("foodId") foodId: String
|
||||
): ApiResponse<MutableList<MakeHistoryChartRow>?>
|
||||
|
||||
}
|
||||
@@ -4,9 +4,26 @@ import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.model.CookFoodDTO
|
||||
import com.shuwei.dish.match.model.CookOrderCompositionItem
|
||||
import com.shuwei.dish.match.model.CookOrderMealGroup
|
||||
import com.shuwei.dish.match.model.CookOrderPageRequest
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.model.GoodsNameQueryDTO
|
||||
import com.shuwei.dish.match.model.ConstituteSaveRequest
|
||||
import com.shuwei.dish.match.model.CookCompleteRequest
|
||||
import com.shuwei.dish.match.model.FoodCompositionResponse
|
||||
import com.shuwei.dish.match.model.FoodSearchItem
|
||||
import com.shuwei.dish.match.model.FoodSearchRequest
|
||||
import com.shuwei.dish.match.model.MakeHistoryChartRow
|
||||
import com.shuwei.dish.match.model.MakeHistoryItem
|
||||
import com.shuwei.dish.match.model.MakeHistoryRequest
|
||||
import com.shuwei.dish.match.model.MaterSearchItem
|
||||
import com.shuwei.dish.match.model.MaterSearchRequest
|
||||
import com.shuwei.dish.match.model.SampleHistoryItem
|
||||
import com.shuwei.dish.match.model.SampleHistoryRequest
|
||||
import com.shuwei.dish.match.model.SeasoningSearchItem
|
||||
import com.shuwei.dish.match.model.SeasoningSearchRequest
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
@@ -64,6 +81,23 @@ class NetViewModel(
|
||||
_foodDetailState.value = UiState.Idle
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询菜品食材构成的 UI 状态流(新配比秤接口),UI 层通过 collect 监听
|
||||
*/
|
||||
private val _cookOrderCompositionState = MutableStateFlow<UiState<List<CookOrderCompositionItem>?>>(UiState.Idle)
|
||||
val cookOrderCompositionState: StateFlow<UiState<List<CookOrderCompositionItem>?>> = _cookOrderCompositionState.asStateFlow()
|
||||
|
||||
/**
|
||||
* 查询菜品食材构成(新配比秤接口,仅返回主材+辅材)
|
||||
* @param cookOrderId 烹制单 ID
|
||||
*/
|
||||
fun getCookOrderComposition(cookOrderId: String) {
|
||||
viewModelScope.launch {
|
||||
_cookOrderCompositionState.value = UiState.Loading
|
||||
_cookOrderCompositionState.value = repository.getCookOrderComposition(cookOrderId)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索菜品列表的 UI 状态流。
|
||||
* 使用 replay=1 保证 Fragment 重建后能收到最近一次结果;
|
||||
@@ -104,6 +138,42 @@ class NetViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 当日烹饪任务列表的 UI 状态流(新配比秤接口),UI 层通过 collect 监听
|
||||
* 使用 SharedFlow(replay=1) 保证 Fragment 重建后收到最近一次结果
|
||||
*/
|
||||
private val _cookOrderPageState = MutableSharedFlow<UiState<List<CookOrderMealGroup>?>>(
|
||||
replay = 1,
|
||||
extraBufferCapacity = 1
|
||||
)
|
||||
val cookOrderPageState: SharedFlow<UiState<List<CookOrderMealGroup>?>> = _cookOrderPageState.asSharedFlow()
|
||||
|
||||
/**
|
||||
* 查询当日烹饪任务列表(新配比秤接口,StateFlow 版本)
|
||||
* 适合 FoodSearchActivity 等通过 collect 监听结果的场景
|
||||
*/
|
||||
fun getCookOrderPage(request: CookOrderPageRequest) {
|
||||
viewModelScope.launch {
|
||||
_cookOrderPageState.emit(UiState.Loading)
|
||||
_cookOrderPageState.emit(repository.getCookOrderPage(request))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当日烹饪任务列表(新配比秤接口,回调版本)
|
||||
* 适合 FoodListFragment 下拉刷新、Tab 切换等需要每次都能触发的场景
|
||||
*/
|
||||
fun getCookOrderPageWithCallback(
|
||||
request: CookOrderPageRequest,
|
||||
onLoading: () -> Unit = {},
|
||||
onResult: (UiState<List<CookOrderMealGroup>?>) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
onLoading()
|
||||
onResult(repository.getCookOrderPage(request))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
private val _samplingListState = MutableStateFlow<UiState<MutableList<FoodRecord>?>>(UiState.Idle)
|
||||
@@ -215,6 +285,166 @@ class NetViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 调料模糊搜索(新配比秤接口,回调版本)
|
||||
* 替代旧 queryGoodsList(goodsType=1) 调用
|
||||
* @param keyword 模糊匹配食材名称和别名,为 null 时不传该字段
|
||||
* @param pageNum 页码,默认第 1 页
|
||||
* @param pageSize 每页条数,默认 50
|
||||
* @param onLoading 请求发起前的回调
|
||||
* @param onResult 结果回调,直接接收 UiState<List<SeasoningSearchItem>?>
|
||||
*/
|
||||
fun querySeasoningSearch(
|
||||
keyword: String? = null,
|
||||
pageNum: Int = 1,
|
||||
pageSize: Int = 50,
|
||||
onLoading: () -> Unit = {},
|
||||
onResult: (UiState<List<SeasoningSearchItem>?>) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
onLoading()
|
||||
onResult(repository.getSeasoningSearch(
|
||||
SeasoningSearchRequest(keyword = keyword, pageNum = pageNum, pageSize = pageSize)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 烹饪完成(新配比秤接口,回调版本),替代旧 submitCookFood
|
||||
* 仅在制作模式下 cookOrderId 可用的场景调用
|
||||
*/
|
||||
fun cookOrderComplete(
|
||||
request: CookCompleteRequest,
|
||||
onLoading: () -> Unit = {},
|
||||
onResult: (UiState<Any?>) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
onLoading()
|
||||
onResult(repository.cookOrderComplete(request))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 食材模糊搜索(回调版本)
|
||||
* @param keyword 模糊匹配食材名称和别名,为 null 时不传该字段
|
||||
* @param pageNum 页码,默认第 1 页
|
||||
* @param pageSize 每页条数,默认 20
|
||||
*/
|
||||
fun materSearch(
|
||||
keyword: String? = null,
|
||||
pageNum: Int = 1,
|
||||
pageSize: Int = 20,
|
||||
onLoading: () -> Unit = {},
|
||||
onResult: (UiState<MutableList<MaterSearchItem>?>) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
onLoading()
|
||||
onResult(repository.materSearch(
|
||||
MaterSearchRequest(keyword = keyword, pageNum = pageNum, pageSize = pageSize)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜菜品(回调版本,制作模式选已有上架菜品)
|
||||
*/
|
||||
fun foodSearch(
|
||||
keyword: String? = null,
|
||||
pageNum: Int = 1,
|
||||
pageSize: Int = 20,
|
||||
onLoading: () -> Unit = {},
|
||||
onResult: (UiState<MutableList<FoodSearchItem>?>) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
onLoading()
|
||||
onResult(repository.foodSearch(
|
||||
FoodSearchRequest(keyword = keyword, pageNum = pageNum, pageSize = pageSize)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查菜品构成(回调版本,制作模式)
|
||||
*/
|
||||
fun getFoodComposition(
|
||||
foodId: String,
|
||||
onLoading: () -> Unit = {},
|
||||
onResult: (UiState<FoodCompositionResponse?>) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
onLoading()
|
||||
onResult(repository.getFoodComposition(foodId))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交采样(回调版本,落库味养创新实验,制作模式已废弃本接口)
|
||||
*/
|
||||
fun constituteSave(
|
||||
request: ConstituteSaveRequest,
|
||||
onLoading: () -> Unit = {},
|
||||
onResult: (UiState<Any?>) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
onLoading()
|
||||
onResult(repository.constituteSave(request))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 已提交采样列表(回调版本,本食堂 source=2,不分日期)
|
||||
* @param pageNum 页码,默认第 1 页
|
||||
* @param pageSize 每页条数,默认 10
|
||||
*/
|
||||
fun sampleHistory(
|
||||
pageNum: Int = 1,
|
||||
pageSize: Int = 10,
|
||||
onLoading: () -> Unit = {},
|
||||
onResult: (UiState<MutableList<SampleHistoryItem>?>) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
onLoading()
|
||||
onResult(repository.sampleHistory(
|
||||
SampleHistoryRequest(
|
||||
pageNum = pageNum,
|
||||
pageSize = pageSize
|
||||
)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 制作历史(回调版本,本设备按日期可选过滤)
|
||||
*/
|
||||
fun makeHistory(
|
||||
pageNum: Int = 1,
|
||||
pageSize: Int = 10,
|
||||
day: String? = null,
|
||||
onLoading: () -> Unit = {},
|
||||
onResult: (UiState<MutableList<MakeHistoryItem>?>) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
onLoading()
|
||||
onResult(repository.makeHistory(
|
||||
MakeHistoryRequest(pageNum = pageNum, pageSize = pageSize, day = day)
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 制作历史图表(回调版本,按菜品id)
|
||||
*/
|
||||
fun makeHistoryChart(
|
||||
foodId: String,
|
||||
onLoading: () -> Unit = {},
|
||||
onResult: (UiState<MutableList<MakeHistoryChartRow>?>) -> Unit
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
onLoading()
|
||||
onResult(repository.makeHistoryChart(foodId))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传采集菜品信息 UI 状态流,UI 层通过 collect 监听
|
||||
*/
|
||||
|
||||
@@ -1,8 +1,25 @@
|
||||
package com.shuwei.dish.match.net
|
||||
|
||||
import com.shuwei.dish.match.model.CookFoodDTO
|
||||
import com.shuwei.dish.match.model.CookOrderCompositionItem
|
||||
import com.shuwei.dish.match.model.CookOrderMealGroup
|
||||
import com.shuwei.dish.match.model.CookOrderPageRequest
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
import com.shuwei.dish.match.model.ConstituteSaveRequest
|
||||
import com.shuwei.dish.match.model.CookCompleteRequest
|
||||
import com.shuwei.dish.match.model.FoodCompositionResponse
|
||||
import com.shuwei.dish.match.model.FoodSearchItem
|
||||
import com.shuwei.dish.match.model.FoodSearchRequest
|
||||
import com.shuwei.dish.match.model.MakeHistoryChartRow
|
||||
import com.shuwei.dish.match.model.MakeHistoryItem
|
||||
import com.shuwei.dish.match.model.MakeHistoryRequest
|
||||
import com.shuwei.dish.match.model.MaterSearchItem
|
||||
import com.shuwei.dish.match.model.MaterSearchRequest
|
||||
import com.shuwei.dish.match.model.SampleHistoryItem
|
||||
import com.shuwei.dish.match.model.SampleHistoryRequest
|
||||
import com.shuwei.dish.match.model.SeasoningSearchItem
|
||||
import com.shuwei.dish.match.model.SeasoningSearchRequest
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
|
||||
@@ -31,6 +48,14 @@ class RemoteRepository {
|
||||
suspend fun getFoodDetail(foodId: String): UiState<CookFoodDTO?> =
|
||||
safeApiCall { apiService.getFoodDetail(foodId = foodId) }
|
||||
|
||||
/** 查询当日烹饪任务列表(按餐次分组),新配比秤接口 */
|
||||
suspend fun getCookOrderPage(request: CookOrderPageRequest): UiState<List<CookOrderMealGroup>?> =
|
||||
safeApiCall { apiService.getCookOrderPage(request = request) }
|
||||
|
||||
/** 查询菜品食材构成(主材+辅材),新配比秤接口 */
|
||||
suspend fun getCookOrderComposition(cookOrderId: String): UiState<List<CookOrderCompositionItem>?> =
|
||||
safeApiCall { apiService.getCookOrderComposition(cookOrderId = cookOrderId) }
|
||||
|
||||
/** 搜索菜品列表 */
|
||||
suspend fun searchFoodList(param: MutableMap<String, Any>): UiState<MutableList<FoodRecord>?> =
|
||||
safeApiCall { apiService.searchFoodList(param = param) }
|
||||
@@ -43,6 +68,42 @@ class RemoteRepository {
|
||||
suspend fun queryGoodsList(param: MutableMap<String, Any>): UiState<MutableList<GoodsItem>?> =
|
||||
safeApiCall { apiService.queryGoodsList(param = param) }
|
||||
|
||||
/** 调料模糊搜索,新配比秤接口 */
|
||||
suspend fun getSeasoningSearch(request: SeasoningSearchRequest): UiState<List<SeasoningSearchItem>?> =
|
||||
safeApiCall { apiService.getSeasoningSearch(request = request) }
|
||||
|
||||
/** 烹饪完成,新配比秤接口,替代旧 submitCookFood */
|
||||
suspend fun cookOrderComplete(request: CookCompleteRequest): UiState<Any?> =
|
||||
safeApiCall { apiService.cookOrderComplete(request = request) }
|
||||
|
||||
/** 食材模糊搜索 */
|
||||
suspend fun materSearch(request: MaterSearchRequest): UiState<MutableList<MaterSearchItem>?> =
|
||||
safeApiCall { apiService.materSearch(request = request) }
|
||||
|
||||
/** 搜菜品(制作模式选已有上架菜品) */
|
||||
suspend fun foodSearch(request: FoodSearchRequest): UiState<MutableList<FoodSearchItem>?> =
|
||||
safeApiCall { apiService.foodSearch(request = request) }
|
||||
|
||||
/** 查菜品构成(制作模式) */
|
||||
suspend fun getFoodComposition(foodId: String): UiState<FoodCompositionResponse?> =
|
||||
safeApiCall { apiService.getFoodComposition(foodId = foodId) }
|
||||
|
||||
/** 提交采样(落库味养创新实验,制作模式已废弃本接口) */
|
||||
suspend fun constituteSave(request: ConstituteSaveRequest): UiState<Any?> =
|
||||
safeApiCall { apiService.constituteSave(request = request) }
|
||||
|
||||
/** 已提交采样列表(本食堂 source=2,按提交时间倒序,不分日期) */
|
||||
suspend fun sampleHistory(request: SampleHistoryRequest): UiState<MutableList<SampleHistoryItem>?> =
|
||||
safeApiCall { apiService.sampleHistory(request = request) }
|
||||
|
||||
/** 制作历史(本设备,按日期可选过滤) */
|
||||
suspend fun makeHistory(request: MakeHistoryRequest): UiState<MutableList<MakeHistoryItem>?> =
|
||||
safeApiCall { apiService.makeHistory(request = request) }
|
||||
|
||||
/** 制作历史图表(按菜品id) */
|
||||
suspend fun makeHistoryChart(foodId: String): UiState<MutableList<MakeHistoryChartRow>?> =
|
||||
safeApiCall { apiService.makeHistoryChart(foodId = foodId) }
|
||||
|
||||
/** 上传采集数据 */
|
||||
suspend fun uploadFoodVectorData(
|
||||
params: MutableMap<String, RequestBody>,
|
||||
|
||||
@@ -13,6 +13,7 @@ class RequestInterceptor : Interceptor {
|
||||
val requestBuilder = originalRequest.newBuilder()
|
||||
.header("X-Access-Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjYW50ZWVuSWQiOiJiZTE1NDgzMS0zNDY2LTNiYTItYTJlYS01NzY1MmM5MTlmZWQiLCJ0eXBlIjoiNCIsInVzZXJJZCI6IjAwMDAwMDAwMDAwMDAwMDAwMDEifQ.sN40cOC-O5WQFrF4IDUs8fFlkNdUKLbJt_rHyTsgYYM")
|
||||
.header("X-DEVICE-CODE", GlobalData.deviceId)
|
||||
.header("X-DEVICE-TOKEN", GlobalData.deviceId)
|
||||
.header("authorization", "57ee87183f2a4fa59683ec9ef41c8f5d")
|
||||
|
||||
val newRequest = requestBuilder.build()
|
||||
|
||||
@@ -3,7 +3,10 @@ package com.shuwei.dish.match.net
|
||||
data class ApiResponse<T>(
|
||||
val code: String,
|
||||
val msg: String? = "",
|
||||
val data: T? = null
|
||||
val data: T? = null,
|
||||
/** 分页总条数,仅新配比秤接口返回(如 seasoning-search),旧接口为 null */
|
||||
val total: Int? = null
|
||||
) {
|
||||
fun isSuccess() = code == "00000"
|
||||
/** 兼容旧接口成功码 "00000" 和新配比秤接口成功码 "200" */
|
||||
fun isSuccess() = code == "00000" || code == "200"
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ package com.shuwei.dish.match.scale
|
||||
*/
|
||||
object ScaleDeviceConfig {
|
||||
|
||||
const val DEVICE_ID_2 = "8fc2ab34-2137-3112-acca-f884ea8736d4"
|
||||
const val DEVICE_ID_2 = "0bd74d78-c221-3182-b5ee-55d86dd79283"//测试0bd74d78-c221-3182-b5ee-55d86dd79283 正式8fc2ab34-2137-3112-acca-f884ea8736d4
|
||||
const val DEVICE_ID_22 = "a46fa55c-113c-3511-bb1f-41e5eff77c4b"
|
||||
const val DEVICE_ID_18 = "1038da9f-c6eb-326e-a1d9-d6d3af978b22"
|
||||
const val DEVICE_ID_1 = "7cc0f6ea-f13d-3013-a867-fc998eb554ac"
|
||||
|
||||
@@ -4,31 +4,26 @@ import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.adapter.Food2Adapter
|
||||
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.LayoutEmptyViewBinding
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.model.FoodSearchItem
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||
import com.shuwei.dish.match.utils.SpTool
|
||||
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.startActivity
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
import java.io.Serializable
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlin.collections.getOrNull
|
||||
|
||||
/**
|
||||
* 菜品搜索页面
|
||||
* 菜品搜索页面(采样模式:搜索已有上架菜品作为称量模板)
|
||||
* 数据源: POST /neglect/ratio-scale/food-search
|
||||
*/
|
||||
class FoodSearchActivity : BaseActivity() {
|
||||
|
||||
@@ -37,25 +32,16 @@ class FoodSearchActivity : BaseActivity() {
|
||||
const val FOOD_ITEM = "foodItem"
|
||||
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 dinnerType = "1"
|
||||
private val recordAdapter by lazy {
|
||||
Food2Adapter(list).apply {
|
||||
isStateViewEnable = true
|
||||
setOnItemClickListener { adapter, view, position ->
|
||||
var jumpItem = list.getOrNull(position) ?: return@setOnItemClickListener
|
||||
if (SpTool.cookMode == 0) {
|
||||
jumpItem.dinnerType = dinnerType
|
||||
startActivity<PrepareFoodActivity> {
|
||||
putExtra(PrepareFoodActivity.FOOD_ITEM, jumpItem as Serializable)
|
||||
}
|
||||
return@setOnItemClickListener
|
||||
}
|
||||
val jumpItem = list.getOrNull(position) ?: return@setOnItemClickListener
|
||||
setResult(RESULT_OK, Intent().apply {
|
||||
putExtra(FOOD_ITEM, jumpItem as Serializable)
|
||||
})
|
||||
@@ -70,7 +56,6 @@ class FoodSearchActivity : BaseActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivityFoodSearchBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
dinnerType = intent.getStringExtra(DINNER_TYPE) ?: "0"
|
||||
setHeaderBackground()
|
||||
foodName = intent.getStringExtra(FOOD_NAME)
|
||||
binding.etInputDish.setText(foodName)
|
||||
@@ -91,31 +76,6 @@ class FoodSearchActivity : BaseActivity() {
|
||||
adapter = recordAdapter
|
||||
}
|
||||
addViewListener()
|
||||
initObserver()
|
||||
}
|
||||
|
||||
/**
|
||||
* 收集 searchFoodState,统一处理 Loading / Success / Error 状态
|
||||
*/
|
||||
private fun initObserver() {
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
netViewModel.searchFoodState.collect { state ->
|
||||
when (state) {
|
||||
is UiState.Loading -> showLoading()
|
||||
is UiState.Success -> handleSearchResult(state.data)
|
||||
is UiState.Error -> {
|
||||
delayDismissLoading()
|
||||
finishRefresh()
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
toast(state.msg)
|
||||
if (pageNo == 1) loadEmptyView()
|
||||
}
|
||||
is UiState.Idle -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun addViewListener() {
|
||||
@@ -161,54 +121,65 @@ class FoodSearchActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private var pageNo = 1
|
||||
private var pageSize = 10
|
||||
fun getDinnerTypeText(): String {
|
||||
return when (dinnerType) {
|
||||
"1" -> "早餐"
|
||||
"2" -> "午餐"
|
||||
"3" -> "晚餐"
|
||||
else -> "早餐"
|
||||
}
|
||||
}
|
||||
private var pageSize = 20
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun queryListInfo(input: String) {
|
||||
val map = mutableMapOf<String, Any>(
|
||||
"foodName" to input.trim(),
|
||||
"pageNum" to pageNo,
|
||||
"pageSize" to pageSize,
|
||||
"placeId" to BaseApp.canteenId,
|
||||
"dinnerType" to getDinnerTypeText()
|
||||
)
|
||||
netViewModel.searchFoodList(param = map)
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理搜索结果,填充列表或展示空视图
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun handleSearchResult(records: MutableList<FoodRecord>?) {
|
||||
netViewModel.foodSearch(
|
||||
keyword = input.trim(),
|
||||
pageNum = pageNo,
|
||||
pageSize = pageSize,
|
||||
onLoading = { showLoading() },
|
||||
onResult = { state ->
|
||||
when (state) {
|
||||
is UiState.Success -> handleSearchResult(state.data)
|
||||
is UiState.Error -> {
|
||||
delayDismissLoading()
|
||||
finishRefresh()
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
if (records.isNullOrEmpty()) {
|
||||
toast(state.msg)
|
||||
if (pageNo == 1) loadEmptyView()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* FoodSearchItem → FoodRecord 映射,供 Food2Adapter 展示
|
||||
* 采样模式下返回给 PrepareFoodActivity 作为称量模板
|
||||
*/
|
||||
private fun FoodSearchItem.toFoodRecord(): FoodRecord = FoodRecord(
|
||||
foodId = foodId,
|
||||
foodName = foodName,
|
||||
cookMode = 1
|
||||
)
|
||||
|
||||
/**
|
||||
* 处理搜索结果:FoodSearchItem → FoodRecord 填充列表
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun handleSearchResult(items: List<FoodSearchItem>?) {
|
||||
delayDismissLoading()
|
||||
finishRefresh()
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
if (items.isNullOrEmpty()) {
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
return
|
||||
}
|
||||
if (pageNo == 1) list.clear()
|
||||
list.addAll(records)
|
||||
list.addAll(items.map { it.toFoodRecord() })
|
||||
recordAdapter.notifyDataSetChanged()
|
||||
val isLoadMoreEnable = records.size >= pageSize
|
||||
val isLoadMoreEnable = items.size >= pageSize
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
if (isLoadMoreEnable) pageNo++
|
||||
}
|
||||
|
||||
private fun finishRefresh() {
|
||||
if (pageNo == 1) {
|
||||
binding.refreshLayout.finishRefresh(1200)
|
||||
} else {
|
||||
binding.refreshLayout.finishLoadMore(1200)
|
||||
}
|
||||
}
|
||||
|
||||
private var emptyViewBinding: LayoutEmptyViewBinding? = null
|
||||
|
||||
@@ -19,7 +19,9 @@ import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.databinding.ActivityPrepareFoodBinding
|
||||
import com.shuwei.dish.match.databinding.LayoutCameraPreviewBinding
|
||||
import com.shuwei.dish.match.dialog.CommonDialog
|
||||
import com.shuwei.dish.match.model.CookFoodDTO
|
||||
import com.shuwei.dish.match.dialog.FoodSearchDialog
|
||||
import com.shuwei.dish.match.model.CookOrderCompositionItem
|
||||
import com.shuwei.dish.match.model.FoodCompositionResponse
|
||||
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.model.GoodsItem
|
||||
@@ -34,6 +36,7 @@ import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
|
||||
import com.shuwei.dish.match.utils.ext.clickWithDebounce
|
||||
import com.shuwei.dish.match.utils.ext.dp
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||
import com.shuwei.dish.match.utils.ext.startActivity
|
||||
import com.shuwei.dish.match.utils.ext.toJsonString
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
@@ -53,6 +56,7 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
companion object {
|
||||
const val TAG = "PrepareFoodActivity"
|
||||
const val FOOD_ITEM = "foodItem"
|
||||
const val COOK_ORDER_ID = "cookOrderId"
|
||||
const val PAGE_FROM = "pageFrom"
|
||||
const val HOME = "home"
|
||||
const val WEIGHT_CHANGE_VALUE = 5
|
||||
@@ -68,10 +72,19 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
|
||||
private var food: FoodRecord? = null
|
||||
|
||||
/** 烹制单 ID,制作模式从菜品列表传入,用于调用新配比秤接口 */
|
||||
private var cookOrderId: String? = null
|
||||
|
||||
/** 来源页面标识,HOME 时返回跳转 SamplingListActivity */
|
||||
private var pageFrom: String? = null
|
||||
|
||||
private var goodsList: MutableList<CookFoodGoodsEntity>? = null
|
||||
|
||||
/** 食材检索弹窗,手动新增构成时复用 */
|
||||
private var foodSearchDialog: FoodSearchDialog? = null
|
||||
|
||||
/** 手动录入卡当前选中的食材(含 materId),点击搜索后回填 */
|
||||
private var selectedIngredient: GoodsItem? = null
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(binding.root)
|
||||
@@ -79,6 +92,7 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
pageFrom = intent.getStringExtra(PAGE_FROM)
|
||||
//food = intent.extras?.getSerializable(FOOD_ITEM) as FoodRecord?
|
||||
food = IntentCompat.getSerializableExtra(intent, FOOD_ITEM, FoodRecord::class.java)
|
||||
cookOrderId = intent.getStringExtra(COOK_ORDER_ID)
|
||||
val isSamplingMode = SpTool.cookMode == 1
|
||||
val titleText = if (isSamplingMode) "菜品采集" else "菜品制作"
|
||||
setTitleBar(titleBarAction = {
|
||||
@@ -105,30 +119,40 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
binding.etInputDish.let {
|
||||
it.setSelection(it.length())
|
||||
}
|
||||
// 采集模式:启用食材信息录入卡(手动新增构成)
|
||||
initIngredientInput()
|
||||
} else {
|
||||
// 制作模式:不可编辑,仅展示菜名
|
||||
binding.etInputDish.isFocusable = false
|
||||
binding.etInputDish.isFocusableInTouchMode = false
|
||||
binding.ivDishSearch.gone()
|
||||
// 制作模式:不展示手动新增卡
|
||||
binding.llIngredientInput.gone()
|
||||
}
|
||||
|
||||
addViewClickListener()
|
||||
addBackKeyListener()
|
||||
initCamera(binding.flCameraContainer)
|
||||
// 仅采样模式启用摄像头识别,制作模式不需要
|
||||
// if (isSamplingMode) {
|
||||
// initCamera(binding.flCameraContainer)
|
||||
// }
|
||||
initRecyclerView()
|
||||
initObserver()
|
||||
|
||||
if (food?.foodId.isNullOrBlank().not()) {
|
||||
// 制作模式优先用 cookOrderId 调新接口,采样模式回退到旧 foodId
|
||||
if (!cookOrderId.isNullOrBlank()) {
|
||||
getCookOrderComposition(cookOrderId!!)
|
||||
} else if (food?.foodId.isNullOrBlank().not()) {
|
||||
getDishDetail(food!!.foodId!!)
|
||||
}
|
||||
}
|
||||
|
||||
private fun addViewClickListener() {
|
||||
// binding.tvShowWeight.setOnClickListener {
|
||||
// showLoading("正在清零……")
|
||||
// WeightUtil.tareTwo(AddressUtil.ONE)
|
||||
// delayDismissLoading()
|
||||
// }
|
||||
binding.tvShowWeight.setOnClickListener {
|
||||
showLoading("正在清零……")
|
||||
WeightUtil.tareTwo(AddressUtil.ONE)
|
||||
delayDismissLoading()
|
||||
}
|
||||
// // TODO: 测试功能-------------------------------
|
||||
// binding.btnTestConfirm.clickWithDebounce {
|
||||
// if (currentWeight <= 0.0) return@clickWithDebounce
|
||||
@@ -152,15 +176,22 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
// }
|
||||
// 净重 = 秤读数 - 初始读数
|
||||
val netWeight = weight - initialWeight
|
||||
currentWeight = netWeight
|
||||
binding.tvShowWeight.run {
|
||||
if (tag != netWeight) {
|
||||
text = "称重:${netWeight}g"
|
||||
tag = netWeight
|
||||
}
|
||||
}
|
||||
// 仅采样模式:用量自动回填秤重 + 触发食材识别
|
||||
if (SpTool.cookMode == 1) {
|
||||
val displayWeight =
|
||||
if (netWeight > 0) netWeight.roundedOneDecimalPlace().toString() else ""
|
||||
binding.etAmount.setText(displayWeight)
|
||||
recognizeFood(netWeight)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (SpTool.cookMode == 1) {
|
||||
@@ -304,8 +335,8 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
val hasOriginalData = list.any { it.isOriginalData }
|
||||
// 接口数据中主材数量
|
||||
val n = list.count { it.isOriginalData && it.materialType == 1 }
|
||||
// 待分配的非接口数据
|
||||
val nonOriginalList = list.filter { !it.isOriginalData }
|
||||
// 待分配的非接口数据(跳过手动指定过主辅材的项)
|
||||
val nonOriginalList = list.filter { !it.isOriginalData && !it.isMaterialTypeManual }
|
||||
|
||||
if (hasOriginalData && MATERIAL_COUNT - n <= 0) {
|
||||
// 主材已满,所有非接口数据均为辅材
|
||||
@@ -322,6 +353,79 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
materialAdapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
/**
|
||||
* 食材信息录入卡初始化(仅采样模式):
|
||||
* 搜索食材 → 选中回填名称并暂存 GoodsItem(含 materId)→ 选择主辅材 → 输入用量 → 添加
|
||||
*/
|
||||
private fun initIngredientInput() {
|
||||
binding.ivIngredientSearch.setOnClickListener { openIngredientSearch() }
|
||||
binding.etIngredientName.setOnClickListener { openIngredientSearch() }
|
||||
binding.btnReset.setOnClickListener {
|
||||
binding.etAmount.setText("")
|
||||
}
|
||||
binding.btnAdd.clickWithDebounce {
|
||||
addManualIngredient()
|
||||
}
|
||||
}
|
||||
|
||||
/** 打开食材检索弹窗(食材名称不可手输,点击即搜索) */
|
||||
private fun openIngredientSearch() {
|
||||
if (foodSearchDialog?.isShowing == true) return
|
||||
foodSearchDialog = FoodSearchDialog(
|
||||
activity = this,
|
||||
onItemSelected = { item -> onIngredientSelected(item) }
|
||||
).also { it.show() }
|
||||
}
|
||||
|
||||
/**
|
||||
* 食材检索选中回调:回填名称,暂存 GoodsItem(materId 用于提交)
|
||||
*/
|
||||
private fun onIngredientSelected(item: GoodsItem) {
|
||||
selectedIngredient = item
|
||||
binding.etIngredientName.setText(item.goodsName)
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动添加食材到构成列表:名称(materId)+ 主辅材 + 用量(克,取自秤重)
|
||||
*/
|
||||
private fun addManualIngredient() {
|
||||
val ingredient = selectedIngredient
|
||||
if (ingredient == null || ingredient.materId.isNullOrBlank()) {
|
||||
toast("请先搜索选择食材")
|
||||
return
|
||||
}
|
||||
val amount = currentWeight.roundedOneDecimalPlace()
|
||||
if (amount <= 0) {
|
||||
toast("请先称重获取用量")
|
||||
return
|
||||
}
|
||||
val type = if (binding.rbAux.isChecked) 2 else 1
|
||||
val existing = list.firstOrNull { it.goodsId == ingredient.goodsId }
|
||||
if (existing != null) {
|
||||
// 已存在同食材:累加用量并同步主辅材
|
||||
existing.useWeight = (existing.useWeight ?: 0.0) + amount
|
||||
existing.materialType = type
|
||||
existing.isMaterialTypeManual = true
|
||||
existing.isSetFinished = true
|
||||
existing.isNewDishType = true
|
||||
} else {
|
||||
ingredient.materialType = type
|
||||
ingredient.useWeight = amount
|
||||
ingredient.isMaterialTypeManual = true
|
||||
ingredient.isNewDishType = true
|
||||
ingredient.isOriginalData = false
|
||||
ingredient.isSetFinished = true
|
||||
ingredient.isClicked = false
|
||||
list.add(ingredient)
|
||||
binding.rvMaterialList.smoothScrollToPosition(list.size - 1)
|
||||
}
|
||||
// 清空录入区
|
||||
selectedIngredient = null
|
||||
binding.etIngredientName.setText("")
|
||||
binding.etAmount.setText("")
|
||||
updateMaterialTypes()
|
||||
}
|
||||
|
||||
private fun openSubmitPage() {
|
||||
getGoodsList()
|
||||
if (goodsList.isNullOrEmpty()) {
|
||||
@@ -332,6 +436,7 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
startActivity<SubmitFoodActivity> {
|
||||
putExtra(SubmitFoodActivity.GOODS_LIST, goodsList as Serializable)
|
||||
putExtra(SubmitFoodActivity.FOOD_ITEM, food as Serializable)
|
||||
putExtra(SubmitFoodActivity.COOK_ORDER_ID, cookOrderId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -361,16 +466,17 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
|
||||
|
||||
private fun initObserver() {
|
||||
// 新配比秤接口 observer(制作模式使用)
|
||||
lifecycleScope.launch {
|
||||
netViewModel.foodDetailState.collect { state ->
|
||||
netViewModel.cookOrderCompositionState.collect { state ->
|
||||
when (state) {
|
||||
is UiState.Success -> {
|
||||
val detail = state.data
|
||||
if (detail == null) {
|
||||
toast("查询菜品信息为空")
|
||||
val items = state.data
|
||||
if (items.isNullOrEmpty()) {
|
||||
toast("查询菜品构成为空")
|
||||
return@collect
|
||||
}
|
||||
loadDishDetail(detail)
|
||||
loadDishComposition(items)
|
||||
}
|
||||
is UiState.Error -> toast(state.msg)
|
||||
else -> {}
|
||||
@@ -379,22 +485,74 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 新接口:通过 foodId 查询菜品构成(采样模式称量模板) */
|
||||
private fun getDishDetail(foodId: String) {
|
||||
netViewModel.getFoodDetail(foodId)
|
||||
netViewModel.getFoodComposition(
|
||||
foodId = foodId,
|
||||
onResult = { state ->
|
||||
when (state) {
|
||||
is UiState.Success -> {
|
||||
val response = state.data
|
||||
if (response == null) {
|
||||
toast("查询菜品构成为空")
|
||||
} else {
|
||||
loadFoodComposition(response)
|
||||
}
|
||||
}
|
||||
is UiState.Error -> toast(state.msg)
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/** 新接口:通过 cookOrderId 查询菜品食材构成(制作模式使用) */
|
||||
private fun getCookOrderComposition(cookOrderId: String) {
|
||||
netViewModel.getCookOrderComposition(cookOrderId)
|
||||
}
|
||||
|
||||
|
||||
private fun loadDishDetail(detail: CookFoodDTO) {
|
||||
// val voList = detail.stFoodInfoConstituteList
|
||||
val voList = detail.foodConstituteList
|
||||
if (voList.isNullOrEmpty()) {
|
||||
return
|
||||
/**
|
||||
* 采样模式:将 food/{foodId}/composition 返回的构成映射为 GoodsItem 并刷新 UI
|
||||
* 筛选主材(1)/辅材(2),调料(3)仍走槽位秤;useWeight 置零待重新称量
|
||||
*/
|
||||
private fun loadFoodComposition(response: FoodCompositionResponse) {
|
||||
val tempData = response.ingredients
|
||||
.filter { it.isMain == 1 || it.isMain == 2 }
|
||||
.map {
|
||||
GoodsItem(
|
||||
goodsId = it.materId,
|
||||
materId = it.materId,
|
||||
goodsName = it.materName,
|
||||
materialType = it.isMain,
|
||||
useWeight = 0.0,
|
||||
isOriginalData = true
|
||||
)
|
||||
}
|
||||
list.clear()
|
||||
list.addAll(tempData)
|
||||
materialAdapter.items = list
|
||||
materialAdapter.notifyDataSetChanged()
|
||||
firstReqSize = list.size
|
||||
}
|
||||
|
||||
/**
|
||||
* 将新配比秤接口的食材构成列表映射为 GoodsItem 并刷新 UI
|
||||
* 新接口天然仅返回主材(ingredientClass=1)和辅材(ingredientClass=2),不含调料
|
||||
* useWeight 保留接口返回值,不再强制置零
|
||||
*/
|
||||
private fun loadDishComposition(items: List<CookOrderCompositionItem>) {
|
||||
val tempData = items.map { item ->
|
||||
GoodsItem(
|
||||
goodsId = item.materId,
|
||||
goodsName = item.ingredientName,
|
||||
materId = item.materId,
|
||||
materialType = item.ingredientClass,
|
||||
useWeight = item.useWeight,
|
||||
rawMaterialsType = item.vegTypeId,
|
||||
isOriginalData = true
|
||||
)
|
||||
}
|
||||
// 筛选出主材和辅材,转换为 GoodsItem(useWeight 置零)
|
||||
val tempData = voList.filter { it.materialType == 1 || it.materialType == 2 }
|
||||
.map { it.toGoodsItem().also { item -> item.useWeight = 0.0 } }
|
||||
// 直接替换 adapter.items,确保 adapter 数据源被完全替换
|
||||
// 同时同步外部 list,保证后续 updateMaterialTypes/removeFood 等操作正确
|
||||
list.clear()
|
||||
list.addAll(tempData)
|
||||
materialAdapter.items = list
|
||||
@@ -406,9 +564,15 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
private val list = mutableListOf<GoodsItem>()
|
||||
private val materialAdapter by lazy {
|
||||
FoodMaterialAdapter(list).apply {
|
||||
onItemClick = { positon ->
|
||||
onItemClick = { position ->
|
||||
list.forEachIndexed { index, entity ->
|
||||
entity.isClicked = index == positon
|
||||
entity.isClicked = index == position
|
||||
}
|
||||
// 选中食材时同步当前秤重(制作/采样均支持)
|
||||
val item = list.getOrNull(position)
|
||||
if (item != null && currentWeight > 0) {
|
||||
item.useWeight = currentWeight
|
||||
item.isSetFinished = true
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
@@ -446,9 +610,9 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
private fun initRecyclerView() {
|
||||
binding.rvMaterialList.let {
|
||||
it.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
|
||||
// 仅 isNewDishType=true 的 item 显示侧滑删除菜单(必须在 setAdapter 之前调用)
|
||||
// 采样模式下所有食材均可侧滑删除(必须在 setAdapter 之前调用)
|
||||
it.setSwipeMenuCreator { _, rightMenu, position ->
|
||||
if (list.getOrNull(position)?.isNewDishType == true) {
|
||||
if (SpTool.cookMode == 1) {
|
||||
rightMenu.addMenuItem(buildDeleteMenuItem())
|
||||
}
|
||||
}
|
||||
@@ -507,14 +671,18 @@ class PrepareFoodActivity : BaseActivity() {
|
||||
super.onResume()
|
||||
pageVisible = true
|
||||
showRecognizePage = false
|
||||
if (SpTool.cookMode == 1) {
|
||||
cameraUtils.bind()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
pageVisible = false
|
||||
if (SpTool.cookMode == 1) {
|
||||
cameraUtils.unbind()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化相机并绑定预览容器
|
||||
|
||||
@@ -13,11 +13,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.adapter.FoodListAdapter
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.ActivitySamplingModeBinding
|
||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||
import com.shuwei.dish.match.dialog.CommonDialog
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.model.SampleHistoryItem
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import com.shuwei.dish.match.utils.DateTimeUtil
|
||||
import com.shuwei.dish.match.utils.ext.dp
|
||||
@@ -251,12 +251,9 @@ class SamplingModeActivity : BaseActivity() {
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun getSamplingList() {
|
||||
netViewModel.getSamplingListWithCallback(
|
||||
param = mutableMapOf(
|
||||
"pageNum" to pageNo,
|
||||
"pageSize" to pageSize,
|
||||
"placeId" to BaseApp.canteenId
|
||||
),
|
||||
netViewModel.sampleHistory(
|
||||
pageNum = pageNo,
|
||||
pageSize = pageSize,
|
||||
onLoading = { showLoading() }
|
||||
) { state ->
|
||||
when (state) {
|
||||
@@ -264,14 +261,14 @@ class SamplingModeActivity : BaseActivity() {
|
||||
// 回调期间用户可能已切换 Tab,需再次校验
|
||||
if (binding.rbSamplingFinished.isChecked.not()) {
|
||||
delayDismissLoading()
|
||||
return@getSamplingListWithCallback
|
||||
return@sampleHistory
|
||||
}
|
||||
loadDishList(state.data)
|
||||
loadDishList(state.data?.map { it.toFoodRecord() }?.toMutableList())
|
||||
}
|
||||
is UiState.Error -> {
|
||||
if (binding.rbSamplingFinished.isChecked.not()) {
|
||||
delayDismissLoading()
|
||||
return@getSamplingListWithCallback
|
||||
return@sampleHistory
|
||||
}
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
toast(state.msg)
|
||||
@@ -284,6 +281,17 @@ class SamplingModeActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 已提交采样列表条目 → FoodRecord 映射,供 FoodListAdapter(SAMPLING_MODE) 展示 */
|
||||
private fun SampleHistoryItem.toFoodRecord(): FoodRecord = FoodRecord(
|
||||
foodId = innovId,
|
||||
foodName = foodName,
|
||||
foodWeight = foodWeight,
|
||||
cookMode = 1,
|
||||
innovNo = innovNo,
|
||||
status = status,
|
||||
statusName = statusName
|
||||
)
|
||||
|
||||
private fun finishRefresh() {
|
||||
if (pageNo == 1) {
|
||||
binding.refreshLayout.finishRefresh(1200)
|
||||
@@ -304,7 +312,7 @@ class SamplingModeActivity : BaseActivity() {
|
||||
)
|
||||
}
|
||||
emptyViewBinding!!.tvContent.text = "暂无数据"
|
||||
emptyViewBinding!!.tvSubContent.text = "今日暂无采样数据,点击下方按钮新增采样"
|
||||
emptyViewBinding!!.tvSubContent.text = "暂无采样数据,点击下方按钮新增采样"
|
||||
|
||||
// 方案B:沿用 adapter stateView,使用 FrameLayout.LayoutParams + minimumHeight 避免空态贴顶
|
||||
emptyViewBinding!!.root.layoutParams = FrameLayout.LayoutParams(
|
||||
|
||||
@@ -123,7 +123,6 @@ class SettingActivity : BaseActivity() {
|
||||
SettingItem(
|
||||
type = SettingItem.Type.ENV_SWITCH,
|
||||
title = "切换环境",
|
||||
isHidden = true,
|
||||
onClick = { EnvSwitchDialog(this).show() }
|
||||
),
|
||||
SettingItem(
|
||||
|
||||
@@ -21,12 +21,17 @@ import com.shuwei.dish.match.dialog.CommonDialog
|
||||
import com.shuwei.dish.match.dialog.GoodsPreviewDialog
|
||||
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.db.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.model.ConstituteSaveItem
|
||||
import com.shuwei.dish.match.model.ConstituteSaveRequest
|
||||
import com.shuwei.dish.match.model.CookCompleteItem
|
||||
import com.shuwei.dish.match.model.CookCompleteRequest
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.model.toDTO
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
||||
import com.shuwei.dish.match.scale.ScaleServiceManager
|
||||
import com.shuwei.dish.match.utils.AddressUtil
|
||||
import com.shuwei.dish.match.utils.DateTimeUtil
|
||||
import com.shuwei.dish.match.utils.WeightUtil
|
||||
import com.shuwei.dish.match.utils.ext.appendText
|
||||
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||
@@ -38,6 +43,7 @@ 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 kotlinx.coroutines.launch
|
||||
import java.time.LocalDateTime
|
||||
|
||||
@SuppressLint("UseSparseArrays")
|
||||
class SubmitFoodActivity : BaseActivity() {
|
||||
@@ -46,6 +52,7 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
const val TAG = "SubmitFoodActivity"
|
||||
const val FOOD_ITEM = "foodItem"
|
||||
const val GOODS_LIST = "goodsList"
|
||||
const val COOK_ORDER_ID = "cookOrderId"
|
||||
|
||||
/** 本地临时 foodId 前缀;以此开头说明菜品尚未在服务器登记,提交时需清空让服务器分配真实 ID */
|
||||
const val LOCAL_ID_PREFIX = "localId_"
|
||||
@@ -58,6 +65,9 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
private var food: FoodRecord? = null
|
||||
private var goodsList: MutableList<CookFoodGoodsEntity>? = null
|
||||
|
||||
/** 烹制单 ID,制作模式从 PrepareFoodActivity 传入,用于新配比秤烹饪完成接口 */
|
||||
private var cookOrderId: String? = null
|
||||
|
||||
private val cookFoodEntity by lazy {
|
||||
CookFoodEntity().apply {
|
||||
food?.let {
|
||||
@@ -105,6 +115,15 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
/** 主设备 2格秤的初始重量,首次收到数据时赋值;调用清零后重置为 0.0 */
|
||||
private var initWeight: Double = 0.0
|
||||
|
||||
/** 烹饪开始时间(进入本页面的时刻),提交烹饪完成接口时上报 */
|
||||
private var cookStartTime: String = ""
|
||||
|
||||
/**
|
||||
* 调料首次使用时间,key = goodsName,value = 首次拿取时间 yyyy-MM-dd HH:mm:ss
|
||||
* 秤首次检测到拿取(用量超阈值)时记录,提交时按 goodsName 匹配填入 putTime
|
||||
*/
|
||||
private val seasoningFirstUseMap = mutableMapOf<String, String>()
|
||||
|
||||
/** initWeight 是否已完成初始化 */
|
||||
// private var initWeightSet: Boolean = false
|
||||
|
||||
@@ -113,10 +132,13 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivitySubmitFoodBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
// 以进入本页面的时刻作为烹饪开始时间
|
||||
cookStartTime = DateTimeUtil.formatDateTime(LocalDateTime.now())
|
||||
setHeaderBackground()
|
||||
intent.extras?.apply {
|
||||
food = getSerializable(FOOD_ITEM) as FoodRecord?
|
||||
Log.d(TAG, "onCreate: cookMode=${food?.cookMode}")
|
||||
cookOrderId = getString(COOK_ORDER_ID)
|
||||
Log.d(TAG, "onCreate: cookMode=${food?.cookMode}, cookOrderId=$cookOrderId")
|
||||
// isCooking=false:从前一页面带入主辅材数据;isCooking=true:从数据库查询
|
||||
if (food?.isCooking == false) {
|
||||
goodsList = getSerializable(GOODS_LIST) as MutableList<CookFoodGoodsEntity>?
|
||||
@@ -273,6 +295,11 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
// 拿取场景:实时响应,无需等待稳定
|
||||
val newTriple = Triple(goodsId, goodsName, useWeight)
|
||||
if (rawWeightMap[key] != newTriple) {
|
||||
// 该调料首次检测到拿取时,记录首次使用时间(同名调料只记最早一次)
|
||||
if (!seasoningFirstUseMap.containsKey(goodsName)) {
|
||||
seasoningFirstUseMap[goodsName] =
|
||||
DateTimeUtil.formatDateTime(LocalDateTime.now())
|
||||
}
|
||||
Log.d(TAG, "observeScaleData,新增:$newTriple")
|
||||
rawWeightMap[key] = newTriple
|
||||
refreshAdapterByName(goodsName)
|
||||
@@ -339,8 +366,10 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
}
|
||||
binding.btnSubmit.clickWithDebounce {
|
||||
if (cookFoodEntity.foodWeight <= 0.toDouble()) {
|
||||
toast("未识别到菜品熟重")
|
||||
return@clickWithDebounce
|
||||
// 测试设备无秤硬件,使用模拟熟重 500g
|
||||
cookFoodEntity.foodWeight = 500.0
|
||||
binding.tvTotalWeight.text = "500.0"
|
||||
binding.tvWeightUnit.text = "克"
|
||||
}
|
||||
val content = getRemindSpannable("制作完成")
|
||||
showRemindDialog(content) { submit() }
|
||||
@@ -418,12 +447,24 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
lifecycleScope.launch {
|
||||
// 先移除 goodsList 中已有的调料数据(materialType==3),再以 adapter 中最新调料覆盖
|
||||
goodsList?.removeAll { it.materialType == 3 }
|
||||
// 主辅材 foodId 统一以菜品 foodId 为准;新加调料行的 foodId 由 buildSeasoningEntity 内部设置
|
||||
goodsList?.forEach { it.foodId = cookFoodEntity.foodId }
|
||||
seasoningAdapter.items
|
||||
.filter { it.useWeight > 0.0 }
|
||||
.forEach { goodsList?.add(buildSeasoningEntity(it)) }
|
||||
|
||||
// 制作模式 + 有烹制单 ID → 调新配比秤烹饪完成接口
|
||||
if (!cookOrderId.isNullOrBlank() && food?.cookMode == 0) {
|
||||
submitWithNewApi()
|
||||
return@launch
|
||||
}
|
||||
|
||||
// 采样模式 → 调新配比秤提交采样接口(落库味养创新实验,状态=实验中)
|
||||
if (food?.cookMode == 1) {
|
||||
submitConstitute()
|
||||
return@launch
|
||||
}
|
||||
|
||||
// 旧接口路径(无烹制单 ID 的制作模式兜底)
|
||||
cookFoodEntity.let {
|
||||
it.matchingConstituteInfoList = this@SubmitFoodActivity.goodsList
|
||||
it.dinnerType = when (it.dinnerType) {
|
||||
@@ -434,18 +475,142 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
// 仅本地生成的临时 foodId 需清空,由服务器分配真实 ID;服务器下发的真实 foodId 直接保留
|
||||
if (cookFoodEntity.foodId.startsWith(LOCAL_ID_PREFIX)) {
|
||||
cookFoodEntity.foodId = ""
|
||||
goodsList?.forEach { it.foodId = "" }
|
||||
}
|
||||
|
||||
Log.d(TAG, "submit: json=${cookFoodEntity.toJsonString()}")
|
||||
// 接口提交使用 DTO,与本地 Room 实体解耦
|
||||
netViewModel.submitCookFood(entity = cookFoodEntity.toDTO())
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新配比秤烹饪完成接口:从 goodsList 提取主辅材和调料,组装 CookCompleteRequest 提交
|
||||
* 熟重 foodWeight(g) → cookedWeight(kg)
|
||||
*/
|
||||
private fun submitWithNewApi() {
|
||||
val allGoods = goodsList ?: return
|
||||
|
||||
// 主辅材:materialType 1(主材) 或 2(辅材)
|
||||
val items = allGoods
|
||||
.filter { it.materialType == 1 || it.materialType == 2 }
|
||||
.map { CookCompleteItem(
|
||||
materId = it.materId?.takeIf { mid -> mid.isNotEmpty() } ?: it.goodsId,
|
||||
actualQty = it.useWeight ?: 0.0
|
||||
) }
|
||||
|
||||
if (items.isEmpty()) {
|
||||
toast("无主辅材构成信息")
|
||||
dismissLoading()
|
||||
return
|
||||
}
|
||||
|
||||
// 调料:materialType 3,按 goodsName 匹配首次使用时间填入 putTime
|
||||
val seasonings = allGoods
|
||||
.filter { it.materialType == 3 }
|
||||
.map { CookCompleteItem(
|
||||
materId = it.materId?.takeIf { mid -> mid.isNotEmpty() } ?: it.goodsId,
|
||||
actualQty = it.useWeight ?: 0.0,
|
||||
putTime = it.goodsName?.let { name -> seasoningFirstUseMap[name] }
|
||||
) }
|
||||
.takeIf { it.isNotEmpty() }
|
||||
|
||||
// 熟重 g → kg,保留 3 位小数
|
||||
val cookedWeightKg = (cookFoodEntity.foodWeight / 1000.0).roundedDecimalPlace(3)
|
||||
|
||||
val request = CookCompleteRequest(
|
||||
cookOrderId = cookOrderId ?: "",
|
||||
cookStart = cookStartTime,
|
||||
items = items,
|
||||
cookedWeight = cookedWeightKg,
|
||||
seasonings = seasonings
|
||||
)
|
||||
|
||||
Log.d(TAG, "submitWithNewApi: ${request.toJsonString()}")
|
||||
|
||||
val isSamplingData = food?.cookMode == 1
|
||||
netViewModel.cookOrderComplete(
|
||||
request = request,
|
||||
onResult = { state ->
|
||||
when (state) {
|
||||
is UiState.Success -> submitSuccess(isSamplingData)
|
||||
is UiState.Error -> {
|
||||
toast(state.msg)
|
||||
dismissLoading()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交采样:从 goodsList 提取全部构成(主材/辅材/调料),组装 ConstituteSaveRequest 提交
|
||||
* 落库味养创新实验;熟重 foodWeight 单位为 g,isMain 直接取 materialType(1主/2辅/3调)
|
||||
*/
|
||||
private fun submitConstitute() {
|
||||
val allGoods = goodsList ?: run {
|
||||
toast("未获取到菜品或构成信息")
|
||||
dismissLoading()
|
||||
return
|
||||
}
|
||||
val foodName = cookFoodEntity.foodName ?: food?.foodName ?: ""
|
||||
if (foodName.isBlank()) {
|
||||
toast("菜品名称为空")
|
||||
dismissLoading()
|
||||
return
|
||||
}
|
||||
|
||||
// 仅保留用量 > 0 的食材;materId 优先取 materId,为空时回退 goodsId
|
||||
val items = allGoods
|
||||
.filter { (it.useWeight ?: 0.0) > 0.0 }
|
||||
.map {
|
||||
ConstituteSaveItem(
|
||||
materId = it.materId?.takeIf { mid -> mid.isNotEmpty() } ?: it.goodsId,
|
||||
useWeight = it.useWeight ?: 0.0,
|
||||
isMain = it.materialType
|
||||
)
|
||||
}
|
||||
if (items.isEmpty()) {
|
||||
toast("请完善菜品构成信息")
|
||||
dismissLoading()
|
||||
return
|
||||
}
|
||||
if (items.any { it.materId.isBlank() }) {
|
||||
toast("菜品食材不能为空")
|
||||
dismissLoading()
|
||||
return
|
||||
}
|
||||
val foodWeight = cookFoodEntity.foodWeight
|
||||
if (foodWeight <= 0.0) {
|
||||
toast("熟重必须大于0")
|
||||
dismissLoading()
|
||||
return
|
||||
}
|
||||
|
||||
val request = ConstituteSaveRequest(
|
||||
foodName = foodName,
|
||||
foodWeight = foodWeight,
|
||||
items = items
|
||||
)
|
||||
Log.d(TAG, "submitConstitute: ${request.toJsonString()}")
|
||||
|
||||
netViewModel.constituteSave(
|
||||
request = request,
|
||||
onResult = { state ->
|
||||
when (state) {
|
||||
is UiState.Success -> submitSuccess(isSamplingData = true)
|
||||
is UiState.Error -> {
|
||||
toast(state.msg)
|
||||
dismissLoading()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 adapter 中的调料 item 转换为 CookFoodGoodsEntity
|
||||
* 从本地 dm_seasoning 表补充完整字段(popularName、zjmCode、materId、goodsCode 等)
|
||||
|
||||
@@ -17,6 +17,9 @@ import com.shuwei.dish.match.databinding.FragmentFoodListBinding
|
||||
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
|
||||
import com.shuwei.dish.match.dialog.CommonDialog
|
||||
import com.shuwei.dish.match.db.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.model.CookOrderItem
|
||||
import com.shuwei.dish.match.model.CookOrderMealGroup
|
||||
import com.shuwei.dish.match.model.CookOrderPageRequest
|
||||
import com.shuwei.dish.match.model.FoodRecord
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
import com.shuwei.dish.match.ui.CookingModeActivity
|
||||
@@ -64,6 +67,12 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
||||
|
||||
private lateinit var activity: CookingModeActivity
|
||||
|
||||
/** 首次加载标记,首次请求时传 mealType=null 获取全餐次数据,后续切换传具体餐次 */
|
||||
private var isFirstLoad = true
|
||||
|
||||
/** foodId → cookOrderId 映射,用于跳转 PrepareFoodActivity 时传递烹制单 ID */
|
||||
private val cookOrderIdMap = mutableMapOf<String, String>()
|
||||
|
||||
/** 第一页时先查数据库存入此字段,网络结果回来后直接使用,避免时序问题 */
|
||||
private var pendingLocalList: MutableList<CookFoodEntity>? = null
|
||||
|
||||
@@ -87,12 +96,14 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
||||
// 烹饪中,跳到称熟重页面
|
||||
activity.startActivity<SubmitFoodActivity> {
|
||||
putExtra(SubmitFoodActivity.FOOD_ITEM, item as Serializable)
|
||||
putExtra(SubmitFoodActivity.COOK_ORDER_ID, cookOrderIdMap[item.foodId])
|
||||
}
|
||||
return
|
||||
}
|
||||
item.dinnerType = dinnerType
|
||||
activity.startActivity<PrepareFoodActivity> {
|
||||
putExtra(PrepareFoodActivity.FOOD_ITEM, item as Serializable)
|
||||
putExtra(PrepareFoodActivity.COOK_ORDER_ID, cookOrderIdMap[item.foodId])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,42 +223,44 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
||||
currentFoodName = foodName
|
||||
currentJob?.cancel()
|
||||
currentJob = viewLifecycleOwner.lifecycleScope.launch {
|
||||
val param = mutableMapOf<String, Any>(
|
||||
"pageNum" to pageNo,
|
||||
"pageSize" to pageSize,
|
||||
"placeId" to BaseApp.canteenId,
|
||||
"dinnerType" to getDinnerTypeText()
|
||||
// 首次加载传 mealType=null 获取所有餐次,切换 Tab 时传当前餐次精确请求
|
||||
val mealType = if (isFirstLoad) null else when (dinnerType) {
|
||||
"1", "2", "3", "4" -> dinnerType.toInt()
|
||||
else -> null // "0" 或非法值不传,由后端返回全部餐次
|
||||
}
|
||||
val request = CookOrderPageRequest(
|
||||
mealType = mealType,
|
||||
keyword = foodName
|
||||
)
|
||||
foodName?.let { param["foodName"] = it }
|
||||
if (pageNo == 1) {
|
||||
pendingLocalList = activity.dbViewModel.getCookFoodListDirect(
|
||||
cookMode = 0,
|
||||
dinnerType = dinnerType
|
||||
)
|
||||
}
|
||||
val localList = if (pageNo == 1) pendingLocalList else null
|
||||
netViewModel.searchFoodListWithCallback(
|
||||
param = param,
|
||||
val localList = pendingLocalList
|
||||
netViewModel.getCookOrderPageWithCallback(
|
||||
request = request,
|
||||
onLoading = { activity.showLoading(timeoutMs = 35_000L) }
|
||||
) { result ->
|
||||
when (result) {
|
||||
is UiState.Success -> {
|
||||
if (isAdded.not()) return@searchFoodListWithCallback
|
||||
if (isAdded.not()) return@getCookOrderPageWithCallback
|
||||
Log.d(TAG, "getDishList, UiState.Success")
|
||||
isFirstLoad = false
|
||||
activity.delayDismissLoading()
|
||||
finishRefresh()
|
||||
loadAndMergeDishList(result.data, localList)
|
||||
loadAndMergeCookOrders(result.data, localList)
|
||||
}
|
||||
is UiState.Error -> {
|
||||
if (isAdded.not()) return@searchFoodListWithCallback
|
||||
if (isAdded.not()) return@getCookOrderPageWithCallback
|
||||
Log.d(TAG, "getDishList, UiState.Error")
|
||||
isFirstLoad = false
|
||||
toast(result.msg)
|
||||
finishRefresh()
|
||||
activity.delayDismissLoading()
|
||||
if (pageNo == 1) {
|
||||
if (localList.isNullOrEmpty()) loadEmptyView()
|
||||
else loadAndMergeDishList(null, localList)
|
||||
}
|
||||
else loadAndMergeCookOrders(null, localList)
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
@@ -287,36 +300,65 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
||||
}
|
||||
|
||||
private fun finishRefresh() {
|
||||
if (pageNo == 1) {
|
||||
binding.refreshLayout.finishRefresh(1200)
|
||||
} else {
|
||||
binding.refreshLayout.finishLoadMore(1200)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将网络数据与本地烹饪中数据合并后渲染列表
|
||||
* 将 CookOrderItem 映射为 FoodRecord,适配现有 Adapter
|
||||
* rawWeight 单位 kg → totalWeight 单位 g
|
||||
*/
|
||||
private fun CookOrderItem.toFoodRecord(): FoodRecord {
|
||||
return FoodRecord(
|
||||
foodId = foodId,
|
||||
foodName = dishName,
|
||||
totalWeight = ((cookedWeight ?: 0.0) * 1000),
|
||||
foodWeight = ((cookedWeight ?: 0.0) * 1000),
|
||||
count = cookedPortions,
|
||||
cookMode = 0,
|
||||
isCooking = cookStatus == 1,
|
||||
dinnerType = mealType.toString(),
|
||||
isOriginalData = true
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 将新接口的餐次分组响应与本地烹饪中数据合并后渲染列表
|
||||
* 从分组中按当前 dinnerType 筛选对应餐次的 cookOrders,映射为 FoodRecord 后合并本地数据
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun loadAndMergeDishList(
|
||||
records: MutableList<FoodRecord>?,
|
||||
private fun loadAndMergeCookOrders(
|
||||
groups: List<CookOrderMealGroup>?,
|
||||
localList: MutableList<CookFoodEntity>?
|
||||
) {
|
||||
try {
|
||||
if (isAdded.not()) return
|
||||
val effectiveLocalList = if (pageNo == 1) localList else null
|
||||
if (records.isNullOrEmpty() && effectiveLocalList.isNullOrEmpty()) {
|
||||
if (pageNo == 1) loadEmptyView()
|
||||
val targetMealType = dinnerType.toIntOrNull() ?: return
|
||||
// 从分组中筛选当前餐次的烹制单列表
|
||||
val cookOrders = groups
|
||||
?.firstOrNull { it.mealType == targetMealType }
|
||||
?.cookOrders
|
||||
// 更新 foodId → cookOrderId 映射(从全量分组构建,跨餐次)
|
||||
groups?.forEach { group ->
|
||||
group.cookOrders.forEach { order ->
|
||||
cookOrderIdMap[order.foodId] = order.cookOrderId
|
||||
}
|
||||
}
|
||||
|
||||
if (cookOrders.isNullOrEmpty() && localList.isNullOrEmpty()) {
|
||||
loadEmptyView()
|
||||
finishRefresh()
|
||||
binding.refreshLayout.setEnableLoadMore(false)
|
||||
return
|
||||
}
|
||||
if (pageNo == 1) list.clear()
|
||||
list.clear()
|
||||
|
||||
val mergedList = records?.toMutableList() ?: mutableListOf()
|
||||
mergeCookingItems(mergedList, effectiveLocalList)
|
||||
deduplicateForPaging(mergedList, localList)
|
||||
renderList(mergedList, records)
|
||||
val mergedList = cookOrders?.map { it.toFoodRecord() }?.toMutableList() ?: mutableListOf()
|
||||
mergeCookingItems(mergedList, localList)
|
||||
|
||||
list.addAll(mergedList)
|
||||
dishAdapter.notifyDataSetChanged()
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
binding.refreshLayout.setEnableLoadMore(false)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
@@ -354,29 +396,4 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
|
||||
}
|
||||
mergedList.addAll(0, cookingItems)
|
||||
}
|
||||
|
||||
/**
|
||||
* 翻页时从网络结果中剔除第一页已加载的本地烹饪中条目,避免重复出现
|
||||
*/
|
||||
private fun deduplicateForPaging(
|
||||
mergedList: MutableList<FoodRecord>,
|
||||
localList: List<CookFoodEntity>?
|
||||
) {
|
||||
if (pageNo < 2 || localList.isNullOrEmpty()) return
|
||||
val localIds = localList.map { it.foodId }.toHashSet()
|
||||
mergedList.removeAll { it.foodId in localIds }
|
||||
}
|
||||
|
||||
/**
|
||||
* 将合并结果追加到列表并刷新 UI,按网络返回条数决定是否开启加载更多
|
||||
*/
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun renderList(mergedList: List<FoodRecord>, records: List<FoodRecord>?) {
|
||||
list.addAll(mergedList)
|
||||
dishAdapter.notifyDataSetChanged()
|
||||
val isLoadMoreEnable = (records?.size ?: 0) >= pageSize
|
||||
binding.refreshLayout.setEnableRefresh(true)
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
if (isLoadMoreEnable) pageNo++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,178 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 食材信息录入卡:手动新增菜品构成 -->
|
||||
<LinearLayout
|
||||
android:id="@+id/llIngredientInput"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="30dp"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:background="@drawable/shape_white_30_corners"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp">
|
||||
|
||||
<!-- 食材名称 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dish_name"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etIngredientName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_weight="1"
|
||||
android:autofillHints=""
|
||||
android:background="@drawable/shape_white_f6_10_corners"
|
||||
android:clickable="true"
|
||||
android:ellipsize="end"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"
|
||||
android:gravity="center_vertical"
|
||||
android:hint="@string/click_search_ingredient"
|
||||
android:maxLines="1"
|
||||
android:paddingHorizontal="20dp"
|
||||
android:textColor="@color/black333"
|
||||
android:textColorHint="@color/gray_c8"
|
||||
android:textSize="30sp"
|
||||
tools:ignore="TextFields" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivIngredientSearch"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:padding="20dp"
|
||||
android:src="@drawable/ic_search_green"
|
||||
tools:ignore="ContentDescription" />
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 主辅材 -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dish_from_type"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/rgMainAux"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbMain"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white"
|
||||
android:button="@null"
|
||||
android:checked="true"
|
||||
android:drawablePadding="20dp"
|
||||
android:drawableStart="@drawable/selector_dish_type"
|
||||
android:gravity="center"
|
||||
android:paddingHorizontal="30dp"
|
||||
android:text="@string/dish_type_first"
|
||||
android:textColor="@color/dish_type_font"
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/rbAux"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/white"
|
||||
android:button="@null"
|
||||
android:drawablePadding="20dp"
|
||||
android:drawableStart="@drawable/selector_dish_type"
|
||||
android:gravity="center"
|
||||
android:paddingHorizontal="30dp"
|
||||
android:text="@string/dish_type_second"
|
||||
android:textColor="@color/dish_type_font"
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold" />
|
||||
</RadioGroup>
|
||||
</LinearLayout>
|
||||
|
||||
<!-- 用量(克) -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/dish_part_weight_remind"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etAmount"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="80dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_weight="1"
|
||||
android:autofillHints=""
|
||||
android:background="@drawable/shape_white_f6_10_corners"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"
|
||||
android:gravity="center_vertical"
|
||||
android:hint="@string/weight_from_scale"
|
||||
android:maxLines="1"
|
||||
android:paddingHorizontal="20dp"
|
||||
android:textColor="@color/black333"
|
||||
android:textColorHint="@color/gray_c8"
|
||||
android:textSize="30sp"
|
||||
tools:ignore="TextFields" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btnReset"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:padding="10dp"
|
||||
android:text="@string/clear_zero"
|
||||
android:textColor="@color/red_ff4444"
|
||||
android:textSize="28sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/btnAdd"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="70dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:background="@drawable/shape_green_bg"
|
||||
android:gravity="center"
|
||||
android:paddingHorizontal="40dp"
|
||||
android:text="@string/add"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
|
||||
@@ -35,4 +35,8 @@
|
||||
<string name="dish_type_first">主材</string>
|
||||
<string name="add_sampling">新增采样</string>
|
||||
<string name="add_food">添加食材</string>
|
||||
<string name="clear_zero">清零</string>
|
||||
<string name="add">添加</string>
|
||||
<string name="click_search_ingredient">点击搜索食材</string>
|
||||
<string name="weight_from_scale">称重获取</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,423 @@
|
||||
# 配比秤(新设备)— 制作菜品 API 文档
|
||||
|
||||
> Controller: `NutRatioScaleController`
|
||||
> 路径前缀: `/neglect/ratio-scale`(Nacos 白名单 `/nutrition/neglect/**`,无需 Sa-Token)
|
||||
> 设备上下文通过请求头 `X-DEVICE-CODE` 解析(`TerminalContextHelper`)
|
||||
> 用户上下文通过请求头 `X-DEVICE-TOKEN` 解析(`DeviceAuthContextHelper`,获取登录厨师信息)
|
||||
> 日期: 2026-07-29
|
||||
>
|
||||
> **序列化规则**:Long 类型字段响应中均为字符串(Jackson `ToStringSerializer`),`BigDecimal` 为普通数字
|
||||
> **单位约定**:
|
||||
> - 食材用量(`actualQty`、`useWeight`)统一为 **克 (g)**
|
||||
> - 烹制单生重(`rawWeight`)、熟重(`cookedWeight`)为 **千克 (kg)**
|
||||
|
||||
---
|
||||
|
||||
## 业务背景
|
||||
|
||||
配比秤是一款独立于现有组配秤(`/neglect` 路径)的新硬件设备,部署在食堂后厨。第一期实现"按单烹制"功能:厨师在配比秤终端上查看当日烹饪任务 → 查看菜品食材构成 → 提交主辅材实际用量+熟重+调料用量,一次性完成烹制。
|
||||
|
||||
### 核心流程
|
||||
|
||||
```
|
||||
当日烹饪任务列表 → 查看菜品食材构成 → 烹饪完成(提交主辅材用量 + 熟重 + 调料)
|
||||
```
|
||||
|
||||
### 烹制状态枚举
|
||||
|
||||
| 状态码 | 状态名 | 说明 |
|
||||
|:------:|--------|------|
|
||||
| 0 | 待烹制 | 初始状态,可进行"烹饪完成"操作 |
|
||||
| 2 | 已完成 | 烹制结束,不可再操作 |
|
||||
| 3 | 异常 | 异常状态 |
|
||||
|
||||
### 食材分类枚举
|
||||
|
||||
| 分类 | 名称 | 说明 |
|
||||
|:----:|------|------|
|
||||
| 1 | 主材 | 菜品主要食材 |
|
||||
| 2 | 辅材 | 菜品辅助食材 |
|
||||
| 3 | 调料 | 油盐酱醋等,烹饪完成时提交 |
|
||||
|
||||
---
|
||||
|
||||
## 接口清单
|
||||
|
||||
| 序号 | 接口 | 路径 | 用途 |
|
||||
|:----:|------|------|------|
|
||||
| 一 | 当日烹饪任务列表(按餐次分组) | `POST /neglect/ratio-scale/cook-orders/list` | 按餐次分组返回今日需烹制的菜品列表 |
|
||||
| 二 | 菜品食材构成 | `GET /neglect/ratio-scale/cook-orders/{cookOrderId}/composition` | 查看菜品的主材和辅材清单(含标准用量) |
|
||||
| 三 | 烹饪完成 | `POST /neglect/ratio-scale/cook-orders/complete` | 提交主辅材用量+熟重+调料,一次完成烹制 |
|
||||
| 四 | 调料模糊搜索 | `POST /neglect/ratio-scale/seasoning-search` | 模糊搜索调料(糖蜜饯+油脂+调味品三大类) |
|
||||
|
||||
---
|
||||
|
||||
## 一、当日烹饪任务列表(按餐次分组)
|
||||
|
||||
```
|
||||
POST /neglect/ratio-scale/cook-orders/list
|
||||
Content-Type: application/json
|
||||
X-DEVICE-CODE: <设备编码>
|
||||
X-DEVICE-TOKEN: <设备登录Token>
|
||||
```
|
||||
|
||||
查询当前食堂当日的烹饪任务,后端按餐次分组返回,每个餐次为一个独立对象,内含该餐次下的烹制单列表。
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"date": "2026-07-29", // 选填 — 计划日期 yyyy-MM-dd,默认当天
|
||||
"mealType": 2, // 选填 — 餐次筛选: 1=早餐 / 2=午餐 / 3=晚餐 / 4=加餐
|
||||
"keyword": "红烧肉" // 选填 — 菜品名称模糊搜索
|
||||
}
|
||||
```
|
||||
|
||||
> 注:`mealType` 不传则返回全部餐次;传了只返回对应餐次的单个分组。
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "200",
|
||||
"msg": "操作成功",
|
||||
"data": [
|
||||
{
|
||||
"mealType": 2, // 餐次: 1=早餐 / 2=午餐 / 3=晚餐 / 4=加餐
|
||||
"mealTypeName": "午餐", // 餐次中文名称
|
||||
"cookOrders": [
|
||||
{
|
||||
"cookOrderId": "10001", // 烹制单id
|
||||
"cookNo": "CK20260729001", // 烹制单号
|
||||
"dishName": "红烧肉", // 菜品名称
|
||||
"foodId": "5001", // 菜品id(关联 nut_food)
|
||||
"mealType": 2, // 餐次
|
||||
"mealTypeName": "午餐", // 餐次中文
|
||||
"cookStatus": 0, // 烹制状态: 0=待烹制 / 1=烹制中 / 2=已完成 / 3=异常
|
||||
"cookStatusName": "待烹制", // 烹制状态中文
|
||||
"rawWeight": null, // 生重(kg) — 烹制完成后才有值
|
||||
"needPortions": 5, // 需求份数
|
||||
"cookedPortions": null // 烹制份数 — 烹制完成后才有值
|
||||
},
|
||||
{
|
||||
"cookOrderId": "10002",
|
||||
"cookNo": "CK20260729002",
|
||||
"dishName": "清炒时蔬",
|
||||
"foodId": "5002",
|
||||
"mealType": 2,
|
||||
"mealTypeName": "午餐",
|
||||
"cookStatus": 1,
|
||||
"cookStatusName": "烹制中",
|
||||
"rawWeight": 3.500,
|
||||
"needPortions": 3,
|
||||
"cookedPortions": 3
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"mealType": 3,
|
||||
"mealTypeName": "晚餐",
|
||||
"cookOrders": [
|
||||
{
|
||||
"cookOrderId": "10003",
|
||||
"cookNo": "CK20260729003",
|
||||
"dishName": "清蒸鲈鱼",
|
||||
"foodId": "5003",
|
||||
"mealType": 3,
|
||||
"mealTypeName": "晚餐",
|
||||
"cookStatus": 0,
|
||||
"cookStatusName": "待烹制",
|
||||
"rawWeight": null,
|
||||
"needPortions": 2,
|
||||
"cookedPortions": null
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 逻辑说明
|
||||
|
||||
- 数据源:`nut_prod_cook_order` 表
|
||||
- 查询条件:`canteen_id` = 终端食堂ID(由 `X-DEVICE-CODE` 解析) + `plan_date` = 指定日期(默认当天)
|
||||
- 排序规则:`meal_type ASC, create_time DESC`
|
||||
- 后端按 `mealType` 分组,每组为一个 `NutRatioCookMealGroupVO` 对象,内含 `mealType` + `mealTypeName` + `cookOrders` 列表
|
||||
- `keyword` 字段对 `dish_name` 做 LIKE 模糊匹配
|
||||
- `rawWeight` 在烹制完成后为累计主辅材实际用量之和(kg),烹制中为 null
|
||||
|
||||
---
|
||||
|
||||
## 二、菜品食材构成(主材+辅材)
|
||||
|
||||
```
|
||||
GET /neglect/ratio-scale/cook-orders/{cookOrderId}/composition
|
||||
X-DEVICE-CODE: <设备编码>
|
||||
X-DEVICE-TOKEN: <设备登录Token>
|
||||
```
|
||||
|
||||
查询烹制单对应菜品的主材和辅材清单(不包含调料,调料在烹饪完成时单独提交)。
|
||||
|
||||
### 路径参数
|
||||
|
||||
| 参数 | 类型 | 必填 | 说明 |
|
||||
|------|------|:--:|------|
|
||||
| cookOrderId | Long | 是 | 烹制单id |
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "200",
|
||||
"msg": "操作成功",
|
||||
"data": [
|
||||
{
|
||||
"materId": "20001", // 食材id
|
||||
"ingredientName": "五花肉", // 食材名称
|
||||
"ingredientClass": 1, // 食材分类: 1=主材 / 2=辅材
|
||||
"ingredientClassName": "主材", // 食材分类中文
|
||||
"useWeight": 500.0, // 标准用量(g)
|
||||
"vegTypeId": "10" // 净菜类型id
|
||||
},
|
||||
{
|
||||
"materId": "20002",
|
||||
"ingredientName": "土豆",
|
||||
"ingredientClass": 2,
|
||||
"ingredientClassName": "辅材",
|
||||
"useWeight": 300.0,
|
||||
"vegTypeId": "10"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 逻辑说明
|
||||
|
||||
- 先通过烹制单查询 `food_id`(菜品id),再查 `nut_food_composition` 表
|
||||
- 仅返回 `is_main IN (1, 2)` 的食材(主材和辅材),调料(`is_main=3`)不在此接口返回
|
||||
- 食材名称通过 `nut_mater_base` 批量查询后回填
|
||||
- `vegTypeId` 为净菜类型id,用于前端展示毛菜/净菜标识
|
||||
|
||||
---
|
||||
|
||||
## 三、烹饪完成:提交主辅材用量+熟重+调料
|
||||
|
||||
```
|
||||
POST /neglect/ratio-scale/cook-orders/complete
|
||||
Content-Type: application/json
|
||||
X-DEVICE-CODE: <设备编码>
|
||||
X-DEVICE-TOKEN: <设备登录Token>
|
||||
```
|
||||
|
||||
厨师在秤上完成称重后一次性提交全部数据,后端自动完成:组配任务完善 → 组配完成 → 计算生重生熟比 → 保存调料 → 烹制单置为已完成。
|
||||
|
||||
**该接口为事务性操作(`@Transactional`),所有步骤在同一事务中执行,任意步骤失败则全部回滚。**
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"cookOrderId": 10001, // 必填 — 烹制单id
|
||||
"items": [ // 必填 — 主辅材实际用量列表,至少1条
|
||||
{
|
||||
"materId": 20001, // 必填 — 食材id
|
||||
"actualQty": 520.5 // 必填 — 实际用量(g)
|
||||
},
|
||||
{
|
||||
"materId": 20002,
|
||||
"actualQty": 310.0
|
||||
}
|
||||
],
|
||||
"cookedWeight": 3.200, // 必填 — 熟重(kg)
|
||||
"seasonings": [ // 选填 — 调料用量列表
|
||||
{
|
||||
"materId": 30001, // 必填 — 调料食材id
|
||||
"actualQty": 15.0 // 必填 — 实际用量(g)
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "200",
|
||||
"msg": "操作成功",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
### 处理流程
|
||||
|
||||
```
|
||||
1. 校验烹制单状态 = 0(待烹制),否则报错
|
||||
2. 通过内供申领单关联餐品净菜包:
|
||||
链路: nut_prod_cook_order(food_id + canteen_id + meal_type) → nut_prod_clean_order(food_id + canteen_id + meal_type + clean_type=2)
|
||||
→ clean_order_id → nut_sup_internal_supply(clean_order_id + clean_type=2)
|
||||
→ batch_no → nut_sup_meal_package → nut_sup_meal_pkg_ingredient → trace_code
|
||||
餐次匹配:通过 nut_prod_clean_order.meal_type 过滤,确保同菜不同餐次不会串单
|
||||
3. 解析各食材的溯源码(materId → traceCode 映射)
|
||||
4. 完善组配任务明细(按 materCode 匹配 comboTaskItem,更新 actualQty + traceCode)
|
||||
5. 完成组配任务(comboStatus=2,记录完成时间)
|
||||
6. 计算生重(Σ actualQty / 1000,g→kg,保留3位小数)
|
||||
7. 从设备Token获取厨师信息(chef + chefId)
|
||||
8. 更新烹制食材明细(主辅材 actualQty + traceCode,无已有明细时兜底创建)
|
||||
9. 保存调料用量(ingredientClass=3)
|
||||
10. 计算生熟比 = 熟重 / 生重(保留3位小数,HALF_UP,生重>0且熟重≠null时才计算)
|
||||
11. 更新烹制单:
|
||||
- cookStatus → 2(已完成)
|
||||
- cookStart / cookEnd → 当前时间
|
||||
- rawWeight → 生重(kg)
|
||||
- cookedWeight → 熟重(kg)
|
||||
- rawCookedRatio → 生熟比
|
||||
- chef / chefId → 登录厨师
|
||||
- needPortions / cookedPortions → 份数
|
||||
```
|
||||
|
||||
### 份数计算优先级
|
||||
|
||||
```
|
||||
内供申领单 quantity > 烹制单 needPortions > 兜底值 1
|
||||
```
|
||||
|
||||
### 异常场景
|
||||
|
||||
| 场景 | 错误信息 |
|
||||
|------|---------|
|
||||
| 烹制单不存在 | `烹制单不存在` |
|
||||
| 当前状态不是"待烹制" | `当前状态不允许此操作,仅待烹制状态可提交` |
|
||||
| 烹制单未关联组配任务(comboNo 为空) | `烹制单未关联组配任务,无法开始烹制` |
|
||||
| 组配任务不存在 | `组配任务不存在,comboNo=xxx` |
|
||||
|
||||
### 涉及数据表
|
||||
|
||||
| 表名 | 操作 | 说明 |
|
||||
|------|:--:|------|
|
||||
| `nut_prod_cook_order` | 查询 + 更新 | 校验状态,更新为已完成 |
|
||||
| `nut_prod_clean_order` | 查询 | 通过 foodId + canteenId + mealType + cleanType=2 匹配净菜订单,获取 clean_order_id 用于内供申领单的餐次过滤 |
|
||||
| `nut_sup_internal_supply` | 查询 | 通过 clean_order_id + cleanType=2 关联,获取 batchNo 和 quantity |
|
||||
| `nut_sup_meal_package` | 查询 | 通过 batchNo 查餐品净菜包 |
|
||||
| `nut_sup_meal_pkg_ingredient` | 查询 | 获取各食材的溯源码 |
|
||||
| `nut_prod_combo_task` | 查询 + 更新 | 完善组配状态为已完成 |
|
||||
| `nut_prod_combo_task_item` | 查询 + 更新 | 更新 actualQty + traceCode |
|
||||
| `nut_prod_cook_ingredient` | 查询 + 新增/更新 | 更新主辅材实际用量 + 保存调料用量 |
|
||||
| `nut_mater_base` | 查询 | 获取食材编码和名称 |
|
||||
| `nut_food_composition` | 查询 | 兜底创建 cook_ingredient 时获取食材分类等信息 |
|
||||
|
||||
---
|
||||
|
||||
## 四、调料模糊搜索
|
||||
|
||||
```
|
||||
POST /neglect/ratio-scale/seasoning-search
|
||||
Content-Type: application/json
|
||||
X-DEVICE-CODE: <设备编码>
|
||||
```
|
||||
|
||||
搜索调料食材库,数据源 `nut_mater_base` 一级分类为 18(糖蜜饯)、19(油脂)、20(调味品) 的食材。
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"keyword": "酱油", // 选填 — 模糊匹配食材名称和别名
|
||||
"pageNum": 1, // 必填 — 页码
|
||||
"pageSize": 20 // 必填 — 每页条数
|
||||
}
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "200",
|
||||
"msg": "操作成功",
|
||||
"data": [
|
||||
{
|
||||
"id": "30001",
|
||||
"materName": "酱油",
|
||||
"materCode": "19192004",
|
||||
"alias": "生抽",
|
||||
"canteenId": "2"
|
||||
}
|
||||
],
|
||||
"total": 1
|
||||
}
|
||||
```
|
||||
|
||||
### 字段说明
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | Long → String | 食材id |
|
||||
| materName | String | 食材名称 |
|
||||
| materCode | String | 食材编码 |
|
||||
| alias | String | 别名 |
|
||||
| canteenId | Long → String | 归属食堂id |
|
||||
|
||||
---
|
||||
|
||||
## 总体数据链路图
|
||||
|
||||
```
|
||||
nut_prod_cook_order (烹制单)
|
||||
│
|
||||
├── food_id ──→ nut_food_composition (菜品食材构成: 主材/辅材/调料)
|
||||
│ │
|
||||
│ └── mater_id ──→ nut_mater_base (食材库: 编码、名称、分类)
|
||||
│
|
||||
├── food_id + canteen_id + meal_type ──→ nut_prod_clean_order (净菜订单, clean_type=2)
|
||||
│ │
|
||||
│ └── id = clean_order_id
|
||||
│
|
||||
├── clean_order_id ──→ nut_sup_internal_supply (内供申领单, 按 clean_order_id + clean_type=2 匹配)
|
||||
│ │
|
||||
│ ├── batch_no ──→ nut_sup_meal_package (餐品净菜包)
|
||||
│ │ │
|
||||
│ │ └── nut_sup_meal_pkg_ingredient (溯源码)
|
||||
│ │
|
||||
│ └── quantity ──→ 份数
|
||||
│
|
||||
├── combo_no ──→ nut_prod_combo_task (组配任务)
|
||||
│ │
|
||||
│ └── nut_prod_combo_task_item (组配明细: ingredientCode)
|
||||
│
|
||||
└── cook_ingredient: nut_prod_cook_ingredient (烹制食材明细)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 接口调用时序
|
||||
|
||||
```
|
||||
┌─────────┐ ┌─────────────┐ ┌──────────┐
|
||||
│ 配比秤终端 │ │ Controller │ │ Database │
|
||||
└────┬────┘ └──────┬──────┘ └────┬─────┘
|
||||
│ │ │
|
||||
│ 1. POST /cook-orders/page │
|
||||
│─────────────────────→│ │
|
||||
│ │──→ nut_prod_cook_order (当日+食堂)
|
||||
│ ← 任务列表(按餐次) │←────────────────────│
|
||||
│ │ │
|
||||
│ 2. GET /cook-orders/{id}/composition │
|
||||
│─────────────────────→│ │
|
||||
│ │──→ nut_food_composition (主材+辅材)
|
||||
│ │──→ nut_mater_base (食材名称)
|
||||
│ ← 食材清单(含标准用量) │←────────────────────│
|
||||
│ │ │
|
||||
│ 3. POST /cook-orders/complete │
|
||||
│─────────────────────→│ │
|
||||
│ │──→ 校验状态=待烹制 │
|
||||
│ │──→ 匹配净菜订单(餐次过滤) │
|
||||
│ │──→ 关联internal_supply │
|
||||
│ │──→ 解析溯源码 │
|
||||
│ │──→ 完善+完成组配任务 │
|
||||
│ │──→ 计算生重 │
|
||||
│ │──→ 更新食材明细 │
|
||||
│ │──→ 保存调料用量 │
|
||||
│ │──→ 计算生熟比 │
|
||||
│ │──→ 更新烹制单=已完成 │
|
||||
│ ← 操作成功 │←──── 事务提交 ──────│
|
||||
│ │ │
|
||||
```
|
||||
@@ -0,0 +1,611 @@
|
||||
# 配比秤(新设备)— 采样与制作模式 API 文档
|
||||
|
||||
> Controller: `NutRatioScaleController`
|
||||
> 路径前缀: `/neglect/ratio-scale`(Nacos 白名单 `/nutrition/neglect/**`,无需 Sa-Token)
|
||||
> 设备上下文通过请求头 `X-DEVICE-CODE` 解析(`TerminalContextHelper`,据此拿到食堂 id)
|
||||
> 日期: 2026-09-09
|
||||
>
|
||||
> **序列化规则**:Long 类型字段响应中均为字符串(Jackson `ToStringSerializer`),`BigDecimal` 为普通数字
|
||||
> **单位约定**:
|
||||
> - 提交构成的熟重 `foodWeight` 单位为 **克 (g)**(与 `nut_food_cook.output_weight` 口径一致)
|
||||
> - 食材称量用量 `useWeight` 单位为 **克 (g)**
|
||||
> - 烹制单生重 `rawWeight`、熟重 `cookedWeight` 单位为 **千克 (kg)**
|
||||
> - 食材实际用量 `actualQty` 单位为 **克 (g)**
|
||||
|
||||
---
|
||||
|
||||
## 业务背景
|
||||
|
||||
配比秤新增「采样模式」与「制作模式」,两者通过**同一个提交接口** `POST /constitute/save` 的 `cookMode` 字段区分:
|
||||
|
||||
| cookMode | 模式 | 说明 |
|
||||
|:--------:|------|------|
|
||||
| 2 | 采样模式 | **从零建菜**:称量食材 → 新增菜品(生成构成/营养/宝塔)→ 进入「待审核」→ 后台审核通过后上架 |
|
||||
| 1 | 制作模式 | **基于已有菜品**:称量食材 → 记录熟重+构成快照(历史参考,不覆盖正式构成)→ 标记菜品为「配比秤制作」 |
|
||||
|
||||
### 制作方式枚举
|
||||
|
||||
| 值 | 名称 | 菜品对象 | 数据来源 data_source |
|
||||
|:--:|------|---------|---------------------|
|
||||
| 1 | 制作模式 | 已有菜品(foodId 必填) | 3(配比秤制作) |
|
||||
| 2 | 采样模式 | 新增菜品(foodName 必填) | 2(配比秤采样) |
|
||||
|
||||
### 采样菜品审核状态枚举
|
||||
|
||||
| 状态码 | 状态名 | 说明 |
|
||||
|:------:|--------|------|
|
||||
| 1 | 待审核 | 采样提交后的初始状态,后台可审核 |
|
||||
| 2 | 已通过 | 审核通过,菜品上架生效 |
|
||||
| 3 | 已驳回 | 审核驳回,菜品保持下架,可重新采样同名菜品 |
|
||||
|
||||
### 食材分类枚举
|
||||
|
||||
| 分类 | 名称 | 说明 |
|
||||
|:----:|------|------|
|
||||
| 1 | 主材 | 菜品主要食材 |
|
||||
| 2 | 辅材 | 菜品辅助食材 |
|
||||
| 3 | 调料 | 油盐酱醋等 |
|
||||
|
||||
---
|
||||
|
||||
## 接口清单
|
||||
|
||||
| 序号 | 接口 | 路径 | 用途 |
|
||||
|:----:|------|------|------|
|
||||
| 一 | 食材模糊搜索 | `POST /neglect/ratio-scale/mater-search` | 称量前检索食材(设备对应食堂食材库) |
|
||||
| 二 | 搜菜品 | `POST /neglect/ratio-scale/food-search` | 制作模式选已有菜品(按名称模糊查上架菜品) |
|
||||
| 三 | 查菜品构成 | `GET /neglect/ratio-scale/food/{foodId}/composition` | 制作模式查看已有菜品的主辅料+调料构成 |
|
||||
| 四 | 提交构成 | `POST /neglect/ratio-scale/constitute/save` | 统一提交,cookMode 区分制作/采样 |
|
||||
| 五 | 采样历史 | `POST /neglect/ratio-scale/sample/history` | 查询本食堂采样提交历史(默认当天) |
|
||||
| 六 | 制作历史 | `POST /neglect/ratio-scale/make/history` | 按设备+日期查询制作记录分页 |
|
||||
| 七 | 制作历史图表 | `GET /neglect/ratio-scale/make/history/{foodId}` | 按菜品id查制作历史图表数据 |
|
||||
| 八 | 烹饪完成 | `POST /neglect/ratio-scale/cook-orders/complete` | 按单烹制,任意状态提交均累加 |
|
||||
|
||||
---
|
||||
|
||||
## 一、食材模糊搜索
|
||||
|
||||
```
|
||||
POST /neglect/ratio-scale/mater-search
|
||||
Content-Type: application/json
|
||||
X-DEVICE-CODE: <设备编码>
|
||||
```
|
||||
|
||||
称量食材前,从食材库检索食材(设备对应食堂食材)。
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"keyword": "萝卜", // 选填 — 模糊匹配食材名称和别名
|
||||
"pageNum": 1, // 必填 — 页码
|
||||
"pageSize": 20 // 必填 — 每页条数
|
||||
}
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "00000",
|
||||
"msg": "操作成功",
|
||||
"data": [
|
||||
{
|
||||
"id": "1979825467306471454", // 食材id
|
||||
"materName": "樱桃萝卜", // 食材名称
|
||||
"materCode": "04041012", // 食材编码
|
||||
"alias": null, // 别名
|
||||
"materFirstClass": "04", // 食材一级分类
|
||||
"materSecondClass": "043", // 食材二级分类
|
||||
"materUrl": null, // 食材图片url
|
||||
"canteenId": "2" // 归属食堂id
|
||||
}
|
||||
],
|
||||
"total": 1
|
||||
}
|
||||
```
|
||||
|
||||
### 字段说明
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| id | Long → String | 食材id(提交构成 items.materId 使用) |
|
||||
| materName | String | 食材名称 |
|
||||
| materCode | String | 食材编码(一级+二级+自编码,全局唯一) |
|
||||
| alias | String | 别名 |
|
||||
| materFirstClass | String | 食材一级分类 |
|
||||
| materSecondClass | String | 食材二级分类 |
|
||||
| materUrl | String | 食材图片url |
|
||||
| canteenId | Long → String | 归属食堂id |
|
||||
|
||||
### 逻辑说明
|
||||
|
||||
- 数据源:`nut_mater_base`
|
||||
- 过滤:`canteen_id` = 当前食堂(由 `X-DEVICE-CODE` 解析)
|
||||
- 关键词模糊匹配 `mater_name` 和 `alias`
|
||||
- 排序:`mater_name ASC`
|
||||
|
||||
---
|
||||
|
||||
## 二、搜菜品
|
||||
|
||||
```
|
||||
POST /neglect/ratio-scale/food-search
|
||||
Content-Type: application/json
|
||||
X-DEVICE-CODE: <设备编码>
|
||||
```
|
||||
|
||||
制作模式下,检索本食堂已上架的菜品,供后厨选择目标菜品。
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"keyword": "西兰花", // 选填 — 菜品名称或编号模糊搜索
|
||||
"pageNum": 1, // 必填 — 页码
|
||||
"pageSize": 20 // 必填 — 每页条数
|
||||
}
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "00000",
|
||||
"msg": "操作成功",
|
||||
"data": [
|
||||
{
|
||||
"foodId": "2091839370283118593", // 菜品id
|
||||
"foodCode": "FOOD00012", // 菜品编号
|
||||
"foodName": "清炒西兰花" // 菜品名称
|
||||
}
|
||||
],
|
||||
"total": 1
|
||||
}
|
||||
```
|
||||
|
||||
### 逻辑说明
|
||||
|
||||
- 数据源:`nut_food`(`status=1` 上架)
|
||||
- 过滤:`canteen_id` = 当前食堂
|
||||
- 关键词模糊匹配 `food_name` 和 `food_code`
|
||||
- 排序:`id DESC`
|
||||
|
||||
---
|
||||
|
||||
## 三、查菜品构成
|
||||
|
||||
```
|
||||
GET /neglect/ratio-scale/food/{foodId}/composition
|
||||
X-DEVICE-CODE: <设备编码>
|
||||
```
|
||||
|
||||
制作模式下,根据菜品 id 查询已有菜品的主辅料+调料构成及熟重。
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "00000",
|
||||
"msg": "操作成功",
|
||||
"data": {
|
||||
"foodId": "2091839370283118593", // 菜品id
|
||||
"foodName": "清炒西兰花", // 菜品名称
|
||||
"foodWeight": 450.0, // 熟重(g),从 nut_food_cook.output_weight 反查
|
||||
"ingredients": [
|
||||
{
|
||||
"materId": "1979825467306471454", // 食材id
|
||||
"materName": "樱桃萝卜", // 食材名称
|
||||
"useWeight": 300.0, // 用量(g)
|
||||
"isMain": 1, // 1=主材 / 2=辅材 / 3=调料
|
||||
"isMainName": "主材"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### 逻辑说明
|
||||
|
||||
- 数据源:`nut_food_composition`(按 `food_id` 查全部构成)
|
||||
- 食材名称从 `nut_mater_base` 批量反查
|
||||
|
||||
---
|
||||
|
||||
## 四、提交构成(cookMode 区分采样/制作)
|
||||
|
||||
```
|
||||
POST /neglect/ratio-scale/constitute/save
|
||||
Content-Type: application/json
|
||||
X-DEVICE-CODE: <设备编码>
|
||||
```
|
||||
|
||||
**统一提交接口**,通过 `cookMode` 区分采样/制作。
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"cookMode": 2, // 必填 — 1=制作模式 / 2=采样模式
|
||||
"foodId": 2091839370283118593, // 制作模式必填 — 已有菜品id
|
||||
"foodName": "清炒西兰花", // 采样模式必填 — 菜品名称
|
||||
"foodWeight": 500, // 必填 — 熟重(g),必须 > 0
|
||||
"mealType": 2, // 选填 — 餐次: 1=早餐/2=午餐/3=晚餐/4=加餐
|
||||
"items": [ // 必填 — 食材构成列表,至少1条
|
||||
{
|
||||
"materId": 20001, // 必填 — 食材id(nut_mater_base.id)
|
||||
"useWeight": 300, // 必填 — 食材称量用量(g),必须 > 0
|
||||
"isMain": 1 // 必填 — 食材分类: 1=主材 / 2=辅材 / 3=调料
|
||||
},
|
||||
{
|
||||
"materId": 30001,
|
||||
"useWeight": 50,
|
||||
"isMain": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "00000",
|
||||
"msg": "操作成功",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
### 处理流程(采样模式 cookMode=2)
|
||||
|
||||
```
|
||||
1. 校验食材构成非空 + materId 非空且唯一
|
||||
2. 校验菜品名称在同食堂下唯一(排除已驳回菜品,允许驳回后重新采样同名)
|
||||
3. 生成菜品编号(FOOD + 5位序号)
|
||||
4. 保存菜品 nut_food:data_source=2(配比秤采样) / audit_status=1(待审核) / status=0(下架)
|
||||
5. 保存熟重 nut_food_cook:output_weight = foodWeight
|
||||
6. 保存食材构成 nut_food_composition:mater_id + use_weight + is_main
|
||||
7. 根据构成自动计算营养指标 nut_food_nutri + 膳食宝塔 nut_food_pagoda
|
||||
8. 发起审核记录 nut_food_audit_record:audit_status=1(待审核)
|
||||
```
|
||||
|
||||
### 处理流程(制作模式 cookMode=1)
|
||||
|
||||
```
|
||||
1. 校验食材构成非空 + materId 非空且唯一
|
||||
2. 校验菜品存在(foodId 必填)
|
||||
3. 标记菜品 nut_food.data_source = 3(配比秤制作)
|
||||
4. 保存制作记录 nut_food_matching_use:device_code + food_id + food_name + meal_type + day + food_weight(熟重)
|
||||
5. 保存制作明细 nut_food_matching_use_item:mater_id + mater_name + use_weight + is_main(构成快照)
|
||||
6. 不覆盖菜品的正式构成/营养/宝塔(历史参考)
|
||||
```
|
||||
|
||||
### 异常场景
|
||||
|
||||
| 场景 | 错误信息 |
|
||||
|------|---------|
|
||||
| 食材构成列表为空 | `请完善菜品构成信息` |
|
||||
| 食材id为空 | `菜品食材不能为空` |
|
||||
| 食材id重复 | `菜品食材不能重复,重复食材id:xxx` |
|
||||
| 制作方式非法 | `不支持的制作方式:xxx` |
|
||||
| 采样:同食堂已存在同名菜品(非驳回) | `该食堂下已存在同名餐品` |
|
||||
| 采样:食材id无效 | `存在无效的食材id` |
|
||||
| 制作:菜品不存在 | `菜品不存在` |
|
||||
| 熟重/用量 ≤ 0 | 参数校验:`熟重必须大于0` / `食材用量必须大于0` |
|
||||
|
||||
### 涉及数据表
|
||||
|
||||
**采样模式(cookMode=2)**
|
||||
|
||||
| 表名 | 操作 | 说明 |
|
||||
|------|:--:|------|
|
||||
| `nut_food` | 新增 | 采样菜品主表(采样来源 + 待审核 + 下架) |
|
||||
| `nut_food_cook` | 新增 | 保存熟重 |
|
||||
| `nut_food_composition` | 新增 | 食材构成 |
|
||||
| `nut_food_nutri` | 新增 | 每100g营养指标(自动计算) |
|
||||
| `nut_food_pagoda` | 新增 | 膳食宝塔(自动计算) |
|
||||
| `nut_food_audit_record` | 新增 | 待审核记录 |
|
||||
|
||||
**制作模式(cookMode=1)**
|
||||
|
||||
| 表名 | 操作 | 说明 |
|
||||
|------|:--:|------|
|
||||
| `nut_food` | 更新 | 标记 data_source=3(配比秤制作) |
|
||||
| `nut_food_matching_use` | 新增 | 制作记录(熟重记录) |
|
||||
| `nut_food_matching_use_item` | 新增 | 制作明细(构成快照) |
|
||||
|
||||
---
|
||||
|
||||
## 五、采样历史
|
||||
|
||||
```
|
||||
POST /neglect/ratio-scale/sample/history
|
||||
Content-Type: application/json
|
||||
X-DEVICE-CODE: <设备编码>
|
||||
```
|
||||
|
||||
查询本食堂(由 `X-DEVICE-CODE` 解析)的采样提交历史,默认查询当天。
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"pageNum": 1, // 必填 — 页码
|
||||
"pageSize": 10, // 必填 — 每页条数
|
||||
"keyword": "西兰花", // 选填 — 菜品名称模糊搜索
|
||||
"auditStatus": 1, // 选填 — 审核状态筛选: 1=待审核 / 2=已通过 / 3=已驳回
|
||||
"sampleDate": "2026-09-09" // 选填 — 采样日期,不传默认当天
|
||||
}
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "00000",
|
||||
"msg": "操作成功",
|
||||
"data": [
|
||||
{
|
||||
"foodId": "2097486806812893186", // 菜品id
|
||||
"foodCode": "FOOD00030", // 菜品编号
|
||||
"foodName": "清炒西兰花", // 菜品名称
|
||||
"foodWeight": 500.0, // 熟重(g)
|
||||
"auditStatus": 1, // 审核状态: 1=待审核 / 2=已通过 / 3=已驳回
|
||||
"auditStatusName": "待审核", // 审核状态中文
|
||||
"auditRecordId": "2097486809375612929", // 审核记录id
|
||||
"createTime": "2026-09-09 08:46:39" // 提交时间
|
||||
}
|
||||
],
|
||||
"total": 1
|
||||
}
|
||||
```
|
||||
|
||||
### 逻辑说明
|
||||
|
||||
- 数据源:`nut_food`(`data_source=2` 配比秤采样)
|
||||
- `canteenId` 由 `X-DEVICE-CODE` 解析终端后自动限定
|
||||
- 排序:`create_time DESC`
|
||||
- `foodWeight` 从 `nut_food_cook.output_weight` 反查
|
||||
- `auditRecordId` 从 `nut_food_audit_record` 反查
|
||||
|
||||
---
|
||||
|
||||
## 六、制作历史
|
||||
|
||||
```
|
||||
POST /neglect/ratio-scale/make/history
|
||||
Content-Type: application/json
|
||||
X-DEVICE-CODE: <设备编码>
|
||||
```
|
||||
|
||||
查询本设备(由 `X-DEVICE-CODE` 解析)的制作记录。
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"pageNum": 1, // 必填 — 页码
|
||||
"pageSize": 10, // 必填 — 每页条数
|
||||
"day": "2026-09-09" // 选填 — 制作日期,不传查全部
|
||||
}
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "00000",
|
||||
"msg": "操作成功",
|
||||
"data": [
|
||||
{
|
||||
"id": "2097499999999999999", // 制作记录id
|
||||
"foodId": "2091839370283118593", // 菜品id
|
||||
"foodName": "清炒西兰花", // 菜品名称
|
||||
"foodWeight": 500.0, // 熟重(g)
|
||||
"mealType": 2, // 餐次: 1=早餐/2=午餐/3=晚餐/4=加餐
|
||||
"mealTypeName": "午餐",
|
||||
"day": "2026-09-09", // 制作日期
|
||||
"createTime": "2026-09-09 08:46:39"
|
||||
}
|
||||
],
|
||||
"total": 1
|
||||
}
|
||||
```
|
||||
|
||||
### 逻辑说明
|
||||
|
||||
- 数据源:`nut_food_matching_use`
|
||||
- 过滤:`device_code` = 当前设备(由 `X-DEVICE-CODE` 解析)
|
||||
- 排序:`create_time DESC`
|
||||
|
||||
---
|
||||
|
||||
## 七、制作历史图表(按菜品id)
|
||||
|
||||
```
|
||||
GET /neglect/ratio-scale/make/history/{foodId}
|
||||
X-DEVICE-CODE: <设备编码>
|
||||
```
|
||||
|
||||
根据菜品 id 查询该菜品的所有制作记录,返回图表数据(对齐借鉴项目 `queryGoodsInfoByFoodIdMatchingList`),用于前端渲染制作趋势图。
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "00000",
|
||||
"msg": "操作成功",
|
||||
"data": [
|
||||
{
|
||||
"xAxes": [
|
||||
{"goodId": "", "goodName": "时间"},
|
||||
{"goodId": "", "goodName": "熟重"},
|
||||
{"goodId": "20001", "goodName": "樱桃萝卜"},
|
||||
{"goodId": "30001", "goodName": "酱油"}
|
||||
],
|
||||
"yAxes": [
|
||||
{"value": "2026-09-09 08:46:39"},
|
||||
{"value": 500.0},
|
||||
{"value": 300.0},
|
||||
{"value": 50.0}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 字段说明
|
||||
|
||||
| 字段 | 说明 |
|
||||
|------|------|
|
||||
| xAxes | 横轴模板:时间、熟重、该菜品所有出现过的食材(去重保序),所有记录共用 |
|
||||
| xAxes[].goodId | 食材id(时间/熟重项为空字符串) |
|
||||
| xAxes[].goodName | 项名称(时间/熟重/食材名称) |
|
||||
| yAxes | 纵轴值,与 xAxes 一一对应 |
|
||||
| yAxes[].value | 值:时间项为时间戳,其余为数值(缺失食材补 0) |
|
||||
|
||||
### 逻辑说明
|
||||
|
||||
- 数据源:`nut_food_matching_use`(主表)+ `nut_food_matching_use_item`(子表)
|
||||
- 主表按 `food_id` 过滤,`create_time DESC` 排序
|
||||
- 子表按 `matching_use_id` 批量查询并分组(消除 N+1)
|
||||
- 时间项取 `create_time`,熟重项取 `food_weight`,食材项取 `use_weight`(缺失补 0)
|
||||
|
||||
---
|
||||
|
||||
## 八、烹饪完成(支持再次烹制)
|
||||
|
||||
```
|
||||
POST /neglect/ratio-scale/cook-orders/complete
|
||||
Content-Type: application/json
|
||||
X-DEVICE-CODE: <设备编码>
|
||||
```
|
||||
|
||||
按单烹制提交。**改造点**:原逻辑一次性完成(`待烹制 → 已完成`),现支持**任意状态下再次烹制**——每次提交累加份数/生重/熟重并留存一条流水,不校验烹制状态,需求达标后仍可继续烹制(应对菜不够卖接着做的场景)。
|
||||
|
||||
### 请求体
|
||||
|
||||
```json
|
||||
{
|
||||
"cookOrderId": 10001, // 必填 — 烹制单id
|
||||
"portions": 10, // 选填 — 本次烹制份数,不传则按申领单/需求份数兜底
|
||||
"cookStart": "2026-09-09 10:00:00", // 选填 — 本次烹制开始时间
|
||||
"cookedWeight": 3.5, // 必填 — 本次熟重(kg)
|
||||
"items": [ // 必填 — 主辅材实际用量列表,至少1条
|
||||
{
|
||||
"materId": 20001, // 必填 — 食材id
|
||||
"actualQty": 5000 // 必填 — 实际用量(g)
|
||||
}
|
||||
],
|
||||
"seasonings": [ // 选填 — 调料用量列表
|
||||
{
|
||||
"materId": 30001,
|
||||
"actualQty": 15.0
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 响应
|
||||
|
||||
```json
|
||||
{
|
||||
"code": "00000",
|
||||
"msg": "操作成功",
|
||||
"data": null
|
||||
}
|
||||
```
|
||||
|
||||
### 状态流转规则(改造核心)
|
||||
|
||||
```
|
||||
每次提交后(不校验状态,任何状态下提交均累加):
|
||||
cooked_portions 累加 += 本次份数
|
||||
raw_weight 累加 += 本次生重
|
||||
cooked_weight 累加 += 本次熟重
|
||||
cook_status → 2(已完成,每次提交都置此状态,允许继续烹制累加)
|
||||
生熟比 = 累计熟重 / 累计生重(用累加后的值)
|
||||
|
||||
时间语义:
|
||||
cook_start = 首次烹制开始时间(后续烹制不覆盖)
|
||||
cook_end = 最后一次烹制结束时间(每次更新)
|
||||
```
|
||||
|
||||
### 处理流程
|
||||
|
||||
```
|
||||
1. 校验烹制单存在 + 食堂权限(不校验烹制状态,任何状态下提交均累加数据)
|
||||
2. 本次烹制份数 = 入参 portions(优先)→ 申领单 quantity → 需求份数 → 1
|
||||
3. 首次烹制(cooked_portions=0)才完善组配任务并完成
|
||||
4. 计算本次生重(Σ actualQty / 1000,g→kg)
|
||||
5. 计算生熟比 = 累计熟重 / 累计生重(用累加后的值)
|
||||
6. 写烹制流水 nut_prod_cook_flow(本次生重/熟重/份数/起止时间)
|
||||
7. 保存食材明细 + 调料(首次更新预生成明细,再次插入新明细,均关联 flow_id)
|
||||
8. 累加主表:份数/生重/熟重累加 + 状态置已完成 + 起止时间
|
||||
```
|
||||
|
||||
### 异常场景
|
||||
|
||||
| 场景 | 错误信息 |
|
||||
|------|---------|
|
||||
| 烹制单不存在 | `烹制单不存在` |
|
||||
| 首次烹制未关联组配任务 | `烹制单未关联组配任务,无法开始烹制` |
|
||||
| 组配任务不存在 | `组配任务不存在,comboNo=xxx` |
|
||||
|
||||
### 涉及数据表
|
||||
|
||||
| 表名 | 操作 | 说明 |
|
||||
|------|:--:|------|
|
||||
| `nut_prod_cook_order` | 查询 + 更新 | 累加份数/生重/熟重 + 状态置已完成 |
|
||||
| `nut_prod_cook_flow` | 新增 | **烹制流水**,每次烹制一条 |
|
||||
| `nut_prod_cook_ingredient` | 查询 + 更新/新增 | 首次更新预生成明细,再次插入新明细,均带 `flow_id` |
|
||||
| `nut_prod_combo_task` / `_item` | 查询 + 更新 | 仅首次烹制时完善组配 |
|
||||
| `nut_sup_internal_supply` / `nut_sup_meal_package` / `_ingredient` | 查询 | 解析溯源码与份数 |
|
||||
| `nut_mater_base` / `nut_food_composition` | 查询 | 食材编码/名称/分类 |
|
||||
|
||||
---
|
||||
|
||||
## 数据链路图(采样模式 cookMode=2)
|
||||
|
||||
```
|
||||
nut_mater_base (食材库)
|
||||
│
|
||||
│ 采样称量 mater_id + use_weight(g)
|
||||
▼
|
||||
POST /constitute/save (cookMode=2)
|
||||
│
|
||||
├── 生成 nut_food (采样来源 + 待审核 + 下架)
|
||||
├── 生成 nut_food_cook (熟重 = foodWeight)
|
||||
├── 生成 nut_food_composition (食材构成)
|
||||
├── 自动计算 nut_food_nutri (每100g营养) + nut_food_pagoda (膳食宝塔)
|
||||
└── 生成 nut_food_audit_record (待审核)
|
||||
```
|
||||
|
||||
## 数据链路图(制作模式 cookMode=1)
|
||||
|
||||
```
|
||||
nut_food (已有菜品)
|
||||
│
|
||||
│ 制作称量 mater_id + use_weight(g) + 熟重
|
||||
▼
|
||||
POST /constitute/save (cookMode=1)
|
||||
│
|
||||
├── 标记 nut_food.data_source = 3 (配比秤制作)
|
||||
├── 生成 nut_food_matching_use (制作记录:熟重/餐次/日期/设备)
|
||||
└── 生成 nut_food_matching_use_item (构成快照,历史参考)
|
||||
(不覆盖 nut_food_composition / nut_food_nutri / nut_food_pagoda)
|
||||
```
|
||||
|
||||
## 数据链路图(再次烹制)
|
||||
|
||||
```
|
||||
nut_prod_cook_order (烹制单,累加数据)
|
||||
│
|
||||
├── POST /cook-orders/complete (每次烹制)
|
||||
│ ├── 生成 nut_prod_cook_flow (流水,每次一条)
|
||||
│ └── 生成/更新 nut_prod_cook_ingredient (明细,带 flow_id)
|
||||
│
|
||||
└── 主表累加: cooked_portions / raw_weight / cooked_weight
|
||||
cook_start = 首次开始 / cook_end = 末次结束
|
||||
cook_status = 已完成(每次提交都置此状态,允许继续烹制累加)
|
||||
```
|
||||
Reference in New Issue
Block a user