๐Ÿ“Œ ์กฐ์ง๋„ ํŠธ๋ฆฌ ๊ตฌ์กฐ ์กฐํšŒ ๊ธฐ๋Šฅ ๊ตฌํ˜„

๐Ÿ“ ๊ฐœ์š”

ํšŒ์‚ฌ ์กฐ์ง๋„๋ฅผ ํŠธ๋ฆฌ ํ˜•ํƒœ๋กœ ๊ตฌ์„ฑํ•˜์—ฌ UI์—์„œ ๊ณ„์ธต ๊ตฌ์กฐ๋ฅผ ์‹œ๊ฐ์ ์œผ๋กœ ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ–ˆ๋‹ค.

์žฌ๊ท€ ์ฟผ๋ฆฌ๋ฅผ ํ†ตํ•ด ์ „์ฒด ๋ถ€์„œ ๊ณ„์ธต์„ ์กฐํšŒํ•œ ๋’ค, Java์—์„œ ํŠธ๋ฆฌ ๊ตฌ์กฐ๋กœ ๊ฐ€๊ณตํ•˜์—ฌ ์‘๋‹ต ๋ฐ์ดํ„ฐ๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.


๐Ÿš€ ๊ตฌํ˜„ ๋‚ด์šฉ

1. ํŠธ๋ฆฌ ๊ตฌ์กฐ ์ƒ์„ฑ์„ ์œ„ํ•œ ๋ฐ์ดํ„ฐ ๋ชจ๋ธ ์„ค๊ณ„

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) { ... }
}

2. ์กฐ์ง๋„ ํŠธ๋ฆฌ ์กฐํšŒ API

@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)));
}

3. ์žฌ๊ท€ ์ฟผ๋ฆฌ๋ฅผ ํ†ตํ•œ ๋ถ€์„œ ๊ณ„์ธต ์กฐํšŒ