소스 검색

新增-新策略对应 获取机器人状态接口

hl 5 달 전
부모
커밋
500c69a888
2개의 변경된 파일5개의 추가작업 그리고 43개의 파일을 삭제
  1. 3 2
      src/robot.js
  2. 2 41
      src/web.js

+ 3 - 2
src/robot.js

@@ -554,14 +554,15 @@ function delRobot(app) {
 //----------------------------------------------
 
 // 新策略-获取状态
-function predictorState(app) {
+ function predictorState(app) {
     var accUrl = "http://127.0.0.1:" + app.port
     //拿到策略余额
     try {
         var config = getRustConfig()
         http.request_get(`${accUrl}/predictor_state`, {...config.headers})
             .then((data) => {
-                return {'code': 200, 'data': data, "message": "SUCCESS"}
+                var d = JSON.parse(data)
+                return {'code': 200, 'data': d, "message": "SUCCESS"}
             }).catch((error) => {
             // 处理可能发生的错误
             logger.error(`#####################汇报:获取状态请求失败: ${error.message}`)

+ 2 - 41
src/web.js

@@ -134,47 +134,8 @@ function init() {
     app.get('/predictorState', (req, res) => {
         const param = req.query;
         logger.info(JSON.stringify(param));
-
-        var id = param.id;
-        var port = -1;
-        robot.appMap.forEach((value, key) => {
-            // logger.info(JSON.stringify(value))
-            if (value.id + "" === id + "") {
-                port = value.port
-            }
-        })
-
-        if (port !== -1) {
-            logger.info('#####################predictorState:');
-            // var config = getRustConfig()
-            // var com = `curl -X GET -H 'auth: 4L' -H 'token: r7T$8gBV!f&L@E2+' "http://127.0.0.1:${port}/predictor_state"`;
-            // logger.info('#####################com:', com);
-            // execSync(com, (error, stdout, stderr) => {
-            //     if (error) {
-            //         logger.info(`#####################汇报:获取状态请求失败: ${error.message}`)
-            //         res.send({'code': -1, 'data': null, "message": `获取状态请求失败`});
-            //     }
-            //
-            //     logger.info('#####################-d', stdout);
-            //     logger.info('#####################-ok');
-            //     res.send({'code': 200, 'data': stdout, "message": "SUCCESS"});
-            // });
-
-            // http.request_get(`http://127.0.0.1:${port}/predictor_state`, {...config.headers})
-            //     .then((data) => {
-            //         logger.info('#####################-d', data);
-            //         res.send({'code': 200, 'data': data, "message": "SUCCESS"});
-            //     })
-            //     // 处理可能发生的错误
-            //     .catch((error) => {
-            //         logger.info(`#####################汇报:获取状态请求失败: ${error.message}`)
-            //         // logger.error(`#####################汇报:获取状态请求失败: ${error.message}`)
-            //         res.send({'code': -1, 'data': null, "message": `获取状态请求失败${error.message}`});
-            //     });
-            res.send({'code': 200, 'data': null, "message": "SUCCESS"});
-        } else {
-            res.send({'code': -1, 'data': null, "message": "机器人不存在"});
-        }
+        let data = robot.predictorState(param)
+        res.send(data);
     })
     // 使服务器监听特定端口
     app.listen(port, () => {