feat(cms): 增加克隆来源租户UID字段与逻辑支持

- CmsWebsite实体新增cloneTenantId字段,作为克隆来源租户UID记录
- 修改version字段描述,增加体验版版本说明
- CmsWebsiteMapper新增cloneTenantId的XML映射支持
- CmsWebsiteServiceImpl改用cloneTenantId作为内容克隆依据,区分templateId用途
- 添加幂等SQL脚本,动态添加clone_tenant_id列以兼容不同MySQL版本
- 保证cloneTenantId记录建站时sys_user.template_id,便于后端按模板分类和内容复制
This commit is contained in:
2026-08-13 18:19:32 +08:00
parent e1a93c1496
commit 09a8300064
4 changed files with 34 additions and 3 deletions
@@ -89,7 +89,7 @@ public class CmsWebsite implements Serializable {
@Schema(description = "自定义API接口") @Schema(description = "自定义API接口")
private String apiUrl; private String apiUrl;
@Schema(description = "应用版本 10免费版 20授权版 30永久授权") @Schema(description = "应用版本 0体验版 10基础版 20授权版 30永久授权")
private Integer version; private Integer version;
@Schema(description = "服务到期时间") @Schema(description = "服务到期时间")
@@ -117,6 +117,9 @@ public class CmsWebsite implements Serializable {
@TableField(exist = false) @TableField(exist = false)
private String templateName; private String templateName;
@Schema(description = "克隆来源租户UID(建站时据此复制参考租户内容;值为 sys_user.template_id,后端据此按模板分类)")
private Integer cloneTenantId;
@Schema(description = "是否初始化示例数据(仅 create 入参使用,不落库;true=生成标准示例栏目与内容,false=空白骨架,null=沿用模板克隆历史行为)") @Schema(description = "是否初始化示例数据(仅 create 入参使用,不落库;true=生成标准示例栏目与内容,false=空白骨架,null=沿用模板克隆历史行为)")
@TableField(exist = false) @TableField(exist = false)
private Boolean initDemoData; private Boolean initDemoData;
@@ -210,6 +210,9 @@
<if test="param.templateId != null"> <if test="param.templateId != null">
template_id = #{param.templateId}, template_id = #{param.templateId},
</if> </if>
<if test="param.cloneTenantId != null">
clone_tenant_id = #{param.cloneTenantId},
</if>
<if test="param.companyId != null"> <if test="param.companyId != null">
company_id = #{param.companyId}, company_id = #{param.companyId},
</if> </if>
@@ -199,7 +199,9 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
website.setUserId(loginUser.getUserId()); website.setUserId(loginUser.getUserId());
website.setDeveloper(loginUser.getNickname()); website.setDeveloper(loginUser.getNickname());
website.setTenantId(loginUser.getTenantId()); website.setTenantId(loginUser.getTenantId());
website.setTemplateId(loginUser.getTemplateId()); // 克隆来源租户UID = sys_user.template_id(注册时选定的模板租户),写入独立字段 cloneTenantId
// 供后端按模板分类;同时作为内容克隆来源。template_id 留给 /templates 模板选择器写入。
website.setCloneTenantId(loginUser.getTemplateId());
website.setCompanyId(loginUser.getCompanyId()); website.setCompanyId(loginUser.getCompanyId());
// 默认运行中:status(后台枚举)与 runninggetSiteInfo 状态展示用)保持一致, // 默认运行中:status(后台枚举)与 runninggetSiteInfo 状态展示用)保持一致,
@@ -235,7 +237,8 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
// cmsWebsiteSettingService.save(setting); // cmsWebsiteSettingService.save(setting);
// 将网站创建者的userId做为查询条件 10257(4716),10324(6978),10398(26564) // 将网站创建者的userId做为查询条件 10257(4716),10324(6978),10398(26564)
Integer websiteUserId = website.getTemplateId(); // 克隆来源 = cloneTenantId=sys_user.template_id),据此复制参考租户的内容
Integer websiteUserId = website.getCloneTenantId();
// 只有当templateId存在时才执行复制操作 // 只有当templateId存在时才执行复制操作
if (websiteUserId != null && websiteUserId > 0) { if (websiteUserId != null && websiteUserId > 0) {
@@ -0,0 +1,22 @@
-- cms_website 补 clone_tenant_id 列(幂等版,兼容 MySQL 5.7 / 8.0
-- 该列用于记录"克隆来源租户UID(=sys_user.template_id)",建站时写入,
-- 供后端按模板分类站点,并作为内容克隆来源。
-- 注:生产 modules.cms_website 通常已存在该列(websopy 建站写入),
-- 本脚本仅作为安全网,缺列才补,可重复执行。
-- 通过存储过程判断存在性,已存在则跳过;
-- 需在支持 DELIMITER 的客户端执行(mysql CLI、Navicat、MySQL Workbench 等)。
DELIMITER $$
DROP PROCEDURE IF EXISTS `add_cms_website_clone_tenant_id`$$
CREATE PROCEDURE `add_cms_website_clone_tenant_id`()
BEGIN
IF NOT EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='modules' AND TABLE_NAME='cms_website' AND COLUMN_NAME='clone_tenant_id') THEN
ALTER TABLE `cms_website` ADD COLUMN `clone_tenant_id` INT NULL COMMENT '克隆来源租户UID(=sys_user.template_id,建站时写入,供后端按模板分类)' AFTER `template_id`;
END IF;
END$$
DELIMITER ;
CALL `add_cms_website_clone_tenant_id`();
DROP PROCEDURE IF EXISTS `add_cms_website_clone_tenant_id`;