You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
126 lines
4.3 KiB
Java
126 lines
4.3 KiB
Java
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:
|
|
* @Version 1.0
|
|
*/
|
|
public class OrganizationChartServiceImpl extends Service implements OrganizationChartService {
|
|
|
|
@Override
|
|
public Map<String, Object> selectData(Map<String, Object> params) {
|
|
|
|
BaseBean bb = new BaseBean();
|
|
RecordSet rs = new RecordSet();
|
|
Map<String,Object> 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<OrganizationChartVo> 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<OrganizationChartVo> 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<OrganizationChartVo> list, OrganizationChartVo parentNode) {
|
|
List<OrganizationChartVo> 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;
|
|
}
|
|
}
|
|
}
|