// ========================================================================== // GFast自动生成controller操作代码。 // 生成日期:2025-08-11 09:34:44 // 生成路径: internal/app/businesses/controller/host_botany.go // 生成人:gfast // desc:寄主生物 // company:云南奇讯科技有限公司 // ========================================================================== package controller import ( "context" "github.com/gogf/gf/v2/frame/g" "github.com/tiger1103/gfast/v3/api/v1/businesses" "github.com/tiger1103/gfast/v3/internal/app/businesses/common" "github.com/tiger1103/gfast/v3/internal/app/businesses/dao" "github.com/tiger1103/gfast/v3/internal/app/businesses/service" "github.com/tiger1103/gfast/v3/internal/app/lock" systemController "github.com/tiger1103/gfast/v3/internal/app/system/controller" ) type hostBotanyController struct { systemController.BaseController } var HostBotany = new(hostBotanyController) // List 列表 func (c *hostBotanyController) List(ctx context.Context, req *businesses.HostBotanySearchReq) (res *businesses.HostBotanySearchRes, err error) { res = new(businesses.HostBotanySearchRes) res.HostBotanySearchRes, err = service.HostBotany().List(ctx, &req.HostBotanySearchReq) return } // Get 获取寄主生物 func (c *hostBotanyController) Get(ctx context.Context, req *businesses.HostBotanyGetReq) (res *businesses.HostBotanyGetRes, err error) { res = new(businesses.HostBotanyGetRes) res.HostBotanyInfoRes, err = service.HostBotany().GetById(ctx, req.Id) return } // Add 添加寄主生物 func (c *hostBotanyController) Add(ctx context.Context, req *businesses.HostBotanyAddReq) (res *businesses.HostBotanyAddRes, err error) { err = service.HostBotany().Add(ctx, req.HostBotanyAddReq) return } // Edit 修改寄主生物 func (c *hostBotanyController) Edit(ctx context.Context, req *businesses.HostBotanyEditReq) (res *businesses.HostBotanyEditRes, err error) { newVersion, err := lock.TryOptimisticLock(ctx, dao.HostBotany.Ctx(ctx), "id", req.Id, req.Version) if err != nil { return nil, err } req.Version = newVersion err = service.HostBotany().Edit(ctx, req.HostBotanyEditReq) return } // Delete 删除寄主生物 func (c *hostBotanyController) Delete(ctx context.Context, req *businesses.HostBotanyDeleteReq) (res *businesses.HostBotanyDeleteRes, err error) { for i, id := range req.Ids { _, err = lock.TryOptimisticLock(ctx, dao.HostBotany.Ctx(ctx), "id", id, req.Version[i]) if err != nil { return nil, err } } err = service.HostBotany().Delete(ctx, req.Ids) return } func (c *hostBotanyController) Audit(ctx context.Context, req *common.AuditReq) (res *g.Map, err error) { err = common.Audit.Audit(ctx, dao.HostBotany.Ctx(ctx), req, func(ctx context.Context, req *common.AuditReq) error { return common.Audit.SaveAudit(dao.HostBotany.Ctx(ctx), req) }) if err != nil { return nil, err } return &g.Map{ "msg": "审核成功", "newVersion": req.Version, }, nil }