餐盘柜接口改造
This commit is contained in:
Generated
+1
-1
@@ -4,6 +4,7 @@
|
|||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
|
<option name="testRunner" value="CHOOSE_PER_TEST" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleJvm" value="azul-17" />
|
<option name="gradleJvm" value="azul-17" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
@@ -13,7 +14,6 @@
|
|||||||
<option value="$PROJECT_DIR$/lib_face" />
|
<option value="$PROJECT_DIR$/lib_face" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
</option>
|
||||||
<option name="resolveExternalAnnotations" value="false" />
|
|
||||||
</GradleProjectSettings>
|
</GradleProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ object GlobalData {
|
|||||||
/**
|
/**
|
||||||
* 具体业务baseurl
|
* 具体业务baseurl
|
||||||
*/
|
*/
|
||||||
var appBaseUrl: String = ""
|
var appBaseUrl: String = "https://dev.yixiong-tech.com:8081"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备id
|
* 设备id
|
||||||
|
|||||||
@@ -26,5 +26,7 @@ class MyApp : App() {
|
|||||||
private fun initGlobalData() {
|
private fun initGlobalData() {
|
||||||
GlobalData.appVersion = AppUtil.getAppVersionCode(this).toString()
|
GlobalData.appVersion = AppUtil.getAppVersionCode(this).toString()
|
||||||
GlobalData.globalEquipmentCode = "202501171634"
|
GlobalData.globalEquipmentCode = "202501171634"
|
||||||
|
|
||||||
|
GlobalData.appBaseUrl = "http://192.168.1.201:14801"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,8 +17,11 @@ import androidx.core.view.WindowCompat
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import com.sw.inbound.utils.DateTimeUtils
|
import com.sw.inbound.utils.DateTimeUtils
|
||||||
|
import com.sw.plate.utils.Base64
|
||||||
import com.sw.plate.utils.ScanGunKeyEventHelper
|
import com.sw.plate.utils.ScanGunKeyEventHelper
|
||||||
import com.sw.plate.utils.ToastUtils
|
import com.sw.plate.utils.ToastUtils
|
||||||
|
import com.sw.plate.utils.arcface.facedb.FaceDatabase
|
||||||
|
import com.sw.plate.utils.arcface.facedb.entity.FaceEntity
|
||||||
import com.sw.plate.utils.comn.SerialApi
|
import com.sw.plate.utils.comn.SerialApi
|
||||||
import com.sw.plate.utils.comn.SerialPortManager
|
import com.sw.plate.utils.comn.SerialPortManager
|
||||||
import com.sw.platecabinet.R
|
import com.sw.platecabinet.R
|
||||||
@@ -26,7 +29,10 @@ import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
|||||||
import com.sw.platecabinet.dialog.BalanceNotEnoughDialog
|
import com.sw.platecabinet.dialog.BalanceNotEnoughDialog
|
||||||
import com.sw.platecabinet.ext.setClickListeners
|
import com.sw.platecabinet.ext.setClickListeners
|
||||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||||
|
import com.sw.platecabinet.model.response.UserFaceModel
|
||||||
|
import com.sw.platecabinet.utils.IntervalExecutor
|
||||||
import com.sw.platecabinet.utils.PermissionHelper
|
import com.sw.platecabinet.utils.PermissionHelper
|
||||||
|
import com.sw.platecabinet.utils.SpTool
|
||||||
import com.sw.platecabinet.view.CustomLoadingDialog
|
import com.sw.platecabinet.view.CustomLoadingDialog
|
||||||
import com.sw.platecabinet.viewmodel.SettingViewModel
|
import com.sw.platecabinet.viewmodel.SettingViewModel
|
||||||
import com.sw.platecabinet.viewmodel.UserViewModel
|
import com.sw.platecabinet.viewmodel.UserViewModel
|
||||||
@@ -77,6 +83,8 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
registerKeyEvent()
|
registerKeyEvent()
|
||||||
val durationTime = System.currentTimeMillis() - startTime
|
val durationTime = System.currentTimeMillis() - startTime
|
||||||
Timber.d("启动时间:$durationTime")
|
Timber.d("启动时间:$durationTime")
|
||||||
|
|
||||||
|
startFaceTask()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -291,23 +299,27 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
handleLoginSuccess(it, true)
|
handleLoginSuccess(it, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
settingViewModel.equipmentList.collect {
|
// settingViewModel.equipmentList.collect {
|
||||||
if (it.isEmpty()) return@collect
|
// loadEquipmentList(it)
|
||||||
val unbindList = it.filter { !it.isBound() }
|
// }
|
||||||
if (unbindList.isEmpty()) {
|
// }
|
||||||
MainActivity.start(context = context, pageType = PageType.PLATE_CABINET_FULL)
|
}
|
||||||
} else {
|
|
||||||
val firstInfo = unbindList[0]
|
private fun loadEquipmentList(items:List<EquipmentUserInfo>) {
|
||||||
val currentUserInfo = settingViewModel.searchUserInfo.value
|
if (items.isEmpty()) return
|
||||||
firstInfo.plateNumber = currentUserInfo?.plateNumber ?: ""
|
val unbindList = items.filter { !it.isBound() }
|
||||||
MainActivity.start(
|
if (unbindList.isEmpty()) {
|
||||||
context = context,
|
MainActivity.start(context = context, pageType = PageType.PLATE_CABINET_FULL)
|
||||||
pageType = PageType.BIND_PLATE,
|
} else {
|
||||||
equipmentUserInfo = firstInfo
|
val firstInfo = unbindList[0]
|
||||||
)
|
val currentUserInfo = settingViewModel.searchUserInfo.value
|
||||||
}
|
firstInfo.plateNumber = currentUserInfo?.plateNumber ?: ""
|
||||||
}
|
MainActivity.start(
|
||||||
|
context = context,
|
||||||
|
pageType = PageType.BIND_PLATE,
|
||||||
|
equipmentUserInfo = firstInfo
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,7 +364,9 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (isAdmin) {
|
if (isAdmin) {
|
||||||
settingViewModel.getEquipmentList()
|
settingViewModel.getEquipmentList{
|
||||||
|
loadEquipmentList(it)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Timber.d("无餐盘信息")
|
Timber.d("无餐盘信息")
|
||||||
MainActivity.start(
|
MainActivity.start(
|
||||||
@@ -370,4 +384,66 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
keyEventHelper?.onDestroy()
|
keyEventHelper?.onDestroy()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private val intervalExecutor by lazy { IntervalExecutor() }
|
||||||
|
private var faceTaskJob: Job? = null
|
||||||
|
|
||||||
|
// private val initialDelay = 5 * 60 * 1000L
|
||||||
|
// private val dealyMillis = 10 * 60 * 1000L
|
||||||
|
private val initialDelay = 60 * 1000L
|
||||||
|
private val dealyMillis = 30 * 1000L
|
||||||
|
private var taskPageNo = 1
|
||||||
|
fun startFaceTask() {
|
||||||
|
faceTaskJob =
|
||||||
|
intervalExecutor.startIntervalTaskWithInitialDelay(initialDelay, dealyMillis) {
|
||||||
|
settingViewModel.getFaceIncrementList(
|
||||||
|
pageNo = taskPageNo,
|
||||||
|
timestamp = SpTool.getLastFaceTimestamp()
|
||||||
|
) { list ->
|
||||||
|
runOnUiThread {
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
return@runOnUiThread
|
||||||
|
}
|
||||||
|
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
|
||||||
|
updateFaceData(list)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateFaceData(list: List<UserFaceModel>) {
|
||||||
|
Thread {
|
||||||
|
val faceList = mutableListOf<FaceEntity>()
|
||||||
|
try {
|
||||||
|
list.forEach { model ->
|
||||||
|
if (model.faceDeleted == true) {
|
||||||
|
//删除数据
|
||||||
|
FaceDatabase.getInstance(this).faceDao().deleteFaceById(model.userId)
|
||||||
|
} else {
|
||||||
|
//保存数据
|
||||||
|
val faceEntity = FaceEntity(
|
||||||
|
model.userId,
|
||||||
|
null,
|
||||||
|
Base64.decode(model.faceFeatureStr)
|
||||||
|
).also {
|
||||||
|
it.userType = "1"
|
||||||
|
}
|
||||||
|
faceList.add(faceEntity)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (faceList.isNotEmpty()) {
|
||||||
|
FaceDatabase.getInstance(this).faceDao().insert(faceList)
|
||||||
|
}
|
||||||
|
recognizeViewModel.refreshFaceList();
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}.start()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,24 +1,19 @@
|
|||||||
package com.sw.platecabinet.activity
|
package com.sw.platecabinet.activity
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.activity.viewModels
|
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import com.sw.plate.utils.AppUtil
|
import com.sw.plate.utils.AppUtil
|
||||||
import com.sw.platecabinet.GlobalData
|
import com.sw.platecabinet.GlobalData
|
||||||
import com.sw.platecabinet.databinding.ActivityDeviceInitBinding
|
import com.sw.platecabinet.databinding.ActivityDeviceInitBinding
|
||||||
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
||||||
import com.sw.platecabinet.utils.QRCodeUtil
|
import com.sw.platecabinet.ext.gone
|
||||||
import com.sw.platecabinet.viewmodel.DeviceViewModel
|
import com.sw.platecabinet.ext.invisible
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import timber.log.Timber
|
|
||||||
import kotlin.getValue
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备初始化界面
|
* 设备初始化界面
|
||||||
*/
|
*/
|
||||||
class DeviceInitActivity : BaseActivity<ActivityDeviceInitBinding>() {
|
class DeviceInitActivity : BaseActivity<ActivityDeviceInitBinding>() {
|
||||||
|
|
||||||
private val deviceViewModel by viewModels<DeviceViewModel>()
|
// private val deviceViewModel by viewModels<DeviceViewModel>()
|
||||||
|
|
||||||
override fun inflateViewBinding(): ActivityDeviceInitBinding {
|
override fun inflateViewBinding(): ActivityDeviceInitBinding {
|
||||||
return ActivityDeviceInitBinding.inflate(layoutInflater)
|
return ActivityDeviceInitBinding.inflate(layoutInflater)
|
||||||
@@ -32,31 +27,36 @@ class DeviceInitActivity : BaseActivity<ActivityDeviceInitBinding>() {
|
|||||||
var deviceId = AppUtil.getUDID(this)
|
var deviceId = AppUtil.getUDID(this)
|
||||||
deviceId = "be154831-3466-3ba2-a2ea-57652c919fed"
|
deviceId = "be154831-3466-3ba2-a2ea-57652c919fed"
|
||||||
GlobalData.deviceId = deviceId
|
GlobalData.deviceId = deviceId
|
||||||
val isSuccess = deviceViewModel.checkEquipmentInfo()
|
// val isSuccess = deviceViewModel.checkEquipmentInfo()
|
||||||
if (isSuccess) {
|
// if (isSuccess) {
|
||||||
|
// goLoginActivity()
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
// binding.ivQrCode.setImageBitmap(
|
||||||
|
// QRCodeUtil.generateQRCode(
|
||||||
|
// content = GlobalData.deviceId,
|
||||||
|
// size = 200
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// binding.btnInit.setOnClickListener {
|
||||||
|
// deviceViewModel.getDeviceToken()
|
||||||
|
// }
|
||||||
|
binding.btnInit.gone()
|
||||||
|
binding.ivQrCode.invisible()
|
||||||
|
binding.root.postDelayed({
|
||||||
goLoginActivity()
|
goLoginActivity()
|
||||||
return
|
}, 1000)
|
||||||
}
|
|
||||||
binding.ivQrCode.setImageBitmap(
|
|
||||||
QRCodeUtil.generateQRCode(
|
|
||||||
content = GlobalData.deviceId,
|
|
||||||
size = 200
|
|
||||||
)
|
|
||||||
)
|
|
||||||
binding.btnInit.setOnClickListener {
|
|
||||||
deviceViewModel.getDeviceToken()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun registerDataChange() {
|
override fun registerDataChange() {
|
||||||
super.registerDataChange()
|
super.registerDataChange()
|
||||||
lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
deviceViewModel.deviceInfoResult.collect { it ->
|
// deviceViewModel.deviceInfoResult.collect { it ->
|
||||||
if (it == true) {
|
// if (it == true) {
|
||||||
goLoginActivity()
|
// goLoginActivity()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun goLoginActivity() {
|
private fun goLoginActivity() {
|
||||||
|
|||||||
@@ -79,7 +79,10 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
initArcView()
|
initArcView()
|
||||||
openRectInfoDraw = true
|
openRectInfoDraw = true
|
||||||
recognizeViewModel.setDrawRectInfoTextValue(true)
|
recognizeViewModel.setDrawRectInfoTextValue(true)
|
||||||
viewModel.generateToken()
|
//viewModel.generateToken()
|
||||||
|
viewModel.activeEngine()
|
||||||
|
viewModel.getUserFaceCache()
|
||||||
|
|
||||||
binding.llToPwd.setOnClickListener {
|
binding.llToPwd.setOnClickListener {
|
||||||
val intent = Intent(this, LoginByPwdActivity::class.java)
|
val intent = Intent(this, LoginByPwdActivity::class.java)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
@@ -169,7 +172,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
|
|
||||||
recognizeViewModel.recognizeUserId.observe(this, Observer { userId: String? ->
|
recognizeViewModel.recognizeUserId.observe(this, Observer { userId: String? ->
|
||||||
Timber.i("recognizeUserId observe userId = $userId")
|
Timber.i("recognizeUserId observe userId = $userId")
|
||||||
viewModel.getUserInfoById(memberId = userId?.toInt() ?: 0)
|
viewModel.getUserInfoById(memberId = userId?.toIntOrNull())
|
||||||
})
|
})
|
||||||
|
|
||||||
recognizeViewModel.drawRectInfoText.observe(this, Observer { info ->
|
recognizeViewModel.drawRectInfoText.observe(this, Observer { info ->
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.sw.plate.utils.ToastUtils
|
|||||||
import com.sw.platecabinet.databinding.ActivityLoginByPwdBinding
|
import com.sw.platecabinet.databinding.ActivityLoginByPwdBinding
|
||||||
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
||||||
import com.sw.platecabinet.dialog.BalanceNotEnoughDialog
|
import com.sw.platecabinet.dialog.BalanceNotEnoughDialog
|
||||||
|
import com.sw.platecabinet.model.request.LoginParam
|
||||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||||
import com.sw.platecabinet.utils.KeyboardUtils
|
import com.sw.platecabinet.utils.KeyboardUtils
|
||||||
|
|
||||||
@@ -29,7 +30,12 @@ class LoginByPwdActivity : BaseActivity<ActivityLoginByPwdBinding>() {
|
|||||||
ToastUtils.showToast("手机或校验码不能为空")
|
ToastUtils.showToast("手机或校验码不能为空")
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
viewModel.loginWithPwd(phone = phone, password = pwd)
|
val loginParam = LoginParam(
|
||||||
|
//equipmentId = equipmentId,
|
||||||
|
phone = phone,
|
||||||
|
password = pwd
|
||||||
|
)
|
||||||
|
viewModel.loginWithPwd(loginParam)
|
||||||
KeyboardUtils.hideKeyboard(this)
|
KeyboardUtils.hideKeyboard(this)
|
||||||
}
|
}
|
||||||
binding.tvFaceRec.setOnClickListener {
|
binding.tvFaceRec.setOnClickListener {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.sw.platecabinet.ext
|
|||||||
|
|
||||||
import android.content.res.Resources
|
import android.content.res.Resources
|
||||||
import android.util.TypedValue
|
import android.util.TypedValue
|
||||||
|
import android.view.View
|
||||||
import androidx.annotation.Dimension
|
import androidx.annotation.Dimension
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,3 +52,15 @@ val Float.sp: Float
|
|||||||
fun formatNumber(num: String): String {
|
fun formatNumber(num: String): String {
|
||||||
return num.padStart(2, '0')
|
return num.padStart(2, '0')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun View.visible() {
|
||||||
|
visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
fun View.invisible() {
|
||||||
|
visibility = View.INVISIBLE
|
||||||
|
}
|
||||||
|
|
||||||
|
fun View.gone() {
|
||||||
|
visibility = View.GONE
|
||||||
|
}
|
||||||
@@ -24,6 +24,8 @@ import com.sw.platecabinet.databinding.ItemSearchUserInfoBinding
|
|||||||
import com.sw.platecabinet.dialog.UserBindRemindDialog
|
import com.sw.platecabinet.dialog.UserBindRemindDialog
|
||||||
import com.sw.platecabinet.ext.maskName
|
import com.sw.platecabinet.ext.maskName
|
||||||
import com.sw.platecabinet.ext.maskPhone
|
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.EquipmentUserInfo
|
||||||
import com.sw.platecabinet.model.response.SearchResult
|
import com.sw.platecabinet.model.response.SearchResult
|
||||||
import com.sw.platecabinet.utils.Debouncer
|
import com.sw.platecabinet.utils.Debouncer
|
||||||
@@ -188,13 +190,16 @@ class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
|
|||||||
ToastUtils.showToast("选中的会员信息异常")
|
ToastUtils.showToast("选中的会员信息异常")
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
}
|
}
|
||||||
|
val bindParam = BindParam(
|
||||||
viewModel.bindPlate(
|
equipmentId = info!!.equipmentId,
|
||||||
equipmentCode = info!!.equipmentCode!!,
|
equipmentCode = info!!.equipmentCode!!,
|
||||||
equipmentBoxCode = info!!.equipmentBoxCode!!,
|
equipmentBoxCode = info!!.equipmentBoxCode!!,
|
||||||
memberId = checkedItem!!.id!!,
|
memberId = checkedItem!!.id!!,
|
||||||
plateNumber = plateNumber
|
plateNumber = plateNumber
|
||||||
)
|
)
|
||||||
|
viewModel.bindPlate(bindParam) { pair ->
|
||||||
|
updateBindState(pair)
|
||||||
|
}
|
||||||
KeyboardUtils.hideKeyboard(requireActivity())
|
KeyboardUtils.hideKeyboard(requireActivity())
|
||||||
}
|
}
|
||||||
binding.tvBack.setOnClickListener { activity?.finish() }
|
binding.tvBack.setOnClickListener { activity?.finish() }
|
||||||
@@ -210,41 +215,11 @@ class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
|
|||||||
adapter.updateData(it)
|
adapter.updateData(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
viewModel.bindStateChange.collect {
|
// viewModel.bindStateChange.collect {
|
||||||
if (it.first == null) return@collect // 解绑状态过滤
|
// updateBindState(it)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createAdapter(): GenericItemAdapter<SearchResult.Member, ItemSearchUserInfoBinding> {
|
private fun createAdapter(): GenericItemAdapter<SearchResult.Member, ItemSearchUserInfoBinding> {
|
||||||
@@ -267,7 +242,7 @@ class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
|
|||||||
//TODO 调用接口查询用户是否已绑盘
|
//TODO 调用接口查询用户是否已绑盘
|
||||||
this@BindPlateFragment.equipmentBoxCode = null
|
this@BindPlateFragment.equipmentBoxCode = null
|
||||||
(activity as? MainActivity)?.showWaitingDialog("查询中,请稍后……")
|
(activity as? MainActivity)?.showWaitingDialog("查询中,请稍后……")
|
||||||
userViewModel.getUserInfoById(memberId = item.id!!) {
|
userViewModel.getUserInfoById(memberId = item.id) {
|
||||||
(activity as? MainActivity)?.hideWaitingDialog()
|
(activity as? MainActivity)?.hideWaitingDialog()
|
||||||
this@BindPlateFragment.equipmentBoxCode = it?.equipmentBoxCode
|
this@BindPlateFragment.equipmentBoxCode = it?.equipmentBoxCode
|
||||||
}
|
}
|
||||||
@@ -285,4 +260,38 @@ class BindPlateFragment : BaseFragment<FragmentBindPlateBinding>(
|
|||||||
)
|
)
|
||||||
.show()
|
.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() {
|
override fun registerDataChange() {
|
||||||
super.registerDataChange()
|
super.registerDataChange()
|
||||||
lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
viewModel.equipmentList.collect { it ->
|
// viewModel.equipmentList.collect { it ->
|
||||||
Timber.d("registerDateChange updateAdapter it = $it")
|
// Timber.d("registerDateChange updateAdapter it = $it")
|
||||||
updateAdapter(it)
|
// updateAdapter(it)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
@@ -80,7 +80,9 @@ class SettingListFragment :
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
viewModel.getEquipmentList()
|
viewModel.getEquipmentList{
|
||||||
|
updateAdapter(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createItemAdapter(): GenericItemAdapter<EquipmentUserInfo, ItemBindViewBinding> {
|
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.databinding.FragmentUnbindPlateBinding
|
||||||
import com.sw.platecabinet.ext.maskName
|
import com.sw.platecabinet.ext.maskName
|
||||||
import com.sw.platecabinet.ext.maskPhone
|
import com.sw.platecabinet.ext.maskPhone
|
||||||
|
import com.sw.platecabinet.model.ErrorInfo
|
||||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@@ -38,16 +39,15 @@ class UnBindPlateFragment private constructor() : BaseFragment<FragmentUnbindPla
|
|||||||
ActivityResultContracts.StartActivityForResult()
|
ActivityResultContracts.StartActivityForResult()
|
||||||
) { result ->
|
) { result ->
|
||||||
if (result.resultCode == Activity.RESULT_OK) {
|
if (result.resultCode == Activity.RESULT_OK) {
|
||||||
viewModel.unbindPlate(
|
viewModel.unbindPlate(info!!.id!!) { pair ->
|
||||||
equipmentBoxCode = info!!.equipmentBoxCode!!,
|
updateBindState(pair)
|
||||||
equipmentCode = info!!.equipmentCode!!
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
arguments?.let {
|
arguments?.let { args ->
|
||||||
info = it.getParcelable(ARG_PARAM1)
|
info = args.getParcelable(ARG_PARAM1)
|
||||||
info?.let {
|
info?.let {
|
||||||
binding.tvNum.text = "${it.equipmentName}-${it.equipmentBoxCode}"
|
binding.tvNum.text = "${it.equipmentName}-${it.equipmentBoxCode}"
|
||||||
binding.tvPlateNumberValue.text = it.plateNumber
|
binding.tvPlateNumberValue.text = it.plateNumber
|
||||||
@@ -73,20 +73,23 @@ class UnBindPlateFragment private constructor() : BaseFragment<FragmentUnbindPla
|
|||||||
|
|
||||||
override fun registerDataChange() {
|
override fun registerDataChange() {
|
||||||
super.registerDataChange()
|
super.registerDataChange()
|
||||||
lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
viewModel.bindStateChange.collect {
|
// viewModel.bindStateChange.collect {
|
||||||
if (it.first == null) return@collect // 绑定状态过滤
|
// updateBindState(it)
|
||||||
val errorInfo = it.second
|
// }
|
||||||
if (errorInfo.isSuccess()) {
|
// }
|
||||||
ToastUtils.showToast("解绑成功")
|
}
|
||||||
|
private fun updateBindState(pair: Pair<Boolean?, ErrorInfo>){
|
||||||
|
if (pair.first == null) return // 绑定状态过滤
|
||||||
|
val errorInfo = pair.second
|
||||||
|
if (errorInfo.isSuccess()) {
|
||||||
|
ToastUtils.showToast("解绑成功")
|
||||||
// activity?.finish()
|
// activity?.finish()
|
||||||
// 关闭宿主 Activity
|
// 关闭宿主 Activity
|
||||||
requireActivity().finish()
|
requireActivity().finish()
|
||||||
requireActivity().overridePendingTransition(0, 0)
|
requireActivity().overridePendingTransition(0, 0)
|
||||||
} else {
|
} else {
|
||||||
ToastUtils.showToast(errorInfo.msg)
|
ToastUtils.showToast(errorInfo.msg)
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,28 +12,24 @@ import kotlinx.parcelize.Parcelize
|
|||||||
@Parcelize
|
@Parcelize
|
||||||
data class BindParam(
|
data class BindParam(
|
||||||
/**
|
/**
|
||||||
* app版本号
|
* 设备Id
|
||||||
*/
|
*/
|
||||||
var appVersion: String = "",
|
val equipmentId: Int? = null,
|
||||||
/**
|
/**
|
||||||
* 设备ID
|
* 设备编号
|
||||||
*/
|
*/
|
||||||
@SerializedName("equipmentCode")
|
|
||||||
var equipmentCode: String = "",
|
var equipmentCode: String = "",
|
||||||
/**
|
/**
|
||||||
*设备盒子编号
|
*设备盒子编号
|
||||||
*/
|
*/
|
||||||
@SerializedName("equipmentBoxCode")
|
|
||||||
val equipmentBoxCode: String? = null,
|
val equipmentBoxCode: String? = null,
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 会员Id
|
* 会员Id
|
||||||
*/
|
*/
|
||||||
@SerializedName("memberId")
|
|
||||||
val memberId: Int? = null,
|
val memberId: Int? = null,
|
||||||
/**
|
/**
|
||||||
*餐盘编号
|
*餐盘编号
|
||||||
*/
|
*/
|
||||||
@SerializedName("plateNumber")
|
|
||||||
val plateNumber: String? = null
|
val plateNumber: String? = null
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
@@ -11,27 +11,19 @@ import kotlinx.parcelize.Parcelize
|
|||||||
@Parcelize
|
@Parcelize
|
||||||
data class LoginParam(
|
data class LoginParam(
|
||||||
/**
|
/**
|
||||||
* app版本号
|
* 设备Id
|
||||||
*/
|
*/
|
||||||
var appVersion: String = "",
|
val equipmentId: Int? = null,
|
||||||
/**
|
|
||||||
* 设备ID
|
|
||||||
*/
|
|
||||||
@SerializedName("equipmentCode")
|
|
||||||
var equipmentCode: String = "",
|
|
||||||
/**
|
/**
|
||||||
* 会员信息
|
* 会员信息
|
||||||
*/
|
*/
|
||||||
@SerializedName("memberId")
|
|
||||||
val memberId: Int? = null,
|
val memberId: Int? = null,
|
||||||
/**
|
/**
|
||||||
* 密码
|
* 密码
|
||||||
*/
|
*/
|
||||||
@SerializedName("password")
|
|
||||||
val password: String? = null,
|
val password: String? = null,
|
||||||
/**
|
/**
|
||||||
* 手机号
|
* 手机号
|
||||||
*/
|
*/
|
||||||
@SerializedName("phone")
|
|
||||||
val phone: String? = null
|
val phone: String? = null
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
package com.sw.platecabinet.model.response
|
package com.sw.platecabinet.model.response
|
||||||
|
|
||||||
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.text.TextUtils
|
import android.text.TextUtils
|
||||||
import com.google.gson.annotations.SerializedName
|
//import com.google.gson.annotations.SerializedName
|
||||||
import com.sw.platecabinet.GlobalData
|
import com.sw.platecabinet.GlobalData
|
||||||
import kotlinx.parcelize.Parcelize
|
import kotlinx.parcelize.Parcelize
|
||||||
|
|
||||||
@@ -13,55 +12,51 @@ import kotlinx.parcelize.Parcelize
|
|||||||
@Parcelize
|
@Parcelize
|
||||||
data class EquipmentUserInfo(
|
data class EquipmentUserInfo(
|
||||||
/**
|
/**
|
||||||
* 设备盒子编号
|
* 主键
|
||||||
*/
|
*/
|
||||||
@SerializedName("equipmentBoxCode")
|
val id: Int? = 0,
|
||||||
var equipmentBoxCode: String? = "",
|
|
||||||
/**
|
|
||||||
* 设备编号
|
|
||||||
*/
|
|
||||||
@SerializedName("equipmentCode")
|
|
||||||
var equipmentCode: String? = "",
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 设备Id
|
* 设备Id
|
||||||
*/
|
*/
|
||||||
@SerializedName("equipmentId")
|
val equipmentId: Int? = 0,
|
||||||
val equipmentId: String? = "",
|
|
||||||
/**
|
/**
|
||||||
* 设备名称
|
* 设备编号
|
||||||
*/
|
*/
|
||||||
@SerializedName("equipmentName")
|
var equipmentCode: String? = "",
|
||||||
val equipmentName: String? = "",
|
|
||||||
/**
|
/**
|
||||||
* 主键
|
* 设备盒子编号
|
||||||
*/
|
*/
|
||||||
@SerializedName("id")
|
var equipmentBoxCode: String? = "",
|
||||||
val id: Int? = 0,
|
|
||||||
/**
|
/**
|
||||||
* 会员Id
|
* 会员Id
|
||||||
*/
|
*/
|
||||||
@SerializedName("memberId")
|
|
||||||
val memberId: Int? = 0,
|
val memberId: Int? = 0,
|
||||||
|
|
||||||
@SerializedName("name")
|
|
||||||
val name: String? = "",
|
|
||||||
@SerializedName("phone")
|
|
||||||
val phone: String? = "",
|
|
||||||
/**
|
/**
|
||||||
* 餐盘编号
|
* 餐盘编号
|
||||||
*/
|
*/
|
||||||
@SerializedName("plateNumber")
|
|
||||||
var plateNumber: String? = "",
|
var plateNumber: String? = "",
|
||||||
|
/**
|
||||||
|
* 设备名称
|
||||||
|
*/
|
||||||
|
val equipmentName: String? = "",
|
||||||
|
|
||||||
|
val orderNo: String? = "",
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 更新时间
|
* 更新时间
|
||||||
*/
|
*/
|
||||||
@SerializedName("updateTime")
|
|
||||||
val updateTime: String? = "",
|
val updateTime: String? = "",
|
||||||
|
|
||||||
|
val name: String? = "",
|
||||||
|
val phone: String? = "",
|
||||||
|
val faceUrl: String? = "",
|
||||||
|
val mealTime: String? = "",
|
||||||
|
val mealTimeInterval: String? = "",
|
||||||
|
val openTime: String? = "",
|
||||||
|
val openTimeInterval: String? = "",
|
||||||
|
val eatCount: Int? = 0,
|
||||||
|
|
||||||
@SerializedName("cardBalance")
|
|
||||||
var cardBalance: Double? = 0.toDouble(),
|
var cardBalance: Double? = 0.toDouble(),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -49,33 +49,36 @@ data class SearchResult(
|
|||||||
) : Parcelable {
|
) : Parcelable {
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class Member(
|
data class Member(
|
||||||
@SerializedName("cardBalance")
|
// @SerializedName("cardBalance")
|
||||||
val cardBalance: String? = "",
|
// val cardBalance: String? = "",
|
||||||
@SerializedName("cardCode")
|
// @SerializedName("cardCode")
|
||||||
val cardCode: String? = "",
|
// val cardCode: String? = "",
|
||||||
@SerializedName("consumptionCount")
|
// @SerializedName("consumptionCount")
|
||||||
val consumptionCount: Int? = 0,
|
// val consumptionCount: Int? = 0,
|
||||||
@SerializedName("consumptionTotal")
|
// @SerializedName("consumptionTotal")
|
||||||
val consumptionTotal: String? = "",
|
// val consumptionTotal: String? = "",
|
||||||
@SerializedName("createTime")
|
// @SerializedName("createTime")
|
||||||
val createTime: String? = "",
|
// val createTime: String? = "",
|
||||||
@SerializedName("firstTopUpTime")
|
// @SerializedName("firstTopUpTime")
|
||||||
val firstTopUpTime: String? = "",
|
// val firstTopUpTime: String? = "",
|
||||||
@SerializedName("id")
|
// @SerializedName("id")
|
||||||
|
// val id: Int? = 0,
|
||||||
|
// @SerializedName("integralBalance")
|
||||||
|
// val integralBalance: Int? = 0,
|
||||||
|
// @SerializedName("lastConsumptionTime")
|
||||||
|
// val lastConsumptionTime: String? = "",
|
||||||
|
// @SerializedName("memberFrom")
|
||||||
|
// val memberFrom: Int? = 0,
|
||||||
|
// @SerializedName("name")
|
||||||
|
// val name: String? = "",
|
||||||
|
// @SerializedName("phone")
|
||||||
|
// val phone: String? = "",
|
||||||
|
// @SerializedName("rewardBalance")
|
||||||
|
// val rewardBalance: String? = "",
|
||||||
|
// @SerializedName("topUpBalance")
|
||||||
|
// val topUpBalance: String? = ""
|
||||||
val id: Int? = 0,
|
val id: Int? = 0,
|
||||||
@SerializedName("integralBalance")
|
|
||||||
val integralBalance: Int? = 0,
|
|
||||||
@SerializedName("lastConsumptionTime")
|
|
||||||
val lastConsumptionTime: String? = "",
|
|
||||||
@SerializedName("memberFrom")
|
|
||||||
val memberFrom: Int? = 0,
|
|
||||||
@SerializedName("name")
|
|
||||||
val name: String? = "",
|
val name: String? = "",
|
||||||
@SerializedName("phone")
|
|
||||||
val phone: String? = "",
|
val phone: String? = "",
|
||||||
@SerializedName("rewardBalance")
|
|
||||||
val rewardBalance: String? = "",
|
|
||||||
@SerializedName("topUpBalance")
|
|
||||||
val topUpBalance: String? = ""
|
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
}
|
}
|
||||||
@@ -10,16 +10,21 @@ import kotlinx.parcelize.Parcelize
|
|||||||
*/
|
*/
|
||||||
@Parcelize
|
@Parcelize
|
||||||
data class UserFaceModel(
|
data class UserFaceModel(
|
||||||
@SerializedName("faceFeature")
|
// @SerializedName("faceFeature")
|
||||||
val faceFeature: String? = "",
|
// val faceFeature: String? = "",
|
||||||
@SerializedName("faceFeatureString")
|
// @SerializedName("faceFeatureString")
|
||||||
val faceFeatureString: String? = "",
|
// val faceFeatureString: String? = "",
|
||||||
@SerializedName("faceType")
|
// @SerializedName("faceType")
|
||||||
val faceType: String? = "",
|
// val faceType: String? = "",
|
||||||
@SerializedName("userFaceId")
|
// @SerializedName("userFaceId")
|
||||||
val userFaceId: String? = "",
|
// val userFaceId: String? = "",
|
||||||
@SerializedName("userId")
|
// @SerializedName("userId")
|
||||||
|
// val userId: String? = "",
|
||||||
|
// @SerializedName("updateTimeStamp")
|
||||||
|
// val updateTimeStamp: Long = 0,
|
||||||
|
|
||||||
val userId: String? = "",
|
val userId: String? = "",
|
||||||
@SerializedName("updateTimeStamp")
|
val faceFeatureStr: String? = "",
|
||||||
val updateTimeStamp: Long = 0,
|
|
||||||
|
val faceDeleted: Boolean?=false
|
||||||
) : Parcelable
|
) : Parcelable
|
||||||
@@ -11,6 +11,7 @@ import com.sw.platecabinet.model.response.EquipmentUserInfo
|
|||||||
import com.sw.platecabinet.model.response.SearchResult
|
import com.sw.platecabinet.model.response.SearchResult
|
||||||
import com.sw.platecabinet.model.response.UserFaceModel
|
import com.sw.platecabinet.model.response.UserFaceModel
|
||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
|
import retrofit2.http.Field
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.Header
|
import retrofit2.http.Header
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
@@ -18,73 +19,109 @@ import retrofit2.http.Query
|
|||||||
import retrofit2.http.Url
|
import retrofit2.http.Url
|
||||||
|
|
||||||
interface ApiService {
|
interface ApiService {
|
||||||
/**
|
// /**
|
||||||
* device获取token
|
// * device获取token
|
||||||
*/
|
// */
|
||||||
@GET("sys/getEquipmentToken")
|
// @GET("sys/getEquipmentToken")
|
||||||
suspend fun getDeviceToken(
|
// suspend fun getDeviceToken(
|
||||||
@Query("qrcodeId") qrcodeId: String,
|
// @Query("qrcodeId") qrcodeId: String,
|
||||||
@Query("appVersion") appVersion: String = GlobalData.appVersion
|
// @Query("appVersion") appVersion: String = GlobalData.appVersion
|
||||||
): ApiResponse<String>
|
// ): ApiResponse<String>
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
*获取配置信息
|
// *获取配置信息
|
||||||
*/
|
// */
|
||||||
@GET("equipment/stEquipment/queryByEquipmentCode")
|
// @GET("equipment/stEquipment/queryByEquipmentCode")
|
||||||
suspend fun getDeviceInfo(
|
// suspend fun getDeviceInfo(
|
||||||
@Query("equipmentCode") equipmentCode: String,
|
// @Query("equipmentCode") equipmentCode: String,
|
||||||
@Query("appVersion") appVersion: String = GlobalData.appVersion,
|
// @Query("appVersion") appVersion: String = GlobalData.appVersion,
|
||||||
@Header("X-Access-Token") token: String
|
// @Header("X-Access-Token") token: String
|
||||||
): ApiResponse<EquipmentInfo>
|
// ): ApiResponse<EquipmentInfo>
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 生成token
|
// * 生成token
|
||||||
*/
|
// */
|
||||||
@GET//("/shuwei-zhct/scales/generateToken")
|
// @GET//("/shuwei-zhct/scales/generateToken")
|
||||||
suspend fun generateToken(
|
// suspend fun generateToken(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/scales/generateToken",
|
// @Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/scales/generateToken",
|
||||||
@Query("deviceId") deviceId: String,
|
// @Query("deviceId") deviceId: String,
|
||||||
@Query("appVersion") appVersion: String,
|
// @Query("appVersion") appVersion: String,
|
||||||
@Query("equipmentCode") equipmentCode: String
|
// @Query("equipmentCode") equipmentCode: String
|
||||||
): ApiResponse<String>
|
// ): ApiResponse<String>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取人脸数据
|
* 获取人脸数据
|
||||||
*/
|
*/
|
||||||
@GET//("/shuwei-zhct/scales/getUserFaceCache")
|
// @GET//("/shuwei-zhct/scales/getUserFaceCache")
|
||||||
|
// suspend fun getUserFaceCache(
|
||||||
|
// @Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/scales/getUserFaceCache",
|
||||||
|
// @Query("appVersion") appVersion: String,
|
||||||
|
// @Query("equipmentCode") equipmentCode: String
|
||||||
|
// ): ApiResponse<List<UserFaceModel>>
|
||||||
|
@POST
|
||||||
suspend fun getUserFaceCache(
|
suspend fun getUserFaceCache(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/scales/getUserFaceCache",
|
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/common/app/faceFeature/list",
|
||||||
@Query("appVersion") appVersion: String,
|
@Body param: Map<String, Int>
|
||||||
@Query("equipmentCode") equipmentCode: String
|
|
||||||
): ApiResponse<List<UserFaceModel>>
|
): ApiResponse<List<UserFaceModel>>
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
|
// * 餐盘用户信息获取
|
||||||
|
// */
|
||||||
|
// @POST//("/shuwei-zhct/swEquipmentRelUser/equipmentBoxLogin")
|
||||||
|
// suspend fun equipmentBoxLogin(
|
||||||
|
// @Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/swEquipmentRelUser/equipmentBoxLogin",
|
||||||
|
// @Body param: LoginParam
|
||||||
|
// ): ApiResponse<EquipmentUserInfo>
|
||||||
|
|
||||||
|
/**
|
||||||
* 餐盘用户信息获取
|
* 餐盘用户信息获取
|
||||||
*/
|
*/
|
||||||
@POST//("/shuwei-zhct/swEquipmentRelUser/equipmentBoxLogin")
|
@POST//("/shuwei-zhct/swEquipmentRelUser/equipmentBoxLogin")
|
||||||
suspend fun equipmentBoxLogin(
|
suspend fun equipmentBoxLogin(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/swEquipmentRelUser/equipmentBoxLogin",
|
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/sideboard/app/getPlateBoxUserInfo",
|
||||||
@Body param: LoginParam
|
@Body param: LoginParam
|
||||||
): ApiResponse<EquipmentUserInfo>
|
): ApiResponse<EquipmentUserInfo>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 餐盘用户信息列表查询
|
* 餐盘用户信息列表查询
|
||||||
*/
|
*/
|
||||||
@POST//("/shuwei-zhct/swEquipmentRelUser/list")
|
// @POST//("/shuwei-zhct/swEquipmentRelUser/list")
|
||||||
|
// suspend fun getEquipmentList(
|
||||||
|
// @Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/swEquipmentRelUser/list",
|
||||||
|
// @Body param: EquipmentParam
|
||||||
|
// ): ApiResponse<List<EquipmentUserInfo>>
|
||||||
|
|
||||||
|
@GET
|
||||||
suspend fun getEquipmentList(
|
suspend fun getEquipmentList(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/swEquipmentRelUser/list",
|
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/sideboard/app/getYxMemberRefPlateByEquipmentCode",
|
||||||
@Body param: EquipmentParam
|
|
||||||
): ApiResponse<List<EquipmentUserInfo>>
|
): ApiResponse<List<EquipmentUserInfo>>
|
||||||
|
// /**
|
||||||
|
// * 餐盘用户信息绑定解绑
|
||||||
|
// */
|
||||||
|
// @POST//("/shuwei-zhct/swEquipmentRelUser/addOrEdit")
|
||||||
|
// suspend fun bindEquipment(
|
||||||
|
// @Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/swEquipmentRelUser/addOrEdit",
|
||||||
|
// @Body param: BindParam
|
||||||
|
// ): ApiResponse<EquipmentUserInfo?>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 餐盘用户信息绑定解绑
|
* 餐盘绑定
|
||||||
*/
|
*/
|
||||||
@POST//("/shuwei-zhct/swEquipmentRelUser/addOrEdit")
|
@POST
|
||||||
suspend fun bindEquipment(
|
suspend fun plateBind(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/swEquipmentRelUser/addOrEdit",
|
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/sideboard/app/plateBinding",
|
||||||
@Body param: BindParam
|
@Body param: BindParam
|
||||||
): ApiResponse<EquipmentUserInfo?>
|
): ApiResponse<EquipmentUserInfo?>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 餐盘解绑
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
suspend fun plateUnbind(
|
||||||
|
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/sideboard/app/plateUnbind",
|
||||||
|
@Field("id") id: Int
|
||||||
|
): ApiResponse<Any?>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户信息模糊搜索
|
* 用户信息模糊搜索
|
||||||
*/
|
*/
|
||||||
@@ -94,23 +131,42 @@ interface ApiService {
|
|||||||
@Body param: SearchParam
|
@Body param: SearchParam
|
||||||
): ApiResponse<SearchResult>
|
): ApiResponse<SearchResult>
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
|
// * 通过餐盘号获取信息
|
||||||
|
// */
|
||||||
|
// @POST//("/shuwei-zhct/swEquipmentRelUser/findByPlateNumber")
|
||||||
|
// suspend fun findByPlateNumber(
|
||||||
|
// @Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/swEquipmentRelUser/findByPlateNumber",
|
||||||
|
// @Body param: BindParam
|
||||||
|
// ): ApiResponse<EquipmentUserInfo>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
* 通过餐盘号获取信息
|
* 通过餐盘号获取信息
|
||||||
*/
|
*/
|
||||||
@POST//("/shuwei-zhct/swEquipmentRelUser/findByPlateNumber")
|
@GET
|
||||||
suspend fun findByPlateNumber(
|
suspend fun findByPlateNumber(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/swEquipmentRelUser/findByPlateNumber",
|
@Url url: String = "${GlobalData.appBaseUrl}/terminal/neglect/sideboard/app/getMemberRefPlateByPlateNumber",
|
||||||
@Body param: BindParam
|
@Query("plateNumber") plateNumber: String
|
||||||
): ApiResponse<EquipmentUserInfo>
|
): ApiResponse<EquipmentUserInfo>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取人脸增量数据
|
* 获取人脸增量数据
|
||||||
*
|
*
|
||||||
* @param timeDate 时间戳(毫秒级)
|
* @param timeDate 时间戳(毫秒级)
|
||||||
*/
|
*/
|
||||||
@GET//("/shuwei-zhct/scales/getHeartbeatInterface")
|
// @GET//("/shuwei-zhct/scales/getHeartbeatInterface")
|
||||||
suspend fun getHeartbeatInterface(
|
// suspend fun getHeartbeatInterface(
|
||||||
@Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/scales/getHeartbeatInterface",
|
// @Url url: String = "${GlobalData.appBaseUrl}/shuwei-zhct/scales/getHeartbeatInterface",
|
||||||
@Query("timeDate") timeDate: Long
|
// @Query("timeDate") timeDate: Long
|
||||||
): ApiResponse<List<UserFaceModel>>
|
// ): ApiResponse<List<UserFaceModel>>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取人脸增量数据
|
||||||
|
*/
|
||||||
|
@POST("/terminal/neglect/common/app/faceFeature/increment/list")
|
||||||
|
suspend fun getFaceIncrementList(@Body param:Map<String, Long>): ApiResponse<List<UserFaceModel>?>
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.sw.platecabinet.network.interceptor
|
|||||||
|
|
||||||
import com.sw.inbound.utils.SPUtil
|
import com.sw.inbound.utils.SPUtil
|
||||||
import com.sw.plate.App
|
import com.sw.plate.App
|
||||||
|
import com.sw.platecabinet.GlobalData
|
||||||
import com.sw.platecabinet.GlobalKey
|
import com.sw.platecabinet.GlobalKey
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
@@ -17,6 +18,9 @@ class RequestInterceptor : Interceptor {
|
|||||||
.header("Accept", "application/json")
|
.header("Accept", "application/json")
|
||||||
// .header("Authorization", "Bearer ${getToken()}")
|
// .header("Authorization", "Bearer ${getToken()}")
|
||||||
.header("Authorization", getToken())
|
.header("Authorization", getToken())
|
||||||
|
.header("X-Access-Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjYW50ZWVuSWQiOiJiZTE1NDgzMS0zNDY2LTNiYTItYTJlYS01NzY1MmM5MTlmZWQiLCJ0eXBlIjoiNCIsInVzZXJJZCI6IjAwMDAwMDAwMDAwMDAwMDAwMDEifQ.sN40cOC-O5WQFrF4IDUs8fFlkNdUKLbJt_rHyTsgYYM")
|
||||||
|
.header("X-DEVICE-CODE", GlobalData.deviceId)
|
||||||
|
.header("authorization", "57ee87183f2a4fa59683ec9ef41c8f5d")
|
||||||
|
|
||||||
val newRequest = requestBuilder.build()
|
val newRequest = requestBuilder.build()
|
||||||
|
|
||||||
|
|||||||
@@ -47,58 +47,58 @@ class HeartBeatTask(appContext: Context, workerParams: WorkerParameters) :
|
|||||||
private val faceApi: FaceApi = FaceApi()
|
private val faceApi: FaceApi = FaceApi()
|
||||||
|
|
||||||
private suspend fun performSync() {
|
private suspend fun performSync() {
|
||||||
withContext(Dispatchers.IO) {
|
// withContext(Dispatchers.IO) {
|
||||||
val faceUpdateTimeStamp = PrefUtils.getLong(App.getContext(), "faceUpdateTimeStamp", 0)
|
// val faceUpdateTimeStamp = PrefUtils.getLong(App.getContext(), "faceUpdateTimeStamp", 0)
|
||||||
if (faceUpdateTimeStamp == 0L) {
|
// if (faceUpdateTimeStamp == 0L) {
|
||||||
val timestamp = System.currentTimeMillis()
|
// val timestamp = System.currentTimeMillis()
|
||||||
PrefUtils.setLong(App.getContext(), "faceUpdateTimeStamp", timestamp)
|
// PrefUtils.setLong(App.getContext(), "faceUpdateTimeStamp", timestamp)
|
||||||
}
|
// }
|
||||||
val resp = repository.getHeartbeatInterface(
|
// val resp = repository.getHeartbeatInterface(
|
||||||
PrefUtils.getLong(
|
// PrefUtils.getLong(
|
||||||
App.getContext(),
|
// App.getContext(),
|
||||||
"faceUpdateTimeStamp",
|
// "faceUpdateTimeStamp",
|
||||||
0
|
// 0
|
||||||
)
|
// )
|
||||||
)
|
// )
|
||||||
Timber.tag(TAG).d("performSync: ${GsonUtils.toJson(resp)}")
|
// Timber.tag(TAG).d("performSync: ${GsonUtils.toJson(resp)}")
|
||||||
val list = resp.data
|
// val list = resp.data
|
||||||
if (list.isNullOrEmpty()) {
|
// if (list.isNullOrEmpty()) {
|
||||||
return@withContext
|
// return@withContext
|
||||||
}
|
// }
|
||||||
val faceServer = FaceServer.getInstance()
|
// val faceServer = FaceServer.getInstance()
|
||||||
val faceEngine: FaceEngine? = faceServer.faceEngine
|
// val faceEngine: FaceEngine? = faceServer.faceEngine
|
||||||
|
//
|
||||||
list.forEachIndexed { index, it ->
|
// list.forEachIndexed { index, it ->
|
||||||
try {
|
// try {
|
||||||
if (index == list.size - 1) {
|
// if (index == list.size - 1) {
|
||||||
PrefUtils.setLong(
|
// PrefUtils.setLong(
|
||||||
App.getContext(),
|
// App.getContext(),
|
||||||
"faceUpdateTimeStamp",
|
// "faceUpdateTimeStamp",
|
||||||
it.updateTimeStamp
|
// it.updateTimeStamp
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
if (it.faceType == "1") {
|
// if (it.faceType == "1") {
|
||||||
if (it.userId.isNullOrBlank().not()) {
|
// if (it.userId.isNullOrBlank().not()) {
|
||||||
//userId非空,根据userId删除人脸数据
|
// //userId非空,根据userId删除人脸数据
|
||||||
faceApi.deleteByUserName(it.userId)
|
// faceApi.deleteByUserName(it.userId)
|
||||||
faceEngine?.removeFaceFeature(it.userId.toInt())
|
// faceEngine?.removeFaceFeature(it.userId.toInt())
|
||||||
}
|
// }
|
||||||
} else if (it.faceType == "0") {
|
// } else if (it.faceType == "0") {
|
||||||
//新增人脸数据
|
// //新增人脸数据
|
||||||
val featureData = Base64.decode(it.faceFeature)
|
// val featureData = Base64.decode(it.faceFeature)
|
||||||
val insertEntity = FaceEntity(it.userId, null, featureData)
|
// val insertEntity = FaceEntity(it.userId, null, featureData)
|
||||||
val faceId = faceApi.insert(insertEntity)
|
// val faceId = faceApi.insert(insertEntity)
|
||||||
insertEntity.faceId = faceId
|
// insertEntity.faceId = faceId
|
||||||
// faceServer.registerFaceFeatureInfoFromDb(insertEntity, faceEngine)
|
//// faceServer.registerFaceFeatureInfoFromDb(insertEntity, faceEngine)
|
||||||
|
//
|
||||||
EventBus.getDefault().post(insertEntity)
|
// EventBus.getDefault().post(insertEntity)
|
||||||
// callback(insertEntity)
|
//// callback(insertEntity)
|
||||||
}
|
// }
|
||||||
} catch (e: Exception) {
|
// } catch (e: Exception) {
|
||||||
e.printStackTrace()
|
// e.printStackTrace()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -19,50 +19,55 @@ class RemoteRepository constructor(
|
|||||||
private val apiService: ApiService
|
private val apiService: ApiService
|
||||||
) : BaseRepository() {
|
) : BaseRepository() {
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 生成token
|
// * 生成token
|
||||||
*/
|
// */
|
||||||
suspend fun getDeviceToken(qrcodeId: String): ApiResponse<String> {
|
// suspend fun getDeviceToken(qrcodeId: String): ApiResponse<String> {
|
||||||
return safeApiCall {
|
// return safeApiCall {
|
||||||
apiService.getDeviceToken(
|
// apiService.getDeviceToken(
|
||||||
qrcodeId
|
// qrcodeId
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 获取设备信息
|
// * 获取设备信息
|
||||||
*/
|
// */
|
||||||
suspend fun getDeviceInfo(equipmentCode: String, token: String): ApiResponse<EquipmentInfo> {
|
// suspend fun getDeviceInfo(equipmentCode: String, token: String): ApiResponse<EquipmentInfo> {
|
||||||
return safeApiCall {
|
// return safeApiCall {
|
||||||
apiService.getDeviceInfo(
|
// apiService.getDeviceInfo(
|
||||||
equipmentCode,
|
// equipmentCode,
|
||||||
token = token
|
// token = token
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 生成token
|
// * 生成token
|
||||||
*/
|
// */
|
||||||
suspend fun generateToken(deviceId: String): ApiResponse<String> {
|
// suspend fun generateToken(deviceId: String): ApiResponse<String> {
|
||||||
return safeApiCall {
|
// return safeApiCall {
|
||||||
apiService.generateToken(
|
// apiService.generateToken(
|
||||||
deviceId = deviceId,
|
// deviceId = deviceId,
|
||||||
appVersion = GlobalData.appVersion,
|
// appVersion = GlobalData.appVersion,
|
||||||
equipmentCode = GlobalData.globalEquipmentCode
|
// equipmentCode = GlobalData.globalEquipmentCode
|
||||||
)
|
// )
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取人脸数据
|
* 获取人脸数据
|
||||||
*/
|
*/
|
||||||
suspend fun getUserFaceCache(): ApiResponse<List<UserFaceModel>> {
|
suspend fun getUserFaceCache(
|
||||||
|
pageNum: Int,
|
||||||
|
pageSize: Int = 100,
|
||||||
|
): ApiResponse<List<UserFaceModel>> {
|
||||||
return safeApiCall {
|
return safeApiCall {
|
||||||
apiService.getUserFaceCache(
|
apiService.getUserFaceCache(
|
||||||
appVersion = GlobalData.appVersion,
|
param = mapOf(
|
||||||
equipmentCode = GlobalData.globalEquipmentCode
|
"pageNum" to pageNum,
|
||||||
|
"pageSize" to pageSize
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,15 +82,23 @@ class RemoteRepository constructor(
|
|||||||
/**
|
/**
|
||||||
* 获取设备绑定用户列表
|
* 获取设备绑定用户列表
|
||||||
*/
|
*/
|
||||||
suspend fun getEquipmentList(param: EquipmentParam): ApiResponse<List<EquipmentUserInfo>> {
|
suspend fun getEquipmentList(): ApiResponse<List<EquipmentUserInfo>> {
|
||||||
return safeApiCall { apiService.getEquipmentList(param = param) }
|
return safeApiCall { apiService.getEquipmentList() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 餐盘用户信息绑定解绑
|
// * 餐盘用户信息绑定解绑
|
||||||
*/
|
// */
|
||||||
suspend fun bindEquipment(param: BindParam): ApiResponse<EquipmentUserInfo?> {
|
// suspend fun bindEquipment(param: BindParam): ApiResponse<EquipmentUserInfo?> {
|
||||||
return safeApiCall { apiService.bindEquipment(param = param) }
|
// return safeApiCall { apiService.bindEquipment(param = param) }
|
||||||
|
// }
|
||||||
|
|
||||||
|
suspend fun plateBind(param: BindParam): ApiResponse<EquipmentUserInfo?> {
|
||||||
|
return safeApiCall { apiService.plateBind(param = param) }
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun plateUnbind(id: Int): ApiResponse<Any?> {
|
||||||
|
return safeApiCall { apiService.plateUnbind(id = id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,8 +111,8 @@ class RemoteRepository constructor(
|
|||||||
/**
|
/**
|
||||||
* 通过餐盘编号获取绑定信息
|
* 通过餐盘编号获取绑定信息
|
||||||
*/
|
*/
|
||||||
suspend fun findByPlateNumber(param: BindParam): ApiResponse<EquipmentUserInfo> {
|
suspend fun findByPlateNumber(plateNumber: String): ApiResponse<EquipmentUserInfo> {
|
||||||
return safeApiCall { apiService.findByPlateNumber(param = param) }
|
return safeApiCall { apiService.findByPlateNumber(plateNumber = plateNumber) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -107,7 +120,23 @@ class RemoteRepository constructor(
|
|||||||
*
|
*
|
||||||
* @param timeDate 时间戳(毫秒级)
|
* @param timeDate 时间戳(毫秒级)
|
||||||
*/
|
*/
|
||||||
suspend fun getHeartbeatInterface(timeDate: Long): ApiResponse<List<UserFaceModel>> {
|
// suspend fun getHeartbeatInterface(timeDate: Long): ApiResponse<List<UserFaceModel>> {
|
||||||
return safeApiCall { apiService.getHeartbeatInterface(timeDate = timeDate) }
|
// return safeApiCall { apiService.getHeartbeatInterface(timeDate = timeDate) }
|
||||||
|
// }
|
||||||
|
|
||||||
|
suspend fun getFaceIncrementList(
|
||||||
|
pageNum: Long,
|
||||||
|
pageSize: Long = 100L,
|
||||||
|
timestamp: Long
|
||||||
|
): ApiResponse<List<UserFaceModel>?> {
|
||||||
|
return safeApiCall {
|
||||||
|
apiService.getFaceIncrementList(
|
||||||
|
param = mapOf(
|
||||||
|
"pageNum" to pageNum,
|
||||||
|
"pageSize" to pageSize,
|
||||||
|
"timestamp" to timestamp
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package com.sw.platecabinet.utils
|
||||||
|
|
||||||
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.isActive
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class IntervalExecutor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动定时任务
|
||||||
|
* @param delayMillis 延迟时间(毫秒)
|
||||||
|
* @param action 要执行的方法
|
||||||
|
* @return Job 可用于取消任务
|
||||||
|
*/
|
||||||
|
fun startIntervalTask(delayMillis: Long, action: suspend () -> Unit): Job {
|
||||||
|
return CoroutineScope(Dispatchers.Default).launch {
|
||||||
|
while (isActive) {
|
||||||
|
action()
|
||||||
|
delay(delayMillis)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启动定时任务(带初始延迟)
|
||||||
|
* @param initialDelay 初始延迟时间(毫秒)
|
||||||
|
* @param delayMillis 后续执行间隔(毫秒)
|
||||||
|
* @param action 要执行的方法
|
||||||
|
* @return Job 可用于取消任务
|
||||||
|
*/
|
||||||
|
fun startIntervalTaskWithInitialDelay(
|
||||||
|
initialDelay: Long,
|
||||||
|
delayMillis: Long,
|
||||||
|
action: suspend () -> Unit
|
||||||
|
): Job {
|
||||||
|
return CoroutineScope(Dispatchers.Default).launch {
|
||||||
|
delay(initialDelay)
|
||||||
|
while (isActive) {
|
||||||
|
action()
|
||||||
|
delay(delayMillis)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用示例
|
||||||
|
fun main() = runBlocking {
|
||||||
|
val executor = IntervalExecutor()
|
||||||
|
|
||||||
|
// 示例1:每隔10秒执行一次
|
||||||
|
val job1 = executor.startIntervalTask(10000) {
|
||||||
|
println("定时任务执行: ${System.currentTimeMillis()}")
|
||||||
|
// 这里可以执行你的业务逻辑
|
||||||
|
}
|
||||||
|
|
||||||
|
// 示例2:先延迟5秒,然后每隔3秒执行一次
|
||||||
|
val job2 = executor.startIntervalTaskWithInitialDelay(5000, 3000) {
|
||||||
|
println("带初始延迟的定时任务: ${System.currentTimeMillis()}")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 运行30秒后取消任务
|
||||||
|
delay(30000)
|
||||||
|
job1.cancel()
|
||||||
|
job2.cancel()
|
||||||
|
println("所有定时任务已取消")
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.sw.platecabinet.utils;
|
||||||
|
|
||||||
|
import com.sw.inbound.utils.SPUtil;
|
||||||
|
import com.sw.platecabinet.MyApp;
|
||||||
|
|
||||||
|
public class SpTool {
|
||||||
|
|
||||||
|
public static final String LAST_FACE_TIMESTAMP = "faceTimestamp";
|
||||||
|
|
||||||
|
public static long getLastFaceTimestamp() {
|
||||||
|
return SPUtil.Companion.getInstance(MyApp.getContext(), "default_sp").get(LAST_FACE_TIMESTAMP, 0L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setLastFaceTimestamp(long timestamp) {
|
||||||
|
SPUtil.Companion.getInstance(MyApp.getContext(), "default_sp").put(LAST_FACE_TIMESTAMP, timestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -67,10 +67,10 @@ abstract class BaseViewModel() : ViewModel() {
|
|||||||
|
|
||||||
fun parseEquipmentInfo(equipmentInfo: EquipmentInfo) {
|
fun parseEquipmentInfo(equipmentInfo: EquipmentInfo) {
|
||||||
// GlobalData.appBaseUrl = equipmentInfo.appPackageUrl!!
|
// GlobalData.appBaseUrl = equipmentInfo.appPackageUrl!!
|
||||||
GlobalData.appBaseUrl="https://vip.shuziweidao.com"
|
// GlobalData.appBaseUrl="https://vip.shuziweidao.com"
|
||||||
// GlobalData.sdkKey = equipmentInfo.arcsoftSdkKey!!
|
// GlobalData.sdkKey = equipmentInfo.arcsoftSdkKey!!
|
||||||
// GlobalData.appId = equipmentInfo.arcsoftAppId!!
|
// GlobalData.appId = equipmentInfo.arcsoftAppId!!
|
||||||
// GlobalData.activeKey = equipmentInfo.arcsoftActiveKey!!
|
// GlobalData.activeKey = equipmentInfo.arcsoftActiveKey!!
|
||||||
GlobalData.restId = equipmentInfo.canteenId!!
|
// GlobalData.restId = equipmentInfo.canteenId!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,68 +1,68 @@
|
|||||||
package com.sw.platecabinet.viewmodel
|
//package com.sw.platecabinet.viewmodel
|
||||||
|
//
|
||||||
import com.sw.inbound.utils.GsonUtils
|
//import com.sw.inbound.utils.GsonUtils
|
||||||
import com.sw.inbound.utils.SPUtil
|
//import com.sw.inbound.utils.SPUtil
|
||||||
import com.sw.platecabinet.GlobalData
|
//import com.sw.platecabinet.GlobalData
|
||||||
import com.sw.platecabinet.GlobalKey
|
//import com.sw.platecabinet.GlobalKey
|
||||||
import com.sw.platecabinet.model.response.EquipmentInfo
|
//import com.sw.platecabinet.model.response.EquipmentInfo
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
//import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
//import kotlinx.coroutines.flow.StateFlow
|
||||||
import timber.log.Timber
|
//import timber.log.Timber
|
||||||
import kotlin.jvm.java
|
//import kotlin.jvm.java
|
||||||
|
//
|
||||||
/**
|
///**
|
||||||
* 初始化的viewmodel
|
// * 初始化的viewmodel
|
||||||
*/
|
// */
|
||||||
class DeviceViewModel : BaseViewModel() {
|
//class DeviceViewModel : BaseViewModel() {
|
||||||
private val _deviceInfoResult = MutableStateFlow<Boolean?>(null)
|
// private val _deviceInfoResult = MutableStateFlow<Boolean?>(null)
|
||||||
val deviceInfoResult: StateFlow<Boolean?> = _deviceInfoResult
|
// val deviceInfoResult: StateFlow<Boolean?> = _deviceInfoResult
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 获取token
|
// * 获取token
|
||||||
*/
|
// */
|
||||||
fun getDeviceToken(deviceId: String = GlobalData.deviceId) {
|
// fun getDeviceToken(deviceId: String = GlobalData.deviceId) {
|
||||||
launchWithLoading {
|
// launchWithLoading {
|
||||||
val response = repository.getDeviceToken(deviceId)
|
// val response = repository.getDeviceToken(deviceId)
|
||||||
if (parseResponse(response)) {
|
// if (parseResponse(response)) {
|
||||||
val response1 = repository.getDeviceInfo(deviceId, response.result!!)
|
// val response1 = repository.getDeviceInfo(deviceId, response.result!!)
|
||||||
|
//
|
||||||
if (parseResponse(response1)) {
|
// if (parseResponse(response1)) {
|
||||||
val equipmentInfo = response1.result
|
// val equipmentInfo = response1.result
|
||||||
if (equipmentInfo == null) return@launchWithLoading
|
// if (equipmentInfo == null) return@launchWithLoading
|
||||||
try {
|
// try {
|
||||||
parseEquipmentInfo(equipmentInfo)
|
// parseEquipmentInfo(equipmentInfo)
|
||||||
SPUtil.getInstance()
|
// SPUtil.getInstance()
|
||||||
.put(GlobalKey.KEY_EQUIPMENT_INFO, GsonUtils.toJson(equipmentInfo))
|
// .put(GlobalKey.KEY_EQUIPMENT_INFO, GsonUtils.toJson(equipmentInfo))
|
||||||
_deviceInfoResult.value = true
|
// _deviceInfoResult.value = true
|
||||||
} catch (e: Exception) {
|
// } catch (e: Exception) {
|
||||||
Timber.e(e)
|
// Timber.e(e)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
/**
|
// /**
|
||||||
* 检查缓存数据
|
// * 检查缓存数据
|
||||||
*/
|
// */
|
||||||
fun checkEquipmentInfo(): Boolean {
|
// fun checkEquipmentInfo(): Boolean {
|
||||||
val equipmentInfoStr = SPUtil.getInstance().get(GlobalKey.KEY_EQUIPMENT_INFO, "")
|
// val equipmentInfoStr = SPUtil.getInstance().get(GlobalKey.KEY_EQUIPMENT_INFO, "")
|
||||||
if (equipmentInfoStr == null) {
|
// if (equipmentInfoStr == null) {
|
||||||
Timber.e("获取缓存设备信息失败")
|
// Timber.e("获取缓存设备信息失败")
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
val equipmentInfo =
|
// val equipmentInfo =
|
||||||
GsonUtils.fromJson<EquipmentInfo>(equipmentInfoStr, EquipmentInfo::class.java)
|
// GsonUtils.fromJson<EquipmentInfo>(equipmentInfoStr, EquipmentInfo::class.java)
|
||||||
if (equipmentInfo == null) {
|
// if (equipmentInfo == null) {
|
||||||
Timber.e("解析缓存设备信息失败")
|
// Timber.e("解析缓存设备信息失败")
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
try {
|
// try {
|
||||||
parseEquipmentInfo(equipmentInfo)
|
// parseEquipmentInfo(equipmentInfo)
|
||||||
return true
|
// return true
|
||||||
} catch (e: Exception) {
|
// } catch (e: Exception) {
|
||||||
Timber.e(e)
|
// Timber.e(e)
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
@@ -9,16 +9,21 @@ import com.sw.platecabinet.model.request.EquipmentParam
|
|||||||
import com.sw.platecabinet.model.request.SearchParam
|
import com.sw.platecabinet.model.request.SearchParam
|
||||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||||
import com.sw.platecabinet.model.response.SearchResult
|
import com.sw.platecabinet.model.response.SearchResult
|
||||||
|
import com.sw.platecabinet.model.response.UserFaceModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 管理员操作viewmodel
|
* 管理员操作viewmodel
|
||||||
*/
|
*/
|
||||||
class SettingViewModel : BaseViewModel() {
|
class SettingViewModel : BaseViewModel() {
|
||||||
// 设备绑定列表
|
// 设备绑定列表
|
||||||
private val _equipmentList = MutableStateFlow<List<EquipmentUserInfo>>(emptyList())
|
// private val _equipmentList = MutableStateFlow<List<EquipmentUserInfo>>(emptyList())
|
||||||
val equipmentList: StateFlow<List<EquipmentUserInfo>> = _equipmentList
|
// val equipmentList: StateFlow<List<EquipmentUserInfo>> = _equipmentList
|
||||||
|
|
||||||
private val _searchMemberList = MutableStateFlow<List<SearchResult.Member>>(emptyList())
|
private val _searchMemberList = MutableStateFlow<List<SearchResult.Member>>(emptyList())
|
||||||
val searchMemberList: StateFlow<List<SearchResult.Member>> = _searchMemberList
|
val searchMemberList: StateFlow<List<SearchResult.Member>> = _searchMemberList
|
||||||
@@ -33,27 +38,36 @@ class SettingViewModel : BaseViewModel() {
|
|||||||
/**
|
/**
|
||||||
* 绑定/解绑状态 <绑定/解绑, 错误信息,>
|
* 绑定/解绑状态 <绑定/解绑, 错误信息,>
|
||||||
*/
|
*/
|
||||||
private val _bindStateChange = MutableStateFlow<Pair<Boolean?, ErrorInfo>>(null to ErrorInfo())
|
// private val _bindStateChange = MutableStateFlow<Pair<Boolean?, ErrorInfo>>(null to ErrorInfo())
|
||||||
val bindStateChange: StateFlow<Pair<Boolean?, ErrorInfo>> = _bindStateChange
|
// val bindStateChange: StateFlow<Pair<Boolean?, ErrorInfo>> = _bindStateChange
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取设备绑定用户信息列表
|
* 获取设备绑定用户信息列表
|
||||||
*/
|
*/
|
||||||
fun getEquipmentList(equipmentCode: String = globalEquipmentCode) {
|
// fun getEquipmentList(equipmentCode: String = globalEquipmentCode) {
|
||||||
|
// launchWithLoading {
|
||||||
|
// val param =
|
||||||
|
// EquipmentParam(appVersion = GlobalData.appVersion, equipmentCode = equipmentCode)
|
||||||
|
// val response = repository.getEquipmentList(param)
|
||||||
|
// if (parseResponse(response)) {
|
||||||
|
// _equipmentList.value = response.data ?: emptyList()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//// val list = mutableListOf<EquipmentUserInfo>()
|
||||||
|
//// for (i in 1 .. 30){
|
||||||
|
//// list.add(EquipmentUserInfo(id = i, equipmentBoxCode = i.toString()))
|
||||||
|
//// }
|
||||||
|
//// _equipmentList.value = list
|
||||||
|
// }
|
||||||
|
fun getEquipmentList(block: (List<EquipmentUserInfo>) -> Unit) {
|
||||||
launchWithLoading {
|
launchWithLoading {
|
||||||
val param =
|
val response = repository.getEquipmentList()
|
||||||
EquipmentParam(appVersion = GlobalData.appVersion, equipmentCode = equipmentCode)
|
|
||||||
val response = repository.getEquipmentList(param)
|
|
||||||
if (parseResponse(response)) {
|
if (parseResponse(response)) {
|
||||||
_equipmentList.value = response.data ?: emptyList()
|
val list = response.data ?: emptyList()
|
||||||
|
block(list)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// val list = mutableListOf<EquipmentUserInfo>()
|
|
||||||
// for (i in 1 .. 30){
|
|
||||||
// list.add(EquipmentUserInfo(id = i, equipmentBoxCode = i.toString()))
|
|
||||||
// }
|
|
||||||
// _equipmentList.value = list
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,52 +100,81 @@ class SettingViewModel : BaseViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun bindPlate(
|
// fun bindPlate(
|
||||||
equipmentBoxCode: String,
|
// equipmentBoxCode: String,
|
||||||
equipmentCode: String = globalEquipmentCode,
|
// equipmentCode: String = globalEquipmentCode,
|
||||||
memberId: Int,
|
// memberId: Int,
|
||||||
plateNumber: String
|
// plateNumber: String
|
||||||
) {
|
// ) {
|
||||||
_bindStateChange.value = null to ErrorInfo()
|
// _bindStateChange.value = null to ErrorInfo()
|
||||||
|
// launchWithLoading {
|
||||||
|
// val bindParam = BindParam(
|
||||||
|
// appVersion = GlobalData.appVersion,
|
||||||
|
// equipmentBoxCode = equipmentBoxCode,
|
||||||
|
// equipmentCode = equipmentCode,
|
||||||
|
// memberId = memberId,
|
||||||
|
// plateNumber = plateNumber
|
||||||
|
// )
|
||||||
|
// val response = repository.bindEquipment(bindParam)
|
||||||
|
// if (parseResponse(response)) {
|
||||||
|
// var userInfo = response.data
|
||||||
|
// if (userInfo == null) {
|
||||||
|
// userInfo = EquipmentUserInfo()
|
||||||
|
// userInfo.equipmentBoxCode = equipmentBoxCode
|
||||||
|
// userInfo.plateNumber = plateNumber
|
||||||
|
// userInfo.equipmentCode = equipmentCode
|
||||||
|
// }
|
||||||
|
// _bindStateChange.value = true to ErrorInfo(equipmentUserInfo = userInfo)
|
||||||
|
// } else {
|
||||||
|
// _bindStateChange.value = true to ErrorInfo(response.code, response.msg.toString())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// fun unbindPlate(
|
||||||
|
// equipmentBoxCode: String,
|
||||||
|
// equipmentCode: String = globalEquipmentCode
|
||||||
|
// ) {
|
||||||
|
// launchWithLoading {
|
||||||
|
// val bindParam = BindParam(
|
||||||
|
// appVersion = GlobalData.appVersion,
|
||||||
|
// equipmentBoxCode = equipmentBoxCode,
|
||||||
|
// equipmentCode = equipmentCode
|
||||||
|
// )
|
||||||
|
// val response = repository.bindEquipment(bindParam)
|
||||||
|
// if (parseResponse(response)) {
|
||||||
|
// _bindStateChange.value = false to ErrorInfo()
|
||||||
|
// } else {
|
||||||
|
// _bindStateChange.value = false to ErrorInfo(response.code, response.msg.toString())
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
fun unbindPlate(id: Int, block:(Pair<Boolean?, ErrorInfo>)-> Unit) {
|
||||||
|
block(null to ErrorInfo())
|
||||||
launchWithLoading {
|
launchWithLoading {
|
||||||
val bindParam = BindParam(
|
val response = repository.plateUnbind(id)
|
||||||
appVersion = GlobalData.appVersion,
|
|
||||||
equipmentBoxCode = equipmentBoxCode,
|
|
||||||
equipmentCode = equipmentCode,
|
|
||||||
memberId = memberId,
|
|
||||||
plateNumber = plateNumber
|
|
||||||
)
|
|
||||||
val response = repository.bindEquipment(bindParam)
|
|
||||||
if (parseResponse(response)) {
|
if (parseResponse(response)) {
|
||||||
var userInfo = response.data
|
block(false to ErrorInfo())
|
||||||
if (userInfo == null) {
|
|
||||||
userInfo = EquipmentUserInfo()
|
|
||||||
userInfo.equipmentBoxCode = equipmentBoxCode
|
|
||||||
userInfo.plateNumber = plateNumber
|
|
||||||
userInfo.equipmentCode = equipmentCode
|
|
||||||
}
|
|
||||||
_bindStateChange.value = true to ErrorInfo(equipmentUserInfo = userInfo)
|
|
||||||
} else {
|
} else {
|
||||||
_bindStateChange.value = true to ErrorInfo(response.code, response.msg.toString())
|
block(false to ErrorInfo(response.code, response.msg.toString()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unbindPlate(
|
fun bindPlate(bindParam: BindParam, block:(Pair<Boolean?, ErrorInfo>)-> Unit) {
|
||||||
equipmentBoxCode: String,
|
|
||||||
equipmentCode: String = globalEquipmentCode
|
|
||||||
) {
|
|
||||||
launchWithLoading {
|
launchWithLoading {
|
||||||
val bindParam = BindParam(
|
val response = repository.plateBind(bindParam)
|
||||||
appVersion = GlobalData.appVersion,
|
|
||||||
equipmentBoxCode = equipmentBoxCode,
|
|
||||||
equipmentCode = equipmentCode
|
|
||||||
)
|
|
||||||
val response = repository.bindEquipment(bindParam)
|
|
||||||
if (parseResponse(response)) {
|
if (parseResponse(response)) {
|
||||||
_bindStateChange.value = false to ErrorInfo()
|
var userInfo = response.data
|
||||||
|
if (userInfo == null) {
|
||||||
|
userInfo = EquipmentUserInfo()
|
||||||
|
userInfo.equipmentBoxCode = bindParam.equipmentBoxCode
|
||||||
|
userInfo.plateNumber = bindParam.plateNumber
|
||||||
|
userInfo.equipmentCode = bindParam.equipmentCode
|
||||||
|
}
|
||||||
|
block(true to ErrorInfo(equipmentUserInfo = userInfo))
|
||||||
} else {
|
} else {
|
||||||
_bindStateChange.value = false to ErrorInfo(response.code, response.msg.toString())
|
block(true to ErrorInfo(response.code, response.msg.toString()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,12 +185,8 @@ class SettingViewModel : BaseViewModel() {
|
|||||||
) {
|
) {
|
||||||
_searchUserInfo.value = null
|
_searchUserInfo.value = null
|
||||||
launchWithLoading {
|
launchWithLoading {
|
||||||
val bindParam = BindParam(
|
// val bindParam = BindParam(plateNumber = plateNumber)
|
||||||
appVersion = GlobalData.appVersion,
|
val response = repository.findByPlateNumber(plateNumber)
|
||||||
plateNumber = plateNumber,
|
|
||||||
equipmentCode = equipmentCode
|
|
||||||
)
|
|
||||||
val response = repository.findByPlateNumber(bindParam)
|
|
||||||
if (response.code == 200) {
|
if (response.code == 200) {
|
||||||
_searchUserInfo.value = response.data
|
_searchUserInfo.value = response.data
|
||||||
} else {
|
} else {
|
||||||
@@ -159,4 +198,31 @@ class SettingViewModel : BaseViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val PAGE_SIZE = 100
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取人脸数据
|
||||||
|
*/
|
||||||
|
fun getFaceIncrementList(
|
||||||
|
pageNo: Int = 1,
|
||||||
|
pageSize: Int = PAGE_SIZE,
|
||||||
|
timestamp: Long,
|
||||||
|
block: (List<UserFaceModel>) -> Unit
|
||||||
|
) {
|
||||||
|
launch {
|
||||||
|
val response = repository.getFaceIncrementList(
|
||||||
|
pageNum = pageNo.toLong(),
|
||||||
|
pageSize = pageSize.toLong(),
|
||||||
|
timestamp = timestamp
|
||||||
|
)
|
||||||
|
if (parseResponse(response)) {
|
||||||
|
withContext(Dispatchers.Default) {
|
||||||
|
val list: List<UserFaceModel> = response.data ?: emptyList()
|
||||||
|
block(list)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14,6 +14,7 @@ import com.sw.platecabinet.GlobalKey
|
|||||||
import com.sw.platecabinet.model.request.LoginParam
|
import com.sw.platecabinet.model.request.LoginParam
|
||||||
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
import com.sw.platecabinet.model.response.EquipmentUserInfo
|
||||||
import com.sw.platecabinet.model.response.UserFaceModel
|
import com.sw.platecabinet.model.response.UserFaceModel
|
||||||
|
import com.sw.platecabinet.utils.SpTool
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
@@ -25,6 +26,11 @@ import timber.log.Timber
|
|||||||
* 用户viewmodel
|
* 用户viewmodel
|
||||||
*/
|
*/
|
||||||
class UserViewModel : BaseViewModel() {
|
class UserViewModel : BaseViewModel() {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val PAGE_SIZE = 100
|
||||||
|
}
|
||||||
|
|
||||||
// 通过人脸获取到的用户信息
|
// 通过人脸获取到的用户信息
|
||||||
private val _currentUserInfo = MutableStateFlow<EquipmentUserInfo?>(null)
|
private val _currentUserInfo = MutableStateFlow<EquipmentUserInfo?>(null)
|
||||||
val currentUserInfo: StateFlow<EquipmentUserInfo?> = _currentUserInfo
|
val currentUserInfo: StateFlow<EquipmentUserInfo?> = _currentUserInfo
|
||||||
@@ -34,36 +40,46 @@ class UserViewModel : BaseViewModel() {
|
|||||||
/**
|
/**
|
||||||
* 获取token
|
* 获取token
|
||||||
*/
|
*/
|
||||||
fun generateToken(deviceId: String = "SWSN:88:12:AC:4E:D9:CC") {
|
// fun generateToken(deviceId: String = "SWSN:88:12:AC:4E:D9:CC") {
|
||||||
launchWithLoading {
|
// launchWithLoading {
|
||||||
val response = repository.generateToken(deviceId)
|
// val response = repository.generateToken(deviceId)
|
||||||
if (parseResponse(response)) {
|
// if (parseResponse(response)) {
|
||||||
// 缓存token
|
// // 缓存token
|
||||||
SPUtil.getInstance().put(GlobalKey.KEY_TOKEN, response.data)
|
// SPUtil.getInstance().put(GlobalKey.KEY_TOKEN, response.data)
|
||||||
// 首次运行获取人脸数据
|
// // 首次运行获取人脸数据
|
||||||
if (SPUtil.getInstance().get(GlobalKey.KEY_FIRST_RUN, false) != true) {
|
// if (SPUtil.getInstance().get(GlobalKey.KEY_FIRST_RUN, false) != true) {
|
||||||
getUserFaceCache()
|
// getUserFaceCache()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取人脸数据
|
* 获取人脸数据
|
||||||
*/
|
*/
|
||||||
fun getUserFaceCache(index: Int = 0) {
|
fun getUserFaceCache(pageNo: Int = 1, pageSize: Int = PAGE_SIZE) {
|
||||||
|
var currentPageNo = pageNo
|
||||||
launchWithLoading {
|
launchWithLoading {
|
||||||
val response = repository.getUserFaceCache()
|
val response = repository.getUserFaceCache(pageNum = pageNo, pageSize = pageSize)
|
||||||
if (parseResponse(response)) {
|
if (parseResponse(response)) {
|
||||||
// 获取成功一次后缓存状态
|
// 获取成功一次后缓存状态
|
||||||
SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
||||||
val list: List<UserFaceModel> = response.data ?: emptyList()
|
val list: List<UserFaceModel> = response.data ?: emptyList()
|
||||||
val faceEntity = list.map {
|
if (list.isEmpty()) {
|
||||||
FaceEntity(it.userId, null, Base64.decode(it.faceFeatureString))
|
return@launchWithLoading
|
||||||
|
}
|
||||||
|
|
||||||
|
SpTool.setLastFaceTimestamp(System.currentTimeMillis())
|
||||||
|
val faceEntityList = list.map {
|
||||||
|
FaceEntity(it.userId, null, Base64.decode(it.faceFeatureStr))
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.Default) {
|
withContext(Dispatchers.Default) {
|
||||||
faceApi.updateFaceData(index, faceEntity)
|
faceApi.updateFaceData(pageNo, faceEntityList)
|
||||||
activeEngine()
|
if (list.size >= pageSize) {
|
||||||
|
currentPageNo++
|
||||||
|
getUserFaceCache(currentPageNo)
|
||||||
|
}
|
||||||
|
//activeEngine()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,14 +128,8 @@ class UserViewModel : BaseViewModel() {
|
|||||||
/**
|
/**
|
||||||
* 校验码登录
|
* 校验码登录
|
||||||
*/
|
*/
|
||||||
fun loginWithPwd(equipmentCode: String = globalEquipmentCode, phone: String, password: String) {
|
fun loginWithPwd(loginParam: LoginParam) {
|
||||||
launchWithLoading {
|
launchWithLoading {
|
||||||
val loginParam = LoginParam(
|
|
||||||
appVersion = GlobalData.appVersion,
|
|
||||||
equipmentCode = equipmentCode,
|
|
||||||
phone = phone,
|
|
||||||
password = password
|
|
||||||
)
|
|
||||||
val response = repository.equipmentBoxLogin(loginParam)
|
val response = repository.equipmentBoxLogin(loginParam)
|
||||||
if (parseResponse(response)) {
|
if (parseResponse(response)) {
|
||||||
_currentUserInfo.value = response.data
|
_currentUserInfo.value = response.data
|
||||||
@@ -130,14 +140,10 @@ class UserViewModel : BaseViewModel() {
|
|||||||
/**
|
/**
|
||||||
* 通过用户id获取用户信息
|
* 通过用户id获取用户信息
|
||||||
*/
|
*/
|
||||||
fun getUserInfoById(equipmentCode: String = globalEquipmentCode, memberId: Int, action:(EquipmentUserInfo?)->Unit={}) {
|
fun getUserInfoById(memberId: Int?, action:(EquipmentUserInfo?)->Unit={}) {
|
||||||
_currentUserInfo.value = null
|
_currentUserInfo.value = null
|
||||||
launchWithLoading {
|
launchWithLoading {
|
||||||
val loginParam = LoginParam(
|
val loginParam = LoginParam(memberId = memberId)
|
||||||
appVersion = GlobalData.appVersion,
|
|
||||||
equipmentCode = equipmentCode,
|
|
||||||
memberId = memberId
|
|
||||||
)
|
|
||||||
val response = repository.equipmentBoxLogin(loginParam)
|
val response = repository.equipmentBoxLogin(loginParam)
|
||||||
if (parseResponse(response)) {
|
if (parseResponse(response)) {
|
||||||
_currentUserInfo.value = response.data
|
_currentUserInfo.value = response.data
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ dependencies {
|
|||||||
implementation("com.licheedev:android-serialport:2.1.5")
|
implementation("com.licheedev:android-serialport:2.1.5")
|
||||||
|
|
||||||
val roomVersion = "2.2.5"
|
val roomVersion = "2.2.5"
|
||||||
implementation("androidx.room:room-runtime:$roomVersion")
|
api("androidx.room:room-runtime:$roomVersion")
|
||||||
annotationProcessor("androidx.room:room-compiler:$roomVersion")
|
annotationProcessor("androidx.room:room-compiler:$roomVersion")
|
||||||
|
|
||||||
implementation("io.reactivex.rxjava2:rxandroid:2.0.1")
|
implementation("io.reactivex.rxjava2:rxandroid:2.0.1")
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public class FaceApi {
|
|||||||
public void updateFaceData(int index, List<FaceEntity> list) {
|
public void updateFaceData(int index, List<FaceEntity> list) {
|
||||||
Log.d(TAG, "updateFaceData: index = " + index + ", listSize = " + list.size());
|
Log.d(TAG, "updateFaceData: index = " + index + ", listSize = " + list.size());
|
||||||
FaceDao faceDao = FaceDatabase.getInstance(App.getContext()).faceDao();
|
FaceDao faceDao = FaceDatabase.getInstance(App.getContext()).faceDao();
|
||||||
if (index == 0) {
|
if (index == 1) {
|
||||||
faceDao.deleteAll();
|
faceDao.deleteAll();
|
||||||
faceDao.resetId();
|
faceDao.resetId();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user