feat(i18n): 新增国际化消息管理功能
新增 Controller、DO、Mapper、Service 及 XML 配置,支持国际化消息分页、保存与维护; 补充 I18N_MESSAGE_NOT_EXISTS 错误码,用于提示配置缺失。
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
package com.yolo.keyboard.controller.admin.i18nmessage;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import jakarta.validation.constraints.*;
|
||||
import jakarta.validation.*;
|
||||
import jakarta.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.pojo.CommonResult;
|
||||
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||
import static com.yolo.keyboard.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import com.yolo.keyboard.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import com.yolo.keyboard.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static com.yolo.keyboard.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import com.yolo.keyboard.controller.admin.i18nmessage.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.i18nmessage.KeyboardI18nMessageDO;
|
||||
import com.yolo.keyboard.service.i18nmessage.KeyboardI18nMessageService;
|
||||
|
||||
@Tag(name = "管理后台 - 国际化错误提醒配置")
|
||||
@RestController
|
||||
@RequestMapping("/keyboard/I18n-message")
|
||||
@Validated
|
||||
public class KeyboardI18nMessageController {
|
||||
|
||||
@Resource
|
||||
private KeyboardI18nMessageService i18nMessageService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建国际化错误提醒配置")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:I18n-message:create')")
|
||||
public CommonResult<Long> createI18nMessage(@Valid @RequestBody KeyboardI18nMessageSaveReqVO createReqVO) {
|
||||
return success(i18nMessageService.createI18nMessage(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新国际化错误提醒配置")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:I18n-message:update')")
|
||||
public CommonResult<Boolean> updateI18nMessage(@Valid @RequestBody KeyboardI18nMessageSaveReqVO updateReqVO) {
|
||||
i18nMessageService.updateI18nMessage(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除国际化错误提醒配置")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:I18n-message:delete')")
|
||||
public CommonResult<Boolean> deleteI18nMessage(@RequestParam("id") Long id) {
|
||||
i18nMessageService.deleteI18nMessage(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除国际化错误提醒配置")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:I18n-message:delete')")
|
||||
public CommonResult<Boolean> deleteI18nMessageList(@RequestParam("ids") List<Long> ids) {
|
||||
i18nMessageService.deleteI18nMessageListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得国际化错误提醒配置")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:I18n-message:query')")
|
||||
public CommonResult<KeyboardI18nMessageRespVO> getI18nMessage(@RequestParam("id") Long id) {
|
||||
KeyboardI18nMessageDO i18nMessage = i18nMessageService.getI18nMessage(id);
|
||||
return success(BeanUtils.toBean(i18nMessage, KeyboardI18nMessageRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得国际化错误提醒配置分页")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:I18n-message:query')")
|
||||
public CommonResult<PageResult<KeyboardI18nMessageRespVO>> getI18nMessagePage(@Valid KeyboardI18nMessagePageReqVO pageReqVO) {
|
||||
PageResult<KeyboardI18nMessageDO> pageResult = i18nMessageService.getI18nMessagePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, KeyboardI18nMessageRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出国际化错误提醒配置 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:I18n-message:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportI18nMessageExcel(@Valid KeyboardI18nMessagePageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<KeyboardI18nMessageDO> list = i18nMessageService.getI18nMessagePage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "国际化错误提醒配置.xls", "数据", KeyboardI18nMessageRespVO.class,
|
||||
BeanUtils.toBean(list, KeyboardI18nMessageRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.yolo.keyboard.controller.admin.i18nmessage.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
|
||||
@Schema(description = "管理后台 - 国际化错误提醒配置分页 Request VO")
|
||||
@Data
|
||||
public class KeyboardI18nMessagePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "错误代码")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "地区")
|
||||
private String locale;
|
||||
|
||||
@Schema(description = "错误提醒")
|
||||
private String message;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.yolo.keyboard.controller.admin.i18nmessage.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import cn.idev.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 国际化错误提醒配置 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class KeyboardI18nMessageRespVO {
|
||||
|
||||
@Schema(description = "主键 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "18823")
|
||||
@ExcelProperty("主键 id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "错误代码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("错误代码")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "地区", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("地区")
|
||||
private String locale;
|
||||
|
||||
@Schema(description = "错误提醒", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("错误提醒")
|
||||
private String message;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.yolo.keyboard.controller.admin.i18nmessage.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import jakarta.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - 国际化错误提醒配置新增/修改 Request VO")
|
||||
@Data
|
||||
public class KeyboardI18nMessageSaveReqVO {
|
||||
|
||||
@Schema(description = "主键 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "18823")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "错误代码", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "错误代码不能为空")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "地区", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "地区不能为空")
|
||||
private String locale;
|
||||
|
||||
@Schema(description = "错误提醒", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "错误提醒不能为空")
|
||||
private String message;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.yolo.keyboard.dal.dataobject.i18nmessage;
|
||||
|
||||
import com.yolo.keyboard.framework.tenant.core.aop.TenantIgnore;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.yolo.keyboard.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 国际化错误提醒配置 DO
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@TableName("keyboard_i18n_message")
|
||||
@KeySequence("keyboard_i18n_message_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TenantIgnore
|
||||
public class KeyboardI18nMessageDO {
|
||||
|
||||
/**
|
||||
* 主键 id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 错误代码
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 地区
|
||||
*/
|
||||
private String locale;
|
||||
/**
|
||||
* 错误提醒
|
||||
*/
|
||||
private String message;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.yolo.keyboard.dal.mysql.i18nmessage;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.yolo.keyboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.yolo.keyboard.dal.dataobject.i18nmessage.KeyboardI18nMessageDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.yolo.keyboard.controller.admin.i18nmessage.vo.*;
|
||||
|
||||
/**
|
||||
* 国际化错误提醒配置 Mapper
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Mapper
|
||||
public interface KeyboardI18nMessageMapper extends BaseMapperX<KeyboardI18nMessageDO> {
|
||||
|
||||
default PageResult<KeyboardI18nMessageDO> selectPage(KeyboardI18nMessagePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardI18nMessageDO>()
|
||||
.eqIfPresent(KeyboardI18nMessageDO::getCode, reqVO.getCode())
|
||||
.eqIfPresent(KeyboardI18nMessageDO::getLocale, reqVO.getLocale())
|
||||
.eqIfPresent(KeyboardI18nMessageDO::getMessage, reqVO.getMessage())
|
||||
.orderByDesc(KeyboardI18nMessageDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.yolo.keyboard.service.i18nmessage;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import com.yolo.keyboard.controller.admin.i18nmessage.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.i18nmessage.KeyboardI18nMessageDO;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 国际化错误提醒配置 Service 接口
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
public interface KeyboardI18nMessageService {
|
||||
|
||||
/**
|
||||
* 创建国际化错误提醒配置
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createI18nMessage(@Valid KeyboardI18nMessageSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新国际化错误提醒配置
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateI18nMessage(@Valid KeyboardI18nMessageSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除国际化错误提醒配置
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteI18nMessage(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除国际化错误提醒配置
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteI18nMessageListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得国际化错误提醒配置
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 国际化错误提醒配置
|
||||
*/
|
||||
KeyboardI18nMessageDO getI18nMessage(Long id);
|
||||
|
||||
/**
|
||||
* 获得国际化错误提醒配置分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 国际化错误提醒配置分页
|
||||
*/
|
||||
PageResult<KeyboardI18nMessageDO> getI18nMessagePage(KeyboardI18nMessagePageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.yolo.keyboard.service.i18nmessage;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import com.yolo.keyboard.controller.admin.i18nmessage.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.i18nmessage.KeyboardI18nMessageDO;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||
|
||||
import com.yolo.keyboard.dal.mysql.i18nmessage.KeyboardI18nMessageMapper;
|
||||
|
||||
import static com.yolo.keyboard.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.yolo.keyboard.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static com.yolo.keyboard.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static com.yolo.keyboard.module.infra.enums.ErrorCodeConstants.I18N_MESSAGE_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 国际化错误提醒配置 Service 实现类
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class KeyboardI18nMessageServiceImpl implements KeyboardI18nMessageService {
|
||||
|
||||
@Resource
|
||||
private KeyboardI18nMessageMapper i18nMessageMapper;
|
||||
|
||||
@Override
|
||||
public Long createI18nMessage(KeyboardI18nMessageSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
KeyboardI18nMessageDO i18nMessage = BeanUtils.toBean(createReqVO, KeyboardI18nMessageDO.class);
|
||||
i18nMessageMapper.insert(i18nMessage);
|
||||
|
||||
// 返回
|
||||
return i18nMessage.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateI18nMessage(KeyboardI18nMessageSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateI18nMessageExists(updateReqVO.getId());
|
||||
// 更新
|
||||
KeyboardI18nMessageDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardI18nMessageDO.class);
|
||||
i18nMessageMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteI18nMessage(Long id) {
|
||||
// 校验存在
|
||||
validateI18nMessageExists(id);
|
||||
// 删除
|
||||
i18nMessageMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteI18nMessageListByIds(List<Long> ids) {
|
||||
// 删除
|
||||
i18nMessageMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
private void validateI18nMessageExists(Long id) {
|
||||
if (i18nMessageMapper.selectById(id) == null) {
|
||||
throw exception(I18N_MESSAGE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyboardI18nMessageDO getI18nMessage(Long id) {
|
||||
return i18nMessageMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<KeyboardI18nMessageDO> getI18nMessagePage(KeyboardI18nMessagePageReqVO pageReqVO) {
|
||||
return i18nMessageMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yolo.keyboard.dal.mysql.i18nmessage.KeyboardI18nMessageMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
@@ -80,7 +80,5 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode USER_PURCHASE_RECORDS_NOT_EXISTS = new ErrorCode(1_001_202_006, "用户内购记录不存在");
|
||||
ErrorCode PRODUCT_ITEMS_NOT_EXISTS = new ErrorCode(1_001_202_007, "内购商品不存在");
|
||||
ErrorCode USER_CALL_LOG_NOT_EXISTS = new ErrorCode(1_001_202_008, "用户每次调用日志(用于记录token、模型、耗时、成功率等)不存在");
|
||||
|
||||
|
||||
|
||||
ErrorCode I18N_MESSAGE_NOT_EXISTS = new ErrorCode(1_001_202_009, "国际化错误提醒配置不存在");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user