张延森 3 년 전
부모
커밋
d2fcb353e5

+ 1
- 1
deploy/template.yml 파일 보기

@@ -11,7 +11,7 @@ Resources:
11 11
       Properties:
12 12
         Handler: com.yunzhi.demo.SpringApplication::main
13 13
         Runtime: custom
14
-        CodeUri: 'oss://yz-serverless/medical-plat/medical-plat-0.0.1.zip'
14
+        CodeUri: 'oss://yz-serverless/medical-plat/medical-plat-0.0.2.zip'
15 15
         MemorySize: 1024
16 16
         Timeout: 30
17 17
         InitializationTimeout: 30

+ 4
- 2
src/main/java/com/yunzhi/demo/common/JWTUtils.java 파일 보기

@@ -1,10 +1,12 @@
1 1
 package com.yunzhi.demo.common;
2 2
 
3
+import com.yunzhi.demo.controller.TaTestLogController;
3 4
 import io.jsonwebtoken.Claims;
4 5
 import io.jsonwebtoken.Jws;
5 6
 import io.jsonwebtoken.Jwts;
6 7
 import io.jsonwebtoken.security.Keys;
7
-import lombok.extern.slf4j.Slf4j;
8
+import org.slf4j.Logger;
9
+import org.slf4j.LoggerFactory;
8 10
 
9 11
 import javax.crypto.SecretKey;
10 12
 import javax.servlet.http.HttpServletRequest;
@@ -20,8 +22,8 @@ import java.util.Map;
20 22
  * jwt 辅助类
21 23
  * https://github.com/jwtk/jjwt
22 24
  */
23
-@Slf4j
24 25
 public class JWTUtils {
26
+    private static final Logger log = LoggerFactory.getLogger(TaTestLogController.class);
25 27
 
26 28
     // 过期时间 30 分钟
27 29
     public static final long EXPIRE_TIME = 30 * 60;

+ 8
- 1
src/main/java/com/yunzhi/demo/controller/TaTestLogController.java 파일 보기

@@ -7,6 +7,8 @@ import com.yunzhi.demo.common.BaseController;
7 7
 import com.yunzhi.demo.common.Constants;
8 8
 import com.yunzhi.demo.common.ResponseBean;
9 9
 import com.yunzhi.demo.entity.TaPerson;
10
+import com.yunzhi.demo.entity.TaStudent;
11
+import com.yunzhi.demo.service.ITaStudentService;
10 12
 import com.yunzhi.demo.vo.StudentTestLog;
11 13
 import io.swagger.annotations.Api;
12 14
 import io.swagger.annotations.ApiOperation;
@@ -42,6 +44,9 @@ public class TaTestLogController extends BaseController {
42 44
     @Autowired
43 45
     public ITaTestLogService iTaTestLogService;
44 46
 
47
+    @Autowired
48
+    public ITaStudentService iTaStudentService;
49
+
45 50
 
46 51
     /**
47 52
      * 分页查询列表
@@ -54,10 +59,12 @@ public class TaTestLogController extends BaseController {
54 59
     public ResponseBean taTestLogList(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
55 60
                                       @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception{
56 61
         TaPerson taPerson = getCurrentPerson();
62
+        TaStudent taStudent = iTaStudentService.getByPersonId(taPerson.getPersonId());
63
+        String studentId = taStudent == null ? "******" : taStudent.getStudentId();
57 64
 
58 65
         IPage<TaTestLog> pg = new Page<>(pageNum, pageSize);
59 66
         QueryWrapper<TaTestLog> queryWrapper = new QueryWrapper<>();
60
-        queryWrapper.eq("person_id", taPerson.getPersonId());
67
+        queryWrapper.eq("student_id", studentId);
61 68
         queryWrapper.eq("status", Constants.STATUS_NORMAL);
62 69
         queryWrapper.orderByDesc("create_date");
63 70
 

+ 79
- 0
src/main/java/com/yunzhi/demo/log/MysqlAppender.java 파일 보기

@@ -0,0 +1,79 @@
1
+package com.yunzhi.demo.log;
2
+
3
+import static ch.qos.logback.core.db.DBHelper.closeStatement;
4
+import ch.qos.logback.core.UnsynchronizedAppenderBase;
5
+import ch.qos.logback.core.db.ConnectionSource;
6
+import ch.qos.logback.core.encoder.Encoder;
7
+
8
+import java.sql.Connection;
9
+import java.sql.PreparedStatement;
10
+import java.util.Arrays;
11
+
12
+public class MysqlAppender<E> extends UnsynchronizedAppenderBase<E> {
13
+    protected ConnectionSource connectionSource;
14
+    protected Encoder<E> encoder;
15
+    protected String app = "medical_plat";
16
+
17
+    @Override
18
+    public void start() {
19
+        if (connectionSource == null) {
20
+            throw new IllegalStateException("MysqlAppender cannot function without a connection source");
21
+        }
22
+
23
+        super.start();
24
+    }
25
+
26
+    public ConnectionSource getConnectionSource() {
27
+        return connectionSource;
28
+    }
29
+
30
+    public void setConnectionSource(ConnectionSource connectionSource) {
31
+        this.connectionSource = connectionSource;
32
+    }
33
+
34
+    @Override
35
+    protected void append(E event) {
36
+        Connection connection = null;
37
+        PreparedStatement insertStatement = null;
38
+
39
+        try {
40
+            connection = connectionSource.getConnection();
41
+            connection.setAutoCommit(false);
42
+            insertStatement = connection.prepareStatement(getInsertSQL());
43
+
44
+            synchronized (this) {
45
+                byte[] logContent = this.encoder.encode(event);
46
+                insertStatement.setBytes(1, logContent);
47
+                insertStatement.execute();
48
+                closeStatement(insertStatement);
49
+            }
50
+
51
+            connection.commit();
52
+        } catch (Throwable sqle) {
53
+            addError("problem appending event", sqle);
54
+        }
55
+
56
+    }
57
+
58
+    public Encoder<E> getEncoder() {
59
+        return encoder;
60
+    }
61
+
62
+    public void setEncoder(Encoder<E> encoder) {
63
+        this.encoder = encoder;
64
+    }
65
+
66
+    @Override
67
+    public void stop() {
68
+        super.stop();
69
+    }
70
+
71
+    private String getInsertSQL() {
72
+        String tableName = "ta_"+app;
73
+        String[] columns = {"log"};
74
+        String[] signs = Arrays.stream(columns).map(x -> "?").toArray(String[]::new);
75
+        String sql = String.format("INSERT INTO %s (%s) values (%s)", tableName, String.join(",", columns), String.join(",", signs));
76
+//        System.out.println(sql);
77
+        return sql;
78
+    }
79
+}

+ 31
- 0
src/main/resources/logback.xml 파일 보기

@@ -0,0 +1,31 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<configuration>
3
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
5
+            <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
6
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
7
+        </encoder>
8
+    </appender>
9
+    <appender name="LOGDB" class="com.yunzhi.demo.log.MysqlAppender">
10
+        <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
11
+            <driverClass>com.mysql.cj.jdbc.Driver</driverClass>
12
+            <url>jdbc:mysql://rm-uf6z3z6jq11x653d77o.mysql.rds.aliyuncs.com:3306/yz_log</url>
13
+            <user>yz_log</user>
14
+            <password>log@1234</password>
15
+        </connectionSource>
16
+        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
17
+            <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
18
+            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
19
+        </encoder>
20
+    </appender>
21
+
22
+    <logger name="com.apache.ibatis" level="TRACE"/>
23
+    <logger name="java.sql.Connection" level="DEBUG"/>
24
+    <logger name="java.sql.Statement" level="DEBUG"/>
25
+    <logger name="java.sql.PreparedStatement" level="DEBUG"/>
26
+
27
+    <root level="INFO">
28
+        <appender-ref ref="STDOUT" />
29
+        <appender-ref ref="LOGDB" />
30
+    </root>
31
+</configuration>