daShangDao_psiServer/models/response/inventory.go
2026-06-15 13:47:39 +08:00

348 lines
12 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package response
import (
"psi/models"
)
// InventoryListResponse 库存汇总列表响应
type InventoryListResponse struct {
List []InventoryItem `json:"list"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}
// InventoryItem 库存汇总项
type InventoryItem struct {
ProductID int64 `json:"product_id"`
ProductName string `json:"product_name"`
Appearance int64 `json:"appearance"`
Barcode string `json:"barcode"`
Price int64 `json:"price"`
WarehouseID int64 `json:"warehouse_id"`
WarehouseName string `json:"warehouse_name"`
WarehouseCode string `json:"warehouse_code"`
LocationCode string `json:"location_code"`
TotalQuantity int64 `json:"total_quantity"`
LockedQuantity int64 `json:"locked_quantity"`
}
// InventoryGroupedListResponse 按仓库库位分组的库存列表响应
type InventoryGroupedListResponse struct {
List []InventoryGroupItem `json:"list"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}
// InventoryGroupItem 仓库库位分组项(父级)
type InventoryGroupItem struct {
WarehouseID int64 `json:"warehouse_id"`
WarehouseName string `json:"warehouse_name"`
WarehouseCode string `json:"warehouse_code"`
LocationID int64 `json:"location_id"`
LocationCode string `json:"location_code"`
TotalQuantity int64 `json:"total_quantity"`
LockedQuantity int64 `json:"locked_quantity"`
ItemCount int `json:"item_count"`
Details []InventoryDetailItem `json:"details"`
}
// InventoryDetailResponse 库存明细响应
type InventoryDetailResponse struct {
ProductID int64 `json:"product_id"`
ProductName string `json:"product_name"`
List []InventoryDetailItem `json:"list"`
Total int64 `json:"total"`
}
// InventoryDetailItem 库存明细项
type InventoryDetailItem struct {
ID int64 `json:"id"`
WarehouseID int64 `json:"warehouse_id"`
WarehouseName string `json:"warehouse_name"`
LocationID int64 `json:"location_id"`
LocationCode string `json:"location_code"`
BatchNo string `json:"batch_no"`
ProductionDate int64 `json:"production_date"`
ExpiryDate int64 `json:"expiry_date"`
Quantity int64 `json:"quantity"`
LockedQuantity int64 `json:"locked_quantity"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
ProductID int64 `json:"product_id"`
ProductName string `json:"product_name"`
Barcode string `json:"barcode"`
Appearance int64 `json:"appearance"`
SalePrice int64 `json:"sale_price"`
WaveNo string `json:"wave_no"` // 波次编号
WaveTaskNo string `json:"wave_task_no"` // 波次任务编号
OutTaskNo int64 `json:"out_task_no"` // 出库任务编号
SalesOrderNo string `json:"sales_order_no"` // 销售单编号
ShippingNo string `json:"shipping_no"` // 发货单编号
}
// InventoryLogListResponse 库存流水列表响应
type InventoryLogListResponse struct {
List []InventoryLogItem `json:"list"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}
// InventoryLogItem 库存流水项
type InventoryLogItem struct {
ID int64 `json:"id"`
WarehouseID int64 `json:"warehouse_id"`
WarehouseName string `json:"warehouse_name"`
LocationID int64 `json:"location_id"`
LocationCode string `json:"location_code"`
ProductID int64 `json:"product_id"`
ProductName string `json:"product_name"`
Barcode string `json:"barcode"`
BatchNo string `json:"batch_no"`
ChangeType int8 `json:"change_type"`
ChangeTypeText string `json:"change_type_text"`
ChangeQuantity int64 `json:"change_quantity"`
BeforeQuantity int64 `json:"before_quantity"`
AfterQuantity int64 `json:"after_quantity"`
RelatedOrderType string `json:"related_order_type"`
RelatedOrderNo string `json:"related_order_no"`
Operator string `json:"operator"`
OperatorID int64 `json:"operator_id"`
Remark string `json:"remark"`
CreatedAt int64 `json:"created_at"`
}
// InventoryStatistResponse ISBN/书名库存总数响应
type InventoryStatistResponse struct {
Barcode string `json:"barcode"`
Appearance int64 `json:"appearance"`
TotalQuantity int64 `json:"total_quantity"`
ProductCount int `json:"product_count"`
}
// StockCheckListResponse 盘库列表响应
type StockCheckListResponse struct {
List []StockCheckItem `json:"list"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}
// StockCheckItem 盘库项
type StockCheckItem struct {
ID int64 `json:"id"`
CheckNo string `json:"check_no"`
WarehouseID int64 `json:"warehouse_id"`
WarehouseName string `json:"warehouse_name"`
CheckType int8 `json:"check_type"`
CheckTypeText string `json:"check_type_text"`
Status int8 `json:"status"`
StatusText string `json:"status_text"`
TotalItems int `json:"total_items"`
CheckedItems int `json:"checked_items"`
TotalQuantity int64 `json:"total_quantity"`
ActualQuantity int64 `json:"actual_quantity"`
Operator string `json:"operator"`
OperatorID int64 `json:"operator_id"`
Remark string `json:"remark"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
// StockCheckDetailResponse 盘库明细列表响应
type StockCheckDetailResponse struct {
List []StockCheckDetailItem `json:"list"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}
// StockCheckDetailItem 盘库明细项
type StockCheckDetailItem struct {
ID int64 `json:"id"`
ProductID int64 `json:"product_id"`
ProductName string `json:"product_name"`
Barcode string `json:"barcode"`
LocationID int64 `json:"location_id"`
LocationCode string `json:"location_code"`
BatchNo string `json:"batch_no"`
ProductionDate int64 `json:"production_date"`
ExpiryDate int64 `json:"expiry_date"`
SystemQuantity int64 `json:"system_quantity"`
ActualQuantity int64 `json:"actual_quantity"`
DifferenceQuantity int64 `json:"difference_quantity"`
Status int8 `json:"status"`
StatusText string `json:"status_text"`
CheckOperator string `json:"check_operator"`
CheckOperatorID int64 `json:"check_operator_id"`
CheckTime int64 `json:"check_time"`
Remark string `json:"remark"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
// InventorySummaryResponse 库存统计响应
type InventorySummaryResponse struct {
ProductTypeCount int64 `json:"product_type_count"` // 商品总种类数同一个barcode算一个
ProductCount int64 `json:"product_count"` // 商品总数(不去重,按库存明细记录数)
TotalQuantity int64 `json:"total_quantity"` // 库存总量
AvailableProductCount int64 `json:"available_product_count"` // 有货商品数量库存大于0的
LocationCount int64 `json:"location_count"` // 库位数
}
// ConvertInventoryToItem 将库存汇总转换为响应项
func ConvertInventoryToItem(
productID int64, productName string, appearance int64, barcode string, price int64,
warehouseID int64, warehouseName, warehouseCode, locationCode string,
totalQty, lockedQty int64,
) InventoryItem {
return InventoryItem{
ProductID: productID,
ProductName: productName,
Appearance: appearance,
Barcode: barcode,
Price: price,
WarehouseID: warehouseID,
WarehouseName: warehouseName,
WarehouseCode: warehouseCode,
LocationCode: locationCode,
TotalQuantity: totalQty,
LockedQuantity: lockedQty,
}
}
// ConvertInventoryDetailToItem 将库存明细转换为响应项
func ConvertInventoryDetailToItem(
detail models.InventoryDetail, warehouseName, locationCode string,
waveNo, waveTaskNo string, outTaskNo int64, salesOrderNo, shippingNo string,
) InventoryDetailItem {
return InventoryDetailItem{
ID: detail.ID,
WarehouseID: detail.WarehouseID,
WarehouseName: warehouseName,
LocationID: detail.LocationID,
LocationCode: locationCode,
BatchNo: detail.BatchNo,
ProductionDate: detail.ProductionDate,
ExpiryDate: detail.ExpiryDate,
Quantity: detail.Quantity,
LockedQuantity: detail.LockedQuantity,
CreatedAt: detail.CreatedAt,
UpdatedAt: detail.UpdatedAt,
WaveNo: waveNo,
WaveTaskNo: waveTaskNo,
OutTaskNo: outTaskNo,
SalesOrderNo: salesOrderNo,
ShippingNo: shippingNo,
}
}
// ConvertInventoryLogToItem 将库存流水转换为响应项
func ConvertInventoryLogToItem(
log models.InventoryLog, warehouseName, locationCode, productName, barcode string,
) InventoryLogItem {
return InventoryLogItem{
ID: log.ID,
WarehouseID: log.WarehouseID,
WarehouseName: warehouseName,
LocationID: log.LocationID,
LocationCode: locationCode,
ProductID: log.ProductID,
ProductName: productName,
Barcode: barcode,
BatchNo: log.BatchNo,
ChangeType: log.ChangeType,
ChangeTypeText: GetInventoryChangeTypeText(log.ChangeType),
ChangeQuantity: log.ChangeQuantity,
BeforeQuantity: log.BeforeQuantity,
AfterQuantity: log.AfterQuantity,
RelatedOrderType: log.RelatedOrderType,
RelatedOrderNo: log.RelatedOrderNo,
Operator: log.Operator,
OperatorID: log.OperatorID,
Remark: log.Remark,
CreatedAt: log.CreatedAt,
}
}
// ConvertStockCheckToItem 将盘库单转换为响应项
func ConvertStockCheckToItem(
check models.StockCheck, warehouseName string,
) StockCheckItem {
return StockCheckItem{
ID: check.ID,
CheckNo: check.CheckNo,
WarehouseID: check.WarehouseID,
WarehouseName: warehouseName,
CheckType: check.CheckType,
CheckTypeText: GetStockCheckTypeText(check.CheckType),
Status: check.Status,
StatusText: GetStockCheckStatusText(check.Status),
TotalItems: check.TotalItems,
CheckedItems: check.CheckedItems,
TotalQuantity: check.TotalQuantity,
ActualQuantity: check.ActualQuantity,
Operator: check.Operator,
OperatorID: check.OperatorID,
Remark: check.Remark,
CreatedAt: check.CreatedAt,
UpdatedAt: check.UpdatedAt,
}
}
// GetInventoryChangeTypeText 获取库存变动类型文本
func GetInventoryChangeTypeText(changeType int8) string {
typeMap := map[int8]string{
1: "入库",
2: "出库",
3: "移库",
4: "盘点调整",
5: "锁定库存",
6: "解锁库存",
}
if text, ok := typeMap[changeType]; ok {
return text
}
return "未知"
}
// GetStockCheckTypeText 获取盘点类型文本
func GetStockCheckTypeText(checkType int8) string {
typeMap := map[int8]string{
1: "全盘",
2: "抽盘",
}
if text, ok := typeMap[checkType]; ok {
return text
}
return "未知"
}
// GetStockCheckStatusText 获取盘点状态文本
func GetStockCheckStatusText(status int8) string {
statusMap := map[int8]string{
1: "待盘点",
2: "盘点中",
3: "已完成",
4: "已取消",
}
if text, ok := statusMap[status]; ok {
return text
}
return "未知"
}
// GetStockCheckItemStatusText 获取盘点明细状态文本
func GetStockCheckItemStatusText(status int8) string {
statusMap := map[int8]string{
1: "待盘点",
2: "已盘点",
}
if text, ok := statusMap[status]; ok {
return text
}
return "未知"
}