宁波精华组织架构图二开接口完成
parent
952b874960
commit
d1de399627
@ -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<OrganizationChartVo> children;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -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<String, Object> selectData(Map<String, Object> params) {
|
||||
return null;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue