133 lines
4.1 KiB
TypeScript
133 lines
4.1 KiB
TypeScript
|
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
|||
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|||
|
|
import { Repository } from 'typeorm';
|
|||
|
|
import { Site } from './site.entity';
|
|||
|
|
import { UpdateSiteSettingsDto } from './site-settings.dto';
|
|||
|
|
|
|||
|
|
@Injectable()
|
|||
|
|
export class SiteSettingsService {
|
|||
|
|
constructor(
|
|||
|
|
@InjectRepository(Site)
|
|||
|
|
private readonly siteRepository: Repository<Site>,
|
|||
|
|
) {}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 获取站点设置
|
|||
|
|
*/
|
|||
|
|
async getSiteSettings() {
|
|||
|
|
// 获取默认站点(id = 1)
|
|||
|
|
const site = await this.siteRepository.findOne({
|
|||
|
|
where: { id: 1 },
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (!site) {
|
|||
|
|
// 如果没有找到站点,返回默认值
|
|||
|
|
return {
|
|||
|
|
site_name: 'WWJ Cloud',
|
|||
|
|
site_title: 'WWJ Cloud 企业级框架',
|
|||
|
|
site_keywords: 'WWJ Cloud,企业级框架,NestJS,VbenAdmin',
|
|||
|
|
site_description: 'WWJ Cloud 企业级框架 - 快速开发SAAS多用户系统后台管理框架',
|
|||
|
|
site_logo: '',
|
|||
|
|
site_favicon: '',
|
|||
|
|
icp_number: '',
|
|||
|
|
copyright: '',
|
|||
|
|
site_status: 1,
|
|||
|
|
close_reason: '',
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return {
|
|||
|
|
site_name: site.site_name || '',
|
|||
|
|
site_title: site.site_title || '',
|
|||
|
|
site_keywords: site.site_keywords || '',
|
|||
|
|
site_description: site.site_description || '',
|
|||
|
|
site_logo: site.site_logo || '',
|
|||
|
|
site_favicon: site.site_favicon || '',
|
|||
|
|
icp_number: site.icp_number || '',
|
|||
|
|
copyright: site.copyright || '',
|
|||
|
|
site_status: site.site_status || 1,
|
|||
|
|
close_reason: site.close_reason || '',
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 更新站点设置
|
|||
|
|
*/
|
|||
|
|
async updateSiteSettings(updateSiteSettingsDto: UpdateSiteSettingsDto) {
|
|||
|
|
const {
|
|||
|
|
site_name,
|
|||
|
|
site_title,
|
|||
|
|
site_keywords,
|
|||
|
|
site_description,
|
|||
|
|
site_logo,
|
|||
|
|
site_favicon,
|
|||
|
|
icp_number,
|
|||
|
|
copyright,
|
|||
|
|
site_status,
|
|||
|
|
close_reason,
|
|||
|
|
} = updateSiteSettingsDto;
|
|||
|
|
|
|||
|
|
// 查找或创建默认站点
|
|||
|
|
let site = await this.siteRepository.findOne({
|
|||
|
|
where: { id: 1 },
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (!site) {
|
|||
|
|
// 创建默认站点
|
|||
|
|
site = this.siteRepository.create({
|
|||
|
|
id: 1,
|
|||
|
|
site_name: site_name || 'WWJ Cloud',
|
|||
|
|
site_title: site_title || 'WWJ Cloud 企业级框架',
|
|||
|
|
site_keywords: site_keywords || '',
|
|||
|
|
site_description: site_description || '',
|
|||
|
|
site_logo: site_logo || '',
|
|||
|
|
site_favicon: site_favicon || '',
|
|||
|
|
icp_number: icp_number || '',
|
|||
|
|
copyright: copyright || '',
|
|||
|
|
site_status: site_status || 1,
|
|||
|
|
close_reason: close_reason || '',
|
|||
|
|
});
|
|||
|
|
} else {
|
|||
|
|
// 更新现有站点
|
|||
|
|
if (site_name !== undefined) site.site_name = site_name;
|
|||
|
|
if (site_title !== undefined) site.site_title = site_title;
|
|||
|
|
if (site_keywords !== undefined) site.site_keywords = site_keywords;
|
|||
|
|
if (site_description !== undefined) site.site_description = site_description;
|
|||
|
|
if (site_logo !== undefined) site.site_logo = site_logo;
|
|||
|
|
if (site_favicon !== undefined) site.site_favicon = site_favicon;
|
|||
|
|
if (icp_number !== undefined) site.icp_number = icp_number;
|
|||
|
|
if (copyright !== undefined) site.copyright = copyright;
|
|||
|
|
if (site_status !== undefined) site.site_status = site_status;
|
|||
|
|
if (close_reason !== undefined) site.close_reason = close_reason;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
await this.siteRepository.save(site);
|
|||
|
|
return { message: '站点设置更新成功' };
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* 重置站点设置为默认值
|
|||
|
|
*/
|
|||
|
|
async resetSiteSettings() {
|
|||
|
|
// 删除现有站点配置
|
|||
|
|
await this.siteRepository.delete({ id: 1 });
|
|||
|
|
|
|||
|
|
// 创建默认站点配置
|
|||
|
|
const defaultSite = this.siteRepository.create({
|
|||
|
|
id: 1,
|
|||
|
|
site_name: 'WWJ Cloud',
|
|||
|
|
site_title: 'WWJ Cloud 企业级框架',
|
|||
|
|
site_keywords: 'WWJ Cloud,企业级框架,NestJS,VbenAdmin',
|
|||
|
|
site_description: 'WWJ Cloud 企业级框架 - 快速开发SAAS多用户系统后台管理框架',
|
|||
|
|
site_logo: '',
|
|||
|
|
site_favicon: '',
|
|||
|
|
icp_number: '',
|
|||
|
|
copyright: '',
|
|||
|
|
site_status: 1,
|
|||
|
|
close_reason: '',
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
await this.siteRepository.save(defaultSite);
|
|||
|
|
return { message: '站点设置已重置为默认值' };
|
|||
|
|
}
|
|||
|
|
}
|