feat: 일일순회점검 시스템 구축 및 관리 기능 개선

- 일일순회점검 시스템 신규 구현
  - DB 테이블: patrol_checklist_items, daily_patrol_sessions, patrol_check_records, workplace_items, item_types
  - API: /api/patrol/* 엔드포인트
  - 프론트엔드: 지도 기반 작업장 점검 UI

- 설비 관리 기능 개선
  - 구매 관련 필드 추가 (구매일, 가격, 공급업체 등)
  - 설비 코드 자동 생성 (TKP-XXX 형식)

- 작업장 관리 개선
  - 레이아웃 이미지 업로드 기능
  - 마커 위치 저장 기능

- 부서 관리 기능 추가
- 사이드바 네비게이션 카테고리 재구성
- 이미지 401 오류 수정 (정적 파일 경로 처리)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Hyungi Ahn
2026-02-04 11:41:41 +09:00
parent 2e9d24faf2
commit 90d3e32992
101 changed files with 17421 additions and 7047 deletions

View File

@@ -49,6 +49,8 @@ function setupRoutes(app) {
const vacationBalanceRoutes = require('../routes/vacationBalanceRoutes');
const visitRequestRoutes = require('../routes/visitRequestRoutes');
const workIssueRoutes = require('../routes/workIssueRoutes');
const departmentRoutes = require('../routes/departmentRoutes');
const patrolRoutes = require('../routes/patrolRoutes');
// Rate Limiters 설정
const rateLimit = require('express-rate-limit');
@@ -153,6 +155,8 @@ function setupRoutes(app) {
app.use('/api', pageAccessRoutes); // 페이지 접근 권한 관리
app.use('/api/tbm', tbmRoutes); // TBM 시스템
app.use('/api/work-issues', workIssueRoutes); // 문제 신고 시스템
app.use('/api/departments', departmentRoutes); // 부서 관리
app.use('/api/patrol', patrolRoutes); // 일일순회점검 시스템
app.use('/api', uploadBgRoutes);
// Swagger API 문서

View File

@@ -0,0 +1,241 @@
// controllers/departmentController.js
const departmentModel = require('../models/departmentModel');
const departmentController = {
// 모든 부서 조회
async getAll(req, res) {
try {
const { active_only } = req.query;
const departments = active_only === 'true'
? await departmentModel.getActive()
: await departmentModel.getAll();
res.json({
success: true,
data: departments
});
} catch (error) {
console.error('부서 목록 조회 오류:', error);
res.status(500).json({
success: false,
error: '부서 목록을 불러오는데 실패했습니다.'
});
}
},
// 부서 상세 조회
async getById(req, res) {
try {
const { id } = req.params;
const department = await departmentModel.getById(id);
if (!department) {
return res.status(404).json({
success: false,
error: '부서를 찾을 수 없습니다.'
});
}
res.json({
success: true,
data: department
});
} catch (error) {
console.error('부서 조회 오류:', error);
res.status(500).json({
success: false,
error: '부서 정보를 불러오는데 실패했습니다.'
});
}
},
// 부서 생성
async create(req, res) {
try {
const { department_name, parent_id, description, is_active, display_order } = req.body;
if (!department_name) {
return res.status(400).json({
success: false,
error: '부서명은 필수입니다.'
});
}
const departmentId = await departmentModel.create({
department_name,
parent_id,
description,
is_active,
display_order
});
const newDepartment = await departmentModel.getById(departmentId);
res.status(201).json({
success: true,
message: '부서가 생성되었습니다.',
data: newDepartment
});
} catch (error) {
console.error('부서 생성 오류:', error);
res.status(500).json({
success: false,
error: '부서 생성에 실패했습니다.'
});
}
},
// 부서 수정
async update(req, res) {
try {
const { id } = req.params;
const { department_name, parent_id, description, is_active, display_order } = req.body;
if (!department_name) {
return res.status(400).json({
success: false,
error: '부서명은 필수입니다.'
});
}
// 자기 자신을 상위 부서로 지정하는 것 방지
if (parent_id && parseInt(parent_id) === parseInt(id)) {
return res.status(400).json({
success: false,
error: '자기 자신을 상위 부서로 지정할 수 없습니다.'
});
}
const updated = await departmentModel.update(id, {
department_name,
parent_id,
description,
is_active,
display_order
});
if (!updated) {
return res.status(404).json({
success: false,
error: '부서를 찾을 수 없습니다.'
});
}
const updatedDepartment = await departmentModel.getById(id);
res.json({
success: true,
message: '부서 정보가 수정되었습니다.',
data: updatedDepartment
});
} catch (error) {
console.error('부서 수정 오류:', error);
res.status(500).json({
success: false,
error: '부서 수정에 실패했습니다.'
});
}
},
// 부서 삭제
async delete(req, res) {
try {
const { id } = req.params;
await departmentModel.delete(id);
res.json({
success: true,
message: '부서가 삭제되었습니다.'
});
} catch (error) {
console.error('부서 삭제 오류:', error);
res.status(400).json({
success: false,
error: error.message || '부서 삭제에 실패했습니다.'
});
}
},
// 부서별 작업자 조회
async getWorkers(req, res) {
try {
const { id } = req.params;
const workers = await departmentModel.getWorkersByDepartment(id);
res.json({
success: true,
data: workers
});
} catch (error) {
console.error('부서 작업자 조회 오류:', error);
res.status(500).json({
success: false,
error: '작업자 목록을 불러오는데 실패했습니다.'
});
}
},
// 작업자 부서 이동
async moveWorker(req, res) {
try {
const { workerId, departmentId } = req.body;
if (!workerId || !departmentId) {
return res.status(400).json({
success: false,
error: '작업자 ID와 부서 ID가 필요합니다.'
});
}
await departmentModel.moveWorker(workerId, departmentId);
res.json({
success: true,
message: '작업자 부서가 변경되었습니다.'
});
} catch (error) {
console.error('작업자 부서 이동 오류:', error);
res.status(500).json({
success: false,
error: '작업자 부서 변경에 실패했습니다.'
});
}
},
// 여러 작업자 부서 일괄 이동
async moveWorkers(req, res) {
try {
const { workerIds, departmentId } = req.body;
if (!workerIds || !Array.isArray(workerIds) || workerIds.length === 0) {
return res.status(400).json({
success: false,
error: '이동할 작업자를 선택하세요.'
});
}
if (!departmentId) {
return res.status(400).json({
success: false,
error: '대상 부서를 선택하세요.'
});
}
const count = await departmentModel.moveWorkers(workerIds, departmentId);
res.json({
success: true,
message: `${count}명의 작업자 부서가 변경되었습니다.`
});
} catch (error) {
console.error('작업자 일괄 이동 오류:', error);
res.status(500).json({
success: false,
error: '작업자 부서 변경에 실패했습니다.'
});
}
}
};
module.exports = departmentController;

View File

@@ -266,6 +266,11 @@ const EquipmentController = {
map_height_percent: req.body.map_height_percent
};
// workplace_id가 있으면 포함 (설비를 다른 작업장으로 이동 가능)
if (req.body.workplace_id !== undefined) {
positionData.workplace_id = req.body.workplace_id;
}
EquipmentModel.updateMapPosition(equipmentId, positionData, (error, result) => {
if (error) {
console.error('설비 위치 업데이트 오류:', error);
@@ -343,6 +348,37 @@ const EquipmentController = {
message: '서버 오류가 발생했습니다.'
});
}
},
// GET NEXT EQUIPMENT CODE - 다음 관리번호 자동 생성
getNextEquipmentCode: (req, res) => {
try {
const prefix = req.query.prefix || 'TKP';
EquipmentModel.getNextEquipmentCode(prefix, (error, nextCode) => {
if (error) {
console.error('다음 관리번호 조회 오류:', error);
return res.status(500).json({
success: false,
message: '다음 관리번호 조회 중 오류가 발생했습니다.'
});
}
res.json({
success: true,
data: {
next_code: nextCode,
prefix: prefix
}
});
});
} catch (error) {
console.error('다음 관리번호 조회 오류:', error);
res.status(500).json({
success: false,
message: '서버 오류가 발생했습니다.'
});
}
}
};

View File

@@ -0,0 +1,295 @@
// patrolController.js
// 일일순회점검 시스템 컨트롤러
const PatrolModel = require('../models/patrolModel');
const PatrolController = {
// ==================== 순회점검 세션 ====================
// 세션 시작/조회
getOrCreateSession: async (req, res) => {
try {
const { patrol_date, patrol_time, category_id } = req.body;
const inspectorId = req.user.user_id;
if (!patrol_date || !patrol_time || !category_id) {
return res.status(400).json({ success: false, message: '필수 정보가 누락되었습니다.' });
}
const session = await PatrolModel.getOrCreateSession(patrol_date, patrol_time, category_id, inspectorId);
res.json({ success: true, data: session });
} catch (error) {
console.error('세션 생성/조회 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 세션 상세 조회
getSession: async (req, res) => {
try {
const { sessionId } = req.params;
const session = await PatrolModel.getSession(sessionId);
if (!session) {
return res.status(404).json({ success: false, message: '세션을 찾을 수 없습니다.' });
}
res.json({ success: true, data: session });
} catch (error) {
console.error('세션 조회 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 세션 목록 조회
getSessions: async (req, res) => {
try {
const { patrol_date, patrol_time, category_id, status, limit } = req.query;
const sessions = await PatrolModel.getSessions({
patrol_date,
patrol_time,
category_id,
status,
limit
});
res.json({ success: true, data: sessions });
} catch (error) {
console.error('세션 목록 조회 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 세션 완료
completeSession: async (req, res) => {
try {
const { sessionId } = req.params;
await PatrolModel.completeSession(sessionId);
res.json({ success: true, message: '순회점검이 완료되었습니다.' });
} catch (error) {
console.error('세션 완료 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 세션 메모 업데이트
updateSessionNotes: async (req, res) => {
try {
const { sessionId } = req.params;
const { notes } = req.body;
await PatrolModel.updateSessionNotes(sessionId, notes);
res.json({ success: true, message: '메모가 저장되었습니다.' });
} catch (error) {
console.error('메모 저장 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// ==================== 체크리스트 항목 ====================
// 체크리스트 항목 조회
getChecklistItems: async (req, res) => {
try {
const { category_id, workplace_id } = req.query;
const items = await PatrolModel.getChecklistItems(category_id, workplace_id);
// 카테고리별로 그룹화
const grouped = {};
items.forEach(item => {
if (!grouped[item.check_category]) {
grouped[item.check_category] = [];
}
grouped[item.check_category].push(item);
});
res.json({ success: true, data: { items, grouped } });
} catch (error) {
console.error('체크리스트 항목 조회 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 체크리스트 항목 추가
createChecklistItem: async (req, res) => {
try {
const itemId = await PatrolModel.createChecklistItem(req.body);
res.json({ success: true, data: { item_id: itemId }, message: '항목이 추가되었습니다.' });
} catch (error) {
console.error('항목 추가 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 체크리스트 항목 수정
updateChecklistItem: async (req, res) => {
try {
const { itemId } = req.params;
await PatrolModel.updateChecklistItem(itemId, req.body);
res.json({ success: true, message: '항목이 수정되었습니다.' });
} catch (error) {
console.error('항목 수정 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 체크리스트 항목 삭제
deleteChecklistItem: async (req, res) => {
try {
const { itemId } = req.params;
await PatrolModel.deleteChecklistItem(itemId);
res.json({ success: true, message: '항목이 삭제되었습니다.' });
} catch (error) {
console.error('항목 삭제 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// ==================== 체크 기록 ====================
// 작업장별 체크 기록 조회
getCheckRecords: async (req, res) => {
try {
const { sessionId } = req.params;
const { workplace_id } = req.query;
const records = await PatrolModel.getCheckRecords(sessionId, workplace_id);
res.json({ success: true, data: records });
} catch (error) {
console.error('체크 기록 조회 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 체크 기록 저장
saveCheckRecord: async (req, res) => {
try {
const { sessionId } = req.params;
const { workplace_id, check_item_id, is_checked, check_result, note } = req.body;
if (!workplace_id || !check_item_id) {
return res.status(400).json({ success: false, message: '필수 정보가 누락되었습니다.' });
}
await PatrolModel.saveCheckRecord(sessionId, workplace_id, check_item_id, is_checked, check_result, note);
res.json({ success: true, message: '저장되었습니다.' });
} catch (error) {
console.error('체크 기록 저장 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 체크 기록 일괄 저장
saveCheckRecords: async (req, res) => {
try {
const { sessionId } = req.params;
const { workplace_id, records } = req.body;
if (!workplace_id || !records || !Array.isArray(records)) {
return res.status(400).json({ success: false, message: '필수 정보가 누락되었습니다.' });
}
await PatrolModel.saveCheckRecords(sessionId, workplace_id, records);
res.json({ success: true, message: '저장되었습니다.' });
} catch (error) {
console.error('체크 기록 일괄 저장 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// ==================== 작업장 물품 현황 ====================
// 작업장 물품 조회
getWorkplaceItems: async (req, res) => {
try {
const { workplaceId } = req.params;
const { include_inactive } = req.query;
const items = await PatrolModel.getWorkplaceItems(workplaceId, include_inactive !== 'true');
res.json({ success: true, data: items });
} catch (error) {
console.error('물품 조회 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 물품 추가
createWorkplaceItem: async (req, res) => {
try {
const { workplaceId } = req.params;
const data = { ...req.body, workplace_id: workplaceId, created_by: req.user.user_id };
const itemId = await PatrolModel.createWorkplaceItem(data);
res.json({ success: true, data: { item_id: itemId }, message: '물품이 추가되었습니다.' });
} catch (error) {
console.error('물품 추가 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 물품 수정
updateWorkplaceItem: async (req, res) => {
try {
const { itemId } = req.params;
await PatrolModel.updateWorkplaceItem(itemId, req.body, req.user.user_id);
res.json({ success: true, message: '물품이 수정되었습니다.' });
} catch (error) {
console.error('물품 수정 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 물품 삭제
deleteWorkplaceItem: async (req, res) => {
try {
const { itemId } = req.params;
const { permanent } = req.query;
if (permanent === 'true') {
await PatrolModel.hardDeleteWorkplaceItem(itemId);
} else {
await PatrolModel.deleteWorkplaceItem(itemId, req.user.user_id);
}
res.json({ success: true, message: '물품이 삭제되었습니다.' });
} catch (error) {
console.error('물품 삭제 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// ==================== 물품 유형 ====================
// 물품 유형 목록
getItemTypes: async (req, res) => {
try {
const types = await PatrolModel.getItemTypes();
res.json({ success: true, data: types });
} catch (error) {
console.error('물품 유형 조회 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// ==================== 대시보드/통계 ====================
// 오늘 순회점검 현황
getTodayStatus: async (req, res) => {
try {
const { category_id } = req.query;
const status = await PatrolModel.getTodayPatrolStatus(category_id);
res.json({ success: true, data: status });
} catch (error) {
console.error('오늘 현황 조회 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
},
// 작업장별 점검 현황
getWorkplaceCheckStatus: async (req, res) => {
try {
const { sessionId } = req.params;
const status = await PatrolModel.getWorkplaceCheckStatus(sessionId);
res.json({ success: true, data: status });
} catch (error) {
console.error('작업장별 점검 현황 조회 오류:', error);
res.status(500).json({ success: false, message: '서버 오류가 발생했습니다.' });
}
}
};
module.exports = PatrolController;

View File

@@ -43,11 +43,17 @@ const getAllUsers = asyncHandler(async (req, res) => {
r.name as role,
u._access_level_old as access_level,
u.is_active,
u.worker_id,
w.worker_name,
w.department_id,
d.department_name,
u.created_at,
u.updated_at,
u.last_login_at as last_login
FROM users u
LEFT JOIN roles r ON u.role_id = r.id
LEFT JOIN workers w ON u.worker_id = w.worker_id
LEFT JOIN departments d ON w.department_id = d.department_id
ORDER BY u.created_at DESC
`;
@@ -218,7 +224,7 @@ const updateUser = asyncHandler(async (req, res) => {
checkAdminPermission(req.user);
const { id } = req.params;
const { username, name, email, role, role_id, password } = req.body;
const { username, name, email, role, role_id, password, worker_id } = req.body;
if (!id || isNaN(id)) {
throw new ValidationError('유효하지 않은 사용자 ID입니다');
@@ -227,7 +233,7 @@ const updateUser = asyncHandler(async (req, res) => {
logger.info('사용자 수정 요청', { userId: id, body: req.body });
// 최소 하나의 수정 필드가 필요
if (!username && !name && email === undefined && !role && !role_id && !password) {
if (!username && !name && email === undefined && !role && !role_id && !password && worker_id === undefined) {
throw new ValidationError('수정할 필드가 없습니다');
}
@@ -318,6 +324,22 @@ const updateUser = asyncHandler(async (req, res) => {
values.push(hashedPassword);
}
// worker_id 업데이트 (null도 허용 - 연결 해제)
if (worker_id !== undefined) {
if (worker_id !== null) {
// worker_id가 유효한지 확인
const [workerCheck] = await db.execute('SELECT worker_id, worker_name FROM workers WHERE worker_id = ?', [worker_id]);
if (workerCheck.length === 0) {
throw new ValidationError('유효하지 않은 작업자 ID입니다');
}
logger.info('작업자 연결', { userId: id, worker_id, worker_name: workerCheck[0].worker_name });
} else {
logger.info('작업자 연결 해제', { userId: id });
}
updates.push('worker_id = ?');
values.push(worker_id);
}
updates.push('updated_at = NOW()');
values.push(id);
@@ -476,6 +498,69 @@ const deleteUser = asyncHandler(async (req, res) => {
}
});
/**
* 사용자 영구 삭제 (Hard Delete)
*/
const permanentDeleteUser = asyncHandler(async (req, res) => {
checkAdminPermission(req.user);
const { id } = req.params;
if (!id || isNaN(id)) {
throw new ValidationError('유효하지 않은 사용자 ID입니다');
}
// 자기 자신 삭제 방지
if (req.user && req.user.user_id == id) {
throw new ValidationError('자기 자신은 삭제할 수 없습니다');
}
logger.info('사용자 영구 삭제 요청', { userId: id });
const { getDb } = require('../dbPool');
const db = await getDb();
try {
// 사용자 존재 확인
const checkQuery = 'SELECT user_id, username FROM users WHERE user_id = ?';
const [users] = await db.execute(checkQuery, [id]);
if (users.length === 0) {
throw new NotFoundError('사용자를 찾을 수 없습니다');
}
const username = users[0].username;
// 관련 데이터 삭제 (외래 키 제약 조건 때문에 순서 중요)
// 1. 로그인 로그 삭제
await db.execute('DELETE FROM login_logs WHERE user_id = ?', [id]);
// 2. 페이지 접근 권한 삭제
await db.execute('DELETE FROM user_page_access WHERE user_id = ?', [id]);
// 3. 사용자 삭제
await db.execute('DELETE FROM users WHERE user_id = ?', [id]);
logger.info('사용자 영구 삭제 성공', {
userId: id,
username: username,
deletedBy: req.user.username
});
res.json({
success: true,
data: { user_id: id },
message: `사용자 "${username}"이(가) 영구적으로 삭제되었습니다`
});
} catch (error) {
if (error instanceof NotFoundError || error instanceof ValidationError) {
throw error;
}
logger.error('사용자 영구 삭제 실패', { userId: id, error: error.message });
throw new DatabaseError('사용자를 영구 삭제하는데 실패했습니다');
}
});
/**
* 사용자의 페이지 접근 권한 조회
*/
@@ -647,6 +732,7 @@ module.exports = {
updateUser,
updateUserStatus,
deleteUser,
permanentDeleteUser,
getUserPageAccess,
updateUserPageAccess,
resetUserPassword

View File

@@ -73,9 +73,9 @@ exports.createWorker = asyncHandler(async (req, res) => {
* 전체 작업자 조회 (캐싱 및 페이지네이션 적용)
*/
exports.getAllWorkers = asyncHandler(async (req, res) => {
const { page = 1, limit = 10, search = '', status = '' } = req.query;
const { page = 1, limit = 10, search = '', status = '', department_id = null } = req.query;
const cacheKey = cache.createKey('workers', 'list', page, limit, search, status);
const cacheKey = cache.createKey('workers', 'list', page, limit, search, status, department_id);
// 캐시에서 조회
const cachedData = await cache.get(cacheKey);
@@ -90,7 +90,7 @@ exports.getAllWorkers = asyncHandler(async (req, res) => {
}
// 최적화된 쿼리 사용
const result = await optimizedQueries.getWorkersPaged(page, limit, search, status);
const result = await optimizedQueries.getWorkersPaged(page, limit, search, status, department_id);
// 캐시에 저장 (5분)
await cache.set(cacheKey, result, cache.TTL.MEDIUM);

View File

@@ -0,0 +1,35 @@
/**
* 설비 테이블에 구입처 및 구입가격 컬럼 추가
*
* @author TK-FB-Project
* @since 2026-02-04
*/
exports.up = async function(knex) {
// 컬럼 존재 여부 확인
const hasSupplier = await knex.schema.hasColumn('equipments', 'supplier');
const hasPurchasePrice = await knex.schema.hasColumn('equipments', 'purchase_price');
if (!hasSupplier || !hasPurchasePrice) {
await knex.schema.alterTable('equipments', (table) => {
if (!hasSupplier) {
table.string('supplier', 100).nullable().after('manufacturer').comment('구입처');
}
if (!hasPurchasePrice) {
table.decimal('purchase_price', 15, 0).nullable().after('supplier').comment('구입가격');
}
});
console.log('✅ equipments 테이블에 supplier, purchase_price 컬럼 추가 완료');
} else {
console.log(' supplier, purchase_price 컬럼이 이미 존재합니다. 스킵합니다.');
}
};
exports.down = async function(knex) {
await knex.schema.alterTable('equipments', (table) => {
table.dropColumn('supplier');
table.dropColumn('purchase_price');
});
console.log('✅ equipments 테이블에서 supplier, purchase_price 컬럼 삭제 완료');
};

View File

@@ -0,0 +1,166 @@
/**
* 마이그레이션: 일일순회점검 시스템
* 작성일: 2026-02-04
*
* 생성 테이블:
* - patrol_checklist_items: 순회점검 체크리스트 마스터
* - daily_patrol_sessions: 순회점검 세션 기록
* - patrol_check_records: 순회점검 체크 결과
* - workplace_items: 작업장 물품 현황 (용기, 플레이트 등)
*/
exports.up = async function(knex) {
console.log('⏳ 일일순회점검 시스템 테이블 생성 중...');
// 1. 순회점검 체크리스트 마스터 테이블
await knex.schema.createTable('patrol_checklist_items', (table) => {
table.increments('item_id').primary();
table.integer('workplace_id').unsigned().nullable().comment('특정 작업장 전용 (NULL=공통)');
table.integer('category_id').unsigned().nullable().comment('특정 공장 전용 (NULL=공통)');
table.string('check_category', 50).notNullable().comment('분류 (안전, 정리정돈, 설비 등)');
table.string('check_item', 200).notNullable().comment('점검 항목');
table.text('description').nullable().comment('설명');
table.integer('display_order').defaultTo(0).comment('표시 순서');
table.boolean('is_required').defaultTo(true).comment('필수 체크 여부');
table.boolean('is_active').defaultTo(true).comment('활성 여부');
table.timestamp('created_at').defaultTo(knex.fn.now());
table.timestamp('updated_at').defaultTo(knex.fn.now());
table.index('workplace_id');
table.index('category_id');
table.index('check_category');
table.foreign('workplace_id').references('workplaces.workplace_id').onDelete('CASCADE');
table.foreign('category_id').references('workplace_categories.category_id').onDelete('CASCADE');
});
console.log('✅ patrol_checklist_items 테이블 생성 완료');
// 초기 순회점검 체크리스트 데이터
await knex('patrol_checklist_items').insert([
// 안전 관련
{ check_category: 'SAFETY', check_item: '소화기 상태 확인', display_order: 1, is_required: true },
{ check_category: 'SAFETY', check_item: '비상구 통로 확보 확인', display_order: 2, is_required: true },
{ check_category: 'SAFETY', check_item: '안전표지판 부착 상태', display_order: 3, is_required: true },
{ check_category: 'SAFETY', check_item: '위험물 관리 상태', display_order: 4, is_required: true },
// 정리정돈
{ check_category: 'ORGANIZATION', check_item: '작업장 정리정돈 상태', display_order: 10, is_required: true },
{ check_category: 'ORGANIZATION', check_item: '통로 장애물 여부', display_order: 11, is_required: true },
{ check_category: 'ORGANIZATION', check_item: '폐기물 처리 상태', display_order: 12, is_required: true },
{ check_category: 'ORGANIZATION', check_item: '자재 적재 상태', display_order: 13, is_required: true },
// 설비
{ check_category: 'EQUIPMENT', check_item: '설비 외관 이상 여부', display_order: 20, is_required: false },
{ check_category: 'EQUIPMENT', check_item: '설비 작동 상태', display_order: 21, is_required: false },
{ check_category: 'EQUIPMENT', check_item: '설비 청결 상태', display_order: 22, is_required: false },
// 환경
{ check_category: 'ENVIRONMENT', check_item: '조명 상태', display_order: 30, is_required: true },
{ check_category: 'ENVIRONMENT', check_item: '환기 상태', display_order: 31, is_required: true },
{ check_category: 'ENVIRONMENT', check_item: '누수/누유 여부', display_order: 32, is_required: true },
]);
console.log('✅ patrol_checklist_items 초기 데이터 입력 완료');
// 2. 순회점검 세션 테이블
await knex.schema.createTable('daily_patrol_sessions', (table) => {
table.increments('session_id').primary();
table.date('patrol_date').notNullable().comment('점검 날짜');
table.enum('patrol_time', ['morning', 'afternoon']).notNullable().comment('점검 시간대');
table.integer('inspector_id').notNullable().comment('순찰자 user_id'); // signed (users.user_id)
table.integer('category_id').unsigned().nullable().comment('공장 ID');
table.enum('status', ['in_progress', 'completed']).defaultTo('in_progress').comment('상태');
table.text('notes').nullable().comment('특이사항');
table.time('started_at').nullable().comment('점검 시작 시간');
table.time('completed_at').nullable().comment('점검 완료 시간');
table.timestamp('created_at').defaultTo(knex.fn.now());
table.timestamp('updated_at').defaultTo(knex.fn.now());
table.unique(['patrol_date', 'patrol_time', 'category_id']);
table.index(['patrol_date', 'patrol_time']);
table.index('inspector_id');
table.foreign('inspector_id').references('users.user_id');
table.foreign('category_id').references('workplace_categories.category_id').onDelete('SET NULL');
});
console.log('✅ daily_patrol_sessions 테이블 생성 완료');
// 3. 순회점검 체크 기록 테이블
await knex.schema.createTable('patrol_check_records', (table) => {
table.increments('record_id').primary();
table.integer('session_id').unsigned().notNullable().comment('순회점검 세션 ID');
table.integer('workplace_id').unsigned().notNullable().comment('작업장 ID');
table.integer('check_item_id').unsigned().notNullable().comment('체크항목 ID');
table.boolean('is_checked').defaultTo(false).comment('체크 여부');
table.enum('check_result', ['good', 'warning', 'bad']).nullable().comment('점검 결과');
table.text('note').nullable().comment('비고');
table.timestamp('checked_at').nullable().comment('체크 시간');
// 인덱스명 길이 제한으로 인해 수동으로 지정
table.unique(['session_id', 'workplace_id', 'check_item_id'], 'pcr_session_wp_item_unique');
table.index(['session_id', 'workplace_id'], 'pcr_session_wp_idx');
table.foreign('session_id').references('daily_patrol_sessions.session_id').onDelete('CASCADE');
table.foreign('workplace_id').references('workplaces.workplace_id').onDelete('CASCADE');
table.foreign('check_item_id').references('patrol_checklist_items.item_id').onDelete('CASCADE');
});
console.log('✅ patrol_check_records 테이블 생성 완료');
// 4. 작업장 물품 현황 테이블
await knex.schema.createTable('workplace_items', (table) => {
table.increments('item_id').primary();
table.integer('workplace_id').unsigned().notNullable().comment('작업장 ID');
table.integer('patrol_session_id').unsigned().nullable().comment('등록한 순회점검 세션');
table.integer('project_id').nullable().comment('관련 프로젝트'); // signed (projects.project_id)
table.enum('item_type', ['container', 'plate', 'material', 'tool', 'other']).notNullable().comment('물품 유형');
table.string('item_name', 100).nullable().comment('물품명/설명');
table.integer('quantity').defaultTo(1).comment('수량');
table.decimal('x_percent', 5, 2).nullable().comment('지도상 X 위치 (%)');
table.decimal('y_percent', 5, 2).nullable().comment('지도상 Y 위치 (%)');
table.decimal('width_percent', 5, 2).nullable().comment('지도상 너비 (%)');
table.decimal('height_percent', 5, 2).nullable().comment('지도상 높이 (%)');
table.boolean('is_active').defaultTo(true).comment('현재 존재 여부');
table.integer('created_by').notNullable().comment('등록자 user_id'); // signed (users.user_id)
table.timestamp('created_at').defaultTo(knex.fn.now());
table.integer('updated_by').nullable().comment('최종 수정자 user_id'); // signed (users.user_id)
table.timestamp('updated_at').defaultTo(knex.fn.now());
table.index(['workplace_id', 'is_active']);
table.index('project_id');
table.foreign('workplace_id').references('workplaces.workplace_id').onDelete('CASCADE');
table.foreign('patrol_session_id').references('daily_patrol_sessions.session_id').onDelete('SET NULL');
table.foreign('project_id').references('projects.project_id').onDelete('SET NULL');
table.foreign('created_by').references('users.user_id');
table.foreign('updated_by').references('users.user_id');
});
console.log('✅ workplace_items 테이블 생성 완료');
// 물품 유형 코드 테이블 (선택적 확장용)
await knex.schema.createTable('item_types', (table) => {
table.string('type_code', 20).primary();
table.string('type_name', 50).notNullable().comment('유형명');
table.string('icon', 10).nullable().comment('아이콘 이모지');
table.string('color', 20).nullable().comment('표시 색상');
table.integer('display_order').defaultTo(0);
table.boolean('is_active').defaultTo(true);
});
await knex('item_types').insert([
{ type_code: 'container', type_name: '용기', icon: '📦', color: '#3b82f6', display_order: 1 },
{ type_code: 'plate', type_name: '플레이트', icon: '🔲', color: '#10b981', display_order: 2 },
{ type_code: 'material', type_name: '자재', icon: '🧱', color: '#f59e0b', display_order: 3 },
{ type_code: 'tool', type_name: '공구/장비', icon: '🔧', color: '#8b5cf6', display_order: 4 },
{ type_code: 'other', type_name: '기타', icon: '📍', color: '#6b7280', display_order: 5 },
]);
console.log('✅ item_types 테이블 생성 및 초기 데이터 완료');
console.log('✅ 모든 일일순회점검 시스템 테이블 생성 완료');
};
exports.down = async function(knex) {
console.log('⏳ 일일순회점검 시스템 테이블 제거 중...');
await knex.schema.dropTableIfExists('item_types');
await knex.schema.dropTableIfExists('workplace_items');
await knex.schema.dropTableIfExists('patrol_check_records');
await knex.schema.dropTableIfExists('daily_patrol_sessions');
await knex.schema.dropTableIfExists('patrol_checklist_items');
console.log('✅ 모든 일일순회점검 시스템 테이블 제거 완료');
};

View File

@@ -0,0 +1,13 @@
-- 설비 테이블 컬럼 추가 (phpMyAdmin용)
-- 현재 구조: equipment_id, factory_id, equipment_name, model, status, purchase_date, description, created_at, updated_at
-- 필요한 컬럼 추가
ALTER TABLE equipments ADD COLUMN equipment_code VARCHAR(50) NULL COMMENT '관리번호' AFTER equipment_id;
ALTER TABLE equipments ADD COLUMN specifications TEXT NULL COMMENT '규격' AFTER model;
ALTER TABLE equipments ADD COLUMN serial_number VARCHAR(100) NULL COMMENT '시리얼번호(S/N)' AFTER specifications;
ALTER TABLE equipments ADD COLUMN supplier VARCHAR(100) NULL COMMENT '구입처' AFTER purchase_date;
ALTER TABLE equipments ADD COLUMN purchase_price DECIMAL(15, 0) NULL COMMENT '구입가격' AFTER supplier;
ALTER TABLE equipments ADD COLUMN manufacturer VARCHAR(100) NULL COMMENT '제조사(메이커)' AFTER purchase_price;
-- equipment_code에 유니크 인덱스 추가
ALTER TABLE equipments ADD UNIQUE INDEX idx_equipment_code (equipment_code);

View File

@@ -0,0 +1,138 @@
-- 설비 관리 전체 설정 스크립트
-- 1. 새 컬럼 추가 (supplier, purchase_price)
-- 2. 65개 설비 데이터 입력
--
-- 실행: mysql -u [user] -p [database] < 20260204_equipment_full_setup.sql
-- ============================================
-- STEP 1: 새 컬럼 추가
-- ============================================
-- 컬럼이 이미 존재하는지 확인 후 추가
SET @dbname = DATABASE();
SET @tablename = 'equipments';
-- supplier 컬럼 추가
SELECT COUNT(*) INTO @col_exists
FROM information_schema.columns
WHERE table_schema = @dbname
AND table_name = @tablename
AND column_name = 'supplier';
SET @sql = IF(@col_exists = 0,
'ALTER TABLE equipments ADD COLUMN supplier VARCHAR(100) NULL COMMENT ''구입처'' AFTER manufacturer',
'SELECT ''supplier column already exists''');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
-- purchase_price 컬럼 추가
SELECT COUNT(*) INTO @col_exists
FROM information_schema.columns
WHERE table_schema = @dbname
AND table_name = @tablename
AND column_name = 'purchase_price';
SET @sql = IF(@col_exists = 0,
'ALTER TABLE equipments ADD COLUMN purchase_price DECIMAL(15, 0) NULL COMMENT ''구입가격'' AFTER supplier',
'SELECT ''purchase_price column already exists''');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SELECT '컬럼 추가 완료' AS status;
-- ============================================
-- STEP 2: 기존 데이터 삭제 (선택사항)
-- ============================================
-- 주의: 기존 데이터가 있으면 삭제됩니다
DELETE FROM equipments WHERE equipment_code LIKE 'TKP-%';
-- ============================================
-- STEP 3: 65개 설비 데이터 입력
-- ============================================
INSERT INTO equipments (equipment_code, equipment_name, model_name, specifications, serial_number, installation_date, supplier, purchase_price, manufacturer, status) VALUES
('TKP-001', 'AIR COMPRESSOR', 'AR10E', '7.5KW(10HP)', 'K603023Y', '2016-06-01', '지티씨', NULL, '경원', 'active'),
('TKP-002', 'TURN TABLE', 'YCT-200T', '220V', NULL, '2016-05-30', '형진종합공구', 3600000, '유체기계', 'active'),
('TKP-003', 'BAND SAW(中)', 'CY300W', '1500W*380V', '20150943', '2016-05-30', '형진종합공구', 4800000, '유림싸이겐', 'active'),
('TKP-004', 'BAND SAW(小)', 'XB-180WA', '180(VICE)', NULL, '2016-05-30', '형진종합공구', 2700000, '렉스', 'active'),
('TKP-005', 'BAND SAW(小)', 'XB-180WA', '180(VICE)', NULL, '2019-05-30', NULL, NULL, '렉스', 'active'),
('TKP-006', 'TIG용접기', 'DAESUNG-500DT', '500A', 'TEAG0168-001', '2016-05-30', '형진종합공구', 2200000, '대성용접기', 'active'),
('TKP-007', 'TIG용접기', 'DAESUNG-500DT', '500A', 'TEAG0168-002', '2016-05-30', '형진종합공구', 2200000, '대성용접기', 'active'),
('TKP-008', 'TIG용접기', 'DAESUNG-500DT', '500A', 'TEAG0168-003', '2016-05-30', '형진종합공구', 2200000, '대성용접기', 'active'),
('TKP-009', 'CO2용접기', 'COD-500A', '500A', '10880', '2016-05-30', '형진종합공구', 2000000, '대성용접기', 'active'),
('TKP-010', 'O2용접기', 'GSORK', '220V', NULL, '2016-05-30', '형진종합공구', 620000, '재현오토닉스', 'active'),
('TKP-011', 'PIPE BEVELLING MACHINE', 'S-200LT_MT(테이블포함)', '2" ~ 8"', 'KR-17030007', '2017-03-29', 'DCS ENG', 12000000, 'DCS ENG', 'active'),
('TKP-012', 'CO2용접기', '500MX', '220/380V,500A', NULL, '2017-08-02', '현대용접기', 1800000, '현대용접기', 'active'),
('TKP-013', '프라즈마', 'Perfect-150AP', '220/380/440V,140A', NULL, '2017-08-02', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-014', '터닝로라', 'JK-5-TR', '5TON/380V', NULL, '2017-09-08', '정일기공', 5700000, '정일기공', 'active'),
('TKP-015', '터닝로라', 'JK-5-TR', '5TON/380V', NULL, '2017-09-08', '정일기공', 5700000, '정일기공', 'active'),
('TKP-016', 'TIG용접기', 'Perfect-500PT', '500A/350A', 'TJAD017B-005', '2017-10-18', '현대용접기', 1600000, '퍼펙트대대', 'active'),
('TKP-017', 'TIG용접기', 'Perfect-500PT', '500A/350A', 'TJAD017B-006', '2017-10-18', '현대용접기', 1600000, '퍼펙트대대', 'active'),
('TKP-018', 'TIG용접기', 'Perfect-500PT', '500A/350A', 'TJAD017B-007', '2017-10-18', '현대용접기', 1600000, '퍼펙트대대', 'active'),
('TKP-019', '전해연마기', 'ONB-8000VP', '220V/MAX1200W', '8022701', '2018-03-13', '오토기전', 1450000, '메탈브라이트(오토기전)', 'active'),
('TKP-020', '지게차', '50DA-9F', '5000KGS', 'HHKHFV36JJ0000061', '2018-05-10', '현대지게차', 45000000, '현대지게차', 'active'),
('TKP-021', '조방', NULL, '3658*12190', NULL, '2018-05-11', '천우기계공업/삼덕금속', 14200000, '테크니컬코리아', 'active'),
('TKP-022', 'BAND SAW(大)', 'WBS-RC500AN', '3,300kgs / 7.88kw', 'BC50A18-005F001', '2018-05-31', '원공사', 36000000, '원공사', 'active'),
('TKP-023', 'AIR COMPRESSOR', 'AR20E', '0.95Mpa', 'AR020FE358', '2018-06-05', '경원기계', NULL, '경원기계', 'active'),
('TKP-024', 'TURN TABLE', 'YCT-200TA', '220V', NULL, '2018-06-12', '청운종합공구', 3245000, '유체기계', 'active'),
('TKP-025', 'TIG용접기', 'Perfect-500WT', '500A/AC DC', 'ADKAC017B-006', '2018-06-12', '현대용접기', 2400000, '퍼펙트대대', 'active'),
('TKP-026', 'TIG용접기', 'Perfect-500PT', '500A/DC', 'TAAI018B-002', '2018-06-12', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-027', 'TIG용접기', 'Perfect-500PT', '500A/DC', 'TAAA018B-009', '2018-06-12', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-028', 'TIG용접기', 'Perfect-500PT', '500A/DC', 'TAAA018B-001', '2018-06-12', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-029', 'ELECTRIC CHAIN HOIST', 'DSM-2S', '3Ph-60Hz-380V', 'K1806077', '2018-07-06', '청운종합공구', 2300000, '대산', 'active'),
('TKP-030', 'ELECTRIC CHAIN HOIST', 'DSM-2S', '3Ph-60Hz-380V', 'K1807028', '2018-07-10', '청운종합공구', 2300000, '대산', 'active'),
('TKP-031', 'ELECTRIC CHAIN HOIST', 'DSM-2S', '3Ph-60Hz-380V', 'K1807029', '2018-07-10', '청운종합공구', 2300000, '대산', 'active'),
('TKP-032', '만능탭 드릴링머신', 'SF-TDM32', '1.5KW', NULL, '2018-11-09', '㈜애스앤애프', 2927000, '㈜애스앤에프', 'active'),
('TKP-033', '지게차', '30D-9B', '2850KGS', 'HHKHHN51KK0000864', '2019-03-06', '현대지게차', 29400000, '현대지게차', 'active'),
('TKP-034', '갠츄리크레인', 'CRANE - DHG', '50/10Ton x SP20M x T/L50M x H15M', NULL, '2019-05-09', '유진산업기계', 249000000, '반도호이스트', 'active'),
('TKP-035', 'OVER HEAD CRANE', 'CRANE - DHO', '20Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 58000000, '반도호이스트', 'active'),
('TKP-036', 'OVER HEAD CRANE', 'CRANE - DHO', '20Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 58000000, '반도호이스트', 'active'),
('TKP-037', 'OVER HEAD CRANE', 'CRANE - DHO', '5Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 29000000, '반도호이스트', 'active'),
('TKP-038', 'OVER HEAD CRANE', 'CRANE - DHO', '5Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 29000000, '반도호이스트', 'active'),
('TKP-039', '고소작업대', NULL, '250 Kg', NULL, '2019-01-01', NULL, NULL, '㈜쓰리제이테크', 'active'),
('TKP-040', '고소작업대', NULL, '250 Kg', NULL, '2019-01-01', NULL, NULL, '㈜쓰리제이테크', 'active'),
('TKP-041', 'AIR CONDITIONER', '코끼리 냉장고', NULL, NULL, '2019-01-01', NULL, NULL, '㈜에스엔에프', 'active'),
('TKP-042', 'AIR CONDITIONER', NULL, NULL, NULL, '2019-01-01', NULL, NULL, '㈜에스엔에프', 'active'),
('TKP-043', 'AIR CONDITIONER', NULL, NULL, NULL, '2019-01-01', NULL, NULL, '㈜에스엔에프', 'active'),
('TKP-044', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-045', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-046', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-047', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-048', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-049', '자동용접기', NULL, NULL, NULL, '2019-01-01', 'Swage-Lok', 50000000, 'Swage-Lok', 'active'),
('TKP-050', 'Magnetic Drill', NULL, NULL, NULL, '2020-01-01', '청운종합공구', NULL, 'NITTO', 'active'),
('TKP-051', 'Magnetic Drill', NULL, NULL, NULL, '2020-01-01', '청운종합공구', NULL, 'Key-Yang', 'active'),
('TKP-052', 'Tube Bending M/C', NULL, NULL, NULL, '2020-01-01', NULL, NULL, 'REMS', 'active'),
('TKP-053', 'Unit Test Panel', NULL, NULL, NULL, '2021-01-01', NULL, NULL, NULL, 'active'),
('TKP-054', '고소작업대', NULL, '500 Kg', NULL, '2021-01-01', NULL, NULL, '㈜쓰리제이테크', 'active'),
('TKP-055', '용접봉 건조기', '주문제작', '박스형', NULL, '2022-05-04', '진원하이텍', 2300000, '진원하이텍', 'active'),
('TKP-056', 'C&T 가공기', 'MS-CTK469', NULL, NULL, '2022-07-20', 'Swage-Lok', 7347600, 'Swage-Lok', 'active'),
('TKP-057', '테이블형 튜브 벤딩기', 'MS-BTT-K', '1/2", 1/4"', NULL, '2022-06-03', 'Swage-Lok', 20000000, 'Swage-Lok', 'active'),
('TKP-058', '자동용접기 헤드', 'SWS-10H-D-15', '1/2"', NULL, '2022-06-03', 'Swage-Lok', 20000000, 'Swage-Lok', 'active'),
('TKP-059', '천장주행크레인', 'HC-75D-13105', '7.5ton', NULL, '2023-06-09', '에이치앤씨', 22800000, '에이치앤씨', 'active'),
('TKP-060', 'AED', 'CU-SP1 Plus', '저출력심장충격기', NULL, '2023-11-09', '제이메디', 1600000, '제이메디', 'active'),
('TKP-061', '베벨머신', 'S-150', 'O.D 20mm ~ 170mm', NULL, '2023-12-12', 'DCSENG', 16000000, 'DCSENG', 'active'),
('TKP-062', '피막제거기', 'CM4_OD_GC', '최대 폭 48mm, 최대 깊이 15mm, 6"이상', NULL, '2023-12-12', 'DCSENG', 2000000, 'DCSENG', 'active'),
('TKP-063', '피막제거기', 'S-CM4_OD', '최대 폭 48mm, 최대 깊이 15mm, 1" 이상', NULL, '2023-12-12', 'DCSENG', 1200000, 'DCSENG', 'active'),
('TKP-064', '텅스텐 가공기', 'S-TGR', '0.89kg, 0.25~3.2', NULL, '2023-12-12', 'DCSENG', 800000, 'DCSENG', 'active'),
('TKP-065', '전동대차', 'LPM15', '2.0 ton', NULL, '2023-12-20', '두산산업차량', 2800000, '두산산업차량', 'active');
-- ============================================
-- STEP 4: 결과 확인
-- ============================================
SELECT '===== 설비 데이터 입력 완료 =====' AS status;
SELECT COUNT(*) AS total_equipments FROM equipments;
SELECT
SUM(CASE WHEN purchase_price IS NOT NULL THEN purchase_price ELSE 0 END) AS total_purchase_value,
COUNT(CASE WHEN purchase_price IS NOT NULL THEN 1 END) AS equipments_with_price
FROM equipments;
-- 최신 10개 설비 확인
SELECT equipment_code, equipment_name, supplier,
FORMAT(purchase_price, 0) AS purchase_price_formatted,
manufacturer
FROM equipments
ORDER BY equipment_code DESC
LIMIT 10;

View File

@@ -0,0 +1,73 @@
-- 설비 데이터 입력 (실제 테이블 구조에 맞춤)
-- 먼저 20260204_equipment_add_columns.sql 실행 후 이 파일 실행
-- 기존 TKP 데이터 삭제
DELETE FROM equipments WHERE equipment_code LIKE 'TKP-%';
-- 65개 설비 데이터 입력
INSERT INTO equipments (equipment_code, equipment_name, model, specifications, serial_number, purchase_date, supplier, purchase_price, manufacturer, status) VALUES
('TKP-001', 'AIR COMPRESSOR', 'AR10E', '7.5KW(10HP)', 'K603023Y', '2016-06-01', '지티씨', NULL, '경원', 'active'),
('TKP-002', 'TURN TABLE', 'YCT-200T', '220V', NULL, '2016-05-30', '형진종합공구', 3600000, '유체기계', 'active'),
('TKP-003', 'BAND SAW(中)', 'CY300W', '1500W*380V', '20150943', '2016-05-30', '형진종합공구', 4800000, '유림싸이겐', 'active'),
('TKP-004', 'BAND SAW(小)', 'XB-180WA', '180(VICE)', NULL, '2016-05-30', '형진종합공구', 2700000, '렉스', 'active'),
('TKP-005', 'BAND SAW(小)', 'XB-180WA', '180(VICE)', NULL, '2019-05-30', NULL, NULL, '렉스', 'active'),
('TKP-006', 'TIG용접기', 'DAESUNG-500DT', '500A', 'TEAG0168-001', '2016-05-30', '형진종합공구', 2200000, '대성용접기', 'active'),
('TKP-007', 'TIG용접기', 'DAESUNG-500DT', '500A', 'TEAG0168-002', '2016-05-30', '형진종합공구', 2200000, '대성용접기', 'active'),
('TKP-008', 'TIG용접기', 'DAESUNG-500DT', '500A', 'TEAG0168-003', '2016-05-30', '형진종합공구', 2200000, '대성용접기', 'active'),
('TKP-009', 'CO2용접기', 'COD-500A', '500A', '10880', '2016-05-30', '형진종합공구', 2000000, '대성용접기', 'active'),
('TKP-010', 'O2용접기', 'GSORK', '220V', NULL, '2016-05-30', '형진종합공구', 620000, '재현오토닉스', 'active'),
('TKP-011', 'PIPE BEVELLING MACHINE', 'S-200LT_MT(테이블포함)', '2" ~ 8"', 'KR-17030007', '2017-03-29', 'DCS ENG', 12000000, 'DCS ENG', 'active'),
('TKP-012', 'CO2용접기', '500MX', '220/380V,500A', NULL, '2017-08-02', '현대용접기', 1800000, '현대용접기', 'active'),
('TKP-013', '프라즈마', 'Perfect-150AP', '220/380/440V,140A', NULL, '2017-08-02', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-014', '터닝로라', 'JK-5-TR', '5TON/380V', NULL, '2017-09-08', '정일기공', 5700000, '정일기공', 'active'),
('TKP-015', '터닝로라', 'JK-5-TR', '5TON/380V', NULL, '2017-09-08', '정일기공', 5700000, '정일기공', 'active'),
('TKP-016', 'TIG용접기', 'Perfect-500PT', '500A/350A', 'TJAD017B-005', '2017-10-18', '현대용접기', 1600000, '퍼펙트대대', 'active'),
('TKP-017', 'TIG용접기', 'Perfect-500PT', '500A/350A', 'TJAD017B-006', '2017-10-18', '현대용접기', 1600000, '퍼펙트대대', 'active'),
('TKP-018', 'TIG용접기', 'Perfect-500PT', '500A/350A', 'TJAD017B-007', '2017-10-18', '현대용접기', 1600000, '퍼펙트대대', 'active'),
('TKP-019', '전해연마기', 'ONB-8000VP', '220V/MAX1200W', '8022701', '2018-03-13', '오토기전', 1450000, '메탈브라이트(오토기전)', 'active'),
('TKP-020', '지게차', '50DA-9F', '5000KGS', 'HHKHFV36JJ0000061', '2018-05-10', '현대지게차', 45000000, '현대지게차', 'active'),
('TKP-021', '조방', NULL, '3658*12190', NULL, '2018-05-11', '천우기계공업/삼덕금속', 14200000, '테크니컬코리아', 'active'),
('TKP-022', 'BAND SAW(大)', 'WBS-RC500AN', '3,300kgs / 7.88kw', 'BC50A18-005F001', '2018-05-31', '원공사', 36000000, '원공사', 'active'),
('TKP-023', 'AIR COMPRESSOR', 'AR20E', '0.95Mpa', 'AR020FE358', '2018-06-05', '경원기계', NULL, '경원기계', 'active'),
('TKP-024', 'TURN TABLE', 'YCT-200TA', '220V', NULL, '2018-06-12', '청운종합공구', 3245000, '유체기계', 'active'),
('TKP-025', 'TIG용접기', 'Perfect-500WT', '500A/AC DC', 'ADKAC017B-006', '2018-06-12', '현대용접기', 2400000, '퍼펙트대대', 'active'),
('TKP-026', 'TIG용접기', 'Perfect-500PT', '500A/DC', 'TAAI018B-002', '2018-06-12', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-027', 'TIG용접기', 'Perfect-500PT', '500A/DC', 'TAAA018B-009', '2018-06-12', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-028', 'TIG용접기', 'Perfect-500PT', '500A/DC', 'TAAA018B-001', '2018-06-12', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-029', 'ELECTRIC CHAIN HOIST', 'DSM-2S', '3Ph-60Hz-380V', 'K1806077', '2018-07-06', '청운종합공구', 2300000, '대산', 'active'),
('TKP-030', 'ELECTRIC CHAIN HOIST', 'DSM-2S', '3Ph-60Hz-380V', 'K1807028', '2018-07-10', '청운종합공구', 2300000, '대산', 'active'),
('TKP-031', 'ELECTRIC CHAIN HOIST', 'DSM-2S', '3Ph-60Hz-380V', 'K1807029', '2018-07-10', '청운종합공구', 2300000, '대산', 'active'),
('TKP-032', '만능탭 드릴링머신', 'SF-TDM32', '1.5KW', NULL, '2018-11-09', '㈜애스앤애프', 2927000, '㈜애스앤에프', 'active'),
('TKP-033', '지게차', '30D-9B', '2850KGS', 'HHKHHN51KK0000864', '2019-03-06', '현대지게차', 29400000, '현대지게차', 'active'),
('TKP-034', '갠츄리크레인', 'CRANE - DHG', '50/10Ton x SP20M x T/L50M x H15M', NULL, '2019-05-09', '유진산업기계', 249000000, '반도호이스트', 'active'),
('TKP-035', 'OVER HEAD CRANE', 'CRANE - DHO', '20Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 58000000, '반도호이스트', 'active'),
('TKP-036', 'OVER HEAD CRANE', 'CRANE - DHO', '20Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 58000000, '반도호이스트', 'active'),
('TKP-037', 'OVER HEAD CRANE', 'CRANE - DHO', '5Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 29000000, '반도호이스트', 'active'),
('TKP-038', 'OVER HEAD CRANE', 'CRANE - DHO', '5Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 29000000, '반도호이스트', 'active'),
('TKP-039', '고소작업대', NULL, '250 Kg', NULL, '2019-01-01', NULL, NULL, '㈜쓰리제이테크', 'active'),
('TKP-040', '고소작업대', NULL, '250 Kg', NULL, '2019-01-01', NULL, NULL, '㈜쓰리제이테크', 'active'),
('TKP-041', 'AIR CONDITIONER', '코끼리 냉장고', NULL, NULL, '2019-01-01', NULL, NULL, '㈜에스엔에프', 'active'),
('TKP-042', 'AIR CONDITIONER', NULL, NULL, NULL, '2019-01-01', NULL, NULL, '㈜에스엔에프', 'active'),
('TKP-043', 'AIR CONDITIONER', NULL, NULL, NULL, '2019-01-01', NULL, NULL, '㈜에스엔에프', 'active'),
('TKP-044', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-045', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-046', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-047', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-048', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-049', '자동용접기', NULL, NULL, NULL, '2019-01-01', 'Swage-Lok', 50000000, 'Swage-Lok', 'active'),
('TKP-050', 'Magnetic Drill', NULL, NULL, NULL, '2020-01-01', '청운종합공구', NULL, 'NITTO', 'active'),
('TKP-051', 'Magnetic Drill', NULL, NULL, NULL, '2020-01-01', '청운종합공구', NULL, 'Key-Yang', 'active'),
('TKP-052', 'Tube Bending M/C', NULL, NULL, NULL, '2020-01-01', NULL, NULL, 'REMS', 'active'),
('TKP-053', 'Unit Test Panel', NULL, NULL, NULL, '2021-01-01', NULL, NULL, NULL, 'active'),
('TKP-054', '고소작업대', NULL, '500 Kg', NULL, '2021-01-01', NULL, NULL, '㈜쓰리제이테크', 'active'),
('TKP-055', '용접봉 건조기', '주문제작', '박스형', NULL, '2022-05-04', '진원하이텍', 2300000, '진원하이텍', 'active'),
('TKP-056', 'C&T 가공기', 'MS-CTK469', NULL, NULL, '2022-07-20', 'Swage-Lok', 7347600, 'Swage-Lok', 'active'),
('TKP-057', '테이블형 튜브 벤딩기', 'MS-BTT-K', '1/2", 1/4"', NULL, '2022-06-03', 'Swage-Lok', 20000000, 'Swage-Lok', 'active'),
('TKP-058', '자동용접기 헤드', 'SWS-10H-D-15', '1/2"', NULL, '2022-06-03', 'Swage-Lok', 20000000, 'Swage-Lok', 'active'),
('TKP-059', '천장주행크레인', 'HC-75D-13105', '7.5ton', NULL, '2023-06-09', '에이치앤씨', 22800000, '에이치앤씨', 'active'),
('TKP-060', 'AED', 'CU-SP1 Plus', '저출력심장충격기', NULL, '2023-11-09', '제이메디', 1600000, '제이메디', 'active'),
('TKP-061', '베벨머신', 'S-150', 'O.D 20mm ~ 170mm', NULL, '2023-12-12', 'DCSENG', 16000000, 'DCSENG', 'active'),
('TKP-062', '피막제거기', 'CM4_OD_GC', '최대 폭 48mm, 최대 깊이 15mm, 6"이상', NULL, '2023-12-12', 'DCSENG', 2000000, 'DCSENG', 'active'),
('TKP-063', '피막제거기', 'S-CM4_OD', '최대 폭 48mm, 최대 깊이 15mm, 1" 이상', NULL, '2023-12-12', 'DCSENG', 1200000, 'DCSENG', 'active'),
('TKP-064', '텅스텐 가공기', 'S-TGR', '0.89kg, 0.25~3.2', NULL, '2023-12-12', 'DCSENG', 800000, 'DCSENG', 'active'),
('TKP-065', '전동대차', 'LPM15', '2.0 ton', NULL, '2023-12-20', '두산산업차량', 2800000, '두산산업차량', 'active');

View File

@@ -0,0 +1,78 @@
-- 설비 관리 설정 (phpMyAdmin용 단순 버전)
-- phpMyAdmin에서 가져오기로 실행
-- ============================================
-- STEP 2: 기존 TKP 데이터 삭제
-- ============================================
DELETE FROM equipments WHERE equipment_code LIKE 'TKP-%';
-- ============================================
-- STEP 3: 65개 설비 데이터 입력
-- ============================================
INSERT INTO equipments (equipment_code, equipment_name, model_name, specifications, serial_number, installation_date, supplier, purchase_price, manufacturer, status) VALUES
('TKP-001', 'AIR COMPRESSOR', 'AR10E', '7.5KW(10HP)', 'K603023Y', '2016-06-01', '지티씨', NULL, '경원', 'active'),
('TKP-002', 'TURN TABLE', 'YCT-200T', '220V', NULL, '2016-05-30', '형진종합공구', 3600000, '유체기계', 'active'),
('TKP-003', 'BAND SAW(中)', 'CY300W', '1500W*380V', '20150943', '2016-05-30', '형진종합공구', 4800000, '유림싸이겐', 'active'),
('TKP-004', 'BAND SAW(小)', 'XB-180WA', '180(VICE)', NULL, '2016-05-30', '형진종합공구', 2700000, '렉스', 'active'),
('TKP-005', 'BAND SAW(小)', 'XB-180WA', '180(VICE)', NULL, '2019-05-30', NULL, NULL, '렉스', 'active'),
('TKP-006', 'TIG용접기', 'DAESUNG-500DT', '500A', 'TEAG0168-001', '2016-05-30', '형진종합공구', 2200000, '대성용접기', 'active'),
('TKP-007', 'TIG용접기', 'DAESUNG-500DT', '500A', 'TEAG0168-002', '2016-05-30', '형진종합공구', 2200000, '대성용접기', 'active'),
('TKP-008', 'TIG용접기', 'DAESUNG-500DT', '500A', 'TEAG0168-003', '2016-05-30', '형진종합공구', 2200000, '대성용접기', 'active'),
('TKP-009', 'CO2용접기', 'COD-500A', '500A', '10880', '2016-05-30', '형진종합공구', 2000000, '대성용접기', 'active'),
('TKP-010', 'O2용접기', 'GSORK', '220V', NULL, '2016-05-30', '형진종합공구', 620000, '재현오토닉스', 'active'),
('TKP-011', 'PIPE BEVELLING MACHINE', 'S-200LT_MT(테이블포함)', '2" ~ 8"', 'KR-17030007', '2017-03-29', 'DCS ENG', 12000000, 'DCS ENG', 'active'),
('TKP-012', 'CO2용접기', '500MX', '220/380V,500A', NULL, '2017-08-02', '현대용접기', 1800000, '현대용접기', 'active'),
('TKP-013', '프라즈마', 'Perfect-150AP', '220/380/440V,140A', NULL, '2017-08-02', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-014', '터닝로라', 'JK-5-TR', '5TON/380V', NULL, '2017-09-08', '정일기공', 5700000, '정일기공', 'active'),
('TKP-015', '터닝로라', 'JK-5-TR', '5TON/380V', NULL, '2017-09-08', '정일기공', 5700000, '정일기공', 'active'),
('TKP-016', 'TIG용접기', 'Perfect-500PT', '500A/350A', 'TJAD017B-005', '2017-10-18', '현대용접기', 1600000, '퍼펙트대대', 'active'),
('TKP-017', 'TIG용접기', 'Perfect-500PT', '500A/350A', 'TJAD017B-006', '2017-10-18', '현대용접기', 1600000, '퍼펙트대대', 'active'),
('TKP-018', 'TIG용접기', 'Perfect-500PT', '500A/350A', 'TJAD017B-007', '2017-10-18', '현대용접기', 1600000, '퍼펙트대대', 'active'),
('TKP-019', '전해연마기', 'ONB-8000VP', '220V/MAX1200W', '8022701', '2018-03-13', '오토기전', 1450000, '메탈브라이트(오토기전)', 'active'),
('TKP-020', '지게차', '50DA-9F', '5000KGS', 'HHKHFV36JJ0000061', '2018-05-10', '현대지게차', 45000000, '현대지게차', 'active'),
('TKP-021', '조방', NULL, '3658*12190', NULL, '2018-05-11', '천우기계공업/삼덕금속', 14200000, '테크니컬코리아', 'active'),
('TKP-022', 'BAND SAW(大)', 'WBS-RC500AN', '3,300kgs / 7.88kw', 'BC50A18-005F001', '2018-05-31', '원공사', 36000000, '원공사', 'active'),
('TKP-023', 'AIR COMPRESSOR', 'AR20E', '0.95Mpa', 'AR020FE358', '2018-06-05', '경원기계', NULL, '경원기계', 'active'),
('TKP-024', 'TURN TABLE', 'YCT-200TA', '220V', NULL, '2018-06-12', '청운종합공구', 3245000, '유체기계', 'active'),
('TKP-025', 'TIG용접기', 'Perfect-500WT', '500A/AC DC', 'ADKAC017B-006', '2018-06-12', '현대용접기', 2400000, '퍼펙트대대', 'active'),
('TKP-026', 'TIG용접기', 'Perfect-500PT', '500A/DC', 'TAAI018B-002', '2018-06-12', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-027', 'TIG용접기', 'Perfect-500PT', '500A/DC', 'TAAA018B-009', '2018-06-12', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-028', 'TIG용접기', 'Perfect-500PT', '500A/DC', 'TAAA018B-001', '2018-06-12', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-029', 'ELECTRIC CHAIN HOIST', 'DSM-2S', '3Ph-60Hz-380V', 'K1806077', '2018-07-06', '청운종합공구', 2300000, '대산', 'active'),
('TKP-030', 'ELECTRIC CHAIN HOIST', 'DSM-2S', '3Ph-60Hz-380V', 'K1807028', '2018-07-10', '청운종합공구', 2300000, '대산', 'active'),
('TKP-031', 'ELECTRIC CHAIN HOIST', 'DSM-2S', '3Ph-60Hz-380V', 'K1807029', '2018-07-10', '청운종합공구', 2300000, '대산', 'active'),
('TKP-032', '만능탭 드릴링머신', 'SF-TDM32', '1.5KW', NULL, '2018-11-09', '㈜애스앤애프', 2927000, '㈜애스앤에프', 'active'),
('TKP-033', '지게차', '30D-9B', '2850KGS', 'HHKHHN51KK0000864', '2019-03-06', '현대지게차', 29400000, '현대지게차', 'active'),
('TKP-034', '갠츄리크레인', 'CRANE - DHG', '50/10Ton x SP20M x T/L50M x H15M', NULL, '2019-05-09', '유진산업기계', 249000000, '반도호이스트', 'active'),
('TKP-035', 'OVER HEAD CRANE', 'CRANE - DHO', '20Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 58000000, '반도호이스트', 'active'),
('TKP-036', 'OVER HEAD CRANE', 'CRANE - DHO', '20Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 58000000, '반도호이스트', 'active'),
('TKP-037', 'OVER HEAD CRANE', 'CRANE - DHO', '5Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 29000000, '반도호이스트', 'active'),
('TKP-038', 'OVER HEAD CRANE', 'CRANE - DHO', '5Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 29000000, '반도호이스트', 'active'),
('TKP-039', '고소작업대', NULL, '250 Kg', NULL, '2019-01-01', NULL, NULL, '㈜쓰리제이테크', 'active'),
('TKP-040', '고소작업대', NULL, '250 Kg', NULL, '2019-01-01', NULL, NULL, '㈜쓰리제이테크', 'active'),
('TKP-041', 'AIR CONDITIONER', '코끼리 냉장고', NULL, NULL, '2019-01-01', NULL, NULL, '㈜에스엔에프', 'active'),
('TKP-042', 'AIR CONDITIONER', NULL, NULL, NULL, '2019-01-01', NULL, NULL, '㈜에스엔에프', 'active'),
('TKP-043', 'AIR CONDITIONER', NULL, NULL, NULL, '2019-01-01', NULL, NULL, '㈜에스엔에프', 'active'),
('TKP-044', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-045', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-046', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-047', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-048', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-049', '자동용접기', NULL, NULL, NULL, '2019-01-01', 'Swage-Lok', 50000000, 'Swage-Lok', 'active'),
('TKP-050', 'Magnetic Drill', NULL, NULL, NULL, '2020-01-01', '청운종합공구', NULL, 'NITTO', 'active'),
('TKP-051', 'Magnetic Drill', NULL, NULL, NULL, '2020-01-01', '청운종합공구', NULL, 'Key-Yang', 'active'),
('TKP-052', 'Tube Bending M/C', NULL, NULL, NULL, '2020-01-01', NULL, NULL, 'REMS', 'active'),
('TKP-053', 'Unit Test Panel', NULL, NULL, NULL, '2021-01-01', NULL, NULL, NULL, 'active'),
('TKP-054', '고소작업대', NULL, '500 Kg', NULL, '2021-01-01', NULL, NULL, '㈜쓰리제이테크', 'active'),
('TKP-055', '용접봉 건조기', '주문제작', '박스형', NULL, '2022-05-04', '진원하이텍', 2300000, '진원하이텍', 'active'),
('TKP-056', 'C&T 가공기', 'MS-CTK469', NULL, NULL, '2022-07-20', 'Swage-Lok', 7347600, 'Swage-Lok', 'active'),
('TKP-057', '테이블형 튜브 벤딩기', 'MS-BTT-K', '1/2", 1/4"', NULL, '2022-06-03', 'Swage-Lok', 20000000, 'Swage-Lok', 'active'),
('TKP-058', '자동용접기 헤드', 'SWS-10H-D-15', '1/2"', NULL, '2022-06-03', 'Swage-Lok', 20000000, 'Swage-Lok', 'active'),
('TKP-059', '천장주행크레인', 'HC-75D-13105', '7.5ton', NULL, '2023-06-09', '에이치앤씨', 22800000, '에이치앤씨', 'active'),
('TKP-060', 'AED', 'CU-SP1 Plus', '저출력심장충격기', NULL, '2023-11-09', '제이메디', 1600000, '제이메디', 'active'),
('TKP-061', '베벨머신', 'S-150', 'O.D 20mm ~ 170mm', NULL, '2023-12-12', 'DCSENG', 16000000, 'DCSENG', 'active'),
('TKP-062', '피막제거기', 'CM4_OD_GC', '최대 폭 48mm, 최대 깊이 15mm, 6"이상', NULL, '2023-12-12', 'DCSENG', 2000000, 'DCSENG', 'active'),
('TKP-063', '피막제거기', 'S-CM4_OD', '최대 폭 48mm, 최대 깊이 15mm, 1" 이상', NULL, '2023-12-12', 'DCSENG', 1200000, 'DCSENG', 'active'),
('TKP-064', '텅스텐 가공기', 'S-TGR', '0.89kg, 0.25~3.2', NULL, '2023-12-12', 'DCSENG', 800000, 'DCSENG', 'active'),
('TKP-065', '전동대차', 'LPM15', '2.0 ton', NULL, '2023-12-20', '두산산업차량', 2800000, '두산산업차량', 'active');

View File

@@ -0,0 +1,13 @@
-- 설비 테이블에 구입처 및 구입가격 컬럼 추가
-- 실행: mysql -u [user] -p [database] < add_equipment_purchase_fields.sql
-- 컬럼 추가
ALTER TABLE equipments
ADD COLUMN supplier VARCHAR(100) NULL COMMENT '구입처' AFTER manufacturer,
ADD COLUMN purchase_price DECIMAL(15, 0) NULL COMMENT '구입가격' AFTER supplier;
-- 확인
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_COMMENT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'equipments'
AND COLUMN_NAME IN ('supplier', 'purchase_price');

View File

@@ -0,0 +1,77 @@
-- 설비 데이터 입력
-- 실행 전 먼저 add_equipment_purchase_fields.sql 실행 필요
-- 실행: mysql -u [user] -p [database] < insert_equipment_data.sql
-- 기존 데이터 삭제 (필요시 주석 해제)
-- TRUNCATE TABLE equipments;
INSERT INTO equipments (equipment_code, equipment_name, model_name, specifications, serial_number, installation_date, supplier, purchase_price, manufacturer, status) VALUES
('TKP-001', 'AIR COMPRESSOR', 'AR10E', '7.5KW(10HP)', 'K603023Y', '2016-06-01', '지티씨', NULL, '경원', 'active'),
('TKP-002', 'TURN TABLE', 'YCT-200T', '220V', NULL, '2016-05-30', '형진종합공구', 3600000, '유체기계', 'active'),
('TKP-003', 'BAND SAW(中)', 'CY300W', '1500W*380V', '20150943', '2016-05-30', '형진종합공구', 4800000, '유림싸이겐', 'active'),
('TKP-004', 'BAND SAW(小)', 'XB-180WA', '180(VICE)', NULL, '2016-05-30', '형진종합공구', 2700000, '렉스', 'active'),
('TKP-005', 'BAND SAW(小)', 'XB-180WA', '180(VICE)', NULL, '2019-05-30', NULL, NULL, '렉스', 'active'),
('TKP-006', 'TIG용접기', 'DAESUNG-500DT', '500A', 'TEAG0168-001', '2016-05-30', '형진종합공구', 2200000, '대성용접기', 'active'),
('TKP-007', 'TIG용접기', 'DAESUNG-500DT', '500A', 'TEAG0168-002', '2016-05-30', '형진종합공구', 2200000, '대성용접기', 'active'),
('TKP-008', 'TIG용접기', 'DAESUNG-500DT', '500A', 'TEAG0168-003', '2016-05-30', '형진종합공구', 2200000, '대성용접기', 'active'),
('TKP-009', 'CO2용접기', 'COD-500A', '500A', '10880', '2016-05-30', '형진종합공구', 2000000, '대성용접기', 'active'),
('TKP-010', 'O2용접기', 'GSORK', '220V', NULL, '2016-05-30', '형진종합공구', 620000, '재현오토닉스', 'active'),
('TKP-011', 'PIPE BEVELLING MACHINE', 'S-200LT_MT(테이블포함)', '2" ~ 8"', 'KR-17030007', '2017-03-29', 'DCS ENG', 12000000, 'DCS ENG', 'active'),
('TKP-012', 'CO2용접기', '500MX', '220/380V,500A', NULL, '2017-08-02', '현대용접기', 1800000, '현대용접기', 'active'),
('TKP-013', '프라즈마', 'Perfect-150AP', '220/380/440V,140A', NULL, '2017-08-02', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-014', '터닝로라', 'JK-5-TR', '5TON/380V', NULL, '2017-09-08', '정일기공', 5700000, '정일기공', 'active'),
('TKP-015', '터닝로라', 'JK-5-TR', '5TON/380V', NULL, '2017-09-08', '정일기공', 5700000, '정일기공', 'active'),
('TKP-016', 'TIG용접기', 'Perfect-500PT', '500A/350A', 'TJAD017B-005', '2017-10-18', '현대용접기', 1600000, '퍼펙트대대', 'active'),
('TKP-017', 'TIG용접기', 'Perfect-500PT', '500A/350A', 'TJAD017B-006', '2017-10-18', '현대용접기', 1600000, '퍼펙트대대', 'active'),
('TKP-018', 'TIG용접기', 'Perfect-500PT', '500A/350A', 'TJAD017B-007', '2017-10-18', '현대용접기', 1600000, '퍼펙트대대', 'active'),
('TKP-019', '전해연마기', 'ONB-8000VP', '220V/MAX1200W', '8022701', '2018-03-13', '오토기전', 1450000, '메탈브라이트(오토기전)', 'active'),
('TKP-020', '지게차', '50DA-9F', '5000KGS', 'HHKHFV36JJ0000061', '2018-05-10', '현대지게차', 45000000, '현대지게차', 'active'),
('TKP-021', '조방', NULL, '3658*12190', NULL, '2018-05-11', '천우기계공업/삼덕금속', 14200000, '테크니컬코리아', 'active'),
('TKP-022', 'BAND SAW(大)', 'WBS-RC500AN', '3,300kgs / 7.88kw', 'BC50A18-005F001', '2018-05-31', '원공사', 36000000, '원공사', 'active'),
('TKP-023', 'AIR COMPRESSOR', 'AR20E', '0.95Mpa', 'AR020FE358', '2018-06-05', '경원기계', NULL, '경원기계', 'active'),
('TKP-024', 'TURN TABLE', 'YCT-200TA', '220V', NULL, '2018-06-12', '청운종합공구', 3245000, '유체기계', 'active'),
('TKP-025', 'TIG용접기', 'Perfect-500WT', '500A/AC DC', 'ADKAC017B-006', '2018-06-12', '현대용접기', 2400000, '퍼펙트대대', 'active'),
('TKP-026', 'TIG용접기', 'Perfect-500PT', '500A/DC', 'TAAI018B-002', '2018-06-12', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-027', 'TIG용접기', 'Perfect-500PT', '500A/DC', 'TAAA018B-009', '2018-06-12', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-028', 'TIG용접기', 'Perfect-500PT', '500A/DC', 'TAAA018B-001', '2018-06-12', '현대용접기', 1900000, '퍼펙트대대', 'active'),
('TKP-029', 'ELECTRIC CHAIN HOIST', 'DSM-2S', '3Ph-60Hz-380V', 'K1806077', '2018-07-06', '청운종합공구', 2300000, '대산', 'active'),
('TKP-030', 'ELECTRIC CHAIN HOIST', 'DSM-2S', '3Ph-60Hz-380V', 'K1807028', '2018-07-10', '청운종합공구', 2300000, '대산', 'active'),
('TKP-031', 'ELECTRIC CHAIN HOIST', 'DSM-2S', '3Ph-60Hz-380V', 'K1807029', '2018-07-10', '청운종합공구', 2300000, '대산', 'active'),
('TKP-032', '만능탭 드릴링머신', 'SF-TDM32', '1.5KW', NULL, '2018-11-09', '㈜애스앤애프', 2927000, '㈜애스앤에프', 'active'),
('TKP-033', '지게차', '30D-9B', '2850KGS', 'HHKHHN51KK0000864', '2019-03-06', '현대지게차', 29400000, '현대지게차', 'active'),
('TKP-034', '갠츄리크레인', 'CRANE - DHG', '50/10Ton x SP20M x T/L50M x H15M', NULL, '2019-05-09', '유진산업기계', 249000000, '반도호이스트', 'active'),
('TKP-035', 'OVER HEAD CRANE', 'CRANE - DHO', '20Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 58000000, '반도호이스트', 'active'),
('TKP-036', 'OVER HEAD CRANE', 'CRANE - DHO', '20Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 58000000, '반도호이스트', 'active'),
('TKP-037', 'OVER HEAD CRANE', 'CRANE - DHO', '5Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 29000000, '반도호이스트', 'active'),
('TKP-038', 'OVER HEAD CRANE', 'CRANE - DHO', '5Ton x SP24.0M x T/L67M x H11M', NULL, '2019-05-09', '유진산업기계', 29000000, '반도호이스트', 'active'),
('TKP-039', '고소작업대', NULL, '250 Kg', NULL, '2019-01-01', NULL, NULL, '㈜쓰리제이테크', 'active'),
('TKP-040', '고소작업대', NULL, '250 Kg', NULL, '2019-01-01', NULL, NULL, '㈜쓰리제이테크', 'active'),
('TKP-041', 'AIR CONDITIONER', '코끼리 냉장고', NULL, NULL, '2019-01-01', NULL, NULL, '㈜에스엔에프', 'active'),
('TKP-042', 'AIR CONDITIONER', NULL, NULL, NULL, '2019-01-01', NULL, NULL, '㈜에스엔에프', 'active'),
('TKP-043', 'AIR CONDITIONER', NULL, NULL, NULL, '2019-01-01', NULL, NULL, '㈜에스엔에프', 'active'),
('TKP-044', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-045', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-046', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-047', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-048', '용접흄집진기', NULL, '5 HP / 60 m3/Min', NULL, '2019-01-01', NULL, NULL, NULL, 'active'),
('TKP-049', '자동용접기', NULL, NULL, NULL, '2019-01-01', 'Swage-Lok', 50000000, 'Swage-Lok', 'active'),
('TKP-050', 'Magnetic Drill', NULL, NULL, NULL, '2020-01-01', '청운종합공구', NULL, 'NITTO', 'active'),
('TKP-051', 'Magnetic Drill', NULL, NULL, NULL, '2020-01-01', '청운종합공구', NULL, 'Key-Yang', 'active'),
('TKP-052', 'Tube Bending M/C', NULL, NULL, NULL, '2020-01-01', NULL, NULL, 'REMS', 'active'),
('TKP-053', 'Unit Test Panel', NULL, NULL, NULL, '2021-01-01', NULL, NULL, NULL, 'active'),
('TKP-054', '고소작업대', NULL, '500 Kg', NULL, '2021-01-01', NULL, NULL, '㈜쓰리제이테크', 'active'),
('TKP-055', '용접봉 건조기', '주문제작', '박스형', NULL, '2022-05-04', '진원하이텍', 2300000, '진원하이텍', 'active'),
('TKP-056', 'C&T 가공기', 'MS-CTK469', NULL, NULL, '2022-07-20', 'Swage-Lok', 7347600, 'Swage-Lok', 'active'),
('TKP-057', '테이블형 튜브 벤딩기', 'MS-BTT-K', '1/2", 1/4"', NULL, '2022-06-03', 'Swage-Lok', 20000000, 'Swage-Lok', 'active'),
('TKP-058', '자동용접기 헤드', 'SWS-10H-D-15', '1/2"', NULL, '2022-06-03', 'Swage-Lok', 20000000, 'Swage-Lok', 'active'),
('TKP-059', '천장주행크레인', 'HC-75D-13105', '7.5ton', NULL, '2023-06-09', '에이치앤씨', 22800000, '에이치앤씨', 'active'),
('TKP-060', 'AED', 'CU-SP1 Plus', '저출력심장충격기', NULL, '2023-11-09', '제이메디', 1600000, '제이메디', 'active'),
('TKP-061', '베벨머신', 'S-150', 'O.D 20mm ~ 170mm', NULL, '2023-12-12', 'DCSENG', 16000000, 'DCSENG', 'active'),
('TKP-062', '피막제거기', 'CM4_OD_GC', '최대 폭 48mm, 최대 깊이 15mm, 6"이상', NULL, '2023-12-12', 'DCSENG', 2000000, 'DCSENG', 'active'),
('TKP-063', '피막제거기', 'S-CM4_OD', '최대 폭 48mm, 최대 깊이 15mm, 1" 이상', NULL, '2023-12-12', 'DCSENG', 1200000, 'DCSENG', 'active'),
('TKP-064', '텅스텐 가공기', 'S-TGR', '0.89kg, 0.25~3.2', NULL, '2023-12-12', 'DCSENG', 800000, 'DCSENG', 'active'),
('TKP-065', '전동대차', 'LPM15', '2.0 ton', NULL, '2023-12-20', '두산산업차량', 2800000, '두산산업차량', 'active');
-- 입력 확인
SELECT COUNT(*) AS total_count FROM equipments;
SELECT equipment_code, equipment_name, supplier, purchase_price, manufacturer FROM equipments ORDER BY equipment_code LIMIT 10;

View File

@@ -0,0 +1,34 @@
-- =====================================================
-- daily_attendance_records 테이블 운영 DB 동기화
-- 실행 전 백업 권장
-- =====================================================
-- 1. is_present 컬럼 추가 (출근 체크용)
ALTER TABLE `daily_attendance_records`
ADD COLUMN IF NOT EXISTS `is_present` TINYINT(1) DEFAULT 1 COMMENT '출근 여부' AFTER `is_overtime_approved`;
-- 기존 데이터는 모두 출근으로 설정
UPDATE `daily_attendance_records` SET `is_present` = 1 WHERE `is_present` IS NULL;
-- 2. created_by 컬럼 추가 (등록자)
ALTER TABLE `daily_attendance_records`
ADD COLUMN IF NOT EXISTS `created_by` INT NULL COMMENT '등록자 user_id' AFTER `is_present`;
-- 기존 데이터는 시스템(1)으로 설정
UPDATE `daily_attendance_records` SET `created_by` = 1 WHERE `created_by` IS NULL;
-- 3. check_in_time, check_out_time 컬럼 추가 (선택사항)
ALTER TABLE `daily_attendance_records`
ADD COLUMN IF NOT EXISTS `check_in_time` TIME NULL COMMENT '출근 시간' AFTER `vacation_type_id`;
ALTER TABLE `daily_attendance_records`
ADD COLUMN IF NOT EXISTS `check_out_time` TIME NULL COMMENT '퇴근 시간' AFTER `check_in_time`;
-- 4. notes 컬럼 추가
ALTER TABLE `daily_attendance_records`
ADD COLUMN IF NOT EXISTS `notes` TEXT NULL COMMENT '비고' AFTER `is_overtime_approved`;
-- =====================================================
-- 확인용 쿼리
-- =====================================================
-- DESCRIBE `daily_attendance_records`;

View File

@@ -13,7 +13,7 @@ class AttendanceModel {
wat.type_code as attendance_type_code,
vt.type_name as vacation_type_name,
vt.type_code as vacation_type_code,
vt.hours_deduction as vacation_hours
vt.deduct_days as vacation_days
FROM daily_attendance_records dar
LEFT JOIN workers w ON dar.worker_id = w.worker_id
LEFT JOIN work_attendance_types wat ON dar.attendance_type_id = wat.id
@@ -315,7 +315,8 @@ class AttendanceModel {
`, [workerId, date]);
const currentHours = parseFloat(workHours[0].total_hours);
const vacationHours = parseFloat(vacationTypeInfo.hours_deduction);
// deduct_days를 시간으로 변환 (1일 = 8시간)
const vacationHours = parseFloat(vacationTypeInfo.deduct_days) * 8;
const totalHours = currentHours + vacationHours;
// 근로 유형 결정

View File

@@ -0,0 +1,120 @@
// models/departmentModel.js
const { getDb } = require('../dbPool');
const departmentModel = {
// 모든 부서 조회 (계층 구조 포함)
async getAll() {
const db = await getDb();
const [rows] = await db.query(`
SELECT d.*,
p.department_name as parent_name,
(SELECT COUNT(*) FROM workers w WHERE w.department_id = d.department_id AND w.status = 'active') as worker_count
FROM departments d
LEFT JOIN departments p ON d.parent_id = p.department_id
ORDER BY d.display_order, d.department_name
`);
return rows;
},
// 활성 부서만 조회
async getActive() {
const db = await getDb();
const [rows] = await db.query(`
SELECT d.*,
p.department_name as parent_name,
(SELECT COUNT(*) FROM workers w WHERE w.department_id = d.department_id AND w.status = 'active') as worker_count
FROM departments d
LEFT JOIN departments p ON d.parent_id = p.department_id
WHERE d.is_active = TRUE
ORDER BY d.display_order, d.department_name
`);
return rows;
},
// 부서 ID로 조회
async getById(departmentId) {
const db = await getDb();
const [rows] = await db.query(`
SELECT d.*,
p.department_name as parent_name
FROM departments d
LEFT JOIN departments p ON d.parent_id = p.department_id
WHERE d.department_id = ?
`, [departmentId]);
return rows[0];
},
// 부서 생성
async create(data) {
const db = await getDb();
const { department_name, parent_id, description, is_active, display_order } = data;
const [result] = await db.query(`
INSERT INTO departments (department_name, parent_id, description, is_active, display_order)
VALUES (?, ?, ?, ?, ?)
`, [department_name, parent_id || null, description || null, is_active !== false, display_order || 0]);
return result.insertId;
},
// 부서 수정
async update(departmentId, data) {
const db = await getDb();
const { department_name, parent_id, description, is_active, display_order } = data;
const [result] = await db.query(`
UPDATE departments
SET department_name = ?, parent_id = ?, description = ?, is_active = ?, display_order = ?
WHERE department_id = ?
`, [department_name, parent_id || null, description || null, is_active, display_order || 0, departmentId]);
return result.affectedRows > 0;
},
// 부서 삭제
async delete(departmentId) {
const db = await getDb();
// 하위 부서가 있는지 확인
const [children] = await db.query('SELECT COUNT(*) as count FROM departments WHERE parent_id = ?', [departmentId]);
if (children[0].count > 0) {
throw new Error('하위 부서가 있어 삭제할 수 없습니다.');
}
// 소속 작업자가 있는지 확인
const [workers] = await db.query('SELECT COUNT(*) as count FROM workers WHERE department_id = ?', [departmentId]);
if (workers[0].count > 0) {
throw new Error('소속 작업자가 있어 삭제할 수 없습니다. 먼저 작업자를 다른 부서로 이동하세요.');
}
const [result] = await db.query('DELETE FROM departments WHERE department_id = ?', [departmentId]);
return result.affectedRows > 0;
},
// 부서별 작업자 조회
async getWorkersByDepartment(departmentId) {
const db = await getDb();
const [rows] = await db.query(`
SELECT w.*, d.department_name, u.user_id, u.username
FROM workers w
LEFT JOIN departments d ON w.department_id = d.department_id
LEFT JOIN users u ON u.worker_id = w.worker_id
WHERE w.department_id = ?
ORDER BY w.worker_name
`, [departmentId]);
return rows;
},
// 작업자 부서 변경
async moveWorker(workerId, departmentId) {
const db = await getDb();
const [result] = await db.query(`
UPDATE workers SET department_id = ? WHERE worker_id = ?
`, [departmentId, workerId]);
return result.affectedRows > 0;
},
// 여러 작업자 부서 일괄 변경
async moveWorkers(workerIds, departmentId) {
const db = await getDb();
const [result] = await db.query(`
UPDATE workers SET department_id = ? WHERE worker_id IN (?)
`, [departmentId, workerIds]);
return result.affectedRows;
}
};
module.exports = departmentModel;

View File

@@ -9,10 +9,10 @@ const EquipmentModel = {
const query = `
INSERT INTO equipments (
equipment_code, equipment_name, equipment_type, model_name,
manufacturer, installation_date, serial_number, specifications,
manufacturer, supplier, purchase_price, installation_date, serial_number, specifications,
status, notes, workplace_id, map_x_percent, map_y_percent,
map_width_percent, map_height_percent
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`;
const values = [
@@ -21,6 +21,8 @@ const EquipmentModel = {
equipmentData.equipment_type || null,
equipmentData.model_name || null,
equipmentData.manufacturer || null,
equipmentData.supplier || null,
equipmentData.purchase_price || null,
equipmentData.installation_date || null,
equipmentData.serial_number || null,
equipmentData.specifications || null,
@@ -168,6 +170,8 @@ const EquipmentModel = {
equipment_type = ?,
model_name = ?,
manufacturer = ?,
supplier = ?,
purchase_price = ?,
installation_date = ?,
serial_number = ?,
specifications = ?,
@@ -188,6 +192,8 @@ const EquipmentModel = {
equipmentData.equipment_type || null,
equipmentData.model_name || null,
equipmentData.manufacturer || null,
equipmentData.supplier || null,
equipmentData.purchase_price || null,
equipmentData.installation_date || null,
equipmentData.serial_number || null,
equipmentData.specifications || null,
@@ -211,11 +217,24 @@ const EquipmentModel = {
}
},
// UPDATE MAP POSITION - 지도상 위치 업데이트
// UPDATE MAP POSITION - 지도상 위치 업데이트 (선택적으로 workplace_id도 업데이트)
updateMapPosition: async (equipmentId, positionData, callback) => {
try {
const db = await getDb();
const query = `
// workplace_id가 포함된 경우 함께 업데이트
const hasWorkplaceId = positionData.workplace_id !== undefined;
const query = hasWorkplaceId ? `
UPDATE equipments SET
workplace_id = ?,
map_x_percent = ?,
map_y_percent = ?,
map_width_percent = ?,
map_height_percent = ?,
updated_at = NOW()
WHERE equipment_id = ?
` : `
UPDATE equipments SET
map_x_percent = ?,
map_y_percent = ?,
@@ -225,7 +244,14 @@ const EquipmentModel = {
WHERE equipment_id = ?
`;
const values = [
const values = hasWorkplaceId ? [
positionData.workplace_id,
positionData.map_x_percent,
positionData.map_y_percent,
positionData.map_width_percent,
positionData.map_height_percent,
equipmentId
] : [
positionData.map_x_percent,
positionData.map_y_percent,
positionData.map_width_percent,
@@ -294,6 +320,39 @@ const EquipmentModel = {
} catch (error) {
callback(error);
}
},
// GET NEXT EQUIPMENT CODE - 다음 관리번호 자동 생성 (TKP-001 형식)
getNextEquipmentCode: async (prefix = 'TKP', callback) => {
try {
const db = await getDb();
// 해당 접두사로 시작하는 가장 큰 번호 찾기
const query = `
SELECT equipment_code
FROM equipments
WHERE equipment_code LIKE ?
ORDER BY equipment_code DESC
LIMIT 1
`;
const [rows] = await db.query(query, [`${prefix}-%`]);
let nextNumber = 1;
if (rows.length > 0) {
// TKP-001 형식에서 숫자 부분 추출
const lastCode = rows[0].equipment_code;
const match = lastCode.match(new RegExp(`^${prefix}-(\\d+)$`));
if (match) {
nextNumber = parseInt(match[1], 10) + 1;
}
}
// 3자리로 패딩 (001, 002, ...)
const nextCode = `${prefix}-${String(nextNumber).padStart(3, '0')}`;
callback(null, nextCode);
} catch (error) {
callback(error);
}
}
};

View File

@@ -0,0 +1,358 @@
// patrolModel.js
// 일일순회점검 시스템 모델
const { getDb } = require('../dbPool');
const PatrolModel = {
// ==================== 순회점검 세션 ====================
// 세션 생성 또는 조회
getOrCreateSession: async (patrolDate, patrolTime, categoryId, inspectorId) => {
const db = await getDb();
// 기존 세션 확인
const [existingRows] = await db.query(`
SELECT session_id, status, started_at, completed_at
FROM daily_patrol_sessions
WHERE patrol_date = ? AND patrol_time = ? AND category_id = ?
`, [patrolDate, patrolTime, categoryId]);
if (existingRows.length > 0) {
return existingRows[0];
}
// 새 세션 생성
const [result] = await db.query(`
INSERT INTO daily_patrol_sessions (patrol_date, patrol_time, category_id, inspector_id, started_at)
VALUES (?, ?, ?, ?, CURTIME())
`, [patrolDate, patrolTime, categoryId, inspectorId]);
return {
session_id: result.insertId,
status: 'in_progress',
started_at: new Date().toTimeString().slice(0, 8)
};
},
// 세션 조회
getSession: async (sessionId) => {
const db = await getDb();
const [rows] = await db.query(`
SELECT s.*, u.name AS inspector_name, wc.category_name
FROM daily_patrol_sessions s
LEFT JOIN users u ON s.inspector_id = u.user_id
LEFT JOIN workplace_categories wc ON s.category_id = wc.category_id
WHERE s.session_id = ?
`, [sessionId]);
return rows[0] || null;
},
// 세션 목록 조회
getSessions: async (filters = {}) => {
const db = await getDb();
let query = `
SELECT s.*, u.name AS inspector_name, wc.category_name,
(SELECT COUNT(*) FROM patrol_check_records WHERE session_id = s.session_id AND is_checked = 1) AS checked_count,
(SELECT COUNT(*) FROM patrol_check_records WHERE session_id = s.session_id) AS total_count
FROM daily_patrol_sessions s
LEFT JOIN users u ON s.inspector_id = u.user_id
LEFT JOIN workplace_categories wc ON s.category_id = wc.category_id
WHERE 1=1
`;
const params = [];
if (filters.patrol_date) {
query += ' AND s.patrol_date = ?';
params.push(filters.patrol_date);
}
if (filters.patrol_time) {
query += ' AND s.patrol_time = ?';
params.push(filters.patrol_time);
}
if (filters.category_id) {
query += ' AND s.category_id = ?';
params.push(filters.category_id);
}
if (filters.status) {
query += ' AND s.status = ?';
params.push(filters.status);
}
query += ' ORDER BY s.patrol_date DESC, s.patrol_time DESC';
if (filters.limit) {
query += ' LIMIT ?';
params.push(parseInt(filters.limit));
}
const [rows] = await db.query(query, params);
return rows;
},
// 세션 완료 처리
completeSession: async (sessionId) => {
const db = await getDb();
await db.query(`
UPDATE daily_patrol_sessions
SET status = 'completed', completed_at = CURTIME(), updated_at = NOW()
WHERE session_id = ?
`, [sessionId]);
return true;
},
// 세션 메모 업데이트
updateSessionNotes: async (sessionId, notes) => {
const db = await getDb();
await db.query(`
UPDATE daily_patrol_sessions
SET notes = ?, updated_at = NOW()
WHERE session_id = ?
`, [notes, sessionId]);
return true;
},
// ==================== 체크리스트 항목 ====================
// 체크리스트 항목 조회 (공장/작업장별 필터링)
getChecklistItems: async (categoryId = null, workplaceId = null) => {
const db = await getDb();
let query = `
SELECT *
FROM patrol_checklist_items
WHERE is_active = 1
AND (workplace_id IS NULL OR workplace_id = ?)
AND (category_id IS NULL OR category_id = ?)
ORDER BY check_category, display_order, check_item
`;
const [rows] = await db.query(query, [workplaceId, categoryId]);
return rows;
},
// 체크리스트 항목 CRUD
createChecklistItem: async (data) => {
const db = await getDb();
const [result] = await db.query(`
INSERT INTO patrol_checklist_items (workplace_id, category_id, check_category, check_item, description, display_order, is_required)
VALUES (?, ?, ?, ?, ?, ?, ?)
`, [data.workplace_id, data.category_id, data.check_category, data.check_item, data.description, data.display_order || 0, data.is_required !== false]);
return result.insertId;
},
updateChecklistItem: async (itemId, data) => {
const db = await getDb();
const fields = [];
const params = [];
['workplace_id', 'category_id', 'check_category', 'check_item', 'description', 'display_order', 'is_required', 'is_active'].forEach(key => {
if (data[key] !== undefined) {
fields.push(`${key} = ?`);
params.push(data[key]);
}
});
if (fields.length === 0) return false;
params.push(itemId);
await db.query(`UPDATE patrol_checklist_items SET ${fields.join(', ')}, updated_at = NOW() WHERE item_id = ?`, params);
return true;
},
deleteChecklistItem: async (itemId) => {
const db = await getDb();
await db.query('UPDATE patrol_checklist_items SET is_active = 0, updated_at = NOW() WHERE item_id = ?', [itemId]);
return true;
},
// ==================== 체크 기록 ====================
// 작업장별 체크 기록 조회
getCheckRecords: async (sessionId, workplaceId = null) => {
const db = await getDb();
let query = `
SELECT r.*, ci.check_category, ci.check_item, ci.is_required
FROM patrol_check_records r
JOIN patrol_checklist_items ci ON r.check_item_id = ci.item_id
WHERE r.session_id = ?
`;
const params = [sessionId];
if (workplaceId) {
query += ' AND r.workplace_id = ?';
params.push(workplaceId);
}
query += ' ORDER BY ci.check_category, ci.display_order';
const [rows] = await db.query(query, params);
return rows;
},
// 체크 기록 저장 (upsert)
saveCheckRecord: async (sessionId, workplaceId, checkItemId, isChecked, checkResult = null, note = null) => {
const db = await getDb();
await db.query(`
INSERT INTO patrol_check_records (session_id, workplace_id, check_item_id, is_checked, check_result, note, checked_at)
VALUES (?, ?, ?, ?, ?, ?, NOW())
ON DUPLICATE KEY UPDATE
is_checked = VALUES(is_checked),
check_result = VALUES(check_result),
note = VALUES(note),
checked_at = NOW()
`, [sessionId, workplaceId, checkItemId, isChecked, checkResult, note]);
return true;
},
// 여러 체크 기록 일괄 저장
saveCheckRecords: async (sessionId, workplaceId, records) => {
const db = await getDb();
for (const record of records) {
await db.query(`
INSERT INTO patrol_check_records (session_id, workplace_id, check_item_id, is_checked, check_result, note, checked_at)
VALUES (?, ?, ?, ?, ?, ?, NOW())
ON DUPLICATE KEY UPDATE
is_checked = VALUES(is_checked),
check_result = VALUES(check_result),
note = VALUES(note),
checked_at = NOW()
`, [sessionId, workplaceId, record.check_item_id, record.is_checked, record.check_result, record.note]);
}
return true;
},
// ==================== 작업장 물품 현황 ====================
// 작업장 물품 조회
getWorkplaceItems: async (workplaceId, activeOnly = true) => {
const db = await getDb();
let query = `
SELECT wi.*, u.name AS created_by_name, it.type_name, it.icon, it.color
FROM workplace_items wi
LEFT JOIN users u ON wi.created_by = u.user_id
LEFT JOIN item_types it ON wi.item_type = it.type_code
WHERE wi.workplace_id = ?
`;
if (activeOnly) {
query += ' AND wi.is_active = 1';
}
query += ' ORDER BY wi.created_at DESC';
const [rows] = await db.query(query, [workplaceId]);
return rows;
},
// 물품 추가
createWorkplaceItem: async (data) => {
const db = await getDb();
const [result] = await db.query(`
INSERT INTO workplace_items
(workplace_id, patrol_session_id, project_id, item_type, item_name, quantity, x_percent, y_percent, width_percent, height_percent, created_by)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`, [
data.workplace_id,
data.patrol_session_id,
data.project_id,
data.item_type,
data.item_name,
data.quantity || 1,
data.x_percent,
data.y_percent,
data.width_percent,
data.height_percent,
data.created_by
]);
return result.insertId;
},
// 물품 수정
updateWorkplaceItem: async (itemId, data, userId) => {
const db = await getDb();
const fields = [];
const params = [];
['item_type', 'item_name', 'quantity', 'x_percent', 'y_percent', 'width_percent', 'height_percent', 'is_active', 'project_id'].forEach(key => {
if (data[key] !== undefined) {
fields.push(`${key} = ?`);
params.push(data[key]);
}
});
if (fields.length === 0) return false;
fields.push('updated_by = ?', 'updated_at = NOW()');
params.push(userId, itemId);
await db.query(`UPDATE workplace_items SET ${fields.join(', ')} WHERE item_id = ?`, params);
return true;
},
// 물품 삭제 (비활성화)
deleteWorkplaceItem: async (itemId, userId) => {
const db = await getDb();
await db.query('UPDATE workplace_items SET is_active = 0, updated_by = ?, updated_at = NOW() WHERE item_id = ?', [userId, itemId]);
return true;
},
// 물품 영구 삭제
hardDeleteWorkplaceItem: async (itemId) => {
const db = await getDb();
await db.query('DELETE FROM workplace_items WHERE item_id = ?', [itemId]);
return true;
},
// ==================== 물품 유형 ====================
// 물품 유형 목록 조회
getItemTypes: async () => {
const db = await getDb();
const [rows] = await db.query('SELECT * FROM item_types WHERE is_active = 1 ORDER BY display_order');
return rows;
},
// ==================== 대시보드/통계 ====================
// 오늘 순회점검 현황
getTodayPatrolStatus: async (categoryId = null) => {
const db = await getDb();
const today = new Date().toISOString().slice(0, 10);
let query = `
SELECT s.session_id, s.patrol_time, s.status, s.inspector_id, u.name AS inspector_name,
s.started_at, s.completed_at,
(SELECT COUNT(*) FROM patrol_check_records WHERE session_id = s.session_id AND is_checked = 1) AS checked_count,
(SELECT COUNT(*) FROM patrol_check_records WHERE session_id = s.session_id) AS total_count
FROM daily_patrol_sessions s
LEFT JOIN users u ON s.inspector_id = u.user_id
WHERE s.patrol_date = ?
`;
const params = [today];
if (categoryId) {
query += ' AND s.category_id = ?';
params.push(categoryId);
}
query += ' ORDER BY s.patrol_time';
const [rows] = await db.query(query, params);
return rows;
},
// 작업장별 점검 현황 (세션 기준)
getWorkplaceCheckStatus: async (sessionId) => {
const db = await getDb();
const [rows] = await db.query(`
SELECT w.workplace_id, w.workplace_name,
COUNT(DISTINCT r.check_item_id) AS checked_count,
(SELECT COUNT(*) FROM patrol_checklist_items WHERE is_active = 1) AS total_items,
MAX(r.checked_at) AS last_check_time
FROM workplaces w
LEFT JOIN patrol_check_records r ON w.workplace_id = r.workplace_id AND r.session_id = ?
WHERE w.is_active = 1
GROUP BY w.workplace_id
ORDER BY w.workplace_name
`, [sessionId]);
return rows;
}
};
module.exports = PatrolModel;

View File

@@ -20,14 +20,15 @@ const create = async (worker, callback) => {
salary = null,
annual_leave = null,
status = 'active',
employment_status = 'employed'
employment_status = 'employed',
department_id = null
} = worker;
const [result] = await db.query(
`INSERT INTO workers
(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]
(worker_name, job_type, join_date, salary, annual_leave, status, employment_status, department_id)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
[worker_name, job_type, formatDate(join_date), salary, annual_leave, status, employment_status, department_id]
);
callback(null, result.insertId);
@@ -45,9 +46,11 @@ const getAll = async (callback) => {
SELECT
w.*,
CASE WHEN w.status = 'active' THEN 1 ELSE 0 END AS is_active,
u.user_id
u.user_id,
d.department_name
FROM workers w
LEFT JOIN users u ON w.worker_id = u.worker_id
LEFT JOIN departments d ON w.department_id = d.department_id
ORDER BY w.worker_id DESC
`);
callback(null, rows);
@@ -64,9 +67,11 @@ const getById = async (worker_id, callback) => {
SELECT
w.*,
CASE WHEN w.status = 'active' THEN 1 ELSE 0 END AS is_active,
u.user_id
u.user_id,
d.department_name
FROM workers w
LEFT JOIN users u ON w.worker_id = u.worker_id
LEFT JOIN departments d ON w.department_id = d.department_id
WHERE w.worker_id = ?
`, [worker_id]);
callback(null, rows[0]);
@@ -87,7 +92,8 @@ const update = async (worker, callback) => {
join_date,
salary,
annual_leave,
employment_status
employment_status,
department_id
} = worker;
// 업데이트할 필드만 동적으로 구성
@@ -122,6 +128,10 @@ const update = async (worker, callback) => {
updates.push('employment_status = ?');
values.push(employment_status);
}
if (department_id !== undefined) {
updates.push('department_id = ?');
values.push(department_id);
}
if (updates.length === 0) {
callback(new Error('업데이트할 필드가 없습니다'));

View File

@@ -162,7 +162,7 @@ const getAllWorkplaces = async (callback) => {
const db = await getDb();
const [rows] = await db.query(
`SELECT w.workplace_id, w.category_id, w.workplace_name, w.description, w.is_active, w.workplace_purpose, w.display_priority,
w.workplace_purpose, w.display_priority, w.created_at, w.updated_at,
w.layout_image, w.created_at, w.updated_at,
wc.category_name
FROM workplaces w
LEFT JOIN workplace_categories wc ON w.category_id = wc.category_id
@@ -182,7 +182,7 @@ const getActiveWorkplaces = async (callback) => {
const db = await getDb();
const [rows] = await db.query(
`SELECT w.workplace_id, w.category_id, w.workplace_name, w.description, w.is_active, w.workplace_purpose, w.display_priority,
w.created_at, w.updated_at,
w.layout_image, w.created_at, w.updated_at,
wc.category_name
FROM workplaces w
LEFT JOIN workplace_categories wc ON w.category_id = wc.category_id
@@ -203,7 +203,7 @@ const getWorkplacesByCategory = async (categoryId, callback) => {
const db = await getDb();
const [rows] = await db.query(
`SELECT w.workplace_id, w.category_id, w.workplace_name, w.description, w.is_active, w.workplace_purpose, w.display_priority,
w.created_at, w.updated_at,
w.layout_image, w.created_at, w.updated_at,
wc.category_name
FROM workplaces w
LEFT JOIN workplace_categories wc ON w.category_id = wc.category_id
@@ -225,7 +225,7 @@ const getWorkplaceById = async (workplaceId, callback) => {
const db = await getDb();
const [rows] = await db.query(
`SELECT w.workplace_id, w.category_id, w.workplace_name, w.description, w.is_active, w.workplace_purpose, w.display_priority,
w.created_at, w.updated_at,
w.layout_image, w.created_at, w.updated_at,
wc.category_name
FROM workplaces w
LEFT JOIN workplace_categories wc ON w.category_id = wc.category_id
@@ -250,15 +250,16 @@ const updateWorkplace = async (workplaceId, workplace, callback) => {
description,
is_active,
workplace_purpose,
display_priority
display_priority,
layout_image
} = workplace;
const [result] = await db.query(
`UPDATE workplaces
SET category_id = ?, workplace_name = ?, description = ?, is_active = ?,
workplace_purpose = ?, display_priority = ?, updated_at = NOW()
workplace_purpose = ?, display_priority = ?, layout_image = ?, updated_at = NOW()
WHERE workplace_id = ?`,
[category_id, workplace_name, description, is_active, workplace_purpose, display_priority, workplaceId]
[category_id, workplace_name, description, is_active, workplace_purpose, display_priority, layout_image, workplaceId]
);
callback(null, result);

View File

@@ -0,0 +1,31 @@
// routes/departmentRoutes.js
const express = require('express');
const router = express.Router();
const departmentController = require('../controllers/departmentController');
const { requireAuth, requireRole } = require('../middlewares/authMiddleware');
// 부서 목록 조회 (인증 필요)
router.get('/', requireAuth, departmentController.getAll);
// 부서 상세 조회
router.get('/:id', requireAuth, departmentController.getById);
// 부서별 작업자 조회
router.get('/:id/workers', requireAuth, departmentController.getWorkers);
// 부서 생성 (관리자만)
router.post('/', requireAuth, requireRole(['Admin', 'System Admin']), departmentController.create);
// 부서 수정 (관리자만)
router.put('/:id', requireAuth, requireRole(['Admin', 'System Admin']), departmentController.update);
// 부서 삭제 (관리자만)
router.delete('/:id', requireAuth, requireRole(['Admin', 'System Admin']), departmentController.delete);
// 작업자 부서 이동 (관리자만)
router.post('/move-worker', requireAuth, requireRole(['Admin', 'System Admin']), departmentController.moveWorker);
// 여러 작업자 부서 일괄 이동 (관리자만)
router.post('/move-workers', requireAuth, requireRole(['Admin', 'System Admin']), departmentController.moveWorkers);
module.exports = router;

View File

@@ -18,6 +18,10 @@ router.get('/active/list', equipmentController.getActiveEquipments);
// READ 설비 유형 목록
router.get('/types', equipmentController.getEquipmentTypes);
// GET NEXT EQUIPMENT CODE - 다음 관리번호 자동 생성
// ?prefix=TKP (기본값: TKP)
router.get('/next-code', equipmentController.getNextEquipmentCode);
// READ 작업장별 설비
router.get('/workplace/:workplaceId', equipmentController.getEquipmentsByWorkplace);

View File

@@ -0,0 +1,73 @@
// patrolRoutes.js
// 일일순회점검 시스템 라우트
const express = require('express');
const router = express.Router();
const patrolController = require('../controllers/patrolController');
// ==================== 순회점검 세션 ====================
// 세션 목록 조회
// GET /patrol/sessions?patrol_date=2026-02-04&patrol_time=morning&category_id=1
router.get('/sessions', patrolController.getSessions);
// 세션 시작/조회 (POST로 생성하거나 기존 세션 반환)
// POST /patrol/sessions { patrol_date, patrol_time, category_id }
router.post('/sessions', patrolController.getOrCreateSession);
// 세션 상세 조회
router.get('/sessions/:sessionId', patrolController.getSession);
// 세션 완료
router.patch('/sessions/:sessionId/complete', patrolController.completeSession);
// 세션 메모 업데이트
router.patch('/sessions/:sessionId/notes', patrolController.updateSessionNotes);
// 세션별 작업장 점검 현황
router.get('/sessions/:sessionId/workplace-status', patrolController.getWorkplaceCheckStatus);
// ==================== 체크리스트 항목 ====================
// 체크리스트 항목 조회 (필터링 가능)
// GET /patrol/checklist?category_id=1&workplace_id=2
router.get('/checklist', patrolController.getChecklistItems);
// 체크리스트 항목 CRUD
router.post('/checklist', patrolController.createChecklistItem);
router.put('/checklist/:itemId', patrolController.updateChecklistItem);
router.delete('/checklist/:itemId', patrolController.deleteChecklistItem);
// ==================== 체크 기록 ====================
// 세션별 체크 기록 조회
// GET /patrol/sessions/:sessionId/records?workplace_id=1
router.get('/sessions/:sessionId/records', patrolController.getCheckRecords);
// 체크 기록 저장 (단건)
router.post('/sessions/:sessionId/records', patrolController.saveCheckRecord);
// 체크 기록 일괄 저장
router.post('/sessions/:sessionId/records/batch', patrolController.saveCheckRecords);
// ==================== 작업장 물품 현황 ====================
// 작업장별 물품 조회
router.get('/workplaces/:workplaceId/items', patrolController.getWorkplaceItems);
// 물품 CRUD
router.post('/workplaces/:workplaceId/items', patrolController.createWorkplaceItem);
router.put('/items/:itemId', patrolController.updateWorkplaceItem);
router.delete('/items/:itemId', patrolController.deleteWorkplaceItem);
// ==================== 물품 유형 ====================
// 물품 유형 목록
router.get('/item-types', patrolController.getItemTypes);
// ==================== 대시보드/통계 ====================
// 오늘 순회점검 현황
router.get('/today-status', patrolController.getTodayStatus);
module.exports = router;

View File

@@ -20,16 +20,25 @@ router.use(verifyToken);
/**
* 관리자 권한 확인 미들웨어
* role 또는 access_level로 관리자 확인
*/
const adminOnly = (req, res, next) => {
const userRole = req.user?.role?.toLowerCase();
if (req.user && (userRole === 'admin' || userRole === 'system' || userRole === 'system admin')) {
const accessLevel = req.user?.access_level?.toLowerCase();
// role 기반 확인
const isAdminByRole = userRole === 'admin' || userRole === 'system' || userRole === 'system admin';
// access_level 기반 확인 (role이 없는 경우 대비)
const isAdminByAccessLevel = accessLevel === 'admin' || accessLevel === 'system';
if (req.user && (isAdminByRole || isAdminByAccessLevel)) {
next();
} else {
logger.warn('관리자 권한 없는 접근 시도', {
userId: req.user?.user_id,
username: req.user?.username,
role: req.user?.role,
accessLevel: req.user?.access_level,
url: req.originalUrl
});
return res.status(403).json({
@@ -146,9 +155,12 @@ router.put('/:id/status', userController.updateUserStatus);
// 🔑 사용자 비밀번호 초기화 (000000)
router.post('/:id/reset-password', userController.resetUserPassword);
// 🗑️ 사용자 삭제
// 🗑️ 사용자 비활성화 (Soft Delete)
router.delete('/:id', userController.deleteUser);
// 💀 사용자 영구 삭제 (Hard Delete)
router.delete('/:id/permanent', userController.permanentDeleteUser);
// 🔐 사용자 페이지 접근 권한 업데이트 (Admin만)
router.put('/:id/page-access', userController.updateUserPageAccess);

View File

@@ -76,7 +76,8 @@ const upsertAttendanceRecordService = async (recordData) => {
is_vacation_processed,
overtime_approved,
status,
notes
notes,
created_by
} = recordData;
// 필수 필드 검증
@@ -99,7 +100,8 @@ const upsertAttendanceRecordService = async (recordData) => {
is_vacation_processed,
overtime_approved,
status,
notes
notes,
created_by
});
logger.info('근태 기록 저장 성공', { record_date, worker_id });

View File

@@ -234,14 +234,18 @@ const generateCacheKey = (query, params = [], prefix = 'query') => {
*/
const optimizedQueries = {
// 작업자 목록 (페이지네이션)
getWorkersPaged: async (page = 1, limit = 10, search = '', status = '') => {
getWorkersPaged: async (page = 1, limit = 10, search = '', status = '', departmentId = null) => {
let baseQuery = `
SELECT w.*, COUNT(dwr.id) as report_count
SELECT w.*, d.department_name, COUNT(dwr.id) as report_count
FROM workers w
LEFT JOIN daily_work_reports dwr ON w.worker_id = dwr.worker_id
LEFT JOIN departments d ON w.department_id = d.department_id
`;
let countQuery = 'SELECT COUNT(*) as total FROM workers w';
let countQuery = `
SELECT COUNT(*) as total FROM workers w
LEFT JOIN departments d ON w.department_id = d.department_id
`;
let params = [];
let conditions = [];
@@ -257,6 +261,12 @@ const optimizedQueries = {
params.push(status);
}
// 부서 조건
if (departmentId) {
conditions.push('w.department_id = ?');
params.push(departmentId);
}
// 조건 조합
if (conditions.length > 0) {
const whereClause = ' WHERE ' + conditions.join(' AND ');