组织架构图,部门选择树
This commit is contained in:
parent
f4c29de76b
commit
fab01583ad
|
|
@ -47,4 +47,12 @@ public interface ChartService {
|
|||
* @return 数据集合
|
||||
*/
|
||||
Map<String, Object> versionRecord(Map<String, Object> params, User user);
|
||||
|
||||
/**
|
||||
* 获取部门下拉框树结构
|
||||
*
|
||||
* @param params 前端入参
|
||||
* @return 树结构
|
||||
*/
|
||||
Map<String, Object> getDepartmentTree(Map<String, Object> params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.engine.organization.service.impl;
|
|||
import com.engine.common.util.ServiceUtil;
|
||||
import com.engine.core.impl.Service;
|
||||
import com.engine.organization.entity.chart.ChartPO;
|
||||
import com.engine.organization.entity.chart.CompanyTreePO;
|
||||
import com.engine.organization.mapper.hrmresource.SystemDataMapper;
|
||||
import com.engine.organization.mapper.jclorgmap.JclOrgMapper;
|
||||
import com.engine.organization.service.ChartService;
|
||||
|
|
@ -10,6 +11,7 @@ import com.engine.organization.service.OrgChartService;
|
|||
import com.engine.organization.util.HasRightUtil;
|
||||
import com.engine.organization.util.OrganizationAssert;
|
||||
import com.engine.organization.util.OrganizationDateUtil;
|
||||
import com.engine.organization.util.db.DBType;
|
||||
import com.engine.organization.util.db.MapperProxyFactory;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
|
@ -446,6 +448,29 @@ public class ChartServiceImpl extends Service implements ChartService {
|
|||
result.put("api_status", true);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getDepartmentTree(Map<String, Object> params) {
|
||||
Map<String, Object> result = new HashMap<>(2);
|
||||
|
||||
RecordSet rs = new RecordSet();
|
||||
List<CompanyTreePO> departmentTree = new ArrayList<>();
|
||||
String subCompany = Util.null2String(params.get("subcompany"));
|
||||
String dimension = Util.null2String(params.get("fclass"));
|
||||
String versionId = Util.null2String(params.get("id"));
|
||||
if (StringUtils.isBlank(subCompany)) {
|
||||
subCompany = "0";
|
||||
}
|
||||
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());
|
||||
}
|
||||
result.put("companyTree", departmentTree);
|
||||
result.put("api_status", true);
|
||||
return result;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
@ -1184,4 +1209,79 @@ public class ChartServiceImpl extends Service implements ChartService {
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取部门树下拉框SQL
|
||||
*
|
||||
* @param versionId 版本ID
|
||||
* @param dimension 维度
|
||||
* @param subCompany 上级Id
|
||||
* @return SQL
|
||||
*/
|
||||
private String getDepartmentTreeSql(String versionId, String dimension, String subCompany) {
|
||||
// 是否展示当前数据
|
||||
boolean isSearchCurrent = StringUtils.isBlank(versionId) || "0".equals(versionId);
|
||||
boolean isCurrentDimension = StringUtils.isNotBlank(dimension) && !"0".equals(dimension);
|
||||
boolean isDepartment = subCompany.startsWith("d");
|
||||
String sql;
|
||||
DBType dbType = DBType.get(new RecordSet().getDBType());
|
||||
if (isDepartment) {
|
||||
subCompany = subCompany.replace("d", "");
|
||||
if (isSearchCurrent) {
|
||||
sql = "select " + dbType.concat("d", "id") + "as id, id as value, departmentname as title, " + dbType.concat("d", "supdepid") + " as pId from hrmdepartment where (canceled is null or canceled != '1') and " + dbType.ifNull("supdepid", "0") + " = " + subCompany;
|
||||
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;
|
||||
}
|
||||
} 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) {
|
||||
sql = "select " + dbType.concat("d", "departmentvirtualid") + "as id, departmentvirtualid as value, departmentname as title, " + dbType.concat("d", "supdepid") + " as pId from jcl_chart_departmentvirtual where (canceled is null or canceled != '1') and " + dbType.ifNull("supdepid", "0") + " = " + subCompany;
|
||||
}
|
||||
// 添加时间轴条件
|
||||
sql += " and versionid = " + versionId;
|
||||
}
|
||||
} 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;
|
||||
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;
|
||||
}
|
||||
} 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;
|
||||
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;
|
||||
}
|
||||
// 添加时间轴条件
|
||||
sql += " and versionid = " + versionId;
|
||||
}
|
||||
}
|
||||
return sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断树是否为叶子节点
|
||||
*
|
||||
* @param sql 查询下级元素SQL
|
||||
* @param treeId 当前元素ID
|
||||
* @return
|
||||
*/
|
||||
|
||||
/**
|
||||
* 判断树是否为叶子节点
|
||||
* @param versionId 版本ID
|
||||
* @param dimension 维度
|
||||
* @param subCompany 上级元素ID
|
||||
* @return
|
||||
*/
|
||||
private boolean judgeTreeLeaf(String versionId, String dimension, String subCompany) {
|
||||
RecordSet recordSet = new RecordSet();
|
||||
String sql = getDepartmentTreeSql(versionId, dimension, subCompany);
|
||||
recordSet.executeQuery(sql);
|
||||
return !recordSet.next();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ public interface DBOperateAdapter {
|
|||
|
||||
String concat(String some);
|
||||
|
||||
String concat(String concatStr, String fieldName);
|
||||
|
||||
String currentDate();
|
||||
|
||||
String ifNull(String some, String defaultValue);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import com.engine.organization.exception.OrganizationRunTimeException;
|
|||
import weaver.conn.RecordSet;
|
||||
|
||||
public enum DBType implements DBOperateAdapter {
|
||||
/**
|
||||
* 根据数据库类型,匹配不通的函数
|
||||
*/
|
||||
MYSQL("mysql") {
|
||||
@Override
|
||||
public String like(String some) {
|
||||
|
|
@ -16,6 +19,11 @@ public enum DBType implements DBOperateAdapter {
|
|||
return " concat(','," + some + ",',') ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String concat(String concatStr, String fieldName) {
|
||||
return " concat('" + concatStr + "'," + fieldName + ") ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String currentDate() {
|
||||
return "now()";
|
||||
|
|
@ -37,6 +45,11 @@ public enum DBType implements DBOperateAdapter {
|
|||
return " ','+" + some + "+',' ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String concat(String concatStr, String fieldName) {
|
||||
return " '" + concatStr + "' + " + fieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String currentDate() {
|
||||
return "GETDATE()";
|
||||
|
|
@ -58,6 +71,11 @@ public enum DBType implements DBOperateAdapter {
|
|||
return " ',' ||" + some + "|| ',' ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String concat(String concatStr, String fieldName) {
|
||||
return " '" + concatStr + "' ||" + fieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String currentDate() {
|
||||
return "SYSDATE";
|
||||
|
|
@ -79,6 +97,11 @@ public enum DBType implements DBOperateAdapter {
|
|||
return " ',' ||" + some + "|| ',' ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String concat(String concatStr, String fieldName) {
|
||||
return " '" + concatStr + "' ||" + fieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String currentDate() {
|
||||
return "now()";
|
||||
|
|
|
|||
|
|
@ -118,6 +118,26 @@ public class OrgChartController {
|
|||
return JSONObject.toJSONString(apidatas);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/getDepartmentTree")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public String getDepartmentTree(@Context HttpServletRequest request, @Context HttpServletResponse response) {
|
||||
Map<String, Object> apidatas = new HashMap<>();
|
||||
try {
|
||||
User user = HrmUserVarify.getUser(request, response);
|
||||
//实例化Service 并调用业务类处理
|
||||
apidatas = getOrgChartWrapper(user).getDepartmentTree(ParamUtil.request2Map(request), user);
|
||||
apidatas.put("api_status", true);
|
||||
} catch (Exception e) {
|
||||
//异常处理
|
||||
e.printStackTrace();
|
||||
apidatas.put("api_status", false);
|
||||
apidatas.put("api_errormsg", "catch exception : " + e.getMessage());
|
||||
}
|
||||
//数据转换
|
||||
return JSONObject.toJSONString(apidatas);
|
||||
}
|
||||
|
||||
/**
|
||||
* 组织架构数据
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -68,4 +68,8 @@ public class OrgChartWrapper extends Service {
|
|||
public Map<String, Object> versionRecord(Map<String, Object> request2Map, User user) {
|
||||
return getChartService(user).versionRecord(request2Map,user);
|
||||
}
|
||||
|
||||
public Map<String, Object> getDepartmentTree(Map<String, Object> request2Map, User user) {
|
||||
return getChartService(user).getDepartmentTree(request2Map);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue