72 lines
2.2 KiB
Go
72 lines
2.2 KiB
Go
package flow
|
|
|
|
import (
|
|
"ai-agent/workflow/consts/public"
|
|
flowDto "ai-agent/workflow/model/dto/flow"
|
|
"ai-agent/workflow/model/entity"
|
|
"context"
|
|
|
|
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
)
|
|
|
|
var FlowUserDao = &flowUserDao{}
|
|
|
|
type flowUserDao struct{}
|
|
|
|
func (d *flowUserDao) Insert(ctx context.Context, req *flowDto.CreateFlowUserReq) (id int64, err error) {
|
|
var e = new(entity.FlowUser)
|
|
err = gconv.Struct(req, &e)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameFlowUser).Insert(e)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.LastInsertId()
|
|
}
|
|
|
|
func (d *flowUserDao) Update(ctx context.Context, req *flowDto.UpdateFlowUserReq) (rows int64, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameFlowUser).OmitEmpty().
|
|
Where(entity.FlowUserCol.Id, req.Id).
|
|
Data(req).
|
|
Update()
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.RowsAffected()
|
|
}
|
|
|
|
func (d *flowUserDao) Delete(ctx context.Context, req *flowDto.DeleteFlowUserReq) (rows int64, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameFlowUser).Where(entity.FlowUserCol.Id, req.Id).Delete()
|
|
if err != nil {
|
|
return
|
|
}
|
|
return r.RowsAffected()
|
|
}
|
|
|
|
func (d *flowUserDao) Get(ctx context.Context, req *flowDto.GetFlowUserReq, fields ...string) (res *entity.FlowUser, err error) {
|
|
r, err := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameFlowUser).NoTenantId(ctx).Where(entity.FlowUserCol.Id, req.Id).Fields(fields).One()
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = r.Struct(&res)
|
|
return
|
|
}
|
|
|
|
func (d *flowUserDao) List(ctx context.Context, req *flowDto.ListFlowUserReq, fields ...string) (res []*entity.FlowUser, total int, err error) {
|
|
model := gfdb.DB(ctx, public.DbNameBlackDeacon).Model(ctx, public.TableNameFlowUser).NoTenantId(ctx).Fields(fields).OmitEmpty()
|
|
model.Where(entity.FlowUserCol.Creator, req.Creator)
|
|
model.OrderDesc(entity.FlowUserCol.CreatedAt)
|
|
if req.Page != nil {
|
|
model.Page(int(req.Page.PageNum), int(req.Page.PageSize))
|
|
}
|
|
r, total, err := model.AllAndCount(false)
|
|
if err != nil {
|
|
return
|
|
}
|
|
err = r.Structs(&res)
|
|
return
|
|
}
|