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

- 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 마이그레이션 러너 추가

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-03-26 15:39:12 +09:00
parent 7abf62620b
commit d6dd03a52f
10 changed files with 264 additions and 27 deletions

View File

@@ -10,7 +10,10 @@ const { getPool } = require('./userModel');
async function getAll() {
const db = getPool();
const [rows] = await db.query(
'SELECT * FROM projects ORDER BY project_id DESC'
`SELECT p.*, pt.code AS product_type_code, pt.name AS product_type_name
FROM projects p
LEFT JOIN product_types pt ON p.product_type_id = pt.id
ORDER BY p.project_id DESC`
);
return rows;
}
@@ -18,7 +21,10 @@ async function getAll() {
async function getActive() {
const db = getPool();
const [rows] = await db.query(
'SELECT * FROM projects WHERE is_active = TRUE ORDER BY project_name ASC'
`SELECT p.*, pt.code AS product_type_code, pt.name AS product_type_name
FROM projects p
LEFT JOIN product_types pt ON p.product_type_id = pt.id
WHERE p.is_active = TRUE ORDER BY p.project_name ASC`
);
return rows;
}
@@ -26,18 +32,29 @@ async function getActive() {
async function getById(id) {
const db = getPool();
const [rows] = await db.query(
'SELECT * FROM projects WHERE project_id = ?',
`SELECT p.*, pt.code AS product_type_code, pt.name AS product_type_name
FROM projects p
LEFT JOIN product_types pt ON p.product_type_id = pt.id
WHERE p.project_id = ?`,
[id]
);
return rows[0] || null;
}
async function create({ job_no, project_name, contract_date, due_date, delivery_method, site, pm }) {
async function getProductTypes() {
const db = getPool();
const [rows] = await db.query(
'SELECT * FROM product_types WHERE is_active = TRUE ORDER BY display_order'
);
return rows;
}
async function create({ job_no, project_name, contract_date, due_date, delivery_method, site, pm, product_type_id }) {
const db = getPool();
const [result] = await db.query(
`INSERT INTO projects (job_no, project_name, contract_date, due_date, delivery_method, site, pm)
VALUES (?, ?, ?, ?, ?, ?, ?)`,
[job_no, project_name, contract_date || null, due_date || null, delivery_method || null, site || null, pm || null]
`INSERT INTO projects (job_no, project_name, contract_date, due_date, delivery_method, site, pm, product_type_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
[job_no, project_name, contract_date || null, due_date || null, delivery_method || null, site || null, pm || null, product_type_id || null]
);
return getById(result.insertId);
}
@@ -57,6 +74,7 @@ async function update(id, data) {
if (data.is_active !== undefined) { fields.push('is_active = ?'); values.push(data.is_active); }
if (data.project_status !== undefined) { fields.push('project_status = ?'); values.push(data.project_status); }
if (data.completed_date !== undefined) { fields.push('completed_date = ?'); values.push(data.completed_date || null); }
if (data.product_type_id !== undefined) { fields.push('product_type_id = ?'); values.push(data.product_type_id || null); }
if (fields.length === 0) return getById(id);
@@ -76,4 +94,4 @@ async function deactivate(id) {
);
}
module.exports = { getAll, getActive, getById, create, update, deactivate };
module.exports = { getAll, getActive, getById, create, update, deactivate, getProductTypes };