组织架构图优化

18880demo环境
Administrator 1 year ago
parent caafa04769
commit 22f7c55354

@ -8,6 +8,7 @@ import com.engine.sship.service.OrgChartService;
import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet;
@ -23,6 +24,7 @@ import java.util.stream.Collectors;
* @Description:
* @Version 1.0
*/
@Slf4j
public class OrgChartServiceImpl extends Service implements OrgChartService {
private final HrmCommonService hrmCommonService = new HrmCommonServiceImpl();
@ -96,6 +98,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
String virtualType = orgTreeParam.getVirtualType();
String root = orgTreeParam.getRoot();
String level = orgTreeParam.getLevel();
log.info("selectVirtualTopTwo.orgTreeParam:{}",orgTreeParam);
TreeDataVO build;
String id;
//判断参数是总部、分部、部门id
@ -103,10 +106,11 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
build = getBaseTree(virtualType);
} else {
//判断入参类型
int judgeId = judgeId(virtualType, root);
int judgeId = judgeId(root);
log.info("selectOrganizationChart.judgeId:{}",judgeId);
switch(judgeId){
case 1:
rs.executeQuery("select id,subcompanyname from hrmsubcompany where id = ? and SUPSUBCOMID = '0' ", root.substring(3));
rs.executeQuery("select id,subcompanyname from hrmsubcompany where id = ? and SUPSUBCOMID = '0' ", root.contains("fenbu")?root.substring(8):root.substring(3));
rs.next();
id = rs.getString("id");
build = TreeDataVO.builder()
@ -160,6 +164,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
rs.executeQuery("select id,companyname from hrmcompany where id =? ", virtualType);
rs.next();
String id = rs.getString("id");
log.info("getBaseTree.hrmcompany:{}",id);
TreeDataVO build = TreeDataVO.builder()
.id(id)
.label(Util.null2String(rs.getString("companyname")))
@ -170,26 +175,45 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
return build;
}
private int judgeId(String virtualType,String root){
private static int judgeId(String root){
log.info("judgeId88888888.root:{}",root);
RecordSet rs = new RecordSet();
int id = 0;
if(virtualType.equals(root)){
return 0;
if(root.contains("fenbu")){
rs.executeQuery("select count(1) from hrmsubcompany where id = ? ",root.substring(8));
if (rs.next()) {
if(rs.getInt(1) > 0){
return 1;
}
}
}
//root为总部
rs.executeQuery("select count(1) from hrmcompany where id = ?",root.substring(3));
if (rs.next()) {
if(rs.getInt(1) > 0){
return 0;
}
}
//root为分部
rs.executeQuery("select count(1) from hrmsubcompany where id = ?",root.substring(3));
rs.executeQuery("select count(1) from hrmsubcompany where id = ? ",root.substring(3));
if (rs.next()) {
id = 1;
if(rs.getInt(1) > 0){
return 1;
}
}
//root为上级部门
rs.executeQuery("select count(1) from hrmdepartment where id = ? and SUPDEPID = '0'",root.substring(3));
rs.executeQuery("select count(1) from hrmdepartment where id = ? and SUPDEPID = 0",root.substring(3));
if (rs.next()) {
id = 2;
if(rs.getInt(1) > 0){
return 2;
}
}
//root为下级部门
rs.executeQuery("select count(1) from hrmdepartment where id = ?",root.substring(3));
if (rs.next()) {
id = 3;
if(rs.getInt(1) > 0){
return 3;
}
}
return id;
}
@ -199,10 +223,11 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
rs.executeQuery("select id,subcompanyname from hrmsubcompany where COMPANYID = ? and SUPSUBCOMID = '0' order by showorder",companyId);
while (rs.next()) {
String id = Util.null2String(rs.getString("id"));
log.info("getSubCompanyBase.hrmsubcompany:{}",id);
ChartChildrensVO build = ChartChildrensVO.builder()
.id(getRandomData()+id)
.id(id.equals(companyId)?"fenbu"+getRandomData()+id:getRandomData()+id)
.pid(companyId)
.label(Util.null2String(rs.getString("subcompanyname")))
.label(StringUtils.isBlank(rs.getString("subcompanyname"))?"无名称":rs.getString("subcompanyname"))
.build();
if (isSubDepartment(id)) {
build.setChildrens(getSubDeptBase(id));
@ -218,13 +243,14 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
rs.executeQuery("select id,departmentmark from hrmdepartment where subcompanyid1 = ? and SUPDEPID = 0 order by showorder",id);
while (rs.next()) {
String deptId = Util.null2String(rs.getString("id"));
log.info("getSubDeptBase.hrmdepartment:{}",deptId);
ChartChildrensVO build = ChartChildrensVO.builder()
.id(getRandomData()+deptId)
.pid(id)
.label(Util.null2String(rs.getString("departmentmark")))
.build();
if (isSubDepartmentChildren(id)) {
build.setChildrens(getSubDeptChildrenBase(id));
if (isSubDepartmentChildren(deptId)) {
build.setChildrens(getSubDeptChildrenBase(deptId));
}
voList.add(build);
}
@ -236,13 +262,14 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
rs.executeQuery("select id,departmentmark from hrmdepartment where SUPDEPID = ? order by showorder",id);
while (rs.next()) {
String deptId = Util.null2String(rs.getString("id"));
log.info("getSubDeptChildrenBase.hrmdepartment:{}",deptId);
ChartChildrensVO build = ChartChildrensVO.builder()
.id(getRandomData()+deptId)
.pid(id)
.label(Util.null2String(rs.getString("departmentmark")))
.build();
if (isSubDepartmentChildren(id)) {
build.setChildrens(getSubDeptChildrenBase(id));
if (isSubDepartmentChildren(deptId)) {
build.setChildrens(getSubDeptChildrenBase(deptId));
}
voList.add(build);
}
@ -253,57 +280,187 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
*
* @param childrens
*/
public static List<ChartChildrensVO> setTreeStructure(List<ChartChildrensVO> childrens,int level) {
switch(level){
public static List<ChartChildrensVO> setTreeStructure(List<ChartChildrensVO> childrens, int level) {
log.info("setTreeStructure.data:{},level:{}", childrens, level);
switch (level) {
case 2:
childrens.forEach(childrensVO->childrensVO.setChildrens(null));
childrens.forEach(childrensVO -> {
childrensVO.setChildrens(null);
});
break;
case 3:
childrens.forEach(childrensVO->childrensVO.getChildrens().forEach(childrensVO1 -> childrensVO1.setChildrens(null)));
childrens.forEach(childrensVO -> {
if (childrensVO.getChildrens() != null) {
childrensVO.getChildrens().forEach(childrensVO1 -> childrensVO1.setChildrens(null));
}
});
break;
case 4:
childrens.forEach(childrensVO->childrensVO.getChildrens().forEach(childrensVO1 ->
childrensVO1.getChildrens().forEach(childrensVO2 -> childrensVO2.setChildrens(null))));
childrens.forEach(childrensVO -> {
if (childrensVO.getChildrens() != null) {
childrensVO.getChildrens().forEach(childrensVO1 -> {
if (childrensVO1.getChildrens() != null) {
childrensVO1.getChildrens().forEach(childrensVO2 -> childrensVO2.setChildrens(null));
}
});
}
});
break;
case 5:
childrens.forEach(childrensVO->childrensVO.getChildrens().forEach(childrensVO1 ->
childrensVO1.getChildrens().forEach(childrensVO2 -> childrensVO2.getChildrens().forEach(childrensVO3 ->
childrensVO3.setChildrens(null)))));
childrens.forEach(childrensVO -> {
if (childrensVO.getChildrens() != null) {
childrensVO.getChildrens().forEach(childrensVO1 -> {
if (childrensVO1.getChildrens() != null) {
childrensVO1.getChildrens().forEach(childrensVO2 -> {
if (childrensVO2.getChildrens() != null) {
childrensVO2.getChildrens().forEach(childrensVO3 -> childrensVO3.setChildrens(null));
}
});
}
});
}
});
break;
case 6:
childrens.forEach(childrensVO->childrensVO.getChildrens().forEach(childrensVO1 ->
childrensVO1.getChildrens().forEach(childrensVO2 -> childrensVO2.getChildrens().forEach(childrensVO3 ->
childrensVO3.getChildrens().forEach(childrensVO4 -> childrensVO4.setChildrens(null))))));
childrens.forEach(childrensVO -> {
if (childrensVO.getChildrens() != null) {
childrensVO.getChildrens().forEach(childrensVO1 -> {
if (childrensVO1.getChildrens() != null) {
childrensVO1.getChildrens().forEach(childrensVO2 -> {
if (childrensVO2.getChildrens() != null) {
childrensVO2.getChildrens().forEach(childrensVO3 -> {
if (childrensVO3.getChildrens() != null) {
childrensVO3.getChildrens().forEach(childrensVO4 -> childrensVO4.setChildrens(null));
}
});
}
});
}
});
}
});
break;
case 7:
childrens.forEach(childrensVO->childrensVO.getChildrens().forEach(childrensVO1 ->
childrensVO1.getChildrens().forEach(childrensVO2 -> childrensVO2.getChildrens().forEach(childrensVO3 ->
childrensVO3.getChildrens().forEach(childrensVO4 -> childrensVO4.getChildrens().
forEach(childrensVO5 -> childrensVO5.setChildrens(null)))))));
childrens.forEach(childrensVO -> {
if (childrensVO.getChildrens() != null) {
childrensVO.getChildrens().forEach(childrensVO1 -> {
if (childrensVO1.getChildrens() != null) {
childrensVO1.getChildrens().forEach(childrensVO2 -> {
if (childrensVO2.getChildrens() != null) {
childrensVO2.getChildrens().forEach(childrensVO3 -> {
if (childrensVO3.getChildrens() != null) {
childrensVO3.getChildrens().forEach(childrensVO4 -> {
if (childrensVO4.getChildrens() != null) {
childrensVO4.getChildrens().forEach(childrensVO5 -> childrensVO5.setChildrens(null));
}
});
}
});
}
});
}
});
}
});
break;
case 8:
childrens.forEach(childrensVO->childrensVO.getChildrens().forEach(childrensVO1 ->
childrensVO1.getChildrens().forEach(childrensVO2 -> childrensVO2.getChildrens().forEach(childrensVO3 ->
childrensVO3.getChildrens().forEach(childrensVO4 -> childrensVO4.getChildrens().
forEach(childrensVO5 -> childrensVO5.getChildrens().forEach(childrensVO6 -> childrensVO6.setChildrens(null))))))));
childrens.forEach(childrensVO -> {
if (childrensVO.getChildrens() != null) {
childrensVO.getChildrens().forEach(childrensVO1 -> {
if (childrensVO1.getChildrens() != null) {
childrensVO1.getChildrens().forEach(childrensVO2 -> {
if (childrensVO2.getChildrens() != null) {
childrensVO2.getChildrens().forEach(childrensVO3 -> {
if (childrensVO3.getChildrens() != null) {
childrensVO3.getChildrens().forEach(childrensVO4 -> {
if (childrensVO4.getChildrens() != null) {
childrensVO4.getChildrens().forEach(childrensVO5 -> {
if (childrensVO5.getChildrens() != null) {
childrensVO5.getChildrens().forEach(childrensVO6 -> childrensVO6.setChildrens(null));
}
});
}
});
}
});
}
});
}
});
}
});
break;
case 9:
childrens.forEach(childrensVO->childrensVO.getChildrens().forEach(childrensVO1 ->
childrensVO1.getChildrens().forEach(childrensVO2 -> childrensVO2.getChildrens().forEach(childrensVO3 ->
childrensVO3.getChildrens().forEach(childrensVO4 -> childrensVO4.getChildrens().
forEach(childrensVO5 -> childrensVO5.getChildrens().forEach(childrensVO6 ->
childrensVO6.getChildrens().forEach(childrensVO7 -> childrensVO7.setChildrens(null)))))))));
childrens.forEach(childrensVO -> {
if (childrensVO.getChildrens() != null) {
childrensVO.getChildrens().forEach(childrensVO1 -> {
if (childrensVO1.getChildrens() != null) {
childrensVO1.getChildrens().forEach(childrensVO2 -> {
if (childrensVO2.getChildrens() != null) {
childrensVO2.getChildrens().forEach(childrensVO3 -> {
if (childrensVO3.getChildrens() != null) {
childrensVO3.getChildrens().forEach(childrensVO4 -> {
if (childrensVO4.getChildrens() != null) {
childrensVO4.getChildrens().forEach(childrensVO5 -> {
if (childrensVO5.getChildrens() != null) {
childrensVO5.getChildrens().forEach(childrensVO6 -> {
if (childrensVO6.getChildrens() != null) {
childrensVO6.getChildrens().forEach(childrensVO7 -> childrensVO7.setChildrens(null));
}
});
}
});
}
});
}
});
}
});
}
});
}
});
break;
case 10:
childrens.forEach(childrensVO->childrensVO.getChildrens().forEach(childrensVO1 ->
childrensVO1.getChildrens().forEach(childrensVO2 -> childrensVO2.getChildrens().forEach(childrensVO3 ->
childrensVO3.getChildrens().forEach(childrensVO4 -> childrensVO4.getChildrens().
forEach(childrensVO5 -> childrensVO5.getChildrens().forEach(childrensVO6 ->
childrensVO6.getChildrens().forEach(childrensVO7 ->
childrensVO7.getChildrens().forEach(childrensVO8 -> childrensVO8.setChildrens(null))))))))));
childrens.forEach(childrensVO -> {
if (childrensVO.getChildrens() != null) {
childrensVO.getChildrens().forEach(childrensVO1 -> {
if (childrensVO1.getChildrens() != null) {
childrensVO1.getChildrens().forEach(childrensVO2 -> {
if (childrensVO2.getChildrens() != null) {
childrensVO2.getChildrens().forEach(childrensVO3 -> {
if (childrensVO3.getChildrens() != null) {
childrensVO3.getChildrens().forEach(childrensVO4 -> {
if (childrensVO4.getChildrens() != null) {
childrensVO4.getChildrens().forEach(childrensVO5 -> {
if (childrensVO5.getChildrens() != null) {
childrensVO5.getChildrens().forEach(childrensVO6 -> {
if (childrensVO6.getChildrens() != null) {
childrensVO6.getChildrens().forEach(childrensVO7 -> {
if (childrensVO7.getChildrens() != null) {
childrensVO7.getChildrens().forEach(childrensVO8 -> childrensVO8.setChildrens(null));
}
});
}
});
}
});
}
});
}
});
}
});
}
});
}
});
break;
default:
childrens.forEach(childrensVO->childrensVO.setChildrens(null));
childrens.forEach(childrensVO -> childrensVO.setChildrens(null));
}
return childrens;
}
@ -423,6 +580,7 @@ public List<DropTreeDataVO> selectVirtualTopTwo(String virtualType) {
rs.executeQuery("select id,companyname from hrmcompany where id = ?",virtualType);
rs.next();
String id = Util.null2String(rs.getString("id"));
log.info("selectVirtualTopTwo.companyname:{}",id);
build = DropTreeDataVO.builder()
.value(getRandomData()+id)
.label(Util.null2String(rs.getString("companyname")))
@ -440,9 +598,10 @@ public List<DropTreeDataVO> selectVirtualTopTwo(String virtualType) {
rs.executeQuery("select id,subcompanyname from hrmsubcompany where COMPANYID = ? and SUPSUBCOMID = '0' order by showorder",companyId);
while (rs.next()) {
String id = Util.null2String(rs.getString("id"));
log.info("selectVirtualTopTwo.hrmsubcompany:{}",id);
DropTreeDataVO build = DropTreeDataVO.builder()
.value(getRandomData()+id)
.label(Util.null2String(rs.getString("subcompanyname")))
.value(id.equals(companyId)?"fenbu"+getRandomData()+id:getRandomData()+id)
.label(StringUtils.isBlank(rs.getString("subcompanyname"))?"无名称":rs.getString("subcompanyname"))
.build();
if (isSubDepartment(id)) {
build.setChildren(getSubDept(id));
@ -485,12 +644,13 @@ public List<DropTreeDataVO> selectVirtualTopTwo(String virtualType) {
rs.executeQuery("select id,departmentmark from hrmdepartment where subcompanyid1 = ? and SUPDEPID = 0 order by showorder",id);
while (rs.next()) {
String deptId = Util.null2String(rs.getString("id"));
log.info("selectVirtualTopTwo.hrmdepartment1:{}",deptId);
DropTreeDataVO build = DropTreeDataVO.builder()
.value(getRandomData()+deptId)
.label(Util.null2String(rs.getString("departmentmark")))
.build();
if (isSubDepartmentChildren(id)) {
build.setChildren(getSubDeptChildren(id));
if (isSubDepartmentChildren(deptId)) {
build.setChildren(getSubDeptChildren(deptId));
}
voList.add(build);
}
@ -502,12 +662,13 @@ public List<DropTreeDataVO> selectVirtualTopTwo(String virtualType) {
rs.executeQuery("select id,departmentmark from hrmdepartment where SUPDEPID = ? order by showorder",id);
while (rs.next()) {
String deptId = Util.null2String(rs.getString("id"));
log.info("selectVirtualTopTwo.hrmdepartment2:{}",deptId);
DropTreeDataVO build = DropTreeDataVO.builder()
.value(getRandomData()+deptId)
.label(Util.null2String(rs.getString("departmentmark")))
.build();
if (isSubDepartmentChildren(id)) {
build.setChildren(getSubDeptChildren(id));
if (isSubDepartmentChildren(deptId)) {
build.setChildren(getSubDeptChildren(deptId));
}
voList.add(build);
}
@ -526,9 +687,9 @@ public List<DropTreeDataVO> selectVirtualTopTwo(String virtualType) {
List<Integer> list = new ArrayList<>();
list.add(num);
//判断入参类型
switch(judgeId(virtualType, root)){
switch(judgeId(root)){
case 1:
rs.executeQuery("select id,subcompanyname from hrmsubcompany where id = ? and SUPSUBCOMID = '0' ", root.substring(3));
rs.executeQuery("select id,subcompanyname from hrmsubcompany where id = ? and SUPSUBCOMID = '0' ", root.contains("fenbu")?root.substring(8):root.substring(3));
rs.next();
id = rs.getString("id");
build = TreeDataVO.builder()

@ -94,7 +94,7 @@ public class OrgChartController {
@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();
VirtualTopParam build = VirtualTopParam.builder().id(id).virtualType(virtualType).build();
return new ResponseResult<VirtualTopParam, List<SelectVO>>(user).run(getOrgChartService(user) :: selectVirtualTopThree,build);
}

Loading…
Cancel
Save