From 5421a4ee0e401e5b1cb17141eb4753cfb9e360c6 Mon Sep 17 00:00:00 2001 From: wangjian Date: Tue, 23 Dec 2025 13:04:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=90=8E=EF=BC=8C=E4=B8=BB?= =?UTF-8?q?=E5=8A=A8=E8=A7=A6=E5=8F=91=E4=B8=8B=E4=B8=80=E6=AC=A1=E5=90=8C?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../webapi/service/DataSyncService.java | 31 ++++++++ .../webapi/service/ScheduledSyncService.java | 2 +- src/main/resources/application-dev.yml | 79 +++++++++++++++++++ src/main/resources/application-xining.yml | 3 + 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/application-dev.yml diff --git a/src/main/java/com/example/webapi/service/DataSyncService.java b/src/main/java/com/example/webapi/service/DataSyncService.java index 4f9cf6d..6738f18 100644 --- a/src/main/java/com/example/webapi/service/DataSyncService.java +++ b/src/main/java/com/example/webapi/service/DataSyncService.java @@ -6,6 +6,7 @@ import com.example.webapi.repository.TwiceWeighingRepository; import com.example.webapi.repository.pg.TwiceWeighingPostgreSQLRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -13,11 +14,17 @@ import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import sun.net.www.http.HttpClient; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; +import java.io.IOException; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.ProtocolException; +import java.net.URL; import java.util.ArrayList; import java.util.Date; import java.util.List; @@ -42,6 +49,9 @@ public class DataSyncService { @Autowired private com.example.webapi.repository.pg.OnceWeighingPostgreSQLRepository onceWeighingPostgreSQLRepository; + @Value("${application.sync-url}") + private String syncUrl; + /** * 同步单条数据 */ @@ -454,6 +464,9 @@ public class DataSyncService { } } System.out.println("成功同步了OnceWeighing数据条数为" + successCount); + if (successCount > 0) { + sendHttpRequest(); + } return successCount; } catch (Exception e) { e.printStackTrace(); @@ -461,6 +474,24 @@ public class DataSyncService { } } + public void sendHttpRequest() { + try { + URL url = new URL(syncUrl); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + // 设置基本属性 + connection.setRequestMethod("POST"); + connection.setConnectTimeout(5000); // 5秒连接超时 + connection.setReadTimeout(10000); // 10秒读取超时 + // 获取响应码 + int responseCode = connection.getResponseCode(); + // 释放连接 + connection.disconnect(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + /** * 一次过磅-批量处理 */ diff --git a/src/main/java/com/example/webapi/service/ScheduledSyncService.java b/src/main/java/com/example/webapi/service/ScheduledSyncService.java index c929865..318bc7a 100644 --- a/src/main/java/com/example/webapi/service/ScheduledSyncService.java +++ b/src/main/java/com/example/webapi/service/ScheduledSyncService.java @@ -51,7 +51,7 @@ public class ScheduledSyncService implements CommandLineRunner { /** * 每5分钟执行一次一次过磅增量同步 */ - @Scheduled(fixedRate = 300000) // 5分钟 = 300000毫秒 + @Scheduled(fixedRate = 60 * 1000) public void syncOnceIncrementalData() { try { logger.info("开始定时一次过磅增量同步数据..."); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml new file mode 100644 index 0000000..72990ea --- /dev/null +++ b/src/main/resources/application-dev.yml @@ -0,0 +1,79 @@ +server: + port: 8806 + servlet: + context-path: /fuquanapi + +spring: + application: + name: fuquanapi + main: + allow-bean-definition-overriding: true + datasource: + # SQL Server数据源配置 + sqlserver: + # 西宁火车煤 - 备用配置 + url: jdbc:sqlserver://192.168.35.216:1433;SelectMethod=cursor;rewriteBatchedStatements=true;DatabaseName=WY_DATAMANAGE;encrypt=true;trustServerCertificate=true + username: sa + password: sa + driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver +# url: jdbc:sqlserver://112.33.47.173:6789;SelectMethod=cursor;rewriteBatchedStatements=true;DatabaseName=WY_DATAMANAGE20250731;encrypt=false;trustServerCertificate=true +# username: admin +# password: admin@Erp2021 +# driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver + # 连接池配置 + hikari: + maximum-pool-size: 10 + minimum-idle: 5 + connection-timeout: 30000 + idle-timeout: 600000 + max-lifetime: 1800000 + + # PostgreSQL数据源配置 + postgresql: + url: jdbc:postgresql://127.0.0.1:5432/auseft_web + username: postgres + password: pg123456 + driver-class-name: org.postgresql.Driver + # 连接池配置 + hikari: + maximum-pool-size: 10 + minimum-idle: 5 + connection-timeout: 30000 + idle-timeout: 600000 + max-lifetime: 1800000 + jpa: + hibernate: + ddl-auto: none + show-sql: true + properties: + hibernate: + dialect: org.hibernate.dialect.SQLServer2008Dialect + format_sql: true + physical_naming_strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl + use_sql_comments: true + # 禁用默认数据源自动配置 + open-in-view: false + jackson: + date-format: yyyy-MM-dd HH:mm:ss + time-zone: GMT+8 + mvc: + pathmatch: + matching-strategy: ant_path_matcher + +# API客户端配置 +api: + client: + ak: 2760cd7c-cc0e-4034-86f3-d58e89f03d80 + sk: e2c0e9c1aaa72a0b1444f879c86a9034bf2f03be31a58b1e5b3b077948da75cf + +# 日志配置 +logging: + level: + com.example.webapi: DEBUG + pattern: + console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" + +# Swagger配置 - Swagger2不需要额外配置 + +application: + sync-url: http://192.168.35.11/commodities/weight/trainShippingDetailsCombination/update-train-scale \ No newline at end of file diff --git a/src/main/resources/application-xining.yml b/src/main/resources/application-xining.yml index d5beaea..2568730 100644 --- a/src/main/resources/application-xining.yml +++ b/src/main/resources/application-xining.yml @@ -73,4 +73,7 @@ logging: pattern: console: "%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n" +application: + sync-url: http://192.168.35.11/commodities/weight/trainShippingDetailsCombination/update-train-scale + # Swagger配置 - Swagger2不需要额外配置