2024-06-24 13:11:19 +08:00
|
|
|
|
import Realm, { UpdateMode } from 'realm'
|
|
|
|
|
|
import path from 'path'
|
|
|
|
|
|
import { BaseService } from '../baseService.js'
|
|
|
|
|
|
import { define } from '../../../define.js'
|
|
|
|
|
|
import { SoftwareModel } from '../../model/SoftWare/software.js'
|
|
|
|
|
|
import { ComponentSize, SoftwareThemeType } from '../../../enum/softwareEnum.js'
|
|
|
|
|
|
import { successMessage } from '../../../../main/generalTools.js'
|
|
|
|
|
|
import { BaseSoftWareService } from './softwareBasic.js'
|
|
|
|
|
|
const { v4: uuidv4 } = require('uuid')
|
|
|
|
|
|
|
|
|
|
|
|
export class SoftwareService extends BaseSoftWareService {
|
|
|
|
|
|
static instance: SoftwareService | null = null
|
|
|
|
|
|
realm: Realm
|
|
|
|
|
|
private constructor() {
|
|
|
|
|
|
super()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取当前实例对象,为空则创建一个新的
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
public static async getInstance() {
|
|
|
|
|
|
if (SoftwareService.instance === null) {
|
|
|
|
|
|
SoftwareService.instance = new SoftwareService()
|
|
|
|
|
|
await super.getInstance()
|
|
|
|
|
|
}
|
2024-07-13 15:44:13 +08:00
|
|
|
|
await SoftwareService.instance.open()
|
2024-06-24 13:11:19 +08:00
|
|
|
|
return SoftwareService.instance
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 修改数据库中行中的某个属性数据
|
2024-07-13 15:44:13 +08:00
|
|
|
|
UpdateSoftware(software) {
|
2024-06-24 13:11:19 +08:00
|
|
|
|
try {
|
|
|
|
|
|
this.realm.write(() => {
|
|
|
|
|
|
this.realm.create('Software', software, UpdateMode.Modified)
|
|
|
|
|
|
})
|
|
|
|
|
|
// 返回成功信息
|
|
|
|
|
|
return successMessage(null, '修改软件配置信息成功', 'SoftwareService_UpdateSoftware')
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
throw error
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-13 15:44:13 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 添加软件配置信息
|
|
|
|
|
|
* @param software 软件配置信息
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
AddSfotware(software) {
|
2024-06-24 13:11:19 +08:00
|
|
|
|
try {
|
|
|
|
|
|
software.id = uuidv4()
|
|
|
|
|
|
this.realm.write(() => {
|
|
|
|
|
|
this.realm.create('Software', software)
|
|
|
|
|
|
})
|
2024-07-13 15:44:13 +08:00
|
|
|
|
return successMessage(null, '添加软件配置信息成功', 'SoftwareService_AddSfotware')
|
2024-06-24 13:11:19 +08:00
|
|
|
|
} catch (error) {
|
|
|
|
|
|
throw error
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 或软件基础配置信息
|
|
|
|
|
|
*/
|
2024-07-13 15:44:13 +08:00
|
|
|
|
GetSoftwareData() {
|
2024-06-24 13:11:19 +08:00
|
|
|
|
try {
|
|
|
|
|
|
let software = this.realm.objects('Software')
|
|
|
|
|
|
return successMessage(
|
|
|
|
|
|
software.toJSON(),
|
|
|
|
|
|
'获取软件配置信息成功',
|
|
|
|
|
|
'SoftwareService_GetSoftwareData'
|
|
|
|
|
|
)
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
global.logger.error(
|
|
|
|
|
|
'SoftwareService_GetSoftwareData',
|
|
|
|
|
|
'获取软件的基础设置失败 ,错误信息如下:' + error.toString()
|
|
|
|
|
|
)
|
|
|
|
|
|
throw error
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-07-13 15:44:13 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取当前软件指定属性的数据
|
|
|
|
|
|
* @param property 属性名称
|
|
|
|
|
|
*/
|
|
|
|
|
|
GetSoftWarePropertyData(property: string) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
let software = this.realm.objects('Software')
|
|
|
|
|
|
if (software.length <= 0) {
|
|
|
|
|
|
throw new Error('数据库中没有软件配置信息')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let softwareData = software.toJSON()[0]
|
|
|
|
|
|
let res = softwareData[property]
|
|
|
|
|
|
|
|
|
|
|
|
return successMessage(res, '获取软件配置信息成功', 'SoftwareService_GetSoftWarePropertyData')
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
global.logger.error(
|
|
|
|
|
|
'SoftwareService_GetSoftWarePropertyData',
|
|
|
|
|
|
'获取软件的基础设置失败 ,错误信息如下:' + error.toString()
|
|
|
|
|
|
)
|
|
|
|
|
|
throw error
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 保存软件的指定属性的设置信息
|
|
|
|
|
|
* @param property 属性的名称
|
|
|
|
|
|
* @param data 数据
|
|
|
|
|
|
* @returns
|
|
|
|
|
|
*/
|
|
|
|
|
|
SaveSoftwarePropertyData(property: string, data: string) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
this.transaction(() => {
|
|
|
|
|
|
let software = this.realm.objects('Software')
|
|
|
|
|
|
// 遍历修改
|
|
|
|
|
|
for (let item of software) {
|
|
|
|
|
|
item[property] = data
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
return successMessage(
|
|
|
|
|
|
null,
|
|
|
|
|
|
'保存软件配置信息成功',
|
|
|
|
|
|
'SoftwareService_SaveSoftwarePropertyData'
|
|
|
|
|
|
)
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
throw error
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-06-24 13:11:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default SoftwareService
|