diff --git a/src/com/engine/jhsecond/entity/vo/OrganizationChartVo.java b/src/com/engine/jhsecond/entity/vo/OrganizationChartVo.java index a263895..41edddd 100644 --- a/src/com/engine/jhsecond/entity/vo/OrganizationChartVo.java +++ b/src/com/engine/jhsecond/entity/vo/OrganizationChartVo.java @@ -1,10 +1,43 @@ package com.engine.jhsecond.entity.vo; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.AllArgsConstructor; + +import java.util.List; + /** * @Author liang.cheng * @Date 2024/7/16 5:19 PM * @Description: TODO * @Version 1.0 */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor public class OrganizationChartVo { + + private Integer id; + + private String deptName; + + private String lastName; + + private String jobName; + + private String photoUrl; + + private String type; + + private String halfType; + + private Integer pId; + + private List children; + + + + } diff --git a/src/com/engine/jhsecond/service/impl/OrganizationChartServiceImpl.java b/src/com/engine/jhsecond/service/impl/OrganizationChartServiceImpl.java index cdf7d42..a6dd122 100644 --- a/src/com/engine/jhsecond/service/impl/OrganizationChartServiceImpl.java +++ b/src/com/engine/jhsecond/service/impl/OrganizationChartServiceImpl.java @@ -1,20 +1,125 @@ package com.engine.jhsecond.service.impl; import com.engine.core.impl.Service; +import com.engine.jhsecond.entity.vo.OrganizationChartVo; import com.engine.jhsecond.service.OrganizationChartService; +import weaver.conn.RecordSet; +import weaver.general.BaseBean; +import weaver.general.Util; +import weaver.hrm.company.DepartmentComInfo; +import weaver.hrm.job.JobTitlesComInfo; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * @Author liang.cheng * @Date 2024/7/16 5:17 PM - * @Description: TODO + * @Description: * @Version 1.0 */ public class OrganizationChartServiceImpl extends Service implements OrganizationChartService { @Override public Map selectData(Map params) { - return null; + + BaseBean bb = new BaseBean(); + RecordSet rs = new RecordSet(); + Map data = new HashMap<>(); + JobTitlesComInfo jopInfo = new JobTitlesComInfo(); + + String topId = bb.getPropValue("jhsecond", "topId"); + String halfId = bb.getPropValue("jhsecond", "halfId"); + String superId = bb.getPropValue("jhsecond", "superId"); + String halfNodeId = bb.getPropValue("jhsecond", "halfNodeId"); + + //1.获取当前有效人员数据 todo 正式去除分部参数 + rs.executeQuery("select a.id,a.departmentid,a.lastname,a.jobtitle,a.resourceimageid,b."+superId+",b."+halfNodeId+" from " + + " hrmresource a left join cus_fielddata b on a.id = b.id and b.scopeid = 3 where status < 4"); + + List voList = new ArrayList<>(); + while (rs.next()) { + OrganizationChartVo build = OrganizationChartVo.builder() + .id(Util.getIntValue(rs.getString("id"))) + .deptName(getDepartmentName(Util.null2String(rs.getString("departmentid")))) + .lastName(Util.null2String(rs.getString("lastname"))) + .jobName(jopInfo.getJobTitlesname(Util.null2String(rs.getString("jobtitle")))) + .photoUrl(getPhotoUrl(Util.null2String(rs.getString("resourceimageid")))) + .pId(Util.getIntValue(rs.getString(superId))) + .type("0".equals(Util.null2String(rs.getString(halfNodeId))) ? "tag" : "") + .build(); + voList.add(build); + } + + //2.筛选出顶部节点 + OrganizationChartVo parentNode = voList.stream() + .filter(vo -> vo.getId() == Integer.parseInt(topId)) + .findFirst() + .orElse(null); + //3.设置半节点存在下级属性值并获取下级 + voList.stream() + .filter(vo -> vo.getId() == Integer.parseInt(halfId)) + .forEach(vo -> vo.setHalfType("true")); + + List filteredList = voList.stream() + .filter(vo -> vo.getPId() != null && vo.getPId() == Integer.parseInt(halfId)) + .collect(Collectors.toList()); + + //4.递归处理 + buildHierarchy(voList,parentNode); + + + + data.put("result",parentNode); + data.put("halfResult",filteredList); + + return data; + } + + /** + * 递归处理 + * @param list + * @param parentNode + */ + private void buildHierarchy(List list, OrganizationChartVo parentNode) { + List children = list.stream() + .filter(vo -> vo.getPId().equals(parentNode.getId())) + .collect(Collectors.toList()); + + for (OrganizationChartVo child : children) { + buildHierarchy(list, child); + } + + parentNode.setChildren(children); + } + + /** + * 部门名称 + * @param departmentId + * @return + */ + private String getDepartmentName(String departmentId) { + try { + DepartmentComInfo deptInfo = new DepartmentComInfo(); + return deptInfo.getDepartmentName(departmentId); + }catch (Exception e) { + return ""; + } + } + + /** + * 照片 + * @param resourceImageId + * @return + */ + private String getPhotoUrl(String resourceImageId){ + if("".equals(resourceImageId)){ + return "/messager/images/icon_w_wev8.jpg"; + }else { + return "/weaver/weaver.file.FileDownload?fileid=" + resourceImageId; + } } } diff --git a/src/com/engine/jhsecond/web/OrganizationChartAction.java b/src/com/engine/jhsecond/web/OrganizationChartAction.java index bf34aa8..f36978a 100644 --- a/src/com/engine/jhsecond/web/OrganizationChartAction.java +++ b/src/com/engine/jhsecond/web/OrganizationChartAction.java @@ -5,6 +5,7 @@ import com.engine.common.util.ParamUtil; import com.engine.common.util.ServiceUtil; import com.engine.jhsecond.service.OrganizationChartService; import com.engine.jhsecond.service.impl.OrganizationChartServiceImpl; +import com.fasterxml.jackson.databind.ObjectMapper; import weaver.hrm.HrmUserVarify; import weaver.hrm.User; @@ -40,9 +41,11 @@ public class OrganizationChartAction { User user = HrmUserVarify.getUser(request, response); apidatas = getOrganizationChartService(user).selectData(ParamUtil.request2Map(request)); apidatas.put("api_status", true); + ObjectMapper mapper = new ObjectMapper(); + return mapper.writeValueAsString(apidatas); } catch (Exception e) { apidatas.put("api_status", false); + return ""; } - return JSONObject.toJSONString(apidatas); } }