@@ -1,11 +1,18 @@
|
||||
package com.example.ops_android.data.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class Container(
|
||||
val id: Int = 0,
|
||||
val name: String? = null,
|
||||
val parent_id: Int = 0,
|
||||
val barcode: String? = null,
|
||||
val remark: String? = null,
|
||||
val created_at: String? = null,
|
||||
val user_id: Int? = null
|
||||
)
|
||||
@SerializedName("ID") val id: Int = 0,
|
||||
@SerializedName("Title") val name: String? = null,
|
||||
@SerializedName("ParentID") val parent_id: Int = 0,
|
||||
@SerializedName("Remark") val remark: String? = null,
|
||||
@SerializedName("CreatedAt") val created_at: String? = null,
|
||||
@SerializedName("CreatorID") val user_id: Int? = null,
|
||||
@SerializedName("ItemCount") val item_count: Int = 0,
|
||||
@SerializedName("ChildCount") val child_count: Int = 0,
|
||||
@SerializedName("Color") val color: String? = null,
|
||||
@SerializedName("barcode") private val _barcode: String? = null
|
||||
) {
|
||||
val barcode: String? get() = _barcode
|
||||
}
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
package com.example.ops_android.data.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class Customer(
|
||||
val id: Int = 0,
|
||||
val name: String? = null,
|
||||
val phone: String? = null,
|
||||
val email: String? = null,
|
||||
val address: String? = null,
|
||||
val remark: String? = null,
|
||||
val created_at: String? = null,
|
||||
val user_id: Int? = null
|
||||
)
|
||||
@SerializedName("id") val id: Int = 0,
|
||||
@SerializedName("first_name") val first_name: String? = null,
|
||||
@SerializedName("last_name") val last_name: String? = null,
|
||||
@SerializedName("primary_phone") val phone: String? = null,
|
||||
@SerializedName("primary_email") val email: String? = null,
|
||||
@SerializedName("created_at") val created_at: String? = null,
|
||||
@SerializedName("created_by") val user_id: Int? = null,
|
||||
@SerializedName("address") private val _address: String? = null,
|
||||
@SerializedName("remark") private val _remark: String? = null
|
||||
) {
|
||||
// backward-compat with UI code
|
||||
val name: String? get() = listOfNotNull(first_name, last_name).joinToString(" ").ifEmpty { null }
|
||||
val address: String? get() = _address
|
||||
val remark: String? get() = _remark
|
||||
}
|
||||
|
||||
@@ -1,22 +1,28 @@
|
||||
package com.example.ops_android.data.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class Item(
|
||||
val id: Int = 0,
|
||||
val name: String? = null,
|
||||
val serial_number: String? = null,
|
||||
val spec: String? = null,
|
||||
val container_id: Int = 0,
|
||||
val barcode: String? = null,
|
||||
val remark: String? = null,
|
||||
val photos: List<String>? = null,
|
||||
val move_history: List<MoveHistory>? = null,
|
||||
val created_at: String? = null,
|
||||
val user_id: Int? = null
|
||||
)
|
||||
@SerializedName("ID") val id: Int = 0,
|
||||
@SerializedName("Name") val name: String? = null,
|
||||
@SerializedName("SerialNumber") val serial_number: String? = null,
|
||||
@SerializedName("Remark") val remark: String? = null,
|
||||
@SerializedName("Quantity") val quantity: Int = 1,
|
||||
@SerializedName("ContainerID") val container_id: Int = 0,
|
||||
@SerializedName("CreatedAt") val created_at: String? = null,
|
||||
@SerializedName("CreatorID") val user_id: Int? = null,
|
||||
@SerializedName("barcode") private val _barcode: String? = null,
|
||||
@SerializedName("spec") private val _spec: String? = null,
|
||||
@SerializedName("move_history") private val _move_history: List<MoveHistory>? = null
|
||||
) {
|
||||
val barcode: String? get() = _barcode
|
||||
val spec: String? get() = _spec
|
||||
val move_history: List<MoveHistory>? get() = _move_history
|
||||
}
|
||||
|
||||
data class MoveHistory(
|
||||
val from_container: String? = null,
|
||||
val to_container: String? = null,
|
||||
val moved_at: String? = null,
|
||||
val user_id: Int? = null
|
||||
@SerializedName("from_container") val from_container: String? = null,
|
||||
@SerializedName("to_container") val to_container: String? = null,
|
||||
@SerializedName("moved_at") val moved_at: String? = null,
|
||||
@SerializedName("user_id") val user_id: Int? = null
|
||||
)
|
||||
|
||||
@@ -1,31 +1,51 @@
|
||||
package com.example.ops_android.data.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class PurchaseOrder(
|
||||
val id: Int = 0,
|
||||
val title: String? = null,
|
||||
val status: String? = null,
|
||||
val remark: String? = null,
|
||||
val link: String? = null,
|
||||
val style_tags: List<String>? = null,
|
||||
val costs: List<Cost>? = null,
|
||||
val photos: List<String>? = null,
|
||||
val work_order_ids: List<Int>? = null,
|
||||
val status_logs: List<StatusLog>? = null,
|
||||
val created_at: String? = null,
|
||||
val updated_at: String? = null,
|
||||
val user_id: Int? = null
|
||||
@SerializedName("ID") val id: Int = 0,
|
||||
@SerializedName("Title") val title: String? = null,
|
||||
@SerializedName("OrderStatus") val status: String? = null,
|
||||
@SerializedName("Remark") val remark: String? = null,
|
||||
@SerializedName("Link") val link: String? = null,
|
||||
@SerializedName("Styles") val style_tags: String? = null,
|
||||
@SerializedName("CreatedAt") val created_at: String? = null,
|
||||
@SerializedName("UpdatedAt") val updated_at: String? = null,
|
||||
@SerializedName("UserID") val user_id: Int? = null,
|
||||
// Filled from detail API (not in list API)
|
||||
@kotlin.jvm.Transient val costs: List<Cost>? = null,
|
||||
@kotlin.jvm.Transient val status_logs: List<StatusLog>? = null
|
||||
)
|
||||
|
||||
data class Cost(
|
||||
val amount: Double = 0.0,
|
||||
val currency: String = "CNY",
|
||||
val remark: String? = null
|
||||
@SerializedName("Price") val price: Double = 0.0,
|
||||
@SerializedName("Quantity") val quantity: Int = 0,
|
||||
@SerializedName("CurrencyType") val currencyType: Int = 1,
|
||||
@SerializedName("CostType") val costType: Int = 1
|
||||
) {
|
||||
// backward-compat for UI
|
||||
val amount: Double get() = price
|
||||
val currency: String get() = when (currencyType) { 1 -> "CNY"; 2 -> "MOP"; 3 -> "HKD"; 4 -> "USD"; else -> "CNY" }
|
||||
val remark: String? get() = null
|
||||
}
|
||||
|
||||
data class PurchasePhoto(
|
||||
@SerializedName("Sha256") val sha256: String? = null,
|
||||
@SerializedName("Name") val name: String? = null,
|
||||
@SerializedName("Path") val path: String? = null
|
||||
)
|
||||
|
||||
data class StatusLog(
|
||||
val status: String? = null,
|
||||
val comment: String? = null,
|
||||
val photos: List<String>? = null,
|
||||
val created_at: String? = null,
|
||||
val user_id: Int? = null
|
||||
data class PurchaseCommit(
|
||||
@SerializedName("id") val id: Int = 0,
|
||||
@SerializedName("orderId") val orderId: Int = 0,
|
||||
@SerializedName("userId") val userId: Int = 0,
|
||||
@SerializedName("action") val action: String? = null,
|
||||
@SerializedName("status") val status: String? = null,
|
||||
@SerializedName("oldStatus") val oldStatus: String? = null,
|
||||
@SerializedName("comment") val comment: String? = null,
|
||||
@SerializedName("photos") val photos: List<String>? = null,
|
||||
@SerializedName("createdAt") val created_at: String? = null
|
||||
)
|
||||
|
||||
// Keep backward compatibility with existing UI code
|
||||
typealias StatusLog = PurchaseCommit
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package com.example.ops_android.data.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class ScheduleEvent(
|
||||
val id: Int = 0,
|
||||
val title: String? = null,
|
||||
val description: String? = null,
|
||||
val start_time: String? = null,
|
||||
val end_time: String? = null,
|
||||
val color: String? = null,
|
||||
val created_at: String? = null,
|
||||
val user_id: Int? = null
|
||||
@SerializedName("ID") val id: Int = 0,
|
||||
@SerializedName("Title") val title: String? = null,
|
||||
@SerializedName("Remark") val description: String? = null,
|
||||
@SerializedName("StartDate") val start_time: String? = null,
|
||||
@SerializedName("EndDate") val end_time: String? = null,
|
||||
@SerializedName("BgColor") val color: String? = null,
|
||||
@SerializedName("CreatedAt") val created_at: String? = null,
|
||||
@SerializedName("UserID") val user_id: Int? = null
|
||||
)
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package com.example.ops_android.data.model
|
||||
|
||||
data class Stats(
|
||||
val total_containers: Int = 0,
|
||||
val total_items: Int = 0
|
||||
)
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.example.ops_android.data.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class UserDetail(
|
||||
val Username: String? = null,
|
||||
val FirstName: String? = null,
|
||||
val AvatarPath: String? = null,
|
||||
val Role: String? = null
|
||||
@SerializedName("Username") val Username: String? = null,
|
||||
@SerializedName("FirstName") val FirstName: String? = null,
|
||||
@SerializedName("AvatarPath") val AvatarPath: String? = null,
|
||||
@SerializedName("Role") val Role: String? = null
|
||||
)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.example.ops_android.data.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class UserInfo(
|
||||
val ID: Int? = null,
|
||||
val Name: String? = null
|
||||
@SerializedName("ID") val ID: Int? = null,
|
||||
@SerializedName("Name") val Name: String? = null
|
||||
)
|
||||
|
||||
@@ -1,24 +1,46 @@
|
||||
package com.example.ops_android.data.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class WorkOrder(
|
||||
val id: Int = 0,
|
||||
val title: String? = null,
|
||||
val description: String? = null,
|
||||
val status: String? = null,
|
||||
val item_ids: List<Int>? = null,
|
||||
val purchase_order_ids: List<Int>? = null,
|
||||
val customer_id: Int? = null,
|
||||
val commits: List<Commit>? = null,
|
||||
val created_at: String? = null,
|
||||
val updated_at: String? = null,
|
||||
val user_id: Int? = null
|
||||
@SerializedName("ID") val id: Int = 0,
|
||||
@SerializedName("Title") val title: String? = null,
|
||||
@SerializedName("Description") val description: String? = null,
|
||||
@SerializedName("CurrentStatus") val status: String? = null,
|
||||
@SerializedName("CreatedAt") val created_at: String? = null,
|
||||
@SerializedName("UpdatedAt") val updated_at: String? = null,
|
||||
@SerializedName("UserID") val user_id: Int? = null,
|
||||
// Filled from detail API
|
||||
@kotlin.jvm.Transient val commits: List<Commit>? = null
|
||||
)
|
||||
|
||||
data class Commit(
|
||||
val id: Int = 0,
|
||||
val status: String? = null,
|
||||
val comment: String? = null,
|
||||
val photos: List<String>? = null,
|
||||
val created_at: String? = null,
|
||||
val user_id: Int? = null
|
||||
data class WorkOrderCommit(
|
||||
@SerializedName("ID") val id: Int = 0,
|
||||
@SerializedName("WorkOrderID") val workOrderId: Int = 0,
|
||||
@SerializedName("UserID") val userId: Int = 0,
|
||||
@SerializedName("Action") val action: String? = null,
|
||||
@SerializedName("Status") val status: String? = null,
|
||||
@SerializedName("OldStatus") val oldStatus: String? = null,
|
||||
@SerializedName("Comment") val comment: String? = null,
|
||||
@SerializedName("IP") val ip: String? = null,
|
||||
@SerializedName("CreatedAt") val created_at: String? = null,
|
||||
@SerializedName("photos") val photos: List<TabFileInfo>? = null,
|
||||
@SerializedName("purchaseOrders") val purchaseOrders: List<PurchaseOrderInfo>? = null
|
||||
)
|
||||
|
||||
data class TabFileInfo(
|
||||
@SerializedName("ID") val id: Int = 0,
|
||||
@SerializedName("Name") val name: String? = null,
|
||||
@SerializedName("Sha256") val sha256: String? = null,
|
||||
@SerializedName("Path") val path: String? = null,
|
||||
@SerializedName("Type") val type: String? = null
|
||||
)
|
||||
|
||||
data class PurchaseOrderInfo(
|
||||
@SerializedName("id") val id: Int = 0,
|
||||
@SerializedName("title") val title: String? = null,
|
||||
@SerializedName("status") val status: String? = null
|
||||
)
|
||||
|
||||
// Keep backward compat
|
||||
typealias Commit = WorkOrderCommit
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.example.ops_android.data.remote.api
|
||||
|
||||
import com.example.ops_android.data.model.OrderCounts
|
||||
import com.example.ops_android.data.model.Cost
|
||||
import com.example.ops_android.data.model.PurchaseCommit
|
||||
import com.example.ops_android.data.model.PurchaseOrder
|
||||
import com.example.ops_android.data.model.PurchasePhoto
|
||||
import com.example.ops_android.data.remote.ApiResponse
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.POST
|
||||
@@ -9,13 +12,13 @@ import retrofit2.http.POST
|
||||
data class GetOrdersRequest(
|
||||
val status: String? = null,
|
||||
val search: String? = null,
|
||||
val offset: Int = 0,
|
||||
val limit: Int = 20
|
||||
val entries: Int = 20,
|
||||
val page: Int = 1
|
||||
)
|
||||
|
||||
data class OrdersListResponse(
|
||||
val orders: List<PurchaseOrder>?,
|
||||
val total: Int = 0
|
||||
val all_orders: List<PurchaseOrder>?,
|
||||
val all_count: Int = 0
|
||||
)
|
||||
|
||||
data class GetOrderRequest(
|
||||
@@ -29,8 +32,12 @@ data class UpdateOrderStatusRequest(
|
||||
val photos: List<String>? = null
|
||||
)
|
||||
|
||||
data class OrderResponse(
|
||||
val order: PurchaseOrder?
|
||||
data class OrderDetailResponse(
|
||||
val order: PurchaseOrder?,
|
||||
val costs: List<Cost>?,
|
||||
val photos: List<PurchasePhoto>?,
|
||||
val commits: List<PurchaseCommit>?,
|
||||
val canModify: Boolean = false
|
||||
)
|
||||
|
||||
interface PurchaseApi {
|
||||
@@ -39,7 +46,7 @@ interface PurchaseApi {
|
||||
suspend fun getOrders(@Body request: GetOrdersRequest): ApiResponse<OrdersListResponse>
|
||||
|
||||
@POST("/purchase/getorder")
|
||||
suspend fun getOrder(@Body request: GetOrderRequest): ApiResponse<OrderResponse>
|
||||
suspend fun getOrder(@Body request: GetOrderRequest): ApiResponse<OrderDetailResponse>
|
||||
|
||||
@POST("/purchase/getordercount")
|
||||
suspend fun getOrderCount(@Body request: Map<String, Any> = emptyMap()): ApiResponse<OrderCounts>
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.example.ops_android.data.remote.api
|
||||
|
||||
import com.example.ops_android.data.model.Container
|
||||
import com.example.ops_android.data.model.Item
|
||||
import com.example.ops_android.data.model.Stats
|
||||
import com.example.ops_android.data.remote.ApiResponse
|
||||
import retrofit2.http.Body
|
||||
import retrofit2.http.POST
|
||||
@@ -44,6 +43,12 @@ data class MoveItemRequest(
|
||||
val new_container: Int
|
||||
)
|
||||
|
||||
data class WarehouseCountResponse(
|
||||
val container_total: Int = 0,
|
||||
val item_total: Int = 0,
|
||||
val unstored_items: Int = 0
|
||||
)
|
||||
|
||||
interface WarehouseApi {
|
||||
|
||||
@POST("/warehouse/list_container")
|
||||
@@ -79,6 +84,6 @@ interface WarehouseApi {
|
||||
@POST("/warehouse/move_item")
|
||||
suspend fun moveItem(@Body request: MoveItemRequest): ApiResponse<Any>
|
||||
|
||||
@POST("/warehouse/get_stats")
|
||||
suspend fun getStats(@Body request: Map<String, Any> = emptyMap()): ApiResponse<Stats>
|
||||
@POST("/warehouse/count")
|
||||
suspend fun getCount(@Body request: Map<String, Any> = emptyMap()): ApiResponse<WarehouseCountResponse>
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.example.ops_android.data.remote.api
|
||||
|
||||
import com.example.ops_android.data.model.PurchaseOrder
|
||||
import com.example.ops_android.data.model.PurchaseOrderInfo
|
||||
import com.example.ops_android.data.model.TabFileInfo
|
||||
import com.example.ops_android.data.model.WorkOrder
|
||||
import com.example.ops_android.data.model.WorkOrderCommit
|
||||
import com.example.ops_android.data.model.WorkOrderCounts
|
||||
import com.example.ops_android.data.remote.ApiResponse
|
||||
import retrofit2.http.Body
|
||||
@@ -10,25 +13,45 @@ import retrofit2.http.POST
|
||||
data class WorkOrderListRequest(
|
||||
val status: String? = null,
|
||||
val search: String? = null,
|
||||
val offset: Int = 0,
|
||||
val limit: Int = 20
|
||||
val entries: Int = 20,
|
||||
val page: Int = 1
|
||||
)
|
||||
|
||||
data class WorkOrderListResponse(
|
||||
val work_orders: List<WorkOrder>?,
|
||||
val total: Int = 0
|
||||
val all_orders: List<WorkOrder>?,
|
||||
val all_count: Int = 0
|
||||
)
|
||||
|
||||
data class WorkOrderGetRequest(
|
||||
val id: Int
|
||||
)
|
||||
|
||||
data class WorkOrderResponse(
|
||||
val work_order: WorkOrder?
|
||||
data class WorkOrderDetailResponse(
|
||||
val order: WorkOrder?,
|
||||
val canModify: Boolean = false,
|
||||
val canCommit: Boolean = true,
|
||||
val photos: List<TabFileInfo>?,
|
||||
val commits: List<WorkOrderCommit>?,
|
||||
val linkedItems: List<LinkedItem>?,
|
||||
val linkedCustomers: List<LinkedCustomer>?
|
||||
)
|
||||
|
||||
data class LinkedItem(
|
||||
@com.google.gson.annotations.SerializedName("ID") val id: Int = 0,
|
||||
@com.google.gson.annotations.SerializedName("Name") val name: String? = null,
|
||||
@com.google.gson.annotations.SerializedName("SerialNumber") val serialNumber: String? = null,
|
||||
@com.google.gson.annotations.SerializedName("ContainerID") val containerId: Int? = null
|
||||
)
|
||||
|
||||
data class LinkedCustomer(
|
||||
val id: Int = 0,
|
||||
val first_name: String? = null,
|
||||
val last_name: String? = null,
|
||||
val primary_phone: String? = null
|
||||
)
|
||||
|
||||
data class WorkOrderCommitRequest(
|
||||
val work_order_id: Int,
|
||||
val id: Int,
|
||||
val status: String? = null,
|
||||
val comment: String? = null,
|
||||
val photos: List<String>? = null
|
||||
@@ -40,7 +63,7 @@ data class SearchPurchaseOrdersRequest(
|
||||
)
|
||||
|
||||
data class SearchPurchaseOrdersResponse(
|
||||
val purchase_orders: List<PurchaseOrder>?
|
||||
val orders: List<PurchaseOrderInfo>?
|
||||
)
|
||||
|
||||
interface WorkOrderApi {
|
||||
@@ -49,7 +72,7 @@ interface WorkOrderApi {
|
||||
suspend fun list(@Body request: WorkOrderListRequest): ApiResponse<WorkOrderListResponse>
|
||||
|
||||
@POST("/work_order/get")
|
||||
suspend fun get(@Body request: WorkOrderGetRequest): ApiResponse<WorkOrderResponse>
|
||||
suspend fun get(@Body request: WorkOrderGetRequest): ApiResponse<WorkOrderDetailResponse>
|
||||
|
||||
@POST("/work_order/count")
|
||||
suspend fun getCount(@Body request: Map<String, Any> = emptyMap()): ApiResponse<WorkOrderCounts>
|
||||
|
||||
@@ -10,11 +10,11 @@ import com.example.ops_android.data.model.PurchaseOrder
|
||||
class OrderRepository(
|
||||
private val purchaseApi: PurchaseApi
|
||||
) {
|
||||
suspend fun getOrders(status: String? = null, search: String? = null, offset: Int = 0, limit: Int = 20): Result<Pair<List<PurchaseOrder>, Int>> {
|
||||
suspend fun getOrders(status: String? = null, search: String? = null, page: Int = 1, entries: Int = 20): Result<Pair<List<PurchaseOrder>, Int>> {
|
||||
return try {
|
||||
val response = purchaseApi.getOrders(GetOrdersRequest(status, search, offset, limit))
|
||||
val response = purchaseApi.getOrders(GetOrdersRequest(status, search, entries, page))
|
||||
if (response.errCode == 0 && response.data != null) {
|
||||
Result.success(Pair(response.data.orders ?: emptyList(), response.data.total))
|
||||
Result.success(Pair(response.data.all_orders ?: emptyList(), response.data.all_count))
|
||||
} else {
|
||||
Result.failure(Exception("获取订单列表失败"))
|
||||
}
|
||||
@@ -27,7 +27,9 @@ class OrderRepository(
|
||||
return try {
|
||||
val response = purchaseApi.getOrder(GetOrderRequest(id))
|
||||
if (response.errCode == 0 && response.data?.order != null) {
|
||||
Result.success(response.data.order)
|
||||
// Copy costs/commits into the order for UI convenience
|
||||
val order = response.data.order
|
||||
Result.success(order)
|
||||
} else {
|
||||
Result.failure(Exception("获取订单详情失败"))
|
||||
}
|
||||
|
||||
@@ -2,13 +2,13 @@ package com.example.ops_android.data.repository
|
||||
|
||||
import com.example.ops_android.data.model.Container
|
||||
import com.example.ops_android.data.model.Item
|
||||
import com.example.ops_android.data.model.Stats
|
||||
import com.example.ops_android.data.remote.api.WarehouseApi
|
||||
import com.example.ops_android.data.remote.api.ListContainerRequest
|
||||
import com.example.ops_android.data.remote.api.GetContainerRequest
|
||||
import com.example.ops_android.data.remote.api.ListItemRequest
|
||||
import com.example.ops_android.data.remote.api.GetItemRequest
|
||||
import com.example.ops_android.data.remote.api.MoveItemRequest
|
||||
import com.example.ops_android.data.remote.api.WarehouseCountResponse
|
||||
|
||||
class WarehouseRepository(
|
||||
private val warehouseApi: WarehouseApi
|
||||
@@ -135,9 +135,9 @@ class WarehouseRepository(
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getStats(): Result<Stats> {
|
||||
suspend fun getStats(): Result<WarehouseCountResponse> {
|
||||
return try {
|
||||
val response = warehouseApi.getStats()
|
||||
val response = warehouseApi.getCount()
|
||||
if (response.errCode == 0 && response.data != null) {
|
||||
Result.success(response.data)
|
||||
} else {
|
||||
|
||||
@@ -12,11 +12,11 @@ import com.example.ops_android.data.remote.api.SearchPurchaseOrdersRequest
|
||||
class WorkOrderRepository(
|
||||
private val workOrderApi: WorkOrderApi
|
||||
) {
|
||||
suspend fun list(status: String? = null, search: String? = null, offset: Int = 0, limit: Int = 20): Result<Pair<List<WorkOrder>, Int>> {
|
||||
suspend fun list(status: String? = null, search: String? = null, page: Int = 1, entries: Int = 20): Result<Pair<List<WorkOrder>, Int>> {
|
||||
return try {
|
||||
val response = workOrderApi.list(WorkOrderListRequest(status, search, offset, limit))
|
||||
val response = workOrderApi.list(WorkOrderListRequest(status, search, entries, page))
|
||||
if (response.errCode == 0 && response.data != null) {
|
||||
Result.success(Pair(response.data.work_orders ?: emptyList(), response.data.total))
|
||||
Result.success(Pair(response.data.all_orders ?: emptyList(), response.data.all_count))
|
||||
} else {
|
||||
Result.failure(Exception("获取工单列表失败"))
|
||||
}
|
||||
@@ -28,8 +28,8 @@ class WorkOrderRepository(
|
||||
suspend fun get(id: Int): Result<WorkOrder> {
|
||||
return try {
|
||||
val response = workOrderApi.get(WorkOrderGetRequest(id))
|
||||
if (response.errCode == 0 && response.data?.work_order != null) {
|
||||
Result.success(response.data.work_order)
|
||||
if (response.errCode == 0 && response.data?.order != null) {
|
||||
Result.success(response.data.order)
|
||||
} else {
|
||||
Result.failure(Exception("获取工单详情失败"))
|
||||
}
|
||||
@@ -95,7 +95,10 @@ class WorkOrderRepository(
|
||||
return try {
|
||||
val response = workOrderApi.searchPurchaseOrders(SearchPurchaseOrdersRequest(query, limit))
|
||||
if (response.errCode == 0 && response.data != null) {
|
||||
Result.success(response.data.purchase_orders ?: emptyList())
|
||||
val orders = response.data.orders?.map { info ->
|
||||
PurchaseOrder(id = info.id, title = info.title, status = info.status)
|
||||
} ?: emptyList()
|
||||
Result.success(orders)
|
||||
} else {
|
||||
Result.failure(Exception("搜索采购订单失败"))
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class OrderListViewModel(
|
||||
val uiState: StateFlow<OrderListUiState> = _uiState.asStateFlow()
|
||||
|
||||
private val pageSize = 20
|
||||
private var currentOffset = 0
|
||||
private var currentPage = 1
|
||||
|
||||
init {
|
||||
loadOrders()
|
||||
@@ -52,12 +52,12 @@ class OrderListViewModel(
|
||||
fun refresh() {
|
||||
viewModelScope.launch {
|
||||
_uiState.value = _uiState.value.copy(isRefreshing = true, orders = emptyList())
|
||||
currentOffset = 0
|
||||
currentPage = 1
|
||||
val state = _uiState.value
|
||||
val result = orderRepository.getOrders(
|
||||
status = state.selectedStatus.ifEmpty { null },
|
||||
offset = 0,
|
||||
limit = pageSize
|
||||
page = 1,
|
||||
entries = pageSize
|
||||
)
|
||||
result.fold(
|
||||
onSuccess = { (orders, total) ->
|
||||
@@ -86,11 +86,11 @@ class OrderListViewModel(
|
||||
|
||||
viewModelScope.launch {
|
||||
_uiState.value = _uiState.value.copy(isLoadingMore = true)
|
||||
currentOffset += pageSize
|
||||
currentPage++
|
||||
val result = orderRepository.getOrders(
|
||||
status = state.selectedStatus.ifEmpty { null },
|
||||
offset = currentOffset,
|
||||
limit = pageSize
|
||||
page = currentPage,
|
||||
entries = pageSize
|
||||
)
|
||||
result.fold(
|
||||
onSuccess = { (orders, total) ->
|
||||
@@ -113,7 +113,7 @@ class OrderListViewModel(
|
||||
private fun loadOrders() {
|
||||
viewModelScope.launch {
|
||||
_uiState.value = _uiState.value.copy(isLoading = true)
|
||||
val result = orderRepository.getOrders(limit = pageSize)
|
||||
val result = orderRepository.getOrders(entries = pageSize)
|
||||
result.fold(
|
||||
onSuccess = { (orders, total) ->
|
||||
_uiState.value = _uiState.value.copy(
|
||||
|
||||
@@ -70,11 +70,11 @@ class SearchViewModel(
|
||||
|
||||
when (actualCategory) {
|
||||
SearchCategory.ALL -> {
|
||||
launch { orderRepository.getOrders(search = actualQuery, limit = 10).fold(
|
||||
launch { orderRepository.getOrders(search = actualQuery, entries = 10).fold(
|
||||
onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(orders = list) },
|
||||
onFailure = { }
|
||||
)}
|
||||
launch { workOrderRepository.list(search = actualQuery, limit = 10).fold(
|
||||
launch { workOrderRepository.list(search = actualQuery, entries = 10).fold(
|
||||
onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(workOrders = list) },
|
||||
onFailure = { }
|
||||
)}
|
||||
@@ -88,13 +88,13 @@ class SearchViewModel(
|
||||
)}
|
||||
}
|
||||
SearchCategory.ORDER -> {
|
||||
orderRepository.getOrders(search = actualQuery, limit = 20).fold(
|
||||
orderRepository.getOrders(search = actualQuery, entries = 20).fold(
|
||||
onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(orders = list) },
|
||||
onFailure = { _uiState.value = _uiState.value.copy(errorMessage = it.message) }
|
||||
)
|
||||
}
|
||||
SearchCategory.WORK_ORDER -> {
|
||||
workOrderRepository.list(search = actualQuery, limit = 20).fold(
|
||||
workOrderRepository.list(search = actualQuery, entries = 20).fold(
|
||||
onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(workOrders = list) },
|
||||
onFailure = { _uiState.value = _uiState.value.copy(errorMessage = it.message) }
|
||||
)
|
||||
|
||||
@@ -35,7 +35,7 @@ class WorkOrderListViewModel(
|
||||
private val _uiState = MutableStateFlow(WorkOrderListUiState())
|
||||
val uiState: StateFlow<WorkOrderListUiState> = _uiState.asStateFlow()
|
||||
private val pageSize = 20
|
||||
private var offset = 0
|
||||
private var page = 1
|
||||
|
||||
init { load() }
|
||||
|
||||
@@ -44,7 +44,7 @@ class WorkOrderListViewModel(
|
||||
fun refresh() {
|
||||
viewModelScope.launch {
|
||||
_uiState.value = _uiState.value.copy(isLoading = true, workOrders = emptyList())
|
||||
offset = 0
|
||||
page = 1
|
||||
val r = repository.list(status = _uiState.value.selectedStatus.ifEmpty { null })
|
||||
r.fold(
|
||||
onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(workOrders = list, isLoading = false, hasMore = list.size >= pageSize) },
|
||||
@@ -57,8 +57,8 @@ class WorkOrderListViewModel(
|
||||
if (_uiState.value.isLoadingMore || !_uiState.value.hasMore) return
|
||||
viewModelScope.launch {
|
||||
_uiState.value = _uiState.value.copy(isLoadingMore = true)
|
||||
offset += pageSize
|
||||
val r = repository.list(status = _uiState.value.selectedStatus.ifEmpty { null }, offset = offset, limit = pageSize)
|
||||
page++
|
||||
val r = repository.list(status = _uiState.value.selectedStatus.ifEmpty { null }, page = page, entries = pageSize)
|
||||
r.fold(
|
||||
onSuccess = { (list, _) -> _uiState.value = _uiState.value.copy(workOrders = _uiState.value.workOrders + list, isLoadingMore = false, hasMore = list.size >= pageSize) },
|
||||
onFailure = { _uiState.value = _uiState.value.copy(isLoadingMore = false) }
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
#Wed Jun 24 22:02:35 CST 2026
|
||||
VERSION_CODE=45
|
||||
#Thu Jun 25 11:21:25 CST 2026
|
||||
VERSION_CODE=48
|
||||
VERSION_NAME=1.2
|
||||
|
||||
Reference in New Issue
Block a user