refactor(service): 重构服务代码结构并更新配置
This commit is contained in:
@@ -2,47 +2,54 @@ package dao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"prompts-core/consts/public"
|
||||
"prompts-core/model/entity"
|
||||
|
||||
"gitea.com/red-future/common/db/gfdb"
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
var ComposeTask = &composeTaskDao{}
|
||||
|
||||
type composeTaskDao struct{}
|
||||
|
||||
func (d *composeTaskDao) Insert(ctx context.Context, m *entity.ComposeTask) (id int64, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeTask).Data(m).Insert()
|
||||
// Insert 插入
|
||||
func (d *composeTaskDao) Insert(ctx context.Context, req *entity.ComposeTask) (id int64, err error) {
|
||||
var m = new(entity.ComposeTask)
|
||||
err = gconv.Struct(req, &m)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return
|
||||
}
|
||||
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeTask).
|
||||
Insert(m)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return r.LastInsertId()
|
||||
}
|
||||
|
||||
func (d *composeTaskDao) GetByTaskId(ctx context.Context, taskId string) (m *entity.ComposeTask, err error) {
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeTask).
|
||||
Where(entity.ComposeTaskCol.TaskId, taskId).
|
||||
One()
|
||||
// Get 获取
|
||||
func (d *composeTaskDao) Get(ctx context.Context, req *entity.ComposeTask, fields ...string) (m *entity.ComposeTask, err error) {
|
||||
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeTask).
|
||||
OmitEmpty().
|
||||
Where(entity.ComposeTaskCol.TaskId, req.TaskId).
|
||||
Fields(fields).One()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if r.IsEmpty() {
|
||||
return nil, nil
|
||||
return
|
||||
}
|
||||
err = r.Struct(&m)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *composeTaskDao) UpdateByTaskId(ctx context.Context, taskId string, data map[string]any) (rows int64, err error) {
|
||||
data[entity.ComposeTaskCol.Updater] = ""
|
||||
r, err := gfdb.DB(ctx).Model(ctx, public.TableNameComposeTask).
|
||||
Where(entity.ComposeTaskCol.TaskId, taskId).
|
||||
Data(data).
|
||||
// Update 更新
|
||||
func (d *composeTaskDao) Update(ctx context.Context, req *entity.ComposeTask) (rows int64, err error) {
|
||||
r, err := gfdb.DB(ctx, public.DbNameModelGateway).Model(ctx, public.TableNameComposeTask).
|
||||
OmitEmpty().
|
||||
Data(&req).
|
||||
Where(entity.ComposeTaskCol.TaskId, req.TaskId).
|
||||
Update()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return
|
||||
}
|
||||
return r.RowsAffected()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user