package com.product.org.admin.service; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.NumberUtil; import com.google.common.collect.Lists; import com.google.common.collect.Sets; import com.product.admin.service.OrganizationCacheService; import com.product.common.lang.StringUtils; import com.product.core.cache.DataPoolCacheImpl; import com.product.core.cache.util.RedisUtil; import com.product.core.entity.DataTableEntity; import com.product.core.entity.FieldSetEntity; import com.product.core.exception.BaseException; import com.product.core.spring.context.SpringMVCContextHolder; import com.product.module.sys.entity.SystemUser; import com.product.org.admin.config.CmnConst; import com.product.org.admin.entity.OrganizationEntity; import com.product.org.admin.service.idel.IOrganizationService; import com.product.util.BaseUtil; import org.springframework.stereotype.Service; import java.util.*; import java.util.stream.Collectors; /** * @Author cheng * @Date 2022/3/29 14:02 * @Desc 组织机构 */ @Service public class OrganizationServiceV2 extends OrganizationCacheService implements IOrganizationService { public void cacheOrganization() { this.cacheOrganization(null); } public void cachePost() { this.cachePost(null); } public void cacheStaff() { this.cacheStaff(null); } /** * 分解多种类型的值 * * @param values 多种类型的值 多个逗号分隔 列: [xxx~uuid],(xxx~user_id),{xxx_post_uuid} * @return 返回二维数组 * 第一个维度:固定长度 4 ,下标0 代表公司 下标1 代表部门 下标 2 代表岗位 下标 3 代表 用户 ,可能为空 * 第二个维度: 长度未知,返回一维数组中对应含义的 值,可能为空 * @auth cheng * @date 2022年4月20日18:21:09 */ public String[][] decomposesMultipleTypeValues(String values) { String[][] typeValues = new String[3][]; if (StringUtils.isEmpty(values)) { return typeValues; } String[] value = values.split(","); for (String val : value) { if (val.length() <= 2) { continue; } String actualValue = val.substring(1, val.length() - 1); int index = -1; if (val.startsWith("[") && val.endsWith("]")) { //机构 Map orgCacheByUuid = this.getOrgCacheByUuid(actualValue); if (orgCacheByUuid != null) { Object org_level_type = orgCacheByUuid.get(CmnConst.ORG_LEVEL_TYPE); if (org_level_type != null) { index = NumberUtil.parseInt(org_level_type.toString()); } } } else if (val.startsWith("{") && val.endsWith("}")) { //岗位 index = 2; } else if (val.startsWith("(") && val.endsWith(")")) { //人员 index = 3; } else { continue; } if (index == -1) { continue; } if (typeValues[index] == null) { typeValues[index] = new String[1]; } else { Arrays.copyOf(typeValues[index], typeValues[index].length + 1); } typeValues[index][typeValues[index].length - 1] = actualValue; } return typeValues; } public static void main(String[] args) { String[] a = new String[1]; System.out.println(a.length); } /** * 获取所有的人员 * * @param organizationArr 组织架构信息,数据来源为decomposesMultipleTypeValues方法的返回 * @return */ public Set getAllUsers(String[][] organizationArr) { Set userSet = Sets.newHashSet(); // 单位 DataTableEntity dte; FieldSetEntity fse; String[] unitArr = organizationArr[0]; if (unitArr != null) { StringBuilder sql = new StringBuilder(128); sql.append("select user_id from product_sys_staffs s"); sql.append("\ninner join product_sys_org_levels o on s.tricode like concat(o.org_level_code,'%')"); sql.append("\nwhere ").append(BaseUtil.buildQuestionMarkFilter("o.uuid", unitArr.length, true)); dte = getBaseDao().listTable(sql.toString(), unitArr); for (int i = 0; i < dte.getRows(); i++) { fse = dte.getFieldSetEntity(i); userSet.add(fse.getString("user_id")); } } // 岗位 String[] postArr = organizationArr[1]; if (postArr != null) { for (String uuid : postArr) { dte = getUserDataByPost(uuid); for (int i = 0; i < dte.getRows(); i++) { fse = dte.getFieldSetEntity(i); userSet.add(fse.getString("user_id")); } } } // 人员 String[] userArr = organizationArr[2]; if (userArr != null) { userSet.addAll(Arrays.asList(userArr)); } return userSet; } /** * 根据输入的值 搜索可以选择的类型 * * @param fse * @param allowDept * @param allowPost * @param userIds * @return */ protected Object getSearchValueResult(FieldSetEntity fse, String[] allowDept, String[] allowPost, String[] userIds) { String searchValue = fse.getString("~search_value~"); String allowType = fse.getString("~allow_type~"); if (StringUtils.isEmpty(searchValue) || StringUtils.isEmpty(allowType)) { return null; } String[] allowTypes = allowType.split(","); StringBuilder sql = new StringBuilder(); List params = new ArrayList<>(); for (String type : allowTypes) { if (sql.length() > 0) { sql.append("\n union all "); } if ("1".equals(type) || "2".equals(type)) { sql.append("\n select uuid `value`,org_level_name label,org_level_type+1 type from product_sys_org_levels where "); sql.append("\n org_level_status=0 and org_level_name like concat('%',?,'%') "); sql.append("\n and org_level_type=? "); if ("2".equals(type) && allowDept != null && allowDept.length > 0) { sql.append(" and ").append(BaseUtil.buildQuestionMarkFilter("uuid", allowDept, true)); } //搜索岗位名称 params.add(searchValue); params.add(Integer.valueOf(type) - 1); } else if ("3".equals(type)) { sql.append("\n select uuid `value`,job_post_name label,3 type from product_sys_job_posts where job_post_name like concat('%',?,'%') and is_used=1 "); //搜索岗位名称 params.add(searchValue); if (!ArrayUtil.isAllEmpty(allowDept, allowDept)) { sql.append(" and ( "); if (!ArrayUtil.isEmpty(allowPost)) { sql.append(" ").append(BaseUtil.buildQuestionMarkFilter("uuid", allowPost, true)); } if (!ArrayUtil.isEmpty(allowDept)) { sql.append(ArrayUtil.isEmpty(allowPost) ? "" : " or ").append(BaseUtil.buildQuestionMarkFilter("dept_uuid", allowDept, true)); } sql.append(" ) "); } } else if ("4".equals(type)) { sql.append("\n select staff.user_id `value`,show_name label,4 type from product_sys_staffs staff "); sql.append("\n join product_sys_users users on users.`status`=1 and users.user_id=staff.user_id and "); sql.append("\n (staff_code like concat('%',?,'%') or show_name like concat('%',?,'%')) "); if (!ArrayUtil.isAllEmpty(userIds, allowDept, allowPost)) { sql.append(" and ( "); boolean or = false; if (userIds != null && userIds.length > 0) { sql.append(" ").append(BaseUtil.buildQuestionMarkFilter("users.user_id", userIds, true)); or = true; } if (!ArrayUtil.isEmpty(allowDept)) { sql.append(or ? " or " : "").append(BaseUtil.buildQuestionMarkFilter("dept_uuid", allowDept, true)); or = true; } if (!ArrayUtil.isEmpty(allowPost)) { sql.append(or ? " or " : "").append(BaseUtil.buildQuestionMarkFilter("job_post_uuid", allowPost, true)); } sql.append(" ) "); } //搜索编码和用户名称 params.add(searchValue); params.add(searchValue); } } if (sql.length() == 0) { return null; } DataTableEntity dt = getBaseDao().listTable(sql.toString(), params.toArray()); return dt; } /** * 获取选中值的label * * @param value * @return * @throws BaseException */ protected Object getSelectedValueLabel(String value) throws BaseException { String[] values = value.split(","); Map result = new HashMap<>(); if (values != null && values.length > 0) { for (String val : values) { if (val.length() < 2) { continue; } //实际值 String actualValue = val.substring(1, val.length() - 1); String label = null; String bracket = val.substring(0, 1) + "*" + val.substring(val.length() - 1); if (StringUtils.equals("[*]", bracket)) { //公司 | 部门 Map o = (HashMap) RedisUtil.get(this.ORG_UUID_CACHE_KEY + actualValue); if (o != null && !o.isEmpty()) { label = (String) o.get(CmnConst.ORG_LEVEL_NAME); } } else if (StringUtils.equals("{*}", bracket)) { //岗位 Object o = RedisUtil.get(this.POST_UUID_CACHE_KEY + actualValue); if (o != null) { Object[] o1 = (Object[]) o; if (o1 != null && o1.length == 2) { label = (String) o1[0]; } } } else if (StringUtils.equals("(*)", bracket)) { //人员 FieldSetEntity user = BaseUtil.getSingleInfoByCache("用户缓存", new String[]{actualValue}); if (!FieldSetEntity.isEmpty(user) && !user.getBoolean("isManager")) { label = user.getString(CmnConst.USER_NAME); } } if (!StringUtils.isEmpty(label)) { result.put(val, label); } } } return result; } private Set[] getOrganizationFilter(String[] dept_uuid, String[] post_uuid, String[] userIds, int type) { Set allowDeptCode = null; Set allowPostUuid = null; Set retainOrgCode = dept_uuid != null ? Sets.newHashSet(Arrays.asList(dept_uuid)) : null; Set retainDPost = post_uuid != null ? Sets.newHashSet(Arrays.asList(post_uuid)) : null; if (type >= 4 && userIds != null && userIds.length > 0) { for (String userId : userIds) { FieldSetEntity user = BaseUtil.getSingleInfoByCache("用户缓存", new String[]{userId}); if (!FieldSetEntity.isEmpty(user)) { String dept = user.getString(CmnConst.DEPT_UUID); if (retainOrgCode == null) { retainOrgCode = Sets.newHashSet(); } retainOrgCode.add(dept); // if (retainDPost == null) { // retainDPost = Sets.newHashSet(); // } // retainDPost.add(user.getString("job_post_uuid")); } else { continue; } if (type != 3 && type != 4) { continue; } String post = user.getString("job_post_uuid"); if (!StringUtils.isEmpty(post)) { if (retainDPost == null) { retainDPost = Sets.newHashSet(); } retainDPost.add(post); } } } if (retainDPost != null && retainDPost.size() > 0) { for (String post : retainDPost) { if (StringUtils.isEmpty(post)) { continue; } Object o = RedisUtil.get(this.POST_UUID_CACHE_KEY + post); if (o != null) { Object[] o1 = (Object[]) o; if (o1 != null && o1.length == 2) { if (allowPostUuid == null) { allowPostUuid = Sets.newHashSet(); } allowPostUuid.add(post); String value = (String) o1[1]; if (retainOrgCode == null) { retainOrgCode = Sets.newHashSet(); } if (!retainOrgCode.contains(value)) { retainOrgCode.add(value); } } } } } if (retainOrgCode != null && retainOrgCode.size() > 0) { for (String dept : retainOrgCode) { if (StringUtils.isEmpty(dept)) { continue; } Map o = (HashMap) RedisUtil.get(this.ORG_UUID_CACHE_KEY + dept); if (o != null && !o.isEmpty()) { String org_level_code = (String) o.get(CmnConst.ORG_LEVEL_CODE); if (!StringUtils.isEmpty(org_level_code)) { String[] codes = org_level_code.split("-"); for (int i = codes.length - 1; i >= 0; i--) { String code = ""; for (int j = 0; j <= i; j++) { if (code.length() > 0) { code += '-'; } code += codes[j]; } if (code.length() > 0) { if (allowDeptCode == null) { allowDeptCode = new HashSet<>(); } allowDeptCode.add(code); } } } } } } return new Set[]{allowDeptCode, allowPostUuid}; } @Override public Object getOrganization(FieldSetEntity fse) throws BaseException { if (!StringUtils.isEmpty(fse.getString("~values~"))) { return getSelectedValueLabel(fse.getString("~values~")); } // 前端点击的类型 参考 组织机构类型 如果为空 0 = 客户下的公司(顶级) -1 返回所有 String current_type = BaseUtil.ifNull(fse.getString("current_type"), "-1"); //组织机构类型 1-公司,2-公司 - 部门,3-公司 - 部门 - 岗位,4-公司 - 部门 - 岗位 - 人员,5-公司 - 部门 - 人员 String organization_type = fse.getString("organization_type"); String[] post_uuids = null; if (!StringUtils.isEmpty(fse.getString("post_uuids"))) { post_uuids = fse.getString("post_uuids").split(","); } String[] dept_uuids = null; if (!StringUtils.isEmpty(fse.getString("dept_uuids"))) { dept_uuids = fse.getString("dept_uuids").split(","); } String[] user_ids = null; if (!StringUtils.isEmpty(fse.getString("user_ids"))) { user_ids = fse.getString("user_ids").split(","); } //当搜索值不为空时 if (!StringUtils.isEmpty(fse.getString("~search_value~"))) { return getSearchValueResult(fse, dept_uuids, post_uuids, user_ids); } SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); //用户类型 0 = 普通用户 1 = 超级管理员 2 单位管理员 int userType = currentUser.getUserType(); //所在客户 String clientUid = currentUser.getClientUuid(); List orgCache = getOrgCache(clientUid); if (orgCache == null) { return null; } FieldSetEntity topCompanyInfo = orgCache.get(0); topCompanyInfo.setValue(CmnConst.VALUE, topCompanyInfo.getString(CmnConst.UUID)); OrganizationService organizationService = new OrganizationService(topCompanyInfo, organization_type, post_uuids, dept_uuids, user_ids, userType, clientUid, currentUser, current_type); return organizationService.getOrganizationData(); } class OrganizationService { private FieldSetEntity topCompanyInfo; private String[] post_uuids; private String[] dept_uuids; private String[] user_ids; private int userType; private String currentType; private String organizationType; private String clientUid; private SystemUser currentUser; public OrganizationService(FieldSetEntity topCompanyInfo, String organizationType, String[] post_uuids, String[] dept_uuids, String[] user_ids, int userType, String clientUid, SystemUser currentUser, String currentType) { this.topCompanyInfo = topCompanyInfo; this.post_uuids = post_uuids; this.dept_uuids = dept_uuids; this.user_ids = user_ids; this.userType = userType; this.clientUid = clientUid; this.currentUser = currentUser; this.currentType = currentType; this.organizationType = organizationType; } public List getOrganizationData() { if (topCompanyInfo == null) { return null; } List orgData = getOrgData(this.topCompanyInfo.getString(CmnConst.ORG_LEVEL_CODE)); OrganizationEntity topEntity = this.orgToEntity(this.topCompanyInfo); if (CollectionUtil.isEmpty(orgData)) { return Lists.newArrayList(topEntity); } getChildren(topEntity); return Lists.newArrayList(topEntity); } private void getChildren(OrganizationEntity entity) { String code = entity.getCode(); // 1 公司 2 部门 3 岗位 4 人员 String type = entity.getType(); if (StringUtils.equalsAny(type, "1", "2")) { //公司、部门 List orgCache = getOrgData(code); if (CollectionUtil.isNotEmpty(orgCache)) { for (FieldSetEntity orgDatum : orgCache) { String t = orgDatum.getString("type"); if ("1".equals(this.organizationType) && !"1".equals(t)) { continue; } if (("1".equals(t) && !companyPermission(orgDatum.getString(CmnConst.UUID))) || ("2".equals(t) && !deptPermission(orgDatum.getString(CmnConst.UUID)))) { continue; } OrganizationEntity organizationEntity = orgToEntity(orgDatum); entity.addChildren(organizationEntity); this.getChildren(organizationEntity); if (organizationEntity.getChildren() != null && organizationEntity.getChildren().size() > 0) { organizationEntity.setChild(true); } } } } if ("2".equals(type) && StringUtils.equalsAny(this.organizationType, "3", "4")) { //岗位 DataTableEntity postDataByDept = getPostDataByDept(entity.getValue()); if (DataTableEntity.isEmpty(postDataByDept)) { return; } sort(postDataByDept.getData()); for (FieldSetEntity datum : postDataByDept.getData()) { if (!postPermission(datum.getString(CmnConst.UUID))) { continue; } OrganizationEntity organizationEntity = postToEntity(datum); entity.addChildren(organizationEntity); this.getChildren(organizationEntity); if (organizationEntity.getChildren() != null && organizationEntity.getChildren().size() > 0) { organizationEntity.setChild(true); } } } else if ("5".equals(this.organizationType) && "2".equals(type)) { //部门下的人员 List staffCacheByDept = getStaffCacheByDept(entity.getValue()); if (CollectionUtil.isEmpty(staffCacheByDept)) { return; } sort(staffCacheByDept); for (FieldSetEntity datum : staffCacheByDept) { if (!userPermission(datum.getString("user_id"))) { continue; } OrganizationEntity organizationEntity = staffToEntity(datum); entity.addChildren(organizationEntity); this.getChildren(organizationEntity); if (organizationEntity.getChildren() != null && organizationEntity.getChildren().size() > 0) { organizationEntity.setChild(true); } } } else if ("4".equals(this.organizationType) && "3".equals(type)) { List staffCacheByPost = getStaffCacheByPost(entity.getValue()); if (CollectionUtil.isEmpty(staffCacheByPost)) { return; } sort(staffCacheByPost); for (FieldSetEntity datum : staffCacheByPost) { if (!userPermission(datum.getString("user_id"))) { continue; } OrganizationEntity organizationEntity = staffToEntity(datum); entity.addChildren(organizationEntity); this.getChildren(organizationEntity); if (organizationEntity.getChildren() != null && organizationEntity.getChildren().size() > 0) { organizationEntity.setChild(true); } } } } private boolean userPermission(String userId) { if (!ArrayUtil.isEmpty(this.user_ids)) { for (String user : this.user_ids) { if (userId.equals(user)) { return true; } } } FieldSetEntity staffCacheByUserId = null; if ("4".equals(this.organizationType) && !ArrayUtil.isEmpty(this.post_uuids)) { String jobPostUuid = BaseUtil.ifNull(staffCacheByUserId, getStaffCacheByUserId(userId)).getString("job_post_uuid"); if (!StringUtils.isEmpty(jobPostUuid) && ArrayUtil.contains(this.post_uuids, jobPostUuid)) { return true; } } if (!ArrayUtil.isEmpty(this.dept_uuids)) { String deptUuid = BaseUtil.ifNull(staffCacheByUserId, getStaffCacheByUserId(userId)).getString("dept_uuid"); if (!StringUtils.isEmpty(deptUuid) && ArrayUtil.contains(this.dept_uuids, deptUuid)) { return true; } } if (ArrayUtil.isEmpty(this.post_uuids) && ArrayUtil.isEmpty(this.user_ids) && ArrayUtil.isEmpty(this.dept_uuids)) { return true; } return false; } private boolean postPermission(String postUid) { if (!ArrayUtil.isEmpty(this.post_uuids)) { for (String postUuid : this.post_uuids) { if (postUid.equals(postUuid)) { return true; } } } if (StringUtils.equalsAny(this.organizationType, "4") && !ArrayUtil.isEmpty(this.user_ids)) { for (String userId : this.user_ids) { FieldSetEntity staffCacheByUserId = getStaffCacheByUserId(userId); if (staffCacheByUserId != null && postUid.equals(staffCacheByUserId.getString("job_post_uuid"))) { return true; } } } if (!ArrayUtil.isEmpty(this.dept_uuids)) { for (String deptUuid : this.dept_uuids) { DataTableEntity postDataByDept = getPostDataByDept(deptUuid); if (postDataByDept != null) { for (int i = 0; i < postDataByDept.getRows(); i++) { String uuid = postDataByDept.getString(i, CmnConst.UUID); if (postUid.equals(uuid)) { return true; } } } } } if (ArrayUtil.isEmpty(this.post_uuids) && ArrayUtil.isEmpty(this.user_ids) && ArrayUtil.isEmpty(this.dept_uuids)) { return true; } return false; } private boolean deptPermission(String deptUid) { String uuid; if (!ArrayUtil.isEmpty(this.dept_uuids)) { for (String deptUuid : this.dept_uuids) { uuid = deptUuid; if (findDept(uuid, deptUid)) { return true; } } } if (StringUtils.equalsAny(this.organizationType, "3", "4") && !ArrayUtil.isEmpty(this.post_uuids)) { for (String postUuid : this.post_uuids) { Object[] postCacheByUUID = getPostCacheByUUID(postUuid); if (ArrayUtil.isEmpty(postCacheByUUID)) { continue; } String deptUuid = (String) postCacheByUUID[1]; uuid = deptUuid; if (findDept(uuid, deptUid)) { return true; } } } if (StringUtils.equalsAny(this.organizationType, "4", "5") && !ArrayUtil.isEmpty(this.user_ids)) { for (String userId : this.user_ids) { FieldSetEntity staffCacheByUserId = getStaffCacheByUserId(userId); if (staffCacheByUserId != null) { uuid = staffCacheByUserId.getString(CmnConst.DEPT_UUID); if (findDept(uuid, deptUid)) { return true; } } } } if (ArrayUtil.isEmpty(this.dept_uuids) && ArrayUtil.isEmpty(this.post_uuids) && ArrayUtil.isEmpty(this.user_ids)) { return true; } return false; } /** * 公司权限 * * @param companyUid * @return */ private boolean companyPermission(String companyUid) { String uuid; if ("1".equals(this.organizationType)) { return true; } if (!ArrayUtil.isEmpty(this.dept_uuids)) { for (String deptUuid : this.dept_uuids) { uuid = deptUuid; if (findCompany(uuid, companyUid)) { return true; } } } if (StringUtils.equalsAny(this.organizationType, "3", "4") && !ArrayUtil.isEmpty(this.post_uuids)) { for (String postUuid : this.post_uuids) { Object[] postCacheByUUID = getPostCacheByUUID(postUuid); if (ArrayUtil.isEmpty(postCacheByUUID)) { continue; } String deptUuid = (String) postCacheByUUID[1]; uuid = deptUuid; if (findCompany(uuid, companyUid)) { return true; } } } if (StringUtils.equalsAny(this.organizationType, "4", "5") && !ArrayUtil.isEmpty(this.user_ids)) { for (String userId : this.user_ids) { FieldSetEntity staffCacheByUserId = getStaffCacheByUserId(userId); if (staffCacheByUserId != null) { uuid = staffCacheByUserId.getString(CmnConst.ORG_LEVEL_UUID); if (findCompany(uuid, companyUid)) { return true; } } } } if (ArrayUtil.isEmpty(this.dept_uuids) && ArrayUtil.isEmpty(this.post_uuids) && ArrayUtil.isEmpty(this.user_ids)) { return true; } return false; } private boolean findDept(String startUid, String targetUid) { if (startUid.equals(targetUid)) { return true; } do { Map orgCacheByUuid = getOrgCacheByUuid(startUid); if (orgCacheByUuid != null) { String parentUuid = (String) orgCacheByUuid.get("parent_uuid"); String parentType = (String) orgCacheByUuid.get("parent_type"); if ("1".equals(parentType)) { return false; } if (targetUid.equals(parentUuid)) { return true; } startUid = parentUuid; } else { return false; } } while (true); } private boolean findCompany(String startUid, String targetUid) { do { Map orgCacheByUuid = getOrgCacheByUuid(startUid); if (orgCacheByUuid != null) { String parentUuid = (String) orgCacheByUuid.get("parent_uuid"); if (targetUid.equals(parentUuid)) { return true; } startUid = parentUuid; } else { return false; } } while (true); } /** * 获取组织机构数据 * * @param parentCode * @return */ private List getOrgData(String parentCode) { List orgCache = getOrgCache(parentCode); if (CollectionUtil.isNotEmpty(orgCache)) { List result = new ArrayList<>(); sort(orgCache); for (int i = 0; i < orgCache.size(); i++) { String type = orgCache.get(i).getString("type"); if (!"1".equals(type)) { result.add(orgCache.get(i)); orgCache.remove(i); i--; } } result.addAll(orgCache); return result; } return Collections.emptyList(); } private void sort(List data) { if (CollectionUtil.isEmpty(data)) { return; } data.sort(Comparator.comparing(a -> Optional.ofNullable(a.getInteger("sequence")).orElse(Integer.MAX_VALUE))); } private OrganizationEntity orgToEntity(FieldSetEntity fse) { OrganizationEntity entity = new OrganizationEntity(); entity.setValue(fse.getString(CmnConst.UUID)); entity.setName(fse.getString(CmnConst.ORG_LEVEL_NAME)); entity.setCode(fse.getString(CmnConst.ORG_LEVEL_CODE)); entity.setParentCode(fse.getString(CmnConst.ORG_LEVEL_CODE_PARENT)); entity.setOrganizationFullName(fse.getString("parent_org_level_all")); // entity.setSequence(fse.getInteger(CmnConst.SEQUENCE)); entity.setType(fse.getString("type")); entity.setChild(isChild(fse)); return entity; } private OrganizationEntity staffToEntity(FieldSetEntity fse) { OrganizationEntity entity = new OrganizationEntity(); entity.setValue(fse.getString(CmnConst.USER_ID)); entity.setName(fse.getString(CmnConst.USER_NAME)); entity.setOrganizationFullName(fse.getString(CmnConst.ORG_LEVEL_ALL)); // entity.setCode(fse.getString(CmnConst.ORG_LEVEL_CODE)); // entity.setParentCode(fse.getString(CmnConst.UUID)); // entity.setSequence(fse.getInteger(CmnConst.SEQUENCE)); entity.setType(fse.getString("type")); entity.setSex(fse.getString("sex")); entity.setChild(false); return entity; } private OrganizationEntity postToEntity(FieldSetEntity fse) { OrganizationEntity entity = new OrganizationEntity(); entity.setValue(fse.getString(CmnConst.UUID)); entity.setOrganizationFullName(fse.getString(CmnConst.ORG_LEVEL_ALL)); entity.setName(fse.getString("job_post_name")); // entity.setCode(fse.getString(CmnConst.ORG_LEVEL_CODE)); // entity.setParentCode(fse.getString(CmnConst.UUID)); // entity.setSequence(fse.getInteger(CmnConst.SEQUENCE)); entity.setType(fse.getString("type")); entity.setChild(isChild(fse)); return entity; } private boolean isChild(FieldSetEntity fse) { String type = fse.getString("type"); if (StringUtils.equalsAny(type, "1", "2")) { if (("1".equals(fse.getString("childrenCompany")) || "1".equals(fse.getString("childrenDept")))) { return true; } if ("2".equals(type)) { if (StringUtils.equalsAny(this.organizationType, "3", "4") && "1".equals(fse.getString("childrenPost"))) { return true; } } return false; } if (("3".equals(type) || "4".equals(type)) && "1".equals(fse.getString("childrenStaff"))) { return true; } return false; } } // /** // * 组织机构入口方法 // * // * @param fse // * @return // * @throws BaseException // */ // @Override // public Object getOrganization(FieldSetEntity fse) throws BaseException { // // if (!StringUtils.isEmpty(fse.getString("~values~"))) { // return getSelectedValueLabel(fse.getString("~values~")); // } // // 前端点击的类型 参考 组织机构类型 如果为空 默认赋值 0 = 客户下的公司(顶级) // String current_type = fse.getString("current_type"); // //组织机构类型 1-公司,2-公司 - 部门,3-公司 - 部门 - 岗位,4-公司 - 部门 - 岗位 - 人员,5-公司 - 部门 - 人员 // String organization_type = fse.getString("organization_type"); // //当前位置 todo //// String showCurrentLocation = fse.getString("showCurrentLocation"); // String[] post_uuids = null; // if (!StringUtils.isEmpty(fse.getString("post_uuids"))) { // post_uuids = fse.getString("post_uuids").split(","); // } // String[] dept_uuids = null; // if (!StringUtils.isEmpty(fse.getString("dept_uuids"))) { // dept_uuids = fse.getString("dept_uuids").split(","); // } // String[] user_ids = null; // if (!StringUtils.isEmpty(fse.getString("user_ids"))) { // user_ids = fse.getString("user_ids").split(","); // } // // //当搜索值不为空时 // if (!StringUtils.isEmpty(fse.getString("~search_value~"))) { // return getSearchValueResult(fse, dept_uuids, post_uuids, user_ids); // } // // DataTableEntity result = new DataTableEntity(); // // 前端点击的value // String current_value = fse.getString("current_value"); // // SystemUser currentUser = SpringMVCContextHolder.getCurrentUser(); // //查看集团 //// String is_group = fse.getString("is_group"); //// if (StringUtils.isEmpty(is_group)) { //// //设置默认值 //// is_group = "1"; //// //// //todo //// } // //上级value // Object[] parentValues = null; // String[] retainUuids = null; // // //用户类型 // int userType = currentUser.getUserType(); // FieldSetEntity currentManager = currentUser.getCurrentManager(); // if ((1 == userType || 4 == userType) && FieldSetEntity.isEmpty(currentManager)) { // return result; // } // //获取客户作为上级values // if ("0".equals(current_type) && StringUtils.isEmpty(current_value)) { // if (0 == userType) { // //普通用户 // parentValues = new Object[]{currentUser.getClientUuid()}; // } else if (1 == userType || 3 == userType) { // //超级管理员 或 隐藏管理员 // DataTableEntity dt = DataPoolCacheImpl.getInstance().getCacheData("客户信息"); // if (DataTableEntity.isEmpty(dt)) { // return result; // } // parentValues = dt.getUuids(); // } else if (2 == userType) { // //管理的所在的客户 // String client_uuids = currentManager.getString("clients_uuid"); // //管理员所管理的公司 //// String org_level_uuid = currentManager.getString("org_level_uuid"); //// if (StringUtils.isEmpty(client_uuids) || StringUtils.isEmpty(org_level_uuid)) { //// return result; //// } //// retainUuids = org_level_uuid.split(","); // parentValues = new Object[]{client_uuids}; // } else if (4 == userType) { // //平台管理员 // //管理的所有客户uuid // String client_uuids = currentManager.getString("clients_uuid"); // if (StringUtils.isEmpty(client_uuids)) { // return result; // } // parentValues = Arrays.stream(client_uuids.split(",")).toArray(); // } // // } else { // if (StringUtils.isEmpty(current_value)) { // return result; // } // parentValues = new Object[]{current_value}; // //公司 // if ("1".equals(current_type)) { // if (2 == userType) { // //管理的所在的客户 // String client_uuids = currentManager.getString("clients_uuid"); // //管理员所管理的公司 //// String org_level_uuid = currentManager.getString("org_level_uuid"); //// if (StringUtils.isEmpty(client_uuids) || StringUtils.isEmpty(org_level_uuid)) { //// return result; //// } //// retainUuids = org_level_uuid.split(","); // } // // } // } // List resultList = new ArrayList<>(); // if (parentValues != null && parentValues.length > 0) { // // 类型为空获取客户下的公司(顶级) // if (StringUtils.isEmpty(current_type)) { // current_type = "0"; // } // //组织机构选择类型 // int orgType = Integer.parseInt(organization_type); // OrganizationFilter filter = getFilter(current_type, orgType, dept_uuids, post_uuids, user_ids); // // 获取公司 / 部门 // if ("0".equals(current_type) || "1".equals(current_type) || "2".equals(current_type)) { // List orgLevelData = getOrgLevelData(parentValues, filter); // orgLevelData.sort(Comparator.comparing(a -> a.getInteger("sequence"))); // resultList.addAll(orgLevelData); // } // // 获取岗位 // if ("2".equals(current_type) && ("3".equals(organization_type) || "4".equals(organization_type))) { // List postDataByDept = getPostDataByDept(fse.getUUID(), filter); // if (postDataByDept != null) { // postDataByDept.sort(Comparator.comparing(a -> a.getInteger("sequence"))); // resultList.addAll(postDataByDept); // } // } // // 获取人员 // if ("3".equals(current_type) || ("5".equals(organization_type) && "2".equals(current_type))) { // List userData = getUserData(orgType, fse.getUUID(), filter); // if (userData != null) { // userData.sort(Comparator.comparing(a -> a.getInteger("sequence"))); // resultList.addAll(userData); // } // } // } // // result.setData(resultList); // return result; // } /** * @param organizationType 组织机构类型 * @param parentValue * @param filter * @return * @throws BaseException */ private List getUserData(int organizationType, String parentValue, OrganizationFilter filter) throws BaseException { List fieldSetEntityList = null; if (5 == organizationType) { fieldSetEntityList = getStaffCacheByDept(parentValue); } else if (4 == organizationType) { fieldSetEntityList = getStaffCacheByPost(parentValue); } if (fieldSetEntityList != null && fieldSetEntityList.size() > 0) { for (int i = 0; i < fieldSetEntityList.size(); i++) { FieldSetEntity ff = fieldSetEntityList.get(i); if (FieldSetEntity.isEmpty(ff)) { fieldSetEntityList.remove(i); i--; continue; } String userId = ff.getString("user_id"); String deptUuid = ff.getString("dept_uuid"); String postUuid = ff.getString("job_post_uuid"); if (!filter.allowUser(userId, deptUuid, postUuid)) { fieldSetEntityList.remove(i); i--; continue; } ff.setValue("type", 4); ff.setValue("label", ff.getString(CmnConst.USER_NAME)); ff.setValue("value", ff.getString(CmnConst.USER_ID)); ff.setValue("sid", ff.getUUID()); } } return fieldSetEntityList; } private List getPostDataByDept(String deptUuid, OrganizationFilter filter) throws BaseException { if (StringUtils.isEmpty(deptUuid)) { return null; } List fieldSetEntityList = getPostCache(deptUuid); if (fieldSetEntityList == null || fieldSetEntityList.size() == 0) { return null; } for (int i = 0; i < fieldSetEntityList.size(); i++) { FieldSetEntity ff = fieldSetEntityList.get(i); if (FieldSetEntity.isEmpty(ff)) { fieldSetEntityList.remove(i); i--; continue; } String uuid = ff.getUUID(); if (!filter.allowPost(uuid, deptUuid)) { fieldSetEntityList.remove(i); i--; continue; } if (isChildren(3, uuid, filter)) { ff.setValue("childrenStaff", 1); } ff.setValue("label", ff.getString("job_post_name")); ff.setValue("value", ff.getUUID()); ff.setValue("sid", ff.getUUID()); } return fieldSetEntityList; } private List getOrgLevelData(Object[] parentValues, OrganizationFilter filter) throws BaseException { List resultList = new ArrayList<>(); List fieldSetEntityList = null; for (Object parentValue : parentValues) { if (StringUtils.isEmpty(parentValue)) { continue; } //格局上级value 获取 机构数据 fieldSetEntityList = getOrgCache((String) parentValue); for (int i = 0; fieldSetEntityList != null && i < fieldSetEntityList.size(); i++) { FieldSetEntity ff = fieldSetEntityList.get(i); if (!FieldSetEntity.isEmpty(ff)) { String type = ff.getString("type"); //是否为公司 boolean isCompany = "1".equals(type); String uuid = ff.getUUID(); if ((!isCompany && !filter.allowDept(uuid)) || (isCompany && !filter.isAllowCompany(ff.getString(CmnConst.ORG_LEVEL_CODE)))) { fieldSetEntityList.remove(i); i--; continue; } if (isChildren(Integer.parseInt(type), ff.getUUID(), filter)) { ff.setValue("childrenCompany", 1); } ff.setValue("label", ff.getString(CmnConst.ORG_LEVEL_NAME)); ff.setValue("value", ff.getUUID()); ff.setValue("sid", ff.getString(CmnConst.ORG_LEVEL_CODE)); } } if (!CollectionUtil.isEmpty(fieldSetEntityList)) { resultList.addAll(fieldSetEntityList); } } return resultList; } private boolean isChildren(int currentType, String currentValue, OrganizationFilter filter) { int orgType = filter.getType(); switch (currentType) { case 1: if (orgType != 1) { return isChildrenOrg(filter, currentValue, "1"); } else { return isChildrenOrg(filter, currentValue, "1") || isChildrenOrg(filter, currentValue, "2"); } case 2: return isChildrenOrg(filter, currentValue, "2") || ((orgType == 3 || orgType == 4) && isChildrenPost(filter, currentValue)) || (orgType == 5 && isChildrenUser(filter, currentValue, currentType)); case 3: return orgType == 4 && isChildrenUser(filter, currentValue, currentType); default: return false; } } private boolean isChildrenOrg(OrganizationFilter filter, String value, String type) { Map orgCacheByUuid = this.getOrgCacheByUuid(value); if (orgCacheByUuid == null) { return false; } List orgCache = this.getOrgCache((String) orgCacheByUuid.get(CmnConst.ORG_LEVEL_CODE)); return !CollectionUtil.isEmpty(orgCache) && orgCache.stream().filter(item -> item != null && type.equals(item.getString(CmnConst.ORG_LEVEL_TYPE)) && (("2".equals(type) && filter.allowDept(item.getUUID())) || "1".equals(type))).count() > 0; } private boolean isChildrenPost(OrganizationFilter filter, String value) { List postCache = this.getPostCache(value); return !CollectionUtil.isEmpty(postCache) && postCache.stream().filter(item -> item != null && filter.allowPost(item.getUUID(), item.getString("dept_uuid"))) .count() > 0; } private boolean isChildrenUser(OrganizationFilter filter, String value, int parentType) { List data = null; if (parentType == 2) { data = this.getStaffCacheByDept(value); } else if (parentType == 3) { data = this.getStaffCacheByPost(value); } return !CollectionUtil.isEmpty(data) && data.stream().filter(item -> item != null && filter.allowUser(item.getString(CmnConst.USER_ID), item.getString(CmnConst.DEPT_UUID), parentType == 2 ? item.getString("job_post_uuid") : null)).count() > 0; } /** * @param currentType 当前获取数据的类型 * @param organizationType 机构选择类型 * @param dept_uuid * @param post_uuid * @param userIds * @return */ private OrganizationFilter getFilter(String currentType, int organizationType, String[] dept_uuid, String[] post_uuid, String[] userIds) { OrganizationFilter organizationFilter = new OrganizationFilter(organizationType); if ("0".equals(currentType)) { return organizationFilter; } if (4 == organizationType || 5 == organizationType) { organizationFilter.addAllowUser(userIds); Set userTheirPost = getUserTheirPost(userIds); organizationFilter.addPostNotAll(userTheirPost); if (userTheirPost != null) { Set postTheirDept = getPostTheirDept(userTheirPost.toArray(new String[userTheirPost.size()])); organizationFilter.addDeptNotAll(postTheirDept); } } if (1 != organizationType) { organizationFilter.addAllowDept(dept_uuid); } if (3 == organizationType || 4 == organizationType) { organizationFilter.addAllowPost(post_uuid); Set postTheirDept = getPostTheirDept(post_uuid); organizationFilter.addDeptNotAll(postTheirDept); } return organizationFilter; } private Set getPostTheirDept(String[] postUuid) { if (ArrayUtil.isEmpty(postUuid)) { return null; } Set resultSet = new HashSet<>(); for (String post : postUuid) { Object[] postCache = getPostCacheByUUID(post); if (!ArrayUtil.isEmpty(postCache) && !StringUtils.isEmpty(postCache[1])) { resultSet.add((String) postCache[1]); } } return resultSet; } private Set getUserTheirPost(String[] userIds) { if (ArrayUtil.isEmpty(userIds)) { return null; } Set resultSet = new HashSet<>(); for (String userId : userIds) { FieldSetEntity user = BaseUtil.getSingleInfoByCache("用户缓存", new String[]{userId}); if (!FieldSetEntity.isEmpty(user) && !StringUtils.isEmpty(user.getString("job_post_uuid"))) { resultSet.add(user.getString("job_post_uuid")); } } return resultSet; } /** * 获取人员 * * @param parentValue * @param type * @param retainUserId * @return */ private List getStaffs(String parentValue, int type, String[] retainUserId, Set[] organizationFilter) { List retainUserIdList = new ArrayList<>(); if (retainUserId != null && retainUserId.length > 0) { retainUserIdList.addAll(Arrays.asList(retainUserId)); } if (StringUtils.isEmpty(parentValue)) { return null; } List fieldSetEntityList = null; if (5 == type) { fieldSetEntityList = getStaffCacheByDept(parentValue); } else if (4 == type) { fieldSetEntityList = getStaffCacheByPost(parentValue); } for (int i = 0; fieldSetEntityList != null && i < fieldSetEntityList.size(); i++) { FieldSetEntity ff = fieldSetEntityList.get(i); if (!FieldSetEntity.isEmpty(ff)) { boolean allow_dept = false; boolean allow_post = false; if (organizationFilter != null) { if (organizationFilter[0] != null && organizationFilter[0].contains(ff.getString("dept_uuid"))) { allow_dept = true; } else if (organizationFilter[1] != null && organizationFilter[1].contains(ff.getString("job_post_uuid"))) { allow_post = true; } } if (retainUserIdList.size() > 0 && !allow_dept && !allow_post) { if (!retainUserIdList.contains(ff.getString(CmnConst.USER_ID))) { // 不允许选择的 fieldSetEntityList.remove(i); i--; continue; } } ff.setValue("~allow_select~", true); ff.setValue("type", 4); ff.setValue("label", ff.getString(CmnConst.USER_NAME)); ff.setValue("value", ff.getString(CmnConst.USER_ID)); ff.setValue("sid", ff.getUUID()); } else { fieldSetEntityList.remove(i); i--; } } return fieldSetEntityList; } /** * 获取岗位 * * @param parentValue 上级部门uuid * @param retainUuids * @return */ private List getPosts(String parentValue, String[] retainUuids, String[] dept_uuid, String[] user_ids, int type, Set[] organizationFilter) { List retainUudList = new ArrayList<>(); if (retainUuids != null && retainUuids.length > 0) { retainUudList.addAll(Arrays.asList(retainUuids)); } if (StringUtils.isEmpty(parentValue)) { return null; } List fieldSetEntityList = getPostCache(parentValue); for (int i = 0; fieldSetEntityList != null && i < fieldSetEntityList.size(); i++) { FieldSetEntity ff = fieldSetEntityList.get(i); if (!FieldSetEntity.isEmpty(ff)) { boolean allow_post = false; if (user_ids != null && user_ids.length > 0 && (type == 4 || type == 5)) { for (String user_id : user_ids) { FieldSetEntity fff = BaseUtil.getSingleInfoByCache("用户缓存", new String[]{user_id}); if (FieldSetEntity.isEmpty(fff)) { continue; } String job_post_uuid = fff.getString("job_post_uuid"); if (StringUtils.equals(job_post_uuid, ff.getUUID())) { allow_post = true; break; } } } if (retainUudList.size() > 0 && !allow_post) { if (!retainUudList.contains(ff.getUUID())) { // 不允许选择的 fieldSetEntityList.remove(i); i--; continue; } } if (dept_uuid != null && dept_uuid.length > 0 && !allow_post) { if (!ArrayUtil.contains(dept_uuid, ff.getString(CmnConst.DEPT_UUID))) { // 不允许选择的 fieldSetEntityList.remove(i); i--; continue; } } if (!allow_post && organizationFilter != null && organizationFilter.length == 2 && organizationFilter[1] != null && organizationFilter[1].size() > 0) { if (!organizationFilter[1].contains(ff.getUUID())) { // 不允许选择的 fieldSetEntityList.remove(i); i--; continue; } } //不选人员 if (4 != type) { ff.setValue("childrenStaff", 0); } ff.setValue("~allow_select~", true); ff.setValue("type", 3); ff.setValue("label", ff.getString("job_post_name")); ff.setValue("value", ff.getUUID()); ff.setValue("sid", ff.getUUID()); } else { fieldSetEntityList.remove(i); i--; } } return fieldSetEntityList; } /** * 获取机构 * * @param parentValues 上级编码 * @param retainUuids 保留的uuid 如果为空则保留所有 * @return` */ private List getOrgLevels(Object[] parentValues, String[] retainUuids, String[] retainDeptUuids, String[] post_uuids, String[] user_ids, int type, Set[] organizationFilter) { List retainUudList = new ArrayList<>(); if (retainUuids != null && retainUuids.length > 0) { retainUudList.addAll(Arrays.asList(retainUuids)); } List retainDeptUudList = new ArrayList<>(); if (retainDeptUuids != null && retainDeptUuids.length > 0) { retainDeptUudList.addAll(Arrays.asList(retainDeptUuids)); } List fieldSetEntityList = null; for (Object parentValue : parentValues) { if (StringUtils.isEmpty(parentValue)) { continue; } fieldSetEntityList = getOrgCache((String) parentValue); for (int i = 0; fieldSetEntityList != null && i < fieldSetEntityList.size(); i++) { FieldSetEntity ff = fieldSetEntityList.get(i); if (!FieldSetEntity.isEmpty(ff)) { ff.setValue("~allow_select~", true); ff.setValue("label", ff.getString(CmnConst.ORG_LEVEL_NAME)); ff.setValue("value", ff.getUUID()); ff.setValue("sid", ff.getString(CmnConst.ORG_LEVEL_CODE)); boolean allow_dept = false; // 不选岗位 if (3 != type && 4 != type) { ff.setValue("childrenPost", 0); } else if (!ArrayUtil.isEmpty(post_uuids)) { for (String post_uuid : post_uuids) { Object[] postCache = getPostCacheByUUID(post_uuid); if (!ArrayUtil.isEmpty(postCache) && StringUtils.equals(ff.getUUID(), (String) postCache[1])) { allow_dept = true; break; } } } // 只选公司 if (1 == type) { if ("2".equals(ff.getString("type"))) { fieldSetEntityList.remove(i); i--; continue; } ff.setValue("childrenDept", 0); } // 不选人员 if (5 != type && 4 != type) { ff.setValue("childrenStaff", 0); } else if (!allow_dept) { if (user_ids != null && user_ids.length > 0) { for (String user_id : user_ids) { FieldSetEntity fff = BaseUtil.getSingleInfoByCache("用户缓存", new String[]{user_id}); if (FieldSetEntity.isEmpty(fff)) { continue; } String dept_uuid = fff.getString("dept_uuid"); if (StringUtils.equals(dept_uuid, ff.getUUID())) { allow_dept = true; break; } } } } if (!allow_dept && organizationFilter != null && organizationFilter[0] != null && organizationFilter[0].size() > 0) { if (!organizationFilter[0].contains(ff.getString(CmnConst.ORG_LEVEL_CODE))) { // 不允许选择的 fieldSetEntityList.remove(i); i--; continue; } } } else { fieldSetEntityList.remove(i); i--; } } } return fieldSetEntityList; } class OrganizationFilter { private int type; private Set allowCompany; private Set allowDept; private Set allowPost; private Set allowUser; private Set deptNotAll; private Set postNotAll; private boolean isEmpty(Collection collection) { return collection == null || collection.size() <= 0; } private boolean isEmpty(Collection... collection) { return collection != null && collection.length > 0 && Arrays.stream(collection).filter(item -> !isEmpty(item)).count() <= 0; } private boolean contains(Collection collection, Object val) { return val != null && !this.isEmpty(collection) && collection.contains(val); } public boolean allowDept(String uuid) { // 允许的部门为空 且 允许部门下的部分为空 if (this.isEmpty(this.allowDept) && this.isEmpty(this.deptNotAll)) { return true; } // 允许的部门中是否有当前传入的部门 if (this.contains(this.allowDept, uuid)) { return true; } // 允许展示部分的部门中是否有当前传入的部门 if (this.contains(this.deptNotAll, uuid)) { return true; } return false; } public boolean allowParentDept(String uuid) { if (this.isEmpty(this.allowDept, this.deptNotAll)) { return false; } Map orgCacheByUuid = getOrgCacheByUuid(uuid); String type = (String) orgCacheByUuid.get("parent_type"); if ("1".equals(type)) { } return false; } public boolean allowPost(String uuid, String deptUuid) { //允许的部门中是否有当前传入的部门 if (this.contains(this.allowDept, deptUuid)) { return true; } //允许展示部分部门中包含当前传入的部门 if (this.contains(this.deptNotAll, deptUuid)) { //传入的岗位是否在允许的岗位中 if (this.contains(this.allowPost, uuid)) { return true; } //传入的岗位是否在允许的部分岗位中 if (this.contains(this.postNotAll, uuid)) { return true; } } if (this.contains(this.allowPost, uuid) || this.contains(this.postNotAll, uuid)) { return true; } if (this.isEmpty(this.allowPost, this.deptNotAll, this.allowPost, this.postNotAll)) { return true; } return false; } public boolean allowUser(String userId, String deptUuid, String postUuid) { if (this.contains(this.allowUser, userId) || this.contains(this.allowDept, deptUuid) || (StringUtils.isEmpty(deptUuid) || this.contains(this.allowPost, postUuid)) ) { return true; } return this.isEmpty(this.allowPost, this.allowDept, this.allowUser); } public OrganizationFilter(int type) { this.type = type; } public int getType() { return type; } public Set getDeptNotAll() { return deptNotAll; } public boolean isDeptNotAll(String val) { if (deptNotAll == null || deptNotAll.size() == 0) { return false; } return deptNotAll.contains(val); } public boolean isPostNotAll(String val) { if (postNotAll == null || postNotAll.size() == 0) { return false; } return postNotAll.contains(val); } public void addDeptNotAll(Collection collection) { if (collection == null || collection.size() == 0) { return; } if (deptNotAll == null) { deptNotAll = new HashSet<>(); } deptNotAll.addAll(collection); addDeptNotAll(getParentUuid(collection.toArray(new String[collection.size()]))); } public Set getPostNotAll() { return postNotAll; } public void addPostNotAll(Collection collection) { if (collection == null || collection.size() == 0) { return; } if (postNotAll == null) { postNotAll = new HashSet<>(); } postNotAll.addAll(collection); } public void addAllowCompany(String... uuid) { if (ArrayUtil.isEmpty(uuid)) { return; } if (allowCompany == null) { allowCompany = new HashSet<>(); } allowCompany.addAll(CollectionUtil.toList(uuid)); } public boolean isAllowCompany(String code) { if (this.isEmpty(deptNotAll, allowDept)) { return true; } else if (!StringUtils.isEmpty(code)) { Set deptSet = new HashSet<>(); if (!this.isEmpty(deptNotAll)) { deptSet.addAll(deptNotAll); } if (!this.isEmpty(allowDept)) { deptSet.addAll(allowDept); } for (String uuid : deptSet) { Map orgCacheByUuid = getOrgCacheByUuid(uuid); if (orgCacheByUuid != null && StringUtils.startsWith((String) orgCacheByUuid.get(CmnConst.ORG_LEVEL_CODE), code)) { return true; } continue; } } return false; } public void addAllowDept(String... uuid) { if (ArrayUtil.isEmpty(uuid)) { return; } if (allowDept == null) { allowDept = new HashSet<>(); } allowDept.addAll(CollectionUtil.toList(uuid)); } public boolean isAllowDept(String val) { if (allowDept == null || allowDept.size() == 0) { return true; } else { return allowDept.contains(val); } } public void addAllowPost(String... uuid) { if (ArrayUtil.isEmpty(uuid)) { return; } if (allowPost == null) { allowPost = new HashSet<>(); } allowPost.addAll(CollectionUtil.toList(uuid)); addDeptNotAll(getParentUuid(uuid)); } public Collection getParentUuid(String[] uuids) { Set parentDept = new HashSet<>(); if (uuids != null && uuids.length > 0) { for (String uuid : uuids) { if (StringUtils.isEmpty(uuid)) continue; Map orgCacheByUuid = getOrgCacheByUuid(uuid); if (orgCacheByUuid != null) { String parent_uuid = (String) orgCacheByUuid.get("parent_uuid"); if ("2".equals(orgCacheByUuid.get("parent_type"))) { parentDept.add(parent_uuid); } } } } return parentDept; } public boolean isAllowPost(String val) { if (allowPost == null || allowPost.size() == 0) { if (isPostNotAll(val)) { } return true; } else { return allowPost.contains(val); } } public void addAllowUser(String... ids) { if (ArrayUtil.isEmpty(ids)) { return; } if (allowUser == null) { allowUser = new HashSet<>(); } allowUser.addAll(CollectionUtil.toList(ids)); } public boolean isAllowUser(String val) { if (allowUser == null || allowUser.size() == 0) { return true; } else { return allowUser.contains(val); } } } }