修复需要从前端传新增人修改人的问题
This commit is contained in:
@@ -283,13 +283,11 @@ function pfHTML(d) {
|
||||
'<div class="form-group"><label>超时(ms)</label><input id="f-to" type="number" value="' + (d.requestTimeoutMs||30000) + '"></div></div>';
|
||||
}
|
||||
async function saveP(id) {
|
||||
const now = Date.now().toString();
|
||||
const body = {
|
||||
platformCode: v('f-pcode'), platformName: v('f-pname'), apiBaseUrl: v('f-apiurl'),
|
||||
authType: v('f-auth'), status: v('f-ps'), token: v('f-tk'),
|
||||
clientId: v('f-cid'), clientSecret: v('f-cs'),
|
||||
rateLimitPerMinute: parseInt(v('f-rpm'))||60, requestTimeoutMs: parseInt(v('f-to'))||30000,
|
||||
createdBy: 'admin', createdAt: now, updatedBy: 'admin', updatedAt: now, version: '0',
|
||||
};
|
||||
try { body.authConfig = JSON.parse(v('f-ac')); } catch(e) { toast('auth_config JSON 格式错误', 'error'); return; }
|
||||
try {
|
||||
|
||||
@@ -18,15 +18,16 @@ var DatasourcePlatform = new(datasourcePlatformDao)
|
||||
type datasourcePlatformDao struct{}
|
||||
|
||||
// Insert 插入数据源平台
|
||||
func (d *datasourcePlatformDao) Insert(ctx context.Context, req *dto.CreateDatasourcePlatformReq) (ID int64, err error) {
|
||||
func (d *datasourcePlatformDao) Insert(ctx context.Context, req *dto.CreateDatasourcePlatformReq, createdBy string) (ID int64, err error) {
|
||||
var res *entity.DatasourcePlatform
|
||||
if err = gconv.Struct(req, &res); err != nil {
|
||||
return
|
||||
}
|
||||
// 设置创建时间
|
||||
// 设置创建时间和更新时间
|
||||
// 设置创建人和时间(服务端生成,不依赖前端入参)
|
||||
now := time.Now()
|
||||
res.CreatedBy = createdBy
|
||||
res.CreatedAt = &now
|
||||
res.UpdatedBy = createdBy
|
||||
res.UpdatedAt = &now
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DatasourcePlatformTable).Data(&res).Insert()
|
||||
@@ -37,9 +38,10 @@ func (d *datasourcePlatformDao) Insert(ctx context.Context, req *dto.CreateDatas
|
||||
}
|
||||
|
||||
// Update 更新数据源平台
|
||||
func (d *datasourcePlatformDao) Update(ctx context.Context, req *dto.UpdateDatasourcePlatformReq) (rows int64, err error) {
|
||||
// 设置更新时间
|
||||
func (d *datasourcePlatformDao) Update(ctx context.Context, req *dto.UpdateDatasourcePlatformReq, updatedBy string) (rows int64, err error) {
|
||||
// 设置更新人和更新时间(服务端生成,不依赖前端入参)
|
||||
data := gconv.Map(req)
|
||||
data[entity.DatasourcePlatformCols.UpdatedBy] = updatedBy
|
||||
data[entity.DatasourcePlatformCols.UpdatedAt] = time.Now()
|
||||
|
||||
r, err := gfdb.DB(ctx).Model(ctx, consts.DatasourcePlatformTable).
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -28,10 +28,6 @@ type CreateDatasourcePlatformReq struct {
|
||||
MaxRetries int `json:"maxRetries" dc:"最大重试次数" d:"3"`
|
||||
RetryDelayMs int `json:"retryDelayMs" dc:"重试延迟(毫秒)" d:"1000"`
|
||||
AuthConfig map[string]interface{} `json:"authConfig" dc:"自定义认证配置(JSON),支持各平台特有认证方式"`
|
||||
CreatedBy string `json:"createdBy" v:"required" dc:"创建人"`
|
||||
CreatedAt string `json:"createdAt" v:"required" dc:"创建时间"`
|
||||
UpdatedBy string `json:"updatedBy" v:"required" dc:"修改人"`
|
||||
UpdatedAt string `json:"updatedAt" v:"required" dc:"修改人"`
|
||||
}
|
||||
|
||||
// CreateDatasourcePlatformRes 创建数据源平台响应
|
||||
@@ -110,9 +106,6 @@ type UpdateDatasourcePlatformReq struct {
|
||||
MaxRetries int `json:"maxRetries" dc:"最大重试次数"`
|
||||
RetryDelayMs int `json:"retryDelayMs" dc:"重试延迟(毫秒)"`
|
||||
AuthConfig map[string]interface{} `json:"authConfig" dc:"自定义认证配置(JSON)"`
|
||||
UpdatedBy string `json:"updatedBy" v:"required" dc:"更新人"`
|
||||
UpdatedAt string `json:"updatedAt" v:"required" dc:"更新时间"`
|
||||
Version string `json:"version" v:"required" dc:"版本"`
|
||||
}
|
||||
|
||||
// DeleteDatasourcePlatformReq 删除数据源平台请求
|
||||
@@ -126,7 +119,6 @@ type UpdateDatasourcePlatformStatusReq struct {
|
||||
g.Meta `path:"/updateDatasourcePlatformStatus" method:"put" tags:"数据源平台管理" summary:"更新数据源平台状态" dc:"更新数据源平台状态"`
|
||||
Id int64 `json:"id" v:"required" dc:"平台ID"`
|
||||
Status api_feature.PlatformStatus `json:"status" v:"required|in:ACTIVE,INACTIVE" dc:"状态:ACTIVE启用/INACTIVE停用"`
|
||||
UpdatedBy string `json:"updatedBy" v:"required" dc:"更新人"`
|
||||
}
|
||||
|
||||
// 以下是几个额外的实用API接口
|
||||
|
||||
@@ -57,7 +57,9 @@ type ApiInterfaceItem struct {
|
||||
Method api_feature.ApiMethod `json:"method"`
|
||||
Status api_feature.PlatformStatus `json:"status"`
|
||||
StatusName string `json:"statusName"`
|
||||
CreatedBy string `json:"createdBy"`
|
||||
CreatedAt int64 `json:"createdAt"`
|
||||
UpdatedBy string `json:"updatedBy"`
|
||||
UpdatedAt int64 `json:"updatedAt"`
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
dao "dataengine/dao/dict"
|
||||
dto "dataengine/model/dto/dict"
|
||||
entity "dataengine/model/entity/dict"
|
||||
"strconv"
|
||||
"dataengine/utils"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
@@ -34,14 +34,11 @@ func (s *datasourcePlatformService) Create(ctx context.Context, req *dto.CreateD
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 设置创建时间为当前时间
|
||||
if req.CreatedAt == "" {
|
||||
req.CreatedAt = strconv.FormatInt(time.Now().Unix(), 10)
|
||||
}
|
||||
req.UpdatedAt = req.CreatedAt
|
||||
// 从 context 中获取当前用户
|
||||
currentUser := utils.GetCurrentUser(ctx)
|
||||
|
||||
// 插入数据库
|
||||
id, err := dao.DatasourcePlatform.Insert(ctx, req)
|
||||
id, err := dao.DatasourcePlatform.Insert(ctx, req, currentUser)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -165,9 +162,9 @@ func (s *datasourcePlatformService) Update(ctx context.Context, req *dto.UpdateD
|
||||
}
|
||||
}
|
||||
|
||||
// 设置更新时间
|
||||
req.UpdatedAt = strconv.FormatInt(time.Now().Unix(), 10)
|
||||
_, err = dao.DatasourcePlatform.Update(ctx, req)
|
||||
// 从 context 中获取当前用户
|
||||
currentUser := utils.GetCurrentUser(ctx)
|
||||
_, err = dao.DatasourcePlatform.Update(ctx, req, currentUser)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -187,7 +184,8 @@ func (s *datasourcePlatformService) UpdateStatus(ctx context.Context, req *dto.U
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err = dao.DatasourcePlatform.UpdateStatus(ctx, req.Id, req.Status.String(), req.UpdatedBy)
|
||||
currentUser := utils.GetCurrentUser(ctx)
|
||||
_, err = dao.DatasourcePlatform.UpdateStatus(ctx, req.Id, req.Status.String(), currentUser)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"dataengine/dao/dict"
|
||||
dto "dataengine/model/dto/dict"
|
||||
entity "dataengine/model/entity/dict"
|
||||
"dataengine/utils"
|
||||
"errors"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
@@ -35,8 +36,11 @@ func (s *apiInterfaceService) Create(ctx context.Context, req *dto.CreateApiInte
|
||||
return nil, errors.New("接口编码在该平台下已存在")
|
||||
}
|
||||
|
||||
// 从 context 中获取当前用户
|
||||
currentUser := utils.GetCurrentUser(ctx)
|
||||
|
||||
// 插入数据库
|
||||
id, err := dict.ApiInterface.Insert(ctx, req)
|
||||
id, err := dict.ApiInterface.Insert(ctx, req, currentUser)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -87,7 +91,9 @@ func (s *apiInterfaceService) List(ctx context.Context, req *dto.ListApiInterfac
|
||||
Method: item.Method,
|
||||
Status: item.Status,
|
||||
StatusName: s.getStatusName(item.Status),
|
||||
CreatedBy: item.Creator,
|
||||
CreatedAt: safeUnix(item.CreatedAt),
|
||||
UpdatedBy: item.Updater,
|
||||
UpdatedAt: safeUnix(item.UpdatedAt),
|
||||
})
|
||||
}
|
||||
@@ -151,13 +157,15 @@ func (s *apiInterfaceService) Update(ctx context.Context, req *dto.UpdateApiInte
|
||||
}
|
||||
}
|
||||
|
||||
_, err = dict.ApiInterface.Update(ctx, req)
|
||||
currentUser := utils.GetCurrentUser(ctx)
|
||||
_, err = dict.ApiInterface.Update(ctx, req, currentUser)
|
||||
return
|
||||
}
|
||||
|
||||
// UpdateStatus 更新接口状态
|
||||
func (s *apiInterfaceService) UpdateStatus(ctx context.Context, req *dto.UpdateApiInterfaceStatusReq) (err error) {
|
||||
_, err = dict.ApiInterface.UpdateStatus(ctx, req.Id, req.Status.String())
|
||||
currentUser := utils.GetCurrentUser(ctx)
|
||||
_, err = dict.ApiInterface.UpdateStatus(ctx, req.Id, req.Status.String(), currentUser)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
16
utils/context_utils.go
Normal file
16
utils/context_utils.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.redpowerfuture.com/red-future/common/beans"
|
||||
)
|
||||
|
||||
// GetCurrentUser 从 context 中获取当前登录用户
|
||||
// 如果未找到用户信息,返回默认 "unknown" 用户名
|
||||
func GetCurrentUser(ctx context.Context) string {
|
||||
if user, ok := ctx.Value("user").(*beans.User); ok && user != nil && user.UserName != "" {
|
||||
return user.UserName
|
||||
}
|
||||
return "unknown"
|
||||
}
|
||||
Reference in New Issue
Block a user