refactor: 重构资产实体和DTO结构类型
将gjson.Json类型替换为具体的结构体和map类型,修正DAO层链式调用,启用SKU元数据校验逻辑
This commit is contained in:
@@ -4,57 +4,48 @@
|
||||
// 注意:区别于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
|
||||
}
|
||||
//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.Delete(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
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user