feat: 근태관리/직원관리 API 구현
- AttendanceController, AttendanceService 추가 - EmployeeController, EmployeeService 추가 - Attendance 모델 및 마이그레이션 추가 - TenantUserProfile에 employee_status 컬럼 추가 - DepartmentService 트리 조회 기능 개선 - Swagger 문서 추가 (AttendanceApi, EmployeeApi) - API 라우트 등록
This commit is contained in:
@@ -60,6 +60,50 @@ public function index(array $params)
|
||||
return $q->paginate($perPage, ['*'], 'page', $page);
|
||||
}
|
||||
|
||||
/** 부서 트리 조회 */
|
||||
public function tree(array $params = []): array
|
||||
{
|
||||
$p = $this->v($params, [
|
||||
'with_users' => 'nullable|in:0,1,true,false',
|
||||
]);
|
||||
if (isset($p['error'])) {
|
||||
return $p;
|
||||
}
|
||||
|
||||
$withUsers = filter_var($p['with_users'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
||||
|
||||
// 최상위 부서 조회 (parent_id가 null인 부서)
|
||||
$query = Department::query()
|
||||
->whereNull('parent_id')
|
||||
->orderBy('sort_order')
|
||||
->orderBy('name');
|
||||
|
||||
// 재귀적으로 자식 부서 로드
|
||||
$query->with(['children' => function ($q) use ($withUsers) {
|
||||
$q->orderBy('sort_order')->orderBy('name');
|
||||
$this->loadChildrenRecursive($q, $withUsers);
|
||||
}]);
|
||||
|
||||
if ($withUsers) {
|
||||
$query->with(['users:id,name,email']);
|
||||
}
|
||||
|
||||
return $query->get()->toArray();
|
||||
}
|
||||
|
||||
/** 재귀적으로 자식 부서 로드 */
|
||||
private function loadChildrenRecursive($query, bool $withUsers): void
|
||||
{
|
||||
$query->with(['children' => function ($q) use ($withUsers) {
|
||||
$q->orderBy('sort_order')->orderBy('name');
|
||||
$this->loadChildrenRecursive($q, $withUsers);
|
||||
}]);
|
||||
|
||||
if ($withUsers) {
|
||||
$query->with(['users:id,name,email']);
|
||||
}
|
||||
}
|
||||
|
||||
/** 생성 */
|
||||
public function store(array $params)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user