fix: 机器文件内容写入导致内容清空、feat: ioc支持根据类型注入

This commit is contained in:
meilin.huang
2024-12-13 12:15:24 +08:00
parent e56788af3e
commit 7f2a49ba3c
31 changed files with 135 additions and 139 deletions

View File

@@ -61,10 +61,6 @@ type fileAppImpl struct {
base.AppImpl[*entity.File, repository.File]
}
func (f *fileAppImpl) InjectFileRepo(repo repository.File) {
f.Repo = repo
}
func (f *fileAppImpl) Upload(ctx context.Context, fileKey string, filename string, r io.Reader) (string, error) {
var err error
fileKey, writer, saveFileFunc, err := f.NewWriter(ctx, fileKey, filename)

View File

@@ -42,11 +42,6 @@ type procdefAppImpl struct {
var _ (Procdef) = (*procdefAppImpl)(nil)
// 注入repo
func (p *procdefAppImpl) InjectProcdefRepo(procdefRepo repository.Procdef) {
p.Repo = procdefRepo
}
func (p *procdefAppImpl) GetPageList(condition *entity.Procdef, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return p.Repo.GetPageList(condition, pageParam, toEntity, orderBy...)
}

View File

@@ -51,11 +51,6 @@ type procinstAppImpl struct {
var _ (Procinst) = (*procinstAppImpl)(nil)
// 注入repo
func (p *procinstAppImpl) InjectProcinstRepo(procinstRepo repository.Procinst) {
p.Repo = procinstRepo
}
func (p *procinstAppImpl) GetPageList(condition *entity.ProcinstQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return p.Repo.GetPageList(condition, pageParam, toEntity, orderBy...)
}

View File

@@ -69,11 +69,6 @@ type machineAppImpl struct {
var _ (Machine) = (*machineAppImpl)(nil)
// 注入MachineRepo
func (m *machineAppImpl) InjectMachineRepo(repo repository.Machine) {
m.Repo = repo
}
// 分页获取机器信息列表
func (m *machineAppImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return m.GetRepo().GetMachineList(condition, pageParam, toEntity, orderBy...)

View File

@@ -36,11 +36,6 @@ type machineCmdConfAppImpl struct {
var _ (MachineCmdConf) = (*machineCmdConfAppImpl)(nil)
// 注入MachineCmdConfRepo
func (m *machineCmdConfAppImpl) InjectMachineCmdConfRepo(repo repository.MachineCmdConf) {
m.Repo = repo
}
func (m *machineCmdConfAppImpl) SaveCmdConf(ctx context.Context, cmdConfParam *dto.SaveMachineCmdConf) error {
cmdConf := cmdConfParam.CmdConf

View File

@@ -51,11 +51,6 @@ type machineCronJobAppImpl struct {
var _ (MachineCronJob) = (*machineCronJobAppImpl)(nil)
// 注入MachineCronJobRepo
func (m *machineCronJobAppImpl) InjectMachineCronJobRepo(repo repository.MachineCronJob) {
m.Repo = repo
}
// 分页获取机器脚本任务列表
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...)

View File

@@ -279,12 +279,15 @@ func (m *machineFileAppImpl) WriteFileContent(ctx context.Context, opParam *dto.
return nil, err
}
f, err := sftpCli.OpenFile(path, os.O_WRONLY|os.O_TRUNC|os.O_CREATE|os.O_RDWR)
f, err := sftpCli.OpenFile(path, os.O_RDWR)
if err != nil {
return mi, err
}
defer f.Close()
f.Write(content)
if _, err := f.Write(content); err != nil {
return mi, err
}
return mi, err
}

View File

@@ -26,11 +26,6 @@ type machineScriptAppImpl struct {
machineApp Machine `inject:"MachineApp"`
}
// 注入MachineScriptRepo
func (m *machineScriptAppImpl) InjectMachineScriptRepo(repo repository.MachineScript) {
m.Repo = repo
}
const Common_Script_Machine_Id = 9999999
// 分页获取机器脚本信息列表

View File

@@ -42,11 +42,6 @@ type machineTermOpAppImpl struct {
fileApp fileapp.File `inject:"FileApp"`
}
// 注入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

View File

@@ -40,11 +40,6 @@ type mongoAppImpl struct {
tagApp tagapp.TagTree `inject:"TagTreeApp"`
}
// 注入MongoRepo
func (d *mongoAppImpl) InjectMongoRepo(repo repository.Mongo) {
d.Repo = repo
}
// 分页获取数据库信息列表
func (d *mongoAppImpl) GetPageList(condition *entity.MongoQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return d.GetRepo().GetList(condition, pageParam, toEntity, orderBy...)

View File

@@ -60,11 +60,6 @@ type redisAppImpl struct {
resourceAuthCertApp tagapp.ResourceAuthCert `inject:"ResourceAuthCertApp"`
}
// 注入RedisRepo
func (r *redisAppImpl) InjectRedisRepo(repo repository.Redis) {
r.Repo = repo
}
// 分页获取redis列表
func (r *redisAppImpl) GetPageList(condition *entity.RedisQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return r.GetRepo().GetRedisList(condition, pageParam, toEntity, orderBy...)

View File

@@ -28,11 +28,6 @@ type accountAppImpl struct {
accountRoleRepo repository.AccountRole `inject:"AccountRoleRepo"`
}
// 注入AccountRepo
func (a *accountAppImpl) InjectAccountRepo(repo repository.Account) {
a.Repo = repo
}
func (a *accountAppImpl) GetPageList(condition *entity.AccountQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return a.GetRepo().GetPageList(condition, pageParam, toEntity)
}

View File

@@ -31,10 +31,6 @@ 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)
}

View File

@@ -41,11 +41,6 @@ type resourceAppImpl struct {
var _ (Resource) = (*resourceAppImpl)(nil)
// 注入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 {

View File

@@ -52,10 +52,6 @@ type roleAppImpl struct {
var _ (Role) = (*roleAppImpl)(nil)
func (r *roleAppImpl) InjectRoleRepo(repo repository.Role) {
r.Repo = repo
}
func (m *roleAppImpl) GetPageList(condition *entity.RoleQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return m.GetRepo().GetPageList(condition, pageParam, toEntity, orderBy...)
}

View File

@@ -54,11 +54,6 @@ type resourceAuthCertAppImpl struct {
tagTreeApp TagTree `inject:"TagTreeApp"`
}
// 注入Repo
func (r *resourceAuthCertAppImpl) InjectResourceAuthCertRepo(resourceAuthCertRepo repository.ResourceAuthCert) {
r.Repo = resourceAuthCertRepo
}
func (r *resourceAuthCertAppImpl) RelateAuthCert(ctx context.Context, params *dto.RelateAuthCert) error {
resourceCode := params.ResourceCode
resourceType := int8(params.ResourceType)

View File

@@ -26,11 +26,6 @@ type resourceOpLogAppImpl struct {
var _ (ResourceOpLog) = (*resourceOpLogAppImpl)(nil)
// 注入ResourceOpLogRepo
func (rol *resourceOpLogAppImpl) InjectResourceOpLogRepo(resourceOpLogRepo repository.ResourceOpLog) {
rol.Repo = resourceOpLogRepo
}
func (rol *resourceOpLogAppImpl) AddResourceOpLog(ctx context.Context, codePath string) error {
loginAccount := contextx.GetLoginAccount(ctx)
if loginAccount == nil {

View File

@@ -74,11 +74,6 @@ type tagTreeAppImpl struct {
var _ (TagTree) = (*tagTreeAppImpl)(nil)
// 注入TagTreeRepo
func (p *tagTreeAppImpl) InjectTagTreeRepo(tagTreeRepo repository.TagTree) {
p.Repo = tagTreeRepo
}
func (p *tagTreeAppImpl) SaveTag(ctx context.Context, pid uint64, tag *entity.TagTree) error {
accountId := contextx.GetLoginAccount(ctx).Id
// 新建项目树节点信息

View File

@@ -42,11 +42,6 @@ type tagTreeRelateAppImpl struct {
var _ (TagTreeRelate) = (*tagTreeRelateAppImpl)(nil)
// 注入TagTreeRelateRepo
func (p *tagTreeRelateAppImpl) InjectTagTreeRelateRepo(tagTreeRelateRepo repository.TagTreeRelate) {
p.Repo = tagTreeRelateRepo
}
func (tr *tagTreeRelateAppImpl) RelateTag(ctx context.Context, relateType entity.TagRelateType, relateId uint64, tagCodePaths ...string) error {
if hasConflictPath(tagCodePaths) {
return errorx.NewBizI(ctx, imsg.ErrConflictingCodePath)