61 lines
1.5 KiB
Go
61 lines
1.5 KiB
Go
// 批次库存服务(逻辑库存)
|
||
// 职责:批次CRUD、列表查询
|
||
// 紧密耦合:dao.StockBatch
|
||
// 注意:区别于PrivateStock的实物库存,批次库存是逻辑概念,不记录物理位置
|
||
package service
|
||
|
||
import (
|
||
dao "assets/dao/stock"
|
||
dto "assets/model/dto/stock"
|
||
"context"
|
||
|
||
"gitea.com/red-future/common/utils"
|
||
"go.mongodb.org/mongo-driver/v2/bson"
|
||
)
|
||
|
||
type stockBatch struct{}
|
||
|
||
// StockBatch 批次服务
|
||
var StockBatch = new(stockBatch)
|
||
|
||
func (s *stockBatch) Create(ctx context.Context, req *dto.CreateBatchReq) (res *dto.CreateBatchRes, err error) {
|
||
ids, err := dao.StockBatch.Insert(ctx, req)
|
||
if err != nil {
|
||
return
|
||
}
|
||
id := ids[0].(bson.ObjectID)
|
||
res = &dto.CreateBatchRes{
|
||
Id: &id,
|
||
}
|
||
return
|
||
}
|
||
|
||
func (s *stockBatch) Update(ctx context.Context, req *dto.UpdateBatchReq) error {
|
||
return dao.StockBatch.Update(ctx, req)
|
||
}
|
||
|
||
func (s *stockBatch) Delete(ctx context.Context, req *dto.DeleteBatchReq) error {
|
||
return dao.StockBatch.DeleteFake(ctx, req)
|
||
}
|
||
|
||
func (s *stockBatch) GetOne(ctx context.Context, req *dto.GetBatchReq) (res *dto.GetBatchRes, err error) {
|
||
one, err := dao.StockBatch.GetOneById(ctx, req)
|
||
if err != nil {
|
||
return
|
||
}
|
||
err = utils.Struct(one, &res)
|
||
return
|
||
}
|
||
|
||
func (s *stockBatch) List(ctx context.Context, req *dto.ListBatchReq) (res *dto.ListBatchRes, err error) {
|
||
list, total, err := dao.StockBatch.List(ctx, req)
|
||
if err != nil {
|
||
return
|
||
}
|
||
res = &dto.ListBatchRes{
|
||
Total: total,
|
||
}
|
||
err = utils.Struct(list, &res.List)
|
||
return
|
||
}
|