85 lines
2.9 KiB
Go
85 lines
2.9 KiB
Go
// ==========================================================================
|
||
// GFast自动生成controller操作代码。
|
||
// 生成日期:2025-08-11 16:49:09
|
||
// 生成路径: internal/app/businesses/controller/species_imgs.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 speciesImgsController struct {
|
||
systemController.BaseController
|
||
}
|
||
|
||
var SpeciesImgs = new(speciesImgsController)
|
||
|
||
// List 列表
|
||
func (c *speciesImgsController) List(ctx context.Context, req *businesses.SpeciesImgsSearchReq) (res *businesses.SpeciesImgsSearchRes, err error) {
|
||
res = new(businesses.SpeciesImgsSearchRes)
|
||
res.SpeciesImgsSearchRes, err = service.SpeciesImgs().List(ctx, &req.SpeciesImgsSearchReq)
|
||
return
|
||
}
|
||
|
||
// Get 获取
|
||
func (c *speciesImgsController) Get(ctx context.Context, req *businesses.SpeciesImgsGetReq) (res *businesses.SpeciesImgsGetRes, err error) {
|
||
res = new(businesses.SpeciesImgsGetRes)
|
||
res.SpeciesImgsInfoRes, err = service.SpeciesImgs().GetByInt(ctx, req.Int)
|
||
return
|
||
}
|
||
|
||
// Add 添加
|
||
func (c *speciesImgsController) Add(ctx context.Context, req *businesses.SpeciesImgsAddReq) (res *businesses.SpeciesImgsAddRes, err error) {
|
||
err = service.SpeciesImgs().Add(ctx, req.SpeciesImgsAddReq)
|
||
return
|
||
}
|
||
|
||
// Edit 修改
|
||
func (c *speciesImgsController) Edit(ctx context.Context, req *businesses.SpeciesImgsEditReq) (res *businesses.SpeciesImgsEditRes, err error) {
|
||
newVersion, err := lock.TryOptimisticLock(ctx, dao.SpeciesImgs.Ctx(ctx), "id", req.Id, req.Version)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
req.Version = newVersion
|
||
err = service.SpeciesImgs().Edit(ctx, req.SpeciesImgsEditReq)
|
||
return
|
||
}
|
||
|
||
// Delete 删除
|
||
func (c *speciesImgsController) Delete(ctx context.Context, req *businesses.SpeciesImgsDeleteReq) (res *businesses.SpeciesImgsDeleteRes, err error) {
|
||
for i, id := range req.Ids {
|
||
_, err = lock.TryOptimisticLock(ctx, dao.SpeciesImgs.Ctx(ctx), "id", id, req.Version[i])
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
}
|
||
err = service.SpeciesImgs().Delete(ctx, req.Ids)
|
||
return
|
||
}
|
||
|
||
func (c *speciesImgsController) Audit(ctx context.Context, req *common.AuditReq) (res *g.Map, err error) {
|
||
err = common.Audit.Audit(ctx, dao.SpeciesImgs.Ctx(ctx), req, func(ctx context.Context, req *common.AuditReq) error {
|
||
return common.Audit.SaveAudit(dao.SpeciesImgs.Ctx(ctx), req)
|
||
})
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
return &g.Map{
|
||
"msg": "审核成功",
|
||
"newVersion": req.Version,
|
||
}, nil
|
||
}
|