Commit 8c9b483ac596e1fcadcb2f02a15c7fca5b8a9b14
1 parent
9c3cf1d6
📖 code review 操作日志的实现
Showing
20 changed files
with
76 additions
and
80 deletions
yudao-framework/yudao-spring-boot-starter-security/pom.xml
| ... | ... | @@ -12,7 +12,10 @@ |
| 12 | 12 | <packaging>jar</packaging> |
| 13 | 13 | |
| 14 | 14 | <name>${project.artifactId}</name> |
| 15 | - <description>用户的认证、权限的校验</description> | |
| 15 | + <description> | |
| 16 | + 1. security:用户的认证、权限的校验,实现「谁」可以做「什么事」 | |
| 17 | + 2. operatelog:操作日志,实现「谁」在「什么时间」对「什么」做了「什么事」 | |
| 18 | + </description> | |
| 16 | 19 | <url>https://github.com/YunaiV/ruoyi-vue-pro</url> |
| 17 | 20 | |
| 18 | 21 | <dependencies> | ... | ... |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/config/YudaoOperateLogV2Configuration.java
| ... | ... | @@ -8,9 +8,8 @@ import org.springframework.boot.autoconfigure.AutoConfiguration; |
| 8 | 8 | import org.springframework.context.annotation.Bean; |
| 9 | 9 | import org.springframework.context.annotation.Primary; |
| 10 | 10 | |
| 11 | - | |
| 12 | 11 | /** |
| 13 | - * mzt-biz-log 配置类 | |
| 12 | + * 操作日志配置类 | |
| 14 | 13 | * |
| 15 | 14 | * @author HUIHUI |
| 16 | 15 | */ | ... | ... |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/core/package-info.java
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/core/service/ILogRecordServiceImpl.java
| ... | ... | @@ -11,9 +11,9 @@ import jakarta.annotation.Resource; |
| 11 | 11 | import jakarta.servlet.http.HttpServletRequest; |
| 12 | 12 | import lombok.extern.slf4j.Slf4j; |
| 13 | 13 | |
| 14 | -import java.util.Collections; | |
| 15 | 14 | import java.util.List; |
| 16 | 15 | |
| 16 | +// TODO @puhui999:LogRecordServiceImpl 改成这个名字哈 | |
| 17 | 17 | /** |
| 18 | 18 | * 操作日志 ILogRecordService 实现类 |
| 19 | 19 | * |
| ... | ... | @@ -26,11 +26,11 @@ public class ILogRecordServiceImpl implements ILogRecordService { |
| 26 | 26 | |
| 27 | 27 | @Resource |
| 28 | 28 | private OperateLogApi operateLogApi; |
| 29 | - | |
| 29 | + | |
| 30 | 30 | @Override |
| 31 | 31 | public void record(LogRecord logRecord) { |
| 32 | + // 1. 补全通用字段 | |
| 32 | 33 | OperateLogV2CreateReqDTO reqDTO = new OperateLogV2CreateReqDTO(); |
| 33 | - // 补全通用字段 | |
| 34 | 34 | reqDTO.setTraceId(TracerUtils.getTraceId()); |
| 35 | 35 | // 补充用户信息 |
| 36 | 36 | fillUserFields(reqDTO); |
| ... | ... | @@ -38,22 +38,24 @@ public class ILogRecordServiceImpl implements ILogRecordService { |
| 38 | 38 | fillModuleFields(reqDTO, logRecord); |
| 39 | 39 | // 补全请求信息 |
| 40 | 40 | fillRequestFields(reqDTO); |
| 41 | - // 异步记录日志 | |
| 41 | + | |
| 42 | + // 2. 异步记录日志 | |
| 42 | 43 | operateLogApi.createOperateLogV2(reqDTO); |
| 43 | 44 | // TODO 测试结束删除或搞个开关 |
| 44 | 45 | log.info("操作日志 ===> {}", reqDTO); |
| 45 | 46 | } |
| 46 | 47 | |
| 47 | 48 | private static void fillUserFields(OperateLogV2CreateReqDTO reqDTO) { |
| 49 | + // TODO @puhui999:使用 SecurityFrameworkUtils。因为要考虑,rpc、mq、job,它其实不是 web; | |
| 48 | 50 | reqDTO.setUserId(WebFrameworkUtils.getLoginUserId()); |
| 49 | 51 | reqDTO.setUserType(WebFrameworkUtils.getLoginUserType()); |
| 50 | 52 | } |
| 51 | 53 | |
| 52 | 54 | public static void fillModuleFields(OperateLogV2CreateReqDTO reqDTO, LogRecord logRecord) { |
| 53 | - reqDTO.setType(logRecord.getType()); // 大模块类型如 crm 客户 | |
| 54 | - reqDTO.setSubType(logRecord.getSubType());// 操作名称如 转移客户 | |
| 55 | - reqDTO.setBizId(Long.parseLong(logRecord.getBizNo())); // 操作模块业务编号 | |
| 56 | - reqDTO.setAction(logRecord.getAction());// 例如说,修改编号为 1 的用户信息,将性别从男改成女,将姓名从芋道改成源码。 | |
| 55 | + reqDTO.setType(logRecord.getType()); // 大模块类型,例如:CRM 客户 | |
| 56 | + reqDTO.setSubType(logRecord.getSubType());// 操作名称,例如:转移客户 | |
| 57 | + reqDTO.setBizId(Long.parseLong(logRecord.getBizNo())); // 业务编号,例如:客户编号 | |
| 58 | + reqDTO.setAction(logRecord.getAction());// 操作内容,例如:修改编号为 1 的用户信息,将性别从男改成女,将姓名从芋道改成源码。 | |
| 57 | 59 | reqDTO.setExtra(logRecord.getExtra()); // 拓展字段,有些复杂的业务,需要记录一些字段 ( JSON 格式 ),例如说,记录订单编号,{ orderId: "1"} |
| 58 | 60 | } |
| 59 | 61 | |
| ... | ... | @@ -72,12 +74,12 @@ public class ILogRecordServiceImpl implements ILogRecordService { |
| 72 | 74 | |
| 73 | 75 | @Override |
| 74 | 76 | public List<LogRecord> queryLog(String bizNo, String type) { |
| 75 | - return Collections.emptyList(); | |
| 77 | + throw new UnsupportedOperationException("使用 OperateLogApi 进行操作日志的查询"); | |
| 76 | 78 | } |
| 77 | 79 | |
| 78 | 80 | @Override |
| 79 | 81 | public List<LogRecord> queryLogByBizNo(String bizNo, String type, String subType) { |
| 80 | - return Collections.emptyList(); | |
| 82 | + throw new UnsupportedOperationException("使用 OperateLogApi 进行操作日志的查询"); | |
| 81 | 83 | } |
| 82 | 84 | |
| 83 | 85 | -} |
| 86 | +} | |
| 84 | 87 | \ No newline at end of file | ... | ... |
yudao-framework/yudao-spring-boot-starter-security/src/main/java/cn/iocoder/yudao/framework/operatelog/package-info.java
0 → 100644
yudao-module-crm/yudao-module-crm-api/src/main/java/cn/iocoder/yudao/module/crm/enums/LogRecordConstants.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.enums; |
| 2 | 2 | |
| 3 | -// TODO 芋艿:操作日志;看看这个类怎么搞个好点的规范; | |
| 4 | 3 | /** |
| 5 | 4 | * CRM 操作日志枚举 |
| 6 | 5 | * |
| ... | ... | @@ -23,4 +22,12 @@ public interface LogRecordConstants { |
| 23 | 22 | |
| 24 | 23 | String TRANSFER_CUSTOMER_LOG_SUCCESS = "把客户【{{#crmCustomer.name}}】的负责人从【{getAdminUserById{#crmCustomer.ownerUserId}}】变更为了【{getAdminUserById{#reqVO.newOwnerUserId}}】"; |
| 25 | 24 | |
| 25 | + // TODO @puhui999:这里格式是不是可以这样;目的是:统一管理,也减少 Service 里各种“复杂”字符串 | |
| 26 | + // ======================= Customer 客户 ======================= | |
| 27 | + String CUSTOMER_TYPE = "CRM 客户"; | |
| 28 | + String CUSTOMER_CREATE_SUB_TYPE = "创建客户"; | |
| 29 | + String CUSTOMER_CREATE_SUCCESS = "更新了客户{_DIFF{#updateReqVO}}"; | |
| 30 | + | |
| 31 | + String CUSTOMER_UPDATE_SUB_TYPE = "更新客户"; | |
| 32 | + | |
| 26 | 33 | } | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/controller/admin/customer/CrmCustomerController.java
| ... | ... | @@ -60,7 +60,7 @@ public class CrmCustomerController { |
| 60 | 60 | |
| 61 | 61 | @PostMapping("/create") |
| 62 | 62 | @Operation(summary = "创建客户") |
| 63 | - @OperateLog(enable = false) // TODO 关闭原有日志记录 | |
| 63 | + @OperateLog(enable = false) // TODO 关闭原有日志记录;@puhui999:注解都先删除。先记录,没关系。我们下个迭代,就都删除掉操作日志了; | |
| 64 | 64 | @PreAuthorize("@ss.hasPermission('crm:customer:create')") |
| 65 | 65 | public CommonResult<Long> createCustomer(@Valid @RequestBody CrmCustomerCreateReqVO createReqVO) { |
| 66 | 66 | return success(customerService.createCustomer(createReqVO, getLoginUserId())); |
| ... | ... | @@ -102,6 +102,7 @@ public class CrmCustomerController { |
| 102 | 102 | return success(CrmCustomerConvert.INSTANCE.convert(customer, userMap, deptMap)); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | + // TODO @puhui999:这个查询会查出多个;微信发你图了 | |
| 105 | 106 | @GetMapping("/page") |
| 106 | 107 | @Operation(summary = "获得客户分页") |
| 107 | 108 | @PreAuthorize("@ss.hasPermission('crm:customer:query')") |
| ... | ... | @@ -141,6 +142,7 @@ public class CrmCustomerController { |
| 141 | 142 | return success(true); |
| 142 | 143 | } |
| 143 | 144 | |
| 145 | + // TODO @puhui999:是不是接口只要传递 bizId,由 Controller 自己组装出 OperateLogV2PageReqDTO | |
| 144 | 146 | @GetMapping("/operate-log-page") |
| 145 | 147 | @Operation(summary = "获得客户操作日志") |
| 146 | 148 | @PreAuthorize("@ss.hasPermission('crm:customer:query')") | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/operatelog/core/CrmIndustryParseFunction.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.framework.operatelog.core; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.util.ObjUtil; | |
| 4 | 3 | import cn.hutool.core.util.StrUtil; |
| 5 | 4 | import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; |
| 6 | 5 | import com.mzt.logapi.service.IParseFunction; |
| ... | ... | @@ -10,7 +9,7 @@ import org.springframework.stereotype.Component; |
| 10 | 9 | import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_INDUSTRY; |
| 11 | 10 | |
| 12 | 11 | /** |
| 13 | - * 自定义函数-通过行业编号获取行业信息 | |
| 12 | + * 行业的 {@link IParseFunction} 实现类 | |
| 14 | 13 | * |
| 15 | 14 | * @author HUIHUI |
| 16 | 15 | */ |
| ... | ... | @@ -30,14 +29,9 @@ public class CrmIndustryParseFunction implements IParseFunction { |
| 30 | 29 | |
| 31 | 30 | @Override |
| 32 | 31 | public String apply(Object value) { |
| 33 | - if (ObjUtil.isEmpty(value)) { | |
| 32 | + if (StrUtil.isEmptyIfStr(value)) { | |
| 34 | 33 | return ""; |
| 35 | 34 | } |
| 36 | - if (StrUtil.isEmpty(value.toString())) { | |
| 37 | - return ""; | |
| 38 | - } | |
| 39 | - | |
| 40 | - // 获取行业信息 | |
| 41 | 35 | return DictFrameworkUtils.getDictDataLabel(CRM_CUSTOMER_INDUSTRY, value.toString()); |
| 42 | 36 | } |
| 43 | 37 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/operatelog/core/CrmLevelParseFunction.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.framework.operatelog.core; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.util.ObjUtil; | |
| 4 | 3 | import cn.hutool.core.util.StrUtil; |
| 5 | 4 | import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; |
| 6 | 5 | import com.mzt.logapi.service.IParseFunction; |
| ... | ... | @@ -10,7 +9,7 @@ import org.springframework.stereotype.Component; |
| 10 | 9 | import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_LEVEL; |
| 11 | 10 | |
| 12 | 11 | /** |
| 13 | - * 自定义函数-通过客户等级编号获取客户等级信息 | |
| 12 | + * 客户等级的 {@link IParseFunction} 实现类 | |
| 14 | 13 | * |
| 15 | 14 | * @author HUIHUI |
| 16 | 15 | */ |
| ... | ... | @@ -30,14 +29,9 @@ public class CrmLevelParseFunction implements IParseFunction { |
| 30 | 29 | |
| 31 | 30 | @Override |
| 32 | 31 | public String apply(Object value) { |
| 33 | - if (ObjUtil.isEmpty(value)) { | |
| 32 | + if (StrUtil.isEmptyIfStr(value)) { | |
| 34 | 33 | return ""; |
| 35 | 34 | } |
| 36 | - if (StrUtil.isEmpty(value.toString())) { | |
| 37 | - return ""; | |
| 38 | - } | |
| 39 | - | |
| 40 | - // 获取客户等级信息 | |
| 41 | 35 | return DictFrameworkUtils.getDictDataLabel(CRM_CUSTOMER_LEVEL, value.toString()); |
| 42 | 36 | } |
| 43 | 37 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/operatelog/core/CrmSourceParseFunction.java
| 1 | 1 | package cn.iocoder.yudao.module.crm.framework.operatelog.core; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.util.ObjUtil; | |
| 4 | 3 | import cn.hutool.core.util.StrUtil; |
| 5 | 4 | import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; |
| 6 | 5 | import com.mzt.logapi.service.IParseFunction; |
| ... | ... | @@ -10,7 +9,7 @@ import org.springframework.stereotype.Component; |
| 10 | 9 | import static cn.iocoder.yudao.module.crm.enums.DictTypeConstants.CRM_CUSTOMER_SOURCE; |
| 11 | 10 | |
| 12 | 11 | /** |
| 13 | - * 自定义函数-通过客户来源编号获取客户来源信息 | |
| 12 | + * 客户来源的 {@link IParseFunction} 实现类 | |
| 14 | 13 | * |
| 15 | 14 | * @author HUIHUI |
| 16 | 15 | */ |
| ... | ... | @@ -30,14 +29,9 @@ public class CrmSourceParseFunction implements IParseFunction { |
| 30 | 29 | |
| 31 | 30 | @Override |
| 32 | 31 | public String apply(Object value) { |
| 33 | - if (ObjUtil.isEmpty(value)) { | |
| 32 | + if (StrUtil.isEmptyIfStr(value)) { | |
| 34 | 33 | return ""; |
| 35 | 34 | } |
| 36 | - if (StrUtil.isEmpty(value.toString())) { | |
| 37 | - return ""; | |
| 38 | - } | |
| 39 | - | |
| 40 | - // 获取客户来源信息 | |
| 41 | 35 | return DictFrameworkUtils.getDictDataLabel(CRM_CUSTOMER_SOURCE, value.toString()); |
| 42 | 36 | } |
| 43 | 37 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/framework/permission/core/util/CrmPermissionUtils.java
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/customer/CrmCustomerServiceImpl.java
| ... | ... | @@ -62,7 +62,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { |
| 62 | 62 | crmPermissionService.createPermission(new CrmPermissionCreateReqBO().setBizType(CrmBizTypeEnum.CRM_CUSTOMER.getType()) |
| 63 | 63 | .setBizId(customer.getId()).setUserId(userId).setLevel(CrmPermissionLevelEnum.OWNER.getLevel())); // 设置当前操作的人为负责人 |
| 64 | 64 | |
| 65 | - // 添加日志上下文所需 | |
| 65 | + // 记录操作日志 | |
| 66 | 66 | LogRecordContext.putVariable("customerId", customer.getId()); |
| 67 | 67 | return customer.getId(); |
| 68 | 68 | } |
| ... | ... | @@ -73,15 +73,15 @@ public class CrmCustomerServiceImpl implements CrmCustomerService { |
| 73 | 73 | @CrmPermission(bizType = CrmBizTypeEnum.CRM_CUSTOMER, bizId = "#updateReqVO.id", level = CrmPermissionLevelEnum.WRITE) |
| 74 | 74 | public void updateCustomer(CrmCustomerUpdateReqVO updateReqVO) { |
| 75 | 75 | // 校验存在 |
| 76 | - CrmCustomerDO oldCustomerDO = validateCustomerExists(updateReqVO.getId()); | |
| 76 | + CrmCustomerDO oldCustomer = validateCustomerExists(updateReqVO.getId()); | |
| 77 | 77 | |
| 78 | 78 | // 更新 |
| 79 | 79 | CrmCustomerDO updateObj = CrmCustomerConvert.INSTANCE.convert(updateReqVO); |
| 80 | 80 | customerMapper.updateById(updateObj); |
| 81 | 81 | |
| 82 | - // __DIFF 函数传递了一个参数,传递的参数是修改之后的对象,这种方式需要在方法内部向 LogRecordContext 中 put 一个变量,代表是之前的对象,这个对象可以是null | |
| 83 | - LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomerDO, CrmCustomerUpdateReqVO.class)); | |
| 84 | - // TODO 扩展信息测试 | |
| 82 | + // 记录操作日志 | |
| 83 | + LogRecordContext.putVariable(DiffParseFunction.OLD_OBJECT, BeanUtils.toBean(oldCustomer, CrmCustomerUpdateReqVO.class)); | |
| 84 | + // TODO 扩展信息测试 @puhui999:看着没啥问题,可以删除啦; | |
| 85 | 85 | HashMap<String, Object> extra = new HashMap<>(); |
| 86 | 86 | extra.put("tips", "随便记录一点啦"); |
| 87 | 87 | LogRecordContext.putVariable("extra", extra); | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/service/permission/CrmPermissionServiceImpl.java
| ... | ... | @@ -90,7 +90,8 @@ public class CrmPermissionServiceImpl implements CrmPermissionService { |
| 90 | 90 | CrmPermissionDO oldPermission = crmPermissionMapper.selectByBizTypeAndBizIdByUserId( |
| 91 | 91 | transferReqBO.getBizType(), transferReqBO.getBizId(), transferReqBO.getUserId()); |
| 92 | 92 | String bizTypeName = CrmBizTypeEnum.getNameByType(transferReqBO.getBizType()); |
| 93 | - if (oldPermission == null || (!isOwner(oldPermission.getLevel()) && !CrmPermissionUtils.isCrmAdmin())) { // 不是拥有者,并且不是超管 | |
| 93 | + if (oldPermission == null // 不是拥有者,并且不是超管 | |
| 94 | + || (!isOwner(oldPermission.getLevel()) && !CrmPermissionUtils.isCrmAdmin())) { | |
| 94 | 95 | throw exception(CRM_PERMISSION_DENIED, bizTypeName); |
| 95 | 96 | } |
| 96 | 97 | // 1.1 校验转移对象是否已经是该负责人 | ... | ... |
yudao-module-crm/yudao-module-crm-biz/src/main/java/cn/iocoder/yudao/module/crm/util/CrmQueryWrapperUtils.java
| ... | ... | @@ -40,7 +40,7 @@ public class CrmQueryWrapperUtils { |
| 40 | 40 | Long userId, Integer sceneType, Boolean pool) { |
| 41 | 41 | final String ownerUserIdField = SingletonManager.getMybatisPlusJoinProperties().getTableAlias() + ".owner_user_id"; |
| 42 | 42 | // 1. 构建数据权限连表条件 |
| 43 | - if (ObjUtil.notEqual(CrmPermissionUtils.isCrmAdmin(), Boolean.TRUE) && ObjUtil.notEqual(pool, Boolean.TRUE)) { // 管理员,公海不需要数据权限 | |
| 43 | + if (!CrmPermissionUtils.isCrmAdmin() && ObjUtil.notEqual(pool, Boolean.TRUE)) { // 管理员,公海不需要数据权限 | |
| 44 | 44 | query.innerJoin(CrmPermissionDO.class, on -> on.eq(CrmPermissionDO::getBizType, bizType) |
| 45 | 45 | .eq(CrmPermissionDO::getBizId, bizId) // 只能使用 SFunction 如果传 id 解析出来的 sql 不对 |
| 46 | 46 | .eq(CrmPermissionDO::getUserId, userId)); |
| ... | ... | @@ -81,7 +81,7 @@ public class CrmQueryWrapperUtils { |
| 81 | 81 | * @param userId 用户编号 |
| 82 | 82 | */ |
| 83 | 83 | public static <T extends MPJLambdaWrapper<?>> void appendPermissionCondition(T query, Integer bizType, Collection<Long> bizIds, Long userId) { |
| 84 | - if (ObjUtil.equal(CrmPermissionUtils.isCrmAdmin(), Boolean.TRUE)) {// 管理员不需要数据权限 | |
| 84 | + if (CrmPermissionUtils.isCrmAdmin()) {// 管理员不需要数据权限 | |
| 85 | 85 | return; |
| 86 | 86 | } |
| 87 | 87 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/logger/OperateLogApiImpl.java
| ... | ... | @@ -53,7 +53,8 @@ public class OperateLogApiImpl implements OperateLogApi { |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // 获取用户 |
| 56 | - List<AdminUserDO> userList = adminUserService.getUserList(convertSet(operateLogPage.getList(), OperateLogV2DO::getUserId)); | |
| 56 | + List<AdminUserDO> userList = adminUserService.getUserList( | |
| 57 | + convertSet(operateLogPage.getList(), OperateLogV2DO::getUserId)); | |
| 57 | 58 | return OperateLogConvert.INSTANCE.convertPage(operateLogPage, userList); |
| 58 | 59 | } |
| 59 | 60 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/logger/OperateLogV2Mapper.java
| ... | ... | @@ -10,12 +10,12 @@ import org.apache.ibatis.annotations.Mapper; |
| 10 | 10 | @Mapper |
| 11 | 11 | public interface OperateLogV2Mapper extends BaseMapperX<OperateLogV2DO> { |
| 12 | 12 | |
| 13 | - default PageResult<OperateLogV2DO> selectPage(OperateLogV2PageReqDTO pageReqVO) { | |
| 14 | - return selectPage(pageReqVO, new LambdaQueryWrapperX<OperateLogV2DO>() | |
| 15 | - .eqIfPresent(OperateLogV2DO::getType, pageReqVO.getBizType()) | |
| 16 | - .eqIfPresent(OperateLogV2DO::getBizId, pageReqVO.getBizId()) | |
| 17 | - .eqIfPresent(OperateLogV2DO::getUserId, pageReqVO.getUserId()) | |
| 18 | - .orderByDesc(OperateLogV2DO::getCreateTime)); | |
| 13 | + default PageResult<OperateLogV2DO> selectPage(OperateLogV2PageReqDTO pageReqDTO) { | |
| 14 | + return selectPage(pageReqDTO, new LambdaQueryWrapperX<OperateLogV2DO>() | |
| 15 | + .eqIfPresent(OperateLogV2DO::getType, pageReqDTO.getBizType()) | |
| 16 | + .eqIfPresent(OperateLogV2DO::getBizId, pageReqDTO.getBizId()) | |
| 17 | + .eqIfPresent(OperateLogV2DO::getUserId, pageReqDTO.getUserId()) | |
| 18 | + .orderByDesc(OperateLogV2DO::getId)); | |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/operatelog/core/AdminUserParseFunction.java
| 1 | 1 | package cn.iocoder.yudao.module.system.framework.operatelog.core; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.util.ObjUtil; | |
| 4 | 3 | import cn.hutool.core.util.StrUtil; |
| 5 | 4 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 6 | 5 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| ... | ... | @@ -10,7 +9,7 @@ import lombok.extern.slf4j.Slf4j; |
| 10 | 9 | import org.springframework.stereotype.Component; |
| 11 | 10 | |
| 12 | 11 | /** |
| 13 | - * 自定义函数-通过用户编号获取用户信息 | |
| 12 | + * 管理员名字的 {@link IParseFunction} 实现类 | |
| 14 | 13 | * |
| 15 | 14 | * @author HUIHUI |
| 16 | 15 | */ |
| ... | ... | @@ -28,25 +27,22 @@ public class AdminUserParseFunction implements IParseFunction { |
| 28 | 27 | |
| 29 | 28 | @Override |
| 30 | 29 | public String apply(Object value) { |
| 31 | - if (ObjUtil.isEmpty(value)) { | |
| 32 | - return ""; | |
| 33 | - } | |
| 34 | - if (StrUtil.isEmpty(value.toString())) { | |
| 30 | + if (StrUtil.isEmptyIfStr(value)) { | |
| 35 | 31 | return ""; |
| 36 | 32 | } |
| 37 | 33 | |
| 38 | 34 | // 获取用户信息 |
| 39 | 35 | AdminUserRespDTO user = adminUserApi.getUser(Long.parseLong(value.toString())); |
| 40 | 36 | if (user == null) { |
| 41 | - log.warn("(getAdminUserById) 获取用户信息失败,参数为:{}", value); | |
| 37 | + log.warn("[apply][获取用户{{}}为空", value); | |
| 42 | 38 | return ""; |
| 43 | 39 | } |
| 44 | 40 | // 返回格式 芋道源码(13888888888) |
| 45 | 41 | String nickname = user.getNickname(); |
| 46 | - if (ObjUtil.isNotEmpty(user.getMobile())) { | |
| 47 | - return nickname.concat("(").concat(user.getMobile()).concat(")"); | |
| 42 | + if (StrUtil.isEmpty(user.getMobile())) { | |
| 43 | + return nickname; | |
| 48 | 44 | } |
| 49 | - return nickname; | |
| 45 | + return StrUtil.format("{}({})", nickname, user.getMobile()); | |
| 50 | 46 | } |
| 51 | 47 | |
| 52 | 48 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/operatelog/core/AreaParseFunction.java
| 1 | 1 | package cn.iocoder.yudao.module.system.framework.operatelog.core; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.util.ObjUtil; | |
| 4 | 3 | import cn.hutool.core.util.StrUtil; |
| 5 | 4 | import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; |
| 6 | 5 | import com.mzt.logapi.service.IParseFunction; |
| ... | ... | @@ -8,7 +7,7 @@ import lombok.extern.slf4j.Slf4j; |
| 8 | 7 | import org.springframework.stereotype.Component; |
| 9 | 8 | |
| 10 | 9 | /** |
| 11 | - * 自定义函数-通过区域编号获取区域信息 | |
| 10 | + * 地名的 {@link IParseFunction} 实现类 | |
| 12 | 11 | * |
| 13 | 12 | * @author HUIHUI |
| 14 | 13 | */ |
| ... | ... | @@ -28,13 +27,9 @@ public class AreaParseFunction implements IParseFunction { |
| 28 | 27 | |
| 29 | 28 | @Override |
| 30 | 29 | public String apply(Object value) { |
| 31 | - if (ObjUtil.isEmpty(value)) { | |
| 30 | + if (StrUtil.isEmptyIfStr(value)) { | |
| 32 | 31 | return ""; |
| 33 | 32 | } |
| 34 | - if (StrUtil.isEmpty(value.toString())) { | |
| 35 | - return ""; | |
| 36 | - } | |
| 37 | - | |
| 38 | 33 | return AreaUtils.format(Integer.parseInt(value.toString())); |
| 39 | 34 | } |
| 40 | 35 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogService.java
| ... | ... | @@ -35,9 +35,9 @@ public interface OperateLogService { |
| 35 | 35 | /** |
| 36 | 36 | * 记录操作日志 V2 |
| 37 | 37 | * |
| 38 | - * @param createReqBO 创建请求 | |
| 38 | + * @param createReqDTO 创建请求 | |
| 39 | 39 | */ |
| 40 | - void createOperateLogV2(OperateLogV2CreateReqDTO createReqBO); | |
| 40 | + void createOperateLogV2(OperateLogV2CreateReqDTO createReqDTO); | |
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * 获得操作日志分页列表 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/logger/OperateLogServiceImpl.java
| ... | ... | @@ -69,15 +69,14 @@ public class OperateLogServiceImpl implements OperateLogService { |
| 69 | 69 | // ======================= LOG V2 ======================= |
| 70 | 70 | |
| 71 | 71 | @Override |
| 72 | - public void createOperateLogV2(OperateLogV2CreateReqDTO createReqBO) { | |
| 73 | - OperateLogV2DO log = BeanUtils.toBean(createReqBO, OperateLogV2DO.class); | |
| 72 | + public void createOperateLogV2(OperateLogV2CreateReqDTO createReqDTO) { | |
| 73 | + OperateLogV2DO log = BeanUtils.toBean(createReqDTO, OperateLogV2DO.class); | |
| 74 | 74 | operateLogV2Mapper.insert(log); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - | |
| 78 | 77 | @Override |
| 79 | - public PageResult<OperateLogV2DO> getOperateLogPage(OperateLogV2PageReqDTO pageReqVO) { | |
| 80 | - return operateLogV2Mapper.selectPage(pageReqVO); | |
| 78 | + public PageResult<OperateLogV2DO> getOperateLogPage(OperateLogV2PageReqDTO pageReqDTO) { | |
| 79 | + return operateLogV2Mapper.selectPage(pageReqDTO); | |
| 81 | 80 | } |
| 82 | 81 | |
| 83 | 82 | } | ... | ... |