| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package base
- import (
- "context"
- "dashoo.cn/common_definition/comm_def"
- "dashoo.cn/opms_libary/myerrors"
- "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 DistributorHandler struct{}
- // GetList 获取列表
- func (p *DistributorHandler) GetList(ctx context.Context, req *model.BaseDistributorSearchReq, rsp *comm_def.CommonMsg) error {
- distributorServer, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- total, list, err := distributorServer.GetList(req)
- _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
- if err != nil {
- return err
- }
- rsp.Data = g.Map{"list": list, "total": total}
- return nil
- }
- //Create 创建
- func (p *DistributorHandler) Create(ctx context.Context, req *model.AddDistributor, rsp *comm_def.CommonMsg) error {
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- distributorServer, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- distributorServer.Create(req)
- _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
- if err != nil {
- return err
- }
- return nil
- }
- //GetEntityById 详情
- func (p *DistributorHandler) GetEntityById(ctx context.Context, req *comm_def.IdReq, rsp *comm_def.CommonMsg) error {
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- distributorServer, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- list, err := distributorServer.GetEntityById(req.Id)
- _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
- if err != nil {
- return err
- }
- rsp.Data = g.Map{"list": list}
- return nil
- }
- //UpdateById 编辑
- func (p *DistributorHandler) UpdateById(ctx context.Context, req *model.UpdateDistributorReq, rsp *comm_def.CommonMsg) error {
- if err := gvalid.CheckStruct(ctx, req, nil); err != nil {
- return err
- }
- distributorServer, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- distributorServer.UpdateById(req)
- _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
- if err != nil {
- return err
- }
- return nil
- }
- //DeleteByIds 删掉
- func (p *DistributorHandler) DeleteByIds(ctx context.Context, req *model.DeleteDistributorReq, rsp *comm_def.CommonMsg) error {
- distributorServer, err := server.NewDistributorService(ctx)
- if err != nil {
- return err
- }
- err = distributorServer.DeleteByIds(req.Ids)
- _, err, rsp.Code, rsp.Msg = myerrors.CheckError(err)
- if err != nil {
- g.Log().Error(err)
- return err
- }
- return nil
- }
|