fix: 优化 repo 部分公共方法 (#6200)
Some checks failed
sync2gitee / repo-sync (push) Failing after -8m7s

This commit is contained in:
ssongliu 2024-08-21 18:04:51 +08:00 committed by GitHub
parent 1215e3bb30
commit a44c4d96d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
43 changed files with 141 additions and 286 deletions

View file

@ -32,8 +32,6 @@ func ErrorWithDetail(ctx *gin.Context, code int, msgKey string, err error) {
res.Message = i18n.GetMsgWithMap("ErrInvalidParams", nil)
case errors.Is(constant.ErrStructTransform, err):
res.Message = i18n.GetMsgWithMap("ErrStructTransform", map[string]interface{}{"detail": err})
case errors.Is(constant.ErrInitialPassword, err):
res.Message = i18n.GetMsgWithMap("ErrInitialPassword", map[string]interface{}{"detail": err})
case errors.As(err, &buserr.BusinessError{}):
res.Message = err.Error()
default:

View file

@ -17,7 +17,7 @@ type IAppRepo interface {
OrderByRecommend() DBOption
GetRecommend() DBOption
WithResource(resource string) DBOption
WithLikeName(name string) DBOption
WithByLikeName(name string) DBOption
Page(page, size int, opts ...DBOption) (int64, []model.App, error)
GetFirst(opts ...DBOption) (model.App, error)
GetBy(opts ...DBOption) ([]model.App, error)
@ -32,7 +32,7 @@ func NewIAppRepo() IAppRepo {
return &AppRepo{}
}
func (a AppRepo) WithLikeName(name string) DBOption {
func (a AppRepo) WithByLikeName(name string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(name) == 0 {
return g

View file

@ -16,7 +16,6 @@ type IBackupRepo interface {
CreateRecord(record *model.BackupRecord) error
DeleteRecord(ctx context.Context, opts ...DBOption) error
UpdateRecord(record *model.BackupRecord) error
WithByDetailName(detailName string) DBOption
WithByFileName(fileName string) DBOption
WithByCronID(cronjobID uint) DBOption
}
@ -47,15 +46,6 @@ func (u *BackupRepo) PageRecord(page, size int, opts ...DBOption) (int64, []mode
return count, users, err
}
func (u *BackupRepo) WithByDetailName(detailName string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(detailName) == 0 {
return g
}
return g.Where("detail_name = ?", detailName)
}
}
func (u *BackupRepo) WithByFileName(fileName string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(fileName) == 0 {

View file

@ -14,19 +14,22 @@ type DBOption func(*gorm.DB) *gorm.DB
type ICommonRepo interface {
WithByID(id uint) DBOption
WithByIDs(ids []uint) DBOption
WithByName(name string) DBOption
WithByNames(names []string) DBOption
WithByLikeName(name string) DBOption
WithByDetailName(detailName string) DBOption
WithByFrom(from string) DBOption
WithByType(tp string) DBOption
WithTypes(types []string) DBOption
WithByStatus(status string) DBOption
WithOrderBy(orderStr string) DBOption
WithOrderRuleBy(orderBy, order string) DBOption
WithByGroupID(groupID uint) DBOption
WithLikeName(name string) DBOption
WithIdsIn(ids []uint) DBOption
WithNamesIn(names []string) DBOption
WithByDate(startTime, endTime time.Time) DBOption
WithByCreatedAt(startTime, endTime time.Time) DBOption
WithByStartDate(startTime time.Time) DBOption
WithByStatus(status string) DBOption
WithByFrom(from string) DBOption
}
type CommonRepo struct{}
@ -40,12 +43,62 @@ func (c *CommonRepo) WithByID(id uint) DBOption {
return g.Where("id = ?", id)
}
}
func (c *CommonRepo) WithByIDs(ids []uint) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("id in (?)", ids)
}
}
func (c *CommonRepo) WithByName(name string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("name = ?", name)
}
}
func (c *CommonRepo) WithByNames(names []string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("name in (?)", names)
}
}
func (c *CommonRepo) WithByLikeName(name string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(name) == 0 {
return g
}
return g.Where("name like ?", "%"+name+"%")
}
}
func (c *CommonRepo) WithByDetailName(detailName string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(detailName) == 0 {
return g
}
return g.Where("detail_name = ?", detailName)
}
}
func (c *CommonRepo) WithByType(tp string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("type = ?", tp)
}
}
func (c *CommonRepo) WithTypes(types []string) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("type in (?)", types)
}
}
func (c *CommonRepo) WithByStatus(status string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(status) == 0 {
return g
}
return g.Where("status = ?", status)
}
}
func (c *CommonRepo) WithByFrom(from string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("`from` = ?", from)
}
}
func (c *CommonRepo) WithByDate(startTime, endTime time.Time) DBOption {
return func(g *gorm.DB) *gorm.DB {
@ -59,57 +112,11 @@ func (c *CommonRepo) WithByCreatedAt(startTime, endTime time.Time) DBOption {
}
}
func (c *CommonRepo) WithByStartDate(startTime time.Time) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("start_time < ?", startTime)
}
}
func (c *CommonRepo) WithByType(tp string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("type = ?", tp)
}
}
func (c *CommonRepo) WithByGroupID(groupID uint) DBOption {
return func(g *gorm.DB) *gorm.DB {
if groupID == 0 {
return g
}
return g.Where("group_id = ?", groupID)
}
}
func (c *CommonRepo) WithByStatus(status string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(status) == 0 {
return g
}
return g.Where("status = ?", status)
}
}
func (c *CommonRepo) WithByFrom(from string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("`from` = ?", from)
}
}
func (c *CommonRepo) WithLikeName(name string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(name) == 0 {
return g
}
return g.Where("name like ?", "%"+name+"%")
}
}
func (c *CommonRepo) WithOrderBy(orderStr string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Order(orderStr)
}
}
func (c *CommonRepo) WithOrderRuleBy(orderBy, order string) DBOption {
switch order {
case constant.OrderDesc:
@ -125,24 +132,6 @@ func (c *CommonRepo) WithOrderRuleBy(orderBy, order string) DBOption {
}
}
func (c *CommonRepo) WithNamesIn(names []string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("name in (?)", names)
}
}
func (c *CommonRepo) WithIdsIn(ids []uint) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("id in (?)", ids)
}
}
func (c *CommonRepo) WithIdsNotIn(ids []uint) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("id not in (?)", ids)
}
}
func getTx(ctx context.Context, opts ...DBOption) *gorm.DB {
tx, ok := ctx.Value(constant.DB).(*gorm.DB)
if ok {

View file

@ -20,7 +20,6 @@ type IDatabaseRepo interface {
Update(id uint, vars map[string]interface{}) error
Delete(ctx context.Context, opts ...DBOption) error
Get(opts ...DBOption) (model.Database, error)
WithByFrom(from string) DBOption
WithoutByFrom(from string) DBOption
WithAppInstallID(appInstallID uint) DBOption
WithTypeList(dbType string) DBOption
@ -87,12 +86,6 @@ func (d *DatabaseRepo) GetList(opts ...DBOption) ([]model.Database, error) {
return databases, nil
}
func (d *DatabaseRepo) WithByFrom(from string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("`from` = ?", from)
}
}
func (d *DatabaseRepo) WithoutByFrom(from string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("`from` != ?", from)

View file

@ -15,7 +15,6 @@ type MysqlRepo struct{}
type IMysqlRepo interface {
Get(opts ...DBOption) (model.DatabaseMysql, error)
WithByMysqlName(mysqlName string) DBOption
WithByFrom(from string) DBOption
List(opts ...DBOption) ([]model.DatabaseMysql, error)
Page(limit, offset int, opts ...DBOption) (int64, []model.DatabaseMysql, error)
Create(ctx context.Context, mysql *model.DatabaseMysql) error
@ -112,12 +111,3 @@ func (u *MysqlRepo) WithByMysqlName(mysqlName string) DBOption {
return g.Where("mysql_name = ?", mysqlName)
}
}
func (u *MysqlRepo) WithByFrom(from string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(from) != 0 {
return g.Where("`from` = ?", from)
}
return g
}
}

View file

@ -15,7 +15,6 @@ type PostgresqlRepo struct{}
type IPostgresqlRepo interface {
Get(opts ...DBOption) (model.DatabasePostgresql, error)
WithByPostgresqlName(postgresqlName string) DBOption
WithByFrom(from string) DBOption
List(opts ...DBOption) ([]model.DatabasePostgresql, error)
Page(limit, offset int, opts ...DBOption) (int64, []model.DatabasePostgresql, error)
Create(ctx context.Context, postgresql *model.DatabasePostgresql) error
@ -112,12 +111,3 @@ func (u *PostgresqlRepo) WithByPostgresqlName(postgresqlName string) DBOption {
return g.Where("postgresql_name = ?", postgresqlName)
}
}
func (u *PostgresqlRepo) WithByFrom(from string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(from) != 0 {
return g.Where("`from` = ?", from)
}
return g
}
}

View file

@ -12,7 +12,6 @@ type RuntimeRepo struct {
}
type IRuntimeRepo interface {
WithName(name string) DBOption
WithImage(image string) DBOption
WithNotId(id uint) DBOption
WithStatus(status string) DBOption
@ -30,12 +29,6 @@ func NewIRunTimeRepo() IRuntimeRepo {
return &RuntimeRepo{}
}
func (r *RuntimeRepo) WithName(name string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("name = ?", name)
}
}
func (r *RuntimeRepo) WithStatus(status string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("status = ?", status)

View file

@ -2,6 +2,7 @@ package repo
import (
"context"
"github.com/1Panel-dev/1Panel/agent/app/model"
"gorm.io/gorm"
)
@ -16,9 +17,7 @@ type ITaskRepo interface {
Update(ctx context.Context, task *model.Task) error
WithByID(id string) DBOption
WithType(taskType string) DBOption
WithResourceID(id uint) DBOption
WithStatus(status string) DBOption
WithOperate(taskOperate string) DBOption
}
@ -32,24 +31,12 @@ func (t TaskRepo) WithByID(id string) DBOption {
}
}
func (t TaskRepo) WithType(taskType string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("type = ?", taskType)
}
}
func (t TaskRepo) WithOperate(taskOperate string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("operate = ?", taskOperate)
}
}
func (t TaskRepo) WithStatus(status string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("status = ?", status)
}
}
func (t TaskRepo) WithResourceID(id uint) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("resource_id = ?", id)

View file

@ -18,8 +18,6 @@ type IWebsiteRepo interface {
WithDefaultServer() DBOption
WithDomainLike(domain string) DBOption
WithRuntimeID(runtimeID uint) DBOption
WithIDs(ids []uint) DBOption
WithTypes(types []string) DBOption
WithParentID(websiteID uint) DBOption
Page(page, size int, opts ...DBOption) (int64, []model.Website, error)
@ -48,18 +46,6 @@ func (w *WebsiteRepo) WithAppInstallId(appInstallID uint) DBOption {
}
}
func (w *WebsiteRepo) WithIDs(ids []uint) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("id in (?)", ids)
}
}
func (w *WebsiteRepo) WithTypes(types []string) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("type in (?)", types)
}
}
func (w *WebsiteRepo) WithRuntimeID(runtimeID uint) DBOption {
return func(db *gorm.DB) *gorm.DB {
return db.Where("runtime_id = ?", runtimeID)

View file

@ -55,7 +55,7 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) {
var opts []repo.DBOption
opts = append(opts, appRepo.OrderByRecommend())
if req.Name != "" {
opts = append(opts, appRepo.WithLikeName(req.Name))
opts = append(opts, appRepo.WithByLikeName(req.Name))
}
if req.Type != "" {
opts = append(opts, appRepo.WithType(req.Type))
@ -83,7 +83,7 @@ func (a AppService) PageApp(req request.AppSearch) (interface{}, error) {
for _, t := range appTags {
appIds = append(appIds, t.AppId)
}
opts = append(opts, commonRepo.WithIdsIn(appIds))
opts = append(opts, commonRepo.WithByIDs(appIds))
}
var res response.AppRes
total, apps, err := appRepo.Page(req.Page, req.PageSize, opts...)

View file

@ -87,7 +87,7 @@ func (a *AppInstallService) Page(req request.AppInstalledSearch) (int64, []respo
)
if req.Name != "" {
opts = append(opts, commonRepo.WithLikeName(req.Name))
opts = append(opts, commonRepo.WithByLikeName(req.Name))
}
if len(req.Tags) != 0 {

View file

@ -33,7 +33,6 @@ import (
"github.com/subosito/gotenv"
"gopkg.in/yaml.v3"
"github.com/1Panel-dev/1Panel/agent/app/repo"
"github.com/1Panel-dev/1Panel/agent/utils/env"
"github.com/1Panel-dev/1Panel/agent/app/dto/response"
@ -256,8 +255,7 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI
if dbConfig.DbName != "" && dbConfig.DbUser != "" && dbConfig.Password != "" {
switch database.Type {
case constant.AppPostgresql, constant.AppPostgres:
iPostgresqlRepo := repo.NewIPostgresqlRepo()
oldPostgresqlDb, _ := iPostgresqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), iPostgresqlRepo.WithByFrom(constant.ResourceLocal))
oldPostgresqlDb, _ := postgresqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), commonRepo.WithByFrom(constant.ResourceLocal))
resourceId = oldPostgresqlDb.ID
if oldPostgresqlDb.ID > 0 {
if oldPostgresqlDb.Username != dbConfig.DbUser || oldPostgresqlDb.Password != dbConfig.Password {
@ -279,8 +277,7 @@ func createLink(ctx context.Context, installTask *task.Task, app model.App, appI
resourceId = pgdb.ID
}
case constant.AppMysql, constant.AppMariaDB:
iMysqlRepo := repo.NewIMysqlRepo()
oldMysqlDb, _ := iMysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), iMysqlRepo.WithByFrom(constant.ResourceLocal))
oldMysqlDb, _ := mysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), commonRepo.WithByFrom(constant.ResourceLocal))
resourceId = oldMysqlDb.ID
if oldMysqlDb.ID > 0 {
if oldMysqlDb.Username != dbConfig.DbUser || oldMysqlDb.Password != dbConfig.Password {
@ -432,7 +429,7 @@ func deleteAppInstall(deleteReq request.AppInstallDelete) error {
_ = postgresqlRepo.Delete(ctx, postgresqlRepo.WithByPostgresqlName(install.Name))
}
_ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType("app"), commonRepo.WithByName(install.App.Key), backupRepo.WithByDetailName(install.Name))
_ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType("app"), commonRepo.WithByName(install.App.Key), commonRepo.WithByDetailName(install.Name))
uploadDir := path.Join(global.CONF.System.BaseDir, fmt.Sprintf("1panel/uploads/app/%s/%s", install.App.Key, install.Name))
if _, err := os.Stat(uploadDir); err == nil {
_ = os.RemoveAll(uploadDir)

View file

@ -66,7 +66,7 @@ func (u *BackupService) SearchRecordsWithPage(search dto.RecordSearch) (int64, [
commonRepo.WithOrderBy("created_at desc"),
commonRepo.WithByName(search.Name),
commonRepo.WithByType(search.Type),
backupRepo.WithByDetailName(search.DetailName),
commonRepo.WithByDetailName(search.DetailName),
)
if err != nil {
return 0, nil, err
@ -153,10 +153,10 @@ func (u *BackupService) DownloadRecord(info dto.DownloadRecord) (string, error)
func (u *BackupService) DeleteRecordByName(backupType, name, detailName string, withDeleteFile bool) error {
if !withDeleteFile {
return backupRepo.DeleteRecord(context.Background(), commonRepo.WithByType(backupType), commonRepo.WithByName(name), backupRepo.WithByDetailName(detailName))
return backupRepo.DeleteRecord(context.Background(), commonRepo.WithByType(backupType), commonRepo.WithByName(name), commonRepo.WithByDetailName(detailName))
}
records, err := backupRepo.ListRecord(commonRepo.WithByType(backupType), commonRepo.WithByName(name), backupRepo.WithByDetailName(detailName))
records, err := backupRepo.ListRecord(commonRepo.WithByType(backupType), commonRepo.WithByName(name), commonRepo.WithByDetailName(detailName))
if err != nil {
return err
}
@ -176,7 +176,7 @@ func (u *BackupService) DeleteRecordByName(backupType, name, detailName string,
}
func (u *BackupService) BatchDeleteRecord(ids []uint) error {
records, err := backupRepo.ListRecord(commonRepo.WithIdsIn(ids))
records, err := backupRepo.ListRecord(commonRepo.WithByIDs(ids))
if err != nil {
return err
}
@ -190,7 +190,7 @@ func (u *BackupService) BatchDeleteRecord(ids []uint) error {
global.LOG.Errorf("remove file %s failed, err: %v", path.Join(record.FileDir, record.FileName), err)
}
}
return backupRepo.DeleteRecord(context.Background(), commonRepo.WithIdsIn(ids))
return backupRepo.DeleteRecord(context.Background(), commonRepo.WithByIDs(ids))
}
func (u *BackupService) ListFiles(req dto.OperateByID) []string {

View file

@ -193,7 +193,7 @@ func handleAppRecover(install *model.AppInstall, recoverFile string, isRollback
if err != nil {
return err
}
database, err = databaseRepo.Get(databaseRepo.WithAppInstallID(resourceApp.ID), commonRepo.WithByType(resource.Key), databaseRepo.WithByFrom(constant.AppResourceLocal), commonRepo.WithByName(resourceApp.Name))
database, err = databaseRepo.Get(databaseRepo.WithAppInstallID(resourceApp.ID), commonRepo.WithByType(resource.Key), commonRepo.WithByFrom(constant.AppResourceLocal), commonRepo.WithByName(resourceApp.Name))
if err != nil {
return err
}

View file

@ -126,7 +126,7 @@ func (c *ClamService) Operate(operate string) error {
}
func (c *ClamService) SearchWithPage(req dto.SearchClamWithPage) (int64, interface{}, error) {
total, commands, err := clamRepo.Page(req.Page, req.PageSize, commonRepo.WithLikeName(req.Info), commonRepo.WithOrderRuleBy(req.OrderBy, req.Order))
total, commands, err := clamRepo.Page(req.Page, req.PageSize, commonRepo.WithByLikeName(req.Info), commonRepo.WithOrderRuleBy(req.OrderBy, req.Order))
if err != nil {
return 0, nil, err
}

View file

@ -38,7 +38,7 @@ func (u *ComposeTemplateService) List() ([]dto.ComposeTemplateInfo, error) {
}
func (u *ComposeTemplateService) SearchWithPage(req dto.SearchWithPage) (int64, interface{}, error) {
total, composes, err := composeRepo.Page(req.Page, req.PageSize, commonRepo.WithLikeName(req.Info))
total, composes, err := composeRepo.Page(req.Page, req.PageSize, commonRepo.WithByLikeName(req.Info))
var dtoComposeTemplates []dto.ComposeTemplateInfo
for _, compose := range composes {
var item dto.ComposeTemplateInfo
@ -72,7 +72,7 @@ func (u *ComposeTemplateService) Delete(ids []uint) error {
}
return composeRepo.Delete(commonRepo.WithByID(ids[0]))
}
return composeRepo.Delete(commonRepo.WithIdsIn(ids))
return composeRepo.Delete(commonRepo.WithByIDs(ids))
}
func (u *ComposeTemplateService) Update(id uint, upMap map[string]interface{}) error {

View file

@ -281,7 +281,7 @@ func (u *ContainerService) Inspect(req dto.InspectReq) (string, error) {
case "image":
inspectInfo, _, err = client.ImageInspectWithRaw(context.Background(), req.ID)
case "network":
inspectInfo, err = client.NetworkInspect(context.TODO(), req.ID, types.NetworkInspectOptions{})
inspectInfo, err = client.NetworkInspect(context.TODO(), req.ID, network.InspectOptions{})
case "volume":
inspectInfo, err = client.VolumeInspect(context.TODO(), req.ID)
}

View file

@ -40,7 +40,7 @@ func NewICronjobService() ICronjobService {
}
func (u *CronjobService) SearchWithPage(search dto.PageCronjob) (int64, interface{}, error) {
total, cronjobs, err := cronjobRepo.Page(search.Page, search.PageSize, commonRepo.WithLikeName(search.Info), commonRepo.WithOrderRuleBy(search.OrderBy, search.Order))
total, cronjobs, err := cronjobRepo.Page(search.Page, search.PageSize, commonRepo.WithByLikeName(search.Info), commonRepo.WithOrderRuleBy(search.OrderBy, search.Order))
var dtoCronjobs []dto.CronjobInfo
for _, cronjob := range cronjobs {
var item dto.CronjobInfo

View file

@ -295,7 +295,7 @@ func (u *CronjobService) removeExpiredBackup(cronjob model.Cronjob, accountMap m
if record.ID != 0 {
opts = append(opts, commonRepo.WithByType(record.Type))
opts = append(opts, commonRepo.WithByName(record.Name))
opts = append(opts, backupRepo.WithByDetailName(record.DetailName))
opts = append(opts, commonRepo.WithByDetailName(record.DetailName))
}
records, _ := backupRepo.ListRecord(opts...)
if len(records) <= int(cronjob.RetainCopies) {

View file

@ -42,7 +42,7 @@ func NewIDatabaseService() IDatabaseService {
func (u *DatabaseService) SearchWithPage(search dto.DatabaseSearch) (int64, interface{}, error) {
total, dbs, err := databaseRepo.Page(search.Page, search.PageSize,
databaseRepo.WithTypeList(search.Type),
commonRepo.WithLikeName(search.Info),
commonRepo.WithByLikeName(search.Info),
commonRepo.WithOrderRuleBy(search.OrderBy, search.Order),
databaseRepo.WithoutByFrom("local"),
)
@ -215,7 +215,7 @@ func (u *DatabaseService) Create(req dto.DatabaseCreate) error {
func (u *DatabaseService) DeleteCheck(id uint) ([]string, error) {
var appInUsed []string
apps, _ := appInstallResourceRepo.GetBy(databaseRepo.WithByFrom("remote"), appInstallResourceRepo.WithLinkId(id))
apps, _ := appInstallResourceRepo.GetBy(commonRepo.WithByFrom("remote"), appInstallResourceRepo.WithLinkId(id))
for _, app := range apps {
appInstall, _ := appInstallRepo.GetFirst(commonRepo.WithByID(app.AppInstallId))
if appInstall.ID != 0 {

View file

@ -55,7 +55,7 @@ func NewIMysqlService() IMysqlService {
func (u *MysqlService) SearchWithPage(search dto.MysqlDBSearch) (int64, interface{}, error) {
total, mysqls, err := mysqlRepo.Page(search.Page, search.PageSize,
mysqlRepo.WithByMysqlName(search.Database),
commonRepo.WithLikeName(search.Info),
commonRepo.WithByLikeName(search.Info),
commonRepo.WithOrderRuleBy(search.OrderBy, search.Order),
)
var dtoMysqls []dto.MysqlDBInfo
@ -101,7 +101,7 @@ func (u *MysqlService) Create(ctx context.Context, req dto.MysqlDBCreate) (*mode
return nil, buserr.New(constant.ErrCmdIllegal)
}
mysql, _ := mysqlRepo.Get(commonRepo.WithByName(req.Name), mysqlRepo.WithByMysqlName(req.Database), databaseRepo.WithByFrom(req.From))
mysql, _ := mysqlRepo.Get(commonRepo.WithByName(req.Name), mysqlRepo.WithByMysqlName(req.Database), commonRepo.WithByFrom(req.From))
if mysql.ID != 0 {
return nil, constant.ErrRecordExist
}
@ -284,7 +284,7 @@ func (u *MysqlService) Delete(ctx context.Context, req dto.MysqlDBDelete) error
if _, err := os.Stat(backupDir); err == nil {
_ = os.RemoveAll(backupDir)
}
_ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType(req.Type), commonRepo.WithByName(req.Database), backupRepo.WithByDetailName(db.Name))
_ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType(req.Type), commonRepo.WithByName(req.Database), commonRepo.WithByDetailName(db.Name))
global.LOG.Infof("delete database %s-%s backups successful", req.Database, db.Name)
}

View file

@ -43,7 +43,7 @@ func NewIPostgresqlService() IPostgresqlService {
func (u *PostgresqlService) SearchWithPage(search dto.PostgresqlDBSearch) (int64, interface{}, error) {
total, postgresqls, err := postgresqlRepo.Page(search.Page, search.PageSize,
postgresqlRepo.WithByPostgresqlName(search.Database),
commonRepo.WithLikeName(search.Info),
commonRepo.WithByLikeName(search.Info),
commonRepo.WithOrderRuleBy(search.OrderBy, search.Order),
)
var dtoPostgresqls []dto.PostgresqlDBInfo
@ -125,7 +125,7 @@ func (u *PostgresqlService) Create(ctx context.Context, req dto.PostgresqlDBCrea
return nil, buserr.New(constant.ErrCmdIllegal)
}
pgsql, _ := postgresqlRepo.Get(commonRepo.WithByName(req.Name), postgresqlRepo.WithByPostgresqlName(req.Database), databaseRepo.WithByFrom(req.From))
pgsql, _ := postgresqlRepo.Get(commonRepo.WithByName(req.Name), postgresqlRepo.WithByPostgresqlName(req.Database), commonRepo.WithByFrom(req.From))
if pgsql.ID != 0 {
return nil, constant.ErrRecordExist
}
@ -309,7 +309,7 @@ func (u *PostgresqlService) Delete(ctx context.Context, req dto.PostgresqlDBDele
if _, err := os.Stat(backupDir); err == nil {
_ = os.RemoveAll(backupDir)
}
_ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType(req.Type), commonRepo.WithByName(req.Database), backupRepo.WithByDetailName(db.Name))
_ = backupRepo.DeleteRecord(ctx, commonRepo.WithByType(req.Type), commonRepo.WithByName(req.Database), commonRepo.WithByDetailName(db.Name))
global.LOG.Infof("delete database %s-%s backups successful", req.Database, db.Name)
}

View file

@ -2,7 +2,6 @@ package service
import (
"fmt"
"github.com/1Panel-dev/1Panel/agent/app/repo"
"io"
"io/fs"
"os"
@ -13,6 +12,8 @@ import (
"time"
"unicode/utf8"
"github.com/1Panel-dev/1Panel/agent/app/repo"
"github.com/1Panel-dev/1Panel/agent/app/dto/request"
"github.com/1Panel-dev/1Panel/agent/app/dto/response"
"github.com/1Panel-dev/1Panel/agent/buserr"
@ -472,7 +473,7 @@ func (f *FileService) ReadLogByLine(req request.FileReadByLineReq) (*response.Fi
if req.TaskID != "" {
opts = append(opts, taskRepo.WithByID(req.TaskID))
} else {
opts = append(opts, taskRepo.WithType(req.TaskType), taskRepo.WithOperate(req.TaskOperate), taskRepo.WithResourceID(req.ID))
opts = append(opts, commonRepo.WithByType(req.TaskType), taskRepo.WithOperate(req.TaskOperate), taskRepo.WithResourceID(req.ID))
}
taskModel, err := taskRepo.GetFirst(opts...)
if err != nil {

View file

@ -34,7 +34,7 @@ func NewIImageRepoService() IImageRepoService {
}
func (u *ImageRepoService) Page(req dto.SearchWithPage) (int64, interface{}, error) {
total, ops, err := imageRepoRepo.Page(req.Page, req.PageSize, commonRepo.WithLikeName(req.Info), commonRepo.WithOrderBy("created_at desc"))
total, ops, err := imageRepoRepo.Page(req.Page, req.PageSize, commonRepo.WithByLikeName(req.Info), commonRepo.WithOrderBy("created_at desc"))
var dtoOps []dto.ImageRepoInfo
for _, op := range ops {
var item dto.ImageRepoInfo
@ -137,7 +137,7 @@ func (u *ImageRepoService) BatchDelete(req dto.ImageRepoDelete) error {
return errors.New("The default value cannot be edit !")
}
}
if err := imageRepoRepo.Delete(commonRepo.WithIdsIn(req.Ids)); err != nil {
if err := imageRepoRepo.Delete(commonRepo.WithByIDs(req.Ids)); err != nil {
return err
}
return nil

View file

@ -56,7 +56,7 @@ func (r *RuntimeService) Create(create request.RuntimeCreate) (*model.Runtime, e
opts []repo.DBOption
)
if create.Name != "" {
opts = append(opts, commonRepo.WithLikeName(create.Name))
opts = append(opts, commonRepo.WithByLikeName(create.Name))
}
if create.Type != "" {
opts = append(opts, commonRepo.WithByType(create.Type))
@ -151,7 +151,7 @@ func (r *RuntimeService) Page(req request.RuntimeSearch) (int64, []response.Runt
res []response.RuntimeDTO
)
if req.Name != "" {
opts = append(opts, commonRepo.WithLikeName(req.Name))
opts = append(opts, commonRepo.WithByLikeName(req.Name))
}
if req.Status != "" {
opts = append(opts, runtimeRepo.WithStatus(req.Status))

View file

@ -47,7 +47,7 @@ func NewISnapshotService() ISnapshotService {
}
func (u *SnapshotService) SearchWithPage(req dto.SearchWithPage) (int64, interface{}, error) {
total, systemBackups, err := snapshotRepo.Page(req.Page, req.PageSize, commonRepo.WithLikeName(req.Info))
total, systemBackups, err := snapshotRepo.Page(req.Page, req.PageSize, commonRepo.WithByLikeName(req.Info))
if err != nil {
return 0, nil, err
}
@ -320,7 +320,7 @@ func (u *SnapshotService) HandleSnapshot(isCronjob bool, logPath string, req dto
}
func (u *SnapshotService) Delete(req dto.SnapshotBatchDelete) error {
snaps, _ := snapshotRepo.GetList(commonRepo.WithIdsIn(req.Ids))
snaps, _ := snapshotRepo.GetList(commonRepo.WithByIDs(req.Ids))
for _, snap := range snaps {
if req.DeleteWithFile {
accounts, err := NewBackupClientMap(strings.Split(snap.SourceAccountIDs, ","))

View file

@ -20,10 +20,10 @@ func (u *TaskLogService) Page(req dto.SearchTaskLogReq) (int64, []dto.TaskDTO, e
commonRepo.WithOrderBy("created_at desc"),
}
if req.Status != "" {
opts = append(opts, taskRepo.WithStatus(req.Status))
opts = append(opts, commonRepo.WithByStatus(req.Status))
}
if req.Type != "" {
opts = append(opts, taskRepo.WithType(req.Type))
opts = append(opts, commonRepo.WithByType(req.Type))
}
total, tasks, err := taskRepo.Page(

View file

@ -143,7 +143,7 @@ func (w WebsiteService) PageWebsite(req request.WebsiteSearch) (int64, []respons
for _, domain := range domains {
websiteIds = append(websiteIds, domain.WebsiteID)
}
opts = append(opts, websiteRepo.WithIDs(websiteIds))
opts = append(opts, commonRepo.WithByIDs(websiteIds))
} else {
opts = append(opts, websiteRepo.WithDomainLike(req.Name))
}
@ -298,8 +298,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
dbConfig := create.DataBaseConfig
switch database.Type {
case constant.AppPostgresql, constant.AppPostgres:
iPostgresqlRepo := repo.NewIPostgresqlRepo()
oldPostgresqlDb, _ := iPostgresqlRepo.Get(commonRepo.WithByName(create.DbName), iPostgresqlRepo.WithByFrom(constant.ResourceLocal))
oldPostgresqlDb, _ := postgresqlRepo.Get(commonRepo.WithByName(create.DbName), commonRepo.WithByFrom(constant.ResourceLocal))
if oldPostgresqlDb.ID > 0 {
return buserr.New(constant.ErrDbUserNotValid)
}
@ -318,8 +317,7 @@ func (w WebsiteService) CreateWebsite(create request.WebsiteCreate) (err error)
website.DbID = pgDB.ID
website.DbType = database.Type
case constant.AppMysql, constant.AppMariaDB:
iMysqlRepo := repo.NewIMysqlRepo()
oldMysqlDb, _ := iMysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), iMysqlRepo.WithByFrom(constant.ResourceLocal))
oldMysqlDb, _ := mysqlRepo.Get(commonRepo.WithByName(dbConfig.DbName), commonRepo.WithByFrom(constant.ResourceLocal))
if oldMysqlDb.ID > 0 {
return buserr.New(constant.ErrDbUserNotValid)
}
@ -520,7 +518,7 @@ func (w WebsiteService) OpWebsite(req request.WebsiteOp) error {
func (w WebsiteService) GetWebsiteOptions(req request.WebsiteOptionReq) ([]response.WebsiteOption, error) {
var options []repo.DBOption
if len(req.Types) > 0 {
options = append(options, websiteRepo.WithTypes(req.Types))
options = append(options, commonRepo.WithTypes(req.Types))
}
webs, _ := websiteRepo.List(options...)
var datas []response.WebsiteOption
@ -1170,7 +1168,7 @@ func (w WebsiteService) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]r
checkIds = append(req.InstallIds, appInstall.ID)
}
if len(checkIds) > 0 {
installList, _ := appInstallRepo.ListBy(commonRepo.WithIdsIn(checkIds))
installList, _ := appInstallRepo.ListBy(commonRepo.WithByIDs(checkIds))
for _, install := range installList {
if err = syncAppInstallStatus(&install, false); err != nil {
return nil, err
@ -2200,6 +2198,9 @@ func (w WebsiteService) GetPathAuthBasics(req request.NginxAuthReq) (res []respo
pathAuth.Path = location.Match
passPath := path.Join(passDir, fmt.Sprintf("%s.pass", name))
authContent, err = fileOp.GetContent(passPath)
if err != nil {
return nil, err
}
authArray := strings.Split(string(authContent), "\n")
for _, line := range authArray {
if line == "" {

View file

@ -18,7 +18,6 @@ var (
ErrRecordExist = errors.New("ErrRecordExist")
ErrRecordNotFound = errors.New("ErrRecordNotFound")
ErrStructTransform = errors.New("ErrStructTransform")
ErrInitialPassword = errors.New("ErrInitialPassword")
ErrNotSupportType = errors.New("ErrNotSupportType")
ErrInvalidParams = errors.New("ErrInvalidParams")
)
@ -132,11 +131,6 @@ var (
ErrFirewall = "ErrFirewall"
)
// cronjob
var (
ErrBashExecute = "ErrBashExecute"
)
var (
ErrNotExistUser = "ErrNotExistUser"
)

View file

@ -1,11 +1,8 @@
ErrInvalidParams: "Request parameter error: {{ .detail }}"
ErrInitialPassword: "Initial password error"
ErrInternalServer: "Service internal error: {{ .detail }}"
ErrRecordExist: "Record already exists"
ErrRecordNotFound: "Records not found"
ErrStructTransform: "Type conversion failure: {{ .detail }}"
ErrNotLogin: "User is not Login: {{ .detail }}"
ErrPasswordExpired: "The current password has expired: {{ .detail }}"
ErrNotSupportType: "The system does not support the current type: {{ .detail }}"
#common
@ -18,7 +15,6 @@ TYPE_APP: "Application"
TYPE_RUNTIME: "Runtime environment"
TYPE_DOMAIN: "Domain name"
ErrTypePort: 'Port {{ .name }} format error'
ErrTypePortRange: 'Port range needs to be between 1-65535'
Success: "Success"
Failed: "Failed"
SystemRestart: "System restart causes task interruption"
@ -167,7 +163,6 @@ ErrUserFindErr: "Failed to find user {{ .name }} {{ .err }}"
ErrFirewall: "No firewalld or ufw service is detected. Please check and try again!"
#cronjob
ErrBashExecute: "Script execution error, please check the specific information in the task output text area."
ErrCutWebsiteLog: "{{ .name }} website log cutting failed, error {{ .err }}"
CutWebsiteLogSuccess: "{{ .name }} website log cut successfully, backup path {{ .path }}"

View file

@ -1,11 +1,8 @@
ErrInvalidParams: "請求參數錯誤: {{ .detail }}"
ErrInitialPassword: "原密碼錯誤"
ErrInternalServer: "伺服器內部錯誤: {{ .detail }}"
ErrRecordExist: "記錄已存在"
ErrRecordNotFound: "記錄未找到"
ErrStructTransform: "類型轉換失敗: {{ .detail }}"
ErrNotLogin: "用戶未登入: {{ .detail }}"
ErrPasswordExpired: "當前密碼已過期: {{ .detail }}"
ErrNotSupportType: "系統暫不支持當前類型: {{ .detail }}"
#common
@ -18,7 +15,6 @@ TYPE_APP: "應用"
TYPE_RUNTIME: "運作環境"
TYPE_DOMAIN: "網域名稱"
ErrTypePort: '埠 {{ .name }} 格式錯誤'
ErrTypePortRange: '連接埠範圍需要在 1-65535 之間'
Success: "成功"
Failed: "失敗"
SystemRestart: "系統重啟導致任務中斷"
@ -168,7 +164,6 @@ ErrUserFindErr: "用戶 {{ .name }} 查找失敗 {{ .err }}"
ErrFirewall: "當前未檢測到系統 firewalld 或 ufw 服務,請檢查後重試!"
#cronjob
ErrBashExecute: "腳本執行錯誤,請在任務輸出文本域中查看具體信息。"
ErrCutWebsiteLog: "{{ .name }} 網站日誌切割失敗,錯誤 {{ .err }}"
CutWebsiteLogSuccess: "{{ .name }} 網站日誌切割成功,備份路徑 {{ .path }}"

View file

@ -1,11 +1,8 @@
ErrInvalidParams: "请求参数错误: {{ .detail }}"
ErrInitialPassword: "原密码错误"
ErrInternalServer: "服务内部错误: {{ .detail }}"
ErrRecordExist: "记录已存在"
ErrRecordNotFound: "记录未能找到"
ErrStructTransform: "类型转换失败: {{ .detail }}"
ErrNotLogin: "用户未登录: {{ .detail }}"
ErrPasswordExpired: "当前密码已过期: {{ .detail }}"
ErrNotSupportType: "系统暂不支持当前类型: {{ .detail }}"
#common
@ -18,7 +15,6 @@ TYPE_APP: "应用"
TYPE_RUNTIME: "运行环境"
TYPE_DOMAIN: "域名"
ErrTypePort: '端口 {{ .name }} 格式错误'
ErrTypePortRange: '端口范围需要在 1-65535 之间'
Success: "成功"
Failed: "失败"
SystemRestart: "系统重启导致任务中断"
@ -128,7 +124,7 @@ ExecShellSuccess: "脚本执行成功"
ErrUserIsExist: "当前用户已存在,请重新输入"
ErrDatabaseIsExist: "当前数据库已存在,请重新输入"
ErrExecTimeOut: "SQL 执行超时,请检查数据库"
ErrRemoteExist: "远程数据库已存在该名称,请修改后重试"
ErrRemoteExist: "远程数据库已存在该名称,请修改后重试"vv
ErrLocalExist: "本地数据库已存在该名称,请修改后重试"
#redis
@ -170,7 +166,6 @@ ErrUserFindErr: "用户 {{ .name }} 查找失败 {{ .err }}"
ErrFirewall: "当前未检测到系统 firewalld 或 ufw 服务,请检查后重试!"
#cronjob
ErrBashExecute: "脚本执行错误,请在任务输出文本域中查看具体信息。"
ErrCutWebsiteLog: "{{ .name }} 网站日志切割失败,错误 {{ .err }}"
CutWebsiteLogSuccess: "{{ .name }} 网站日志切割成功,备份路径 {{ .path }}"

View file

@ -3,21 +3,18 @@ package repo
import (
"github.com/1Panel-dev/1Panel/core/app/model"
"github.com/1Panel-dev/1Panel/core/global"
"gorm.io/gorm"
)
type CommandRepo struct{}
type ICommandRepo interface {
GetList(opts ...DBOption) ([]model.Command, error)
List(opts ...DBOption) ([]model.Command, error)
Page(limit, offset int, opts ...DBOption) (int64, []model.Command, error)
WithByInfo(info string) DBOption
Create(command *model.Command) error
Update(id uint, vars map[string]interface{}) error
UpdateGroup(group, newGroup uint) error
Delete(opts ...DBOption) error
Get(opts ...DBOption) (model.Command, error)
WithLikeName(name string) DBOption
}
func NewICommandRepo() ICommandRepo {
@ -46,7 +43,7 @@ func (u *CommandRepo) Page(page, size int, opts ...DBOption) (int64, []model.Com
return count, users, err
}
func (u *CommandRepo) GetList(opts ...DBOption) ([]model.Command, error) {
func (u *CommandRepo) List(opts ...DBOption) ([]model.Command, error) {
var commands []model.Command
db := global.DB.Model(&model.Command{})
for _, opt := range opts {
@ -56,16 +53,6 @@ func (u *CommandRepo) GetList(opts ...DBOption) ([]model.Command, error) {
return commands, err
}
func (c *CommandRepo) WithByInfo(info string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(info) == 0 {
return g
}
infoStr := "%" + info + "%"
return g.Where("name LIKE ? OR addr LIKE ?", infoStr, infoStr)
}
}
func (u *CommandRepo) Create(command *model.Command) error {
return global.DB.Create(command).Error
}
@ -84,12 +71,3 @@ func (u *CommandRepo) Delete(opts ...DBOption) error {
}
return db.Delete(&model.Command{}).Error
}
func (a CommandRepo) WithLikeName(name string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(name) == 0 {
return g
}
return g.Where("name like ? or command like ?", "%"+name+"%", "%"+name+"%")
}
}

View file

@ -11,8 +11,9 @@ type DBOption func(*gorm.DB) *gorm.DB
type ICommonRepo interface {
WithByID(id uint) DBOption
WithByName(name string) DBOption
WithByIDs(ids []uint) DBOption
WithByName(name string) DBOption
WithLikeName(name string) DBOption
WithByType(ty string) DBOption
WithOrderBy(orderStr string) DBOption
@ -30,6 +31,11 @@ func (c *CommonRepo) WithByID(id uint) DBOption {
return g.Where("id = ?", id)
}
}
func (c *CommonRepo) WithByIDs(ids []uint) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("id in (?)", ids)
}
}
func (c *CommonRepo) WithByName(name string) DBOption {
return func(g *gorm.DB) *gorm.DB {
if len(name) == 0 {
@ -38,9 +44,12 @@ func (c *CommonRepo) WithByName(name string) DBOption {
return g.Where("`name` = ?", name)
}
}
func (c *CommonRepo) WithByIDs(ids []uint) DBOption {
func (c *CommonRepo) WithLikeName(name string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("id in (?)", ids)
if len(name) == 0 {
return g
}
return g.Where("name like ? or command like ?", "%"+name+"%", "%"+name+"%")
}
}
func (c *CommonRepo) WithByType(ty string) DBOption {

View file

@ -12,14 +12,15 @@ type IHostRepo interface {
Get(opts ...DBOption) (model.Host, error)
GetList(opts ...DBOption) ([]model.Host, error)
Page(limit, offset int, opts ...DBOption) (int64, []model.Host, error)
WithByInfo(info string) DBOption
WithByPort(port uint) DBOption
WithByUser(user string) DBOption
WithByAddr(addr string) DBOption
Create(host *model.Host) error
Update(id uint, vars map[string]interface{}) error
UpdateGroup(group, newGroup uint) error
Delete(opts ...DBOption) error
WithByInfo(info string) DBOption
WithByPort(port uint) DBOption
WithByUser(user string) DBOption
WithByAddr(addr string) DBOption
}
func NewIHostRepo() IHostRepo {

View file

@ -13,13 +13,14 @@ type ILogRepo interface {
CreateLoginLog(user *model.LoginLog) error
PageLoginLog(limit, offset int, opts ...DBOption) (int64, []model.LoginLog, error)
CleanOperation() error
CreateOperationLog(user *model.OperationLog) error
PageOperationLog(limit, offset int, opts ...DBOption) (int64, []model.OperationLog, error)
WithByIP(ip string) DBOption
WithByStatus(status string) DBOption
WithByGroup(group string) DBOption
WithByLikeOperation(operation string) DBOption
CleanOperation() error
CreateOperationLog(user *model.OperationLog) error
PageOperationLog(limit, offset int, opts ...DBOption) (int64, []model.OperationLog, error)
}
func NewILogRepo() ILogRepo {

View file

@ -9,7 +9,7 @@ import (
type SettingRepo struct{}
type ISettingRepo interface {
GetList(opts ...DBOption) ([]model.Setting, error)
List(opts ...DBOption) ([]model.Setting, error)
Get(opts ...DBOption) (model.Setting, error)
Create(key, value string) error
Update(key, value string) error
@ -20,7 +20,7 @@ func NewISettingRepo() ISettingRepo {
return &SettingRepo{}
}
func (u *SettingRepo) GetList(opts ...DBOption) ([]model.Setting, error) {
func (u *SettingRepo) List(opts ...DBOption) ([]model.Setting, error) {
var settings []model.Setting
db := global.DB.Model(&model.Setting{})
for _, opt := range opts {

View file

@ -24,7 +24,7 @@ func NewICommandService() ICommandService {
}
func (u *CommandService) List(req dto.OperateByType) ([]dto.CommandInfo, error) {
commands, err := commandRepo.GetList(commonRepo.WithOrderBy("name"), commonRepo.WithByType(req.Type))
commands, err := commandRepo.List(commonRepo.WithOrderBy("name"), commonRepo.WithByType(req.Type))
if err != nil {
return nil, constant.ErrRecordNotFound
}
@ -40,7 +40,7 @@ func (u *CommandService) List(req dto.OperateByType) ([]dto.CommandInfo, error)
}
func (u *CommandService) SearchForTree(req dto.OperateByType) ([]dto.CommandTree, error) {
cmdList, err := commandRepo.GetList(commonRepo.WithOrderBy("name"), commonRepo.WithByType(req.Type))
cmdList, err := commandRepo.List(commonRepo.WithOrderBy("name"), commonRepo.WithByType(req.Type))
if err != nil {
return nil, err
}
@ -71,7 +71,7 @@ func (u *CommandService) SearchWithPage(req dto.SearchCommandWithPage) (int64, i
commonRepo.WithByType(req.Type),
}
if len(req.Info) != 0 {
options = append(options, commandRepo.WithLikeName(req.Info))
options = append(options, commonRepo.WithLikeName(req.Info))
}
if req.GroupID != 0 {
options = append(options, groupRepo.WithByGroupID(req.GroupID))

View file

@ -153,7 +153,7 @@ func (u *HostService) GetHostInfo(id uint) (*model.Host, error) {
func (u *HostService) SearchWithPage(req dto.SearchHostWithPage) (int64, interface{}, error) {
var options []repo.DBOption
if len(req.Info) != 0 {
options = append(options, commandRepo.WithLikeName(req.Info))
options = append(options, commonRepo.WithLikeName(req.Info))
}
if req.GroupID != 0 {
options = append(options, groupRepo.WithByGroupID(req.GroupID))

View file

@ -43,7 +43,7 @@ func NewISettingService() ISettingService {
}
func (u *SettingService) GetSettingInfo() (*dto.SettingInfo, error) {
setting, err := settingRepo.GetList()
setting, err := settingRepo.List()
if err != nil {
return nil, constant.ErrRecordNotFound
}

View file

@ -38,23 +38,6 @@
</template>
</el-table-column>
<el-table-column :label="$t('commons.table.status')" prop="status" :min-width="60">
<template #default="{ row }">
<el-button
v-if="row.status === 'Enable'"
@click="onChangeStatus(row.id, 'disable')"
link
icon="VideoPlay"
type="success"
>
{{ $t('commons.status.enabled') }}
</el-button>
<el-button v-else icon="VideoPause" link type="danger" @click="onChangeStatus(row.id, 'enable')">
{{ $t('commons.status.disabled') }}
</el-button>
</template>
</el-table-column>
<el-table-column :label="$t('commons.table.operate')">
<template #default="{ row, $index }">
<div>
@ -156,18 +139,6 @@ const setDefault = (group: Group.GroupInfo) => {
});
};
const onChangeStatus = async (row: any, status: string) => {
ElMessageBox.confirm(i18n.global.t('cronjob.' + status + 'Msg'), i18n.global.t('cronjob.changeStatus'), {
confirmButtonText: i18n.global.t('commons.button.confirm'),
cancelButtonText: i18n.global.t('commons.button.cancel'),
}).then(async () => {
row.status = status === 'enable' ? 'Enable' : 'Disable';
await UpdateGroup(row);
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
search();
});
};
const openCreate = () => {
for (const d of data.value) {
if (d.name == '') {

View file

@ -373,6 +373,7 @@ const acceptParams = (params: DialogProps): void => {
dialogData.value.rowData.downloadAccountID = 1;
}
if (dialogData.value.rowData.sourceAccountIDs) {
dialogData.value.rowData.sourceAccounts = [];
let itemIDs = dialogData.value.rowData.sourceAccountIDs.split(',');
for (const item of itemIDs) {
dialogData.value.rowData.sourceAccounts.push(Number(item));
@ -628,7 +629,7 @@ const changeAccount = async () => {
}
}
if (exist) {
if (item.value === dialogData.value.rowData.downloadAccountID) {
if (item.id === dialogData.value.rowData.downloadAccountID) {
isInAccounts = true;
}
accountOptions.value.push(item);