组织架构图分权功能
This commit is contained in:
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<>();
|
||||||
|
|
@ -130,7 +139,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
||||||
item.put("fname", rs.getString("fname"));
|
item.put("fname", rs.getString("fname"));
|
||||||
item.put("ftype", rs.getString("ftype"));
|
item.put("ftype", rs.getString("ftype"));
|
||||||
item.put("fnumber", rs.getString("fnumber"));
|
item.put("fnumber", rs.getString("fnumber"));
|
||||||
item.put("fobjid",rs.getString("fobjid"));
|
item.put("fobjid", rs.getString("fobjid"));
|
||||||
item.put("parentId", null);
|
item.put("parentId", null);
|
||||||
item.put("expand", "1");
|
item.put("expand", "1");
|
||||||
item.put("hasChildren", hasChildren(rs.getString("id"), true));
|
item.put("hasChildren", hasChildren(rs.getString("id"), true));
|
||||||
|
|
@ -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<>();
|
||||||
|
|
@ -210,7 +225,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getUserData(Map<String, Object> request2Map, User user) {
|
public Map<String, Object> getUserData(Map<String, Object> request2Map, User user) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
boolean hasRight = HasRightUtil.hasRight(user, USER_RIGHT, true);
|
boolean hasRight = HasRightUtil.hasRight(user, USER_RIGHT, true);
|
||||||
result.put("hasRight", hasRight);
|
result.put("hasRight", hasRight);
|
||||||
if (!hasRight) {
|
if (!hasRight) {
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -251,19 +266,18 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
||||||
item.put("expand", "1");
|
item.put("expand", "1");
|
||||||
item.put("fnumber", rs.getString("fnumber"));
|
item.put("fnumber", rs.getString("fnumber"));
|
||||||
item.put("fleader", rs.getString("fleader"));
|
item.put("fleader", rs.getString("fleader"));
|
||||||
item.put("fobjid",rs.getString("fobjid"));
|
item.put("fobjid", rs.getString("fobjid"));
|
||||||
item.put("fleaderlv",convertLevel(rs.getString("fleaderlv")));
|
item.put("fleaderlv", convertLevel(rs.getString("fleaderlv")));
|
||||||
item.put("fleaderst",convertGrade(rs.getString("fleaderst")));
|
item.put("fleaderst", convertGrade(rs.getString("fleaderst")));
|
||||||
item.put("fecid",rs.getString("fecid"));
|
item.put("fecid", rs.getString("fecid"));
|
||||||
list.add(item);
|
list.add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
@ -294,9 +308,9 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
||||||
item.put("fnumber", rs.getString("fnumber"));
|
item.put("fnumber", rs.getString("fnumber"));
|
||||||
item.put("hasChildren", hasChildren(rs.getString("id"), false));
|
item.put("hasChildren", hasChildren(rs.getString("id"), false));
|
||||||
item.put("fleader", rs.getString("fleader"));
|
item.put("fleader", rs.getString("fleader"));
|
||||||
item.put("fleaderlv",convertLevel(rs.getString("fleaderlv")));
|
item.put("fleaderlv", convertLevel(rs.getString("fleaderlv")));
|
||||||
item.put("fleaderst",convertGrade(rs.getString("fleaderst")));
|
item.put("fleaderst", convertGrade(rs.getString("fleaderst")));
|
||||||
item.put("fobjid",rs.getString("fobjid"));
|
item.put("fobjid", rs.getString("fobjid"));
|
||||||
currentList.add(item);
|
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<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(",");
|
||||||
LevelPO levelByID = MapperProxyFactory.getProxy(LevelMapper.class).getLevelByID(parseLong);
|
for (String s : split) {
|
||||||
if (null != levelByID) {
|
long parseLong = Long.parseLong(s);
|
||||||
jobLevelName = levelByID.getLevelName();
|
LevelPO levelByID = MapperProxyFactory.getProxy(LevelMapper.class).getLevelByID(parseLong);
|
||||||
|
if (null != levelByID) {
|
||||||
|
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(",");
|
||||||
GradePO gradeByID = MapperProxyFactory.getProxy(GradeMapper.class).getGradeByID(parseLong);
|
for (String s : split) {
|
||||||
if (null != gradeByID) {
|
long parseLong = Long.parseLong(s);
|
||||||
jobGradeName = gradeByID.getGradeName();
|
GradePO gradeByID = MapperProxyFactory.getProxy(GradeMapper.class).getGradeByID(parseLong);
|
||||||
|
if (null != gradeByID) {
|
||||||
|
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…
Reference in New Issue