组织架构图优化

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

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

Loading…
Cancel
Save