diff --git a/README.md b/README.md index ad87377..9020ce0 100644 --- a/README.md +++ b/README.md @@ -152,7 +152,9 @@ public class LoggerEventListener { - success: 业务方法是否执行成功。 - errors: 业务方法执行期间发生的异常。 -#### 2.4 关于`@Logger`注解在IDEA设置SpringEL的提示 +#### 2.4 异步监听日志事件 + +#### 2.5 关于`@Logger`注解在IDEA设置SpringEL的提示 `@Logger` 注解中的属性已经支持在 IDEA 中自动有 SpringEL 的提示,无需手动设置。 diff --git a/src/main/java/com/lzhpo/logger/LoggerAspect.java b/src/main/java/com/lzhpo/logger/LoggerAspect.java index dce2eeb..1f1a558 100644 --- a/src/main/java/com/lzhpo/logger/LoggerAspect.java +++ b/src/main/java/com/lzhpo/logger/LoggerAspect.java @@ -102,7 +102,9 @@ private void resolveLogger(ProceedingJoinPoint joinPoint, Logger logger, LoggerE LoggerExpressionEvaluator evaluator = new LoggerExpressionEvaluator(); ParameterNameDiscoverer discoverer = evaluator.getParameterNameDiscoverer(); - LoggerEvaluationContext context = LoggerContextHolder.getContext(object, method, event.getResult(), args, discoverer); + LoggerElementKey elementKey = new LoggerElementKey(object, method, event.getResult(), args, discoverer); + + LoggerEvaluationContext context = LoggerContextHolder.getContext(elementKey); if (!Boolean.parseBoolean(evalExpression(logger.condition(), event, context, evaluator))) { log.debug("The resolved condition is false in @Logger."); return; diff --git a/src/main/java/com/lzhpo/logger/LoggerContextHolder.java b/src/main/java/com/lzhpo/logger/LoggerContextHolder.java index fdc2a9c..1d2fb0e 100644 --- a/src/main/java/com/lzhpo/logger/LoggerContextHolder.java +++ b/src/main/java/com/lzhpo/logger/LoggerContextHolder.java @@ -15,44 +15,51 @@ */ package com.lzhpo.logger; +import cn.hutool.core.util.ObjectUtil; import com.alibaba.ttl.TransmittableThreadLocal; -import java.lang.reflect.Method; import java.util.Optional; import lombok.experimental.UtilityClass; import lombok.extern.slf4j.Slf4j; -import org.springframework.core.ParameterNameDiscoverer; -import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.util.Assert; /** * @author lzhpo */ -// spotless:off @Slf4j @UtilityClass public class LoggerContextHolder { - private static final TransmittableThreadLocal EVALUATION_CONTEXT = new TransmittableThreadLocal<>(); + private static final TransmittableThreadLocal EVALUATION_CONTEXT = + new TransmittableThreadLocal<>(); /** * Get {@link #EVALUATION_CONTEXT}. * - * @param rootObject the root object - * @param method the method - * @param result the result - * @param args the arguments - * @param discoverer the parameter name discoverer + * @param elementKey the logger element key * @return {@link LoggerEvaluationContext} */ - public static LoggerEvaluationContext getContext(Object rootObject, Method method, Object result, Object[] args, ParameterNameDiscoverer discoverer) { - return Optional.ofNullable(EVALUATION_CONTEXT.get()).orElseGet(() -> { - LoggerEvaluationContext context = new LoggerEvaluationContext(rootObject, method, args, discoverer); - context.setVariable(LoggerConstant.VARIABLE_RESULT, result); - LoggerFunctionRegistrar.registerFunction(context); - EVALUATION_CONTEXT.set(context); - log.debug("The evaluation context is null, created new context, current thread name: {}", Thread.currentThread().getName()); - return context; - }); + public static LoggerEvaluationContext getContext(LoggerElementKey elementKey) { + return Optional.ofNullable(EVALUATION_CONTEXT.get()) + .map(context -> { + initializeIfNecessary(elementKey, context); + return context; + }) + .orElseGet(() -> { + LoggerEvaluationContext context = new LoggerEvaluationContext(); + initializeIfNecessary(elementKey, context); + EVALUATION_CONTEXT.set(context); + log.debug( + "[{}] Created new context.", Thread.currentThread().getName()); + return context; + }); + } + + /** + * Get {@link #EVALUATION_CONTEXT}. + * + * @return {@link LoggerEvaluationContext} + */ + public static LoggerEvaluationContext getContext() { + return Optional.ofNullable(EVALUATION_CONTEXT.get()).orElseGet(LoggerEvaluationContext::new); } /** @@ -62,9 +69,9 @@ public static LoggerEvaluationContext getContext(Object rootObject, Method metho * @param value the variable value */ public static void putVariable(String name, Object value) { - StandardEvaluationContext context = EVALUATION_CONTEXT.get(); - Assert.notNull(context, "The evaluation context is null"); + LoggerEvaluationContext context = getContext(); context.setVariable(name, value); + EVALUATION_CONTEXT.set(context); } /** @@ -74,9 +81,7 @@ public static void putVariable(String name, Object value) { * @return the variable value */ public static Object lookupVariable(String name) { - StandardEvaluationContext context = EVALUATION_CONTEXT.get(); - Assert.notNull(context, "The evaluation context is null"); - return context.lookupVariable(name); + return getContext().lookupVariable(name); } /** @@ -84,7 +89,24 @@ public static Object lookupVariable(String name) { */ public static void clearContext() { EVALUATION_CONTEXT.remove(); - log.debug("Cleared evaluation context, current thread name: {}", Thread.currentThread().getName()); + log.debug("[{}] Cleared evaluation context.", Thread.currentThread().getName()); + } + + /** + * Initialize context's fields if it has empty. + * + * @param elementKey {@link LoggerElementKey} + * @param context {@link LoggerEvaluationContext} + */ + private static void initializeIfNecessary(LoggerElementKey elementKey, LoggerEvaluationContext context) { + if (ObjectUtil.hasEmpty(context.getMethod(), context.getMethod(), context.getDiscoverer())) { + context.setRootObject(elementKey.getRootObject()); + context.setMethod(elementKey.getMethod()); + context.setArguments(elementKey.getArguments()); + context.setDiscoverer(elementKey.getDiscoverer()); + context.setVariable(LoggerConstant.VARIABLE_RESULT, elementKey.getResult()); + LoggerFunctionRegistrar.registerFunction(context); + log.debug("The context has null fields, already initialized."); + } } } -// spotless:on diff --git a/src/main/java/com/lzhpo/logger/LoggerElementKey.java b/src/main/java/com/lzhpo/logger/LoggerElementKey.java new file mode 100644 index 0000000..57211d9 --- /dev/null +++ b/src/main/java/com/lzhpo/logger/LoggerElementKey.java @@ -0,0 +1,45 @@ +/* + * Copyright lzhpo + * + * Licensed 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 com.lzhpo.logger; + +import java.lang.reflect.Method; +import java.util.Optional; +import lombok.Getter; +import org.springframework.core.ParameterNameDiscoverer; + +/** + * @author lzhpo + */ +@Getter +public class LoggerElementKey { + + private final Object rootObject; + private final Method method; + private final Object result; + private final Object[] arguments; + private final ParameterNameDiscoverer discoverer; + + public LoggerElementKey( + Object rootObject, Method method, Object result, Object[] arguments, ParameterNameDiscoverer discoverer) { + this.arguments = arguments; + this.result = result; + this.rootObject = + Optional.ofNullable(rootObject).orElseThrow(() -> new IllegalArgumentException("rootObject is null")); + this.method = Optional.ofNullable(method).orElseThrow(() -> new IllegalArgumentException("method is null")); + this.discoverer = + Optional.ofNullable(discoverer).orElseThrow(() -> new IllegalArgumentException("discoverer is null")); + } +} diff --git a/src/main/java/com/lzhpo/logger/LoggerEvaluationContext.java b/src/main/java/com/lzhpo/logger/LoggerEvaluationContext.java index 3c81a86..b8049a2 100644 --- a/src/main/java/com/lzhpo/logger/LoggerEvaluationContext.java +++ b/src/main/java/com/lzhpo/logger/LoggerEvaluationContext.java @@ -18,6 +18,7 @@ import java.lang.reflect.Method; import java.util.Arrays; import lombok.Getter; +import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.expression.spel.support.StandardEvaluationContext; @@ -41,17 +42,26 @@ @Getter public class LoggerEvaluationContext extends StandardEvaluationContext { - private final Method method; - private final Object[] arguments; - private final ParameterNameDiscoverer discoverer; + @Setter + private Method method; + + @Setter + private Object[] arguments; + + @Setter + private ParameterNameDiscoverer discoverer; + private boolean argumentsLoaded = false; - public LoggerEvaluationContext( - Object rootObject, Method method, Object[] arguments, ParameterNameDiscoverer discoverer) { - super(rootObject); - this.method = method; - this.arguments = arguments; - this.discoverer = discoverer; + public LoggerEvaluationContext() { + // NOP + } + + public LoggerEvaluationContext(LoggerElementKey loggerElementKey) { + super(loggerElementKey.getRootObject()); + this.method = loggerElementKey.getMethod(); + this.arguments = loggerElementKey.getArguments(); + this.discoverer = loggerElementKey.getDiscoverer(); } @Override diff --git a/src/test/java/com/lzhpo/logger/service/OrderService.java b/src/test/java/com/lzhpo/logger/LoggerAction.java similarity index 50% rename from src/test/java/com/lzhpo/logger/service/OrderService.java rename to src/test/java/com/lzhpo/logger/LoggerAction.java index 0828fcf..28423b1 100644 --- a/src/test/java/com/lzhpo/logger/service/OrderService.java +++ b/src/test/java/com/lzhpo/logger/LoggerAction.java @@ -13,19 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.lzhpo.logger.service; +package com.lzhpo.logger; -import com.lzhpo.logger.domain.CreateOrderRequest; -import com.lzhpo.logger.domain.CreateOrderResponse; -import com.lzhpo.logger.domain.ModifyOrderRequest; -import com.lzhpo.logger.domain.ModifyOrderResponse; +import org.springframework.boot.test.context.TestComponent; +import org.springframework.web.bind.annotation.RequestParam; /** * @author lzhpo */ -public interface OrderService { +@TestComponent +public class LoggerAction { - CreateOrderResponse createOrder(CreateOrderRequest request); + @Logger(message = "'将地址从' + #oldAddress + '修改为' + #newAddress") + public void updateAddress(@RequestParam String oldAddress, @RequestParam String newAddress) {} - ModifyOrderResponse modifyOrder(ModifyOrderRequest request); + @Logger(message = "'将地址从' + #oldAddress + '修改为' + #newAddress") + public void updateNewAddress(@RequestParam String newAddress) { + LoggerContextHolder.putVariable("oldAddress", "光明小区1号"); + } } diff --git a/src/test/java/com/lzhpo/logger/LoggerActionTest.java b/src/test/java/com/lzhpo/logger/LoggerActionTest.java new file mode 100644 index 0000000..7eaaa50 --- /dev/null +++ b/src/test/java/com/lzhpo/logger/LoggerActionTest.java @@ -0,0 +1,46 @@ +/* + * Copyright lzhpo + * + * Licensed 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 com.lzhpo.logger; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.EnableAspectJAutoProxy; +import org.springframework.context.annotation.Import; + +/** + * @author lzhpo + */ +@Slf4j +@EnableAspectJAutoProxy(proxyTargetClass = true) +@SpringBootTest(classes = LoggerTestApplication.class) +@Import({LoggerAutoConfiguration.class, LoggerAction.class, LoggerListenerTest.class}) +class LoggerActionTest { + + @Autowired + private LoggerAction loggerAction; + + @Test + void updateAddress() { + loggerAction.updateAddress("朝阳小区1号", "光明小区1号"); + } + + @Test + void updateNewAddress() { + loggerAction.updateNewAddress("幸福小区1号"); + } +} diff --git a/src/test/java/com/lzhpo/logger/listener/LoggerEventListener.java b/src/test/java/com/lzhpo/logger/LoggerListenerTest.java similarity index 61% rename from src/test/java/com/lzhpo/logger/listener/LoggerEventListener.java rename to src/test/java/com/lzhpo/logger/LoggerListenerTest.java index 4bd4a7b..a88ad7a 100644 --- a/src/test/java/com/lzhpo/logger/listener/LoggerEventListener.java +++ b/src/test/java/com/lzhpo/logger/LoggerListenerTest.java @@ -13,22 +13,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.lzhpo.logger.listener; +package com.lzhpo.logger; -import com.lzhpo.logger.LoggerEvent; import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.event.EventListener; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; /** + *
+ * {@code
+ *     @Component
+ *     public class LoggerListener implements ApplicationListener {
+ *
+ *         @Override
+ *         public void onApplicationEvent(LoggerEvent event) {
+ *             log.info("Received LoggerEvent: {}", event);
+ *             log.info(event.getMessage());
+ *         }
+ *     }
+ * }
+ * 
+ * * @author lzhpo + * @see org.springframework.context.ApplicationListener */ @Slf4j -@Component -public class LoggerEventListener { +@TestConfiguration +public class LoggerListenerTest { - @Async @EventListener public void process(LoggerEvent event) { log.info("Received LoggerEvent: {}", event); diff --git a/src/test/java/com/lzhpo/logger/context/StandardEvaluationContextTest.java b/src/test/java/com/lzhpo/logger/context/StandardEvaluationContextTest.java deleted file mode 100644 index 1927213..0000000 --- a/src/test/java/com/lzhpo/logger/context/StandardEvaluationContextTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright lzhpo - * - * Licensed 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 com.lzhpo.logger.context; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import cn.hutool.core.util.ReflectUtil; -import java.lang.reflect.Method; -import lombok.extern.slf4j.Slf4j; -import org.junit.jupiter.api.Test; -import org.springframework.expression.ExpressionParser; -import org.springframework.expression.spel.standard.SpelExpressionParser; -import org.springframework.expression.spel.support.StandardEvaluationContext; - -@Slf4j -public class StandardEvaluationContextTest { - - @Test - public void test() { - final ExpressionParser expressionParser = new SpelExpressionParser(); - final StandardEvaluationContext evaluationContext = new StandardEvaluationContext(); - - final String functionNamePrint = "print"; - Method printMethod = ReflectUtil.getMethodByName(StandardEvaluationContextTest.class, functionNamePrint); - evaluationContext.registerFunction(functionNamePrint, printMethod); - - final String expression = "#print('Hello World')"; - String result = expressionParser.parseExpression(expression).getValue(evaluationContext, String.class); - log.info(result); - assertNotNull(result); - } - - public static String print(String content) { - log.info("I'm print, content: {}", content); - return content; - } -} diff --git a/src/test/java/com/lzhpo/logger/controller/OrderController.java b/src/test/java/com/lzhpo/logger/controller/OrderController.java deleted file mode 100644 index 256304d..0000000 --- a/src/test/java/com/lzhpo/logger/controller/OrderController.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright lzhpo - * - * Licensed 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 com.lzhpo.logger.controller; - -import com.lzhpo.logger.Logger; -import com.lzhpo.logger.domain.CreateOrderRequest; -import com.lzhpo.logger.domain.CreateOrderResponse; -import com.lzhpo.logger.domain.ModifyOrderRequest; -import com.lzhpo.logger.domain.ModifyOrderResponse; -import com.lzhpo.logger.service.OrderService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.*; - -/** - * @author lzhpo - */ -// spotless:off -@Slf4j -@RestController -@RequiredArgsConstructor -@RequestMapping("/order") -public class OrderController { - - private final OrderService orderService; - - // @el(request: com.lzhpo.logger.domain.CreateOrderRequest) - // @el(result: com.lzhpo.logger.domain.CreateOrderResponse) - @PostMapping - @Logger( - condition = "#result.getSuccess()", - category = "'Operation Log'", - tag = "'Create Order'", - businessId = "#getBusinessId(#result.getOrderId())", - operatorId = "#findUserName(#request.getUserId())", - message = "#findUserName(#request.getUserId()) + '使用' + #request.getPaymentType() + '下单了' + #findProductName(#request.getProductId()) + '产品'", - additional = "#findUserName(#request.getUserId()) + '等级是' + #findUserVip(#request.getUserId()) + ',请求日期' + T(java.time.LocalDateTime).now()" - ) - public CreateOrderResponse createOrder(@RequestBody CreateOrderRequest request) { - return orderService.createOrder(request); - } - - // @el(request: com.lzhpo.logger.domain.ModifyOrderRequest) - // @el(result: com.lzhpo.logger.domain.ModifyOrderResponse) - @PutMapping - @Logger( - category = "'Operation Log'", - tag = "'Modify Order'", - prelude = true, - returning = false, - businessId = "#request.getOrderId()", - operatorId = "#request.getUserId()", - message = "#findUserName(#request.getUserId()) + '将地址从' + #findOldAddress(#request.getOrderId()) + '修改为' + #findNewAddress(#request.getAddressId())", - additional = "#findUserName(#request.getUserId()) + '等级是' + #findUserVip(#request.getUserId()) + ',请求日期' + T(java.time.LocalDateTime).now()" - ) - public ModifyOrderResponse modifyOrder(@RequestBody ModifyOrderRequest request) { - ModifyOrderResponse response = orderService.modifyOrder(request); - request.setOrderId(""); - request.setUserId(""); - request.setAddressId(""); - return response; - } -} -// spotless:on diff --git a/src/test/java/com/lzhpo/logger/domain/CreateOrderRequest.java b/src/test/java/com/lzhpo/logger/domain/CreateOrderRequest.java deleted file mode 100644 index b105f98..0000000 --- a/src/test/java/com/lzhpo/logger/domain/CreateOrderRequest.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright lzhpo - * - * Licensed 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 com.lzhpo.logger.domain; - -import java.io.Serializable; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author lzhpo - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class CreateOrderRequest implements Serializable { - - private String userId; - private String productId; - private String address; - private String paymentType; -} diff --git a/src/test/java/com/lzhpo/logger/domain/CreateOrderResponse.java b/src/test/java/com/lzhpo/logger/domain/CreateOrderResponse.java deleted file mode 100644 index 21d67bc..0000000 --- a/src/test/java/com/lzhpo/logger/domain/CreateOrderResponse.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright lzhpo - * - * Licensed 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 com.lzhpo.logger.domain; - -import java.io.Serializable; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author lzhpo - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class CreateOrderResponse implements Serializable { - - private Boolean success; - private String orderId; - private String userId; - private String productId; - private String address; - private String paymentType; -} diff --git a/src/test/java/com/lzhpo/logger/domain/ModifyOrderRequest.java b/src/test/java/com/lzhpo/logger/domain/ModifyOrderRequest.java deleted file mode 100644 index bf98a67..0000000 --- a/src/test/java/com/lzhpo/logger/domain/ModifyOrderRequest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright lzhpo - * - * Licensed 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 com.lzhpo.logger.domain; - -import java.io.Serializable; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author lzhpo - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class ModifyOrderRequest implements Serializable { - - private String orderId; - private String userId; - private String addressId; -} diff --git a/src/test/java/com/lzhpo/logger/domain/ModifyOrderResponse.java b/src/test/java/com/lzhpo/logger/domain/ModifyOrderResponse.java deleted file mode 100644 index d616b9e..0000000 --- a/src/test/java/com/lzhpo/logger/domain/ModifyOrderResponse.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright lzhpo - * - * Licensed 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 com.lzhpo.logger.domain; - -import java.io.Serializable; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -/** - * @author lzhpo - */ -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class ModifyOrderResponse implements Serializable { - - private Boolean success; - private String orderId; - private String userId; - private String addressId; -} diff --git a/src/test/java/com/lzhpo/logger/functions/OrderRegisterFunction.java b/src/test/java/com/lzhpo/logger/functions/OrderRegisterFunction.java deleted file mode 100644 index b0d162c..0000000 --- a/src/test/java/com/lzhpo/logger/functions/OrderRegisterFunction.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright lzhpo - * - * Licensed 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 com.lzhpo.logger.functions; - -import com.lzhpo.logger.LoggerComponent; -import com.lzhpo.logger.LoggerFunction; - -/** - * @author lzhpo - */ -@LoggerComponent -public class OrderRegisterFunction { - - @LoggerFunction - public static String getBusinessId(String orderId) { - return "BusinessId_" + orderId; - } - - @LoggerFunction("findUserName") - public static String findUserName(String userId) { - return "UserName_" + userId; - } - - @LoggerFunction - public static String findUserVip(String userId) { - return "UserVip_" + userId.length(); - } - - @LoggerFunction - public static String findProductName(String productId) { - return "ProductName_" + productId; - } - - @LoggerFunction - public static String findOldAddress(String orderId) { - return "OldAddress_" + orderId; - } - - @LoggerFunction - public static String findNewAddress(String addressId) { - return "NewAddress_" + addressId; - } - - public static void test() { - System.out.println("Hello World!"); - } -} diff --git a/src/test/java/com/lzhpo/logger/service/impl/OrderServiceImpl.java b/src/test/java/com/lzhpo/logger/service/impl/OrderServiceImpl.java deleted file mode 100644 index 24c3982..0000000 --- a/src/test/java/com/lzhpo/logger/service/impl/OrderServiceImpl.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright lzhpo - * - * Licensed 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 com.lzhpo.logger.service.impl; - -import cn.hutool.core.util.IdUtil; -import com.lzhpo.logger.Logger; -import com.lzhpo.logger.domain.CreateOrderRequest; -import com.lzhpo.logger.domain.CreateOrderResponse; -import com.lzhpo.logger.domain.ModifyOrderRequest; -import com.lzhpo.logger.domain.ModifyOrderResponse; -import com.lzhpo.logger.service.OrderService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; - -/** - * @author lzhpo - */ -@Slf4j -@Service -public class OrderServiceImpl implements OrderService { - - @Override - @Logger(message = "'I am create order: ' + #findUserName(#request.getUserId()) ") - public CreateOrderResponse createOrder(CreateOrderRequest request) { - CreateOrderResponse response = new CreateOrderResponse(); - response.setSuccess(true); - response.setOrderId(IdUtil.fastSimpleUUID()); - response.setUserId(request.getUserId()); - response.setProductId(request.getProductId()); - response.setAddress(request.getAddress()); - response.setPaymentType(request.getPaymentType()); - return response; - } - - @Override - @Logger(returning = false, message = "'I am modify order: ' + #request.getUserId() ") - public ModifyOrderResponse modifyOrder(ModifyOrderRequest request) { - ModifyOrderResponse response = new ModifyOrderResponse(); - response.setSuccess(true); - response.setOrderId(request.getOrderId()); - response.setUserId(request.getUserId()); - response.setAddressId(request.getAddressId()); - return response; - } -}