wrapper = Wrappers.lambdaUpdate(ConfigAllInfo.class)
.eq(ConfigAllInfo::getTpId, config.getTpId())
@@ -173,8 +170,10 @@ public class ConfigServiceImpl implements ConfigService {
config.setGmtCreate(null);
config.setContent(ContentUtil.getPoolContent(config));
config.setMd5(Md5Util.getTpContentMd5(config));
+ recordOperationLog(config);
try {
- // 创建线程池配置实例临时配置, 也可以当作历史配置, 不过针对的是单节点
+ // Create a temporary configuration of a thread pool configuration instance,
+ // which can also be used as a historical configuration, but it is aimed at a single node.
if (StringUtil.isNotBlank(identify)) {
ConfigInstanceInfo instanceInfo = BeanUtil.convert(config, ConfigInstanceInfo.class);
instanceInfo.setInstanceId(identify);
@@ -198,10 +197,23 @@ public class ConfigServiceImpl implements ConfigService {
}
}
+ private void recordOperationLog(ConfigAllInfo requestParam) {
+ LogRecordInfo logRecordInfo = LogRecordInfo.builder()
+ .bizKey(requestParam.getItemId() + "_" + requestParam.getTpId())
+ .bizNo(requestParam.getItemId() + "_" + requestParam.getTpId())
+ .operator(Optional.ofNullable(UserContext.getUserName()).orElse("-"))
+ .action(String.format("核心线程: %d, 最大线程: %d, 队列类型: %d, 队列容量: %d, 拒绝策略: %d", requestParam.getCoreSize(), requestParam.getMaxSize(), requestParam.getQueueType(), requestParam.getCapacity(), requestParam.getRejectedType()))
+ .category("THREAD_POOL_UPDATE")
+ .detail(JSONUtil.toJSONString(requestParam))
+ .createTime(new Date())
+ .build();
+ operationLogService.record(logRecordInfo);
+ }
+
/**
- * 根据队列类型获取队列大小.
- *
- * 不支持设置队列大小 {@link SynchronousQueue} {@link LinkedTransferQueue}
+ * Get queue size based on queue type.
+ *
+ *
不支持设置队列大小 {@link SynchronousQueue} {@link LinkedTransferQueue}
*
* @param config
* @return
diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/LogRecordServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/LogRecordServiceImpl.java
deleted file mode 100644
index d0f1d405..00000000
--- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/LogRecordServiceImpl.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package cn.hippo4j.config.service.biz.impl;
-
-import cn.hippo4j.config.mapper.LogRecordMapper;
-import cn.hippo4j.tools.logrecord.model.LogRecordInfo;
-import cn.hippo4j.tools.logrecord.service.LogRecordService;
-import lombok.AllArgsConstructor;
-import org.springframework.stereotype.Service;
-
-/**
- * 操作日志保存数据库.
- *
- * @author chen.ma
- * @date 2021/10/24 20:57
- */
-@Service
-@AllArgsConstructor
-public class LogRecordServiceImpl implements LogRecordService {
-
- private final LogRecordMapper logRecordMapper;
-
- @Override
- public void record(LogRecordInfo logRecordInfo) {
- logRecordMapper.insert(logRecordInfo);
- }
-
-}
diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/LogRecordBizServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/OperationLogServiceImpl.java
similarity index 79%
rename from hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/LogRecordBizServiceImpl.java
rename to hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/OperationLogServiceImpl.java
index 760eb5d5..dd0ed0f0 100644
--- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/LogRecordBizServiceImpl.java
+++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/OperationLogServiceImpl.java
@@ -17,12 +17,12 @@
package cn.hippo4j.config.service.biz.impl;
-import cn.hippo4j.config.mapper.LogRecordMapper;
+import cn.hippo4j.config.mapper.OperationLogMapper;
+import cn.hippo4j.config.model.LogRecordInfo;
import cn.hippo4j.config.model.biz.log.LogRecordQueryReqDTO;
import cn.hippo4j.config.model.biz.log.LogRecordRespDTO;
-import cn.hippo4j.config.service.biz.LogRecordBizService;
+import cn.hippo4j.config.service.biz.OperationLogService;
import cn.hippo4j.config.toolkit.BeanUtil;
-import cn.hippo4j.tools.logrecord.model.LogRecordInfo;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -31,16 +31,16 @@ import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
/**
- * 操作日志.
+ * Operation log service impl.
*
* @author chen.ma
* @date 2021/11/17 21:50
*/
@Service
@AllArgsConstructor
-public class LogRecordBizServiceImpl implements LogRecordBizService {
+public class OperationLogServiceImpl implements OperationLogService {
- private final LogRecordMapper logRecordMapper;
+ private final OperationLogMapper operationLogMapper;
@Override
public IPage queryPage(LogRecordQueryReqDTO pageQuery) {
@@ -49,8 +49,12 @@ public class LogRecordBizServiceImpl implements LogRecordBizService {
.eq(StrUtil.isNotBlank(pageQuery.getCategory()), LogRecordInfo::getCategory, pageQuery.getCategory())
.eq(StrUtil.isNotBlank(pageQuery.getOperator()), LogRecordInfo::getOperator, pageQuery.getOperator())
.orderByDesc(LogRecordInfo::getCreateTime);
- IPage selectPage = logRecordMapper.selectPage(pageQuery, queryWrapper);
+ IPage selectPage = operationLogMapper.selectPage(pageQuery, queryWrapper);
return selectPage.convert(each -> BeanUtil.convert(each, LogRecordRespDTO.class));
}
+ @Override
+ public void record(LogRecordInfo requestParam) {
+ operationLogMapper.insert(requestParam);
+ }
}
diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/TenantServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/TenantServiceImpl.java
index 6a9501f3..85950f2f 100644
--- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/TenantServiceImpl.java
+++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/TenantServiceImpl.java
@@ -17,8 +17,8 @@
package cn.hippo4j.config.service.biz.impl;
-import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.common.enums.DelEnum;
+import cn.hippo4j.common.toolkit.Assert;
import cn.hippo4j.config.mapper.TenantInfoMapper;
import cn.hippo4j.config.model.TenantInfo;
import cn.hippo4j.config.model.biz.item.ItemQueryReqDTO;
@@ -30,7 +30,6 @@ import cn.hippo4j.config.model.biz.tenant.TenantUpdateReqDTO;
import cn.hippo4j.config.service.biz.ItemService;
import cn.hippo4j.config.service.biz.TenantService;
import cn.hippo4j.config.toolkit.BeanUtil;
-import cn.hippo4j.tools.logrecord.annotation.LogRecord;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@@ -102,7 +101,6 @@ public class TenantServiceImpl implements TenantService {
}
@Override
- @LogRecord(prefix = "item", bizNo = "{{#reqDTO.tenantId}}_{{#reqDTO.tenantName}}", category = "TENANT_UPDATE", success = "更新租户, ID :: {{#reqDTO.id}}, 租户名称由 :: {TENANT{#reqDTO.id}} -> {{#reqDTO.tenantName}}", detail = "{{#reqDTO.toString()}}")
public void updateTenant(TenantUpdateReqDTO reqDTO) {
TenantInfo tenantInfo = BeanUtil.convert(reqDTO, TenantInfo.class);
int updateResult = tenantInfoMapper.update(tenantInfo, Wrappers
diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolServiceImpl.java
index ebecdf8d..8e704112 100644
--- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolServiceImpl.java
+++ b/hippo4j-config/src/main/java/cn/hippo4j/config/service/biz/impl/ThreadPoolServiceImpl.java
@@ -18,16 +18,19 @@
package cn.hippo4j.config.service.biz.impl;
import cn.hippo4j.common.enums.DelEnum;
+import cn.hippo4j.common.toolkit.JSONUtil;
+import cn.hippo4j.common.toolkit.UserContext;
import cn.hippo4j.config.mapper.ConfigInfoMapper;
import cn.hippo4j.config.model.ConfigAllInfo;
+import cn.hippo4j.config.model.LogRecordInfo;
import cn.hippo4j.config.model.biz.threadpool.ThreadPoolDelReqDTO;
import cn.hippo4j.config.model.biz.threadpool.ThreadPoolQueryReqDTO;
import cn.hippo4j.config.model.biz.threadpool.ThreadPoolRespDTO;
import cn.hippo4j.config.model.biz.threadpool.ThreadPoolSaveOrUpdateReqDTO;
import cn.hippo4j.config.service.biz.ConfigService;
+import cn.hippo4j.config.service.biz.OperationLogService;
import cn.hippo4j.config.service.biz.ThreadPoolService;
import cn.hippo4j.config.toolkit.BeanUtil;
-import cn.hippo4j.tools.logrecord.annotation.LogRecord;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
@@ -35,13 +38,12 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
+import java.util.Date;
import java.util.List;
+import java.util.Optional;
/**
* Thread pool service impl.
- *
- * @author chen.ma
- * @date 2021/6/30 21:26
*/
@Service
@AllArgsConstructor
@@ -51,6 +53,8 @@ public class ThreadPoolServiceImpl implements ThreadPoolService {
private final ConfigInfoMapper configInfoMapper;
+ private final OperationLogService operationLogService;
+
@Override
public IPage queryThreadPoolPage(ThreadPoolQueryReqDTO reqDTO) {
LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(ConfigAllInfo.class)
@@ -59,7 +63,6 @@ public class ThreadPoolServiceImpl implements ThreadPoolService {
.eq(!StringUtils.isBlank(reqDTO.getTpId()), ConfigAllInfo::getTpId, reqDTO.getTpId())
.eq(ConfigAllInfo::getDelFlag, DelEnum.NORMAL)
.orderByDesc(ConfigAllInfo::getGmtCreate);
-
return configInfoMapper.selectPage(reqDTO, wrapper).convert(each -> BeanUtil.convert(each, ThreadPoolRespDTO.class));
}
@@ -73,7 +76,6 @@ public class ThreadPoolServiceImpl implements ThreadPoolService {
public List getThreadPoolByItemId(String itemId) {
LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery(ConfigAllInfo.class)
.eq(ConfigAllInfo::getItemId, itemId);
-
List selectList = configInfoMapper.selectList(queryWrapper);
return BeanUtil.convert(selectList, ThreadPoolRespDTO.class);
}
@@ -83,14 +85,27 @@ public class ThreadPoolServiceImpl implements ThreadPoolService {
configService.insertOrUpdate(identify, false, BeanUtil.convert(reqDTO, ConfigAllInfo.class));
}
- @LogRecord(bizNo = "{{#reqDTO.itemId}}_{{#reqDTO.tpId}}", category = "THREAD_POOL_DELETE", success = "删除线程池: {{#reqDTO.tpId}}", detail = "{{#reqDTO.toString()}}")
@Override
- public void deletePool(ThreadPoolDelReqDTO reqDTO) {
+ public void deletePool(ThreadPoolDelReqDTO requestParam) {
configInfoMapper.delete(
Wrappers.lambdaUpdate(ConfigAllInfo.class)
- .eq(ConfigAllInfo::getTenantId, reqDTO.getTenantId())
- .eq(ConfigAllInfo::getItemId, reqDTO.getItemId())
- .eq(ConfigAllInfo::getTpId, reqDTO.getTpId()));
+ .eq(ConfigAllInfo::getTenantId, requestParam.getTenantId())
+ .eq(ConfigAllInfo::getItemId, requestParam.getItemId())
+ .eq(ConfigAllInfo::getTpId, requestParam.getTpId()));
+ recordOperationLog(requestParam);
+ }
+
+ private void recordOperationLog(ThreadPoolDelReqDTO requestParam) {
+ LogRecordInfo logRecordInfo = LogRecordInfo.builder()
+ .bizKey(requestParam.getItemId() + "_" + requestParam.getTpId())
+ .bizNo(requestParam.getItemId() + "_" + requestParam.getTpId())
+ .operator(Optional.ofNullable(UserContext.getUserName()).orElse("-"))
+ .action("删除线程池: " + requestParam.getTpId())
+ .category("THREAD_POOL_DELETE")
+ .detail(JSONUtil.toJSONString(requestParam))
+ .createTime(new Date())
+ .build();
+ operationLogService.record(logRecordInfo);
}
@Override
diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/handler/CustomOperatorGetServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/handler/CustomOperatorGetServiceImpl.java
deleted file mode 100644
index 86cb7835..00000000
--- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/handler/CustomOperatorGetServiceImpl.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package cn.hippo4j.config.service.handler;
-
-import cn.hippo4j.common.toolkit.StringUtil;
-import cn.hippo4j.common.toolkit.UserContext;
-import cn.hippo4j.tools.logrecord.model.Operator;
-import cn.hippo4j.tools.logrecord.service.OperatorGetService;
-import org.springframework.stereotype.Component;
-
-/**
- * Custom operator get service.
- *
- * @author chen.ma
- * @date 2021/11/28 17:57
- */
-@Component
-public class CustomOperatorGetServiceImpl implements OperatorGetService {
-
- @Override
- public Operator getUser() {
- String userName = UserContext.getUserName();
- userName = StringUtil.isEmpty(userName) ? "-" : userName;
- return new Operator(userName);
- }
-
-}
diff --git a/hippo4j-config/src/main/java/cn/hippo4j/config/service/handler/TenantIdFunctionServiceImpl.java b/hippo4j-config/src/main/java/cn/hippo4j/config/service/handler/TenantIdFunctionServiceImpl.java
deleted file mode 100644
index e9073dfe..00000000
--- a/hippo4j-config/src/main/java/cn/hippo4j/config/service/handler/TenantIdFunctionServiceImpl.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package cn.hippo4j.config.service.handler;
-
-import cn.hippo4j.config.model.biz.tenant.TenantRespDTO;
-import cn.hippo4j.config.service.biz.TenantService;
-import cn.hippo4j.tools.logrecord.service.ParseFunction;
-import lombok.AllArgsConstructor;
-import org.springframework.stereotype.Component;
-
-import java.util.Optional;
-
-/**
- * 查找原租户名称.
- *
- * @author chen.ma
- * @date 2021/10/24 22:07
- */
-@Component
-@AllArgsConstructor
-public class TenantIdFunctionServiceImpl implements ParseFunction {
-
- private final TenantService tenantService;
-
- @Override
- public boolean executeBefore() {
- return true;
- }
-
- @Override
- public String functionName() {
- return "TENANT";
- }
-
- @Override
- public String apply(String tenantId) {
- TenantRespDTO tenant = tenantService.getTenantById(tenantId);
- return Optional.ofNullable(tenant).map(TenantRespDTO::getTenantName).orElse("");
- }
-
-}
diff --git a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/LogRecordController.java b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/LogRecordController.java
index 52dffbc7..de972232 100644
--- a/hippo4j-console/src/main/java/cn/hippo4j/console/controller/LogRecordController.java
+++ b/hippo4j-console/src/main/java/cn/hippo4j/console/controller/LogRecordController.java
@@ -22,7 +22,7 @@ import cn.hippo4j.common.web.base.Result;
import cn.hippo4j.common.web.base.Results;
import cn.hippo4j.config.model.biz.log.LogRecordQueryReqDTO;
import cn.hippo4j.config.model.biz.log.LogRecordRespDTO;
-import cn.hippo4j.config.service.biz.LogRecordBizService;
+import cn.hippo4j.config.service.biz.OperationLogService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
@@ -38,10 +38,10 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping(Constants.BASE_PATH + "/log")
public class LogRecordController {
- private final LogRecordBizService logRecordBizService;
+ private final OperationLogService operationLogService;
@PostMapping("/query/page")
public Result> queryPage(@RequestBody LogRecordQueryReqDTO queryReqDTO) {
- return Results.success(logRecordBizService.queryPage(queryReqDTO));
+ return Results.success(operationLogService.queryPage(queryReqDTO));
}
}
diff --git a/hippo4j-server/src/main/java/cn/hippo4j/server/ServerApplication.java b/hippo4j-server/src/main/java/cn/hippo4j/server/ServerApplication.java
index 9871d0d6..239a632f 100644
--- a/hippo4j-server/src/main/java/cn/hippo4j/server/ServerApplication.java
+++ b/hippo4j-server/src/main/java/cn/hippo4j/server/ServerApplication.java
@@ -22,12 +22,6 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
-/**
- * Example application.
- *
- * @author chen.ma
- * @date 2022/01/23 21:06
- */
@EnableTransactionManagement
@SpringBootApplication(scanBasePackages = "cn.hippo4j")
@MapperScan(basePackages = {"cn.hippo4j.config.mapper", "cn.hippo4j.auth.mapper"})
diff --git a/hippo4j-tool/log-record-tool/pom.xml b/hippo4j-tool/log-record-tool/pom.xml
deleted file mode 100644
index 4dbf4844..00000000
--- a/hippo4j-tool/log-record-tool/pom.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
- 4.0.0
-
- cn.hippo4j
- hippo4j-tool
- ${revision}
-
- log-record-tool
- jar
- log-record-tool
-
-
- true
-
-
-
-
- org.springframework.boot
- spring-boot-starter
-
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
-
- org.aspectj
- aspectjweaver
-
-
-
- org.projectlombok
- lombok
-
-
-
- com.alibaba
- transmittable-thread-local
-
-
-
- com.google.guava
- guava
-
-
-
- org.hibernate.validator
- hibernate-validator
-
-
-
diff --git a/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/annotation/LogField.java b/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/annotation/LogField.java
deleted file mode 100644
index 48bf9ee7..00000000
--- a/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/annotation/LogField.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package cn.hippo4j.tools.logrecord.annotation;
-
-/**
- * Log field, used to mark entity properties that need to be compared.
- *
- * @author chen.ma
- * @date 2021/10/23 21:29
- */
-public @interface LogField {
-
- String name();
-}
diff --git a/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/annotation/LogRecord.java b/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/annotation/LogRecord.java
deleted file mode 100644
index 7a30ee1f..00000000
--- a/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/annotation/LogRecord.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package cn.hippo4j.tools.logrecord.annotation;
-
-import cn.hippo4j.tools.logrecord.enums.LogRecordTypeEnum;
-
-import java.lang.annotation.*;
-
-/**
- * 日志记录注解.
- *
- * @author chen.ma
- * @date 2021/10/23 21:29
- */
-@Documented
-@Target({ElementType.METHOD})
-@Retention(RetentionPolicy.RUNTIME)
-public @interface LogRecord {
-
- /**
- * 业务前缀
- *
- * @return
- */
- String prefix() default "";
-
- /**
- * 操作日志文本模版
- *
- * @return
- */
- String success();
-
- /**
- * 操作日志失败的文本
- *
- * @return
- */
- String fail() default "";
-
- /**
- * 操作人
- *
- * @return
- */
- String operator() default "";
-
- /**
- * 业务码
- *
- * @return
- */
- String bizNo();
-
- /**
- * 日志详情
- *
- * @return
- */
- String detail() default "";
-
- /**
- * 日志种类
- *
- * @return
- */
- String category();
-
- /**
- * 记录类型
- *
- * @return
- */
- LogRecordTypeEnum recordType() default LogRecordTypeEnum.COMPLETE;
-
- /**
- * 记录日志条件
- *
- * @return
- */
- String condition() default "";
-
-}
diff --git a/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/aop/LogRecordAspect.java b/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/aop/LogRecordAspect.java
deleted file mode 100644
index 510dfad2..00000000
--- a/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/aop/LogRecordAspect.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package cn.hippo4j.tools.logrecord.aop;
-
-import cn.hippo4j.tools.logrecord.annotation.LogRecord;
-import cn.hippo4j.tools.logrecord.context.LogRecordContext;
-import cn.hippo4j.tools.logrecord.model.LogRecordInfo;
-import cn.hippo4j.tools.logrecord.model.LogRecordOps;
-import cn.hippo4j.tools.logrecord.model.MethodExecuteResult;
-import cn.hippo4j.tools.logrecord.parse.LogRecordOperationSource;
-import cn.hippo4j.tools.logrecord.parse.LogRecordValueParser;
-import cn.hippo4j.tools.logrecord.service.LogRecordService;
-import cn.hippo4j.tools.logrecord.service.OperatorGetService;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import lombok.AllArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.aspectj.lang.ProceedingJoinPoint;
-import org.aspectj.lang.annotation.Around;
-import org.aspectj.lang.annotation.Aspect;
-import org.aspectj.lang.reflect.MethodSignature;
-import org.springframework.aop.framework.AopProxyUtils;
-import org.springframework.core.env.ConfigurableEnvironment;
-import org.springframework.stereotype.Component;
-import org.springframework.util.CollectionUtils;
-import org.springframework.util.StringUtils;
-
-import java.lang.reflect.Method;
-import java.util.*;
-
-/**
- * 日志记录切面.
- *
- * @author chen.ma
- * @date 2021/10/23 22:00
- */
-@Slf4j
-@Aspect
-@Component
-@AllArgsConstructor
-public class LogRecordAspect {
-
- private final LogRecordService bizLogService;
-
- private final LogRecordValueParser logRecordValueParser;
-
- private final OperatorGetService operatorGetService;
-
- private final LogRecordOperationSource logRecordOperationSource;
-
- private final ConfigurableEnvironment environment;
-
- @Around("@annotation(logRecord)")
- public Object logRecord(ProceedingJoinPoint joinPoint, LogRecord logRecord) throws Throwable {
- MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
- Method method = methodSignature.getMethod();
- Object target = joinPoint.getTarget();
- Class> targetClass = AopProxyUtils.ultimateTargetClass(target);
- Object[] args = joinPoint.getArgs();
-
- LogRecordContext.putEmptySpan();
-
- Object result = null;
- Collection operations = Lists.newArrayList();
- Map functionNameAndReturnMap = Maps.newHashMap();
- MethodExecuteResult methodExecuteResult = new MethodExecuteResult(true);
-
- try {
- operations = logRecordOperationSource.computeLogRecordOperations(method, targetClass);
- List spElTemplates = getBeforeExecuteFunctionTemplate(operations);
- functionNameAndReturnMap = logRecordValueParser.processBeforeExecuteFunctionTemplate(spElTemplates, targetClass, method, args);
-
- } catch (Exception ex) {
- log.error("Log record parse before function exception.", ex);
- }
-
- try {
- result = joinPoint.proceed();
- } catch (Exception ex) {
- methodExecuteResult = new MethodExecuteResult(false, ex, ex.getMessage());
- }
-
- try {
- if (!CollectionUtils.isEmpty(operations)) {
- recordExecute(result, method, args, operations, targetClass,
- methodExecuteResult.isSuccess(), methodExecuteResult.getErrorMsg(), functionNameAndReturnMap);
- }
- } catch (Exception ex) {
- log.error("Log record parse exception.", ex);
- } finally {
- LogRecordContext.clear();
- }
-
- if (methodExecuteResult.getThrowable() != null) {
- throw methodExecuteResult.getThrowable();
- }
-
- return result;
-
- }
-
- private List getBeforeExecuteFunctionTemplate(Collection operations) {
- List spElTemplates = new ArrayList();
- for (LogRecordOps operation : operations) {
- // 执行之前的函数
- List templates = getSpElTemplates(operation, operation.getSuccessLogTemplate());
- if (!CollectionUtils.isEmpty(templates)) {
- spElTemplates.addAll(templates);
- }
- }
-
- return spElTemplates;
- }
-
- private List getSpElTemplates(LogRecordOps operation, String action) {
- List spElTemplates = Lists.newArrayList(operation.getBizKey(), operation.getBizNo(), action, operation.getDetail());
-
- if (!StringUtils.isEmpty(operation.getCondition())) {
- spElTemplates.add(operation.getCondition());
- }
-
- return spElTemplates;
- }
-
- /**
- * 记录日志.
- *
- * @param ret
- * @param method
- * @param args
- * @param operations
- * @param targetClass
- * @param success
- * @param errorMsg
- * @param functionNameAndReturnMap
- */
- private void recordExecute(Object ret, Method method, Object[] args, Collection operations,
- Class> targetClass, boolean success, String errorMsg, Map functionNameAndReturnMap) {
- for (LogRecordOps operation : operations) {
- try {
- String action = getActionContent(success, operation);
- if (StringUtils.isEmpty(action)) {
- // 没有日志内容则忽略
- continue;
- }
- // 获取需要解析的表达式
- List spElTemplates = getSpElTemplates(operation, action);
- String operatorIdFromService = getOperatorIdFromServiceAndPutTemplate(operation, spElTemplates);
-
- Map expressionValues = logRecordValueParser.processTemplate(spElTemplates, ret, targetClass, method, args, errorMsg, functionNameAndReturnMap);
- if (logConditionPassed(operation.getCondition(), expressionValues)) {
- String tenant = environment.getProperty("tenant");
- LogRecordInfo logRecordInfo = LogRecordInfo.builder()
- .tenant(StringUtils.isEmpty(tenant) ? "hippo4j" : tenant)
- .bizKey(expressionValues.get(operation.getBizKey()))
- .bizNo(expressionValues.get(operation.getBizNo()))
- .operator(getRealOperatorId(operation, operatorIdFromService, expressionValues))
- .category(operation.getCategory())
- .detail(expressionValues.get(operation.getDetail()))
- .action(expressionValues.get(action))
- .createTime(new Date())
- .build();
-
- // 如果 action 为空, 不记录日志
- if (StringUtils.isEmpty(logRecordInfo.getAction())) {
- continue;
- }
- // save log 需要新开事务, 失败日志不能因为事务回滚而丢失
- Preconditions.checkNotNull(bizLogService, "bizLogService not init");
- bizLogService.record(logRecordInfo);
- }
- } catch (Exception t) {
- log.error("log record execute exception", t);
- }
- }
- }
-
- private String getActionContent(boolean success, LogRecordOps operation) {
- if (success) {
- return operation.getSuccessLogTemplate();
- }
-
- return operation.getFailLogTemplate();
- }
-
- private String getOperatorIdFromServiceAndPutTemplate(LogRecordOps operation, List spElTemplates) {
- String realOperatorId = "";
- if (StringUtils.isEmpty(operation.getOperatorId())) {
- realOperatorId = operatorGetService.getUser().getOperatorId();
- if (StringUtils.isEmpty(realOperatorId)) {
- throw new IllegalArgumentException("LogRecord operator is null");
- }
- } else {
- spElTemplates.add(operation.getOperatorId());
- }
-
- return realOperatorId;
- }
-
- private boolean logConditionPassed(String condition, Map expressionValues) {
- return StringUtils.isEmpty(condition) || StringUtils.endsWithIgnoreCase(expressionValues.get(condition), "true");
- }
-
- private String getRealOperatorId(LogRecordOps operation, String operatorIdFromService, Map expressionValues) {
- return !StringUtils.isEmpty(operatorIdFromService) ? operatorIdFromService : expressionValues.get(operation.getOperatorId());
- }
-
-}
diff --git a/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/config/LogRecordConfig.java b/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/config/LogRecordConfig.java
deleted file mode 100644
index ff09136c..00000000
--- a/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/config/LogRecordConfig.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package cn.hippo4j.tools.logrecord.config;
-
-import cn.hippo4j.tools.logrecord.parse.LogRecordOperationSource;
-import cn.hippo4j.tools.logrecord.parse.LogRecordValueParser;
-import cn.hippo4j.tools.logrecord.service.FunctionService;
-import cn.hippo4j.tools.logrecord.service.LogRecordService;
-import cn.hippo4j.tools.logrecord.service.OperatorGetService;
-import cn.hippo4j.tools.logrecord.service.ParseFunction;
-import cn.hippo4j.tools.logrecord.service.impl.*;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.config.BeanDefinition;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Role;
-
-import java.util.List;
-
-/**
- * 日志记录配置.
- *
- * @author chen.ma
- * @date 2021/10/23 22:49
- */
-@Configuration
-public class LogRecordConfig {
-
- @Bean
- @ConditionalOnMissingBean(ParseFunction.class)
- public DefaultParseFunction parseFunction() {
- return new DefaultParseFunction();
- }
-
- @Bean
- public ParseFunctionFactory parseFunctionFactory(@Autowired List parseFunctions) {
- return new ParseFunctionFactory(parseFunctions);
- }
-
- @Bean
- @ConditionalOnMissingBean(FunctionService.class)
- public FunctionService functionService(ParseFunctionFactory parseFunctionFactory) {
- return new DefaultFunctionServiceImpl(parseFunctionFactory);
- }
-
- @Bean
- @Role(BeanDefinition.ROLE_APPLICATION)
- @ConditionalOnMissingBean(OperatorGetService.class)
- public OperatorGetService operatorGetService() {
- return new DefaultOperatorGetServiceImpl();
- }
-
- @Bean
- @ConditionalOnMissingBean(LogRecordService.class)
- @Role(BeanDefinition.ROLE_APPLICATION)
- public LogRecordService recordService() {
- return new DefaultLogRecordServiceImpl();
- }
-
- @Bean
- public LogRecordValueParser logRecordValueParser() {
- return new LogRecordValueParser();
- }
-
- @Bean
- public LogRecordOperationSource logRecordOperationSource() {
- return new LogRecordOperationSource();
- }
-
-}
diff --git a/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/context/LogRecordContext.java b/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/context/LogRecordContext.java
deleted file mode 100644
index 07b819d5..00000000
--- a/hippo4j-tool/log-record-tool/src/main/java/cn/hippo4j/tools/logrecord/context/LogRecordContext.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package cn.hippo4j.tools.logrecord.context;
-
-import com.alibaba.ttl.TransmittableThreadLocal;
-import com.google.common.collect.Maps;
-
-import java.util.Map;
-import java.util.Stack;
-
-/**
- * 日志记录上下文.
- *
- * @author chen.ma
- * @date 2021/10/23 21:47
- */
-public class LogRecordContext {
-
- private static final ThreadLocal>> VARIABLE_MAP_STACK = new TransmittableThreadLocal();
-
- /**
- * 出栈.
- */
- public static void clear() {
- if (VARIABLE_MAP_STACK.get() != null) {
- VARIABLE_MAP_STACK.get().pop();
- }
- }
-
- /**
- * 初始化.
- */
- public static void putEmptySpan() {
- Stack