mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-04-08 05:35:19 +08:00
refactor: 后端路由定义方式&请求参数绑定重构
This commit is contained in:
@@ -18,25 +18,15 @@ type AuthCert struct {
|
||||
}
|
||||
|
||||
func (ac *AuthCert) BaseAuthCerts(rc *req.Ctx) {
|
||||
g := rc.GinCtx
|
||||
condition := &entity.AuthCert{
|
||||
Name: g.Query("name"),
|
||||
AuthMethod: int8(ginx.QueryInt(g, "authMethod", 0)),
|
||||
}
|
||||
condition.Id = uint64(ginx.QueryInt(g, "id", 0))
|
||||
rc.ResData = ac.AuthCertApp.GetPageList(condition, ginx.GetPageParam(g), new([]vo.AuthCertBaseVO))
|
||||
queryCond, page := ginx.BindQueryAndPage(rc.GinCtx, new(entity.AuthCertQuery))
|
||||
rc.ResData = ac.AuthCertApp.GetPageList(queryCond, page, new([]vo.AuthCertBaseVO))
|
||||
}
|
||||
|
||||
func (ac *AuthCert) AuthCerts(rc *req.Ctx) {
|
||||
g := rc.GinCtx
|
||||
condition := &entity.AuthCert{
|
||||
Name: g.Query("name"),
|
||||
AuthMethod: int8(ginx.QueryInt(g, "authMethod", 0)),
|
||||
}
|
||||
condition.Id = uint64(ginx.QueryInt(g, "id", 0))
|
||||
queryCond, page := ginx.BindQueryAndPage(rc.GinCtx, new(entity.AuthCertQuery))
|
||||
|
||||
res := new([]*entity.AuthCert)
|
||||
pageRes := ac.AuthCertApp.GetPageList(condition, ginx.GetPageParam(g), res)
|
||||
pageRes := ac.AuthCertApp.GetPageList(queryCond, page, res)
|
||||
for _, r := range *res {
|
||||
r.PwdDecrypt()
|
||||
}
|
||||
|
||||
@@ -33,10 +33,7 @@ type Machine struct {
|
||||
}
|
||||
|
||||
func (m *Machine) Machines(rc *req.Ctx) {
|
||||
condition := new(entity.MachineQuery)
|
||||
condition.Ip = rc.GinCtx.Query("ip")
|
||||
condition.Name = rc.GinCtx.Query("name")
|
||||
condition.TagPathLike = rc.GinCtx.Query("tagPath")
|
||||
condition, pageParam := ginx.BindQueryAndPage(rc.GinCtx, new(entity.MachineQuery))
|
||||
|
||||
// 不存在可访问标签id,即没有可操作数据
|
||||
tagIds := m.TagApp.ListTagIdByAccountId(rc.LoginAccount.Id)
|
||||
@@ -46,7 +43,7 @@ func (m *Machine) Machines(rc *req.Ctx) {
|
||||
}
|
||||
condition.TagIds = tagIds
|
||||
|
||||
res := m.MachineApp.GetMachineList(condition, ginx.GetPageParam(rc.GinCtx), new([]*vo.MachineVO))
|
||||
res := m.MachineApp.GetMachineList(condition, pageParam, new([]*vo.MachineVO))
|
||||
if res.Total == 0 {
|
||||
rc.ResData = res
|
||||
return
|
||||
@@ -65,12 +62,8 @@ func (m *Machine) MachineStats(rc *req.Ctx) {
|
||||
|
||||
// 保存机器信息
|
||||
func (m *Machine) SaveMachine(rc *req.Ctx) {
|
||||
g := rc.GinCtx
|
||||
machineForm := new(form.MachineForm)
|
||||
ginx.BindJsonAndValid(g, machineForm)
|
||||
|
||||
me := new(entity.Machine)
|
||||
utils.Copy(me, machineForm)
|
||||
me := ginx.BindJsonAndCopyTo(rc.GinCtx, machineForm, new(entity.Machine))
|
||||
|
||||
machineForm.Password = "******"
|
||||
rc.ReqParam = machineForm
|
||||
@@ -199,7 +192,7 @@ func (m *Machine) WsSSH(g *gin.Context) {
|
||||
biz.ErrIsNilAppendErr(err, "\033[1;31m连接失败: %s\033[0m")
|
||||
|
||||
// 记录系统操作日志
|
||||
rc.WithLog(req.NewLogInfo("机器-终端操作").WithSave(true))
|
||||
rc.WithLog(req.NewLogSave("机器-终端操作"))
|
||||
rc.ReqParam = cli.GetMachine().GetLogDesc()
|
||||
req.LogHandler(rc)
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/ginx"
|
||||
"mayfly-go/pkg/req"
|
||||
"mayfly-go/pkg/utils"
|
||||
"mayfly-go/pkg/ws"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -40,22 +39,16 @@ func (m *MachineFile) MachineFiles(rc *req.Ctx) {
|
||||
}
|
||||
|
||||
func (m *MachineFile) SaveMachineFiles(rc *req.Ctx) {
|
||||
g := rc.GinCtx
|
||||
fileForm := new(form.MachineFileForm)
|
||||
ginx.BindJsonAndValid(g, fileForm)
|
||||
|
||||
entity := new(entity.MachineFile)
|
||||
utils.Copy(entity, fileForm)
|
||||
|
||||
entity := ginx.BindJsonAndCopyTo[*entity.MachineFile](rc.GinCtx, fileForm, new(entity.MachineFile))
|
||||
entity.SetBaseInfo(rc.LoginAccount)
|
||||
|
||||
rc.ReqParam = fileForm
|
||||
m.MachineFileApp.Save(entity)
|
||||
}
|
||||
|
||||
func (m *MachineFile) DeleteFile(rc *req.Ctx) {
|
||||
g := rc.GinCtx
|
||||
fid := GetMachineFileId(g)
|
||||
m.MachineFileApp.Delete(fid)
|
||||
m.MachineFileApp.Delete(GetMachineFileId(rc.GinCtx))
|
||||
}
|
||||
|
||||
/*** sftp相关操作 */
|
||||
@@ -64,8 +57,7 @@ func (m *MachineFile) CreateFile(rc *req.Ctx) {
|
||||
g := rc.GinCtx
|
||||
fid := GetMachineFileId(g)
|
||||
|
||||
form := new(form.MachineCreateFileForm)
|
||||
ginx.BindJsonAndValid(g, form)
|
||||
form := ginx.BindJsonAndValid(g, new(form.MachineCreateFileForm))
|
||||
path := form.Path
|
||||
|
||||
mi := m.MachineFileApp.GetMachine(fid)
|
||||
|
||||
@@ -31,12 +31,9 @@ func (m *MachineScript) MachineScripts(rc *req.Ctx) {
|
||||
|
||||
func (m *MachineScript) SaveMachineScript(rc *req.Ctx) {
|
||||
form := new(form.MachineScriptForm)
|
||||
ginx.BindJsonAndValid(rc.GinCtx, form)
|
||||
rc.ReqParam = form
|
||||
machineScript := ginx.BindJsonAndCopyTo(rc.GinCtx, form, new(entity.MachineScript))
|
||||
|
||||
// 转换为entity,并设置基本信息
|
||||
machineScript := new(entity.MachineScript)
|
||||
utils.Copy(machineScript, form)
|
||||
rc.ReqParam = form
|
||||
machineScript.SetBaseInfo(rc.LoginAccount)
|
||||
|
||||
m.MachineScriptApp.Save(machineScript)
|
||||
|
||||
Reference in New Issue
Block a user