{
  "properties" : { },
  "id" : "55ddadf56dfe433baae1b5c26580cf00",
  "script" : null,
  "groupId" : "4f0230049d7e4f39b1e0897cc0f46f9a",
  "name" : "所有机构",
  "createTime" : 1646490239474,
  "updateTime" : 1642134606249,
  "lock" : "0",
  "createBy" : null,
  "updateBy" : null,
  "path" : "/offices",
  "method" : "GET",
  "parameters" : [ ],
  "options" : [ ],
  "requestBody" : "",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 200,\n    \"message\": \"success\",\n    \"data\": {\n        \"list\": [{\n            \"id\": \"4c37a80226134bce8bc91c8fc04a7d2f\",\n            \"label\": \"<font color=\\\"yellow\\\">马小东公司</font>\",\n            \"pid\": \"0\",\n            \"children\": [{\n                \"id\": \"81b5493cdb31477f9ceea85b2cd08f15\",\n                \"label\": \"<font color=\\\"yellow\\\">马小东子公司</font>\",\n                \"pid\": \"4c37a80226134bce8bc91c8fc04a7d2f\",\n                \"children\": []\n            }, {\n                \"id\": \"31b365008f994e93850186126fce87cb\",\n                \"label\": \"<font color=\\\"yellow\\\">马小东子公司2</font>\",\n                \"pid\": \"4c37a80226134bce8bc91c8fc04a7d2f\",\n                \"children\": []\n            }]\n        }, {\n            \"id\": \"935126327e2a4f90b3f485f818f61ea5\",\n            \"label\": \"<font color=\\\"yellow\\\">吕金泽公司</font>\",\n            \"pid\": \"0\",\n            \"children\": [{\n                \"id\": \"1ae0299fc79b43c6b0ae2e14756ec41a\",\n                \"label\": \"<font color=\\\"yellow\\\">吕金泽子公司</font>\",\n                \"pid\": \"935126327e2a4f90b3f485f818f61ea5\",\n                \"children\": []\n            }]\n        }],\n        \"total\": 2\n    },\n    \"timestamp\": 1642134574553,\n    \"executeTime\": 5\n}",
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "code",
      "value" : "200",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "success",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "",
      "description" : "",
      "required" : false,
      "dataType" : "Object",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ {
        "name" : "list",
        "value" : "",
        "description" : "",
        "required" : false,
        "dataType" : "Array",
        "type" : null,
        "defaultValue" : null,
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ {
          "name" : "",
          "value" : "",
          "description" : "",
          "required" : false,
          "dataType" : "Object",
          "type" : null,
          "defaultValue" : null,
          "validateType" : "",
          "error" : "",
          "expression" : "",
          "children" : [ {
            "name" : "id",
            "value" : "4c37a80226134bce8bc91c8fc04a7d2f",
            "description" : "",
            "required" : false,
            "dataType" : "String",
            "type" : null,
            "defaultValue" : null,
            "validateType" : "",
            "error" : "",
            "expression" : "",
            "children" : [ ]
          }, {
            "name" : "label",
            "value" : "<font color=\\\"yellow\\\">马小东公司</font>",
            "description" : "",
            "required" : false,
            "dataType" : "String",
            "type" : null,
            "defaultValue" : null,
            "validateType" : "",
            "error" : "",
            "expression" : "",
            "children" : [ ]
          }, {
            "name" : "pid",
            "value" : "0",
            "description" : "",
            "required" : false,
            "dataType" : "String",
            "type" : null,
            "defaultValue" : null,
            "validateType" : "",
            "error" : "",
            "expression" : "",
            "children" : [ ]
          }, {
            "name" : "children",
            "value" : "",
            "description" : "",
            "required" : false,
            "dataType" : "Array",
            "type" : null,
            "defaultValue" : null,
            "validateType" : "",
            "error" : "",
            "expression" : "",
            "children" : [ {
              "name" : "",
              "value" : "",
              "description" : "",
              "required" : false,
              "dataType" : "Object",
              "type" : null,
              "defaultValue" : null,
              "validateType" : "",
              "error" : "",
              "expression" : "",
              "children" : [ {
                "name" : "id",
                "value" : "81b5493cdb31477f9ceea85b2cd08f15",
                "description" : "",
                "required" : false,
                "dataType" : "String",
                "type" : null,
                "defaultValue" : null,
                "validateType" : "",
                "error" : "",
                "expression" : "",
                "children" : [ ]
              }, {
                "name" : "label",
                "value" : "<font color=\\\"yellow\\\">马小东子公司</font>",
                "description" : "",
                "required" : false,
                "dataType" : "String",
                "type" : null,
                "defaultValue" : null,
                "validateType" : "",
                "error" : "",
                "expression" : "",
                "children" : [ ]
              }, {
                "name" : "pid",
                "value" : "4c37a80226134bce8bc91c8fc04a7d2f",
                "description" : "",
                "required" : false,
                "dataType" : "String",
                "type" : null,
                "defaultValue" : null,
                "validateType" : "",
                "error" : "",
                "expression" : "",
                "children" : [ ]
              }, {
                "name" : "children",
                "value" : "",
                "description" : "",
                "required" : false,
                "dataType" : "Array",
                "type" : null,
                "defaultValue" : null,
                "validateType" : "",
                "error" : "",
                "expression" : "",
                "children" : [ ]
              } ]
            } ]
          } ]
        } ]
      }, {
        "name" : "total",
        "value" : "2",
        "description" : "",
        "required" : false,
        "dataType" : "Integer",
        "type" : null,
        "defaultValue" : null,
        "validateType" : "",
        "error" : "",
        "expression" : "",
        "children" : [ ]
      } ]
    }, {
      "name" : "timestamp",
      "value" : "1642134574553",
      "description" : "",
      "required" : false,
      "dataType" : "Long",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "executeTime",
      "value" : "5",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
var toTree = (list,pid) => select t.*,toTree(list,t.id) children from list t where t.pid = pid
var list = toTree(db.select('select id,name label,pid from sys_office where is_del = 0 order by sort'),'0')

return {
    list: list,
    total: list.getLength()
}