修正Ecology同步时没有更新祖级列表信息的问题
This commit is contained in:
parent
c9b127eb28
commit
123dcd95e5
|
|
@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
import com.ruoyi.common.core.domain.entity.SysDept;
|
import com.ruoyi.common.core.domain.entity.SysDept;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.common.utils.http.HttpUtils;
|
import com.ruoyi.common.utils.http.HttpUtils;
|
||||||
import com.ruoyi.system.domain.EcologyDept;
|
import com.ruoyi.system.domain.EcologyDept;
|
||||||
import com.ruoyi.system.mapper.SysDeptMapper;
|
import com.ruoyi.system.mapper.SysDeptMapper;
|
||||||
|
|
@ -14,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -65,6 +67,39 @@ public class GetEcologyInfoTestController extends BaseController {
|
||||||
return map;
|
return map;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
public SysDept insertEcologyDept(EcologyDept ecologyDept){
|
||||||
|
SysDept dept=new SysDept();
|
||||||
|
dept.setDeptId(Long.parseLong(ecologyDept.getId()));
|
||||||
|
dept.setParentId(Long.parseLong(ecologyDept.getSupdepid()) == 0 ? 999999 : Long.parseLong(ecologyDept.getSupdepid()));
|
||||||
|
dept.setDeptName(ecologyDept.getDepartmentname());
|
||||||
|
//dept.setAncestors(pAncestors);
|
||||||
|
dept.setOrderNum("0");
|
||||||
|
dept.setStatus("0");
|
||||||
|
dept.setCreateBy("Admin");
|
||||||
|
deptMapper.insertDept(dept);
|
||||||
|
return dept;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateAncestors(List<SysDept> sysDeptList)
|
||||||
|
{
|
||||||
|
if(sysDeptList.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<SysDept> list =new ArrayList<>();
|
||||||
|
for(SysDept dept:sysDeptList){
|
||||||
|
SysDept info = deptMapper.selectDeptById(dept.getParentId());
|
||||||
|
if(StringUtils.isNotEmpty(info.getAncestors())) {
|
||||||
|
dept.setAncestors(info.getAncestors()+","+dept.getParentId());
|
||||||
|
deptMapper.updateDept(dept);
|
||||||
|
}else{
|
||||||
|
list.add(dept);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateAncestors(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String deptSync(Map<String,String> mapResult){
|
public String deptSync(Map<String,String> mapResult){
|
||||||
//如果接口返回状态码不为200,则不做同步处理
|
//如果接口返回状态码不为200,则不做同步处理
|
||||||
|
|
@ -79,31 +114,26 @@ public class GetEcologyInfoTestController extends BaseController {
|
||||||
Map<String,Object> o= (Map<String, Object>) map.get("data");
|
Map<String,Object> o= (Map<String, Object>) map.get("data");
|
||||||
JSONArray json = (JSONArray) o.get("dataList");
|
JSONArray json = (JSONArray) o.get("dataList");
|
||||||
List<EcologyDept> depts = JSONArray.parseArray(json.toJSONString(), EcologyDept.class);
|
List<EcologyDept> depts = JSONArray.parseArray(json.toJSONString(), EcologyDept.class);
|
||||||
//清空部门表
|
|
||||||
|
//清空部门表,并插入顶级部门
|
||||||
|
SysDept sysDept=deptMapper.selectDeptById(Long.parseLong("999999"));
|
||||||
deptMapper.truncateDept();
|
deptMapper.truncateDept();
|
||||||
//插入最顶层部门
|
deptMapper.insertDept(sysDept);
|
||||||
SysDept dept =new SysDept();
|
List<SysDept> list=new ArrayList<>();
|
||||||
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部门信息
|
//同步Ecology部门信息
|
||||||
for(EcologyDept ecologyDept:depts){
|
for(EcologyDept ecologyDept:depts){
|
||||||
//System.out.println(ecologyDept.getDepartmentname());
|
|
||||||
//String subCompanyid=ecologyDept.getSubcompanyid1();
|
|
||||||
if(ecologyDept.getSubcompanyid1().equals("1")) { //只取分部ID为“1”的部门,排除代理商
|
if(ecologyDept.getSubcompanyid1().equals("1")) { //只取分部ID为“1”的部门,排除代理商
|
||||||
dept.setDeptId(Long.parseLong(ecologyDept.getId()));
|
/* String pAncestors=null;
|
||||||
dept.setParentId(Long.parseLong(ecologyDept.getSupdepid()) == 0 ? 999999 : Long.parseLong(ecologyDept.getSupdepid()));
|
if(ecologyDept.getSupdepid().equals("0")){ //如果Ecology部门为一级部门,则设定ancestors="0,999999"
|
||||||
dept.setDeptName(ecologyDept.getDepartmentname());
|
pAncestors="0,999999";
|
||||||
dept.setOrderNum("0");
|
}*/
|
||||||
dept.setStatus("0");
|
SysDept dept= insertEcologyDept(ecologyDept);
|
||||||
dept.setCreateBy("Admin");
|
list.add(dept);
|
||||||
deptMapper.insertDept(dept);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//更新祖级信息
|
||||||
|
updateAncestors(list);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -323,28 +323,7 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
public int syncEcologyDept(String url,String params) {
|
public int syncEcologyDept(String url,String params) {
|
||||||
int result= deptSync(HttpUtils.sendPostWithRest(url,params));
|
int result= deptSync(HttpUtils.sendPostWithRest(url,params));
|
||||||
return result;
|
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){
|
public int deptSync(Map<String,String> mapResult){
|
||||||
//如果接口返回状态码不为200,则不做同步处理
|
//如果接口返回状态码不为200,则不做同步处理
|
||||||
|
|
@ -352,7 +331,6 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
String result= mapResult.get("result");
|
String result= mapResult.get("result");
|
||||||
if(!statusCode.equals("200"))
|
if(!statusCode.equals("200"))
|
||||||
{
|
{
|
||||||
//return mapResult.get("result");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//取Ecology返回信息中的部门信息
|
//取Ecology返回信息中的部门信息
|
||||||
|
|
@ -360,32 +338,57 @@ public class SysDeptServiceImpl implements ISysDeptService
|
||||||
Map<String,Object> o= (Map<String, Object>) map.get("data");
|
Map<String,Object> o= (Map<String, Object>) map.get("data");
|
||||||
JSONArray json = (JSONArray) o.get("dataList");
|
JSONArray json = (JSONArray) o.get("dataList");
|
||||||
List<EcologyDept> depts = JSONArray.parseArray(json.toJSONString(), EcologyDept.class);
|
List<EcologyDept> depts = JSONArray.parseArray(json.toJSONString(), EcologyDept.class);
|
||||||
//清空部门表
|
//清空部门表,并插入顶级部门
|
||||||
|
SysDept sysDept=deptMapper.selectDeptById(Long.parseLong("999999"));
|
||||||
deptMapper.truncateDept();
|
deptMapper.truncateDept();
|
||||||
//插入最顶层部门
|
deptMapper.insertDept(sysDept);
|
||||||
SysDept dept =new SysDept();
|
List<SysDept> list=new ArrayList<>();
|
||||||
dept.setDeptId(Long.parseLong("999999"));
|
//同步Ecology部门信息
|
||||||
dept.setParentId(Long.parseLong("0"));
|
for(EcologyDept ecologyDept:depts){
|
||||||
dept.setDeptName("BPS");
|
if(ecologyDept.getSubcompanyid1().equals("1")) { //只取分部ID为“1”的部门,排除代理商
|
||||||
|
SysDept dept= insertEcologyDept(ecologyDept);
|
||||||
|
list.add(dept);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//更新祖级列表信息
|
||||||
|
updateAncestors(list);
|
||||||
|
|
||||||
|
return 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
//将Ecology部门转化为系统部门,并更新到部门表sys_dept
|
||||||
|
public SysDept insertEcologyDept(EcologyDept ecologyDept){
|
||||||
|
SysDept dept=new SysDept();
|
||||||
|
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.setOrderNum("0");
|
||||||
dept.setStatus("0");
|
dept.setStatus("0");
|
||||||
dept.setCreateBy("Admin");
|
dept.setCreateBy("Admin");
|
||||||
deptMapper.insertDept(dept);
|
deptMapper.insertDept(dept);
|
||||||
//同步Ecology部门信息
|
return dept;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//更新祖级列表信息
|
||||||
|
public void updateAncestors(List<SysDept> sysDeptList)
|
||||||
|
{
|
||||||
|
if(sysDeptList.isEmpty())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<SysDept> list =new ArrayList<>();
|
||||||
|
for(SysDept dept:sysDeptList){
|
||||||
|
SysDept info = deptMapper.selectDeptById(dept.getParentId());
|
||||||
|
if(StringUtils.isNotEmpty(info.getAncestors())) {
|
||||||
|
dept.setAncestors(info.getAncestors()+","+dept.getParentId());
|
||||||
|
deptMapper.updateDept(dept);
|
||||||
|
}else{
|
||||||
|
list.add(dept);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateAncestors(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue