mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 07:50:25 +08:00
feat: 机器脚本新增分配、组件属性类型不匹配警告调整
This commit is contained in:
@@ -68,7 +68,7 @@ func (d *dbAppImpl) GetPageList(condition *entity.DbQuery, orderBy ...string) (*
|
||||
|
||||
func (d *dbAppImpl) SaveDb(ctx context.Context, dbEntity *entity.Db) error {
|
||||
// 查找是否存在
|
||||
oldDb := &entity.Db{Name: dbEntity.Name, InstanceId: dbEntity.InstanceId}
|
||||
oldDb := &entity.Db{Name: dbEntity.Name, InstanceId: dbEntity.InstanceId, AuthCertName: dbEntity.AuthCertName}
|
||||
|
||||
authCert, err := d.resourceAuthCertApp.GetAuthCert(dbEntity.AuthCertName)
|
||||
if err != nil {
|
||||
|
||||
@@ -32,6 +32,7 @@ type MachineScriptForm struct {
|
||||
Name string `json:"name" binding:"required"`
|
||||
MachineId uint64 `json:"machineId" binding:"required"`
|
||||
Type int `json:"type" binding:"required"`
|
||||
Category string `json:"category"`
|
||||
Description string `json:"description" binding:"required"`
|
||||
Params string `json:"params"`
|
||||
Script string `json:"script" binding:"required"`
|
||||
|
||||
@@ -28,6 +28,8 @@ func (ms *MachineScript) ReqConfs() *req.Confs {
|
||||
// 获取指定机器脚本列表
|
||||
req.NewGet(":machineId/scripts", ms.MachineScripts),
|
||||
|
||||
req.NewGet("/scripts/categorys", ms.MachineScriptCategorys),
|
||||
|
||||
req.NewPost(":machineId/scripts", ms.SaveMachineScript).Log(req.NewLogSave("机器-保存脚本")).RequiredPermissionCode("machine:script:save"),
|
||||
|
||||
req.NewDelete(":machineId/scripts/:scriptId", ms.DeleteMachineScript).Log(req.NewLogSave("机器-删除脚本")).RequiredPermissionCode("machine:script:del"),
|
||||
@@ -39,12 +41,18 @@ func (ms *MachineScript) ReqConfs() *req.Confs {
|
||||
}
|
||||
|
||||
func (m *MachineScript) MachineScripts(rc *req.Ctx) {
|
||||
condition := &entity.MachineScript{MachineId: GetMachineId(rc)}
|
||||
condition := &entity.MachineScript{MachineId: GetMachineId(rc), Category: rc.Query("category")}
|
||||
res, err := m.machineScriptApp.GetPageList(condition, rc.GetPageParam())
|
||||
biz.ErrIsNil(err)
|
||||
rc.ResData = model.PageResultConv[*entity.MachineScript, *vo.MachineScriptVO](res)
|
||||
}
|
||||
|
||||
func (m *MachineScript) MachineScriptCategorys(rc *req.Ctx) {
|
||||
res, err := m.machineScriptApp.GetScriptCategorys(rc.MetaCtx)
|
||||
biz.ErrIsNil(err)
|
||||
rc.ResData = res
|
||||
}
|
||||
|
||||
func (m *MachineScript) SaveMachineScript(rc *req.Ctx) {
|
||||
form, machineScript := req.BindJsonAndCopyTo[*form.MachineScriptForm, *entity.MachineScript](rc)
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ type MachineScriptVO struct {
|
||||
Name *string `json:"name"`
|
||||
Script *string `json:"script"`
|
||||
Type *int `json:"type"`
|
||||
Category string `json:"category"`
|
||||
Description *string `json:"description"`
|
||||
Params *string `json:"params"`
|
||||
MachineId *uint64 `json:"machineId"`
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/errorx"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
)
|
||||
|
||||
type MachineScript interface {
|
||||
@@ -15,11 +16,16 @@ type MachineScript interface {
|
||||
// 分页获取机器脚本信息列表
|
||||
GetPageList(condition *entity.MachineScript, pageParam model.PageParam, orderBy ...string) (*model.PageResult[*entity.MachineScript], error)
|
||||
|
||||
// GetScriptCategorys 获取脚本分类
|
||||
GetScriptCategorys(ctx context.Context) ([]string, error)
|
||||
|
||||
Save(ctx context.Context, entity *entity.MachineScript) error
|
||||
|
||||
Delete(ctx context.Context, id uint64)
|
||||
}
|
||||
|
||||
var _ (MachineScript) = (*machineScriptAppImpl)(nil)
|
||||
|
||||
type machineScriptAppImpl struct {
|
||||
base.AppImpl[*entity.MachineScript, repository.MachineScript]
|
||||
|
||||
@@ -33,6 +39,15 @@ func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, page
|
||||
return m.GetRepo().GetPageList(condition, pageParam, orderBy...)
|
||||
}
|
||||
|
||||
func (m *machineScriptAppImpl) GetScriptCategorys(ctx context.Context) ([]string, error) {
|
||||
scripts, err := m.ListByCond(new(entity.MachineScript), "category")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return collx.ArrayRemoveBlank(collx.ArrayDeduplicate(collx.ArrayMap(scripts, func(script *entity.MachineScript) string { return script.Category }))), nil
|
||||
}
|
||||
|
||||
// 保存机器脚本
|
||||
func (m *machineScriptAppImpl) Save(ctx context.Context, ms *entity.MachineScript) error {
|
||||
// 如果机器id不为公共脚本id,则校验机器是否存在
|
||||
|
||||
@@ -8,7 +8,8 @@ type MachineScript struct {
|
||||
Name string `json:"name" gorm:"not null;size:255;comment:脚本名"` // 脚本名
|
||||
MachineId uint64 `json:"machineId" gorm:"not null;comment:机器id[0:公共]"` // 机器id
|
||||
Type int `json:"type" gorm:"comment:脚本类型[1: 有结果;2:无结果;3:实时交互]"` // 脚本类型[1: 有结果;2:无结果;3:实时交互]
|
||||
Description string `json:"description" gorm:"size:255;comment:脚本描述"` // 脚本描述
|
||||
Params string `json:"params" gorm:"size:500;comment:脚本入参"` // 参数列表json
|
||||
Script string `json:"script" gorm:"type:text;comment:脚本内容"` // 脚本内容
|
||||
Category string `json:"category" gorm:"size:20;comment:分类"`
|
||||
Description string `json:"description" gorm:"size:255;comment:脚本描述"` // 脚本描述
|
||||
Params string `json:"params" gorm:"size:500;comment:脚本入参"` // 参数列表json
|
||||
Script string `json:"script" gorm:"type:text;comment:脚本内容"` // 脚本内容
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import "fmt"
|
||||
|
||||
const (
|
||||
AppName = "mayfly-go"
|
||||
Version = "v1.10.0"
|
||||
Version = "v1.10.1"
|
||||
)
|
||||
|
||||
func GetAppInfo() string {
|
||||
|
||||
@@ -3,6 +3,7 @@ package migrations
|
||||
import (
|
||||
esentity "mayfly-go/internal/es/domain/entity"
|
||||
flowentity "mayfly-go/internal/flow/domain/entity"
|
||||
machineentity "mayfly-go/internal/machine/domain/entity"
|
||||
sysentity "mayfly-go/internal/sys/domain/entity"
|
||||
"mayfly-go/pkg/model"
|
||||
"time"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
func V1_10() []*gormigrate.Migration {
|
||||
var migrations []*gormigrate.Migration
|
||||
migrations = append(migrations, V1_10_0()...)
|
||||
migrations = append(migrations, V1_10_1()...)
|
||||
return migrations
|
||||
}
|
||||
|
||||
@@ -132,3 +134,22 @@ func V1_10_0() []*gormigrate.Migration {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func V1_10_1() []*gormigrate.Migration {
|
||||
return []*gormigrate.Migration{
|
||||
{
|
||||
ID: "20250610-v1.10.1",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
if !tx.Migrator().HasColumn(&machineentity.MachineScript{}, "category") {
|
||||
if err := tx.Migrator().AddColumn(&machineentity.MachineScript{}, "category"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user