功能迭代
This commit is contained in:
1 parent
d1844ce9a2
commit
617371be3e
13 files changed
+884
-138
No files matched your search
@@ -8,4 +8,5 @@ public record StoreProfileAdminReq(
|
||||
/** 站点业务编号。 */ @NotBlank @Size(max = 16) String siteCode,
|
||||
/** 店铺名称。 */ @NotBlank @Size(max = 100) String storeName,
|
||||
/** 店铺描述。 */ @Size(max = 1000) String description,
|
||||
/** 店铺所属行业。 */ @NotBlank @Size(max = 100) String industry) {}
|
||||
/** 店铺所属行业。 */ @NotBlank @Size(max = 100) String industry,
|
||||
/** 店铺主域名,不含协议、端口和路径。 */ @Size(max = 255) String domain) {}
|
||||
@@ -1,4 +1,9 @@
|
||||
package com.shoplix.admin.modules.store.res;
|
||||
|
||||
/** 店铺基本信息响应。 */
|
||||
public record StoreProfileAdminRes(String siteCode, String storeName, String description, String industry) {}
|
||||
public record StoreProfileAdminRes(
|
||||
/** 站点业务编号。 */ String siteCode,
|
||||
/** 店铺名称。 */ String storeName,
|
||||
/** 店铺描述。 */ String description,
|
||||
/** 店铺所属行业。 */ String industry,
|
||||
/** 店铺主域名。 */ String domain) {}
|
||||
@@ -2,10 +2,20 @@ package com.shoplix.admin.service;
|
||||
|
||||
import com.shoplix.admin.modules.store.req.StoreProfileAdminReq;
|
||||
import com.shoplix.admin.modules.store.res.StoreProfileAdminRes;
|
||||
import com.shoplix.admin.store.StoreMessageKeys;
|
||||
import com.shoplix.common.exception.BusinessException;
|
||||
import com.shoplix.modules.account.repository.entity.AdminUserEntity;
|
||||
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
|
||||
import com.shoplix.common.utils.BusinessCodeUtils;
|
||||
import com.shoplix.modules.site.enums.SiteDomainStatusEnum;
|
||||
import com.shoplix.modules.site.repository.entity.SiteDomainEntity;
|
||||
import com.shoplix.modules.site.repository.entity.SiteEntity;
|
||||
import com.shoplix.modules.site.repository.service.SiteDomainRepositoryService;
|
||||
import com.shoplix.modules.site.repository.service.SiteRepositoryService;
|
||||
import java.net.IDN;
|
||||
import java.net.URI;
|
||||
import java.util.Locale;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -14,11 +24,19 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public class AdminStoreService {
|
||||
private final SiteRepositoryService repository;
|
||||
private final AdminSiteAccessService accessService;
|
||||
private final SiteDomainRepositoryService domainRepository;
|
||||
private final BusinessCodeUtils codes;
|
||||
private final MessageSource messageSource;
|
||||
|
||||
/** 注入站点数据源。 */
|
||||
public AdminStoreService(SiteRepositoryService repository, AdminSiteAccessService accessService) {
|
||||
public AdminStoreService(SiteRepositoryService repository, AdminSiteAccessService accessService,
|
||||
SiteDomainRepositoryService domainRepository, BusinessCodeUtils codes,
|
||||
MessageSource messageSource) {
|
||||
this.repository = repository;
|
||||
this.accessService = accessService;
|
||||
this.domainRepository = domainRepository;
|
||||
this.codes = codes;
|
||||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
/** 查询店铺基本信息。 */
|
||||
@@ -36,6 +54,7 @@ public class AdminStoreService {
|
||||
entity.setSiteDescription(request.description());
|
||||
entity.setIndustry(request.industry().trim());
|
||||
if (repository.updateProfile(entity) != 1) throw new BusinessException("STORE_PROFILE_UPDATE_FAILED", "店铺信息保存失败");
|
||||
saveDomain(request.siteCode(), request.domain());
|
||||
return toResponse(entity);
|
||||
}
|
||||
|
||||
@@ -51,6 +70,53 @@ public class AdminStoreService {
|
||||
|
||||
/** 转换店铺信息响应。 */
|
||||
private StoreProfileAdminRes toResponse(SiteEntity entity) {
|
||||
return new StoreProfileAdminRes(entity.getSiteCode(), entity.getSiteName(), entity.getSiteDescription(), entity.getIndustry());
|
||||
String domain = domainRepository.findPrimaryBySiteCode(entity.getSiteCode())
|
||||
.map(SiteDomainEntity::getDomain).orElse("");
|
||||
return new StoreProfileAdminRes(entity.getSiteCode(), entity.getSiteName(),
|
||||
entity.getSiteDescription(), entity.getIndustry(), domain);
|
||||
}
|
||||
|
||||
/** 保存规范化后的站点主域名。 */
|
||||
private void saveDomain(String siteCode, String input) {
|
||||
String domain = normalizeDomain(input);
|
||||
if (domain.isBlank()) return;
|
||||
if (domainRepository.existsByDomainExcludingSite(domain, siteCode)) {
|
||||
throw exception("STORE_DOMAIN_EXISTS", StoreMessageKeys.DOMAIN_EXISTS);
|
||||
}
|
||||
SiteDomainEntity entity = domainRepository.findPrimaryBySiteCode(siteCode).orElseGet(() -> {
|
||||
SiteDomainEntity created = new SiteDomainEntity();
|
||||
created.setDomainCode(codes.generate(BusinessCodePrefixEnum.DOMAIN));
|
||||
created.setSiteCode(siteCode);
|
||||
created.setPrimaryFlag(1);
|
||||
created.setForceHttps(1);
|
||||
created.setStatus(SiteDomainStatusEnum.ENABLED.name());
|
||||
created.setDeleted(0);
|
||||
return created;
|
||||
});
|
||||
entity.setDomain(domain);
|
||||
int rows = entity.getId() == null ? domainRepository.insert(entity) : domainRepository.updatePrimary(entity);
|
||||
if (rows != 1) throw exception("STORE_DOMAIN_UPDATE_FAILED", StoreMessageKeys.DOMAIN_SAVE_FAILED);
|
||||
}
|
||||
|
||||
/** 将输入规范化为不含协议、端口和路径的 ASCII 小写域名。 */
|
||||
private String normalizeDomain(String input) {
|
||||
if (input == null || input.isBlank()) return "";
|
||||
try {
|
||||
String value = input.trim();
|
||||
URI uri = URI.create(value.contains("://") ? value : "https://" + value);
|
||||
String host = uri.getHost();
|
||||
if (host == null || host.isBlank() || host.contains("_") || host.startsWith(".") || host.endsWith(".")) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return IDN.toASCII(host).toLowerCase(Locale.ROOT);
|
||||
} catch (IllegalArgumentException exception) {
|
||||
throw exception("STORE_DOMAIN_INVALID", StoreMessageKeys.DOMAIN_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
/** 创建已完成多语言解析的店铺业务异常。 */
|
||||
private BusinessException exception(String code, String key) {
|
||||
return new BusinessException(code,
|
||||
messageSource.getMessage(key, null, LocaleContextHolder.getLocale()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.shoplix.admin.store;
|
||||
|
||||
/** 店铺信息多语言消息键。 */
|
||||
public final class StoreMessageKeys {
|
||||
/** 禁止实例化。 */ private StoreMessageKeys() { }
|
||||
/** 域名已被其他店铺绑定。 */ public static final String DOMAIN_EXISTS = "store.domain.exists";
|
||||
/** 域名保存失败。 */ public static final String DOMAIN_SAVE_FAILED = "store.domain.save-failed";
|
||||
/** 域名格式错误。 */ public static final String DOMAIN_INVALID = "store.domain.invalid";
|
||||
}
|
||||
@@ -17,3 +17,6 @@ site.membership-create-failed=Failed to grant access to the new site.
|
||||
crm.customer.not-found=Customer not found
|
||||
crm.customer.save-failed=Failed to save customer
|
||||
crm.tag.save-failed=Failed to save customer tag
|
||||
store.domain.exists=This domain is already bound to another store
|
||||
store.domain.save-failed=Failed to save the store domain
|
||||
store.domain.invalid=Enter a valid domain, for example www.example.com
|
||||
@@ -17,3 +17,6 @@ site.membership-create-failed=新站点访问权限创建失败。
|
||||
crm.customer.not-found=客户不存在
|
||||
crm.customer.save-failed=客户保存失败
|
||||
crm.tag.save-failed=客户标签保存失败
|
||||
store.domain.exists=该域名已绑定其他店铺
|
||||
store.domain.save-failed=店铺域名保存失败
|
||||
store.domain.invalid=请输入有效域名,例如 www.example.com
|
||||
@@ -17,3 +17,6 @@ site.membership-create-failed=新站點存取權限建立失敗。
|
||||
crm.customer.not-found=客戶不存在
|
||||
crm.customer.save-failed=客戶儲存失敗
|
||||
crm.tag.save-failed=客戶標籤儲存失敗
|
||||
store.domain.exists=該網域已綁定其他店鋪
|
||||
store.domain.save-failed=店鋪網域儲存失敗
|
||||
store.domain.invalid=請輸入有效網域,例如 www.example.com
|
||||
Reference in new issue
Block a user