2025-08-24 02:31:42 +08:00
|
|
|
|
import { Injectable } from '@nestjs/common';
|
2025-08-23 13:20:01 +08:00
|
|
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
|
|
import { Repository } from 'typeorm';
|
|
|
|
|
|
import { Site } from './site.entity';
|
|
|
|
|
|
import { UpdateSiteSettingsDto } from './site-settings.dto';
|
refactor: 全面清理项目结构,优化代码组织
主要变更:
1. 清理Core层空壳目录
- 删除traits, transformers, query, entities等空目录
- 删除security, http, queue, logger, context, exception, cache, utils, interceptor等空模块
- 修复core/index.ts中的模块引用
2. 清理Common层冗余模块
- 删除utils, cache, queue, health, openapi等空壳模块
- 删除dictionary, dict等重复字典模块
- 删除重复的MemberModule.ts文件
- 移动config到config/common目录
3. 优化项目结构
- 保留业务逻辑模块:auth, member, rbac, admin, settings, upload, notification
- 统一命名规范:所有模块使用{模块名}.module.ts格式
- 修复导入路径和模块引用
4. 代码质量提升
- 删除所有空壳和重复代码
- 项目结构更清晰,符合NestJS最佳实践
- 打包测试通过,代码更干净整洁
清理后项目结构:
- config/: 配置层(基础设施)
- core/: 核心层(数据库、枚举、验证)
- common/: 业务逻辑层
- vendor/: 第三方服务
2025-08-24 02:54:27 +08:00
|
|
|
|
import { DEFAULT_SITE_CONFIG, SYSTEM_CONSTANTS } from '../../../config/common/constants';
|
2025-08-23 13:20:01 +08:00
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
|
export class SiteSettingsService {
|
|
|
|
|
|
constructor(
|
|
|
|
|
|
@InjectRepository(Site)
|
|
|
|
|
|
private readonly siteRepository: Repository<Site>,
|
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取站点设置
|
|
|
|
|
|
*/
|
|
|
|
|
|
async getSiteSettings() {
|
|
|
|
|
|
// 获取默认站点(id = 1)
|
|
|
|
|
|
const site = await this.siteRepository.findOne({
|
2025-08-24 02:31:42 +08:00
|
|
|
|
where: { site_id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID },
|
2025-08-23 13:20:01 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (!site) {
|
|
|
|
|
|
// 如果没有找到站点,返回默认值
|
2025-08-24 02:31:42 +08:00
|
|
|
|
return { ...DEFAULT_SITE_CONFIG };
|
2025-08-23 13:20:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
2025-08-24 02:31:42 +08:00
|
|
|
|
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,
|
2025-08-23 13:20:01 +08:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 更新站点设置
|
|
|
|
|
|
*/
|
|
|
|
|
|
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({
|
2025-08-24 02:31:42 +08:00
|
|
|
|
where: { id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID },
|
2025-08-23 13:20:01 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (!site) {
|
|
|
|
|
|
// 创建默认站点
|
|
|
|
|
|
site = this.siteRepository.create({
|
2025-08-24 02:31:42 +08:00
|
|
|
|
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,
|
2025-08-23 13:20:01 +08:00
|
|
|
|
});
|
|
|
|
|
|
} 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() {
|
|
|
|
|
|
// 删除现有站点配置
|
2025-08-24 02:31:42 +08:00
|
|
|
|
await this.siteRepository.delete({ id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID });
|
2025-08-23 13:20:01 +08:00
|
|
|
|
|
|
|
|
|
|
// 创建默认站点配置
|
|
|
|
|
|
const defaultSite = this.siteRepository.create({
|
2025-08-24 02:31:42 +08:00
|
|
|
|
id: SYSTEM_CONSTANTS.DEFAULT_SITE_ID,
|
|
|
|
|
|
...DEFAULT_SITE_CONFIG,
|
2025-08-23 13:20:01 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
await this.siteRepository.save(defaultSite);
|
2025-08-24 02:31:42 +08:00
|
|
|
|
return { message: '站点设置重置成功' };
|
2025-08-23 13:20:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|