|
|
@@ -1,27 +1,30 @@
|
|
|
-package handler
|
|
|
+package base
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+
|
|
|
"dashoo.cn/common_definition/comm_def"
|
|
|
- "dashoo.cn/micro/app/model"
|
|
|
- "dashoo.cn/micro/app/service"
|
|
|
"dashoo.cn/opms_libary/myerrors"
|
|
|
"github.com/gogf/gf/errors/gerror"
|
|
|
"github.com/gogf/gf/frame/g"
|
|
|
"github.com/gogf/gf/util/gvalid"
|
|
|
+
|
|
|
+ model "dashoo.cn/micro/app/model/base"
|
|
|
+ server "dashoo.cn/micro/app/service/base"
|
|
|
)
|
|
|
|
|
|
type ProductHandler struct{}
|
|
|
|
|
|
// GetList 获取列表
|
|
|
func (p *ProductHandler) GetList(ctx context.Context, req *model.BaseProductSearchReq, rsp *comm_def.CommonMsg) error {
|
|
|
- productServer, err := service.NewBaseProductService(ctx)
|
|
|
+
|
|
|
+ productServer, err := server.NewProductService(ctx) //service.NewBaseProductService(ctx)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
return err
|
|
|
}
|
|
|
- g.Log().Info("搜索值",req)
|
|
|
- total, list, err:=productServer.GetList(req)
|
|
|
+ g.Log().Info("搜索值", req)
|
|
|
+ total, list, err := productServer.GetList(req)
|
|
|
_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
@@ -37,7 +40,7 @@ func (p *ProductHandler) Create(ctx context.Context, req *model.AddBaseProductRe
|
|
|
if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- productServer, err := service.NewBaseProductService(ctx)
|
|
|
+ productServer, err := server.NewProductService(ctx)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
return err
|
|
|
@@ -50,19 +53,19 @@ func (p *ProductHandler) Create(ctx context.Context, req *model.AddBaseProductRe
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
-//单条删除数据
|
|
|
-func (p *ProductHandler)Delete(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
|
|
|
+
|
|
|
+//批量删除数据
|
|
|
+func (p *ProductHandler) DeleteByIds(ctx context.Context, req *model.DeIds, rsp *comm_def.CommonMsg) error {
|
|
|
// 参数校验
|
|
|
- if req.Id == 0{
|
|
|
- return gerror.New("参数有误!")
|
|
|
+ if len(req.Ids) == 0 {
|
|
|
+ return gerror.New("参数为空,操作失败")
|
|
|
}
|
|
|
- productServer, err := service.NewBaseProductService(ctx)
|
|
|
+ productServer, err := server.NewProductService(ctx)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
return gerror.New("系统异常,请重新尝试")
|
|
|
}
|
|
|
-
|
|
|
- err = productServer.Delete(req.Id)
|
|
|
+ err = productServer.DeleteByIds(req.Ids)
|
|
|
_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
@@ -70,18 +73,19 @@ func (p *ProductHandler)Delete(ctx context.Context, req *comm_def.IdReq, rsp *co
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
//编辑
|
|
|
-func (p *ProductHandler)Editinfo(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
|
|
|
+func (p *ProductHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
|
|
|
// 参数校验
|
|
|
- if req.Id == 0{
|
|
|
+ if req.Id == 0 {
|
|
|
return gerror.New("参数有误!")
|
|
|
}
|
|
|
- productServer, err := service.NewBaseProductService(ctx)
|
|
|
+ productServer, err := server.NewProductService(ctx)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
return gerror.New("系统异常,请重新尝试")
|
|
|
}
|
|
|
- _,err = productServer.GetProductInfo(req.Id)
|
|
|
+ _, err = productServer.GetEntityById(req.Id)
|
|
|
_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
@@ -89,14 +93,15 @@ func (p *ProductHandler)Editinfo(ctx context.Context, req *comm_def.IdReq, rsp *
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
//更新信息
|
|
|
-func (p *ProductHandler)UpdateInfo(ctx context.Context, req *model.UpdateBaseProductReq, rsp *comm_def.CommonMsg) error {
|
|
|
- productServer, err := service.NewBaseProductService(ctx)
|
|
|
+func (p *ProductHandler) UpdateById(ctx context.Context, req *model.UpdateBaseProductReq, rsp *comm_def.CommonMsg) error {
|
|
|
+ productServer, err := server.NewProductService(ctx)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
return gerror.New("系统异常,请重新尝试")
|
|
|
}
|
|
|
- err = productServer.Update(req)
|
|
|
+ err = productServer.UpdateById(req)
|
|
|
_, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
|
|
|
if err != nil {
|
|
|
g.Log().Error(err)
|
|
|
@@ -104,4 +109,4 @@ func (p *ProductHandler)UpdateInfo(ctx context.Context, req *model.UpdateBasePro
|
|
|
}
|
|
|
return nil
|
|
|
|
|
|
-}
|
|
|
+}
|