Parcourir la source

优化数据库

lighter il y a 3 ans
Parent
commit
175bfa3190

+ 7 - 11
pom.xml

@@ -10,7 +10,7 @@
     </parent>
     <groupId>thyyxxk</groupId>
     <artifactId>wxservice-server</artifactId>
-    <version>7.2</version>
+    <version>7.3</version>
     <name>wxservice-server</name>
     <description>server for wxservice-web</description>
 
@@ -45,22 +45,18 @@
         <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-jdbc</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.apache.tomcat</groupId>
-                    <artifactId>tomcat-jdbc</artifactId>
-                </exclusion>
-            </exclusions>
         </dependency>
+        <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc -->
         <dependency>
             <groupId>com.microsoft.sqlserver</groupId>
             <artifactId>mssql-jdbc</artifactId>
-            <scope>runtime</scope>
+            <version>7.4.1.jre8</version>
         </dependency>
+        <!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
         <dependency>
-            <groupId>com.alibaba</groupId>
-            <artifactId>druid</artifactId>
-            <version>1.2.8</version>
+            <groupId>com.zaxxer</groupId>
+            <artifactId>HikariCP</artifactId>
+            <version>3.3.1</version>
         </dependency>
         <dependency>
             <groupId>org.projectlombok</groupId>

+ 0 - 2
src/main/java/thyyxxk/wxservice_server/WxserviceServerApplication.java

@@ -5,13 +5,11 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.retry.annotation.EnableRetry;
 import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.transaction.annotation.EnableTransactionManagement;
 import thyyxxk.wxservice_server.utils.PropertiesUtil;
 
 /**
  * @author dj
  */
-@EnableTransactionManagement
 @EnableRetry
 @EnableScheduling
 @SpringBootApplication

+ 3 - 3
src/main/java/thyyxxk/wxservice_server/dao/WxApiDao.java

@@ -50,7 +50,7 @@ public interface WxApiDao {
             "his_status=0,refund_op_datetime=getdate() where trade_no=#{tradeNo}")
     void refundOrder(@Param("tradeNo") String tradeNo, @Param("rea") String rea);
 
-    @Update("update t_wechat_pay_order set his_status=1 where trade_no=#{tradeNo}")
+    @Update("update t_wechat_pay_order set his_status=1,pay_status=1 where trade_no=#{tradeNo}")
     void updateSuccessHisStatus(@Param("tradeNo") String tradeNo);
 
     @Update("update t_wechat_pay_order set open_id=#{openId} where trade_no=#{tradeNo}")
@@ -60,9 +60,9 @@ public interface WxApiDao {
     @Select("select * from t_wechat_pay_order with(nolock) where trade_no=#{tradeNo}")
     WxPayOrder selectOrderByTradeNo(@Param("tradeNo") String tradeNo);
 
-    @Select("select trade_no, query_state_times from t_wechat_pay_order with(nolock) where his_status=0 " +
+    @Select("select trade_no, query_state_times from t_wechat_pay_order with(nolock) where his_status=#{status} " +
             "and order_type<=3 and pay_status in (99, 0, 5, 6, 100) ")
-    List<TradeNo> selectTradeNosForScheduleTask();
+    List<TradeNo> selectTradeNosForScheduleTask(@Param("status") int status);
 
     @Select("select open_id from t_wechat_patient_bind with(nolock) where patient_id=#{cardNo} and del_flag=0")
     List<String> selectOpenIdByPatientId(@Param("cardNo") String cardNo);

+ 1 - 1
src/main/java/thyyxxk/wxservice_server/scheduled/QueryOrderStateTask.java

@@ -51,7 +51,7 @@ public class QueryOrderStateTask {
     @Scheduled(fixedRate = 180 * 1000)
     public void queryOrderState() throws Exception {
         if (canScheduleRun && production) {
-            List<TradeNo> tradeNos = dao.selectTradeNosForScheduleTask();
+            List<TradeNo> tradeNos = dao.selectTradeNosForScheduleTask(0);
             if (null != tradeNos && !tradeNos.isEmpty()) {
                 log.info("定时查询订单支付状态:{}", tradeNos);
                 for (TradeNo tradeNo : tradeNos) {

+ 1 - 0
src/main/java/thyyxxk/wxservice_server/service/WxApiService.java

@@ -202,6 +202,7 @@ public class WxApiService {
                         order.getSerialNo(), order.getTotalFee().toPlainString(), order.getPayDatetime());
             }
             if (hasSaved == 1) {
+                dao.updateSuccessHisStatus(tradeNo);
                 if (orderType == OrderType.REGISTRATION) {
                     log.info("订单号:{} 的挂号信息已保存,无需再次查询订单状态。", order.getTradeNo());
                     return ResultVoUtil.success("保存挂号信息成功。");

+ 12 - 23
src/main/resources/application-8083.yml

@@ -8,30 +8,19 @@ spring:
   thymeleaf:
     cache: false
   datasource:
-    url: jdbc:sqlserver://172.16.32.168:1433;databaseName=thxyhisdb
-    username: sa
-    password:
     driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
-    type: com.alibaba.druid.pool.DruidDataSource
-    druid:
-      initial-size: 10
-      max-active: 40
-      min-idle: 10
-      max-wait: 60000
-      validation-query: SELECT 1
-      test-while-idle: true
-      test-on-borrow: false
-      test-on-return: false
-      time-between-eviction-runs-millis: 60000
-      min-evictable-idle-time-millis: 300000
-      filters: stat
-      pool-prepared-statements: false
-      max-pool-prepared-statement-per-connection-size: 200
-      remove-abandoned: true
-      remove-abandoned-timeout: 180
-      log-abandoned: true
-    autoconfigure:
-      exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 去除druid配置
+    url: jdbc:sqlserver://172.16.32.168:1433;databaseName=thxyhisdb
+    hikari:
+      username: sa
+      password:
+      connection-timeout: 30000
+      idle-timeout: 120000
+      max-lifetime: 600000
+      minimum-idle: 10
+      maximum-pool-size: 20
+      pool-name: ThyyDatabasePool
+      leak-detection-threshold: 6000
+      connection-test-query: select 1
   jackson:
     time-zone: GMT+8
     date-format: yyyy-MM-dd HH:mm:ss

+ 12 - 23
src/main/resources/application-8085.yml

@@ -8,30 +8,19 @@ spring:
   thymeleaf:
     cache: false
   datasource:
-    url: jdbc:sqlserver://172.16.32.168:1433;databaseName=thxyhisdb
-    username: sa
-    password:
     driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
-    type: com.alibaba.druid.pool.DruidDataSource
-    druid:
-      initial-size: 10
-      max-active: 40
-      min-idle: 10
-      max-wait: 60000
-      validation-query: SELECT 1
-      test-while-idle: true
-      test-on-borrow: false
-      test-on-return: false
-      time-between-eviction-runs-millis: 60000
-      min-evictable-idle-time-millis: 300000
-      filters: stat
-      pool-prepared-statements: false
-      max-pool-prepared-statement-per-connection-size: 200
-      remove-abandoned: true
-      remove-abandoned-timeout: 180
-      log-abandoned: true
-    autoconfigure:
-      exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 去除druid配置
+    url: jdbc:sqlserver://172.16.32.168:1433;databaseName=thxyhisdb
+    hikari:
+      username: sa
+      password:
+      connection-timeout: 30000
+      idle-timeout: 120000
+      max-lifetime: 600000
+      minimum-idle: 10
+      maximum-pool-size: 20
+      pool-name: ThyyDatabasePool
+      leak-detection-threshold: 6000
+      connection-test-query: select 1
   jackson:
     time-zone: GMT+8
     date-format: yyyy-MM-dd HH:mm:ss

+ 12 - 23
src/main/resources/application.yml

@@ -8,30 +8,19 @@ spring:
   thymeleaf:
     cache: false
   datasource:
-    url: jdbc:sqlserver://172.16.32.168:1433;databaseName=thxyhisdb
-    username: sa
-    password:
     driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
-    type: com.alibaba.druid.pool.DruidDataSource
-    druid:
-      initial-size: 10
-      max-active: 40
-      min-idle: 10
-      max-wait: 60000
-      validation-query: SELECT 1
-      test-while-idle: true
-      test-on-borrow: false
-      test-on-return: false
-      time-between-eviction-runs-millis: 60000
-      min-evictable-idle-time-millis: 300000
-      filters: stat
-      pool-prepared-statements: false
-      max-pool-prepared-statement-per-connection-size: 200
-      remove-abandoned: true
-      remove-abandoned-timeout: 180
-      log-abandoned: true
-    autoconfigure:
-      exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure # 去除druid配置
+    url: jdbc:sqlserver://172.16.32.168:1433;databaseName=thxyhisdb
+    hikari:
+      username: sa
+      password:
+      connection-timeout: 30000
+      idle-timeout: 120000
+      max-lifetime: 600000
+      minimum-idle: 10
+      maximum-pool-size: 20
+      pool-name: ThyyDatabasePool
+      leak-detection-threshold: 6000
+      connection-test-query: select 1
   jackson:
     time-zone: GMT+8
     date-format: yyyy-MM-dd HH:mm:ss