diff --git a/src/com/engine/organization/service/OrgChartService.java b/src/com/engine/organization/service/OrgChartService.java index 917c77a3..30039cbb 100644 --- a/src/com/engine/organization/service/OrgChartService.java +++ b/src/com/engine/organization/service/OrgChartService.java @@ -16,4 +16,8 @@ public interface OrgChartService { Map getCompanyData(Map request2Map, User user); Map getUserData(Map request2Map, User user); + + Map asyncUserData(Map request2Map, User user); + + Map asyncCompanyData(Map request2Map, User user); } diff --git a/src/com/engine/organization/service/impl/OrgChartServiceImpl.java b/src/com/engine/organization/service/impl/OrgChartServiceImpl.java index 06a8a7f1..4213a973 100644 --- a/src/com/engine/organization/service/impl/OrgChartServiceImpl.java +++ b/src/com/engine/organization/service/impl/OrgChartServiceImpl.java @@ -17,6 +17,9 @@ import java.util.*; * @description: 组织架构图ServiceImpl **/ public class OrgChartServiceImpl extends Service implements OrgChartService { + + private RecordSet grs = new RecordSet(); + @Override public Map getOptionCondition(Map request2Map, User user) { RecordSet rs = new RecordSet(); @@ -54,19 +57,15 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { return result; } - @Override - public Map getCompanyData(Map request2Map, User user) { + private String companyDateWhereSql(Map 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 root = (String) request2Map.get("root"); // 根节点 - String level = (String) request2Map.get("level"); // 显示层级 - if(StringUtils.isBlank(level)) { - level = "3"; - } + + String fisvitual = (String) request2Map.get("fisvitual"); // 是否显示虚拟组织 if(StringUtils.isBlank(fisvitual)) { @@ -83,6 +82,20 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { whereSql += " and fisvitual in (0, 1) "; } + whereSql += " and ftype in (0 , 1 ,2) "; + return whereSql; + } + + @Override + public Map getCompanyData(Map request2Map, User user) { + + String root = (String) request2Map.get("root"); // 根节点 + String level = (String) request2Map.get("level"); // 显示层级 + if(StringUtils.isBlank(level)) { + level = "3"; + } + String whereSql = companyDateWhereSql(request2Map); + String whereItemSql = " "; if("0".equals(root)) { // 集团的情况 whereItemSql += " and ftype = 0 "; @@ -92,7 +105,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { // 获取根节点 RecordSet rs = new RecordSet(); - rs.executeQuery("select id, fname, ftype, fparentid from jcl_org_map " + whereSql + whereItemSql); + rs.executeQuery("select id, fname, ftype, fparentid, fnumber from jcl_org_map " + whereSql + whereItemSql); List> list = new ArrayList<>(); String id = null; if(rs.next()) { @@ -101,13 +114,16 @@ 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("fnumber", rs.getString("fnumber")); item.put("parentId", null); + item.put("expand", "1"); + item.put("hasChildren", hasChildren(rs.getString("id"), true)); list.add(item); } int currentLevel = 1; if(currentLevel + 1 <= Integer.parseInt(level)) { - findCompanyItemByParantId(id, currentLevel + 1, level, rs, list, whereSql); + findCompanyItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, true); } Map result = new HashMap<>(); @@ -116,8 +132,8 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { return result; } - private void findCompanyItemByParantId(String id, int currentLevel, String level, RecordSet rs, List> list, String whereSql) { - rs.executeQuery("select id, fname, ftype, fparentid from jcl_org_map " + whereSql + " and fparentid = " + id); + private void findCompanyItemByParantId(String id, int currentLevel, String level, RecordSet rs, List> list, String whereSql, boolean expand) { + rs.executeQuery("select id, fname, ftype, fparentid, fnumber from jcl_org_map " + whereSql + " and fparentid = " + id); List> currentList = new ArrayList<>(); while(rs.next()) { Map item = new HashMap<>(); @@ -125,6 +141,9 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { item.put("fname", rs.getString("fname")); item.put("ftype", rs.getString("ftype")); item.put("parentId", rs.getString("fparentid")); + item.put("fnumber", rs.getString("fnumber")); + item.put("expand", expand ? "1" : "0"); + item.put("hasChildren", hasChildren(rs.getString("id"), true)); currentList.add(item); } @@ -132,25 +151,22 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { for (Map stringObjectMap : currentList) { if(currentLevel + 1 <= Integer.parseInt(level)) { - findCompanyItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql); + findCompanyItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, true); + } else if(currentLevel == Integer.parseInt(level)) { + findCompanyItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql, false); } } } - @Override - public Map getUserData(Map request2Map, User user) { + private String userWhereSql(Map 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 root = (String) request2Map.get("root"); // 根节点 - String level = (String) request2Map.get("level"); // 显示层级 - if(StringUtils.isBlank(level)) { - level = "3"; - } + String fisvitual = (String) request2Map.get("fisvitual"); // 是否显示虚拟组织 if(StringUtils.isBlank(fisvitual)) { @@ -166,6 +182,18 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { }else { whereSql += " and t.fisvitual in (0, 1) "; } + return whereSql; + } + + @Override + public Map getUserData(Map request2Map, User user) { + 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)) { // 集团的情况 @@ -176,7 +204,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { // 获取根节点 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 from jcl_org_map t " + whereSql + whereItemSql); + rs.executeQuery("select t.id, t.fname, t.ftype, t.fparentid, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber from jcl_org_map t " + whereSql + whereItemSql); List> list = new ArrayList<>(); String id = null; if(rs.next()) { @@ -191,12 +219,15 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { item.put("fleaderjob", rs.getString("fleaderjob")); 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")); list.add(item); } int currentLevel = 1; if(currentLevel + 1 <= Integer.parseInt(level)) { - findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql); + findUserItemByParantId(id, currentLevel + 1, level, rs, list, whereSql, true); } Map result = new HashMap<>(); @@ -205,7 +236,84 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { return result; } - private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List> list, String whereSql) { + @Override + public Map asyncUserData(Map 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 from jcl_org_map t " + whereSql ); + List> currentList = new ArrayList<>(); + 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("fleadername", rs.getString("fleadername")); + item.put("fleaderimg", rs.getString("fleaderimg")); + item.put("fleaderjob", rs.getString("fleaderjob")); + 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)); + 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")); + } + + } + } + + Map result = new HashMap<>(); + result.put("api_status", true); + result.put("data", currentList); + return result; + } + + @Override + public Map asyncCompanyData(Map request2Map, User user) { + String ids = (String) request2Map.get("ids"); + String whereSql = companyDateWhereSql(request2Map); + + whereSql += " and fparentid in (" +ids+ ") "; + + RecordSet rs = new RecordSet(); + rs.executeQuery("select id, fname, ftype, fparentid, fnumber from jcl_org_map " + whereSql); + List> currentList = new ArrayList<>(); + 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("fnumber", rs.getString("fnumber")); + item.put("hasChildren", hasChildren(rs.getString("id"), true)); + currentList.add(item); + } + + Map result = new HashMap<>(); + result.put("api_status", true); + result.put("data", currentList); + return result; + } + + private void findUserItemByParantId(String id, int currentLevel, String level, RecordSet rs, List> list, String whereSql, boolean expand) { rs.executeQuery("select t.id, t.fname, t.ftype, t.fparentid, t.fleadername, t.fleaderimg, t.fleaderjob, t.fplan, t.fonjob, t.fnumber from jcl_org_map t " + whereSql + " and t.fparentid = " + id); List> currentList = new ArrayList<>(); while(rs.next()) { @@ -220,6 +328,8 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { 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("hasChildren", hasChildren(rs.getString("id"), false)); currentList.add(item); } @@ -240,10 +350,24 @@ public class OrgChartServiceImpl extends Service implements OrgChartService { } if(currentLevel + 1 <= Integer.parseInt(level)) { - findUserItemByParantId((String) stringObjectMap.get("id"), currentLevel + 1, level, rs, list, whereSql); + 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 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 jcl_org_map " + whereSql); + String count = "0"; + if(grs.next()) { + count = grs.getString("count"); + } + return !"0".equals(count); } } diff --git a/src/com/engine/organization/web/OrgChartController.java b/src/com/engine/organization/web/OrgChartController.java index 78c327be..92dcbaac 100644 --- a/src/com/engine/organization/web/OrgChartController.java +++ b/src/com/engine/organization/web/OrgChartController.java @@ -97,4 +97,50 @@ public class OrgChartController { return JSONObject.toJSONString(apidatas); } + /** + * 异步人员数据 + */ + @GET + @Path("/asyncUserData") + @Produces(MediaType.APPLICATION_JSON) + public String asyncUserData(@Context HttpServletRequest request, @Context HttpServletResponse + response){ + Map apidatas = new HashMap(); + try{ + User user = HrmUserVarify.getUser(request, response); + //实例化Service 并调用业务类处理 + apidatas = getOrgChartWrapper(user).asyncUserData(ParamUtil.request2Map(request), user); + }catch(Exception e){ + //异常处理 + e.printStackTrace(); + apidatas.put("api_status", false); + apidatas.put("api_errormsg", "catch exception : " + e.getMessage()); + } + //数据转换 + return JSONObject.toJSONString(apidatas); + } + + /** + * 异步组织数据 + */ + @GET + @Path("/asyncCompanyData") + @Produces(MediaType.APPLICATION_JSON) + public String asyncCompanyData(@Context HttpServletRequest request, @Context HttpServletResponse + response){ + Map apidatas = new HashMap(); + try{ + User user = HrmUserVarify.getUser(request, response); + //实例化Service 并调用业务类处理 + apidatas = getOrgChartWrapper(user).asyncCompanyData(ParamUtil.request2Map(request), user); + }catch(Exception e){ + //异常处理 + e.printStackTrace(); + apidatas.put("api_status", false); + apidatas.put("api_errormsg", "catch exception : " + e.getMessage()); + } + //数据转换 + return JSONObject.toJSONString(apidatas); + } + } diff --git a/src/com/engine/organization/wrapper/OrgChartWrapper.java b/src/com/engine/organization/wrapper/OrgChartWrapper.java index 5ec82c64..33c672a0 100644 --- a/src/com/engine/organization/wrapper/OrgChartWrapper.java +++ b/src/com/engine/organization/wrapper/OrgChartWrapper.java @@ -31,4 +31,12 @@ public class OrgChartWrapper extends Service { public Map getUserData(Map request2Map, User user) { return getOrgChartService(user).getUserData(request2Map, user); } + + public Map asyncUserData(Map request2Map, User user) { + return getOrgChartService(user).asyncUserData(request2Map, user); + } + + public Map asyncCompanyData(Map request2Map, User user) { + return getOrgChartService(user).asyncCompanyData(request2Map, user); + } }