Author SHA1 Message Date
mazengfei 23149aa131 隐藏cvImageBg 2026-06-01 09:54:26 +08:00
mazengfei 1092a7c43d 接口报错显示具体信息 2026-05-25 10:33:33 +08:00
mazengfei 0c0aba2aeb 接口报错显示具体信息 2026-05-20 14:21:03 +08:00
mazengfei e81df4f55c 优化 2026-05-13 09:55:11 +08:00
lvmeng 07e0a1996f 入库单数据提交入库新增采购单号字段purCode 2026-05-11 18:20:35 +08:00
lvmeng 79f58a36e3 fix(activity): 修复拿走物品后识别弹窗未自动关闭的问题
- 将关闭阈值从 weight < 10 调整为 weight < 20,覆盖轻微零点漂移
- 将 size == 1 判断改为 none { isShowing && it != goodsRecognizeDialog },避免 DialogManager 中存在幽灵条目时导致关闭逻辑失效
- GoodsStoreDialog:无论 funcType 值,均拍照上传图片以增加样本数据
- BaseViewModel:recognizeGoodsList 增加异常捕获,异常时回调空列表
2026-05-09 15:44:05 +08:00
6 changed files with 91 additions and 69 deletions
@@ -78,6 +78,7 @@ abstract class GoodsListActivity : BaseActivity() {
private const val TAG = "GoodsListActivity"
public const val ID = "id"
public const val SUPPLIER_ID = "supplierId"
public const val PUR_CODE = "purCode"
public const val IS_RECEIPT_PAGE = "isReceiptPage"
// public const val IS_NEW_RECEIPT = "isNewReceipt"
@@ -91,6 +92,7 @@ abstract class GoodsListActivity : BaseActivity() {
// var isNewReceipt: Boolean = false
var id: String = ""
var supplierId: String = ""
var purCode: String = ""
lateinit var binding: ActivityGoodsListBinding
val receiptViewModel: ReceiptViewModel by viewModels()
val userViewModel: UserViewModel by viewModels()
@@ -116,6 +118,7 @@ abstract class GoodsListActivity : BaseActivity() {
//isNewReceipt = intent.getBooleanExtra(IS_NEW_RECEIPT, false)
id = intent.getStringExtra(ID) ?: ""
supplierId = intent.getStringExtra(SUPPLIER_ID) ?: ""
purCode = intent.getStringExtra(PUR_CODE) ?: ""
replaceIncludeContent()
initRecyclerView()
@@ -210,13 +213,13 @@ abstract class GoodsListActivity : BaseActivity() {
binding.tvTotalWeight.text = "重量:${weight}"
}
if (weight < 200) {
if (weight < 10) {
if (weight < 20) {
// val clazzName = DialogManager.getDialogList()
// .map { it.javaClass.simpleName }
// .joinToString(",")
// Timber.tag(TAG).d(clazzName)
if (DialogManager.getDialogList().size == 1 &&
DialogManager.contains("GoodsRecognizeDialog") &&
// 无其他弹窗正在显示时(过滤幽灵条目),自动关闭识别弹窗
if (DialogManager.getDialogList().none { it.isShowing && it != goodsRecognizeDialog } &&
goodsRecognizeDialog?.isShowing == true
) {
goodsRecognizeDialog?.dismiss()
@@ -253,8 +256,9 @@ abstract class GoodsListActivity : BaseActivity() {
searchFood(uri)
} catch (e: Exception) {
e.printStackTrace()
Loading.dismiss()
}
}.start()
}
}
private val delayHandler by lazy {
@@ -395,19 +399,22 @@ abstract class GoodsListActivity : BaseActivity() {
// readBitmap(it)
// }
// }
ImageUtil.uriToBitmap(this, uri)?.let { bitmap ->
val newBmp = BitmapCropper.cropCenter(
original = bitmap,
targetWidth = 1000, targetHeight = 1300,
offsetX = 30, offsetY = 100
)
readBitmap(newBmp)
if (newBmp.isRecycled.not()) {
newBmp.recycle()
}
if (bitmap.isRecycled.not()) {
bitmap.recycle()
}
val bitmap = ImageUtil.uriToBitmap(this, uri)
if (bitmap == null) {
Loading.dismiss()
return
}
val newBmp = BitmapCropper.cropCenter(
original = bitmap,
targetWidth = 1000, targetHeight = 1300,
offsetX = 30, offsetY = 100
)
readBitmap(newBmp)
if (newBmp.isRecycled.not()) {
newBmp.recycle()
}
if (bitmap.isRecycled.not()) {
bitmap.recycle()
}
}
@@ -643,11 +650,12 @@ abstract class GoodsListActivity : BaseActivity() {
val uploadInfo = UploadInfo(
id = id,
supplierId = supplierId,
purCode = purCode,
receiveGoodsInfos = goodsList
)
logInfo("receiptSubmit确认收货提交数据:${uploadInfo.toJsonString()}")
showWaitingDialog2("加载中")
receiptViewModel.confirmReceipt(uploadInfo) { success ->
receiptViewModel.confirmReceipt(uploadInfo) { success, msg ->
hideWaitingDialog()
if (success) {
userViewModel.deleteKey(localGoodsKey)
@@ -656,7 +664,7 @@ abstract class GoodsListActivity : BaseActivity() {
finish()
}, 200)
} else {
toast("确认收货失败")
toast("确认收货失败$msg")
}
}
}
@@ -686,7 +694,7 @@ abstract class GoodsListActivity : BaseActivity() {
}
logInfo("selfProcurementSubmit自采入库提交数据:${submitData.toJsonString()}")
showWaitingDialog2("加载中")
receiptViewModel.addToWarehouse(submitData) { success ->
receiptViewModel.addToWarehouse(submitData) { success, msg ->
hideWaitingDialog()
if (success) {
toast("提交入库成功")
@@ -695,7 +703,7 @@ abstract class GoodsListActivity : BaseActivity() {
finish()
}, 200)
} else {
toast("提交入库失败")
toast("提交入库失败$msg")
}
}
}
@@ -41,6 +41,7 @@ class PurchaseOrderActivity : BaseActivity() {
startActivity<ReceiptActivity> {
putExtra(GoodsListActivity.ID, item.id)
putExtra(GoodsListActivity.SUPPLIER_ID, item.supplierId)
putExtra(GoodsListActivity.PUR_CODE, item.purCode)
putExtra(GoodsListActivity.IS_RECEIPT_PAGE, true)
//putExtra(GoodsListActivity.IS_NEW_RECEIPT, false)
}
@@ -357,27 +357,28 @@ class GoodsStoreDialog(
context.toast("入库金额不能为0")
return
}
if (funcType == 1) {
activity?.let { Loading.show(it) }
cameraUtils.takePhoto { uri ->
//imageUri = uri
collectGoodsVector(uri) {
activity?.uploadImage(goods.id!!, goods.goodsName!!, imageFile)
}
binding.root.postDelayed({
Loading.dismiss()
confirm(unitName, count, price, totalPrice)
}, 500)
// if (funcType == 1) {
//无论是否识别到物品,都上传图片增加样本数据
activity?.let { Loading.show(it) }
cameraUtils.takePhoto { uri ->
//imageUri = uri
collectGoodsVector(uri) {
activity?.uploadImage(goods.id!!, goods.goodsName!!, imageFile)
}
cameraUtils.addFailCallback {
binding.root.postDelayed({
Loading.dismiss()
confirm(unitName, count, price, totalPrice)
}, 500)
}
} else {
confirm(unitName, count, price, totalPrice)
binding.root.postDelayed({
Loading.dismiss()
confirm(unitName, count, price, totalPrice)
}, 500)
}
cameraUtils.addFailCallback {
binding.root.postDelayed({
Loading.dismiss()
confirm(unitName, count, price, totalPrice)
}, 500)
}
// } else {
// confirm(unitName, count, price, totalPrice)
// }
}
private fun confirm(unitName: String, count: Double, price: Double, totalPrice: Double?) {
@@ -423,7 +424,7 @@ class GoodsStoreDialog(
override fun show() {
super.show()
if (funcType == 1) {
// if (funcType == 1) {
takePhotoBinding?.let {
cameraUtils.setPreviewController(previewView)
cameraUtils.bind()
@@ -433,7 +434,7 @@ class GoodsStoreDialog(
}, 1000)
}
}
}
// }
binding.root.postDelayed({
SensorScaleUtils.startScale()
}, 2600)
@@ -454,7 +455,7 @@ class GoodsStoreDialog(
private var imagePreviewBinding: LayoutImagePreviewBinding? = null
private fun addChildToContainer() {
val inflater = LayoutInflater.from(context)
if (funcType == 1) {
// if (funcType == 1) {
//预览及拍照
takePhotoBinding = LayoutTakePhotoBinding.inflate(inflater, binding.flContainer, true)
activity?.unBindCamera()
@@ -474,19 +475,19 @@ class GoodsStoreDialog(
// cameraUtils.takePhoto(takePhotoCallback)
// }
}
return
}
//只显示原始图片
imagePreviewBinding = LayoutImagePreviewBinding.inflate(inflater, binding.flContainer)
imagePreviewBinding?.imageView?.load(goods.relativeUrl) {
transformations(RoundedCornersTransformation(radius = 10.dp.toFloat()))
}
binding.flContainer.let {
it.setBackgroundResource(R.drawable.bg_white_radius10_stroke2)
it.updateLayoutParams<LinearLayout.LayoutParams> {
width = 488.dp
height = 356.dp
bottomMargin = 35.dp
if(funcType != 1){
//只显示原始图片
imagePreviewBinding = LayoutImagePreviewBinding.inflate(inflater, binding.flContainer)
imagePreviewBinding?.imageView?.load(goods.relativeUrl) {
transformations(RoundedCornersTransformation(radius = 10.dp.toFloat()))
}
binding.flContainer.let {
it.setBackgroundResource(R.drawable.bg_white_radius10_stroke2)
it.updateLayoutParams<LinearLayout.LayoutParams> {
width = 488.dp
height = 356.dp
bottomMargin = 35.dp
}
}
}
}
@@ -18,6 +18,10 @@ data class UploadInfo(
* 供应商id
*/
var supplierId: String? = null,
/**
* 采购单号
*/
var purCode: String? = null,
/**
*
* 物品信息 【全部收货使用】
@@ -212,17 +212,25 @@ abstract class BaseViewModel(
callback: (List<SearchGoodsInfo.Record>) -> Unit
) {
launch {
if (nameList.isNullOrEmpty() && scoreList.isNullOrEmpty()) return@launch
val paramList = if (nameList.isNullOrEmpty()) scoreList!!.map { it.name } else nameList
val response = repository.recognizeGoodsList(paramList)
val list = if (parseResponse(response)) response.data ?: listOf() else listOf()
if (scoreList.isNullOrEmpty().not()) {
list.forEach { record ->
val item = scoreList.firstOrNull { it.name == record.goodsName }
record.score = ((1 - (item?.score ?: 0.0)) * 10000).roundToInt()
try {
if (nameList.isNullOrEmpty() && scoreList.isNullOrEmpty()) {
callback(listOf())
return@launch
}
val paramList = if (nameList.isNullOrEmpty()) scoreList!!.map { it.name } else nameList
val response = repository.recognizeGoodsList(paramList)
val list = if (parseResponse(response)) response.data ?: listOf() else listOf()
if (scoreList.isNullOrEmpty().not()) {
list.forEach { record ->
val item = scoreList.firstOrNull { it.name == record.goodsName }
record.score = ((1 - (item?.score ?: 0.0)) * 10000).roundToInt()
}
}
callback(list)
} catch (e: Exception) {
Timber.e(e)
callback(listOf())
}
callback(list)
}
}
@@ -323,17 +323,17 @@ class ReceiptViewModel @Inject constructor(
// }
// }
fun confirmReceipt(uploadInfo: UploadInfo, callback: (Boolean) -> Unit) {
fun confirmReceipt(uploadInfo: UploadInfo, callback: (Boolean, String) -> Unit) {
launchWithLoading {
val resp = repository.confirmReceipt(uploadInfo)
callback(resp.data == true)
callback(resp.isSuccess(), resp.msg?:"")
}
}
fun addToWarehouse(list: List<PurchaseWarehouseParam>, callback: (Boolean) -> Unit) {
fun addToWarehouse(list: List<PurchaseWarehouseParam>, callback: (Boolean, String) -> Unit) {
launchWithLoading {
val resp = repository.selfPurchaseWarehousing(list)
callback(resp.data == true)
callback(resp.isSuccess(), resp.msg?:"")
}
}