同步Ecology部门功能完成
This commit is contained in:
parent
e803a7f3fa
commit
6da42f4b11
|
|
@ -204,4 +204,22 @@ public class SysDeptController extends BaseController
|
|||
List<Ztree> ztrees = deptService.roleDeptTreeData(role);
|
||||
return ztrees;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ecology部门信息同步
|
||||
*/
|
||||
@Log(title = "部门管理", businessType = BusinessType.UPDATE)
|
||||
@RequiresPermissions("system:dept:edit")
|
||||
@PostMapping("/syncDept")
|
||||
@ResponseBody
|
||||
public AjaxResult syncDept()
|
||||
{
|
||||
String url="http://192.168.2.85:90/api/hrm/resful/getHrmdepartmentWithPage";
|
||||
String params="{\"params\":{\"pagesize\":1000}}";
|
||||
int result = deptService.syncEcologyDept(url,params);
|
||||
if(result==200){
|
||||
return AjaxResult.success("部门同步成功,返回状态码:"+result);
|
||||
}
|
||||
return AjaxResult.error("同步失败,返回状态码:"+result);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
<a class="btn btn-success" onclick="syncDept()" shiro:hasPermission="system:dept:sync">
|
||||
<i class="fa fa-plus"></i> 同步
|
||||
</a>
|
||||
<a class="btn btn-success" onclick="$.operate.add(100)" shiro:hasPermission="system:dept:add">
|
||||
<a class="btn btn-success" onclick="addDept()" shiro:hasPermission="system:dept:add" >
|
||||
<i class="fa fa-plus"></i> 新增
|
||||
</a>
|
||||
<a class="btn btn-primary" onclick="$.operate.edit()" shiro:hasPermission="system:dept:edit">
|
||||
|
|
@ -53,6 +53,7 @@
|
|||
var editFlag = [[${@permission.hasPermi('system:dept:edit')}]];
|
||||
var removeFlag = [[${@permission.hasPermi('system:dept:remove')}]];
|
||||
var datas = [[${@dict.getType('sys_normal_disable')}]];
|
||||
var deptSyncType = [[${#strings.defaultString(@config.getKey('sys.dept.sync'), 0)}]];
|
||||
var prefix = ctx + "system/dept"
|
||||
|
||||
$(function() {
|
||||
|
|
@ -111,17 +112,30 @@
|
|||
$.treeTable.init(options);
|
||||
});
|
||||
|
||||
|
||||
function addDept(){
|
||||
|
||||
if(deptSyncType =="0") {
|
||||
$.operate.add(999999);
|
||||
}else {
|
||||
alert("系统参数已启用同步Ecology部门信息,禁止手动新增部门!")
|
||||
}
|
||||
}
|
||||
function syncDept() {
|
||||
if(deptSyncType =="1") {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: ctx+"system/dept/syncDept",
|
||||
url: ctx + "system/dept/syncDept",
|
||||
data: JSON.stringify(""), //beauty是字符串
|
||||
contentType: "application/json",
|
||||
dataType: "json",
|
||||
success: function(message) {
|
||||
//alert(JSON.stringify(message)); //将JSON对象转换为字符串
|
||||
success: function (message) {
|
||||
alert(JSON.stringify(message)); //将JSON对象转换为字符串
|
||||
}
|
||||
});
|
||||
}else {
|
||||
alert("系统参数未启用同步Ecology部门!")
|
||||
}
|
||||
};
|
||||
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -107,4 +107,9 @@ public interface ISysDeptService
|
|||
* @return 结果
|
||||
*/
|
||||
public String checkDeptNameUnique(SysDept dept);
|
||||
|
||||
/**
|
||||
* Ecology部门信息同步
|
||||
*/
|
||||
public int syncEcologyDept(String url,String params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.ruoyi.system.domain.EcologyDept;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
|
|
@ -17,6 +20,8 @@ import com.ruoyi.common.exception.BusinessException;
|
|||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
/**
|
||||
* 部门管理 服务实现
|
||||
|
|
@ -308,4 +313,78 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
}
|
||||
return UserConstants.DEPT_NAME_UNIQUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ecology部门信息同步
|
||||
*/
|
||||
@Override
|
||||
public int syncEcologyDept(String url,String params) {
|
||||
int result= deptSync(sendPostWithRest(url,params));
|
||||
return result;
|
||||
|
||||
}
|
||||
public Map<String,String> sendPostWithRest(String url, String params){
|
||||
RestTemplate restTemplate=new RestTemplate();
|
||||
ResponseEntity<String> result=null;
|
||||
int statusCode=0;
|
||||
try{
|
||||
result=restTemplate.postForEntity(url,params,String.class);
|
||||
statusCode=result.getStatusCode().value();
|
||||
}catch (RestClientException e){
|
||||
System.out.println("POST Request uri: "+url+", params:"+params+" error:"+e.getMessage());
|
||||
}
|
||||
Map<String,String> map=new HashMap<>();
|
||||
map.put("statusCode",String.valueOf(statusCode));
|
||||
if(statusCode== 200){
|
||||
map.put("result",result.getBody());
|
||||
} else{
|
||||
map.put("result",String.valueOf(statusCode));
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
public int deptSync(Map<String,String> mapResult){
|
||||
//如果接口返回状态码不为200,则不做同步处理
|
||||
String statusCode=mapResult.get("statusCode");
|
||||
String result= mapResult.get("result");
|
||||
if(!statusCode.equals("200"))
|
||||
{
|
||||
//return mapResult.get("result");
|
||||
return 0;
|
||||
}
|
||||
//取Ecology返回信息中的部门信息
|
||||
Map<String,Object> map = (Map) JSON.parse(result);
|
||||
Map<String,Object> o= (Map<String, Object>) map.get("data");
|
||||
JSONArray json = (JSONArray) o.get("dataList");
|
||||
List<EcologyDept> depts = JSONArray.parseArray(json.toJSONString(), EcologyDept.class);
|
||||
//清空部门表
|
||||
deptMapper.truncateDept();
|
||||
//插入最顶层部门
|
||||
SysDept dept =new SysDept();
|
||||
dept.setDeptId(Long.parseLong("999999"));
|
||||
dept.setParentId(Long.parseLong("0"));
|
||||
dept.setDeptName("BPS");
|
||||
dept.setOrderNum("0");
|
||||
dept.setStatus("0");
|
||||
dept.setCreateBy("Admin");
|
||||
deptMapper.insertDept(dept);
|
||||
//同步Ecology部门信息
|
||||
for(EcologyDept ecologyDept:depts){
|
||||
//System.out.println(ecologyDept.getDepartmentname());
|
||||
//String subCompanyid=ecologyDept.getSubcompanyid1();
|
||||
if(ecologyDept.getSubcompanyid1().equals("1")) { //只取分部ID为“1”的部门,排除代理商
|
||||
dept.setDeptId(Long.parseLong(ecologyDept.getId()));
|
||||
dept.setParentId(Long.parseLong(ecologyDept.getSupdepid()) == 0 ? 999999 : Long.parseLong(ecologyDept.getSupdepid()));
|
||||
dept.setDeptName(ecologyDept.getDepartmentname());
|
||||
dept.setOrderNum("0");
|
||||
dept.setStatus("0");
|
||||
dept.setCreateBy("Admin");
|
||||
deptMapper.insertDept(dept);
|
||||
}
|
||||
}
|
||||
return 200;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue