组织架构图增加根节点选择、层级选择、部门负责人展示

顺胜组织架构图V2
Administrator 1 year ago
parent 2431ba5edc
commit f13c42ab6e

@ -22,5 +22,7 @@ public class ChartChildrensVO {
private String label; private String label;
private String lastName;
private List<ChartChildrensVO> childrens; private List<ChartChildrensVO> childrens;
} }

@ -21,6 +21,10 @@ public class TreeDataVO {
private String label; private String label;
private String lastName;
private int num;
private List<ChartChildrensVO> childrens; private List<ChartChildrensVO> childrens;

@ -0,0 +1,23 @@
package com.engine.sship.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author xxy
* @Date 2024/1/31 15:26 PM
* @Description: TODO
* @Version 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class VirtualTopParam {
private String id;
private String virtualType;
}

@ -1,12 +1,10 @@
package com.engine.sship.service; package com.engine.sship.service;
import com.engine.sship.entity.PersonTableParam; import com.engine.sship.entity.*;
import com.engine.sship.entity.PersonTableVO;
import com.engine.sship.entity.SelectVO;
import com.engine.sship.entity.TreeDataVO;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
@ -88,4 +86,23 @@ public interface OrgChartService {
* @return: java.util.List<com.engine.sship.entity.PersonTableVO> * @return: java.util.List<com.engine.sship.entity.PersonTableVO>
*/ */
List<SelectVO> selectVirtualTop(); List<SelectVO> selectVirtualTop();
/**
* @Description:
* @Author: xxy
* @Date: 2024/1/31 14:26 PM
* @param: [virtualType]
* @return: java.util.List<com.engine.sship.entity.TreeDataVO>
*/
TreeDataVO selectVirtualTopTwo(String virtualType);
/**
* @Description:
* @Author: xxy
* @Date: 2024/1/31 15:26 PM
* @param: [virtualTopParam]
* @return: java.util.List<com.engine.sship.entity.SelectVO>
*/
List<SelectVO> selectVirtualTopThree(VirtualTopParam virtualTopParam);
} }

@ -14,10 +14,7 @@ import weaver.conn.RecordSet;
import weaver.hrm.company.DepartmentComInfo; import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.resource.ResourceComInfo; import weaver.hrm.resource.ResourceComInfo;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -29,8 +26,7 @@ import java.util.stream.Collectors;
*/ */
public class OrgChartServiceImpl extends Service implements OrgChartService { public class OrgChartServiceImpl extends Service implements OrgChartService {
private HrmCommonService hrmCommonService = new HrmCommonServiceImpl(); private final HrmCommonService hrmCommonService = new HrmCommonServiceImpl();
@Override @Override
public boolean selectIdsByRole(String roleId,String rolelevel) { public boolean selectIdsByRole(String roleId,String rolelevel) {
String roleMemberIds = hrmCommonService.getRoleMemberIds(roleId, rolelevel); String roleMemberIds = hrmCommonService.getRoleMemberIds(roleId, rolelevel);
@ -115,12 +111,16 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
if (isVirtualSubDepartment(id,virtualType)) { if (isVirtualSubDepartment(id,virtualType)) {
build.setChildrens(getVirtualSubDept(id,virtualType)); build.setChildrens(getVirtualSubDept(id,virtualType));
} }
// 根据id查询对应建模的虚拟部门领导
rs.executeQuery("select bmfzrid from uf_xnbmfzr where xnzzid = ? ",id);
build.setLastName(rs.getString("bmfzrid"));
} else { } else {
//获取当前部门 //获取当前部门
rs.executeQuery("select departmentid from hrmresourcevirtual where resourceid = ? and virtualtype = ?",user.getUID(),virtualType); rs.executeQuery("select departmentid from hrmresourcevirtual where resourceid = ? and virtualtype = ?",user.getUID(),virtualType);
rs.next(); rs.next();
String departmentId = Util.null2String(rs.getString("departmentid")); String departmentId = Util.null2String(rs.getString("departmentid"));
rs.executeQuery("select departmentmark from hrmdepartmentvirtual where id = ? and virtualtype = ?",departmentId,virtualType); rs.executeQuery("select departmentmark from hrmdepartmentvirtual where id = ? and virtualtype = ? order by showorder",departmentId,virtualType);
rs.next(); rs.next();
build = TreeDataVO.builder() build = TreeDataVO.builder()
.id(departmentId) .id(departmentId)
@ -129,11 +129,111 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
if (isVirtualSubDepartment(departmentId,virtualType)) { if (isVirtualSubDepartment(departmentId,virtualType)) {
build.setChildrens(getVirtualSubDept(departmentId,virtualType)); build.setChildrens(getVirtualSubDept(departmentId,virtualType));
} }
} // 根据id查询对应建模的虚拟部门领导
rs.executeQuery("select bmfzrid from uf_xnbmfzr where xnzzid = ? ",departmentId);
build.setLastName(rs.getString("bmfzrid"));
}
return build; return build;
} }
public static void main(String[] args) {
List<SelectVO> voList = assembleSelectVOList();
// 判断是否满足删除条件
for (int i = voList.size() - 1; i >= 0; i--) {
if(Integer.parseInt(voList.get(i).getValue())>5){
voList.remove(i);
}
}
List<SelectVO> collect = voList.stream().filter(SelectVO->Integer.parseInt(SelectVO.getValue())>5).collect(Collectors.toList());
TreeDataVO build;
int num = 1;
List<Integer> list = new ArrayList<>();
list.add(num);
List<ChartChildrensVO> childList4 = new ArrayList<>();
ChartChildrensVO chart5 = null;
chart5 = chart5.builder().id("1111").label("aaaa").pid("11111").childrens(null).build();
ChartChildrensVO chart6 = null;
chart6 = chart6.builder().id("2222").label("bbbb").pid("22222").childrens(null).build();
ChartChildrensVO chart7 = null;
chart7 = chart7.builder().id("2222").label("bbbb").pid("22222").childrens(null).build();
childList4.add(chart5);
childList4.add(chart6);
childList4.add(chart7);
List<ChartChildrensVO> childList3 = new ArrayList<>();
ChartChildrensVO chart3 = null;
chart3 = chart3.builder().id("1111").label("aaaa").pid("11111").childrens(null).build();
ChartChildrensVO chart4 = null;
chart4 = chart4.builder().id("2222").label("bbbb").pid("22222").childrens(null).build();
childList3.add(chart3);
childList3.add(chart4);
List<ChartChildrensVO> childList2 = new ArrayList<>();
ChartChildrensVO chart1 = null;
chart1 = chart1.builder().id("111").label("aaa").pid("1111").childrens(childList3).build();
ChartChildrensVO chart2 = null;
chart2 = chart2.builder().id("222").label("bbb").pid("2222").childrens(childList3).build();
childList2.add(chart1);
childList2.add(chart2);
List<ChartChildrensVO> childList1 = new ArrayList<>();
ChartChildrensVO chartChildrensVO1 = null;
chartChildrensVO1 = chartChildrensVO1.builder().id("11").label("aa").pid("111").childrens(childList2).build();
ChartChildrensVO chartChildrensVO2 = null;
chartChildrensVO2 = chartChildrensVO2.builder().id("22").label("bb").pid("222").childrens(childList2).build();
ChartChildrensVO chartChildrensVO3 = null;
chartChildrensVO3 = chartChildrensVO3.builder().id("33").label("cc").pid("333").childrens(childList2).build();
ChartChildrensVO chartChildrensVO4 = null;
chartChildrensVO4 = chartChildrensVO4.builder().id("44").label("dd").pid("444").childrens(childList2).build();
childList1.add(chartChildrensVO1);
childList1.add(chartChildrensVO2);
childList1.add(chartChildrensVO3);
childList1.add(chartChildrensVO4);
build = TreeDataVO.builder()
.id("11")
.label("aa")
.childrens(childList1)
.build();
if(null!=build.getChildrens()&&build.getChildrens().size()>0){
for (ChartChildrensVO children : build.getChildrens()) {
num = maxDepth(children)+1;
list.add(num);
}
build.setNum(Collections.max(list)+1);
}else{
build.setNum(num);
}
}
/**
* n
* @param root
*/
public static int maxDepth(ChartChildrensVO root) {
if(CollectionUtils.isEmpty(root.getChildrens())){
return 0;
}
int num = 0;
if(!CollectionUtils.isEmpty(root.getChildrens())){
for (int i = 0; i < root.getChildrens().size(); i++) {
num = Math.max(num, 1 + maxDepth(root.getChildrens().get(i)));
}
}
return num;
}
private List<ChartChildrensVO> getVirtualSubDept(String supdepid,String virtualType) { private List<ChartChildrensVO> getVirtualSubDept(String supdepid,String virtualType) {
RecordSet rs = new RecordSet(); RecordSet rs = new RecordSet();
@ -149,11 +249,43 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
if (isVirtualSubDepartment(id,virtualType)) { if (isVirtualSubDepartment(id,virtualType)) {
build.setChildrens(getVirtualSubDept(id,virtualType)); build.setChildrens(getVirtualSubDept(id,virtualType));
} }
// 根据id查询对应建模的虚拟部门领导
rs.executeQuery("select bmfzrid from uf_xnbmfzr where xnzzid = ? ",id);
build.setLastName(rs.getString("bmfzrid"));
voList.add(build); voList.add(build);
} }
return voList; return voList;
} }
private List<ChartChildrensVO> getVirtualSubDeptData(String supdepid,String virtualType) {
RecordSet rs = new RecordSet();
List<ChartChildrensVO> voList = new ArrayList<>();
rs.executeQuery("select id,departmentmark from hrmdepartmentvirtual where supdepid <> '' and supdepid = ? and virtualtype = ? order by showorder",supdepid,virtualType);
while (rs.next()) {
String id = Util.null2String(rs.getString("id"));
ChartChildrensVO build = ChartChildrensVO.builder()
.pid(supdepid)
.id(getRandomData()+id)
.label(Util.null2String(rs.getString("departmentmark")))
.build();
if (isVirtualSubDepartment(id,virtualType)) {
build.setChildrens(getVirtualSubDeptData(id,virtualType));
}
voList.add(build);
}
return voList;
}
private String getRandomData() {
String name="";//先定义空字符串
for (int i=0;i<3;i++){
char n=(char)(new Random().nextInt(26)+97) ;
name += n;//name=name+n;
}
return name;
}
@Override @Override
public boolean isVirtualSubDepartment(String supdepid,String virtualType) { public boolean isVirtualSubDepartment(String supdepid,String virtualType) {
RecordSet rs = new RecordSet(); RecordSet rs = new RecordSet();
@ -215,6 +347,97 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
return voList; return voList;
} }
@Override
public TreeDataVO selectVirtualTopTwo(String virtualType) {
RecordSet rs = new RecordSet();
BaseBean bb = new BaseBean();
TreeDataVO build;
String roleId = bb.getPropValue("sship", "roleId");
String rolelevel = bb.getPropValue("sship", "rolelevel");
boolean isExsit = selectIdsByRole(roleId, rolelevel);
if (isExsit || (user.getUID() == 1)) {
//ShareHolder唯一
rs.executeQuery("select id,departmentmark from hrmdepartmentvirtual where supdepid = 0 and virtualtype = ? order by showorder",virtualType);
rs.next();
String id = Util.null2String(rs.getString("id"));
build = TreeDataVO.builder()
.id(getRandomData()+id)
.label(Util.null2String(rs.getString("departmentmark")))
.build();
if (isVirtualSubDepartment(id,virtualType)) {
build.setChildrens(getVirtualSubDeptData(id,virtualType));
}
} else {
//获取当前部门
rs.executeQuery("select departmentid from hrmresourcevirtual where resourceid = ? and virtualtype = ?",user.getUID(),virtualType);
rs.next();
String departmentId = Util.null2String(rs.getString("departmentid"));
rs.executeQuery("select departmentmark from hrmdepartmentvirtual where id = ? and virtualtype = ? order by showorder",departmentId,virtualType);
rs.next();
build = TreeDataVO.builder()
.id(getRandomData()+departmentId)
.label(Util.null2String(rs.getString("departmentmark")))
.build();
if (isVirtualSubDepartment(departmentId,virtualType)) {
build.setChildrens(getVirtualSubDeptData(departmentId,virtualType));
}
}
return build;
}
@Override
public List<SelectVO> selectVirtualTopThree(VirtualTopParam virtualTopParam) {
RecordSet rs = new RecordSet();
List<SelectVO> voList = assembleSelectVOList();
TreeDataVO build;
int num = 1;
List<Integer> list = new ArrayList<>();
list.add(num);
rs.executeQuery("select departmentmark from hrmdepartmentvirtual where id = ? and virtualtype = ? order by showorder",virtualTopParam.getId(),virtualTopParam.getVirtualType());
rs.next();
build = TreeDataVO.builder()
.id(virtualTopParam.getId())
.label(Util.null2String(rs.getString("departmentmark")))
.build();
if (isVirtualSubDepartment(virtualTopParam.getId(),virtualTopParam.getVirtualType())) {
build.setChildrens(getVirtualSubDept(virtualTopParam.getId(),virtualTopParam.getVirtualType()));
}
if(null!=build.getChildrens()&&build.getChildrens().size()>0){
for (ChartChildrensVO children : build.getChildrens()) {
num = maxDepth(children)+1;
list.add(num);
}
build.setNum(Collections.max(list)+1);
}else{
build.setNum(num);
}
// 判断是否满足删除条件
for (int i = voList.size() - 1; i >= 0; i--) {
if(Integer.parseInt(voList.get(i).getValue())>build.getNum()){
voList.remove(i);
}
}
//MAP.entrySet().removeIf(entry -> Integer.parseInt(entry.getKey()) > build.getNum());
return voList;
}
private static List<SelectVO> assembleSelectVOList() {
List<SelectVO> voList = new ArrayList<>();
voList.add(SelectVO.builder().value("1").label("一级").build());
voList.add(SelectVO.builder().value("2").label("二级").build());
voList.add(SelectVO.builder().value("3").label("三级").build());
voList.add(SelectVO.builder().value("4").label("四级").build());
voList.add(SelectVO.builder().value("5").label("五级").build());
voList.add(SelectVO.builder().value("6").label("六级").build());
voList.add(SelectVO.builder().value("7").label("七级").build());
voList.add(SelectVO.builder().value("8").label("八级").build());
voList.add(SelectVO.builder().value("9").label("九级").build());
voList.add(SelectVO.builder().value("10").label("十级").build());
return voList;
}
private List<PersonTablePO> selectByLevel(Integer level) { private List<PersonTablePO> selectByLevel(Integer level) {
RecordSet rs = new RecordSet(); RecordSet rs = new RecordSet();

@ -1,10 +1,7 @@
package com.engine.sship.web; package com.engine.sship.web;
import com.engine.common.util.ServiceUtil; import com.engine.common.util.ServiceUtil;
import com.engine.sship.entity.PersonTableParam; import com.engine.sship.entity.*;
import com.engine.sship.entity.PersonTableVO;
import com.engine.sship.entity.SelectVO;
import com.engine.sship.entity.TreeDataVO;
import com.engine.sship.service.OrgChartService; import com.engine.sship.service.OrgChartService;
import com.engine.sship.service.impl.OrgChartServiceImpl; import com.engine.sship.service.impl.OrgChartServiceImpl;
import com.engine.sship.util.ResponseResult; import com.engine.sship.util.ResponseResult;
@ -20,6 +17,7 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
@ -79,7 +77,23 @@ public class OrgChartController {
return new ResponseResult<PersonTableParam, List<SelectVO>>(user).run(getOrgChartService(user) :: selectVirtualTop); return new ResponseResult<PersonTableParam, List<SelectVO>>(user).run(getOrgChartService(user) :: selectVirtualTop);
} }
@GET
@Path("/virtual-top-two")
@Produces(MediaType.APPLICATION_JSON)
public String selectVirtualTopTwo(@Context HttpServletRequest request, @Context HttpServletResponse response,@QueryParam("virtualType") String virtualType) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<String, TreeDataVO>(user).run(getOrgChartService(user) :: selectVirtualTopTwo,virtualType);
}
@GET
@Path("/virtual-top-three")
@Produces(MediaType.APPLICATION_JSON)
public String selectVirtualTopThree(@Context HttpServletRequest request, @Context HttpServletResponse response,
@QueryParam("id") String id,
@QueryParam("virtualType") String virtualType) {
User user = HrmUserVarify.getUser(request, response);
VirtualTopParam build = VirtualTopParam.builder().id(id.substring(3)).virtualType(virtualType).build();
return new ResponseResult<VirtualTopParam, List<SelectVO>>(user).run(getOrgChartService(user) :: selectVirtualTopThree,build);
}

Loading…
Cancel
Save