ํ์ฌ ์กฐ์ง๋๋ฅผ ํธ๋ฆฌ ํํ๋ก ๊ตฌ์ฑํ์ฌ UI์์ ๊ณ์ธต ๊ตฌ์กฐ๋ฅผ ์๊ฐ์ ์ผ๋ก ํํํ ์ ์๋๋ก ๊ธฐ๋ฅ์ ๊ตฌํํ๋ค.
์ฌ๊ท ์ฟผ๋ฆฌ๋ฅผ ํตํด ์ ์ฒด ๋ถ์ ๊ณ์ธต์ ์กฐํํ ๋ค, Java์์ ํธ๋ฆฌ ๊ตฌ์กฐ๋ก ๊ฐ๊ณตํ์ฌ ์๋ต ๋ฐ์ดํฐ๋ก ๋ฐํํ๋ค.
children
ํ๋ ์ถ๊ฐbuildTree()
๋ฉ์๋๋ฅผ ํตํด ์ ๋ ฌ๋ ๋ฆฌ์คํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ณ์ธต ํธ๋ฆฌ ๊ตฌ์กฐ ์์ฑpublic class OrgGroup implements Comparable<OrgGroup> {
String code;
String parentCode;
String name;
String companyCode;
String groupType; // ํ์ฌ/๋ถ์ ๊ตฌ๋ถ
String relationCode;
Long relationDepth;
int sortOrder;
List<OrgGroup> children;
public void appendChild(OrgGroup child) { ... }
public static List<OrgGroup> buildTree(List<OrgGroup> groups) { ... }
public int compareTo(OrgGroup other) { ... }
}
buildTree()
๋ก ํธ๋ฆฌ ํํ๋ก ๊ตฌ์ฑํ์ฌ ๋ฐํ@GetMapping("organizations/tree/{company_code}")
public ResponseEntity<?> getOrganizationTree(@PathVariable String company_code) {
List<OrgGroup> result = new ArrayList<>();
List<OrgGroup> companies = baseMapper.getCompanies(company_code);
for (OrgGroup company : companies) {
if (!company_code.equals(company.getCode())) {
result.add(company);
}
result.addAll(baseMapper.getDepartmentsByCompany(company.getCode(), null));
}
return ResponseEntity.ok().body(TreeResponse.success(OrgGroup.buildTree(result)));
}
WITH RECURSIVE
๋ฅผ ์ฌ์ฉํ์ฌ ํน์ ํ์ฌ๋ฅผ ๊ธฐ์ค์ผ๋ก ํ์ ๋ถ์๋ฅผ ์ฌ๊ท์ ์ผ๋ก ์กฐํ