|
|
package com.engine.junchuang.service;
|
|
|
|
|
|
import cn.hutool.core.date.DateField;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.engine.core.impl.Service;
|
|
|
import com.engine.junchuang.util.OrganizationDateUtil;
|
|
|
import com.engine.junchuang.util.db.DBType;
|
|
|
import com.engine.junchuang.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;
|
|
|
|
|
|
public class OrgChartServiceImpl extends Service implements OrgChartService {
|
|
|
private RecordSet grs = new RecordSet();
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> getOptionCondition(Map<String, Object> request2Map, User user) {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
RecordSet rs = new RecordSet();
|
|
|
rs.executeQuery("select id, companyname from HrmCompanyVirtual order by id");
|
|
|
List<Map<String, Object>> fclasslist = new ArrayList<>();
|
|
|
Map<String, Object> defaultItem = new HashMap<>();
|
|
|
defaultItem.put("id", "0");
|
|
|
defaultItem.put("companyname", "行政维度");
|
|
|
fclasslist.add(defaultItem);
|
|
|
while (rs.next()) {
|
|
|
Map<String, Object> item = new HashMap<>();
|
|
|
item.put("id", rs.getString("id"));
|
|
|
item.put("companyname", rs.getString("companyname"));
|
|
|
fclasslist.add(item);
|
|
|
}
|
|
|
String sql = "select id, fnumber, fname, ftype from junc_org_map where ftype in (0, 1) ";
|
|
|
|
|
|
// 分部分权过滤
|
|
|
DetachUtil detachUtil = new DetachUtil(user.getUID());
|
|
|
if (detachUtil.isDETACH()) {
|
|
|
String jclRoleLevels = detachUtil.getJclRoleLevels();
|
|
|
if (StringUtils.isNotBlank(jclRoleLevels)) {
|
|
|
sql = "select id, fnumber, fname, ftype from junc_org_map where (ftype = 0 or (ftype = 1 and fobjid in(" + jclRoleLevels + "))) ";
|
|
|
} else {
|
|
|
sql = "select id, fnumber, fname, ftype from junc_org_map where ftype = 0 ";
|
|
|
}
|
|
|
}
|
|
|
rs.executeQuery(sql + " and fdateend > " + DBType.get(new RecordSet().getDBType()).currentDate() + " order by ftype , id,fdateend desc ");
|
|
|
Set<OrgSelectItem> companySet = new HashSet<>();
|
|
|
while (rs.next()) {
|
|
|
OrgSelectItem item = new OrgSelectItem();
|
|
|
item.setId(rs.getString("id"));
|
|
|
item.setFnumber(rs.getString("fnumber"));
|
|
|
item.setFname(rs.getString("fname"));
|
|
|
companySet.add(item);
|
|
|
}
|
|
|
result.put("api_status", true);
|
|
|
result.put("fclasslist", fclasslist);
|
|
|
result.put("companylist", companySet);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> getUserData(Map<String, Object> request2Map, User user) {
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("hasRight", true);
|
|
|
String root = (String) request2Map.get("root");// 根节点
|
|
|
String level = (String) request2Map.get("level");// 显示层级
|
|
|
if (StringUtils.isBlank(level)) {
|
|
|
level = "3";
|
|
|
}
|
|
|
String whereSql = userWhereSql(request2Map);
|
|
|
String whereItemSql = " ";
|
|
|
if ("0".equals(root)) { // 集团的情况
|
|
|
whereItemSql += " and t.ftype = 0 ";
|
|
|
} else {
|
|
|
whereItemSql += " and t.id = '" + root + "' ";
|
|
|
}
|
|
|
|
|
|
// 获取根节点
|
|
|
RecordSet rs = new RecordSet();
|
|
|
rs.executeQuery("select t.id, t.fname, t.ftype, t.fparentid, t.fleadername,t.fobjid,t.fecid, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber, t.fleader, t.fleaderlv, t.fleaderst, t.fecid, t.fisvitual from junc_org_map t " + whereSql + whereItemSql);
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
String id = null;
|
|
|
if (rs.next()) {
|
|
|
Map<String, Object> item = new HashMap<>();
|
|
|
id = rs.getString("id");
|
|
|
item.put("id", rs.getString("id"));
|
|
|
item.put("fname", rs.getString("fname"));
|
|
|
item.put("ftype", rs.getString("ftype"));
|
|
|
item.put("parentId", null);
|
|
|
if ("0".equals(id)) {
|
|
|
item.put("fleadername", "");
|
|
|
item.put("fleaderimg", "");
|
|
|
item.put("fleaderjob", "");
|
|
|
item.put("fleader", "");
|
|
|
} else {
|
|
|
item.put("fleadername", Util.null2String(rs.getString("fleadername")));
|
|
|
item.put("fleaderimg", Util.null2String(rs.getString("fleaderimg")));
|
|
|
item.put("fleaderjob", Util.null2String(rs.getString("fleaderjob")));
|
|
|
item.put("fleader", Util.null2String(rs.getString("fleader")));
|
|
|
|
|
|
}
|
|
|
item.put("fplan", rs.getString("fplan"));
|
|
|
item.put("fonjob", rs.getString("fonjob"));
|
|
|
item.put("hasChildren", hasChildren(rs.getString("id"), false));
|
|
|
item.put("expand", "1");
|
|
|
item.put("fnumber", rs.getString("fnumber"));
|
|
|
item.put("fobjid", rs.getString("fobjid"));
|
|
|
item.put("fecid", rs.getString("fecid"));
|
|
|
item.put("fisvitual", rs.getString("fisvitual"));
|
|
|
list.add(item);
|
|
|
}
|
|
|
|
|
|
int currentLevel = 1;
|
|
|
findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level));
|
|
|
|
|
|
// 分部数据,构建层级关系
|
|
|
reBuildTreeList(list, root);
|
|
|
|
|
|
result.put("api_status", true);
|
|
|
result.put("data", list);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Map<String, Object> asyncUserData(Map<String, Object> request2Map, User user) {
|
|
|
String ids = (String) request2Map.get("ids");
|
|
|
String whereSql = userWhereSql(request2Map);
|
|
|
|
|
|
whereSql += " and fparentid in (" + ids + ") ";
|
|
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
rs.executeQuery("select t.id, t.fname, t.ftype, t.fparentid, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber, t.fleader,t.fleaderlv, t.fleaderst,t.fobjid,t.fisvitual from junc_org_map t " + whereSql);
|
|
|
List<Map<String, Object>> currentList = new ArrayList<>();
|
|
|
while (rs.next()) {
|
|
|
Map<String, Object> item = new HashMap<>();
|
|
|
item.put("id", rs.getString("id"));
|
|
|
item.put("fname", rs.getString("fname"));
|
|
|
item.put("ftype", rs.getString("ftype"));
|
|
|
item.put("parentId", rs.getString("fparentid"));
|
|
|
item.put("fplan", rs.getString("fplan"));
|
|
|
item.put("fonjob", rs.getString("fonjob"));
|
|
|
item.put("fnumber", rs.getString("fnumber"));
|
|
|
item.put("hasChildren", hasChildren(rs.getString("id"), false));
|
|
|
item.put("fleader", rs.getString("fleader"));
|
|
|
item.put("fleaderimg", rs.getString("fleaderimg"));
|
|
|
item.put("fleadername", rs.getString("fleadername"));
|
|
|
item.put("fleaderjob", rs.getString("fleaderjob"));
|
|
|
item.put("fobjid", rs.getString("fobjid"));
|
|
|
item.put("fisvitual", rs.getString("fisvitual"));
|
|
|
currentList.add(item);
|
|
|
}
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
result.put("api_status", true);
|
|
|
result.put("data", currentList);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String syncOrgMapData(Map<String, Object> request2Map, User user) {
|
|
|
String currentDate = OrganizationDateUtil.getFormatLocalDate(new java.util.Date());
|
|
|
java.sql.Date date = new java.sql.Date(OrganizationDateUtil.stringToDate(currentDate).getTime());
|
|
|
Calendar cal = Calendar.getInstance();
|
|
|
cal.setTime(date);
|
|
|
Calendar calendar = weaver.common.DateUtil.addDay(cal, -1);
|
|
|
java.sql.Date yesterday = new java.sql.Date(calendar.getTime().getTime());
|
|
|
|
|
|
RecordSet rs = new RecordSet();
|
|
|
// 1、清空当天所有数据
|
|
|
rs.execute("delete from junc_org_map where fdatebegin = TO_DATE('"+date+"','yyyy-MM-dd')");
|
|
|
// 2、修改所有失效数据
|
|
|
rs.execute("update junc_org_map set fdateend=TO_DATE('"+yesterday+"','yyyy-MM-dd') where fdateend > TO_DATE('"+date+"','yyyy-MM-dd')");
|
|
|
// 3、同步集团数据
|
|
|
String jtSql = "INSERT INTO junc_org_map ( id, ftype, fobjid, uuid,fclass, fclassname, fnumber, fname,\n" +
|
|
|
" fleader, fleaderimg, fleadername, fleaderjobid, fleaderjob, fparentid,fobjparentid,\n" +
|
|
|
" fplan, fonjob, fisvitual, fdatebegin, fdateend)\n" +
|
|
|
" SELECT 0, 0, 0, uuid, 0, '行政维度', '00', companyname,\n" +
|
|
|
" 0, NULL, NULL, 0, NULL, -1, 0,\n" +
|
|
|
" 0, (select count(1) from hrmresource where status<4), 0, TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd') FROM hrmcompany";
|
|
|
rs.execute(jtSql);
|
|
|
// 4、同步分部数据
|
|
|
String fbSql = "insert into junc_org_map\n" +
|
|
|
" (id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleader,fleaderimg,\n" +
|
|
|
" fleadername,fleaderjobid,fleaderjob,fleaderlv,fleaderst,fparentid,fobjparentid,\n" +
|
|
|
" fplan,fonjob,fisvitual,fdatebegin,fdateend)\n" +
|
|
|
" select a.id,1,a.id,a.uuid,0,'行政维度', '',a.subcompanyname,null,'',\n" +
|
|
|
" '',NULL,'','','',nvl(a.supsubcomid,0),nvl(a.supsubcomid,0),\n" +
|
|
|
" 0,0,0,TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd') from hrmsubcompany a\n" +
|
|
|
" where nvl(a.canceled,0) <> 1";
|
|
|
rs.execute(fbSql);
|
|
|
// 5、同步部门数据
|
|
|
String bmSql = "insert into junc_org_map\n" +
|
|
|
"(id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleader,fleaderimg,\n" +
|
|
|
" fleadername,fleaderjobid,fleaderjob,fparentid,fobjparentid,\n" +
|
|
|
" fplan,fonjob,fisvitual,fdatebegin,fdateend)\n" +
|
|
|
"select a.id+100000000,2,a.id,a.uuid,0,'行政维度',a.DEPARTMENTCODE,a.departmentname,substr(b.bmfzr,0,instr(b.bmfzr,',',1)-1),c.messagerurl,\n" +
|
|
|
" c.lastname,c.jobtitle,d.jobtitlemark,\n" +
|
|
|
" (case nvl(a.supdepid,0) when 0 then a.subcompanyid1 else a.supdepid+100000000 end),\n" +
|
|
|
" (case nvl(a.supdepid,0) when 0 then a.subcompanyid1 else a.supdepid end),\n" +
|
|
|
" 0,0,0,TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd')\n" +
|
|
|
"from HrmDepartment a\n" +
|
|
|
"left join hrmdepartmentdefined b on a.id=b.deptid\n" +
|
|
|
"left join hrmresource c on to_char(substr(b.bmfzr,0,instr(b.bmfzr,',',1)-1))=to_char(c.ID)\n" +
|
|
|
"left join hrmjobtitles d on c.JOBTITLE=d.id\n" +
|
|
|
"where nvl(a.canceled,0) <> 1";
|
|
|
rs.execute(bmSql);
|
|
|
// 6、同步人员数据
|
|
|
String queryDept = "select id from hrmdepartment a where nvl(a.canceled,0)='0' ";
|
|
|
RecordSet recordSet = new RecordSet();
|
|
|
recordSet.execute(queryDept);
|
|
|
while (recordSet.next()){
|
|
|
String deptId = Util.null2String(recordSet.getString("id"));
|
|
|
// 处理部门(含子部门人数)
|
|
|
String getSupDeptSql = "select wm_concat(id) as allSupDept from hrmdepartment a start with a.id="+deptId+" connect by a.supdepid=prior a.id";
|
|
|
rs.execute(getSupDeptSql);
|
|
|
String allSupDeptIds = null;
|
|
|
if (rs.next()){
|
|
|
allSupDeptIds = Util.null2String(rs.getString("allSupDept"));
|
|
|
}
|
|
|
String getZrs = "select nvl(sum(zrs),0) zrs from (\n" +
|
|
|
"select a.departmentid,count(id) as zrs from hrmresource a where a.status<4 group by a.departmentid\n" +
|
|
|
") b where b.departmentid in ("+allSupDeptIds+")";
|
|
|
rs.execute(getZrs);
|
|
|
String zrs = "0";
|
|
|
if (rs.next()){
|
|
|
zrs = Util.null2String(rs.getString("zrs"));
|
|
|
}
|
|
|
rs.execute("update junc_org_map set fonjob = '"+zrs+"' where ftype=2 and fdateend>sysdate and fobjid="+deptId);
|
|
|
|
|
|
// 找出没有下级的人员
|
|
|
String noHaveChildSql = "select a.id,a.managerid from hrmresource a \n" +
|
|
|
"inner join (select id from hrmresource where departmentid='"+deptId+"'\n" +
|
|
|
"MINUS\n" +
|
|
|
"select managerid from hrmresource a \n" +
|
|
|
"where a.managerid in (select id from hrmresource where departmentid='"+deptId+"')\n" +
|
|
|
"and a.departmentid='"+deptId+"') b on a.id=b.id";
|
|
|
rs.execute(noHaveChildSql);
|
|
|
while (rs.next()){
|
|
|
String id = Util.null2String(rs.getString("id"));
|
|
|
String managerid = Util.null2String(rs.getString("managerid"));
|
|
|
handleSuperior(id,managerid,deptId);
|
|
|
}
|
|
|
}
|
|
|
// 7、删除重复人员上级
|
|
|
String deleRepeatSql = "delete from junc_org_map\n" +
|
|
|
" where fobjid in (select fobjid\n" +
|
|
|
" from junc_org_map a\n" +
|
|
|
" where a.ftype = 3\n" +
|
|
|
" and a.fdateend > TO_DATE(to_char(SYSDATE, 'yyyy-MM-dd'),\n" +
|
|
|
" 'yyyy-MM-dd')\n" +
|
|
|
" group by fobjid\n" +
|
|
|
" having count(fobjid) > 1)\n" +
|
|
|
" and rowid not in\n" +
|
|
|
" (select min(rowid)\n" +
|
|
|
" from junc_org_map a\n" +
|
|
|
" where a.ftype = 3\n" +
|
|
|
" and a.fdateend >\n" +
|
|
|
" TO_DATE(to_char(SYSDATE, 'yyyy-MM-dd'), 'yyyy-MM-dd')\n" +
|
|
|
" group by a.fobjid\n" +
|
|
|
" having count(*) > 1) and ftype=3\n";
|
|
|
rs.execute(deleRepeatSql);
|
|
|
// 8、同步分部人数
|
|
|
String queryAllSubCompanySql = "select id,subcompanyname,supsubcomid from hrmsubcompany a where nvl(a.canceled,0)='0'";
|
|
|
rs.execute(queryAllSubCompanySql);
|
|
|
while (rs.next()) {
|
|
|
recordSet.execute("update junc_org_map set fonjob = (\n" +
|
|
|
"select nvl(sum(fbrs),0) fbrs from (\n" +
|
|
|
"select subcompanyid1,count(id) fbrs from hrmresource where status<4 group by subcompanyid1) \n" +
|
|
|
"where subcompanyid1 in (select id from hrmsubcompany a start with a.id="+rs.getString("id")+" connect by a.supsubcomid=prior a.id)) \n" +
|
|
|
"where ftype=1 and fdateend>sysdate and fobjid="+rs.getString("id"));
|
|
|
}
|
|
|
return "同步成功";
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @Author ml
|
|
|
* @Date 2023/3/7 15:47
|
|
|
* @Description 处理上级
|
|
|
*/
|
|
|
private void handleSuperior(String id,String managerid,String deptId){
|
|
|
// 校验当前人员的直接上级是否在同一部门,如不在当前部门,map表中的上级应为部门id+
|
|
|
RecordSet rs = new RecordSet();
|
|
|
Boolean flag = checkManager(rs,managerid,deptId);
|
|
|
if (flag) {
|
|
|
|
|
|
rs.execute("insert into junc_org_map\n" +
|
|
|
" (id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,\n" +
|
|
|
" fleaderjobid,fleaderjob,fparentid,fobjparentid,\n" +
|
|
|
" fisvitual,fdatebegin,fdateend)\n" +
|
|
|
"select a.id+200000000,3,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,\n" +
|
|
|
" b.id,b.jobtitlename, nvl( a.managerid, '' ) +200000000,a.managerid,\n" +
|
|
|
" 0,TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd')\n" +
|
|
|
"from hrmresource a\n" +
|
|
|
"left join hrmjobtitles b on a.jobtitle=b.id\n" +
|
|
|
"where a.status < 4 and a.id='"+id+"'");
|
|
|
// 找上级的上级
|
|
|
rs.execute("select id,managerid,departmentid from hrmresource where id='"+managerid+"'");
|
|
|
if (rs.next()){
|
|
|
String supId = Util.null2String(rs.getString("id"));
|
|
|
String supManagerId = Util.null2String(rs.getString("managerid"));
|
|
|
String departmentid = Util.null2String(rs.getString("departmentid"));
|
|
|
handleSuperior(supId,supManagerId,departmentid);
|
|
|
}
|
|
|
} else {
|
|
|
rs.execute("insert into junc_org_map\n" +
|
|
|
" (id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,\n" +
|
|
|
" fleaderjobid,fleaderjob,fparentid,fobjparentid,\n" +
|
|
|
" fisvitual,fdatebegin,fdateend)\n" +
|
|
|
"select a.id+200000000,3,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,\n" +
|
|
|
" b.id,b.jobtitlename, nvl( a.departmentid, '' ) +100000000,a.departmentid,\n" +
|
|
|
" 0,TO_DATE(to_char(SYSDATE,'yyyy-MM-dd'),'yyyy-MM-dd'), TO_DATE('2099-12-31','yyyy-MM-dd')\n" +
|
|
|
"from hrmresource a\n" +
|
|
|
"left join hrmjobtitles b on a.jobtitle=b.id\n" +
|
|
|
"where a.status < 4 and a.id='"+id+"'");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @Author ml
|
|
|
* @Date 2023/3/7 17:14
|
|
|
* @Description 校验上级是否在当前部门
|
|
|
*/
|
|
|
private Boolean checkManager(RecordSet recordSet,String managerid,String deptId){
|
|
|
Boolean flag = false;
|
|
|
recordSet.execute("select departmentid from hrmresource where id='"+managerid+"'");
|
|
|
if (recordSet.next()){
|
|
|
if (deptId.equals(Util.null2String(recordSet.getString("departmentid")))) {
|
|
|
flag = true;
|
|
|
}
|
|
|
}
|
|
|
return flag;
|
|
|
}
|
|
|
|
|
|
private String userWhereSql(Map<String, Object> request2Map) {
|
|
|
// 数据日期
|
|
|
String date = (String) request2Map.get("date");
|
|
|
if (StringUtils.isBlank(date)) {
|
|
|
date = DateUtil.format(DateUtil.offset(new Date(), DateField.DAY_OF_MONTH, 1), "yyyy-MM-dd");
|
|
|
}
|
|
|
// 维度
|
|
|
String fclass = (String) request2Map.get("fclass");
|
|
|
// 是否显示虚拟组织
|
|
|
String fisvitual = (String) request2Map.get("fisvitual");
|
|
|
if (StringUtils.isBlank(fisvitual)) {
|
|
|
fisvitual = "0";
|
|
|
}
|
|
|
|
|
|
String whereSql = " where 1 = 1 ";
|
|
|
if (DBType.isOracle()) {
|
|
|
whereSql += " and ((t.fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and t.fdateend >= to_date('" + date + "','yyyy-MM-DD')) or (t.fdatebegin <= to_date('" + date + "','yyyy-MM-DD') and t.fdateend is null )) ";
|
|
|
} else {
|
|
|
whereSql += " and ((t.fdatebegin <= '" + date + "' and t.fdateend >= '" + date + "') or (t.fdatebegin <= '" + date + "' and t.fdateend is null )) ";
|
|
|
}
|
|
|
whereSql += " and t.fclass = " + fclass + " ";
|
|
|
|
|
|
if ("0".equals(fisvitual)) {
|
|
|
whereSql += " and t.fisvitual = 0 ";
|
|
|
} else {
|
|
|
whereSql += " and t.fisvitual in (0, 1) ";
|
|
|
}
|
|
|
return whereSql;
|
|
|
}
|
|
|
|
|
|
private boolean hasChildren(String id, boolean isCompany) {
|
|
|
String whereSql = " where fparentid = " + id + " ";
|
|
|
if (isCompany) {
|
|
|
whereSql += " and ftype in (0, 1, 2) ";
|
|
|
}
|
|
|
grs.executeQuery("select count(1) as count from junc_org_map " + whereSql);
|
|
|
String count = "0";
|
|
|
if (grs.next()) {
|
|
|
count = grs.getString("count");
|
|
|
}
|
|
|
return !"0".equals(count);
|
|
|
}
|
|
|
|
|
|
private String getFieldName(String fieldabel) {
|
|
|
RecordSet recordSet = new RecordSet();
|
|
|
String fieldname = null;
|
|
|
recordSet.executeQuery("select fieldname from jcl_org_field where fieldlabel='" + fieldabel+"'");
|
|
|
if (recordSet.next()) {
|
|
|
fieldname = recordSet.getString("fieldname");
|
|
|
}
|
|
|
return fieldname;
|
|
|
}
|
|
|
|
|
|
private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List<Map<String, Object>> list, String whereSql, boolean expand) {
|
|
|
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, t.fisvitual from junc_org_map t " + whereSql;
|
|
|
DetachUtil detachUtil = new DetachUtil(user.getUID());
|
|
|
if (detachUtil.isDETACH()) {
|
|
|
if ("0".equals(id)) {
|
|
|
sql += " and t.ftype = 1 and t.fobjid in(" + detachUtil.getJclRoleLevels() + ")";
|
|
|
} else {
|
|
|
sql += " and t.fparentid = " + id + " and t.ftype !=1";
|
|
|
}
|
|
|
} else {
|
|
|
sql += " and t.fparentid = " + id;
|
|
|
}
|
|
|
rs.executeQuery(sql);
|
|
|
List<Map<String, Object>> currentList = new ArrayList<>();
|
|
|
while (rs.next()) {
|
|
|
Map<String, Object> item = new HashMap<>();
|
|
|
item.put("id", rs.getString("id"));
|
|
|
item.put("fname", rs.getString("fname"));
|
|
|
item.put("ftype", rs.getString("ftype"));
|
|
|
item.put("parentId", rs.getString("fparentid"));
|
|
|
item.put("fobjparentId", rs.getString("fobjparentid"));
|
|
|
item.put("fplan", rs.getString("fplan"));
|
|
|
item.put("fonjob", rs.getString("fonjob"));
|
|
|
item.put("fnumber", rs.getString("fnumber"));
|
|
|
item.put("expand", expand ? "1" : "0");
|
|
|
item.put("fobjid", rs.getString("fobjid"));
|
|
|
item.put("fecid", rs.getString("fecid"));
|
|
|
item.put("fleader", rs.getString("fleader"));
|
|
|
item.put("fleaderimg", rs.getString("fleaderimg"));
|
|
|
item.put("fleadername", rs.getString("fleadername"));
|
|
|
item.put("fleaderjob", rs.getString("fleaderjob"));
|
|
|
|
|
|
item.put("fisvitual", rs.getString("fisvitual"));
|
|
|
item.put("hasChildren", hasChildren(rs.getString("id"), false));
|
|
|
currentList.add(item);
|
|
|
}
|
|
|
|
|
|
for (Map<String, Object> stringObjectMap : currentList) {
|
|
|
if ("4".equals(stringObjectMap.get("ftype"))) { // 员工信息
|
|
|
rs.executeQuery("select id, mobile, homeaddress from hrmresource where id = ? ", stringObjectMap.get("fnumber"));
|
|
|
if (rs.next()) {
|
|
|
stringObjectMap.put("mobile", rs.getString("mobile"));
|
|
|
stringObjectMap.put("address", rs.getString("homeaddress"));
|
|
|
}
|
|
|
rs.executeQuery("select departmentname from hrmresource hrm \n" +
|
|
|
"left join hrmdepartment d\n" +
|
|
|
"on hrm.departmentid = d.id\n" +
|
|
|
"where hrm.id = ? ", stringObjectMap.get("fnumber"));
|
|
|
if (rs.next()) {
|
|
|
stringObjectMap.put("department", rs.getString("departmentname"));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
if (currentLevel + 1 <= Integer.parseInt(level)) {
|
|
|
findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, true);
|
|
|
} else if (currentLevel == Integer.parseInt(level)) { // 多查一层
|
|
|
findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, false);
|
|
|
}
|
|
|
}
|
|
|
list.addAll(currentList);
|
|
|
}
|
|
|
|
|
|
private void reBuildTreeList(List<Map<String, Object>> list, String root) {
|
|
|
// 分部数据,构建层级关系
|
|
|
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 (!root.equals(Util.null2String(item.get("id"))) && "1".equals(Util.null2String(item.get("ftype"))) && !idSet.contains(Util.null2String(item.get("parentId")))) {
|
|
|
item.put("parentId", root);
|
|
|
item.put("fobjparentId", root);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
static class OrgSelectItem {
|
|
|
private String id;
|
|
|
private String fnumber;
|
|
|
private String fname;
|
|
|
public String getId() {
|
|
|
return id;
|
|
|
}
|
|
|
public void setId(String id) {
|
|
|
this.id = id;
|
|
|
}
|
|
|
public String getFnumber() {
|
|
|
return fnumber;
|
|
|
}
|
|
|
public void setFnumber(String fnumber) {
|
|
|
this.fnumber = fnumber;
|
|
|
}
|
|
|
public String getFname() {
|
|
|
return fname;
|
|
|
}
|
|
|
public void setFname(String fname) {
|
|
|
this.fname = fname;
|
|
|
}
|
|
|
}
|
|
|
}
|