组织架构图分权功能

pull/34/head
dxfeng 3 years ago
parent 796487941c
commit be90013ca0

@ -522,9 +522,9 @@ public class HrmResourceServiceImpl extends Service implements HrmResourceServic
} }
// 分权查询 // 分权查询
List<Long> jclRoleLevels = new DetachUtil(user.getUID()).getJclRoleLevels(); DetachUtil detachUtil = new DetachUtil(user.getUID());
String parentCompanyIds = StringUtils.join(jclRoleLevels, ","); String parentCompanyIds = detachUtil.getJclRoleLevels();
if (StringUtils.isNotBlank(parentCompanyIds)) { if (detachUtil.isDETACH()) {
sqlWhere += " And t.company_id in(" + parentCompanyIds + ")"; sqlWhere += " And t.company_id in(" + parentCompanyIds + ")";
} }

@ -11,11 +11,14 @@ import com.engine.organization.service.OrgChartService;
import com.engine.organization.util.HasRightUtil; import com.engine.organization.util.HasRightUtil;
import com.engine.organization.util.db.DBType; import com.engine.organization.util.db.DBType;
import com.engine.organization.util.db.MapperProxyFactory; import com.engine.organization.util.db.MapperProxyFactory;
import com.engine.organization.util.detach.DetachUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet; import weaver.conn.RecordSet;
import weaver.general.Util;
import weaver.hrm.User; import weaver.hrm.User;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @className: OrgChartServiceImpl * @className: OrgChartServiceImpl
@ -47,8 +50,14 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
item.put("companyname", rs.getString("companyname")); item.put("companyname", rs.getString("companyname"));
fclasslist.add(item); 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<Map<String, Object>> companylist = new ArrayList<>(); List<Map<String, Object>> companylist = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
Map<String, Object> item = new HashMap<>(); Map<String, Object> item = new HashMap<>();
@ -138,11 +147,10 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
} }
int currentLevel = 1; int currentLevel = 1;
if (currentLevel + 1 <= Integer.parseInt(level)) { findCompanyItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level));
findCompanyItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, true);
} else { // 分部数据,构建层级关系
findCompanyItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, false); reBuildTreeList(list);
}
result.put("api_status", true); result.put("api_status", true);
result.put("data", list); 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<Map<String, Object>> list, String whereSql, boolean expand) { private void findCompanyItemByParantId(String id, int currentLevel, String level, RecordSet rs, List<Map<String, Object>> 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<Map<String, Object>> currentList = new ArrayList<>(); List<Map<String, Object>> currentList = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
Map<String, Object> item = new HashMap<>(); Map<String, Object> item = new HashMap<>();
@ -259,11 +274,10 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
} }
int currentLevel = 1; int currentLevel = 1;
if (currentLevel + 1 <= Integer.parseInt(level)) { findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level));
findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, true);
}else{ // 分部数据,构建层级关系
findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, false); reBuildTreeList(list);
}
result.put("api_status", true); result.put("api_status", true);
result.put("data", list); result.put("data", list);
@ -354,7 +368,14 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List<Map<String, Object>> list, String whereSql, boolean expand) { private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List<Map<String, Object>> 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<Map<String, Object>> currentList = new ArrayList<>(); List<Map<String, Object>> currentList = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
Map<String, Object> item = new HashMap<>(); Map<String, Object> item = new HashMap<>();
@ -418,34 +439,52 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
} }
private String convertLevel(String fLeaderLv) { private String convertLevel(String fLeaderLv) {
String jobLevelName = ""; StringBuilder jobLevelName = new StringBuilder();
if (StringUtils.isNotBlank(fLeaderLv)) { if (StringUtils.isNotBlank(fLeaderLv)) {
try { try {
long parseLong = Long.parseLong(fLeaderLv); String[] split = fLeaderLv.split(",");
for (String s : split) {
long parseLong = Long.parseLong(s);
LevelPO levelByID = MapperProxyFactory.getProxy(LevelMapper.class).getLevelByID(parseLong); LevelPO levelByID = MapperProxyFactory.getProxy(LevelMapper.class).getLevelByID(parseLong);
if (null != levelByID) { if (null != levelByID) {
jobLevelName = levelByID.getLevelName(); jobLevelName.append(levelByID.getLevelName());
}
} }
} catch (NumberFormatException exception) { } catch (NumberFormatException exception) {
jobLevelName = fLeaderLv; jobLevelName = new StringBuilder(fLeaderLv);
} }
} }
return jobLevelName; return jobLevelName.toString();
} }
private String convertGrade(String fLeaderSt) { private String convertGrade(String fLeaderSt) {
String jobGradeName = ""; StringBuilder jobGradeName = new StringBuilder();
if (StringUtils.isNotBlank(fLeaderSt)) { if (StringUtils.isNotBlank(fLeaderSt)) {
try { try {
long parseLong = Long.parseLong(fLeaderSt); String[] split = fLeaderSt.split(",");
for (String s : split) {
long parseLong = Long.parseLong(s);
GradePO gradeByID = MapperProxyFactory.getProxy(GradeMapper.class).getGradeByID(parseLong); GradePO gradeByID = MapperProxyFactory.getProxy(GradeMapper.class).getGradeByID(parseLong);
if (null != gradeByID) { if (null != gradeByID) {
jobGradeName = gradeByID.getGradeName(); jobGradeName.append(gradeByID.getGradeName());
}
} }
} catch (NumberFormatException exception) { } catch (NumberFormatException exception) {
jobGradeName = fLeaderSt; jobGradeName = new StringBuilder(fLeaderSt);
} }
} }
return jobGradeName; return jobGradeName.toString();
}
private void reBuildTreeList(List<Map<String, Object>> list) {
// 分部数据,构建层级关系
Set<String> 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");
}
});
} }
} }

@ -7,6 +7,7 @@ import com.engine.organization.entity.job.po.JobPO;
import com.engine.organization.service.impl.ManagerDetachServiceImpl; import com.engine.organization.service.impl.ManagerDetachServiceImpl;
import com.weaver.general.BaseBean; import com.weaver.general.BaseBean;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -17,15 +18,15 @@ import java.util.List;
* @version: 1.0 * @version: 1.0
*/ */
public class DetachUtil { 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<Long> jclRoleLevels; private final List<Long> jclRoleLevels;
public DetachUtil(Integer uId) { public DetachUtil(Integer uId) {
if (1 == uId) { if (1 == uId) {
IS_DETACH = false; DETACH = false;
} }
if (IS_DETACH) { if (DETACH) {
jclRoleLevels = ManagerDetachServiceImpl.getJclRoleLevels(uId); jclRoleLevels = ManagerDetachServiceImpl.getJclRoleLevels(uId);
} else { } else {
jclRoleLevels = new ArrayList<>(); jclRoleLevels = new ArrayList<>();
@ -36,7 +37,7 @@ public class DetachUtil {
* *
*/ */
public void filterCompanyList(List<CompPO> companyList) { public void filterCompanyList(List<CompPO> companyList) {
if (IS_DETACH && CollectionUtils.isNotEmpty(companyList)) { if (DETACH && CollectionUtils.isNotEmpty(companyList)) {
companyList.removeIf(item -> !jclRoleLevels.contains(item.getId())); companyList.removeIf(item -> !jclRoleLevels.contains(item.getId()));
} }
} }
@ -45,7 +46,7 @@ public class DetachUtil {
* *
*/ */
public void filterDepartmentList(List<DepartmentPO> departmentList) { public void filterDepartmentList(List<DepartmentPO> departmentList) {
if (IS_DETACH && CollectionUtils.isNotEmpty(departmentList)) { if (DETACH && CollectionUtils.isNotEmpty(departmentList)) {
departmentList.removeIf(item -> !jclRoleLevels.contains(item.getParentComp())); departmentList.removeIf(item -> !jclRoleLevels.contains(item.getParentComp()));
} }
} }
@ -54,7 +55,7 @@ public class DetachUtil {
* *
*/ */
public void filterJobDTOList(List<JobListDTO> jobList) { public void filterJobDTOList(List<JobListDTO> jobList) {
if (IS_DETACH && CollectionUtils.isNotEmpty(jobList)) { if (DETACH && CollectionUtils.isNotEmpty(jobList)) {
jobList.removeIf(item -> !jclRoleLevels.contains(item.getParentComp())); jobList.removeIf(item -> !jclRoleLevels.contains(item.getParentComp()));
} }
} }
@ -63,12 +64,16 @@ public class DetachUtil {
* *
*/ */
public void filterJobList(List<JobPO> jobList) { public void filterJobList(List<JobPO> jobList) {
if (IS_DETACH && CollectionUtils.isNotEmpty(jobList)) { if (DETACH && CollectionUtils.isNotEmpty(jobList)) {
jobList.removeIf(item -> !jclRoleLevels.contains(item.getParentComp())); jobList.removeIf(item -> !jclRoleLevels.contains(item.getParentComp()));
} }
} }
public List<Long> getJclRoleLevels() { public String getJclRoleLevels() {
return jclRoleLevels; return StringUtils.join(jclRoleLevels, ",");
}
public boolean isDETACH() {
return DETACH;
} }
} }

Loading…
Cancel
Save