Commit bbef2a0e by shiwenbo

修改OA同步接口

parent cb38293e
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/syncOrg", paramData, "");
String result = this.httpClientUtil.postJson(dnaOaUrl + "/oa/syncRole", 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/syncOrg", paramData, "");
String result = this.httpClientUtil.postJson(dnaOaUrl + "/oa/syncStaff", 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")){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment