diff --git a/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java b/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java index 36ed1fb7..2e053b41 100644 --- a/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java +++ b/src/com/engine/organization/service/impl/HrmResourceServiceImpl.java @@ -522,9 +522,9 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic } // 分权查询 - List jclRoleLevels = new DetachUtil(user.getUID()).getJclRoleLevels(); - String parentCompanyIds = StringUtils.join(jclRoleLevels, ","); - if (StringUtils.isNotBlank(parentCompanyIds)) { + DetachUtil detachUtil = new DetachUtil(user.getUID()); + String parentCompanyIds = detachUtil.getJclRoleLevels(); + if (detachUtil.isDETACH()) { sqlWhere += " And t.company_id in(" + parentCompanyIds + ")"; } diff --git a/src/com/engine/organization/service/impl/OrgChartServiceImpl.java b/src/com/engine/organization/service/impl/OrgChartServiceImpl.java index 8c17ffd4..b85d838e 100644 --- a/src/com/engine/organization/service/impl/OrgChartServiceImpl.java +++ b/src/com/engine/organization/service/impl/OrgChartServiceImpl.java @@ -11,11 +11,14 @@ import com.engine.organization.service.OrgChartService; import com.engine.organization.util.HasRightUtil; import com.engine.organization.util.db.DBType; import com.engine.organization.util.db.MapperProxyFactory; +import com.engine.organization.util.detach.DetachUtil; import org.apache.commons.lang3.StringUtils; import weaver.conn.RecordSet; +import weaver.general.Util; import weaver.hrm.User; import java.util.*; +import java.util.stream.Collectors; /** * @className: OrgChartServiceImpl @@ -47,8 +50,14 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { item.put("companyname", rs.getString("companyname")); fclasslist.add(item); } + String sql = "select distinct id, fnumber, fname, ftype from jcl_org_map where ftype in (0, 1) order by ftype , id "; - rs.executeQuery("select distinct id, fnumber, fname, ftype from jcl_org_map where ftype in (0, 1) order by ftype , id "); + // 分部分权过滤 + DetachUtil detachUtil = new DetachUtil(user.getUID()); + if (detachUtil.isDETACH()) { + sql = "select distinct id, fnumber, fname, ftype from jcl_org_map where (ftype = 0 or (ftype = 1 and fobjid in(" + detachUtil.getJclRoleLevels() + "))) order by ftype , id"; + } + rs.executeQuery(sql); List> companylist = new ArrayList<>(); while (rs.next()) { Map item = new HashMap<>(); @@ -130,7 +139,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { item.put("fname", rs.getString("fname")); item.put("ftype", rs.getString("ftype")); item.put("fnumber", rs.getString("fnumber")); - item.put("fobjid",rs.getString("fobjid")); + item.put("fobjid", rs.getString("fobjid")); item.put("parentId", null); item.put("expand", "1"); item.put("hasChildren", hasChildren(rs.getString("id"), true)); @@ -138,11 +147,10 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { } int currentLevel = 1; - if (currentLevel + 1 <= Integer.parseInt(level)) { - findCompanyItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, true); - } else { - findCompanyItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, false); - } + findCompanyItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level)); + + // 分部数据,构建层级关系 + reBuildTreeList(list); result.put("api_status", true); result.put("data", list); @@ -150,7 +158,14 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { } private void findCompanyItemByParantId(String id, int currentLevel, String level, RecordSet rs, List> list, String whereSql, boolean expand) { - rs.executeQuery("select id, fname, ftype, fparentid,fobjid,fecid,fnumber from jcl_org_map " + whereSql + " and fparentid = " + id); + String sql = "select id, fname, ftype, fparentid,fobjid,fecid,fnumber from jcl_org_map " + whereSql; + DetachUtil detachUtil = new DetachUtil(user.getUID()); + if (detachUtil.isDETACH() && "0".equals(id)) { + sql += " and ftype = 1 and fobjid in(" + detachUtil.getJclRoleLevels() + ")"; + } else { + sql += " and fparentid = " + id; + } + rs.executeQuery(sql); List> currentList = new ArrayList<>(); while (rs.next()) { Map item = new HashMap<>(); @@ -210,7 +225,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { @Override public Map getUserData(Map request2Map, User user) { Map result = new HashMap<>(); - boolean hasRight = HasRightUtil.hasRight(user, USER_RIGHT, true); + boolean hasRight = HasRightUtil.hasRight(user, USER_RIGHT, true); result.put("hasRight", hasRight); if (!hasRight) { return result; @@ -251,19 +266,18 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { item.put("expand", "1"); item.put("fnumber", rs.getString("fnumber")); item.put("fleader", rs.getString("fleader")); - item.put("fobjid",rs.getString("fobjid")); - item.put("fleaderlv",convertLevel(rs.getString("fleaderlv"))); - item.put("fleaderst",convertGrade(rs.getString("fleaderst"))); - item.put("fecid",rs.getString("fecid")); + item.put("fobjid", rs.getString("fobjid")); + item.put("fleaderlv", convertLevel(rs.getString("fleaderlv"))); + item.put("fleaderst", convertGrade(rs.getString("fleaderst"))); + item.put("fecid", rs.getString("fecid")); list.add(item); } int currentLevel = 1; - if (currentLevel + 1 <= Integer.parseInt(level)) { - findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, true); - }else{ - findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, false); - } + findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level)); + + // 分部数据,构建层级关系 + reBuildTreeList(list); result.put("api_status", true); result.put("data", list); @@ -294,9 +308,9 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { item.put("fnumber", rs.getString("fnumber")); item.put("hasChildren", hasChildren(rs.getString("id"), false)); item.put("fleader", rs.getString("fleader")); - item.put("fleaderlv",convertLevel(rs.getString("fleaderlv"))); - item.put("fleaderst",convertGrade(rs.getString("fleaderst"))); - item.put("fobjid",rs.getString("fobjid")); + item.put("fleaderlv", convertLevel(rs.getString("fleaderlv"))); + item.put("fleaderst", convertGrade(rs.getString("fleaderst"))); + item.put("fobjid", rs.getString("fobjid")); currentList.add(item); } @@ -354,7 +368,14 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List> list, String whereSql, boolean expand) { - rs.executeQuery("select t.id, t.fname, t.ftype, t.fparentid,t.fobjparentid,t.fleader, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber,t.fobjid,t.fecid,t.fleaderlv, t.fleaderst from jcl_org_map t " + whereSql + " and t.fparentid = " + id); + String sql = "select t.id, t.fname, t.ftype, t.fparentid,t.fobjparentid,t.fleader, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber,t.fobjid,t.fecid,t.fleaderlv, t.fleaderst from jcl_org_map t " + whereSql; + DetachUtil detachUtil = new DetachUtil(user.getUID()); + if (detachUtil.isDETACH() && "0".equals(id)) { + sql += " and ftype = 1 and fobjid in(" + detachUtil.getJclRoleLevels() + ")"; + } else { + sql += " and t.fparentid = " + id; + } + rs.executeQuery(sql); List> currentList = new ArrayList<>(); while (rs.next()) { Map item = new HashMap<>(); @@ -418,34 +439,52 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { } private String convertLevel(String fLeaderLv) { - String jobLevelName = ""; + StringBuilder jobLevelName = new StringBuilder(); if (StringUtils.isNotBlank(fLeaderLv)) { try { - long parseLong = Long.parseLong(fLeaderLv); - LevelPO levelByID = MapperProxyFactory.getProxy(LevelMapper.class).getLevelByID(parseLong); - if (null != levelByID) { - jobLevelName = levelByID.getLevelName(); + String[] split = fLeaderLv.split(","); + for (String s : split) { + long parseLong = Long.parseLong(s); + LevelPO levelByID = MapperProxyFactory.getProxy(LevelMapper.class).getLevelByID(parseLong); + if (null != levelByID) { + jobLevelName.append(levelByID.getLevelName()); + } } } catch (NumberFormatException exception) { - jobLevelName = fLeaderLv; + jobLevelName = new StringBuilder(fLeaderLv); } } - return jobLevelName; + return jobLevelName.toString(); } private String convertGrade(String fLeaderSt) { - String jobGradeName = ""; + StringBuilder jobGradeName = new StringBuilder(); if (StringUtils.isNotBlank(fLeaderSt)) { try { - long parseLong = Long.parseLong(fLeaderSt); - GradePO gradeByID = MapperProxyFactory.getProxy(GradeMapper.class).getGradeByID(parseLong); - if (null != gradeByID) { - jobGradeName = gradeByID.getGradeName(); + String[] split = fLeaderSt.split(","); + for (String s : split) { + long parseLong = Long.parseLong(s); + GradePO gradeByID = MapperProxyFactory.getProxy(GradeMapper.class).getGradeByID(parseLong); + if (null != gradeByID) { + jobGradeName.append(gradeByID.getGradeName()); + } } } catch (NumberFormatException exception) { - jobGradeName = fLeaderSt; + jobGradeName = new StringBuilder(fLeaderSt); } } - return jobGradeName; + return jobGradeName.toString(); + } + + + private void reBuildTreeList(List> list) { + // 分部数据,构建层级关系 + Set idSet = list.stream().filter(item -> "1".equals(Util.null2String(item.get("ftype")))).map(item -> Util.null2String(item.get("id"))).collect(Collectors.toSet()); + list.forEach(item -> { + if ("1".equals(Util.null2String(item.get("ftype"))) && !idSet.contains(Util.null2String(item.get("parentId")))) { + item.put("parentId", "0"); + item.put("fobjparentId", "0"); + } + }); } } diff --git a/src/com/engine/organization/util/detach/DetachUtil.java b/src/com/engine/organization/util/detach/DetachUtil.java index ec0fd254..7b047c29 100644 --- a/src/com/engine/organization/util/detach/DetachUtil.java +++ b/src/com/engine/organization/util/detach/DetachUtil.java @@ -7,6 +7,7 @@ import com.engine.organization.entity.job.po.JobPO; import com.engine.organization.service.impl.ManagerDetachServiceImpl; import com.weaver.general.BaseBean; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.List; @@ -17,15 +18,15 @@ import java.util.List; * @version: 1.0 */ public class DetachUtil { - private boolean IS_DETACH = "true".equals(new BaseBean().getPropValue("hrmOrganization", "detach")); + private boolean DETACH = "true".equals(new BaseBean().getPropValue("hrmOrganization", "detach")); private final List jclRoleLevels; public DetachUtil(Integer uId) { if (1 == uId) { - IS_DETACH = false; + DETACH = false; } - if (IS_DETACH) { + if (DETACH) { jclRoleLevels = ManagerDetachServiceImpl.getJclRoleLevels(uId); } else { jclRoleLevels = new ArrayList<>(); @@ -36,7 +37,7 @@ public class DetachUtil { * 根据分权配置过滤分部 */ public void filterCompanyList(List companyList) { - if (IS_DETACH && CollectionUtils.isNotEmpty(companyList)) { + if (DETACH && CollectionUtils.isNotEmpty(companyList)) { companyList.removeIf(item -> !jclRoleLevels.contains(item.getId())); } } @@ -45,7 +46,7 @@ public class DetachUtil { * 根据分权配置过滤分部 */ public void filterDepartmentList(List departmentList) { - if (IS_DETACH && CollectionUtils.isNotEmpty(departmentList)) { + if (DETACH && CollectionUtils.isNotEmpty(departmentList)) { departmentList.removeIf(item -> !jclRoleLevels.contains(item.getParentComp())); } } @@ -54,7 +55,7 @@ public class DetachUtil { * 根据分权配置过滤分部 */ public void filterJobDTOList(List jobList) { - if (IS_DETACH && CollectionUtils.isNotEmpty(jobList)) { + if (DETACH && CollectionUtils.isNotEmpty(jobList)) { jobList.removeIf(item -> !jclRoleLevels.contains(item.getParentComp())); } } @@ -63,12 +64,16 @@ public class DetachUtil { * 根据分权配置过滤分部 */ public void filterJobList(List jobList) { - if (IS_DETACH && CollectionUtils.isNotEmpty(jobList)) { + if (DETACH && CollectionUtils.isNotEmpty(jobList)) { jobList.removeIf(item -> !jclRoleLevels.contains(item.getParentComp())); } } - public List getJclRoleLevels() { - return jclRoleLevels; + public String getJclRoleLevels() { + return StringUtils.join(jclRoleLevels, ","); + } + + public boolean isDETACH() { + return DETACH; } }