设备联调,接口参数优化

This commit is contained in:
马增飞
2025-08-08 17:48:07 +08:00
parent 0b52dad0fe
commit 9e5ede4a8e
8 changed files with 32 additions and 18 deletions
@@ -115,7 +115,8 @@ class HomeActivity : BaseActivity() {
val androidId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
Log.d(TAG, "onCreate: androidId=${androidId}")
App.getInstance().deviceId = "53babf69-0d2f-3875-a649-f2e12f80ad4c1"
App.getInstance().deviceId = androidId
//"53babf69-0d2f-3875-a649-f2e12f80ad4c1"
val swDpValue = resources?.configuration?.smallestScreenWidthDp
Log.d(TAG, "onCreate: swDpValue=$swDpValue")
@@ -166,8 +167,8 @@ class HomeActivity : BaseActivity() {
val subList01 = tempList.subList(0, 5)
val subList02 = tempList.subList(5, 10)
repeat(5) { index ->
list.add(subList01[index])
list.add(subList02[index])
list.add(subList01[index].also { it.deviceId = App.getInstance().deviceId })
list.add(subList02[index].also { it.deviceId = App.getInstance().deviceId })
}
shelfAdapter.notifyDataSetChanged()
}
@@ -189,15 +190,16 @@ class HomeActivity : BaseActivity() {
data = serialReader.toString()
} else if (srcData.startsWith(HEADER) && srcData.contains(FOOTER).not()) {
serialReader.clear()
serialReader.append(srcData)
serialReader.append(srcData).append(",")
return
} else if (srcData.contains(FOOTER).not()) {
serialReader.append(srcData)
} else if (srcData.startsWith(HEADER).not() && srcData.contains(FOOTER).not()) {
serialReader.append(srcData).append(",")
return
} else {
val endIndex = srcData.indexOf(FOOTER) + FOOTER.length
serialReader.append(srcData.substring(0, endIndex))
data = serialReader.toString()
Log.d(TAG, "receiveSerialPortData:serialReader: $serialReader")
data = serialReader.toString().replace(",","")
}
val cmd = data.substring(HEADER.length, HEADER.length + 4)
@@ -274,8 +276,9 @@ class HomeActivity : BaseActivity() {
if (index <= 10) {
list.firstOrNull { it.deviceNo == index }?.let {
it.weight = realWeightDouble
val pos = list.indexOf(it)
shelfAdapter.notifyItemChanged(pos)
}
shelfAdapter.notifyItemChanged(index)
}
count += 8
@@ -337,6 +340,7 @@ class HomeActivity : BaseActivity() {
val model =
getSerializableExtra(ShelfActivity.SHELF_MODEL) as ShelfModel
list[position].apply {
goodsId = model.goodsId
goodsName = model.goodsName
weight = model.weight
createTime = model.createTime
@@ -103,6 +103,7 @@ class ShelfActivity : BaseActivity() {
}
val data = ShelfModel(
shelfName = shelfModel?.shelfName,
goodsId = list[clickIndex].goodsId?:"",
goodsName = list[clickIndex].goodsName,
weight = realWeight / 1000.0,
createTime = DateTimeUtil.formatDateTime(dateTime = Date())
@@ -124,6 +125,9 @@ class ShelfActivity : BaseActivity() {
val zeroClearingCmd = "${HomeActivity.HEADER}0401${hex}${HomeActivity.FOOTER}"
Log.d(TAG, "onCreate: zeroClearingCmd=$zeroClearingCmd")
SerialPortManager.send(zeroClearingCmd)
//清零
realWeight = 0
binding.tvFoodWeight.text = "${realWeight}"
}
KeyboardUtil.hideKeyboard(v.context, v)
}
@@ -163,6 +167,8 @@ class ShelfActivity : BaseActivity() {
it.finishRefresh(500)
} else if (binding.refreshLayout.state == RefreshState.Loading) {
it.finishLoadMore(500)
} else {
}
}
@@ -8,6 +8,7 @@ data class ShelfModel(
var shelfName: String? = null,
var goodsId: String = "",
var goodsName: String? = null,
var deviceId: String? = null,
var weight: Double? = null,
var createTime: String? = null
) : Serializable
@@ -20,16 +20,16 @@ class NetViewModel : ViewModel() {
// .build()
// .create(ApiService::class.java)
private val _getShelfListUiState = MutableStateFlow<UiState>(UiState.Loading)
private val _getShelfListUiState = MutableStateFlow<UiState>(UiState.Initial)
val getShelfListUiState: StateFlow<UiState> = _getShelfListUiState
private val _saveShelfGoodsListUiState = MutableStateFlow<UiState>(UiState.Loading)
private val _saveShelfGoodsListUiState = MutableStateFlow<UiState>(UiState.Initial)
val saveShelfGoodsListUiState: StateFlow<UiState> = _saveShelfGoodsListUiState
private val _getGoodsListUiState = MutableStateFlow<UiState>(UiState.Loading)
private val _getGoodsListUiState = MutableStateFlow<UiState>(UiState.Initial)
val getGoodsListUiState: StateFlow<UiState> = _getGoodsListUiState
private val _getAccessTokenUiState = MutableStateFlow<UiState>(UiState.Loading)
private val _getAccessTokenUiState = MutableStateFlow<UiState>(UiState.Initial)
val getAccessTokenUiState: StateFlow<UiState> = _getAccessTokenUiState
fun getAccessToken(deviceId: String) {
@@ -1,6 +1,7 @@
package com.shuwei.intelligent.shelves.net
sealed class UiState {
object Initial : UiState()
object Loading : UiState()
data class Success<T>(val data: RespData<T>) : UiState()
data class Error(val msg: String) : UiState()
@@ -2,11 +2,12 @@ package com.shuwei.intelligent.shelves.net
object UrlConfig {
const val BASE_URL = "http://192.168.1.7:9002"
const val GET_ACCESS_TOKEN = "/restaurant/equipment/stEquipment/getEquipmentToken"
const val GET_SHELF_LIST = "/inventory/smartShelves/app/getShelvesListByDeviceId"
const val GET_GOODS_LIST = "/inventory/smartShelves/app/getGoodsPageList"
const val SAVE_SHELF_GOODS_LIST = "/inventory/smartShelves/app/saveShelvesGoodsList"
//const val BASE_URL = "http://192.168.1.7:9002"
const val BASE_URL = "https://yyjk.shuziweidao.com/gateway/"
const val GET_ACCESS_TOKEN = "restaurant/equipment/stEquipment/getEquipmentToken"
const val GET_SHELF_LIST = "inventory/smartShelves/app/getShelvesListByDeviceId"
const val GET_GOODS_LIST = "inventory/smartShelves/app/getGoodsPageList"
const val SAVE_SHELF_GOODS_LIST = "inventory/smartShelves/app/saveShelvesGoodsList"
}
@@ -44,6 +44,7 @@ class SyncTask(appContext: Context, workerParams: WorkerParameters) :
it.goodsList = submitList
}
val resp = apiService.saveShelfGoodsList(body)
Log.d(TAG, "performSync: body:${body.toJsonString()}")
Log.d(TAG, "performSync: resp:${resp.toJsonString()}")
}
}
@@ -12,7 +12,7 @@ object TaskManager {
fun startTask() {
val nextRequest = OneTimeWorkRequestBuilder<SyncTask>()
.setInitialDelay(3, TimeUnit.MINUTES)
// .setInitialDelay(10, TimeUnit.SECONDS)
// .setInitialDelay(30, TimeUnit.SECONDS)
// .setInputData(inputData)
.build()
WorkManager.getInstance(App.getInstance())