From 77cdad58edb8f6c10b34da1d240dd973ce3a1da1 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Mon, 15 Dec 2025 11:18:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B6=88=E6=81=AF=E5=9B=BD?= =?UTF-8?q?=E9=99=85=E5=8C=96=E9=85=8D=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/i18n/SystemI18nConfigQryExe.java | 64 +++++++++++++++ .../system/SystemI18nConfigService.java | 35 ++++++++ .../gateway/SystemI18nConfigGateway.java | 41 ++++++++++ .../domain/system/i18n/I18nTypeEnum.java | 35 ++++++++ .../domain/system/i18n/SystemI18nConfig.java | 75 +++++++++++++++++ .../convertor/SystemI18nConfigConvertor.java | 23 ++++++ .../rds/dao/system/SystemI18nConfigDAO.java | 36 +++++++++ .../rds/entity/system/SystemI18nConfigDO.java | 80 +++++++++++++++++++ .../gateway/SystemI18nConfigGatewayImpl.java | 50 ++++++++++++ .../dao/system/SystemI18nConfigDAO.xml | 44 ++++++++++ .../UserBeautifulNumberClientServiceImpl.java | 20 ++++- 11 files changed, 499 insertions(+), 4 deletions(-) create mode 100644 rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/system/i18n/SystemI18nConfigQryExe.java create mode 100644 rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/system/SystemI18nConfigService.java create mode 100644 rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/gateway/SystemI18nConfigGateway.java create mode 100644 rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/system/i18n/I18nTypeEnum.java create mode 100644 rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/system/i18n/SystemI18nConfig.java create mode 100644 rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/convertor/SystemI18nConfigConvertor.java create mode 100644 rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/dao/system/SystemI18nConfigDAO.java create mode 100644 rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/system/SystemI18nConfigDO.java create mode 100644 rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/SystemI18nConfigGatewayImpl.java create mode 100644 rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/system/SystemI18nConfigDAO.xml diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/system/i18n/SystemI18nConfigQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/system/i18n/SystemI18nConfigQryExe.java new file mode 100644 index 00000000..568cc99a --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/system/i18n/SystemI18nConfigQryExe.java @@ -0,0 +1,64 @@ +package com.red.circle.other.app.command.system.i18n; + +import com.red.circle.other.domain.gateway.SystemI18nConfigGateway; +import com.red.circle.other.domain.system.i18n.SystemI18nConfig; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 国际化配置查询执行器 + * + * @author Leo + * @date 2025-01-13 + */ +@Slf4j +@Component +@RequiredArgsConstructor +public class SystemI18nConfigQryExe { + + private final SystemI18nConfigGateway systemI18nConfigGateway; + + /** + * 获取单个配置值 + */ + public String getValue(String i18nType, String countryCode, String i18nKey) { + SystemI18nConfig config = systemI18nConfigGateway.getByTypeCountryKey(i18nType, countryCode, i18nKey); + if (config != null) { + return config.getI18nValue(); + } + + // 降级到ALL通用配置 + config = systemI18nConfigGateway.getByTypeCountryKey(i18nType, "ALL", i18nKey); + return config != null ? config.getI18nValue() : null; + } + + /** + * 获取某业务类型下某国家的所有配置(返回Map) + */ + public Map getConfigMap(String i18nType, String countryCode) { + List configList = systemI18nConfigGateway.listByTypeAndCountry(i18nType, countryCode); + Map configMap = new HashMap<>(); + + if (!CollectionUtils.isEmpty(configList)) { + for (SystemI18nConfig config : configList) { + configMap.put(config.getI18nKey(), config.getI18nValue()); + } + } + + // 降级补充ALL通用配置 + List allConfigList = systemI18nConfigGateway.listByTypeAndCountry(i18nType, "ALL"); + if (!CollectionUtils.isEmpty(allConfigList)) { + for (SystemI18nConfig config : allConfigList) { + configMap.putIfAbsent(config.getI18nKey(), config.getI18nValue()); + } + } + + return configMap; + } +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/system/SystemI18nConfigService.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/system/SystemI18nConfigService.java new file mode 100644 index 00000000..8306882f --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/system/SystemI18nConfigService.java @@ -0,0 +1,35 @@ +package com.red.circle.other.app.service.system; + +import com.red.circle.other.app.command.system.i18n.SystemI18nConfigQryExe; +import com.red.circle.other.domain.system.i18n.I18nTypeEnum; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Map; + +/** + * 国际化配置服务 + * + * @author Leo + * @date 2025-01-13 + */ +@Service +@RequiredArgsConstructor +public class SystemI18nConfigService { + + private final SystemI18nConfigQryExe systemI18nConfigQryExe; + + /** + * 获取配置值 + */ + public String getValue(I18nTypeEnum i18nType, String countryCode, String i18nKey) { + return systemI18nConfigQryExe.getValue(i18nType.getCode(), countryCode, i18nKey); + } + + /** + * 获取配置Map + */ + public Map getConfigMap(I18nTypeEnum i18nType, String countryCode) { + return systemI18nConfigQryExe.getConfigMap(i18nType.getCode(), countryCode); + } +} diff --git a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/gateway/SystemI18nConfigGateway.java b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/gateway/SystemI18nConfigGateway.java new file mode 100644 index 00000000..7c2d0408 --- /dev/null +++ b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/gateway/SystemI18nConfigGateway.java @@ -0,0 +1,41 @@ +package com.red.circle.other.domain.gateway; + +import com.red.circle.other.domain.system.i18n.SystemI18nConfig; + +import java.util.List; + +/** + * 国际化配置领域网关 + * + * @author Leo + * @date 2025-01-13 + */ +public interface SystemI18nConfigGateway { + + /** + * 查询单个配置 + * + * @param i18nType 业务类型 + * @param countryCode 国家代码 + * @param i18nKey 配置key + * @return 配置对象 + */ + SystemI18nConfig getByTypeCountryKey(String i18nType, String countryCode, String i18nKey); + + /** + * 查询某业务类型下某国家的所有配置 + * + * @param i18nType 业务类型 + * @param countryCode 国家代码 + * @return 配置列表 + */ + List listByTypeAndCountry(String i18nType, String countryCode); + + /** + * 查询某业务类型的所有配置 + * + * @param i18nType 业务类型 + * @return 配置列表 + */ + List listByType(String i18nType); +} diff --git a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/system/i18n/I18nTypeEnum.java b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/system/i18n/I18nTypeEnum.java new file mode 100644 index 00000000..eac86342 --- /dev/null +++ b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/system/i18n/I18nTypeEnum.java @@ -0,0 +1,35 @@ +package com.red.circle.other.domain.system.i18n; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 国际化配置业务类型枚举 + * + * @author Leo + * @date 2025-01-13 + */ +@Getter +@AllArgsConstructor +public enum I18nTypeEnum { + + /** + * 靓号相关 + */ + BEAUTIFUL_NUMBER("BEAUTIFUL_NUMBER", "靓号"), + + /** + * 道具券相关 + */ + PROP_COUPON("PROP_COUPON", "道具券"); + + /** + * 类型代码 + */ + private final String code; + + /** + * 类型名称 + */ + private final String name; +} diff --git a/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/system/i18n/SystemI18nConfig.java b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/system/i18n/SystemI18nConfig.java new file mode 100644 index 00000000..c9023927 --- /dev/null +++ b/rc-service/rc-service-other/other-domain/src/main/java/com/red/circle/other/domain/system/i18n/SystemI18nConfig.java @@ -0,0 +1,75 @@ +package com.red.circle.other.domain.system.i18n; + +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 通用国际化配置领域实体 + * + * @author Leo + * @date 2025-01-13 + */ +@Data +public class SystemI18nConfig { + + /** + * 主键 + */ + private Long id; + + /** + * 业务类型(BEAUTIFUL_NUMBER/PROP_COUPON等) + */ + private String i18nType; + + /** + * 国家代码(CN/US/SA/ALL等) + */ + private String countryCode; + + /** + * 配置项key(content/title/subtitle等) + */ + private String i18nKey; + + /** + * 国际化文案内容 + */ + private String i18nValue; + + /** + * 排序号 + */ + private Integer sortOrder; + + /** + * 状态(0-禁用,1-启用) + */ + private Integer status; + + /** + * 备注说明 + */ + private String remark; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private LocalDateTime createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private LocalDateTime updatedTime; +} diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/convertor/SystemI18nConfigConvertor.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/convertor/SystemI18nConfigConvertor.java new file mode 100644 index 00000000..f34fcb77 --- /dev/null +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/convertor/SystemI18nConfigConvertor.java @@ -0,0 +1,23 @@ +package com.red.circle.other.infra.convertor; + +import com.red.circle.other.domain.system.i18n.SystemI18nConfig; +import com.red.circle.other.infra.database.rds.entity.system.SystemI18nConfigDO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +/** + * 国际化配置转换器 + * + * @author Leo + * @date 2025-01-13 + */ +@Mapper +public interface SystemI18nConfigConvertor { + + SystemI18nConfigConvertor INSTANCE = Mappers.getMapper(SystemI18nConfigConvertor.class); + + /** + * DO转Domain + */ + SystemI18nConfig toDomain(SystemI18nConfigDO configDO); +} diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/dao/system/SystemI18nConfigDAO.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/dao/system/SystemI18nConfigDAO.java new file mode 100644 index 00000000..11070773 --- /dev/null +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/dao/system/SystemI18nConfigDAO.java @@ -0,0 +1,36 @@ +package com.red.circle.other.infra.database.rds.dao.system; + +import com.red.circle.framework.mybatis.dao.BaseDAO; +import com.red.circle.other.infra.database.rds.entity.system.SystemI18nConfigDO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 国际化配置Mapper + * + * @author Leo + * @date 2025-01-13 + */ +@Mapper +public interface SystemI18nConfigDAO extends BaseDAO { + + /** + * 查询单个配置 + */ + SystemI18nConfigDO selectByTypeCountryKey(@Param("i18nType") String i18nType, + @Param("countryCode") String countryCode, + @Param("i18nKey") String i18nKey); + + /** + * 查询某业务类型下某国家的所有配置 + */ + List selectByTypeAndCountry(@Param("i18nType") String i18nType, + @Param("countryCode") String countryCode); + + /** + * 查询某业务类型的所有配置 + */ + List selectByType(@Param("i18nType") String i18nType); +} diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/system/SystemI18nConfigDO.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/system/SystemI18nConfigDO.java new file mode 100644 index 00000000..0e2bc02c --- /dev/null +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/entity/system/SystemI18nConfigDO.java @@ -0,0 +1,80 @@ +package com.red.circle.other.infra.database.rds.entity.system; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * 通用国际化配置表 + * + * @author Leo + * @date 2025-01-13 + */ +@Data +@TableName("system_i18n_config") +public class SystemI18nConfigDO { + + /** + * 主键 + */ + @TableId(type = IdType.AUTO) + private Long id; + + /** + * 业务类型 + */ + private String i18nType; + + /** + * 国家代码 + */ + private String countryCode; + + /** + * 配置项key + */ + private String i18nKey; + + /** + * 国际化文案内容 + */ + private String i18nValue; + + /** + * 排序号 + */ + private Integer sortOrder; + + /** + * 状态 + */ + private Integer status; + + /** + * 备注说明 + */ + private String remark; + + /** + * 创建人 + */ + private String createdBy; + + /** + * 创建时间 + */ + private LocalDateTime createdTime; + + /** + * 更新人 + */ + private String updatedBy; + + /** + * 更新时间 + */ + private LocalDateTime updatedTime; +} diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/SystemI18nConfigGatewayImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/SystemI18nConfigGatewayImpl.java new file mode 100644 index 00000000..e25cdefe --- /dev/null +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/gateway/SystemI18nConfigGatewayImpl.java @@ -0,0 +1,50 @@ +package com.red.circle.other.infra.gateway; + +import com.red.circle.other.domain.gateway.SystemI18nConfigGateway; +import com.red.circle.other.domain.system.i18n.SystemI18nConfig; +import com.red.circle.other.infra.convertor.SystemI18nConfigConvertor; +import com.red.circle.other.infra.database.rds.dao.system.SystemI18nConfigDAO; +import com.red.circle.other.infra.database.rds.entity.system.SystemI18nConfigDO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.stream.Collectors; + +/** + * 国际化配置网关实现 + * + * @author Leo + * @date 2025-01-13 + */ +@Component +@RequiredArgsConstructor +public class SystemI18nConfigGatewayImpl implements SystemI18nConfigGateway { + + private final SystemI18nConfigDAO systemI18NConfigDAO; + + @Override + public SystemI18nConfig getByTypeCountryKey(String i18nType, String countryCode, String i18nKey) { + SystemI18nConfigDO configDO = systemI18NConfigDAO.selectByTypeCountryKey(i18nType, countryCode, i18nKey); + if (configDO == null) { + configDO = systemI18NConfigDAO.selectByTypeCountryKey(i18nType, "EN", i18nKey); + } + return SystemI18nConfigConvertor.INSTANCE.toDomain(configDO); + } + + @Override + public List listByTypeAndCountry(String i18nType, String countryCode) { + List configDOList = systemI18NConfigDAO.selectByTypeAndCountry(i18nType, countryCode); + return configDOList.stream() + .map(SystemI18nConfigConvertor.INSTANCE::toDomain) + .collect(Collectors.toList()); + } + + @Override + public List listByType(String i18nType) { + List configDOList = systemI18NConfigDAO.selectByType(i18nType); + return configDOList.stream() + .map(SystemI18nConfigConvertor.INSTANCE::toDomain) + .collect(Collectors.toList()); + } +} diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/system/SystemI18nConfigDAO.xml b/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/system/SystemI18nConfigDAO.xml new file mode 100644 index 00000000..7ff9ba8c --- /dev/null +++ b/rc-service/rc-service-other/other-infrastructure/src/main/resources/dao/system/SystemI18nConfigDAO.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserBeautifulNumberClientServiceImpl.java b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserBeautifulNumberClientServiceImpl.java index 7950da60..bf05c3b9 100644 --- a/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserBeautifulNumberClientServiceImpl.java +++ b/rc-service/rc-service-other/other-inner-endpoint/src/main/java/com/red/circle/other/app/inner/service/user/user/impl/UserBeautifulNumberClientServiceImpl.java @@ -6,8 +6,13 @@ import com.red.circle.external.inner.model.enums.message.OfficialNoticeTypeEnum; import com.red.circle.framework.core.asserts.ResponseAssert; import com.red.circle.framework.core.response.CommonErrorCode; import com.red.circle.framework.dto.PageResult; +import com.red.circle.other.domain.gateway.SystemI18nConfigGateway; +import com.red.circle.other.domain.gateway.user.ability.UserRegionGateway; +import com.red.circle.other.domain.system.i18n.I18nTypeEnum; +import com.red.circle.other.domain.system.i18n.SystemI18nConfig; import com.red.circle.other.infra.database.mongo.entity.user.profile.UserSpecialId; import com.red.circle.other.infra.database.mongo.service.user.profile.UserSpecialIdService; +import com.red.circle.other.infra.database.rds.dao.system.SystemI18nConfigDAO; import com.red.circle.other.infra.database.rds.entity.user.user.UserBeautifulNumberApply; import com.red.circle.other.infra.database.rds.service.user.user.UserBeautifulNumberApplyService; import com.red.circle.other.infra.database.rds.service.user.user.UserBeautifulNumberService; @@ -18,6 +23,7 @@ import com.red.circle.other.inner.model.cmd.user.UserBeautifulNumberCmd; import com.red.circle.other.inner.model.dto.user.BeautifulNumberDTO; import com.red.circle.other.inner.model.dto.user.UserBeautifulNumberApplyDTO; import com.red.circle.other.app.inner.service.user.user.UserBeautifulNumberClientService; +import com.red.circle.other.inner.model.dto.user.reigon.UserRegionDTO; import com.red.circle.tool.core.date.TimestampUtils; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -42,6 +48,8 @@ public class UserBeautifulNumberClientServiceImpl implements private final UserBeautifulNumberApplyService userBeautifulNumberApplyService; private final UserSpecialIdService userSpecialIdService; private final OfficialNoticeClient officialNoticeClient; + private final SystemI18nConfigGateway systemI18nConfigGateway; + private final UserRegionGateway userRegionGateway; @Override public PageResult pageBeautifulNumberApply( @@ -59,6 +67,10 @@ public class UserBeautifulNumberClientServiceImpl implements userBeautifulNumberApplyService.handleApply(id, state); + UserRegionDTO userRegion = userRegionGateway.getUserRegion(beautifulNumberApply.getApplyUser()); + String regionCode = userRegion.getRegionCode(); + + SystemI18nConfig applyContent; String content; if (state == 1) { UserSpecialId userSpecialId = userSpecialIdService.getByUserId(beautifulNumberApply.getApplyUser()); @@ -75,11 +87,11 @@ public class UserBeautifulNumberClientServiceImpl implements specialIdCmd.setExpiredTime(TimestampUtils.dateTimePlusDays(TimestampUtils.now(),365 * 3)); userSpecialIdService.add(specialIdCmd); - - content = String.format("Your application for exclusive lD 【%s】has been approved and has been applied to both you user lD and room lD.", - beautifulNumberApply.getApplyAccount()); + applyContent = systemI18nConfigGateway.getByTypeCountryKey(I18nTypeEnum.BEAUTIFUL_NUMBER.getCode(), regionCode, "apply_content"); + content = String.format(applyContent.getI18nValue(),beautifulNumberApply.getApplyAccount()); } else { - content = String.format("Your application for exclusive lD 【%s】wasn't approved for reason 【%s】", + applyContent = systemI18nConfigGateway.getByTypeCountryKey(I18nTypeEnum.BEAUTIFUL_NUMBER.getCode(), regionCode, "audit_result_content"); + content = String.format(applyContent.getI18nValue(), beautifulNumberApply.getApplyAccount(), remark); }