Author SHA1 Message Date
mazengfei 94bcdb3d9b feat(ratio-scale): 新增烹饪时长采集及调料放置时间支持
- 配比秤采样提交接口新增字段 cookStart,传递烹饪开始时间
- 食材构成中调料项新增 putTime 字段,记录调料首次使用时间
- 设备端提交采样时食材构造调整,调料按名称匹配 putTime 填充
- 新增对烹饪时长的后端计算功能,时长单位为分钟自动向上取整
- 采样列表接口响应新增 cookStart 与 cookDuration 字段,用于显示烹饪时长
- 配比秤采样模式相关API文档同步更新,废弃制作模式接口及字段
- 烹饪完成接口要求强化传递 cookStart,后端基于此计算并更新烹饪时长
- 关联数据库迁移支持烹饪时长字段持久化及历史记录完善
2026-09-21 14:21:17 +08:00
mazengfei 7b66652c0b 厨配秤: 统一采样数据结构及接口
- 将提交构成接口改为提交采样,废弃制作模式,调整请求参数结构
- 修改采样历史接口为已提交采样列表,调整接口路径和请求参数
- 更新数据模型,替换旧的审核状态为实验状态,新增实验编号字段
- 修改列表适配器显示逻辑,展示实验状态及熟重信息,调整颜色映射
- 调整相关网络请求及回调函数,删除无用参数,简化调用
- 更新UI页面文本,适配新版采样列表数据格式与提示信息
- 删除相关无用的旧状态定义及属性,保持代码整洁
2026-09-11 15:34:37 +08:00
mazengfei 9e4b2bd009 厨配秤: 统一采样数据结构及接口
- 将提交构成接口改为提交采样,废弃制作模式,调整请求参数结构
- 修改采样历史接口为已提交采样列表,调整接口路径和请求参数
- 更新数据模型,替换旧的审核状态为实验状态,新增实验编号字段
- 修改列表适配器显示逻辑,展示实验状态及熟重信息,调整颜色映射
- 调整相关网络请求及回调函数,删除无用参数,简化调用
- 更新UI页面文本,适配新版采样列表数据格式与提示信息
- 删除相关无用的旧状态定义及属性,保持代码整洁
2026-09-11 15:34:06 +08:00
mazengfei 6d3c5490a4 feat(food-prepare): 增加食材信息录入卡及相关接口支持
- 新增手动录入食材信息的UI布局,包含食材名称搜索、主辅材选择及用量输入
- 整合采样模式下的食材搜索弹窗,支持食材模糊查询与净材种类选择
- 新增相关网络接口调用,实现食材搜索、菜品搜索、菜品构成查询及采样历史等功能
- 优化食材列表展示,支持采样历史审核状态和熟重显示,增加颜色区分
- 修改PrepareFoodActivity,采样模式启用手动新增食材功能,包含添加、重置操作
- 调整Adapter和ViewModel,兼容新接口数据模型,支持分页加载和状态回调
- 修正接口路径和网络请求地址,统一使用nutrition/neglect路径前缀
- 删除冗余代码和未使用的旧接口代码,简化搜索逻辑及界面响应机制
2026-09-10 13:41:35 +08:00
mazengfei 45543295e3 Merge remote-tracking branch 'origin/dev_260316_新设备' into dev_260316_新设备 2026-09-08 14:13:05 +08:00
mazengfei 049c724303 config(base): 更新生产环境配置地址和设备ID
- 将appBaseUrl从UAT环境切换到PROD生产环境
- 更新PROD_BASE_URL为正式平台API地址
- 更换SCALE设备的正式环境DEVICE_ID_2
- 移除测试设备ID注释,启用正式设备ID配置
2026-09-08 14:12:48 +08:00
21 changed files with 1592 additions and 299 deletions
@@ -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,7 +8,7 @@ package com.shuwei.dish.match.base
enum class DeviceRole { MASTER, SLAVE }
object GlobalData {
var appBaseUrl: String = UAT_BASE_URL
var appBaseUrl: String = PROD_BASE_URL
/**
* 具体业务 BaseUrl
@@ -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,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,259 @@
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(
/** 食材idLong → 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,
/** 归属食堂idLong → String */
val canteenId: String = ""
)
// ==================== 二、搜菜品 ====================
/**
* 搜菜品请求参数(制作模式选已有菜品)
* 对应接口: POST /neglect/ratio-scale/food-search
* 数据源: nut_foodstatus=1 上架)
*/
data class FoodSearchRequest(
/** 菜品名称或编号模糊搜索 */
val keyword: String? = null,
/** 页码 */
val pageNum: Int = 1,
/** 每页条数 */
val pageSize: Int = 20
)
/**
* 搜菜品结果条目
* 注意: foodId 为 Long 类型,服务端序列化为 String
*/
data class FoodSearchItem(
/** 菜品idLong → String */
val foodId: String = "",
/** 菜品编号 */
val foodCode: String = "",
/** 菜品名称 */
val foodName: String = ""
)
// ==================== 三、查菜品构成 ====================
/**
* 查菜品构成响应 — 单个食材
* 对应接口: GET /neglect/ratio-scale/food/{foodId}/composition
*/
data class FoodCompositionIngredient(
/** 食材idLong → 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(
/** 菜品idLong → 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(
/** 食材idnut_mater_base.id */
val materId: String = "",
/** 食材称量用量(g),必须 > 0 */
val useWeight: Double = 0.0,
/** 食材分类: 1=主材 / 2=辅材 / 3=调料 */
val isMain: Int = 0,
/** 调料首次使用时间 yyyy-MM-dd HH:mm:ss,仅调料需要,主辅材留空;字段与制作模式 CookCompleteItem 对齐 */
val putTime: String? = null
)
/**
* 提交采样请求(落库味养创新实验,status=1 实验中)
* 对应接口: POST /neglect/ratio-scale/constitute/save
* 制作模式已废弃本接口,统一为提交采样,不再传 cookMode/foodId
*/
data class ConstituteSaveRequest(
/** 菜品名称 */
val foodName: String? = null,
/** 烹饪开始时间 yyyy-MM-dd HH:mm:ss,进入提交页面时刻;字段与制作模式 CookCompleteRequest 对齐 */
val cookStart: String? = null,
/** 熟重(g),必须 > 0 */
val foodWeight: Double = 0.0,
/** 食材构成列表,至少 1 条 */
val items: List<ConstituteSaveItem> = emptyList()
)
// ==================== 五、已提交采样列表 ====================
/**
* 已提交采样列表查询请求参数
* 对应接口: POST /neglect/ratio-scale/sample-list
* 数据源: nut_innovationsource=2 配比秤采样),按提交时间倒序,不分日期
*/
data class SampleHistoryRequest(
/** 页码 */
val pageNum: Int = 1,
/** 每页条数 */
val pageSize: Int = 10
)
/**
* 已提交采样列表结果条目
* 注意: innovId 为 Long 类型,服务端序列化为 String
*/
data class SampleHistoryItem(
/** 味养创新实验idLong → String */
val innovId: String = "",
/** 实验编号 */
val innovNo: String = "",
/** 餐品名称 */
val foodName: String = "",
/** 熟重(g) */
val foodWeight: Double = 0.0,
/** 烹饪开始时间,提交时未传则为 null */
val cookStart: String? = null,
/** 烹饪时长(分钟),后端按 提交时间-烹饪开始时间 向上取整计算;未传 cookStart 则为 null */
val cookDuration: Int? = null,
/** 状态: 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(
/** 制作记录idLong → String */
val id: String = "",
/** 菜品idLong → 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()
)
@@ -7,7 +7,18 @@ 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
@@ -29,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?>
@@ -39,7 +50,7 @@ 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?>
@@ -48,7 +59,7 @@ interface ApiService {
*/
@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>?>
@@ -57,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>?>
@@ -66,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>?>
@@ -76,7 +87,7 @@ 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>?>
@@ -120,4 +131,66 @@ interface ApiService {
@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>?>
}
@@ -10,7 +10,18 @@ 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
@@ -313,6 +324,127 @@ class NetViewModel(
}
}
/**
* 食材模糊搜索(回调版本)
* @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 监听
*/
@@ -6,7 +6,18 @@ 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
@@ -65,6 +76,34 @@ class RemoteRepository {
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>,
@@ -4,34 +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.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.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() {
@@ -40,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)
})
@@ -73,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)
@@ -94,31 +76,6 @@ class FoodSearchActivity : BaseActivity() {
adapter = recordAdapter
}
addViewListener()
initObserver()
}
/**
* 收集 cookOrderPageState,统一处理 Loading / Success / Error 状态
*/
private fun initObserver() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
netViewModel.cookOrderPageState.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)
loadEmptyView()
}
is UiState.Idle -> {}
}
}
}
}
}
private fun addViewListener() {
@@ -164,63 +121,61 @@ 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 request = CookOrderPageRequest(
mealType = dinnerType.toIntOrNull(),
keyword = input.trim()
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)
toast(state.msg)
if (pageNo == 1) loadEmptyView()
}
else -> {}
}
}
)
netViewModel.getCookOrderPage(request = request)
}
/**
* 将 CookOrderItem 映射为 FoodRecord,适配现有 Adapter
* FoodSearchItem FoodRecord 映射,供 Food2Adapter 展示
* 采样模式下返回给 PrepareFoodActivity 作为称量模板
*/
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
)
}
private fun FoodSearchItem.toFoodRecord(): FoodRecord = FoodRecord(
foodId = foodId,
foodName = foodName,
cookMode = 1
)
/**
* 处理搜索结果:从分组响应中 flatten 所有 cookOrders,映射为 FoodRecord 填充列表
* 处理搜索结果:FoodSearchItem → FoodRecord 填充列表
*/
@SuppressLint("NotifyDataSetChanged")
private fun handleSearchResult(groups: List<CookOrderMealGroup>?) {
private fun handleSearchResult(items: List<FoodSearchItem>?) {
delayDismissLoading()
finishRefresh()
binding.refreshLayout.setEnableRefresh(true)
val records = groups
?.flatMap { it.cookOrders }
?.map { it.toFoodRecord() }
?.toMutableList()
if (records.isNullOrEmpty()) {
loadEmptyView()
if (items.isNullOrEmpty()) {
if (pageNo == 1) {
loadEmptyView()
}
return
}
list.clear()
list.addAll(records)
if (pageNo == 1) list.clear()
list.addAll(items.map { it.toFoodRecord() })
recordAdapter.notifyDataSetChanged()
// 新接口暂不分页,禁用加载更多
binding.refreshLayout.setEnableLoadMore(false)
val isLoadMoreEnable = items.size >= pageSize
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
if (isLoadMoreEnable) pageNo++
}
private fun finishRefresh() {
@@ -19,8 +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
@@ -35,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
@@ -77,6 +79,12 @@ class PrepareFoodActivity : BaseActivity() {
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)
@@ -111,19 +119,23 @@ 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()
// 仅采样模式启用摄像头识别,制作模式不需要
if (isSamplingMode) {
initCamera(binding.flCameraContainer)
}
// if (isSamplingMode) {
// initCamera(binding.flCameraContainer)
// }
initRecyclerView()
initObserver()
@@ -136,11 +148,11 @@ class PrepareFoodActivity : BaseActivity() {
}
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
@@ -171,8 +183,11 @@ class PrepareFoodActivity : BaseActivity() {
tag = netWeight
}
}
// 仅采样模式触发食材识别
// 仅采样模式:用量自动回填秤重 + 触发食材识别
if (SpTool.cookMode == 1) {
val displayWeight =
if (netWeight > 0) netWeight.roundedOneDecimalPlace().toString() else ""
binding.etAmount.setText(displayWeight)
recognizeFood(netWeight)
}
}
@@ -320,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) {
// 主材已满,所有非接口数据均为辅材
@@ -338,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() }
}
/**
* 食材检索选中回调:回填名称,暂存 GoodsItemmaterId 用于提交)
*/
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()) {
@@ -378,23 +466,6 @@ class PrepareFoodActivity : BaseActivity() {
private fun initObserver() {
// 旧接口 observer(采样模式使用)
lifecycleScope.launch {
netViewModel.foodDetailState.collect { state ->
when (state) {
is UiState.Success -> {
val detail = state.data
if (detail == null) {
toast("查询菜品信息为空")
return@collect
}
loadDishDetail(detail)
}
is UiState.Error -> toast(state.msg)
else -> {}
}
}
}
// 新配比秤接口 observer(制作模式使用)
lifecycleScope.launch {
netViewModel.cookOrderCompositionState.collect { state ->
@@ -414,9 +485,25 @@ class PrepareFoodActivity : BaseActivity() {
}
}
/** 接口:通过 foodId 查询菜品构成(采样模式使用 */
/** 接口:通过 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 查询菜品食材构成(制作模式使用) */
@@ -425,17 +512,23 @@ class PrepareFoodActivity : BaseActivity() {
}
private fun loadDishDetail(detail: CookFoodDTO) {
// val voList = detail.stFoodInfoConstituteList
val voList = detail.foodConstituteList
if (voList.isNullOrEmpty()) {
return
}
// 筛选出主材和辅材,转换为 GoodsItemuseWeight 置零)
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 等操作正确
/**
* 采样模式:将 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
@@ -475,13 +568,11 @@ class PrepareFoodActivity : BaseActivity() {
list.forEachIndexed { index, entity ->
entity.isClicked = index == position
}
// 制作模式:选中食材时同步当前秤重
if (SpTool.cookMode == 0) {
val item = list.getOrNull(position)
if (item != null && currentWeight > 0) {
item.useWeight = currentWeight
item.isSetFinished = true
}
// 选中食材时同步当前秤重(制作/采样均支持)
val item = list.getOrNull(position)
if (item != null && currentWeight > 0) {
item.useWeight = currentWeight
item.isSetFinished = true
}
notifyDataSetChanged()
}
@@ -519,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())
}
}
@@ -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(
@@ -21,6 +21,8 @@ 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
@@ -456,7 +458,13 @@ class SubmitFoodActivity : BaseActivity() {
return@launch
}
// 旧接口路径(采样模式 / 无烹制单 ID
// 采样模式 → 调新配比秤提交采样接口(落库味养创新实验,状态=实验中
if (food?.cookMode == 1) {
submitConstitute()
return@launch
}
// 旧接口路径(无烹制单 ID 的制作模式兜底)
cookFoodEntity.let {
it.matchingConstituteInfoList = this@SubmitFoodActivity.goodsList
it.dinnerType = when (it.dinnerType) {
@@ -537,6 +545,77 @@ class SubmitFoodActivity : BaseActivity() {
)
}
/**
* 提交采样:从 goodsList 提取全部构成(主材/辅材/调料),组装 ConstituteSaveRequest 提交
* 落库味养创新实验;熟重 foodWeight 单位为 gisMain 直接取 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
// 调料(isMain=3)按 goodsName 匹配首次使用时间填入 putTime,主辅材留空
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,
putTime = if (it.materialType == 3) {
it.goodsName?.let { name -> seasoningFirstUseMap[name] }
} else null
)
}
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,
cookStart = cookStartTime,
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 等)
@@ -224,7 +224,10 @@ class FoodListFragment : BaseFragment<FragmentFoodListBinding>() {
currentJob?.cancel()
currentJob = viewLifecycleOwner.lifecycleScope.launch {
// 首次加载传 mealType=null 获取所有餐次,切换 Tab 时传当前餐次精确请求
val mealType = if (isFirstLoad) null else dinnerType.toIntOrNull()
val mealType = if (isFirstLoad) null else when (dinnerType) {
"1", "2", "3", "4" -> dinnerType.toInt()
else -> null // "0" 或非法值不传,由后端返回全部餐次
}
val request = CookOrderPageRequest(
mealType = mealType,
keyword = foodName
@@ -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"
+4
View File
@@ -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>
+75 -98
View File
@@ -15,20 +15,19 @@
## 业务背景
配比秤是一款独立于现有组配秤(`/neglect` 路径)的新硬件设备,部署在食堂后厨。第一期实现"按单烹制"功能:厨师在配比秤终端上查看当日烹饪任务 → 查看菜品食材构成 → 提交材实际用量并触发组配完成 → 开始烹制 → 烹饪完成后提交熟重调料用量。
配比秤是一款独立于现有组配秤(`/neglect` 路径)的新硬件设备,部署在食堂后厨。第一期实现"按单烹制"功能:厨师在配比秤终端上查看当日烹饪任务 → 查看菜品食材构成 → 提交主辅材实际用量+熟重+调料用量,一次性完成烹制
### 核心流程
```
当日烹饪任务列表 → 查看菜品食材构成 → 去制作(提交主辅材实际用量) → 烹饪完成(提交熟重 + 调料用量
当日烹饪任务列表 → 查看菜品食材构成 → 烹饪完成(提交主辅材用量 + 熟重 + 调料)
```
### 烹制状态枚举
| 状态码 | 状态名 | 说明 |
|:------:|--------|------|
| 0 | 待烹制 | 初始状态,可进行"去制作"操作 |
| 1 | 烹制中 | 已提交制作,可进行"烹饪完成"操作 |
| 0 | 待烹制 | 初始状态,可进行"烹饪完成"操作 |
| 2 | 已完成 | 烹制结束,不可再操作 |
| 3 | 异常 | 异常状态 |
@@ -46,17 +45,17 @@
| 序号 | 接口 | 路径 | 用途 |
|:----:|------|------|------|
| 一 | 当日烹饪任务列表(按餐次分组) | `POST /neglect/ratio-scale/cook-orders/page` | 按餐次分组返回今日需烹制的菜品列表 |
| 一 | 当日烹饪任务列表(按餐次分组) | `POST /neglect/ratio-scale/cook-orders/list` | 按餐次分组返回今日需烹制的菜品列表 |
| 二 | 菜品食材构成 | `GET /neglect/ratio-scale/cook-orders/{cookOrderId}/composition` | 查看菜品的主材和辅材清单(含标准用量) |
| 三 | 去制作 | `POST /neglect/ratio-scale/cook-orders/submit` | 提交主辅材实际用量,完善组配并开始烹制 |
| 四 | 烹饪完成 | `POST /neglect/ratio-scale/cook-orders/finish` | 提交熟重和调料用量,计算生熟比 |
| 三 | 烹饪完成 | `POST /neglect/ratio-scale/cook-orders/complete` | 提交主辅材用量+熟重+调料,一次完成烹制 |
| 四 | 调料模糊搜索 | `POST /neglect/ratio-scale/seasoning-search` | 模糊搜索调料(糖蜜饯+油脂+调味品三大类) |
---
## 一、当日烹饪任务列表(按餐次分组)
```
POST /neglect/ratio-scale/cook-orders/page
POST /neglect/ratio-scale/cook-orders/list
Content-Type: application/json
X-DEVICE-CODE: <设备编码>
X-DEVICE-TOKEN: <设备登录Token>
@@ -70,9 +69,7 @@ X-DEVICE-TOKEN: <设备登录Token>
{
"date": "2026-07-29", // 选填 — 计划日期 yyyy-MM-dd,默认当天
"mealType": 2, // 选填 — 餐次筛选: 1=早餐 / 2=午餐 / 3=晚餐 / 4=加餐
"keyword": "红烧肉", // 选填 — 菜品名称模糊搜索
"pageNum": 1, // 选填 — 保留字段,当前不使用
"pageSize": 20 // 选填 — 保留字段,当前不使用
"keyword": "红烧肉" // 选填 — 菜品名称模糊搜索
}
```
@@ -203,16 +200,16 @@ X-DEVICE-TOKEN: <设备登录Token>
---
## 三、去制作:提交食材实际用量并开始烹制
## 三、烹饪完成:提交主辅材用量+熟重+调料
```
POST /neglect/ratio-scale/cook-orders/submit
POST /neglect/ratio-scale/cook-orders/complete
Content-Type: application/json
X-DEVICE-CODE: <设备编码>
X-DEVICE-TOKEN: <设备登录Token>
```
厨师在秤上完成主辅材称重后,提交各食材的实际用量。后端自动完成:组配任务完善 → 组配完成 → 烹制单状态切换为"烹制中" → 烹制食材明细更新
厨师在秤上完成称重后一次性提交全部数据,后端自动完成:组配任务完善 → 组配完成 → 计算生重生熟比 → 保存调料 → 烹制单置为已完成
**该接口为事务性操作(`@Transactional`),所有步骤在同一事务中执行,任意步骤失败则全部回滚。**
@@ -221,7 +218,7 @@ X-DEVICE-TOKEN: <设备登录Token>
```json
{
"cookOrderId": 10001, // 必填 — 烹制单id
"items": [ // 必填 — 材实际用量列表,至少1条
"items": [ // 必填 — 主辅材实际用量列表,至少1条
{
"materId": 20001, // 必填 — 食材id
"actualQty": 520.5 // 必填 — 实际用量(g)
@@ -230,6 +227,13 @@ X-DEVICE-TOKEN: <设备登录Token>
"materId": 20002,
"actualQty": 310.0
}
],
"cookedWeight": 3.200, // 必填 — 熟重(kg)
"seasonings": [ // 选填 — 调料用量列表
{
"materId": 30001, // 必填 — 调料食材id
"actualQty": 15.0 // 必填 — 实际用量(g)
}
]
}
```
@@ -249,22 +253,26 @@ X-DEVICE-TOKEN: <设备登录Token>
```
1. 校验烹制单状态 = 0(待烹制),否则报错
2. 通过内供申领单关联餐品净菜包:
链路: nut_prod_cook_order.food_id → nut_sup_internal_supply(food_id + canteen_id + clean_type=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 / 1000g→kg,保留3位小数)
7. 从设备Token获取厨师信息(chef + chefId
8. 更新烹制单:
- cookStatus → 1(烹制中
- cookStart → 当前时间
- rawWeight → 生重(kg)
- chef / chefId → 登录厨师
- needPortions / cookedPortions → 份数
9. 更新烹制食材明细(cook_ingredient):
- 已有明细 → 更新 actualQty + traceCode
- 无已有明细 → 按 foodComposition 自动创建兜底记录
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 → 份数
```
### 份数计算优先级
@@ -278,7 +286,7 @@ X-DEVICE-TOKEN: <设备登录Token>
| 场景 | 错误信息 |
|------|---------|
| 烹制单不存在 | `烹制单不存在` |
| 当前状态不是"待烹制" | `当前状态不允许此操作,仅待烹制状态可提交制作` |
| 当前状态不是"待烹制" | `当前状态不允许此操作,仅待烹制状态可提交` |
| 烹制单未关联组配任务(comboNo 为空) | `烹制单未关联组配任务,无法开始烹制` |
| 组配任务不存在 | `组配任务不存在,comboNo=xxx` |
@@ -286,47 +294,36 @@ X-DEVICE-TOKEN: <设备登录Token>
| 表名 | 操作 | 说明 |
|------|:--:|------|
| `nut_prod_cook_order` | 查询 + 更新 | 校验状态,更新为烹制中 |
| `nut_sup_internal_supply` | 查询 | 通过 foodId + canteenId + cleanType=2 关联,获取 batchNo 和 quantity |
| `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_prod_cook_ingredient` | 查询 + 新增/更新 | 更新主辅材实际用量 + 保存调料用量 |
| `nut_mater_base` | 查询 | 获取食材编码和名称 |
| `nut_food_composition` | 查询 | 兜底创建 cook_ingredient 时获取食材分类等信息 |
---
## 四、烹饪完成:提交熟重和调料用量
## 四、调料模糊搜索
```
POST /neglect/ratio-scale/cook-orders/finish
POST /neglect/ratio-scale/seasoning-search
Content-Type: application/json
X-DEVICE-CODE: <设备编码>
X-DEVICE-TOKEN: <设备登录Token>
```
烹饪结束后,厨师在秤上称量熟重,并提交调料用量。后端自动计算生熟比
**该接口为事务性操作(`@Transactional`)。**
搜索调料食材库,数据源 `nut_mater_base` 一级分类为 18(糖蜜饯)、19(油脂)、20(调味品) 的食材
### 请求体
```json
{
"cookOrderId": 10001, // 填 — 烹制单id
"cookedWeight": 3.200, // 必填 — 熟重(kg)
"seasonings": [ // 填 — 调料用量列表
{
"materId": 30001, // 必填 — 调料食材id
"actualQty": 15.0 // 必填 — 实际用量(g)
},
{
"materId": 30002,
"actualQty": 8.5
}
]
"keyword": "酱油", // 填 — 模糊匹配食材名称和别名
"pageNum": 1, // 必填 — 页码
"pageSize": 20 // 填 — 每页条数
}
```
@@ -336,47 +333,28 @@ X-DEVICE-TOKEN: <设备登录Token>
{
"code": "200",
"msg": "操作成功",
"data": null
"data": [
{
"id": "30001",
"materName": "酱油",
"materCode": "19192004",
"alias": "生抽",
"canteenId": "2"
}
],
"total": 1
}
```
### 处理流程
### 字段说明
```
1. 校验烹制单状态 = 1(烹制中),否则报错
2. 如有调料:保存到 nut_prod_cook_ingredient
- 已在 cook_ingredient 中的调料(ingredientClass=3 → 更新 actualQty
- 新调料 → 新增记录(ingredientClass=3 调料)
3. 计算生熟比 = cookedWeight / rawWeight(保留3位小数,HALF_UP
4. 更新烹制单:
- cookStatus → 2(已完成)
- cookedWeight → 熟重(kg)
- rawCookedRatio → 生熟比
- cookEnd → 当前时间
```
### 生熟比计算
```
生熟比 = 熟重(kg) / 生重(kg)
精度: 3位小数, HALF_UP
条件: 生重 > 0 且熟重 != null 时才计算,否则生熟比为 null
```
### 异常场景
| 场景 | 错误信息 |
|------|---------|
| 烹制单不存在 | `烹制单不存在` |
| 当前状态不是"烹制中" | `当前状态不允许此操作,仅烹制中状态可完成烹制` |
### 涉及数据表
| 表名 | 操作 | 说明 |
|------|:--:|------|
| `nut_prod_cook_order` | 查询 + 更新 | 校验状态,更新为已完成,记录熟重和生熟比 |
| `nut_prod_cook_ingredient` | 查询 + 新增/更新 | 保存调料用量(ingredientClass=3 |
| `nut_mater_base` | 查询 | 获取调料食材编码和名称 |
| 字段 | 类型 | 说明 |
|------|------|------|
| id | Long → String | 食材id |
| materName | String | 食材名称 |
| materCode | String | 食材编码 |
| alias | String | 别名 |
| canteenId | Long → String | 归属食堂id |
---
@@ -389,13 +367,17 @@ nut_prod_cook_order (烹制单)
│ │
│ └── mater_id ──→ nut_mater_base (食材库: 编码、名称、分类)
├── canteen_id + food_id ──→ nut_sup_internal_supply (内供申领单)
│ │
├── batch_no ──→ nut_sup_meal_package (餐品净菜包)
│ │
│ │ └── nut_sup_meal_pkg_ingredient (溯源码)
└── quantity ──→ 份数
├── 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 (组配任务)
│ │
@@ -424,20 +406,15 @@ nut_prod_cook_order (烹制单)
│ │──→ nut_mater_base (食材名称)
│ ← 食材清单(含标准用量) │←────────────────────│
│ │ │
│ 3. POST /cook-orders/submit
│ 3. POST /cook-orders/complete
│─────────────────────→│ │
│ │──→ 校验状态=待烹制 │
│ │──→ 匹配净菜订单(餐次过滤) │
│ │──→ 关联internal_supply │
│ │──→ 解析溯源码 │
│ │──→ 完善+完成组配任务 │
│ │──→ 计算生重 │
│ │──→ 更新烹制单=烹制中 │
│ │──→ 更新食材明细 │
│ ← 操作成功 │←──── 事务提交 ──────│
│ │ │
│ 4. POST /cook-orders/finish │
│─────────────────────→│ │
│ │──→ 校验状态=烹制中 │
│ │──→ 保存调料用量 │
│ │──→ 计算生熟比 │
│ │──→ 更新烹制单=已完成 │
+351
View File
@@ -0,0 +1,351 @@
# 配比秤(新设备)— 采样模式 API 文档
> Controller: `NutRatioScaleController`
> 路径前缀: `/neglect/ratio-scale`Nacos 白名单 `/nutrition/neglect/**`,无需 Sa-Token
> 设备上下文通过请求头 `X-DEVICE-CODE` 解析(`TerminalContextHelper`,据此拿到食堂 id
> 日期: 2026-09-10
>
> **序列化规则**:Long 类型字段响应中均为字符串(Jackson `ToStringSerializer`),`BigDecimal` 为普通数字
> **单位约定**
> - 提交采样的熟重 `foodWeight` 单位为 **克 (g)**
> - 食材称量用量 `useWeight` 单位为 **克 (g)**
---
## 业务背景
配比秤「采样」复用 **味养创新(nut_innovation** 的人工创新实验流程,不再直接落 `nut_food` 主表。
### 完整流程(3 步)
```
① 提交采样(设备端) → 落库味养创新实验,状态 = 1 实验中
② 提交评测(味养创新后台)→ 计算营养 + 完善检验信息,状态 = 2 已评测
③ 转化餐品(味养创新后台)→ 走 nut_food 新建餐品流程关联,状态 = 9 已转化
```
### 设备端职责边界
配比秤设备端只负责 **① 提交采样**(称量食材 + 熟重 → 写味养创新实验)。后续的 **② 提交评测**、**③ 转化餐品** 走味养创新已有的后台接口(`/nut/innovation`),不在设备端范围内。
### 采样交互流程
```
搜菜品(food-search
├─ 有目标餐品 → 查菜品构成(food/{foodId}/composition)回显 → 可增删构成
└─ 无目标餐品 → 食材模糊搜索(mater-search)自己添加食材/调料
提交采样(constitute/save)→ 落库味养创新
```
### 食材分类枚举
| 分类 | 名称 | 说明 |
|:----:|------|------|
| 1 | 主材 | 菜品主要食材 |
| 2 | 辅材 | 菜品辅助食材 |
| 3 | 调料 | 油盐酱醋等 |
---
## 接口清单
| 序号 | 接口 | 路径 | 用途 |
|:----:|------|------|------|
| 一 | 搜菜品 | `POST /neglect/ratio-scale/food-search` | 按名称模糊查上架菜品 |
| 二 | 查菜品构成 | `GET /neglect/ratio-scale/food/{foodId}/composition` | 按菜品id查主辅料+调料,回显构成 |
| 三 | 食材模糊搜索 | `POST /neglect/ratio-scale/mater-search` | 采样称量前检索食材 |
| 四 | 提交采样 | `POST /neglect/ratio-scale/constitute/save` | **落库味养创新实验** |
| 五 | 已提交采样列表 | `POST /neglect/ratio-scale/sample-list` | 按日期查已提交采样,默认当天 |
---
## 一、搜菜品
```
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)
"ingredients": [
{
"materId": "1979825467306471454", // 食材id
"materName": "樱桃萝卜", // 食材名称
"useWeight": 300.0, // 用量(g)
"isMain": 1, // 1=主材 / 2=辅材 / 3=调料
"isMainName": "主材"
}
]
}
}
```
### 逻辑说明
- 数据源:`nut_food_composition`(按 `food_id` 查全部构成)
- 食材名称从 `nut_mater_base` **批量反查**(无 N+1
- `foodWeight``nut_food_cook.output_weight` 反查
---
## 三、食材模糊搜索
```
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
}
```
### 逻辑说明
- 数据源:`nut_mater_base`
- 过滤:`canteen_id` = 当前食堂(由 `X-DEVICE-CODE` 解析)
- 关键词模糊匹配 `mater_name``alias`
- 排序:`mater_name ASC`
---
## 四、提交采样(落库味养创新)
```
POST /neglect/ratio-scale/constitute/save
Content-Type: application/json
X-DEVICE-CODE: <设备编码>
```
> ⚠️ **接口变更标注**:原提交接口含 `cookMode`(区分制作/采样),现制作模式已废弃,本接口统一为「提交采样」,入参去掉 `cookMode`、`foodId` 字段。
后厨称量食材 + 熟重后提交,后端落库到 **味养创新实验**`nut_innovation`,人工创新,状态 = 实验中)。
### 请求体
```json
{
"foodName": "清炒西兰花", // 必填 — 菜品名称
"foodWeight": 500, // 必填 — 熟重(g),必须 > 0
"items": [ // 必填 — 食材构成列表,至少1条
{
"materId": 20001, // 必填 — 食材idnut_mater_base.id
"useWeight": 300, // 必填 — 食材称量用量(g),必须 > 0
"isMain": 1 // 必填 — 食材分类: 1=主材 / 2=辅材 / 3=调料
},
{
"materId": 30001,
"useWeight": 50,
"isMain": 3
}
]
}
```
### 响应
```json
{
"code": "00000",
"msg": "操作成功",
"data": null
}
```
### 处理流程
```
1. 校验食材构成非空 + materId 非空且唯一
2. 反查食材名称(nut_mater_base + 一级分类名称(nut_mater_class
3. 构建味养创新实验 DTO
- foodName → food_name
- foodWeight → food_weight(熟重)
- items → 食材构成(mater_id + mater_name + mater_cat + amount_g + is_main
- canteenId → 从 X-DEVICE-CODE 解析
- startDate → 回填当天(实验开始日期)
- source / deviceCode → 来源标识(2) + 设备编码
- innovGoal → 默认值「配比秤采样」
4. 调用味养创新 manualAdd,落库 nut_innovationstatus=1 实验中)+ nut_innovation_ing(食材构成)
5. 自动初始化营养:按食材构成 + 熟重计算每100g熟重营养,写入草稿评测事件 nut_innovation_evalstatus=0+ 营养维度 nut_innovation_eval_nutri7 项:热量/蛋白/碳水/脂肪/维C/膳食纤维/钠,mineral 留空)
```
> 注:设备端不传 `foodCategory`(餐品分类),落库为空,后期在味养创新后台维护;`innovGoal`(创新目标)后端填默认值「配比秤采样」,后续可改。
### 异常场景
| 场景 | 错误信息 |
|------|---------|
| 食材构成列表为空 | `请完善菜品构成信息` |
| 食材id为空 | `菜品食材不能为空` |
| 食材id重复 | `菜品食材不能重复,重复食材id:xxx` |
| 熟重/用量 ≤ 0 | 参数校验:`熟重必须大于0` / `食材用量必须大于0` |
### 涉及数据表
| 表名 | 操作 | 说明 |
|------|:--:|------|
| `nut_innovation` | 新增 | 味养创新实验(status=1 实验中,含熟重 food_weight |
| `nut_innovation_ing` | 新增 | 食材构成(mater_id + mater_name + mater_cat + amount_g + is_main |
| `nut_innovation_eval` | 新增 | 草稿评测事件(status=0,采样时初始化) |
| `nut_innovation_eval_nutri` | 新增 | 营养维度(7 项自动计算值,mineral 留空) |
| `nut_mater_base` | 查询 | 反查食材名称 + 营养数据(计算营养) |
| `nut_mater_class` | 查询 | 反查一级分类名称 |
---
## 五、已提交采样列表
```
POST /neglect/ratio-scale/sample-list
Content-Type: application/json
X-DEVICE-CODE: <设备编码>
```
查询本食堂已提交的采样记录(味养创新实验 `source=2`),分页返回、按提交时间倒序,供硬件端回看。
### 请求体
```json
{
"pageNum": 1, // 必填 — 页码
"pageSize": 20 // 必填 — 每页条数
}
```
### 响应
```json
{
"code": "00000",
"msg": "操作成功",
"data": [
{
"innovId": "2097486806812893186", // 味养创新实验id
"innovNo": "INN-H-2026-001", // 实验编号
"foodName": "清炒西兰花", // 餐品名称
"foodWeight": 500.0, // 熟重(g)
"status": 1, // 状态: 1实验中/2已评测/9已转化
"statusName": "实验中", // 状态中文
"createTime": "2026-09-11 10:30:00" // 提交时间
}
],
"total": 1
}
```
### 逻辑说明
- 数据源:`nut_innovation`
- 过滤:`canteen_id` = 当前食堂 + `source` = 2(配比秤采样,后台手动为 1)
- 排序:`create_time DESC`(查所有,不分日期)
---
## 数据链路图(提交采样 → 味养创新)
```
nut_mater_base (食材库)
│ 称量 mater_id + use_weight(g) + 熟重 food_weight(g)
POST /constitute/save
├── 生成 nut_innovation (味养创新实验,status=1 实验中,含 food_weight)
├── 生成 nut_innovation_ing (食材构成:mater_id + mater_name + mater_cat + amount_g + is_main)
└── 自动算营养 → nut_innovation_eval(草稿) + nut_innovation_eval_nutri(7项)
后续(味养创新后台,非设备端):
├── 提交评测 → 复核营养 + 补味道/口感/色泽,status=2 已评测
└── 转化餐品 → nut_food(新建餐品流程),convert_food_id 关联,status=9 已转化
```
@@ -0,0 +1,116 @@
# 配比秤烹饪时长 - 设备端对接文档
> 本次变更:配比秤新增「烹饪时长」采集与计算能力。设备端只需**传烹饪开始时间**和**调料放置时间**,时长由后端自动计算落库,设备端不需要自己算。
>
> 部署依赖:数据库迁移 `V21__nut_innovation_cook_duration.sql` 需先于服务发布执行。
---
## 通用说明
- 时间格式统一为 `yyyy-MM-dd HH:mm:ss`
- 时长单位:**分钟**,由后端计算,规则:`时长 = 接口调用时间 - 烹饪开始时间`,**向上取整,正数至少 1 分钟**(如 90 秒 → 2 分钟,30 秒 → 1 分钟)
- 烹饪开始时间为空、或晚于当前时间(无效)时,后端**跳过时长计算**,接口正常成功
---
## 1. 提交采样(新增入参字段)
**POST** `/nutrition/neglect/ratio-scale/constitute/save`
### 请求参数(仅列出新增字段,其余字段不变)
| 字段 | 类型 | 必填 | 说明 |
|------|------|:----:|------|
| cookStart | string | 建议 | **新增**。烹饪开始时间,用于与提交时间计算烹饪时长(分钟) |
| items[].putTime | string | - | **新增**。调料放置时间,仅调料项(`isMain=3`)传,主材/辅材不传 |
### 完整请求示例
```json
{
"foodName": "低钠宫保鸡丁",
"foodWeight": 1250.5,
"cookStart": "2026-09-21 10:30:00",
"items": [
{ "materId": 1001, "useWeight": 500, "isMain": 1 },
{ "materId": 1002, "useWeight": 200, "isMain": 2 },
{ "materId": 1003, "useWeight": 15, "isMain": 3, "putTime": "2026-09-21 10:32:10" },
{ "materId": 1004, "useWeight": 8, "isMain": 3, "putTime": "2026-09-21 10:35:40" }
]
}
```
### 后端行为
- 烹饪开始时间落库 `nut_innovation.cook_start`,时长落库 `nut_innovation.cook_duration`,调料放置时间落库 `nut_innovation_ing.put_time`
- 响应结构不变(`Result<Void>`
---
## 2. 烹饪完成(入参字段无变化,传值要求强化)
**POST** `/nutrition/neglect/ratio-scale/cook-orders/complete`
### 相关字段
| 字段 | 类型 | 必填 | 说明 |
|------|------|:----:|------|
| cookOrderId | long | ✓ | 烹制单 id(原有) |
| cookStart | string | **强烈建议** | 烹饪开始时间(字段原有)。**本次开始烹饪时务必回传**,否则不计算时长 |
| seasonings[].putTime | string | - | 调料放置时间(字段原有),继续按原逻辑传 |
### 后端行为(新增)
- 每次完成按 `本次 cookStart → 接口调用时间` 计算时长,**更新菜品烹饪工艺表 `nut_food_cook.cook_duration`**
- **多次烹饪时长不累计、各算各的**:同一烹制单多次提交时,每次都用本次的时长**覆盖**菜品烹饪时长
- 同时写一条餐品操作记录(后台可见):操作标题「配比秤烹饪餐品计算」,记录时长从 X 分钟更新为 Y 分钟
- `cookStart` 为空时跳过以上更新,其余原有逻辑(流水、生熟比、累加)不受影响
---
## 3. 已提交采样列表(响应新增字段)
**POST** `/nutrition/neglect/ratio-scale/sample-list`
### 响应 `data.list[]` 新增字段
| 字段 | 类型 | 说明 |
|------|------|------|
| cookStart | string | **新增**。烹饪开始时间;提交时未传则为 null |
| cookDuration | int | **新增**。烹饪时长(分钟);提交时未传 cookStart 则为 null |
### 响应示例
```json
{
"code": "00000",
"msg": "操作成功",
"data": {
"list": [
{
"innovId": 1930123456789,
"innovNo": "INN-H-2026-041",
"foodName": "低钠宫保鸡丁",
"foodWeight": 1250.5,
"cookStart": "2026-09-21 10:30:00",
"cookDuration": 12,
"status": 1,
"statusName": "实验中",
"createTime": "2026-09-21 10:42:03"
}
],
"total": 1
}
}
```
---
## 设备端改动清单
| 接口 | 改动 |
|------|------|
| constitute/save | 请求新增 `cookStart` + 调料项 `putTime`(开始烹饪时记录时间,放调料时记录时间) |
| cook-orders/complete | 字段无变化,确保每次提交回传 `cookStart``seasonings[].putTime` 继续传 |
| sample-list | 响应新增 `cookDuration`,列表可展示「烹饪时长(分钟)」 |