docs: add work log for 2026-06-15 and update DB deletion policy in README
This commit is contained in:
85
scratch/reexamine_full.cjs
Normal file
85
scratch/reexamine_full.cjs
Normal file
@@ -0,0 +1,85 @@
|
||||
const XLSX = require('xlsx');
|
||||
const mysql = require('mysql2/promise');
|
||||
require('dotenv').config();
|
||||
|
||||
async function reexamineData() {
|
||||
const connection = await mysql.createConnection({
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASS,
|
||||
database: process.env.DB_NAME,
|
||||
port: parseInt(process.env.DB_PORT || '3306')
|
||||
});
|
||||
|
||||
console.log('🧐 [전수 조사] 엑셀 vs DB 데이터 비교 분석...');
|
||||
|
||||
// 1. 엑셀 데이터 로드
|
||||
const workbook = XLSX.readFile('asset_pc (2026.06.15).xlsx');
|
||||
const sheet = workbook.Sheets[workbook.SheetNames[0]];
|
||||
const excelRows = XLSX.utils.sheet_to_json(sheet);
|
||||
|
||||
// 2. DB 데이터 로드
|
||||
const [dbRows] = await connection.query(`
|
||||
SELECT id, asset_code, asset_type, user_current, emp_no, current_dept
|
||||
FROM asset_core
|
||||
WHERE id LIKE "PC_20260615_%"
|
||||
`);
|
||||
const dbMap = new Map();
|
||||
dbRows.forEach(r => dbMap.set(r.id, r));
|
||||
|
||||
const report = {
|
||||
total: excelRows.length,
|
||||
publicInExcelWithEmpNo: [], // 엑셀은 공용PC인데 사번이 있는 경우
|
||||
personalInExcelNoEmpNo: [], // 엑셀은 개인PC인데 사번이 없는 경우
|
||||
typeMismatch: [], // 엑셀과 DB의 asset_type이 다른 경우
|
||||
userMismatch: [] // 사용자명이 크게 다른 경우
|
||||
};
|
||||
|
||||
for (let i = 0; i < excelRows.length; i++) {
|
||||
const ex = excelRows[i];
|
||||
const id = `PC_20260615_${String(i + 1).padStart(4, '0')}`;
|
||||
const db = dbMap.get(id);
|
||||
|
||||
if (!db) continue;
|
||||
|
||||
const exType = ex.asset_type || '개인PC';
|
||||
const exEmpNo = ex.emp_no ? String(ex.emp_no) : null;
|
||||
const exUser = ex.user_current || '';
|
||||
|
||||
// A. 공용PC인데 사번이 있는 경우 (가장 큰 혼란 포인트)
|
||||
if (exType === '공용PC' && exEmpNo) {
|
||||
report.publicInExcelWithEmpNo.push({ id, exUser, exEmpNo, exDept: ex.current_dept });
|
||||
}
|
||||
|
||||
// B. 개인PC인데 사번이 없는 경우
|
||||
if (exType === '개인PC' && !exEmpNo) {
|
||||
report.personalInExcelNoEmpNo.push({ id, exUser, exDept: ex.current_dept });
|
||||
}
|
||||
|
||||
// C. DB와의 타입 불일치 (현재 DB 상태 체크)
|
||||
if (db.asset_type !== exType) {
|
||||
report.typeMismatch.push({ id, exType, dbType: db.asset_type, user: db.user_current });
|
||||
}
|
||||
}
|
||||
|
||||
console.log('\n================================================');
|
||||
console.log(`📊 전수 조사 요약 (총 ${report.total}건)`);
|
||||
console.log(`1. 엑셀은 '공용PC'이나 '사번'이 있는 항목: ${report.publicInExcelWithEmpNo.length}건`);
|
||||
console.log(`2. 엑셀은 '개인PC'이나 '사번'이 없는 항목: ${report.personalInExcelNoEmpNo.length}건`);
|
||||
console.log(`3. 현재 DB와 엑셀의 '자산유형' 불일치: ${report.typeMismatch.length}건`);
|
||||
console.log('================================================\n');
|
||||
|
||||
if (report.publicInExcelWithEmpNo.length > 0) {
|
||||
console.log('⚠️ [그룹 1] 공용PC인데 실사용자/관리자가 지정된 사례 (샘플 15건):');
|
||||
console.table(report.publicInExcelWithEmpNo.slice(0, 15));
|
||||
}
|
||||
|
||||
if (report.personalInExcelNoEmpNo.length > 0) {
|
||||
console.log('\n⚠️ [그룹 2] 개인PC인데 사번 정보가 누락된 사례 (샘플 15건):');
|
||||
console.table(report.personalInExcelNoEmpNo.slice(0, 15));
|
||||
}
|
||||
|
||||
await connection.end();
|
||||
}
|
||||
|
||||
reexamineData().catch(console.error);
|
||||
Reference in New Issue
Block a user