reafctor: 团队管理与授权凭证优化

This commit is contained in:
meilin.huang
2024-04-10 13:04:31 +08:00
parent 21498584b1
commit 40b6e603fc
43 changed files with 981 additions and 937 deletions

View File

@@ -1,59 +0,0 @@
package api
import (
"mayfly-go/internal/machine/api/form"
"mayfly-go/internal/machine/api/vo"
"mayfly-go/internal/machine/application"
"mayfly-go/internal/machine/domain/entity"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/req"
"strconv"
"strings"
)
type AuthCert struct {
AuthCertApp application.AuthCert `inject:""`
}
func (ac *AuthCert) BaseAuthCerts(rc *req.Ctx) {
queryCond, page := req.BindQueryAndPage(rc, new(entity.AuthCertQuery))
res, err := ac.AuthCertApp.GetPageList(queryCond, page, new([]vo.AuthCertBaseVO))
biz.ErrIsNil(err)
rc.ResData = res
}
func (ac *AuthCert) AuthCerts(rc *req.Ctx) {
queryCond, page := req.BindQueryAndPage(rc, new(entity.AuthCertQuery))
res := new([]*entity.AuthCert)
pageRes, err := ac.AuthCertApp.GetPageList(queryCond, page, res)
biz.ErrIsNil(err)
for _, r := range *res {
r.PwdDecrypt()
}
rc.ResData = pageRes
}
func (c *AuthCert) SaveAuthCert(rc *req.Ctx) {
acForm := &form.AuthCertForm{}
ac := req.BindJsonAndCopyTo(rc, acForm, new(entity.AuthCert))
// 脱敏记录日志
acForm.Passphrase = "***"
acForm.Password = "***"
rc.ReqParam = acForm
biz.ErrIsNil(c.AuthCertApp.Save(rc.MetaCtx, ac))
}
func (c *AuthCert) Delete(rc *req.Ctx) {
idsStr := rc.PathParam("id")
rc.ReqParam = idsStr
ids := strings.Split(idsStr, ",")
for _, v := range ids {
value, err := strconv.Atoi(v)
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
c.AuthCertApp.DeleteById(rc.MetaCtx, uint64(value))
}
}

View File

@@ -33,17 +33,6 @@ type MachineScriptForm struct {
Script string `json:"script" binding:"required"`
}
// 授权凭证
type AuthCertForm struct {
Id uint64 `json:"id"`
Name string `json:"name" binding:"required"`
AuthMethod int8 `json:"authMethod" binding:"required"` // 1.密码 2.秘钥
Username string `json:"username"`
Password string `json:"password"` // 密码or私钥
Passphrase string `json:"passphrase"` // 私钥口令
Remark string `json:"remark"`
}
// 机器记录任务
type MachineCronJobForm struct {
Id uint64 `json:"id"`

View File

@@ -50,10 +50,9 @@ func (m *MachineScript) DeleteMachineScript(rc *req.Ctx) {
func (m *MachineScript) RunMachineScript(rc *req.Ctx) {
scriptId := GetMachineScriptId(rc)
machineId := GetMachineId(rc)
ac := GetMachineAc(rc)
ms, err := m.MachineScriptApp.GetById(new(entity.MachineScript), scriptId, "MachineId", "Name", "Script")
biz.ErrIsNil(err, "该脚本不存在")
biz.IsTrue(ms.MachineId == application.Common_Script_Machine_Id || ms.MachineId == machineId, "该脚本不属于该机器")
script := ms.Script
// 如果有脚本参数,则用脚本参数替换脚本中的模板占位符参数
@@ -61,7 +60,7 @@ func (m *MachineScript) RunMachineScript(rc *req.Ctx) {
script, err = stringx.TemplateParse(ms.Script, jsonx.ToMap(params))
biz.ErrIsNilAppendErr(err, "脚本模板参数解析失败: %s")
}
cli, err := m.MachineApp.GetCli(machineId)
cli, err := m.MachineApp.GetCliByAc(ac)
biz.ErrIsNilAppendErr(err, "获取客户端连接失败: %s")
biz.ErrIsNilAppendErr(m.TagApp.CanAccess(rc.GetLoginAccount().Id, cli.Info.TagPath...), "%s")

View File

@@ -5,13 +5,6 @@ import (
"time"
)
// 授权凭证基础信息
type AuthCertBaseVO struct {
Id int `json:"id"`
Name string `json:"name"`
AuthMethod int8 `json:"authMethod"`
}
type MachineVO struct {
tagentity.ResourceTags // 标签信息
tagentity.AuthCerts // 授权凭证信息

View File

@@ -8,7 +8,6 @@ func InitIoc() {
ioc.Register(new(machineAppImpl), ioc.WithComponentName("MachineApp"))
ioc.Register(new(machineFileAppImpl), ioc.WithComponentName("MachineFileApp"))
ioc.Register(new(machineScriptAppImpl), ioc.WithComponentName("MachineScriptApp"))
ioc.Register(new(authCertAppImpl), ioc.WithComponentName("AuthCertApp"))
ioc.Register(new(machineCronJobAppImpl), ioc.WithComponentName("MachineCronJobApp"))
ioc.Register(new(machineTermOpAppImpl), ioc.WithComponentName("MachineTermOpApp"))
}

View File

@@ -1,58 +0,0 @@
package application
import (
"context"
"mayfly-go/internal/machine/domain/entity"
"mayfly-go/internal/machine/domain/repository"
"mayfly-go/pkg/base"
"mayfly-go/pkg/errorx"
"mayfly-go/pkg/model"
)
type AuthCert interface {
base.App[*entity.AuthCert]
GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
Save(ctx context.Context, ac *entity.AuthCert) error
GetByIds(ids ...uint64) []*entity.AuthCert
}
type authCertAppImpl struct {
base.AppImpl[*entity.AuthCert, repository.AuthCert]
}
// 注入AuthCertRepo
func (a *authCertAppImpl) InjectAuthCertRepo(repo repository.AuthCert) {
a.Repo = repo
}
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return a.GetRepo().GetPageList(condition, pageParam, toEntity)
}
func (a *authCertAppImpl) Save(ctx context.Context, ac *entity.AuthCert) error {
oldAc := &entity.AuthCert{Name: ac.Name}
err := a.GetBy(oldAc, "Id", "Name")
ac.PwdEncrypt()
if ac.Id == 0 {
if err == nil {
return errorx.NewBiz("该凭证名已存在")
}
return a.Insert(ctx, ac)
}
// 如果存在该库,则校验修改的库是否为该库
if err == nil && oldAc.Id != ac.Id {
return errorx.NewBiz("该凭证名已存在")
}
return a.UpdateById(ctx, ac)
}
func (a *authCertAppImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
acs := new([]*entity.AuthCert)
a.GetByIdIn(acs, ids)
return *acs
}

View File

@@ -18,8 +18,6 @@ import (
"mayfly-go/pkg/model"
"mayfly-go/pkg/scheduler"
"time"
"github.com/may-fly/cast"
)
type SaveMachineParam struct {
@@ -164,6 +162,15 @@ func (m *machineAppImpl) SaveMachine(ctx context.Context, param *SaveMachinePara
func (m *machineAppImpl) TestConn(me *entity.Machine, authCert *tagentity.ResourceAuthCert) error {
me.Id = 0
if authCert.CiphertextType == tagentity.AuthCertCiphertextTypePublic {
publicAuthCert, err := m.resourceAuthCertApp.GetAuthCert(authCert.Ciphertext)
if err != nil {
return err
}
authCert = publicAuthCert
}
mi, err := m.toMi(me, authCert)
if err != nil {
return err
@@ -338,7 +345,7 @@ func (m *machineAppImpl) toMi(me *entity.Machine, authCert *tagentity.ResourceAu
mi.Username = authCert.Username
mi.Password = authCert.Ciphertext
mi.Passphrase = cast.ToString(authCert.Extra["passphrase"])
mi.Passphrase = authCert.GetExtraString(tagentity.ExtraKeyPassphrase)
mi.AuthMethod = int8(authCert.CiphertextType)
// 使用了ssh隧道则将隧道机器信息也附上

View File

@@ -1,60 +0,0 @@
package entity
import (
"errors"
"mayfly-go/internal/common/utils"
"mayfly-go/pkg/model"
)
// 授权凭证
type AuthCert struct {
model.Model
Name string `json:"name"`
AuthMethod int8 `json:"authMethod"` // 1.密码 2.秘钥
Password string `json:"password" gorm:"column:password;type:varchar(4200)"` // 密码or私钥
Passphrase string `json:"passphrase"` // 私钥口令
Remark string `json:"remark"`
}
func (ac *AuthCert) TableName() string {
return "t_auth_cert"
}
const (
AuthCertAuthMethodPassword int8 = 1 // 密码
MachineAuthMethodPublicKey int8 = 2 // 密钥
AuthCertTypePrivate int8 = 1
AuthCertTypePublic int8 = 2
)
// PwdEncrypt 密码加密
func (ac *AuthCert) PwdEncrypt() error {
password, err := utils.PwdAesEncrypt(ac.Password)
if err != nil {
return errors.New("加密授权凭证密码失败")
}
passphrase, err := utils.PwdAesEncrypt(ac.Passphrase)
if err != nil {
return errors.New("加密授权凭证私钥失败")
}
ac.Password = password
ac.Passphrase = passphrase
return nil
}
// PwdDecrypt 密码解密
func (ac *AuthCert) PwdDecrypt() error {
password, err := utils.PwdAesDecrypt(ac.Password)
if err != nil {
return errors.New("解密授权凭证密码失败")
}
passphrase, err := utils.PwdAesDecrypt(ac.Passphrase)
if err != nil {
return errors.New("解密授权凭证私钥失败")
}
ac.Password = password
ac.Passphrase = passphrase
return nil
}

View File

@@ -1,15 +0,0 @@
package repository
import (
"mayfly-go/internal/machine/domain/entity"
"mayfly-go/pkg/base"
"mayfly-go/pkg/model"
)
type AuthCert interface {
base.Repo[*entity.AuthCert]
GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
// GetByIds(ids ...uint64) []*entity.AuthCert
}

View File

@@ -1,28 +0,0 @@
package persistence
import (
"mayfly-go/internal/machine/domain/entity"
"mayfly-go/internal/machine/domain/repository"
"mayfly-go/pkg/base"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/model"
)
type authCertRepoImpl struct {
base.RepoImpl[*entity.AuthCert]
}
func newAuthCertRepo() repository.AuthCert {
return &authCertRepoImpl{base.RepoImpl[*entity.AuthCert]{M: new(entity.AuthCert)}}
}
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
qd := gormx.NewQuery(new(entity.AuthCert)).WithCondModel(condition).WithOrderBy(orderBy...)
return gormx.PageQuery(qd, pageParam, toEntity)
}
// func (m *authCertRepoImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
// acs := new([]*entity.AuthCert)
// gormx.GetByIdIn(new(entity.AuthCert), acs, ids)
// return *acs
// }

View File

@@ -8,7 +8,6 @@ func InitIoc() {
ioc.Register(newMachineRepo(), ioc.WithComponentName("MachineRepo"))
ioc.Register(newMachineFileRepo(), ioc.WithComponentName("MachineFileRepo"))
ioc.Register(newMachineScriptRepo(), ioc.WithComponentName("MachineScriptRepo"))
ioc.Register(newAuthCertRepo(), ioc.WithComponentName("AuthCertRepo"))
ioc.Register(newMachineCronJobRepo(), ioc.WithComponentName("MachineCronJobRepo"))
ioc.Register(newMachineCronJobExecRepo(), ioc.WithComponentName("MachineCronJobExecRepo"))
ioc.Register(newMachineCronJobRelateRepo(), ioc.WithComponentName("MachineCronJobRelateRepo"))

View File

@@ -1,30 +0,0 @@
package router
import (
"mayfly-go/internal/machine/api"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/ioc"
"mayfly-go/pkg/req"
"github.com/gin-gonic/gin"
)
func InitAuthCertRouter(router *gin.RouterGroup) {
ag := router.Group("sys/authcerts")
r := new(api.AuthCert)
biz.ErrIsNil(ioc.Inject(r))
reqs := [...]*req.Conf{
req.NewGet("", r.AuthCerts).RequiredPermissionCode("authcert"),
// 基础授权凭证信息,不包含密码等
req.NewGet("base", r.BaseAuthCerts),
req.NewPost("", r.SaveAuthCert).Log(req.NewLogSave("保存授权凭证")).RequiredPermissionCode("authcert:save"),
req.NewDelete(":id", r.Delete).Log(req.NewLogSave("删除授权凭证")).RequiredPermissionCode("authcert:del"),
}
req.BatchSetGroup(ag, reqs[:])
}

View File

@@ -23,7 +23,7 @@ func InitMachineScriptRouter(router *gin.RouterGroup) {
req.NewDelete(":machineId/scripts/:scriptId", ms.DeleteMachineScript).Log(req.NewLogSave("机器-删除脚本")).RequiredPermissionCode("machine:script:del"),
req.NewGet(":machineId/scripts/:scriptId/run", ms.RunMachineScript).Log(req.NewLogSave("机器-执行脚本")).RequiredPermissionCode("machine:script:run"),
req.NewGet("scripts/:scriptId/:ac/run", ms.RunMachineScript).Log(req.NewLogSave("机器-执行脚本")).RequiredPermissionCode("machine:script:run"),
}
req.BatchSetGroup(machines, reqs[:])

View File

@@ -6,6 +6,5 @@ func Init(router *gin.RouterGroup) {
InitMachineRouter(router)
InitMachineFileRouter(router)
InitMachineScriptRouter(router)
InitAuthCertRouter(router)
InitMachineCronJobRouter(router)
}

View File

@@ -0,0 +1,20 @@
package form
import (
"mayfly-go/internal/tag/domain/entity"
"mayfly-go/pkg/model"
)
// 授权凭证
type AuthCertForm struct {
Id uint64 `json:"id"`
Name string `json:"name" binding:"required"` // 名称
ResourceCode string `json:"resourceCode"` // 资源编号
ResourceType int8 `json:"resourceType"` // 资源类型
Username string `json:"username"` // 用户名
Ciphertext string `json:"ciphertext"` // 密文
CiphertextType entity.AuthCertCiphertextType `json:"ciphertextType" binding:"required"` // 密文类型
Extra model.Map[string, any] `json:"extra"` // 账号需要的其他额外信息(如秘钥口令等)
Type entity.AuthCertType `json:"type" binding:"required"` // 凭证类型
Remark string `json:"remark"` // 备注
}

View File

@@ -1,6 +0,0 @@
package form
type TagTreeTeam struct {
TeamId uint64 `json:"teamId"`
TagIds []uint64 `json:"tagIds"`
}

View File

@@ -1,6 +1,6 @@
package form
type TeamMember struct {
TeamId uint64 `json:"teamId"`
TeamId uint64 `json:"teamId" binding:"required"`
AccountIds []uint64 `json:"accountIds"`
}

View File

@@ -1,10 +1,15 @@
package api
import (
"mayfly-go/internal/tag/api/form"
"mayfly-go/internal/tag/application"
"mayfly-go/internal/tag/domain/entity"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils/collx"
"strings"
"github.com/may-fly/cast"
)
type ResourceAuthCert struct {
@@ -23,7 +28,48 @@ func (r *ResourceAuthCert) ListByQuery(rc *req.Ctx) {
res, err := r.ResourceAuthCertApp.PageQuery(cond, rc.GetPageParam(), &racs)
biz.ErrIsNil(err)
for _, rac := range racs {
rac.CiphertextDecrypt()
rac.CiphertextClear()
}
rc.ResData = res
}
func (r *ResourceAuthCert) GetCompleteAuthCert(rc *req.Ctx) {
acName := rc.Query("name")
biz.NotEmpty(acName, "授权凭证名不能为空")
res := &entity.ResourceAuthCert{Name: acName}
err := r.ResourceAuthCertApp.GetBy(res)
biz.ErrIsNil(err)
res.CiphertextDecrypt()
rc.ResData = res
}
func (c *ResourceAuthCert) SaveAuthCert(rc *req.Ctx) {
acForm := &form.AuthCertForm{}
ac := req.BindJsonAndCopyTo(rc, acForm, new(entity.ResourceAuthCert))
// 脱敏记录日志
acForm.Ciphertext = "***"
rc.ReqParam = acForm
biz.ErrIsNil(c.ResourceAuthCertApp.SavePulbicAuthCert(rc.MetaCtx, ac))
}
func (c *ResourceAuthCert) Delete(rc *req.Ctx) {
idsStr := rc.PathParam("id")
ids := strings.Split(idsStr, ",")
acIds := make([]uint64, 0)
acNames := make([]string, 0)
for _, v := range ids {
id := cast.ToUint64(v)
rac, err := c.ResourceAuthCertApp.GetById(new(entity.ResourceAuthCert), id)
biz.ErrIsNil(err, "存在错误授权凭证id")
biz.IsTrue(rac.Type == entity.AuthCertTypePublic, "只允许删除公共授权凭证")
biz.IsTrue(c.ResourceAuthCertApp.CountByCond(&entity.ResourceAuthCert{Ciphertext: rac.Name}) == 0, "[%s]该授权凭证已被关联", rac.Name)
acIds = append(acIds, id)
acNames = append(acNames, rac.Name)
}
rc.ReqParam = acNames
biz.ErrIsNil(c.ResourceAuthCertApp.DeleteByWheres(rc.MetaCtx, collx.M{"id in ?": acIds}))
}

View File

@@ -10,9 +10,9 @@ import (
"mayfly-go/internal/tag/domain/entity"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/req"
"mayfly-go/pkg/utils/collx"
"strconv"
"strings"
"github.com/may-fly/cast"
)
type Team struct {
@@ -30,22 +30,9 @@ func (p *Team) GetTeams(rc *req.Ctx) {
}
func (p *Team) SaveTeam(rc *req.Ctx) {
team := req.BindJsonAndValid(rc, new(entity.Team))
team := req.BindJsonAndValid(rc, new(application.SaveTeamParam))
rc.ReqParam = team
isAdd := team.Id == 0
loginAccount := rc.GetLoginAccount()
p.TeamApp.Save(rc.MetaCtx, team)
// 如果是新增团队则默认将自己加入该团队
if isAdd {
teamMem := &entity.TeamMember{}
teamMem.AccountId = loginAccount.Id
teamMem.Username = loginAccount.Username
teamMem.TeamId = team.Id
p.TeamApp.SaveMember(rc.MetaCtx, teamMem)
}
biz.ErrIsNil(p.TeamApp.Save(rc.MetaCtx, team))
}
func (p *Team) DelTeam(rc *req.Ctx) {
@@ -54,9 +41,7 @@ func (p *Team) DelTeam(rc *req.Ctx) {
ids := strings.Split(idsStr, ",")
for _, v := range ids {
value, err := strconv.Atoi(v)
biz.ErrIsNilAppendErr(err, "string类型转换为int异常: %s")
p.TeamApp.Delete(rc.MetaCtx, uint64(value))
p.TeamApp.Delete(rc.MetaCtx, cast.ToUint64(v))
}
}
@@ -109,28 +94,3 @@ func (p *Team) DelTeamMember(rc *req.Ctx) {
func (p *Team) GetTagIds(rc *req.Ctx) {
rc.ResData = p.TeamApp.ListTagIds(uint64(rc.PathParamInt("id")))
}
// 保存团队关联标签信息
func (p *Team) SaveTags(rc *req.Ctx) {
form := req.BindJsonAndValid(rc, new(form.TagTreeTeam))
teamId := form.TeamId
// 将[]uint64转为[]any
oIds := p.TeamApp.ListTagIds(teamId)
// 比较新旧两合集
addIds, delIds, _ := collx.ArrayCompare(form.TagIds, oIds)
for _, v := range addIds {
tagId := v
tag, err := p.TagTreeApp.GetById(new(entity.TagTree), tagId)
biz.ErrIsNil(err, "存在非法标签id")
ptt := &entity.TagTreeTeam{TeamId: teamId, TagId: tagId, TagPath: tag.CodePath}
p.TeamApp.SaveTag(rc.MetaCtx, ptt)
}
for _, v := range delIds {
p.TeamApp.DeleteTag(rc.MetaCtx, teamId, v)
}
rc.ReqParam = form
}

View File

@@ -20,3 +20,16 @@ type ResourceAuthCert struct {
CreateTime *time.Time `json:"createTime"`
}
// 授权凭证基础信息
type AuthCertBaseVO struct {
Id int `json:"id"`
Name string `json:"name"` // 名称(全局唯一)
ResourceCode string `json:"resourceCode"` // 资源编号
ResourceType int8 `json:"resourceType"` // 资源类型
Type entity.AuthCertType `json:"type"` // 凭证类型
Username string `json:"username"` // 用户名
CiphertextType entity.AuthCertCiphertextType `json:"ciphertextType"` // 密文类型
Remark string `json:"remark"` // 备注
}

View File

@@ -6,6 +6,7 @@ import (
"mayfly-go/internal/tag/domain/repository"
"mayfly-go/pkg/base"
"mayfly-go/pkg/errorx"
"mayfly-go/pkg/logx"
"mayfly-go/pkg/utils/collx"
)
@@ -27,6 +28,9 @@ type ResourceAuthCert interface {
// SaveAuthCert 保存资源授权凭证信息,不可放于事务中
SaveAuthCert(ctx context.Context, param *SaveAuthCertParam) error
// SavePublicAuthCert 保存公共授权凭证信息
SavePulbicAuthCert(ctx context.Context, rac *entity.ResourceAuthCert) error
// GetAuthCert 根据授权凭证名称获取授权凭证
GetAuthCert(authCertName string) (*entity.ResourceAuthCert, error)
@@ -68,6 +72,7 @@ func (r *resourceAuthCertAppImpl) SaveAuthCert(ctx context.Context, params *Save
// 删除授权信息
if len(resourceAuthCerts) == 0 {
logx.DebugfContext(ctx, "SaveAuthCert[%d-%s]-删除所有关联的授权凭证信息", resourceType, resourceCode)
if err := r.DeleteByCond(ctx, &entity.ResourceAuthCert{ResourceCode: resourceCode, ResourceType: resourceType}); err != nil {
return err
}
@@ -111,6 +116,7 @@ func (r *resourceAuthCertAppImpl) SaveAuthCert(ctx context.Context, params *Save
var adds, dels, unmodifys []string
if len(oldAuthCert) == 0 {
logx.DebugfContext(ctx, "SaveAuthCert[%d-%s]-不存在已有的授权凭证信息, 为新增资源授权凭证", resourceType, resourceCode)
adds = collx.MapKeys(name2AuthCert)
} else {
oldNames := collx.ArrayMap(oldAuthCert, func(ac *entity.ResourceAuthCert) string {
@@ -128,6 +134,7 @@ func (r *resourceAuthCertAppImpl) SaveAuthCert(ctx context.Context, params *Save
// 处理新增的授权凭证
if len(addAuthCerts) > 0 {
logx.DebugfContext(ctx, "SaveAuthCert[%d-%s]-新增授权凭证-[%v]", resourceType, resourceCode, adds)
if err := r.BatchInsert(ctx, addAuthCerts); err != nil {
return err
}
@@ -140,20 +147,24 @@ func (r *resourceAuthCertAppImpl) SaveAuthCert(ctx context.Context, params *Save
return tag.Id
})
// 保存授权凭证类型的资源标签
for _, authCert := range addAuthCerts {
if err := r.tagTreeApp.SaveResource(ctx, &SaveResourceTagParam{
ResourceCode: authCert.Name,
ResourceType: authCertTagType,
ResourceName: authCert.Username,
TagIds: resourceTagIds,
}); err != nil {
return err
if len(resourceTagIds) > 0 {
// 保存授权凭证类型的资源标签
for _, authCert := range addAuthCerts {
logx.DebugfContext(ctx, "SaveAuthCert[%d-%s]-授权凭证标签[%d-%s]关联至所属资源标签下[%v]", resourceType, resourceCode, authCertTagType, authCert.Name, resourceTagIds)
if err := r.tagTreeApp.SaveResource(ctx, &SaveResourceTagParam{
ResourceCode: authCert.Name,
ResourceType: authCertTagType,
ResourceName: authCert.Username,
TagIds: resourceTagIds,
}); err != nil {
return err
}
}
}
}
for _, del := range dels {
logx.DebugfContext(ctx, "SaveAuthCert[%d-%s]-删除授权凭证-[%v]", resourceType, resourceCode, del)
if err := r.DeleteByCond(ctx, &entity.ResourceAuthCert{ResourceCode: resourceCode, ResourceType: resourceType, Name: del}); err != nil {
return err
}
@@ -171,6 +182,12 @@ func (r *resourceAuthCertAppImpl) SaveAuthCert(ctx context.Context, params *Save
if unmodifyAc.Id == 0 {
continue
}
logx.DebugfContext(ctx, "SaveAuthCert[%d-%s]-更新授权凭证-[%v]", resourceType, resourceCode, unmodify)
// 置空用户名不允许修改TagTree的name关联了该值修改了会造成数据不一致懒得处理该同步。要修改用户名可通过重新删除旧凭证后添加一个授权凭证或通过关联公共凭证公共凭证可修改用户名
if unmodifyAc.CiphertextType != entity.AuthCertCiphertextTypePublic {
unmodifyAc.Username = ""
}
if err := r.UpdateById(ctx, unmodifyAc); err != nil {
return err
}
@@ -179,6 +196,22 @@ func (r *resourceAuthCertAppImpl) SaveAuthCert(ctx context.Context, params *Save
return nil
}
func (r *resourceAuthCertAppImpl) SavePulbicAuthCert(ctx context.Context, rac *entity.ResourceAuthCert) error {
rac.Type = entity.AuthCertTypePublic
rac.CiphertextEncrypt()
rac.ResourceType = 0
rac.ResourceCode = "-"
if rac.Id == 0 {
if r.CountByCond(&entity.ResourceAuthCert{Name: rac.Name}) > 0 {
return errorx.NewBiz("授权凭证的名称不能重复[%s]", rac.Name)
}
return r.Insert(ctx, rac)
}
// 名称置空,防止被更新
rac.Name = ""
return r.UpdateById(ctx, rac)
}
func (r *resourceAuthCertAppImpl) GetAuthCert(authCertName string) (*entity.ResourceAuthCert, error) {
authCert := &entity.ResourceAuthCert{Name: authCertName}
if err := r.GetBy(authCert); err != nil {
@@ -232,17 +265,23 @@ func (r *resourceAuthCertAppImpl) GetAccountAuthCert(accountId uint64, authCertT
}
func (r *resourceAuthCertAppImpl) FillAuthCert(authCerts []*entity.ResourceAuthCert, resources ...entity.IAuthCert) {
if len(resources) == 0 {
if len(resources) == 0 || len(authCerts) == 0 {
return
}
// 资源编号 -> 资源
resourceCode2Resouce := collx.ArrayToMap(resources, func(ac entity.IAuthCert) string {
resourceCode2Resource := collx.ArrayToMap(resources, func(ac entity.IAuthCert) string {
return ac.GetCode()
})
for _, authCert := range authCerts {
resourceCode2Resouce[authCert.ResourceCode].SetAuthCert(entity.AuthCert{
resource := resourceCode2Resource[authCert.ResourceCode]
if resource == nil {
logx.Debugf("FillAuthCert-授权凭证[%s]未匹配到对应的资源[%s]", authCert.Name, authCert.ResourceCode)
continue
}
resource.SetAuthCert(entity.AuthCert{
Name: authCert.Name,
Username: authCert.Username,
Type: authCert.Type,
@@ -254,11 +293,21 @@ func (r *resourceAuthCertAppImpl) FillAuthCert(authCerts []*entity.ResourceAuthC
// 解密授权凭证信息
func (r *resourceAuthCertAppImpl) decryptAuthCert(authCert *entity.ResourceAuthCert) (*entity.ResourceAuthCert, error) {
if authCert.CiphertextType == entity.AuthCertCiphertextTypePublic {
// 需要维持资源关联信息
resourceCode := authCert.ResourceCode
resourceType := authCert.ResourceType
authCertType := authCert.Type
// 如果是公共授权凭证,则密文为公共授权凭证名称,需要使用该名称再去获取对应的授权凭证
authCert = &entity.ResourceAuthCert{Name: authCert.Ciphertext}
if err := r.GetBy(authCert); err != nil {
return nil, errorx.NewBiz("该公共授权凭证[%s]不存在", authCert.Ciphertext)
}
// 使用资源关联的凭证类型
authCert.ResourceCode = resourceCode
authCert.ResourceType = resourceType
authCert.Type = authCertType
}
if err := authCert.CiphertextDecrypt(); err != nil {

View File

@@ -5,17 +5,30 @@ import (
"mayfly-go/internal/tag/domain/entity"
"mayfly-go/internal/tag/domain/repository"
"mayfly-go/pkg/biz"
"mayfly-go/pkg/contextx"
"mayfly-go/pkg/errorx"
"mayfly-go/pkg/gormx"
"mayfly-go/pkg/logx"
"mayfly-go/pkg/model"
"mayfly-go/pkg/utils/collx"
"gorm.io/gorm"
)
type SaveTeamParam struct {
Id uint64 `json:"id"`
Name string `json:"name" binding:"required"` // 名称
Remark string `json:"remark"` // 备注说明
Tags []uint64 `json:"tags"` // 关联标签信息
}
type Team interface {
// 分页获取项目团队信息列表
GetPageList(condition *entity.TeamQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
Save(ctx context.Context, team *entity.Team) error
// Save 保存团队信息
Save(ctx context.Context, team *SaveTeamParam) error
Delete(ctx context.Context, id uint64) error
@@ -33,8 +46,6 @@ type Team interface {
ListTagIds(teamId uint64) []uint64
SaveTag(ctx context.Context, tagTeam *entity.TagTreeTeam) error
DeleteTag(tx context.Context, teamId, tagId uint64) error
}
@@ -42,17 +53,78 @@ type teamAppImpl struct {
teamRepo repository.Team `inject:"TeamRepo"`
teamMemberRepo repository.TeamMember `inject:"TeamMemberRepo"`
tagTreeTeamRepo repository.TagTreeTeam `inject:"TagTreeTeamRepo"`
tagTreeApp TagTree `inject:"TagTreeApp"`
}
func (p *teamAppImpl) GetPageList(condition *entity.TeamQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return p.teamRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
}
func (p *teamAppImpl) Save(ctx context.Context, team *entity.Team) error {
func (p *teamAppImpl) Save(ctx context.Context, saveParam *SaveTeamParam) error {
team := &entity.Team{Name: saveParam.Name, Remark: saveParam.Remark}
team.Id = saveParam.Id
if team.Id == 0 {
return p.teamRepo.Insert(ctx, team)
if p.teamRepo.CountByCond(&entity.Team{Name: saveParam.Name}) > 0 {
return errorx.NewBiz("团队名[%s]已存在", saveParam.Name)
}
if err := p.teamRepo.Insert(ctx, team); err != nil {
return err
}
loginAccount := contextx.GetLoginAccount(ctx)
logx.DebugfContext(ctx, "将[%s]默认加入至[%s]团队", loginAccount.Username, team.Name)
teamMem := &entity.TeamMember{}
teamMem.AccountId = loginAccount.Id
teamMem.Username = loginAccount.Username
teamMem.TeamId = team.Id
p.SaveMember(ctx, teamMem)
} else {
// 置空名称,防止变更
team.Name = ""
if err := p.teamRepo.UpdateById(ctx, team); err != nil {
return err
}
}
return p.teamRepo.UpdateById(ctx, team)
// 保存团队关联的标签信息
teamId := team.Id
var addIds, delIds []uint64
if saveParam.Id == 0 {
addIds = saveParam.Tags
} else {
// 将[]uint64转为[]any
oIds := p.ListTagIds(team.Id)
// 比较新旧两合集
addIds, delIds, _ = collx.ArrayCompare(saveParam.Tags, oIds)
}
addTeamTags := make([]*entity.TagTreeTeam, 0)
for _, v := range addIds {
tagId := v
tag, err := p.tagTreeApp.GetById(new(entity.TagTree), tagId)
if err != nil {
return errorx.NewBiz("存在非法标签id")
}
ptt := &entity.TagTreeTeam{TeamId: teamId, TagId: tagId, TagPath: tag.CodePath}
addTeamTags = append(addTeamTags, ptt)
}
if len(addTeamTags) > 0 {
logx.DebugfContext(ctx, "团队[%s]新增关联的标签信息: [%v]", team.Name, addTeamTags)
p.tagTreeTeamRepo.BatchInsert(ctx, addTeamTags)
}
for _, v := range delIds {
p.DeleteTag(ctx, teamId, v)
}
if len(delIds) > 0 {
logx.DebugfContext(ctx, "团队[%s]删除关联的标签信息: [%v]", team.Name, delIds)
}
return nil
}
func (p *teamAppImpl) Delete(ctx context.Context, id uint64) error {
@@ -91,7 +163,7 @@ func (p *teamAppImpl) IsExistMember(teamId, accounId uint64) bool {
return p.teamMemberRepo.IsExist(teamId, accounId)
}
//--------------- 关联标签相关接口 ---------------
//--------------- 标签相关接口 ---------------
func (p *teamAppImpl) ListTagIds(teamId uint64) []uint64 {
tags := &[]entity.TagTreeTeam{}
@@ -103,12 +175,6 @@ func (p *teamAppImpl) ListTagIds(teamId uint64) []uint64 {
return ids
}
// 保存关联项目信息
func (p *teamAppImpl) SaveTag(ctx context.Context, tagTreeTeam *entity.TagTreeTeam) error {
tagTreeTeam.Id = 0
return p.tagTreeTeamRepo.Insert(ctx, tagTreeTeam)
}
// 删除关联项目信息
func (p *teamAppImpl) DeleteTag(ctx context.Context, teamId, tagId uint64) error {
return p.tagTreeTeamRepo.DeleteByCond(ctx, &entity.TagTreeTeam{TeamId: teamId, TagId: tagId})

View File

@@ -8,6 +8,10 @@ import (
"github.com/may-fly/cast"
)
const (
ExtraKeyPassphrase = "passphrase"
)
// 资源授权凭证
type ResourceAuthCert struct {
model.Model
@@ -16,14 +20,15 @@ type ResourceAuthCert struct {
ResourceCode string `json:"resourceCode"` // 资源编号
ResourceType int8 `json:"resourceType"` // 资源类型
Type AuthCertType `json:"type"` // 凭证类型
Username string `json:"username"` // 用户名
Ciphertext string `json:"ciphertext"` // 密文
CiphertextType AuthCertCiphertextType `json:"ciphertextType"` // 密文类型
Extra model.Map[string, any] `json:"extra"` // 账号需要的其他额外信息(如秘钥口令等)
Type AuthCertType `json:"type"` // 凭证类型
Remark string `json:"remark"` // 备注
}
// CiphertextEncrypt 密文加密
func (m *ResourceAuthCert) CiphertextEncrypt() error {
// 密码替换为加密后的密码
password, err := utils.PwdAesEncrypt(m.Ciphertext)
@@ -34,19 +39,20 @@ func (m *ResourceAuthCert) CiphertextEncrypt() error {
// 加密秘钥口令
if m.CiphertextType == AuthCertCiphertextTypePrivateKey {
passphrase := cast.ToString(m.Extra["passphrase"])
passphrase := m.GetExtraString(ExtraKeyPassphrase)
if passphrase != "" {
passphrase, err := utils.PwdAesEncrypt(passphrase)
if err != nil {
return errors.New("加密秘钥口令失败")
}
m.Extra["passphrase"] = passphrase
m.SetExtra(ExtraKeyPassphrase, passphrase)
}
}
return nil
}
// CiphertextDecrypt 密文解密
func (m *ResourceAuthCert) CiphertextDecrypt() error {
// 密码替换为解密后的密码
password, err := utils.PwdAesDecrypt(m.Ciphertext)
@@ -57,18 +63,40 @@ func (m *ResourceAuthCert) CiphertextDecrypt() error {
// 加密秘钥口令
if m.CiphertextType == AuthCertCiphertextTypePrivateKey {
passphrase := cast.ToString(m.Extra["passphrase"])
passphrase := m.GetExtraString(ExtraKeyPassphrase)
if passphrase != "" {
passphrase, err := utils.PwdAesDecrypt(passphrase)
if err != nil {
return errors.New("解密秘钥口令失败")
}
m.Extra["passphrase"] = passphrase
m.SetExtra(ExtraKeyPassphrase, passphrase)
}
}
return nil
}
// CiphertextClear 密文清楚
func (m *ResourceAuthCert) CiphertextClear() {
// 如果密文类型非公共授权凭证,则清空
if m.CiphertextType != AuthCertCiphertextTypePublic {
m.Ciphertext = ""
}
m.SetExtra(ExtraKeyPassphrase, "")
}
func (m *ResourceAuthCert) SetExtra(key string, val any) {
if m.Extra != nil {
m.Extra[key] = val
}
}
func (m *ResourceAuthCert) GetExtraString(key string) string {
if m.Extra == nil {
return ""
}
return cast.ToString(m.Extra[key])
}
// 密文类型
type AuthCertCiphertextType int8
@@ -76,14 +104,14 @@ type AuthCertCiphertextType int8
type AuthCertType int8
const (
AuthCertCiphertextTypePublic AuthCertCiphertextType = -1 // 公共授权凭证
AuthCertCiphertextTypePublic AuthCertCiphertextType = -1 // 公共授权凭证密文
AuthCertCiphertextTypePassword AuthCertCiphertextType = 1 // 密码
AuthCertCiphertextTypePrivateKey AuthCertCiphertextType = 2 // 私钥
AuthCertTypePublic AuthCertType = 2 // 公共凭证(可多个资源共享该授权凭证)
AuthCertTypePrivate AuthCertType = 1 // 普通私有凭证
AuthCertTypePrivileged AuthCertType = 11 // 特权私有凭证
AuthCertTypePrivateDefault AuthCertType = 12 // 默认私有凭证
AuthCertTypePublic AuthCertType = 2 // 公共凭证(可多个资源共享该授权凭证)
)
// 授权凭证接口,填充资源授权凭证信息

View File

@@ -17,6 +17,12 @@ func InitResourceAuthCertRouter(router *gin.RouterGroup) {
{
reqs := [...]*req.Conf{
req.NewGet("", m.ListByQuery),
req.NewGet("/detail", m.GetCompleteAuthCert).Log(req.NewLogSave("授权凭证-查看密文")).RequiredPermissionCode("authcert:showciphertext"),
req.NewPost("", m.SaveAuthCert).Log(req.NewLogSave("授权凭证-保存")).RequiredPermissionCode("authcert:save"),
req.NewDelete(":id", m.Delete).Log(req.NewLogSave("授权凭证-删除")).RequiredPermissionCode("authcert:del"),
}
req.BatchSetGroup(resourceAuthCert, reqs[:])

View File

@@ -32,8 +32,6 @@ func InitTeamRouter(router *gin.RouterGroup) {
// 获取团队关联的标签id列表
req.NewGet("/:id/tags", m.GetTagIds),
req.NewPost("/:id/tags", m.SaveTags).Log(req.NewLogSave("团队-保存标签关联信息")).RequiredPermissionCode("team:tag:save"),
}
req.BatchSetGroup(team, reqs[:])

View File

@@ -18,9 +18,6 @@ func T2022() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "2022",
Migrate: func(tx *gorm.DB) error {
if err := tx.AutoMigrate(&entity.AuthCert{}); err != nil {
return err
}
if err := tx.AutoMigrate(&entity.Machine{}); err != nil {
return err
}

View File

@@ -27,7 +27,7 @@ CREATE TABLE `t_db_instance` (
`is_deleted` tinyint(8) NOT NULL DEFAULT '0',
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='数据库实例信息表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='数据库实例信息表';
-- ----------------------------
-- Table structure for t_db
@@ -51,7 +51,7 @@ CREATE TABLE `t_db` (
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_code` (`code`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='数据库资源信息表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='数据库资源信息表';
-- ----------------------------
-- Table structure for t_db_sql
@@ -73,7 +73,7 @@ CREATE TABLE `t_db_sql` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='数据库sql信息';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='数据库sql信息';
-- ----------------------------
-- Table structure for t_db_sql_exec
@@ -132,7 +132,7 @@ CREATE TABLE `t_db_backup` (
PRIMARY KEY (`id`),
KEY `idx_db_name` (`db_name`) USING BTREE,
KEY `idx_db_instance_id` (`db_instance_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- ----------------------------
-- Table structure for t_db_backup_history
@@ -157,7 +157,7 @@ CREATE TABLE `t_db_backup_history` (
KEY `idx_db_backup_id` (`db_backup_id`) USING BTREE,
KEY `idx_db_instance_id` (`db_instance_id`) USING BTREE,
KEY `idx_db_name` (`db_name`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- ----------------------------
-- Table structure for t_db_restore
@@ -190,7 +190,7 @@ CREATE TABLE `t_db_restore` (
PRIMARY KEY (`id`),
KEY `idx_db_instane_id` (`db_instance_id`) USING BTREE,
KEY `idx_db_name` (`db_name`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- ----------------------------
-- Table structure for t_db_restore_history
@@ -204,7 +204,7 @@ CREATE TABLE `t_db_restore_history` (
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_db_restore_id` (`db_restore_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- ----------------------------
-- Table structure for t_db_binlog
@@ -226,7 +226,7 @@ CREATE TABLE `t_db_binlog` (
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_db_instance_id` (`db_instance_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- ----------------------------
-- Table structure for t_db_binlog_history
@@ -245,7 +245,7 @@ CREATE TABLE `t_db_binlog_history` (
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_db_instance_id` (`db_instance_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
-- ----------------------------
-- Table structure for t_db_data_sync_task
@@ -322,7 +322,7 @@ CREATE TABLE `t_auth_cert` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='授权凭证';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='授权凭证';
-- ----------------------------
-- Table structure for t_machine
@@ -349,7 +349,7 @@ CREATE TABLE `t_machine` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器信息';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器信息';
-- ----------------------------
-- Table structure for t_machine_file
@@ -370,7 +370,7 @@ CREATE TABLE `t_machine_file` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器文件';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器文件';
-- ----------------------------
-- Records of t_machine_file
@@ -416,7 +416,7 @@ CREATE TABLE `t_machine_script` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器脚本';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器脚本';
-- ----------------------------
-- Records of t_machine_script
@@ -426,7 +426,7 @@ INSERT INTO `t_machine_script` VALUES (1, 'sys_info', 9999999, '# 获取系统cp
INSERT INTO `t_machine_script` VALUES (2, 'get_process_by_name', 9999999, '#! /bin/bash\n# Function: 根据输入的程序的名字过滤出所对应的PID并显示出详细信息如果有几个PID则全部显示\nNAME={{.processName}}\nN=`ps -aux | grep $NAME | grep -v grep | wc -l` ##统计进程总数\nif [ $N -le 0 ];then\n echo \"无该进程!\"\nfi\ni=1\nwhile [ $N -gt 0 ]\ndo\n echo \"进程PID: `ps -aux | grep $NAME | grep -v grep | awk \'NR==\'$i\'{print $0}\'| awk \'{print $2}\'`\"\n echo \"进程命令:`ps -aux | grep $NAME | grep -v grep | awk \'NR==\'$i\'{print $0}\'| awk \'{print $11}\'`\"\n echo \"进程所属用户: `ps -aux | grep $NAME | grep -v grep | awk \'NR==\'$i\'{print $0}\'| awk \'{print $1}\'`\"\n echo \"CPU占用率`ps -aux | grep $NAME | grep -v grep | awk \'NR==\'$i\'{print $0}\'| awk \'{print $3}\'`%\"\n echo \"内存占用率:`ps -aux | grep $NAME | grep -v grep | awk \'NR==\'$i\'{print $0}\'| awk \'{print $4}\'`%\"\n echo \"进程开始运行的时刻:`ps -aux | grep $NAME | grep -v grep | awk \'NR==\'$i\'{print $0}\'| awk \'{print $9}\'`\"\n echo \"进程运行的时间:` ps -aux | grep $NAME | grep -v grep | awk \'NR==\'$i\'{print $0}\'| awk \'{print $11}\'`\"\n echo \"进程状态:`ps -aux | grep $NAME | grep -v grep | awk \'NR==\'$i\'{print $0}\'| awk \'{print $8}\'`\"\n echo \"进程虚拟内存:`ps -aux | grep $NAME | grep -v grep | awk \'NR==\'$i\'{print $0}\'| awk \'{print $5}\'`\"\n echo \"进程共享内存:`ps -aux | grep $NAME | grep -v grep | awk \'NR==\'$i\'{print $0}\'| awk \'{print $6}\'`\"\n echo \"***************************************************************\"\n let N-- i++\ndone', '[{\"name\": \"进程名\",\"model\": \"processName\", \"placeholder\": \"请输入进程名\"}]', '获取进程运行状态', 1, NULL, NULL, 1, 'admin', NULL, '2021-07-12 15:33:41', 0, NULL);
INSERT INTO `t_machine_script` VALUES (3, 'sys_run_info', 9999999, '#!/bin/bash\n# 获取要监控的本地服务器IP地址\nIP=`ifconfig | grep inet | grep -vE \'inet6|127.0.0.1\' | awk \'{print $2}\'`\necho \"IP地址\"$IP\n \n# 获取cpu总核数\ncpu_num=`grep -c \"model name\" /proc/cpuinfo`\necho \"cpu总核数\"$cpu_num\n \n# 1、获取CPU利用率\n################################################\n#us 用户空间占用CPU百分比\n#sy 内核空间占用CPU百分比\n#ni 用户进程空间内改变过优先级的进程占用CPU百分比\n#id 空闲CPU百分比\n#wa 等待输入输出的CPU时间百分比\n#hi 硬件中断\n#si 软件中断\n#################################################\n# 获取用户空间占用CPU百分比\ncpu_user=`top -b -n 1 | grep Cpu | awk \'{print $2}\' | cut -f 1 -d \"%\"`\necho \"用户空间占用CPU百分比\"$cpu_user\n \n# 获取内核空间占用CPU百分比\ncpu_system=`top -b -n 1 | grep Cpu | awk \'{print $4}\' | cut -f 1 -d \"%\"`\necho \"内核空间占用CPU百分比\"$cpu_system\n \n# 获取空闲CPU百分比\ncpu_idle=`top -b -n 1 | grep Cpu | awk \'{print $8}\' | cut -f 1 -d \"%\"`\necho \"空闲CPU百分比\"$cpu_idle\n \n# 获取等待输入输出占CPU百分比\ncpu_iowait=`top -b -n 1 | grep Cpu | awk \'{print $10}\' | cut -f 1 -d \"%\"`\necho \"等待输入输出占CPU百分比\"$cpu_iowait\n \n#2、获取CPU上下文切换和中断次数\n# 获取CPU中断次数\ncpu_interrupt=`vmstat -n 1 1 | sed -n 3p | awk \'{print $11}\'`\necho \"CPU中断次数\"$cpu_interrupt\n \n# 获取CPU上下文切换次数\ncpu_context_switch=`vmstat -n 1 1 | sed -n 3p | awk \'{print $12}\'`\necho \"CPU上下文切换次数\"$cpu_context_switch\n \n#3、获取CPU负载信息\n# 获取CPU15分钟前到现在的负载平均值\ncpu_load_15min=`uptime | awk \'{print $11}\' | cut -f 1 -d \',\'`\necho \"CPU 15分钟前到现在的负载平均值\"$cpu_load_15min\n \n# 获取CPU5分钟前到现在的负载平均值\ncpu_load_5min=`uptime | awk \'{print $10}\' | cut -f 1 -d \',\'`\necho \"CPU 5分钟前到现在的负载平均值\"$cpu_load_5min\n \n# 获取CPU1分钟前到现在的负载平均值\ncpu_load_1min=`uptime | awk \'{print $9}\' | cut -f 1 -d \',\'`\necho \"CPU 1分钟前到现在的负载平均值\"$cpu_load_1min\n \n# 获取任务队列(就绪状态等待的进程数)\ncpu_task_length=`vmstat -n 1 1 | sed -n 3p | awk \'{print $1}\'`\necho \"CPU任务队列长度\"$cpu_task_length\n \n#4、获取内存信息\n# 获取物理内存总量\nmem_total=`free -h | grep Mem | awk \'{print $2}\'`\necho \"物理内存总量:\"$mem_total\n \n# 获取操作系统已使用内存总量\nmem_sys_used=`free -h | grep Mem | awk \'{print $3}\'`\necho \"已使用内存总量(操作系统)\"$mem_sys_used\n \n# 获取操作系统未使用内存总量\nmem_sys_free=`free -h | grep Mem | awk \'{print $4}\'`\necho \"剩余内存总量(操作系统)\"$mem_sys_free\n \n# 获取应用程序已使用的内存总量\nmem_user_used=`free | sed -n 3p | awk \'{print $3}\'`\necho \"已使用内存总量(应用程序)\"$mem_user_used\n \n# 获取应用程序未使用内存总量\nmem_user_free=`free | sed -n 3p | awk \'{print $4}\'`\necho \"剩余内存总量(应用程序)\"$mem_user_free\n \n# 获取交换分区总大小\nmem_swap_total=`free | grep Swap | awk \'{print $2}\'`\necho \"交换分区总大小:\"$mem_swap_total\n \n# 获取已使用交换分区大小\nmem_swap_used=`free | grep Swap | awk \'{print $3}\'`\necho \"已使用交换分区大小:\"$mem_swap_used\n \n# 获取剩余交换分区大小\nmem_swap_free=`free | grep Swap | awk \'{print $4}\'`\necho \"剩余交换分区大小:\"$mem_swap_free', NULL, '获取cpu、内存等系统运行状态', 1, NULL, NULL, NULL, NULL, NULL, '2021-04-25 15:07:16', 0, NULL);
INSERT INTO `t_machine_script` VALUES (4, 'top', 9999999, 'top', NULL, '实时获取系统运行状态', 3, NULL, NULL, 1, 'admin', NULL, '2021-05-24 15:58:20', 0, NULL);
INSERT INTO `t_machine_script` VALUES (18, 'disk-mem', 9999999, 'df -h', '', '磁盘空间查看', 1, 1, 'admin', 1, 'admin', '2021-07-16 10:49:53', '2021-07-16 10:49:53', 0, NULL);
INSERT INTO `t_machine_script` VALUES (5, 'disk-mem', 9999999, 'df -h', '', '磁盘空间查看', 1, 1, 'admin', 1, 'admin', '2021-07-16 10:49:53', '2021-07-16 10:49:53', 0, NULL);
COMMIT;
DROP TABLE IF EXISTS `t_machine_cron_job`;
@@ -449,7 +449,7 @@ CREATE TABLE `t_machine_cron_job` (
`is_deleted` tinyint NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器计划任务';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器计划任务';
DROP TABLE IF EXISTS `t_machine_cron_job_exec`;
CREATE TABLE `t_machine_cron_job_exec` (
@@ -462,7 +462,7 @@ CREATE TABLE `t_machine_cron_job_exec` (
`is_deleted` tinyint NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器计划任务执行记录';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器计划任务执行记录';
DROP TABLE IF EXISTS `t_machine_cron_job_relate`;
CREATE TABLE `t_machine_cron_job_relate` (
@@ -475,7 +475,7 @@ CREATE TABLE `t_machine_cron_job_relate` (
`is_deleted` tinyint NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器计划任务关联表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器计划任务关联表';
DROP TABLE IF EXISTS `t_machine_term_op`;
CREATE TABLE `t_machine_term_op` (
@@ -490,7 +490,7 @@ CREATE TABLE `t_machine_term_op` (
`is_deleted` tinyint DEFAULT '0',
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器终端操作记录表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='机器终端操作记录表';
-- ----------------------------
-- Table structure for t_mongo
@@ -511,7 +511,7 @@ CREATE TABLE `t_mongo` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
-- ----------------------------
-- Table structure for t_redis
@@ -538,7 +538,7 @@ CREATE TABLE `t_redis` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='redis信息';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='redis信息';
DROP TABLE IF EXISTS `t_oauth2_account`;
@@ -551,7 +551,7 @@ CREATE TABLE `t_oauth2_account` (
`is_deleted` tinyint DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='oauth2关联账号';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='oauth2关联账号';
-- ----------------------------
-- Table structure for t_sys_account
@@ -575,7 +575,7 @@ CREATE TABLE `t_sys_account` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='账号信息表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='账号信息表';
-- ----------------------------
-- Records of t_sys_account
@@ -598,7 +598,7 @@ CREATE TABLE `t_sys_account_role` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='账号角色关联表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='账号角色关联表';
-- ----------------------------
-- Table structure for t_sys_config
@@ -621,7 +621,7 @@ CREATE TABLE `t_sys_config` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
-- ----------------------------
-- Records of t_sys_config
@@ -655,7 +655,7 @@ CREATE TABLE `t_sys_log` (
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_creator_id` (`creator_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=58 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='系统操作日志';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='系统操作日志';
-- ----------------------------
-- Table structure for t_sys_msg
@@ -672,7 +672,7 @@ CREATE TABLE `t_sys_msg` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=91 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='系统消息表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='系统消息表';
-- ----------------------------
-- Table structure for t_sys_resource
@@ -698,7 +698,7 @@ CREATE TABLE `t_sys_resource` (
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `t_sys_resource_ui_path_IDX` (`ui_path`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=128 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='资源表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='资源表';
-- ----------------------------
-- Records of t_sys_resource
@@ -778,7 +778,7 @@ INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(100, 95, 'Tag3fhad/Bjlag32x/Lgidsq32/', 2, 1, '新增团队成员', 'team:member:save', 30000000, 'null', 1, 'admin', 1, 'admin', '2022-10-26 13:59:27', '2022-10-26 13:59:27', 0, NULL);
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(101, 95, 'Tag3fhad/Bjlag32x/Lixaue3G/', 2, 1, '移除团队成员', 'team:member:del', 40000000, 'null', 1, 'admin', 1, 'admin', '2022-10-26 13:59:43', '2022-10-26 13:59:43', 0, NULL);
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(102, 95, 'Tag3fhad/Bjlag32x/Oygsq3xg/', 2, 1, '保存团队标签', 'team:tag:save', 50000000, 'null', 1, 'admin', 1, 'admin', '2022-10-26 13:59:57', '2022-10-26 13:59:57', 0, NULL);
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(103, 2, '12sSjal1/exahgl32/', 1, 1, '授权凭证', 'authcerts', 60000000, '{"component":"ops/machine/authcert/AuthCertList","icon":"Unlock","isKeepAlive":true,"routeName":"AuthCertList"}', 1, 'admin', 1, 'admin', '2023-02-23 11:36:26', '2023-03-14 14:33:28', 0, NULL);
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(103, 93, '12sSjal1/exahgl32/', 1, 1, '授权凭证', 'authcerts', 19999999, '{"component":"ops/tag/AuthCertList","icon":"Ticket","isKeepAlive":true,"routeName":"AuthCertList"}', 1, 'admin', 1, 'admin', '2023-02-23 11:36:26', '2023-03-14 14:33:28', 0, NULL);
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(104, 103, '12sSjal1/exahgl32/egxahg24/', 2, 1, '基本权限', 'authcert', 10000000, 'null', 1, 'admin', 1, 'admin', '2023-02-23 11:37:24', '2023-02-23 11:37:24', 0, NULL);
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(105, 103, '12sSjal1/exahgl32/yglxahg2/', 2, 1, '保存权限', 'authcert:save', 20000000, 'null', 1, 'admin', 1, 'admin', '2023-02-23 11:37:54', '2023-02-23 11:37:54', 0, NULL);
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(106, 103, '12sSjal1/exahgl32/Glxag234/', 2, 1, '删除权限', 'authcert:del', 30000000, 'null', 1, 'admin', 1, 'admin', '2023-02-23 11:38:09', '2023-02-23 11:38:09', 0, NULL);
@@ -807,7 +807,8 @@ INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(1709045735, 1708910975, '6egfEVYr/3r3hHEub/', 1, 1, '我的任务', 'procinst-tasks', 1708911263, '{"component":"flow/ProcinstTaskList","icon":"Tickets","isKeepAlive":true,"routeName":"ProcinstTaskList"}', 1, 'admin', 1, 'admin', '2024-02-27 22:55:35', '2024-02-27 22:56:35', 0, NULL);
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(1708911264, 1708910975, '6egfEVYr/fw0Hhvye/', 1, 1, '流程定义', 'procdefs', 1708911264, '{"component":"flow/ProcdefList","icon":"List","isKeepAlive":true,"routeName":"ProcdefList"}', 1, 'admin', 1, 'admin', '2024-02-26 09:34:24', '2024-02-27 22:54:32', 0, NULL);
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(1708910975, 0, '6egfEVYr/', 1, 1, '工单流程', '/flow', 60000000, '{"icon":"List","isKeepAlive":true,"routeName":"flow"}', 1, 'admin', 1, 'admin', '2024-02-26 09:29:36', '2024-02-26 15:37:52', 0, NULL);
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(1712717290, 0, 'tLb8TKLB/', 1, 1, '无页面权限', 'empty', 1712717290, '{"component":"empty","icon":"Menu","isHide":true,"isKeepAlive":true,"routeName":"empty"}', 1, 'admin', 1, 'admin', '2024-04-10 10:48:10', '2024-04-10 10:48:10', 0, NULL);
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(1712717337, 1712717290, 'tLb8TKLB/m2abQkA8/', 2, 1, '授权凭证密文查看', 'authcert:showciphertext', 1712717337, 'null', 1, 'admin', 1, 'admin', '2024-04-10 10:48:58', '2024-04-10 10:48:58', 0, NULL);
COMMIT;
-- ----------------------------
@@ -830,14 +831,13 @@ CREATE TABLE `t_sys_role` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='角色表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='角色表';
-- ----------------------------
-- Records of t_sys_role
-- ----------------------------
BEGIN;
INSERT INTO `t_sys_role` VALUES (7, '公共角色', 'COMMON', 1, '所有账号基础角色', 1, '2021-07-06 15:05:47', 1, 'admin', '2021-07-06 15:05:47', 1, 'admin', 0, NULL);
INSERT INTO `t_sys_role` VALUES (8, '开发', 'DEV', 1, '研发人员', 0, '2021-07-09 10:46:10', 1, 'admin', '2021-07-09 10:46:10', 1, 'admin', 0, NULL);
COMMIT;
-- ----------------------------
@@ -854,32 +854,14 @@ CREATE TABLE `t_sys_role_resource` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=526 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='角色资源关联表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='角色资源关联表';
-- ----------------------------
-- Records of t_sys_role_resource
-- ----------------------------
BEGIN;
INSERT INTO `t_sys_role_resource` (role_id,resource_id,creator_id,creator,create_time,is_deleted,delete_time) VALUES
(7,1,1,'admin','2021-07-06 15:07:09', 0, NULL),
(8,57,1,'admin','2021-07-09 10:49:46', 0, NULL),
(8,12,1,'admin','2021-07-09 10:49:46', 0, NULL),
(8,15,1,'admin','2021-07-09 10:49:46', 0, NULL),
(8,38,1,'admin','2021-07-09 10:49:46', 0, NULL),
(8,2,1,'admin','2021-07-09 10:49:46', 0, NULL),
(8,3,1,'admin','2021-07-09 10:49:46', 0, NULL),
(8,36,1,'admin','2021-07-09 10:49:46', 0, NULL),
(8,59,1,'admin','2021-07-09 10:50:32', 0, NULL),
(7,39,1,'admin','2021-09-09 10:10:30', 0, NULL),
(8,42,1,'admin','2021-11-05 15:59:16', 0, NULL),
(8,43,1,'admin','2021-11-05 15:59:16', 0, NULL),
(8,47,1,'admin','2021-11-05 15:59:16', 0, NULL),
(8,60,1,'admin','2021-11-05 15:59:16', 0, NULL),
(8,61,1,'admin','2021-11-05 15:59:16', 0, NULL),
(8,62,1,'admin','2021-11-05 15:59:16', 0, NULL),
(8,80,1,'admin','2022-10-08 10:54:34', 0, NULL),
(8,81,1,'admin','2022-10-08 10:54:34', 0, NULL),
(8,79,1,'admin','2022-10-08 10:54:34', 0, NULL);
(7,1,1,'admin','2021-07-06 15:07:09', 0, NULL);
COMMIT;
-- ----------------------------
@@ -904,13 +886,13 @@ CREATE TABLE `t_tag_tree` (
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_code_path` (`code_path`(100)) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=34 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='标签树';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='标签树';
-- ----------------------------
-- Records of t_tag_tree
-- ----------------------------
BEGIN;
INSERT INTO `t_tag_tree` VALUES (33, 0, 'default', 'default/', '默认', '默认标签', '2022-10-26 20:04:19', 1, 'admin', '2022-10-26 20:04:19', 1, 'admin', 0, NULL);
INSERT INTO `t_tag_tree` VALUES (1, 0, -1, 'default', 'default/', '默认', '默认标签', '2022-10-26 20:04:19', 1, 'admin', '2022-10-26 20:04:19', 1, 'admin', 0, NULL);
COMMIT;
-- ----------------------------
@@ -932,13 +914,13 @@ CREATE TABLE `t_tag_tree_team` (
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_tag_id` (`tag_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='标签树团队关联信息';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='标签树团队关联信息';
-- ----------------------------
-- Records of t_tag_tree_team
-- ----------------------------
BEGIN;
INSERT INTO `t_tag_tree_team` VALUES (31, 33, 'default/', 3, '2022-10-26 20:04:45', 1, 'admin', '2022-10-26 20:04:45', 1, 'admin', 0, NULL);
INSERT INTO `t_tag_tree_team` VALUES (1, 1, 'default/', 1, '2022-10-26 20:04:45', 1, 'admin', '2022-10-26 20:04:45', 1, 'admin', 0, NULL);
COMMIT;
-- ----------------------------
@@ -958,13 +940,13 @@ CREATE TABLE `t_team` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='团队信息';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='团队信息';
-- ----------------------------
-- Records of t_team
-- ----------------------------
BEGIN;
INSERT INTO `t_team` VALUES (3, '默认团队', '默认团队', '2022-10-26 20:04:36', 1, 'admin', '2022-10-26 20:04:36', 1, 'admin', 0, NULL);
INSERT INTO `t_team` VALUES (1, 'default_team', '默认团队', '2022-10-26 20:04:36', 1, 'admin', '2022-10-26 20:04:36', 1, 'admin', 0, NULL);
COMMIT;
-- ----------------------------
@@ -985,13 +967,13 @@ CREATE TABLE `t_team_member` (
`is_deleted` tinyint(8) NOT NULL DEFAULT 0,
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='团队成员表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='团队成员表';
-- ----------------------------
-- Records of t_team_member
-- ----------------------------
BEGIN;
INSERT INTO `t_team_member` VALUES (7, 3, 1, 'admin', '2022-10-26 20:04:36', 1, 'admin', '2022-10-26 20:04:36', 1, 'admin', 0, NULL);
INSERT INTO `t_team_member` VALUES (1, 1, 1, 'admin', '2022-10-26 20:04:36', 1, 'admin', '2022-10-26 20:04:36', 1, 'admin', 0, NULL);
COMMIT;
DROP TABLE IF EXISTS `t_resource_auth_cert`;
@@ -1017,7 +999,7 @@ CREATE TABLE `t_resource_auth_cert` (
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_resource_code` (`resource_code`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='资源授权凭证表';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='资源授权凭证表';
DROP TABLE IF EXISTS `t_flow_procdef`;
-- 工单流程相关表
@@ -1037,7 +1019,7 @@ CREATE TABLE `t_flow_procdef` (
`is_deleted` tinyint DEFAULT '0',
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='流程-流程定义';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='流程-流程定义';
DROP TABLE IF EXISTS `t_flow_procinst`;
CREATE TABLE `t_flow_procinst` (
@@ -1064,7 +1046,7 @@ CREATE TABLE `t_flow_procinst` (
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_procdef_id` (`procdef_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='流程-流程实例(根据流程定义开启一个流程)';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='流程-流程实例(根据流程定义开启一个流程)';
DROP TABLE IF EXISTS `t_flow_procinst_task`;
CREATE TABLE `t_flow_procinst_task` (
@@ -1087,6 +1069,6 @@ CREATE TABLE `t_flow_procinst_task` (
`delete_time` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `idx_procinst_id` (`procinst_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='流程-流程实例任务';
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='流程-流程实例任务';
SET FOREIGN_KEY_CHECKS = 1;

View File

@@ -118,7 +118,90 @@ CREATE TABLE `t_resource_auth_cert` (
KEY `idx_resource_code` (`resource_code`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=43 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='资源授权凭证表';
Begin;
-- 迁移机器表账号
INSERT
INTO
t_resource_auth_cert (name,
resource_code,
resource_type,
type,
username,
ciphertext,
ciphertext_type,
create_time,
creator_id,
creator,
update_time,
modifier_id,
modifier,
is_deleted)
select
CONCAT('machine_', code, '_' username),
code,
1,
1,
username,
password,
1,
DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s'),
1,
'admin',
DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s'),
1,
'admin',
0
from
t_machine
WHERE
is_deleted = 0;
-- 关联机器账号到tag_tree
INSERT
INTO
t_tag_tree (pid,
code,
code_path,
type,
name,
create_time,
creator_id,
creator,
update_time,
modifier_id,
modifier,
is_deleted)
SELECT
tt.id,
rac.`name`,
CONCAT(tt.code_path, rac.`name`, '/'),
11,
rac.`username`,
DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s'),
1,
'admin',
DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s'),
1,
'admin',
0
FROM
`t_tag_tree` tt
JOIN `t_resource_auth_cert` rac ON tt.`code` = rac.`resource_code`
AND tt.`type` = rac.`resource_type`
WHERE
tt.`is_deleted` = 0
-- 删除机器表 账号相关字段
ALTER TABLE t_machine DROP COLUMN username;
ALTER TABLE t_machine DROP COLUMN password;
ALTER TABLE t_machine DROP COLUMN auth_cert_id;
UPDATE t_sys_resource SET pid=93, ui_path='Tag3fhad/exahgl32/', weight=19999999, meta='{"component":"ops/tag/AuthCertList","icon":"Ticket","isKeepAlive":true,"routeName":"AuthCertList"}' WHERE id=103;
UPDATE t_sys_resource SET ui_path='Tag3fhad/exahgl32/egxahg24/', weight=10000000 WHERE id=104;
UPDATE t_sys_resource SET ui_path='Tag3fhad/exahgl32/yglxahg2/', weight=20000000 WHERE id=105;
UPDATE t_sys_resource SET ui_path='Tag3fhad/exahgl32/Glxag234/', weight=30000000 WHERE id=106;
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(1712717290, 0, 'tLb8TKLB/', 1, 1, '无页面权限', 'empty', 1712717290, '{"component":"empty","icon":"Menu","isHide":true,"isKeepAlive":true,"routeName":"empty"}', 1, 'admin', 1, 'admin', '2024-04-10 10:48:10', '2024-04-10 10:48:10', 0, NULL);
INSERT INTO t_sys_resource (id, pid, ui_path, `type`, status, name, code, weight, meta, creator_id, creator, modifier_id, modifier, create_time, update_time, is_deleted, delete_time) VALUES(1712717337, 1712717290, 'tLb8TKLB/m2abQkA8/', 2, 1, '授权凭证密文查看', 'authcert:showciphertext', 1712717337, 'null', 1, 'admin', 1, 'admin', '2024-04-10 10:48:58', '2024-04-10 10:48:58', 0, NULL);
commit;