mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	feat: 新增简易版ioc
This commit is contained in:
		@@ -49,13 +49,14 @@
 | 
			
		||||
    "@typescript-eslint/parser": "^6.7.4",
 | 
			
		||||
    "@vitejs/plugin-vue": "^5.0.3",
 | 
			
		||||
    "@vue/compiler-sfc": "^3.4.14",
 | 
			
		||||
    "code-inspector-plugin": "^0.4.5",
 | 
			
		||||
    "dotenv": "^16.3.1",
 | 
			
		||||
    "eslint": "^8.35.0",
 | 
			
		||||
    "eslint-plugin-vue": "^9.19.2",
 | 
			
		||||
    "prettier": "^3.1.0",
 | 
			
		||||
    "sass": "^1.69.0",
 | 
			
		||||
    "typescript": "^5.3.2",
 | 
			
		||||
    "vite": "^5.0.11",
 | 
			
		||||
    "vite": "^5.0.12",
 | 
			
		||||
    "vue-eslint-parser": "^9.4.0"
 | 
			
		||||
  },
 | 
			
		||||
  "browserslist": [
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ const config = {
 | 
			
		||||
    baseWsUrl: `${(window as any).globalConfig.BaseWsUrl || `${location.protocol == 'https:' ? 'wss:' : 'ws:'}//${getBaseApiUrl()}`}/api`,
 | 
			
		||||
 | 
			
		||||
    // 系统版本
 | 
			
		||||
    version: 'v1.7.0',
 | 
			
		||||
    version: 'v1.7.1',
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export default config;
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ import vue from '@vitejs/plugin-vue';
 | 
			
		||||
import { resolve } from 'path';
 | 
			
		||||
import type { UserConfig } from 'vite';
 | 
			
		||||
import { loadEnv } from './src/common/utils/viteBuild';
 | 
			
		||||
import { CodeInspectorPlugin } from 'code-inspector-plugin';
 | 
			
		||||
 | 
			
		||||
const pathResolve = (dir: string): any => {
 | 
			
		||||
    return resolve(__dirname, '.', dir);
 | 
			
		||||
@@ -14,7 +15,12 @@ const alias: Record<string, string> = {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const viteConfig: UserConfig = {
 | 
			
		||||
    plugins: [vue()],
 | 
			
		||||
    plugins: [
 | 
			
		||||
        vue(),
 | 
			
		||||
        CodeInspectorPlugin({
 | 
			
		||||
            bundler: 'vite',
 | 
			
		||||
        }),
 | 
			
		||||
    ],
 | 
			
		||||
    root: process.cwd(),
 | 
			
		||||
    resolve: {
 | 
			
		||||
        alias,
 | 
			
		||||
 
 | 
			
		||||
@@ -3,9 +3,14 @@ package initialize
 | 
			
		||||
import (
 | 
			
		||||
	dbInit "mayfly-go/internal/db/init"
 | 
			
		||||
	machineInit "mayfly-go/internal/machine/init"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func InitOther() {
 | 
			
		||||
	// 为所有注册的实例注入其依赖的其他组件实例
 | 
			
		||||
	biz.ErrIsNil(ioc.DefaultContainer.InjectComponents())
 | 
			
		||||
 | 
			
		||||
	machineInit.Init()
 | 
			
		||||
	dbInit.Init()
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -25,8 +25,8 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type AccountLogin struct {
 | 
			
		||||
	AccountApp sysapp.Account
 | 
			
		||||
	MsgApp     msgapp.Msg
 | 
			
		||||
	AccountApp sysapp.Account `inject:""`
 | 
			
		||||
	MsgApp     msgapp.Msg     `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**   用户账号密码登录   **/
 | 
			
		||||
 
 | 
			
		||||
@@ -28,8 +28,8 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type LdapLogin struct {
 | 
			
		||||
	AccountApp sysapp.Account
 | 
			
		||||
	MsgApp     msgapp.Msg
 | 
			
		||||
	AccountApp sysapp.Account `inject:""`
 | 
			
		||||
	MsgApp     msgapp.Msg     `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// @router /auth/ldap/enabled [get]
 | 
			
		||||
 
 | 
			
		||||
@@ -28,9 +28,9 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Oauth2Login struct {
 | 
			
		||||
	Oauth2App  application.Oauth2
 | 
			
		||||
	AccountApp sysapp.Account
 | 
			
		||||
	MsgApp     msgapp.Msg
 | 
			
		||||
	Oauth2App  application.Oauth2 `inject:""`
 | 
			
		||||
	AccountApp sysapp.Account     `inject:""`
 | 
			
		||||
	MsgApp     msgapp.Msg         `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *Oauth2Login) OAuth2Login(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,16 @@
 | 
			
		||||
package application
 | 
			
		||||
 | 
			
		||||
import "mayfly-go/internal/auth/infrastructure/persistence"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	authApp = newAuthApp(persistence.GetOauthAccountRepo())
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/auth/infrastructure/persistence"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func GetAuthApp() Oauth2 {
 | 
			
		||||
	return authApp
 | 
			
		||||
func init() {
 | 
			
		||||
	persistence.Init()
 | 
			
		||||
 | 
			
		||||
	ioc.Register(new(oauth2AppImpl), ioc.WithComponentName("Oauth2App"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAuthApp() Oauth2 {
 | 
			
		||||
	return ioc.Get[Oauth2]("Oauth2App")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -14,27 +14,21 @@ type Oauth2 interface {
 | 
			
		||||
	Unbind(accountId uint64)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newAuthApp(oauthAccountRepo repository.Oauth2Account) Oauth2 {
 | 
			
		||||
	return &oauth2AppImpl{
 | 
			
		||||
		oauthAccountRepo: oauthAccountRepo,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type oauth2AppImpl struct {
 | 
			
		||||
	oauthAccountRepo repository.Oauth2Account
 | 
			
		||||
	Oauth2AccountRepo repository.Oauth2Account `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *oauth2AppImpl) GetOAuthAccount(condition *entity.Oauth2Account, cols ...string) error {
 | 
			
		||||
	return a.oauthAccountRepo.GetBy(condition, cols...)
 | 
			
		||||
	return a.Oauth2AccountRepo.GetBy(condition, cols...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *oauth2AppImpl) BindOAuthAccount(e *entity.Oauth2Account) error {
 | 
			
		||||
	if e.Id == 0 {
 | 
			
		||||
		return a.oauthAccountRepo.Insert(context.Background(), e)
 | 
			
		||||
		return a.Oauth2AccountRepo.Insert(context.Background(), e)
 | 
			
		||||
	}
 | 
			
		||||
	return a.oauthAccountRepo.UpdateById(context.Background(), e)
 | 
			
		||||
	return a.Oauth2AccountRepo.UpdateById(context.Background(), e)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *oauth2AppImpl) Unbind(accountId uint64) {
 | 
			
		||||
	a.oauthAccountRepo.DeleteByCond(context.Background(), &entity.Oauth2Account{AccountId: accountId})
 | 
			
		||||
	a.Oauth2AccountRepo.DeleteByCond(context.Background(), &entity.Oauth2Account{AccountId: accountId})
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,14 @@
 | 
			
		||||
package persistence
 | 
			
		||||
 | 
			
		||||
import "mayfly-go/internal/auth/domain/repository"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	authAccountRepo = newAuthAccountRepo()
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/auth/domain/repository"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func GetOauthAccountRepo() repository.Oauth2Account {
 | 
			
		||||
	return authAccountRepo
 | 
			
		||||
func Init() {
 | 
			
		||||
	ioc.Register(newAuthAccountRepo(), ioc.WithComponentName("Oauth2AccountRepo"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetOauthAccountRepo() repository.Oauth2Account {
 | 
			
		||||
	return ioc.Get[repository.Oauth2Account]("Oauth2AccountRepo")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,30 +2,22 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/auth/api"
 | 
			
		||||
	"mayfly-go/internal/auth/application"
 | 
			
		||||
	msgapp "mayfly-go/internal/msg/application"
 | 
			
		||||
	sysapp "mayfly-go/internal/sys/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func Init(router *gin.RouterGroup) {
 | 
			
		||||
	accountLogin := &api.AccountLogin{
 | 
			
		||||
		AccountApp: sysapp.GetAccountApp(),
 | 
			
		||||
		MsgApp:     msgapp.GetMsgApp(),
 | 
			
		||||
	}
 | 
			
		||||
	accountLogin := new(api.AccountLogin)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(accountLogin))
 | 
			
		||||
 | 
			
		||||
	ldapLogin := &api.LdapLogin{
 | 
			
		||||
		AccountApp: sysapp.GetAccountApp(),
 | 
			
		||||
		MsgApp:     msgapp.GetMsgApp(),
 | 
			
		||||
	}
 | 
			
		||||
	ldapLogin := new(api.LdapLogin)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(ldapLogin))
 | 
			
		||||
 | 
			
		||||
	oauth2Login := &api.Oauth2Login{
 | 
			
		||||
		Oauth2App:  application.GetAuthApp(),
 | 
			
		||||
		AccountApp: sysapp.GetAccountApp(),
 | 
			
		||||
		MsgApp:     msgapp.GetMsgApp(),
 | 
			
		||||
	}
 | 
			
		||||
	oauth2Login := new(api.Oauth2Login)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(oauth2Login))
 | 
			
		||||
 | 
			
		||||
	rg := router.Group("/auth")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -12,11 +12,11 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Index struct {
 | 
			
		||||
	TagApp     tagapp.TagTree
 | 
			
		||||
	MachineApp machineapp.Machine
 | 
			
		||||
	DbApp      dbapp.Db
 | 
			
		||||
	RedisApp   redisapp.Redis
 | 
			
		||||
	MongoApp   mongoapp.Mongo
 | 
			
		||||
	TagApp     tagapp.TagTree     `inject:"TagTreeApp"`
 | 
			
		||||
	MachineApp machineapp.Machine `inject:""`
 | 
			
		||||
	DbApp      dbapp.Db           `inject:""`
 | 
			
		||||
	RedisApp   redisapp.Redis     `inject:""`
 | 
			
		||||
	MongoApp   mongoapp.Mongo     `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (i *Index) Count(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,11 +2,8 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/common/api"
 | 
			
		||||
	dbapp "mayfly-go/internal/db/application"
 | 
			
		||||
	machineapp "mayfly-go/internal/machine/application"
 | 
			
		||||
	mongoapp "mayfly-go/internal/mongo/application"
 | 
			
		||||
	redisapp "mayfly-go/internal/redis/application"
 | 
			
		||||
	tagapp "mayfly-go/internal/tag/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -14,13 +11,8 @@ import (
 | 
			
		||||
 | 
			
		||||
func InitIndexRouter(router *gin.RouterGroup) {
 | 
			
		||||
	index := router.Group("common/index")
 | 
			
		||||
	i := &api.Index{
 | 
			
		||||
		TagApp:     tagapp.GetTagTreeApp(),
 | 
			
		||||
		MachineApp: machineapp.GetMachineApp(),
 | 
			
		||||
		DbApp:      dbapp.GetDbApp(),
 | 
			
		||||
		RedisApp:   redisapp.GetRedisApp(),
 | 
			
		||||
		MongoApp:   mongoapp.GetMongoApp(),
 | 
			
		||||
	}
 | 
			
		||||
	i := new(api.Index)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(i))
 | 
			
		||||
	{
 | 
			
		||||
		// 首页基本信息统计
 | 
			
		||||
		req.NewGet("count", i.Count).Group(index)
 | 
			
		||||
 
 | 
			
		||||
@@ -32,11 +32,11 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Db struct {
 | 
			
		||||
	InstanceApp  application.Instance
 | 
			
		||||
	DbApp        application.Db
 | 
			
		||||
	DbSqlExecApp application.DbSqlExec
 | 
			
		||||
	MsgApp       msgapp.Msg
 | 
			
		||||
	TagApp       tagapp.TagTree
 | 
			
		||||
	InstanceApp  application.Instance  `inject:"DbInstanceApp"`
 | 
			
		||||
	DbApp        application.Db        `inject:""`
 | 
			
		||||
	DbSqlExecApp application.DbSqlExec `inject:""`
 | 
			
		||||
	MsgApp       msgapp.Msg            `inject:""`
 | 
			
		||||
	TagApp       tagapp.TagTree        `inject:"TagTreeApp"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// @router /api/dbs [get]
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type DataSyncTask struct {
 | 
			
		||||
	DataSyncTaskApp application.DataSyncTask
 | 
			
		||||
	DataSyncTaskApp application.DataSyncTask `inject:"DbDataSyncTaskApp"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DataSyncTask) Tasks(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type DbSql struct {
 | 
			
		||||
	DbSqlApp application.DbSql
 | 
			
		||||
	DbSqlApp application.DbSql `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// @router /api/db/:dbId/sql [post]
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type DbSqlExec struct {
 | 
			
		||||
	DbSqlExecApp application.DbSqlExec
 | 
			
		||||
	DbSqlExecApp application.DbSqlExec `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *DbSqlExec) DbSqlExecs(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -16,8 +16,8 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Instance struct {
 | 
			
		||||
	InstanceApp application.Instance
 | 
			
		||||
	DbApp       application.Db
 | 
			
		||||
	InstanceApp application.Instance `inject:"DbInstanceApp"`
 | 
			
		||||
	DbApp       application.Db       `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Instances 获取数据库实例信息
 | 
			
		||||
 
 | 
			
		||||
@@ -4,21 +4,26 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"mayfly-go/internal/db/domain/repository"
 | 
			
		||||
	"mayfly-go/internal/db/infrastructure/persistence"
 | 
			
		||||
	tagapp "mayfly-go/internal/tag/application"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"sync"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	instanceApp  Instance
 | 
			
		||||
	dbApp        Db
 | 
			
		||||
	dbSqlExecApp DbSqlExec
 | 
			
		||||
	dbSqlApp     DbSql
 | 
			
		||||
	dbBackupApp  *DbBackupApp
 | 
			
		||||
	dbRestoreApp *DbRestoreApp
 | 
			
		||||
	dbBinlogApp  *DbBinlogApp
 | 
			
		||||
	dataSyncApp  DataSyncTask
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	persistence.Init()
 | 
			
		||||
 | 
			
		||||
	ioc.Register(new(instanceAppImpl), ioc.WithComponentName("DbInstanceApp"))
 | 
			
		||||
	ioc.Register(new(dbAppImpl), ioc.WithComponentName("DbApp"))
 | 
			
		||||
	ioc.Register(new(dbSqlExecAppImpl), ioc.WithComponentName("DbSqlExecApp"))
 | 
			
		||||
	ioc.Register(new(dbSqlAppImpl), ioc.WithComponentName("DbSqlApp"))
 | 
			
		||||
	ioc.Register(new(dataSyncAppImpl), ioc.WithComponentName("DbDataSyncTaskApp"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Init() {
 | 
			
		||||
	sync.OnceFunc(func() {
 | 
			
		||||
		repositories := &repository.Repositories{
 | 
			
		||||
@@ -31,13 +36,7 @@ func Init() {
 | 
			
		||||
			BinlogHistory:  persistence.NewDbBinlogHistoryRepo(),
 | 
			
		||||
		}
 | 
			
		||||
		var err error
 | 
			
		||||
		instanceRepo := persistence.GetInstanceRepo()
 | 
			
		||||
		instanceApp = newInstanceApp(instanceRepo)
 | 
			
		||||
		dbApp = newDbApp(persistence.GetDbRepo(), persistence.GetDbSqlRepo(), instanceApp, tagapp.GetTagTreeApp())
 | 
			
		||||
		dbSqlExecApp = newDbSqlExecApp(persistence.GetDbSqlExecRepo())
 | 
			
		||||
		dbSqlApp = newDbSqlApp(persistence.GetDbSqlRepo())
 | 
			
		||||
		dataSyncApp = newDataSyncApp(persistence.GetDataSyncTaskRepo(), persistence.GetDataSyncLogRepo())
 | 
			
		||||
 | 
			
		||||
		dbApp := GetDbApp()
 | 
			
		||||
		scheduler, err := newDbScheduler(repositories)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			panic(fmt.Sprintf("初始化 dbScheduler 失败: %v", err))
 | 
			
		||||
@@ -55,24 +54,24 @@ func Init() {
 | 
			
		||||
			panic(fmt.Sprintf("初始化 dbBinlogApp 失败: %v", err))
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		dataSyncApp.InitCronJob()
 | 
			
		||||
		GetDataSyncTaskApp().InitCronJob()
 | 
			
		||||
	})()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetInstanceApp() Instance {
 | 
			
		||||
	return instanceApp
 | 
			
		||||
	return ioc.Get[Instance]("DbInstance")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDbApp() Db {
 | 
			
		||||
	return dbApp
 | 
			
		||||
	return ioc.Get[Db]("DbApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDbSqlApp() DbSql {
 | 
			
		||||
	return dbSqlApp
 | 
			
		||||
	return ioc.Get[DbSql]("DbSqlApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDbSqlExecApp() DbSqlExec {
 | 
			
		||||
	return dbSqlExecApp
 | 
			
		||||
	return ioc.Get[DbSqlExec]("DbSqlExecApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDbBackupApp() *DbBackupApp {
 | 
			
		||||
@@ -88,5 +87,5 @@ func GetDbBinlogApp() *DbBinlogApp {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDataSyncTaskApp() DataSyncTask {
 | 
			
		||||
	return dataSyncApp
 | 
			
		||||
	return ioc.Get[DataSyncTask]("DbDataSyncTaskApp")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -40,22 +40,17 @@ type Db interface {
 | 
			
		||||
	GetDbConnByInstanceId(instanceId uint64) (*dbi.DbConn, error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newDbApp(dbRepo repository.Db, dbSqlRepo repository.DbSql, dbInstanceApp Instance, tagApp tagapp.TagTree) Db {
 | 
			
		||||
	app := &dbAppImpl{
 | 
			
		||||
		dbSqlRepo:     dbSqlRepo,
 | 
			
		||||
		dbInstanceApp: dbInstanceApp,
 | 
			
		||||
		tagApp:        tagApp,
 | 
			
		||||
	}
 | 
			
		||||
	app.Repo = dbRepo
 | 
			
		||||
	return app
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type dbAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.Db, repository.Db]
 | 
			
		||||
 | 
			
		||||
	dbSqlRepo     repository.DbSql
 | 
			
		||||
	dbInstanceApp Instance
 | 
			
		||||
	tagApp        tagapp.TagTree
 | 
			
		||||
	DbSqlRepo     repository.DbSql `inject:""`
 | 
			
		||||
	DbInstanceApp Instance         `inject:""`
 | 
			
		||||
	TagApp        tagapp.TagTree   `inject:"TagTreeApp"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 注入DbRepo
 | 
			
		||||
func (d *dbAppImpl) InjectDbRepo(repo repository.Db) {
 | 
			
		||||
	d.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 分页获取数据库信息列表
 | 
			
		||||
@@ -83,7 +78,7 @@ func (d *dbAppImpl) SaveDb(ctx context.Context, dbEntity *entity.Db, tagIds ...u
 | 
			
		||||
		return d.Tx(ctx, func(ctx context.Context) error {
 | 
			
		||||
			return d.Insert(ctx, dbEntity)
 | 
			
		||||
		}, func(ctx context.Context) error {
 | 
			
		||||
			return d.tagApp.RelateResource(ctx, resouceCode, consts.TagResourceTypeDb, tagIds)
 | 
			
		||||
			return d.TagApp.RelateResource(ctx, resouceCode, consts.TagResourceTypeDb, tagIds)
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -107,13 +102,13 @@ func (d *dbAppImpl) SaveDb(ctx context.Context, dbEntity *entity.Db, tagIds ...u
 | 
			
		||||
		// 关闭数据库连接
 | 
			
		||||
		dbm.CloseDb(dbEntity.Id, v)
 | 
			
		||||
		// 删除该库关联的所有sql记录
 | 
			
		||||
		d.dbSqlRepo.DeleteByCond(ctx, &entity.DbSql{DbId: dbId, Db: v})
 | 
			
		||||
		d.DbSqlRepo.DeleteByCond(ctx, &entity.DbSql{DbId: dbId, Db: v})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return d.Tx(ctx, func(ctx context.Context) error {
 | 
			
		||||
		return d.UpdateById(ctx, dbEntity)
 | 
			
		||||
	}, func(ctx context.Context) error {
 | 
			
		||||
		return d.tagApp.RelateResource(ctx, old.Code, consts.TagResourceTypeDb, tagIds)
 | 
			
		||||
		return d.TagApp.RelateResource(ctx, old.Code, consts.TagResourceTypeDb, tagIds)
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -134,10 +129,10 @@ func (d *dbAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
			
		||||
		},
 | 
			
		||||
		func(ctx context.Context) error {
 | 
			
		||||
			// 删除该库下用户保存的所有sql信息
 | 
			
		||||
			return d.dbSqlRepo.DeleteByCond(ctx, &entity.DbSql{DbId: id})
 | 
			
		||||
			return d.DbSqlRepo.DeleteByCond(ctx, &entity.DbSql{DbId: id})
 | 
			
		||||
		}, func(ctx context.Context) error {
 | 
			
		||||
			var tagIds []uint64
 | 
			
		||||
			return d.tagApp.RelateResource(ctx, db.Code, consts.TagResourceTypeDb, tagIds)
 | 
			
		||||
			return d.TagApp.RelateResource(ctx, db.Code, consts.TagResourceTypeDb, tagIds)
 | 
			
		||||
		})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -148,7 +143,7 @@ func (d *dbAppImpl) GetDbConn(dbId uint64, dbName string) (*dbi.DbConn, error) {
 | 
			
		||||
			return nil, errorx.NewBiz("数据库信息不存在")
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		instance, err := d.dbInstanceApp.GetById(new(entity.DbInstance), db.InstanceId)
 | 
			
		||||
		instance, err := d.DbInstanceApp.GetById(new(entity.DbInstance), db.InstanceId)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, errorx.NewBiz("数据库实例不存在")
 | 
			
		||||
		}
 | 
			
		||||
@@ -169,7 +164,7 @@ func (d *dbAppImpl) GetDbConn(dbId uint64, dbName string) (*dbi.DbConn, error) {
 | 
			
		||||
		if err := instance.PwdDecrypt(); err != nil {
 | 
			
		||||
			return nil, errorx.NewBiz(err.Error())
 | 
			
		||||
		}
 | 
			
		||||
		return toDbInfo(instance, dbId, dbName, d.tagApp.ListTagPathByResource(consts.TagResourceTypeDb, db.Code)...), nil
 | 
			
		||||
		return toDbInfo(instance, dbId, dbName, d.TagApp.ListTagPathByResource(consts.TagResourceTypeDb, db.Code)...), nil
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -38,17 +38,14 @@ type DataSyncTask interface {
 | 
			
		||||
	GetTaskLogList(condition *entity.DataSyncLogQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newDataSyncApp(dataSyncRepo repository.DataSyncTask, dataSyncLogRepo repository.DataSyncLog) DataSyncTask {
 | 
			
		||||
	app := new(dataSyncAppImpl)
 | 
			
		||||
	app.Repo = dataSyncRepo
 | 
			
		||||
	app.dataSyncLogRepo = dataSyncLogRepo
 | 
			
		||||
	return app
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type dataSyncAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.DataSyncTask, repository.DataSyncTask]
 | 
			
		||||
 | 
			
		||||
	dataSyncLogRepo repository.DataSyncLog
 | 
			
		||||
	DbDataSyncLogRepo repository.DataSyncLog `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *dataSyncAppImpl) InjectDbDataSyncTaskRepo(repo repository.DataSyncTask) {
 | 
			
		||||
	d.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *dataSyncAppImpl) GetPageList(condition *entity.DataSyncTaskQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
@@ -328,7 +325,7 @@ func (app *dataSyncAppImpl) endRunning(taskEntity *entity.DataSyncTask, log *ent
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *dataSyncAppImpl) saveLog(log *entity.DataSyncLog) {
 | 
			
		||||
	app.dataSyncLogRepo.Save(context.Background(), log)
 | 
			
		||||
	app.DbDataSyncLogRepo.Save(context.Background(), log)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *dataSyncAppImpl) InitCronJob() {
 | 
			
		||||
@@ -374,5 +371,5 @@ func (app *dataSyncAppImpl) InitCronJob() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (app *dataSyncAppImpl) GetTaskLogList(condition *entity.DataSyncLogQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
	return app.dataSyncLogRepo.GetTaskLogList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
	return app.DbDataSyncLogRepo.GetTaskLogList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -33,7 +33,7 @@ type dbScheduler struct {
 | 
			
		||||
 | 
			
		||||
func newDbScheduler(repositories *repository.Repositories) (*dbScheduler, error) {
 | 
			
		||||
	scheduler := &dbScheduler{
 | 
			
		||||
		dbApp:              dbApp,
 | 
			
		||||
		dbApp:              GetDbApp(),
 | 
			
		||||
		backupRepo:         repositories.Backup,
 | 
			
		||||
		backupHistoryRepo:  repositories.BackupHistory,
 | 
			
		||||
		restoreRepo:        repositories.Restore,
 | 
			
		||||
 
 | 
			
		||||
@@ -14,8 +14,7 @@ type dbSqlAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.DbSql, repository.DbSql]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newDbSqlApp(dbSqlRepo repository.DbSql) DbSql {
 | 
			
		||||
	app := new(dbSqlAppImpl)
 | 
			
		||||
	app.Repo = dbSqlRepo
 | 
			
		||||
	return app
 | 
			
		||||
// 注入DbSqlRepo
 | 
			
		||||
func (d *dbSqlAppImpl) InjectDbSqlRepo(repo repository.DbSql) {
 | 
			
		||||
	d.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -56,14 +56,8 @@ type DbSqlExec interface {
 | 
			
		||||
	GetPageList(condition *entity.DbSqlExecQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newDbSqlExecApp(dbExecSqlRepo repository.DbSqlExec) DbSqlExec {
 | 
			
		||||
	return &dbSqlExecAppImpl{
 | 
			
		||||
		dbSqlExecRepo: dbExecSqlRepo,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type dbSqlExecAppImpl struct {
 | 
			
		||||
	dbSqlExecRepo repository.DbSqlExec
 | 
			
		||||
	DbSqlExecRepo repository.DbSqlExec `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func createSqlExecRecord(ctx context.Context, execSqlReq *DbSqlExecReq) *entity.DbSqlExec {
 | 
			
		||||
@@ -144,23 +138,23 @@ func (d *dbSqlExecAppImpl) Exec(ctx context.Context, execSqlReq *DbSqlExecReq) (
 | 
			
		||||
// 保存sql执行记录,如果是查询类则根据系统配置判断是否保存
 | 
			
		||||
func (d *dbSqlExecAppImpl) saveSqlExecLog(isQuery bool, dbSqlExecRecord *entity.DbSqlExec) {
 | 
			
		||||
	if !isQuery {
 | 
			
		||||
		d.dbSqlExecRepo.Insert(context.TODO(), dbSqlExecRecord)
 | 
			
		||||
		d.DbSqlExecRepo.Insert(context.TODO(), dbSqlExecRecord)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if config.GetDbSaveQuerySql() {
 | 
			
		||||
		dbSqlExecRecord.Table = "-"
 | 
			
		||||
		dbSqlExecRecord.OldValue = "-"
 | 
			
		||||
		dbSqlExecRecord.Type = entity.DbSqlExecTypeQuery
 | 
			
		||||
		d.dbSqlExecRepo.Insert(context.TODO(), dbSqlExecRecord)
 | 
			
		||||
		d.DbSqlExecRepo.Insert(context.TODO(), dbSqlExecRecord)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *dbSqlExecAppImpl) DeleteBy(ctx context.Context, condition *entity.DbSqlExec) {
 | 
			
		||||
	d.dbSqlExecRepo.DeleteByCond(ctx, condition)
 | 
			
		||||
	d.DbSqlExecRepo.DeleteByCond(ctx, condition)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (d *dbSqlExecAppImpl) GetPageList(condition *entity.DbSqlExecQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
	return d.dbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
	return d.DbSqlExecRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func doSelect(ctx context.Context, selectStmt *sqlparser.Select, execSqlReq *DbSqlExecReq) (*DbSqlExecRes, error) {
 | 
			
		||||
 
 | 
			
		||||
@@ -30,16 +30,15 @@ type Instance interface {
 | 
			
		||||
	GetDatabases(entity *entity.DbInstance) ([]string, error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newInstanceApp(instanceRepo repository.Instance) Instance {
 | 
			
		||||
	app := new(instanceAppImpl)
 | 
			
		||||
	app.Repo = instanceRepo
 | 
			
		||||
	return app
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type instanceAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.DbInstance, repository.Instance]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 注入DbInstanceRepo
 | 
			
		||||
func (i *instanceAppImpl) InjectDbInstanceRepo(repo repository.Instance) {
 | 
			
		||||
	i.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetPageList 分页获取数据库实例
 | 
			
		||||
func (app *instanceAppImpl) GetPageList(condition *entity.InstanceQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
	return app.GetRepo().GetInstanceList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,46 +1,49 @@
 | 
			
		||||
package persistence
 | 
			
		||||
 | 
			
		||||
import "mayfly-go/internal/db/domain/repository"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	instanceRepo         repository.Instance     = newInstanceRepo()
 | 
			
		||||
	dbRepo               repository.Db           = newDbRepo()
 | 
			
		||||
	dbSqlRepo            repository.DbSql        = newDbSqlRepo()
 | 
			
		||||
	dbSqlExecRepo        repository.DbSqlExec    = newDbSqlExecRepo()
 | 
			
		||||
	dbBackupHistoryRepo                          = NewDbBackupHistoryRepo()
 | 
			
		||||
	dbRestoreHistoryRepo                         = NewDbRestoreHistoryRepo()
 | 
			
		||||
	dbDataSyncTaskRepo   repository.DataSyncTask = newDataSyncTaskRepo()
 | 
			
		||||
	dbDataSyncLogRepo    repository.DataSyncLog  = newDataSyncLogRepo()
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/db/domain/repository"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func Init() {
 | 
			
		||||
	ioc.Register(newInstanceRepo(), ioc.WithComponentName("DbInstanceRepo"))
 | 
			
		||||
	ioc.Register(newDbRepo(), ioc.WithComponentName("DbRepo"))
 | 
			
		||||
	ioc.Register(newDbSqlRepo(), ioc.WithComponentName("DbSqlRepo"))
 | 
			
		||||
	ioc.Register(newDbSqlExecRepo(), ioc.WithComponentName("DbSqlExecRepo"))
 | 
			
		||||
	ioc.Register(NewDbBackupHistoryRepo(), ioc.WithComponentName("DbBackupHistoryRepo"))
 | 
			
		||||
	ioc.Register(NewDbRestoreHistoryRepo(), ioc.WithComponentName("DbRestoreHistoryRepo"))
 | 
			
		||||
	ioc.Register(newDataSyncTaskRepo(), ioc.WithComponentName("DbDataSyncTaskRepo"))
 | 
			
		||||
	ioc.Register(newDataSyncLogRepo(), ioc.WithComponentName("DbDataSyncLogRepo"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetInstanceRepo() repository.Instance {
 | 
			
		||||
	return instanceRepo
 | 
			
		||||
	return ioc.Get[repository.Instance]("DbInstanceRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDbRepo() repository.Db {
 | 
			
		||||
	return dbRepo
 | 
			
		||||
	return ioc.Get[repository.Db]("DbRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDbSqlRepo() repository.DbSql {
 | 
			
		||||
	return dbSqlRepo
 | 
			
		||||
	return ioc.Get[repository.DbSql]("DbSqlRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDbSqlExecRepo() repository.DbSqlExec {
 | 
			
		||||
	return dbSqlExecRepo
 | 
			
		||||
	return ioc.Get[repository.DbSqlExec]("DbSqlExecRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDbBackupHistoryRepo() repository.DbBackupHistory {
 | 
			
		||||
	return dbBackupHistoryRepo
 | 
			
		||||
	return ioc.Get[repository.DbBackupHistory]("DbBackupHistoryRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDbRestoreHistoryRepo() repository.DbRestoreHistory {
 | 
			
		||||
	return dbRestoreHistoryRepo
 | 
			
		||||
	return ioc.Get[repository.DbRestoreHistory]("DbRestoreHistoryRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDataSyncLogRepo() repository.DataSyncLog {
 | 
			
		||||
	return dbDataSyncLogRepo
 | 
			
		||||
	return ioc.Get[repository.DataSyncLog]("DataSyncLogRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetDataSyncTaskRepo() repository.DataSyncTask {
 | 
			
		||||
	return dbDataSyncTaskRepo
 | 
			
		||||
	return ioc.Get[repository.DataSyncTask]("DataSyncTaskRepo")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,8 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/db/api"
 | 
			
		||||
	"mayfly-go/internal/db/application"
 | 
			
		||||
	msgapp "mayfly-go/internal/msg/application"
 | 
			
		||||
	tagapp "mayfly-go/internal/tag/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -13,13 +12,8 @@ import (
 | 
			
		||||
func InitDbRouter(router *gin.RouterGroup) {
 | 
			
		||||
	db := router.Group("dbs")
 | 
			
		||||
 | 
			
		||||
	d := &api.Db{
 | 
			
		||||
		InstanceApp:  application.GetInstanceApp(),
 | 
			
		||||
		DbApp:        application.GetDbApp(),
 | 
			
		||||
		DbSqlExecApp: application.GetDbSqlExecApp(),
 | 
			
		||||
		MsgApp:       msgapp.GetMsgApp(),
 | 
			
		||||
		TagApp:       tagapp.GetTagTreeApp(),
 | 
			
		||||
	}
 | 
			
		||||
	d := new(api.Db)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(d))
 | 
			
		||||
 | 
			
		||||
	reqs := [...]*req.Conf{
 | 
			
		||||
		// 获取数据库列表
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,8 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/db/api"
 | 
			
		||||
	"mayfly-go/internal/db/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -11,9 +12,8 @@ import (
 | 
			
		||||
func InitDbDataSyncRouter(router *gin.RouterGroup) {
 | 
			
		||||
	instances := router.Group("/datasync/tasks")
 | 
			
		||||
 | 
			
		||||
	d := &api.DataSyncTask{
 | 
			
		||||
		DataSyncTaskApp: application.GetDataSyncTaskApp(),
 | 
			
		||||
	}
 | 
			
		||||
	d := new(api.DataSyncTask)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(d))
 | 
			
		||||
 | 
			
		||||
	reqs := [...]*req.Conf{
 | 
			
		||||
		// 获取任务列表 /datasync
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,8 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/db/api"
 | 
			
		||||
	"mayfly-go/internal/db/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -11,9 +12,8 @@ import (
 | 
			
		||||
func InitDbSqlRouter(router *gin.RouterGroup) {
 | 
			
		||||
	db := router.Group("dbs")
 | 
			
		||||
 | 
			
		||||
	dbSql := &api.DbSql{
 | 
			
		||||
		DbSqlApp: application.GetDbSqlApp(),
 | 
			
		||||
	}
 | 
			
		||||
	dbSql := new(api.DbSql)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(dbSql))
 | 
			
		||||
 | 
			
		||||
	reqs := [...]*req.Conf{
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,8 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/db/api"
 | 
			
		||||
	"mayfly-go/internal/db/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -11,9 +12,8 @@ import (
 | 
			
		||||
func InitDbSqlExecRouter(router *gin.RouterGroup) {
 | 
			
		||||
	db := router.Group("/dbs/:dbId/sql-execs")
 | 
			
		||||
 | 
			
		||||
	d := &api.DbSqlExec{
 | 
			
		||||
		DbSqlExecApp: application.GetDbSqlExecApp(),
 | 
			
		||||
	}
 | 
			
		||||
	d := new(api.DbSqlExec)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(d))
 | 
			
		||||
 | 
			
		||||
	// 获取所有数据库sql执行记录列表
 | 
			
		||||
	req.NewGet("", d.DbSqlExecs).Group(db)
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,8 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/db/api"
 | 
			
		||||
	"mayfly-go/internal/db/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -11,10 +12,8 @@ import (
 | 
			
		||||
func InitInstanceRouter(router *gin.RouterGroup) {
 | 
			
		||||
	instances := router.Group("/instances")
 | 
			
		||||
 | 
			
		||||
	d := &api.Instance{
 | 
			
		||||
		InstanceApp: application.GetInstanceApp(),
 | 
			
		||||
		DbApp:       application.GetDbApp(),
 | 
			
		||||
	}
 | 
			
		||||
	d := new(api.Instance)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(d))
 | 
			
		||||
 | 
			
		||||
	reqs := [...]*req.Conf{
 | 
			
		||||
		// 获取数据库列表
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type AuthCert struct {
 | 
			
		||||
	AuthCertApp application.AuthCert
 | 
			
		||||
	AuthCertApp application.AuthCert `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (ac *AuthCert) BaseAuthCerts(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -29,9 +29,9 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Machine struct {
 | 
			
		||||
	MachineApp       application.Machine
 | 
			
		||||
	MachineTermOpApp application.MachineTermOp
 | 
			
		||||
	TagApp           tagapp.TagTree
 | 
			
		||||
	MachineApp       application.Machine       `inject:""`
 | 
			
		||||
	MachineTermOpApp application.MachineTermOp `inject:""`
 | 
			
		||||
	TagApp           tagapp.TagTree            `inject:"TagTreeApp"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *Machine) Machines(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type MachineCronJob struct {
 | 
			
		||||
	MachineCronJobApp application.MachineCronJob
 | 
			
		||||
	MachineCronJobApp application.MachineCronJob `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *MachineCronJob) MachineCronJobs(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -31,8 +31,8 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type MachineFile struct {
 | 
			
		||||
	MachineFileApp application.MachineFile
 | 
			
		||||
	MsgApp         msgapp.Msg
 | 
			
		||||
	MachineFileApp application.MachineFile `inject:""`
 | 
			
		||||
	MsgApp         msgapp.Msg              `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
 
 | 
			
		||||
@@ -19,9 +19,9 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type MachineScript struct {
 | 
			
		||||
	MachineScriptApp application.MachineScript
 | 
			
		||||
	MachineApp       application.Machine
 | 
			
		||||
	TagApp           tagapp.TagTree
 | 
			
		||||
	MachineScriptApp application.MachineScript `inject:""`
 | 
			
		||||
	MachineApp       application.Machine       `inject:""`
 | 
			
		||||
	TagApp           tagapp.TagTree            `inject:"TagTreeApp"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *MachineScript) MachineScripts(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,58 +2,40 @@ package application
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/machine/infrastructure/persistence"
 | 
			
		||||
	tagapp "mayfly-go/internal/tag/application"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	machineApp Machine = newMachineApp(
 | 
			
		||||
		persistence.GetMachineRepo(),
 | 
			
		||||
		GetAuthCertApp(),
 | 
			
		||||
		tagapp.GetTagTreeApp(),
 | 
			
		||||
	)
 | 
			
		||||
func init() {
 | 
			
		||||
	persistence.Init()
 | 
			
		||||
 | 
			
		||||
	machineFileApp MachineFile = newMachineFileApp(
 | 
			
		||||
		persistence.GetMachineFileRepo(),
 | 
			
		||||
		GetMachineApp(),
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	machineScriptApp MachineScript = newMachineScriptApp(
 | 
			
		||||
		persistence.GetMachineScriptRepo(),
 | 
			
		||||
		GetMachineApp(),
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	authCertApp AuthCert = newAuthCertApp(persistence.GetAuthCertRepo())
 | 
			
		||||
 | 
			
		||||
	machineCropJobApp MachineCronJob = newMachineCronJobApp(
 | 
			
		||||
		persistence.GetMachineCronJobRepo(),
 | 
			
		||||
		persistence.GetMachineCronJobRelateRepo(),
 | 
			
		||||
		persistence.GetMachineCronJobExecRepo(),
 | 
			
		||||
		GetMachineApp(),
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	machineTermOpApp MachineTermOp = newMachineTermOpApp(persistence.GetMachineTermOpRepo())
 | 
			
		||||
)
 | 
			
		||||
	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"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMachineApp() Machine {
 | 
			
		||||
	return machineApp
 | 
			
		||||
	return ioc.Get[Machine]("MachineApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMachineFileApp() MachineFile {
 | 
			
		||||
	return machineFileApp
 | 
			
		||||
	return ioc.Get[MachineFile]("MachineFileApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMachineScriptApp() MachineScript {
 | 
			
		||||
	return machineScriptApp
 | 
			
		||||
	return ioc.Get[MachineScript]("MachineScriptApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAuthCertApp() AuthCert {
 | 
			
		||||
	return authCertApp
 | 
			
		||||
	return ioc.Get[AuthCert]("AuthCertApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMachineCronJobApp() MachineCronJob {
 | 
			
		||||
	return machineCropJobApp
 | 
			
		||||
	return ioc.Get[MachineCronJob]("MachineCronJobApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMachineTermOpApp() MachineTermOp {
 | 
			
		||||
	return machineTermOpApp
 | 
			
		||||
	return ioc.Get[MachineTermOp]("MachineTermOpApp")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,16 +19,15 @@ type AuthCert interface {
 | 
			
		||||
	GetByIds(ids ...uint64) []*entity.AuthCert
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newAuthCertApp(authCertRepo repository.AuthCert) AuthCert {
 | 
			
		||||
	return &authCertAppImpl{
 | 
			
		||||
		base.AppImpl[*entity.AuthCert, repository.AuthCert]{Repo: authCertRepo},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -49,24 +49,16 @@ type Machine interface {
 | 
			
		||||
	GetMachineStats(machineId uint64) (*mcm.Stats, error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newMachineApp(machineRepo repository.Machine,
 | 
			
		||||
	authCertApp AuthCert,
 | 
			
		||||
	tagApp tagapp.TagTree) Machine {
 | 
			
		||||
	app := &machineAppImpl{
 | 
			
		||||
		authCertApp: authCertApp,
 | 
			
		||||
		tagApp:      tagApp,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	app.Repo = machineRepo
 | 
			
		||||
	return app
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type machineAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.Machine, repository.Machine]
 | 
			
		||||
 | 
			
		||||
	authCertApp AuthCert
 | 
			
		||||
	AuthCertApp AuthCert       `inject:""`
 | 
			
		||||
	TagApp      tagapp.TagTree `inject:"TagTreeApp"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
	tagApp tagapp.TagTree
 | 
			
		||||
// 注入MachineRepo
 | 
			
		||||
func (m *machineAppImpl) InjectMachineRepo(repo repository.Machine) {
 | 
			
		||||
	m.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 分页获取机器信息列表
 | 
			
		||||
@@ -99,7 +91,7 @@ func (m *machineAppImpl) SaveMachine(ctx context.Context, me *entity.Machine, ta
 | 
			
		||||
		return m.Tx(ctx, func(ctx context.Context) error {
 | 
			
		||||
			return m.Insert(ctx, me)
 | 
			
		||||
		}, func(ctx context.Context) error {
 | 
			
		||||
			return m.tagApp.RelateResource(ctx, resouceCode, consts.TagResourceTypeMachine, tagIds)
 | 
			
		||||
			return m.TagApp.RelateResource(ctx, resouceCode, consts.TagResourceTypeMachine, tagIds)
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -117,7 +109,7 @@ func (m *machineAppImpl) SaveMachine(ctx context.Context, me *entity.Machine, ta
 | 
			
		||||
	return m.Tx(ctx, func(ctx context.Context) error {
 | 
			
		||||
		return m.UpdateById(ctx, me)
 | 
			
		||||
	}, func(ctx context.Context) error {
 | 
			
		||||
		return m.tagApp.RelateResource(ctx, oldMachine.Code, consts.TagResourceTypeMachine, tagIds)
 | 
			
		||||
		return m.TagApp.RelateResource(ctx, oldMachine.Code, consts.TagResourceTypeMachine, tagIds)
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -162,7 +154,7 @@ func (m *machineAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
			
		||||
			return m.DeleteById(ctx, id)
 | 
			
		||||
		}, func(ctx context.Context) error {
 | 
			
		||||
			var tagIds []uint64
 | 
			
		||||
			return m.tagApp.RelateResource(ctx, machine.Code, consts.TagResourceTypeMachine, tagIds)
 | 
			
		||||
			return m.TagApp.RelateResource(ctx, machine.Code, consts.TagResourceTypeMachine, tagIds)
 | 
			
		||||
		})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -235,11 +227,11 @@ func (m *machineAppImpl) toMachineInfo(me *entity.Machine) (*mcm.MachineInfo, er
 | 
			
		||||
	mi.Ip = me.Ip
 | 
			
		||||
	mi.Port = me.Port
 | 
			
		||||
	mi.Username = me.Username
 | 
			
		||||
	mi.TagPath = m.tagApp.ListTagPathByResource(consts.TagResourceTypeMachine, me.Code)
 | 
			
		||||
	mi.TagPath = m.TagApp.ListTagPathByResource(consts.TagResourceTypeMachine, me.Code)
 | 
			
		||||
	mi.EnableRecorder = me.EnableRecorder
 | 
			
		||||
 | 
			
		||||
	if me.UseAuthCert() {
 | 
			
		||||
		ac, err := m.authCertApp.GetById(new(entity.AuthCert), uint64(me.AuthCertId))
 | 
			
		||||
		ac, err := m.AuthCertApp.GetById(new(entity.AuthCert), uint64(me.AuthCertId))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, errorx.NewBiz("授权凭证信息已不存在,请重新关联")
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -50,41 +50,31 @@ type MachineCronJob interface {
 | 
			
		||||
	RunCronJob(key string)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type machineCropJobAppImpl struct {
 | 
			
		||||
type machineCronJobAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.MachineCronJob, repository.MachineCronJob]
 | 
			
		||||
 | 
			
		||||
	machineCropJobRelateRepo repository.MachineCronJobRelate
 | 
			
		||||
	machineCropJobExecRepo   repository.MachineCronJobExec
 | 
			
		||||
	machineApp               Machine
 | 
			
		||||
	MachineCronJobRelateRepo repository.MachineCronJobRelate `inject:""`
 | 
			
		||||
	MachineCronJobExecRepo   repository.MachineCronJobExec   `inject:""`
 | 
			
		||||
	MachineApp               Machine                         `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newMachineCronJobApp(
 | 
			
		||||
	machineCropJobRepo repository.MachineCronJob,
 | 
			
		||||
	machineCropJobRelateRepo repository.MachineCronJobRelate,
 | 
			
		||||
	machineCropJobExecRepo repository.MachineCronJobExec,
 | 
			
		||||
	machineApp Machine,
 | 
			
		||||
) MachineCronJob {
 | 
			
		||||
	app := &machineCropJobAppImpl{
 | 
			
		||||
		machineCropJobRelateRepo: machineCropJobRelateRepo,
 | 
			
		||||
		machineCropJobExecRepo:   machineCropJobExecRepo,
 | 
			
		||||
		machineApp:               machineApp,
 | 
			
		||||
	}
 | 
			
		||||
	app.Repo = machineCropJobRepo
 | 
			
		||||
	return app
 | 
			
		||||
// 注入MachineCronJobRepo
 | 
			
		||||
func (m *machineCronJobAppImpl) InjectMachineCronJobRepo(repo repository.MachineCronJob) {
 | 
			
		||||
	m.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 分页获取机器脚本任务列表
 | 
			
		||||
func (m *machineCropJobAppImpl) GetPageList(condition *entity.MachineCronJob, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
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 *machineCropJobAppImpl) GetExecPageList(condition *entity.MachineCronJobExec, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
	return m.machineCropJobExecRepo.GetPageList(condition, pageParam, toEntity, 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 *machineCropJobAppImpl) SaveMachineCronJob(ctx context.Context, mcj *entity.MachineCronJob) (uint64, error) {
 | 
			
		||||
func (m *machineCronJobAppImpl) SaveMachineCronJob(ctx context.Context, mcj *entity.MachineCronJob) (uint64, error) {
 | 
			
		||||
	// 更新操作
 | 
			
		||||
	if mcj.Id != 0 {
 | 
			
		||||
		m.UpdateById(ctx, mcj)
 | 
			
		||||
@@ -104,22 +94,22 @@ func (m *machineCropJobAppImpl) SaveMachineCronJob(ctx context.Context, mcj *ent
 | 
			
		||||
	return mcj.Id, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineCropJobAppImpl) Delete(ctx context.Context, id uint64) {
 | 
			
		||||
func (m *machineCronJobAppImpl) Delete(ctx context.Context, id uint64) {
 | 
			
		||||
	m.DeleteById(ctx, id)
 | 
			
		||||
	m.machineCropJobExecRepo.DeleteByCond(ctx, &entity.MachineCronJobExec{CronJobId: id})
 | 
			
		||||
	m.machineCropJobRelateRepo.DeleteByCond(ctx, &entity.MachineCronJobRelate{CronJobId: id})
 | 
			
		||||
	m.MachineCronJobExecRepo.DeleteByCond(ctx, &entity.MachineCronJobExec{CronJobId: id})
 | 
			
		||||
	m.MachineCronJobRelateRepo.DeleteByCond(ctx, &entity.MachineCronJobRelate{CronJobId: id})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineCropJobAppImpl) GetRelateMachineIds(cronJobId uint64) []uint64 {
 | 
			
		||||
	return m.machineCropJobRelateRepo.GetMachineIds(cronJobId)
 | 
			
		||||
func (m *machineCronJobAppImpl) GetRelateMachineIds(cronJobId uint64) []uint64 {
 | 
			
		||||
	return m.MachineCronJobRelateRepo.GetMachineIds(cronJobId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineCropJobAppImpl) GetRelateCronJobIds(machineId uint64) []uint64 {
 | 
			
		||||
	return m.machineCropJobRelateRepo.GetCronJobIds(machineId)
 | 
			
		||||
func (m *machineCronJobAppImpl) GetRelateCronJobIds(machineId uint64) []uint64 {
 | 
			
		||||
	return m.MachineCronJobRelateRepo.GetCronJobIds(machineId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineCropJobAppImpl) CronJobRelateMachines(ctx context.Context, cronJobId uint64, machineIds []uint64) {
 | 
			
		||||
	oldMachineIds := m.machineCropJobRelateRepo.GetMachineIds(cronJobId)
 | 
			
		||||
func (m *machineCronJobAppImpl) CronJobRelateMachines(ctx context.Context, cronJobId uint64, machineIds []uint64) {
 | 
			
		||||
	oldMachineIds := m.MachineCronJobRelateRepo.GetMachineIds(cronJobId)
 | 
			
		||||
	addIds, delIds, _ := collx.ArrayCompare[uint64](machineIds, oldMachineIds)
 | 
			
		||||
	addVals := make([]*entity.MachineCronJobRelate, 0)
 | 
			
		||||
 | 
			
		||||
@@ -129,20 +119,20 @@ func (m *machineCropJobAppImpl) CronJobRelateMachines(ctx context.Context, cronJ
 | 
			
		||||
			CronJobId: cronJobId,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	m.machineCropJobRelateRepo.BatchInsert(ctx, addVals)
 | 
			
		||||
	m.MachineCronJobRelateRepo.BatchInsert(ctx, addVals)
 | 
			
		||||
 | 
			
		||||
	for _, delId := range delIds {
 | 
			
		||||
		m.machineCropJobRelateRepo.DeleteByCond(ctx, &entity.MachineCronJobRelate{CronJobId: cronJobId, MachineId: delId})
 | 
			
		||||
		m.MachineCronJobRelateRepo.DeleteByCond(ctx, &entity.MachineCronJobRelate{CronJobId: cronJobId, MachineId: delId})
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineCropJobAppImpl) MachineRelateCronJobs(ctx context.Context, machineId uint64, cronJobs []uint64) {
 | 
			
		||||
func (m *machineCronJobAppImpl) MachineRelateCronJobs(ctx context.Context, machineId uint64, cronJobs []uint64) {
 | 
			
		||||
	if len(cronJobs) == 0 {
 | 
			
		||||
		m.machineCropJobRelateRepo.DeleteByCond(ctx, &entity.MachineCronJobRelate{MachineId: machineId})
 | 
			
		||||
		m.MachineCronJobRelateRepo.DeleteByCond(ctx, &entity.MachineCronJobRelate{MachineId: machineId})
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	oldCronIds := m.machineCropJobRelateRepo.GetCronJobIds(machineId)
 | 
			
		||||
	oldCronIds := m.MachineCronJobRelateRepo.GetCronJobIds(machineId)
 | 
			
		||||
	addIds, delIds, _ := collx.ArrayCompare[uint64](cronJobs, oldCronIds)
 | 
			
		||||
	addVals := make([]*entity.MachineCronJobRelate, 0)
 | 
			
		||||
 | 
			
		||||
@@ -152,14 +142,14 @@ func (m *machineCropJobAppImpl) MachineRelateCronJobs(ctx context.Context, machi
 | 
			
		||||
			CronJobId: addId,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	m.machineCropJobRelateRepo.BatchInsert(ctx, addVals)
 | 
			
		||||
	m.MachineCronJobRelateRepo.BatchInsert(ctx, addVals)
 | 
			
		||||
 | 
			
		||||
	for _, delId := range delIds {
 | 
			
		||||
		m.machineCropJobRelateRepo.DeleteByCond(ctx, &entity.MachineCronJobRelate{CronJobId: delId, MachineId: machineId})
 | 
			
		||||
		m.MachineCronJobRelateRepo.DeleteByCond(ctx, &entity.MachineCronJobRelate{CronJobId: delId, MachineId: machineId})
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineCropJobAppImpl) InitCronJob() {
 | 
			
		||||
func (m *machineCronJobAppImpl) InitCronJob() {
 | 
			
		||||
	defer func() {
 | 
			
		||||
		if err := recover(); err != nil {
 | 
			
		||||
			logx.ErrorTrace("机器计划任务初始化失败: %s", err.(error))
 | 
			
		||||
@@ -192,7 +182,7 @@ func (m *machineCropJobAppImpl) InitCronJob() {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineCropJobAppImpl) RunCronJob(key string) {
 | 
			
		||||
func (m *machineCronJobAppImpl) RunCronJob(key string) {
 | 
			
		||||
	// 简单使用redis分布式锁防止多实例同一时刻重复执行
 | 
			
		||||
	if lock := rediscli.NewLock(key, 30*time.Second); lock != nil {
 | 
			
		||||
		if !lock.Lock() {
 | 
			
		||||
@@ -209,13 +199,13 @@ func (m *machineCropJobAppImpl) RunCronJob(key string) {
 | 
			
		||||
		scheduler.RemoveByKey(key)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	machienIds := m.machineCropJobRelateRepo.GetMachineIds(cronJob.Id)
 | 
			
		||||
	machienIds := m.MachineCronJobRelateRepo.GetMachineIds(cronJob.Id)
 | 
			
		||||
	for _, machineId := range machienIds {
 | 
			
		||||
		go m.runCronJob0(machineId, cronJob)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineCropJobAppImpl) addCronJob(mcj *entity.MachineCronJob) {
 | 
			
		||||
func (m *machineCronJobAppImpl) addCronJob(mcj *entity.MachineCronJob) {
 | 
			
		||||
	var key string
 | 
			
		||||
	isDisable := mcj.Status == entity.MachineCronJobStatusDisable
 | 
			
		||||
	if mcj.Id == 0 {
 | 
			
		||||
@@ -237,11 +227,11 @@ func (m *machineCropJobAppImpl) addCronJob(mcj *entity.MachineCronJob) {
 | 
			
		||||
		go m.RunCronJob(key)
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
func (m *machineCropJobAppImpl) runCronJob0(mid uint64, cronJob *entity.MachineCronJob) {
 | 
			
		||||
func (m *machineCronJobAppImpl) runCronJob0(mid uint64, cronJob *entity.MachineCronJob) {
 | 
			
		||||
	defer func() {
 | 
			
		||||
		if err := recover(); err != nil {
 | 
			
		||||
			res := anyx.ToString(err)
 | 
			
		||||
			m.machineCropJobExecRepo.Insert(context.TODO(), &entity.MachineCronJobExec{
 | 
			
		||||
			m.MachineCronJobExecRepo.Insert(context.TODO(), &entity.MachineCronJobExec{
 | 
			
		||||
				MachineId: mid,
 | 
			
		||||
				CronJobId: cronJob.Id,
 | 
			
		||||
				ExecTime:  time.Now(),
 | 
			
		||||
@@ -252,7 +242,7 @@ func (m *machineCropJobAppImpl) runCronJob0(mid uint64, cronJob *entity.MachineC
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	machineCli, err := m.machineApp.GetCli(uint64(mid))
 | 
			
		||||
	machineCli, err := m.MachineApp.GetCli(uint64(mid))
 | 
			
		||||
	biz.ErrIsNilAppendErr(err, "获取客户端连接失败: %s")
 | 
			
		||||
	res, err := machineCli.Run(cronJob.Script)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
@@ -281,5 +271,5 @@ func (m *machineCropJobAppImpl) runCronJob0(mid uint64, cronJob *entity.MachineC
 | 
			
		||||
		execRes.Status = entity.MachineCronJobExecStatusError
 | 
			
		||||
	}
 | 
			
		||||
	// 保存执行记录
 | 
			
		||||
	m.machineCropJobExecRepo.Insert(context.TODO(), execRes)
 | 
			
		||||
	m.MachineCronJobExecRepo.Insert(context.TODO(), execRes)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -72,42 +72,40 @@ type MachineFile interface {
 | 
			
		||||
	Rename(fileId uint64, oldname string, newname string) (*mcm.MachineInfo, error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newMachineFileApp(machineFileRepo repository.MachineFile, machineApp Machine) MachineFile {
 | 
			
		||||
	app := &machineFileAppImpl{machineApp: machineApp, machineFileRepo: machineFileRepo}
 | 
			
		||||
	app.Repo = machineFileRepo
 | 
			
		||||
	return app
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type machineFileAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.MachineFile, repository.MachineFile]
 | 
			
		||||
 | 
			
		||||
	machineFileRepo repository.MachineFile
 | 
			
		||||
	MachineFileRepo repository.MachineFile `inject:""`
 | 
			
		||||
	MachineApp      Machine                `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
	machineApp Machine
 | 
			
		||||
// 注入MachineFileRepo
 | 
			
		||||
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.machineFileRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
	return m.MachineFileRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 根据条件获取
 | 
			
		||||
func (m *machineFileAppImpl) GetMachineFile(condition *entity.MachineFile, cols ...string) error {
 | 
			
		||||
	return m.machineFileRepo.GetBy(condition, cols...)
 | 
			
		||||
	return m.MachineFileRepo.GetBy(condition, cols...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 保存机器文件配置
 | 
			
		||||
func (m *machineFileAppImpl) Save(ctx context.Context, mf *entity.MachineFile) error {
 | 
			
		||||
	_, err := m.machineApp.GetById(new(entity.Machine), mf.MachineId, "Name")
 | 
			
		||||
	_, err := m.MachineApp.GetById(new(entity.Machine), mf.MachineId, "Name")
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return errorx.NewBiz("该机器不存在")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if mf.Id != 0 {
 | 
			
		||||
		return m.machineFileRepo.UpdateById(ctx, mf)
 | 
			
		||||
		return m.MachineFileRepo.UpdateById(ctx, mf)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return m.machineFileRepo.Insert(ctx, mf)
 | 
			
		||||
	return m.MachineFileRepo.Insert(ctx, mf)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineFileAppImpl) ReadDir(fid uint64, path string) ([]fs.FileInfo, error) {
 | 
			
		||||
@@ -308,7 +306,7 @@ func (m *machineFileAppImpl) GetMachineCli(fid uint64, inputPath ...string) (*mc
 | 
			
		||||
			return nil, errorx.NewBiz("无权访问该目录或文件: %s", path)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return m.machineApp.GetCli(mf.MachineId)
 | 
			
		||||
	return m.MachineApp.GetCli(mf.MachineId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 获取文件机器 sftp cli
 | 
			
		||||
 
 | 
			
		||||
@@ -20,16 +20,15 @@ type MachineScript interface {
 | 
			
		||||
	Delete(ctx context.Context, id uint64)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newMachineScriptApp(machineScriptRepo repository.MachineScript, machineApp Machine) MachineScript {
 | 
			
		||||
	app := &machineScriptAppImpl{machineApp: machineApp}
 | 
			
		||||
	app.Repo = machineScriptRepo
 | 
			
		||||
	return app
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type machineScriptAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.MachineScript, repository.MachineScript]
 | 
			
		||||
 | 
			
		||||
	machineApp Machine
 | 
			
		||||
	MachineApp Machine `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 注入MachineScriptRepo
 | 
			
		||||
func (m *machineScriptAppImpl) InjectMachineScriptRepo(repo repository.MachineScript) {
 | 
			
		||||
	m.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const Common_Script_Machine_Id = 9999999
 | 
			
		||||
@@ -43,7 +42,7 @@ func (m *machineScriptAppImpl) GetPageList(condition *entity.MachineScript, page
 | 
			
		||||
func (m *machineScriptAppImpl) Save(ctx context.Context, ms *entity.MachineScript) error {
 | 
			
		||||
	// 如果机器id不为公共脚本id,则校验机器是否存在
 | 
			
		||||
	if machineId := ms.MachineId; machineId != Common_Script_Machine_Id {
 | 
			
		||||
		_, err := m.machineApp.GetById(new(entity.Machine), machineId, "Name")
 | 
			
		||||
		_, err := m.MachineApp.GetById(new(entity.Machine), machineId, "Name")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return errorx.NewBiz("该机器不存在")
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -33,16 +33,15 @@ type MachineTermOp interface {
 | 
			
		||||
	TimerDeleteTermOp()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newMachineTermOpApp(machineTermOpRepo repository.MachineTermOp) MachineTermOp {
 | 
			
		||||
	return &machineTermOpAppImpl{
 | 
			
		||||
		base.AppImpl[*entity.MachineTermOp, repository.MachineTermOp]{Repo: machineTermOpRepo},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type machineTermOpAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.MachineTermOp, repository.MachineTermOp]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 注入MachineTermOpRepo
 | 
			
		||||
func (m *machineTermOpAppImpl) InjectMachineTermOpRepo(repo repository.MachineTermOp) {
 | 
			
		||||
	m.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineTermOpAppImpl) TermConn(ctx context.Context, cli *mcm.Cli, wsConn *websocket.Conn, rows, cols int) error {
 | 
			
		||||
	var recorder *mcm.Recorder
 | 
			
		||||
	var termOpRecord *entity.MachineTermOp
 | 
			
		||||
 
 | 
			
		||||
@@ -8,16 +8,16 @@ import (
 | 
			
		||||
	"mayfly-go/pkg/model"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type machineCropJobRepoImpl struct {
 | 
			
		||||
type machineCronJobRepoImpl struct {
 | 
			
		||||
	base.RepoImpl[*entity.MachineCronJob]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newMachineCronJobRepo() repository.MachineCronJob {
 | 
			
		||||
	return &machineCropJobRepoImpl{base.RepoImpl[*entity.MachineCronJob]{M: new(entity.MachineCronJob)}}
 | 
			
		||||
	return &machineCronJobRepoImpl{base.RepoImpl[*entity.MachineCronJob]{M: new(entity.MachineCronJob)}}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 分页获取机器信息列表
 | 
			
		||||
func (m *machineCropJobRepoImpl) 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, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
	qd := gormx.NewQuery(condition).Like("name", condition.Name).Eq("status", condition.Status).WithOrderBy(orderBy...)
 | 
			
		||||
	return gormx.PageQuery(qd, pageParam, toEntity)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,27 +7,27 @@ import (
 | 
			
		||||
	"mayfly-go/pkg/gormx"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type machineCropJobRelateRepoImpl struct {
 | 
			
		||||
type machineCronJobRelateRepoImpl struct {
 | 
			
		||||
	base.RepoImpl[*entity.MachineCronJobRelate]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newMachineCropJobRelateRepo() repository.MachineCronJobRelate {
 | 
			
		||||
	return &machineCropJobRelateRepoImpl{base.RepoImpl[*entity.MachineCronJobRelate]{M: new(entity.MachineCronJobRelate)}}
 | 
			
		||||
func newMachineCronJobRelateRepo() repository.MachineCronJobRelate {
 | 
			
		||||
	return &machineCronJobRelateRepoImpl{base.RepoImpl[*entity.MachineCronJobRelate]{M: new(entity.MachineCronJobRelate)}}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineCropJobRelateRepoImpl) GetList(condition *entity.MachineCronJobRelate) []entity.MachineCronJobRelate {
 | 
			
		||||
func (m *machineCronJobRelateRepoImpl) GetList(condition *entity.MachineCronJobRelate) []entity.MachineCronJobRelate {
 | 
			
		||||
	list := new([]entity.MachineCronJobRelate)
 | 
			
		||||
	m.ListByCond(condition, list)
 | 
			
		||||
	return *list
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineCropJobRelateRepoImpl) GetMachineIds(cronJobId uint64) []uint64 {
 | 
			
		||||
func (m *machineCronJobRelateRepoImpl) GetMachineIds(cronJobId uint64) []uint64 {
 | 
			
		||||
	var machineIds []uint64
 | 
			
		||||
	m.ListByCond(&entity.MachineCronJobRelate{CronJobId: cronJobId}, &machineIds, "machine_id")
 | 
			
		||||
	return machineIds
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *machineCropJobRelateRepoImpl) GetCronJobIds(machineId uint64) []uint64 {
 | 
			
		||||
func (m *machineCronJobRelateRepoImpl) GetCronJobIds(machineId uint64) []uint64 {
 | 
			
		||||
	var cronJobIds []uint64
 | 
			
		||||
	gormx.ListBy(&entity.MachineCronJobRelate{MachineId: machineId}, &cronJobIds, "cron_job_id")
 | 
			
		||||
	return cronJobIds
 | 
			
		||||
 
 | 
			
		||||
@@ -1,46 +1,49 @@
 | 
			
		||||
package persistence
 | 
			
		||||
 | 
			
		||||
import "mayfly-go/internal/machine/domain/repository"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	machineRepo              repository.Machine              = newMachineRepo()
 | 
			
		||||
	machineFileRepo          repository.MachineFile          = newMachineFileRepo()
 | 
			
		||||
	machineScriptRepo        repository.MachineScript        = newMachineScriptRepo()
 | 
			
		||||
	authCertRepo             repository.AuthCert             = newAuthCertRepo()
 | 
			
		||||
	machineCropJobRepo       repository.MachineCronJob       = newMachineCronJobRepo()
 | 
			
		||||
	machineCropJobExecRepo   repository.MachineCronJobExec   = newMachineCronJobExecRepo()
 | 
			
		||||
	machineCronJobRelateRepo repository.MachineCronJobRelate = newMachineCropJobRelateRepo()
 | 
			
		||||
	machineTermOpRepo        repository.MachineTermOp        = newMachineTermOpRepoImpl()
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/machine/domain/repository"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func Init() {
 | 
			
		||||
	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"))
 | 
			
		||||
	ioc.Register(newMachineTermOpRepoImpl(), ioc.WithComponentName("MachineTermOpRepo"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMachineRepo() repository.Machine {
 | 
			
		||||
	return machineRepo
 | 
			
		||||
	return ioc.Get[repository.Machine]("MachineRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMachineFileRepo() repository.MachineFile {
 | 
			
		||||
	return machineFileRepo
 | 
			
		||||
	return ioc.Get[repository.MachineFile]("MachineFileRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMachineScriptRepo() repository.MachineScript {
 | 
			
		||||
	return machineScriptRepo
 | 
			
		||||
	return ioc.Get[repository.MachineScript]("MachineScriptRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAuthCertRepo() repository.AuthCert {
 | 
			
		||||
	return authCertRepo
 | 
			
		||||
	return ioc.Get[repository.AuthCert]("AuthCertRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMachineCronJobRepo() repository.MachineCronJob {
 | 
			
		||||
	return machineCropJobRepo
 | 
			
		||||
	return ioc.Get[repository.MachineCronJob]("MachineCronJobRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMachineCronJobExecRepo() repository.MachineCronJobExec {
 | 
			
		||||
	return machineCropJobExecRepo
 | 
			
		||||
	return ioc.Get[repository.MachineCronJobExec]("MachineCronJobExecRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMachineCronJobRelateRepo() repository.MachineCronJobRelate {
 | 
			
		||||
	return machineCronJobRelateRepo
 | 
			
		||||
	return ioc.Get[repository.MachineCronJobRelate]("MachineCropJobRelateRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMachineTermOpRepo() repository.MachineTermOp {
 | 
			
		||||
	return machineTermOpRepo
 | 
			
		||||
	return ioc.Get[repository.MachineTermOp]("MachineTermOpRepo")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,17 +2,19 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/machine/api"
 | 
			
		||||
	"mayfly-go/internal/machine/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func InitAuthCertRouter(router *gin.RouterGroup) {
 | 
			
		||||
	r := &api.AuthCert{AuthCertApp: application.GetAuthCertApp()}
 | 
			
		||||
 | 
			
		||||
	ag := router.Group("sys/authcerts")
 | 
			
		||||
 | 
			
		||||
	r := new(api.AuthCert)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(r))
 | 
			
		||||
 | 
			
		||||
	reqs := [...]*req.Conf{
 | 
			
		||||
		req.NewGet("", r.AuthCerts).RequiredPermissionCode("authcert"),
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,19 +2,16 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/machine/api"
 | 
			
		||||
	"mayfly-go/internal/machine/application"
 | 
			
		||||
	tagapp "mayfly-go/internal/tag/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func InitMachineRouter(router *gin.RouterGroup) {
 | 
			
		||||
	m := &api.Machine{
 | 
			
		||||
		MachineApp:       application.GetMachineApp(),
 | 
			
		||||
		MachineTermOpApp: application.GetMachineTermOpApp(),
 | 
			
		||||
		TagApp:           tagapp.GetTagTreeApp(),
 | 
			
		||||
	}
 | 
			
		||||
	m := new(api.Machine)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(m))
 | 
			
		||||
 | 
			
		||||
	machines := router.Group("machines")
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,8 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/machine/api"
 | 
			
		||||
	"mayfly-go/internal/machine/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -10,9 +11,9 @@ import (
 | 
			
		||||
 | 
			
		||||
func InitMachineCronJobRouter(router *gin.RouterGroup) {
 | 
			
		||||
	cronjobs := router.Group("machine-cronjobs")
 | 
			
		||||
	cj := &api.MachineCronJob{
 | 
			
		||||
		MachineCronJobApp: application.GetMachineCronJobApp(),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cj := new(api.MachineCronJob)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(cj))
 | 
			
		||||
 | 
			
		||||
	reqs := [...]*req.Conf{
 | 
			
		||||
		// 获取机器任务列表
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,8 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/machine/api"
 | 
			
		||||
	"mayfly-go/internal/machine/application"
 | 
			
		||||
	msgapp "mayfly-go/internal/msg/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -12,10 +12,8 @@ import (
 | 
			
		||||
func InitMachineFileRouter(router *gin.RouterGroup) {
 | 
			
		||||
	machineFile := router.Group("machines")
 | 
			
		||||
 | 
			
		||||
	mf := &api.MachineFile{
 | 
			
		||||
		MachineFileApp: application.GetMachineFileApp(),
 | 
			
		||||
		MsgApp:         msgapp.GetMsgApp(),
 | 
			
		||||
	}
 | 
			
		||||
	mf := new(api.MachineFile)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(mf))
 | 
			
		||||
 | 
			
		||||
	reqs := [...]*req.Conf{
 | 
			
		||||
		// 获取指定机器文件列表
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,8 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/machine/api"
 | 
			
		||||
	"mayfly-go/internal/machine/application"
 | 
			
		||||
	tagapp "mayfly-go/internal/tag/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -11,11 +11,9 @@ import (
 | 
			
		||||
 | 
			
		||||
func InitMachineScriptRouter(router *gin.RouterGroup) {
 | 
			
		||||
	machines := router.Group("machines")
 | 
			
		||||
	ms := &api.MachineScript{
 | 
			
		||||
		MachineScriptApp: application.GetMachineScriptApp(),
 | 
			
		||||
		MachineApp:       application.GetMachineApp(),
 | 
			
		||||
		TagApp:           tagapp.GetTagTreeApp(),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ms := new(api.MachineScript)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(ms))
 | 
			
		||||
 | 
			
		||||
	reqs := [...]*req.Conf{
 | 
			
		||||
		// 获取指定机器脚本列表
 | 
			
		||||
 
 | 
			
		||||
@@ -23,8 +23,8 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Mongo struct {
 | 
			
		||||
	MongoApp application.Mongo
 | 
			
		||||
	TagApp   tagapp.TagTree
 | 
			
		||||
	MongoApp application.Mongo `inject:""`
 | 
			
		||||
	TagApp   tagapp.TagTree    `inject:"TagTreeApp"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *Mongo) Mongos(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -2,13 +2,15 @@ package application
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/mongo/infrastructure/persistence"
 | 
			
		||||
	tagapp "mayfly-go/internal/tag/application"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	mongoApp Mongo = newMongoAppImpl(persistence.GetMongoRepo(), tagapp.GetTagTreeApp())
 | 
			
		||||
)
 | 
			
		||||
func init() {
 | 
			
		||||
	persistence.Init()
 | 
			
		||||
 | 
			
		||||
	ioc.Register(new(mongoAppImpl), ioc.WithComponentName("MongoApp"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMongoApp() Mongo {
 | 
			
		||||
	return mongoApp
 | 
			
		||||
	return ioc.Get[Mongo]("MongoApp")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -31,18 +31,15 @@ type Mongo interface {
 | 
			
		||||
	GetMongoConn(id uint64) (*mgm.MongoConn, error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newMongoAppImpl(mongoRepo repository.Mongo, tagApp tagapp.TagTree) Mongo {
 | 
			
		||||
	app := &mongoAppImpl{
 | 
			
		||||
		tagApp: tagApp,
 | 
			
		||||
	}
 | 
			
		||||
	app.Repo = mongoRepo
 | 
			
		||||
	return app
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type mongoAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.Mongo, repository.Mongo]
 | 
			
		||||
 | 
			
		||||
	tagApp tagapp.TagTree
 | 
			
		||||
	TagApp tagapp.TagTree `inject:"TagTreeApp"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 注入MongoRepo
 | 
			
		||||
func (d *mongoAppImpl) InjectMongoRepo(repo repository.Mongo) {
 | 
			
		||||
	d.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 分页获取数据库信息列表
 | 
			
		||||
@@ -63,7 +60,7 @@ func (d *mongoAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
			
		||||
		},
 | 
			
		||||
		func(ctx context.Context) error {
 | 
			
		||||
			var tagIds []uint64
 | 
			
		||||
			return d.tagApp.RelateResource(ctx, mongoEntity.Code, consts.TagResourceTypeMongo, tagIds)
 | 
			
		||||
			return d.TagApp.RelateResource(ctx, mongoEntity.Code, consts.TagResourceTypeMongo, tagIds)
 | 
			
		||||
		})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -91,7 +88,7 @@ func (d *mongoAppImpl) SaveMongo(ctx context.Context, m *entity.Mongo, tagIds ..
 | 
			
		||||
		return d.Tx(ctx, func(ctx context.Context) error {
 | 
			
		||||
			return d.Insert(ctx, m)
 | 
			
		||||
		}, func(ctx context.Context) error {
 | 
			
		||||
			return d.tagApp.RelateResource(ctx, resouceCode, consts.TagResourceTypeMongo, tagIds)
 | 
			
		||||
			return d.TagApp.RelateResource(ctx, resouceCode, consts.TagResourceTypeMongo, tagIds)
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -109,7 +106,7 @@ func (d *mongoAppImpl) SaveMongo(ctx context.Context, m *entity.Mongo, tagIds ..
 | 
			
		||||
	return d.Tx(ctx, func(ctx context.Context) error {
 | 
			
		||||
		return d.UpdateById(ctx, m)
 | 
			
		||||
	}, func(ctx context.Context) error {
 | 
			
		||||
		return d.tagApp.RelateResource(ctx, oldMongo.Code, consts.TagResourceTypeMongo, tagIds)
 | 
			
		||||
		return d.TagApp.RelateResource(ctx, oldMongo.Code, consts.TagResourceTypeMongo, tagIds)
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -119,6 +116,6 @@ func (d *mongoAppImpl) GetMongoConn(id uint64) (*mgm.MongoConn, error) {
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, errorx.NewBiz("mongo信息不存在")
 | 
			
		||||
		}
 | 
			
		||||
		return me.ToMongoInfo(d.tagApp.ListTagPathByResource(consts.TagResourceTypeMongo, me.Code)...), nil
 | 
			
		||||
		return me.ToMongoInfo(d.TagApp.ListTagPathByResource(consts.TagResourceTypeMongo, me.Code)...), nil
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,12 +2,13 @@ package persistence
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/mongo/domain/repository"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	mongoRepo repository.Mongo = newMongoRepo()
 | 
			
		||||
)
 | 
			
		||||
func Init() {
 | 
			
		||||
	ioc.Register(newMongoRepo(), ioc.WithComponentName("MongoRepo"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMongoRepo() repository.Mongo {
 | 
			
		||||
	return mongoRepo
 | 
			
		||||
	return ioc.Get[repository.Mongo]("MongoRepo")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,8 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/mongo/api"
 | 
			
		||||
	"mayfly-go/internal/mongo/application"
 | 
			
		||||
	tagapp "mayfly-go/internal/tag/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -12,10 +12,8 @@ import (
 | 
			
		||||
func InitMongoRouter(router *gin.RouterGroup) {
 | 
			
		||||
	m := router.Group("mongos")
 | 
			
		||||
 | 
			
		||||
	ma := &api.Mongo{
 | 
			
		||||
		MongoApp: application.GetMongoApp(),
 | 
			
		||||
		TagApp:   tagapp.GetTagTreeApp(),
 | 
			
		||||
	}
 | 
			
		||||
	ma := new(api.Mongo)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(ma))
 | 
			
		||||
 | 
			
		||||
	saveDataPerm := req.NewPermission("mongo:data:save")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Msg struct {
 | 
			
		||||
	MsgApp application.Msg
 | 
			
		||||
	MsgApp application.Msg `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 获取账号接收的消息列表
 | 
			
		||||
 
 | 
			
		||||
@@ -2,12 +2,15 @@ package application
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/msg/infrastructure/persistence"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	msgApp = newMsgApp(persistence.GetMsgRepo())
 | 
			
		||||
)
 | 
			
		||||
func init() {
 | 
			
		||||
	persistence.Init()
 | 
			
		||||
 | 
			
		||||
	ioc.Register(new(msgAppImpl), ioc.WithComponentName("MsgApp"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMsgApp() Msg {
 | 
			
		||||
	return msgApp
 | 
			
		||||
	return ioc.Get[Msg]("MsgApp")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -19,27 +19,21 @@ type Msg interface {
 | 
			
		||||
	CreateAndSend(la *model.LoginAccount, msg *dto.SysMsg)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newMsgApp(msgRepo repository.Msg) Msg {
 | 
			
		||||
	return &msgAppImpl{
 | 
			
		||||
		msgRepo: msgRepo,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type msgAppImpl struct {
 | 
			
		||||
	msgRepo repository.Msg
 | 
			
		||||
	MsgRepo repository.Msg `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *msgAppImpl) GetPageList(condition *entity.Msg, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
	return a.msgRepo.GetPageList(condition, pageParam, toEntity)
 | 
			
		||||
	return a.MsgRepo.GetPageList(condition, pageParam, toEntity)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *msgAppImpl) Create(ctx context.Context, msg *entity.Msg) {
 | 
			
		||||
	a.msgRepo.Insert(ctx, msg)
 | 
			
		||||
	a.MsgRepo.Insert(ctx, msg)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *msgAppImpl) CreateAndSend(la *model.LoginAccount, wmsg *dto.SysMsg) {
 | 
			
		||||
	now := time.Now()
 | 
			
		||||
	msg := &entity.Msg{Type: 2, Msg: wmsg.Msg, RecipientId: int64(la.Id), CreateTime: &now, CreatorId: la.Id, Creator: la.Username}
 | 
			
		||||
	a.msgRepo.Insert(context.TODO(), msg)
 | 
			
		||||
	a.MsgRepo.Insert(context.TODO(), msg)
 | 
			
		||||
	ws.SendJsonMsg(ws.UserId(la.Id), wmsg.ClientId, wmsg)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,14 @@
 | 
			
		||||
package persistence
 | 
			
		||||
 | 
			
		||||
import "mayfly-go/internal/msg/domain/repository"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	msgRepo = newMsgRepo()
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/msg/domain/repository"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func GetMsgRepo() repository.Msg {
 | 
			
		||||
	return msgRepo
 | 
			
		||||
func Init() {
 | 
			
		||||
	ioc.Register(newMsgRepo(), ioc.WithComponentName("MsgRepo"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetMsgRepo() repository.Msg {
 | 
			
		||||
	return ioc.Get[repository.Msg]("msgRepo")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/msg/api"
 | 
			
		||||
	"mayfly-go/internal/msg/application"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -10,9 +10,9 @@ import (
 | 
			
		||||
 | 
			
		||||
func InitMsgRouter(router *gin.RouterGroup) {
 | 
			
		||||
	msg := router.Group("msgs")
 | 
			
		||||
	a := &api.Msg{
 | 
			
		||||
		MsgApp: application.GetMsgApp(),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	a := new(api.Msg)
 | 
			
		||||
	ioc.Inject(a)
 | 
			
		||||
 | 
			
		||||
	req.NewGet("/self", a.GetMsgs).Group(msg)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,8 @@
 | 
			
		||||
package router
 | 
			
		||||
 | 
			
		||||
import "github.com/gin-gonic/gin"
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func Init(router *gin.RouterGroup) {
 | 
			
		||||
	InitMsgRouter(router)
 | 
			
		||||
 
 | 
			
		||||
@@ -64,7 +64,7 @@ func (r *Redis) Hset(rc *req.Ctx) {
 | 
			
		||||
	rc.ResData = res
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Redis) SetHashValue(rc *req.Ctx) {
 | 
			
		||||
func (r *Redis) SaveHashValue(rc *req.Ctx) {
 | 
			
		||||
	g := rc.GinCtx
 | 
			
		||||
	hashValue := new(form.HashValue)
 | 
			
		||||
	ginx.BindJsonAndValid(g, hashValue)
 | 
			
		||||
 
 | 
			
		||||
@@ -54,7 +54,7 @@ func (r *Redis) SaveListValue(rc *req.Ctx) {
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Redis) SetListValue(rc *req.Ctx) {
 | 
			
		||||
func (r *Redis) Lset(rc *req.Ctx) {
 | 
			
		||||
	g := rc.GinCtx
 | 
			
		||||
	listSetValue := new(form.ListSetValue)
 | 
			
		||||
	ginx.BindJsonAndValid(g, listSetValue)
 | 
			
		||||
 
 | 
			
		||||
@@ -24,8 +24,8 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Redis struct {
 | 
			
		||||
	RedisApp application.Redis
 | 
			
		||||
	TagApp   tagapp.TagTree
 | 
			
		||||
	RedisApp application.Redis `inject:""`
 | 
			
		||||
	TagApp   tagapp.TagTree    `inject:"TagTreeApp"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Redis) RedisList(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ func (r *Redis) GetSetValue(rc *req.Ctx) {
 | 
			
		||||
	rc.ResData = res
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Redis) SetSetValue(rc *req.Ctx) {
 | 
			
		||||
func (r *Redis) SaveSetValue(rc *req.Ctx) {
 | 
			
		||||
	g := rc.GinCtx
 | 
			
		||||
	keyvalue := new(form.SetValue)
 | 
			
		||||
	ginx.BindJsonAndValid(g, keyvalue)
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,7 @@ func (r *Redis) GetStringValue(rc *req.Ctx) {
 | 
			
		||||
	rc.ResData = str
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Redis) SetStringValue(rc *req.Ctx) {
 | 
			
		||||
func (r *Redis) SaveStringValue(rc *req.Ctx) {
 | 
			
		||||
	g := rc.GinCtx
 | 
			
		||||
	keyValue := new(form.StringValue)
 | 
			
		||||
	ginx.BindJsonAndValid(g, keyValue)
 | 
			
		||||
 
 | 
			
		||||
@@ -2,13 +2,15 @@ package application
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/redis/infrastructure/persistence"
 | 
			
		||||
	tagapp "mayfly-go/internal/tag/application"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	redisApp Redis = newRedisApp(persistence.GetRedisRepo(), tagapp.GetTagTreeApp())
 | 
			
		||||
)
 | 
			
		||||
func init() {
 | 
			
		||||
	persistence.Init()
 | 
			
		||||
 | 
			
		||||
	ioc.Register(new(redisAppImpl), ioc.WithComponentName("RedisApp"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetRedisApp() Redis {
 | 
			
		||||
	return redisApp
 | 
			
		||||
	return ioc.Get[Redis]("RedisApp")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -35,18 +35,15 @@ type Redis interface {
 | 
			
		||||
	GetRedisConn(id uint64, db int) (*rdm.RedisConn, error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newRedisApp(redisRepo repository.Redis, tagApp tagapp.TagTree) Redis {
 | 
			
		||||
	app := &redisAppImpl{
 | 
			
		||||
		tagApp: tagApp,
 | 
			
		||||
	}
 | 
			
		||||
	app.Repo = redisRepo
 | 
			
		||||
	return app
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type redisAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.Redis, repository.Redis]
 | 
			
		||||
 | 
			
		||||
	tagApp tagapp.TagTree
 | 
			
		||||
	TagApp tagapp.TagTree `inject:"TagTreeApp"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 注入RedisRepo
 | 
			
		||||
func (r *redisAppImpl) InjectRedisRepo(repo repository.Redis) {
 | 
			
		||||
	r.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 分页获取redis列表
 | 
			
		||||
@@ -90,7 +87,7 @@ func (r *redisAppImpl) SaveRedis(ctx context.Context, re *entity.Redis, tagIds .
 | 
			
		||||
		return r.Tx(ctx, func(ctx context.Context) error {
 | 
			
		||||
			return r.Insert(ctx, re)
 | 
			
		||||
		}, func(ctx context.Context) error {
 | 
			
		||||
			return r.tagApp.RelateResource(ctx, resouceCode, consts.TagResourceTypeRedis, tagIds)
 | 
			
		||||
			return r.TagApp.RelateResource(ctx, resouceCode, consts.TagResourceTypeRedis, tagIds)
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -116,7 +113,7 @@ func (r *redisAppImpl) SaveRedis(ctx context.Context, re *entity.Redis, tagIds .
 | 
			
		||||
	return r.Tx(ctx, func(ctx context.Context) error {
 | 
			
		||||
		return r.UpdateById(ctx, re)
 | 
			
		||||
	}, func(ctx context.Context) error {
 | 
			
		||||
		return r.tagApp.RelateResource(ctx, oldRedis.Code, consts.TagResourceTypeRedis, tagIds)
 | 
			
		||||
		return r.TagApp.RelateResource(ctx, oldRedis.Code, consts.TagResourceTypeRedis, tagIds)
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -136,7 +133,7 @@ func (r *redisAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
			
		||||
		return r.DeleteById(ctx, id)
 | 
			
		||||
	}, func(ctx context.Context) error {
 | 
			
		||||
		var tagIds []uint64
 | 
			
		||||
		return r.tagApp.RelateResource(ctx, re.Code, consts.TagResourceTypeRedis, tagIds)
 | 
			
		||||
		return r.TagApp.RelateResource(ctx, re.Code, consts.TagResourceTypeRedis, tagIds)
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -151,6 +148,6 @@ func (r *redisAppImpl) GetRedisConn(id uint64, db int) (*rdm.RedisConn, error) {
 | 
			
		||||
		if err := re.PwdDecrypt(); err != nil {
 | 
			
		||||
			return nil, errorx.NewBiz(err.Error())
 | 
			
		||||
		}
 | 
			
		||||
		return re.ToRedisInfo(db, r.tagApp.ListTagPathByResource(consts.TagResourceTypeRedis, re.Code)...), nil
 | 
			
		||||
		return re.ToRedisInfo(db, r.TagApp.ListTagPathByResource(consts.TagResourceTypeRedis, re.Code)...), nil
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,14 @@
 | 
			
		||||
package persistence
 | 
			
		||||
 | 
			
		||||
import "mayfly-go/internal/redis/domain/repository"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	redisRepo repository.Redis = newRedisRepo()
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/redis/domain/repository"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func GetRedisRepo() repository.Redis {
 | 
			
		||||
	return redisRepo
 | 
			
		||||
func Init() {
 | 
			
		||||
	ioc.Register(newRedisRepo(), ioc.WithComponentName("RedisRepo"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetRedisRepo() repository.Redis {
 | 
			
		||||
	return ioc.Get[repository.Redis]("RedisRepo")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,8 +2,8 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/redis/api"
 | 
			
		||||
	"mayfly-go/internal/redis/application"
 | 
			
		||||
	tagapp "mayfly-go/internal/tag/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -12,10 +12,8 @@ import (
 | 
			
		||||
func InitRedisRouter(router *gin.RouterGroup) {
 | 
			
		||||
	redis := router.Group("redis")
 | 
			
		||||
 | 
			
		||||
	rs := &api.Redis{
 | 
			
		||||
		RedisApp: application.GetRedisApp(),
 | 
			
		||||
		TagApp:   tagapp.GetTagTreeApp(),
 | 
			
		||||
	}
 | 
			
		||||
	rs := new(api.Redis)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(rs))
 | 
			
		||||
 | 
			
		||||
	// 保存数据权限
 | 
			
		||||
	saveDataP := req.NewPermission("redis:data:save")
 | 
			
		||||
@@ -61,7 +59,7 @@ func InitRedisRouter(router *gin.RouterGroup) {
 | 
			
		||||
		req.NewGet(":id/:db/string-value", rs.GetStringValue),
 | 
			
		||||
 | 
			
		||||
		// 设置string类型值
 | 
			
		||||
		req.NewPost(":id/:db/string-value", rs.SetStringValue).Log(req.NewLogSave("redis-setString")).RequiredPermission(saveDataP),
 | 
			
		||||
		req.NewPost(":id/:db/string-value", rs.SaveStringValue).Log(req.NewLogSave("redis-setString")).RequiredPermission(saveDataP),
 | 
			
		||||
 | 
			
		||||
		// ———————————————— hash操作 ————————————————
 | 
			
		||||
		req.NewGet(":id/:db/hscan", rs.Hscan),
 | 
			
		||||
@@ -73,12 +71,12 @@ func InitRedisRouter(router *gin.RouterGroup) {
 | 
			
		||||
		req.NewDelete(":id/:db/hdel", rs.Hdel).Log(req.NewLogSave("redis-hdel")).RequiredPermission(deleteDataP),
 | 
			
		||||
 | 
			
		||||
		// 设置hash类型值
 | 
			
		||||
		req.NewPost(":id/:db/hash-value", rs.SetHashValue).Log(req.NewLogSave("redis-setHashValue")).RequiredPermission(saveDataP),
 | 
			
		||||
		req.NewPost(":id/:db/hash-value", rs.SaveHashValue).Log(req.NewLogSave("redis-setHashValue")).RequiredPermission(saveDataP),
 | 
			
		||||
 | 
			
		||||
		// ---------------  set操作  ----------------
 | 
			
		||||
		req.NewGet(":id/:db/set-value", rs.GetSetValue),
 | 
			
		||||
 | 
			
		||||
		req.NewPost(":id/:db/set-value", rs.SetSetValue).RequiredPermission(saveDataP),
 | 
			
		||||
		req.NewPost(":id/:db/set-value", rs.SaveSetValue).RequiredPermission(saveDataP),
 | 
			
		||||
 | 
			
		||||
		req.NewGet(":id/:db/scard", rs.Scard),
 | 
			
		||||
 | 
			
		||||
@@ -93,7 +91,7 @@ func InitRedisRouter(router *gin.RouterGroup) {
 | 
			
		||||
 | 
			
		||||
		req.NewPost(":id/:db/list-value", rs.SaveListValue).RequiredPermission(saveDataP),
 | 
			
		||||
 | 
			
		||||
		req.NewPost(":id/:db/list-value/lset", rs.SetListValue).RequiredPermission(saveDataP),
 | 
			
		||||
		req.NewPost(":id/:db/list-value/lset", rs.Lset).RequiredPermission(saveDataP),
 | 
			
		||||
 | 
			
		||||
		req.NewPost(":id/:db/lrem", rs.Lrem).RequiredPermission(deleteDataP),
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -27,11 +27,11 @@ const (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Account struct {
 | 
			
		||||
	AccountApp  application.Account
 | 
			
		||||
	ResourceApp application.Resource
 | 
			
		||||
	RoleApp     application.Role
 | 
			
		||||
	MsgApp      msgapp.Msg
 | 
			
		||||
	ConfigApp   application.Config
 | 
			
		||||
	AccountApp  application.Account  `inject:""`
 | 
			
		||||
	ResourceApp application.Resource `inject:""`
 | 
			
		||||
	RoleApp     application.Role     `inject:""`
 | 
			
		||||
	MsgApp      msgapp.Msg           `inject:""`
 | 
			
		||||
	ConfigApp   application.Config   `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 获取当前登录用户的菜单与权限码
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Config struct {
 | 
			
		||||
	ConfigApp application.Config
 | 
			
		||||
	ConfigApp application.Config `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (c *Config) Configs(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -13,7 +13,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Resource struct {
 | 
			
		||||
	ResourceApp application.Resource
 | 
			
		||||
	ResourceApp application.Resource `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Resource) GetAllResourceTree(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -15,8 +15,8 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Role struct {
 | 
			
		||||
	RoleApp     application.Role
 | 
			
		||||
	ResourceApp application.Resource
 | 
			
		||||
	RoleApp     application.Role     `inject:""`
 | 
			
		||||
	ResourceApp application.Resource `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Role) Roles(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -9,7 +9,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Syslog struct {
 | 
			
		||||
	SyslogApp application.Syslog
 | 
			
		||||
	SyslogApp application.Syslog `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *Syslog) Syslogs(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -25,14 +25,15 @@ type Account interface {
 | 
			
		||||
	Delete(ctx context.Context, id uint64) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newAccountApp(accountRepo repository.Account) Account {
 | 
			
		||||
	return &accountAppImpl{base.AppImpl[*entity.Account, repository.Account]{Repo: accountRepo}}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type accountAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.Account, repository.Account]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 注入AccountRepo
 | 
			
		||||
func (a *accountAppImpl) InjectAccountRepo(repo repository.Account) {
 | 
			
		||||
	a.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *accountAppImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
	return a.GetRepo().GetPageList(condition, pageParam, toEntity)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,32 +2,35 @@ package application
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/sys/infrastructure/persistence"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	accountApp  = newAccountApp(persistence.GetAccountRepo())
 | 
			
		||||
	configApp   = newConfigApp(persistence.GetConfigRepo())
 | 
			
		||||
	resourceApp = newResourceApp(persistence.GetResourceRepo())
 | 
			
		||||
	roleApp     = newRoleApp(persistence.GetRoleRepo(), persistence.GetAccountRoleRepo())
 | 
			
		||||
	syslogApp   = newSyslogApp(persistence.GetSyslogRepo())
 | 
			
		||||
)
 | 
			
		||||
func init() {
 | 
			
		||||
	persistence.Init()
 | 
			
		||||
 | 
			
		||||
	ioc.Register(new(accountAppImpl), ioc.WithComponentName("AccountApp"))
 | 
			
		||||
	ioc.Register(new(roleAppImpl), ioc.WithComponentName("RoleApp"))
 | 
			
		||||
	ioc.Register(new(configAppImpl), ioc.WithComponentName("ConfigApp"))
 | 
			
		||||
	ioc.Register(new(resourceAppImpl), ioc.WithComponentName("ResourceApp"))
 | 
			
		||||
	ioc.Register(new(syslogAppImpl), ioc.WithComponentName("SyslogApp"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAccountApp() Account {
 | 
			
		||||
	return accountApp
 | 
			
		||||
	return ioc.Get[Account]("AccountApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetConfigApp() Config {
 | 
			
		||||
	return configApp
 | 
			
		||||
	return ioc.Get[Config]("ConfigApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetResourceApp() Resource {
 | 
			
		||||
	return resourceApp
 | 
			
		||||
	return ioc.Get[Resource]("ResourceApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetRoleApp() Role {
 | 
			
		||||
	return roleApp
 | 
			
		||||
	return ioc.Get[Role]("RoleApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetSyslogApp() Syslog {
 | 
			
		||||
	return syslogApp
 | 
			
		||||
	return ioc.Get[Syslog]("SyslogApp")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -27,17 +27,14 @@ type Config interface {
 | 
			
		||||
	GetConfig(key string) *entity.Config
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newConfigApp(configRepo repository.Config) Config {
 | 
			
		||||
	configApp := new(configAppImpl)
 | 
			
		||||
	configApp.Repo = configRepo
 | 
			
		||||
	return configApp
 | 
			
		||||
	// return &configAppImpl{base.AppImpl[*entity.Config, repository.Config]{Repo: configRepo}}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type configAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.Config, repository.Config]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *configAppImpl) InjectConfigRepo(repo repository.Config) {
 | 
			
		||||
	a.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *configAppImpl) GetPageList(condition *entity.Config, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
	return a.GetRepo().GetPageList(condition, pageParam, toEntity)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -27,16 +27,15 @@ type Resource interface {
 | 
			
		||||
	GetAccountResources(accountId uint64, toEntity any) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newResourceApp(resourceRepo repository.Resource) Resource {
 | 
			
		||||
	return &resourceAppImpl{
 | 
			
		||||
		base.AppImpl[*entity.Resource, repository.Resource]{Repo: resourceRepo},
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type resourceAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.Resource, repository.Resource]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 注入ResourceRepo
 | 
			
		||||
func (r *resourceAppImpl) InjectResourceRepo(repo repository.Resource) {
 | 
			
		||||
	r.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (r *resourceAppImpl) Save(ctx context.Context, resource *entity.Resource) error {
 | 
			
		||||
	// 更新操作
 | 
			
		||||
	if resource.Id != 0 {
 | 
			
		||||
 
 | 
			
		||||
@@ -41,24 +41,17 @@ type Role interface {
 | 
			
		||||
	GetRoleAccountPage(condition *entity.RoleAccountQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newRoleApp(roleRepo repository.Role, accountRoleRepo repository.AccountRole) Role {
 | 
			
		||||
	return &roleAppImpl{
 | 
			
		||||
		roleRepo:        roleRepo,
 | 
			
		||||
		accountRoleRepo: accountRoleRepo,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type roleAppImpl struct {
 | 
			
		||||
	roleRepo        repository.Role
 | 
			
		||||
	accountRoleRepo repository.AccountRole
 | 
			
		||||
	RoleRepo        repository.Role        `inject:""`
 | 
			
		||||
	AccountRoleRepo repository.AccountRole `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *roleAppImpl) GetPageList(condition *entity.RoleQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
	return m.roleRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
	return m.RoleRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *roleAppImpl) ListByQuery(condition *entity.RoleQuery) ([]*entity.Role, error) {
 | 
			
		||||
	return m.roleRepo.ListByQuery(condition)
 | 
			
		||||
	return m.RoleRepo.ListByQuery(condition)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *roleAppImpl) SaveRole(ctx context.Context, role *entity.Role) error {
 | 
			
		||||
@@ -69,14 +62,14 @@ func (m *roleAppImpl) SaveRole(ctx context.Context, role *entity.Role) error {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	role.Status = 1
 | 
			
		||||
	return m.roleRepo.Insert(ctx, role)
 | 
			
		||||
	return m.RoleRepo.Insert(ctx, role)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *roleAppImpl) DeleteRole(ctx context.Context, id uint64) error {
 | 
			
		||||
	// 删除角色与资源账号的关联关系
 | 
			
		||||
	return gormx.Tx(
 | 
			
		||||
		func(db *gorm.DB) error {
 | 
			
		||||
			return m.roleRepo.DeleteByIdWithDb(ctx, db, id)
 | 
			
		||||
			return m.RoleRepo.DeleteByIdWithDb(ctx, db, id)
 | 
			
		||||
		},
 | 
			
		||||
		func(db *gorm.DB) error {
 | 
			
		||||
			return gormx.DeleteByWithDb(db, &entity.RoleResource{RoleId: id})
 | 
			
		||||
@@ -88,11 +81,11 @@ func (m *roleAppImpl) DeleteRole(ctx context.Context, id uint64) error {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *roleAppImpl) GetRoleResourceIds(roleId uint64) []uint64 {
 | 
			
		||||
	return m.roleRepo.GetRoleResourceIds(roleId)
 | 
			
		||||
	return m.RoleRepo.GetRoleResourceIds(roleId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *roleAppImpl) GetRoleResources(roleId uint64, toEntity any) {
 | 
			
		||||
	m.roleRepo.GetRoleResources(roleId, toEntity)
 | 
			
		||||
	m.RoleRepo.GetRoleResources(roleId, toEntity)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *roleAppImpl) SaveRoleResource(ctx context.Context, roleId uint64, resourceIds []uint64) {
 | 
			
		||||
@@ -112,20 +105,20 @@ func (m *roleAppImpl) SaveRoleResource(ctx context.Context, roleId uint64, resou
 | 
			
		||||
		rr.IsDeleted = undeleted
 | 
			
		||||
		addVals = append(addVals, rr)
 | 
			
		||||
	}
 | 
			
		||||
	m.roleRepo.SaveRoleResource(addVals)
 | 
			
		||||
	m.RoleRepo.SaveRoleResource(addVals)
 | 
			
		||||
 | 
			
		||||
	for _, v := range delIds {
 | 
			
		||||
		m.roleRepo.DeleteRoleResource(roleId, v)
 | 
			
		||||
		m.RoleRepo.DeleteRoleResource(roleId, v)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *roleAppImpl) RelateAccountRole(ctx context.Context, accountId, roleId uint64, relateType consts.AccountRoleRelateType) error {
 | 
			
		||||
	accountRole := &entity.AccountRole{AccountId: accountId, RoleId: roleId}
 | 
			
		||||
	if relateType == consts.AccountRoleUnbind {
 | 
			
		||||
		return m.accountRoleRepo.DeleteByCond(ctx, accountRole)
 | 
			
		||||
		return m.AccountRoleRepo.DeleteByCond(ctx, accountRole)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err := m.accountRoleRepo.GetBy(accountRole)
 | 
			
		||||
	err := m.AccountRoleRepo.GetBy(accountRole)
 | 
			
		||||
	if err == nil {
 | 
			
		||||
		return errorx.NewBiz("该用户已拥有该权限")
 | 
			
		||||
	}
 | 
			
		||||
@@ -135,15 +128,15 @@ func (m *roleAppImpl) RelateAccountRole(ctx context.Context, accountId, roleId u
 | 
			
		||||
	accountRole.Creator = la.Username
 | 
			
		||||
	accountRole.CreatorId = la.Id
 | 
			
		||||
	accountRole.CreateTime = &createTime
 | 
			
		||||
	return m.accountRoleRepo.Insert(ctx, accountRole)
 | 
			
		||||
	return m.AccountRoleRepo.Insert(ctx, accountRole)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *roleAppImpl) GetAccountRoles(accountId uint64) ([]*entity.AccountRole, error) {
 | 
			
		||||
	var res []*entity.AccountRole
 | 
			
		||||
	err := m.accountRoleRepo.ListByCond(&entity.AccountRole{AccountId: accountId}, &res)
 | 
			
		||||
	err := m.AccountRoleRepo.ListByCond(&entity.AccountRole{AccountId: accountId}, &res)
 | 
			
		||||
	return res, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *roleAppImpl) GetRoleAccountPage(condition *entity.RoleAccountQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
	return m.accountRoleRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
	return m.AccountRoleRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -20,18 +20,12 @@ type Syslog interface {
 | 
			
		||||
	SaveFromReq(req *req.Ctx)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newSyslogApp(syslogRepo repository.Syslog) Syslog {
 | 
			
		||||
	return &syslogAppImpl{
 | 
			
		||||
		syslogRepo: syslogRepo,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type syslogAppImpl struct {
 | 
			
		||||
	syslogRepo repository.Syslog
 | 
			
		||||
	SyslogRepo repository.Syslog `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *syslogAppImpl) GetPageList(condition *entity.SysLogQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
	return m.syslogRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
	return m.SyslogRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *syslogAppImpl) SaveFromReq(req *req.Ctx) {
 | 
			
		||||
@@ -76,5 +70,5 @@ func (m *syslogAppImpl) SaveFromReq(req *req.Ctx) {
 | 
			
		||||
		syslog.Type = entity.SyslogTypeNorman
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	m.syslogRepo.Insert(req.MetaCtx, syslog)
 | 
			
		||||
	m.SyslogRepo.Insert(req.MetaCtx, syslog)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -8,15 +8,15 @@ import (
 | 
			
		||||
	"mayfly-go/pkg/model"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type accountRepoImpl struct {
 | 
			
		||||
type AccountRepoImpl struct {
 | 
			
		||||
	base.RepoImpl[*entity.Account]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newAccountRepo() repository.Account {
 | 
			
		||||
	return &accountRepoImpl{base.RepoImpl[*entity.Account]{M: new(entity.Account)}}
 | 
			
		||||
	return &AccountRepoImpl{base.RepoImpl[*entity.Account]{M: new(entity.Account)}}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *accountRepoImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
func (m *AccountRepoImpl) GetPageList(condition *entity.Account, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
 | 
			
		||||
	qd := gormx.NewQuery(new(entity.Account)).
 | 
			
		||||
		Like("name", condition.Name).
 | 
			
		||||
		Like("username", condition.Username)
 | 
			
		||||
 
 | 
			
		||||
@@ -1,36 +1,39 @@
 | 
			
		||||
package persistence
 | 
			
		||||
 | 
			
		||||
import "mayfly-go/internal/sys/domain/repository"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	accountRepo     = newAccountRepo()
 | 
			
		||||
	configRepo      = newConfigRepo()
 | 
			
		||||
	resourceRepo    = newResourceRepo()
 | 
			
		||||
	roleRepo        = newRoleRepo()
 | 
			
		||||
	accountRoleRepo = newAccountRoleRepo()
 | 
			
		||||
	syslogRepo      = newSyslogRepo()
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/sys/domain/repository"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func Init() {
 | 
			
		||||
	ioc.Register(newAccountRepo(), ioc.WithComponentName("AccountRepo"))
 | 
			
		||||
	ioc.Register(newRoleRepo(), ioc.WithComponentName("RoleRepo"))
 | 
			
		||||
	ioc.Register(newAccountRoleRepo(), ioc.WithComponentName("AccountRoleRepo"))
 | 
			
		||||
	ioc.Register(newResourceRepo(), ioc.WithComponentName("ResourceRepo"))
 | 
			
		||||
	ioc.Register(newConfigRepo(), ioc.WithComponentName("ConfigRepo"))
 | 
			
		||||
	ioc.Register(newSyslogRepo(), ioc.WithComponentName("SyslogRepo"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAccountRepo() repository.Account {
 | 
			
		||||
	return accountRepo
 | 
			
		||||
	return ioc.Get[repository.Account]("AccountRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetConfigRepo() repository.Config {
 | 
			
		||||
	return configRepo
 | 
			
		||||
	return ioc.Get[repository.Config]("ConfigRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetResourceRepo() repository.Resource {
 | 
			
		||||
	return resourceRepo
 | 
			
		||||
	return ioc.Get[repository.Resource]("ResourceRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetRoleRepo() repository.Role {
 | 
			
		||||
	return roleRepo
 | 
			
		||||
	return ioc.Get[repository.Role]("RoleRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetAccountRoleRepo() repository.AccountRole {
 | 
			
		||||
	return accountRoleRepo
 | 
			
		||||
	return ioc.Get[repository.AccountRole]("AccountRoleRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetSyslogRepo() repository.Syslog {
 | 
			
		||||
	return syslogRepo
 | 
			
		||||
	return ioc.Get[repository.Syslog]("SyslogRepo")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,9 @@
 | 
			
		||||
package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	msgapp "mayfly-go/internal/msg/application"
 | 
			
		||||
	"mayfly-go/internal/sys/api"
 | 
			
		||||
	"mayfly-go/internal/sys/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
@@ -11,13 +11,8 @@ import (
 | 
			
		||||
 | 
			
		||||
func InitAccountRouter(router *gin.RouterGroup) {
 | 
			
		||||
	account := router.Group("sys/accounts")
 | 
			
		||||
	a := &api.Account{
 | 
			
		||||
		AccountApp:  application.GetAccountApp(),
 | 
			
		||||
		ResourceApp: application.GetResourceApp(),
 | 
			
		||||
		RoleApp:     application.GetRoleApp(),
 | 
			
		||||
		MsgApp:      msgapp.GetMsgApp(),
 | 
			
		||||
		ConfigApp:   application.GetConfigApp(),
 | 
			
		||||
	}
 | 
			
		||||
	a := new(api.Account)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(a))
 | 
			
		||||
 | 
			
		||||
	addAccountPermission := req.NewPermission("account:add")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,15 +2,17 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/sys/api"
 | 
			
		||||
	"mayfly-go/internal/sys/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func InitSysConfigRouter(router *gin.RouterGroup) {
 | 
			
		||||
	r := &api.Config{ConfigApp: application.GetConfigApp()}
 | 
			
		||||
	configG := router.Group("sys/configs")
 | 
			
		||||
	r := new(api.Config)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(r))
 | 
			
		||||
 | 
			
		||||
	baseP := req.NewPermission("config:base")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -2,15 +2,17 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/sys/api"
 | 
			
		||||
	"mayfly-go/internal/sys/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func InitResourceRouter(router *gin.RouterGroup) {
 | 
			
		||||
	r := &api.Resource{ResourceApp: application.GetResourceApp()}
 | 
			
		||||
	rg := router.Group("sys/resources")
 | 
			
		||||
	r := new(api.Resource)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(r))
 | 
			
		||||
 | 
			
		||||
	reqs := [...]*req.Conf{
 | 
			
		||||
		req.NewGet("", r.GetAllResourceTree),
 | 
			
		||||
 
 | 
			
		||||
@@ -2,18 +2,17 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/sys/api"
 | 
			
		||||
	"mayfly-go/internal/sys/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func InitRoleRouter(router *gin.RouterGroup) {
 | 
			
		||||
	r := &api.Role{
 | 
			
		||||
		RoleApp:     application.GetRoleApp(),
 | 
			
		||||
		ResourceApp: application.GetResourceApp(),
 | 
			
		||||
	}
 | 
			
		||||
	rg := router.Group("sys/roles")
 | 
			
		||||
	r := new(api.Role)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(r))
 | 
			
		||||
 | 
			
		||||
	reqs := [...]*req.Conf{
 | 
			
		||||
		req.NewGet("", r.Roles),
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,8 @@
 | 
			
		||||
package router
 | 
			
		||||
 | 
			
		||||
import "github.com/gin-gonic/gin"
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func Init(router *gin.RouterGroup) {
 | 
			
		||||
	InitCaptchaRouter(router)
 | 
			
		||||
 
 | 
			
		||||
@@ -2,17 +2,17 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/sys/api"
 | 
			
		||||
	"mayfly-go/internal/sys/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func InitSyslogRouter(router *gin.RouterGroup) {
 | 
			
		||||
	s := &api.Syslog{
 | 
			
		||||
		SyslogApp: application.GetSyslogApp(),
 | 
			
		||||
	}
 | 
			
		||||
	sysG := router.Group("syslogs")
 | 
			
		||||
	s := new(api.Syslog)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(s))
 | 
			
		||||
 | 
			
		||||
	req.NewGet("", s.Syslogs).Group(sysG)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,13 +2,16 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/sys/api"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func InitSystemRouter(router *gin.RouterGroup) {
 | 
			
		||||
	s := &api.System{}
 | 
			
		||||
	sys := router.Group("sysmsg")
 | 
			
		||||
	s := new(api.System)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(s))
 | 
			
		||||
 | 
			
		||||
	{
 | 
			
		||||
		sys.GET("", s.ConnectWs)
 | 
			
		||||
 
 | 
			
		||||
@@ -17,8 +17,8 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type TagTree struct {
 | 
			
		||||
	TagTreeApp     application.TagTree
 | 
			
		||||
	TagResourceApp application.TagResource
 | 
			
		||||
	TagTreeApp     application.TagTree     `inject:""`
 | 
			
		||||
	TagResourceApp application.TagResource `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *TagTree) GetTagTree(rc *req.Ctx) {
 | 
			
		||||
 
 | 
			
		||||
@@ -17,9 +17,9 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Team struct {
 | 
			
		||||
	TeamApp    application.Team
 | 
			
		||||
	TagApp     application.TagTree
 | 
			
		||||
	AccountApp sys_applicaiton.Account
 | 
			
		||||
	TeamApp    application.Team        `inject:""`
 | 
			
		||||
	TagTreeApp application.TagTree     `inject:""`
 | 
			
		||||
	AccountApp sys_applicaiton.Account `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *Team) GetTeams(rc *req.Ctx) {
 | 
			
		||||
@@ -131,7 +131,7 @@ func (p *Team) SaveTags(rc *req.Ctx) {
 | 
			
		||||
 | 
			
		||||
	for _, v := range addIds {
 | 
			
		||||
		tagId := v
 | 
			
		||||
		tag, err := p.TagApp.GetById(new(entity.TagTree), tagId)
 | 
			
		||||
		tag, err := p.TagTreeApp.GetById(new(entity.TagTree), tagId)
 | 
			
		||||
		biz.ErrIsNil(err, "存在非法标签id")
 | 
			
		||||
 | 
			
		||||
		ptt := &entity.TagTreeTeam{TeamId: teamId, TagId: tagId, TagPath: tag.CodePath}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,32 +2,25 @@ package application
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/tag/infrastructure/persistence"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	tagTreeApp TagTree = newTagTreeApp(
 | 
			
		||||
		persistence.GetTagTreeRepo(),
 | 
			
		||||
		GetTagResourceApp(),
 | 
			
		||||
		persistence.GetTagTreeTeamRepo(),
 | 
			
		||||
	)
 | 
			
		||||
func init() {
 | 
			
		||||
	persistence.Init()
 | 
			
		||||
 | 
			
		||||
	teamApp Team = newTeamApp(
 | 
			
		||||
		persistence.GetTeamRepo(),
 | 
			
		||||
		persistence.GetTeamMemberRepo(),
 | 
			
		||||
		persistence.GetTagTreeTeamRepo(),
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	tagResourceApp TagResource = newTagResourceApp(persistence.GetTagResourceRepo())
 | 
			
		||||
)
 | 
			
		||||
	ioc.Register(new(tagTreeAppImpl), ioc.WithComponentName("TagTreeApp"))
 | 
			
		||||
	ioc.Register(new(teamAppImpl), ioc.WithComponentName("TeamApp"))
 | 
			
		||||
	ioc.Register(new(tagResourceAppImpl), ioc.WithComponentName("TagResourceApp"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetTagTreeApp() TagTree {
 | 
			
		||||
	return tagTreeApp
 | 
			
		||||
	return ioc.Get[TagTree]("TagTreeApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetTeamApp() Team {
 | 
			
		||||
	return teamApp
 | 
			
		||||
	return ioc.Get[Team]("TeamApp")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetTagResourceApp() TagResource {
 | 
			
		||||
	return tagResourceApp
 | 
			
		||||
	return ioc.Get[TagResource]("TagResourceApp")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -12,16 +12,15 @@ type TagResource interface {
 | 
			
		||||
	ListByQuery(condition *entity.TagResourceQuery, toEntity any)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newTagResourceApp(tagResourceRepo repository.TagResource) TagResource {
 | 
			
		||||
	tagResourceApp := &tagResourceAppImpl{}
 | 
			
		||||
	tagResourceApp.Repo = tagResourceRepo
 | 
			
		||||
	return tagResourceApp
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type tagResourceAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.TagResource, repository.TagResource]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 注入TagResourceRepo
 | 
			
		||||
func (tr *tagResourceAppImpl) InjectTagResourceRepo(repo repository.TagResource) {
 | 
			
		||||
	tr.Repo = repo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (tr *tagResourceAppImpl) ListByQuery(condition *entity.TagResourceQuery, toEntity any) {
 | 
			
		||||
	tr.Repo.SelectByCondition(condition, toEntity)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -51,23 +51,16 @@ type TagTree interface {
 | 
			
		||||
	CanAccess(accountId uint64, tagPath ...string) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newTagTreeApp(tagTreeRepo repository.TagTree,
 | 
			
		||||
	tagResourceApp TagResource,
 | 
			
		||||
	tagTreeTeamRepo repository.TagTreeTeam,
 | 
			
		||||
) TagTree {
 | 
			
		||||
	tagTreeApp := &tagTreeAppImpl{
 | 
			
		||||
		tagTreeTeamRepo: tagTreeTeamRepo,
 | 
			
		||||
		tagResourceApp:  tagResourceApp,
 | 
			
		||||
	}
 | 
			
		||||
	tagTreeApp.Repo = tagTreeRepo
 | 
			
		||||
	return tagTreeApp
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type tagTreeAppImpl struct {
 | 
			
		||||
	base.AppImpl[*entity.TagTree, repository.TagTree]
 | 
			
		||||
 | 
			
		||||
	tagTreeTeamRepo repository.TagTreeTeam
 | 
			
		||||
	tagResourceApp  TagResource
 | 
			
		||||
	TagTreeTeamRepo repository.TagTreeTeam `inject:""`
 | 
			
		||||
	TagResourceApp  TagResource            `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 注入TagTreeRepo
 | 
			
		||||
func (p *tagTreeAppImpl) InjectTagTreeRepo(tagTreeRepo repository.TagTree) {
 | 
			
		||||
	p.Repo = tagTreeRepo
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *tagTreeAppImpl) Save(ctx context.Context, tag *entity.TagTree) error {
 | 
			
		||||
@@ -82,7 +75,7 @@ func (p *tagTreeAppImpl) Save(ctx context.Context, tag *entity.TagTree) error {
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return errorx.NewBiz("父节点不存在")
 | 
			
		||||
			}
 | 
			
		||||
			if p.tagResourceApp.CountByCond(&entity.TagResource{TagId: tag.Pid}) > 0 {
 | 
			
		||||
			if p.TagResourceApp.CountByCond(&entity.TagResource{TagId: tag.Pid}) > 0 {
 | 
			
		||||
				return errorx.NewBiz("该父标签已关联资源, 无法添加子标签")
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@@ -135,7 +128,7 @@ func (p *tagTreeAppImpl) GetAccountTagResources(accountId uint64, resourceType i
 | 
			
		||||
 | 
			
		||||
	tagResourceQuery.TagPath = tagPath
 | 
			
		||||
	tagResourceQuery.TagPathLikes = accountTagPaths
 | 
			
		||||
	p.tagResourceApp.ListByQuery(tagResourceQuery, &tagResources)
 | 
			
		||||
	p.TagResourceApp.ListByQuery(tagResourceQuery, &tagResources)
 | 
			
		||||
	return tagResources
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -155,14 +148,14 @@ func (p *tagTreeAppImpl) RelateResource(ctx context.Context, resourceCode string
 | 
			
		||||
	}
 | 
			
		||||
	// 如果tagIds为空数组,则为解绑该标签资源关联关系
 | 
			
		||||
	if len(tagIds) == 0 {
 | 
			
		||||
		return p.tagResourceApp.DeleteByCond(ctx, &entity.TagResource{
 | 
			
		||||
		return p.TagResourceApp.DeleteByCond(ctx, &entity.TagResource{
 | 
			
		||||
			ResourceCode: resourceCode,
 | 
			
		||||
			ResourceType: resourceType,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var oldTagResources []*entity.TagResource
 | 
			
		||||
	p.tagResourceApp.ListByQuery(&entity.TagResourceQuery{ResourceType: resourceType, ResourceCode: resourceCode}, &oldTagResources)
 | 
			
		||||
	p.TagResourceApp.ListByQuery(&entity.TagResourceQuery{ResourceType: resourceType, ResourceCode: resourceCode}, &oldTagResources)
 | 
			
		||||
 | 
			
		||||
	var addTagIds, delTagIds []uint64
 | 
			
		||||
	if len(oldTagResources) == 0 {
 | 
			
		||||
@@ -188,7 +181,7 @@ func (p *tagTreeAppImpl) RelateResource(ctx context.Context, resourceCode string
 | 
			
		||||
				TagPath:      tag.CodePath,
 | 
			
		||||
			})
 | 
			
		||||
		}
 | 
			
		||||
		if err := p.tagResourceApp.BatchInsert(ctx, addTagResource); err != nil {
 | 
			
		||||
		if err := p.TagResourceApp.BatchInsert(ctx, addTagResource); err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
@@ -196,7 +189,7 @@ func (p *tagTreeAppImpl) RelateResource(ctx context.Context, resourceCode string
 | 
			
		||||
	if len(delTagIds) > 0 {
 | 
			
		||||
		for _, tagId := range delTagIds {
 | 
			
		||||
			cond := &entity.TagResource{ResourceCode: resourceCode, ResourceType: resourceType, TagId: tagId}
 | 
			
		||||
			if err := p.tagResourceApp.DeleteByCond(ctx, cond); err != nil {
 | 
			
		||||
			if err := p.TagResourceApp.DeleteByCond(ctx, cond); err != nil {
 | 
			
		||||
				return err
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@@ -207,7 +200,7 @@ func (p *tagTreeAppImpl) RelateResource(ctx context.Context, resourceCode string
 | 
			
		||||
 | 
			
		||||
func (p *tagTreeAppImpl) ListTagPathByResource(resourceType int8, resourceCode string) []string {
 | 
			
		||||
	var trs []*entity.TagResource
 | 
			
		||||
	p.tagResourceApp.ListByQuery(&entity.TagResourceQuery{ResourceType: resourceType, ResourceCode: resourceCode}, &trs)
 | 
			
		||||
	p.TagResourceApp.ListByQuery(&entity.TagResourceQuery{ResourceType: resourceType, ResourceCode: resourceCode}, &trs)
 | 
			
		||||
	return collx.ArrayMap(trs, func(tr *entity.TagResource) string {
 | 
			
		||||
		return tr.TagPath
 | 
			
		||||
	})
 | 
			
		||||
@@ -220,7 +213,7 @@ func (p *tagTreeAppImpl) ListTagByPath(tagPaths ...string) []*entity.TagTree {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *tagTreeAppImpl) ListTagByAccountId(accountId uint64) []string {
 | 
			
		||||
	return p.tagTreeTeamRepo.SelectTagPathsByAccountId(accountId)
 | 
			
		||||
	return p.TagTreeTeamRepo.SelectTagPathsByAccountId(accountId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *tagTreeAppImpl) CanAccess(accountId uint64, tagPath ...string) error {
 | 
			
		||||
@@ -250,7 +243,7 @@ func (p *tagTreeAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
			
		||||
		return errorx.NewBiz("您无权删除该标签")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if p.tagResourceApp.CountByCond(&entity.TagResource{TagId: id}) > 0 {
 | 
			
		||||
	if p.TagResourceApp.CountByCond(&entity.TagResource{TagId: id}) > 0 {
 | 
			
		||||
		return errorx.NewBiz("请先移除该标签关联的资源")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -258,6 +251,6 @@ func (p *tagTreeAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
			
		||||
		return p.DeleteById(ctx, id)
 | 
			
		||||
	}, func(ctx context.Context) error {
 | 
			
		||||
		// 删除该标签关联的团队信息
 | 
			
		||||
		return p.tagTreeTeamRepo.DeleteByCond(ctx, &entity.TagTreeTeam{TagId: id})
 | 
			
		||||
		return p.TagTreeTeamRepo.DeleteByCond(ctx, &entity.TagTreeTeam{TagId: id})
 | 
			
		||||
	})
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -38,44 +38,33 @@ type Team interface {
 | 
			
		||||
	DeleteTag(tx context.Context, teamId, tagId uint64) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func newTeamApp(teamRepo repository.Team,
 | 
			
		||||
	teamMemberRepo repository.TeamMember,
 | 
			
		||||
	tagTreeTeamRepo repository.TagTreeTeam,
 | 
			
		||||
) Team {
 | 
			
		||||
	return &teamAppImpl{
 | 
			
		||||
		teamRepo:        teamRepo,
 | 
			
		||||
		teamMemberRepo:  teamMemberRepo,
 | 
			
		||||
		tagTreeTeamRepo: tagTreeTeamRepo,
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type teamAppImpl struct {
 | 
			
		||||
	teamRepo        repository.Team
 | 
			
		||||
	teamMemberRepo  repository.TeamMember
 | 
			
		||||
	tagTreeTeamRepo repository.TagTreeTeam
 | 
			
		||||
	TeamRepo        repository.Team        `inject:""`
 | 
			
		||||
	TeamMemberRepo  repository.TeamMember  `inject:""`
 | 
			
		||||
	TagTreeTeamRepo repository.TagTreeTeam `inject:""`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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...)
 | 
			
		||||
	return p.TeamRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *teamAppImpl) Save(ctx context.Context, team *entity.Team) error {
 | 
			
		||||
	if team.Id == 0 {
 | 
			
		||||
		return p.teamRepo.Insert(ctx, team)
 | 
			
		||||
		return p.TeamRepo.Insert(ctx, team)
 | 
			
		||||
	}
 | 
			
		||||
	return p.teamRepo.UpdateById(ctx, team)
 | 
			
		||||
	return p.TeamRepo.UpdateById(ctx, team)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *teamAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
			
		||||
	return gormx.Tx(
 | 
			
		||||
		func(db *gorm.DB) error {
 | 
			
		||||
			return p.teamRepo.DeleteByIdWithDb(ctx, db, id)
 | 
			
		||||
			return p.TeamRepo.DeleteByIdWithDb(ctx, db, id)
 | 
			
		||||
		},
 | 
			
		||||
		func(db *gorm.DB) error {
 | 
			
		||||
			return p.teamMemberRepo.DeleteByCondWithDb(ctx, db, &entity.TeamMember{TeamId: id})
 | 
			
		||||
			return p.TeamMemberRepo.DeleteByCondWithDb(ctx, db, &entity.TeamMember{TeamId: id})
 | 
			
		||||
		},
 | 
			
		||||
		func(db *gorm.DB) error {
 | 
			
		||||
			return p.tagTreeTeamRepo.DeleteByCondWithDb(ctx, db, &entity.TagTreeTeam{TeamId: id})
 | 
			
		||||
			return p.TagTreeTeamRepo.DeleteByCondWithDb(ctx, db, &entity.TagTreeTeam{TeamId: id})
 | 
			
		||||
		},
 | 
			
		||||
	)
 | 
			
		||||
}
 | 
			
		||||
@@ -83,30 +72,30 @@ func (p *teamAppImpl) Delete(ctx context.Context, id uint64) error {
 | 
			
		||||
// --------------- 团队成员相关接口 ---------------
 | 
			
		||||
 | 
			
		||||
func (p *teamAppImpl) GetMemberPage(condition *entity.TeamMember, pageParam *model.PageParam, toEntity any) (*model.PageResult[any], error) {
 | 
			
		||||
	return p.teamMemberRepo.GetPageList(condition, pageParam, toEntity)
 | 
			
		||||
	return p.TeamMemberRepo.GetPageList(condition, pageParam, toEntity)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 保存团队成员信息
 | 
			
		||||
func (p *teamAppImpl) SaveMember(ctx context.Context, teamMember *entity.TeamMember) {
 | 
			
		||||
	teamMember.Id = 0
 | 
			
		||||
	biz.IsTrue(!p.teamMemberRepo.IsExist(teamMember.TeamId, teamMember.AccountId), "该成员已存在")
 | 
			
		||||
	p.teamMemberRepo.Insert(ctx, teamMember)
 | 
			
		||||
	biz.IsTrue(!p.TeamMemberRepo.IsExist(teamMember.TeamId, teamMember.AccountId), "该成员已存在")
 | 
			
		||||
	p.TeamMemberRepo.Insert(ctx, teamMember)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 删除团队成员信息
 | 
			
		||||
func (p *teamAppImpl) DeleteMember(ctx context.Context, teamId, accountId uint64) {
 | 
			
		||||
	p.teamMemberRepo.DeleteByCond(ctx, &entity.TeamMember{TeamId: teamId, AccountId: accountId})
 | 
			
		||||
	p.TeamMemberRepo.DeleteByCond(ctx, &entity.TeamMember{TeamId: teamId, AccountId: accountId})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (p *teamAppImpl) IsExistMember(teamId, accounId uint64) bool {
 | 
			
		||||
	return p.teamMemberRepo.IsExist(teamId, accounId)
 | 
			
		||||
	return p.TeamMemberRepo.IsExist(teamId, accounId)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//--------------- 关联项目相关接口 ---------------
 | 
			
		||||
//--------------- 关联标签相关接口 ---------------
 | 
			
		||||
 | 
			
		||||
func (p *teamAppImpl) ListTagIds(teamId uint64) []uint64 {
 | 
			
		||||
	tags := &[]entity.TagTreeTeam{}
 | 
			
		||||
	p.tagTreeTeamRepo.ListByCondOrder(&entity.TagTreeTeam{TeamId: teamId}, tags)
 | 
			
		||||
	p.TagTreeTeamRepo.ListByCondOrder(&entity.TagTreeTeam{TeamId: teamId}, tags)
 | 
			
		||||
	ids := make([]uint64, 0)
 | 
			
		||||
	for _, v := range *tags {
 | 
			
		||||
		ids = append(ids, v.TagId)
 | 
			
		||||
@@ -117,10 +106,10 @@ func (p *teamAppImpl) ListTagIds(teamId uint64) []uint64 {
 | 
			
		||||
// 保存关联项目信息
 | 
			
		||||
func (p *teamAppImpl) SaveTag(ctx context.Context, tagTreeTeam *entity.TagTreeTeam) error {
 | 
			
		||||
	tagTreeTeam.Id = 0
 | 
			
		||||
	return p.tagTreeTeamRepo.Insert(ctx, tagTreeTeam)
 | 
			
		||||
	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})
 | 
			
		||||
	return p.TagTreeTeamRepo.DeleteByCond(ctx, &entity.TagTreeTeam{TeamId: teamId, TagId: tagId})
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,31 +1,34 @@
 | 
			
		||||
package persistence
 | 
			
		||||
 | 
			
		||||
import "mayfly-go/internal/tag/domain/repository"
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	tagTreeRepo     repository.TagTree     = newTagTreeRepo()
 | 
			
		||||
	tagTreeTeamRepo repository.TagTreeTeam = newTagTreeTeamRepo()
 | 
			
		||||
	tagResourceRepo repository.TagResource = newTagResourceRepo()
 | 
			
		||||
	teamRepo        repository.Team        = newTeamRepo()
 | 
			
		||||
	teamMemberRepo  repository.TeamMember  = newTeamMemberRepo()
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/tag/domain/repository"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func Init() {
 | 
			
		||||
	ioc.Register(newTagTreeRepo(), ioc.WithComponentName("TagTreeRepo"))
 | 
			
		||||
	ioc.Register(newTagTreeTeamRepo(), ioc.WithComponentName("TagTreeTeamRepo"))
 | 
			
		||||
	ioc.Register(newTagResourceRepo(), ioc.WithComponentName("TagResourceRepo"))
 | 
			
		||||
	ioc.Register(newTeamRepo(), ioc.WithComponentName("TeamRepo"))
 | 
			
		||||
	ioc.Register(newTeamMemberRepo(), ioc.WithComponentName("TeamMemberRepo"))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetTagTreeRepo() repository.TagTree {
 | 
			
		||||
	return tagTreeRepo
 | 
			
		||||
	return ioc.Get[repository.TagTree]("TagTreeRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetTagTreeTeamRepo() repository.TagTreeTeam {
 | 
			
		||||
	return tagTreeTeamRepo
 | 
			
		||||
	return ioc.Get[repository.TagTreeTeam]("TagTreeTeamRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetTagResourceRepo() repository.TagResource {
 | 
			
		||||
	return tagResourceRepo
 | 
			
		||||
	return ioc.Get[repository.TagResource]("TagResourceRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetTeamRepo() repository.Team {
 | 
			
		||||
	return teamRepo
 | 
			
		||||
	return ioc.Get[repository.Team]("TeamRepo")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetTeamMemberRepo() repository.TeamMember {
 | 
			
		||||
	return teamMemberRepo
 | 
			
		||||
	return ioc.Get[repository.TeamMember]("TeamMemberRepo")
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,17 +2,16 @@ package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mayfly-go/internal/tag/api"
 | 
			
		||||
	"mayfly-go/internal/tag/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func InitTagTreeRouter(router *gin.RouterGroup) {
 | 
			
		||||
	m := &api.TagTree{
 | 
			
		||||
		TagTreeApp:     application.GetTagTreeApp(),
 | 
			
		||||
		TagResourceApp: application.GetTagResourceApp(),
 | 
			
		||||
	}
 | 
			
		||||
	m := new(api.TagTree)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(m))
 | 
			
		||||
 | 
			
		||||
	tagTree := router.Group("/tag-trees")
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
@@ -1,20 +1,17 @@
 | 
			
		||||
package router
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	sysapp "mayfly-go/internal/sys/application"
 | 
			
		||||
	"mayfly-go/internal/tag/api"
 | 
			
		||||
	"mayfly-go/internal/tag/application"
 | 
			
		||||
	"mayfly-go/pkg/biz"
 | 
			
		||||
	"mayfly-go/pkg/ioc"
 | 
			
		||||
	"mayfly-go/pkg/req"
 | 
			
		||||
 | 
			
		||||
	"github.com/gin-gonic/gin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func InitTeamRouter(router *gin.RouterGroup) {
 | 
			
		||||
	m := &api.Team{
 | 
			
		||||
		TeamApp:    application.GetTeamApp(),
 | 
			
		||||
		TagApp:     application.GetTagTreeApp(),
 | 
			
		||||
		AccountApp: sysapp.GetAccountApp(),
 | 
			
		||||
	}
 | 
			
		||||
	m := new(api.Team)
 | 
			
		||||
	biz.ErrIsNil(ioc.Inject(m))
 | 
			
		||||
 | 
			
		||||
	team := router.Group("/teams")
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user