package com.changhong.epc.rely.api.tool;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
import com.changhong.epc.rely.api.bean.Organization;
|
import com.changhong.epc.rely.api.bean.Position;
|
import com.changhong.epc.rely.api.bean.User;
|
import com.changhong.epc.rely.api.bean.WFParticipantEntity;
|
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
|
|
/**
|
* 格式化组织机构数据工具
|
* @author liush
|
*
|
*/
|
public class OrganizationFormat {
|
|
/**
|
* 组织机构接口返回格式
|
* 整理成
|
* 普元参与者格式
|
* @param organization
|
* @param participantList
|
*/
|
public static void format(List<Organization> organizationList, List<WFParticipantEntity> participantList){
|
if(ObjectUtil.empty(organizationList) || participantList == null) { return; }
|
organizationList.stream().forEach(org->{
|
WFParticipantEntity orgP = getOrg(org);
|
/* 添加部门 */
|
setChildOrg(orgP, org.getChildren());
|
/* 添加角色 */
|
setChildJob(orgP, org.getPositions());
|
/* 添加员工 */
|
participantList.add(orgP);
|
});
|
}
|
|
/**
|
* 获取组织机构下所有用户
|
* @param organizationList
|
* @param users
|
*/
|
public static void getAllUsers(List<Organization> organizationList, List<WFParticipantEntity> users){
|
if(ObjectUtil.empty(organizationList) || users == null) { return; }
|
organizationList.stream().forEach(org->{
|
/* 添加部门 */
|
getAllUsers(org.getChildren(), users);
|
//获取所有用户
|
setChildUser(users, org.getUsers());
|
|
});
|
}
|
|
/**
|
* 获取组织机构下所有机构
|
* @param organizationList
|
* @param orgs
|
*/
|
public static void getAllOrgs(List<Organization> organizationList, List<WFParticipantEntity> orgs) {
|
if(ObjectUtil.empty(organizationList) || orgs == null) { return; }
|
organizationList.stream().forEach(org->{
|
getAllOrgs(org.getChildren(), orgs);
|
setChildOrg(orgs, org.getChildren());
|
});
|
}
|
|
|
/**
|
* 添加子角色
|
* @param orgP
|
* @param positions
|
*/
|
public static void setChildJob(WFParticipantEntity orgP, List<Position> positions) {
|
if(ObjectUtil.empty(positions)) { return; }
|
positions.stream().forEach(job->{
|
WFParticipantEntity jobP = getJob(job,orgP);
|
/* 添加员工 */
|
setChildUser(jobP, job.getUsers());
|
/* 添加到机构中 */
|
getChildParticipant(orgP).add(jobP);
|
});
|
}
|
|
/**
|
* 添加子员工
|
* @param orgP
|
* @param users
|
*/
|
public static void setChildUser(WFParticipantEntity orgP, List<User> users) {
|
if(ObjectUtil.empty(users)) { return; }
|
/* 添加到机构中 */
|
users.stream().forEach(user->getChildParticipant(orgP).add(getUser(user,orgP)));
|
}
|
|
public static void setChildUser(List<WFParticipantEntity> users, List<User> users2) {
|
if(ObjectUtil.empty(users2)) { return; }
|
/* 添加到机构中 */
|
users2.stream().forEach(user->users.add(getUser(user, null)));
|
}
|
|
/**
|
* 添加子部门
|
* @param orgP
|
* @param organizationList
|
*/
|
public static void setChildOrg(WFParticipantEntity orgP, List<Organization> organizationList){
|
List<WFParticipantEntity> childOrgP = new ArrayList<>();
|
format(organizationList, childOrgP);
|
/* 添加到机构中 */
|
getChildParticipant(orgP).addAll(childOrgP);
|
}
|
|
public static void setChildOrg(List<WFParticipantEntity> orgs, List<Organization> organizationList){
|
if(ObjectUtil.empty(organizationList)) { return; }
|
/* 添加到机构中 */
|
organizationList.stream().forEach(org->orgs.add(getOrg(org)));
|
}
|
|
/**
|
* 获得组织机构参与者
|
* @param organization
|
* @return
|
*/
|
public static WFParticipantEntity getOrg(Organization organization){
|
return new WFParticipantEntity(organization.getId(), "org",organization.getId(), organization.getName(),organization.getParentId(), organization.getCode(), null);
|
}
|
|
|
public static WFParticipantEntity getOrg(Organization organization, WFParticipantEntity orgP){
|
if(ObjectUtil.empty(orgP)){
|
return new WFParticipantEntity(organization.getId(), "org",organization.getId(), organization.getName(),organization.getParentId(), organization.getCode(), null);
|
}
|
return new WFParticipantEntity(organization.getId(), "org", organization.getId(), organization.getName(), organization.getParentId(), organization.getCode(), orgP.getParentCode());
|
}
|
|
/**
|
* 获得员工参与者
|
* @param user
|
* @return
|
*/
|
public static WFParticipantEntity getUser(User user, WFParticipantEntity orgP){
|
if(ObjectUtil.empty(orgP)){
|
return new WFParticipantEntity(user.getId(), "emp", user.getId(), user.getUserName(), user.getEmail(), user.getPhone(), user.getOpenId(), null);
|
}
|
return new WFParticipantEntity(user.getId(), "emp", user.getId(), user.getUserName(), user.getEmail(), user.getPhone(), user.getOpenId(), orgP.getId());
|
}
|
|
/**
|
* 获得角色参与者
|
* @param position
|
* @return
|
*/
|
public static WFParticipantEntity getJob(Position position, WFParticipantEntity orgP){
|
return new WFParticipantEntity(position.getId(), "role", position.getId(), position.getName(),orgP.getId(), orgP.getCode(), null);
|
}
|
|
/**
|
* 获得子参与者
|
* @param participant
|
* @return
|
*/
|
private static List<WFParticipantEntity> getChildParticipant(WFParticipantEntity participant){
|
if(participant.getChildren() == null){
|
participant.setChildren(new ArrayList<>());
|
}
|
return participant.getChildren();
|
}
|
|
|
/**
|
* 获取父机构code)
|
* @param organizationList
|
* @param orgs
|
*/
|
public static void getParentCode(List<Organization> organizationList, List<WFParticipantEntity> orgs) {
|
if(ObjectUtil.empty(organizationList) || orgs == null) { return; }
|
organizationList.stream().forEach(org->{
|
getParentCode(org.getChildren(), orgs);
|
orgs.stream().forEach(o->{
|
getParentCodeById(o, org);
|
});
|
});
|
}
|
|
/**
|
* 获取父机构code(依据当前的parentId)
|
* @param participant
|
* @param org
|
*/
|
private static void getParentCodeById(WFParticipantEntity participant, Organization org){
|
if(participant.getParentId().equals(org.getId())){
|
participant.setParentCode(org.getCode());
|
} else {
|
return;
|
}
|
}
|
|
|
}
|