官方测试

This commit is contained in:
中青华年 2025-04-21 18:08:49 +08:00
parent 5224cfb1a7
commit bcf8893b00
21 changed files with 431 additions and 317 deletions

View File

@ -0,0 +1,127 @@
2025-04-21 17:06:00 [main] INFO com.yang.test.TestApplication - Starting TestApplication using Java 17.0.13 with PID 21100 (D:\project\Mbti\test\target\classes started by DENG in D:\project\Mbti\test)
2025-04-21 17:06:00 [main] DEBUG com.yang.test.TestApplication - Running with Spring Boot v3.4.4, Spring v6.2.5
2025-04-21 17:06:00 [main] INFO com.yang.test.TestApplication - No active profile set, falling back to 1 default profile: "default"
2025-04-21 17:06:01 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port 8080 (http)
2025-04-21 17:06:01 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat]
2025-04-21 17:06:01 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/10.1.39]
2025-04-21 17:06:01 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
2025-04-21 17:06:01 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 1111 ms
2025-04-21 17:06:01 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
2025-04-21 17:06:06 [main] INFO com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@64518270
2025-04-21 17:06:06 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
2025-04-21 17:06:07 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port 8080 (http) with context path '/'
2025-04-21 17:06:07 [main] INFO com.yang.test.TestApplication - Started TestApplication in 7.638 seconds (process running for 8.243)
2025-04-21 17:06:07 [main] INFO com.yang.test.TestApplication - MBTI测试系统启动成功! 服务运行在端口: 8080
2025-04-21 17:06:46 [http-nio-8080-exec-3] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring DispatcherServlet 'dispatcherServlet'
2025-04-21 17:06:46 [http-nio-8080-exec-3] INFO o.s.web.servlet.DispatcherServlet - Initializing Servlet 'dispatcherServlet'
2025-04-21 17:06:46 [http-nio-8080-exec-3] INFO o.s.web.servlet.DispatcherServlet - Completed initialization in 1 ms
2025-04-21 17:06:46 [http-nio-8080-exec-3] INFO c.y.test.controller.MbtiController - 开始获取题目, 测试ID: 1
2025-04-21 17:06:46 [http-nio-8080-exec-3] DEBUG c.y.t.mapper.MbtiMapper.getTestById - ==> Preparing: SELECT id, name FROM test WHERE id = ?
2025-04-21 17:06:46 [http-nio-8080-exec-3] DEBUG c.y.t.mapper.MbtiMapper.getTestById - ==> Parameters: 1(String)
2025-04-21 17:06:46 [http-nio-8080-exec-3] DEBUG c.y.t.mapper.MbtiMapper.getTestById - <== Total: 1
2025-04-21 17:06:46 [http-nio-8080-exec-3] DEBUG c.y.t.m.M.getQuestionsByTestId - ==> Preparing: SELECT id, name, type, ? as testId FROM question WHERE test_id = ? ORDER BY id
2025-04-21 17:06:46 [http-nio-8080-exec-3] DEBUG c.y.t.m.M.getQuestionsByTestId - ==> Parameters: 1(String), 1(String)
2025-04-21 17:06:46 [http-nio-8080-exec-3] DEBUG c.y.t.m.M.getQuestionsByTestId - <== Total: 93
2025-04-21 17:06:46 [http-nio-8080-exec-3] DEBUG c.y.t.m.M.getOptionsByQuestionIds - ==> Preparing: SELECT id, code, name, question_id as questionId, character_type as characterType FROM option_table WHERE question_id IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ORDER BY question_id, id
2025-04-21 17:06:46 [http-nio-8080-exec-3] DEBUG c.y.t.m.M.getOptionsByQuestionIds - ==> Parameters: 1(Integer), 2(Integer), 3(Integer), 4(Integer), 5(Integer), 6(Integer), 7(Integer), 8(Integer), 9(Integer), 10(Integer), 11(Integer), 12(Integer), 13(Integer), 14(Integer), 15(Integer), 16(Integer), 17(Integer), 18(Integer), 19(Integer), 20(Integer), 21(Integer), 22(Integer), 23(Integer), 24(Integer), 25(Integer), 26(Integer), 27(Integer), 28(Integer), 29(Integer), 30(Integer), 31(Integer), 32(Integer), 33(Integer), 34(Integer), 35(Integer), 36(Integer), 37(Integer), 38(Integer), 39(Integer), 40(Integer), 41(Integer), 42(Integer), 43(Integer), 44(Integer), 45(Integer), 46(Integer), 47(Integer), 48(Integer), 49(Integer), 50(Integer), 51(Integer), 52(Integer), 53(Integer), 54(Integer), 55(Integer), 56(Integer), 57(Integer), 58(Integer), 59(Integer), 60(Integer), 61(Integer), 62(Integer), 63(Integer), 64(Integer), 65(Integer), 66(Integer), 67(Integer), 68(Integer), 69(Integer), 70(Integer), 71(Integer), 72(Integer), 73(Integer), 74(Integer), 75(Integer), 76(Integer), 77(Integer), 78(Integer), 79(Integer), 80(Integer), 81(Integer), 82(Integer), 83(Integer), 84(Integer), 85(Integer), 86(Integer), 87(Integer), 88(Integer), 89(Integer), 90(Integer), 91(Integer), 92(Integer), 93(Integer)
2025-04-21 17:06:46 [http-nio-8080-exec-3] DEBUG c.y.t.m.M.getOptionsByQuestionIds - <== Total: 186
2025-04-21 17:06:46 [http-nio-8080-exec-3] INFO c.y.test.controller.MbtiController - 获取题目完成, 测试ID: 1, 题目数量: 93, 总耗时: PT0.3134364S
2025-04-21 17:10:28 [http-nio-8080-exec-6] INFO c.y.test.controller.MbtiController - 开始获取题目, 测试ID: 1
2025-04-21 17:10:28 [http-nio-8080-exec-6] DEBUG c.y.t.mapper.MbtiMapper.getTestById - ==> Preparing: SELECT id, name FROM test WHERE id = ?
2025-04-21 17:10:28 [http-nio-8080-exec-6] DEBUG c.y.t.mapper.MbtiMapper.getTestById - ==> Parameters: 1(String)
2025-04-21 17:10:29 [http-nio-8080-exec-6] DEBUG c.y.t.mapper.MbtiMapper.getTestById - <== Total: 1
2025-04-21 17:10:29 [http-nio-8080-exec-6] DEBUG c.y.t.m.M.getQuestionsByTestId - ==> Preparing: SELECT id, name, type, ? as testId FROM question WHERE test_id = ? ORDER BY id
2025-04-21 17:10:29 [http-nio-8080-exec-6] DEBUG c.y.t.m.M.getQuestionsByTestId - ==> Parameters: 1(String), 1(String)
2025-04-21 17:10:29 [http-nio-8080-exec-6] DEBUG c.y.t.m.M.getQuestionsByTestId - <== Total: 93
2025-04-21 17:10:29 [http-nio-8080-exec-6] DEBUG c.y.t.m.M.getOptionsByQuestionIds - ==> Preparing: SELECT id, code, name, question_id as questionId, character_type as characterType FROM option_table WHERE question_id IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ORDER BY question_id, id
2025-04-21 17:10:29 [http-nio-8080-exec-6] DEBUG c.y.t.m.M.getOptionsByQuestionIds - ==> Parameters: 1(Integer), 2(Integer), 3(Integer), 4(Integer), 5(Integer), 6(Integer), 7(Integer), 8(Integer), 9(Integer), 10(Integer), 11(Integer), 12(Integer), 13(Integer), 14(Integer), 15(Integer), 16(Integer), 17(Integer), 18(Integer), 19(Integer), 20(Integer), 21(Integer), 22(Integer), 23(Integer), 24(Integer), 25(Integer), 26(Integer), 27(Integer), 28(Integer), 29(Integer), 30(Integer), 31(Integer), 32(Integer), 33(Integer), 34(Integer), 35(Integer), 36(Integer), 37(Integer), 38(Integer), 39(Integer), 40(Integer), 41(Integer), 42(Integer), 43(Integer), 44(Integer), 45(Integer), 46(Integer), 47(Integer), 48(Integer), 49(Integer), 50(Integer), 51(Integer), 52(Integer), 53(Integer), 54(Integer), 55(Integer), 56(Integer), 57(Integer), 58(Integer), 59(Integer), 60(Integer), 61(Integer), 62(Integer), 63(Integer), 64(Integer), 65(Integer), 66(Integer), 67(Integer), 68(Integer), 69(Integer), 70(Integer), 71(Integer), 72(Integer), 73(Integer), 74(Integer), 75(Integer), 76(Integer), 77(Integer), 78(Integer), 79(Integer), 80(Integer), 81(Integer), 82(Integer), 83(Integer), 84(Integer), 85(Integer), 86(Integer), 87(Integer), 88(Integer), 89(Integer), 90(Integer), 91(Integer), 92(Integer), 93(Integer)
2025-04-21 17:10:29 [http-nio-8080-exec-6] DEBUG c.y.t.m.M.getOptionsByQuestionIds - <== Total: 186
2025-04-21 17:10:29 [http-nio-8080-exec-6] INFO c.y.test.controller.MbtiController - 获取题目完成, 测试ID: 1, 题目数量: 93, 总耗时: PT0.2429666S
2025-04-21 17:12:07 [SpringApplicationShutdownHook] INFO o.s.b.w.e.tomcat.GracefulShutdown - Commencing graceful shutdown. Waiting for active requests to complete
2025-04-21 17:12:08 [tomcat-shutdown] INFO o.s.b.w.e.tomcat.GracefulShutdown - Graceful shutdown complete
2025-04-21 17:12:08 [SpringApplicationShutdownHook] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown initiated...
2025-04-21 17:12:08 [SpringApplicationShutdownHook] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown completed.
2025-04-21 17:12:09 [main] INFO com.yang.test.TestApplication - Starting TestApplication using Java 17.0.13 with PID 12056 (D:\project\Mbti\test\target\classes started by DENG in D:\project\Mbti\test)
2025-04-21 17:12:09 [main] DEBUG com.yang.test.TestApplication - Running with Spring Boot v3.4.4, Spring v6.2.5
2025-04-21 17:12:09 [main] INFO com.yang.test.TestApplication - No active profile set, falling back to 1 default profile: "default"
2025-04-21 17:12:10 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port 8080 (http)
2025-04-21 17:12:10 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat]
2025-04-21 17:12:10 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/10.1.39]
2025-04-21 17:12:10 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
2025-04-21 17:12:10 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 841 ms
2025-04-21 17:12:10 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
2025-04-21 17:12:16 [main] INFO com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@2bb62414
2025-04-21 17:12:16 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
2025-04-21 17:12:16 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port 8080 (http) with context path '/'
2025-04-21 17:12:16 [main] INFO com.yang.test.TestApplication - Started TestApplication in 7.415 seconds (process running for 8.039)
2025-04-21 17:12:16 [main] INFO com.yang.test.TestApplication - MBTI测试系统启动成功! 服务运行在端口: 8080
2025-04-21 17:12:23 [http-nio-8080-exec-2] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring DispatcherServlet 'dispatcherServlet'
2025-04-21 17:12:23 [http-nio-8080-exec-2] INFO o.s.web.servlet.DispatcherServlet - Initializing Servlet 'dispatcherServlet'
2025-04-21 17:12:23 [http-nio-8080-exec-2] INFO o.s.web.servlet.DispatcherServlet - Completed initialization in 0 ms
2025-04-21 17:12:23 [http-nio-8080-exec-2] INFO c.y.test.controller.MbtiController - 开始获取题目, 测试ID: 1
2025-04-21 17:12:23 [http-nio-8080-exec-2] DEBUG c.y.t.mapper.MbtiMapper.getTestById - ==> Preparing: SELECT id, name FROM test WHERE id = ?
2025-04-21 17:12:23 [http-nio-8080-exec-2] DEBUG c.y.t.mapper.MbtiMapper.getTestById - ==> Parameters: 1(String)
2025-04-21 17:12:24 [http-nio-8080-exec-2] DEBUG c.y.t.mapper.MbtiMapper.getTestById - <== Total: 1
2025-04-21 17:12:24 [http-nio-8080-exec-2] DEBUG c.y.t.m.M.getQuestionsByTestId - ==> Preparing: SELECT id, name, type, ? as testId FROM question WHERE test_id = ? ORDER BY id
2025-04-21 17:12:24 [http-nio-8080-exec-2] DEBUG c.y.t.m.M.getQuestionsByTestId - ==> Parameters: 1(String), 1(String)
2025-04-21 17:12:24 [http-nio-8080-exec-2] DEBUG c.y.t.m.M.getQuestionsByTestId - <== Total: 93
2025-04-21 17:12:24 [http-nio-8080-exec-2] DEBUG c.y.t.m.M.getOptionsByQuestionIds - ==> Preparing: SELECT id, code, name, question_id as questionId, character_type as characterType FROM option_table WHERE question_id IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ORDER BY question_id, id
2025-04-21 17:12:24 [http-nio-8080-exec-2] DEBUG c.y.t.m.M.getOptionsByQuestionIds - ==> Parameters: 1(Integer), 2(Integer), 3(Integer), 4(Integer), 5(Integer), 6(Integer), 7(Integer), 8(Integer), 9(Integer), 10(Integer), 11(Integer), 12(Integer), 13(Integer), 14(Integer), 15(Integer), 16(Integer), 17(Integer), 18(Integer), 19(Integer), 20(Integer), 21(Integer), 22(Integer), 23(Integer), 24(Integer), 25(Integer), 26(Integer), 27(Integer), 28(Integer), 29(Integer), 30(Integer), 31(Integer), 32(Integer), 33(Integer), 34(Integer), 35(Integer), 36(Integer), 37(Integer), 38(Integer), 39(Integer), 40(Integer), 41(Integer), 42(Integer), 43(Integer), 44(Integer), 45(Integer), 46(Integer), 47(Integer), 48(Integer), 49(Integer), 50(Integer), 51(Integer), 52(Integer), 53(Integer), 54(Integer), 55(Integer), 56(Integer), 57(Integer), 58(Integer), 59(Integer), 60(Integer), 61(Integer), 62(Integer), 63(Integer), 64(Integer), 65(Integer), 66(Integer), 67(Integer), 68(Integer), 69(Integer), 70(Integer), 71(Integer), 72(Integer), 73(Integer), 74(Integer), 75(Integer), 76(Integer), 77(Integer), 78(Integer), 79(Integer), 80(Integer), 81(Integer), 82(Integer), 83(Integer), 84(Integer), 85(Integer), 86(Integer), 87(Integer), 88(Integer), 89(Integer), 90(Integer), 91(Integer), 92(Integer), 93(Integer)
2025-04-21 17:12:24 [http-nio-8080-exec-2] DEBUG c.y.t.m.M.getOptionsByQuestionIds - <== Total: 186
2025-04-21 17:12:24 [http-nio-8080-exec-2] INFO c.y.test.controller.MbtiController - 获取题目完成, 测试ID: 1, 题目数量: 93, 总耗时: PT0.3188868S
2025-04-21 17:22:13 [http-nio-8080-exec-4] INFO c.y.test.controller.MbtiController - 开始获取题目, 测试ID: 1
2025-04-21 17:22:13 [http-nio-8080-exec-4] DEBUG c.y.t.mapper.MbtiMapper.getTestById - ==> Preparing: SELECT id, name FROM test WHERE id = ?
2025-04-21 17:22:13 [http-nio-8080-exec-4] DEBUG c.y.t.mapper.MbtiMapper.getTestById - ==> Parameters: 1(String)
2025-04-21 17:22:13 [http-nio-8080-exec-4] DEBUG c.y.t.mapper.MbtiMapper.getTestById - <== Total: 1
2025-04-21 17:22:13 [http-nio-8080-exec-4] DEBUG c.y.t.m.M.getQuestionsByTestId - ==> Preparing: SELECT id, name, type, ? as testId FROM question WHERE test_id = ? ORDER BY id
2025-04-21 17:22:13 [http-nio-8080-exec-4] DEBUG c.y.t.m.M.getQuestionsByTestId - ==> Parameters: 1(String), 1(String)
2025-04-21 17:22:13 [http-nio-8080-exec-4] DEBUG c.y.t.m.M.getQuestionsByTestId - <== Total: 93
2025-04-21 17:22:13 [http-nio-8080-exec-4] DEBUG c.y.t.m.M.getOptionsByQuestionIds - ==> Preparing: SELECT id, code, name, question_id as questionId, character_type as characterType FROM option_table WHERE question_id IN ( ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? ) ORDER BY question_id, id
2025-04-21 17:22:13 [http-nio-8080-exec-4] DEBUG c.y.t.m.M.getOptionsByQuestionIds - ==> Parameters: 1(Integer), 2(Integer), 3(Integer), 4(Integer), 5(Integer), 6(Integer), 7(Integer), 8(Integer), 9(Integer), 10(Integer), 11(Integer), 12(Integer), 13(Integer), 14(Integer), 15(Integer), 16(Integer), 17(Integer), 18(Integer), 19(Integer), 20(Integer), 21(Integer), 22(Integer), 23(Integer), 24(Integer), 25(Integer), 26(Integer), 27(Integer), 28(Integer), 29(Integer), 30(Integer), 31(Integer), 32(Integer), 33(Integer), 34(Integer), 35(Integer), 36(Integer), 37(Integer), 38(Integer), 39(Integer), 40(Integer), 41(Integer), 42(Integer), 43(Integer), 44(Integer), 45(Integer), 46(Integer), 47(Integer), 48(Integer), 49(Integer), 50(Integer), 51(Integer), 52(Integer), 53(Integer), 54(Integer), 55(Integer), 56(Integer), 57(Integer), 58(Integer), 59(Integer), 60(Integer), 61(Integer), 62(Integer), 63(Integer), 64(Integer), 65(Integer), 66(Integer), 67(Integer), 68(Integer), 69(Integer), 70(Integer), 71(Integer), 72(Integer), 73(Integer), 74(Integer), 75(Integer), 76(Integer), 77(Integer), 78(Integer), 79(Integer), 80(Integer), 81(Integer), 82(Integer), 83(Integer), 84(Integer), 85(Integer), 86(Integer), 87(Integer), 88(Integer), 89(Integer), 90(Integer), 91(Integer), 92(Integer), 93(Integer)
2025-04-21 17:22:13 [http-nio-8080-exec-4] DEBUG c.y.t.m.M.getOptionsByQuestionIds - <== Total: 186
2025-04-21 17:22:13 [http-nio-8080-exec-4] INFO c.y.test.controller.MbtiController - 获取题目完成, 测试ID: 1, 题目数量: 93, 总耗时: PT0.2650471S
2025-04-21 17:24:33 [SpringApplicationShutdownHook] INFO o.s.b.w.e.tomcat.GracefulShutdown - Commencing graceful shutdown. Waiting for active requests to complete
2025-04-21 17:24:33 [tomcat-shutdown] INFO o.s.b.w.e.tomcat.GracefulShutdown - Graceful shutdown complete
2025-04-21 17:24:33 [SpringApplicationShutdownHook] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown initiated...
2025-04-21 17:24:33 [SpringApplicationShutdownHook] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown completed.
2025-04-21 17:28:16 [main] INFO com.yang.test.TestApplication - Starting TestApplication using Java 17.0.13 with PID 13076 (D:\project\Mbti\test\target\classes started by DENG in D:\project\Mbti\test)
2025-04-21 17:28:16 [main] DEBUG com.yang.test.TestApplication - Running with Spring Boot v3.4.4, Spring v6.2.5
2025-04-21 17:28:16 [main] INFO com.yang.test.TestApplication - No active profile set, falling back to 1 default profile: "default"
2025-04-21 17:28:17 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat initialized with port 8080 (http)
2025-04-21 17:28:17 [main] INFO o.a.catalina.core.StandardService - Starting service [Tomcat]
2025-04-21 17:28:17 [main] INFO o.a.catalina.core.StandardEngine - Starting Servlet engine: [Apache Tomcat/10.1.39]
2025-04-21 17:28:17 [main] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring embedded WebApplicationContext
2025-04-21 17:28:17 [main] INFO o.s.b.w.s.c.ServletWebServerApplicationContext - Root WebApplicationContext: initialization completed in 842 ms
2025-04-21 17:28:17 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
2025-04-21 17:28:23 [main] INFO com.zaxxer.hikari.pool.HikariPool - HikariPool-1 - Added connection com.mysql.cj.jdbc.ConnectionImpl@2bb62414
2025-04-21 17:28:23 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
2025-04-21 17:28:23 [main] INFO o.s.b.w.e.tomcat.TomcatWebServer - Tomcat started on port 8080 (http) with context path '/'
2025-04-21 17:28:23 [main] INFO com.yang.test.TestApplication - Started TestApplication in 7.294 seconds (process running for 7.834)
2025-04-21 17:28:23 [main] INFO com.yang.test.TestApplication - MBTI测试系统启动成功! 服务运行在端口: 8080
2025-04-21 17:28:54 [http-nio-8080-exec-1] INFO o.a.c.c.C.[Tomcat].[localhost].[/] - Initializing Spring DispatcherServlet 'dispatcherServlet'
2025-04-21 17:28:54 [http-nio-8080-exec-1] INFO o.s.web.servlet.DispatcherServlet - Initializing Servlet 'dispatcherServlet'
2025-04-21 17:28:54 [http-nio-8080-exec-1] INFO o.s.web.servlet.DispatcherServlet - Completed initialization in 0 ms
2025-04-21 17:28:54 [http-nio-8080-exec-1] INFO c.y.test.controller.MbtiController - 开始获取结果, ID: result_1744874809561
2025-04-21 17:28:54 [http-nio-8080-exec-1] DEBUG c.y.t.m.MbtiMapper.getResultById - ==> Preparing: SELECT id, type, dimensions, report, created_at as createdAt FROM results WHERE id = ?
2025-04-21 17:28:54 [http-nio-8080-exec-1] DEBUG c.y.t.m.MbtiMapper.getResultById - ==> Parameters: result_1744874809561(String)
2025-04-21 17:28:54 [http-nio-8080-exec-1] DEBUG c.y.t.m.MbtiMapper.getResultById - <== Total: 1
2025-04-21 17:28:54 [http-nio-8080-exec-1] INFO c.y.test.controller.MbtiController - 获取结果完成, ID: result_1744874809561, 总耗时: PT0.1893936S
2025-04-21 17:29:00 [http-nio-8080-exec-2] INFO c.y.test.controller.MbtiController - 开始获取结果, ID: result_1744874809561
2025-04-21 17:29:00 [http-nio-8080-exec-2] DEBUG c.y.t.m.MbtiMapper.getResultById - ==> Preparing: SELECT id, type, dimensions, report, created_at as createdAt FROM results WHERE id = ?
2025-04-21 17:29:00 [http-nio-8080-exec-2] DEBUG c.y.t.m.MbtiMapper.getResultById - ==> Parameters: result_1744874809561(String)
2025-04-21 17:29:01 [http-nio-8080-exec-2] DEBUG c.y.t.m.MbtiMapper.getResultById - <== Total: 1
2025-04-21 17:29:01 [http-nio-8080-exec-2] INFO c.y.test.controller.MbtiController - 获取结果完成, ID: result_1744874809561, 总耗时: PT0.1230948S
2025-04-21 17:29:13 [http-nio-8080-exec-4] INFO c.y.test.controller.MbtiController - 开始获取结果, ID: result_1744874809561
2025-04-21 17:29:13 [http-nio-8080-exec-4] DEBUG c.y.t.m.MbtiMapper.getResultById - ==> Preparing: SELECT id, type, dimensions, report, created_at as createdAt FROM results WHERE id = ?
2025-04-21 17:29:13 [http-nio-8080-exec-4] DEBUG c.y.t.m.MbtiMapper.getResultById - ==> Parameters: result_1744874809561(String)
2025-04-21 17:29:13 [http-nio-8080-exec-4] DEBUG c.y.t.m.MbtiMapper.getResultById - <== Total: 1
2025-04-21 17:29:13 [http-nio-8080-exec-4] INFO c.y.test.controller.MbtiController - 获取结果完成, ID: result_1744874809561, 总耗时: PT0.1314746S
2025-04-21 17:29:16 [http-nio-8080-exec-3] INFO c.y.test.controller.MbtiController - 开始获取结果, ID: result_1744874809561
2025-04-21 17:29:16 [http-nio-8080-exec-3] DEBUG c.y.t.m.MbtiMapper.getResultById - ==> Preparing: SELECT id, type, dimensions, report, created_at as createdAt FROM results WHERE id = ?
2025-04-21 17:29:16 [http-nio-8080-exec-3] DEBUG c.y.t.m.MbtiMapper.getResultById - ==> Parameters: result_1744874809561(String)
2025-04-21 17:29:16 [http-nio-8080-exec-3] DEBUG c.y.t.m.MbtiMapper.getResultById - <== Total: 1
2025-04-21 17:29:16 [http-nio-8080-exec-3] INFO c.y.test.controller.MbtiController - 获取结果完成, ID: result_1744874809561, 总耗时: PT0.0970814S
2025-04-21 17:29:40 [SpringApplicationShutdownHook] INFO o.s.b.w.e.tomcat.GracefulShutdown - Commencing graceful shutdown. Waiting for active requests to complete
2025-04-21 17:29:40 [tomcat-shutdown] INFO o.s.b.w.e.tomcat.GracefulShutdown - Graceful shutdown complete
2025-04-21 17:29:40 [SpringApplicationShutdownHook] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown initiated...
2025-04-21 17:29:40 [SpringApplicationShutdownHook] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Shutdown completed.

View File

@ -3,15 +3,19 @@ package com.yang.test.controller;
import com.yang.test.domain.DTO.ResultRequest;
import com.yang.test.domain.DTO.ResultResponse;
import com.yang.test.domain.QuestionH;
import com.yang.test.domain.Result;
import com.yang.test.service.HldzyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.Duration;
import java.time.Instant;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/api")
public class HldzyController {
@ -23,30 +27,41 @@ public class HldzyController {
* 获取所有测试题目
*/
@GetMapping("/questionsH")
public Map<String, Object> getAllQuestions() {
List<QuestionH> questions = hldzyService.getAllQuestions();
Collections.shuffle(questions); // 随机排序问题
public Result<?> getAllQuestions() {
Instant start = Instant.now();
log.info("开始获取所有题目");
Map<String, Object> response = new HashMap<>();
response.put("code", 0);
response.put("message", "success");
response.put("data", questions);
try {
List<QuestionH> questions = hldzyService.getAllQuestions();
Collections.shuffle(questions); // 随机排序问题
return response;
log.info("获取题目完成, 题目数量: {}, 总耗时: {}",
questions.size(), Duration.between(start, Instant.now()));
return Result.success(questions);
} catch (Exception e) {
log.error("获取题目失败: {}", e.getMessage(), e);
return Result.error("获取题目失败: " + e.getMessage());
}
}
/**
* 提交测试结果并获取分析
*/
@PostMapping("/results")
public Map<String, Object> submitResult(@RequestBody ResultRequest request) {
ResultResponse result = hldzyService.calculateResult(request.getAnswers());
public Result<?> submitResult(@RequestBody ResultRequest request) {
Instant start = Instant.now();
log.info("开始处理结果提交请求");
Map<String, Object> response = new HashMap<>();
response.put("code", 0);
response.put("message", "success");
response.put("data", result);
try {
ResultResponse result = hldzyService.calculateResult(request.getAnswers());
return response;
log.info("结果计算完成, 总耗时: {}", Duration.between(start, Instant.now()));
return Result.success(result);
} catch (Exception e) {
log.error("处理结果提交请求失败: {}", e.getMessage(), e);
return Result.error("处理请求失败: " + e.getMessage());
}
}
}

View File

@ -1,17 +1,15 @@
package com.yang.test.controller;
import com.yang.test.domain.Answer;
import com.yang.test.domain.VO.QuestionVO;
import com.yang.test.domain.VO.ResultVO;
import com.yang.test.domain.Result;
import com.yang.test.domain.VO.ResultMVO;
import com.yang.test.domain.VO.TestQuestionsVO;
import com.yang.test.service.MbtiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.Map;
@Slf4j
@ -23,60 +21,64 @@ public class MbtiController {
private MbtiService mbtiService;
@GetMapping("/questions")
public ResponseEntity<?> getQuestions(@RequestParam(value = "type", defaultValue = "simple") String testType) {
public Result<?> getQuestions(@RequestParam(value = "testId", defaultValue = "1") String testId) {
Instant start = Instant.now();
log.info("开始获取题目, 类型: {}", testType);
log.info("开始获取题目, 测试ID: {}", testId);
try {
List<QuestionVO> questions = mbtiService.getQuestions(testType);
TestQuestionsVO testQuestions = mbtiService.getTestQuestions(testId);
log.info("获取题目完成, 类型: {}, 题目数量: {}, 总耗时: {}",
testType, questions.size(), Duration.between(start, Instant.now()));
if (testQuestions == null) {
return Result.error("未找到相关测试或题目");
}
return ResponseEntity.ok(questions);
log.info("获取题目完成, 测试ID: {}, 题目数量: {}, 总耗时: {}",
testId, testQuestions.getList().size(), Duration.between(start, Instant.now()));
return Result.success(testQuestions);
} catch (Exception e) {
log.error("获取题目失败: {}", e.getMessage(), e);
return ResponseEntity.internalServerError().body(Map.of("error", "获取题目失败"));
return Result.error("获取题目失败: " + e.getMessage());
}
}
@PostMapping("/submit")
public ResponseEntity<?> submitAnswers(@RequestBody Answer answer,
@RequestParam(value = "type", defaultValue = "simple") String testType) {
public Result<?> submitAnswers(@RequestBody Map<String, Integer> answers,
@RequestParam(value = "testId", defaultValue = "1") String testId) {
Instant start = Instant.now();
log.info("开始处理答案提交请求");
try {
String resultId = mbtiService.processAnswers(answer.getAnswers(), testType);
String resultId = mbtiService.processAnswers(answers, testId);
log.info("答案提交处理完成, 结果ID: {}, 总耗时: {}",
resultId, Duration.between(start, Instant.now()));
return ResponseEntity.ok(Map.of("resultId", resultId));
return Result.success(Map.of("resultId", resultId));
} catch (Exception e) {
log.error("处理答案提交请求失败: {}", e.getMessage(), e);
return ResponseEntity.internalServerError().body(Map.of("error", "处理请求失败"));
return Result.error("处理请求失败: " + e.getMessage());
}
}
@GetMapping("/result/{id}")
public ResponseEntity<?> getResult(@PathVariable("id") String resultId) {
public Result<ResultMVO> getResult(@PathVariable("id") String resultId) {
Instant start = Instant.now();
log.info("开始获取结果, ID: {}", resultId);
try {
ResultVO result = mbtiService.getResult(resultId);
ResultMVO result = mbtiService.getResult(resultId);
if (result == null) {
return ResponseEntity.notFound().build();
return Result.error("未找到相关结果");
}
log.info("获取结果完成, ID: {}, 类型: {}, 总耗时: {}",
resultId, result.getType(), Duration.between(start, Instant.now()));
log.info("获取结果完成, ID: {}, 总耗时: {}",
resultId, Duration.between(start, Instant.now()));
return ResponseEntity.ok(result);
return Result.success(result);
} catch (Exception e) {
log.error("获取结果失败: {}", e.getMessage(), e);
return ResponseEntity.internalServerError().body(Map.of("error", "获取结果失败"));
return Result.error("获取结果失败: " + e.getMessage());
}
}
}

View File

@ -1,9 +0,0 @@
package com.yang.test.domain;
import lombok.Data;
import java.util.List;
@Data
public class Answer {
private List<Integer> answers;
}

View File

@ -1,8 +1,12 @@
package com.yang.test.domain;
import lombok.Data;
import java.util.Date;
/**
* Hldzy
*/
@Data
public class Category {
private Integer id;

View File

@ -3,6 +3,9 @@ package com.yang.test.domain.DTO;
import lombok.Data;
import java.util.Map;
/**
* Hldzy
*/
@Data
public class ResultRequest {
private Map<String, Integer> answers;

View File

@ -2,8 +2,12 @@ package com.yang.test.domain.DTO;
import com.yang.test.domain.Category;
import lombok.Data;
import java.util.Map;
/**
* Hldzy
*/
@Data
public class ResultResponse {
private String resultCode;

View File

@ -4,6 +4,9 @@ import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Mbti
*/
@Data
@NoArgsConstructor
@AllArgsConstructor

View File

@ -1,16 +0,0 @@
package com.yang.test.domain;
import lombok.Data;
import java.util.List;
import java.util.Date;
@Data
public class Question {
private Integer id;
private String question;
private String dimension;
private Integer direction;
private String type;
private Date createdAt;
private List<String> options;
}

View File

@ -3,6 +3,9 @@ package com.yang.test.domain;
import lombok.Data;
import java.util.Date;
/**
* Hldzy
*/
@Data
public class QuestionH {
private Long id;

View File

@ -4,8 +4,11 @@ import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* Mbti
*/
@Data
public class Result {
public class ResultM {
private String id;
private String type;
private List<Dimension> dimensions;

View File

@ -1,8 +1,12 @@
package com.yang.test.domain;
import lombok.Data;
import java.util.Date;
/**
* Hldzy
*/
@Data
public class TestResult {
private Long id;

View File

@ -1,13 +0,0 @@
package com.yang.test.domain.VO;
import lombok.Data;
import java.util.List;
@Data
public class QuestionVO {
private Integer id;
private String question;
private List<String> options;
private String dimension;
private Integer direction;
}

View File

@ -5,8 +5,11 @@ import com.yang.test.domain.Dimension;
import lombok.Data;
import java.util.List;
/**
* Mbti
*/
@Data
public class ResultVO {
public class ResultMVO {
private String id;
private String type;
private List<Dimension> dimensions;

View File

@ -1,41 +1,44 @@
package com.yang.test.mapper;
import com.yang.test.domain.Question;
import com.yang.test.domain.Result;
import com.yang.test.domain.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
@Mapper
public interface MbtiMapper {
/**
* 根据类型获取题目列表
* @param types 题目类型
* @return 题目列表
* 根据ID获取测试信息
*/
List<Question> getQuestionsByTypes(List<String> types);
Test getTestById(@Param("id") String id);
/**
* 获取题目的维度和方向信息
* @param types 题目类型
* @return 维度和方向信息列表
* 获取测试的所有问题
*/
List<Map<String, Object>> getQuestionDimensionsAndDirections(List<String> types);
List<Question> getQuestionsByTestId(@Param("testId") String testId);
/**
* 获取问题的所有选项
*/
List<Option> getOptionsByQuestionId(@Param("questionId") Integer questionId);
/**
* 获取问题的所有选项批量
*/
List<Option> getOptionsByQuestionIds(@Param("questionIds") List<Integer> questionIds);
/**
* 保存测试结果
* @param result 结果对象
* @return 影响的行数
*/
int saveResult(Result result);
int saveResult(ResultM result);
/**
* 根据ID获取结果
* @param resultId 结果ID
* @return 结果对象
*/
Result getResultById(String resultId);
ResultM getResultById(String resultId);
}

View File

@ -1,7 +1,7 @@
package com.yang.test.service;
import com.yang.test.domain.DTO.ResultResponse;
import com.yang.test.domain.Category;
import com.yang.test.domain.DTO.ResultResponse;
import com.yang.test.domain.QuestionH;
import com.yang.test.domain.TestResult;

View File

@ -1,43 +1,40 @@
package com.yang.test.service;
import com.yang.test.domain.VO.ResultMVO;
import com.yang.test.domain.VO.TestQuestionsVO;
import com.yang.test.domain.VO.QuestionVO;
import com.yang.test.domain.VO.ResultVO;
import java.util.List;
import java.util.Map;
public interface MbtiService {
/**
* 获取测试题目
* @param testType 测试类型
* @return 题目列表
*/
List<QuestionVO> getQuestions(String testType);
/**
* 处理用户提交的答案
* @param answers 用户答案
* @param testType 测试类型
* 获取测试和问题
* @param testId 测试ID
* @return 测试和问题信息
*/
TestQuestionsVO getTestQuestions(String testId);
/**
* 处理答案并生成结果
* @param answers 用户的答案
* @param testId 测试ID
* @return 结果ID
*/
String processAnswers(List<Integer> answers, String testType);
String processAnswers(Map<String, Integer> answers, String testId);
/**
* 获取测试结果
* @param resultId 结果ID
* @return 结果视图对象
*/
ResultVO getResult(String resultId);
ResultMVO getResult(String resultId);
/**
* 计算MBTI维度得分
* @param answers 用户答案
* @param testType 测试类型
* @return 维度得分映射
*/
Map<String, Double> calculateScores(List<Integer> answers, String testType);
Map<String, Double> calculateScores(Map<String, Integer> answers);
/**
* 根据得分确定MBTI类型

View File

@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yang.test.domain.Dimension;
import com.yang.test.service.DeepseekService;
import lombok.extern.slf4j.Slf4j;

View File

@ -1,15 +1,17 @@
package com.yang.test.service.serviceImpl;
import com.yang.test.mapper.HldzyMapper;
import com.yang.test.domain.DTO.ResultResponse;
import com.yang.test.domain.Category;
import com.yang.test.domain.DTO.ResultResponse;
import com.yang.test.domain.QuestionH;
import com.yang.test.domain.TestResult;
import com.yang.test.mapper.HldzyMapper;
import com.yang.test.service.HldzyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Service

View File

@ -1,21 +1,22 @@
package com.yang.test.service.serviceImpl;
import com.yang.test.mapper.MbtiMapper;
import com.yang.test.domain.Dimension;
import com.yang.test.domain.Question;
import com.yang.test.domain.Result;
import com.yang.test.domain.*;
import com.yang.test.domain.VO.QuestionVO;
import com.yang.test.domain.VO.ResultVO;
import com.yang.test.domain.VO.ResultMVO;
import com.yang.test.domain.VO.TestQuestionsVO;
import com.yang.test.mapper.MbtiMapper;
import com.yang.test.service.DeepseekService;
import com.yang.test.service.MbtiService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.Instant;
import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@Slf4j
@Service
@ -28,44 +29,55 @@ public class MbtiServiceImpl implements MbtiService {
private DeepseekService deepseekService;
@Override
public List<QuestionVO> getQuestions(String testType) {
List<String> types;
switch (testType) {
case "simple":
types = Collections.singletonList("simple");
break;
case "detailed":
types = Arrays.asList("simple", "detailed");
break;
case "full":
types = Arrays.asList("simple", "detailed", "full");
break;
default:
log.warn("无效的测试类型: {}, 使用simple类型", testType);
types = Collections.singletonList("simple");
public TestQuestionsVO getTestQuestions(String testId) {
// 获取测试信息
Test test = mbtiMapper.getTestById(testId);
if (test == null) {
return null;
}
List<Question> questions = mbtiMapper.getQuestionsByTypes(types);
List<QuestionVO> questionVOs = new ArrayList<>();
for (Question q : questions) {
QuestionVO vo = new QuestionVO();
vo.setId(q.getId());
vo.setQuestion(q.getQuestion());
vo.setDimension(q.getDimension());
vo.setDirection(q.getDirection());
// 设置7级量表选项
vo.setOptions(Arrays.asList("非常不符合", "不符合", "有点不符合", "中立", "有点符合", "符合", "非常符合"));
questionVOs.add(vo);
// 获取测试的所有问题
List<Question> questions = mbtiMapper.getQuestionsByTestId(testId);
if (questions == null || questions.isEmpty()) {
return null;
}
return questionVOs;
// 获取所有问题ID
List<Integer> questionIds = questions.stream()
.map(Question::getId)
.collect(Collectors.toList());
// 批量获取所有选项
List<Option> allOptions = mbtiMapper.getOptionsByQuestionIds(questionIds);
// 按问题ID对选项进行分组
Map<Integer, List<Option>> optionsByQuestionId = allOptions.stream()
.collect(Collectors.groupingBy(Option::getQuestionId));
// 构建返回结果
List<QuestionVO> questionVOList = new ArrayList<>();
for (Question question : questions) {
QuestionVO questionVO = new QuestionVO();
questionVO.setId(question.getId());
questionVO.setName(question.getName());
questionVO.setType(question.getType());
questionVO.setInfoname(test.getName());
questionVO.setOption(optionsByQuestionId.getOrDefault(question.getId(), new ArrayList<>()));
questionVOList.add(questionVO);
}
TestQuestionsVO result = new TestQuestionsVO();
result.setId(test.getId());
result.setName(test.getName());
result.setList(questionVOList);
return result;
}
@Override
public String processAnswers(List<Integer> answers, String testType) {
public String processAnswers(Map<String, Integer> answers, String testType) {
// 计算MBTI维度得分
Map<String, Double> scores = calculateScores(answers, testType);
Map<String, Double> scores = calculateScores(answers);
// 生成结果ID
String resultId = generateResultId();
@ -75,18 +87,13 @@ public class MbtiServiceImpl implements MbtiService {
log.info("计算得到MBTI类型: {}, 得分: {}", mbtiType, scores);
// 生成维度数据
List<Dimension> dimensions = Arrays.asList(
new Dimension("E", "I", Math.round(100 - scores.getOrDefault("EI", 0.0)), Math.round(scores.getOrDefault("EI", 0.0))),
new Dimension("S", "N", Math.round(100 - scores.getOrDefault("SN", 0.0)), Math.round(scores.getOrDefault("SN", 0.0))),
new Dimension("T", "F", Math.round(100 - scores.getOrDefault("TF", 0.0)), Math.round(scores.getOrDefault("TF", 0.0))),
new Dimension("J", "P", Math.round(100 - scores.getOrDefault("JP", 0.0)), Math.round(scores.getOrDefault("JP", 0.0)))
);
List<Dimension> dimensions = generateDimensions(answers);
// 生成个性化报告
String report = deepseekService.generateReport(mbtiType, dimensions);
// 创建结果对象
Result result = new Result();
ResultM result = new ResultM();
result.setId(resultId);
result.setType(mbtiType);
result.setDimensions(dimensions);
@ -101,136 +108,99 @@ public class MbtiServiceImpl implements MbtiService {
}
@Override
public ResultVO getResult(String resultId) {
Result result = mbtiMapper.getResultById(resultId);
public ResultMVO getResult(String resultId) {
ResultM result = mbtiMapper.getResultById(resultId);
if (result == null) {
return null;
}
// 转换为视图对象
ResultVO resultVO = new ResultVO();
resultVO.setId(result.getId());
resultVO.setType(result.getType());
resultVO.setDimensions(result.getDimensions());
resultVO.setReport(result.getReport());
ResultMVO resultMVO = new ResultMVO();
resultMVO.setId(result.getId());
resultMVO.setType(result.getType());
resultMVO.setDimensions(result.getDimensions());
resultMVO.setReport(result.getReport());
return resultVO;
return resultMVO;
}
// @Override
// public Object getResult(String resultId) {
// // 实现获取结果的逻辑
// return mbtiMapper.getResultById(resultId);
// }
/**
* 计算MBTI维度得分
*/
@Override
public Map<String, Double> calculateScores(List<Integer> answers, String testType) {
Map<String, Double> scores = new HashMap<>();
// 根据测试类型确定题目范围
List<String> types;
switch (testType) {
case "simple":
types = Collections.singletonList("simple");
break;
case "detailed":
types = Arrays.asList("simple", "detailed");
break;
case "full":
types = Arrays.asList("simple", "detailed", "full");
break;
default:
log.warn("无效的测试类型: {}", testType);
return scores;
}
// 查询题目信息
List<Map<String, Object>> questions = mbtiMapper.getQuestionDimensionsAndDirections(types);
// 计算每个维度的得分
Map<String, ScoreInfo> dimensionScores = new HashMap<>();
for (int i = 0; i < Math.min(answers.size(), questions.size()); i++) {
Map<String, Object> question = questions.get(i);
String dimension = (String) question.get("dimension");
int direction = ((Number) question.get("direction")).intValue();
// 确保答案在1-7的范围内
int answer = answers.get(i);
if (answer < 1) answer = 1;
if (answer > 7) answer = 7;
// 计算得分考虑题目方向
double score;
if (direction == 1) {
score = (answer - 1) * (100.0 / 6.0); // 正向题目将1-7线性映射到0-100
} else {
score = (7 - answer) * (100.0 / 6.0); // 反向题目将7-1线性映射到0-100
}
// 确保得分在0-100范围内
if (score < 0) score = 0;
if (score > 100) score = 100;
// 累加分数
ScoreInfo scoreInfo = dimensionScores.getOrDefault(dimension, new ScoreInfo());
scoreInfo.setTotal(scoreInfo.getTotal() + score);
scoreInfo.setCount(scoreInfo.getCount() + 1);
dimensionScores.put(dimension, scoreInfo);
}
// 计算每个维度的最终得分
for (Map.Entry<String, ScoreInfo> entry : dimensionScores.entrySet()) {
String dim = entry.getKey();
ScoreInfo info = entry.getValue();
if (info.getCount() > 0) {
// 计算平均分并确保在0-100范围内
double avgScore = info.getTotal() / info.getCount();
if (avgScore < 0) avgScore = 0;
if (avgScore > 100) avgScore = 100;
scores.put(dim, (double) Math.round(avgScore));
}
}
return scores;
public Map<String, Double> calculateScores(Map<String, Integer> answers) {
// 在此示例中我们直接将原始分数作为得分因为输入已经是每个维度的得分
return Map.of(
"E", (double) answers.getOrDefault("E", 0),
"I", (double) answers.getOrDefault("I", 0),
"S", (double) answers.getOrDefault("S", 0),
"N", (double) answers.getOrDefault("N", 0),
"T", (double) answers.getOrDefault("T", 0),
"F", (double) answers.getOrDefault("F", 0),
"J", (double) answers.getOrDefault("J", 0),
"P", (double) answers.getOrDefault("P", 0)
);
}
/**
* 根据得分确定MBTI类型
*/
@Override
public String determineMbtiType(Map<String, Double> scores) {
StringBuilder mbtiType = new StringBuilder();
String attitude = scores.get("E") >= scores.get("I") ? "E" : "I";
String perception = scores.get("S") >= scores.get("N") ? "S" : "N";
String judgment = scores.get("T") >= scores.get("F") ? "T" : "F";
String lifestyle = scores.get("J") >= scores.get("P") ? "J" : "P";
// 当分数等于50时默认选择第二个类型
if (scores.getOrDefault("EI", 0.0) >= 50) {
mbtiType.append("E");
} else {
mbtiType.append("I");
return attitude + perception + judgment + lifestyle;
}
/**
* 生成维度数据
*/
private static List<Dimension> generateDimensions(Map<String, Integer> scores) {
List<Dimension> dimensions = new ArrayList<>();
dimensions.add(normalizeDimension("E", "I", scores));
dimensions.add(normalizeDimension("S", "N", scores));
dimensions.add(normalizeDimension("T", "F", scores));
dimensions.add(normalizeDimension("J", "P", scores));
return dimensions;
}
/**
* 归一化并生成单个维度的数据
*/
private static Dimension normalizeDimension(String left, String right, Map<String, Integer> scores) {
int leftScore = scores.getOrDefault(left, 0);
int rightScore = scores.getOrDefault(right, 0);
double total = leftScore + rightScore;
long leftValue = Math.round((leftScore / total) * 100);
long rightValue = Math.round((rightScore / total) * 100);
// 确保总和为100
if (leftValue + rightValue != 100) {
if (leftValue > rightValue) {
leftValue = 100 - rightValue;
} else {
rightValue = 100 - leftValue;
}
}
if (scores.getOrDefault("SN", 0.0) >= 50) {
mbtiType.append("S");
} else {
mbtiType.append("N");
}
if (scores.getOrDefault("TF", 0.0) >= 50) {
mbtiType.append("T");
} else {
mbtiType.append("F");
}
if (scores.getOrDefault("JP", 0.0) >= 50) {
mbtiType.append("J");
} else {
mbtiType.append("P");
}
return mbtiType.toString();
return new Dimension(left, right, leftValue, rightValue);
}
private String generateResultId() {
return "result_" + Instant.now().toEpochMilli();
}
// 内部类用于存储每个维度的分数信息
@Data
private static class ScoreInfo {
private double total = 0;
private int count = 0;
}
}

View File

@ -1,36 +1,46 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yang.test.mapper.MbtiMapper">
<!-- 获取题目列表 -->
<select id="getQuestionsByTypes" resultType="com.yang.test.domain.Question">
SELECT id, question, dimension, direction, type, created_at as createdAt
FROM questions
WHERE type IN
<foreach item="item" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
<!-- 根据ID获取测试信息 -->
<select id="getTestById" resultType="com.yang.test.domain.Test">
SELECT id, name FROM test WHERE id = #{id}
</select>
<!-- 获取测试的所有问题 -->
<select id="getQuestionsByTestId" resultType="com.yang.test.domain.Question">
SELECT id, name, type, #{testId} as testId
FROM question
WHERE test_id = #{testId}
ORDER BY id
</select>
<!-- 获取题目的维度和方向信息 -->
<select id="getQuestionDimensionsAndDirections" resultType="java.util.Map">
SELECT id, dimension, direction
FROM questions
WHERE type IN
<foreach item="item" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
<!-- 获取问题的所有选项 -->
<select id="getOptionsByQuestionId" resultType="com.yang.test.domain.Option">
SELECT id, code, name, question_id as questionId, character_type as characterType
FROM option_table
WHERE question_id = #{questionId}
ORDER BY id
</select>
<!-- 获取问题的所有选项(批量) -->
<select id="getOptionsByQuestionIds" resultType="com.yang.test.domain.Option">
SELECT id, code, name, question_id as questionId, character_type as characterType
FROM option_table
WHERE question_id IN
<foreach item="id" collection="questionIds" open="(" separator="," close=")">
#{id}
</foreach>
ORDER BY question_id, id
</select>
<!-- 保存测试结果 -->
<insert id="saveResult" parameterType="com.yang.test.domain.Result">
<insert id="saveResult" parameterType="com.yang.test.domain.ResultM">
INSERT INTO results (id, type, dimensions, report, created_at)
VALUES (#{id}, #{type}, #{dimensions, typeHandler=com.yang.test.util.JsonTypeHandler}, #{report}, #{createdAt})
</insert>
<!-- 根据ID获取结果 -->
<select id="getResultById" resultType="com.yang.test.domain.Result">
<select id="getResultById" resultType="com.yang.test.domain.ResultM">
SELECT id, type, dimensions, report, created_at as createdAt
FROM results
WHERE id = #{resultId}