Commit 981daf63 by 赵剑炜

增加根据当前组织机构列表查询

parent 9ae62318
......@@ -2,6 +2,9 @@ package com.junmp.jyzb.api.bean.dto;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class OrgDto {
private Long orgId;
......@@ -13,5 +16,9 @@ public class OrgDto {
private String levelFlag;
private String dName;
private Boolean isLeaf;
private List<OrgDto> children = new ArrayList<>();
public void addChild(OrgDto child) {
children.add(child);
}
}
......@@ -48,6 +48,11 @@ public class PubOrgController {
public ApiRes<List<OrgDto>> getOrgList(@RequestBody QueryOrgReq req) {
return ApiRes.success(pubOrgService.getOrgList(req));
}
@PostMapping("/GetCurrentList")
@ApiOperation("根据当前组织机构列表查询")
public ApiRes<OrgDto> GetCurrentList(@RequestBody QueryOrgReq req) {
return ApiRes.success(pubOrgService.getOrgHierarchy(req));
}
@PostMapping("/ChangeOrgState")
@ApiOperation("改变组织机构状态信息")
public ApiRes<Boolean> changeOrgState(@RequestBody @Validated(ValidationApi.updateStatus.class) UpdateOrgReq req) {
......
......@@ -21,6 +21,8 @@ public interface PubOrgService extends IService<PubOrg> {
ResponseResult setOrgParentIds();
List<OrgDto> getOrgList(QueryOrgReq req);
OrgDto getOrgHierarchy(QueryOrgReq req);
List<OrgDto> getLowOrg(QueryOrgReq req);
Boolean ChangeState(UpdateOrgReq req);
......
......@@ -29,6 +29,7 @@ import com.junmp.jyzb.service.PubOrgService;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
@Service
......@@ -270,6 +271,83 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem
return nonexistentOrgs;
}
public OrgDto getOrgHierarchy(QueryOrgReq req) {
req.setDelFlag(1);
// req.setDelFlag(1);
LambdaQueryWrapper<PubOrg> wp = this.createWrapper(req);
LambdaQueryWrapper<PubOrg> one = this.createWrapper(req);
List<PubOrg> list = this.list(wp);
OrgDto orgSet=new OrgDto();
PubOrg OrgOne= this.getById(req.getOrgId());
BeanPlusUtil.copyProperties(OrgOne, orgSet);
// Convert PubOrg list to OrgDto list
List<OrgDto> orgs = new ArrayList<>();
list.forEach(p -> {
OrgDto org = new OrgDto();
BeanPlusUtil.copyProperties(p, org);
orgs.add(org);
});
return getMaximumParent(orgs,orgSet);
}
public OrgDto getMaximumParent(List<OrgDto> orgs, OrgDto org) {
OrgDto dept = null;
String parentId = org.getOrgParentId().toString();
if(parentId.equals("-1")){
dept = org;
}else {
List<OrgDto> parent = orgs.stream().filter(item -> item.getOrgId().toString().equals( parentId)).collect(Collectors.toList());
OrgDto maximumParent = getMaximumParent(orgs, parent.get(0));
dept = maximumParent;
parent.get(0).addChild(org);
List<OrgDto> siblings = orgs.stream()
.filter(item -> !item.getOrgId().equals(org.getOrgId()) &&
item.getOrgParentId().toString().equals(org.getOrgParentId().toString()))
.sorted((o1, o2) -> {
String orgCode1 = o1.getOrgCode();
String orgCode2 = o2.getOrgCode();
// Check if either orgCode contains letters
boolean hasLetter1 = orgCode1.matches(".*[a-zA-Z].*");
boolean hasLetter2 = orgCode2.matches(".*[a-zA-Z].*");
if (hasLetter1 && hasLetter2) {
return orgCode1.compareTo(orgCode2); // Alphabetical order
} else if (hasLetter1) {
return 1; // o2 with letters should come first
} else if (hasLetter2) {
return -1; // o1 with letters should come first
} else {
return orgCode1.compareTo(orgCode2); // Numeric order
}
})
.collect(Collectors.toList());
siblings.forEach(p->
{
parent.get(0).addChild(p);
});
}
return dept;
}
public List<OrgDto> getLowOrg(QueryOrgReq req){
if (ObjectUtil.isEmpty(req.getParentId())) {
req.setParentId(req.getOrgId());
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论