LingxinMeng 1 tahun lalu
induk
melakukan
fa128f030b

+ 49 - 3
amd64/dispatch_server/package/handler/old_interface_adapter.go

@@ -1,15 +1,61 @@
 package handler
 
-import "github.com/gin-gonic/gin"
+import (
+	"cicv-data-closedloop/amd64/dispatch_server/package/infra"
+	"cicv-data-closedloop/amd64/dispatch_server/package/util"
+	"github.com/gin-gonic/gin"
+	"net/http"
+)
 
+// 返回 true
 func Confirm(c *gin.Context) {
-
+	c.String(http.StatusOK, "true")
 }
 
 func Tick(c *gin.Context) {
-
+	c.String(http.StatusOK, "true")
 }
 
 func State(c *gin.Context) {
+	taskId := c.Query("taskId")
+	state := c.Query("state")
+	//podName := c.Query("podName") // todo 根据pod名称杀死pod并清理redis缓存
+
+	// 发送http请求到索为系统
+	/*
+		仿真测试任务回调接口:
+			1、接口url
+				http://1.202.169.139:8081/project/task/callback
+
+			2、请求方式
+				POST
+
+			3、请求体
+				{
+					"taskId":1764907332423110657,
+					"state":"RUNNING"
+				}
+
+			4、响应结果
 
+				{
+					"data":true/false,
+					"success": true,
+					"message": "ok",
+					"code": 1,
+					"nowTime": "2024-05-10 15:57:42"
+				}
+	*/
+	_, err := util.PostJsonResponseJson(
+		"http://1.202.169.139:8081/project/task/callback",
+		map[string]string{
+			"taskId": taskId,
+			"state":  state,
+		},
+	)
+	if err != nil {
+		infra.GlobalLogger.Error(err)
+		c.String(http.StatusOK, "false")
+	}
+	c.String(http.StatusOK, "true")
 }

+ 28 - 0
amd64/dispatch_server/package/util/u_http.go

@@ -0,0 +1,28 @@
+package util
+
+import (
+	"bytes"
+	"encoding/json"
+	"errors"
+	"io"
+	"net/http"
+)
+
+func PostJsonResponseJson(url string, params map[string]string) (string, error) {
+	jsonData, err := json.Marshal(params)
+	if err != nil {
+		return "", errors.New("参数转换成json失败,错误信息为:" + err.Error())
+	}
+	resp, err := http.Post(url, "application/json", bytes.NewBuffer(jsonData))
+	if err != nil {
+		return "", errors.New("发送请求失败,错误信息为:" + err.Error())
+	}
+	defer func(Body io.ReadCloser) {
+		_ = Body.Close()
+	}(resp.Body)
+	body, err := io.ReadAll(resp.Body)
+	if err != nil {
+		return "", errors.New("读取响应结果失败,错误信息为:" + err.Error())
+	}
+	return string(body), nil
+}