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

169 lines
4.7 KiB
Go

package controllers
import (
"github.com/gin-gonic/gin"
"net/http"
"psi/constant"
"psi/database"
systemReq "psi/models/request"
systemRes "psi/models/response"
"psi/service"
"psi/utils"
)
type InventoryApi struct{}
var inventoryService = service.InventoryService{}
// GetInventoryList 获取库存汇总列表
func (r *InventoryApi) GetInventoryList(c *gin.Context) {
var req systemReq.GetInventoryListRequest
if err := c.ShouldBindQuery(&req); err != nil {
ValidAndFail(constant.LoggerChannelRequest, "库存汇总列表请求异常", "参数错误: "+err.Error(), c, err)
return
}
result, err := inventoryService.GetInventoryList(req, database.GetDB(c))
if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "库存汇总列表异常", err, c, req)
return
}
c.JSON(http.StatusOK, gin.H{
"code": 200,
"data": result,
})
}
// GetInventoryGroupedList 获取按仓库库位分组的库存列表
func (i *InventoryApi) GetInventoryGroupedList(c *gin.Context) {
var req systemReq.GetInventoryGroupedListRequest
if err := c.ShouldBindQuery(&req); err != nil {
ValidAndFail(constant.LoggerChannelRequest, "库存分组列表请求参数异常", "参数错误: "+err.Error(), c, err)
return
}
result, err := inventoryService.GetInventoryGroupedList(req, database.GetDB(c))
if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "库存分组列表异常", err, c, req)
return
}
c.JSON(http.StatusOK, gin.H{
"code": 200,
"data": result,
})
}
// GetInventorySummary 获取库存统计信息
func (r *InventoryApi) GetInventorySummary(c *gin.Context) {
result, err := inventoryService.GetInventorySummary(database.GetDB(c))
if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "库存统计信息异常", err, c, nil)
return
}
systemRes.OkWithDetailed(result, "查询成功", c)
}
// GetInventoryDetail 获取库存明细
func (r *InventoryApi) GetInventoryDetail(c *gin.Context) {
var req systemReq.GetInventoryDetailRequest
if err := c.ShouldBindQuery(&req); err != nil {
ValidAndFail(constant.LoggerChannelRequest, "库存明细请求异常", "参数错误: "+err.Error(), c, err)
return
}
result, err := inventoryService.GetInventoryDetail(req.ProductID, database.GetDB(c))
if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "库存明细异常", err, c, req)
return
}
systemRes.OkWithDetailed(result, "查询成功", c)
}
// GetInventoryLogList 获取库存流水列表
func (r *InventoryApi) GetInventoryLogList(c *gin.Context) {
var req systemReq.GetInventoryLogListRequest
if err := c.ShouldBindQuery(&req); err != nil {
ValidAndFail(constant.LoggerChannelRequest, "库存流水列表请求异常", "参数错误: "+err.Error(), c, err)
return
}
result, err := inventoryService.GetInventoryLogList(req, database.GetDB(c))
if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "库存流水列表异常", err, c, req)
return
}
c.JSON(http.StatusOK, gin.H{
"code": 200,
"data": result,
})
}
// InventoryStatist 获取ISBN/品相的库存总数
func (r *InventoryApi) InventoryStatist(c *gin.Context) {
var req systemReq.InventoryStatistRequest
if err := c.ShouldBindQuery(&req); err != nil {
ValidAndFail(constant.LoggerChannelRequest, "库存统计请求异常", "参数错误: "+err.Error(), c, err)
return
}
result, err := inventoryService.InventoryStatist(req, database.GetDB(c))
if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "库存统计异常", err, c, req)
return
}
systemRes.OkWithDetailed(result, "查询成功", c)
}
// GetStockCheckList 获取盘库列表
func (r *InventoryApi) GetStockCheckList(c *gin.Context) {
var req systemReq.GetStockCheckListRequest
if err := c.ShouldBindQuery(&req); err != nil {
ValidAndFail(constant.LoggerChannelRequest, "盘库列表请求异常", "参数错误: "+err.Error(), c, err)
return
}
result, err := inventoryService.GetStockCheckList(req, database.GetDB(c))
if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "盘库列表异常", err, c, req)
return
}
c.JSON(http.StatusOK, gin.H{
"code": 200,
"data": result,
})
}
// GetStockCheckDetail 获取盘库明细列表
func (r *InventoryApi) GetStockCheckDetail(c *gin.Context) {
var req systemReq.GetStockCheckDetailRequest
if err := c.ShouldBindQuery(&req); err != nil {
ValidAndFail(constant.LoggerChannelRequest, "盘库明细列表请求异常", "参数错误: "+err.Error(), c, err)
return
}
result, err := inventoryService.GetStockCheckDetail(req, database.GetDB(c))
if err != nil {
utils.FailWithRequestLog(constant.LoggerChannelWork, "盘库明细列表异常", err, c, req)
return
}
c.JSON(http.StatusOK, gin.H{
"code": 200,
"data": result,
})
}