controller/controller.proto

syntax = "proto3";

package jsgenerate_kb2022.controller;
option go_package = "gateway/protocol/controller";

import "google/api/annotations.proto";
import "adadd52b-e7a2-4fe2-9f15-356ceddbd4f6/utils/utils.proto";
// controller 模塊用於對受控設備下達一系列指令
service Controller{
    // 對設備設置一個控制指令
    rpc Add(AddRequest) returns (AddResponse){
        option (google.api.http) = {
            post: "/api/v1/controller/add"
            body: "*"
        };
    }
    // 返回指定 id 的命令,僅用於顯示歷史數據
    rpc ID (IDRequest) returns (IDResponse){
        option (google.api.http) = {
            get: "/api/v1/controller/by_id"
        };
    }
    // 查詢已經設置的命令
    rpc Find(FindRequest) returns (FindResponse){
        option (google.api.http) = {
            get: "/api/v1/controller"
        };
    }
}

message AddRequest{
    // 受控設備 id
    int64 target = 1;
    // 要執行的命令
    uint32 command = 2;
    // 命令包含的參數以 json 編碼的 utf8 字符串
    string value = 3;
}
message AddResponse{
    // 指令任務流水號
    int64 id = 1;
}


message Data{
	// 指令流水
	int64 id = 1;
	// 下達命令的用戶 id
	int64 uid = 2;
	// 受控設備 id
	int64 target = 3;
	// 指令創建時間 unix
	int64 post = 4;

	// 要執行的 指令
	uint32 command = 5;
	// 要執行的指令名稱,僅方便人類觀看,無其它實際作用
	string name = 6;

	// 與指令關聯的參數,以 json 編碼
	string parameters = 7;

	// 受控端最後 處理此指令的時間 unix
	int64 last = 8;

	// 指令執行狀態
	// * 0 未處理
	// * 1 處理中
	// * 10 處理完成,並且成功
	// * 11 處理完成,但是失敗
	uint32 completer = 9;

	// 受控端設置的最後處理結果描述
	string message = 10;
}
message IDRequest{
    repeated int64 id = 1;
}
message IDResponse{
    repeated Data data = 1;
}

message FindRequest{
    jsgenerate_kb2022.utils.FindLimit limit = 1;
    // id not in (...)
    repeated int64 notID = 50;
    // id in 
    repeated int64 id = 2;
    // uid in 
    repeated int64 uid = 3;
    // target in
    repeated int64 target = 4;
    // command in
    repeated uint32 command = 5;
    // completer in
    repeated uint32 completer = 6;

    // 如果 >0 返回 創建時間 unix >= post 的日誌
    int64 afterPost = 10;
    // 如果 >0 返回 創建時間 unix <= post 的日誌
    int64 beforePost = 11;
    // 如果 >0 返回 創建時間 unix >= last 的日誌
    int64 afterLast = 12;
    // 如果 >0 返回 創建時間 unix <= last 的日誌
    int64 beforeLast = 13;
}
message FindResponse{
    jsgenerate_kb2022.utils.FindResult result = 1;
    repeated Data data = 2;
}