From 1522935517e6249fc241cf229146c113e7129cd5 Mon Sep 17 00:00:00 2001 From: Mlin Date: Mon, 10 Jul 2023 11:05:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=98=89=E5=85=86bug=E4=BC=98=E5=8C=960710?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/OrgChartServiceImpl.java | 193 ++++++++++++++---- 1 file changed, 152 insertions(+), 41 deletions(-) diff --git a/src/com/engine/organization/service/impl/OrgChartServiceImpl.java b/src/com/engine/organization/service/impl/OrgChartServiceImpl.java index 403c3116..1b362f9f 100644 --- a/src/com/engine/organization/service/impl/OrgChartServiceImpl.java +++ b/src/com/engine/organization/service/impl/OrgChartServiceImpl.java @@ -270,6 +270,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { 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 jcl_org_map t " + whereSql + whereItemSql); List> list = new ArrayList<>(); String id = null; + String type = "0"; if (rs.next()) { Map item = new HashMap<>(); id = rs.getString("id"); @@ -302,7 +303,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { } int currentLevel = 1; - findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level)); + findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, currentLevel + 1 <= Integer.parseInt(level),type,null); // 分部数据,构建层级关系 reBuildTreeList(list, root); @@ -315,23 +316,60 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { @Override public Map asyncUserData(Map request2Map, User user) { String ids = (String) request2Map.get("ids"); - String whereSql = userWhereSql(request2Map); - - whereSql += " and fparentid in (" + ids + ") "; - + String[] split = ids.split(","); + String sql = "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 jcl_org_map t "; 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 jcl_org_map t " + whereSql); List> currentList = new ArrayList<>(); + DetachUtil detachUtil = new DetachUtil(user); + for (String id:split) { + String whereSql = userWhereSql(request2Map); + String deptLeader = ""; + if (id.contains("_")) { + whereSql += " and t.id != '" + id.split("_")[1] + "'"; + + } else if (Integer.parseInt(id) > 100000000 && Integer.parseInt(id) < 200000000) { + rs.executeQuery(sql + whereSql + " and id = ? ", id); + if (rs.next()) { + deptLeader = rs.getString("fleader"); + } + } + + if (detachUtil.isDETACH()) { + if ("0".equals(id)) { + whereSql += " and t.ftype = 1 and t.fobjid in(" + detachUtil.getJclRoleLevels() + ")"; + } else { + if (StringUtils.isNotBlank(deptLeader)) { + deptLeader = deptLeader.split(",")[0]; + whereSql += " and t.ftype = 3 and fobjid = '" + deptLeader + "' "; + deptLeader = String.valueOf(200000000 + Integer.parseInt(deptLeader)); + } else { + whereSql += " and t.fparentid = " + id.split("_")[0] + " and ((t.ftype =1 and t.fobjid in(" + detachUtil.getJclRoleLevels() + ")) or (t.ftype =2 ) or (t.ftype = 3 ))"; + } + } + } else { + if (StringUtils.isNotBlank(deptLeader)) { + deptLeader = deptLeader.split(",")[0]; + whereSql += " and t.ftype = 3 and fobjid = '" + deptLeader + "' "; + deptLeader = String.valueOf(200000000 + Integer.parseInt(deptLeader)); + } else { + if (checkDeptManager(id.split("_")[0])){ + whereSql += " and t.fparentid = "+ id.split("_")[0] +" or t.fparentid = "+ id.split("_")[1]; + }else{ + whereSql += " and t.fparentid = "+ id.split("_")[0]; + } + } + } + rs.executeQuery(sql + whereSql); while (rs.next()) { Map 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("parentId", id.contains("_") ? id : 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("hasChildren", hasChildren(rs.getString("id"), false)); if (rs.getString("ftype").equals("2")) { JclOrgMap jclOrgMap = getBmfzrInfo(rs.getString("fleader")); item.put("fleader", jclOrgMap.getFLeader() == null ? "" : String.valueOf(jclOrgMap.getFLeader())); @@ -350,10 +388,19 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { } item.put("fobjid", rs.getString("fobjid")); item.put("fisvitual", rs.getString("fisvitual")); + if (deptLeader.equals(item.get("id"))) { + item.put("id", id + "_" + deptLeader); + item.put("parentId", id); + item.put("hasChildren", hasChildren(id, false)); + item.put("this_dept",checkDeptManager(id)?1:0); + + } else { + item.put("hasChildren", hasChildren(rs.getString("id"), false)); + } currentList.add(item); } - + } Map result = new HashMap<>(); result.put("api_status", true); result.put("data", currentList); @@ -402,17 +449,47 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { return jclOrgMap; } - private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List> list, String whereSql, boolean expand) { + private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List> list, String whereSql, boolean expand, String type, String parentDeptId) { 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 jcl_org_map t " + whereSql; + String deptLeader = ""; + String manageDeptId = ""; + if ("2".equals(type)) { + rs.executeQuery(sql +" and t.ftype = '2' and t.fobjid = '" + parentDeptId + "'"); + if (rs.next()) { + deptLeader = rs.getString("fleader"); + } + } + + if ("3".equals(type)) { + manageDeptId = id; + id = id.split("_")[0]; + //sql += " and ftype = 3 "; + if (manageDeptId.contains("_")) { + sql += " and t.id != '" + manageDeptId.split("_")[1] + "'"; + } + } + DetachUtil detachUtil = new DetachUtil(user); if (detachUtil.isDETACH()) { if ("0".equals(id)) { - sql += " and t.ftype = 1 and t.fobjid in(" + detachUtil.getJclRoleLevels() + ")"; + sql += " and t.ftype = 1 and t.fparentid = " + id + " and t.fobjid in(" + detachUtil.getJclRoleLevels() + ")"; } else { - sql += " and t.fparentid = " + id + " and t.ftype !=1"; + if (StringUtils.isNotBlank(deptLeader)) { + deptLeader = deptLeader.split(",")[0]; + sql += " and t.ftype = 3 and fobjid = '" + deptLeader + "' "; + deptLeader = String.valueOf(200000000 + Integer.parseInt(deptLeader)); + } else { + sql += " and t.fparentid = " + id + " and ((t.ftype =1 and t.fobjid in(" + detachUtil.getJclRoleLevels() + ")) or (t.ftype =2) or (t.ftype = 3 ))"; + } } } else { - sql += " and t.fparentid = " + id; + if (StringUtils.isNotBlank(deptLeader)) { + deptLeader = deptLeader.split(",")[0]; + sql += " and t.ftype = 3 and fobjid = '" + deptLeader + "' "; + deptLeader = String.valueOf(200000000 + Integer.parseInt(deptLeader)); + } else { + sql += " and t.fparentid = " + id; + } } rs.executeQuery(sql); List> currentList = new ArrayList<>(); @@ -421,7 +498,11 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { item.put("id", rs.getString("id")); item.put("fname", rs.getString("fname")); item.put("ftype", rs.getString("ftype")); - item.put("parentId", rs.getString("fparentid")); + if ("3".equals(type)) { + item.put("parentId", manageDeptId); + } else { + item.put("parentId", rs.getString("fparentid")); + } item.put("fobjparentId", rs.getString("fobjparentid")); item.put("fplan", rs.getString("fplan")); item.put("fonjob", rs.getString("fonjob")); @@ -429,6 +510,8 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { item.put("expand", expand ? "1" : "0"); item.put("fobjid", rs.getString("fobjid")); item.put("fecid", rs.getString("fecid")); + + if (rs.getString("ftype").equals("2")) { JclOrgMap jclOrgMap = getBmfzrInfo(rs.getString("fleader")); item.put("fleader", jclOrgMap.getFLeader() == null ? "" : String.valueOf(jclOrgMap.getFLeader())); @@ -446,30 +529,38 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { item.put("fleaderst", convertGrade(rs.getString("fleaderst"))); } item.put("fisvitual", rs.getString("fisvitual")); - item.put("hasChildren", hasChildren(rs.getString("id"), false)); + if (deptLeader.equals(item.get("id"))) { + item.put("id", id + "_" + deptLeader); + item.put("parentId", id); + item.put("hasChildren", hasChildren(id, false)); + item.put("this_dept",checkDeptManager(id)?1:0); + } else { + item.put("hasChildren", hasChildren(rs.getString("id"), false)); + } currentList.add(item); } for (Map 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 ("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")); +// } +// +// } + String fType = Util.null2String(stringObjectMap.get("ftype")); if (currentLevel + 1 <= Integer.parseInt(level)) { - findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, true); + findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, true, fType, Util.null2String(stringObjectMap.get("fobjid"))); } else if (currentLevel == Integer.parseInt(level)) { // 多查一层 - findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, false); + findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, false, fType, Util.null2String(stringObjectMap.get("fobjid"))); } } list.addAll(currentList); @@ -563,7 +654,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { //同步岗位信息 // getJclOrgMapMapper().insertJobToMap(); // 同步部门负责人 - getJclOrgMapMapper().insertBmfzrToMapJZ(level,grade); +// getJclOrgMapMapper().insertBmfzrToMapJZ(level,grade); RecordSet rs = new RecordSet(); // rs.execute("select c.id,a.id as departmentid from hrmdepartment a \n" + // "inner join hrmdepartmentdefined b on a.id=b.DEPTID\n" + @@ -630,17 +721,17 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { String deleRepeatSql = "delete from jcl_org_map\n" + " where fobjid in (select fobjid\n" + " from jcl_org_map a\n" + - " where a.ftype = 4\n" + + " where a.ftype = 3\n" + " and a.fdateend > convert(varchar(100),getDate(),23)" + " group by fobjid\n" + " having count(fobjid) > 1)\n" + " and fid not in\n" + " (select min(fid)\n" + " from jcl_org_map a\n" + - " where a.ftype = 4\n" + + " where a.ftype = 3\n" + " and a.fdateend >convert(varchar(100),getDate(),23)" + " group by a.fobjid\n" + - " having count(*) > 1) and ftype=4\n"; + " having count(*) > 1) and ftype=3\n"; rs.execute(deleRepeatSql); // 8、同步分部人数 String queryAllSubCompanySql = "select id,subcompanyname,supsubcomid from hrmsubcompany a where isnull(a.canceled,0)='0'"; @@ -683,8 +774,8 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { " (id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,\n" + " fleaderjobid,fleaderjob,fparentid,fobjparentid,\n" + " fisvitual,fdatebegin,fdateend)\n" + - "select a.id+300000000,4,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,\n" + - " b.id,b.jobtitlename, isnull( a.managerid, '' ) +300000000,a.managerid,\n" + + "select a.id+200000000,3,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,\n" + + " b.id,b.jobtitlename, isnull( a.managerid, '' ) +200000000,a.managerid,\n" + " 0,convert(varchar(100),getDate(),23), '2099-12-31'\n" + "from hrmresource a\n" + "left join hrmjobtitles b on a.jobtitle=b.id\n" + @@ -702,12 +793,11 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { " (id,ftype,fobjid,uuid,fclass,fclassname,fnumber,fname,fleaderimg,\n" + " fleaderjobid,fleaderjob,fparentid,fobjparentid,\n" + " fisvitual,fdatebegin,fdateend)\n" + - "select a.id+300000000,4,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,\n" + - " b.id,b.jobtitlename, isnull( cast(c.BMFZR as varchar(10)), '' ) +200000000,cast(c.BMFZR as varchar(10)),\n" + + "select a.id+200000000,3,a.id,a.uuid,0,'行政维度',a.workcode,a.LASTNAME,a.messagerurl,\n" + + " b.id,b.jobtitlename, isnull( a.departmentid, '' ) +100000000,a.departmentid,\n" + " 0,convert(varchar(100),getDate(),23), '2099-12-31'\n" + "from hrmresource a\n" + "left join hrmjobtitles b on a.jobtitle=b.id\n" + - "left join hrmdepartmentdefined c on a.departmentid=c.deptid\n"+ "where a.status < 4 and a.id='" + id + "'"); } } @@ -728,6 +818,27 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { return flag; } + private Boolean checkDeptManager(String id) { + RecordSet recordSet = new RecordSet(); + boolean flag = false; + recordSet.executeQuery("select fleader,fobjid,ftype from jcl_org_map where id = "+id); + String fleader = ""; + String fobjid = ""; + String ftype = ""; + if (recordSet.next()){ + fleader = recordSet.getString("fleader"); + fobjid = recordSet.getString("fobjid"); + ftype = recordSet.getString("ftype"); + } + recordSet.execute("select departmentid from hrmresource where id='" + fleader + "'"); + if (recordSet.next()) { + if (fobjid.equals(Util.null2String(recordSet.getString("departmentid")))) { + flag = true; + } + } + return flag; + } + /** * 刷新在岗、编制数 */