3 Комити b0eea7a23b ... c1e0ba8805

Аутор SHA1 Порука Датум
  Twelve615 c1e0ba8805 :poop: 铲屎,铲除创建订单时重复判断后设置错误的企业id的逻辑 пре 1 година
  Twelve615 2612c11d87 :zap: 还原用户信息判断 пре 1 година
  Twelve615 f332d8b5b4 :sparkles: 添加切面日志 пре 1 година

+ 92 - 2
crmeb-admin/src/main/java/com/zbkj/admin/aspect/ControllerAspect.java

@@ -1,13 +1,33 @@
 package com.zbkj.admin.aspect;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Strings;
+import com.qcloud.cos.utils.Jackson;
+import com.zbkj.common.model.user.User;
+import com.zbkj.service.service.UserService;
+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.annotation.Pointcut;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.Aware;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.InputStreamSource;
 import org.springframework.stereotype.Component;
-
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.View;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
 import java.util.Arrays;
 
 
@@ -17,9 +37,13 @@ import java.util.Arrays;
  */
 @Aspect
 @Component
+@Slf4j
 public class ControllerAspect {
 
-    Logger logger = LoggerFactory.getLogger(ControllerAspect.class);
+    //Logger logger = LoggerFactory.getLogger(ControllerAspect.class);
+
+    @Autowired
+    private UserService userService;
 
     @Pointcut("execution(* com.zbkj.admin.controller.*.*(..))")
     private void pointCutMethodController() {
@@ -29,6 +53,71 @@ public class ControllerAspect {
     @Around("pointCutMethodController()")
     public Object doAroundService(ProceedingJoinPoint pjp) throws Throwable {
 
+        long startTime = System.currentTimeMillis();
+        try {
+            RequestAttributes ra = RequestContextHolder.getRequestAttributes();
+            ServletRequestAttributes sra = (ServletRequestAttributes) ra;
+            //防止不是http请求的方法,例如:scheduled
+            if (ra == null || sra == null) {
+                log.info("非Http请求 : {}", pjp.getSignature().getDeclaringTypeName() + "." + pjp.getSignature().getName());
+                return pjp.proceed();
+            }
+            HttpServletRequest request = sra.getRequest();
+            User user = userService.getInfo();
+            //String authorization = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
+            //log.info("X-Access-Token : {}", authorization);
+            if (user != null) {
+                log.info("USER_NAME : {}", Strings.isNullOrEmpty(user.getRealName())? user.getNickname():user.getRealName());
+            } else {
+                log.info("USER_NAME : 用户未登录,请求头中未携带Authorization");
+            }
+            log.info("URL : " + request.getRequestURL().toString());
+            log.info("HTTP_METHOD : " + request.getMethod());
+            log.info("IP : " + request.getRemoteAddr());
+            log.info("CLASS_METHOD : " + pjp.getSignature().getDeclaringTypeName() + "." + pjp.getSignature().getName());
+
+            ObjectMapper objectMapper = Jackson.getObjectMapper();
+            Object[] args = pjp.getArgs();
+            if (args != null) {
+                Object[] objects = new Object[args.length];
+                for (int i = 0; i < objects.length; i++) {
+                    if (args[i] instanceof Aware ||args[i] instanceof View || args[i] instanceof ModelAndView ||args[i] instanceof ServletRequest || args[i] instanceof ServletResponse || args[i] instanceof InputStreamSource || args[i] instanceof BindingResult || args[i] instanceof MultipartFile) {
+                        // 不打印request
+                        objects[i] = args[i].getClass().getName();
+                        continue;
+                    }
+                    objects[i] = args[i];
+                }
+                log.info("请求参数 : " + objectMapper.writeValueAsString(objects));
+            }
+            startTime = System.currentTimeMillis();
+            Object response = pjp.proceed();
+            // 3.出参打印
+            if (!(response instanceof Aware ||response instanceof View ||response instanceof ModelAndView ||response instanceof ServletRequest || response instanceof ServletResponse || response instanceof InputStreamSource || response instanceof BindingResult|| response instanceof MultipartFile)) {
+                log.info("返回参数 : {}", response != null ? objectMapper.writeValueAsString(response) : "null");
+            } else {
+                log.info("返回参数 : {}", "无法格式化数据");
+            }
+            return response;
+        } catch (Throwable e) {
+            if (e instanceof MethodArgumentNotValidException) {
+                log.info("响应错误:{}", e.getMessage());
+            } else {
+                log.error("响应错误:{}", Arrays.toString(e.getStackTrace()));
+            }
+            e.printStackTrace();
+            //throw e;
+            return pjp.proceed();
+        } finally {
+            long endTime = System.currentTimeMillis();
+            log.info("耗时 : {}ms", (endTime - startTime));
+        }
+    }
+/*
+
+    @Around("pointCutMethodController()")
+    public Object doAroundService(ProceedingJoinPoint pjp) throws Throwable {
+
         long begin = System.nanoTime();
 
         Object obj = pjp.proceed();
@@ -41,5 +130,6 @@ public class ControllerAspect {
 
         return obj;
     }
+*/
 
 }

+ 92 - 2
crmeb-front/src/main/java/com/zbkj/front/aspect/ControllerAspect.java

@@ -1,13 +1,33 @@
 package com.zbkj.front.aspect;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Strings;
+import com.qcloud.cos.utils.Jackson;
+import com.zbkj.common.model.user.User;
+import com.zbkj.service.service.UserService;
+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.annotation.Pointcut;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.Aware;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.InputStreamSource;
 import org.springframework.stereotype.Component;
-
+import org.springframework.validation.BindingResult;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.context.request.RequestAttributes;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.servlet.View;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
 import java.util.Arrays;
 
 
@@ -17,9 +37,13 @@ import java.util.Arrays;
  */
 @Aspect
 @Component
+@Slf4j
 public class ControllerAspect {
 
-    Logger logger = LoggerFactory.getLogger(ControllerAspect.class);
+    //Logger logger = LoggerFactory.getLogger(ControllerAspect.class);
+
+    @Autowired
+    private UserService userService;
 
     @Pointcut("execution(* com.zbkj.front.controller.*.*(..))")
     private void pointCutMethodController() {
@@ -29,6 +53,71 @@ public class ControllerAspect {
     @Around("pointCutMethodController()")
     public Object doAroundService(ProceedingJoinPoint pjp) throws Throwable {
 
+        long startTime = System.currentTimeMillis();
+        try {
+            RequestAttributes ra = RequestContextHolder.getRequestAttributes();
+            ServletRequestAttributes sra = (ServletRequestAttributes) ra;
+            //防止不是http请求的方法,例如:scheduled
+            if (ra == null || sra == null) {
+                log.info("非Http请求 : {}", pjp.getSignature().getDeclaringTypeName() + "." + pjp.getSignature().getName());
+                return pjp.proceed();
+            }
+            HttpServletRequest request = sra.getRequest();
+            User user = userService.getInfo();
+            //String authorization = request.getHeader(CommonConstant.X_ACCESS_TOKEN);
+            //log.info("X-Access-Token : {}", authorization);
+            if (user != null) {
+                log.info("USER_NAME : {}", Strings.isNullOrEmpty(user.getRealName())? user.getNickname():user.getRealName());
+            } else {
+                log.info("USER_NAME : 用户未登录,请求头中未携带Authorization");
+            }
+            log.info("URL : " + request.getRequestURL().toString());
+            log.info("HTTP_METHOD : " + request.getMethod());
+            log.info("IP : " + request.getRemoteAddr());
+            log.info("CLASS_METHOD : " + pjp.getSignature().getDeclaringTypeName() + "." + pjp.getSignature().getName());
+
+            ObjectMapper objectMapper = Jackson.getObjectMapper();
+            Object[] args = pjp.getArgs();
+            if (args != null) {
+                Object[] objects = new Object[args.length];
+                for (int i = 0; i < objects.length; i++) {
+                    if (args[i] instanceof Aware ||args[i] instanceof View || args[i] instanceof ModelAndView ||args[i] instanceof ServletRequest || args[i] instanceof ServletResponse || args[i] instanceof InputStreamSource || args[i] instanceof BindingResult || args[i] instanceof MultipartFile) {
+                        // 不打印request
+                        objects[i] = args[i].getClass().getName();
+                        continue;
+                    }
+                    objects[i] = args[i];
+                }
+                log.info("请求参数 : " + objectMapper.writeValueAsString(objects));
+            }
+            startTime = System.currentTimeMillis();
+            Object response = pjp.proceed();
+            // 3.出参打印
+            if (!(response instanceof Aware ||response instanceof View ||response instanceof ModelAndView ||response instanceof ServletRequest || response instanceof ServletResponse || response instanceof InputStreamSource || response instanceof BindingResult|| response instanceof MultipartFile)) {
+                log.info("返回参数 : {}", response != null ? objectMapper.writeValueAsString(response) : "null");
+            } else {
+                log.info("返回参数 : {}", "无法格式化数据");
+            }
+            return response;
+        } catch (Throwable e) {
+            if (e instanceof MethodArgumentNotValidException) {
+                log.info("响应错误:{}", e.getMessage());
+            } else {
+                log.error("响应错误:{}", Arrays.toString(e.getStackTrace()));
+            }
+            e.printStackTrace();
+            //throw e;
+            return pjp.proceed();
+        } finally {
+            long endTime = System.currentTimeMillis();
+            log.info("耗时 : {}ms", (endTime - startTime));
+        }
+    }
+/*
+
+    @Around("pointCutMethodController()")
+    public Object doAroundService(ProceedingJoinPoint pjp) throws Throwable {
+
         long begin = System.nanoTime();
 
         Object obj = pjp.proceed();
@@ -41,5 +130,6 @@ public class ControllerAspect {
 
         return obj;
     }
+*/
 
 }

+ 7 - 5
crmeb-front/src/main/java/com/zbkj/front/service/impl/FrontOrderServiceImpl.java

@@ -319,9 +319,9 @@ public class FrontOrderServiceImpl implements FrontOrderService {
     @Override
     public OrderNoResponse createOrder(CreateOrderRequest orderRequest) {
         User user = userService.getInfo();
-        //if (user ==null) {
-        //    throw new CrmebException("获取用户信息失败无法创建订单");
-        //}
+        if (user ==null) {
+            throw new CrmebException("获取用户信息失败无法创建订单");
+        }
         //if(Strings.isNullOrEmpty(user.getPhone())){
         //    throw new CrmebException("请添加手机号");
         //}
@@ -408,6 +408,7 @@ public class FrontOrderServiceImpl implements FrontOrderService {
                 UserEnterprise userEnterprise = userEnterpriseService.getOne(enterpriseLambdaQueryWrapper);
                 if (null != userEnterprise) {
                     order.setProcureUnit(userEnterprise.getEnterpriseName());
+                    order.setEnterpriseId(userEnterprise.getId());
                 }
 
             } else if (3 == isEnterpriseUser) {
@@ -419,6 +420,7 @@ public class FrontOrderServiceImpl implements FrontOrderService {
                     Integer enterpriseId = userBypassAccount.getEnterpriseId();
                     UserEnterprise userEnterprise = userEnterpriseService.getById(enterpriseId);
                     order.setProcureUnit(userEnterprise.getEnterpriseName());
+                    order.setEnterpriseId(enterpriseId);
                 } else {
                     order.setProcureUnit("");
                 }
@@ -431,7 +433,7 @@ public class FrontOrderServiceImpl implements FrontOrderService {
         }
 
         //企业子账户只能看自己企业的订单
-        if (2 == user.getIsEnterpriseUser() || 3 == user.getIsEnterpriseUser()) {
+/*        if (2 == user.getIsEnterpriseUser() || 3 == user.getIsEnterpriseUser()) {
             LambdaQueryWrapper<UserBypassAccount> queryWrapper = new LambdaQueryWrapper<>();
             queryWrapper.eq(UserBypassAccount::getUserId, user.getId());
             queryWrapper.eq(UserBypassAccount::getIsDelete, 0);
@@ -449,7 +451,7 @@ public class FrontOrderServiceImpl implements FrontOrderService {
                     order.setEnterpriseId(enterpriseId);
                 }
             }
-        }
+        }*/
 
         // 商户订单
         List<Integer> couponIdList = CollUtil.newArrayList();

+ 3 - 3
crmeb-front/src/main/java/com/zbkj/front/service/impl/SeckillServiceImpl.java

@@ -677,9 +677,9 @@ public class SeckillServiceImpl implements SeckillService {
      */
     @Override
     public OrderNoResponse createOrder(CreateOrderRequest orderRequest, PreOrderInfoVo orderInfoVo, User user) {
-        //if (user ==null) {
-        //    throw new CrmebException("获取用户信息失败无法创建订单");
-        //}
+        if (user ==null) {
+            throw new CrmebException("获取用户信息失败无法创建订单");
+        }
         //if(Strings.isNullOrEmpty(user.getPhone())){
         //    throw new CrmebException("请添加手机号");
         //}