refactor: 작업자 관리 개선 - 계정 연동 기능으로 변경

작업 보고서 표시 여부 대신 계정 연동 기능으로 개선했습니다.

## 주요 변경사항

### 개념 변경
- **이전**: 작업 보고서 표시 여부 (show_in_work_reports)
- **이후**: 계정 생성/연동 기능

### 데이터베이스
- **마이그레이션**: 20260119095549_add_worker_display_fields.js
  - show_in_work_reports 컬럼 제거
  - employment_status만 유지 (employed/resigned)

- **workerModel**:
  - getAll, getById에서 users 테이블 JOIN하여 user_id 조회
  - create, update에서 show_in_work_reports 필드 제거

### 백엔드 API
- **workerController.js**:
  - createWorker: create_account 체크 시 자동으로 users 테이블에 계정 생성
    - username: hangulToRoman으로 한글 이름 변환
    - password: 초기 비밀번호 '1234' (bcrypt 해시)
    - role: User 역할 자동 할당
  - updateWorker:
    - create_account=true & 계정 없음 → 계정 생성
    - create_account=false & 계정 있음 → 계정 연동 해제 (users.worker_id=NULL)

### 프론트엔드
- **worker-management.html**:
  - "작업 보고서 표시" → "🔐 계정 생성/연동"으로 변경
  - 체크 시 로그인 계정 자동 생성 안내

- **worker-management.js**:
  - 카드 렌더링: user_id 존재 여부로 계정 연동 상태 표시 (🔐 아이콘)
  - saveWorker: create_account 필드 전송
  - show_in_work_reports 관련 로직 모두 제거

- **daily-work-report.js**:
  - 필터링 조건 단순화: 퇴사자만 제외 (employment_status≠resigned)
  - 계정 여부와 무관하게 모든 재직자 표시

## 사용 방법
1. 작업자 등록/수정 시 "계정 생성/연동" 체크
2. 자동으로 로그인 계정 생성 (초기 비밀번호: 1234)
3. 계정이 있는 작업자는 나의 대시보드, 연차/출퇴근 관리 가능

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-01-19 10:17:31 +09:00
parent 25cca1482e
commit bea62dfdee
6 changed files with 120 additions and 55 deletions

View File

@@ -20,15 +20,14 @@ const create = async (worker, callback) => {
salary = null,
annual_leave = null,
status = 'active',
show_in_work_reports = true,
employment_status = 'employed'
} = worker;
const [result] = await db.query(
`INSERT INTO workers
(worker_name, job_type, join_date, salary, annual_leave, status, show_in_work_reports, employment_status)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
[worker_name, job_type, formatDate(join_date), salary, annual_leave, status, show_in_work_reports, employment_status]
(worker_name, job_type, join_date, salary, annual_leave, status, employment_status)
VALUES (?, ?, ?, ?, ?, ?, ?)`,
[worker_name, job_type, formatDate(join_date), salary, annual_leave, status, employment_status]
);
callback(null, result.insertId);
@@ -44,10 +43,12 @@ const getAll = async (callback) => {
const db = await getDb();
const [rows] = await db.query(`
SELECT
*,
CASE WHEN status = 'active' THEN 1 ELSE 0 END AS is_active
FROM workers
ORDER BY worker_id DESC
w.*,
CASE WHEN w.status = 'active' THEN 1 ELSE 0 END AS is_active,
u.user_id
FROM workers w
LEFT JOIN users u ON w.worker_id = u.worker_id
ORDER BY w.worker_id DESC
`);
callback(null, rows);
} catch (err) {
@@ -61,10 +62,12 @@ const getById = async (worker_id, callback) => {
const db = await getDb();
const [rows] = await db.query(`
SELECT
*,
CASE WHEN status = 'active' THEN 1 ELSE 0 END AS is_active
FROM workers
WHERE worker_id = ?
w.*,
CASE WHEN w.status = 'active' THEN 1 ELSE 0 END AS is_active,
u.user_id
FROM workers w
LEFT JOIN users u ON w.worker_id = u.worker_id
WHERE w.worker_id = ?
`, [worker_id]);
callback(null, rows[0]);
} catch (err) {
@@ -84,7 +87,6 @@ const update = async (worker, callback) => {
join_date,
salary,
annual_leave,
show_in_work_reports,
employment_status
} = worker;
@@ -116,10 +118,6 @@ const update = async (worker, callback) => {
updates.push('annual_leave = ?');
values.push(annual_leave);
}
if (show_in_work_reports !== undefined) {
updates.push('show_in_work_reports = ?');
values.push(show_in_work_reports);
}
if (employment_status !== undefined) {
updates.push('employment_status = ?');
values.push(employment_status);