84 lines
3.1 KiB
Go
84 lines
3.1 KiB
Go
// ==========================================================================
|
||
// GFast自动生成controller操作代码。
|
||
// 生成日期:2025-08-08 15:18:02
|
||
// 生成路径: internal/app/businesses/controller/characteristic.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 characteristicController struct {
|
||
systemController.BaseController
|
||
}
|
||
|
||
var Characteristic = new(characteristicController)
|
||
|
||
// List 列表
|
||
func (c *characteristicController) List(ctx context.Context, req *businesses.CharacteristicSearchReq) (res *businesses.CharacteristicSearchRes, err error) {
|
||
res = new(businesses.CharacteristicSearchRes)
|
||
res.CharacteristicSearchRes, err = service.Characteristic().List(ctx, &req.CharacteristicSearchReq)
|
||
return
|
||
}
|
||
|
||
// Get 获取识别特征
|
||
func (c *characteristicController) Get(ctx context.Context, req *businesses.CharacteristicGetReq) (res *businesses.CharacteristicGetRes, err error) {
|
||
res = new(businesses.CharacteristicGetRes)
|
||
res.CharacteristicInfoRes, err = service.Characteristic().GetById(ctx, req.Id)
|
||
return
|
||
}
|
||
|
||
// Add 添加识别特征
|
||
func (c *characteristicController) Add(ctx context.Context, req *businesses.CharacteristicAddReq) (res *businesses.CharacteristicAddRes, err error) {
|
||
err = service.Characteristic().Add(ctx, req.CharacteristicAddReq)
|
||
return
|
||
}
|
||
|
||
// Edit 修改识别特征
|
||
func (c *characteristicController) Edit(ctx context.Context, req *businesses.CharacteristicEditReq) (res *businesses.CharacteristicEditRes, err error) {
|
||
newVersion, err := lock.TryOptimisticLock(ctx, dao.Characteristic.Ctx(ctx), "id", req.Id, req.Version)
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
req.Version = newVersion
|
||
err = service.Characteristic().Edit(ctx, req.CharacteristicEditReq)
|
||
return
|
||
}
|
||
|
||
// Delete 删除识别特征
|
||
func (c *characteristicController) Delete(ctx context.Context, req *businesses.CharacteristicDeleteReq) (res *businesses.CharacteristicDeleteRes, err error) {
|
||
for i, id := range req.Ids {
|
||
_, err = lock.TryOptimisticLock(ctx, dao.Characteristic.Ctx(ctx), "id", id, req.Version[i])
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
}
|
||
err = service.Characteristic().Delete(ctx, req.Ids)
|
||
return
|
||
}
|
||
func (c *characteristicController) Audit(ctx context.Context, req *common.AuditReq) (res *g.Map, err error) {
|
||
err = common.Audit.Audit(ctx, dao.Characteristic.Ctx(ctx), req, func(ctx context.Context, req *common.AuditReq) error {
|
||
return common.Audit.SaveAudit(dao.Characteristic.Ctx(ctx), req)
|
||
})
|
||
if err != nil {
|
||
return nil, err
|
||
}
|
||
return &g.Map{
|
||
"msg": "审核成功",
|
||
"newVersion": req.Version,
|
||
}, nil
|
||
}
|