基于List数组转换成tree对象
package com.shjysoft.yunxi.sync.webservice;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.xml.bind.JAXBElement;
import org.junit.Test;
import org.springframework.stereotype.Service;
import com.shjysoft.base.util.common.StringUtil;
import com.shjysoft.yunxi.person.entity.PersonSeal;
import com.shjysoft.yunxi.sync.TreeDepartment;
import com.shjysoft.yunxi.sync.webservice.EC_OA.entity.ArrayOfDepartmentBean;
import com.shjysoft.yunxi.sync.webservice.EC_OA.entity.ArrayOfSubCompanyBean;
import com.shjysoft.yunxi.sync.webservice.EC_OA.entity.ArrayOfUserBean;
import com.shjysoft.yunxi.sync.webservice.EC_OA.entity.DepartmentBean;
import com.shjysoft.yunxi.sync.webservice.EC_OA.entity.HrmService;
import com.shjysoft.yunxi.sync.webservice.EC_OA.entity.HrmServicePortType;
import com.shjysoft.yunxi.sync.webservice.EC_OA.entity.SubCompanyBean;
import com.shjysoft.yunxi.sync.webservice.EC_OA.entity.UserBean;
@Service
public class WebserviceUtil {
public static String ip = "http://192.168.8.100";
public static String BASE = "0";
/**
* 测试同步
*/
@Test
public void SynTimingFromOASubCompany(){
HrmService hrmService = new HrmService();
HrmServicePortType hrmServicePortType =hrmService.getHrmServiceHttpPort();
ArrayOfSubCompanyBean arrayOfSubCompanyBean= hrmServicePortType.getHrmSubcompanyInfo(ip);
if(arrayOfSubCompanyBean!=null){
List<SubCompanyBean> subCompanyBeanList = arrayOfSubCompanyBean.getSubCompanyBean();
WebserviceUtil wsutil = new WebserviceUtil();
TreeDepartment treeDepartment = wsutil.builderLdapDepartment(subCompanyBeanList, BASE);
System.out.println("xxx");
}
}
/**
* 同步组织架构
* @param subCompanyBeanList
* @param base
* @return
*/
public TreeDepartment builderLdapDepartment(List<SubCompanyBean> subCompanyBeanList,String base){
TreeDepartment treeDepartment = new TreeDepartment();
//treeDepartment.setName(base);//祖先的名字必须为""
treeDepartment.setName("");
if(subCompanyBeanList == null || subCompanyBeanList.size() == 0) return treeDepartment;
builderDepartment(subCompanyBeanList,base,treeDepartment);
return treeDepartment;
}
public void builderDepartment(List<SubCompanyBean> subCompanyBeanList,String base,TreeDepartment parentTreeDepartment){
boolean hasChiled = findSubDepartment(subCompanyBeanList,base,parentTreeDepartment);
if(!hasChiled) return;
List<TreeDepartment> subTreeDepartmentList = parentTreeDepartment.getSubTreeDepartment();
for(TreeDepartment treeDepartment:subTreeDepartmentList){
builderDepartment(subCompanyBeanList,treeDepartment.getWeb_id(),treeDepartment);
}
}
public boolean findSubDepartment(List<SubCompanyBean> subCompanyBeanList,String base,TreeDepartment parentTreeDepartment){
List<TreeDepartment> subTreeDepartmentList = parentTreeDepartment.getSubTreeDepartment();
boolean hasChiled = false;
for(SubCompanyBean subCompanyBean:subCompanyBeanList){
JAXBElement<String> supsubcompanyidJAXBElement = subCompanyBean.getSupsubcompanyid(); //上级分部id
String parentId = supsubcompanyidJAXBElement.getValue();
JAXBElement<String> canceledJAXBElement = subCompanyBean.getCanceled(); //是否封存(0和null表示是正常,1:表示封存)
String canceled = canceledJAXBElement.getValue();
String code = subCompanyBean.getCode().getValue();
//if(canceled != null && "1".equals(canceled)) continue;
if(base.equals(parentId)){
if(!hasChiled){
if(subTreeDepartmentList == null){
subTreeDepartmentList = new ArrayList<TreeDepartment>();
parentTreeDepartment.setSubTreeDepartment(subTreeDepartmentList);
}
}
TreeDepartment subTreeDepartment = new TreeDepartment();
subTreeDepartment.setWeb_id(subCompanyBean.getSubcompanyid().getValue());
subTreeDepartment.setName(subCompanyBean.getFullname().getValue());
//停用
if(canceled != null && "1".equals(canceled)){
subTreeDepartment.setEnableOrDisable(true);
}
//添加编码
subTreeDepartment.setCode("S"+subCompanyBean.getSubcompanyid().getValue());
subTreeDepartmentList.add(subTreeDepartment);
//查询部门并添加
HrmService hrmService = new HrmService();
HrmServicePortType hrmServicePortType =hrmService.getHrmServiceHttpPort();
ArrayOfDepartmentBean arrayOfDepartmentBean= hrmServicePortType.getHrmDepartmentInfo(ip,subTreeDepartment.getWeb_id());
if(arrayOfDepartmentBean!=null&&StringUtil.isNotNullOrBlank(arrayOfDepartmentBean)){
List<DepartmentBean> departmentBeanList = arrayOfDepartmentBean.getDepartmentBean();
if(departmentBeanList!=null&&departmentBeanList.size()>0){
builderDepartment_dept(departmentBeanList,subTreeDepartment.getWeb_id(),subTreeDepartment);
}
}
hasChiled = true;
}
}
return hasChiled;
}
public void builderDepartment_dept(List<DepartmentBean> departmentBeanList,String base,TreeDepartment parentTreeDepartment){
boolean hasChiled = findSubDepartment_dept(departmentBeanList,base,parentTreeDepartment);
if(!hasChiled) return;
List<TreeDepartment> subTreeDepartmentList = parentTreeDepartment.getSubTreeDepartment();
for(TreeDepartment treeDepartment:subTreeDepartmentList){
builderDepartment_dept(departmentBeanList,treeDepartment.getWeb_id(),treeDepartment);
}
}
public boolean findSubDepartment_dept(List<DepartmentBean> departmentBeanList,String base,TreeDepartment parentTreeDepartment){
List<TreeDepartment> subTreeDepartmentList = parentTreeDepartment.getSubTreeDepartment();
boolean hasChiled = false;
for(DepartmentBean departmentBean:departmentBeanList){
//分部id
JAXBElement<String> subcompanyidJAXBElement = departmentBean.getSubcompanyid();
String subId = subcompanyidJAXBElement.getValue();
//上级分部id
JAXBElement<String> departJAXBElement = departmentBean.getSupdepartmentid();
String parentId = departJAXBElement.getValue();
if(StringUtil.isNotNullOrBlank(parentId)&&parentId.equals("0")){
parentId = subId;
}
JAXBElement<String> canceledJAXBElement = departmentBean.getCanceled(); //是否封存(0和null表示是正常,1:表示封存)
String canceled = canceledJAXBElement.getValue();
//编码
String code = departmentBean.getCode().getValue();
//if(canceled != null && "1".equals(canceled)) continue;
if(base.equals(parentId)){
if(!hasChiled){
if(subTreeDepartmentList == null){
subTreeDepartmentList = new ArrayList<TreeDepartment>();
parentTreeDepartment.setSubTreeDepartment(subTreeDepartmentList);
}
}
TreeDepartment subTreeDepartment = new TreeDepartment();
subTreeDepartment.setWeb_id(departmentBean.getDepartmentid().getValue());
subTreeDepartment.setName(departmentBean.getFullname().getValue());
if(canceled != null && "1".equals(canceled)){
subTreeDepartment.setEnableOrDisable(true);//停用
}
//添加编码
subTreeDepartment.setCode("D"+departmentBean.getDepartmentid().getValue());
subTreeDepartmentList.add(subTreeDepartment);
//根据部门添加人员
List<PersonSeal> personList = getPersonList(departmentBean.getDepartmentid().getValue());
subTreeDepartment.setPersons(personList);
hasChiled = true;
}
}
return hasChiled;
}
/**
* 根据分部和部门id同步人员
* @return
*/
public static List<PersonSeal> getPersonList(String departmentid){
List<PersonSeal> personList = new ArrayList<PersonSeal>();
HrmService hrmService = new HrmService();
HrmServicePortType hrmServicePortType =hrmService.getHrmServiceHttpPort();
ArrayOfUserBean arrayOfUserBean= hrmServicePortType.getHrmUserInfo(ip,"", "", departmentid, "", "");
if(arrayOfUserBean!=null){
List<UserBean> userBeanList = arrayOfUserBean.getUserBean();
if(userBeanList!=null&&userBeanList.size()>0){
for (UserBean userBean : userBeanList) {
//获取人员唯一标识
String uid = userBean.getLoginid().getValue();
if(StringUtil.isNullOrBlank(uid)) continue;
PersonSeal personSeal = new PersonSeal();
//人员名称
JAXBElement<String> lastnameElement= userBean.getLastname();
String name = lastnameElement.getValue();
//手机号码
JAXBElement<String> mobileElement= userBean.getMobile();
String mobile = mobileElement.getValue();
//职位
JAXBElement<String> jobtitleElement= userBean.getJobtitle();
String jobtitle = jobtitleElement.getValue();
//编号
JAXBElement<String> workcodeElement= userBean.getWorkcode();
String workcode = workcodeElement.getValue();
//邮箱
JAXBElement<String> emailElement= userBean.getEmail();
String email = emailElement.getValue();
//判断人员状态
String status = userBean.getStatus().getValue();
//状态,0:试用、1:正式、2:临时、3:试用延期、4:解聘、5:离职、6:退休、7:无效
if(status.equals("4")||status.equals("5")||status.equals("6")||status.equals("7")){
personSeal.setIs_enable(false);//同步为停用
}
personSeal.setPassword("88888888");
personSeal.setCreate_time(new Date());
personSeal.setUpdate_time(new Date());
personSeal.setMobile(mobile);
personSeal.setName(name);
personSeal.setPosition(jobtitle);
personSeal.setMail_address(email);
personSeal.setCode(userBean.getLoginid().getValue());
personList.add(personSeal);
}
}
}
return personList;
}
}
基于List数组转换成tree对象的更多相关文章
- js 一维数组转成tree 对象
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 如何将PHP对象数组转换成普通数组
/** * 对象数组转为普通数组 * * AJAX提交到后台的JSON字串经decode解码后为一个对象数组, * 为此必须转为普通数组后才能进行后续处理, * 此函数支持多维数组处理. * * @p ...
- LeetCode OJ:Convert Sorted Array to Binary Search Tree(将排序好的数组转换成二叉搜索树)
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 讲一 ...
- JavaScript 系列--JavaScript一些奇淫技巧的实现方法(二)数字格式化 1234567890转1,234,567,890;argruments 对象(类数组)转换成数组
一.前言 之前写了一篇文章:JavaScript 系列--JavaScript一些奇淫技巧的实现方法(一)简短的sleep函数,获取时间戳 https://www.mwcxs.top/page/746 ...
- js 中 json.stringfy()将对象、数组转换成字符串
json.stringfy()将对象.数组转换成字符串 var student = new Object(); student.name = "Lanny"; student.ag ...
- JSON-JSON字符串转换成JSON对象、JSON对象数组、java实体类以及保存到List列表中
处理JSON字符串时,一直出错,写个样例后发现原来是没有弄清楚数据的格式问题. 实现的是 JSONString 转换成java对象 或是 list列表 实例类 News package lyx.ent ...
- PHP 把返回的数据集转换成Tree树
/** * 把返回的数据集转换成Tree * @access public * @param array $list 要转换的数据集 * @param string $pid parent标记字段 * ...
- 100怎么变成100.00 || undefined在数字环境下是:NaN || null在数字环境下是0 || 数组的toString()方法把每个元素变成字符串,拼在一起以逗号隔开 || 空数组转换成字符串后是什么?
100怎么变成100.00?
- $.toJSON的用法或把数组转换成json类型
1. html页面全部代码 <html> <head> <title></title> <script src="../../S ...
随机推荐
- 使用Python破解验证码
Keywords: python captcha Most people don’t know this but my honours thesis was about using a compute ...
- 使用devcpp在windowXP上qt4.4.3安装与使用入门
1.安装前先安装devcpp,我下载的是devcpp-4.9.9.2_setup.exe2.安装qt4.4.3,下载的是qt-win-opensource-4.4.3-mingw.rar,解压后运行后 ...
- EPI_H/EPI_V(边缘保持指数,matlab 矢量化编程)
EPI: edge preservation index,衡量对原始图像的操作(目标图像)对图像边缘的保持能力. EPI_H:horizontal ,水平方向: EPI_V:vertical,垂直方向 ...
- 【书单】matlab 科学计算、数值分析以及数学物理问题
1. 数学计算 MATLAB数值计算 MATLAB之父 : 编程实践 2. 数学物理问题 高等应用数学问题的MATLAB求解(第3版)(豆瓣评价极好) 3. 模式识别
- WPF响应长按事件
原文:WPF响应长按事件 版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/lwwl12/article/details/78983140 思路:MouseD ...
- String关于BeanFactory与ApplicationContext的简单区别
1.创建的方式不同 ApplicationContext: ApplicationContext context = new ClassPathXmlApplicationContext(" ...
- SharePoint 2010 WebPart Web部分 总的膏
SharePoint 2010 WebPart Web部分 总的膏 之前写SharePoint WebPart Web部分相关的博客,我们没有做一个索引.网友在查看的时候非常不方便,于 ...
- wpf 触摸屏 button 背景为null的 问题
原文:wpf 触摸屏 button 背景为null的 问题 <!-- button样式--> <Style x:Key="myBtn" TargetType=&q ...
- 疯狂的图形(利用C# + GDI plus模拟杂乱无章的现实场景)
原文:疯狂的图形(利用C# + GDI plus模拟杂乱无章的现实场景) 本文给出了模拟竹叶.长叶草.杂乱石头.天上繁星等关键代码.使用.Net环境下C#语言,GDI+编写. 模拟竹叶 挺像的吧? ...
- MVC 添加数据的三种方法
1 通过Request接收数据,进行添加 <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<d ...