建立一个内部函数-同步部门,用递归循环调用
Functions.Execute("同步部门",1)
同步部门:
Dim id As Integer = args(0)
Dim ur As String = "https://oapi.dingtalk.com/topapi/v2/department/listsub"
Dim hc As New HttpClient(ur)
hc.FormData.Add("access_token",Functions.Execute("access_token"))
hc.FormData.Add("dept_id",id)
hc.FormData.Add("language","zh_CN")
Dim jo As JObject = JObject.Parse(hc.GetData())
Dim dt As DataTable = DataTables("dept")
Dim w As DataRow
If jo("errcode") = "0" Then
For Each jt As JToken In jo("result")
w = dt.Find("dept_id = '"& jt("dept_id").tostring &"'")
If w IsNot Nothing Then
w("name") = jt("name").tostring
w("parent_id") = jt("parent_id").tostring
Functions.Execute("同步部门",jt("dept_id").tostring)
Else
w = dt.AddNew
w("dept_id") = jt("dept_id").tostring
w("name") = jt("name").tostring
w("parent_id") = jt("parent_id").tostring
Functions.Execute("同步部门",jt("dept_id").tostring)
End If
Next
else
Output.show(jo("errmsg").Tostring)
End If
[此贴子已经被作者于2021/12/1 8:30:01编辑过]