优化入库单位逻辑,识别阈值设置为0.8

This commit is contained in:
2025-11-04 12:11:51 +08:00
parent 324986fb10
commit 069306d48b
9 changed files with 154 additions and 51 deletions
@@ -209,12 +209,14 @@ abstract class GoodsListActivity : ComponentActivity() {
)
Timber.d("${this.javaClass.simpleName}-searchFood-裁剪bitmap保存文件路径:${file?.absolutePath}")
val foodNameList = FoodModule.queryFood(newBmp)
viewModel.recognizeGoodsList(foodNameList) { goodsList ->
handleGoodsResult(
goodsList = if (goodsList.size == foodNameList.size) goodsList else mutableListOf(),
file = file,
name = foodNameList.joinToString(",")
)
runOnUiThread {
viewModel.recognizeGoodsList(foodNameList) { goodsList ->
handleGoodsResult(
goodsList = if (goodsList.size == foodNameList.size) goodsList else mutableListOf(),
file = file,
name = foodNameList.joinToString(",")
)
}
}
// searchMultipleGoods(foodNameList) { goodsList ->
// handleGoodsResult(
@@ -108,7 +108,7 @@ class AddGoodsDialog(
binding.flProcurementUnit,
textView = binding.tvProcurementUnit,
list = GlobalData.unitTypeList,
height = 213.dp
height = 2*71.dp
)
// showDropDownList(
// binding.flGoodsType,
@@ -123,7 +123,8 @@ class AddGoodsDialog(
showDropDownList(
dropdownView = binding.flWarehouseUnit,
textView = binding.tvWarehouseUnit,
list = GlobalData.unitTypeList
list = GlobalData.unitTypeList,
height = 3*71.dp
) {
binding.tvSelectUseUnit.text = it.value
binding.tvSelectProcurementUnit.text = it.value
@@ -15,7 +15,7 @@ import com.sw.inbound.utils.ext.hideKeyboard
abstract class BaseDialog(
context: Context,
var defWidth: Int = 1500.dp,
var defHeight: Int = 900.dp
var defHeight: Int = 800.dp
) : Dialog(context, R.style.DialogTheme) {
override fun onCreate(savedInstanceState: Bundle?) {
@@ -13,8 +13,6 @@ import androidx.core.widget.addTextChangedListener
import coil.load
import com.shuwei.intelligent.shelves.utils.ext.appendText
import com.shuwei.intelligent.shelves.utils.ext.buildSpannableString
import com.sw.inbound.GlobalData
import com.sw.inbound.R
import com.sw.inbound.activity.GoodsListActivity
import com.sw.inbound.databinding.DialogGoodsStoreBinding
import com.sw.inbound.ext.toFormattedString
@@ -25,6 +23,7 @@ import com.sw.inbound.sdk.SensorScaleUtils
import com.sw.inbound.utils.ext.dp
import com.sw.inbound.utils.ext.toast
import kotlin.Int
import kotlin.math.min
class GoodsStoreDialog(
context: Context,
@@ -51,6 +50,28 @@ class GoodsStoreDialog(
activity?.readWeightInfo { weight ->
this.realWeight = weight
binding.tvTotalWeight.text = getSpannable(weight)
val id = binding.tvProcurementUnit.tag.toString()
val count = getUnitVo(id)
if (count == 0.toDouble()) {
return@readWeightInfo
}
val currentCount = binding.etProcurementCount.text.toString().trim()
if (currentCount == "$count") {
return@readWeightInfo
}
binding.etProcurementCount.let {
it.setText("$count")
it.setSelection(it.length())
}
}
if (goods.unitVoList.isNullOrEmpty()) {
activity?.toast("未匹配到合适的入库单位")
dismiss()
return
}
dropdownList.clear()
goods.unitVoList!!.forEach {
dropdownList.add(DictType(id = it.businessUnitId, value = it.purchaseUnitName))
}
binding.etGoodsName.run {
setText(goods.goodsName)
@@ -69,18 +90,32 @@ class GoodsStoreDialog(
// }
binding.flUnitDropdown.setOnClickListener { v ->
if (dropdownPopup == null) {
dropdownList.clear()
dropdownList.addAll(GlobalData.unitTypeList)
dropdownPopup = DropdownPopup(
context = context,
list = dropdownList,
popWidth = 428.dp
) {
popWidth = 428.dp,
popHeight = min(dropdownList.size, 4) * 71.dp
) { dictType ->
binding.tvProcurementUnit.run {
text = it.value
tag = it.id
text = dictType.value
tag = dictType.id
}
binding.tvCountUnit.text = dictType.value
val first = goods.unitVoList!!.first { it.businessUnitId == dictType.id }
val stringBuilder = StringBuilder()
.append("1").append(dictType.value).append("=").append(first.purchaseValue!!.toInt().toString()).append(goods.kcUnitName)
.append("")
.append("1").append(goods.kcUnitName).append("=").append(first.consumeValue).append("")
binding.tvUnitCalculate.text = stringBuilder.toString()
val count = getUnitVo(dictType.id!!)
if (count == 0.toDouble()) {
//context.toast("入库数量不能为0")
return@DropdownPopup
}
binding.etProcurementCount.let {
it.setText("$count")
it.setSelection(it.length())
}
binding.tvCountUnit.text = it.value
}
}
dropdownPopup?.showAsDropDown(v)
@@ -96,7 +131,11 @@ class GoodsStoreDialog(
//}
addPriceInputListener(binding.etProcurementAmount) {
val countText = binding.etProcurementCount.text.trim().toString()
val count = if (countText.isNotBlank()) countText.toInt() else 0
val count = if (countText.isNotBlank()) countText.toDouble() else 0.toDouble()
if (count == 0.toDouble()) {
//context.toast("入库数量不能为0")
return@addPriceInputListener
}
val price = (it / count).toFormattedString(2)
binding.tvProcurementPrice.text = price
}
@@ -110,8 +149,12 @@ class GoodsStoreDialog(
if (amountText.isEmpty()) {
return@addTextChangedListener
}
val input = it ?: ""
val count = if (input.isNotBlank()) input.toString().toInt() else 0
val input = it?.toString() ?: ""
val count = if (input.isNotBlank()) input.toDouble() else 0.toDouble()
if (count == 0.toDouble()) {
//context.toast("入库数量不能为0")
return@addTextChangedListener
}
val amount = amountText.toDouble()
val price = amount / count
binding.tvProcurementPrice.text = price.toFormattedString(2)
@@ -189,9 +232,21 @@ class GoodsStoreDialog(
context.toast("物品重量需大于0")
return
}
val count = countText.toDoubleOrNull()
val price = priceText.toDoubleOrNull()
val count = countText.toDoubleOrNull() ?: 0.toDouble()
if (count == 0.toDouble()) {
context.toast("入库数量不能为0")
return
}
val price = priceText.toDoubleOrNull() ?: 0.toDouble()
if (price == 0.toDouble()) {
context.toast("入库单价不能为0")
return
}
val totalPrice = amountText.toDoubleOrNull()
if (totalPrice == 0.toDouble()) {
context.toast("入库金额不能为0")
return
}
confirmBlock(
GoodsInfo(
goodId = goods.id,
@@ -214,4 +269,10 @@ class GoodsStoreDialog(
dismiss()
}
private fun getUnitVo(id: String): Double {
val first = goods.unitVoList!!.first { it.businessUnitId == id }
val count = first.getPurchaseUnitValue(this.realWeight)
return count
}
}
@@ -3,6 +3,8 @@ package com.sw.inbound.model.response
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.sw.inbound.utils.ext.roundedDecimalPlace
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize
/**
@@ -114,7 +116,31 @@ data class SearchGoodsInfo(
/**
* 消耗转换值
*/
val purchaseValue: Int? = 0,
) : Parcelable
val purchaseValue: Double? = 0.0,
) : Parcelable {
/**
* 购买单位数值
*/
fun getPurchaseUnitValue(value: Int): Double {
val defZero = 0.toDouble()
val num = when (purchaseUnitName) {
"千克", "公斤" -> 2
"" -> 1
else -> 0
}
if (purchaseValue == null || purchaseValue == defZero || consumeValue.isNullOrBlank()) {
return defZero.roundedDecimalPlace(num)
}
var consumeValueDouble: Double
try {
consumeValueDouble = consumeValue.toDouble()
} catch (e: Exception) {
e.printStackTrace()
return defZero.roundedDecimalPlace(num)
}
return (value / purchaseValue / consumeValueDouble).roundedDecimalPlace(num)
}
}
}
}
@@ -17,8 +17,8 @@ class RequestInterceptor : Interceptor {
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.header("deviceId", GlobalData.deviceId)
.header("X-DEVICE-CODE", GlobalData.deviceId)
// .header("X-DEVICE-CODE", "bcf396ed-78f6-3864-9837-7c37c5b2ec41")
// .header("X-DEVICE-CODE", GlobalData.deviceId)
.header("X-DEVICE-CODE", "bcf396ed-78f6-3864-9837-7c37c5b2ec41")
.header("x-access-token", GlobalData.appToken)
.header("authorization", "57ee87183f2a4fa59683ec9ef41c8f5d")
// .header("Authorization", "Bearer ${getToken()}")
@@ -88,7 +88,7 @@ object FoodModule {
//查询比较分数
// val tempList = query.findWithScores().sortedBy { it.score }.map { "${it.get().name}|${it.get().foodIdx}|${it.score}" }
val map = mutableMapOf<String, Int>()
query.findIdsWithScores().forEach {
query.findIdsWithScores().filter { it.score < 0.2 }.forEach {
val food = box.get(it.id)
//FoodQueryResult(id = it.id, name = food.name, foodIdx = food.foodIdx, score = it.score)
food.name?.let { key ->