init
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.sw.inbound.network
|
||||
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
object LoadingState {
|
||||
private var _isLoading by mutableStateOf(false)
|
||||
val isLoading: Boolean get() = _isLoading
|
||||
|
||||
private val counter = AtomicInteger(0)
|
||||
|
||||
fun show() = counter.incrementAndGet().let { if (it == 1) _isLoading = true }
|
||||
fun hide() = counter.decrementAndGet().let { if (it <= 0) _isLoading = false }
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.sw.inbound.network.api
|
||||
|
||||
import com.sw.inbound.model.request.GoodsAddParam
|
||||
import com.sw.inbound.model.request.LoginParam
|
||||
import com.sw.inbound.model.request.PurchaseWarehouseParam
|
||||
import com.sw.inbound.model.request.UploadInfo
|
||||
import com.sw.inbound.model.response.ApiResponse
|
||||
import com.sw.inbound.model.response.DictType
|
||||
import com.sw.inbound.model.response.GoodsType
|
||||
import com.sw.inbound.model.response.PurchaseInfo
|
||||
import com.sw.inbound.model.response.SearchGoodsInfo
|
||||
import com.sw.inbound.model.response.StorageType
|
||||
import com.sw.inbound.model.response.SupplierResponse
|
||||
import com.sw.inbound.model.response.User
|
||||
import okhttp3.MultipartBody
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Multipart
|
||||
import retrofit2.http.POST
|
||||
import retrofit2.http.Part
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface ApiService {
|
||||
/**
|
||||
* 登录
|
||||
*/
|
||||
@POST("/shuwei-user/swuserbase/loginPad")
|
||||
suspend fun login(@Body body: LoginParam): ApiResponse<User>
|
||||
|
||||
/**
|
||||
* 采购单入库-列表
|
||||
*/
|
||||
@GET("/shuwei-zhct/pad/receivePage")
|
||||
suspend fun getReceiveList(
|
||||
@Query("pageNo") pageNo: Int,
|
||||
@Query("pageSize") pageSize: Int
|
||||
): ApiResponse<SupplierResponse>
|
||||
|
||||
/**
|
||||
* 采购单入库-详情
|
||||
*/
|
||||
@GET("/shuwei-zhct/pad/receiveDetail")
|
||||
suspend fun getReceiveDetail(@Query("id") id: Int): ApiResponse<PurchaseInfo>
|
||||
|
||||
/**
|
||||
* 部分收货
|
||||
*/
|
||||
@POST("/shuwei-zhct/pad/partialReceiptGoods")
|
||||
suspend fun partialReceipt(@Body uploadInfo: UploadInfo): ApiResponse<Boolean>
|
||||
|
||||
/**
|
||||
* 确认收货
|
||||
*/
|
||||
@POST("/shuwei-zhct/pad/saveAndReceiveAndGoWare")
|
||||
suspend fun confirmReceipt(@Body uploadInfo: UploadInfo): ApiResponse<Boolean>
|
||||
|
||||
/**
|
||||
* 存储方式
|
||||
*/
|
||||
@GET("/shuwei-zhct/swsysdictitem/getDictItemByF")
|
||||
suspend fun getGoodsStorageType(@Query("dictCode") dictCode: String = "goods_storage_type"): ApiResponse<List<StorageType>>
|
||||
|
||||
/**
|
||||
* 物品类型
|
||||
*/
|
||||
@GET("/shuwei-zhct/swkcglgoodstype/notLimitList")
|
||||
suspend fun getGoodsType(): ApiResponse<GoodsType>
|
||||
|
||||
/**
|
||||
* 获取字典数据
|
||||
*/
|
||||
@GET("/shuwei-zhct/pad/dataList")
|
||||
suspend fun getDictType(@Query("type") type: String): ApiResponse<List<DictType>>
|
||||
|
||||
/**
|
||||
* 上传图片
|
||||
*/
|
||||
@Multipart
|
||||
@POST("/shuwei-zhct/fileUpload/fileUpload/")
|
||||
suspend fun uploadImage(
|
||||
@Part("code") code: RequestBody,
|
||||
@Part file: MultipartBody.Part
|
||||
): ApiResponse<String>
|
||||
|
||||
/**
|
||||
* 搜索物品列表
|
||||
*/
|
||||
@GET("/shuwei-zhct/pad/goodsInfoList")
|
||||
suspend fun searchGoodsInfoList(
|
||||
@Query("goodsName") goodsName: String,
|
||||
@Query("pageNo") pageNo: Int,
|
||||
@Query("pageSize") pageSize: Int
|
||||
): ApiResponse<SearchGoodsInfo>
|
||||
|
||||
/**
|
||||
* 自采添加商品
|
||||
*/
|
||||
@POST("/shuwei-zhct/pad/goodsAdd")
|
||||
suspend fun selfPurchaseGoodsAdd(@Body goodsAddParam: GoodsAddParam): ApiResponse<SearchGoodsInfo>
|
||||
|
||||
/**
|
||||
* 自采入库
|
||||
*/
|
||||
@POST("/shuwei-zhct/pad/SelfPurchasedGoods")
|
||||
suspend fun selfPurchaseWarehousing(@Body list: List<PurchaseWarehouseParam>): ApiResponse<Boolean>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sw.inbound.network.interceptor
|
||||
|
||||
import com.google.gson.JsonParseException
|
||||
import com.sw.inbound.model.exception.NetException
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import retrofit2.HttpException
|
||||
import timber.log.Timber
|
||||
import java.io.IOException
|
||||
|
||||
class ErrorInterceptor : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
try {
|
||||
val response = chain.proceed(chain.request())
|
||||
if (!response.isSuccessful) {
|
||||
throw NetException(response.code, "HTTP Error ${response.code}")
|
||||
}
|
||||
return response
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e)
|
||||
throw when (e) {
|
||||
is IOException -> NetException(-1, "Network error: ${e.message}")
|
||||
is JsonParseException -> NetException(-2, "Data parse error")
|
||||
is HttpException -> NetException(-3, e.message ?: "未知错误")
|
||||
else -> NetException(-100, e.message ?: "未知错误")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.sw.inbound.network.interceptor
|
||||
|
||||
import com.sw.inbound.GlobalKey
|
||||
import com.sw.inbound.utils.ContextUtils
|
||||
import com.sw.inbound.utils.SPUtil
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
|
||||
class RequestInterceptor : Interceptor {
|
||||
override fun intercept(chain: Interceptor.Chain): Response {
|
||||
val originalRequest = chain.request()
|
||||
val requestBuilder = originalRequest.newBuilder()
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Accept", "application/json")
|
||||
// .header("Authorization", "Bearer ${getToken()}")
|
||||
.header("Authorization", getToken())
|
||||
|
||||
val newRequest = requestBuilder.build()
|
||||
|
||||
return chain.proceed(newRequest)
|
||||
}
|
||||
|
||||
private fun getToken(): String {
|
||||
// 从本地获取token的逻辑
|
||||
val spUtil = SPUtil.getInstance(context = ContextUtils.getAppContext())
|
||||
return spUtil.get(GlobalKey.KEY_TOKEN, "") as String
|
||||
// return "eyJhbGciOiJIUzUxMiJ9.eyJpZCI6MTQ2LCJ1c2VyTmFtZSI6IjEzNjgxNDQ4ODU2IiwibmFtZSI6IuW-kOejiiIsInBhc3N3b3JkIjoiOTllOTQ1ZmVjZmZjNWIzNDI4MmUwNDRlODYyMzdjM2UxZjU5OWY5OCIsInNhbHQiOiI0NmEzMzUzYWU4OTA0MDYxYjMzODU5ZWNlYTBlMGE2NyIsInBob25lIjoiMTM2ODE0NDg4NTYiLCJzdGF0dXMiOjEsInVzZXJUeXBlIjoyLCJjcmVhdGVVc2VyTm8iOiIxNDEiLCJjcmVhdGVUaW1lIjoxNjI2OTQzNDE2MDAwLCJ1cGRhdGVVc2VyTm8iOiIxNDEiLCJ1cGRhdGVUaW1lIjoxNjI2OTQzNDE2MDAwLCJpc0RlbCI6ZmFsc2UsImVhSWQiOjk5LCJlYUlkTGlzdCI6Ijk5IiwiaXNTaG9wTWFuYWdlciI6dHJ1ZSwidXNlck5vIjoiMWY5Nzk5ZWMtODlkYi00MWYyLTk1YTEtY2UzNTA3Y2QyMTU2In0.f7wImPgBOYMV0AqRchnXGPkUWZN9dFJ9gLPsaB8uNldd21IfXLjJl8y-FiWVuVUvlwUvGpgqGDFR1JKj5H7amw"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user