虚拟维度组织架构图完成

顺胜组织架构图V2
Chengliang 1 year ago
parent a8ff1c021c
commit 89ff0ea423

@ -0,0 +1,24 @@
package com.engine.sship.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author liang.cheng
* @Date 2024/1/8 3:33 PM
* @Description: TODO
* @Version 1.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SelectVO {
private String value;
private String label;
}

@ -3,6 +3,7 @@ package com.engine.sship.service;
import com.engine.sship.entity.PersonTableParam; import com.engine.sship.entity.PersonTableParam;
import com.engine.sship.entity.PersonTableVO; import com.engine.sship.entity.PersonTableVO;
import com.engine.sship.entity.SelectVO;
import com.engine.sship.entity.TreeDataVO; import com.engine.sship.entity.TreeDataVO;
import java.util.List; import java.util.List;
@ -24,7 +25,7 @@ public interface OrgChartService {
boolean selectIdsByRole(String roleId,String rolelevel); boolean selectIdsByRole(String roleId,String rolelevel);
/** /**
* @Description: * @Description:
* @Author: liang.cheng * @Author: liang.cheng
* @Date: 2024/1/3 10:07 AM * @Date: 2024/1/3 10:07 AM
* @param: [] * @param: []
@ -50,4 +51,41 @@ public interface OrgChartService {
* @return: com.engine.sship.entity.PersonTableVO * @return: com.engine.sship.entity.PersonTableVO
*/ */
List<PersonTableVO> selectPerson(PersonTableParam personTableParam); List<PersonTableVO> selectPerson(PersonTableParam personTableParam);
/**
* @Description:
* @Author: liang.cheng
* @Date: 2024/1/8 10:44 AM
* @param: []
* @return: com.engine.sship.entity.TreeDataVO
*/
TreeDataVO selectOrganizationChart(String virtualType);
/**
* @Description:
* @Author: liang.cheng
* @Date: 2024/1/8 1:52 PM
* @param: [supdepid]
* @return: boolean
*/
boolean isVirtualSubDepartment(String supdepid,String virtualType);
/**
* @Description:
* @Author: liang.cheng
* @Date: 2024/1/8 2:59 PM
* @param: [personTableParam]
* @return: java.util.List<com.engine.sship.entity.PersonTableVO>
*/
List<PersonTableVO> selectVirtualPerson(PersonTableParam personTableParam);
/**
* @Description:
* @Author: liang.cheng
* @Date: 2024/1/8 3:41 PM
* @param: []
* @return: java.util.List<com.engine.sship.entity.PersonTableVO>
*/
List<SelectVO> selectVirtualTop();
} }

@ -8,6 +8,8 @@ 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 org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import weaver.conn.RecordSet; import weaver.conn.RecordSet;
import weaver.hrm.company.DepartmentComInfo; import weaver.hrm.company.DepartmentComInfo;
import weaver.hrm.resource.ResourceComInfo; import weaver.hrm.resource.ResourceComInfo;
@ -93,6 +95,126 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Override
public TreeDataVO selectOrganizationChart(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 = ?",virtualType);
rs.next();
String id = Util.null2String(rs.getString("id"));
build = TreeDataVO.builder()
.id(id)
.label(Util.null2String(rs.getString("departmentmark")))
.build();
if (isVirtualSubDepartment(id,virtualType)) {
build.setChildrens(getVirtualSubDept(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 = ?",departmentId,virtualType);
rs.next();
build = TreeDataVO.builder()
.id(departmentId)
.label(Util.null2String(rs.getString("departmentmark")))
.build();
if (isVirtualSubDepartment(departmentId,virtualType)) {
build.setChildrens(getVirtualSubDept(departmentId,virtualType));
}
}
return build;
}
private List<ChartChildrensVO> getVirtualSubDept(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 = ?",supdepid,virtualType);
while (rs.next()) {
String id = Util.null2String(rs.getString("id"));
ChartChildrensVO build = ChartChildrensVO.builder()
.pid(supdepid)
.id(id)
.label(Util.null2String(rs.getString("departmentmark")))
.build();
if (isVirtualSubDepartment(id,virtualType)) {
build.setChildrens(getVirtualSubDept(id,virtualType));
}
voList.add(build);
}
return voList;
}
@Override
public boolean isVirtualSubDepartment(String supdepid,String virtualType) {
RecordSet rs = new RecordSet();
boolean isSupdepid = false;
rs.executeQuery("select count(1) from hrmdepartmentvirtual where supdepid <> '' and supdepid = ? and virtualtype = ?",supdepid,virtualType);
if (rs.next()) {
isSupdepid = rs.getInt(1) > 0;
}
return isSupdepid;
}
@SneakyThrows
@Override
public List<PersonTableVO> selectVirtualPerson(PersonTableParam personTableParam) {
RecordSet rs = new RecordSet();
List<Integer> idList = new ArrayList<>();
ResourceComInfo rInfo = new ResourceComInfo();
List<PersonTableVO> voList = new ArrayList<>();
List<PersonTablePO> poList = new ArrayList<>();
rs.executeQuery("select resourceid from hrmresourcevirtual where departmentid = ?",personTableParam.getId());
while (rs.next()) {
idList.add(Util.getIntValue(rs.getString("resourceid")));
}
if (CollectionUtils.isNotEmpty(idList)) {
rs.executeQuery("select id,lastname,workcode,sex,managerid,loginid from hrmresource where status < 4 and id in ("+ StringUtils.join(idList,",")+")");
while (rs.next()) {
poList.add(
PersonTablePO.builder()
.id(Util.getIntValue(rs.getString("id")))
.lastname(Util.null2String(rs.getString("lastname")))
.workcode(Util.null2String(rs.getString("workcode")))
.sex(Util.getIntValue(rs.getString("sex")))
.managerid(Util.getIntValue(rs.getString("managerid")))
.loginid(Util.null2String(rs.getString("loginid")))
.build()
);
}
voList = poList.stream()
.map(po -> new PersonTableVO(po.getId(), po.getLastname(), po.getWorkcode(),
po.getSex() == 0 ? "男" : "女",
po.getManagerid() != null ? rInfo.getLastname(String.valueOf(po.getManagerid())) : "",
po.getLoginid()))
.collect(Collectors.toList());
}
return voList;
}
@Override
public List<SelectVO> selectVirtualTop() {
List<SelectVO> voList = new ArrayList<>();
RecordSet rs = new RecordSet();
rs.executeQuery("select id,companyname from hrmcompanyvirtual");
while (rs.next()) {
voList.add(SelectVO.builder()
.value(Util.null2String(rs.getString("id")))
.label(Util.null2String(rs.getString("companyname"))).build());
}
return voList;
}
private List<PersonTablePO> selectByLevel(Integer level) { private List<PersonTablePO> selectByLevel(Integer level) {
RecordSet rs = new RecordSet(); RecordSet rs = new RecordSet();
@ -143,14 +265,12 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
@SneakyThrows @SneakyThrows
private TreeDataVO getBaseTreeData() { private TreeDataVO getBaseTreeData() {
int uid = user.getUID(); int uid = user.getUID();
List<Integer> idList = selectCusSiteHead();
boolean contains = idList.contains(uid);
DepartmentComInfo dInfo = new DepartmentComInfo(); DepartmentComInfo dInfo = new DepartmentComInfo();
ResourceComInfo rInfo = new ResourceComInfo(); ResourceComInfo rInfo = new ResourceComInfo();
String departmentId = rInfo.getDepartmentID(String.valueOf(uid)); String departmentId = rInfo.getDepartmentID(String.valueOf(uid));
TreeDataVO build = TreeDataVO.builder() TreeDataVO build = TreeDataVO.builder()
.id(departmentId) .id(departmentId)
.label(contains ? dInfo.getDepartmentName(departmentId) : rInfo.getLastname(String.valueOf(uid))) .label(dInfo.getDepartmentName(departmentId))
.build(); .build();
boolean manager = hrmCommonService.isManager(uid); boolean manager = hrmCommonService.isManager(uid);
if (manager) { if (manager) {
@ -189,8 +309,7 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
ChartChildrensVO build = ChartChildrensVO.builder() ChartChildrensVO build = ChartChildrensVO.builder()
.id(departmentId) .id(departmentId)
.pid("C-1") .pid("C-1")
//.label(dInfo.getDepartmentmark(departmentId)) .label(dInfo.getDepartmentmark(departmentId))
.label(rInfo.getLastname(String.valueOf(item)))
.build(); .build();
boolean manager = hrmCommonService.isManager(item); boolean manager = hrmCommonService.isManager(item);
if (manager) { if (manager) {
@ -214,24 +333,32 @@ public class OrgChartServiceImpl extends Service implements OrgChartService {
DepartmentComInfo dInfo = new DepartmentComInfo(); DepartmentComInfo dInfo = new DepartmentComInfo();
ResourceComInfo rInfo = new ResourceComInfo(); ResourceComInfo rInfo = new ResourceComInfo();
String underling = hrmCommonService.getUnderling(id); String underling = hrmCommonService.getUnderling(id);
String localId = rInfo.getDepartmentID(String.valueOf(id));
//获取直接下属 //获取直接下属
List<String> underList = Arrays.stream(underling.split(",")) List<String> underList = Arrays.stream(underling.split(","))
.filter(s -> !s.isEmpty()) .filter(s -> !s.isEmpty())
.collect(Collectors.toList()); .collect(Collectors.toList());
underList.forEach(item -> {
for (String item : underList) {
String departmentId = rInfo.getDepartmentID(String.valueOf(item)); String departmentId = rInfo.getDepartmentID(String.valueOf(item));
//过滤同部门和子部门
boolean exists = vos.stream()
.anyMatch(e -> e.getId().equals(departmentId));
if (departmentId.equals(localId) || exists){
continue;
}
ChartChildrensVO build = ChartChildrensVO.builder() ChartChildrensVO build = ChartChildrensVO.builder()
.id(departmentId) .id(departmentId)
.pid(item) .pid(item)
//.label(dInfo.getDepartmentmark(departmentId)) .label(dInfo.getDepartmentmark(departmentId))
.label(rInfo.getLastname(String.valueOf(item)))
.build(); .build();
boolean manager = hrmCommonService.isManager(Integer.valueOf(item)); boolean manager = hrmCommonService.isManager(Integer.valueOf(item));
if (manager) { if (manager) {
build.setChildrens(recursionDepartment(Integer.valueOf(item))); build.setChildrens(recursionDepartment(Integer.valueOf(item)));
} }
vos.add(build); vos.add(build);
}); }
return vos; return vos;
} }

@ -3,6 +3,7 @@ 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.PersonTableParam;
import com.engine.sship.entity.PersonTableVO; import com.engine.sship.entity.PersonTableVO;
import com.engine.sship.entity.SelectVO;
import com.engine.sship.entity.TreeDataVO; 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;
@ -42,6 +43,16 @@ public class OrgChartController {
return new ResponseResult<String, TreeDataVO>(user).run(getOrgChartService(user) :: selectResourceChart); return new ResponseResult<String, TreeDataVO>(user).run(getOrgChartService(user) :: selectResourceChart);
} }
@GET
@Path("/organization-tree")
@Produces(MediaType.APPLICATION_JSON)
public String selectOrganizationChart(@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) :: selectOrganizationChart,virtualType);
}
@GET @GET
@Path("/person") @Path("/person")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -51,6 +62,25 @@ public class OrgChartController {
return new ResponseResult<PersonTableParam, List<PersonTableVO>>(user).run(getOrgChartService(user) :: selectPerson,build); return new ResponseResult<PersonTableParam, List<PersonTableVO>>(user).run(getOrgChartService(user) :: selectPerson,build);
} }
@GET
@Path("/virtual-person")
@Produces(MediaType.APPLICATION_JSON)
public String selectVirtualPerson(@Context HttpServletRequest request, @Context HttpServletResponse response,@QueryParam("id") String id) {
User user = HrmUserVarify.getUser(request, response);
PersonTableParam build = PersonTableParam.builder().id(id).build();
return new ResponseResult<PersonTableParam, List<PersonTableVO>>(user).run(getOrgChartService(user) :: selectVirtualPerson,build);
}
@GET
@Path("/virtual-top")
@Produces(MediaType.APPLICATION_JSON)
public String selectVirtualTop(@Context HttpServletRequest request, @Context HttpServletResponse response) {
User user = HrmUserVarify.getUser(request, response);
return new ResponseResult<PersonTableParam, List<SelectVO>>(user).run(getOrgChartService(user) :: selectVirtualTop);
}
} }

Loading…
Cancel
Save