first commit

This commit is contained in:
2026-04-11 11:51:54 +08:00
commit b12a84e388
99 changed files with 19620 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
import * as dotenv from 'dotenv';
dotenv.config();
import pool from './src/config/database';
async function run() {
// 找出所有 self_score 为空但有 perf_item 的记录
const [perfs] = await pool.query<any[]>(
`SELECT perf_id FROM performance_month WHERE self_score IS NULL OR self_score = 0`
);
for (const perf of perfs) {
const [items] = await pool.query<any[]>(
'SELECT weight, self_score FROM perf_item WHERE perf_id = ? AND self_score IS NOT NULL',
[perf.perf_id]
);
if (items.length === 0) continue;
let weightedSum = 0;
let totalWeight = 0;
for (const item of items) {
weightedSum += Number(item.self_score) * Number(item.weight);
totalWeight += Number(item.weight);
}
if (totalWeight === 0) continue;
const selfScore = parseFloat((weightedSum / totalWeight).toFixed(2));
await pool.query(
'UPDATE performance_month SET self_score = ? WHERE perf_id = ?',
[selfScore, perf.perf_id]
);
console.log(`perfId=${perf.perf_id} 自评总分=${selfScore}`);
}
await pool.end();
console.log('完成');
}
run().catch(console.error);