From 5f31cf5274073bacad4bcad8a1c7347b8b602e7d Mon Sep 17 00:00:00 2001 From: YANGJIANKUAN Date: Mon, 26 Jan 2026 12:34:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=87=BA=E6=B8=AF=E7=BB=84=E8=A3=85=20?= =?UTF-8?q?=E5=9B=9E=E5=A1=AB=E9=87=8D=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 6 + .../lukouguoji/module_base/MyApplication.kt | 2 +- .../module_base/bean/GjcUldUseBean.kt | 3 +- .../module_base/bean/GjcWarehouse.kt | 21 ++ .../lukouguoji/module_base/http/net/Api.kt | 8 + .../module_base/router/ARouterConstants.kt | 1 + .../activity/GjcAssembleWeightEditActivity.kt | 69 ++++++ .../holder/GjcAssembleWeightEditViewHolder.kt | 21 ++ .../GjcAssembleWeightEditViewModel.kt | 218 ++++++++++++++++ .../gjc/viewModel/IntExpAssembleViewModel.kt | 62 +---- .../activity_gjc_assemble_weight_edit.xml | 232 ++++++++++++++++++ .../layout/item_gjc_assemble_weight_edit.xml | 66 +++++ 12 files changed, 654 insertions(+), 55 deletions(-) create mode 100644 module_gjc/src/main/java/com/lukouguoji/gjc/activity/GjcAssembleWeightEditActivity.kt create mode 100644 module_gjc/src/main/java/com/lukouguoji/gjc/holder/GjcAssembleWeightEditViewHolder.kt create mode 100644 module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/GjcAssembleWeightEditViewModel.kt create mode 100644 module_gjc/src/main/res/layout/activity_gjc_assemble_weight_edit.xml create mode 100644 module_gjc/src/main/res/layout/item_gjc_assemble_weight_edit.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 88a4303..b4ac4f6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -109,6 +109,12 @@ android:configChanges="orientation|keyboardHidden" android:exported="false" android:screenOrientation="userLandscape" /> + + Unit)? = null } diff --git a/module_base/src/main/java/com/lukouguoji/module_base/http/net/Api.kt b/module_base/src/main/java/com/lukouguoji/module_base/http/net/Api.kt index 8141452..81b5c97 100644 --- a/module_base/src/main/java/com/lukouguoji/module_base/http/net/Api.kt +++ b/module_base/src/main/java/com/lukouguoji/module_base/http/net/Api.kt @@ -661,6 +661,14 @@ interface Api { @POST("IntExpAssemble/queryAssembledByUld") suspend fun getAssembledWaybillsByUld(@Body data: RequestBody): BaseResultBean> + /** + * 国际出港组装 - 修改列表(批量更新运单重量) + * 接口路径: /IntExpAssemble/update + * @param data GjcWarehouse数组 + */ + @POST("IntExpAssemble/update") + suspend fun updateIntExpAssemble(@Body data: RequestBody): BaseResultBean + /** * 国际出港出库交接-分页查询 * 接口路径: /IntExpOutHandover/pageQuery diff --git a/module_base/src/main/java/com/lukouguoji/module_base/router/ARouterConstants.kt b/module_base/src/main/java/com/lukouguoji/module_base/router/ARouterConstants.kt index 747c193..6bfea93 100644 --- a/module_base/src/main/java/com/lukouguoji/module_base/router/ARouterConstants.kt +++ b/module_base/src/main/java/com/lukouguoji/module_base/router/ARouterConstants.kt @@ -147,6 +147,7 @@ object ARouterConstants { const val ACTIVITY_URL_INT_EXP_TALLY = "/gjc/IntExpTallyActivity" //国际出港 出港理货 const val ACTIVITY_URL_INT_EXP_ARRIVE = "/gjc/IntExpArriveActivity" //国际出港 出港运抵 const val ACTIVITY_URL_INT_EXP_STORAGE_USE = "/gjc/IntExpStorageUseActivity" //国际出港 仓库 + const val ACTIVITY_URL_GJC_ASSEMBLE_WEIGHT_EDIT = "/gjc/GjcAssembleWeightEditActivity" //国际出港 修改组装重量 ///////////////// 国际进港模块 /** diff --git a/module_gjc/src/main/java/com/lukouguoji/gjc/activity/GjcAssembleWeightEditActivity.kt b/module_gjc/src/main/java/com/lukouguoji/gjc/activity/GjcAssembleWeightEditActivity.kt new file mode 100644 index 0000000..555bebe --- /dev/null +++ b/module_gjc/src/main/java/com/lukouguoji/gjc/activity/GjcAssembleWeightEditActivity.kt @@ -0,0 +1,69 @@ +package com.lukouguoji.gjc.activity + +import android.content.Context +import android.content.Intent +import android.os.Bundle +import androidx.recyclerview.widget.DividerItemDecoration +import androidx.recyclerview.widget.LinearLayoutManager +import com.alibaba.android.arouter.facade.annotation.Route +import com.lukouguoji.gjc.R +import com.lukouguoji.gjc.databinding.ActivityGjcAssembleWeightEditBinding +import com.lukouguoji.gjc.holder.GjcAssembleWeightEditViewHolder +import com.lukouguoji.gjc.viewModel.GjcAssembleWeightEditViewModel +import com.lukouguoji.module_base.base.BaseBindingActivity +import com.lukouguoji.module_base.base.CommonAdapter +import com.lukouguoji.module_base.bean.GjcUldUseBean +import com.lukouguoji.module_base.common.Constant +import com.lukouguoji.module_base.router.ARouterConstants + +/** + * 国际出港-修改组装重量页面 + */ +@Route(path = ARouterConstants.ACTIVITY_URL_GJC_ASSEMBLE_WEIGHT_EDIT) +class GjcAssembleWeightEditActivity : + BaseBindingActivity() { + + private lateinit var adapter: CommonAdapter + + override fun layoutId() = R.layout.activity_gjc_assemble_weight_edit + + override fun viewModelClass() = GjcAssembleWeightEditViewModel::class.java + + override fun initOnCreate(savedInstanceState: Bundle?) { + setBackArrow("修改组装重量") + + binding.viewModel = viewModel + + // 初始化RecyclerView + val layoutManager = LinearLayoutManager(this) + binding.recyclerView.layoutManager = layoutManager + + // 添加分割线 + val divider = DividerItemDecoration(this, DividerItemDecoration.VERTICAL) + binding.recyclerView.addItemDecoration(divider) + + adapter = CommonAdapter( + this, + R.layout.item_gjc_assemble_weight_edit, + GjcAssembleWeightEditViewHolder::class.java + ) + binding.recyclerView.adapter = adapter + + // 监听数据变化更新RecyclerView + viewModel.waybillList.observe(this) { records -> + adapter.refresh(records) + } + + // 初始化数据 + viewModel.initOnCreated(intent) + } + + companion object { + @JvmStatic + fun start(context: Context, bean: GjcUldUseBean) { + val starter = Intent(context, GjcAssembleWeightEditActivity::class.java) + .putExtra(Constant.Key.BEAN, bean) + context.startActivity(starter) + } + } +} diff --git a/module_gjc/src/main/java/com/lukouguoji/gjc/holder/GjcAssembleWeightEditViewHolder.kt b/module_gjc/src/main/java/com/lukouguoji/gjc/holder/GjcAssembleWeightEditViewHolder.kt new file mode 100644 index 0000000..fc7bcbe --- /dev/null +++ b/module_gjc/src/main/java/com/lukouguoji/gjc/holder/GjcAssembleWeightEditViewHolder.kt @@ -0,0 +1,21 @@ +package com.lukouguoji.gjc.holder + +import android.view.View +import com.lukouguoji.gjc.databinding.ItemGjcAssembleWeightEditBinding +import com.lukouguoji.module_base.base.BaseViewHolder +import com.lukouguoji.module_base.bean.GjcWarehouse + +/** + * 国际出港-修改组装重量列表 ViewHolder + */ +class GjcAssembleWeightEditViewHolder(view: View) : + BaseViewHolder(view) { + + override fun onBind(item: Any?, position: Int) { + val warehouse = getItemBean(item) ?: return + + binding.bean = warehouse + binding.position = position + binding.executePendingBindings() + } +} diff --git a/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/GjcAssembleWeightEditViewModel.kt b/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/GjcAssembleWeightEditViewModel.kt new file mode 100644 index 0000000..5e743e9 --- /dev/null +++ b/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/GjcAssembleWeightEditViewModel.kt @@ -0,0 +1,218 @@ +package com.lukouguoji.gjc.viewModel + +import android.content.Intent +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.viewModelScope +import com.lukouguoji.module_base.base.BaseViewModel +import com.lukouguoji.module_base.bean.GjcUldUseBean +import com.lukouguoji.module_base.bean.GjcWarehouse +import com.lukouguoji.module_base.common.Constant +import com.lukouguoji.module_base.common.ConstantEvent +import com.lukouguoji.module_base.http.net.NetApply +import com.lukouguoji.module_base.impl.FlowBus +import com.lukouguoji.module_base.ktx.launchLoadingCollect +import com.lukouguoji.module_base.ktx.showToast +import com.lukouguoji.module_base.ktx.toRequestBody +import kotlinx.coroutines.launch + +/** + * 国际出港-修改组装重量 ViewModel + */ +class GjcAssembleWeightEditViewModel : BaseViewModel() { + + /////////////////////////////////////////////////////////////////////////// + // 数据字段 + /////////////////////////////////////////////////////////////////////////// + + // ULD信息Bean(从列表页传入) + val uldBean = MutableLiveData() + + // 运单列表 + val waybillList = MutableLiveData>(emptyList()) + + /////////////////////////////////////////////////////////////////////////// + // ULD信息显示字段 + /////////////////////////////////////////////////////////////////////////// + + val uldNo = MutableLiveData("") // ULD编号 + val totalPc = MutableLiveData("") // 总件数 + val totalWeight = MutableLiveData("") // 总重量 + val cargoWeight = MutableLiveData("") // 货重 + + /////////////////////////////////////////////////////////////////////////// + // 底部统计字段 + /////////////////////////////////////////////////////////////////////////// + + val sumCargoWeight = MutableLiveData("0") // 总货重 + val weightError = MutableLiveData("0%") // 重量误差百分比 + + // 传递参数(用于API调用) + private var useId: Long = 0 + private var uld: String = "" + private var fdate: String = "" + private var fno: String = "" + + init { + // 监听 waybillList 变化,自动触发统计计算 + waybillList.observeForever { + calculateStatistics() + } + } + + /////////////////////////////////////////////////////////////////////////// + // 初始化 + /////////////////////////////////////////////////////////////////////////// + + fun initOnCreated(intent: Intent) { + // 接收传入的完整 Bean 对象 + val bean = intent.getSerializableExtra(Constant.Key.BEAN) as? GjcUldUseBean + bean?.let { + uldBean.value = it + + // 提取ULD信息字段 + uldNo.value = it.uld + totalPc.value = it.pc.toString() + totalWeight.value = it.totalWeight.toString() + cargoWeight.value = it.cargoWeight.toString() + + // 保存参数用于API调用 + useId = it.useId + uld = it.uld + fdate = it.fdate + fno = it.fno + + // 加载运单数据 + loadData() + } ?: run { + showToast("参数错误") + } + } + + /////////////////////////////////////////////////////////////////////////// + // 数据加载 + /////////////////////////////////////////////////////////////////////////// + + private fun loadData() { + val params = mapOf( + "useId" to useId, + "uld" to uld, + "fdate" to fdate, + "fno" to fno + ).toRequestBody() + + launchLoadingCollect({ NetApply.api.getAssembledWaybillsByUld(params) }) { + onSuccess = { result -> + val list = result.data ?: emptyList() + + // 为每个运单设置数据变化回调 + list.forEach { warehouse -> + warehouse.onDataChanged = { + // 数据变化时重新计算统计 + calculateStatistics() + } + } + + waybillList.value = list + + if (list.isEmpty()) { + showToast("暂无运单数据") + } + } + onFailed = { code, msg -> + showToast("加载失败:$msg") + } + } + } + + /** + * 计算统计数据:总货重、重量误差 + */ + private fun calculateStatistics() { + val records = waybillList.value ?: emptyList() + + // 计算总货重(所有运单weight之和) + val sumWeight = records.sumOf { it.weight } + sumCargoWeight.value = String.format("%.2f", sumWeight) + + // 计算重量误差百分比(相对于ULD的货重) + val uldCargoWeight = cargoWeight.value?.toDoubleOrNull() ?: 0.0 + val error = if (sumWeight > 0 && uldCargoWeight > 0) { + ((sumWeight - uldCargoWeight) / uldCargoWeight * 100) + } else { + 0.0 + } + weightError.value = String.format("%.1f%%", error) + } + + /////////////////////////////////////////////////////////////////////////// + // 按钮事件 + /////////////////////////////////////////////////////////////////////////// + + /** + * 点击"取消"按钮 + */ + fun onCancelClick() { + getTopActivity().finish() + } + + /** + * 点击"保存"按钮 + */ + fun onSaveClick() { + val records = waybillList.value ?: return + + if (records.isEmpty()) { + showToast("没有可保存的数据") + return + } + + // 验证数据 + if (!validateRecords(records)) return + + // 调用批量更新接口 + saveRecords(records) + } + + /////////////////////////////////////////////////////////////////////////// + // 业务逻辑 + /////////////////////////////////////////////////////////////////////////// + + /** + * 验证数据 + */ + private fun validateRecords(records: List): Boolean { + records.forEachIndexed { index, record -> + if (record.weight < 0) { + showToast("第${index + 1}条记录的重量不能为负数") + return false + } + } + return true + } + + /** + * 批量保存运单重量 + */ + private fun saveRecords(records: List) { + launchLoadingCollect({ + NetApply.api.updateIntExpAssemble(records.toRequestBody()) + }) { + onSuccess = { result -> + if (result.data == true) { + showToast("保存成功") + // 发送刷新事件通知列表页 + viewModelScope.launch { + FlowBus.with(ConstantEvent.EVENT_REFRESH).emit("refresh") + } + // 关闭页面 + getTopActivity().finish() + } else { + showToast("保存失败") + } + } + onFailed = { code, msg -> + showToast("保存失败:$msg") + } + } + } +} diff --git a/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/IntExpAssembleViewModel.kt b/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/IntExpAssembleViewModel.kt index 8709b35..e351f44 100644 --- a/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/IntExpAssembleViewModel.kt +++ b/module_gjc/src/main/java/com/lukouguoji/gjc/viewModel/IntExpAssembleViewModel.kt @@ -1,10 +1,6 @@ package com.lukouguoji.gjc.viewModel -import android.text.InputType -import android.widget.EditText -import androidx.appcompat.app.AlertDialog import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.viewModelScope import com.alibaba.android.arouter.launcher.ARouter import com.lukouguoji.gjc.R import com.lukouguoji.gjc.holder.IntExpAssembleItemViewHolder @@ -12,17 +8,15 @@ import com.lukouguoji.module_base.base.BasePageViewModel import com.lukouguoji.module_base.bean.GjcUldUseBean import com.lukouguoji.module_base.http.net.NetApply import com.lukouguoji.module_base.ktx.commonAdapter +import com.lukouguoji.module_base.ktx.formatDate import com.lukouguoji.module_base.ktx.launchCollect import com.lukouguoji.module_base.ktx.launchLoadingCollect import com.lukouguoji.module_base.ktx.showConfirmDialog import com.lukouguoji.module_base.ktx.showToast import com.lukouguoji.module_base.ktx.toRequestBody -import com.lukouguoji.module_base.ktx.verifyNullOrEmpty import com.lukouguoji.module_base.router.ARouterConstants import dev.utils.app.info.KeyValue import dev.utils.common.DateUtils -import com.lukouguoji.module_base.ktx.formatDate -import kotlinx.coroutines.launch /** * 国际出港-出港组装ViewModel @@ -264,7 +258,7 @@ class IntExpAssembleViewModel : BasePageViewModel() { } /** - * 回填重量按钮点击 + * 回填重量按钮点击 - 跳转到修改组装重量页面 */ fun onBackfillWeightClick() { // 获取选中的数据 @@ -275,55 +269,17 @@ class IntExpAssembleViewModel : BasePageViewModel() { .filter { it.isSelected } if (selectedItems.isEmpty()) { - showToast("请选择要回填重量的记录") + showToast("请选择要修改重量的ULD") return } - // 显示输入对话框 - showBackfillWeightDialog(selectedItems) - } - - /** - * 显示回填重量对话框 - */ - private fun showBackfillWeightDialog(items: List) { - val activity = getTopActivity() - - // 创建输入框 - val input = EditText(activity).apply { - hint = "请输入重量(KG)" - inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL - setPadding(40, 40, 40, 40) + if (selectedItems.size > 1) { + showToast("每次只能选择一个ULD进行重量修改") + return } - AlertDialog.Builder(activity) - .setTitle("回填重量") - .setMessage("共选中 ${items.size} 条记录") - .setView(input) - .setPositiveButton("确定") { _, _ -> - val weight = input.text.toString() - if (weight.verifyNullOrEmpty("请输入重量")) return@setPositiveButton - backfillWeight(items, weight) - } - .setNegativeButton("取消", null) - .show() - } - - /** - * 回填重量API调用 - */ - private fun backfillWeight(items: List, weight: String) { - val ids = items.mapNotNull { it.useId }.joinToString(",") - val params = mapOf( - "ids" to ids, - "weight" to weight - ).toRequestBody() - - launchLoadingCollect({ NetApply.api.backfillIntExpAssembleWeight(params) }) { - onSuccess = { - showToast("回填重量成功") - refresh() - } - } + // 跳转到修改组装重量页面 + val bean = selectedItems.first() + com.lukouguoji.gjc.activity.GjcAssembleWeightEditActivity.start(getTopActivity(), bean) } } diff --git a/module_gjc/src/main/res/layout/activity_gjc_assemble_weight_edit.xml b/module_gjc/src/main/res/layout/activity_gjc_assemble_weight_edit.xml new file mode 100644 index 0000000..d1d8d3f --- /dev/null +++ b/module_gjc/src/main/res/layout/activity_gjc_assemble_weight_edit.xml @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/module_gjc/src/main/res/layout/item_gjc_assemble_weight_edit.xml b/module_gjc/src/main/res/layout/item_gjc_assemble_weight_edit.xml new file mode 100644 index 0000000..c2280aa --- /dev/null +++ b/module_gjc/src/main/res/layout/item_gjc_assemble_weight_edit.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + +