Files
pqs-9100_tool_client/electron/controller/activateRecord.ts
hongawen 51d607d970 调整界面
调整脚本
增加功能:备份、恢复、清空
2026-04-03 14:05:18 +08:00

98 lines
2.8 KiB
TypeScript

import path from 'path';
import { app as electronApp, dialog } from 'electron';
import { activateRecordService } from "../service/database/activateRecord";
class ActivateRecordController {
async list(args: { macAddress: string, modules: string[] }): Promise<any> {
const { macAddress, modules } = args;
return activateRecordService.list(macAddress, modules);
}
async save(args: {
applicant: string,
macAddress: string,
applicationCode: string,
modules: string[],
activationCode: string,
createTime: string,
remark: string
}): Promise<any> {
const { modules } = args;
return activateRecordService.save({ ...args, module: modules.join(',') });
}
async removeById(args: { id: number }): Promise<any> {
const { id } = args;
return activateRecordService.removeById(id);
}
async clear(): Promise<any> {
return activateRecordService.clear();
}
async backup(): Promise<any> {
const defaultFileName = `activate-record-backup-${this.getTimestamp()}.json`;
const filePath = dialog.showSaveDialogSync({
title: '导出备份',
defaultPath: path.join(electronApp.getPath('documents'), defaultFileName),
filters: [
{ name: 'JSON', extensions: ['json'] }
]
});
if (!filePath) {
return {
canceled: true
};
}
const count = await activateRecordService.backup(filePath);
return {
canceled: false,
count,
filePath
};
}
async importBackup(): Promise<any> {
const filePaths = dialog.showOpenDialogSync({
title: '导入备份',
properties: ['openFile'],
filters: [
{ name: 'JSON', extensions: ['json'] }
]
});
if (!filePaths || filePaths.length === 0) {
return {
canceled: true
};
}
const filePath = filePaths[0];
const count = await activateRecordService.importBackup(filePath);
return {
canceled: false,
count,
filePath
};
}
private getTimestamp(): string {
const now = new Date();
const year = now.getFullYear();
const month = `${now.getMonth() + 1}`.padStart(2, '0');
const day = `${now.getDate()}`.padStart(2, '0');
const hour = `${now.getHours()}`.padStart(2, '0');
const minute = `${now.getMinutes()}`.padStart(2, '0');
const second = `${now.getSeconds()}`.padStart(2, '0');
return `${year}${month}${day}-${hour}${minute}${second}`;
}
}
ActivateRecordController.toString = () => '[class ActivateRecordController]';
export default ActivateRecordController;