优化入库单位逻辑,识别阈值设置为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,6 +209,7 @@ abstract class GoodsListActivity : ComponentActivity() {
) )
Timber.d("${this.javaClass.simpleName}-searchFood-裁剪bitmap保存文件路径:${file?.absolutePath}") Timber.d("${this.javaClass.simpleName}-searchFood-裁剪bitmap保存文件路径:${file?.absolutePath}")
val foodNameList = FoodModule.queryFood(newBmp) val foodNameList = FoodModule.queryFood(newBmp)
runOnUiThread {
viewModel.recognizeGoodsList(foodNameList) { goodsList -> viewModel.recognizeGoodsList(foodNameList) { goodsList ->
handleGoodsResult( handleGoodsResult(
goodsList = if (goodsList.size == foodNameList.size) goodsList else mutableListOf(), goodsList = if (goodsList.size == foodNameList.size) goodsList else mutableListOf(),
@@ -216,6 +217,7 @@ abstract class GoodsListActivity : ComponentActivity() {
name = foodNameList.joinToString(",") name = foodNameList.joinToString(",")
) )
} }
}
// searchMultipleGoods(foodNameList) { goodsList -> // searchMultipleGoods(foodNameList) { goodsList ->
// handleGoodsResult( // handleGoodsResult(
// if (goodsList.size == foodNameList.size) goodsList // if (goodsList.size == foodNameList.size) goodsList
@@ -108,7 +108,7 @@ class AddGoodsDialog(
binding.flProcurementUnit, binding.flProcurementUnit,
textView = binding.tvProcurementUnit, textView = binding.tvProcurementUnit,
list = GlobalData.unitTypeList, list = GlobalData.unitTypeList,
height = 213.dp height = 2*71.dp
) )
// showDropDownList( // showDropDownList(
// binding.flGoodsType, // binding.flGoodsType,
@@ -123,7 +123,8 @@ class AddGoodsDialog(
showDropDownList( showDropDownList(
dropdownView = binding.flWarehouseUnit, dropdownView = binding.flWarehouseUnit,
textView = binding.tvWarehouseUnit, textView = binding.tvWarehouseUnit,
list = GlobalData.unitTypeList list = GlobalData.unitTypeList,
height = 3*71.dp
) { ) {
binding.tvSelectUseUnit.text = it.value binding.tvSelectUseUnit.text = it.value
binding.tvSelectProcurementUnit.text = it.value binding.tvSelectProcurementUnit.text = it.value
@@ -15,7 +15,7 @@ import com.sw.inbound.utils.ext.hideKeyboard
abstract class BaseDialog( abstract class BaseDialog(
context: Context, context: Context,
var defWidth: Int = 1500.dp, var defWidth: Int = 1500.dp,
var defHeight: Int = 900.dp var defHeight: Int = 800.dp
) : Dialog(context, R.style.DialogTheme) { ) : Dialog(context, R.style.DialogTheme) {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@@ -13,8 +13,6 @@ import androidx.core.widget.addTextChangedListener
import coil.load import coil.load
import com.shuwei.intelligent.shelves.utils.ext.appendText import com.shuwei.intelligent.shelves.utils.ext.appendText
import com.shuwei.intelligent.shelves.utils.ext.buildSpannableString 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.activity.GoodsListActivity
import com.sw.inbound.databinding.DialogGoodsStoreBinding import com.sw.inbound.databinding.DialogGoodsStoreBinding
import com.sw.inbound.ext.toFormattedString 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.dp
import com.sw.inbound.utils.ext.toast import com.sw.inbound.utils.ext.toast
import kotlin.Int import kotlin.Int
import kotlin.math.min
class GoodsStoreDialog( class GoodsStoreDialog(
context: Context, context: Context,
@@ -51,6 +50,28 @@ class GoodsStoreDialog(
activity?.readWeightInfo { weight -> activity?.readWeightInfo { weight ->
this.realWeight = weight this.realWeight = weight
binding.tvTotalWeight.text = getSpannable(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 { binding.etGoodsName.run {
setText(goods.goodsName) setText(goods.goodsName)
@@ -69,18 +90,32 @@ class GoodsStoreDialog(
// } // }
binding.flUnitDropdown.setOnClickListener { v -> binding.flUnitDropdown.setOnClickListener { v ->
if (dropdownPopup == null) { if (dropdownPopup == null) {
dropdownList.clear()
dropdownList.addAll(GlobalData.unitTypeList)
dropdownPopup = DropdownPopup( dropdownPopup = DropdownPopup(
context = context, context = context,
list = dropdownList, list = dropdownList,
popWidth = 428.dp popWidth = 428.dp,
) { popHeight = min(dropdownList.size, 4) * 71.dp
) { dictType ->
binding.tvProcurementUnit.run { binding.tvProcurementUnit.run {
text = it.value text = dictType.value
tag = it.id 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) dropdownPopup?.showAsDropDown(v)
@@ -96,7 +131,11 @@ class GoodsStoreDialog(
//} //}
addPriceInputListener(binding.etProcurementAmount) { addPriceInputListener(binding.etProcurementAmount) {
val countText = binding.etProcurementCount.text.trim().toString() 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) val price = (it / count).toFormattedString(2)
binding.tvProcurementPrice.text = price binding.tvProcurementPrice.text = price
} }
@@ -110,8 +149,12 @@ class GoodsStoreDialog(
if (amountText.isEmpty()) { if (amountText.isEmpty()) {
return@addTextChangedListener return@addTextChangedListener
} }
val input = it ?: "" val input = it?.toString() ?: ""
val count = if (input.isNotBlank()) input.toString().toInt() else 0 val count = if (input.isNotBlank()) input.toDouble() else 0.toDouble()
if (count == 0.toDouble()) {
//context.toast("入库数量不能为0")
return@addTextChangedListener
}
val amount = amountText.toDouble() val amount = amountText.toDouble()
val price = amount / count val price = amount / count
binding.tvProcurementPrice.text = price.toFormattedString(2) binding.tvProcurementPrice.text = price.toFormattedString(2)
@@ -189,9 +232,21 @@ class GoodsStoreDialog(
context.toast("物品重量需大于0") context.toast("物品重量需大于0")
return return
} }
val count = countText.toDoubleOrNull() val count = countText.toDoubleOrNull() ?: 0.toDouble()
val price = priceText.toDoubleOrNull() 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() val totalPrice = amountText.toDoubleOrNull()
if (totalPrice == 0.toDouble()) {
context.toast("入库金额不能为0")
return
}
confirmBlock( confirmBlock(
GoodsInfo( GoodsInfo(
goodId = goods.id, goodId = goods.id,
@@ -214,4 +269,10 @@ class GoodsStoreDialog(
dismiss() 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 android.os.Parcelable
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
import com.sw.inbound.utils.ext.roundedDecimalPlace
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.Parcelize import kotlinx.parcelize.Parcelize
/** /**
@@ -114,7 +116,31 @@ data class SearchGoodsInfo(
/** /**
* 消耗转换值 * 消耗转换值
*/ */
val purchaseValue: Int? = 0, val purchaseValue: Double? = 0.0,
) : Parcelable ) : 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("Content-Type", "application/json")
.header("Accept", "application/json") .header("Accept", "application/json")
.header("deviceId", GlobalData.deviceId) .header("deviceId", GlobalData.deviceId)
.header("X-DEVICE-CODE", GlobalData.deviceId) // .header("X-DEVICE-CODE", GlobalData.deviceId)
// .header("X-DEVICE-CODE", "bcf396ed-78f6-3864-9837-7c37c5b2ec41") .header("X-DEVICE-CODE", "bcf396ed-78f6-3864-9837-7c37c5b2ec41")
.header("x-access-token", GlobalData.appToken) .header("x-access-token", GlobalData.appToken)
.header("authorization", "57ee87183f2a4fa59683ec9ef41c8f5d") .header("authorization", "57ee87183f2a4fa59683ec9ef41c8f5d")
// .header("Authorization", "Bearer ${getToken()}") // .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 tempList = query.findWithScores().sortedBy { it.score }.map { "${it.get().name}|${it.get().foodIdx}|${it.score}" }
val map = mutableMapOf<String, Int>() val map = mutableMapOf<String, Int>()
query.findIdsWithScores().forEach { query.findIdsWithScores().filter { it.score < 0.2 }.forEach {
val food = box.get(it.id) val food = box.get(it.id)
//FoodQueryResult(id = it.id, name = food.name, foodIdx = food.foodIdx, score = it.score) //FoodQueryResult(id = it.id, name = food.name, foodIdx = food.foodIdx, score = it.score)
food.name?.let { key -> food.name?.let { key ->
+8 -6
View File
@@ -11,7 +11,8 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="120dp" android:layout_height="0dp"
android:layout_weight="11"
android:gravity="center" android:gravity="center"
android:text="新增物品" android:text="新增物品"
android:textColor="#ff141428" android:textColor="#ff141428"
@@ -27,7 +28,7 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="62"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingHorizontal="40dp"> android:paddingHorizontal="40dp">
@@ -241,7 +242,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp"> android:layout_marginTop="25dp">
<TextView <TextView
android:layout_width="432dp" android:layout_width="432dp"
@@ -334,7 +335,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp"> android:layout_marginTop="25dp">
<TextView <TextView
android:layout_width="432dp" android:layout_width="432dp"
@@ -449,7 +450,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="30dp" android:layout_marginTop="25dp"
android:text="采购单位" android:text="采购单位"
android:textColor="#ff141428" android:textColor="#ff141428"
android:textSize="24sp" android:textSize="24sp"
@@ -587,7 +588,8 @@
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="160dp" android:layout_height="0dp"
android:layout_weight="15"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingHorizontal="50dp"> android:paddingHorizontal="50dp">
+28 -17
View File
@@ -11,7 +11,8 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="142dp" android:layout_height="0dp"
android:layout_weight="14"
android:gravity="center" android:gravity="center"
android:text="物品入库" android:text="物品入库"
android:textColor="#ff141428" android:textColor="#ff141428"
@@ -27,7 +28,7 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="60"
android:orientation="horizontal"> android:orientation="horizontal">
<androidx.constraintlayout.widget.Guideline <androidx.constraintlayout.widget.Guideline
@@ -46,7 +47,7 @@
app:layout_constraintStart_toStartOf="parent"> app:layout_constraintStart_toStartOf="parent">
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="580dp"
android:layout_height="70dp" android:layout_height="70dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
@@ -76,7 +77,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="580dp"
android:layout_height="70dp" android:layout_height="70dp"
android:layout_marginTop="30dp" android:layout_marginTop="30dp"
android:gravity="center_vertical" android:gravity="center_vertical"
@@ -128,14 +129,23 @@
android:layout_height="70dp" android:layout_height="70dp"
android:layout_marginStart="10dp" android:layout_marginStart="10dp"
android:src="@mipmap/ic_add_unit" android:src="@mipmap/ic_add_unit"
tools:ignore="ContentDescription" android:visibility="gone"
android:visibility="gone"/> tools:ignore="ContentDescription" />
</LinearLayout> </LinearLayout>
<TextView
android:id="@+id/tvUnitCalculate"
android:layout_width="580dp"
android:layout_height="30dp"
android:gravity="end|center_vertical"
tools:text="1袋=3斤"
android:textColor="#ff141428"
android:textSize="16sp" />
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="580dp"
android:layout_height="70dp" android:layout_height="70dp"
android:layout_marginTop="30dp" android:layout_marginTop="0dp"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal">
@@ -160,8 +170,8 @@
android:layout_marginEnd="70dp" android:layout_marginEnd="70dp"
android:background="#00000000" android:background="#00000000"
android:hint="请录入" android:hint="请录入"
android:maxLines="1"
android:inputType="number" android:inputType="number"
android:maxLines="1"
android:paddingHorizontal="24dp" android:paddingHorizontal="24dp"
android:textColor="#ff141428" android:textColor="#ff141428"
android:textColorHint="#FF96A0AA" android:textColorHint="#FF96A0AA"
@@ -183,7 +193,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="580dp"
android:layout_height="70dp" android:layout_height="70dp"
android:layout_marginTop="30dp" android:layout_marginTop="30dp"
android:gravity="center_vertical" android:gravity="center_vertical"
@@ -209,10 +219,10 @@
android:layout_height="70dp" android:layout_height="70dp"
android:layout_marginEnd="70dp" android:layout_marginEnd="70dp"
android:background="#00000000" android:background="#00000000"
android:hint="由入库数量和金额计算生成"
android:gravity="center_vertical"
android:maxLines="1"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center_vertical"
android:hint="由入库数量和金额计算生成"
android:maxLines="1"
android:paddingHorizontal="24dp" android:paddingHorizontal="24dp"
android:textColor="#ff141428" android:textColor="#ff141428"
android:textColorHint="#FF96A0AA" android:textColorHint="#FF96A0AA"
@@ -233,7 +243,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="580dp"
android:layout_height="70dp" android:layout_height="70dp"
android:layout_marginTop="30dp" android:layout_marginTop="30dp"
android:gravity="center_vertical" android:gravity="center_vertical"
@@ -260,8 +270,8 @@
android:layout_marginEnd="70dp" android:layout_marginEnd="70dp"
android:background="#00000000" android:background="#00000000"
android:hint="请录入" android:hint="请录入"
android:maxLines="1"
android:inputType="numberDecimal" android:inputType="numberDecimal"
android:maxLines="1"
android:paddingHorizontal="24dp" android:paddingHorizontal="24dp"
android:textColor="#ff141428" android:textColor="#ff141428"
android:textColorHint="#FF96A0AA" android:textColorHint="#FF96A0AA"
@@ -302,7 +312,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:scaleType="fitCenter" android:scaleType="fitCenter"
tools:ignore="ContentDescription" tools:ignore="ContentDescription"
tools:src="@mipmap/ic_launcher"/> tools:src="@mipmap/ic_launcher" />
</FrameLayout> </FrameLayout>
@@ -357,7 +367,8 @@
<LinearLayout <LinearLayout
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="160dp" android:layout_height="0dp"
android:layout_weight="16"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal" android:orientation="horizontal"
android:paddingHorizontal="50dp"> android:paddingHorizontal="50dp">