diff --git a/src/main/java/com/gxwebsoft/cms/entity/CmsWebsite.java b/src/main/java/com/gxwebsoft/cms/entity/CmsWebsite.java index 01b4293..a2c87d3 100644 --- a/src/main/java/com/gxwebsoft/cms/entity/CmsWebsite.java +++ b/src/main/java/com/gxwebsoft/cms/entity/CmsWebsite.java @@ -117,6 +117,10 @@ public class CmsWebsite implements Serializable { @TableField(exist = false) private String templateName; + @Schema(description = "是否初始化示例数据(仅 create 入参使用,不落库;true=生成标准示例栏目与内容,false=空白骨架,null=沿用模板克隆历史行为)") + @TableField(exist = false) + private Boolean initDemoData; + @Schema(description = "行业类型(父级)") private String industryParent; diff --git a/src/main/java/com/gxwebsoft/cms/service/impl/CmsWebsiteServiceImpl.java b/src/main/java/com/gxwebsoft/cms/service/impl/CmsWebsiteServiceImpl.java index 833f811..c9e398f 100644 --- a/src/main/java/com/gxwebsoft/cms/service/impl/CmsWebsiteServiceImpl.java +++ b/src/main/java/com/gxwebsoft/cms/service/impl/CmsWebsiteServiceImpl.java @@ -19,7 +19,9 @@ import com.gxwebsoft.shop.vo.ShopVo; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.math.BigDecimal; import java.time.LocalDateTime; +import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; @@ -69,6 +71,12 @@ public class CmsWebsiteServiceImpl extends ServiceImpl parents = cmsNavigationMapper.selectListAllRel(cmsNavigationParam); - parents.forEach(d -> { - Integer navigationId = d.getNavigationId(); - // 复制顶级栏目 - d.setTenantId(loginUser.getTenantId()); - d.setUserId(loginUser.getUserId()); - if (cmsNavigationService.save(d)) { - cmsNavigationService.saveAsync(d); - // 复制栏目文章 - CmsArticleParam cmsArticleParam = new CmsArticleParam(); - cmsArticleParam.setWebsiteUserId(websiteUserId); - cmsArticleParam.setCategoryId(navigationId); - final List articles = cmsArticleMapper.selectListAllRel(cmsArticleParam); - articles.forEach(a -> { - a.setCategoryId(d.getNavigationId()); - a.setUserId(loginUser.getUserId()); - a.setTenantId(loginUser.getTenantId()); - if (cmsArticleService.save(a)) { - final CmsArticleContent content = new CmsArticleContent(); - content.setArticleId(a.getArticleId()); - content.setContent(a.getContent()); - cmsArticleContentService.save(content); - } - }); - // 复制子栏目 - cmsNavigationParam.setParentId(navigationId); - final List navigations = cmsNavigationMapper.selectListAllRel(cmsNavigationParam); - navigations.forEach(c -> { - cmsArticleParam.setCategoryId(c.getNavigationId()); - c.setParentId(d.getNavigationId()); - c.setTenantId(loginUser.getTenantId()); - c.setUserId(loginUser.getUserId()); - cmsNavigationService.save(c); - cmsNavigationService.saveAsync(c); - // 复制子栏目文章 - final List articles2 = cmsArticleMapper.selectListAllRel(cmsArticleParam); - articles2.forEach(a2 -> { - a2.setCategoryId(c.getNavigationId()); - a2.setParentId(c.getParentId()); - a2.setUserId(loginUser.getUserId()); - a2.setTenantId(loginUser.getTenantId()); - if (cmsArticleService.save(a2)) { - final CmsArticleContent content = new CmsArticleContent(); - content.setArticleId(a2.getArticleId()); - content.setContent(a2.getContent()); - cmsArticleContentService.save(content); - } - }); - }); - } - }); + // 栏目与内容初始化:按 initDemoData 决定分支 + if (Boolean.TRUE.equals(website.getInitDemoData())) { + // 注册流程勾选「填充示例内容」:生成标准示例栏目与内容(不克隆模板,避免千篇一律) + initDemoData(website, loginUser); + } else if (Boolean.FALSE.equals(website.getInitDemoData())) { + // 注册流程明确不勾选:仅保留基础配置克隆,跳过栏目与文章,站点保持空白骨架 + log.info("initDemoData=false,跳过示例内容生成,站点保持空白骨架, tenantId={}", loginUser.getTenantId()); + } else { + // 历史行为(后台手动建站等未传 initDemoData):克隆模板栏目与文章 + cloneTemplateContent(website, loginUser, websiteUserId); + } } else { log.warn("没有有效的模板ID,跳过复制操作"); } @@ -608,4 +572,218 @@ public class CmsWebsiteServiceImpl extends ServiceImpl parents = cmsNavigationMapper.selectListAllRel(cmsNavigationParam); + parents.forEach(d -> { + Integer navigationId = d.getNavigationId(); + d.setTenantId(loginUser.getTenantId()); + d.setUserId(loginUser.getUserId()); + if (cmsNavigationService.save(d)) { + cmsNavigationService.saveAsync(d); + CmsArticleParam cmsArticleParam = new CmsArticleParam(); + cmsArticleParam.setWebsiteUserId(websiteUserId); + cmsArticleParam.setCategoryId(navigationId); + final List articles = cmsArticleMapper.selectListAllRel(cmsArticleParam); + articles.forEach(a -> { + a.setCategoryId(d.getNavigationId()); + a.setUserId(loginUser.getUserId()); + a.setTenantId(loginUser.getTenantId()); + if (cmsArticleService.save(a)) { + CmsArticleContent content = new CmsArticleContent(); + content.setArticleId(a.getArticleId()); + content.setContent(a.getContent()); + cmsArticleContentService.save(content); + } + }); + cmsNavigationParam.setParentId(navigationId); + final List navigations = cmsNavigationMapper.selectListAllRel(cmsNavigationParam); + navigations.forEach(c -> { + cmsArticleParam.setCategoryId(c.getNavigationId()); + c.setParentId(d.getNavigationId()); + c.setTenantId(loginUser.getTenantId()); + c.setUserId(loginUser.getUserId()); + cmsNavigationService.save(c); + cmsNavigationService.saveAsync(c); + final List articles2 = cmsArticleMapper.selectListAllRel(cmsArticleParam); + articles2.forEach(a2 -> { + a2.setCategoryId(c.getNavigationId()); + a2.setParentId(c.getParentId()); + a2.setUserId(loginUser.getUserId()); + a2.setTenantId(loginUser.getTenantId()); + if (cmsArticleService.save(a2)) { + CmsArticleContent content = new CmsArticleContent(); + content.setArticleId(a2.getArticleId()); + content.setContent(a2.getContent()); + cmsArticleContentService.save(content); + } + }); + }); + } + }); + } + + /** 构造一个顶部导航栏目 */ + private CmsNavigation buildNav(String title, String model, String path, int sort, int type, + Integer tenantId, Integer userId) { + CmsNavigation nav = new CmsNavigation(); + nav.setTitle(title); + nav.setModel(model); + nav.setPath(path); + nav.setType(type); + nav.setParentId(0); + nav.setTop(1); + nav.setBottom(0); + nav.setPosition(1); + nav.setHide(0); + nav.setStatus(0); + nav.setSortNumber(sort); + nav.setTenantId(tenantId); + nav.setUserId(userId); + return nav; + } + + /** 生成关于我们单页正文(富文本 HTML) */ + private String buildAboutContent(String companyName) { + return "

欢迎来到 " + companyName + "!我们是一家专注于为企业提供数字化解决方案的服务商。

" + + "

自成立以来," + companyName + "始终以客户成功为中心,围绕官网建设、内容管理与营销增长等场景," + + "提供从咨询、设计到落地运营的一站式服务。

" + + "

我们的团队由资深产品、设计与技术专家组成,已为众多行业客户交付稳定可靠的数字平台。" + + "期待与您携手,共创更大价值。

"; + } }