Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
邬吉朋
ops
Commits
49d86301
Commit
49d86301
authored
Feb 28, 2025
by
wujipeng
Browse files
钉钉-获取部门树状图-第二版/查询部门详情
parent
ac5b4264
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/ruzhoukj/sms/controller/DingAttendanceController.java
View file @
49d86301
...
@@ -2,15 +2,15 @@ package com.ruzhoukj.sms.controller;
...
@@ -2,15 +2,15 @@ package com.ruzhoukj.sms.controller;
import
com.dingtalk.api.DefaultDingTalkClient
;
import
com.dingtalk.api.DefaultDingTalkClient
;
import
com.dingtalk.api.DingTalkClient
;
import
com.dingtalk.api.DingTalkClient
;
import
com.dingtalk.api.request.OapiV2DepartmentGetRequest
;
import
com.dingtalk.api.request.OapiV2DepartmentListsubidRequest
;
import
com.dingtalk.api.request.OapiV2DepartmentListsubidRequest
;
import
com.dingtalk.api.response.OapiV2DepartmentGetResponse
;
import
com.dingtalk.api.response.OapiV2DepartmentListsubidResponse
;
import
com.dingtalk.api.response.OapiV2DepartmentListsubidResponse
;
import
com.google.common.collect.Lists
;
import
com.ruzhoukj.sms.ding.PermissionConfig
;
import
com.ruzhoukj.sms.ding.PermissionConfig
;
import
com.ruzhoukj.sms.model.vo.DingDeptVO
;
import
com.ruzhoukj.sms.model.vo.DingDeptVO
;
import
com.taobao.api.ApiException
;
import
com.taobao.api.ApiException
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
import
org.checkerframework.checker.nullness.qual.Nullable
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
@@ -20,7 +20,6 @@ import javax.annotation.Resource;
...
@@ -20,7 +20,6 @@ import javax.annotation.Resource;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* @author : wujipeng
* @author : wujipeng
...
@@ -59,6 +58,8 @@ public class DingAttendanceController {
...
@@ -59,6 +58,8 @@ public class DingAttendanceController {
public
DingDeptVO
getDeptTree
()
{
public
DingDeptVO
getDeptTree
()
{
// 创建根节点
// 创建根节点
DingDeptVO
root
=
new
DingDeptVO
();
DingDeptVO
root
=
new
DingDeptVO
();
OapiV2DepartmentGetResponse
.
DeptGetResponse
deptDetail
=
getDeptDetail
(
1L
);
root
.
setName
(
deptDetail
.
getName
());
root
.
setId
(
1L
);
root
.
setId
(
1L
);
// 构建子节点树
// 构建子节点树
...
@@ -85,8 +86,10 @@ public class DingAttendanceController {
...
@@ -85,8 +86,10 @@ public class DingAttendanceController {
// 构建子节点列表
// 构建子节点列表
List
<
DingDeptVO
>
children
=
new
ArrayList
<>();
List
<
DingDeptVO
>
children
=
new
ArrayList
<>();
for
(
Long
childId
:
childIds
)
{
for
(
Long
childId
:
childIds
)
{
OapiV2DepartmentGetResponse
.
DeptGetResponse
deptDetail
=
getDeptDetail
(
childId
);
DingDeptVO
child
=
DingDeptVO
.
builder
()
DingDeptVO
child
=
DingDeptVO
.
builder
()
.
id
(
childId
)
.
id
(
childId
)
.
name
(
deptDetail
.
getName
())
.
build
();
.
build
();
// 递归构建子节点的子树
// 递归构建子节点的子树
...
@@ -102,5 +105,22 @@ public class DingAttendanceController {
...
@@ -102,5 +105,22 @@ public class DingAttendanceController {
}
}
@ApiOperation
(
value
=
"查询部门详情"
)
@GetMapping
(
"/detail/{deptId}"
)
public
OapiV2DepartmentGetResponse
.
DeptGetResponse
getDeptDetail
(
@PathVariable
Long
deptId
)
{
String
accessToken
=
permissionConfig
.
getAccessToken
();
try
{
DingTalkClient
client
=
new
DefaultDingTalkClient
(
"https://oapi.dingtalk.com/topapi/v2/department/get"
);
OapiV2DepartmentGetRequest
req
=
new
OapiV2DepartmentGetRequest
();
req
.
setDeptId
(
deptId
);
req
.
setLanguage
(
"zh_CN"
);
req
.
setHttpMethod
(
"POST"
);
OapiV2DepartmentGetResponse
rsp
=
client
.
execute
(
req
,
accessToken
);
return
rsp
.
getResult
();
}
catch
(
ApiException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment