关联用户1
This commit is contained in:
@@ -7,6 +7,7 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.defenseapplication.databinding.ItemLinkedUserBinding
|
||||
|
||||
data class LinkedUser(
|
||||
val userId: String,
|
||||
val name: String,
|
||||
val phone: String,
|
||||
val idCard: String,
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package com.example.defenseapplication.bean
|
||||
|
||||
data class DeleteDeviceUserRequest(
|
||||
val userId: String,
|
||||
val deviceId: String
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.example.defenseapplication.bean
|
||||
|
||||
data class DeviceUserBean(
|
||||
val createDept: String? = null, //创建部门
|
||||
val createBy: String? = null, //创建人
|
||||
val updateBy: String? = null, //更新者
|
||||
val updateTime: String? = null, //更新时间
|
||||
val paramskeykey: String? = null,
|
||||
val deviceId: String? = null, // 设备 ID
|
||||
val deviceNo: String? = null, // 设备编号
|
||||
val deviceName: String? = null, // 设备名称
|
||||
val userId: String? = null, // 用户 ID
|
||||
val nickName: String? = null, // 用户昵称
|
||||
val idCard: String? = null, // 身份证号
|
||||
val phonenumber: String? = null, // 手机号码
|
||||
val createTime: String? = null // 创建时间
|
||||
)
|
||||
@@ -2,17 +2,27 @@ package com.example.defenseapplication.liveVideo
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.adapter.LinkedUser
|
||||
import com.example.defenseapplication.adapter.LinkedUserAdapter
|
||||
import com.example.defenseapplication.bean.DeleteDeviceUserRequest
|
||||
import com.example.defenseapplication.bean.DeviceUserBean
|
||||
import com.example.defenseapplication.databinding.LinkedUserActivityBinding
|
||||
import com.example.defenseapplication.utils.DeviceIdEvent
|
||||
import com.example.defenseapplication.utils.RetrofitNetwork
|
||||
import com.example.defenseapplication.view.CustomDialogFragmentText
|
||||
import com.gyf.immersionbar.ImmersionBar
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
//关联用户页面
|
||||
class LinkedUserActivity : AppCompatActivity() {
|
||||
|
||||
@@ -152,9 +162,7 @@ class LinkedUserActivity : AppCompatActivity() {
|
||||
dialog.setPositiveText(getString(R.string.confirm))
|
||||
dialog.setNegativeText(getString(R.string.cancel))
|
||||
dialog.setOnConfirmListener {
|
||||
userList.removeAt(position)
|
||||
adapter.removeItem(position)
|
||||
resetSwipeState()
|
||||
deleteDeviceUser(user, position)
|
||||
}
|
||||
dialog.setOnDismissListener {
|
||||
resetSwipeState()
|
||||
@@ -162,6 +170,41 @@ class LinkedUserActivity : AppCompatActivity() {
|
||||
dialog.show(supportFragmentManager, "UnlinkDialog")
|
||||
}
|
||||
|
||||
private fun deleteDeviceUser(user: LinkedUser, position: Int) {
|
||||
val deviceId = DeviceIdEvent.getDeviceId()
|
||||
if (deviceId.isNullOrEmpty() || user.userId.isEmpty()) {
|
||||
Toast.makeText(this, "参数错误", Toast.LENGTH_SHORT).show()
|
||||
resetSwipeState()
|
||||
return
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val request = DeleteDeviceUserRequest(
|
||||
userId = user.userId,
|
||||
deviceId = deviceId
|
||||
)
|
||||
val response = RetrofitNetwork.getNetworkService().deleteDeviceUser(request)
|
||||
withContext(Dispatchers.Main) {
|
||||
if (response.code == 200) {
|
||||
userList.removeAt(position)
|
||||
adapter.removeItem(position)
|
||||
Toast.makeText(this@LinkedUserActivity, "删除成功", Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
Toast.makeText(this@LinkedUserActivity, response.msg, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
resetSwipeState()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(this@LinkedUserActivity, "网络请求失败", Toast.LENGTH_SHORT).show()
|
||||
resetSwipeState()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun resetSwipeState() {
|
||||
if (currentSwipePosition >= 0 && currentSwipeHeld) {
|
||||
binding.rvLinkedUser.post {
|
||||
@@ -179,10 +222,48 @@ class LinkedUserActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun initData() {
|
||||
fetchDeviceUserList()
|
||||
}
|
||||
|
||||
private fun fetchDeviceUserList() {
|
||||
val deviceId = DeviceIdEvent.getDeviceId()
|
||||
if (deviceId.isNullOrEmpty()) {
|
||||
Toast.makeText(this, "设备 ID 为空", Toast.LENGTH_SHORT).show()
|
||||
return
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val response = RetrofitNetwork.getNetworkService().getDeviceUserList(deviceId)
|
||||
withContext(Dispatchers.Main) {
|
||||
if (response.code == 200 && response.data != null) {
|
||||
updateDeviceUserList(response.data)
|
||||
} else {
|
||||
Toast.makeText(this@LinkedUserActivity, response.msg, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
withContext(Dispatchers.Main) {
|
||||
Toast.makeText(this@LinkedUserActivity, "网络请求失败", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateDeviceUserList(deviceUserList: List<DeviceUserBean>) {
|
||||
userList.clear()
|
||||
userList.add(LinkedUser("张三", "12388888888", "123456789012345678", "2026-05-06 16:03:26"))
|
||||
userList.add(LinkedUser("李四", "13899999999", "987654321098765432", "2026-05-05 14:20:15"))
|
||||
userList.add(LinkedUser("王五", "15977777777", "456123789012345678", "2026-05-04 10:15:30"))
|
||||
deviceUserList.forEach { deviceUser ->
|
||||
userList.add(
|
||||
LinkedUser(
|
||||
userId = deviceUser.userId ?: "",
|
||||
name = deviceUser.nickName ?: "未知用户",
|
||||
phone = deviceUser.phonenumber ?: "",
|
||||
idCard = deviceUser.idCard ?: "",
|
||||
time = deviceUser.createTime ?: ""
|
||||
)
|
||||
)
|
||||
}
|
||||
adapter.submitList(userList)
|
||||
}
|
||||
|
||||
@@ -222,6 +303,7 @@ class LinkedUserActivity : AppCompatActivity() {
|
||||
if (requestCode == REQUEST_CODE_SEARCH && resultCode == RESULT_OK) {
|
||||
data?.getStringExtra(EXTRA_SEARCH_RESULT)?.let { result ->
|
||||
val newUser = LinkedUser(
|
||||
userId = "",
|
||||
name = result,
|
||||
phone = "13800000000",
|
||||
idCard = "110101199001011234",
|
||||
|
||||
@@ -4,8 +4,10 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.widget.Toast
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.base.BaseActivity
|
||||
import com.example.defenseapplication.bean.DeviceUserBean
|
||||
import com.example.defenseapplication.databinding.SettingsActivityBinding
|
||||
import com.example.defenseapplication.utils.DeviceIdEvent
|
||||
import com.example.defenseapplication.utils.LanguageUtil
|
||||
@@ -146,14 +148,14 @@ class SettingsActivity : BaseActivity() {
|
||||
return
|
||||
}
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val response = RetrofitNetwork.getNetworkService().getDeviceInfo(deviceId)
|
||||
val deviceResponse = RetrofitNetwork.getNetworkService().getDeviceInfo(deviceId)
|
||||
withContext(Dispatchers.Main) {
|
||||
if (response.code == 200 && response.data != null) {
|
||||
updateDeviceInfo(response.data)
|
||||
if (deviceResponse.code == 200 && deviceResponse.data != null) {
|
||||
updateDeviceInfo(deviceResponse.data)
|
||||
} else {
|
||||
Toast.makeText(this@SettingsActivity, response.msg, Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(this@SettingsActivity, deviceResponse.msg, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
@@ -163,6 +165,32 @@ class SettingsActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fetchDeviceUserList()
|
||||
}
|
||||
|
||||
private fun fetchDeviceUserList() {
|
||||
val deviceId = DeviceIdEvent.getDeviceId()
|
||||
if (deviceId.isNullOrEmpty()) {
|
||||
return
|
||||
}
|
||||
|
||||
lifecycleScope.launch {
|
||||
try {
|
||||
val response = RetrofitNetwork.getNetworkService().getDeviceUserList(deviceId)
|
||||
withContext(Dispatchers.Main) {
|
||||
if (response.code == 200 && response.data != null) {
|
||||
updateRelatedUsersCount(response.data.size)
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateRelatedUsersCount(count: Int) {
|
||||
binding.tvRelatedUsers.text = "$count 人"
|
||||
}
|
||||
|
||||
private fun updateDeviceInfo(device: com.example.defenseapplication.bean.DeviceBean) {
|
||||
|
||||
@@ -2,12 +2,14 @@ package com.example.defenseapplication.utils
|
||||
|
||||
import bean.ForgotRequest
|
||||
import com.example.defenseapplication.bean.DeviceBean
|
||||
import com.example.defenseapplication.bean.DeviceUserBean
|
||||
import com.example.defenseapplication.bean.FamilyBean
|
||||
import com.example.defenseapplication.bean.GetCodeBean
|
||||
import bean.LoginBean
|
||||
import bean.LoginRequest
|
||||
import bean.RegisterRequest
|
||||
import com.example.defenseapplication.bean.DeleteBean
|
||||
import com.example.defenseapplication.bean.DeleteDeviceUserRequest
|
||||
import com.example.defenseapplication.bean.MessageGroup
|
||||
import com.example.defenseapplication.bean.SwitchFamilyRequest
|
||||
import retrofit2.http.Body
|
||||
@@ -82,5 +84,25 @@ interface ApiService {
|
||||
@POST("/app/deleteDevice")
|
||||
suspend fun deleteDevice(@Body deleteBean: DeleteBean): GetCodeBean<DeleteBean>
|
||||
|
||||
/**
|
||||
* 查看设备关联用户列表
|
||||
*/
|
||||
@GET("/app/deviceUser/list/{deviceId}")
|
||||
suspend fun getDeviceUserList(
|
||||
@retrofit2.http.Path("deviceId") deviceId: String,
|
||||
@Query("deviceNo") deviceNo: String? = null,
|
||||
@Query("deviceName") deviceName: String? = null,
|
||||
@Query("userId") userId: String? = null,
|
||||
@Query("nickName") nickName: String? = null,
|
||||
@Query("idCard") idCard: String? = null,
|
||||
@Query("phonenumber") phonenumber: String? = null
|
||||
): GetCodeBean<List<DeviceUserBean>>
|
||||
|
||||
/**
|
||||
* 删除关联用户
|
||||
*/
|
||||
@POST("/app/deleteDeviceUser")
|
||||
suspend fun deleteDeviceUser(@Body request: DeleteDeviceUserRequest): GetCodeBean<Any>
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user