feat: 페이지 구조 재구성 및 사이드바 네비게이션 구현
- 페이지 폴더 재구성: safety/, attendance/ 폴더 신규 생성 - work/ → safety/: 이슈 신고, 출입 신청 관련 페이지 이동 - common/ → attendance/: 근태/휴가 관련 페이지 이동 - admin/ 정리: safety-* 파일들을 safety/로 이동 - 사이드바 네비게이션 메뉴 구현 - 카테고리별 메뉴: 작업관리, 안전관리, 근태관리, 시스템관리 - 접기/펼치기 기능 및 상태 저장 - 관리자 전용 메뉴 자동 표시/숨김 - 날씨 API 연동 (기상청 단기예보) - TBM 및 navbar에 현재 날씨 표시 - weatherService.js 추가 - 안전 체크리스트 확장 - 기본/날씨별/작업별 체크 유형 추가 - checklist-manage.html 페이지 추가 - 이슈 신고 시스템 구현 - workIssueController, workIssueModel, workIssueRoutes 추가 - DB 마이그레이션 파일 추가 (실행 대기) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,266 @@
|
||||
/**
|
||||
* 마이그레이션: 작업 중 문제 신고 시스템
|
||||
* - 신고 카테고리 테이블 (부적합/안전)
|
||||
* - 사전 정의 신고 항목 테이블
|
||||
* - 문제 신고 메인 테이블
|
||||
* - 상태 변경 이력 테이블
|
||||
*/
|
||||
|
||||
exports.up = async function(knex) {
|
||||
// 1. 신고 카테고리 테이블 생성
|
||||
await knex.schema.createTable('issue_report_categories', function(table) {
|
||||
table.increments('category_id').primary().comment('카테고리 ID');
|
||||
table.enum('category_type', ['nonconformity', 'safety']).notNullable().comment('카테고리 유형 (부적합/안전)');
|
||||
table.string('category_name', 100).notNullable().comment('카테고리명');
|
||||
table.text('description').nullable().comment('카테고리 설명');
|
||||
table.integer('display_order').defaultTo(0).comment('표시 순서');
|
||||
table.boolean('is_active').defaultTo(true).comment('활성 여부');
|
||||
table.timestamp('created_at').defaultTo(knex.fn.now());
|
||||
|
||||
table.index('category_type', 'idx_irc_category_type');
|
||||
table.index('is_active', 'idx_irc_is_active');
|
||||
});
|
||||
|
||||
// 카테고리 초기 데이터 삽입
|
||||
await knex('issue_report_categories').insert([
|
||||
// 부적합 사항
|
||||
{ category_type: 'nonconformity', category_name: '자재누락', display_order: 1, is_active: true },
|
||||
{ category_type: 'nonconformity', category_name: '설계미스', display_order: 2, is_active: true },
|
||||
{ category_type: 'nonconformity', category_name: '입고불량', display_order: 3, is_active: true },
|
||||
{ category_type: 'nonconformity', category_name: '검사미스', display_order: 4, is_active: true },
|
||||
{ category_type: 'nonconformity', category_name: '기타 부적합', display_order: 99, is_active: true },
|
||||
// 안전 관련
|
||||
{ category_type: 'safety', category_name: '보호구 미착용', display_order: 1, is_active: true },
|
||||
{ category_type: 'safety', category_name: '위험구역 출입', display_order: 2, is_active: true },
|
||||
{ category_type: 'safety', category_name: '안전시설 파손', display_order: 3, is_active: true },
|
||||
{ category_type: 'safety', category_name: '안전수칙 위반', display_order: 4, is_active: true },
|
||||
{ category_type: 'safety', category_name: '기타 안전', display_order: 99, is_active: true }
|
||||
]);
|
||||
|
||||
// 2. 사전 정의 신고 항목 테이블 생성
|
||||
await knex.schema.createTable('issue_report_items', function(table) {
|
||||
table.increments('item_id').primary().comment('항목 ID');
|
||||
table.integer('category_id').unsigned().notNullable().comment('소속 카테고리 ID');
|
||||
table.string('item_name', 200).notNullable().comment('신고 항목명');
|
||||
table.text('description').nullable().comment('항목 설명');
|
||||
table.enum('severity', ['low', 'medium', 'high', 'critical']).defaultTo('medium').comment('심각도');
|
||||
table.integer('display_order').defaultTo(0).comment('표시 순서');
|
||||
table.boolean('is_active').defaultTo(true).comment('활성 여부');
|
||||
table.timestamp('created_at').defaultTo(knex.fn.now());
|
||||
|
||||
table.foreign('category_id')
|
||||
.references('category_id')
|
||||
.inTable('issue_report_categories')
|
||||
.onDelete('CASCADE')
|
||||
.onUpdate('CASCADE');
|
||||
|
||||
table.index('category_id', 'idx_iri_category_id');
|
||||
table.index('is_active', 'idx_iri_is_active');
|
||||
});
|
||||
|
||||
// 사전 정의 항목 초기 데이터 삽입
|
||||
await knex('issue_report_items').insert([
|
||||
// 자재누락 (category_id: 1)
|
||||
{ category_id: 1, item_name: '배관 자재 미입고', severity: 'high', display_order: 1 },
|
||||
{ category_id: 1, item_name: '피팅류 부족', severity: 'medium', display_order: 2 },
|
||||
{ category_id: 1, item_name: '밸브류 미입고', severity: 'high', display_order: 3 },
|
||||
{ category_id: 1, item_name: '가스켓/볼트류 부족', severity: 'low', display_order: 4 },
|
||||
{ category_id: 1, item_name: '서포트 자재 부족', severity: 'medium', display_order: 5 },
|
||||
|
||||
// 설계미스 (category_id: 2)
|
||||
{ category_id: 2, item_name: '도면 치수 오류', severity: 'high', display_order: 1 },
|
||||
{ category_id: 2, item_name: '스펙 불일치', severity: 'high', display_order: 2 },
|
||||
{ category_id: 2, item_name: '누락된 상세도', severity: 'medium', display_order: 3 },
|
||||
{ category_id: 2, item_name: '간섭 발생', severity: 'critical', display_order: 4 },
|
||||
|
||||
// 입고불량 (category_id: 3)
|
||||
{ category_id: 3, item_name: '외관 불량', severity: 'medium', display_order: 1 },
|
||||
{ category_id: 3, item_name: '치수 불량', severity: 'high', display_order: 2 },
|
||||
{ category_id: 3, item_name: '수량 부족', severity: 'medium', display_order: 3 },
|
||||
{ category_id: 3, item_name: '재질 불일치', severity: 'critical', display_order: 4 },
|
||||
|
||||
// 검사미스 (category_id: 4)
|
||||
{ category_id: 4, item_name: '치수 검사 누락', severity: 'high', display_order: 1 },
|
||||
{ category_id: 4, item_name: '외관 검사 누락', severity: 'medium', display_order: 2 },
|
||||
{ category_id: 4, item_name: '용접 검사 누락', severity: 'critical', display_order: 3 },
|
||||
{ category_id: 4, item_name: '도장 검사 누락', severity: 'medium', display_order: 4 },
|
||||
|
||||
// 보호구 미착용 (category_id: 6)
|
||||
{ category_id: 6, item_name: '안전모 미착용', severity: 'high', display_order: 1 },
|
||||
{ category_id: 6, item_name: '안전화 미착용', severity: 'high', display_order: 2 },
|
||||
{ category_id: 6, item_name: '보안경 미착용', severity: 'medium', display_order: 3 },
|
||||
{ category_id: 6, item_name: '안전대 미착용', severity: 'critical', display_order: 4 },
|
||||
{ category_id: 6, item_name: '귀마개 미착용', severity: 'low', display_order: 5 },
|
||||
{ category_id: 6, item_name: '안전장갑 미착용', severity: 'medium', display_order: 6 },
|
||||
|
||||
// 위험구역 출입 (category_id: 7)
|
||||
{ category_id: 7, item_name: '통제구역 무단 출입', severity: 'critical', display_order: 1 },
|
||||
{ category_id: 7, item_name: '고소 작업 구역 무단 출입', severity: 'critical', display_order: 2 },
|
||||
{ category_id: 7, item_name: '밀폐공간 무단 진입', severity: 'critical', display_order: 3 },
|
||||
{ category_id: 7, item_name: '장비 가동 구역 무단 접근', severity: 'high', display_order: 4 },
|
||||
|
||||
// 안전시설 파손 (category_id: 8)
|
||||
{ category_id: 8, item_name: '안전난간 파손', severity: 'high', display_order: 1 },
|
||||
{ category_id: 8, item_name: '경고 표지판 훼손', severity: 'medium', display_order: 2 },
|
||||
{ category_id: 8, item_name: '안전망 파손', severity: 'high', display_order: 3 },
|
||||
{ category_id: 8, item_name: '비상조명 고장', severity: 'medium', display_order: 4 },
|
||||
{ category_id: 8, item_name: '소화설비 파손', severity: 'critical', display_order: 5 },
|
||||
|
||||
// 안전수칙 위반 (category_id: 9)
|
||||
{ category_id: 9, item_name: '지정 통로 미사용', severity: 'medium', display_order: 1 },
|
||||
{ category_id: 9, item_name: '고소 작업 안전 미준수', severity: 'critical', display_order: 2 },
|
||||
{ category_id: 9, item_name: '화기 작업 절차 미준수', severity: 'critical', display_order: 3 },
|
||||
{ category_id: 9, item_name: '정리정돈 미흡', severity: 'low', display_order: 4 },
|
||||
{ category_id: 9, item_name: '장비 조작 절차 미준수', severity: 'high', display_order: 5 }
|
||||
]);
|
||||
|
||||
// 3. 문제 신고 메인 테이블 생성
|
||||
await knex.schema.createTable('work_issue_reports', function(table) {
|
||||
table.increments('report_id').primary().comment('신고 ID');
|
||||
|
||||
// 신고자 정보
|
||||
table.integer('reporter_id').notNullable().comment('신고자 user_id');
|
||||
table.datetime('report_date').defaultTo(knex.fn.now()).comment('신고 일시');
|
||||
|
||||
// 위치 정보
|
||||
table.integer('factory_category_id').unsigned().nullable().comment('공장 카테고리 ID (지도 외 위치 시 null)');
|
||||
table.integer('workplace_id').unsigned().nullable().comment('작업장 ID (지도 외 위치 시 null)');
|
||||
table.string('custom_location', 200).nullable().comment('기타 위치 (지도 외 선택 시)');
|
||||
|
||||
// 작업 연결 정보 (선택적)
|
||||
table.integer('tbm_session_id').unsigned().nullable().comment('연결된 TBM 세션');
|
||||
table.integer('visit_request_id').unsigned().nullable().comment('연결된 출입 신청');
|
||||
|
||||
// 신고 내용
|
||||
table.integer('issue_category_id').unsigned().notNullable().comment('신고 카테고리 ID');
|
||||
table.integer('issue_item_id').unsigned().nullable().comment('사전 정의 신고 항목 ID');
|
||||
table.text('additional_description').nullable().comment('추가 설명');
|
||||
|
||||
// 사진 (최대 5장)
|
||||
table.string('photo_path1', 255).nullable().comment('사진 1');
|
||||
table.string('photo_path2', 255).nullable().comment('사진 2');
|
||||
table.string('photo_path3', 255).nullable().comment('사진 3');
|
||||
table.string('photo_path4', 255).nullable().comment('사진 4');
|
||||
table.string('photo_path5', 255).nullable().comment('사진 5');
|
||||
|
||||
// 상태 관리
|
||||
table.enum('status', ['reported', 'received', 'in_progress', 'completed', 'closed'])
|
||||
.defaultTo('reported')
|
||||
.comment('상태: 신고→접수→처리중→완료→종료');
|
||||
|
||||
// 담당자 배정
|
||||
table.string('assigned_department', 100).nullable().comment('담당 부서');
|
||||
table.integer('assigned_user_id').nullable().comment('담당자 user_id');
|
||||
table.datetime('assigned_at').nullable().comment('배정 일시');
|
||||
table.integer('assigned_by').nullable().comment('배정자 user_id');
|
||||
|
||||
// 처리 정보
|
||||
table.text('resolution_notes').nullable().comment('처리 내용');
|
||||
table.string('resolution_photo_path1', 255).nullable().comment('처리 완료 사진 1');
|
||||
table.string('resolution_photo_path2', 255).nullable().comment('처리 완료 사진 2');
|
||||
table.datetime('resolved_at').nullable().comment('처리 완료 일시');
|
||||
table.integer('resolved_by').nullable().comment('처리 완료자 user_id');
|
||||
|
||||
// 수정 이력 (JSON)
|
||||
table.json('modification_history').nullable().comment('수정 이력 추적');
|
||||
|
||||
// 타임스탬프
|
||||
table.timestamp('created_at').defaultTo(knex.fn.now());
|
||||
table.timestamp('updated_at').defaultTo(knex.fn.now());
|
||||
|
||||
// 외래키
|
||||
table.foreign('reporter_id')
|
||||
.references('user_id')
|
||||
.inTable('users')
|
||||
.onDelete('RESTRICT')
|
||||
.onUpdate('CASCADE');
|
||||
|
||||
table.foreign('factory_category_id')
|
||||
.references('category_id')
|
||||
.inTable('workplace_categories')
|
||||
.onDelete('SET NULL')
|
||||
.onUpdate('CASCADE');
|
||||
|
||||
table.foreign('workplace_id')
|
||||
.references('workplace_id')
|
||||
.inTable('workplaces')
|
||||
.onDelete('SET NULL')
|
||||
.onUpdate('CASCADE');
|
||||
|
||||
table.foreign('issue_category_id')
|
||||
.references('category_id')
|
||||
.inTable('issue_report_categories')
|
||||
.onDelete('RESTRICT')
|
||||
.onUpdate('CASCADE');
|
||||
|
||||
table.foreign('issue_item_id')
|
||||
.references('item_id')
|
||||
.inTable('issue_report_items')
|
||||
.onDelete('SET NULL')
|
||||
.onUpdate('CASCADE');
|
||||
|
||||
table.foreign('assigned_user_id')
|
||||
.references('user_id')
|
||||
.inTable('users')
|
||||
.onDelete('SET NULL')
|
||||
.onUpdate('CASCADE');
|
||||
|
||||
table.foreign('assigned_by')
|
||||
.references('user_id')
|
||||
.inTable('users')
|
||||
.onDelete('SET NULL')
|
||||
.onUpdate('CASCADE');
|
||||
|
||||
table.foreign('resolved_by')
|
||||
.references('user_id')
|
||||
.inTable('users')
|
||||
.onDelete('SET NULL')
|
||||
.onUpdate('CASCADE');
|
||||
|
||||
// 인덱스
|
||||
table.index('reporter_id', 'idx_wir_reporter_id');
|
||||
table.index('status', 'idx_wir_status');
|
||||
table.index('report_date', 'idx_wir_report_date');
|
||||
table.index(['factory_category_id', 'workplace_id'], 'idx_wir_workplace');
|
||||
table.index('issue_category_id', 'idx_wir_issue_category');
|
||||
table.index('assigned_user_id', 'idx_wir_assigned_user');
|
||||
});
|
||||
|
||||
// 4. 상태 변경 이력 테이블 생성
|
||||
await knex.schema.createTable('work_issue_status_logs', function(table) {
|
||||
table.increments('log_id').primary().comment('로그 ID');
|
||||
table.integer('report_id').unsigned().notNullable().comment('신고 ID');
|
||||
table.string('previous_status', 50).nullable().comment('이전 상태');
|
||||
table.string('new_status', 50).notNullable().comment('새 상태');
|
||||
table.integer('changed_by').notNullable().comment('변경자 user_id');
|
||||
table.text('change_reason').nullable().comment('변경 사유');
|
||||
table.timestamp('changed_at').defaultTo(knex.fn.now());
|
||||
|
||||
table.foreign('report_id')
|
||||
.references('report_id')
|
||||
.inTable('work_issue_reports')
|
||||
.onDelete('CASCADE')
|
||||
.onUpdate('CASCADE');
|
||||
|
||||
table.foreign('changed_by')
|
||||
.references('user_id')
|
||||
.inTable('users')
|
||||
.onDelete('RESTRICT')
|
||||
.onUpdate('CASCADE');
|
||||
|
||||
table.index('report_id', 'idx_wisl_report_id');
|
||||
table.index('changed_at', 'idx_wisl_changed_at');
|
||||
});
|
||||
|
||||
console.log('작업 중 문제 신고 시스템 테이블 생성 완료');
|
||||
};
|
||||
|
||||
exports.down = async function(knex) {
|
||||
// 역순으로 테이블 삭제
|
||||
await knex.schema.dropTableIfExists('work_issue_status_logs');
|
||||
await knex.schema.dropTableIfExists('work_issue_reports');
|
||||
await knex.schema.dropTableIfExists('issue_report_items');
|
||||
await knex.schema.dropTableIfExists('issue_report_categories');
|
||||
|
||||
console.log('작업 중 문제 신고 시스템 테이블 삭제 완료');
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* 마이그레이션: 문제 신고 관련 페이지 등록
|
||||
*/
|
||||
|
||||
exports.up = async function(knex) {
|
||||
// 문제 신고 등록 페이지
|
||||
await knex('pages').insert({
|
||||
page_key: 'issue-report',
|
||||
page_name: '문제 신고',
|
||||
page_path: '/pages/work/issue-report.html',
|
||||
category: 'work',
|
||||
description: '작업 중 문제(부적합/안전) 신고 등록',
|
||||
is_admin_only: 0,
|
||||
display_order: 16
|
||||
});
|
||||
|
||||
// 신고 목록 페이지
|
||||
await knex('pages').insert({
|
||||
page_key: 'issue-list',
|
||||
page_name: '신고 목록',
|
||||
page_path: '/pages/work/issue-list.html',
|
||||
category: 'work',
|
||||
description: '문제 신고 목록 조회 및 관리',
|
||||
is_admin_only: 0,
|
||||
display_order: 17
|
||||
});
|
||||
|
||||
// 신고 상세 페이지
|
||||
await knex('pages').insert({
|
||||
page_key: 'issue-detail',
|
||||
page_name: '신고 상세',
|
||||
page_path: '/pages/work/issue-detail.html',
|
||||
category: 'work',
|
||||
description: '문제 신고 상세 조회',
|
||||
is_admin_only: 0,
|
||||
display_order: 18
|
||||
});
|
||||
|
||||
console.log('✅ 문제 신고 페이지 등록 완료');
|
||||
};
|
||||
|
||||
exports.down = async function(knex) {
|
||||
await knex('pages').whereIn('page_key', [
|
||||
'issue-report',
|
||||
'issue-list',
|
||||
'issue-detail'
|
||||
]).delete();
|
||||
|
||||
console.log('✅ 문제 신고 페이지 삭제 완료');
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 작업보고서 부적합 상세 테이블 마이그레이션
|
||||
*
|
||||
* 기존: error_hours, error_type_id (단일 값)
|
||||
* 변경: 여러 부적합 원인 + 각 원인별 시간 저장 가능
|
||||
*/
|
||||
|
||||
exports.up = function(knex) {
|
||||
return knex.schema
|
||||
// 1. work_report_defects 테이블 생성
|
||||
.createTable('work_report_defects', function(table) {
|
||||
table.increments('defect_id').primary();
|
||||
table.integer('report_id').notNullable()
|
||||
.comment('daily_work_reports의 id');
|
||||
table.integer('error_type_id').notNullable()
|
||||
.comment('error_types의 id (부적합 원인)');
|
||||
table.decimal('defect_hours', 4, 1).notNullable().defaultTo(0)
|
||||
.comment('해당 원인의 부적합 시간');
|
||||
table.text('note').nullable()
|
||||
.comment('추가 메모');
|
||||
table.timestamp('created_at').defaultTo(knex.fn.now());
|
||||
|
||||
// 외래키
|
||||
table.foreign('report_id').references('id').inTable('daily_work_reports').onDelete('CASCADE');
|
||||
table.foreign('error_type_id').references('id').inTable('error_types');
|
||||
|
||||
// 인덱스
|
||||
table.index('report_id');
|
||||
table.index('error_type_id');
|
||||
|
||||
// 같은 보고서에 같은 원인이 중복되지 않도록
|
||||
table.unique(['report_id', 'error_type_id']);
|
||||
})
|
||||
// 2. 기존 데이터 마이그레이션 (error_hours > 0인 경우)
|
||||
.then(function() {
|
||||
return knex.raw(`
|
||||
INSERT INTO work_report_defects (report_id, error_type_id, defect_hours, created_at)
|
||||
SELECT id, error_type_id, error_hours, created_at
|
||||
FROM daily_work_reports
|
||||
WHERE error_hours > 0 AND error_type_id IS NOT NULL
|
||||
`);
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function(knex) {
|
||||
return knex.schema.dropTableIfExists('work_report_defects');
|
||||
};
|
||||
@@ -0,0 +1,141 @@
|
||||
/**
|
||||
* 안전 체크리스트 확장 마이그레이션
|
||||
*
|
||||
* 1. tbm_safety_checks 테이블 확장 (check_type, weather_condition, task_id)
|
||||
* 2. weather_conditions 테이블 생성 (날씨 조건 코드)
|
||||
* 3. tbm_weather_records 테이블 생성 (세션별 날씨 기록)
|
||||
* 4. 초기 날씨별 체크항목 데이터
|
||||
*
|
||||
* @since 2026-02-02
|
||||
*/
|
||||
|
||||
exports.up = function(knex) {
|
||||
return knex.schema
|
||||
// 1. tbm_safety_checks 테이블 확장
|
||||
.alterTable('tbm_safety_checks', function(table) {
|
||||
table.enum('check_type', ['basic', 'weather', 'task']).defaultTo('basic').after('check_category');
|
||||
table.string('weather_condition', 50).nullable().after('check_type');
|
||||
table.integer('task_id').unsigned().nullable().after('weather_condition');
|
||||
|
||||
// 인덱스 추가
|
||||
table.index('check_type');
|
||||
table.index('weather_condition');
|
||||
table.index('task_id');
|
||||
})
|
||||
|
||||
// 2. weather_conditions 테이블 생성
|
||||
.createTable('weather_conditions', function(table) {
|
||||
table.string('condition_code', 50).primary();
|
||||
table.string('condition_name', 100).notNullable();
|
||||
table.text('description').nullable();
|
||||
table.string('icon', 50).nullable();
|
||||
table.decimal('temp_threshold_min', 4, 1).nullable(); // 최소 기온 기준
|
||||
table.decimal('temp_threshold_max', 4, 1).nullable(); // 최대 기온 기준
|
||||
table.decimal('wind_threshold', 4, 1).nullable(); // 풍속 기준 (m/s)
|
||||
table.decimal('precip_threshold', 5, 1).nullable(); // 강수량 기준 (mm)
|
||||
table.boolean('is_active').defaultTo(true);
|
||||
table.integer('display_order').defaultTo(0);
|
||||
table.timestamp('created_at').defaultTo(knex.fn.now());
|
||||
})
|
||||
|
||||
// 3. tbm_weather_records 테이블 생성
|
||||
.createTable('tbm_weather_records', function(table) {
|
||||
table.increments('record_id').primary();
|
||||
table.integer('session_id').unsigned().notNullable();
|
||||
table.date('weather_date').notNullable();
|
||||
table.decimal('temperature', 4, 1).nullable(); // 기온 (섭씨)
|
||||
table.integer('humidity').nullable(); // 습도 (%)
|
||||
table.decimal('wind_speed', 4, 1).nullable(); // 풍속 (m/s)
|
||||
table.decimal('precipitation', 5, 1).nullable(); // 강수량 (mm)
|
||||
table.string('sky_condition', 50).nullable(); // 하늘 상태
|
||||
table.string('weather_condition', 50).nullable(); // 주요 날씨 상태
|
||||
table.json('weather_conditions').nullable(); // 복수 조건 ['rain', 'wind']
|
||||
table.string('data_source', 50).defaultTo('api'); // 데이터 출처
|
||||
table.timestamp('fetched_at').nullable();
|
||||
table.timestamp('created_at').defaultTo(knex.fn.now());
|
||||
|
||||
// 외래키
|
||||
table.foreign('session_id').references('session_id').inTable('tbm_sessions').onDelete('CASCADE');
|
||||
|
||||
// 인덱스
|
||||
table.index('weather_date');
|
||||
table.unique(['session_id']);
|
||||
})
|
||||
|
||||
// 4. 초기 데이터 삽입
|
||||
.then(function() {
|
||||
// 기존 체크항목을 'basic' 유형으로 업데이트
|
||||
return knex('tbm_safety_checks').update({ check_type: 'basic' });
|
||||
})
|
||||
.then(function() {
|
||||
// 날씨 조건 코드 삽입
|
||||
return knex('weather_conditions').insert([
|
||||
{ condition_code: 'clear', condition_name: '맑음', description: '맑은 날씨', icon: 'sunny', display_order: 1 },
|
||||
{ condition_code: 'rain', condition_name: '비', description: '비 오는 날씨', icon: 'rainy', precip_threshold: 0.1, display_order: 2 },
|
||||
{ condition_code: 'snow', condition_name: '눈', description: '눈 오는 날씨', icon: 'snowy', display_order: 3 },
|
||||
{ condition_code: 'heat', condition_name: '폭염', description: '기온 35도 이상', icon: 'hot', temp_threshold_min: 35, display_order: 4 },
|
||||
{ condition_code: 'cold', condition_name: '한파', description: '기온 영하 10도 이하', icon: 'cold', temp_threshold_max: -10, display_order: 5 },
|
||||
{ condition_code: 'wind', condition_name: '강풍', description: '풍속 10m/s 이상', icon: 'windy', wind_threshold: 10, display_order: 6 },
|
||||
{ condition_code: 'fog', condition_name: '안개', description: '시정 1km 미만', icon: 'foggy', display_order: 7 },
|
||||
{ condition_code: 'dust', condition_name: '미세먼지', description: '미세먼지 나쁨 이상', icon: 'dusty', display_order: 8 }
|
||||
]);
|
||||
})
|
||||
.then(function() {
|
||||
// 날씨별 안전 체크항목 삽입
|
||||
return knex('tbm_safety_checks').insert([
|
||||
// 비 (rain)
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'rain', check_item: '우의/우산 준비 확인', description: '비 오는 날 우의 또는 우산 준비 여부', is_required: true, display_order: 1 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'rain', check_item: '미끄럼 방지 조치 확인', description: '빗물로 인한 미끄러움 방지 조치', is_required: true, display_order: 2 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'rain', check_item: '전기 작업 중단 여부 확인', description: '우천 시 전기 작업 중단 필요성 확인', is_required: true, display_order: 3 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'rain', check_item: '배수 상태 확인', description: '작업장 배수 상태 점검', is_required: false, display_order: 4 },
|
||||
|
||||
// 눈 (snow)
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'snow', check_item: '제설 작업 완료 확인', description: '작업장 주변 제설 작업 완료 여부', is_required: true, display_order: 1 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'snow', check_item: '동파 방지 조치 확인', description: '배관 및 설비 동파 방지 조치', is_required: true, display_order: 2 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'snow', check_item: '미끄럼 방지 모래/염화칼슘 비치', description: '미끄럼 방지를 위한 모래 또는 염화칼슘 비치', is_required: true, display_order: 3 },
|
||||
|
||||
// 폭염 (heat)
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'heat', check_item: '그늘막/휴게소 확보', description: '무더위 휴식을 위한 그늘막 또는 휴게소 확보', is_required: true, display_order: 1 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'heat', check_item: '음료수/식염 포도당 비치', description: '열사병 예방을 위한 음료수 및 염분 보충제 비치', is_required: true, display_order: 2 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'heat', check_item: '무더위 휴식 시간 확보', description: '10~15시 사이 충분한 휴식 시간 확보', is_required: true, display_order: 3 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'heat', check_item: '작업자 건강 상태 확인', description: '열사병 증상 체크 및 건강 상태 확인', is_required: true, display_order: 4 },
|
||||
|
||||
// 한파 (cold)
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'cold', check_item: '방한복/방한장갑 착용 확인', description: '동상 방지를 위한 방한복 및 방한장갑 착용', is_required: true, display_order: 1 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'cold', check_item: '난방시설 가동 확인', description: '휴게 공간 난방시설 가동 상태 확인', is_required: true, display_order: 2 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'cold', check_item: '온열 음료 비치', description: '체온 유지를 위한 따뜻한 음료 비치', is_required: false, display_order: 3 },
|
||||
|
||||
// 강풍 (wind)
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'wind', check_item: '고소 작업 중단 여부 확인', description: '강풍 시 고소 작업 중단 필요성 확인', is_required: true, display_order: 1 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'wind', check_item: '자재/장비 결박 확인', description: '바람에 날릴 수 있는 자재 및 장비 고정', is_required: true, display_order: 2 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'wind', check_item: '가설물 안전 점검', description: '가설 구조물 및 비계 안전 상태 점검', is_required: true, display_order: 3 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'wind', check_item: '크레인 작업 중단 여부 확인', description: '강풍 시 크레인 작업 중단 필요성 확인', is_required: true, display_order: 4 },
|
||||
|
||||
// 안개 (fog)
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'fog', check_item: '경광등/조명 확보', description: '시정 확보를 위한 경광등 및 조명 설치', is_required: true, display_order: 1 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'fog', check_item: '차량 운행 주의 안내', description: '안개로 인한 차량 운행 주의 안내', is_required: true, display_order: 2 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'fog', check_item: '작업 구역 표시 강화', description: '시인성 확보를 위한 작업 구역 표시 강화', is_required: false, display_order: 3 },
|
||||
|
||||
// 미세먼지 (dust)
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'dust', check_item: '보호 마스크 착용 확인', description: 'KF94 이상 마스크 착용 여부 확인', is_required: true, display_order: 1 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'dust', check_item: '실외 작업 시간 조정', description: '미세먼지 농도에 따른 실외 작업 시간 조정', is_required: true, display_order: 2 },
|
||||
{ check_category: 'WEATHER', check_type: 'weather', weather_condition: 'dust', check_item: '호흡기 질환자 실내 배치', description: '호흡기 질환 작업자 실내 작업 배치', is_required: false, display_order: 3 }
|
||||
]);
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function(knex) {
|
||||
return knex.schema
|
||||
.dropTableIfExists('tbm_weather_records')
|
||||
.dropTableIfExists('weather_conditions')
|
||||
.then(function() {
|
||||
return knex.schema.alterTable('tbm_safety_checks', function(table) {
|
||||
table.dropIndex('check_type');
|
||||
table.dropIndex('weather_condition');
|
||||
table.dropIndex('task_id');
|
||||
table.dropColumn('check_type');
|
||||
table.dropColumn('weather_condition');
|
||||
table.dropColumn('task_id');
|
||||
});
|
||||
});
|
||||
};
|
||||
319
api.hyungi.net/db/migrations/20260202200000_reorganize_pages.js
Normal file
319
api.hyungi.net/db/migrations/20260202200000_reorganize_pages.js
Normal file
@@ -0,0 +1,319 @@
|
||||
/**
|
||||
* 페이지 구조 재구성 마이그레이션
|
||||
* - 페이지 경로 업데이트 (safety/, attendance/ 폴더로 이동)
|
||||
* - 카테고리 재분류
|
||||
* - 역할별 기본 페이지 권한 테이블 생성
|
||||
*/
|
||||
|
||||
exports.up = async function(knex) {
|
||||
// 1. 페이지 경로 업데이트 - safety 폴더로 이동된 페이지들
|
||||
const safetyPageUpdates = [
|
||||
{
|
||||
old_key: 'issue-report',
|
||||
new_key: 'safety.issue_report',
|
||||
new_path: '/pages/safety/issue-report.html',
|
||||
new_category: 'safety',
|
||||
new_name: '이슈 신고'
|
||||
},
|
||||
{
|
||||
old_key: 'issue-list',
|
||||
new_key: 'safety.issue_list',
|
||||
new_path: '/pages/safety/issue-list.html',
|
||||
new_category: 'safety',
|
||||
new_name: '이슈 목록'
|
||||
},
|
||||
{
|
||||
old_key: 'issue-detail',
|
||||
new_key: 'safety.issue_detail',
|
||||
new_path: '/pages/safety/issue-detail.html',
|
||||
new_category: 'safety',
|
||||
new_name: '이슈 상세'
|
||||
},
|
||||
{
|
||||
old_key: 'visit-request',
|
||||
new_key: 'safety.visit_request',
|
||||
new_path: '/pages/safety/visit-request.html',
|
||||
new_category: 'safety',
|
||||
new_name: '방문 요청'
|
||||
},
|
||||
{
|
||||
old_key: 'safety-management',
|
||||
new_key: 'safety.management',
|
||||
new_path: '/pages/safety/management.html',
|
||||
new_category: 'safety',
|
||||
new_name: '안전 관리'
|
||||
},
|
||||
{
|
||||
old_key: 'safety-training-conduct',
|
||||
new_key: 'safety.training_conduct',
|
||||
new_path: '/pages/safety/training-conduct.html',
|
||||
new_category: 'safety',
|
||||
new_name: '안전교육 진행'
|
||||
}
|
||||
];
|
||||
|
||||
// 2. 페이지 경로 업데이트 - attendance 폴더로 이동된 페이지들
|
||||
const attendancePageUpdates = [
|
||||
{
|
||||
old_key: 'daily-attendance',
|
||||
new_key: 'attendance.daily',
|
||||
new_path: '/pages/attendance/daily.html',
|
||||
new_category: 'attendance',
|
||||
new_name: '일일 출퇴근'
|
||||
},
|
||||
{
|
||||
old_key: 'monthly-attendance',
|
||||
new_key: 'attendance.monthly',
|
||||
new_path: '/pages/attendance/monthly.html',
|
||||
new_category: 'attendance',
|
||||
new_name: '월간 근태'
|
||||
},
|
||||
{
|
||||
old_key: 'annual-vacation-overview',
|
||||
new_key: 'attendance.annual_overview',
|
||||
new_path: '/pages/attendance/annual-overview.html',
|
||||
new_category: 'attendance',
|
||||
new_name: '연간 휴가 현황'
|
||||
},
|
||||
{
|
||||
old_key: 'vacation-request',
|
||||
new_key: 'attendance.vacation_request',
|
||||
new_path: '/pages/attendance/vacation-request.html',
|
||||
new_category: 'attendance',
|
||||
new_name: '휴가 신청'
|
||||
},
|
||||
{
|
||||
old_key: 'vacation-management',
|
||||
new_key: 'attendance.vacation_management',
|
||||
new_path: '/pages/attendance/vacation-management.html',
|
||||
new_category: 'attendance',
|
||||
new_name: '휴가 관리'
|
||||
},
|
||||
{
|
||||
old_key: 'vacation-allocation',
|
||||
new_key: 'attendance.vacation_allocation',
|
||||
new_path: '/pages/attendance/vacation-allocation.html',
|
||||
new_category: 'attendance',
|
||||
new_name: '휴가 발생 입력'
|
||||
}
|
||||
];
|
||||
|
||||
// 3. admin 폴더 내 파일명 변경
|
||||
const adminPageUpdates = [
|
||||
{
|
||||
old_key: 'attendance-report-comparison',
|
||||
new_key: 'admin.attendance_report',
|
||||
new_path: '/pages/admin/attendance-report.html',
|
||||
new_category: 'admin',
|
||||
new_name: '출퇴근-보고서 대조'
|
||||
}
|
||||
];
|
||||
|
||||
// 모든 업데이트 실행
|
||||
const allUpdates = [...safetyPageUpdates, ...attendancePageUpdates, ...adminPageUpdates];
|
||||
|
||||
for (const update of allUpdates) {
|
||||
await knex('pages')
|
||||
.where('page_key', update.old_key)
|
||||
.update({
|
||||
page_key: update.new_key,
|
||||
page_path: update.new_path,
|
||||
category: update.new_category,
|
||||
page_name: update.new_name
|
||||
});
|
||||
}
|
||||
|
||||
// 4. 안전 체크리스트 관리 페이지 추가 (새로 생성된 페이지)
|
||||
const existingChecklistPage = await knex('pages')
|
||||
.where('page_key', 'safety.checklist_manage')
|
||||
.orWhere('page_key', 'safety-checklist-manage')
|
||||
.first();
|
||||
|
||||
if (!existingChecklistPage) {
|
||||
await knex('pages').insert({
|
||||
page_key: 'safety.checklist_manage',
|
||||
page_name: '안전 체크리스트 관리',
|
||||
page_path: '/pages/safety/checklist-manage.html',
|
||||
category: 'safety',
|
||||
description: '안전 체크리스트 항목 관리',
|
||||
is_admin_only: 1,
|
||||
display_order: 50
|
||||
});
|
||||
}
|
||||
|
||||
// 5. 휴가 승인/직접입력 페이지 추가 (새로 생성된 페이지인 경우)
|
||||
const vacationPages = [
|
||||
{
|
||||
page_key: 'attendance.vacation_approval',
|
||||
page_name: '휴가 승인 관리',
|
||||
page_path: '/pages/attendance/vacation-approval.html',
|
||||
category: 'attendance',
|
||||
description: '휴가 신청 승인/거부',
|
||||
is_admin_only: 1,
|
||||
display_order: 65
|
||||
},
|
||||
{
|
||||
page_key: 'attendance.vacation_input',
|
||||
page_name: '휴가 직접 입력',
|
||||
page_path: '/pages/attendance/vacation-input.html',
|
||||
category: 'attendance',
|
||||
description: '관리자 휴가 직접 입력',
|
||||
is_admin_only: 1,
|
||||
display_order: 66
|
||||
}
|
||||
];
|
||||
|
||||
for (const page of vacationPages) {
|
||||
const existing = await knex('pages').where('page_key', page.page_key).first();
|
||||
if (!existing) {
|
||||
await knex('pages').insert(page);
|
||||
}
|
||||
}
|
||||
|
||||
// 6. role_default_pages 테이블 생성 (역할별 기본 페이지 권한)
|
||||
const tableExists = await knex.schema.hasTable('role_default_pages');
|
||||
if (!tableExists) {
|
||||
await knex.schema.createTable('role_default_pages', (table) => {
|
||||
table.integer('role_id').unsigned().notNullable()
|
||||
.references('id').inTable('roles').onDelete('CASCADE');
|
||||
table.integer('page_id').unsigned().notNullable()
|
||||
.references('id').inTable('pages').onDelete('CASCADE');
|
||||
table.primary(['role_id', 'page_id']);
|
||||
table.timestamps(true, true);
|
||||
});
|
||||
}
|
||||
|
||||
// 7. 기본 역할-페이지 매핑 데이터 삽입
|
||||
// 역할 조회
|
||||
const roles = await knex('roles').select('id', 'name');
|
||||
const pages = await knex('pages').select('id', 'page_key', 'category');
|
||||
|
||||
const roleMap = {};
|
||||
roles.forEach(r => { roleMap[r.name] = r.id; });
|
||||
|
||||
const pageMap = {};
|
||||
pages.forEach(p => { pageMap[p.page_key] = p.id; });
|
||||
|
||||
// Worker 역할 기본 페이지 (대시보드, 작업보고서, 휴가신청)
|
||||
const workerPages = [
|
||||
'dashboard',
|
||||
'work.report_create',
|
||||
'work.report_view',
|
||||
'attendance.vacation_request'
|
||||
];
|
||||
|
||||
// Leader 역할 기본 페이지 (Worker + TBM, 안전, 근태 일부)
|
||||
const leaderPages = [
|
||||
...workerPages,
|
||||
'work.tbm',
|
||||
'work.analysis',
|
||||
'safety.issue_report',
|
||||
'safety.issue_list',
|
||||
'attendance.daily',
|
||||
'attendance.monthly'
|
||||
];
|
||||
|
||||
// SafetyManager 역할 기본 페이지 (Leader + 안전 전체)
|
||||
const safetyManagerPages = [
|
||||
...leaderPages,
|
||||
'safety.issue_detail',
|
||||
'safety.visit_request',
|
||||
'safety.management',
|
||||
'safety.training_conduct',
|
||||
'safety.checklist_manage'
|
||||
];
|
||||
|
||||
// 역할별 페이지 매핑 삽입
|
||||
const rolePageMappings = [];
|
||||
|
||||
if (roleMap['Worker']) {
|
||||
workerPages.forEach(pageKey => {
|
||||
if (pageMap[pageKey]) {
|
||||
rolePageMappings.push({ role_id: roleMap['Worker'], page_id: pageMap[pageKey] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (roleMap['Leader']) {
|
||||
leaderPages.forEach(pageKey => {
|
||||
if (pageMap[pageKey]) {
|
||||
rolePageMappings.push({ role_id: roleMap['Leader'], page_id: pageMap[pageKey] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (roleMap['SafetyManager']) {
|
||||
safetyManagerPages.forEach(pageKey => {
|
||||
if (pageMap[pageKey]) {
|
||||
rolePageMappings.push({ role_id: roleMap['SafetyManager'], page_id: pageMap[pageKey] });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 중복 제거 후 삽입
|
||||
for (const mapping of rolePageMappings) {
|
||||
const existing = await knex('role_default_pages')
|
||||
.where('role_id', mapping.role_id)
|
||||
.where('page_id', mapping.page_id)
|
||||
.first();
|
||||
|
||||
if (!existing) {
|
||||
await knex('role_default_pages').insert(mapping);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('페이지 구조 재구성 완료');
|
||||
console.log(`- 업데이트된 페이지: ${allUpdates.length}개`);
|
||||
console.log(`- 역할별 기본 페이지 매핑: ${rolePageMappings.length}개`);
|
||||
};
|
||||
|
||||
exports.down = async function(knex) {
|
||||
// 1. role_default_pages 테이블 삭제
|
||||
await knex.schema.dropTableIfExists('role_default_pages');
|
||||
|
||||
// 2. 페이지 경로 원복 - safety → work/admin
|
||||
const safetyRevert = [
|
||||
{ new_key: 'safety.issue_report', old_key: 'issue-report', old_path: '/pages/work/issue-report.html', old_category: 'work' },
|
||||
{ new_key: 'safety.issue_list', old_key: 'issue-list', old_path: '/pages/work/issue-list.html', old_category: 'work' },
|
||||
{ new_key: 'safety.issue_detail', old_key: 'issue-detail', old_path: '/pages/work/issue-detail.html', old_category: 'work' },
|
||||
{ new_key: 'safety.visit_request', old_key: 'visit-request', old_path: '/pages/work/visit-request.html', old_category: 'work' },
|
||||
{ new_key: 'safety.management', old_key: 'safety-management', old_path: '/pages/admin/safety-management.html', old_category: 'admin' },
|
||||
{ new_key: 'safety.training_conduct', old_key: 'safety-training-conduct', old_path: '/pages/admin/safety-training-conduct.html', old_category: 'admin' },
|
||||
];
|
||||
|
||||
// 3. 페이지 경로 원복 - attendance → common
|
||||
const attendanceRevert = [
|
||||
{ new_key: 'attendance.daily', old_key: 'daily-attendance', old_path: '/pages/common/daily-attendance.html', old_category: 'common' },
|
||||
{ new_key: 'attendance.monthly', old_key: 'monthly-attendance', old_path: '/pages/common/monthly-attendance.html', old_category: 'common' },
|
||||
{ new_key: 'attendance.annual_overview', old_key: 'annual-vacation-overview', old_path: '/pages/common/annual-vacation-overview.html', old_category: 'common' },
|
||||
{ new_key: 'attendance.vacation_request', old_key: 'vacation-request', old_path: '/pages/common/vacation-request.html', old_category: 'common' },
|
||||
{ new_key: 'attendance.vacation_management', old_key: 'vacation-management', old_path: '/pages/common/vacation-management.html', old_category: 'common' },
|
||||
{ new_key: 'attendance.vacation_allocation', old_key: 'vacation-allocation', old_path: '/pages/common/vacation-allocation.html', old_category: 'common' },
|
||||
];
|
||||
|
||||
// 4. admin 파일명 원복
|
||||
const adminRevert = [
|
||||
{ new_key: 'admin.attendance_report', old_key: 'attendance-report-comparison', old_path: '/pages/admin/attendance-report-comparison.html', old_category: 'admin' }
|
||||
];
|
||||
|
||||
const allReverts = [...safetyRevert, ...attendanceRevert, ...adminRevert];
|
||||
|
||||
for (const revert of allReverts) {
|
||||
await knex('pages')
|
||||
.where('page_key', revert.new_key)
|
||||
.update({
|
||||
page_key: revert.old_key,
|
||||
page_path: revert.old_path,
|
||||
category: revert.old_category
|
||||
});
|
||||
}
|
||||
|
||||
// 5. 새로 추가된 페이지 삭제
|
||||
await knex('pages').whereIn('page_key', [
|
||||
'safety.checklist_manage',
|
||||
'attendance.vacation_approval',
|
||||
'attendance.vacation_input'
|
||||
]).del();
|
||||
|
||||
console.log('페이지 구조 재구성 롤백 완료');
|
||||
};
|
||||
Reference in New Issue
Block a user