Browse Source

对接任务数据

Former-commit-id: efcea561a7
pull/9/head
zhangwei 2 years ago
parent
commit
6e8275d1ca
7 changed files with 96 additions and 0 deletions
  1. +8
    -0
      adaptor/PCM-CORE/api/desc/core/pcm-core.api
  2. +3
    -0
      adaptor/PCM-CORE/api/desc/pcm.api
  3. +21
    -0
      adaptor/PCM-CORE/api/internal/handler/core/jobtotalhandler.go
  4. +5
    -0
      adaptor/PCM-CORE/api/internal/handler/routes.go
  5. +37
    -0
      adaptor/PCM-CORE/api/internal/logic/core/jobtotallogic.go
  6. +6
    -0
      adaptor/PCM-CORE/api/internal/types/types.go
  7. +16
    -0
      common/tool/http.go

+ 8
- 0
adaptor/PCM-CORE/api/desc/core/pcm-core.api View File

@@ -201,6 +201,14 @@ type (
} }
) )


type (
jobTotalResp {
AllCardRunTime float64 `json:"allCardRunTime"`
AllJobCount float64 `json:"allJobCount"`
AllJobRunTime float64 `json:"allJobRunTime"`
}
)

type ( type (
taskListResp { taskListResp {
TotalCount int `json:"totalCount"` TotalCount int `json:"totalCount"`


+ 3
- 0
adaptor/PCM-CORE/api/desc/pcm.api View File

@@ -30,6 +30,9 @@ service pcm {
@handler TaskListHandler @handler TaskListHandler
get /core/taskList () returns (taskListResp) get /core/taskList () returns (taskListResp)
@handler JobTotalHandler
get /core/jobTotal () returns (jobTotalResp)
@handler listCenterHandler @handler listCenterHandler
get /core/listCenter () returns (listCenterResp) get /core/listCenter () returns (listCenterResp)


+ 21
- 0
adaptor/PCM-CORE/api/internal/handler/core/jobtotalhandler.go View File

@@ -0,0 +1,21 @@
package core

import (
"net/http"

"PCM/adaptor/PCM-CORE/api/internal/logic/core"
"PCM/adaptor/PCM-CORE/api/internal/svc"
"github.com/zeromicro/go-zero/rest/httpx"
)

func JobTotalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
l := core.NewJobTotalLogic(r.Context(), svcCtx)
resp, err := l.JobTotal()
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}

+ 5
- 0
adaptor/PCM-CORE/api/internal/handler/routes.go View File

@@ -32,6 +32,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/core/taskList", Path: "/core/taskList",
Handler: core.TaskListHandler(serverCtx), Handler: core.TaskListHandler(serverCtx),
}, },
{
Method: http.MethodGet,
Path: "/core/jobTotal",
Handler: core.JobTotalHandler(serverCtx),
},
{ {
Method: http.MethodGet, Method: http.MethodGet,
Path: "/core/listCenter", Path: "/core/listCenter",


+ 37
- 0
adaptor/PCM-CORE/api/internal/logic/core/jobtotallogic.go View File

@@ -0,0 +1,37 @@
package core

import (
"PCM/common/tool"
"context"
"k8s.io/apimachinery/pkg/util/json"

"PCM/adaptor/PCM-CORE/api/internal/svc"
"PCM/adaptor/PCM-CORE/api/internal/types"

"github.com/zeromicro/go-zero/core/logx"
)

type JobTotalLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}

func NewJobTotalLogic(ctx context.Context, svcCtx *svc.ServiceContext) *JobTotalLogic {
return &JobTotalLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}

func (l *JobTotalLogic) JobTotal() (resp *types.JobTotalResp, err error) {
// todo: add your logic here and delete this line
resp = &types.JobTotalResp{}
bytes, err := tool.HttpGet("GET", "https://grampus.openi.org.cn/openapi/v1/sharescreen/computepower/alljobinfo")
if err != nil {
return nil, err
}
json.Unmarshal(bytes, resp)
return resp, nil
}

+ 6
- 0
adaptor/PCM-CORE/api/internal/types/types.go View File

@@ -180,6 +180,12 @@ type TaskInfo struct {
Metadata interface{} `json:"metadata"` Metadata interface{} `json:"metadata"`
} }


type JobTotalResp struct {
AllCardRunTime float64 `json:"allCardRunTime"`
AllJobCount float64 `json:"allJobCount"`
AllJobRunTime float64 `json:"allJobRunTime"`
}

type TaskListResp struct { type TaskListResp struct {
TotalCount int `json:"totalCount"` TotalCount int `json:"totalCount"`
CardTime float32 `json:"cardTime"` CardTime float32 `json:"cardTime"`


+ 16
- 0
common/tool/http.go View File

@@ -75,6 +75,22 @@ func HttpClient(method string, url string, payload io.Reader, token string) ([]b
return body, err return body, err
} }


func HttpGet(method string, url string) ([]byte, error) {
request, err := http.NewRequest(method, url, nil)
client := &http.Client{}
res, err := client.Do(request)
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}

return body, err
}

// 发送POST请求 // 发送POST请求
// url:请求地址,data:POST请求提交的数据,contentType:请求体格式,如:application/json // url:请求地址,data:POST请求提交的数据,contentType:请求体格式,如:application/json
// content:请求放回的内容 // content:请求放回的内容


Loading…
Cancel
Save