mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-12-25 17:16:33 +08:00
refactor: 代码重构、分页数据组件支持多选
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package persistence
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"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/gormx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
@@ -15,28 +16,14 @@ func newMachineRepo() repository.Machine {
|
||||
}
|
||||
|
||||
// 分页获取机器信息列表
|
||||
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) *model.PageResult {
|
||||
sql := "SELECT m.* FROM t_machine m WHERE 1 = 1 "
|
||||
|
||||
values := make([]any, 0)
|
||||
if condition.Ip != "" {
|
||||
sql = sql + " AND m.ip LIKE ?"
|
||||
values = append(values, "%"+condition.Ip+"%")
|
||||
}
|
||||
if condition.Name != "" {
|
||||
sql = sql + " AND m.name LIKE ?"
|
||||
values = append(values, "%"+condition.Name+"%")
|
||||
}
|
||||
if len(condition.TagIds) > 0 {
|
||||
sql = fmt.Sprintf("%s AND m.tag_id IN ? ", sql)
|
||||
values = append(values, condition.TagIds)
|
||||
}
|
||||
if condition.TagPathLike != "" {
|
||||
sql = sql + " AND m.tag_path LIKE ?"
|
||||
values = append(values, condition.TagPathLike+"%")
|
||||
}
|
||||
sql = sql + " ORDER BY m.tag_path"
|
||||
return model.GetPageBySql(sql, pageParam, toEntity, values...)
|
||||
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]vo.MachineVO, orderBy ...string) *model.PageResult[*[]vo.MachineVO] {
|
||||
qd := gormx.NewQuery(new(entity.Machine)).
|
||||
Like("ip", condition.Ip).
|
||||
Like("name", condition.Name).
|
||||
In("tag_id", condition.TagIds).
|
||||
RLike("tag_path", condition.TagPathLike).
|
||||
OrderByAsc("tag_path")
|
||||
return gormx.PageQuery(qd, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (m *machineRepoImpl) Count(condition *entity.MachineQuery) int64 {
|
||||
@@ -48,18 +35,18 @@ func (m *machineRepoImpl) Count(condition *entity.MachineQuery) int64 {
|
||||
where["tag_id"] = condition.TagId
|
||||
}
|
||||
|
||||
return model.CountByMap(new(entity.Machine), where)
|
||||
return gormx.CountByCond(new(entity.Machine), where)
|
||||
}
|
||||
|
||||
// 根据条件获取账号信息
|
||||
func (m *machineRepoImpl) GetMachine(condition *entity.Machine, cols ...string) error {
|
||||
return model.GetBy(condition, cols...)
|
||||
return gormx.GetBy(condition, cols...)
|
||||
}
|
||||
|
||||
// 根据id获取
|
||||
func (m *machineRepoImpl) GetById(id uint64, cols ...string) *entity.Machine {
|
||||
machine := new(entity.Machine)
|
||||
if err := model.GetById(machine, id, cols...); err != nil {
|
||||
if err := gormx.GetById(machine, id, cols...); err != nil {
|
||||
return nil
|
||||
|
||||
}
|
||||
@@ -67,9 +54,9 @@ func (m *machineRepoImpl) GetById(id uint64, cols ...string) *entity.Machine {
|
||||
}
|
||||
|
||||
func (m *machineRepoImpl) Create(entity *entity.Machine) {
|
||||
biz.ErrIsNilAppendErr(model.Insert(entity), "创建机器信息失败: %s")
|
||||
biz.ErrIsNilAppendErr(gormx.Insert(entity), "创建机器信息失败: %s")
|
||||
}
|
||||
|
||||
func (m *machineRepoImpl) UpdateById(entity *entity.Machine) {
|
||||
biz.ErrIsNilAppendErr(model.UpdateById(entity), "更新机器信息失败: %s")
|
||||
biz.ErrIsNilAppendErr(gormx.UpdateById(entity), "更新机器信息失败: %s")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user