基于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 ...
随机推荐
- ubuntu12.04下编译安装x86平台qt库qt-everywhere-opensource-src-4.8.5
本文记录PC(x86)下安装Linux/X11版Qt 开发环境.下载页面:http://qt-project.org/downloads ARM嵌入式版本qt库的编译安装详见<unbunt12. ...
- ASP.NET Core 路由 - ASP.NET Core 基础教程 - 简单教程,简单编程
原文:ASP.NET Core 路由 - ASP.NET Core 基础教程 - 简单教程,简单编程 ASP.NET Core 路由 前两章节中,我们提到 ASP.NET Core 支持 MVC 开发 ...
- Qt on Android 资源文件系统qrc与assets
使用 Qt 为 Android 开发应用时,有时我们的应用会携带一些资源文件,如 png . jpg 等,也可能有一些配置文件,如 xml 等,这些文件放在哪里呢?有两种方式:qrc和assets,咱 ...
- 图像金字塔(pyramid)与 SIFT 图像特征提取(feature extractor)
David Lowe(SIFT 的提出者) 0. 图像金字塔变换(matlab) matlab 对图像金字塔变换接口的支持(impyramid),十分简单好用. 其支持在reduce和expand两种 ...
- svm资料收集
向量点乘(内积)和叉乘(外积.向量积)概念及几何意义解读: https://blog.csdn.net/dcrmg/article/details/52416832 三角形余弦定理:https://z ...
- .net 模拟发起HTTP请求(用于上传文件)
用C#在服务端发起http请求,附上代码一 /// <summary> /// 文件帮助类 /// </summary> public class FileHelper { / ...
- ThreadPoolExecutor原理和使用
大家先从ThreadPoolExecutor的整体流程入手: 针对ThreadPoolExecutor代码.我们来看下execute方法: public void execute(Runnable c ...
- 【Linux知识】server性能测试--UnixBench
链接地址: http://blog.csdn.net/jason_asia/article/details/38309079 1.1. server性能测试UnixBench 分别DELL R72 ...
- [WPF]有Focus(), 那Unfocus()呢?
原文:[WPF]有Focus(), 那Unfocus()呢? [WPF]有Focus(), 那Unfocus()呢? 周银辉 我们可以调用Focus()方法,让WPF控件获得焦点, 那我现在不想要焦点 ...
- MVC CRUD 的两种方法
//Index.cshtml @model IQueryable<MvcExam2.Models.Product>@{ Layout = null;}<!DOCTYPE htm ...