Browse Source

fix bug

Signed-off-by: jagger <cossjie@foxmail.com>

Former-commit-id: a6d7814781
pull/209/head
jagger 1 year ago
parent
commit
e29002b4d6
7 changed files with 78 additions and 61 deletions
  1. +7
    -1
      api/desc/core/pcm-core.api
  2. +3
    -0
      api/internal/logic/adapters/clusterlistlogic.go
  3. +15
    -2
      api/internal/logic/adapters/createadapterlogic.go
  4. +4
    -4
      api/internal/logic/adapters/getclustersumlogic.go
  5. +3
    -2
      api/internal/logic/core/taskdetailslogic.go
  6. +0
    -12
      api/internal/logic/dictionary/listdictitemlogic.go
  7. +46
    -40
      api/internal/types/types.go

+ 7
- 1
api/desc/core/pcm-core.api 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
}

@@ -968,7 +975,6 @@ type (
Type string `form:"type,optional"`
ParentId string `form:"parentId,optional"`
Status string `form:"status,optional"`
PageInfo
}

DictItemEditReq {


+ 3
- 0
api/internal/logic/adapters/clusterlistlogic.go 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


+ 15
- 2
api/internal/logic/adapters/createadapterlogic.go View File

@@ -34,14 +34,27 @@ func (l *CreateAdapterLogic) CreateAdapter(req *types.AdapterCreateReq) (resp *t
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.Type).First(&types.DictItemInfo{}).Error
err = l.svcCtx.DbEngin.Raw(sql, req.ResourceType).First(&types.DictItemInfo{}).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errors.New("Type error, please check!")
return nil, errors.New("resourceType error, please check!")
}
adapter.Id = utils.GenSnowflakeIDStr()
adapter.CreateTime = time.Now().Format("2006-01-02 15:04:05")


+ 4
- 4
api/internal/logic/adapters/getclustersumlogic.go 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)


+ 3
- 2
api/internal/logic/core/taskdetailslogic.go 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 {


+ 0
- 12
api/internal/logic/dictionary/listdictitemlogic.go View File

@@ -24,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")
@@ -48,13 +46,6 @@ 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

// 找出第一级字典项,(父字典项id为0)
@@ -73,9 +64,6 @@ func (l *ListDictItemLogic) ListDictItem(req *types.DictItemReq) (resp *types.Pa
getTreeMap(dictItemFormat, dictList)

resp.List = dictItemFormat
resp.PageSize = req.PageSize
resp.PageNum = req.PageNum
resp.Total = total

return resp, nil
}


+ 46
- 40
api/internal/types/types.go 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
}

@@ -904,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 {


Loading…
Cancel
Save