Bladeren bron

同步后,主动触发下一次同步

master
wangjian 3 weken geleden
bovenliggende
commit
5421a4ee0e
4 gewijzigde bestanden met toevoegingen van 114 en 1 verwijderingen
  1. +31
    -0
      src/main/java/com/example/webapi/service/DataSyncService.java
  2. +1
    -1
      src/main/java/com/example/webapi/service/ScheduledSyncService.java
  3. +79
    -0
      src/main/resources/application-dev.yml
  4. +3
    -0
      src/main/resources/application-xining.yml

+ 31
- 0
src/main/java/com/example/webapi/service/DataSyncService.java Bestand weergeven

@@ -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();
}

}

/**
* 一次过磅-批量处理
*/


+ 1
- 1
src/main/java/com/example/webapi/service/ScheduledSyncService.java Bestand weergeven

@@ -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("开始定时一次过磅增量同步数据...");


+ 79
- 0
src/main/resources/application-dev.yml Bestand weergeven

@@ -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

+ 3
- 0
src/main/resources/application-xining.yml Bestand weergeven

@@ -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不需要额外配置

Laden…
Annuleren
Opslaan