mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-11 20:00:26 +08:00
refactor: 新增base.Repo与base.App,重构repo与app层代码
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user