feat(新增): 🔧 多语言修改

This commit is contained in:
bunny 2024-09-30 14:57:43 +08:00
parent c1d4eb235e
commit e817494645
12 changed files with 52 additions and 79 deletions

View File

@ -22,7 +22,7 @@ public class MybatisPlusConfig {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// 分页插件
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(DbType.MYSQL);
paginationInnerInterceptor.setMaxLimit(100L);// ? 设置最大分页为100
paginationInnerInterceptor.setMaxLimit(600L);// ? 设置最大分页为100
interceptor.addInnerInterceptor(paginationInnerInterceptor);
// 乐观锁
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());

View File

@ -34,8 +34,16 @@ public class GlobalExceptionHandler {
@ExceptionHandler(RuntimeException.class)
@ResponseBody
public Result<Object> exceptionHandler(RuntimeException exception) {
log.error("GlobalExceptionHandler===>运行时异常信息:{}", exception.getMessage());
String message = exception.getMessage();
log.error("GlobalExceptionHandler===>运行时异常信息:{}", message);
exception.printStackTrace();
// 解析异常
String jsonParseError = "JSON parse error (.*)";
Matcher jsonParseErrorMatcher = Pattern.compile(jsonParseError).matcher(message);
if (jsonParseErrorMatcher.find())
return Result.error(null, 500, "JSON解析异常 " + jsonParseErrorMatcher.group(1));
return Result.error(null, 500, "服务器异常");
}

View File

@ -22,8 +22,9 @@ public class I18nAddDto {
@NotBlank(message = "多语言翻译名称不能为空")
private String translation;
@Schema(name = "typeId", title = "多语言类型id")
private Long typeId;
@Schema(name = "typeName", title = "多语言类型名称")
@NotBlank(message = "多语言类型名称不能为空")
private String typeName;
}

View File

@ -19,5 +19,8 @@ public class I18nDto {
@Schema(name = "translation", title = "多语言翻译名称")
private String translation;
@Schema(name = "typeName", title = "多语言类型名称")
private String typeName;
}

View File

@ -28,7 +28,7 @@ public class I18n extends BaseEntity {
@Schema(name = "translation", title = "多语言翻译名称")
private String translation;
@Schema(name = "typeId", title = "多语言类型id")
private Long typeId;
@Schema(name = "typeName", title = "多语言类型id")
private String typeName;
}

View File

@ -1,29 +0,0 @@
package cn.bunny.dao.entity.i18n;
import cn.bunny.dao.entity.BaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
@Getter
@Setter
@Accessors(chain = true)
@TableName("sys_i18n")
@Schema(name = "I18nWithI18nType对象", title = "多语言和多语言类型", description = "多语言和多语言类型内容")
public class I18nWithI18nType extends BaseEntity {
@Schema(name = "keyName", title = "多语言key")
private String keyName;
@Schema(name = "translation", title = "多语言翻译名称")
private String translation;
@Schema(name = "typeName", title = "多语言类型(比如zh,en)")
private String typeName;
@Schema(name = "summary", title = "名称解释(比如中文,英文)")
private String summary;
}

View File

@ -31,6 +31,7 @@ public enum ResultCodeEnum {
EMAIL_CODE_EMPTY(201, "邮箱验证码过期或不存在"),
DATA_EXIST(201, "数据已存在"),
DATA_NOT_EXIST(201, "数据不存在"),
REQUEST_IS_EMPTY(201, "请求数据为空"),
// 数据相关 206
ILLEGAL_REQUEST(206, "非法请求"),

View File

@ -18,8 +18,8 @@ public class I18nVo extends BaseVo {
@Schema(name = "translation", title = "多语言翻译名称")
private String translation;
@Schema(name = "typeId", title = "多语言类型id")
private Long typeId;
@Schema(name = "typeName", title = "多语言类型id")
private String typeName;
}

View File

@ -2,7 +2,6 @@ package cn.bunny.services.mapper;
import cn.bunny.dao.dto.i18n.I18nDto;
import cn.bunny.dao.entity.i18n.I18n;
import cn.bunny.dao.entity.i18n.I18nWithI18nType;
import cn.bunny.dao.entity.system.MenuIcon;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -23,13 +22,6 @@ import java.util.List;
@Mapper
public interface I18nMapper extends BaseMapper<I18n> {
/**
* * 多语言和多语言类型
*
* @return 多语言和多语言类型列表
*/
List<I18nWithI18nType> selectListWithI18nType();
/**
* * 分页查询多语言内容
*

View File

@ -6,7 +6,6 @@ import cn.bunny.dao.dto.i18n.I18nDto;
import cn.bunny.dao.dto.i18n.I18nUpdateDto;
import cn.bunny.dao.entity.i18n.I18n;
import cn.bunny.dao.entity.i18n.I18nType;
import cn.bunny.dao.entity.i18n.I18nWithI18nType;
import cn.bunny.dao.entity.system.MenuIcon;
import cn.bunny.dao.pojo.result.PageResult;
import cn.bunny.dao.pojo.result.ResultCodeEnum;
@ -54,17 +53,13 @@ public class I18nServiceImpl extends ServiceImpl<I18nMapper, I18n> implements I1
public HashMap<String, Object> getI18n() {
// 查找默认语言内容
I18nType i18nType = i18nTypeMapper.selectOne(Wrappers.<I18nType>lambdaQuery().eq(I18nType::getIsDefault, true));
List<I18nWithI18nType> i18nWithI18nTypes = baseMapper.selectListWithI18nType();
List<I18n> i18nList = list();
// 整理集合
Map<String, Map<String, String>> map = i18nWithI18nTypes.stream()
Map<String, Map<String, String>> map = i18nList.stream()
.collect(Collectors.groupingBy(
I18nWithI18nType::getTypeName,
Collectors.toMap(
I18nWithI18nType::getKeyName,
I18nWithI18nType::getTranslation
)
));
I18n::getTypeName,
Collectors.toMap(I18n::getKeyName, I18n::getTranslation)));
// 返回集合
HashMap<String, Object> hashMap = new HashMap<>(map);
@ -102,10 +97,10 @@ public class I18nServiceImpl extends ServiceImpl<I18nMapper, I18n> implements I1
@Override
public void addI18n(@Valid I18nAddDto dto) {
String keyName = dto.getKeyName();
Long typeId = dto.getTypeId();
String typeName = dto.getTypeName();
// 查询数据是否存在
List<I18n> i18nList = list(Wrappers.<I18n>lambdaQuery().eq(I18n::getKeyName, keyName).eq(I18n::getTypeId, typeId));
List<I18n> i18nList = list(Wrappers.<I18n>lambdaQuery().eq(I18n::getKeyName, keyName).eq(I18n::getTypeName, typeName));
if (!i18nList.isEmpty()) throw new BunnyException(ResultCodeEnum.DATA_EXIST);
// 保存内容
@ -140,6 +135,9 @@ public class I18nServiceImpl extends ServiceImpl<I18nMapper, I18n> implements I1
*/
@Override
public void deleteI18n(List<Long> ids) {
if (ids.isEmpty()) {
throw new BunnyException(ResultCodeEnum.REQUEST_IS_EMPTY);
}
baseMapper.deleteBatchIdsWithPhysics(ids);
}
}

View File

@ -50,12 +50,12 @@ spring:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
rabbitmq:
host: ${bunny.rabbitmq.host}
port: ${bunny.rabbitmq.port}
username: ${bunny.rabbitmq.username}
password: ${bunny.rabbitmq.password}
virtual-host: ${bunny.rabbitmq.virtual-host}
# rabbitmq:
# host: ${bunny.rabbitmq.host}
# port: ${bunny.rabbitmq.port}
# username: ${bunny.rabbitmq.username}
# password: ${bunny.rabbitmq.password}
# virtual-host: ${bunny.rabbitmq.virtual-host}
# publisher-confirm-type: correlated # 交换机确认
# publisher-returns: true # 队列确认
# listener:

View File

@ -7,7 +7,7 @@
<id column="id" property="id"/>
<result column="key_name" property="keyName"/>
<result column="translation" property="translation"/>
<result column="type_id" property="typeId"/>
<result column="type_name" property="typeName"/>
<result column="create_user" property="createUser"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
@ -17,7 +17,7 @@
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, key_name, translation, type_id, create_user, update_user, update_time, create_time, is_deleted
id, key_name, translation, type_name, create_user, update_user, update_time, create_time, is_deleted
</sql>
<!-- 物理删除多语言 -->
@ -30,24 +30,23 @@
</foreach>
</delete>
<!-- 多语言和多语言类型 -->
<select id="selectListWithI18nType" resultType="cn.bunny.dao.entity.i18n.I18nWithI18nType">
select i18n.*, i18n_type.type_name
from sys_i18n i18n,
sys_i18n_type i18n_type
where i18n.type_id = i18n_type.id
</select>
<!-- 分页查询多语言内容 -->
<select id="selectListByPage" resultType="cn.bunny.dao.entity.i18n.I18n">
select *
select
<include refid="Base_Column_List"/>
from sys_i18n
<if test="dto.keyName != null and dto.keyName != ''">
key_name like CONCAT('%',#{dto.keyName},'%')
</if>
<if test="dto.translation != null and dto.translation != ''">
translation like CONCAT('%',#{dto.translation},'%')
</if>
<where>
<if test="dto.keyName != null and dto.keyName != ''">
key_name like CONCAT('%',#{dto.keyName},'%')
</if>
<if test="dto.translation != null and dto.translation != ''">
translation like CONCAT('%',#{dto.translation},'%')
</if>
<if test="dto.typeName != null and dto.typeName != ''">
type_name like CONCAT('%',#{dto.typeName},'%')
</if>
</where>
order by update_time
</select>
</mapper>