|
@@ -0,0 +1,76 @@
|
|
|
+package org.springblade.common.aspect;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+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.springblade.core.launch.props.BladeProperties;
|
|
|
+import org.springblade.core.launch.server.ServerInfo;
|
|
|
+import org.springblade.core.log.model.LogApi;
|
|
|
+import org.springblade.core.log.utils.LogAbstractUtil;
|
|
|
+import org.springblade.core.tool.utils.WebUtil;
|
|
|
+import org.springblade.modules.business.entity.FacilityLog;
|
|
|
+import org.springblade.modules.business.service.IFacilityLogService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.lang.reflect.Method;
|
|
|
+
|
|
|
+@Aspect
|
|
|
+@Component
|
|
|
+public class VendingLogAspect {
|
|
|
+
|
|
|
+ @Value("${spring.profiles.active}")
|
|
|
+ private String active;
|
|
|
+ @Autowired
|
|
|
+ private ServerInfo serverInfo;
|
|
|
+ @Autowired
|
|
|
+ private BladeProperties bladeProperties;
|
|
|
+ @Autowired
|
|
|
+ private IFacilityLogService facilityLogService;
|
|
|
+
|
|
|
+ public VendingLogAspect() {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Around("@annotation(org.springblade.common.aspect.VendingLog)")
|
|
|
+ public Object doAround(ProceedingJoinPoint point) throws Throwable {
|
|
|
+ MethodSignature methodSignature = (MethodSignature) point.getSignature();
|
|
|
+ Method method = methodSignature.getMethod();
|
|
|
+ VendingLog vendingLog = method.getAnnotation(VendingLog.class);
|
|
|
+
|
|
|
+ String className = point.getTarget().getClass().getName();
|
|
|
+ String methodName = point.getSignature().getName();
|
|
|
+ long beginTime = System.currentTimeMillis();
|
|
|
+ Object result = point.proceed();
|
|
|
+ long time = System.currentTimeMillis() - beginTime;
|
|
|
+ publishEvent(methodName, className, vendingLog, time);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void publishEvent(String methodName, String methodClass, VendingLog vendingLog, long time) {
|
|
|
+ HttpServletRequest request = WebUtil.getRequest();
|
|
|
+ LogApi logApi = new LogApi();
|
|
|
+ logApi.setType(vendingLog.value().getType());
|
|
|
+ logApi.setTitle(vendingLog.value().getTitle());
|
|
|
+ logApi.setTime(String.valueOf(time));
|
|
|
+ logApi.setMethodClass(methodClass);
|
|
|
+ logApi.setMethodName(methodName);
|
|
|
+ LogAbstractUtil.addRequestInfoToLog(request, logApi);
|
|
|
+ LogAbstractUtil.addOtherInfoToLog(logApi, bladeProperties, serverInfo);
|
|
|
+ FacilityLog facilityLog = new FacilityLog();
|
|
|
+ BeanUtil.copyProperties(logApi, facilityLog);
|
|
|
+
|
|
|
+ facilityLog.setEnv(active);
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(facilityLog.getParams());
|
|
|
+ String machineId = jsonObject.get("machineId").toString();
|
|
|
+ facilityLog.setCreateBy(machineId);
|
|
|
+
|
|
|
+ facilityLogService.save(facilityLog);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|