bug修复

This commit is contained in:
张锐 committed 2026-11-25 20:46:36 +08:00
1 parent 7fed799118
commit eae135ec88
37 files changed
+866 -27

No files matched your search

@@ -0,0 +1,40 @@
package com.shoplix.admin.controller;
import com.shoplix.admin.modules.common.res.CommonAdminRes;
import com.shoplix.admin.modules.social.req.SaveSocialChannelsAdminReq;
import com.shoplix.admin.modules.social.req.SocialChannelListAdminReq;
import com.shoplix.admin.modules.social.res.SocialChannelListAdminRes;
import com.shoplix.admin.service.AdminSocialChannelService;
import jakarta.validation.Valid;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** 运营后台社媒渠道配置接口。 */
@RestController
@RequestMapping("/api/admin/v1/social-channels")
public class AdminSocialChannelController {
private final AdminSocialChannelService service;
/** 注入社媒渠道配置业务。 */
public AdminSocialChannelController(AdminSocialChannelService service) {
this.service = service;
}
/** 查询当前站点社媒渠道配置。 */
@PostMapping("/list")
public SocialChannelListAdminRes list(@Valid @RequestBody SocialChannelListAdminReq request,
Authentication authentication) {
return service.list(authentication.getName(), request.siteCode());
}
/** 保存当前站点社媒渠道配置。 */
@PostMapping("/save")
public CommonAdminRes save(@Valid @RequestBody SaveSocialChannelsAdminReq request,
Authentication authentication) {
service.save(authentication.getName(), request);
return CommonAdminRes.success();
}
}
@@ -0,0 +1,14 @@
package com.shoplix.admin.modules.social.req;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.util.List;
/** 保存后台社媒渠道配置请求。 */
public record SaveSocialChannelsAdminReq(
/** 站点业务编号。 */ @NotBlank @Size(max = 16) String siteCode,
/** 社媒渠道配置列表。 */ @NotNull @Size(max = 11) List<@Valid SocialChannelAdminReq> items) {
}
@@ -0,0 +1,19 @@
package com.shoplix.admin.modules.social.req;
import com.shoplix.modules.social.enums.SocialPlatformEnum;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
/** 后台社媒渠道配置项请求。 */
public record SocialChannelAdminReq(
/** 社媒平台。 */ @NotNull SocialPlatformEnum platform,
/** 前台展示名称。 */ @NotBlank @Size(max = 100) String displayName,
/** 社媒主页或联系地址。 */ @NotBlank @Size(max = 1000) String profileUrl,
/** 是否在产品详情显示分享入口。 */ @NotNull Boolean shareEnabled,
/** 是否在全站显示悬浮入口。 */ @NotNull Boolean floatingEnabled,
/** 是否启用渠道。 */ @NotNull Boolean enabled,
/** 展示排序值。 */ @NotNull @Min(0) @Max(9999) Integer sortNo) {
}
@@ -0,0 +1,9 @@
package com.shoplix.admin.modules.social.req;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
/** 查询后台社媒渠道请求。 */
public record SocialChannelListAdminReq(
/** 站点业务编号。 */ @NotBlank @Size(max = 16) String siteCode) {
}
@@ -0,0 +1,13 @@
package com.shoplix.admin.modules.social.res;
/** 后台社媒渠道配置项响应。 */
public record SocialChannelAdminRes(
/** 渠道业务编号。 */ String channelCode,
/** 社媒平台枚举值。 */ String platform,
/** 前台展示名称。 */ String displayName,
/** 社媒主页或联系地址。 */ String profileUrl,
/** 是否在产品详情显示分享入口。 */ Boolean shareEnabled,
/** 是否在全站显示悬浮入口。 */ Boolean floatingEnabled,
/** 是否启用渠道。 */ Boolean enabled,
/** 展示排序值。 */ Integer sortNo) {
}
@@ -0,0 +1,8 @@
package com.shoplix.admin.modules.social.res;
import java.util.List;
/** 后台社媒渠道配置列表响应。 */
public record SocialChannelListAdminRes(
/** 社媒渠道配置列表。 */ List<SocialChannelAdminRes> items) {
}
@@ -0,0 +1,94 @@
package com.shoplix.admin.service;
import com.shoplix.admin.modules.social.req.SaveSocialChannelsAdminReq;
import com.shoplix.admin.modules.social.res.SocialChannelAdminRes;
import com.shoplix.admin.modules.social.res.SocialChannelListAdminRes;
import com.shoplix.admin.social.SocialMessageKeys;
import com.shoplix.common.code.enums.BusinessCodePrefixEnum;
import com.shoplix.common.exception.BusinessException;
import com.shoplix.common.utils.BusinessCodeUtils;
import com.shoplix.modules.account.repository.service.AdminUserRepositoryService;
import com.shoplix.modules.social.repository.entity.SocialChannelEntity;
import com.shoplix.modules.social.repository.service.SocialChannelRepositoryService;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashSet;
import java.util.Set;
/** 运营后台社媒渠道配置业务。 */
@Service
public class AdminSocialChannelService {
private final SocialChannelRepositoryService repository;
private final AdminUserRepositoryService accountRepository;
private final BusinessCodeUtils codeUtils;
private final MessageSource messageSource;
/** 注入社媒渠道配置依赖。 */
public AdminSocialChannelService(SocialChannelRepositoryService repository,
AdminUserRepositoryService accountRepository,
BusinessCodeUtils codeUtils,
MessageSource messageSource) {
this.repository = repository;
this.accountRepository = accountRepository;
this.codeUtils = codeUtils;
this.messageSource = messageSource;
}
/** 查询当前管理员站点的社媒渠道。 */
public SocialChannelListAdminRes list(String userCode, String siteCode) {
validateSiteOwnership(userCode, siteCode);
return new SocialChannelListAdminRes(repository.list(siteCode, false).stream().map(this::toResponse).toList());
}
/** 原子替换当前站点的社媒渠道配置。 */
@Transactional
public void save(String userCode, SaveSocialChannelsAdminReq request) {
validateSiteOwnership(userCode, request.siteCode());
Set<String> platforms = new HashSet<>();
request.items().forEach(item -> {
if (!platforms.add(item.platform().name())) {
throw businessException("SOCIAL_CHANNEL_PLATFORM_DUPLICATED", SocialMessageKeys.PLATFORM_DUPLICATED);
}
});
repository.deleteBySite(request.siteCode());
for (var item : request.items()) {
SocialChannelEntity entity = new SocialChannelEntity();
entity.setChannelCode(codeUtils.generate(BusinessCodePrefixEnum.SOCIAL_CHANNEL));
entity.setSiteCode(request.siteCode());
entity.setPlatform(item.platform().name());
entity.setDisplayName(item.displayName().trim());
entity.setProfileUrl(item.profileUrl().trim());
entity.setShareEnabled(Boolean.TRUE.equals(item.shareEnabled()) ? 1 : 0);
entity.setFloatingEnabled(Boolean.TRUE.equals(item.floatingEnabled()) ? 1 : 0);
entity.setEnabled(Boolean.TRUE.equals(item.enabled()) ? 1 : 0);
entity.setSortNo(item.sortNo());
if (repository.insert(entity) != 1) {
throw businessException("SOCIAL_CHANNEL_SAVE_FAILED", SocialMessageKeys.SAVE_FAILED);
}
}
}
/** 校验当前管理员是否归属目标站点。 */
private void validateSiteOwnership(String userCode, String siteCode) {
var account = accountRepository.findByCode(userCode)
.orElseThrow(() -> businessException("ACCOUNT_NOT_FOUND", SocialMessageKeys.ACCOUNT_NOT_FOUND));
if (!siteCode.equals(account.getSiteCode())) {
throw businessException("SOCIAL_CHANNEL_ACCESS_DENIED", SocialMessageKeys.ACCESS_DENIED);
}
}
/** 创建已完成多语言解析的业务异常。 */
private BusinessException businessException(String code, String messageKey) {
return new BusinessException(code, messageSource.getMessage(messageKey, null, LocaleContextHolder.getLocale()));
}
/** 转换后台社媒渠道响应。 */
private SocialChannelAdminRes toResponse(SocialChannelEntity entity) {
return new SocialChannelAdminRes(entity.getChannelCode(), entity.getPlatform(), entity.getDisplayName(),
entity.getProfileUrl(), entity.getShareEnabled() == 1, entity.getFloatingEnabled() == 1,
entity.getEnabled() == 1, entity.getSortNo());
}
}
@@ -0,0 +1,13 @@
package com.shoplix.admin.social;
/** 社媒渠道多语言消息键。 */
public final class SocialMessageKeys {
/** 平台配置重复。 */ public static final String PLATFORM_DUPLICATED = "social.channel.platform.duplicated";
/** 渠道保存失败。 */ public static final String SAVE_FAILED = "social.channel.save.failed";
/** 店铺访问无权限。 */ public static final String ACCESS_DENIED = "social.channel.access.denied";
/** 管理员账户不存在。 */ public static final String ACCOUNT_NOT_FOUND = "social.channel.account.not.found";
/** 禁止实例化消息键容器。 */
private SocialMessageKeys() {
}
}
@@ -0,0 +1,18 @@
CREATE TABLE social_channel (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '数据库内部主键',
channel_code VARCHAR(16) NOT NULL COMMENT '社媒渠道业务编号',
site_code VARCHAR(16) NOT NULL COMMENT '所属站点业务编号',
platform VARCHAR(30) NOT NULL COMMENT '社媒平台:FACEBOOK、X、LINKEDIN、YOUTUBE、INSTAGRAM、WHATSAPP、PINTEREST、TIKTOK、LINE、TUMBLR、EMAIL',
display_name VARCHAR(100) NOT NULL COMMENT '前台展示名称',
profile_url VARCHAR(1000) NOT NULL COMMENT '社媒主页或联系地址',
share_enabled TINYINT NOT NULL DEFAULT 0 COMMENT '产品详情分享开关:0关闭,1开启',
floating_enabled TINYINT NOT NULL DEFAULT 0 COMMENT '全站悬浮栏开关:0关闭,1开启',
enabled TINYINT NOT NULL DEFAULT 1 COMMENT '渠道启用状态:0停用,1启用',
sort_no INT NOT NULL DEFAULT 30 COMMENT '展示排序值',
create_time BIGINT NOT NULL DEFAULT (ROUND(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000)) COMMENT '创建毫秒时间戳',
update_time BIGINT NOT NULL DEFAULT (ROUND(UNIX_TIMESTAMP(CURRENT_TIMESTAMP(3)) * 1000)) COMMENT '更新毫秒时间戳',
PRIMARY KEY (id),
UNIQUE KEY uk_social_channel_code (channel_code),
UNIQUE KEY uk_social_channel_site_platform (site_code, platform),
KEY idx_social_channel_site_enabled_sort (site_code, enabled, sort_no)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='站点社媒渠道配置';
@@ -0,0 +1,4 @@
social.channel.platform.duplicated=The same social platform cannot be configured more than once.
social.channel.save.failed=Failed to save social channel configuration.
social.channel.access.denied=You do not have access to this store.
social.channel.account.not.found=Administrator account was not found.
@@ -0,0 +1,4 @@
social.channel.platform.duplicated=同一社媒平台不能重复配置。
social.channel.save.failed=社媒渠道配置保存失败。
social.channel.access.denied=无权访问该店铺。
social.channel.account.not.found=管理员账户不存在。
@@ -0,0 +1,4 @@
social.channel.platform.duplicated=同一社媒平台不能重複配置。
social.channel.save.failed=社媒渠道配置儲存失敗。
social.channel.access.denied=無權存取該商店。
social.channel.account.not.found=管理員帳戶不存在。