feat: 대시보드 작업장 현황 지도 구현
- 실시간 작업장 현황을 지도로 시각화 - 작업장 관리 페이지에서 정의한 구역 정보 활용 - TBM 작업자 및 방문자 현황 표시 주요 변경사항: - dashboard.html: 작업장 현황 섹션 추가 (기존 작업 현황 테이블 제거) - workplace-status.js: 지도 렌더링 및 데이터 통합 로직 구현 - modern-dashboard.js: 삭제된 DOM 요소 조건부 체크 추가 시각화 방식: - 인원 없음: 회색 테두리 + 작업장 이름 - 내부 작업자: 파란색 영역 + 인원 수 - 외부 방문자: 보라색 영역 + 인원 수 - 둘 다: 초록색 영역 + 총 인원 수 기술 구현: - Canvas API 기반 사각형 영역 렌더링 - map-regions API를 통한 데이터 일관성 보장 - 클릭 이벤트로 상세 정보 모달 표시 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -178,36 +178,68 @@ exports.updateWorker = asyncHandler(async (req, res) => {
|
||||
// 계정 생성/해제 처리
|
||||
const db = await getDb();
|
||||
const hasAccount = currentWorker.user_id !== null && currentWorker.user_id !== undefined;
|
||||
let accountAction = null;
|
||||
let accountUsername = null;
|
||||
|
||||
console.log('🔍 계정 생성 체크:', {
|
||||
createAccount,
|
||||
hasAccount,
|
||||
currentWorker_user_id: currentWorker.user_id,
|
||||
worker_name: workerData.worker_name
|
||||
});
|
||||
|
||||
if (createAccount && !hasAccount && workerData.worker_name) {
|
||||
// 계정 생성
|
||||
console.log('✅ 계정 생성 로직 시작');
|
||||
try {
|
||||
console.log('🔑 사용자명 생성 중...');
|
||||
const username = await generateUniqueUsername(workerData.worker_name, db);
|
||||
console.log('🔑 생성된 사용자명:', username);
|
||||
|
||||
const hashedPassword = await bcrypt.hash('1234', 10);
|
||||
console.log('🔒 비밀번호 해싱 완료');
|
||||
|
||||
// User 역할 조회
|
||||
console.log('👤 User 역할 조회 중...');
|
||||
const [userRole] = await db.query('SELECT id FROM roles WHERE name = ?', ['User']);
|
||||
console.log('👤 User 역할 조회 결과:', userRole);
|
||||
|
||||
if (userRole && userRole.length > 0) {
|
||||
console.log('💾 계정 DB 삽입 시작...');
|
||||
await db.query(
|
||||
`INSERT INTO users (username, password, name, worker_id, role_id, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, NOW(), NOW())`,
|
||||
[username, hashedPassword, workerData.worker_name, id, userRole[0].id]
|
||||
);
|
||||
console.log('✅ 계정 DB 삽입 완료');
|
||||
|
||||
accountAction = 'created';
|
||||
accountUsername = username;
|
||||
logger.info('작업자 계정 생성 성공', { worker_id: id, username });
|
||||
} else {
|
||||
console.log('❌ User 역할을 찾을 수 없음');
|
||||
}
|
||||
} catch (accountError) {
|
||||
console.error('❌ 계정 생성 오류:', accountError);
|
||||
logger.error('계정 생성 실패', { worker_id: id, error: accountError.message });
|
||||
accountAction = 'failed';
|
||||
}
|
||||
} else if (!createAccount && hasAccount) {
|
||||
} else {
|
||||
console.log('⏭️ 계정 생성 조건 불만족:', { createAccount, hasAccount, hasWorkerName: !!workerData.worker_name });
|
||||
}
|
||||
|
||||
if (!createAccount && hasAccount) {
|
||||
// 계정 연동 해제 (users.worker_id = NULL)
|
||||
try {
|
||||
await db.query('UPDATE users SET worker_id = NULL WHERE worker_id = ?', [id]);
|
||||
accountAction = 'unlinked';
|
||||
logger.info('작업자 계정 연동 해제 성공', { worker_id: id });
|
||||
} catch (unlinkError) {
|
||||
logger.error('계정 연동 해제 실패', { worker_id: id, error: unlinkError.message });
|
||||
accountAction = 'unlink_failed';
|
||||
}
|
||||
} else if (createAccount && hasAccount) {
|
||||
accountAction = 'already_exists';
|
||||
}
|
||||
|
||||
// 작업자 관련 캐시 무효화
|
||||
@@ -216,10 +248,26 @@ exports.updateWorker = asyncHandler(async (req, res) => {
|
||||
|
||||
logger.info('작업자 수정 성공', { worker_id: id });
|
||||
|
||||
// 응답 메시지 구성
|
||||
let message = '작업자 정보가 성공적으로 수정되었습니다';
|
||||
if (accountAction === 'created') {
|
||||
message += ` (계정 생성 완료: ${accountUsername}, 초기 비밀번호: 1234)`;
|
||||
} else if (accountAction === 'unlinked') {
|
||||
message += ' (계정 연동 해제 완료)';
|
||||
} else if (accountAction === 'already_exists') {
|
||||
message += ' (이미 계정이 존재합니다)';
|
||||
} else if (accountAction === 'failed') {
|
||||
message += ' (계정 생성 실패)';
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: { changes },
|
||||
message: '작업자 정보가 성공적으로 수정되었습니다'
|
||||
data: {
|
||||
changes,
|
||||
account_action: accountAction,
|
||||
account_username: accountUsername
|
||||
},
|
||||
message
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user