同步Ecology部门,测试模块OK
This commit is contained in:
parent
b369889400
commit
e803a7f3fa
|
|
@ -35,6 +35,14 @@
|
|||
<version>20160810</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-system</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,122 @@
|
|||
package com.ruoyi.test.conrtroller;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.domain.EcologyDept;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
public class GetEcologyInfoTestController extends BaseController {
|
||||
@Autowired
|
||||
private SysDeptMapper deptMapper;
|
||||
|
||||
@RequestMapping("/anon/getEcologyDept")
|
||||
public String getEcologyDept() throws Exception {
|
||||
String url="http://192.168.2.85:90/api/hrm/resful/getHrmdepartmentWithPage";
|
||||
String params="{\"params\":{\"pagesize\":1000}}";
|
||||
//return sendPost(url,params);
|
||||
return deptSync(sendPostWithRest(url,params));
|
||||
}
|
||||
|
||||
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 String deptSync(Map<String,String> mapResult){
|
||||
//如果接口返回状态码不为200,则不做同步处理
|
||||
String statusCode=mapResult.get("statusCode");
|
||||
String result= mapResult.get("result");
|
||||
if(!statusCode.equals("200"))
|
||||
{
|
||||
return mapResult.get("result");
|
||||
}
|
||||
//取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 result;
|
||||
}
|
||||
|
||||
/* public String sendPost(String url,String params) throws Exception {
|
||||
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) {
|
||||
//logger.error("POST Request uri: {}, params: {}, error: {}", url, params, e.getMessage());
|
||||
}
|
||||
if (statusCode == 200) {
|
||||
|
||||
return result.getBody();
|
||||
}
|
||||
if (statusCode >= 300 || statusCode < 200) {
|
||||
throw new Exception("Response code is " + statusCode);
|
||||
}
|
||||
//return ResponseCreator.writeJsonErr(result.getStatusCode().toString());
|
||||
|
||||
return result.getStatusCode().toString();
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -29,6 +29,9 @@
|
|||
</div>
|
||||
|
||||
<div class="btn-group-sm" id="toolbar" role="group">
|
||||
<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">
|
||||
<i class="fa fa-plus"></i> 新增
|
||||
</a>
|
||||
|
|
@ -107,6 +110,20 @@
|
|||
};
|
||||
$.treeTable.init(options);
|
||||
});
|
||||
|
||||
function syncDept() {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: ctx+"system/dept/syncDept",
|
||||
data: JSON.stringify(""), //beauty是字符串
|
||||
contentType: "application/json",
|
||||
dataType: "json",
|
||||
success: function(message) {
|
||||
//alert(JSON.stringify(message)); //将JSON对象转换为字符串
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
package com.ruoyi.system.domain;
|
||||
|
||||
public class EcologyDept {
|
||||
String Canceled;
|
||||
String supdepid;
|
||||
String departmentmark;
|
||||
String departmentname;
|
||||
String created;
|
||||
String departmentcode;
|
||||
String modified;
|
||||
String id;
|
||||
String subcompanyid1;
|
||||
String showorder;
|
||||
|
||||
public String getCanceled() {
|
||||
return Canceled;
|
||||
}
|
||||
|
||||
public void setCanceled(String canceled) {
|
||||
Canceled = canceled;
|
||||
}
|
||||
|
||||
public String getSupdepid() {
|
||||
return supdepid;
|
||||
}
|
||||
|
||||
public void setSupdepid(String supdepid) {
|
||||
this.supdepid = supdepid;
|
||||
}
|
||||
|
||||
public String getDepartmentmark() {
|
||||
return departmentmark;
|
||||
}
|
||||
|
||||
public void setDepartmentmark(String departmentmark) {
|
||||
this.departmentmark = departmentmark;
|
||||
}
|
||||
|
||||
public String getDepartmentname() {
|
||||
return departmentname;
|
||||
}
|
||||
|
||||
public void setDepartmentname(String departmentname) {
|
||||
this.departmentname = departmentname;
|
||||
}
|
||||
|
||||
public String getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(String created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public String getDepartmentcode() {
|
||||
return departmentcode;
|
||||
}
|
||||
|
||||
public void setDepartmentcode(String departmentcode) {
|
||||
this.departmentcode = departmentcode;
|
||||
}
|
||||
|
||||
public String getModified() {
|
||||
return modified;
|
||||
}
|
||||
|
||||
public void setModified(String modified) {
|
||||
this.modified = modified;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getSubcompanyid1() {
|
||||
return subcompanyid1;
|
||||
}
|
||||
|
||||
public void setSubcompanyid1(String subcompanyid1) {
|
||||
this.subcompanyid1 = subcompanyid1;
|
||||
}
|
||||
|
||||
public String getShoworder() {
|
||||
return showorder;
|
||||
}
|
||||
|
||||
public void setShoworder(String showorder) {
|
||||
this.showorder = showorder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "EcologyDept{" +
|
||||
"Canceled='" + Canceled + '\'' +
|
||||
", supdepid='" + supdepid + '\'' +
|
||||
", departmentmark='" + departmentmark + '\'' +
|
||||
", departmentname='" + departmentname + '\'' +
|
||||
", created='" + created + '\'' +
|
||||
", departmentcode='" + departmentcode + '\'' +
|
||||
", modified='" + modified + '\'' +
|
||||
", id='" + id + '\'' +
|
||||
", subcompanyid1='" + subcompanyid1 + '\'' +
|
||||
", showorder='" + showorder + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
@ -114,4 +114,9 @@ public interface SysDeptMapper
|
|||
* @return 子部门数
|
||||
*/
|
||||
public int selectNormalChildrenDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* Truncate部门表,用于与Ecology部门同步
|
||||
*/
|
||||
public void truncateDept();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -152,4 +152,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="truncateDept">
|
||||
truncate table sys_dept
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue