348 lines
14 KiB
Go
348 lines
14 KiB
Go
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"` //商品ID
|
||
ProductName string `json:"product_name"` //商品名称
|
||
Appearance int64 `json:"appearance"` //封面
|
||
Barcode string `json:"barcode"` //条码
|
||
Price int64 `json:"price"` // 价格
|
||
WarehouseID int64 `json:"warehouse_id"` //仓库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"` //仓库ID
|
||
WarehouseName string `json:"warehouse_name"` //仓库名称
|
||
WarehouseCode string `json:"warehouse_code"` //仓库编码
|
||
LocationID int64 `json:"location_id"` //库位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"` //商品ID
|
||
ProductName string `json:"product_name"` //商品名称
|
||
List []InventoryDetailItem `json:"list"` //库明细项
|
||
Total int64 `json:"total"` //总数量
|
||
}
|
||
|
||
// InventoryDetailItem 库存明细项
|
||
type InventoryDetailItem struct {
|
||
ID int64 `json:"id"` //库明细项ID
|
||
WarehouseID int64 `json:"warehouse_id"` //仓库ID
|
||
WarehouseName string `json:"warehouse_name"` //仓库名称
|
||
LocationID int64 `json:"location_id"` //库位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"` //商品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"` //库流水项ID
|
||
WarehouseID int64 `json:"warehouse_id"` //仓库ID
|
||
WarehouseName string `json:"warehouse_name"` //仓库名称
|
||
LocationID int64 `json:"location_id"` //库位ID
|
||
LocationCode string `json:"location_code"` //库位编码
|
||
ProductID int64 `json:"product_id"` //商品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"` //操作人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"` //盘库项ID
|
||
CheckNo string `json:"check_no"` //盘库编号
|
||
WarehouseID int64 `json:"warehouse_id"` //仓库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"` //操作人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"` //库明细项ID
|
||
ProductID int64 `json:"product_id"` //商品ID
|
||
ProductName string `json:"product_name"` //商品名称
|
||
Barcode string `json:"barcode"` //条码
|
||
LocationID int64 `json:"location_id"` //库位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"` //盘库人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 "未知"
|
||
}
|