diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000000000000000000000000000000000000..2b63946d5b31084bbb7dda418ceb3d75eb686373 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index e595274ee56d42876c00fd71243b233aba24b5d6..b925ba38454791dbc1570b8362582eae25bbd552 100644 --- a/pom.xml +++ b/pom.xml @@ -101,6 +101,11 @@ commons-codec 1.15 + + org.redisson + redisson-spring-boot-starter + 3.23.4 + diff --git a/xfg-frame-archetype-lite-app/data/log/log-error-2024-11-13.0.log b/xfg-frame-archetype-lite-app/data/log/log-error-2024-11-13.0.log new file mode 100644 index 0000000000000000000000000000000000000000..e81127a602b97de770c7d519fec021737c8f73b8 --- /dev/null +++ b/xfg-frame-archetype-lite-app/data/log/log-error-2024-11-13.0.log @@ -0,0 +1,196 @@ +24-11-13.22:15:50.764 [main ] ERROR HikariPool - HikariPool-1 - Exception during pool initialization. +java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up. + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) + at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:906) + at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:831) + at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456) + at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) + at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) + at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) + at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) + at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) + at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) + at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) + at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115) + at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) + at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:159) + at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:117) + at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) + at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80) + at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67) + at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337) + at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86) + at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) + at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) + at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) + at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) + at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) + at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) + at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:498) + at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) + at com.sun.proxy.$Proxy79.selectList(Unknown Source) + at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) + at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) + at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) + at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152) + at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) + at com.sun.proxy.$Proxy82.queryAwardList(Unknown Source) + at cn.bugstack.test.infrastructure.AwardDaoTest.Test_queryAwardList(AwardDaoTest.java:31) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:498) + at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) + at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) + at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) + at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) + at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) + at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) + at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) + at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) + at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) + at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) + at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) + at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) + at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) + at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) + at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) + at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) + at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) + at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) + at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) + at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) + at org.junit.runners.ParentRunner.run(ParentRunner.java:413) + at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) + at org.junit.runner.JUnitCore.run(JUnitCore.java:137) + at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) + at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) + at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) + at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) + at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232) + at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55) +Caused by: com.mysql.cj.exceptions.CJException: Unknown database 'big_market' + at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) + at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) + at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) + at java.lang.reflect.Constructor.newInstance(Constructor.java:423) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:129) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:792) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:717) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:685) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:134) + at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:469) + at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:174) + at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1348) + at com.mysql.cj.NativeSession.connect(NativeSession.java:157) + at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:850) + ... 71 common frames omitted +24-11-13.22:17:02.261 [main ] ERROR HikariPool - HikariPool-1 - Exception during pool initialization. +java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up. + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) + at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:906) + at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:831) + at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456) + at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) + at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) + at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) + at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) + at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) + at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) + at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) + at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115) + at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) + at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:159) + at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:117) + at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) + at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80) + at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67) + at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337) + at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86) + at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) + at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) + at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) + at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) + at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) + at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) + at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:498) + at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) + at com.sun.proxy.$Proxy79.selectList(Unknown Source) + at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) + at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) + at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) + at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152) + at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) + at com.sun.proxy.$Proxy82.queryAwardList(Unknown Source) + at cn.bugstack.test.infrastructure.AwardDaoTest.Test_queryAwardList(AwardDaoTest.java:31) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:498) + at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) + at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) + at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) + at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) + at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) + at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) + at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) + at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) + at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) + at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) + at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) + at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) + at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) + at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) + at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) + at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) + at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) + at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) + at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) + at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) + at org.junit.runners.ParentRunner.run(ParentRunner.java:413) + at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) + at org.junit.runner.JUnitCore.run(JUnitCore.java:137) + at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) + at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) + at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) + at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) + at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232) + at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55) +Caused by: com.mysql.cj.exceptions.CJException: Unknown database 'big_market' + at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) + at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) + at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) + at java.lang.reflect.Constructor.newInstance(Constructor.java:423) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:129) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:792) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:717) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:685) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:134) + at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:469) + at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:174) + at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1348) + at com.mysql.cj.NativeSession.connect(NativeSession.java:157) + at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:850) + ... 71 common frames omitted diff --git a/xfg-frame-archetype-lite-app/data/log/log-info-2024-11-13.0.log b/xfg-frame-archetype-lite-app/data/log/log-info-2024-11-13.0.log new file mode 100644 index 0000000000000000000000000000000000000000..4bc6711edf1b90764de6c7540ef10907b3662d34 --- /dev/null +++ b/xfg-frame-archetype-lite-app/data/log/log-info-2024-11-13.0.log @@ -0,0 +1,221 @@ +24-11-13.21:47:44.554 [main ] INFO AwardDaoTest - Starting AwardDaoTest using Java 1.8.0_412 on zhaoyongfeng with PID 23628 (started by zhaoyongfeng in C:\Users\31126\Desktop\study\xfg-frame-archetype-lite\xfg-frame-archetype-lite-app) +24-11-13.21:47:44.556 [main ] INFO AwardDaoTest - The following 1 profile is active: "dev" +24-11-13.21:47:47.348 [main ] INFO AwardDaoTest - Started AwardDaoTest in 3.388 seconds (JVM running for 4.48) +24-11-13.22:01:33.005 [main ] INFO AwardDaoTest - Starting AwardDaoTest using Java 1.8.0_412 on zhaoyongfeng with PID 18680 (started by zhaoyongfeng in C:\Users\31126\Desktop\study\xfg-frame-archetype-lite\xfg-frame-archetype-lite-app) +24-11-13.22:01:33.006 [main ] INFO AwardDaoTest - The following 1 profile is active: "dev" +24-11-13.22:01:35.930 [main ] INFO AwardDaoTest - Started AwardDaoTest in 3.719 seconds (JVM running for 4.92) +24-11-13.22:02:30.137 [main ] INFO AwardDaoTest - Starting AwardDaoTest using Java 1.8.0_412 on zhaoyongfeng with PID 16484 (started by zhaoyongfeng in C:\Users\31126\Desktop\study\xfg-frame-archetype-lite\xfg-frame-archetype-lite-app) +24-11-13.22:02:30.138 [main ] INFO AwardDaoTest - The following 1 profile is active: "dev" +24-11-13.22:02:32.977 [main ] INFO AwardDaoTest - Started AwardDaoTest in 3.413 seconds (JVM running for 4.608) +24-11-13.22:15:40.573 [main ] INFO AwardDaoTest - Starting AwardDaoTest using Java 1.8.0_412 on zhaoyongfeng with PID 24008 (started by zhaoyongfeng in C:\Users\31126\Desktop\study\xfg-frame-archetype-lite\xfg-frame-archetype-lite-app) +24-11-13.22:15:40.574 [main ] INFO AwardDaoTest - The following 1 profile is active: "dev" +24-11-13.22:15:43.767 [main ] INFO AwardDaoTest - Started AwardDaoTest in 3.816 seconds (JVM running for 5.064) +24-11-13.22:15:44.065 [main ] INFO HikariDataSource - HikariPool-1 - Starting... +24-11-13.22:15:50.764 [main ] ERROR HikariPool - HikariPool-1 - Exception during pool initialization. +java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up. + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) + at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:906) + at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:831) + at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456) + at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) + at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) + at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) + at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) + at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) + at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) + at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) + at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115) + at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) + at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:159) + at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:117) + at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) + at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80) + at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67) + at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337) + at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86) + at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) + at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) + at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) + at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) + at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) + at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) + at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:498) + at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) + at com.sun.proxy.$Proxy79.selectList(Unknown Source) + at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) + at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) + at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) + at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152) + at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) + at com.sun.proxy.$Proxy82.queryAwardList(Unknown Source) + at cn.bugstack.test.infrastructure.AwardDaoTest.Test_queryAwardList(AwardDaoTest.java:31) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:498) + at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) + at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) + at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) + at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) + at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) + at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) + at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) + at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) + at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) + at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) + at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) + at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) + at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) + at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) + at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) + at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) + at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) + at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) + at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) + at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) + at org.junit.runners.ParentRunner.run(ParentRunner.java:413) + at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) + at org.junit.runner.JUnitCore.run(JUnitCore.java:137) + at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) + at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) + at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) + at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) + at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232) + at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55) +Caused by: com.mysql.cj.exceptions.CJException: Unknown database 'big_market' + at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) + at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) + at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) + at java.lang.reflect.Constructor.newInstance(Constructor.java:423) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:129) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:792) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:717) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:685) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:134) + at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:469) + at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:174) + at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1348) + at com.mysql.cj.NativeSession.connect(NativeSession.java:157) + at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:850) + ... 71 common frames omitted +24-11-13.22:16:52.152 [main ] INFO AwardDaoTest - Starting AwardDaoTest using Java 1.8.0_412 on zhaoyongfeng with PID 1908 (started by zhaoyongfeng in C:\Users\31126\Desktop\study\xfg-frame-archetype-lite\xfg-frame-archetype-lite-app) +24-11-13.22:16:52.154 [main ] INFO AwardDaoTest - The following 1 profile is active: "dev" +24-11-13.22:16:55.315 [main ] INFO AwardDaoTest - Started AwardDaoTest in 3.657 seconds (JVM running for 4.75) +24-11-13.22:16:55.597 [main ] INFO HikariDataSource - HikariPool-1 - Starting... +24-11-13.22:17:02.261 [main ] ERROR HikariPool - HikariPool-1 - Exception during pool initialization. +java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up. + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:110) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) + at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) + at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:906) + at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:831) + at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456) + at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) + at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198) + at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138) + at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:364) + at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:206) + at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:476) + at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:561) + at com.zaxxer.hikari.pool.HikariPool.(HikariPool.java:115) + at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) + at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:159) + at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:117) + at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80) + at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:80) + at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:67) + at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:337) + at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:86) + at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) + at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:325) + at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) + at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) + at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:89) + at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) + at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:140) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:498) + at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427) + at com.sun.proxy.$Proxy79.selectList(Unknown Source) + at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:224) + at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:147) + at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:80) + at org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:152) + at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) + at com.sun.proxy.$Proxy82.queryAwardList(Unknown Source) + at cn.bugstack.test.infrastructure.AwardDaoTest.Test_queryAwardList(AwardDaoTest.java:31) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:498) + at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) + at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) + at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) + at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) + at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74) + at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84) + at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) + at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) + at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) + at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) + at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251) + at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97) + at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) + at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) + at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) + at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) + at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) + at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) + at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) + at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) + at org.junit.runners.ParentRunner.run(ParentRunner.java:413) + at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190) + at org.junit.runner.JUnitCore.run(JUnitCore.java:137) + at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) + at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) + at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) + at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) + at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232) + at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55) +Caused by: com.mysql.cj.exceptions.CJException: Unknown database 'big_market' + at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) + at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) + at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) + at java.lang.reflect.Constructor.newInstance(Constructor.java:423) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:105) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:151) + at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:129) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:792) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:717) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:685) + at com.mysql.cj.protocol.a.NativeProtocol.checkErrorMessage(NativeProtocol.java:134) + at com.mysql.cj.protocol.a.NativeAuthenticationProvider.proceedHandshakeWithPluggableAuthentication(NativeAuthenticationProvider.java:469) + at com.mysql.cj.protocol.a.NativeAuthenticationProvider.connect(NativeAuthenticationProvider.java:174) + at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1348) + at com.mysql.cj.NativeSession.connect(NativeSession.java:157) + at com.mysql.cj.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:850) + ... 71 common frames omitted +24-11-13.22:18:23.243 [main ] INFO AwardDaoTest - Starting AwardDaoTest using Java 1.8.0_412 on zhaoyongfeng with PID 24192 (started by zhaoyongfeng in C:\Users\31126\Desktop\study\xfg-frame-archetype-lite\xfg-frame-archetype-lite-app) +24-11-13.22:18:23.244 [main ] INFO AwardDaoTest - The following 1 profile is active: "dev" +24-11-13.22:18:26.253 [main ] INFO AwardDaoTest - Started AwardDaoTest in 3.541 seconds (JVM running for 4.635) +24-11-13.22:18:26.501 [main ] INFO HikariDataSource - HikariPool-1 - Starting... +24-11-13.22:18:28.057 [main ] INFO HikariDataSource - HikariPool-1 - Start completed. +24-11-13.22:18:28.100 [main ] INFO AwardDaoTest - 测试结果:[Award(id=null, awardId=101, awardKey=user_credit_random, awardConfig=1,100, awardDesc=用户积分【优先透彻规则范围,如果没有则走配置】, createTime=null, updateTime=null), Award(id=null, awardId=102, awardKey=openai_use_count, awardConfig=5, awardDesc=OpenAI 增加使用次数, createTime=null, updateTime=null), Award(id=null, awardId=103, awardKey=openai_use_count, awardConfig=10, awardDesc=OpenAI 增加使用次数, createTime=null, updateTime=null), Award(id=null, awardId=104, awardKey=openai_use_count, awardConfig=20, awardDesc=OpenAI 增加使用次数, createTime=null, updateTime=null), Award(id=null, awardId=105, awardKey=openai_model, awardConfig=gpt-4, awardDesc=OpenAI 增加模型, createTime=null, updateTime=null), Award(id=null, awardId=106, awardKey=openai_model, awardConfig=dall-e-2, awardDesc=OpenAI 增加模型, createTime=null, updateTime=null), Award(id=null, awardId=107, awardKey=openai_model, awardConfig=dall-e-3, awardDesc=OpenAI 增加模型, createTime=null, updateTime=null), Award(id=null, awardId=108, awardKey=openai_use_count, awardConfig=100, awardDesc=OpenAI 增加使用次数, createTime=null, updateTime=null), Award(id=null, awardId=109, awardKey=openai_model, awardConfig=gpt-4,dall-e-2,dall-e-3, awardDesc=OpenAI 增加模型, createTime=null, updateTime=null), Award(id=null, awardId=100, awardKey=user_credit_blacklist, awardConfig=1, awardDesc=黑名单积分, createTime=null, updateTime=null)] +24-11-13.22:18:28.109 [SpringApplicationShutdownHook] INFO HikariDataSource - HikariPool-1 - Shutdown initiated... +24-11-13.22:18:28.113 [SpringApplicationShutdownHook] INFO HikariDataSource - HikariPool-1 - Shutdown completed. diff --git a/xfg-frame-archetype-lite-app/pom.xml b/xfg-frame-archetype-lite-app/pom.xml index e96799dfa530589136e1c1d144b2f095b8664144..a185abe55baedeff47e3f5a0ea812f99b6ebaf37 100644 --- a/xfg-frame-archetype-lite-app/pom.xml +++ b/xfg-frame-archetype-lite-app/pom.xml @@ -78,6 +78,10 @@ converter-gson 2.9.0 + + org.redisson + redisson-spring-boot-starter + diff --git a/xfg-frame-archetype-lite-app/src/main/java/cn/bugstack/config/RedisClientConfig.java b/xfg-frame-archetype-lite-app/src/main/java/cn/bugstack/config/RedisClientConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..dcda1b64a9bbfc41c5cece4fd33a8d6892c23822 --- /dev/null +++ b/xfg-frame-archetype-lite-app/src/main/java/cn/bugstack/config/RedisClientConfig.java @@ -0,0 +1,85 @@ +package cn.bugstack.config; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.serializer.SerializerFeature; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.ByteBufAllocator; +import io.netty.buffer.ByteBufInputStream; +import io.netty.buffer.ByteBufOutputStream; +import org.redisson.Redisson; +import org.redisson.api.RedissonClient; +import org.redisson.client.codec.BaseCodec; +import org.redisson.client.protocol.Decoder; +import org.redisson.client.protocol.Encoder; +import org.redisson.config.Config; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.io.IOException; + +/** + * @ClassName: RedisClientConfig + * @Description: + * @Author: zhaoyongfeng + * @Date: 2024/11/14 17:40 + */ +@Configuration +@EnableConfigurationProperties(RedisClientConfigProperties.class) +public class RedisClientConfig { + + @Bean("redissonClient") + public RedissonClient redissonClient(ConfigurableApplicationContext applicationContext, RedisClientConfigProperties properties) { + Config config = new Config(); + // 根据需要可以设定编解码器;https://github.com/redisson/redisson/wiki/4.-%E6%95%B0%E6%8D%AE%E5%BA%8F%E5%88%97%E5%8C%96 + // config.setCodec(new RedisCodec()); + + config.useSingleServer() + .setAddress("redis://" + properties.getHost() + ":" + properties.getPort()) +// .setPassword(properties.getPassword()) + .setConnectionPoolSize(properties.getPoolSize()) + .setConnectionMinimumIdleSize(properties.getMinIdleSize()) + .setIdleConnectionTimeout(properties.getIdleTimeout()) + .setConnectTimeout(properties.getConnectTimeout()) + .setRetryAttempts(properties.getRetryAttempts()) + .setRetryInterval(properties.getRetryInterval()) + .setPingConnectionInterval(properties.getPingInterval()) + .setKeepAlive(properties.isKeepAlive()) + ; + + return Redisson.create(config); + } + + static class RedisCodec extends BaseCodec { + + private final Encoder encoder = in -> { + ByteBuf out = ByteBufAllocator.DEFAULT.buffer(); + try { + ByteBufOutputStream os = new ByteBufOutputStream(out); + JSON.writeJSONString(os, in, SerializerFeature.WriteClassName); + return os.buffer(); + } catch (IOException e) { + out.release(); + throw e; + } catch (Exception e) { + out.release(); + throw new IOException(e); + } + }; + + private final Decoder decoder = (buf, state) -> JSON.parseObject(new ByteBufInputStream(buf), Object.class); + + @Override + public Decoder getValueDecoder() { + return decoder; + } + + @Override + public Encoder getValueEncoder() { + return encoder; + } + + } + +} + diff --git a/xfg-frame-archetype-lite-app/src/main/java/cn/bugstack/config/RedisClientConfigProperties.java b/xfg-frame-archetype-lite-app/src/main/java/cn/bugstack/config/RedisClientConfigProperties.java new file mode 100644 index 0000000000000000000000000000000000000000..f42933bad7d46e667d43d080daa2e115861d02e5 --- /dev/null +++ b/xfg-frame-archetype-lite-app/src/main/java/cn/bugstack/config/RedisClientConfigProperties.java @@ -0,0 +1,40 @@ +package cn.bugstack.config; + +import lombok.Data; +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * @ClassName: RedisClientConfigProperties + * @Description: + * @Author: zhaoyongfeng + * @Date: 2024/11/14 17:40 + */ +@Data +@ConfigurationProperties(prefix = "redis.sdk.config", ignoreInvalidFields = true) +public class RedisClientConfigProperties { + + /** host:ip */ + private String host; + /** 端口 */ + private int port; + /** 账密 */ + private String password; + /** 设置连接池的大小,默认为64 */ + private int poolSize = 64; + /** 设置连接池的最小空闲连接数,默认为10 */ + private int minIdleSize = 10; + /** 设置连接的最大空闲时间(单位:毫秒),超过该时间的空闲连接将被关闭,默认为10000 */ + private int idleTimeout = 10000; + /** 设置连接超时时间(单位:毫秒),默认为10000 */ + private int connectTimeout = 10000; + /** 设置连接重试次数,默认为3 */ + private int retryAttempts = 3; + /** 设置连接重试的间隔时间(单位:毫秒),默认为1000 */ + private int retryInterval = 1000; + /** 设置定期检查连接是否可用的时间间隔(单位:毫秒),默认为0,表示不进行定期检查 */ + private int pingInterval = 0; + /** 设置是否保持长连接,默认为true */ + private boolean keepAlive = true; + +} + diff --git a/xfg-frame-archetype-lite-app/src/main/resources/application-dev.yml b/xfg-frame-archetype-lite-app/src/main/resources/application-dev.yml index 335102e0c5fd37196780457ddb38888f4004e0f5..d23ad81b8288cb045b4ef82199c8fc9e42a98648 100644 --- a/xfg-frame-archetype-lite-app/src/main/resources/application-dev.yml +++ b/xfg-frame-archetype-lite-app/src/main/resources/application-dev.yml @@ -34,6 +34,21 @@ mybatis: mapper-locations: classpath:/mybatis/mapper/*.xml config-location: classpath:/mybatis/config/mybatis-config.xml +# Redis +redis: + sdk: + config: + host: 127.0.0.1 + port: 6379 + pool-size: 10 + min-idle-size: 5 + idle-timeout: 30000 + connect-timeout: 5000 + retry-attempts: 3 + retry-interval: 1000 + ping-interval: 60000 + keep-alive: true + # 日志 logging: level: diff --git a/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/award_mapper.xml b/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/award_mapper.xml index cd5f3712e1666313cd691ec914c6f599b8f81da3..408af6260a569311f61f8219429f7f00cba1c3ad 100644 --- a/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/award_mapper.xml +++ b/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/award_mapper.xml @@ -1,8 +1,8 @@ - + - + diff --git a/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_award_mapper.xml b/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_award_mapper.xml index e3f708cefc2f878c6a27cadb3ee7c2597d48fc97..29972809552d9a98500734193665da071fe55338 100644 --- a/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_award_mapper.xml +++ b/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_award_mapper.xml @@ -1,8 +1,8 @@ - + - + @@ -22,6 +22,11 @@ from strategy_award limit 10 + diff --git a/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_mapper.xml b/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_mapper.xml index 5c08ebdfbc2044f226023a6d597087033ed693bf..03af8bdc861dabf415593d0339713abdba3dbd35 100644 --- a/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_mapper.xml +++ b/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_mapper.xml @@ -1,8 +1,8 @@ - + - + diff --git a/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_rule_mapper.xml b/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_rule_mapper.xml index c1eb458eb266b28ac497b2b2a28e39de85365ed6..fe61a807cbdcf80877549d19de8a8477b6acb467 100644 --- a/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_rule_mapper.xml +++ b/xfg-frame-archetype-lite-app/src/main/resources/mybatis/mapper/strategy_rule_mapper.xml @@ -1,8 +1,8 @@ - + - + diff --git a/xfg-frame-archetype-lite-app/src/test/java/cn/bugstack/test/domain/StrategyArmoryTest.java b/xfg-frame-archetype-lite-app/src/test/java/cn/bugstack/test/domain/StrategyArmoryTest.java new file mode 100644 index 0000000000000000000000000000000000000000..ae682c440e1dae69b97740b0f988e6dc6f05c20e --- /dev/null +++ b/xfg-frame-archetype-lite-app/src/test/java/cn/bugstack/test/domain/StrategyArmoryTest.java @@ -0,0 +1,42 @@ +package cn.bugstack.test.domain; + +import cn.bugstack.domain.strategy.service.armory.IStrategyArmory; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import javax.annotation.Resource; + +/** + * @ClassName: StrategyArmoryTest + * @Description: + * @Author: zhaoyongfeng + * @Date: 2024/11/14 20:28 + */ +@SpringBootTest +@Slf4j +@RunWith(SpringRunner.class) +public class StrategyArmoryTest { + + @Resource + private IStrategyArmory strategyArmory; + @Test + public void test_strategyArmory(){ + strategyArmory.assembleLotteryStrategy(100002L); + } + + /** + * 从装配的策略中随机获取奖品ID值 + */ + @Test + public void test_getAssembleRandomVal() { + log.info("测试结果:{} - 奖品ID值", strategyArmory.getRandomAwardId(100002L)); + log.info("测试结果:{} - 奖品ID值", strategyArmory.getRandomAwardId(100002L)); + log.info("测试结果:{} - 奖品ID值", strategyArmory.getRandomAwardId(100002L)); + log.info("测试结果:{} - 奖品ID值", strategyArmory.getRandomAwardId(100002L)); + log.info("测试结果:{} - 奖品ID值", strategyArmory.getRandomAwardId(100002L)); + + } +} diff --git a/xfg-frame-archetype-lite-app/src/test/java/cn/bugstack/test/infrastructure/AwardDaoTest.java b/xfg-frame-archetype-lite-app/src/test/java/cn/bugstack/test/infrastructure/AwardDaoTest.java index d1d88c4bccbc8c125e7c97525a521e9793bfde18..00de8a65ef97393e764d2eb25d6d3106ae6369d3 100644 --- a/xfg-frame-archetype-lite-app/src/test/java/cn/bugstack/test/infrastructure/AwardDaoTest.java +++ b/xfg-frame-archetype-lite-app/src/test/java/cn/bugstack/test/infrastructure/AwardDaoTest.java @@ -1,7 +1,7 @@ package cn.bugstack.test.infrastructure; -import cn.bugstack.infrastructure.dao.IAwardDao; -import cn.bugstack.infrastructure.dao.po.Award; +import cn.bugstack.infrastructure.persistent.dao.IAwardDao; +import cn.bugstack.infrastructure.persistent.po.Award; import lombok.extern.slf4j.Slf4j; import org.junit.Test; diff --git a/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/AwardEntity.java b/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/AwardEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..34bd3a37e2bd42b2576387da2c9a453fa094de8a --- /dev/null +++ b/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/AwardEntity.java @@ -0,0 +1,27 @@ +package cn.bugstack.domain.strategy.model.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @ClassName: AwardEntity + * @Description: + * @Author: zhaoyongfeng + * @Date: 2024/11/14 19:37 + */ + +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class AwardEntity { + + /** 用户ID */ + private String userId; + /** 奖品ID */ + private Integer awardId; + +} + diff --git a/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/StrategyAwardEntity.java b/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/StrategyAwardEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..260d06b50addc1345cb5d1398f8fa81d70955f77 --- /dev/null +++ b/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/StrategyAwardEntity.java @@ -0,0 +1,32 @@ +package cn.bugstack.domain.strategy.model.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.math.BigDecimal; + +/** + * @ClassName: StrategyAwardEntity + * @Description: + * @Author: zhaoyongfeng + * @Date: 2024/11/14 19:32 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class StrategyAwardEntity { + /** 抽奖策略ID */ + private Long strategyId; + /** 抽奖奖品ID - 内部流转使用 */ + private Integer awardId; + /** 奖品库存总量 */ + private Integer awardCount; + /** 奖品库存剩余 */ + private Integer awardCountSurplus; + /** 奖品中奖概率 */ + private BigDecimal awardRate; + +} diff --git a/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/StrategyConditionEntity.java b/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/StrategyConditionEntity.java new file mode 100644 index 0000000000000000000000000000000000000000..1522557d4b30fcba366a793a1f1ddf8b7689f9aa --- /dev/null +++ b/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/model/entity/StrategyConditionEntity.java @@ -0,0 +1,24 @@ +package cn.bugstack.domain.strategy.model.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @ClassName: StrategyConditionEntity + * @Description: + * @Author: zhaoyongfeng + * @Date: 2024/11/14 19:37 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class StrategyConditionEntity { + /** 用户ID */ + private String userId; + /** 策略ID */ + private Integer strategyId; + +} diff --git a/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/repository/IStrategyRepository.java b/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/repository/IStrategyRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..1b19192b416ba08bcfe97023fe385b4d1a3e8ac0 --- /dev/null +++ b/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/repository/IStrategyRepository.java @@ -0,0 +1,17 @@ +package cn.bugstack.domain.strategy.repository; + +import cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity; + +import java.util.List; +import java.util.Map; + +public interface IStrategyRepository { + List queryStrategyAwardList(Long strategyId); + + void storeStrategyAwardSearchRateTable(Long strategyId, Integer rateRange, Map strategyAwardSearchRateTable); + + Integer getStrategyAwardAssemble(Long strategyId, Integer rateKey); + + int getRateRange(Long strategyId); + +} diff --git a/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/armory/IStrategyArmory.java b/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/armory/IStrategyArmory.java new file mode 100644 index 0000000000000000000000000000000000000000..18859a527809ba46ea9fdcf1ae833ca06639a92e --- /dev/null +++ b/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/armory/IStrategyArmory.java @@ -0,0 +1,21 @@ +package cn.bugstack.domain.strategy.service.armory; + +public interface IStrategyArmory { + + /** + * 装配抽奖策略配置「触发的时机可以为活动审核通过后进行调用」 + * + * @param strategyId 策略ID + * @return 装配结果 + */ + boolean assembleLotteryStrategy(Long strategyId); + + /** + * 获取抽奖策略装配的随机结果 + * + * @param strategyId 策略ID + * @return 抽奖结果 + */ + Integer getRandomAwardId(Long strategyId); + +} diff --git a/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/armory/StrategyArmory.java b/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/armory/StrategyArmory.java new file mode 100644 index 0000000000000000000000000000000000000000..6d91d707fe576780c969d76e8d8a6c4a65c1b901 --- /dev/null +++ b/xfg-frame-archetype-lite-domain/src/main/java/cn/bugstack/domain/strategy/service/armory/StrategyArmory.java @@ -0,0 +1,77 @@ +package cn.bugstack.domain.strategy.service.armory; + +import cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity; +import cn.bugstack.domain.strategy.repository.IStrategyRepository; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.security.SecureRandom; +import java.util.*; + +/** + * @ClassName: StrategyArmory + * @Description: 策略装配库(兵工厂),负责初始化策略计算 + * @Author: zhaoyongfeng + * @Date: 2024/11/14 17:39 + */ +@Slf4j +@Service +public class StrategyArmory implements IStrategyArmory{ + @Resource + private IStrategyRepository repository; + + @Override + public boolean assembleLotteryStrategy(Long strategyId) { + //1. 查询策略配置 + List strategyAwardEntities = repository.queryStrategyAwardList(strategyId); + // 获取最小概率值 + BigDecimal minAwardRate = strategyAwardEntities.stream() + .map(StrategyAwardEntity::getAwardRate) + .min(BigDecimal::compareTo) + .orElse(BigDecimal.ZERO); + + // 3. 获取概率值总和 + BigDecimal totalAwardRate = strategyAwardEntities.stream() + .map(StrategyAwardEntity::getAwardRate) + .reduce(BigDecimal.ZERO, BigDecimal::add); +//TODO 需要修改问题 + // 4. 用 1 % 0.0001 获得概率范围,百分位、千分位、万分位 + BigDecimal rateRange = totalAwardRate.divide(minAwardRate, 0, RoundingMode.CEILING); + // 5. 生成策略奖品概率查找表「这里指需要在list集合中,存放上对应的奖品占位即可,占位越多等于概率越高」 + + ArrayList strategyAwardSearchRateTables = new ArrayList<>(rateRange.intValue()); + for(StrategyAwardEntity strategyAward: strategyAwardEntities){ + Integer awardId = strategyAward.getAwardId(); + BigDecimal awardRate = strategyAward.getAwardRate(); + // 计算出每个概率值需要存放到查找表的数量,循环填充 + for (int i = 0; i < rateRange.multiply(awardRate).setScale(0, RoundingMode.CEILING).intValue(); i++) { + strategyAwardSearchRateTables.add(awardId); + } + + } + // 6. 对存储的奖品进行乱序操作 + Collections.shuffle(strategyAwardSearchRateTables); + // 7. 生成出Map集合,key值,对应的就是后续的概率值。通过概率来获得对应的奖品ID + Map shuffleStrategyAwardSearchRateTable = new LinkedHashMap<>(); + for (int i = 0; i < strategyAwardSearchRateTables.size(); i++) { + shuffleStrategyAwardSearchRateTable.put(i, strategyAwardSearchRateTables.get(i)); + } + // 8. 存放到 Redis + repository.storeStrategyAwardSearchRateTable(strategyId, shuffleStrategyAwardSearchRateTable.size(), shuffleStrategyAwardSearchRateTable); + + return true; + + } + + @Override + public Integer getRandomAwardId(Long strategyId) { + // 分布式部署下,不一定为当前应用做的策略装配。也就是值不一定会保存到本应用,而是分布式应用,所以需要从 Redis 中获取。 + int rateRange = repository.getRateRange(strategyId); + // 通过生成的随机值,获取概率值奖品查找表的结果 + return repository.getStrategyAwardAssemble(strategyId, new SecureRandom().nextInt(rateRange)); + } + +} diff --git a/xfg-frame-archetype-lite-infrastructure/pom.xml b/xfg-frame-archetype-lite-infrastructure/pom.xml index 2bb0475805526ef6a7f55d6b32a067a5e174bfc9..6801b012da0045b48bc253ebd914bbda8e71917a 100644 --- a/xfg-frame-archetype-lite-infrastructure/pom.xml +++ b/xfg-frame-archetype-lite-infrastructure/pom.xml @@ -18,6 +18,10 @@ org.projectlombok lombok + + org.redisson + redisson-spring-boot-starter + cn.bugstack diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/IStrategyAwardDao.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/IStrategyAwardDao.java deleted file mode 100644 index 0f789cfd7411bd9c266068fe4398c5c9a456f992..0000000000000000000000000000000000000000 --- a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/IStrategyAwardDao.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.bugstack.infrastructure.dao; - -import cn.bugstack.infrastructure.dao.po.Award; -import org.apache.ibatis.annotations.Mapper; - -import java.util.List; -@Mapper -public interface IStrategyAwardDao { - List queryStrategyAwardList(); -} diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/IAwardDao.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IAwardDao.java similarity index 57% rename from xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/IAwardDao.java rename to xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IAwardDao.java index eaa99da0fa1c4144076b9afe3d6e5c477b86bfda..6e0ed3aea0ed5a2d26f3336138732787d9cd065d 100644 --- a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/IAwardDao.java +++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IAwardDao.java @@ -1,6 +1,6 @@ -package cn.bugstack.infrastructure.dao; +package cn.bugstack.infrastructure.persistent.dao; -import cn.bugstack.infrastructure.dao.po.Award; +import cn.bugstack.infrastructure.persistent.po.Award; import org.apache.ibatis.annotations.Mapper; import java.util.List; diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IStrategyAwardDao.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IStrategyAwardDao.java new file mode 100644 index 0000000000000000000000000000000000000000..fdac7c4e0af95a16cf81df748a1394159c0fb67e --- /dev/null +++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IStrategyAwardDao.java @@ -0,0 +1,15 @@ +package cn.bugstack.infrastructure.persistent.dao; + +import cn.bugstack.infrastructure.persistent.po.Award; +import cn.bugstack.infrastructure.persistent.po.StrategyAward; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; +@Mapper +public interface IStrategyAwardDao { + List queryStrategyAwardList(); + + List queryStrategyAwardListByStrategyId(Long strategyId); + + +} diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/IStrategyDao.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IStrategyDao.java similarity index 58% rename from xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/IStrategyDao.java rename to xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IStrategyDao.java index 16951c7a01779a703a1c889fc441e77f80b34d3b..8540ee6c8f63ec6f7a5a75038999ba2925f8f3c3 100644 --- a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/IStrategyDao.java +++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IStrategyDao.java @@ -1,6 +1,6 @@ -package cn.bugstack.infrastructure.dao; +package cn.bugstack.infrastructure.persistent.dao; -import cn.bugstack.infrastructure.dao.po.Award; +import cn.bugstack.infrastructure.persistent.po.Award; import org.apache.ibatis.annotations.Mapper; import java.util.List; diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/IStrategyRuleDao.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IStrategyRuleDao.java similarity index 59% rename from xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/IStrategyRuleDao.java rename to xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IStrategyRuleDao.java index 6fd666496225c8e872cff7c46dfb29180efd1ad5..83d301e189dc8cc95d6cf7c4f8683b1fa561c641 100644 --- a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/IStrategyRuleDao.java +++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/dao/IStrategyRuleDao.java @@ -1,6 +1,6 @@ -package cn.bugstack.infrastructure.dao; +package cn.bugstack.infrastructure.persistent.dao; -import cn.bugstack.infrastructure.dao.po.Award; +import cn.bugstack.infrastructure.persistent.po.Award; import org.apache.ibatis.annotations.Mapper; import java.util.List; diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/po/Award.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/po/Award.java similarity index 92% rename from xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/po/Award.java rename to xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/po/Award.java index 141591af43b4aea5f166184d5e14dd38e5bbf58f..d238ca2d1c7248265d8c1a1f0835187e57583cd4 100644 --- a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/po/Award.java +++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/po/Award.java @@ -1,4 +1,4 @@ -package cn.bugstack.infrastructure.dao.po; +package cn.bugstack.infrastructure.persistent.po; import lombok.Data; diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/po/Strategy.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/po/Strategy.java similarity index 89% rename from xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/po/Strategy.java rename to xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/po/Strategy.java index 0747197957028409f01c8e5096ebf95217b147f6..f2163fad21d2613352eb84eec8879be4ca0008fc 100644 --- a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/po/Strategy.java +++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/po/Strategy.java @@ -1,4 +1,4 @@ -package cn.bugstack.infrastructure.dao.po; +package cn.bugstack.infrastructure.persistent.po; import lombok.Data; diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/po/StrategyAward.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/po/StrategyAward.java similarity index 95% rename from xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/po/StrategyAward.java rename to xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/po/StrategyAward.java index f4557a861be90e6351c94d1c04287f78b518a384..83a085fb48983f44c37908062f744f80622cb719 100644 --- a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/po/StrategyAward.java +++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/po/StrategyAward.java @@ -1,4 +1,4 @@ -package cn.bugstack.infrastructure.dao.po; +package cn.bugstack.infrastructure.persistent.po; import lombok.Data; diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/po/StrategyRule.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/po/StrategyRule.java similarity index 94% rename from xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/po/StrategyRule.java rename to xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/po/StrategyRule.java index 64832220f5a8078062e5f72002e7d1171b653cbf..1fa5c7e6bf369695a20204161e472bd5ca648a0f 100644 --- a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/dao/po/StrategyRule.java +++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/po/StrategyRule.java @@ -1,4 +1,4 @@ -package cn.bugstack.infrastructure.dao.po; +package cn.bugstack.infrastructure.persistent.po; import lombok.Data; diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/redis/IRedisService.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/redis/IRedisService.java new file mode 100644 index 0000000000000000000000000000000000000000..ccc5a59c8aaef86298edb31ec4adbfb14c55452e --- /dev/null +++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/redis/IRedisService.java @@ -0,0 +1,251 @@ +package cn.bugstack.infrastructure.persistent.redis; + +import org.redisson.api.*; + +/* + * @return + * @author zhaoyongfeng + * @description + * Redis服务 + * @param null + */ +public interface IRedisService { + + /** + * 设置指定 key 的值 + * + * @param key 键 + * @param value 值 + */ + void setValue(String key, T value); + + /** + * 设置指定 key 的值 + * + * @param key 键 + * @param value 值 + * @param expired 过期时间 + */ + void setValue(String key, T value, long expired); + + /** + * 获取指定 key 的值 + * + * @param key 键 + * @return 值 + */ + T getValue(String key); + + /** + * 获取队列 + * + * @param key 键 + * @param 泛型 + * @return 队列 + */ + RQueue getQueue(String key); + + /** + * 加锁队列 + * + * @param key 键 + * @param 泛型 + * @return 队列 + */ + RBlockingQueue getBlockingQueue(String key); + + /** + * 延迟队列 + * + * @param rBlockingQueue 加锁队列 + * @param 泛型 + * @return 队列 + */ + RDelayedQueue getDelayedQueue(RBlockingQueue rBlockingQueue); + + /** + * 自增 Key 的值;1、2、3、4 + * + * @param key 键 + * @return 自增后的值 + */ + long incr(String key); + + /** + * 指定值,自增 Key 的值;1、2、3、4 + * + * @param key 键 + * @return 自增后的值 + */ + long incrBy(String key, long delta); + + /** + * 自减 Key 的值;1、2、3、4 + * + * @param key 键 + * @return 自增后的值 + */ + long decr(String key); + + /** + * 指定值,自增 Key 的值;1、2、3、4 + * + * @param key 键 + * @return 自增后的值 + */ + long decrBy(String key, long delta); + + + /** + * 移除指定 key 的值 + * + * @param key 键 + */ + void remove(String key); + + /** + * 判断指定 key 的值是否存在 + * + * @param key 键 + * @return true/false + */ + boolean isExists(String key); + + /** + * 将指定的值添加到集合中 + * + * @param key 键 + * @param value 值 + */ + void addToSet(String key, String value); + + /** + * 判断指定的值是否是集合的成员 + * + * @param key 键 + * @param value 值 + * @return 如果是集合的成员返回 true,否则返回 false + */ + boolean isSetMember(String key, String value); + + /** + * 将指定的值添加到列表中 + * + * @param key 键 + * @param value 值 + */ + void addToList(String key, String value); + + /** + * 获取列表中指定索引的值 + * + * @param key 键 + * @param index 索引 + * @return 值 + */ + String getFromList(String key, int index); + + /** + * 获取Map + * + * @param key 键 + * @return 值 + */ + RMap getMap(String key); + + /** + * 将指定的键值对添加到哈希表中 + * + * @param key 键 + * @param field 字段 + * @param value 值 + */ + void addToMap(String key, String field, String value); + + /** + * 获取哈希表中指定字段的值 + * + * @param key 键 + * @param field 字段 + * @return 值 + */ + String getFromMap(String key, String field); + + /** + * 获取哈希表中指定字段的值 + * + * @param key 键 + * @param field 字段 + * @return 值 + */ + V getFromMap(String key, K field); + + /** + * 将指定的值添加到有序集合中 + * + * @param key 键 + * @param value 值 + */ + void addToSortedSet(String key, String value); + + /** + * 获取 Redis 锁(可重入锁) + * + * @param key 键 + * @return Lock + */ + RLock getLock(String key); + + /** + * 获取 Redis 锁(公平锁) + * + * @param key 键 + * @return Lock + */ + RLock getFairLock(String key); + + /** + * 获取 Redis 锁(读写锁) + * + * @param key 键 + * @return RReadWriteLock + */ + RReadWriteLock getReadWriteLock(String key); + + /** + * 获取 Redis 信号量 + * + * @param key 键 + * @return RSemaphore + */ + RSemaphore getSemaphore(String key); + + /** + * 获取 Redis 过期信号量 + *

+ * 基于Redis的Redisson的分布式信号量(Semaphore)Java对象RSemaphore采用了与java.util.concurrent.Semaphore相似的接口和用法。 + * 同时还提供了异步(Async)、反射式(Reactive)和RxJava2标准的接口。 + * + * @param key 键 + * @return RPermitExpirableSemaphore + */ + RPermitExpirableSemaphore getPermitExpirableSemaphore(String key); + + /** + * 闭锁 + * + * @param key 键 + * @return RCountDownLatch + */ + RCountDownLatch getCountDownLatch(String key); + + /** + * 布隆过滤器 + * + * @param key 键 + * @param 存放对象 + * @return 返回结果 + */ + RBloomFilter getBloomFilter(String key); + +} diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/redis/RedissonService.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/redis/RedissonService.java new file mode 100644 index 0000000000000000000000000000000000000000..f1a31ca9d649c0db51c4fb4fa7d52e0aa0f27e80 --- /dev/null +++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/redis/RedissonService.java @@ -0,0 +1,161 @@ +package cn.bugstack.infrastructure.persistent.redis; + +import org.redisson.api.*; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.time.Duration; + +/** + * @ClassName: RedissonService + * @Description: + * @Author: zhaoyongfeng + * @Date: 2024/11/14 17:49 + */ +@Service("redissonService") +public class RedissonService implements IRedisService { + + @Resource + private RedissonClient redissonClient; + + public void setValue(String key, T value) { + redissonClient.getBucket(key).set(value); + } + + @Override + public void setValue(String key, T value, long expired) { + RBucket bucket = redissonClient.getBucket(key); + bucket.set(value, Duration.ofMillis(expired)); + } + + public T getValue(String key) { + return redissonClient.getBucket(key).get(); + } + + @Override + public RQueue getQueue(String key) { + return redissonClient.getQueue(key); + } + + @Override + public RBlockingQueue getBlockingQueue(String key) { + return redissonClient.getBlockingQueue(key); + } + + @Override + public RDelayedQueue getDelayedQueue(RBlockingQueue rBlockingQueue) { + return redissonClient.getDelayedQueue(rBlockingQueue); + } + + @Override + public long incr(String key) { + return redissonClient.getAtomicLong(key).incrementAndGet(); + } + + @Override + public long incrBy(String key, long delta) { + return redissonClient.getAtomicLong(key).addAndGet(delta); + } + + @Override + public long decr(String key) { + return redissonClient.getAtomicLong(key).decrementAndGet(); + } + + @Override + public long decrBy(String key, long delta) { + return redissonClient.getAtomicLong(key).addAndGet(-delta); + } + + @Override + public void remove(String key) { + redissonClient.getBucket(key).delete(); + } + + @Override + public boolean isExists(String key) { + return redissonClient.getBucket(key).isExists(); + } + + public void addToSet(String key, String value) { + RSet set = redissonClient.getSet(key); + set.add(value); + } + + public boolean isSetMember(String key, String value) { + RSet set = redissonClient.getSet(key); + return set.contains(value); + } + + public void addToList(String key, String value) { + RList list = redissonClient.getList(key); + list.add(value); + } + + public String getFromList(String key, int index) { + RList list = redissonClient.getList(key); + return list.get(index); + } + + @Override + public RMap getMap(String key) { + return redissonClient.getMap(key); + } + + public void addToMap(String key, String field, String value) { + RMap map = redissonClient.getMap(key); + map.put(field, value); + } + + public String getFromMap(String key, String field) { + RMap map = redissonClient.getMap(key); + return map.get(field); + } + + @Override + public V getFromMap(String key, K field) { + return redissonClient.getMap(key).get(field); + } + + public void addToSortedSet(String key, String value) { + RSortedSet sortedSet = redissonClient.getSortedSet(key); + sortedSet.add(value); + } + + @Override + public RLock getLock(String key) { + return redissonClient.getLock(key); + } + + @Override + public RLock getFairLock(String key) { + return redissonClient.getFairLock(key); + } + + @Override + public RReadWriteLock getReadWriteLock(String key) { + return redissonClient.getReadWriteLock(key); + } + + @Override + public RSemaphore getSemaphore(String key) { + return redissonClient.getSemaphore(key); + } + + @Override + public RPermitExpirableSemaphore getPermitExpirableSemaphore(String key) { + return redissonClient.getPermitExpirableSemaphore(key); + } + + @Override + public RCountDownLatch getCountDownLatch(String key) { + return redissonClient.getCountDownLatch(key); + } + + @Override + public RBloomFilter getBloomFilter(String key) { + return redissonClient.getBloomFilter(key); + } + + +} diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/repository/StrategyRepository.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/repository/StrategyRepository.java new file mode 100644 index 0000000000000000000000000000000000000000..5c2355f6594c9c26e72575e5a7a8920b425174e4 --- /dev/null +++ b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/persistent/repository/StrategyRepository.java @@ -0,0 +1,76 @@ +package cn.bugstack.infrastructure.persistent.repository; + + +import cn.bugstack.domain.strategy.model.entity.StrategyAwardEntity; +import cn.bugstack.domain.strategy.repository.IStrategyRepository; +import cn.bugstack.infrastructure.persistent.dao.IStrategyAwardDao; +import cn.bugstack.infrastructure.persistent.po.StrategyAward; +import cn.bugstack.infrastructure.persistent.redis.IRedisService; +import cn.bugstack.types.common.Constants; +import org.springframework.stereotype.Repository; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + + +/** + * @ClassName: StrategyRepository + * @Description: 策略服务仓储实现 + * @Author: zhaoyongfeng + * @Date: 2024/11/14 19:27 + */ +@Repository +public class StrategyRepository implements IStrategyRepository { + + @Resource + private IStrategyAwardDao strategyAwardDao; + @Resource + private IRedisService redisService; + + @Override + public List queryStrategyAwardList(Long strategyId) { + // 优先从缓存获取 + String cacheKey = Constants.RedisKey.STRATEGY_AWARD_KEY + strategyId; + List strategyAwardEntities = redisService.getValue(cacheKey); + if (null != strategyAwardEntities && !strategyAwardEntities.isEmpty()) return strategyAwardEntities; + // 从库中获取数据 + List strategyAwards = strategyAwardDao.queryStrategyAwardListByStrategyId(strategyId); + strategyAwardEntities = new ArrayList<>(strategyAwards.size()); + for (StrategyAward strategyAward : strategyAwards) { + StrategyAwardEntity strategyAwardEntity = StrategyAwardEntity.builder() + .strategyId(strategyAward.getStrategyId()) + .awardId(strategyAward.getAwardId()) + .awardCount(strategyAward.getAwardCount()) + .awardCountSurplus(strategyAward.getAwardCountSurplus()) + .awardRate(strategyAward.getAwardRate()) + .build(); + strategyAwardEntities.add(strategyAwardEntity); + } + redisService.setValue(cacheKey, strategyAwardEntities); + return strategyAwardEntities; + } + + @Override + public void storeStrategyAwardSearchRateTable(Long strategyId, Integer rateRange, Map strategyAwardSearchRateTable) { + // 1. 存储抽奖策略范围值,如10000,用于生成1000以内的随机数 + redisService.setValue(Constants.RedisKey.STRATEGY_RATE_RANGE_KEY + strategyId, rateRange); + // 2. 存储概率查找表 + Map cacheRateTable = redisService.getMap(Constants.RedisKey.STRATEGY_RATE_TABLE_KEY + strategyId); + cacheRateTable.putAll(strategyAwardSearchRateTable); + + } + + @Override + public Integer getStrategyAwardAssemble(Long strategyId, Integer rateKey) { + return redisService.getFromMap(Constants.RedisKey.STRATEGY_RATE_TABLE_KEY + strategyId, rateKey); + } + + @Override + public int getRateRange(Long strategyId) { + return redisService.getValue(Constants.RedisKey.STRATEGY_RATE_RANGE_KEY + strategyId); + } + +} + diff --git a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/redis/package-info.java b/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/redis/package-info.java deleted file mode 100644 index 6c4af599f36b3ce3e4b4b9dd56a530470f9f1270..0000000000000000000000000000000000000000 --- a/xfg-frame-archetype-lite-infrastructure/src/main/java/cn/bugstack/infrastructure/redis/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * 提供redis链接配置 - */ -package cn.bugstack.infrastructure.redis; \ No newline at end of file diff --git a/xfg-frame-archetype-lite-types/src/main/java/cn/bugstack/types/common/Constants.java b/xfg-frame-archetype-lite-types/src/main/java/cn/bugstack/types/common/Constants.java index 3e21a0d11d286581ba84b5545c78411809a745e9..008bc32b0ba0ae1a280531c7528f15fd4107ef46 100644 --- a/xfg-frame-archetype-lite-types/src/main/java/cn/bugstack/types/common/Constants.java +++ b/xfg-frame-archetype-lite-types/src/main/java/cn/bugstack/types/common/Constants.java @@ -4,4 +4,11 @@ public class Constants { public final static String SPLIT = ","; + public static class RedisKey { + public static String STRATEGY_AWARD_KEY = "big_market_strategy_award_key_"; + public static String STRATEGY_RATE_TABLE_KEY = "big_market_strategy_rate_table_key_"; + public static String STRATEGY_RATE_RANGE_KEY = "big_market_strategy_rate_range_key_"; + } + + }