|
|
|
@ -19,8 +19,10 @@ 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.BaseBean;
|
|
|
|
|
import weaver.general.Util;
|
|
|
|
|
import weaver.hrm.User;
|
|
|
|
|
import weaver.wechat.util.Utils;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
@ -39,6 +41,10 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
private static final String USER_RIGHT = "OrgPerspective:All";
|
|
|
|
|
private final String level = getFieldName("职等");
|
|
|
|
|
private final String grade = getFieldName("职级");
|
|
|
|
|
// 配置文件禁用分部
|
|
|
|
|
private static final String disableComp = new BaseBean().getPropValue("hrmOrganization", "disableComp");
|
|
|
|
|
// 读取配置文件中分部负责人对应字段
|
|
|
|
|
private static final String compLeader = new BaseBean().getPropValue("hrmOrganization", "compLeader");
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, Object> getOptionCondition(Map<String, Object> request2Map, User user) {
|
|
|
|
@ -124,11 +130,14 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
if (!hasRight) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String root = (String) request2Map.get("root"); // 根节点
|
|
|
|
|
String level = (String) request2Map.get("level"); // 显示层级
|
|
|
|
|
String outKey = (String) request2Map.get("outkey");// 显示外部机构: 0不显示、1显示
|
|
|
|
|
if (StringUtils.isBlank(outKey)){
|
|
|
|
|
outKey = "0";
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(level)) {
|
|
|
|
|
level = "3";
|
|
|
|
|
level = "0";
|
|
|
|
|
}
|
|
|
|
|
String whereSql = companyDateWhereSql(request2Map);
|
|
|
|
|
|
|
|
|
@ -141,7 +150,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
|
|
|
|
|
// 获取根节点
|
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
|
|
rs.executeQuery("select id, fname, ftype, fparentid, fnumber, fobjid, fisvitual from jcl_org_map " + whereSql + whereItemSql);
|
|
|
|
|
rs.executeQuery("select id, fname, ftype, fparentid, fleader, fleadername, fnumber, fobjid, fisvitual from jcl_org_map " + whereSql + whereItemSql);
|
|
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
|
String id = null;
|
|
|
|
|
if (rs.next()) {
|
|
|
|
@ -156,10 +165,21 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
item.put("expand", "1");
|
|
|
|
|
item.put("fisvitual", rs.getString("fisvitual"));
|
|
|
|
|
item.put("hasChildren", hasChildren(rs.getString("id"), true));
|
|
|
|
|
item.put("fleadername", Utils.null2String(rs.getString("fleadername")));
|
|
|
|
|
item.put("fleader", Utils.null2String(rs.getString("fleader")));
|
|
|
|
|
if (rs.getString("ftype").equals("1")) {
|
|
|
|
|
item.put("empNum", computeComOrDeptNums(rs.getString("ftype"), rs.getString("fobjid"), hasChildren(rs.getString("id"), true)));
|
|
|
|
|
}
|
|
|
|
|
list.add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int currentLevel = 1;
|
|
|
|
|
if (outKey.equals("0")) {
|
|
|
|
|
whereSql = whereSql + " and id !=" + disableComp;
|
|
|
|
|
}
|
|
|
|
|
if ("0".equals(level)){
|
|
|
|
|
level = "4";
|
|
|
|
|
}
|
|
|
|
|
findCompanyItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level));
|
|
|
|
|
|
|
|
|
|
// 分部数据,构建层级关系
|
|
|
|
@ -171,7 +191,7 @@ 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) {
|
|
|
|
|
String sql = "select id, fname, ftype, fparentid,fobjid,fecid,fnumber,fisvitual from jcl_org_map " + whereSql;
|
|
|
|
|
String sql = "select id, fname, ftype, fparentid, fleader, fleadername, fnumber, fobjid, fisvitual from jcl_org_map " + whereSql;
|
|
|
|
|
DetachUtil detachUtil = new DetachUtil(user);
|
|
|
|
|
if (detachUtil.isDETACH()) {
|
|
|
|
|
if ("0".equals(id)) {
|
|
|
|
@ -196,6 +216,17 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
item.put("fisvitual", rs.getString("fisvitual"));
|
|
|
|
|
item.put("expand", expand ? "1" : "0");
|
|
|
|
|
item.put("hasChildren", hasChildren(rs.getString("id"), true));
|
|
|
|
|
item.put("empNum", computeComOrDeptNums(rs.getString("ftype"), rs.getString("fobjid"), hasChildren(rs.getString("id"), true)));
|
|
|
|
|
if (rs.getString("ftype").equals("2")) {
|
|
|
|
|
JclOrgMap jclOrgMap = getBmfzrInfo(rs.getString("fleader"));
|
|
|
|
|
item.put("fleadername", jclOrgMap.getFLeaderName() == null ? "" : jclOrgMap.getFLeaderName());
|
|
|
|
|
}else{
|
|
|
|
|
item.put("fleadername", Utils.null2String(rs.getString("fleadername")));
|
|
|
|
|
}
|
|
|
|
|
item.put("fleader", Utils.null2String(rs.getString("fleader")));
|
|
|
|
|
if (Integer.parseInt(level) > 3){
|
|
|
|
|
level = String.valueOf(hasChildren(rs.getString("id"),true) ? Integer.parseInt(level)+1 : Integer.parseInt(level));
|
|
|
|
|
}
|
|
|
|
|
currentList.add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -250,6 +281,10 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
}
|
|
|
|
|
String root = (String) request2Map.get("root"); // 根节点
|
|
|
|
|
String level = (String) request2Map.get("level"); // 显示层级
|
|
|
|
|
String outKey = (String) request2Map.get("outkey");// 显示外部机构: 0不显示、1显示
|
|
|
|
|
if (StringUtils.isBlank(outKey)){
|
|
|
|
|
outKey = "0";
|
|
|
|
|
}
|
|
|
|
|
if (StringUtils.isBlank(level)) {
|
|
|
|
|
level = "3";
|
|
|
|
|
}
|
|
|
|
@ -298,7 +333,9 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
item.put("fisvitual", rs.getString("fisvitual"));
|
|
|
|
|
list.add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (outKey.equals("0")) {
|
|
|
|
|
whereSql = whereSql + " and id !=" + disableComp;
|
|
|
|
|
}
|
|
|
|
|
int currentLevel = 1;
|
|
|
|
|
findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level));
|
|
|
|
|
|
|
|
|
@ -366,7 +403,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
whereSql += " and fparentid in (" + ids + ") ";
|
|
|
|
|
|
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
|
|
rs.executeQuery("select id, fname, ftype, fparentid, fnumber,fobjid,fisvitual from jcl_org_map " + whereSql);
|
|
|
|
|
rs.executeQuery("select id, fname, ftype, fparentid, fleader, fleadername, fnumber,fobjid,fisvitual from jcl_org_map " + whereSql);
|
|
|
|
|
List<Map<String, Object>> currentList = new ArrayList<>();
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
Map<String, Object> item = new HashMap<>();
|
|
|
|
@ -378,6 +415,9 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
item.put("fobjid", rs.getString("fobjid"));
|
|
|
|
|
item.put("fisvitual", rs.getString("fisvitual"));
|
|
|
|
|
item.put("hasChildren", hasChildren(rs.getString("id"), true));
|
|
|
|
|
item.put("empNum", computeComOrDeptNums(rs.getString("ftype"), rs.getString("fobjid"), hasChildren(rs.getString("id"), true)));
|
|
|
|
|
item.put("fleadername", rs.getString("fleadername"));
|
|
|
|
|
item.put("fleader", rs.getString("fleader"));
|
|
|
|
|
currentList.add(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -486,6 +526,48 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
return !"0".equals(count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 计算分部、部门人数
|
|
|
|
|
private Integer computeComOrDeptNums( String ftype, String fobjid, boolean hasChildren) {
|
|
|
|
|
int nums = 0;
|
|
|
|
|
String id = null;
|
|
|
|
|
RecordSet recordSet = new RecordSet();
|
|
|
|
|
if (ftype.equals("2")) {
|
|
|
|
|
id = String.valueOf(100000000 + Integer.parseInt(fobjid));
|
|
|
|
|
String deptSql = "select count(1) as deptNums from hrmdepartment a " +
|
|
|
|
|
"inner join hrmresource b on a.id = b.departmentid and b.status<4 " +
|
|
|
|
|
"where a.id=";
|
|
|
|
|
recordSet.executeQuery(deptSql + fobjid);
|
|
|
|
|
while (recordSet.next()) {
|
|
|
|
|
nums = nums + Integer.parseInt(recordSet.getString("deptNums"));
|
|
|
|
|
}
|
|
|
|
|
} else if (ftype.equals("1")) {
|
|
|
|
|
id = fobjid;
|
|
|
|
|
String comSql = "select count(1) as deptNums from hrmsubcompany a " +
|
|
|
|
|
"inner join hrmresource b on a.id = b.subcompanyid1 and b.status<4 " +
|
|
|
|
|
"where a.id=";
|
|
|
|
|
recordSet.executeQuery(comSql + fobjid);
|
|
|
|
|
while (recordSet.next()) {
|
|
|
|
|
nums = nums + Integer.parseInt(recordSet.getString("deptNums"));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
// 查询下级(判断是否具有下级部门、分部)
|
|
|
|
|
String currentDate = OrganizationDateUtil.getFormatLocalDate(new java.util.Date());
|
|
|
|
|
java.sql.Date date = new java.sql.Date(OrganizationDateUtil.stringToDate(currentDate).getTime());
|
|
|
|
|
List<JclOrgMap> jclOrgMapList = getJclOrgMapMapper().getChildInfoById(id, ftype, date);
|
|
|
|
|
if (jclOrgMapList.size() > 0) {
|
|
|
|
|
for (JclOrgMap jclOrgMap : jclOrgMapList) {
|
|
|
|
|
String newType = Utils.null2String(jclOrgMap.getFType());
|
|
|
|
|
String childId = Utils.null2String(jclOrgMap.getFObjId());
|
|
|
|
|
if (newType.equals(ftype)) {
|
|
|
|
|
nums = nums + computeComOrDeptNums(newType, childId, hasChildren(String.valueOf(jclOrgMap.getId()),false));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return nums;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String convertLevel(String fLeaderLv) {
|
|
|
|
|
StringBuilder jobLevelName = new StringBuilder();
|
|
|
|
|
if (StringUtils.isNotBlank(fLeaderLv)) {
|
|
|
|
@ -557,7 +639,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
|
|
//同步部门信息
|
|
|
|
|
getJclOrgMapMapper().insertDeptToMap(level,grade);
|
|
|
|
|
//同步分部信息
|
|
|
|
|
getJclOrgMapMapper().insertSubComToMap();
|
|
|
|
|
getJclOrgMapMapper().insertSubComToMap(compLeader);
|
|
|
|
|
//同步集团信息
|
|
|
|
|
getJclOrgMapMapper().insertComToMap();
|
|
|
|
|
//清除部门合并、转移造成的脏数据
|
|
|
|
|