feat: 国际进港 报文解析
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package com.lukouguoji.gjj.activity
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.lukouguoji.gjj.R
|
||||
import com.lukouguoji.gjj.databinding.ActivityIntImpMsgParseBinding
|
||||
import com.lukouguoji.gjj.viewModel.IntImpMsgParseViewModel
|
||||
import com.lukouguoji.module_base.base.BaseBindingActivity
|
||||
import com.lukouguoji.module_base.common.ConstantEvent
|
||||
import com.lukouguoji.module_base.impl.FlowBus
|
||||
import com.lukouguoji.module_base.impl.observe
|
||||
import com.lukouguoji.module_base.ktx.addOnItemClickListener
|
||||
import com.lukouguoji.module_base.router.ARouterConstants
|
||||
|
||||
/**
|
||||
* 国际进港-电报解析(电报生成)页面
|
||||
*/
|
||||
@Route(path = ARouterConstants.ACTIVITY_URL_INT_IMP_MSG_PARSE)
|
||||
class IntImpMsgParseActivity :
|
||||
BaseBindingActivity<ActivityIntImpMsgParseBinding, IntImpMsgParseViewModel>() {
|
||||
|
||||
override fun layoutId() = R.layout.activity_int_imp_msg_parse
|
||||
override fun viewModelClass() = IntImpMsgParseViewModel::class.java
|
||||
|
||||
override fun initOnCreate(savedInstanceState: Bundle?) {
|
||||
setBackArrow("电报生成")
|
||||
binding.viewModel = viewModel
|
||||
|
||||
// 观察全选状态,更新图标透明度
|
||||
viewModel.isAllChecked.observe(this) { isAllChecked ->
|
||||
binding.checkIcon.alpha = if (isAllChecked) 1.0f else 0.5f
|
||||
}
|
||||
|
||||
// 绑定分页
|
||||
viewModel.pageModel.bindSmartRefreshLayout(binding.srl, binding.rv, viewModel, this)
|
||||
|
||||
// 设置item点击监听
|
||||
binding.rv.addOnItemClickListener(viewModel)
|
||||
|
||||
// 监听刷新事件
|
||||
FlowBus.with<String>(ConstantEvent.EVENT_REFRESH).observe(this) {
|
||||
viewModel.refresh()
|
||||
}
|
||||
|
||||
// 初始加载数据
|
||||
viewModel.refresh()
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun start(context: Context) {
|
||||
val starter = Intent(context, IntImpMsgParseActivity::class.java)
|
||||
context.startActivity(starter)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.lukouguoji.gjj.holder
|
||||
|
||||
import android.view.View
|
||||
import com.lukouguoji.gjj.databinding.ItemIntImpMsgParseBinding
|
||||
import com.lukouguoji.module_base.base.BaseViewHolder
|
||||
import com.lukouguoji.module_base.bean.MsgReceivePool
|
||||
|
||||
/**
|
||||
* 国际进港电报解析列表项ViewHolder
|
||||
*/
|
||||
class IntImpMsgParseViewHolder(view: View) :
|
||||
BaseViewHolder<MsgReceivePool, ItemIntImpMsgParseBinding>(view) {
|
||||
|
||||
override fun onBind(item: Any?, position: Int) {
|
||||
val bean = getItemBean(item) ?: return
|
||||
binding.bean = bean
|
||||
binding.position = position
|
||||
binding.executePendingBindings()
|
||||
|
||||
// 添加卡片点击事件 - 查看详情
|
||||
notifyItemClick(position, binding.cardView)
|
||||
|
||||
// 添加选择图标点击事件 - 切换选择状态
|
||||
binding.ivCheck.setOnClickListener {
|
||||
// 反转checked状态
|
||||
bean.checked.set(!bean.checked.get())
|
||||
|
||||
// 立即更新UI
|
||||
binding.executePendingBindings()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package com.lukouguoji.gjj.viewModel
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.lukouguoji.gjj.R
|
||||
import com.lukouguoji.gjj.holder.IntImpMsgParseViewHolder
|
||||
import com.lukouguoji.module_base.base.BasePageViewModel
|
||||
import com.lukouguoji.module_base.bean.MsgReceivePool
|
||||
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.commonAdapter
|
||||
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 IntImpMsgParseViewModel : BasePageViewModel() {
|
||||
|
||||
// ========== 搜索条件 ==========
|
||||
val flightDate = MutableLiveData("") // 航班日期
|
||||
val flightNo = MutableLiveData("") // 航班号
|
||||
val sendAddress = MutableLiveData("") // 发站(择始发站)
|
||||
val receiveAddress = MutableLiveData("HFE") // 收报地址(目的站)
|
||||
val msgType = MutableLiveData("") // 报文类型
|
||||
|
||||
// ========== 统计信息 ==========
|
||||
val totalCount = MutableLiveData("0") // 合计条数
|
||||
|
||||
// ========== 全选状态 ==========
|
||||
val isAllChecked = MutableLiveData(false)
|
||||
|
||||
init {
|
||||
// 监听全选状态,自动更新所有列表项
|
||||
isAllChecked.observeForever { checked ->
|
||||
val list = pageModel.rv?.commonAdapter()?.items as? List<MsgReceivePool> ?: return@observeForever
|
||||
list.forEach { it.checked.set(checked) }
|
||||
pageModel.rv?.commonAdapter()?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 适配器配置 ==========
|
||||
val itemViewHolder = IntImpMsgParseViewHolder::class.java
|
||||
val itemLayoutId = R.layout.item_int_imp_msg_parse
|
||||
|
||||
/**
|
||||
* 搜索按钮点击
|
||||
*/
|
||||
fun searchClick() {
|
||||
refresh()
|
||||
}
|
||||
|
||||
/**
|
||||
* 全选按钮点击(切换全选状态)
|
||||
*/
|
||||
fun checkAllClick() {
|
||||
val list = pageModel.rv?.commonAdapter()?.items as? List<MsgReceivePool> ?: return
|
||||
|
||||
// 切换全选状态
|
||||
val shouldCheckAll = !isAllChecked.value!!
|
||||
list.forEach { it.checked.set(shouldCheckAll) }
|
||||
isAllChecked.value = shouldCheckAll
|
||||
|
||||
pageModel.rv?.commonAdapter()?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
/**
|
||||
* 电报生成(批量操作)
|
||||
*/
|
||||
fun generateMsg() {
|
||||
val list = pageModel.rv?.commonAdapter()?.items as? List<MsgReceivePool> ?: return
|
||||
val selectedItems = list.filter { it.isSelected }
|
||||
|
||||
if (selectedItems.isEmpty()) {
|
||||
showToast("请选择要生成的电报")
|
||||
return
|
||||
}
|
||||
|
||||
// 提取选中项的ID列表
|
||||
val ids = selectedItems.mapNotNull { it.id }
|
||||
val requestData = mapOf("ids" to ids).toRequestBody()
|
||||
|
||||
launchLoadingCollect({ NetApply.api.batchGenerateMsg(requestData) }) {
|
||||
onSuccess = {
|
||||
showToast("电报生成成功")
|
||||
viewModelScope.launch {
|
||||
FlowBus.with<String>(ConstantEvent.EVENT_REFRESH).emit("refresh")
|
||||
}
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据(重写BasePageViewModel)
|
||||
*/
|
||||
override fun getData() {
|
||||
// 构建搜索条件
|
||||
val filterParams = mutableMapOf(
|
||||
"fdate" to flightDate.value?.ifEmpty { null },
|
||||
"fno" to flightNo.value?.ifEmpty { null },
|
||||
"sendAddress" to sendAddress.value?.ifEmpty { null },
|
||||
"msgType" to msgType.value?.ifEmpty { null }
|
||||
)
|
||||
|
||||
// 列表参数(含分页)
|
||||
val listParams = (filterParams + mapOf(
|
||||
"pageNum" to pageModel.page,
|
||||
"pageSize" to pageModel.limit
|
||||
)).toRequestBody()
|
||||
|
||||
// 获取列表(带Loading)
|
||||
launchLoadingCollect({ NetApply.api.getIntImpMsgList(listParams) }) {
|
||||
onSuccess = { result ->
|
||||
// 处理PageInfo结构
|
||||
val pageInfo = result.data
|
||||
if (pageInfo != null) {
|
||||
val list = pageInfo.list ?: emptyList()
|
||||
val pages = pageInfo.pages ?: 1
|
||||
|
||||
// 更新统计信息
|
||||
totalCount.value = (pageInfo.total ?: 0).toString()
|
||||
|
||||
// 处理分页数据
|
||||
pageModel.handleDataList(list)
|
||||
pageModel.haveMore.postValue(pages > pageModel.page)
|
||||
} else {
|
||||
pageModel.handleDataList(emptyList())
|
||||
pageModel.haveMore.postValue(false)
|
||||
totalCount.value = "0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user