From fb415853fd0b407d47425ee83b61bac81a6b13f2 Mon Sep 17 00:00:00 2001 From: Chengliang <1546584672@qq.com> Date: Fri, 10 May 2024 16:37:10 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=BA=E8=83=9C=E7=BB=84=E7=BB=87=E6=9E=B6?= =?UTF-8?q?=E6=9E=84=E5=9B=BE=E8=99=9A=E6=8B=9F=E7=BB=B4=E5=BA=A6=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=80=BC=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/chart/CompanyTreePO.java | 1 + .../service/impl/ChartServiceImpl.java | 27 ++++++++++- .../service/impl/OrgChartServiceImpl.java | 47 +++++++++---------- 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/com/engine/organization/entity/chart/CompanyTreePO.java b/src/com/engine/organization/entity/chart/CompanyTreePO.java index ce287e19..f153b0ea 100644 --- a/src/com/engine/organization/entity/chart/CompanyTreePO.java +++ b/src/com/engine/organization/entity/chart/CompanyTreePO.java @@ -24,6 +24,7 @@ public class CompanyTreePO { private boolean disabled; private int level; private int depth; + private int showorder; public boolean getIsLeaf() { return isLeaf; diff --git a/src/com/engine/organization/service/impl/ChartServiceImpl.java b/src/com/engine/organization/service/impl/ChartServiceImpl.java index 1042b712..a67f48f4 100644 --- a/src/com/engine/organization/service/impl/ChartServiceImpl.java +++ b/src/com/engine/organization/service/impl/ChartServiceImpl.java @@ -85,13 +85,17 @@ public class ChartServiceImpl extends Service implements ChartService { return result; } + + Map map = getRootAndFclass(); + // 根结点 String root = Util.null2String(params.get("root")); root = StringUtils.isBlank(root) ? "0" : root; // 维度 String dimension = Util.null2String(params.get("fclass")); - dimension = StringUtils.isBlank(dimension) ? "0" : dimension; + //dimension = StringUtils.isBlank(dimension) ? "0" : dimension; + dimension = StringUtils.isBlank(dimension) ? map.get("fclass") : dimension; // 是否展示虚拟组织 String isVirtual = Util.null2String(params.get("fisvitual")); @@ -1857,4 +1861,25 @@ public class ChartServiceImpl extends Service implements ChartService { .colorCheck(colorCheck) .build(); } + + /** + * 获取 showorder 最小虚拟维度 和 最小分部 + * @return + */ + private Map getRootAndFclass(){ + Map map = new HashMap<>(); + RecordSet rs = new RecordSet(); + String fclass = "0"; + rs.executeQuery("select id from HrmCompanyVirtual order by showorder asc"); + if(rs.next()) { + fclass = Util.null2String(rs.getString("id")); + map.put("fclass",fclass); + } + + rs.executeQuery("select id from hrmsubcompanyvirtual where companyid = ? order by showorder asc",fclass); + if (rs.next()) { + map.put("root",Util.null2String(rs.getString("id"))); + } + return map; + } } diff --git a/src/com/engine/organization/service/impl/OrgChartServiceImpl.java b/src/com/engine/organization/service/impl/OrgChartServiceImpl.java index b2b3feff..99b1fc3f 100644 --- a/src/com/engine/organization/service/impl/OrgChartServiceImpl.java +++ b/src/com/engine/organization/service/impl/OrgChartServiceImpl.java @@ -41,44 +41,42 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { public Map getOptionCondition(Map request2Map, User user) { Map result = new HashMap<>(); RecordSet rs = new RecordSet(); - Map defaultItem = new HashMap<>(); + Map defaultItem = new HashMap<>(4); rs.executeQuery("select companyname from hrmcompany"); rs.next(); int fkey = 0; defaultItem.put("key", fkey++); defaultItem.put("id", "0"); defaultItem.put("companyname", Util.null2String(rs.getString("companyname"))); - rs.executeQuery("select id, companyname from HrmCompanyVirtual order by id"); + rs.executeQuery("select id, companyname,showorder from HrmCompanyVirtual order by id"); List> fclasslist = new ArrayList<>(); fclasslist.add(defaultItem); while (rs.next()) { - Map item = new HashMap<>(); + Map item = new HashMap<>(4); item.put("key", fkey++); item.put("id", rs.getString("id")); item.put("companyname", rs.getString("companyname")); + float showorder = Util.getFloatValue(rs.getString("showorder")); + item.put("showorder", (int) showorder); fclasslist.add(item); } - List companyTree = new ArrayList<>(); - String sql = "select id as id, id as value, subcompanyname as title, supsubcomid as pId from hrmsubcompany where (canceled is null or canceled != '1') and " + DBType.get(new RecordSet().getDBType()).ifNull("supsubcomid", "0") + " = '0'"; - // 一级分部数据分权处理 - String dimension = Util.null2String(request2Map.get("fclass")); - //版本id - String id = Util.null2String(request2Map.get("id")); - boolean isRealDimension = StringUtils.isBlank(dimension) || "0".equals(dimension); - boolean isRealTime = StringUtils.isBlank(id) || "0".equals(id); - if (isRealTime && user.getUID() != 1 && isRealDimension) { - DetachUtil detachUtil = new DetachUtil(user); - if(detachUtil.isDETACH()) { - String ids = detachUtil.getJclRoleLevels(); - sql = sql + " and id in (" + ids + ")"; - } - } + Optional> minCompany = fclasslist.stream() + .filter(map -> map.containsKey("showorder")) + .min(Comparator.comparingInt(map -> (int) map.get("showorder"))); + + minCompany.ifPresent(map -> result.put("fclass", map.get("id"))); + + Map params = new HashMap<>(2); + params.put("fclass",result.get("fclass")); + Map subCompanyTree = getSubCompanyTree(params); + List companyTree = (List)subCompanyTree.get("companyTree"); + + Optional minElement = companyTree.stream() + .min(Comparator.comparingInt(CompanyTreePO::getShoworder)); + + minElement.ifPresent(companyTreePO -> result.put("root",companyTreePO.getId())); - rs.executeQuery(sql); - while (rs.next()) { - companyTree.add(CompanyTreePO.builder().id(rs.getString("id")).pId(rs.getString("pId")).value(rs.getString("value")).title(rs.getString("title")).isLeaf(judgeTreeLeaf("select id from hrmsubcompany where (canceled is null or canceled != '1') and supsubcomid = ?", rs.getString("id"))).build()); - } result.put("api_status", true); result.put("fclasslist", fclasslist); result.put("companyTree", companyTree); @@ -116,7 +114,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { } } if (StringUtils.isNotBlank(fclass) && !"0".equals(fclass)) { - sql = "select id as id, id as value, subcompanyname as title, supsubcomid as pId from hrmsubcompanyvirtual where (canceled is null or canceled != '1') and " + DBType.get(new RecordSet().getDBType()).ifNull("supsubcomid", "0") + " = ? and companyid = '" + fclass + "'"; + sql = "select id as id, id as value, subcompanyname as title, supsubcomid as pId,showorder from hrmsubcompanyvirtual where (canceled is null or canceled != '1') and " + DBType.get(new RecordSet().getDBType()).ifNull("supsubcomid", "0") + " = ? and companyid = '" + fclass + "'"; } } else { sql = "select subcompanyid as id, id as value, subcompanyname as title, supsubcompanyid as pId from jcl_chart_subcompany where (canceled is null or canceled != '1') and " + DBType.get(new RecordSet().getDBType()).ifNull("supsubcompanyid", "0") + " = ? "; @@ -129,7 +127,8 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { } rs.executeQuery(sql, subcompany); while (rs.next()) { - companyTree.add(CompanyTreePO.builder().id(rs.getString("id")).pId(rs.getString("pId")).value(rs.getString("value")).title(rs.getString("title")).isLeaf(judgeTreeLeaf(judgeTreeLeafSql, rs.getString("id"))).build()); + float showorder = Util.getFloatValue(rs.getString("showorder")); + companyTree.add(CompanyTreePO.builder().id(rs.getString("id")).pId(rs.getString("pId")).value(rs.getString("value")).title(rs.getString("title")).isLeaf(judgeTreeLeaf(judgeTreeLeafSql, rs.getString("id"))).showorder((int)showorder).build()); }