Browse Source

Merge remote-tracking branch 'origin/dev' into dev

dzx 1 month ago
parent
commit
026321e1f6

+ 28 - 1
.drone.yml

@@ -6,20 +6,39 @@ node:
   mode: local_test
 
 steps:
+  # 只需要下载一次,以后将其注释
+#  - name: skywalking
+#    image: alpine/git:v2.45.2
+#    commands:
+#      - git clone https://git.yingcaibx.com/public/skywalking-agent-java.git /root/skywalking-agent-java
+#    volumes:
+#      - name: skywalking-cache
+#        path: /root/skywalking-agent-java
+
   - name: maven
     image: maven:3.6.3-jdk-11
     volumes:
       - name: maven-cache
         path: /root/.m2 # 将maven下载依赖的目录挂载出来,防止重复下载
+      - name: skywalking
+        host:
+          path: /data/cache/skywalking
+        container:
+          path: /code/skywalking-agent-java
     commands:
       - mvn -Dmaven.test.skip=true -P dev clean package
 
   - name: build
     image: docker:20.10.7
-    depends_on: [maven]
+#    depends_on: [maven]
     volumes:
       - name: docker
         path: /var/run/docker.sock
+      - name: skywalking
+        host:
+          path: /data/cache/skywalking
+        container:
+          path: /code/skywalking-agent-java
     environment:
       IMAGE: registry.yingcaibx.com/tl/api:latest
     commands:
@@ -49,6 +68,14 @@ volumes:
   - name: maven-cache
     host:
       path: /data/cache/tl/api
+  - name: skywalking-cache
+    host:
+      path: /data/cache/skywalking
+  - name: skywalking
+    host:
+      path: /data/cache/skywalking
+    container:
+      path: /code/skywalking-agent-java
 
 ---
 kind: pipeline

+ 7 - 2
Dockerfile

@@ -4,5 +4,10 @@ EXPOSE 8080
 ENV TZ=Asia/Shanghai
 RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
 
-ADD target/xjrsoft-boot.jar  /app.jar
-ENTRYPOINT ["java","-jar","/app.jar"]
+#ADD target/xjrsoft-boot.jar  /app.jar
+#ADD start.sh  /start.sh
+
+RUN mkdir /skywalking-agent-java
+COPY /code/skywalking-agent-java/ /skywalking-agent-java/
+
+CMD ["sh","/start.sh"]

+ 4 - 0
src/main/java/com/xjrsoft/common/annotation/XjrLog.java

@@ -17,4 +17,8 @@ import java.lang.annotation.Target;
 public @interface XjrLog {
 
 	String value() default "";
+
+	boolean saveRequestData() default true;
+
+	boolean saveResponseData() default false;
 }

+ 94 - 95
src/main/java/com/xjrsoft/common/aspect/XjrLogAspect.java

@@ -33,99 +33,98 @@ import java.time.LocalDateTime;
 @Component
 public class XjrLogAspect {
 
-	@Autowired
-	private LogMapper logMapper;
-
-	
-	@Pointcut("@annotation(com.xjrsoft.common.annotation.XjrLog)")
-	public void logPointCut() { 
-		
-	}
-
-
-	@Around("logPointCut()")
-	public Object around(ProceedingJoinPoint point) throws Throwable {
-		long beginTime = System.currentTimeMillis();
-		Object result = null;
-		try {
-			//执行方法
-			result = point.proceed();
-		} catch (Throwable e) {
-			//执行时长(毫秒)
-			long time = System.currentTimeMillis() - beginTime;
-			insertLog(point, time, LogCategoryEnum.EXCEPTION.getCode());
-			throw e;
-		}
-		//执行时长(毫秒)
-		long time = System.currentTimeMillis() - beginTime;
-
-		//保存日志
-		insertLog(point, time, null);
-
-		return result;
-	}
-
-	private void insertLog(ProceedingJoinPoint joinPoint, long time, Integer category) {
-		MethodSignature signature = (MethodSignature) joinPoint.getSignature();
-		Method method = signature.getMethod();
-
-		Log logEntity = new Log();
-		XjrLog xjrLog = method.getAnnotation(XjrLog.class);
-		if(xjrLog != null){
-			//注解上的描述
-			logEntity.setOperation(xjrLog.value());
-		}
-
-		//请求的方法名
-		String className = joinPoint.getTarget().getClass().getName();
-		String methodName = signature.getName();
-		logEntity.setMethod(className + "." + methodName + "()");
-
-		//请求的参数
-		Object[] args = joinPoint.getArgs();
-		try{
-			String params = new Gson().toJson(args);
-			if (params.length() < 4000) {
-				logEntity.setParams(params);
-			}
-		}catch (Exception e){
-
-		}
-
-		//获取request
-		HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
-		//设置IP地址
-		logEntity.setIp(ServletUtil.getClientIP(request));
-
-		//用户名
-		//判断是否已登录,如果已登录了,就获取token时间,未登录状态直接放行
-		if(StpUtil.isLogin()){
-			SaSession tokenSession = StpUtil.getTokenSession();
-			User user = tokenSession.get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
-			logEntity.setUsername(user.getUserName());
-			logEntity.setTime(time);
-			logEntity.setCategory(category == null ? getCategory(request) : category);
-			logEntity.setCreateTime(LocalDateTime.now());
-			//保存系统日志
-			logMapper.insert(logEntity);
-		}
-	}
-
-	/**
-	 * @title 获取日志分类
-	 * @create 2020111119:23:30
-	 * */
-	private int getCategory(HttpServletRequest request){
-		if(request.getRequestURI().equalsIgnoreCase("/system/login")){
-			return LogCategoryEnum.LOGIN.getCode();
-		}
-		else if (request.getMethod().toLowerCase().equals("get")){
-			return  LogCategoryEnum.GET.getCode();
-		}
-		else if(request.getMethod().toLowerCase().equals("post") || request.getMethod().toLowerCase().equals("put") || request.getMethod().toLowerCase().equals("patch") || request.getMethod().toLowerCase().equals("delete")) {
-			return  LogCategoryEnum.OPERAT.getCode();
-		}
-		else
-			return  LogCategoryEnum.EXCEPTION.getCode();
-	}
+    @Autowired
+    private LogMapper logMapper;
+
+
+    @Pointcut("@annotation(com.xjrsoft.common.annotation.XjrLog)")
+    public void logPointCut() {
+
+    }
+
+
+    @Around("logPointCut()")
+    public Object around(ProceedingJoinPoint point) throws Throwable {
+        long beginTime = System.currentTimeMillis();
+        Object result = null;
+        try {
+            //执行方法
+            result = point.proceed();
+        } catch (Throwable e) {
+            //执行时长(毫秒)
+            long time = System.currentTimeMillis() - beginTime;
+            insertLog(point, time, LogCategoryEnum.EXCEPTION.getCode());
+            throw e;
+        }
+        //执行时长(毫秒)
+        long time = System.currentTimeMillis() - beginTime;
+
+        //保存日志
+        insertLog(point, time, null);
+
+        return result;
+    }
+
+    private void insertLog(ProceedingJoinPoint joinPoint, long time, Integer category) {
+        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
+        Method method = signature.getMethod();
+
+        Log logEntity = new Log();
+        XjrLog xjrLog = method.getAnnotation(XjrLog.class);
+        if (xjrLog != null) {
+            //注解上的描述
+            logEntity.setOperation(xjrLog.value());
+        }
+
+        //请求的方法名
+        String className = joinPoint.getTarget().getClass().getName();
+        String methodName = signature.getName();
+        logEntity.setMethod(className + "." + methodName + "()");
+
+        if (xjrLog != null && xjrLog.saveRequestData()) {
+            //请求的参数
+            Object[] args = joinPoint.getArgs();
+            try {
+                String params = new Gson().toJson(args);
+                if (params.length() < 4000) {
+                    logEntity.setParams(params);
+                }
+            } catch (Exception e) {
+
+            }
+        }
+
+        //获取request
+        HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
+        //设置IP地址
+        logEntity.setIp(ServletUtil.getClientIP(request));
+
+        //用户名
+        //判断是否已登录,如果已登录了,就获取token时间,未登录状态直接放行
+        if (StpUtil.isLogin()) {
+            SaSession tokenSession = StpUtil.getTokenSession();
+            User user = tokenSession.get(GlobalConstant.LOGIN_USER_INFO_KEY, new User());
+            logEntity.setUsername(user.getUserName());
+            logEntity.setTime(time);
+            logEntity.setCategory(category == null ? getCategory(request) : category);
+            logEntity.setCreateTime(LocalDateTime.now());
+            //保存系统日志
+            logMapper.insert(logEntity);
+        }
+    }
+
+    /**
+     * @title 获取日志分类
+     * @create 2020111119:23:30
+     */
+    private int getCategory(HttpServletRequest request) {
+        if (request.getRequestURI().equalsIgnoreCase("/system/login")) {
+            return LogCategoryEnum.LOGIN.getCode();
+        } else if (request.getMethod().toLowerCase().equals("get")) {
+            return LogCategoryEnum.GET.getCode();
+        } else if (request.getMethod().toLowerCase().equals("post") || request.getMethod().toLowerCase().equals("put") || request.getMethod().toLowerCase().equals("patch") || request.getMethod().toLowerCase().equals("delete")) {
+            return LogCategoryEnum.OPERAT.getCode();
+        } else
+            return LogCategoryEnum.EXCEPTION.getCode();
+    }
 }

+ 11 - 10
src/main/java/com/xjrsoft/module/system/controller/LoginController.java

@@ -82,7 +82,7 @@ public class LoginController {
 
     @PostMapping("/login")
     @ApiOperation(value = "登录", notes = "传入账号:account,密码:password")
-    @XjrLog(value = "账号密码登录成功")
+    @XjrLog(value = "账号密码登录成功", saveRequestData = false)
     public R login(@RequestBody @Valid LoginDto dto) throws Exception {
         return R.ok(loginService.login(dto));
     }
@@ -102,14 +102,15 @@ public class LoginController {
     }
 
     @GetMapping(value = "/loginQRCode")
-    @ApiOperation(value="登录-二维码")
+    @ApiOperation(value = "登录-二维码")
     @SaCheckPermission("login:detail")
+    @XjrLog(value = "登录-二维码")
     public RT<LoginQRCodeVo> qrcode() {
         long loginCode = IdUtil.getSnowflakeNextId();
-        String url = commonPropertiesConfig.getDomainApp() + "pages/login/qrCodeLogin/index?loginCode="+loginCode;
+        String url = commonPropertiesConfig.getDomainApp() + "pages/login/qrCodeLogin/index?loginCode=" + loginCode;
         String active = SpringUtil.getActiveProfile();
-        if(!"prod".equals(active)){
-            url = "http://yxh-web.ngrok.yingcaibx.com/app/#/pages/login/qrCodeLogin/index?loginCode="+loginCode;
+        if (!"prod".equals(active)) {
+            url = "http://yxh-web.ngrok.yingcaibx.com/app/#/pages/login/qrCodeLogin/index?loginCode=" + loginCode;
         }
         int width = 200;
         int height = 200;
@@ -138,7 +139,7 @@ public class LoginController {
 //            return RT.error("二维码失效,请刷新重试");
 //        }
         Boolean b = loginService.loginQRCode(dto);
-        if(b){
+        if (b) {
             return RT.ok("登录成功");
         }
 
@@ -150,12 +151,12 @@ public class LoginController {
     @XjrLog(value = "验证是否登录成功")
     public RT<LoginCheckQRCodeVo> checkLoginQRCode(@RequestBody @Valid QRLoginDto dto) {
         Long timestamp = redisUtil.get(dto.getLoginCode() + "time", Long.class);
-        if(timestamp == null){
+        if (timestamp == null) {
             timestamp = System.currentTimeMillis();
         }
         long timeMillis = System.currentTimeMillis();
         LoginCheckQRCodeVo loginCheckQRCodeVo = new LoginCheckQRCodeVo();
-        if(timeMillis - timestamp > 300000){
+        if (timeMillis - timestamp > 300000) {
             loginCheckQRCodeVo.setStatus(1);
             return RT.ok(loginCheckQRCodeVo);
         }
@@ -284,7 +285,7 @@ public class LoginController {
     @PostMapping("/qrcode-login")
     @ApiOperation(value = "oauth 扫码登录", notes = "oauth 扫码登录")
     @XjrLog(value = "oauth 扫码登录")
-    public R createAuthorizeUrl(@Valid @RequestBody CreateAuthorizeUrlDto dto){
+    public R createAuthorizeUrl(@Valid @RequestBody CreateAuthorizeUrlDto dto) {
 
         AuthRequest authRequest = oauthService.getAuthRequest(dto.getSource());
         String authorizeUrl = authRequest.authorize(AuthStateUtils.createState());
@@ -295,7 +296,7 @@ public class LoginController {
     @ApiOperation(value = "图形验证码", notes = "图形验证码")
     public R imgcaptchaAnswer(String key) {
         String active = SpringUtil.getActiveProfile();
-        if(!"dev".equals(active)){
+        if (!"dev".equals(active)) {
             return R.ok();
         }
 

+ 7 - 0
start.sh

@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ $JAVA_AGENT ]; then
+    java -javaagent:$JAVA_AGENT -Duser.timezone=Asia/Shanghai -jar /app.jar
+else
+    java -Duser.timezone=Asia/Shanghai -jar /app.jar
+fi