84 lines
2.9 KiB
Go
84 lines
2.9 KiB
Go
// ==========================================================================
|
||
// GFast自动生成controller操作代码。
|
||
// 生成日期:2025-08-11 10:15:42
|
||
// 生成路径: internal/app/businesses/controller/prevention.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 preventionController struct {
|
||
systemController.BaseController
|
||
}
|
||
|
||
var Prevention = new(preventionController)
|
||
|
||
// List 列表
|
||
func (c *preventionController) List(ctx context.Context, req *businesses.PreventionSearchReq) (res *businesses.PreventionSearchRes, err error) {
|
||
res = new(businesses.PreventionSearchRes)
|
||
res.PreventionSearchRes, err = service.Prevention().List(ctx, &req.PreventionSearchReq)
|
||
return
|
||
}
|
||
|
||
// Get 获取防控措施
|
||
func (c *preventionController) Get(ctx context.Context, req *businesses.PreventionGetReq) (res *businesses.PreventionGetRes, err error) {
|
||
res = new(businesses.PreventionGetRes)
|
||
res.PreventionInfoRes, err = service.Prevention().GetById(ctx, req.Id)
|
||
return
|
||
}
|
||
|
||
// Add 添加防控措施
|
||
func (c *preventionController) Add(ctx context.Context, req *businesses.PreventionAddReq) (res *businesses.PreventionAddRes, err error) {
|
||
err = service.Prevention().Add(ctx, req.PreventionAddReq)
|
||
return
|
||
}
|
||
|
||
// Edit 修改防控措施
|
||
func (c *preventionController) Edit(ctx context.Context, req *businesses.PreventionEditReq) (res *businesses.PreventionEditRes, err error) {
|
||
newVersion, err := lock.TryOptimisticLock(ctx, dao.Prevention.Ctx(ctx), "id", req.Id, req.Version)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
req.Version = newVersion
|
||
err = service.Prevention().Edit(ctx, req.PreventionEditReq)
|
||
return
|
||
}
|
||
|
||
// Delete 删除防控措施
|
||
func (c *preventionController) Delete(ctx context.Context, req *businesses.PreventionDeleteReq) (res *businesses.PreventionDeleteRes, err error) {
|
||
for i, id := range req.Ids {
|
||
_, err = lock.TryOptimisticLock(ctx, dao.Prevention.Ctx(ctx), "id", id, req.Version[i])
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
}
|
||
err = service.Prevention().Delete(ctx, req.Ids)
|
||
return
|
||
}
|
||
func (c *preventionController) Audit(ctx context.Context, req *common.AuditReq) (res *g.Map, err error) {
|
||
err = common.Audit.Audit(ctx, dao.Prevention.Ctx(ctx), req, func(ctx context.Context, req *common.AuditReq) error {
|
||
return common.Audit.SaveAudit(dao.Prevention.Ctx(ctx), req)
|
||
})
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
return &g.Map{
|
||
"msg": "审核成功",
|
||
"newVersion": req.Version,
|
||
}, nil
|
||
}
|