diff --git a/yudao-framework/yudao-common/pom.xml b/yudao-framework/yudao-common/pom.xml
index bc70c946e..f364df7c3 100644
--- a/yudao-framework/yudao-common/pom.xml
+++ b/yudao-framework/yudao-common/pom.xml
@@ -133,6 +133,11 @@
transmittable-thread-local
+
+ com.fhs-opensource
+ easy-trans-anno
+
+
org.springframework.boot
diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/pom.xml b/yudao-framework/yudao-spring-boot-starter-mybatis/pom.xml
index ae13a9056..acc2dc507 100644
--- a/yudao-framework/yudao-spring-boot-starter-mybatis/pom.xml
+++ b/yudao-framework/yudao-spring-boot-starter-mybatis/pom.xml
@@ -71,6 +71,15 @@
com.github.yulichang
mybatis-plus-join-boot-starter
+
+
+ com.fhs-opensource
+ easy-trans-spring-boot-starter
+
+
+ com.fhs-opensource
+ easy-trans-mybatis-plus-extend
+
diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/dataobject/BaseDO.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/dataobject/BaseDO.java
index 19abaa6fe..fc5f0a301 100644
--- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/dataobject/BaseDO.java
+++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/dataobject/BaseDO.java
@@ -3,6 +3,8 @@ package cn.iocoder.yudao.framework.mybatis.core.dataobject;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fhs.core.trans.vo.TransPojo;
import lombok.Data;
import org.apache.ibatis.type.JdbcType;
@@ -12,10 +14,14 @@ import java.time.LocalDateTime;
/**
* 基础实体对象
*
+ * 为什么实现 {@link TransPojo} 接口?
+ * 因为使用 Easy-Trans TransType.SIMPLE 模式,集成 MyBatis Plus 查询
+ *
* @author 芋道源码
*/
@Data
-public abstract class BaseDO implements Serializable {
+@JsonIgnoreProperties(value = "transMap") // 由于 Easy-Trans 会添加 transMap 属性,避免 Jackson 在 Spring Cache 反序列化报错
+public abstract class BaseDO implements Serializable, TransPojo {
/**
* 创建时间
diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/package-info.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/package-info.java
deleted file mode 100644
index 8c69219d0..000000000
--- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package cn.iocoder.yudao.framework;
diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/translate/config/YudaoTranslateAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/translate/config/YudaoTranslateAutoConfiguration.java
new file mode 100644
index 000000000..bcc46b80d
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/translate/config/YudaoTranslateAutoConfiguration.java
@@ -0,0 +1,18 @@
+package cn.iocoder.yudao.framework.translate.config;
+
+import cn.iocoder.yudao.framework.translate.core.TranslateUtils;
+import com.fhs.trans.service.impl.TransService;
+import org.springframework.boot.autoconfigure.AutoConfiguration;
+import org.springframework.context.annotation.Bean;
+
+@AutoConfiguration
+public class YudaoTranslateAutoConfiguration {
+
+ @Bean
+ @SuppressWarnings({"InstantiationOfUtilityClass", "SpringJavaInjectionPointsAutowiringInspection"})
+ public TranslateUtils translateUtils(TransService transService) {
+ TranslateUtils.init(transService);
+ return new TranslateUtils();
+ }
+
+}
diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/translate/core/TranslateUtils.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/translate/core/TranslateUtils.java
new file mode 100644
index 000000000..2974b0c32
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/translate/core/TranslateUtils.java
@@ -0,0 +1,37 @@
+package cn.iocoder.yudao.framework.translate.core;
+
+import cn.hutool.core.collection.CollUtil;
+import com.fhs.core.trans.vo.VO;
+import com.fhs.trans.service.impl.TransService;
+
+import java.util.List;
+
+/**
+ * VO 数据翻译 Utils
+ *
+ * @author 芋道源码
+ */
+public class TranslateUtils {
+
+ private static TransService transService;
+
+ public static void init(TransService transService) {
+ TranslateUtils.transService = transService;
+ }
+
+ /**
+ * 数据翻译
+ *
+ * 使用场景:无法使用 @TransMethodResult 注解的场景,只能通过手动触发翻译
+ *
+ * @param data 数据
+ * @return 翻译结果
+ */
+ public static List translate(List data) {
+ if (CollUtil.isNotEmpty((data))) {
+ transService.transBatch(data);
+ }
+ return data;
+ }
+
+}
diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/translate/package-info.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/translate/package-info.java
new file mode 100644
index 000000000..f14914a08
--- /dev/null
+++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/translate/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * 使用 Easy-Trans 提升使用 VO 数据翻译的开发效率
+ */
+package cn.iocoder.yudao.framework.translate;
diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
index 1c159fd6f..4a4eb95b7 100644
--- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
+++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
@@ -1,2 +1,3 @@
cn.iocoder.yudao.framework.datasource.config.YudaoDataSourceAutoConfiguration
-cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration
\ No newline at end of file
+cn.iocoder.yudao.framework.mybatis.config.YudaoMybatisAutoConfiguration
+cn.iocoder.yudao.framework.translate.config.YudaoTranslateAutoConfiguration
\ No newline at end of file
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/CrmProductController.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/CrmProductController.java
index 68271da3e..d41382a8c 100644
--- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/CrmProductController.java
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/CrmProductController.java
@@ -1,23 +1,19 @@
package cn.iocoder.yudao.module.crm.controller.admin.product;
-import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
+import cn.iocoder.yudao.framework.translate.core.TranslateUtils;
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductPageReqVO;
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductRespVO;
import cn.iocoder.yudao.module.crm.controller.admin.product.vo.product.CrmProductSaveReqVO;
-import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductDO;
import cn.iocoder.yudao.module.crm.enums.product.CrmProductStatusEnum;
-import cn.iocoder.yudao.module.crm.service.product.CrmProductCategoryService;
import cn.iocoder.yudao.module.crm.service.product.CrmProductService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
-import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -29,15 +25,11 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
-import java.util.Collections;
import java.util.List;
-import java.util.Map;
-import java.util.stream.Stream;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
-import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
-import static java.util.Collections.singletonList;
@Tag(name = "管理后台 - CRM 产品")
@RestController
@@ -47,9 +39,6 @@ public class CrmProductController {
@Resource
private CrmProductService productService;
- @Resource
- private CrmProductCategoryService productCategoryService;
-
@Resource
private AdminUserApi adminUserApi;
@@ -83,14 +72,7 @@ public class CrmProductController {
@PreAuthorize("@ss.hasPermission('crm:product:query')")
public CommonResult getProduct(@RequestParam("id") Long id) {
CrmProductDO product = productService.getProduct(id);
- return success(buildProductDetail(product));
- }
-
- private CrmProductRespVO buildProductDetail(CrmProductDO product) {
- if (product == null) {
- return null;
- }
- return buildProductDetailList(singletonList(product)).get(0);
+ return success(BeanUtils.toBean(product, CrmProductRespVO.class));
}
@GetMapping("/simple-list")
@@ -106,7 +88,7 @@ public class CrmProductController {
@PreAuthorize("@ss.hasPermission('crm:product:query')")
public CommonResult> getProductPage(@Valid CrmProductPageReqVO pageVO) {
PageResult pageResult = productService.getProductPage(pageVO);
- return success(new PageResult<>(buildProductDetailList(pageResult.getList()), pageResult.getTotal()));
+ return success(BeanUtils.toBean(pageResult, CrmProductRespVO.class));
}
@GetMapping("/export-excel")
@@ -119,27 +101,7 @@ public class CrmProductController {
List list = productService.getProductPage(exportReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "产品.xls", "数据", CrmProductRespVO.class,
- buildProductDetailList(list));
- }
-
- private List buildProductDetailList(List list) {
- if (CollUtil.isEmpty(list)) {
- return Collections.emptyList();
- }
- // 1.1 获得用户信息
- Map userMap = adminUserApi.getUserMap(
- convertSetByFlatMap(list, user -> Stream.of(Long.valueOf(user.getCreator()), user.getOwnerUserId())));
- // 1.2 获得分类信息
- Map categoryMap = productCategoryService.getProductCategoryMap(
- convertSet(list, CrmProductDO::getCategoryId));
- // 2. 拼接数据
- return BeanUtils.toBean(list, CrmProductRespVO.class, productVO -> {
- // 2.1 设置用户信息
- MapUtils.findAndThen(userMap, productVO.getOwnerUserId(), user -> productVO.setOwnerUserName(user.getNickname()));
- MapUtils.findAndThen(userMap, Long.valueOf(productVO.getCreator()), user -> productVO.setCreatorName(user.getNickname()));
- // 2.2 设置分类名称
- MapUtils.findAndThen(categoryMap, productVO.getCategoryId(), category -> productVO.setCategoryName(category.getName()));
- });
+ TranslateUtils.translate(BeanUtils.toBean(list, CrmProductRespVO.class)));
}
}
diff --git a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductRespVO.java b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductRespVO.java
index 1f659aa77..43d2c7421 100644
--- a/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductRespVO.java
+++ b/yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/product/vo/product/CrmProductRespVO.java
@@ -2,9 +2,13 @@ package cn.iocoder.yudao.module.crm.controller.admin.product.vo.product;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
+import cn.iocoder.yudao.module.crm.dal.dataobject.product.CrmProductCategoryDO;
import cn.iocoder.yudao.module.crm.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
+import com.fhs.core.trans.anno.Trans;
+import com.fhs.core.trans.constant.TransType;
+import com.fhs.core.trans.vo.VO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@@ -14,7 +18,7 @@ import java.time.LocalDateTime;
@Schema(description = "管理后台 - CRM 产品 Response VO")
@Data
@ExcelIgnoreUnannotated
-public class CrmProductRespVO {
+public class CrmProductRespVO implements VO {
@Schema(description = "产品编号", example = "20529")
@ExcelProperty("产品编号")
@@ -43,6 +47,7 @@ public class CrmProductRespVO {
private Integer status;
@Schema(description = "产品分类编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2")
+ @Trans(type = TransType.SIMPLE, target = CrmProductCategoryDO.class, fields = "name", ref = "categoryName")
private Long categoryId;
@Schema(description = "产品分类名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "衣服")
@ExcelProperty("产品分类")
@@ -53,12 +58,16 @@ public class CrmProductRespVO {
private String description;
@Schema(description = "负责人的用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "31926")
+ @Trans(type = TransType.RPC, targetClassName = "cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO",
+ fields = "nickname", ref = "ownerUserName")
private Long ownerUserId;
@Schema(description = "负责人的用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
@ExcelProperty("负责人")
private String ownerUserName;
@Schema(description = "创建人编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+ @Trans(type = TransType.RPC, targetClassName = "cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO",
+ fields = "nickname", ref = "creatorName")
private String creator;
@Schema(description = "创建人名字", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋道源码")
@ExcelProperty("创建人")
diff --git a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/OperateLogV2RespDTO.java b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/OperateLogV2RespDTO.java
index e217baada..2e3997cd0 100644
--- a/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/OperateLogV2RespDTO.java
+++ b/yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/logger/dto/OperateLogV2RespDTO.java
@@ -1,5 +1,8 @@
package cn.iocoder.yudao.module.system.api.logger.dto;
+import com.fhs.core.trans.anno.Trans;
+import com.fhs.core.trans.constant.TransType;
+import com.fhs.core.trans.vo.VO;
import lombok.Data;
import java.time.LocalDateTime;
@@ -10,8 +13,12 @@ import java.time.LocalDateTime;
* @author HUIHUI
*/
@Data
-public class OperateLogV2RespDTO {
+public class OperateLogV2RespDTO implements VO {
+ /**
+ * 日志编号
+ */
+ private Long id;
/**
* 链路追踪编号
*/
@@ -19,6 +26,8 @@ public class OperateLogV2RespDTO {
/**
* 用户编号
*/
+ @Trans(type = TransType.RPC, targetClassName = "cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO",
+ fields = "nickname", ref = "userName")
private Long userId;
/**
* 用户名称
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/logger/OperateLogApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/logger/OperateLogApiImpl.java
index 63d561a79..3f7b66d27 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/logger/OperateLogApiImpl.java
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/logger/OperateLogApiImpl.java
@@ -2,24 +2,19 @@ package cn.iocoder.yudao.module.system.api.logger;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogCreateReqDTO;
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2CreateReqDTO;
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2PageReqDTO;
import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2RespDTO;
-import cn.iocoder.yudao.module.system.convert.logger.OperateLogConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
-import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.logger.OperateLogService;
-import cn.iocoder.yudao.module.system.service.user.AdminUserService;
+import com.fhs.core.trans.anno.TransMethodResult;
+import jakarta.annotation.Resource;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
-import javax.annotation.Resource;
-import java.util.List;
-
-import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
-
/**
* 操作日志 API 实现类
*
@@ -31,8 +26,6 @@ public class OperateLogApiImpl implements OperateLogApi {
@Resource
private OperateLogService operateLogService;
- @Resource
- private AdminUserService adminUserService;
@Override
public void createOperateLog(OperateLogCreateReqDTO createReqDTO) {
@@ -46,16 +39,13 @@ public class OperateLogApiImpl implements OperateLogApi {
}
@Override
+ @TransMethodResult
public PageResult getOperateLogPage(OperateLogV2PageReqDTO pageReqVO) {
PageResult operateLogPage = operateLogService.getOperateLogPage(pageReqVO);
if (CollUtil.isEmpty(operateLogPage.getList())) {
return PageResult.empty();
}
-
- // 获取用户
- List userList = adminUserService.getUserList(
- convertSet(operateLogPage.getList(), OperateLogV2DO::getUserId));
- return OperateLogConvert.INSTANCE.convertPage(operateLogPage, userList);
+ return BeanUtils.toBean(operateLogPage, OperateLogV2RespDTO.class);
}
}
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.http b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.http
index f667482da..485358165 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.http
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.http
@@ -1,4 +1,4 @@
-### 请求 /system/operate-log/demo 接口 => 成功
-GET {{baseUrl}}/system/operate-log/demo
+### 请求 /system/operate-log/page 接口 => 成功
+GET {{baseUrl}}/system/operate-log/page
Authorization: Bearer {{token}}
tenant-id: {{adminTenentId}}
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.java
index 277aa0a75..2933eef29 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.java
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/OperateLogController.java
@@ -3,32 +3,29 @@ package cn.iocoder.yudao.module.system.controller.admin.logger;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
+import cn.iocoder.yudao.framework.translate.core.TranslateUtils;
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogPageReqVO;
import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogRespVO;
-import cn.iocoder.yudao.module.system.convert.logger.OperateLogConvert;
import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
-import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.logger.OperateLogService;
-import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
-import javax.annotation.Resource;
-import javax.servlet.http.HttpServletResponse;
-import javax.validation.Valid;
import java.io.IOException;
import java.util.List;
-import java.util.Map;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
-import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;
@Tag(name = "管理后台 - 操作日志")
@@ -39,19 +36,13 @@ public class OperateLogController {
@Resource
private OperateLogService operateLogService;
- @Resource
- private AdminUserService userService;
@GetMapping("/page")
@Operation(summary = "查看操作日志分页列表")
@PreAuthorize("@ss.hasPermission('system:operate-log:query')")
public CommonResult> pageOperateLog(@Valid OperateLogPageReqVO pageReqVO) {
PageResult pageResult = operateLogService.getOperateLogPage(pageReqVO);
- // 获得拼接需要的数据
- Map userMap = userService.getUserMap(
- convertList(pageResult.getList(), OperateLogDO::getUserId));
- return success(new PageResult<>(OperateLogConvert.INSTANCE.convertList(pageResult.getList(), userMap),
- pageResult.getTotal()));
+ return success(BeanUtils.toBean(pageResult, OperateLogRespVO.class));
}
@Operation(summary = "导出操作日志")
@@ -61,11 +52,8 @@ public class OperateLogController {
public void exportOperateLog(HttpServletResponse response, @Valid OperateLogPageReqVO exportReqVO) throws IOException {
exportReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List list = operateLogService.getOperateLogPage(exportReqVO).getList();
- // 输出
- Map userMap = userService.getUserMap(
- convertList(list, OperateLogDO::getUserId));
ExcelUtils.write(response, "操作日志.xls", "数据列表", OperateLogRespVO.class,
- OperateLogConvert.INSTANCE.convertList(list, userMap));
+ TranslateUtils.translate(BeanUtils.toBean(list, OperateLogRespVO.class)));
}
}
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogRespVO.java
index 3de8d669e..575dc417b 100644
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogRespVO.java
+++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/logger/vo/operatelog/OperateLogRespVO.java
@@ -2,20 +2,24 @@ package cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
+import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.enums.DictTypeConstants;
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import com.alibaba.excel.annotation.ExcelProperty;
+import com.fhs.core.trans.anno.Trans;
+import com.fhs.core.trans.constant.TransType;
+import com.fhs.core.trans.vo.VO;
import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotEmpty;
import lombok.Data;
-import javax.validation.constraints.NotEmpty;
import java.time.LocalDateTime;
import java.util.Map;
@Schema(description = "管理后台 - 操作日志 Response VO")
@Data
@ExcelIgnoreUnannotated
-public class OperateLogRespVO {
+public class OperateLogRespVO implements VO {
@Schema(description = "日志编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
@ExcelProperty("日志编号")
@@ -25,6 +29,7 @@ public class OperateLogRespVO {
private String traceId;
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+ @Trans(type = TransType.SIMPLE, target = AdminUserDO.class, fields = "nickname", ref = "userNickname")
private Long userId;
@Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "芋艿")
diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/OperateLogConvert.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/OperateLogConvert.java
deleted file mode 100644
index 9500a35f5..000000000
--- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/logger/OperateLogConvert.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package cn.iocoder.yudao.module.system.convert.logger;
-
-import cn.iocoder.yudao.framework.common.pojo.PageResult;
-import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
-import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
-import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
-import cn.iocoder.yudao.module.system.api.logger.dto.OperateLogV2RespDTO;
-import cn.iocoder.yudao.module.system.controller.admin.logger.vo.operatelog.OperateLogRespVO;
-import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogDO;
-import cn.iocoder.yudao.module.system.dal.dataobject.logger.OperateLogV2DO;
-import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
-import org.mapstruct.Mapper;
-import org.mapstruct.factory.Mappers;
-
-import java.util.List;
-import java.util.Map;
-
-import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
-import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
-
-@Mapper
-public interface OperateLogConvert {
-
- OperateLogConvert INSTANCE = Mappers.getMapper(OperateLogConvert.class);
-
- default List convertList(List list, Map userMap) {
- return CollectionUtils.convertList(list, log -> {
- OperateLogRespVO logVO = BeanUtils.toBean(log, OperateLogRespVO.class);
- MapUtils.findAndThen(userMap, log.getUserId(), user -> logVO.setUserNickname(user.getNickname()));
- return logVO;
- });
- }
-
- default PageResult convertPage(PageResult operateLogPage, List userList) {
- return BeanUtils.toBean(operateLogPage, OperateLogV2RespDTO.class).setList(setUserInfo(operateLogPage.getList(), userList));
- }
-
- OperateLogV2RespDTO convert(OperateLogV2DO operateLogV2DO);
-
- default List setUserInfo(List logList, List userList) {
- Map userMap = convertMap(userList, AdminUserDO::getId);
- return CollectionUtils.convertList(logList, item -> {
- OperateLogV2RespDTO respDTO = convert(item);
- findAndThen(userMap, item.getUserId(), user -> respDTO.setUserName(user.getNickname()));
- return respDTO;
- });
- }
-
-}
diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml
index 19aa7d73b..d8d6c493d 100644
--- a/yudao-server/src/main/resources/application.yaml
+++ b/yudao-server/src/main/resources/application.yaml
@@ -91,6 +91,12 @@ spring:
redis:
repositories:
enabled: false # 项目未使用到 Spring Data Redis 的 Repository,所以直接禁用,保证启动速度
+
+# VO 转换(数据翻译)相关
+easy-trans:
+ is-enable-global: true # 启用全局翻译(拦截所有 SpringMVC ResponseBody 进行自动翻译 )。如果对于性能要求很高可关闭此配置,或通过 @IgnoreTrans 忽略某个接口
+ is-enable-cloud: false # 禁用 TransType.RPC 微服务模式
+
--- #################### 验证码相关配置 ####################
aj: