feat(schedule): 공정표 제품유형 + 표준공정 자동생성

Backend:
- product_types 참조 테이블 + projects.product_type_id FK (tkuser 마이그레이션)
- schedule_entries에 work_type_id, risk_assessment_id, source 컬럼 추가
- schedule_phases에 product_type_id 추가 (phase 오염 방지)
- generateFromTemplate: tksafety 템플릿 기반 공정 자동 생성 (트랜잭션)
- phase 매칭 3단계 우선순위 (전용→범용→신규)
- 간트 데이터 NULL 날짜 guard 추가
- system1 startup 마이그레이션 러너 추가

Frontend:
- tkuser 프로젝트 추가/수정 폼에 제품유형 드롭다운 추가
- 프로젝트 목록에 제품유형 뱃지 표시
- 공정표 툴바에 "표준공정 생성" 버튼 + 모달 추가

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-03-26 15:41:39 +09:00
parent 1ceeef2a65
commit 5cae2362cc
4 changed files with 127 additions and 3 deletions

View File

@@ -28,6 +28,8 @@ document.addEventListener('DOMContentLoaded', async () => {
document.getElementById('btnAddEntry').classList.remove('hidden');
document.getElementById('btnBatchAdd').classList.remove('hidden');
document.getElementById('btnAddMilestone').classList.remove('hidden');
const btnGen = document.getElementById('btnGenTemplate');
if (btnGen) btnGen.classList.remove('hidden');
}
// Load collapse state

View File

@@ -110,6 +110,9 @@
<button class="zoom-btn px-3 py-1.5 rounded-lg text-sm border" data-zoom="year">연간</button>
</div>
<div class="flex items-center gap-2 ml-auto">
<button id="btnGenTemplate" class="hidden bg-indigo-600 text-white px-3 py-1.5 rounded-lg text-sm hover:bg-indigo-700" onclick="openTemplateModal()">
<i class="fas fa-wand-magic-sparkles mr-1"></i>표준공정 생성
</button>
<button id="btnAddEntry" class="hidden bg-orange-600 text-white px-3 py-1.5 rounded-lg text-sm hover:bg-orange-700">
<i class="fas fa-plus mr-1"></i>항목 추가
</button>
@@ -315,7 +318,95 @@
</div>
</div>
<!-- 표준공정 생성 모달 -->
<div id="templateModal" class="modal-overlay hidden">
<div class="modal-content p-6" style="max-width: 400px;">
<div class="flex justify-between items-center mb-4">
<h3 class="text-lg font-bold"><i class="fas fa-wand-magic-sparkles text-indigo-500 mr-2"></i>표준공정 생성</h3>
<button onclick="closeTemplateModal()" class="text-gray-400 hover:text-gray-600"><i class="fas fa-times"></i></button>
</div>
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">프로젝트</label>
<select id="tmplProjectSelect" class="input-field w-full rounded-lg px-3 py-2 text-sm"></select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">제품유형</label>
<select id="tmplProductType" class="input-field w-full rounded-lg px-3 py-2 text-sm">
<option value="">선택</option>
</select>
</div>
<p class="text-xs text-gray-500"><i class="fas fa-info-circle mr-1"></i>선택한 제품유형의 표준공정이 자동으로 생성됩니다</p>
</div>
<div class="flex justify-end gap-2 mt-5">
<button onclick="closeTemplateModal()" class="px-4 py-2 border rounded-lg text-sm text-gray-600 hover:bg-gray-50">취소</button>
<button onclick="generateTemplate()" class="px-4 py-2 bg-indigo-600 text-white rounded-lg text-sm hover:bg-indigo-700">
<i class="fas fa-wand-magic-sparkles mr-1"></i>생성
</button>
</div>
</div>
</div>
<script src="/static/js/tkfb-core.js?v=2026031701"></script>
<script src="/js/schedule.js?v=2026031701"></script>
<script>
// 표준공정 생성 모달
async function openTemplateModal() {
const modal = document.getElementById('templateModal');
const projSel = document.getElementById('tmplProjectSelect');
const typeSel = document.getElementById('tmplProductType');
// 프로젝트 목록 로드
try {
const r = await apiFetch('/api/schedule/product-types');
typeSel.innerHTML = '<option value="">선택</option>';
(r.data || []).forEach(pt => {
typeSel.innerHTML += `<option value="${pt.code}">${pt.code} - ${escHtml(pt.name)}</option>`;
});
} catch(e) { console.warn('제품유형 로드 실패:', e); }
// 프로젝트 목록 (기존 gantt에서 사용 중인 projects 변수 활용)
if (typeof allProjects !== 'undefined' && allProjects.length) {
projSel.innerHTML = allProjects.map(p =>
`<option value="${p.project_id}">${escHtml(p.job_no)} - ${escHtml(p.project_name)}</option>`
).join('');
} else {
try {
const r = await apiFetch('/api/projects/active');
const projs = r.data || [];
projSel.innerHTML = projs.map(p =>
`<option value="${p.project_id}">${escHtml(p.job_no)} - ${escHtml(p.project_name)}</option>`
).join('');
} catch(e) { projSel.innerHTML = '<option>프로젝트 로드 실패</option>'; }
}
modal.classList.remove('hidden');
}
function closeTemplateModal() {
document.getElementById('templateModal').classList.add('hidden');
}
async function generateTemplate() {
const projectId = document.getElementById('tmplProjectSelect').value;
const productTypeCode = document.getElementById('tmplProductType').value;
if (!projectId || !productTypeCode) {
showToast('프로젝트와 제품유형을 선택해주세요', 'error');
return;
}
try {
const r = await apiFetch('/api/schedule/generate-from-template', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ project_id: parseInt(projectId), product_type_code: productTypeCode })
});
showToast(r.message || `${r.data.created}개 표준공정이 생성되었습니다`);
closeTemplateModal();
if (typeof loadGanttData === 'function') loadGanttData();
} catch(e) {
showToast(e.message || '표준공정 생성 실패', 'error');
}
}
</script>
</body>
</html>