feat(cms): 同步域名到租户表保证一致性

- 在保存网站信息后同步 cms_website.domain 到 company.app_domain 字段
- 去除域名前缀的 http(s):// 以保持与前端处理一致
- 添加异常捕获,防止同步失败影响主流程
- 通过 tenantId 关联查询对应租户公司信息并更新域名字段
- 记录同步失败的警告日志,便于问题排查
This commit is contained in:
2026-08-06 19:51:05 +08:00
parent ed963b7a40
commit 9a905268e6

View File

@@ -9,6 +9,7 @@ import com.gxwebsoft.common.core.utils.JSONUtil;
import com.gxwebsoft.common.core.utils.RedisUtil; import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.Company;
import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.service.CompanyService; import com.gxwebsoft.common.system.service.CompanyService;
import com.gxwebsoft.common.system.service.UserService; import com.gxwebsoft.common.system.service.UserService;
@@ -204,6 +205,21 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
// 初始化数据 // 初始化数据
if(save(website)){ if(save(website)){
// 同步域名到 company.app_domainwebsopy 租户表),保证 cms_website.domain 与 app_domain 一致
if (StrUtil.isNotBlank(website.getDomain())) {
try {
Company company = companyService.getByTenantIdRel(loginUser.getTenantId());
if (company != null) {
// 去掉 http(s):// 前缀,与前端处理保持一致
String cleanDomain = website.getDomain().replaceFirst("^(https?://)", "");
company.setDomain(cleanDomain);
companyService.updateById(company);
}
} catch (Exception e) {
log.warn("同步域名到 company 失败, tenantId={}", loginUser.getTenantId(), e);
}
}
// 插入网站设置记录 // 插入网站设置记录
// final CmsWebsiteSetting setting = new CmsWebsiteSetting(); // final CmsWebsiteSetting setting = new CmsWebsiteSetting();
// setting.setWebsiteId(website.getWebsiteId()); // setting.setWebsiteId(website.getWebsiteId());