愛招飛幫助手冊 愛招飛幫助手冊
  • FastERP-1
  • Smart
  • PinToo
  • FastWeb
  • FastERP-2 企業管理系統 (opens new window)
  • 印染業ERP (opens new window)
  • 工廠終端機 (opens new window)
  • TARS
  • MARS
  • TaskRunner
  • Flying
  • FastDesk
  • HiDesk
  • HiNAT
  • FastBPM
  • 設備故障診斷 (opens new window)
  • 設備最佳運轉效益 (opens new window)
  • 企業智能助手SmeGPT (opens new window)
  • 燈號管理 (opens new window)
  • 戰情室 (opens new window)
  • 能源管理 (opens new window)
  • 人車定位 (opens new window)
  • 戰情指揮系統 (opens new window)
  • FastERP-1
  • FastWeb
  • Smart
  • PinToo
  • Flying
  • TARS
  • 通用功能

    • Report
    • Script
    • Echarts
    • Chart
    • DB Install
  • FastERP-1
  • Smart
  • PinToo
  • FastWeb
  • FastERP-2 企業管理系統 (opens new window)
  • 印染業ERP (opens new window)
  • 工廠終端機 (opens new window)
  • TARS
  • MARS
  • TaskRunner
  • Flying
  • FastDesk
  • HiDesk
  • HiNAT
  • FastBPM
  • 設備故障診斷 (opens new window)
  • 設備最佳運轉效益 (opens new window)
  • 企業智能助手SmeGPT (opens new window)
  • 燈號管理 (opens new window)
  • 戰情室 (opens new window)
  • 能源管理 (opens new window)
  • 人車定位 (opens new window)
  • 戰情指揮系統 (opens new window)
  • FastERP-1
  • FastWeb
  • Smart
  • PinToo
  • Flying
  • TARS
  • 通用功能

    • Report
    • Script
    • Echarts
    • Chart
    • DB Install
  • TaskRunner幫助主頁
  • 學習手冊

    • 安裝配置
    • 快速上手
    • 界面介紹
    • 功能介紹
    • 預設資料
    • RestAPI說明
      • 1. 執行Cmd
      • 2. 執行PowerShell
      • 3. 獲取表達式的值
      • 4. 執行自定批處理程式
      • 5. 執行自定程式
      • 6. 執行工作流
      • 7. 執行自定RestAPI
        • 7.1. 參數獲取
        • 7.2. 流獲取
        • 7.3. 引用資料庫設定
      • 8. 獲取印表機列表
      • 9. 運行Python任務
    • WebSocket說明
    • MQTT說明
    • Python說明
    • 自定程式
    • 公共單元
    • 工作流
    • 運行衛士
    • 自定報表
    • 自動化作業
    • 控制元件使用
    • 函式程式

  • 開發手冊

目录

RestAPI說明

# TaskRunner RestAPI說明

  以下對 TaskRunner 使用的 RestAPI 進行說明。

# 1. 執行Cmd

  • 請求地址:
http(s)://${host}:${port}/?restapi=script&syntaxtype=cmd
1

  在請求體的地址中,syntaxtype 的參數為 cmd 時,將文字或檔案中的文字以 cmd 的方式進行處理。

  • 請求體格式:text/plain

  • 請求體:批處理文字的內容。

  • 請求示例:

echo
:結束程序
taskkill /im TARS.exe /f
 :等待1秒
ping 127.0.0.1 -n 1
start "" "C:\Program Files\IsoFace\TARS\TARS.exe"
echo
1
2
3
4
5
6
7
  • 返回示例:如果返回的示例中包含 {"status": "ok","message": "執行耗時 xx 毫秒"},則批處理語句已執行在目標主機上。

# 2. 執行PowerShell

  • 請求地址:
http(s)://${host}:${port}/?restapi=script&syntaxtype=powershell
1

  在請求體的地址中,syntaxtype 的參數為 powershell 時,將文字或檔案中的文字以 powershell 的方式進行處理。

  • 請求體格式:text/plain

  • 請求體:批處理文字的內容。

  • 請求示例:

# 指定目錄位置
$directory = "E:\setup"
# 指定檔名
$filename = "test.txt"
# 指定檔案內容
$content = "hello world"
# 建立完整的檔案路徑
$filePath = Join-Path -Path $directory -ChildPath $filename
# 建立目錄(如果不存在)
if (-not (Test-Path -Path $directory)) {
    New-Item -ItemType Directory -Path $directory
}
# 建立並寫入檔案內容
Set-Content -Path $filePath -Value $content
# 輸出檔案建立成功訊息
Write-Output "file created:$filePath"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  • 返回示例:如果返回的示例中包含 {"status": "ok","message": "執行耗時 xx 毫秒"},則批處理語句已執行在目標主機上。

# 3. 獲取表達式的值

  • 請求地址:
http(s)://${host}:${port}/?restapi=script&evaluate=${param_name}&responsecontenttype=${content_type}&syntaxtype={syntaxtype}
1

  其中${param_name}為要獲取的變數的名稱。responsecontenttype=${content_type} 部分用於填寫預期返回的值的內容型別,此參數不是必選項,在不填寫時預設使用 text/plain。{syntaxtype} 中設定輸入的表達式的語法型別,可選 jscript、pascalscript。

  • 請求體格式:text/plain

  • 請求體:JScript、PascalScript的程式內容。

  • 請求示例:

var s;
{
  s = "Hello, TaskRunner!";
  var ss="TaskRunner!";
}
1
2
3
4
5

注意

  請不要在非除錯階段的程式中使用訊息彈出語句(比如ShowMessage()),否則會導致發出的Rest請求無法得到響應。

  • 返回示例:返回的示例為 ss 的取值 TaskRunner,content-type 為預設使用的型別text/plain。

# 4. 執行自定批處理程式

  • 請求地址:
http://${host}:${port}/?restapi=script&taskname=${batch_file_name}
1

  通過執行自定程式列表中的批處理自定程式實現運行。${batch_file_name} 為指定的批處理自定程式的名稱。

# 5. 執行自定程式

  • 請求地址:
http(s)://${host}:${port}/?restapi=script&taskname=${filename}&evaluate=${param_name}&responsecontenttype=${content_type}
1

  通過執行自定程式列表中的 JScript、PascalScript 的自定程式實現程式運行。其中${filename}為要獲取的JScript、PascalScript自定程式名稱。${param_name}為要獲取的變數的名稱。responsecontenttype=${content_type} 部分用於填寫預期返回的值的內容型別,此參數不是必選項,在不填寫時預設使用 text/plain。編寫的程式中不要帶有訊息彈出框型別的語句(比如ShowMessage()),否則會導致發出的Rest請求無法得到響應。

# 6. 執行工作流

  • 請求地址:
http(s)://${host}:${port}/?restapi=workflow
1
  • 請求方法:POST

  • 請求體:

Body:
{
  "name": "BPM001",
  "params": [
    {
      "name": "Var1",
      "value": "123"
    }
  ]
}
1
2
3
4
5
6
7
8
9
10

請求體中的參數說明如下:

  • name:要執行的工作流的名稱。
  • params:執行的工作流的參數資訊。如果執行的工作流不需要通過呼叫的方式引用參數,則此項可不設定。如果使用了此項,則引入的參數值必須先在工作流的變數中定義好。

# 7. 執行自定RestAPI

  在RestAPI中設定了介面相關的資訊后,可以通過以下方式來執行自定RestAPI。

  • 請求地址:
http(s)://${host}:${port}/?restapi={restapi_name}&token={token}&param1={param1}...
1

  其中 {restapi_name} 為設定的介面名稱。{token} 為令牌。如未設定令牌,此項可不填寫。 {param1} 等為根據需要設定的參數,在RestAPI介面中可獲取。

# 7.1. 參數獲取

  TaskRunner包含UgParams對象,該對像儲存了接收到的請求使用的參數,按照請求參數的排序產生對應的陣列。也可以直接引用參數的名稱獲取對應參數的取值。

//JScript
//獲取的參數在URLParams中,以index方式獲取,從0開始
String = UgParams.ValueFromIndex[i];

//以參數名為依據獲取
String = UgParams.Values["ParamsName"];
1
2
3
4
5
6

# 7.2. 流獲取

  當使用Post方法進行RestAPI呼叫時,獲取到的Body流資訊會儲存在PostStream中,比如一些JSON資訊,供函式處理呼叫。以下是將流中的數據轉換為文字的方法,轉換后的文字在 s 變數中,可供處理使用。

//JScript
function RestAPI()
{
    var Stream,s;
    Stream = new TStringStream("",UTF8Encoding);
    try{
        Stream.LoadFromStream(PostStream);
        s = Stream.DataString;
        Result = s;
    }
    finally{
        Stream.Free;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 7.3. 引用資料庫設定

  如需連線資料庫,或引用SQL預設資料中的資訊,需在資料庫設定中提前設定好連線資訊 FastERP,並且在SQL預設資料中設定配置 SQL002,在RestAPI設定中可使用以下方式連線:

function RestAPI()
{
  var DB,D,V,O;
  D = new TFDQuery(nil);
  //使用資料庫設定的連線
  DB = UGMM.GetDBConnection("FastERP");
  D.Connection = DB;
  //使用預設SQL
  D.SQL.Text = UGMM.GetSQL("SQL002");
  D.Open;
  //數據集轉換
  V = TFDQuery(D).ToJSONArray;
  O = new TJSONObject();
  O.AddPair("status","ok");
  O.AddPair("message","success");
  O.AddPair("records",TJSONNumber.Create(D.RecordCount));
  O.AddPair("data",V);
  return(O.ToString);
  D.Free;
  DB.Free;
  V.Free;
  O.Free;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

# 8. 獲取印表機列表

  • 請求地址:
http(s)://${host}:${port}/?restapi=getprinterlist
1

  獲取印表機列表資訊,此功能用於配合自定報表功能使用,用於指定自定報表列印時使用的印表機。獲取的示例格式如下:

{"status":"ok",
"data":[
    {"name":"\u5BFC\u51FA\u4E3AWPS PDF"},
    {"name":"OneNote for Windows 10"},
    {"name":"Microsoft XPS Document Writer"},
    {"name":"Microsoft Print to PDF"},
    {"name":"Fax"}
]}
1
2
3
4
5
6
7
8

# 9. 運行Python任務

  • 請求地址:
http(s)://${host}:${port}/?restapi=pythonscript&pyid={pyid}&varname={varname}&varvalue={varvalue}
1

  其中 {pyid} 為預設資料(資料型別為python)的編號。{varname} 為python輸入變數的名稱。{varvalue} 為python輸入變數的的取值。

  這個介面的作用是從預設資料的Python指令碼中建立運行任務,排入運行佇列中,當排入至運行佇列后,會返回提示資訊,運行佇列中的任務會按照請求的先後順序依次進行執行。

預設資料
WebSocket說明

← 預設資料 WebSocket說明→

Copyright © 2021-2025 愛招飛IsoFace | ALL Rights Reserved
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式