mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-24 16:46:35 +08:00
refactor: 新增base.Repo与base.App,重构repo与app层代码
This commit is contained in:
@@ -3,49 +3,26 @@ package persistence
|
||||
import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type authCertRepoImpl struct{}
|
||||
|
||||
func newAuthCertRepo() repository.AuthCert {
|
||||
return new(authCertRepoImpl)
|
||||
type authCertRepoImpl struct {
|
||||
base.RepoImpl[*entity.AuthCert]
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
func newAuthCertRepo() repository.AuthCert {
|
||||
return &authCertRepoImpl{base.RepoImpl[*entity.AuthCert]{M: new(entity.AuthCert)}}
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
|
||||
qd := gormx.NewQuery(new(entity.AuthCert)).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) Insert(ac *entity.AuthCert) {
|
||||
biz.ErrIsNil(gormx.Insert(ac), "新增授权凭证失败")
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) Update(ac *entity.AuthCert) {
|
||||
biz.ErrIsNil(gormx.UpdateById(ac), "更新授权凭证失败")
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) GetById(id uint64) *entity.AuthCert {
|
||||
ac := new(entity.AuthCert)
|
||||
err := gormx.GetById(ac, id)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
return ac
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
|
||||
acs := new([]*entity.AuthCert)
|
||||
gormx.GetByIdIn(new(entity.AuthCert), acs, ids)
|
||||
return *acs
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) GetByCondition(condition *entity.AuthCert, cols ...string) error {
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
func (m *authCertRepoImpl) DeleteById(id uint64) {
|
||||
gormx.DeleteById(new(entity.AuthCert), id)
|
||||
}
|
||||
// func (m *authCertRepoImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
|
||||
// acs := new([]*entity.AuthCert)
|
||||
// gormx.GetByIdIn(new(entity.AuthCert), acs, ids)
|
||||
// return *acs
|
||||
// }
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"mayfly-go/internal/machine/api/vo"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/utils/collx"
|
||||
@@ -12,14 +12,16 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type machineRepoImpl struct{}
|
||||
type machineRepoImpl struct {
|
||||
base.RepoImpl[*entity.Machine]
|
||||
}
|
||||
|
||||
func newMachineRepo() repository.Machine {
|
||||
return new(machineRepoImpl)
|
||||
return &machineRepoImpl{base.RepoImpl[*entity.Machine]{M: new(entity.Machine)}}
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]*vo.MachineVO, orderBy ...string) *model.PageResult[*[]*vo.MachineVO] {
|
||||
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]*vo.MachineVO, orderBy ...string) (*model.PageResult[*[]*vo.MachineVO], error) {
|
||||
qd := gormx.NewQuery(new(entity.Machine)).
|
||||
Like("ip", condition.Ip).
|
||||
Like("name", condition.Name).
|
||||
@@ -44,28 +46,5 @@ func (m *machineRepoImpl) Count(condition *entity.MachineQuery) int64 {
|
||||
where["tag_id"] = condition.TagIds
|
||||
}
|
||||
|
||||
return gormx.CountByCond(new(entity.Machine), where)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (m *machineRepoImpl) GetMachine(condition *entity.Machine, cols ...string) error {
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineRepoImpl) GetById(id uint64, cols ...string) *entity.Machine {
|
||||
machine := new(entity.Machine)
|
||||
if err := gormx.GetById(machine, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
return machine
|
||||
}
|
||||
|
||||
func (m *machineRepoImpl) Create(entity *entity.Machine) {
|
||||
biz.ErrIsNilAppendErr(gormx.Insert(entity), "创建机器信息失败: %s")
|
||||
}
|
||||
|
||||
func (m *machineRepoImpl) UpdateById(entity *entity.Machine) {
|
||||
biz.ErrIsNilAppendErr(gormx.UpdateById(entity), "更新机器信息失败: %s")
|
||||
return m.CountByCond(where)
|
||||
}
|
||||
|
||||
@@ -3,44 +3,21 @@ package persistence
|
||||
import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type machineCropJobRepoImpl struct{}
|
||||
type machineCropJobRepoImpl struct {
|
||||
base.RepoImpl[*entity.MachineCronJob]
|
||||
}
|
||||
|
||||
func newMachineCronJobRepo() repository.MachineCronJob {
|
||||
return new(machineCropJobRepoImpl)
|
||||
return &machineCropJobRepoImpl{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] {
|
||||
func (m *machineCropJobRepoImpl) 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)
|
||||
}
|
||||
|
||||
func (m *machineCropJobRepoImpl) GetBy(cond *entity.MachineCronJob, cols ...string) error {
|
||||
return gormx.GetBy(cond, cols...)
|
||||
}
|
||||
|
||||
func (m *machineCropJobRepoImpl) GetById(id uint64, cols ...string) *entity.MachineCronJob {
|
||||
res := new(entity.MachineCronJob)
|
||||
if err := gormx.GetById(res, id, cols...); err == nil {
|
||||
return res
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m *machineCropJobRepoImpl) Delete(id uint64) {
|
||||
biz.ErrIsNil(gormx.DeleteById(new(entity.MachineCronJob), id), "删除失败")
|
||||
}
|
||||
|
||||
func (m *machineCropJobRepoImpl) Insert(entity *entity.MachineCronJob) {
|
||||
gormx.Insert(entity)
|
||||
}
|
||||
|
||||
func (m *machineCropJobRepoImpl) UpdateById(entity *entity.MachineCronJob) {
|
||||
gormx.UpdateById(entity)
|
||||
}
|
||||
|
||||
@@ -3,26 +3,21 @@ package persistence
|
||||
import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type machineCropJobExecRepoImpl struct{}
|
||||
type machineCropJobExecRepoImpl struct {
|
||||
base.RepoImpl[*entity.MachineCronJobExec]
|
||||
}
|
||||
|
||||
func newMachineCronJobExecRepo() repository.MachineCronJobExec {
|
||||
return new(machineCropJobExecRepoImpl)
|
||||
return &machineCropJobExecRepoImpl{base.RepoImpl[*entity.MachineCronJobExec]{M: new(entity.MachineCronJobExec)}}
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineCropJobExecRepoImpl) GetPageList(condition *entity.MachineCronJobExec, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
func (m *machineCropJobExecRepoImpl) GetPageList(condition *entity.MachineCronJobExec, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
|
||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (m *machineCropJobExecRepoImpl) Insert(entity *entity.MachineCronJobExec) {
|
||||
gormx.Insert(entity)
|
||||
}
|
||||
|
||||
func (m *machineCropJobExecRepoImpl) Delete(mcje *entity.MachineCronJobExec) {
|
||||
gormx.DeleteByCondition(mcje)
|
||||
}
|
||||
|
||||
@@ -3,24 +3,27 @@ package persistence
|
||||
import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/gormx"
|
||||
)
|
||||
|
||||
type machineCropJobRelateRepoImpl struct{}
|
||||
type machineCropJobRelateRepoImpl struct {
|
||||
base.RepoImpl[*entity.MachineCronJobRelate]
|
||||
}
|
||||
|
||||
func newMachineCropJobRelateRepo() repository.MachineCronJobRelate {
|
||||
return new(machineCropJobRelateRepoImpl)
|
||||
return &machineCropJobRelateRepoImpl{base.RepoImpl[*entity.MachineCronJobRelate]{M: new(entity.MachineCronJobRelate)}}
|
||||
}
|
||||
|
||||
func (m *machineCropJobRelateRepoImpl) GetList(condition *entity.MachineCronJobRelate) []entity.MachineCronJobRelate {
|
||||
list := new([]entity.MachineCronJobRelate)
|
||||
gormx.ListByOrder(condition, list)
|
||||
m.ListByCond(condition, list)
|
||||
return *list
|
||||
}
|
||||
|
||||
func (m *machineCropJobRelateRepoImpl) GetMachineIds(cronJobId uint64) []uint64 {
|
||||
var machineIds []uint64
|
||||
gormx.ListBy(&entity.MachineCronJobRelate{CronJobId: cronJobId}, &machineIds, "machine_id")
|
||||
m.ListByCond(&entity.MachineCronJobRelate{CronJobId: cronJobId}, &machineIds, "machine_id")
|
||||
return machineIds
|
||||
}
|
||||
|
||||
@@ -29,11 +32,3 @@ func (m *machineCropJobRelateRepoImpl) GetCronJobIds(machineId uint64) []uint64
|
||||
gormx.ListBy(&entity.MachineCronJobRelate{MachineId: machineId}, &cronJobIds, "cron_job_id")
|
||||
return cronJobIds
|
||||
}
|
||||
|
||||
func (m *machineCropJobRelateRepoImpl) Delete(condition *entity.MachineCronJobRelate) {
|
||||
gormx.DeleteByCondition(condition)
|
||||
}
|
||||
|
||||
func (m *machineCropJobRelateRepoImpl) BatchInsert(mcjrs []*entity.MachineCronJobRelate) {
|
||||
gormx.BatchInsert(mcjrs)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package persistence
|
||||
import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
@@ -15,7 +14,7 @@ func newMachineFileRepo() repository.MachineFile {
|
||||
}
|
||||
|
||||
// 分页获取机器文件信息列表
|
||||
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
func (m *machineFileRepoImpl) GetPageList(condition *entity.MachineFile, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
|
||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
@@ -35,14 +34,14 @@ func (m *machineFileRepoImpl) GetById(id uint64, cols ...string) *entity.Machine
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineFileRepoImpl) Delete(id uint64) {
|
||||
biz.ErrIsNil(gormx.DeleteById(new(entity.MachineFile), id), "删除失败")
|
||||
func (m *machineFileRepoImpl) Delete(id uint64) error {
|
||||
return gormx.DeleteById(new(entity.MachineFile), id)
|
||||
}
|
||||
|
||||
func (m *machineFileRepoImpl) Create(entity *entity.MachineFile) {
|
||||
biz.ErrIsNil(gormx.Insert(entity), "新增机器文件配置失败")
|
||||
func (m *machineFileRepoImpl) Create(entity *entity.MachineFile) error {
|
||||
return gormx.Insert(entity)
|
||||
}
|
||||
|
||||
func (m *machineFileRepoImpl) UpdateById(entity *entity.MachineFile) {
|
||||
biz.ErrIsNil(gormx.UpdateById(entity), "更新机器文件失败")
|
||||
func (m *machineFileRepoImpl) UpdateById(entity *entity.MachineFile) error {
|
||||
return gormx.UpdateById(entity)
|
||||
}
|
||||
|
||||
@@ -3,47 +3,21 @@ package persistence
|
||||
import (
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/biz"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type machineScriptRepoImpl struct{}
|
||||
type machineScriptRepoImpl struct {
|
||||
base.RepoImpl[*entity.MachineScript]
|
||||
}
|
||||
|
||||
func newMachineScriptRepo() repository.MachineScript {
|
||||
return new(machineScriptRepoImpl)
|
||||
return &machineScriptRepoImpl{base.RepoImpl[*entity.MachineScript]{M: new(entity.MachineScript)}}
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult[any] {
|
||||
func (m *machineScriptRepoImpl) GetPageList(condition *entity.MachineScript, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
|
||||
qd := gormx.NewQuery(condition).WithCondModel(condition).WithOrderBy(orderBy...)
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (m *machineScriptRepoImpl) GetMachineScript(condition *entity.MachineScript, cols ...string) error {
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineScriptRepoImpl) GetById(id uint64, cols ...string) *entity.MachineScript {
|
||||
ms := new(entity.MachineScript)
|
||||
if err := gormx.GetById(ms, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
return ms
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineScriptRepoImpl) Delete(id uint64) {
|
||||
biz.ErrIsNil(gormx.DeleteById(new(entity.MachineScript), id), "删除失败")
|
||||
}
|
||||
|
||||
func (m *machineScriptRepoImpl) Create(entity *entity.MachineScript) {
|
||||
gormx.Insert(entity)
|
||||
}
|
||||
|
||||
func (m *machineScriptRepoImpl) UpdateById(entity *entity.MachineScript) {
|
||||
gormx.UpdateById(entity)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user