|
|
@@ -6,6 +6,7 @@ import com.example.webapi.repository.TwiceWeighingRepository; |
|
|
import com.example.webapi.repository.pg.TwiceWeighingPostgreSQLRepository; |
|
|
import com.example.webapi.repository.pg.TwiceWeighingPostgreSQLRepository; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Qualifier; |
|
|
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.Page; |
|
|
import org.springframework.data.domain.PageRequest; |
|
|
import org.springframework.data.domain.PageRequest; |
|
|
import org.springframework.data.domain.Pageable; |
|
|
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.data.jpa.domain.Specification; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
import sun.net.www.http.HttpClient; |
|
|
|
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder; |
|
|
import javax.persistence.criteria.CriteriaBuilder; |
|
|
import javax.persistence.criteria.CriteriaQuery; |
|
|
import javax.persistence.criteria.CriteriaQuery; |
|
|
import javax.persistence.criteria.Predicate; |
|
|
import javax.persistence.criteria.Predicate; |
|
|
import javax.persistence.criteria.Root; |
|
|
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.ArrayList; |
|
|
import java.util.Date; |
|
|
import java.util.Date; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
@@ -42,6 +49,9 @@ public class DataSyncService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private com.example.webapi.repository.pg.OnceWeighingPostgreSQLRepository onceWeighingPostgreSQLRepository; |
|
|
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); |
|
|
System.out.println("成功同步了OnceWeighing数据条数为" + successCount); |
|
|
|
|
|
if (successCount > 0) { |
|
|
|
|
|
sendHttpRequest(); |
|
|
|
|
|
} |
|
|
return successCount; |
|
|
return successCount; |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
e.printStackTrace(); |
|
|
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(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 一次过磅-批量处理 |
|
|
* 一次过磅-批量处理 |
|
|
*/ |
|
|
*/ |
|
|
|