餐盘柜接口改造

This commit is contained in:
2025-12-26 14:05:41 +08:00
parent 5e4dc4baa4
commit 7a6c4012d1
28 changed files with 859 additions and 507 deletions
@@ -24,6 +24,8 @@ import com.sw.platecabinet.databinding.ItemSearchUserInfoBinding
import com.sw.platecabinet.dialog.UserBindRemindDialog
import com.sw.platecabinet.ext.maskName
import com.sw.platecabinet.ext.maskPhone
import com.sw.platecabinet.model.ErrorInfo
import com.sw.platecabinet.model.request.BindParam
import com.sw.platecabinet.model.response.EquipmentUserInfo
import com.sw.platecabinet.model.response.SearchResult
import com.sw.platecabinet.utils.Debouncer
@@ -188,13 +190,16 @@ class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
ToastUtils.showToast("选中的会员信息异常")
return@setOnClickListener
}
viewModel.bindPlate(
val bindParam = BindParam(
equipmentId = info!!.equipmentId,
equipmentCode = info!!.equipmentCode!!,
equipmentBoxCode = info!!.equipmentBoxCode!!,
memberId = checkedItem!!.id!!,
plateNumber = plateNumber
)
viewModel.bindPlate(bindParam) { pair ->
updateBindState(pair)
}
KeyboardUtils.hideKeyboard(requireActivity())
}
binding.tvBack.setOnClickListener { activity?.finish() }
@@ -210,41 +215,11 @@ class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
adapter.updateData(it)
}
}
lifecycleScope.launch {
viewModel.bindStateChange.collect {
if (it.first == null) return@collect // 解绑状态过滤
val errorInfo = it.second
if (errorInfo.isSuccess()) {
if (errorInfo.equipmentUserInfo == null) {
ToastUtils.showToast("数据异常")
return@collect
}
if (errorInfo.equipmentUserInfo.isOtherEquipment() == true) {
MainActivity.start(
requireContext(),
pageType = PageType.PLATE_TIP,
equipmentUserInfo = errorInfo.equipmentUserInfo,
isAdmin = true
)
} else {
SerialApi.openPlate(
errorInfo.equipmentUserInfo.equipmentBoxCode!!.toInt(),
object : SerialPortManager.SendCallback {
override fun onSuccess() {
ToastUtils.showToast("绑定成功")
activity?.finish()
}
override fun onFail(e: Exception?) {
ToastUtils.showToast("绑定失败")
}
})
}
} else {
ToastUtils.showToast(errorInfo.msg)
}
}
}
// lifecycleScope.launch {
// viewModel.bindStateChange.collect {
// updateBindState(it)
// }
// }
}
private fun createAdapter(): GenericItemAdapter<SearchResult.Member, ItemSearchUserInfoBinding> {
@@ -267,7 +242,7 @@ class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
//TODO 调用接口查询用户是否已绑盘
this@BindPlateFragment.equipmentBoxCode = null
(activity as? MainActivity)?.showWaitingDialog("查询中,请稍后……")
userViewModel.getUserInfoById(memberId = item.id!!) {
userViewModel.getUserInfoById(memberId = item.id) {
(activity as? MainActivity)?.hideWaitingDialog()
this@BindPlateFragment.equipmentBoxCode = it?.equipmentBoxCode
}
@@ -285,4 +260,38 @@ class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
)
.show()
}
private fun updateBindState(pair: Pair<Boolean?, ErrorInfo>){
if (pair.first == null) return // 解绑状态过滤
val errorInfo = pair.second
if (errorInfo.isSuccess()) {
if (errorInfo.equipmentUserInfo == null) {
ToastUtils.showToast("数据异常")
return
}
if (errorInfo.equipmentUserInfo.isOtherEquipment()) {
MainActivity.start(
requireContext(),
pageType = PageType.PLATE_TIP,
equipmentUserInfo = errorInfo.equipmentUserInfo,
isAdmin = true
)
} else {
SerialApi.openPlate(
errorInfo.equipmentUserInfo.equipmentBoxCode!!.toInt(),
object : SerialPortManager.SendCallback {
override fun onSuccess() {
ToastUtils.showToast("绑定成功")
activity?.finish()
}
override fun onFail(e: Exception?) {
ToastUtils.showToast("绑定失败")
}
})
}
} else {
ToastUtils.showToast(errorInfo.msg)
}
}
}
@@ -47,12 +47,12 @@ class SettingListFragment :
override fun registerDataChange() {
super.registerDataChange()
lifecycleScope.launch {
viewModel.equipmentList.collect { it ->
Timber.d("registerDateChange updateAdapter it = $it")
updateAdapter(it)
}
}
// lifecycleScope.launch {
// viewModel.equipmentList.collect { it ->
// Timber.d("registerDateChange updateAdapter it = $it")
// updateAdapter(it)
// }
// }
}
override fun initialize() {
@@ -80,7 +80,9 @@ class SettingListFragment :
override fun onResume() {
super.onResume()
viewModel.getEquipmentList()
viewModel.getEquipmentList{
updateAdapter(it)
}
}
private fun createItemAdapter(): GenericItemAdapter<EquipmentUserInfo, ItemBindViewBinding> {
@@ -12,6 +12,7 @@ import com.sw.platecabinet.activity.UnBindDialogActivity
import com.sw.platecabinet.databinding.FragmentUnbindPlateBinding
import com.sw.platecabinet.ext.maskName
import com.sw.platecabinet.ext.maskPhone
import com.sw.platecabinet.model.ErrorInfo
import com.sw.platecabinet.model.response.EquipmentUserInfo
import kotlinx.coroutines.launch
@@ -38,16 +39,15 @@ class UnBindPlateFragment private constructor() : BaseFragment<FragmentUnbindPla
ActivityResultContracts.StartActivityForResult()
) { result ->
if (result.resultCode == Activity.RESULT_OK) {
viewModel.unbindPlate(
equipmentBoxCode = info!!.equipmentBoxCode!!,
equipmentCode = info!!.equipmentCode!!
)
viewModel.unbindPlate(info!!.id!!) { pair ->
updateBindState(pair)
}
}
}
override fun initialize() {
arguments?.let {
info = it.getParcelable(ARG_PARAM1)
arguments?.let { args ->
info = args.getParcelable(ARG_PARAM1)
info?.let {
binding.tvNum.text = "${it.equipmentName}-${it.equipmentBoxCode}"
binding.tvPlateNumberValue.text = it.plateNumber
@@ -73,20 +73,23 @@ class UnBindPlateFragment private constructor() : BaseFragment<FragmentUnbindPla
override fun registerDataChange() {
super.registerDataChange()
lifecycleScope.launch {
viewModel.bindStateChange.collect {
if (it.first == null) return@collect // 绑定状态过滤
val errorInfo = it.second
if (errorInfo.isSuccess()) {
ToastUtils.showToast("解绑成功")
// lifecycleScope.launch {
// viewModel.bindStateChange.collect {
// updateBindState(it)
// }
// }
}
private fun updateBindState(pair: Pair<Boolean?, ErrorInfo>){
if (pair.first == null) return // 绑定状态过滤
val errorInfo = pair.second
if (errorInfo.isSuccess()) {
ToastUtils.showToast("解绑成功")
// activity?.finish()
// 关闭宿主 Activity
requireActivity().finish()
requireActivity().overridePendingTransition(0, 0)
} else {
ToastUtils.showToast(errorInfo.msg)
}
}
// 关闭宿主 Activity
requireActivity().finish()
requireActivity().overridePendingTransition(0, 0)
} else {
ToastUtils.showToast(errorInfo.msg)
}
}
}