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)).
|
2023-11-07 21:05:21 +08:00
|
|
|
Eq("status", condition.Status).
|
2023-07-01 14:34:42 +08:00
|
|
|
Like("ip", condition.Ip).
|
|
|
|
|
Like("name", condition.Name).
|
2023-12-05 23:03:51 +08:00
|
|
|
In("code", condition.Codes)
|
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
|
|
|
}
|