新接口调试

This commit is contained in:
2026-01-30 18:01:07 +08:00
parent a4905e7226
commit eaa1b1eb00
10 changed files with 74 additions and 181 deletions
@@ -9,7 +9,6 @@ import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.shuwei.dish.match.R import com.shuwei.dish.match.R
import com.shuwei.dish.match.entity.FoodRecord import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.databinding.ListItemDishBinding import com.shuwei.dish.match.databinding.ListItemDishBinding
import com.shuwei.dish.match.utils.ext.gone
import com.shuwei.dish.match.utils.ext.visible import com.shuwei.dish.match.utils.ext.visible
import java.text.DecimalFormat import java.text.DecimalFormat
@@ -28,9 +27,9 @@ class SamplingAdapter(list: MutableList<FoodRecord>) :
holder.binding.run { holder.binding.run {
val isCooking = item!!.isCooking val isCooking = item!!.isCooking
clBlock.setBackgroundResource(R.drawable.shape_white_fb_15_corners) clBlock.setBackgroundResource(R.drawable.shape_white_fb_15_corners)
val totalWeight = item!!.totalWeight ?: 0.toDouble() val totalWeight = item.totalWeight ?: 0.toDouble()
tvDishName.run { tvDishName.run {
text = item!!.foodName text = (item.foodName?:"").ifBlank { "--" }
setTextColor( setTextColor(
ContextCompat.getColor( ContextCompat.getColor(
holder.itemView.context, holder.itemView.context,
@@ -43,9 +42,14 @@ class SamplingAdapter(list: MutableList<FoodRecord>) :
tvDishCount.text = "制作统计:-kg" tvDishCount.text = "制作统计:-kg"
tvShowState.text = "烹饪中" tvShowState.text = "烹饪中"
} else { } else {
val useWeight = if (totalWeight > 0.toDouble()) totalWeight else (item.foodWeight ?: 0.toDouble()) val realTotalWeight = if (totalWeight > 0.toDouble()) totalWeight else (item.foodWeight
tvDishCount.text = "累计统计:${df.format(useWeight / 1000.0F)}kg(${item.count}次)" ?: 0.toDouble())
tvShowState.text = "${df.format((item.foodWeight ?: 0.toDouble()) / 1000.0F)}kg" val showTotalWeight =
if (realTotalWeight == 0.toDouble()) "-" else df.format(realTotalWeight / 1000.0F)
tvDishCount.text = "累计统计:${showTotalWeight}kg(${item.count ?: "-"}次)"
val foodWeight = item.foodWeight ?: 0.toDouble()
val showFoodWeight = if (foodWeight == 0.toDouble()) "-" else df.format(foodWeight / 1000.0F)
tvShowState.text = "${showFoodWeight}kg"
} }
} }
} }
@@ -32,10 +32,10 @@ class BaseApp : Application() {
// const val canteenId = "1678234139391512577" // const val canteenId = "1678234139391512577"
var canteenId = "0" var canteenId = "0"
var configUrl = "" // var configUrl = ""
var token: String? = null // var token: String? = null
var deviceId: String? = null // var deviceId: String? = null
var appVersion: String = "1" var appVersion: String = "1"
@Volatile @Volatile
private var sharedPref: SharedPreferences? = null private var sharedPref: SharedPreferences? = null
@@ -138,7 +138,7 @@ class FoodSearchDialog(
} }
private var pageNo = 1 private var pageNo = 1
private val pageSize = 120 private val pageSize = 50
/** /**
*/ */
@@ -204,22 +204,27 @@ class FoodSearchDialog(
"pageSize" to pageSize "pageSize" to pageSize
) )
if (goodsName.isNullOrBlank().not()) { if (goodsName.isNullOrBlank().not()) {
param.put("name", goodsName!!) param.put("goodsName", goodsName!!)
} }
activity?.queryGoodsList(param = param, onSuccess = { activity?.queryGoodsList(param = param, onSuccess = {
loadGoodsList(it) loadGoodsList(it)
}, onFailure = { code, msg -> }, onFailure = { code, msg ->
activity?.toast(msg) activity?.toast(msg)
if (pageNo == 1) { finishRefresh()
binding.refreshLayout.finishRefresh(1200)
} else {
binding.refreshLayout.finishLoadMore(1200)
}
}) })
} }
private fun finishRefresh() {
if (pageNo == 1) {
binding.refreshLayout.finishRefresh()
} else {
binding.refreshLayout.finishLoadMore()
}
}
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
private fun loadGoodsList(records: MutableList<CookFoodGoodsEntity>?) { private fun loadGoodsList(records: MutableList<CookFoodGoodsEntity>?) {
finishRefresh()
if (records.isNullOrEmpty()) { if (records.isNullOrEmpty()) {
activity?.toast("暂未搜索到食材信息") activity?.toast("暂未搜索到食材信息")
return return
@@ -229,11 +234,6 @@ class FoodSearchDialog(
} }
list.addAll(records) list.addAll(records)
searchAdapter.notifyDataSetChanged() searchAdapter.notifyDataSetChanged()
if (pageNo == 1) {
binding.refreshLayout.finishRefresh(1200)
} else {
binding.refreshLayout.finishLoadMore(1200)
}
val isLoadMoreEnable = records.size >= pageSize val isLoadMoreEnable = records.size >= pageSize
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable) binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
if (isLoadMoreEnable) { if (isLoadMoreEnable) {
@@ -167,6 +167,7 @@ class SeasoningSearchDialog(
} }
} }
binding.refreshLayout.setEnableRefresh(false) binding.refreshLayout.setEnableRefresh(false)
binding.refreshLayout.setEnableLoadMore(false)
binding.tvClear.setOnClickListener { binding.tvClear.setOnClickListener {
Log.d(TAG, "show: weighAddress=$weighAddress") Log.d(TAG, "show: weighAddress=$weighAddress")
WeightUtil.tareTwo(weighAddress) WeightUtil.tareTwo(weighAddress)
@@ -204,7 +205,7 @@ class SeasoningSearchDialog(
private var currentWeight = 0.toDouble() private var currentWeight = 0.toDouble()
private var pageNo = 1 private var pageNo = 1
private val pageSize = 120 private val pageSize = 50
/** /**
*/ */
@@ -271,7 +272,7 @@ class SeasoningSearchDialog(
"pageSize" to pageSize "pageSize" to pageSize
) )
if (goodsName.isNullOrBlank().not()) { if (goodsName.isNullOrBlank().not()) {
param.put("name", goodsName!!) param.put("goodsName", goodsName!!)
} }
activity?.querySeasoningList( activity?.querySeasoningList(
param = param, param = param,
@@ -280,17 +281,14 @@ class SeasoningSearchDialog(
}, },
onFailure = { code, msg -> onFailure = { code, msg ->
activity?.toast(msg) activity?.toast(msg)
if (pageNo == 1) { finishRefresh()
binding.refreshLayout.finishRefresh(1200)
} else {
binding.refreshLayout.finishLoadMore(1200)
}
} }
) )
} }
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
private fun loadGoodsList(records: MutableList<SeasoningEntity>?) { private fun loadGoodsList(records: MutableList<SeasoningEntity>?) {
finishRefresh()
if (records.isNullOrEmpty()) { if (records.isNullOrEmpty()) {
activity?.toast("暂未搜索到调料信息") activity?.toast("暂未搜索到调料信息")
return return
@@ -300,11 +298,6 @@ class SeasoningSearchDialog(
} }
list.addAll(records) list.addAll(records)
searchAdapter.notifyDataSetChanged() searchAdapter.notifyDataSetChanged()
if (pageNo == 1) {
binding.refreshLayout.finishRefresh(1200)
} else {
binding.refreshLayout.finishLoadMore(1200)
}
val isLoadMoreEnable = records.size >= pageSize val isLoadMoreEnable = records.size >= pageSize
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable) binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
if (isLoadMoreEnable) { if (isLoadMoreEnable) {
@@ -312,6 +305,13 @@ class SeasoningSearchDialog(
} }
} }
private fun finishRefresh() {
if (pageNo == 1) {
binding.refreshLayout.finishRefresh()
} else {
binding.refreshLayout.finishLoadMore()
}
}
fun getTextSpan(weight: Double): SpannableStringBuilder { fun getTextSpan(weight: Double): SpannableStringBuilder {
var topWeight = "$weight" var topWeight = "$weight"
@@ -13,14 +13,6 @@ import retrofit2.http.Url
interface ApiService { interface ApiService {
// @GET("/food/stFoodInfoMatching/list")
// suspend fun getFoodList(
// @Query("dinnerType") dinnerType: String,
// @Query("canteenId") canteenId: String = BaseApp.canteenId,
// @Query("pageNo") pageNo: Int,
// @Query("pageSize") pageSize: Int
// ): ApiResponse<FoodRecordBean?>
/** /**
* 查询菜品详情 * 查询菜品详情
*/ */
@@ -67,8 +59,8 @@ interface ApiService {
@Body param: MutableMap<String, Any> @Body param: MutableMap<String, Any>
): ApiResponse<MutableList<CookFoodGoodsEntity>?> ): ApiResponse<MutableList<CookFoodGoodsEntity>?>
/** /**
* 物品信息 * 调料信息
*/ */
@POST @POST
suspend fun querySeasoningList( suspend fun querySeasoningList(
@@ -1,68 +0,0 @@
//package com.shuwei.dish.match.net
//
//import com.shuwei.dish.match.base.BaseApp
//import com.shuwei.dish.match.base.BaseReq
//import com.shuwei.dish.match.entity.FoodRecordBean
//import com.shuwei.dish.match.http.UrlConfig
//import retrofit2.http.Body
//import retrofit2.http.GET
//import retrofit2.http.POST
//import retrofit2.http.Query
//import retrofit2.http.Url
//
//interface ApiService2 {
//
// @GET("food/stFoodInfoMatching/list")
// suspend fun getDishList(
// @Query("dinnerType") dinnerType: String,
// @Query("canteenId") canteenId: String = BaseApp.canteenId,
// @Query("pageNo") pageNo: Int,
// @Query("pageSize") pageSize: Int
// ): BaseReq<FoodRecordBean?>
//
//// /**
//// * device获取token
//// */
//// @GET("/sys/getEquipmentToken")
//// suspend fun getDeviceToken(
//// @Query("qrcodeId") qrcodeId: String,
//// @Query("appVersion") appVersion: String = App.appVersion
//// ): ApiResponse<String>
////
//// /**
//// *获取配置信息
//// */
//// @GET("/equipment/stEquipment/queryByEquipmentCode")
//// suspend fun getDeviceInfo(
//// @Query("equipmentCode") equipmentCode: String,
//// @Query("appVersion") appVersion: String = App.appVersion
//// ): ApiResponse<DeviceConfigInfo>
////
//// @GET
//// suspend fun getAccessToken(
//// @Url url: String = UrlConfig.GET_ACCESS_TOKEN,
//// @Query("qrcodeId") qrcodeId: String
//// ): ApiResponse<String?>
////
//// @GET
//// suspend fun getShelfList(
//// @Url url: String = UrlConfig.GET_SHELF_LIST,
//// @Query("deviceId") deviceId: String
//// ): ApiResponse<ShelfResult>
////
//// @GET
//// suspend fun getGoodsList(
//// @Url url: String = UrlConfig.GET_GOODS_LIST,
//// @Query("canteenId") canteenId: String = "0",
//// @Query("goodsName") goodsName: String? = null,
//// @Query("pageNo") pageNo: Int = 1,
//// @Query("pageSize") pageSize: Int = 50
//// ): ApiResponse<MutableList<GoodsModel>?>
////
//// @POST
//// suspend fun saveShelfGoodsList(
//// @Url url: String = UrlConfig.SAVE_SHELF_GOODS_LIST,
//// @Body body: ShelfBody
//// ): ApiResponse<Any?>
//
//}
@@ -10,36 +10,6 @@ import kotlinx.coroutines.launch
class NetViewModel : ViewModel() { class NetViewModel : ViewModel() {
// fun getFoodList(
// dinnerType: String,
// pageNo: Int,
// pageSize: Int,
// onSuccess: (FoodRecordBean?) -> Unit,
// onFailure: (String, String) -> Unit
// ) {
// viewModelScope.launch {
// apiRequest(
// onRequest = {
// apiService2.getDishList(
// dinnerType = dinnerType,
// pageNo = pageNo,
// pageSize = pageSize
// )
// },
// onSuccess = {
// if (it.code == 200) {
// onSuccess(it.data)
// return@apiRequest
// }
// onFailure("${it.code}", it.msg ?: "")
// },
// onFailure = {
// onFailure("-1", it.errorMsg)
// }
// )
// }
// }
fun submitCookFood( fun submitCookFood(
entity: CookFoodEntity, entity: CookFoodEntity,
onSuccess: (Any?) -> Unit, onSuccess: (Any?) -> Unit,
@@ -197,8 +197,8 @@ class FoodSearchActivity : BaseActivity() {
val map = mutableMapOf<String, Any>( val map = mutableMapOf<String, Any>(
"foodName" to input.trim(), "foodName" to input.trim(),
"pageNum" to "$pageNo", "pageNum" to pageNo,
"pageSize" to "$pageSize", "pageSize" to pageSize,
"placeId" to BaseApp.canteenId, "placeId" to BaseApp.canteenId,
"dinnerType" to getDinnerTypeText() "dinnerType" to getDinnerTypeText()
) )
@@ -207,10 +207,7 @@ class FoodSearchActivity : BaseActivity() {
onSuccess = { onSuccess = {
delayDismissLoading() delayDismissLoading()
finishRefresh() finishRefresh()
binding.refreshLayout.run { binding.refreshLayout.setEnableRefresh(true)
setEnableRefresh(true)
}
// if (it == null || it.records.isNullOrEmpty()) {
if (it.isNullOrEmpty()) { if (it.isNullOrEmpty()) {
// toast("暂未搜索到相关菜品信息") // toast("暂未搜索到相关菜品信息")
if (pageNo == 1) { if (pageNo == 1) {
@@ -218,7 +215,6 @@ class FoodSearchActivity : BaseActivity() {
} }
return@searchFoodList return@searchFoodList
} }
// val records = it.records
if (pageNo == 1) { if (pageNo == 1) {
list.clear() list.clear()
} }
@@ -44,12 +44,11 @@ class InitActivity : BaseActivity() {
BaseApp.appVersion = AppUtil.getAppVersionCode(this).toString() BaseApp.appVersion = AppUtil.getAppVersionCode(this).toString()
// 获取 ANDROID_ID // 获取 ANDROID_ID
var androidId = // var androidId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID) // androidId = "39a7abdd06b3c7ab"
androidId = "39a7abdd06b3c7ab" // BaseApp.deviceId = androidId
BaseApp.deviceId = androidId // SpTool.put(SpTool.DEVICE_ID, androidId)
SpTool.put(SpTool.DEVICE_ID, androidId) // BaseApp.configUrl = UrlConfig.BASE_URL
BaseApp.configUrl = UrlConfig.BASE_URL
BaseApp.canteenId = "0" BaseApp.canteenId = "0"
// // TODO: 以上保存deviceId用于临时使用,后续改为下面注释方式 // // TODO: 以上保存deviceId用于临时使用,后续改为下面注释方式
@@ -150,18 +149,18 @@ class InitActivity : BaseActivity() {
} }
} }
private fun initConfig() { // private fun initConfig() {
binding.ivQrCode.setImageBitmap( // binding.ivQrCode.setImageBitmap(
QRCodeUtil.generateQRCode( // QRCodeUtil.generateQRCode(
content = BaseApp.deviceId ?: "", // content = BaseApp.deviceId ?: "",
size = 200.dp // size = 200.dp
) // )
) // )
binding.btnInit.setOnClickListener { // binding.btnInit.setOnClickListener {
// HttpUtil.loopGetToken = false //// HttpUtil.loopGetToken = false
// getDeviceConfig() //// getDeviceConfig()
} // }
} // }
// private fun getDeviceConfig() { // private fun getDeviceConfig() {
// val tokenUrl = // val tokenUrl =
@@ -203,18 +202,18 @@ class InitActivity : BaseActivity() {
var canteenId: String? = null var canteenId: String? = null
) )
private fun checkConfigData(data: String): Boolean { // private fun checkConfigData(data: String): Boolean {
if (data.isBlank()) { // if (data.isBlank()) {
return false // return false
} // }
val config = data.toObject<DeviceConfigBean?>() // val config = data.toObject<DeviceConfigBean?>()
if (config == null) { // if (config == null) {
return false // return false
} // }
BaseApp.configUrl = config.appPackageUrl ?: "" // BaseApp.configUrl = config.appPackageUrl ?: ""
BaseApp.canteenId = config.canteenId ?: "" // BaseApp.canteenId = config.canteenId ?: ""
return true // return true
} // }
override fun onDestroy() { override fun onDestroy() {
WeightUtil.stopContinuousRead() WeightUtil.stopContinuousRead()
@@ -156,10 +156,10 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
"placeId" to BaseApp.canteenId, "placeId" to BaseApp.canteenId,
"dinnerType" to getDinnerTypeText() "dinnerType" to getDinnerTypeText()
), ),
onSuccess = { recordBean -> onSuccess = { records ->
activity.delayDismissLoading() activity.delayDismissLoading()
finishRefresh() finishRefresh()
loadDishList(recordBean) loadDishList(records)
}, },
onFailure = { code, msg -> onFailure = { code, msg ->
if (isAdded.not()) { if (isAdded.not()) {