修复需要从前端传新增人修改人的问题

This commit is contained in:
2026-06-12 09:51:09 +08:00
parent 9dc12634f5
commit e5133eea34
8 changed files with 74 additions and 37 deletions

View File

@@ -9,6 +9,7 @@ import (
"gitea.redpowerfuture.com/red-future/common/db/gfdb"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/util/gconv"
)
@@ -17,11 +18,18 @@ var ApiInterface = new(apiInterfaceDao)
type apiInterfaceDao struct{}
// Insert 插入接口
func (d *apiInterfaceDao) Insert(ctx context.Context, req *dto.CreateApiInterfaceReq) (id int64, err error) {
func (d *apiInterfaceDao) Insert(ctx context.Context, req *dto.CreateApiInterfaceReq, creator string) (id int64, err error) {
var res *entity.ApiInterface
if err = gconv.Struct(req, &res); err != nil {
return
}
// 设置创建人和时间(服务端生成,不依赖前端入参)
now := gtime.Now()
res.Creator = creator
res.CreatedAt = now
res.Updater = creator
res.UpdatedAt = now
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Data(&res).Insert()
if err != nil {
return
@@ -30,8 +38,17 @@ func (d *apiInterfaceDao) Insert(ctx context.Context, req *dto.CreateApiInterfac
}
// Update 更新接口
func (d *apiInterfaceDao) Update(ctx context.Context, req *dto.UpdateApiInterfaceReq) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).Data(&req).OmitEmpty().Where(entity.ApiInterfaceCols.Id, req.Id).Update()
func (d *apiInterfaceDao) Update(ctx context.Context, req *dto.UpdateApiInterfaceReq, updater string) (rows int64, err error) {
// 设置更新人和更新时间(服务端生成,不依赖前端入参)
data := gconv.Map(req)
data[entity.ApiInterfaceCols.Updater] = updater
data[entity.ApiInterfaceCols.UpdatedAt] = gtime.Now()
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).
Data(data).
OmitEmpty().
Where(entity.ApiInterfaceCols.Id, req.Id).
Update()
if err != nil {
return
}
@@ -96,9 +113,13 @@ func (d *apiInterfaceDao) buildListFilter(ctx context.Context, req *dto.ListApiI
}
// UpdateStatus 更新接口状态
func (d *apiInterfaceDao) UpdateStatus(ctx context.Context, id int64, status string) (rows int64, err error) {
func (d *apiInterfaceDao) UpdateStatus(ctx context.Context, id int64, status string, updater string) (rows int64, err error) {
r, err := gfdb.DB(ctx).Model(ctx, consts.ApiInterfaceTable).
Data(map[string]interface{}{"status": status}).
Data(map[string]interface{}{
entity.ApiInterfaceCols.Status: status,
entity.ApiInterfaceCols.Updater: updater,
entity.ApiInterfaceCols.UpdatedAt: gtime.Now(),
}).
Where(entity.ApiInterfaceCols.Id, id).
Update()
if err != nil {