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