diff --git a/src/com/engine/organization/service/ChartService.java b/src/com/engine/organization/service/ChartService.java index d49e9e78..20710587 100644 --- a/src/com/engine/organization/service/ChartService.java +++ b/src/com/engine/organization/service/ChartService.java @@ -26,4 +26,7 @@ public interface ChartService { Map asyncCompanyData(Map params); + Map getDepartmentDetail(Map params); + + } diff --git a/src/com/engine/organization/service/impl/ChartServiceImpl.java b/src/com/engine/organization/service/impl/ChartServiceImpl.java index 68fdb5af..2cf6cbee 100644 --- a/src/com/engine/organization/service/impl/ChartServiceImpl.java +++ b/src/com/engine/organization/service/impl/ChartServiceImpl.java @@ -1,17 +1,18 @@ 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.service.ChartService; import com.engine.organization.util.HasRightUtil; +import com.engine.organization.util.OrganizationAssert; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import weaver.conn.RecordSet; import weaver.general.Util; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.stream.Collectors; /** * @author:dxfeng @@ -162,6 +163,100 @@ public class ChartServiceImpl extends Service implements ChartService { return result; } + @Override + public Map getDepartmentDetail(Map params) { + String rootId = Util.null2String(params.get("rootId")); + + OrganizationAssert.isFalse(StringUtils.isBlank(rootId) || !rootId.startsWith("d_"), "数据有误,未查询到对应数据"); + String departmentId = rootId.split("_")[1]; + String detauleType = Util.null2String(params.get("detauleType")); + if(!"chart".equals(detauleType)){ + return ServiceUtil.getService(HrmResourceServiceImpl.class, user).chartResourceList(Integer.parseInt(departmentId)); + } + + + // 维度 + String dimension = Util.null2String(params.get("fclass")); + dimension = StringUtils.isBlank(dimension) ? "0" : dimension; + + + // 初始化表名 + initTableNameByClass(dimension); + + List dataList = new ArrayList<>(); + List resourceList = new ArrayList<>(); + Set jobTitleSet = new HashSet<>(); + RecordSet rs = new RecordSet(); + // TODO 查询当前实际的数据 + String sql; + // 查询当当前部门下的人员 + if ("0".equals(dimension)) { + sql = "select a.id,a.lastname as 'name' ,a.jobtitle from hrmresource a where a.departmentid = '" + departmentId + "'"; + } else { + sql = "select a.id,a.lastname as 'name' ,a.jobtitle from hrmresource a inner join hrmresourcevirtual b on a.id = b.resourceid where b.departmentid = '" + departmentId + "'"; + } + rs.executeQuery(sql); + while (rs.next()){ + String jobTitle = Util.null2String(rs.getString("jobtitle")); + ChartPO chartPO = new ChartPO(); + chartPO.setFtype("4"); + chartPO.setFobjid(rs.getString("id")); + chartPO.setFname(rs.getString("name")); + // 岗位处理后的ID + chartPO.setParentId(departmentId + "_" + jobTitle); + chartPO.setExpand("1"); + chartPO.setHasChildren("0"); + resourceList.add(chartPO); + + jobTitleSet.add(jobTitle); + } + Map> resourceMap = resourceList.stream().collect(Collectors.groupingBy(ChartPO::getParentId)); + // 查询人员的岗位 + if(CollectionUtils.isNotEmpty(jobTitleSet)) { + sql = "select a.id,a.jobtitlename as 'name' from hrmjobtitles a where a.id in(" + StringUtils.join(jobTitleSet, ",") + ")"; + rs.executeQuery(sql); + while (rs.next()){ + ChartPO chartPO = new ChartPO(); + chartPO.setFtype("3"); + chartPO.setFobjid(rs.getString("id")); + chartPO.setId(departmentId + "_" + chartPO.getFobjid()); + chartPO.setFname(rs.getString("name")); + // 岗位处理后的ID + chartPO.setParentId(rootId); + chartPO.setExpand("1"); + chartPO.setHasChildren("1"); + dataList.add(chartPO); + + // 避免出现人员没有上级岗位的情况 + List chartPOS = resourceMap.get(chartPO.getId()); + if (CollectionUtils.isNotEmpty(chartPOS)) { + dataList.addAll(chartPOS); + } + } + } + // 查询部门本身 + sql = "select a.id,a.departmentname as 'name' from " + DEPARTMENT_TABLE + " a where id = '" + departmentId + "'"; + rs.executeQuery(sql); + if(rs.next()){ + ChartPO chartPO = new ChartPO(); + chartPO.setFtype("2"); + chartPO.setFobjid(departmentId); + chartPO.setId(rootId); + chartPO.setFname(rs.getString("name")); + // 岗位处理后的ID + chartPO.setParentId(rootId); + chartPO.setExpand("1"); + chartPO.setHasChildren(CollectionUtils.isNotEmpty(dataList) ? "1" : "0"); + dataList.add(chartPO); + } + + + Map result = new HashMap<>(); + result.put("api_status", true); + result.put("data", dataList); + return result; + } + /** * 查询实时数据,顶级元素SQL * diff --git a/src/com/engine/organization/web/OrgChartController.java b/src/com/engine/organization/web/OrgChartController.java index 7bace160..2c9b94bb 100644 --- a/src/com/engine/organization/web/OrgChartController.java +++ b/src/com/engine/organization/web/OrgChartController.java @@ -63,8 +63,22 @@ public class OrgChartController { return JSONObject.toJSONString(apidatas); } - - + @GET + @Path("/getDepartmentDetail") + @Produces(MediaType.APPLICATION_JSON) + public String getDepartmentDetail(@Context HttpServletRequest request, @Context HttpServletResponse response) { + Map apidatas = new HashMap<>(); + try { + User user = HrmUserVarify.getUser(request, response); + apidatas = getOrgChartWrapper(user).getDepartmentDetail(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 diff --git a/src/com/engine/organization/wrapper/OrgChartWrapper.java b/src/com/engine/organization/wrapper/OrgChartWrapper.java index 8d117795..f916a2a1 100644 --- a/src/com/engine/organization/wrapper/OrgChartWrapper.java +++ b/src/com/engine/organization/wrapper/OrgChartWrapper.java @@ -60,4 +60,8 @@ public class OrgChartWrapper extends Service { public Map searchTimeLines(Map request2Map, User user) { return getOrgChartService(user).searchTimeLines(request2Map); } + + public Map getDepartmentDetail(Map request2Map, User user) { + return getChartService(user).getDepartmentDetail(request2Map); + } }