2021-05-08 18:00:33 +08:00
|
|
|
package persistence
|
|
|
|
|
|
|
|
|
|
import (
|
2023-07-01 14:34:42 +08:00
|
|
|
"mayfly-go/internal/machine/api/vo"
|
2022-09-09 18:26:08 +08:00
|
|
|
"mayfly-go/internal/machine/domain/entity"
|
|
|
|
|
"mayfly-go/internal/machine/domain/repository"
|
2023-10-26 17:15:49 +08:00
|
|
|
"mayfly-go/pkg/base"
|
2023-07-01 14:34:42 +08:00
|
|
|
"mayfly-go/pkg/gormx"
|
2022-06-02 17:41:11 +08:00
|
|
|
"mayfly-go/pkg/model"
|
2023-07-21 17:07:04 +08:00
|
|
|
"mayfly-go/pkg/utils/collx"
|
2023-07-20 22:41:13 +08:00
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
2021-05-08 18:00:33 +08:00
|
|
|
)
|
|
|
|
|
|
2023-10-26 17:15:49 +08:00
|
|
|
type machineRepoImpl struct {
|
|
|
|
|
base.RepoImpl[*entity.Machine]
|
|
|
|
|
}
|
2021-05-08 18:00:33 +08:00
|
|
|
|
2022-09-09 18:26:08 +08:00
|
|
|
func newMachineRepo() repository.Machine {
|
2023-10-26 17:15:49 +08:00
|
|
|
return &machineRepoImpl{base.RepoImpl[*entity.Machine]{M: new(entity.Machine)}}
|
2022-09-09 18:26:08 +08:00
|
|
|
}
|
2021-05-08 18:00:33 +08:00
|
|
|
|
|
|
|
|
// 分页获取机器信息列表
|
2023-10-26 17:15:49 +08:00
|
|
|
func (m *machineRepoImpl) GetMachineList(condition *entity.MachineQuery, pageParam *model.PageParam, toEntity *[]*vo.MachineVO, orderBy ...string) (*model.PageResult[*[]*vo.MachineVO], error) {
|
2023-07-01 14:34:42 +08:00
|
|
|
qd := gormx.NewQuery(new(entity.Machine)).
|
|
|
|
|
Like("ip", condition.Ip).
|
|
|
|
|
Like("name", condition.Name).
|
|
|
|
|
In("tag_id", condition.TagIds).
|
2023-07-08 20:05:55 +08:00
|
|
|
RLike("tag_path", condition.TagPath).
|
2023-07-01 14:34:42 +08:00
|
|
|
OrderByAsc("tag_path")
|
2023-07-20 22:41:13 +08:00
|
|
|
|
|
|
|
|
if condition.Ids != "" {
|
|
|
|
|
// ,分割id转为id数组
|
2023-07-21 17:07:04 +08:00
|
|
|
qd.In("id", collx.ArrayMap[string, uint64](strings.Split(condition.Ids, ","), func(val string) uint64 {
|
2023-07-20 22:41:13 +08:00
|
|
|
id, _ := strconv.Atoi(val)
|
|
|
|
|
return uint64(id)
|
|
|
|
|
}))
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-01 14:34:42 +08:00
|
|
|
return gormx.PageQuery(qd, pageParam, toEntity)
|
2021-05-08 18:00:33 +08:00
|
|
|
}
|
|
|
|
|
|
2022-10-26 20:49:29 +08:00
|
|
|
func (m *machineRepoImpl) Count(condition *entity.MachineQuery) int64 {
|
2023-06-01 12:31:32 +08:00
|
|
|
where := make(map[string]any)
|
2022-10-26 20:49:29 +08:00
|
|
|
if len(condition.TagIds) > 0 {
|
|
|
|
|
where["tag_id"] = condition.TagIds
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-26 17:15:49 +08:00
|
|
|
return m.CountByCond(where)
|
2021-05-08 18:00:33 +08:00
|
|
|
}
|