feat: 新增机器与项目关联及相关资源列表查询以项目关联成员为准

This commit is contained in:
meilin.huang
2021-12-11 11:19:47 +08:00
parent fb0fc274b4
commit 358b34c7f4
14 changed files with 128 additions and 48 deletions

View File

@@ -1,6 +1,7 @@
package persistence
import (
"fmt"
"mayfly-go/base/model"
"mayfly-go/server/devops/domain/entity"
"mayfly-go/server/devops/domain/repository"
@@ -12,7 +13,19 @@ var MachineDao repository.Machine = &machineRepo{}
// 分页获取机器信息列表
func (m *machineRepo) GetMachineList(condition *entity.Machine, pageParam *model.PageParam, toEntity interface{}, orderBy ...string) *model.PageResult {
return model.GetPage(pageParam, condition, toEntity, orderBy...)
sql := "SELECT m.* FROM t_machine m JOIN t_project_member pm ON m.project_id = pm.project_id WHERE 1 = 1 "
if condition.CreatorId != 0 {
// 使用创建者id模拟项目成员id
sql = fmt.Sprintf("%s AND pm.account_id = %d", sql, condition.CreatorId)
}
if condition.ProjectId != 0 {
sql = fmt.Sprintf("%s AND m.project_id = %d", sql, condition.ProjectId)
}
if condition.Ip != "" {
sql = sql + " AND m.ip LIKE '%" + condition.Ip + "%'"
}
sql = sql + " ORDER BY m.create_time DESC"
return model.GetPageBySql(sql, pageParam, toEntity)
}
func (m *machineRepo) Count(condition *entity.Machine) int64 {