mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-03 16:00:25 +08:00
* fix: 代码合并 * feat:支持数据库版本兼容,目前兼容了oracle11g部分特性 * fix: 修改数据同步bug,数据sql里指定修改字段别,导致未正确记录修改字段值 * feat: 数据库迁移支持定时迁移和迁移到sql文件
79 lines
2.0 KiB
Go
79 lines
2.0 KiB
Go
package application
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"github.com/google/uuid"
|
|
"mayfly-go/internal/db/config"
|
|
"mayfly-go/internal/db/domain/entity"
|
|
"mayfly-go/internal/db/domain/repository"
|
|
"mayfly-go/pkg/base"
|
|
"mayfly-go/pkg/model"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type DbTransferFile interface {
|
|
base.App[*entity.DbTransferFile]
|
|
|
|
// GetPageList 分页获取数据库实例
|
|
GetPageList(condition *entity.DbTransferFileQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
|
|
|
|
Save(ctx context.Context, instanceEntity *entity.DbTransferFile) error
|
|
|
|
Delete(ctx context.Context, id ...uint64) error
|
|
|
|
GetFilePath(ent *entity.DbTransferFile) string
|
|
}
|
|
|
|
var _ DbTransferFile = (*dbTransferFileAppImpl)(nil)
|
|
|
|
type dbTransferFileAppImpl struct {
|
|
base.AppImpl[*entity.DbTransferFile, repository.DbTransferFile]
|
|
}
|
|
|
|
func (app *dbTransferFileAppImpl) InjectDbTransferFileRepo(repo repository.DbTransferFile) {
|
|
app.Repo = repo
|
|
}
|
|
|
|
func (app *dbTransferFileAppImpl) GetPageList(condition *entity.DbTransferFileQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
|
|
return app.GetRepo().GetPageList(condition, pageParam, toEntity, orderBy...)
|
|
}
|
|
|
|
func (app *dbTransferFileAppImpl) Save(ctx context.Context, taskEntity *entity.DbTransferFile) error {
|
|
var err error
|
|
if taskEntity.Id == 0 {
|
|
err = app.Insert(ctx, taskEntity)
|
|
} else {
|
|
err = app.UpdateById(ctx, taskEntity)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (app *dbTransferFileAppImpl) Delete(ctx context.Context, id ...uint64) error {
|
|
|
|
arr, err := app.GetByIds(id, "task_id", "file_uuid")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// 删除对应的文件
|
|
for _, file := range arr {
|
|
_ = os.Remove(app.GetFilePath(file))
|
|
}
|
|
|
|
// 删除数据
|
|
return app.DeleteById(ctx, id...)
|
|
}
|
|
|
|
func (app *dbTransferFileAppImpl) GetFilePath(ent *entity.DbTransferFile) string {
|
|
brc := config.GetDbBackupRestore()
|
|
if ent.FileUuid == "" {
|
|
ent.FileUuid = uuid.New().String()
|
|
}
|
|
|
|
filePath := filepath.Join(fmt.Sprintf("%s/%d/%s.sql", brc.TransferPath, ent.TaskId, ent.FileUuid))
|
|
|
|
return filePath
|
|
}
|