diff --git a/src/com/engine/organization/entity/chart/CompanyTreePO.java b/src/com/engine/organization/entity/chart/CompanyTreePO.java index 9a358082..c5c3dd1e 100644 --- a/src/com/engine/organization/entity/chart/CompanyTreePO.java +++ b/src/com/engine/organization/entity/chart/CompanyTreePO.java @@ -21,6 +21,7 @@ public class CompanyTreePO { private String title; private boolean isLeaf; private String key; + private boolean disabled; public boolean getIsLeaf() { return isLeaf; @@ -33,4 +34,8 @@ public class CompanyTreePO { public String getKey() { return id; } + + public String getValue() { + return id; + } } diff --git a/src/com/engine/organization/entity/chart/TreeSelect.java b/src/com/engine/organization/entity/chart/TreeSelect.java index fed41471..8e3da768 100644 --- a/src/com/engine/organization/entity/chart/TreeSelect.java +++ b/src/com/engine/organization/entity/chart/TreeSelect.java @@ -1,5 +1,6 @@ package com.engine.organization.entity.chart; +import com.alibaba.fastjson.annotation.JSONField; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -25,12 +26,17 @@ public class TreeSelect { public static final String SUB_COMPANY = "1"; public static final String DEPARTMENT = "2"; + @JSONField(ordinal = 1) private String key; - private String id; + @JSONField(ordinal = 2) private String title; + @JSONField(ordinal = 3) + private String id; + @JSONField(ordinal = 4) + private List children; private String type; private String canceled; - private List children; + private boolean disabled; private String cancelSql; @@ -41,24 +47,24 @@ public class TreeSelect { children = new ArrayList<>(); RecordSet rs = new RecordSet(); if (COMPANY.equals(type)) { - String sql = "select id ,subcompanyname ,canceled from hrmsubcompany where " + getCancelSqlStr() + " and (supsubcomid is null or supsubcomid = 0) and companyid = ? order by showorder"; + String sql = "select id ,subcompanyname ,canceled from hrmsubcompany where " + getCancelSqlStr() + " and (supsubcomid is null or supsubcomid = 0) and companyid = ? order by showorder,id"; rs.executeQuery(sql, key); while (rs.next()) { children.add(TreeSelect.builder().key(rs.getString("id")).title(rs.getString("subcompanyname")).canceled(rs.getString("canceled")).type(SUB_COMPANY).cancelSql(cancelSql).build()); } } else if (SUB_COMPANY.equals(type)) { - String sql = "select id ,subcompanyname ,canceled from hrmsubcompany where " + getCancelSqlStr() + " and supsubcomid = ? order by showorder"; + String sql = "select id ,subcompanyname ,canceled from hrmsubcompany where " + getCancelSqlStr() + " and supsubcomid = ? order by showorder,id"; rs.executeQuery(sql, key); while (rs.next()) { children.add(TreeSelect.builder().key(rs.getString("id")).title(rs.getString("subcompanyname")).canceled(rs.getString("canceled")).type(SUB_COMPANY).cancelSql(cancelSql).build()); } - sql = "select id,departmentname ,canceled from hrmdepartment where " + getCancelSqlStr() + " and (supdepid is null or supdepid =0) and subcompanyid1 = ? order by showorder"; + sql = "select id,departmentname ,canceled from hrmdepartment where " + getCancelSqlStr() + " and (supdepid is null or supdepid =0) and subcompanyid1 = ? order by showorder,id"; rs.executeQuery(sql, key); while (rs.next()) { children.add(TreeSelect.builder().key(rs.getString("id")).title(rs.getString("departmentname")).canceled(rs.getString("canceled")).type(DEPARTMENT).cancelSql(cancelSql).build()); } } else if (DEPARTMENT.equals(type)) { - String sql = "select id,departmentname ,canceled from hrmdepartment where " + getCancelSqlStr() + " and supdepid = ? order by showorder"; + String sql = "select id,departmentname ,canceled from hrmdepartment where " + getCancelSqlStr() + " and supdepid = ? order by showorder,id"; rs.executeQuery(sql, key); while (rs.next()) { children.add(TreeSelect.builder().key(rs.getString("id")).title(rs.getString("departmentname")).canceled(rs.getString("canceled")).type(DEPARTMENT).cancelSql(cancelSql).build()); @@ -82,7 +88,7 @@ public class TreeSelect { } public String getId() { - return key; + return getKey(); } public String getCanceled() { diff --git a/src/com/engine/organization/service/impl/ChartServiceImpl.java b/src/com/engine/organization/service/impl/ChartServiceImpl.java index 90db88fe..6d57df96 100644 --- a/src/com/engine/organization/service/impl/ChartServiceImpl.java +++ b/src/com/engine/organization/service/impl/ChartServiceImpl.java @@ -467,9 +467,9 @@ public class ChartServiceImpl extends Service implements ChartService { String sql = getDepartmentTreeSql(versionId, dimension, subCompany); rs.executeQuery(sql); while (rs.next()) { - departmentTree.add(CompanyTreePO.builder().id(rs.getString("id")).pId(rs.getString("pId")).value(rs.getString("value")).title(rs.getString("title")).isLeaf(judgeTreeLeaf(versionId, dimension, rs.getString("id"))).build()); + departmentTree.add(CompanyTreePO.builder().id(rs.getString("id")).pId(rs.getString("pId")).disabled(!rs.getString("id").startsWith("d")).value(rs.getString("value")).title(rs.getString("title")).isLeaf(judgeTreeLeaf(versionId, dimension, rs.getString("id"))).build()); } - result.put("companyTree", departmentTree); + result.put("departmentTree", departmentTree); result.put("api_status", true); return result; } @@ -477,15 +477,17 @@ public class ChartServiceImpl extends Service implements ChartService { @Override public Map getMovingTree(Map params) { RecordSet rs = new RecordSet(); + rs.executeQuery("select id,companyname from hrmcompany"); + TreeSelect companyTree = null; + List expandedKeys = new ArrayList<>(); String canceled = Util.null2String(params.get("canceled")); - rs.executeQuery("select id,subcompanyname,canceled from hrmsubcompany where (canceled is null or canceled != 1) and (supsubcomid is null or supsubcomid = 0) order by showorder"); - List movingTrees = new ArrayList<>(); - while(rs.next()){ - movingTrees.add(TreeSelect.builder().key(rs.getString("id")).title(rs.getString("subcompanyname")).type(TreeSelect.SUB_COMPANY).cancelSql(canceled).build()); + if(rs.next()){ + companyTree = TreeSelect.builder().key(rs.getString("id")).title(rs.getString("companyname")).type(TreeSelect.COMPANY).cancelSql(canceled).build(); + expandedKeys.add(companyTree.getKey()); } Map result = new HashMap<>(3); - result.put("movingTree", movingTrees); - result.put("expandedKeys", movingTrees.stream().filter(item -> CollectionUtils.isNotEmpty(item.getChildren())).map(TreeSelect::getKey).collect(Collectors.toList())); + result.put("movingTree", Collections.singletonList(companyTree)); + result.put("expandedKeys", expandedKeys); result.put("api_status", true); return result; } @@ -502,7 +504,7 @@ public class ChartServiceImpl extends Service implements ChartService { expandedKeys = companyTree.getChildren().stream().filter(item -> CollectionUtils.isNotEmpty(item.getChildren())).map(TreeSelect::getKey).collect(Collectors.toList()); expandedKeys.add(companyTree.getKey()); } - + disableTreeItem(Collections.singletonList(companyTree),TreeSelect.DEPARTMENT); Map result = new HashMap<>(3); result.put("selectTree", companyTree); result.put("expandedKeys", expandedKeys); @@ -510,6 +512,23 @@ public class ChartServiceImpl extends Service implements ChartService { return result; } + /** + * 树节点是否禁用 + * + * @param companyTreeList TreeSelect组件数据集合 + */ + private void disableTreeItem(List companyTreeList, String enableTreeType) { + if (CollectionUtils.isNotEmpty(companyTreeList)) { + for (TreeSelect treeSelect : companyTreeList) { + treeSelect.setDisabled(!enableTreeType.equals(treeSelect.getType())); + List children = treeSelect.getChildren(); + if (CollectionUtils.isNotEmpty(children)) { + disableTreeItem(children, enableTreeType); + } + } + } + } + private void trueDimension(RecordSetTrans recordSetTrans,String versionId,String currentUser,String currentDate){ RecordSet rs = new RecordSet(); rs.execute("delete from jcl_chart_subcompany where versionid = "+versionId); @@ -1272,6 +1291,7 @@ public class ChartServiceImpl extends Service implements ChartService { if (isCurrentDimension) { sql = "select " + dbType.concat("d", "id") + "as id, id as value, departmentname as title, " + dbType.concat("d", "supdepid") + " as pId from hrmdepartmentvirtual where (canceled is null or canceled != '1') and " + dbType.ifNull("supdepid", "0") + " = " + subCompany; } + sql += " order by showorder,id "; } else { sql = "select " + dbType.concat("d", "departmentid") + "as id, departmentid as value, departmentname as title, " + dbType.concat("d", "supdepartmentid") + " as pId from jcl_chart_department where (canceled is null or canceled != '1') and " + dbType.ifNull("supdepartmentid", "0") + " = " + subCompany; if (isCurrentDimension) { @@ -1282,18 +1302,19 @@ public class ChartServiceImpl extends Service implements ChartService { } } else { if (isSearchCurrent) { - 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.ifNull("supsubcomid", "0") + " = " + subCompany + - " union select " + dbType.concat("d", "id") + "as id, id as value, departmentname as title, subcompanyid1 as pId from hrmdepartment where (canceled is null or canceled != '1') and " + dbType.ifNull("subcompanyid1", "0") + " = " + subCompany; + sql = "select id as id, id as value, subcompanyname as title, supsubcomid as pId, showorder from hrmsubcompany where (canceled is null or canceled != '1') and " + dbType.ifNull("supsubcomid", "0") + " = " + subCompany + + " union select " + dbType.concat("d", "id") + "as id, id as value, departmentname as title, subcompanyid1 as pId, showorder from hrmdepartment where (canceled is null or canceled != '1') and (supdepid is null or supdepid =0) and " + dbType.ifNull("subcompanyid1", "0") + " = " + subCompany; if (isCurrentDimension) { 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.ifNull("supsubcomid", "0") + " = " + subCompany + " and companyid = '" + dimension + "' " + - " union select " + dbType.concat("d", "id") + "as id, id as value, departmentname as title, subcompanyid1 as pId from hrmdepartmentvirtual where (canceled is null or canceled != '1') and " + dbType.ifNull("subcompanyid1", "0") + " = " + subCompany; + " union select " + dbType.concat("d", "id") + "as id, id as value, departmentname as title, subcompanyid1 as pId from hrmdepartmentvirtual where (canceled is null or canceled != '1') and (supdepid is null or supdepid =0) and" + dbType.ifNull("subcompanyid1", "0") + " = " + subCompany; } + sql += " order by showorder,id "; } else { sql = "select subcompanyid as id, subcompanyid as value, subcompanyname as title, supsubcompanyid as pId from jcl_chart_subcompany where (canceled is null or canceled != '1') and " + dbType.ifNull("supsubcompanyid", "0") + " = " + subCompany + - " union select " + dbType.concat("d", "subcompanyid") + "as id, subcompanyid as value, departmentname as title, subcompanyid as pId from jcl_chart_department where (canceled is null or canceled != '1') and " + dbType.ifNull("subcompanyid", "0") + " = " + subCompany; + " union select " + dbType.concat("d", "subcompanyid") + "as id, subcompanyid as value, departmentname as title, subcompanyid as pId from jcl_chart_department where (canceled is null or canceled != '1') and (supdepartmentid is null or supdepartmentid =0) and " + dbType.ifNull("subcompanyid", "0") + " = " + subCompany; if (isCurrentDimension) { sql = "select subcompanyvirtualid as id, subcompanyvirtualid as value, subcompanyname as title, supsubcompanyid as pId from jcl_chart_subcompanyvirtual where (canceled is null or canceled != '1') and " + dbType.ifNull("supsubcompanyid", "0") + " = " + subCompany + " and companyid = '" + dimension + "' " + - " union select " + dbType.concat("d", "departmentvirtualid") + "as id, departmentvirtualid as value, departmentname as title, subcompanyid as pId from jcl_chart_departmentvirtual where (canceled is null or canceled != '1') and " + dbType.ifNull("subcompanyid", "0") + " = " + subCompany; + " union select " + dbType.concat("d", "departmentvirtualid") + "as id, departmentvirtualid as value, departmentname as title, subcompanyid as pId from jcl_chart_departmentvirtual where (canceled is null or canceled != '1') and (supdepid is null or supdepid =0) and" + dbType.ifNull("subcompanyid", "0") + " = " + subCompany; } // 添加时间轴条件 sql += " and versionid = " + versionId;