Merge remote-tracking branch 'origin/master' into master-wq

Former-commit-id: e150842727f39e6ad9eb4b83db0197c97af108ea
This commit is contained in:
qiwang 2024-06-05 17:25:22 +08:00
commit f66138afa0
8 changed files with 158 additions and 70 deletions

View File

@ -712,6 +712,7 @@ type (
Id string `form:"id,optional" db:"id"`
Name string `form:"name,optional"`
Type string `form:"type,optional"`
ResourceType string `form:"resourceType,optional"`
Nickname string `form:"nickname,optional"`
Version string `form:"version,optional"`
Server string `form:"server,optional"`
@ -721,6 +722,7 @@ type (
Id string `form:"id,optional" db:"id"`
Name string `form:"name,optional"`
Type string `form:"type,optional"`
ResourceType string `form:"resourceType,optional"`
Nickname string `form:"nickname,optional"`
Version string `form:"version,optional"`
Server string `form:"server,optional"`
@ -729,6 +731,7 @@ type (
Id string `json:"id,optional" db:"id"`
Name string `json:"name,optional"`
Type string `json:"type,optional"`
ResourceType string `json:"resourceType,optional"`
Nickname string `json:"nickname,optional"`
Version string `json:"version,optional"`
Server string `json:"server,optional"`
@ -737,6 +740,7 @@ type (
Id string `json:"id,optional" db:"id"`
Name string `json:"name"`
Type string `json:"type"`
ResourceType string `json:"resourceType"`
Nickname string `json:"nickname"`
Version string `json:"version"`
Server string `json:"server"`
@ -748,6 +752,7 @@ type (
Id string `json:"id,omitempty" db:"id"`
Name string `json:"name,omitempty" db:"name"`
Type string `json:"type,omitempty" db:"type"`
ResourceType string `json:"resourceType,omitempty" db:"resource_type"`
Nickname string `json:"nickname,omitempty" db:"nickname"`
Version string `json:"version,omitempty" db:"version"`
Server string `json:"server,omitempty" db:"server"`
@ -766,6 +771,7 @@ type (
Id string `json:"id,omitempty" db:"id"`
Name string `json:"name,omitempty" db:"name"`
Type string `json:"type,omitempty" db:"type"`
ResourceType string `json:"resourceType" db:"resource_type"`
Nickname string `json:"nickname,omitempty" db:"nickname"`
Version string `json:"version,omitempty" db:"version"`
Server string `json:"server,omitempty" db:"server"`
@ -797,6 +803,7 @@ type (
Type string `form:"type,optional"`
ProducerDict string `form:"producerDict,optional"`
RegionDict string `form:"regionDict,optional"`
ResourceType string `form:"resourceType,optional"`
PageInfo
}
@ -955,6 +962,7 @@ type (
ParentId string `json:"parentId,omitempty"`
Status string `json:"status,omitempty" db:"status"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
Children []DictItemInfo `json:"children,omitempty" gorm:"-"`
}
DictItemReq {
@ -967,7 +975,6 @@ type (
Type string `form:"type,optional"`
ParentId string `form:"parentId,optional"`
Status string `form:"status,optional"`
PageInfo
}
DictItemEditReq {

View File

@ -55,6 +55,9 @@ func (l *ClusterListLogic) ClusterList(req *types.ClusterReq) (resp *types.PageR
if req.Type != "" {
db = db.Where("t_adapter.type = ?", req.Type)
}
if req.ResourceType != "" {
db = db.Where("t_adapter.resource_type = ?", req.ResourceType)
}
//count total
var total int64

View File

@ -2,10 +2,12 @@ package adapters
import (
"context"
"github.com/pkg/errors"
"github.com/zeromicro/go-zero/core/logx"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"gorm.io/gorm"
"time"
)
@ -26,6 +28,34 @@ func NewCreateAdapterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Cre
func (l *CreateAdapterLogic) CreateAdapter(req *types.AdapterCreateReq) (resp *types.AdapterResp, err error) {
adapter := types.AdapterInfo{}
utils.Convert(req, &adapter)
//check name
exist := l.svcCtx.DbEngin.Table("t_adapter").Where("name = ?", req.Name).First(&types.AdapterInfo{}).Error
if !errors.Is(exist, gorm.ErrRecordNotFound) {
return nil, errors.New("name already exists")
}
//check type
var arr = [...]string{"0", "1", "2"}
found := false
for _, str := range arr {
if str == req.Type {
found = true
break
}
}
if found == false {
return nil, errors.New("type not found")
}
//check resourceTypeDict
sql := `select t_dict_item.item_value
from t_dict
join t_dict_item on t_dict.id = t_dict_item.dict_id
where dict_code = 'adapter_type' and item_value = ?
and t_dict_item.parent_id != 0`
err = l.svcCtx.DbEngin.Raw(sql, req.ResourceType).First(&types.DictItemInfo{}).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errors.New("resourceType error, please check!")
}
adapter.Id = utils.GenSnowflakeIDStr()
adapter.CreateTime = time.Now().Format("2006-01-02 15:04:05")
result := l.svcCtx.DbEngin.Table("t_adapter").Create(&adapter)

View File

@ -32,28 +32,28 @@ func (l *GetClusterSumLogic) GetClusterSum(req *types.ClusterSumReq) (resp *type
var vmSum int //
var TaskSum int //
//
sqlStr := "SELECT COUNT(*) FROM `t_adapter` t where t.type = 0"
sqlStr := "SELECT COUNT(*) FROM `t_adapter` t where t.type ='0' and deleted_at is null"
tx := l.svcCtx.DbEngin.Raw(sqlStr).Scan(&AdapterSum)
if tx.Error != nil {
logx.Error(err)
return nil, tx.Error
}
//vm
sqlStrVm := "SELECT COUNT(*) FROM `t_adapter` t left join t_cluster tc on t.id=tc.adapter_id where t.type='3' and tc.deleted_at is null"
sqlStrVm := "SELECT COUNT(*) FROM `t_adapter` t left join t_cluster tc on t.id=tc.adapter_id where t.type = '0' and t.resource_type='02' and tc.deleted_at is null"
txClusterVm := l.svcCtx.DbEngin.Raw(sqlStrVm).Scan(&vmSum)
if txClusterVm.Error != nil {
logx.Error(err)
return nil, txClusterVm.Error
}
//pod
sqlStrPod := "SELECT COUNT(*) FROM `t_adapter` t left join t_cluster tc on t.id=tc.adapter_id where t.type='0' and tc.deleted_at is null"
sqlStrPod := "SELECT COUNT(*) FROM `t_adapter` t left join t_cluster tc on t.id=tc.adapter_id where t.type = '0' and t.resource_type='02' and tc.deleted_at is null"
txClusterPod := l.svcCtx.DbEngin.Raw(sqlStrPod).Scan(&podSum)
if txClusterPod.Error != nil {
logx.Error(err)
return nil, txClusterPod.Error
}
//
sqlStrTask := "SELECT COUNT(*) FROM `task`"
sqlStrTask := "SELECT COUNT(*) FROM `task` where adapter_type_dict = '0'"
txTask := l.svcCtx.DbEngin.Raw(sqlStrTask).Scan(&TaskSum)
if txTask.Error != nil {
logx.Error(err)

View File

@ -37,12 +37,13 @@ func (l *TaskDetailsLogic) TaskDetails(req *types.FId) (resp *types.TaskDetailsR
switch task.AdapterTypeDict {
case 0:
l.svcCtx.DbEngin.Table("task_cloud").Select("cluster_id").Where("task_id", task.Id).Scan(&clusterIds)
if len(clusterIds) <= 0 {
l.svcCtx.DbEngin.Table("task_vm").Select("cluster_id").Where("task_id", task.Id).Find(&clusterIds)
}
case 1:
l.svcCtx.DbEngin.Table("task_ai").Select("cluster_id").Where("task_id", task.Id).Scan(&clusterIds)
case 2:
l.svcCtx.DbEngin.Table("task_hpc").Select("cluster_id").Where("task_id", task.Id).Scan(&clusterIds)
case 3:
l.svcCtx.DbEngin.Table("task_vm").Select("cluster_id").Where("task_id", task.Id).Find(&clusterIds)
}
err = l.svcCtx.DbEngin.Table("t_cluster").Where("id in ?", clusterIds).Scan(&cList).Error
if err != nil {

View File

@ -3,6 +3,7 @@ package dictionary
import (
"context"
"github.com/pkg/errors"
"sort"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
@ -38,6 +39,22 @@ func (l *ListDictItemByCodeLogic) ListDictItemByCode(req *types.DictCodeReq) (re
logx.Errorf("ListDictItemByCode()=> failed %s", err.Error())
return nil, errors.New("description Failed to query dictionary entry data")
}
resp.List = dictList
// 找出第一级字典项父字典项id为0
dictItemFormat := make([]types.DictItemInfo, 0)
for _, item := range dictList {
if item.ParentId == "0" {
dictItemFormat = append(dictItemFormat, item)
}
}
// 排序
sort.Slice(dictItemFormat, func(i, j int) bool {
return dictItemFormat[i].SortOrder < dictItemFormat[j].SortOrder
})
// 递归找出一级路由下面的子路由
getTreeMap(dictItemFormat, dictList)
resp.List = dictItemFormat
return resp, nil
}

View File

@ -4,6 +4,7 @@ import (
"context"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/api/internal/types"
"sort"
"github.com/zeromicro/go-zero/core/logx"
)
@ -23,8 +24,6 @@ func NewListDictItemLogic(ctx context.Context, svcCtx *svc.ServiceContext) *List
}
func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.PageResult, err error) {
limit := req.PageSize
offset := req.PageSize * (req.PageNum - 1)
resp = &types.PageResult{}
var dictList []types.DictItemInfo
db := l.svcCtx.DbEngin.Model(&types.DictItemInfo{}).Table("t_dict_item")
@ -47,19 +46,43 @@ func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.Pa
if req.DictId != "" {
db = db.Where("dict_id = ?", req.DictId)
}
var total int64
err = db.Count(&total).Error
if err != nil {
return resp, err
}
db = db.Limit(limit).Offset(offset)
err = db.Order("sort_order").Find(&dictList).Error
resp.List = dictList
resp.PageSize = req.PageSize
resp.PageNum = req.PageNum
resp.Total = total
// 找出第一级字典项父字典项id为0
dictItemFormat := make([]types.DictItemInfo, 0)
for _, item := range dictList {
if item.ParentId == "0" {
dictItemFormat = append(dictItemFormat, item)
}
}
// 排序
sort.Slice(dictItemFormat, func(i, j int) bool {
return dictItemFormat[i].SortOrder < dictItemFormat[j].SortOrder
})
// 递归找出一级路由下面的子路由
getTreeMap(dictItemFormat, dictList)
resp.List = dictItemFormat
return resp, nil
}
func getTreeMap(dictItemFormat []types.DictItemInfo, dictItems []types.DictItemInfo) {
for index, itemF := range dictItemFormat {
for _, dictItem := range dictItems {
if itemF.Id == dictItem.ParentId {
// itemF 只是个复制值
//itemF.Children = append(itemF.Children, dictItem)
dictItemFormat[index].Children = append(dictItemFormat[index].Children, dictItem)
}
}
if len(dictItemFormat[index].Children) > 0 {
// 排序
sort.Slice(dictItemFormat[index].Children, func(i, j int) bool {
return dictItemFormat[index].Children[i].SortOrder < dictItemFormat[index].Children[j].SortOrder
})
getTreeMap(dictItemFormat[index].Children, dictItems)
}
}
}

View File

@ -639,40 +639,44 @@ type AppResp struct {
}
type AdapterQueryReq struct {
Id string `form:"id,optional" db:"id"`
Name string `form:"name,optional"`
Type string `form:"type,optional"`
Nickname string `form:"nickname,optional"`
Version string `form:"version,optional"`
Server string `form:"server,optional"`
Id string `form:"id,optional" db:"id"`
Name string `form:"name,optional"`
Type string `form:"type,optional"`
ResourceType string `form:"resourceType,optional"`
Nickname string `form:"nickname,optional"`
Version string `form:"version,optional"`
Server string `form:"server,optional"`
PageInfo
}
type AdapterRelationQueryReq struct {
Id string `form:"id,optional" db:"id"`
Name string `form:"name,optional"`
Type string `form:"type,optional"`
Nickname string `form:"nickname,optional"`
Version string `form:"version,optional"`
Server string `form:"server,optional"`
Id string `form:"id,optional" db:"id"`
Name string `form:"name,optional"`
Type string `form:"type,optional"`
ResourceType string `form:"resourceType,optional"`
Nickname string `form:"nickname,optional"`
Version string `form:"version,optional"`
Server string `form:"server,optional"`
}
type AdapterReq struct {
Id string `json:"id,optional" db:"id"`
Name string `json:"name,optional"`
Type string `json:"type,optional"`
Nickname string `json:"nickname,optional"`
Version string `json:"version,optional"`
Server string `json:"server,optional"`
Id string `json:"id,optional" db:"id"`
Name string `json:"name,optional"`
Type string `json:"type,optional"`
ResourceType string `json:"resourceType,optional"`
Nickname string `json:"nickname,optional"`
Version string `json:"version,optional"`
Server string `json:"server,optional"`
}
type AdapterCreateReq struct {
Id string `json:"id,optional" db:"id"`
Name string `json:"name"`
Type string `json:"type"`
Nickname string `json:"nickname"`
Version string `json:"version"`
Server string `json:"server"`
Id string `json:"id,optional" db:"id"`
Name string `json:"name"`
Type string `json:"type"`
ResourceType string `json:"resourceType"`
Nickname string `json:"nickname"`
Version string `json:"version"`
Server string `json:"server"`
}
type AdapterDelReq struct {
@ -680,13 +684,14 @@ type AdapterDelReq struct {
}
type AdapterInfo struct {
Id string `json:"id,omitempty" db:"id"`
Name string `json:"name,omitempty" db:"name"`
Type string `json:"type,omitempty" db:"type"`
Nickname string `json:"nickname,omitempty" db:"nickname"`
Version string `json:"version,omitempty" db:"version"`
Server string `json:"server,omitempty" db:"server"`
CreateTime string `json:"createTime,omitempty" db:"create_time" gorm:"autoCreateTime"`
Id string `json:"id,omitempty" db:"id"`
Name string `json:"name,omitempty" db:"name"`
Type string `json:"type,omitempty" db:"type"`
ResourceType string `json:"resourceType,omitempty" db:"resource_type"`
Nickname string `json:"nickname,omitempty" db:"nickname"`
Version string `json:"version,omitempty" db:"version"`
Server string `json:"server,omitempty" db:"server"`
CreateTime string `json:"createTime,omitempty" db:"create_time" gorm:"autoCreateTime"`
}
type AdapterResp struct {
@ -702,14 +707,15 @@ type AdapterRelationResp struct {
}
type AdapterRelation struct {
Id string `json:"id,omitempty" db:"id"`
Name string `json:"name,omitempty" db:"name"`
Type string `json:"type,omitempty" db:"type"`
Nickname string `json:"nickname,omitempty" db:"nickname"`
Version string `json:"version,omitempty" db:"version"`
Server string `json:"server,omitempty" db:"server"`
CreateTime string `json:"createTime,omitempty" db:"create_time" gorm:"autoCreateTime"`
Clusters []*ClusterInfo `json:"clusters,omitempty"`
Id string `json:"id,omitempty" db:"id"`
Name string `json:"name,omitempty" db:"name"`
Type string `json:"type,omitempty" db:"type"`
ResourceType string `json:"resourceType" db:"resource_type"`
Nickname string `json:"nickname,omitempty" db:"nickname"`
Version string `json:"version,omitempty" db:"version"`
Server string `json:"server,omitempty" db:"server"`
CreateTime string `json:"createTime,omitempty" db:"create_time" gorm:"autoCreateTime"`
Clusters []*ClusterInfo `json:"clusters,omitempty"`
}
type ClusterReq struct {
@ -734,6 +740,7 @@ type ClusterReq struct {
Type string `form:"type,optional"`
ProducerDict string `form:"producerDict,optional"`
RegionDict string `form:"regionDict,optional"`
ResourceType string `form:"resourceType,optional"`
PageInfo
}
@ -882,15 +889,16 @@ type Dicts struct {
}
type DictItemInfo struct {
Id string `json:"id,omitempty"`
DictId string `json:"dictId,omitempty"`
ItemText string `json:"itemText,omitempty"`
ItemValue string `json:"itemValue,omitempty"`
Description string `json:"description,omitempty"`
SortOrder string `json:"sortOrder,omitempty"`
ParentId string `json:"parentId,omitempty"`
Status string `json:"status,omitempty" db:"status"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
Id string `json:"id,omitempty"`
DictId string `json:"dictId,omitempty"`
ItemText string `json:"itemText,omitempty"`
ItemValue string `json:"itemValue,omitempty"`
Description string `json:"description,omitempty"`
SortOrder string `json:"sortOrder,omitempty"`
ParentId string `json:"parentId,omitempty"`
Status string `json:"status,omitempty" db:"status"`
CreateTime string `json:"createTime,omitempty" db:"created_time" gorm:"autoCreateTime"`
Children []DictItemInfo `json:"children,omitempty" gorm:"-"`
}
type DictItemReq struct {
@ -903,7 +911,6 @@ type DictItemReq struct {
Type string `form:"type,optional"`
ParentId string `form:"parentId,optional"`
Status string `form:"status,optional"`
PageInfo
}
type DictItemEditReq struct {