refactor(home): 重构货架重量数据模型和显示逻辑

- 将实际重量计算统一到weight字段,移除actualQty和totalWeightG字段
- 修改HomeV2Activity中的重量数据处理逻辑,统一转换为千克单位
- 更新ShelfV2Activity中重量显示格式,优化单位转换逻辑
- 调整ShelfV2Adapter中重量显示逻辑,统一使用weight字段进行展示
- 在日志记录中增加温度信息输出
- 移除废弃的条件判断逻辑,简化代码结构
This commit is contained in:
mazengfei
2026-06-04 17:28:23 +08:00
parent 694e20023a
commit 4f1a9dd0a1
4 changed files with 27 additions and 20 deletions
@@ -90,18 +90,20 @@ class HomeV2Activity : BaseActivity() {
it.slotNo?.filter { c -> c.isDigit() }?.toIntOrNull() == shelfNo
}
val model = list.getOrNull(pos)?:return@forEach
if (model.itemType == 1) {
model.actualQty = (weight.grams / 1000.0).toBigDecimal()
} else {
model.totalWeightG = weight.grams.toBigDecimal()
}
model.weight = (1.0 * weight.grams / 1000.0).toBigDecimal()
// if (model.itemType == 1) {
// model.actualQty = (weight.grams / 1000.0).toBigDecimal()
// } else {
// model.totalWeightG = weight.grams.toBigDecimal()
// }
shelfAdapter.notifyItemChanged(pos)
log("getWeightInfo: slotNo=${model.slotNo},realWeight=${weight.grams}, item:${model.toJsonString()}")
log("getWeightInfo: slotNo=${model.slotNo}, realWeight=${weight.grams}, temp=${data.temperature}, item:${model.toJsonString()}")
EventBus.getDefault().post(SendWeightEvent(shelfNo, weight.grams))
// }
}
}
.onTempReport { _ ->
.onTempReport { frame ->
log("onTempReport: $frame")
updateLeftStatus(deviceName)
}
.onLog { message -> log(message) }
@@ -106,10 +106,10 @@ class ShelfV2Activity : BaseActivity() {
recordItem?.let {
binding.tvShelfName.text = it.slotNo
binding.tvFoodName.text = if (it.itemName.isNullOrBlank()) "-" else it.itemName
val weightG = it.totalWeightG?.toInt() ?: 0
realWeight = weightG
binding.tvFoodWeight.text = if (weightG < 1000) "${weightG}"
else "%.3f千克".format(weightG / 1000.0)
val weightG = it.weight?.toDouble() ?: 0.0
realWeight = (weightG * 1000.0).toInt()
binding.tvFoodWeight.text = if (weightG >= 1.0) "%.3f千克".format(weightG)
else "${realWeight}"
startTime = System.currentTimeMillis()
}
@@ -187,8 +187,9 @@ class ShelfV2Activity : BaseActivity() {
it.itemName = ""
//4-空置
it.slotStatus = 4
it.totalWeightG = null
it.actualQty = null
// it.totalWeightG = null
// it.actualQty = null
it.weight = null
it.itemType = 0
it.traceCode = null
it.storeTime = null
@@ -35,13 +35,15 @@ class ShelfV2Adapter(list: MutableList<ShelfModelV2>) :
if (item.slotStatus.toInt() == 2) binding.ivStaleFood.visible()
else binding.ivStaleFood.gone()
// 重量:itemType=2 用 totalWeightG(g)itemType=1 用 actualQty×1000(g)
val weightG = if (item.itemType == 1) (item.actualQty?.toDouble() ?: 0.0) * 1000.0
else item.totalWeightG?.toDouble() ?: 0.0
// // 重量:itemType=2 用 totalWeightG(g)itemType=1 用 actualQty×1000(g)
// val weightG = if (item.itemType == 1) (item.actualQty?.toDouble() ?: 0.0) * 1000.0
// else item.totalWeightG?.toDouble() ?: 0.0
val weightG = item.weight?.toDouble() ?: 0.0
binding.tvFoodWeight.run {
setTextColor(getColor(R.color.food_weight_orange))
text = if (abs(weightG) < 1000) "${weightG.toInt()}"
else "%.3f千克".format(weightG / 1000.0)
text = if (abs(weightG) >= 1.0) "%.3f千克".format(weightG)
else "${(weightG * 1000.0).toInt()}"
}
val isBlank = item.itemName.isNullOrBlank()
@@ -26,7 +26,7 @@ data class ShelfModelV2(
/** 订单量 kgitemType=1 */
var orderQty: BigDecimal? = null,
/** 实收量 kgitemType=1 */
var actualQty: BigDecimal? = null,
// var actualQty: BigDecimal? = null,
/** 差异量 kgitemType=1,可为负) */
var diffQty: BigDecimal? = null,
/** 规格(itemType=2,如:标准份) */
@@ -35,7 +35,9 @@ data class ShelfModelV2(
/** 包数(itemType=2 */
var pkgCount: Int? = null,
/** 总重量 gitemType=2 */
var totalWeightG: BigDecimal? = null,
// var totalWeightG: BigDecimal? = null,
/** 统一重量字段,单位千克 */
var weight: BigDecimal? = null,
/** 验收结果:1-合格 / 2-轻微差异 / 3-不合格 / 4-待验 */
var checkResult: Short? = null,
/** 存储温度(℃) */