feat: flow design & page query refactor

This commit is contained in:
meilin.huang
2025-05-20 21:04:47 +08:00
parent 44d379a016
commit f676ec9e7b
269 changed files with 5072 additions and 5075 deletions

View File

@@ -76,7 +76,7 @@ func (m *Machine) ReqConfs() *req.Confs {
}
func (m *Machine) Machines(rc *req.Ctx) {
condition, pageParam := req.BindQueryAndPage(rc, new(entity.MachineQuery))
condition := req.BindQuery(rc, new(entity.MachineQuery))
tags := m.tagTreeApp.GetAccountTags(rc.GetLoginAccount().Id, &tagentity.TagTreeQuery{
TypePaths: collx.AsArray(tagentity.NewTypePaths(tagentity.TagTypeMachine, tagentity.TagTypeAuthCert)),
@@ -84,7 +84,7 @@ func (m *Machine) Machines(rc *req.Ctx) {
})
// 不存在可操作的机器-授权凭证标签,即没有可操作数据
if len(tags) == 0 {
rc.ResData = model.EmptyPageResult[any]()
rc.ResData = model.NewEmptyPageResult[any]()
return
}
@@ -92,14 +92,16 @@ func (m *Machine) Machines(rc *req.Ctx) {
machineCodes := tagentity.GetCodesByCodePaths(tagentity.TagTypeMachine, tagCodePaths...)
condition.Codes = collx.ArrayDeduplicate(machineCodes)
var machinevos []*vo.MachineVO
res, err := m.machineApp.GetMachineList(condition, pageParam, &machinevos)
res, err := m.machineApp.GetMachineList(condition)
biz.ErrIsNil(err)
if res.Total == 0 {
rc.ResData = res
return
}
resVo := model.PageResultConv[*entity.Machine, *vo.MachineVO](res)
machinevos := resVo.List
// 填充标签信息
m.tagTreeApp.FillTagInfo(tagentity.TagType(consts.ResourceTypeMachine), collx.ArrayMap(machinevos, func(mvo *vo.MachineVO) tagentity.ITagResource {
return mvo
@@ -120,7 +122,7 @@ func (m *Machine) Machines(rc *req.Ctx) {
}
}
}
rc.ResData = res
rc.ResData = resVo
}
func (m *Machine) SimpleMachieInfo(rc *req.Ctx) {
@@ -270,7 +272,7 @@ func (m *Machine) WsSSH(rc *req.Ctx) {
func (m *Machine) MachineTermOpRecords(rc *req.Ctx) {
mid := GetMachineId(rc)
res, err := m.machineTermOpApp.GetPageList(&entity.MachineTermOp{MachineId: mid}, rc.GetPageParam(), new([]entity.MachineTermOp))
res, err := m.machineTermOpApp.GetPageList(&entity.MachineTermOp{MachineId: mid}, rc.GetPageParam())
biz.ErrIsNil(err)
rc.ResData = res
}

View File

@@ -12,6 +12,7 @@ import (
"strings"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/model"
"mayfly-go/pkg/req"
"mayfly-go/pkg/scheduler"
"mayfly-go/pkg/utils/collx"
@@ -44,9 +45,10 @@ func (mcj *MachineCronJob) ReqConfs() *req.Confs {
func (m *MachineCronJob) MachineCronJobs(rc *req.Ctx) {
cond, pageParam := req.BindQueryAndPage(rc, new(entity.MachineCronJob))
var vos []*vo.MachineCronJobVO
pageRes, err := m.machineCronJobApp.GetPageList(cond, pageParam, &vos)
pageRes, err := m.machineCronJobApp.GetPageList(cond, pageParam)
biz.ErrIsNil(err)
resVo := model.PageResultConv[*entity.MachineCronJob, *vo.MachineCronJobVO](pageRes)
vos := resVo.List
for _, mcj := range vos {
mcj.Running = scheduler.ExistKey(mcj.Key)
@@ -56,7 +58,7 @@ func (m *MachineCronJob) MachineCronJobs(rc *req.Ctx) {
return mvo
})...)
rc.ResData = pageRes
rc.ResData = resVo
}
func (m *MachineCronJob) Save(rc *req.Ctx) {
@@ -89,7 +91,7 @@ func (m *MachineCronJob) RunCronJob(rc *req.Ctx) {
func (m *MachineCronJob) CronJobExecs(rc *req.Ctx) {
cond, pageParam := req.BindQueryAndPage[*entity.MachineCronJobExec](rc, new(entity.MachineCronJobExec))
res, err := m.machineCronJobApp.GetExecPageList(cond, pageParam, new([]entity.MachineCronJobExec))
res, err := m.machineCronJobApp.GetExecPageList(cond, pageParam)
biz.ErrIsNil(err)
rc.ResData = res
}

View File

@@ -18,6 +18,7 @@ import (
"mayfly-go/pkg/errorx"
"mayfly-go/pkg/i18n"
"mayfly-go/pkg/logx"
"mayfly-go/pkg/model"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils/anyx"
"mayfly-go/pkg/utils/collx"
@@ -86,9 +87,9 @@ const (
func (m *MachineFile) MachineFiles(rc *req.Ctx) {
condition := &entity.MachineFile{MachineId: GetMachineId(rc)}
res, err := m.machineFileApp.GetPageList(condition, rc.GetPageParam(), new([]vo.MachineFileVO))
res, err := m.machineFileApp.GetPageList(condition, rc.GetPageParam())
biz.ErrIsNil(err)
rc.ResData = res
rc.ResData = model.PageResultConv[*entity.MachineFile, *vo.MachineFileVO](res)
}
func (m *MachineFile) SaveMachineFiles(rc *req.Ctx) {

View File

@@ -7,6 +7,7 @@ import (
"mayfly-go/internal/machine/domain/entity"
tagapp "mayfly-go/internal/tag/application"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/model"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils/collx"
"mayfly-go/pkg/utils/jsonx"
@@ -39,9 +40,9 @@ func (ms *MachineScript) ReqConfs() *req.Confs {
func (m *MachineScript) MachineScripts(rc *req.Ctx) {
condition := &entity.MachineScript{MachineId: GetMachineId(rc)}
res, err := m.machineScriptApp.GetPageList(condition, rc.GetPageParam(), new([]vo.MachineScriptVO))
res, err := m.machineScriptApp.GetPageList(condition, rc.GetPageParam())
biz.ErrIsNil(err)
rc.ResData = res
rc.ResData = model.PageResultConv[*entity.MachineScript, *vo.MachineScriptVO](res)
}
func (m *MachineScript) SaveMachineScript(rc *req.Ctx) {

View File

@@ -35,7 +35,7 @@ type Machine interface {
Delete(ctx context.Context, id uint64) error
// 分页获取机器信息列表
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
GetMachineList(condition *entity.MachineQuery, orderBy ...string) (*model.PageResult[*entity.Machine], error)
// 新建机器客户端连接需手动调用Close
NewCli(authCertName string) (*mcm.Cli, error)
@@ -71,8 +71,8 @@ type machineAppImpl struct {
var _ (Machine) = (*machineAppImpl)(nil)
// 分页获取机器信息列表
func (m *machineAppImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return m.GetRepo().GetMachineList(condition, pageParam, toEntity, orderBy...)
func (m *machineAppImpl) GetMachineList(condition *entity.MachineQuery, orderBy ...string) (*model.PageResult[*entity.Machine], error) {
return m.GetRepo().GetMachineList(condition, orderBy...)
}
func (m *machineAppImpl) SaveMachine(ctx context.Context, param *dto.SaveMachine) error {

View File

@@ -22,10 +22,10 @@ type MachineCronJob interface {
base.App[*entity.MachineCronJob]
// 分页获取机器任务列表信息
GetPageList(condition *entity.MachineCronJob, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
GetPageList(condition *entity.MachineCronJob, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineCronJob], error)
// 获取分页执行结果列表
GetExecPageList(condition *entity.MachineCronJobExec, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
GetExecPageList(condition *entity.MachineCronJobExec, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineCronJobExec], error)
SaveMachineCronJob(ctx context.Context, param *dto.SaveMachineCronJob) error
@@ -52,13 +52,13 @@ type machineCronJobAppImpl struct {
var _ (MachineCronJob) = (*machineCronJobAppImpl)(nil)
// 分页获取机器脚本任务列表
func (m *machineCronJobAppImpl) GetPageList(condition *entity.MachineCronJob, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return m.GetRepo().GetPageList(condition, pageParam, toEntity, orderBy...)
func (m *machineCronJobAppImpl) GetPageList(condition *entity.MachineCronJob, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineCronJob], error) {
return m.GetRepo().GetPageList(condition, pageParam, orderBy...)
}
// 获取分页执行结果列表
func (m *machineCronJobAppImpl) GetExecPageList(condition *entity.MachineCronJobExec, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return m.machineCronJobExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
func (m *machineCronJobAppImpl) GetExecPageList(condition *entity.MachineCronJobExec, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineCronJobExec], error) {
return m.machineCronJobExecRepo.GetPageList(condition, pageParam, orderBy...)
}
// 保存机器任务信息
@@ -101,14 +101,14 @@ func (m *machineCronJobAppImpl) InitCronJob() {
}
}()
pageParam := &model.PageParam{
pageParam := model.PageParam{
PageSize: 100,
PageNum: 1,
}
var mcjs []*entity.MachineCronJob
cond := &entity.MachineCronJob{Status: entity.MachineCronJobStatusEnable}
pr, _ := m.GetPageList(cond, pageParam, &mcjs)
pr, _ := m.GetPageList(cond, pageParam)
total := pr.Total
add := 0
@@ -122,7 +122,7 @@ func (m *machineCronJobAppImpl) InitCronJob() {
}
pageParam.PageNum = pageParam.PageNum + 1
m.GetPageList(cond, pageParam, mcjs)
m.GetPageList(cond, pageParam)
}
}

View File

@@ -30,7 +30,7 @@ type MachineFile interface {
base.App[*entity.MachineFile]
// 分页获取机器文件信息列表
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
GetPageList(condition *entity.MachineFile, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineFile], error)
// 根据条件获取
GetMachineFile(condition *entity.MachineFile, cols ...string) error
@@ -91,9 +91,9 @@ func (m *machineFileAppImpl) InjectMachineFileRepo(repo repository.MachineFile)
m.Repo = repo
}
// 分页获取机器脚本信息列表
func (m *machineFileAppImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return m.GetRepo().GetPageList(condition, pageParam, toEntity, orderBy...)
// 分页获取机器文件配置信息列表
func (m *machineFileAppImpl) GetPageList(condition *entity.MachineFile, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineFile], error) {
return m.GetRepo().GetPageList(condition, pageParam, orderBy...)
}
// 根据条件获取

View File

@@ -13,7 +13,7 @@ type MachineScript interface {
base.App[*entity.MachineScript]
// 分页获取机器脚本信息列表
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
GetPageList(condition *entity.MachineScript, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineScript], error)
Save(ctx context.Context, entity *entity.MachineScript) error
@@ -29,8 +29,8 @@ type machineScriptAppImpl struct {
const Common_Script_Machine_Id = 9999999
// 分页获取机器脚本信息列表
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return m.GetRepo().GetPageList(condition, pageParam, toEntity, orderBy...)
func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineScript], error) {
return m.GetRepo().GetPageList(condition, pageParam, orderBy...)
}
// 保存机器脚本

View File

@@ -29,7 +29,7 @@ type MachineTermOp interface {
// 终端连接操作
TermConn(ctx context.Context, cli *mcm.Cli, wsConn *websocket.Conn, rows, cols int) error
GetPageList(condition *entity.MachineTermOp, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
GetPageList(condition *entity.MachineTermOp, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineTermOp], error)
// 定时删除终端文件回放记录
TimerDeleteTermOp()
@@ -110,8 +110,8 @@ func (m *machineTermOpAppImpl) TermConn(ctx context.Context, cli *mcm.Cli, wsCon
return nil
}
func (m *machineTermOpAppImpl) GetPageList(condition *entity.MachineTermOp, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return m.GetRepo().GetPageList(condition, pageParam, toEntity)
func (m *machineTermOpAppImpl) GetPageList(condition *entity.MachineTermOp, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineTermOp], error) {
return m.GetRepo().GetPageList(condition, pageParam)
}
func (m *machineTermOpAppImpl) TimerDeleteTermOp() {

View File

@@ -1,8 +1,13 @@
package entity
import "time"
import (
"mayfly-go/pkg/model"
"time"
)
type MachineQuery struct {
model.PageParam
Id uint64 `json:"id" form:"id"`
Code string `json:"code" form:"code"`
Name string `json:"name" form:"name"`

View File

@@ -10,5 +10,5 @@ type Machine interface {
base.Repo[*entity.Machine]
// 分页获取机器信息列表
GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
GetMachineList(condition *entity.MachineQuery, orderBy ...string) (*model.PageResult[*entity.Machine], error)
}

View File

@@ -9,11 +9,11 @@ import (
type MachineCronJob interface {
base.Repo[*entity.MachineCronJob]
GetPageList(condition *entity.MachineCronJob, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
GetPageList(condition *entity.MachineCronJob, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineCronJob], error)
}
type MachineCronJobExec interface {
base.Repo[*entity.MachineCronJobExec]
GetPageList(condition *entity.MachineCronJobExec, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
GetPageList(condition *entity.MachineCronJobExec, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineCronJobExec], error)
}

View File

@@ -10,5 +10,5 @@ type MachineFile interface {
base.Repo[*entity.MachineFile]
// 分页获取机器脚本信息列表
GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
GetPageList(condition *entity.MachineFile, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineFile], error)
}

View File

@@ -10,5 +10,5 @@ type MachineScript interface {
base.Repo[*entity.MachineScript]
// 分页获取机器脚本信息列表
GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
GetPageList(condition *entity.MachineScript, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineScript], error)
}

View File

@@ -10,7 +10,7 @@ type MachineTermOp interface {
base.Repo[*entity.MachineTermOp]
// 分页获取机器终端执行记录列表
GetPageList(condition *entity.MachineTermOp, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
GetPageList(condition *entity.MachineTermOp, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineTermOp], error)
// 根据条件获取记录列表
SelectByQuery(cond *entity.MachineTermOpQuery) ([]*entity.MachineTermOp, error)

View File

@@ -16,7 +16,7 @@ func newMachineRepo() repository.Machine {
}
// 分页获取机器信息列表
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, orderBy ...string) (*model.PageResult[*entity.Machine], error) {
qd := model.NewCond().
Eq("id", condition.Id).
Eq("status", condition.Status).
@@ -32,5 +32,5 @@ func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pagePar
qd.And("ip like ? or name like ? or code like ?", keyword, keyword, keyword)
}
return m.PageByCondToAny(qd, pageParam, toEntity)
return m.PageByCond(qd, condition.PageParam)
}

View File

@@ -16,7 +16,7 @@ func newMachineCronJobRepo() repository.MachineCronJob {
}
// 分页获取机器信息列表
func (m *machineCronJobRepoImpl) GetPageList(condition *entity.MachineCronJob, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
func (m *machineCronJobRepoImpl) GetPageList(condition *entity.MachineCronJob, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineCronJob], error) {
qd := model.NewCond().Like("name", condition.Name).Eq("status", condition.Status).OrderBy(orderBy...)
return m.PageByCondToAny(qd, pageParam, toEntity)
return m.PageByCond(qd, pageParam)
}

View File

@@ -16,7 +16,7 @@ func newMachineCronJobExecRepo() repository.MachineCronJobExec {
}
// 分页获取机器信息列表
func (m *machineCropJobExecRepoImpl) GetPageList(condition *entity.MachineCronJobExec, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
func (m *machineCropJobExecRepoImpl) GetPageList(condition *entity.MachineCronJobExec, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineCronJobExec], error) {
qd := model.NewModelCond(condition).OrderBy(orderBy...)
return m.PageByCondToAny(qd, pageParam, toEntity)
return m.PageByCond(qd, pageParam)
}

View File

@@ -16,7 +16,7 @@ func newMachineFileRepo() repository.MachineFile {
}
// 分页获取机器文件信息列表
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineFile], error) {
qd := model.NewModelCond(condition).OrderBy(orderBy...)
return m.PageByCondToAny(qd, pageParam, toEntity)
return m.PageByCond(qd, pageParam)
}

View File

@@ -16,7 +16,7 @@ func newMachineScriptRepo() repository.MachineScript {
}
// 分页获取机器信息列表
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineScript], error) {
qd := model.NewModelCond(condition).OrderBy(orderBy...)
return m.PageByCondToAny(qd, pageParam, toEntity)
return m.PageByCond(qd, pageParam)
}

View File

@@ -15,9 +15,9 @@ func newMachineTermOpRepoImpl() repository.MachineTermOp {
return &machineTermOpRepoImpl{}
}
func (m *machineTermOpRepoImpl) GetPageList(condition *entity.MachineTermOp, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
func (m *machineTermOpRepoImpl) GetPageList(condition *entity.MachineTermOp, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineTermOp], error) {
pd := model.NewModelCond(condition).OrderBy(orderBy...)
return m.PageByCondToAny(pd, pageParam, toEntity)
return m.PageByCond(pd, pageParam)
}
// 根据条件获取记录列表