2026-04-03 14:05:18 +08:00
|
|
|
import path from 'path';
|
|
|
|
|
import { app as electronApp, dialog } from 'electron';
|
|
|
|
|
import { activateRecordService } from "../service/database/activateRecord";
|
2025-10-24 15:10:23 +08:00
|
|
|
|
|
|
|
|
class ActivateRecordController {
|
|
|
|
|
|
|
|
|
|
async list(args: { macAddress: string, modules: string[] }): Promise<any> {
|
2026-04-03 14:05:18 +08:00
|
|
|
const { macAddress, modules } = args;
|
|
|
|
|
return activateRecordService.list(macAddress, modules);
|
2025-10-24 15:10:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async save(args: {
|
2026-04-03 14:05:18 +08:00
|
|
|
applicant: string,
|
2025-10-24 15:10:23 +08:00
|
|
|
macAddress: string,
|
|
|
|
|
applicationCode: string,
|
|
|
|
|
modules: string[],
|
|
|
|
|
activationCode: string,
|
|
|
|
|
createTime: string,
|
|
|
|
|
remark: string
|
|
|
|
|
}): Promise<any> {
|
2026-04-03 14:05:18 +08:00
|
|
|
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}`;
|
2025-10-24 15:10:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ActivateRecordController.toString = () => '[class ActivateRecordController]';
|
|
|
|
|
|
|
|
|
|
export default ActivateRecordController;
|