Files
assets/controller/stock/inventory_count_controller.go

77 lines
2.8 KiB
Go
Raw Normal View History

2026-03-18 10:18:03 +08:00
// 盘点任务控制器
// 职责盘点任务CRUD、完成/取消、导出模板、导入Excel
// 调用服务service.InventoryCount
// 注意ImportInventoryCount从multipart form读取文件Update/Delete返回*beans.ResponseEmpty
package controller
import (
dto "assets/model/dto/stock"
service "assets/service/stock"
"context"
"fmt"
"io"
2026-06-10 15:40:17 +08:00
"gitea.redpowerfuture.com/red-future/common/beans"
2026-03-18 10:18:03 +08:00
"github.com/gogf/gf/v2/frame/g"
)
type inventoryCount struct{}
var InventoryCount = new(inventoryCount)
func init() {
}
func (c *inventoryCount) CreateInventoryCount(ctx context.Context, req *dto.CreateInventoryCountReq) (res *dto.CreateInventoryCountRes, err error) {
g.Log().Debugf(ctx, "[CreateInventoryCount] req: %+v", req)
return service.InventoryCount.Create(ctx, req)
}
func (c *inventoryCount) UpdateInventoryCount(ctx context.Context, req *dto.UpdateInventoryCountReq) (res *beans.ResponseEmpty, err error) {
err = service.InventoryCount.Update(ctx, req)
return
}
func (c *inventoryCount) DeleteInventoryCount(ctx context.Context, req *dto.DeleteInventoryCountReq) (res *beans.ResponseEmpty, err error) {
err = service.InventoryCount.Delete(ctx, req)
return
}
func (c *inventoryCount) GetInventoryCount(ctx context.Context, req *dto.GetInventoryCountReq) (res *dto.GetInventoryCountRes, err error) {
return service.InventoryCount.GetOne(ctx, req)
}
func (c *inventoryCount) ListInventoryCounts(ctx context.Context, req *dto.ListInventoryCountReq) (res *dto.ListInventoryCountRes, err error) {
return service.InventoryCount.List(ctx, req)
}
func (c *inventoryCount) CompleteInventoryCount(ctx context.Context, req *dto.CompleteInventoryCountReq) (res *dto.CompleteInventoryCountRes, err error) {
return service.InventoryCount.Complete(ctx, req)
}
func (c *inventoryCount) CancelInventoryCount(ctx context.Context, req *dto.CancelInventoryCountReq) (res *dto.CancelInventoryCountRes, err error) {
return service.InventoryCount.Cancel(ctx, req)
}
func (c *inventoryCount) ExportInventoryCountTemplate(ctx context.Context, req *dto.ExportInventoryCountTemplateReq) (res *dto.ExportInventoryCountTemplateRes, err error) {
return service.InventoryCount.ExportTemplate(ctx, req)
}
// ImportInventoryCount 上传盘点Excel
// 从multipart form读取文件数据并调用Service层解析导入
func (c *inventoryCount) ImportInventoryCount(ctx context.Context, req *dto.ImportInventoryCountReq) (res *dto.ImportInventoryCountRes, err error) {
r := g.RequestFromCtx(ctx)
file, _, err := r.Request.FormFile("file")
if err != nil {
return nil, fmt.Errorf("读取上传文件失败: %v", err)
}
defer file.Close()
fileData, err := io.ReadAll(file)
if err != nil {
return nil, fmt.Errorf("读取文件内容失败: %v", err)
}
return service.InventoryCount.ImportInventoryCount(ctx, req, fileData)
}