This commit is contained in:
parent
54696ed7a0
commit
c49935cb6c
|
|
@ -1,37 +1,30 @@
|
|||
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.AjaxResult;
|
||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import com.ruoyi.system.domain.EcologyDept;
|
||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||
import com.ruoyi.system.service.ISysDeptService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
public class GetEcologyInfoTestController extends BaseController {
|
||||
@Autowired
|
||||
private SysDeptMapper deptMapper;
|
||||
private ISysDeptService deptService;
|
||||
@Autowired
|
||||
private ISysUserService userService;
|
||||
|
||||
@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}}";
|
||||
String params="{\"params\":{\"pagesize\":999999}}";
|
||||
//return sendPost(url,params);
|
||||
return deptSync(HttpUtils.sendPostWithRest(url,params));
|
||||
int result = deptService.syncEcologyDept(url,params);
|
||||
if(result==200){
|
||||
return "同步成功";
|
||||
}
|
||||
return "同步失败";
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +39,7 @@ public class GetEcologyInfoTestController extends BaseController {
|
|||
return "同步失败";
|
||||
}
|
||||
|
||||
/*public Map<String,String> sendPostWithRest(String url,String params){
|
||||
/* *//*public Map<String,String> sendPostWithRest(String url,String params){
|
||||
RestTemplate restTemplate=new RestTemplate();
|
||||
ResponseEntity<String> result=null;
|
||||
int statusCode=0;
|
||||
|
|
@ -65,7 +58,7 @@ public class GetEcologyInfoTestController extends BaseController {
|
|||
}
|
||||
|
||||
return map;
|
||||
}*/
|
||||
}*//*
|
||||
|
||||
public SysDept insertEcologyDept(EcologyDept ecologyDept){
|
||||
SysDept dept=new SysDept();
|
||||
|
|
@ -123,10 +116,10 @@ public class GetEcologyInfoTestController extends BaseController {
|
|||
//同步Ecology部门信息
|
||||
for(EcologyDept ecologyDept:depts){
|
||||
if(ecologyDept.getSubcompanyid1().equals("1")) { //只取分部ID为“1”的部门,排除代理商
|
||||
/* String pAncestors=null;
|
||||
*//* String pAncestors=null;
|
||||
if(ecologyDept.getSupdepid().equals("0")){ //如果Ecology部门为一级部门,则设定ancestors="0,999999"
|
||||
pAncestors="0,999999";
|
||||
}*/
|
||||
}*//*
|
||||
SysDept dept= insertEcologyDept(ecologyDept);
|
||||
list.add(dept);
|
||||
}
|
||||
|
|
@ -137,7 +130,7 @@ public class GetEcologyInfoTestController extends BaseController {
|
|||
return result;
|
||||
}
|
||||
|
||||
/* public String sendPost(String url,String params) throws Exception {
|
||||
*//* public String sendPost(String url,String params) throws Exception {
|
||||
RestTemplate restTemplate=new RestTemplate();
|
||||
ResponseEntity<String> result = null;
|
||||
int statusCode = 0;
|
||||
|
|
@ -158,8 +151,8 @@ public class GetEcologyInfoTestController extends BaseController {
|
|||
|
||||
return result.getStatusCode().toString();
|
||||
}
|
||||
*//*
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@
|
|||
<groupId>com.ruoyi</groupId>
|
||||
<artifactId>ruoyi-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import java.util.*;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import com.ruoyi.system.domain.EcologyDept;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
|
@ -333,17 +335,30 @@ public class SysDeptServiceImpl implements ISysDeptService
|
|||
{
|
||||
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);
|
||||
//清空部门表,并插入顶级部门
|
||||
SysDept sysDept=deptMapper.selectDeptById(Long.parseLong("999999"));
|
||||
Map<String,Object> dataMap= (Map<String, Object>) map.get("data");
|
||||
//JSONArray json = (JSONArray) o.get("dataList");
|
||||
//List<EcologyDept> depts = JSONArray.parseArray(json.toJSONString(), EcologyDept.class);
|
||||
List<EcologyDept> depts= new Gson().fromJson(dataMap.get("dataList").toString(), new TypeToken<List<EcologyDept>>(){}.getType());
|
||||
|
||||
//清空部门表
|
||||
deptMapper.truncateDept();
|
||||
deptMapper.insertDept(sysDept);
|
||||
List<SysDept> list=new ArrayList<>();
|
||||
|
||||
//插入顶级部门
|
||||
SysDept topDept= new SysDept();//deptMapper.selectDeptById(Long.parseLong("999999"));
|
||||
topDept.setDeptId(Long.parseLong("999999"));
|
||||
topDept.setParentId(Long.parseLong("0"));
|
||||
topDept.setDeptName("BPS");
|
||||
topDept.setAncestors("0");
|
||||
topDept.setOrderNum("0");
|
||||
topDept.setStatus("0");
|
||||
topDept.setCreateBy("Admin");
|
||||
deptMapper.insertDept(topDept);
|
||||
|
||||
//同步Ecology部门信息
|
||||
List<SysDept> list=new ArrayList<>();
|
||||
for(EcologyDept ecologyDept:depts){
|
||||
if(ecologyDept.getSubcompanyid1().equals("1")) { //只取分部ID为“1”的部门,排除代理商
|
||||
SysDept dept= insertEcologyDept(ecologyDept);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.ruoyi.system.service.impl;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.ruoyi.common.annotation.DataScope;
|
||||
import com.ruoyi.common.constant.UserConstants;
|
||||
import com.ruoyi.common.core.domain.entity.SysRole;
|
||||
|
|
@ -11,10 +13,7 @@ import com.ruoyi.common.exception.BusinessException;
|
|||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.http.HttpUtils;
|
||||
import com.ruoyi.common.utils.security.Md5Utils;
|
||||
import com.ruoyi.system.domain.EcologyUser;
|
||||
import com.ruoyi.system.domain.SysPost;
|
||||
import com.ruoyi.system.domain.SysUserPost;
|
||||
import com.ruoyi.system.domain.SysUserRole;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.mapper.*;
|
||||
import com.ruoyi.system.service.ISysConfigService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
|
|
@ -550,9 +549,10 @@ public class SysUserServiceImpl implements ISysUserService
|
|||
}
|
||||
//取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<EcologyUser> ecologyUserList = JSONArray.parseArray(json.toJSONString(), EcologyUser.class);
|
||||
Map<String,Object> dataMap= (Map<String, Object>) map.get("data");
|
||||
/*JSONArray json = (JSONArray) dataMap.get("dataList");
|
||||
List<EcologyUser> ecologyUserList = JSONArray.parseArray(json.toJSONString(), EcologyUser.class);*/
|
||||
List<EcologyUser> ecologyUserList= new Gson().fromJson(dataMap.get("dataList").toString(), new TypeToken<List<EcologyUser>>(){}.getType());
|
||||
|
||||
userMapper.deleteEcologySyncUser();
|
||||
SysUser user = new SysUser();
|
||||
|
|
|
|||
Loading…
Reference in New Issue