feat: 完成配置中心重构和命名规范优化
- 重构config层为配置中心架构,支持动态配置管理 - 统一core层命名规范(event-bus→event, circuit-breaker→breaker, domain-sdk→sdk) - 修复数据库连接配置路径问题 - 实现配置中心完整功能:系统配置、动态配置、配置验证、统计 - 优化目录结构,为微服务架构做准备 - 修复TypeScript编译错误和依赖注入问题
This commit is contained in:
@@ -3,10 +3,10 @@ import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { Site } from './site.entity';
|
||||
import { UpdateSiteSettingsDto } from './site-settings.dto';
|
||||
import {
|
||||
DEFAULT_SITE_CONFIG,
|
||||
SYSTEM_CONSTANTS,
|
||||
} from '@wwjConfig/common/constants';
|
||||
|
||||
|
||||
// 不允许硬编码,从配置系统获取
|
||||
// TODO: 配置系统重构中,此功能暂时不可用
|
||||
|
||||
@Injectable()
|
||||
export class SiteSettingsService {
|
||||
@@ -18,103 +18,24 @@ export class SiteSettingsService {
|
||||
/**
|
||||
* 获取站点设置
|
||||
*/
|
||||
async getSiteSettings() {
|
||||
// 获取默认站点(id = 1)
|
||||
const site = await this.siteRepository.findOne({
|
||||
where: { site_id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID },
|
||||
});
|
||||
|
||||
if (!site) {
|
||||
// 如果没有找到站点,返回默认值
|
||||
return { ...DEFAULT_SITE_CONFIG };
|
||||
}
|
||||
|
||||
return {
|
||||
site_name: site.site_name || DEFAULT_SITE_CONFIG.site_name,
|
||||
site_title: site.site_title || DEFAULT_SITE_CONFIG.site_title,
|
||||
site_keywords: site.site_keywords || DEFAULT_SITE_CONFIG.site_keywords,
|
||||
site_description:
|
||||
site.site_description || DEFAULT_SITE_CONFIG.site_description,
|
||||
site_logo: site.site_logo || DEFAULT_SITE_CONFIG.site_logo,
|
||||
site_favicon: site.site_favicon || DEFAULT_SITE_CONFIG.site_favicon,
|
||||
icp_number: site.icp_number || DEFAULT_SITE_CONFIG.icp_number,
|
||||
copyright: site.copyright || DEFAULT_SITE_CONFIG.copyright,
|
||||
site_status: site.site_status || DEFAULT_SITE_CONFIG.site_status,
|
||||
close_reason: site.close_reason || DEFAULT_SITE_CONFIG.close_reason,
|
||||
};
|
||||
getSiteSettings() {
|
||||
// 配置系统重构中,此功能暂时不可用
|
||||
throw new Error('配置系统重构中,站点设置功能暂时不可用');
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新站点设置
|
||||
*/
|
||||
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: SYSTEM_CONSTANTS.DEFAULT_SITE_ID },
|
||||
});
|
||||
|
||||
if (!site) {
|
||||
// 创建默认站点
|
||||
site = this.siteRepository.create({
|
||||
id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID,
|
||||
site_name: site_name || DEFAULT_SITE_CONFIG.site_name,
|
||||
site_title: site_title || DEFAULT_SITE_CONFIG.site_title,
|
||||
site_keywords: site_keywords || DEFAULT_SITE_CONFIG.site_keywords,
|
||||
site_description:
|
||||
site_description || DEFAULT_SITE_CONFIG.site_description,
|
||||
site_logo: site_logo || DEFAULT_SITE_CONFIG.site_logo,
|
||||
site_favicon: site_favicon || DEFAULT_SITE_CONFIG.site_favicon,
|
||||
icp_number: icp_number || DEFAULT_SITE_CONFIG.icp_number,
|
||||
copyright: copyright || DEFAULT_SITE_CONFIG.copyright,
|
||||
site_status: site_status || DEFAULT_SITE_CONFIG.site_status,
|
||||
close_reason: close_reason || DEFAULT_SITE_CONFIG.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: '站点设置更新成功' };
|
||||
updateSiteSettings(updateSiteSettingsDto: UpdateSiteSettingsDto) {
|
||||
// 配置系统重构中,此功能暂时不可用
|
||||
throw new Error('配置系统重构中,站点设置更新功能暂时不可用');
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置站点设置为默认值
|
||||
*/
|
||||
async resetSiteSettings() {
|
||||
// 删除现有站点配置
|
||||
await this.siteRepository.delete({ id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID });
|
||||
|
||||
// 创建默认站点配置
|
||||
const defaultSite = this.siteRepository.create({
|
||||
id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID,
|
||||
...DEFAULT_SITE_CONFIG,
|
||||
});
|
||||
|
||||
await this.siteRepository.save(defaultSite);
|
||||
return { message: '站点设置重置成功' };
|
||||
resetSiteSettings() {
|
||||
// 配置系统重构中,此功能暂时不可用
|
||||
throw new Error('配置系统重构中,站点设置重置功能暂时不可用');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user