Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-fb
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王衍超
cloud-fb
Commits
bbef2a0e
Commit
bbef2a0e
authored
May 30, 2021
by
shiwenbo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改OA同步接口
parent
cb38293e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
73 additions
and
4 deletions
+73
-4
SyncOaController.java
...rc/main/java/com/xyst/dinas/biz/web/SyncOaController.java
+73
-4
No files found.
backend/xyst.dinas.biz/src/main/java/com/xyst/dinas/biz/web/SyncOaController.java
View file @
bbef2a0e
package
com
.
xyst
.
dinas
.
biz
.
web
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.UUID
;
import
org.json.JSONArray
;
import
org.json.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -11,6 +17,11 @@ import org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.beecode.bap.department.service.DepartmentService
;
import
com.beecode.bap.staff.service.StaffService
;
import
com.beecode.bcp.authz.Role
;
import
com.beecode.bcp.authz.service.RoleService
;
import
com.beecode.bcp.type.KObject
;
import
com.xyst.dinas.biz.web.request.HttpClientUtil
;
/**
...
...
@@ -29,6 +40,15 @@ public class SyncOaController {
@Value
(
"${dna.oa.url:}"
)
private
String
dnaOaUrl
=
null
;
@Autowired
private
DepartmentService
departmentService
;
@Autowired
private
StaffService
staffService
;
@Autowired
private
RoleService
roleService
;
/**
* 同步组织
* @param body
...
...
@@ -56,11 +76,25 @@ public class SyncOaController {
@RequestMapping
(
value
=
"/oa/syncUser"
,
method
=
RequestMethod
.
POST
)
public
Object
syncUser
(
@RequestBody
String
body
)
{
JSONObject
paramData
=
new
JSONObject
(
body
);
String
result
=
this
.
httpClientUtil
.
postJson
(
dnaOaUrl
+
"/oa/syncOrg"
,
paramData
,
""
);
JSONArray
array
=
paramData
.
getJSONArray
(
"datas"
);
JSONObject
json
=
array
.
getJSONObject
(
0
);
String
departmentId
=
json
.
getString
(
"departmentId"
);
KObject
department
=
departmentService
.
getById
(
UUID
.
fromString
(
departmentId
));
json
.
put
(
"orgName"
,
department
.
getString
(
"name"
));
json
.
put
(
"orgLevel"
,
department
.
getInt
(
"level"
)
+
1
);
String
result
=
this
.
httpClientUtil
.
postJson
(
dnaOaUrl
+
"/oa/syncUser"
,
paramData
,
""
);
JSONObject
param
=
new
JSONObject
(
result
);
String
resultStr
=
param
.
optString
(
"result"
);
if
(
resultStr
.
equals
(
"fail"
)){
logger
.
error
(
"向DNA服务同步用户时失败! "
+
param
.
optString
(
"errorMessage"
));
}
else
{
String
result2
=
this
.
httpClientUtil
.
postJson
(
dnaOaUrl
+
"/oa/syncStaff"
,
paramData
,
""
);
JSONObject
param2
=
new
JSONObject
(
result2
);
String
resultStr2
=
param2
.
optString
(
"result"
);
if
(
resultStr2
.
equals
(
"fail"
)){
logger
.
error
(
"向DNA服务同步职员时失败! "
+
param
.
optString
(
"errorMessage"
));
}
return
param
.
toString
();
}
return
param
.
toString
();
}
...
...
@@ -74,7 +108,7 @@ public class SyncOaController {
@RequestMapping
(
value
=
"/oa/syncRole"
,
method
=
RequestMethod
.
POST
)
public
Object
syncRole
(
@RequestBody
String
body
)
{
JSONObject
paramData
=
new
JSONObject
(
body
);
String
result
=
this
.
httpClientUtil
.
postJson
(
dnaOaUrl
+
"/oa/sync
Org
"
,
paramData
,
""
);
String
result
=
this
.
httpClientUtil
.
postJson
(
dnaOaUrl
+
"/oa/sync
Role
"
,
paramData
,
""
);
JSONObject
param
=
new
JSONObject
(
result
);
String
resultStr
=
param
.
optString
(
"result"
);
if
(
resultStr
.
equals
(
"fail"
)){
...
...
@@ -92,7 +126,7 @@ public class SyncOaController {
@RequestMapping
(
value
=
"/oa/syncStaff"
,
method
=
RequestMethod
.
POST
)
public
Object
syncStaff
(
@RequestBody
String
body
)
{
JSONObject
paramData
=
new
JSONObject
(
body
);
String
result
=
this
.
httpClientUtil
.
postJson
(
dnaOaUrl
+
"/oa/sync
Org
"
,
paramData
,
""
);
String
result
=
this
.
httpClientUtil
.
postJson
(
dnaOaUrl
+
"/oa/sync
Staff
"
,
paramData
,
""
);
JSONObject
param
=
new
JSONObject
(
result
);
String
resultStr
=
param
.
optString
(
"result"
);
if
(
resultStr
.
equals
(
"fail"
)){
...
...
@@ -110,7 +144,42 @@ public class SyncOaController {
@RequestMapping
(
value
=
"/oa/addRoleToUser"
,
method
=
RequestMethod
.
POST
)
public
Object
addRoleToUser
(
@RequestBody
String
body
)
{
JSONObject
paramData
=
new
JSONObject
(
body
);
String
result
=
this
.
httpClientUtil
.
postJson
(
dnaOaUrl
+
"/oa/syncOrg"
,
paramData
,
""
);
JSONArray
roleIds
=
paramData
.
getJSONArray
(
"roleIds"
);
JSONArray
staffIds
=
paramData
.
getJSONArray
(
"staffIds"
);
JSONArray
deptIds
=
paramData
.
getJSONArray
(
"deptIds"
);
List
<
String
>
roleNameList
=
new
ArrayList
<
String
>();
List
<
String
>
staffNameList
=
new
ArrayList
<
String
>();
for
(
int
i
=
0
;
i
<
roleIds
.
length
();
i
++)
{
Optional
<
Role
>
role
=
roleService
.
get
(
UUID
.
fromString
(
roleIds
.
getString
(
i
)));
if
(
role
.
isPresent
())
{
roleNameList
.
add
(
role
.
get
().
getName
());
}
}
for
(
int
i
=
0
;
i
<
staffIds
.
length
();
i
++)
{
staffNameList
.
add
(
staffService
.
getById
(
UUID
.
fromString
(
staffIds
.
getString
(
i
))).
getString
(
"name"
));
}
for
(
int
i
=
0
;
i
<
deptIds
.
length
();
i
++)
{
List
<
KObject
>
staffList
=
staffService
.
getByDept
(
UUID
.
fromString
(
deptIds
.
getString
(
i
)));
for
(
int
j
=
0
;
j
<
staffList
.
size
();
j
++)
{
if
(
staffNameList
.
contains
(
staffList
.
get
(
j
).
getString
(
"name"
)))
{
staffNameList
.
add
(
staffList
.
get
(
j
).
getString
(
"name"
));
}
}
}
JSONObject
paramData2
=
new
JSONObject
();
JSONArray
array
=
new
JSONArray
();
paramData2
.
put
(
"datas"
,
array
);
for
(
int
i
=
0
;
i
<
roleNameList
.
size
();
i
++)
{
String
roleName
=
roleNameList
.
get
(
i
);
for
(
int
j
=
0
;
j
<
staffNameList
.
size
();
j
++)
{
String
staffName
=
staffNameList
.
get
(
j
);
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"userName"
,
staffName
);
json
.
put
(
"roleName"
,
roleName
);
array
.
put
(
json
);
}
}
String
result
=
this
.
httpClientUtil
.
postJson
(
dnaOaUrl
+
"/oa/addRoleToUser"
,
paramData2
,
""
);
JSONObject
param
=
new
JSONObject
(
result
);
String
resultStr
=
param
.
optString
(
"result"
);
if
(
resultStr
.
equals
(
"fail"
)){
...
...
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