remove-empty-license.js
This commit is contained in:
parent
4faf102f9b
commit
c8d9ab1f5e
26
remove-empty-license.js
Normal file
26
remove-empty-license.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
import fs from 'fs/promises';
|
||||||
|
|
||||||
|
async function removeEmptyLicenseRecords() {
|
||||||
|
try {
|
||||||
|
const filePath = './data.json';
|
||||||
|
const data = await fs.readFile(filePath, 'utf-8');
|
||||||
|
let records = JSON.parse(data);
|
||||||
|
|
||||||
|
// Filter out records where "许可证号" is "空"
|
||||||
|
const filteredRecords = records.filter(record => record['许可证号'] !== '空');
|
||||||
|
|
||||||
|
// Update the sequential "序号" field for the remaining records
|
||||||
|
for (let i = 0; i < filteredRecords.length; i++) {
|
||||||
|
filteredRecords[i]['序号'] = (i + 1).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.writeFile(filePath, JSON.stringify(filteredRecords, null, 4), 'utf-8');
|
||||||
|
console.log(`已从 data.json 中删除所有 "许可证号" 为 "空" 的数据。共删除 ${records.length - filteredRecords.length} 条记录。`);
|
||||||
|
console.log('序号字段已重新编号以保持顺序。');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('删除空许可证号数据时发生错误:', error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removeEmptyLicenseRecords();
|
||||||
Loading…
Reference in New Issue
Block a user