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:
@@ -80,4 +80,13 @@ async function remove(req, res, next) {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getAll, getActive, getById, create, update, remove };
|
||||
async function getProductTypes(req, res, next) {
|
||||
try {
|
||||
const types = await projectModel.getProductTypes();
|
||||
res.json({ success: true, data: types });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { getAll, getActive, getById, create, update, remove, getProductTypes };
|
||||
|
||||
@@ -93,6 +93,7 @@ async function start() {
|
||||
const { runMigration, runGenericMigration } = require('./models/vacationSettingsModel');
|
||||
await runMigration();
|
||||
await runGenericMigration('20260323_add_resigned_date.sql');
|
||||
await runGenericMigration('20260326_add_product_types.sql');
|
||||
} catch (err) {
|
||||
if (!['ER_DUP_FIELDNAME', 'ER_TABLE_EXISTS_ERROR', 'ER_DUP_KEYNAME'].includes(err.code)) {
|
||||
console.error('Fatal migration error:', err.message);
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -9,6 +9,7 @@ const { requireAuth, requireAdminOrPermission } = require('../middleware/auth');
|
||||
|
||||
const projectPerm = requireAdminOrPermission('tkuser.projects');
|
||||
|
||||
router.get('/product-types', requireAuth, projectController.getProductTypes);
|
||||
router.get('/', requireAuth, projectController.getAll);
|
||||
router.get('/active', requireAuth, projectController.getActive);
|
||||
router.get('/:id', requireAuth, projectController.getById);
|
||||
|
||||
22
user-management/migrations/20260326_add_product_types.sql
Normal file
22
user-management/migrations/20260326_add_product_types.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
-- 제품유형 참조 테이블
|
||||
CREATE TABLE IF NOT EXISTS product_types (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
code VARCHAR(20) NOT NULL UNIQUE,
|
||||
name VARCHAR(100) NOT NULL,
|
||||
display_order INT DEFAULT 0,
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
-- 초기 데이터
|
||||
INSERT IGNORE INTO product_types (code, name, display_order) VALUES
|
||||
('PKG', 'Package', 1),
|
||||
('VESSEL', '압력용기', 2),
|
||||
('HX', '열교환기', 3),
|
||||
('SKID', 'Skid', 4);
|
||||
|
||||
-- projects에 product_type_id FK 추가
|
||||
ALTER TABLE projects ADD COLUMN product_type_id INT NULL;
|
||||
|
||||
ALTER TABLE projects ADD CONSTRAINT fk_project_product_type
|
||||
FOREIGN KEY (product_type_id) REFERENCES product_types(id)
|
||||
Reference in New Issue
Block a user