Commit f2b93298b611d109850ddf74d1eaa604798d4d39

Authored by yiming
1 parent 5570148a

青浦客流

src/main/java/com/example/demo/SaticScheduleTask.java
@@ -9,8 +9,10 @@ import org.slf4j.LoggerFactory; @@ -9,8 +9,10 @@ import org.slf4j.LoggerFactory;
9 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.context.annotation.Configuration; 10 import org.springframework.context.annotation.Configuration;
11 import org.springframework.scheduling.annotation.EnableScheduling; 11 import org.springframework.scheduling.annotation.EnableScheduling;
  12 +import org.springframework.scheduling.annotation.Scheduled;
12 import org.springframework.stereotype.Component; 13 import org.springframework.stereotype.Component;
13 import javax.annotation.PostConstruct; 14 import javax.annotation.PostConstruct;
  15 +import java.time.LocalDate;
14 import java.time.LocalDateTime; 16 import java.time.LocalDateTime;
15 import java.time.format.DateTimeFormatter; 17 import java.time.format.DateTimeFormatter;
16 import java.util.*; 18 import java.util.*;
@@ -30,21 +32,16 @@ public class SaticScheduleTask { @@ -30,21 +32,16 @@ public class SaticScheduleTask {
30 private Contrast contrast; 32 private Contrast contrast;
31 33
32 34
33 - //@Scheduled(cron = "0 0/5 * * * ?")  
34 - @PostConstruct 35 + @Scheduled(cron = "0 0 12 * * ?")
35 void getArrivalInfos(){ 36 void getArrivalInfos(){
36 - logger.info("票务数据缓存加载: " + LocalDateTime.now());  
37 try { 37 try {
38 - LocalDateTime now=LocalDateTime.now();  
39 - DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");  
40 - now=LocalDateTime.parse("2024-08-26 00:00",tdf);  
41 - List<Scheduling> result=contrast.getSchedulingS(now,1); 38 + LocalDateTime now=LocalDate.now().atStartOfDay();
  39 + /*DateTimeFormatter tdf=DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
  40 + now=LocalDateTime.parse("2024-08-26 00:00",tdf);*/
  41 + contrast.getSchedulingS(now,1);
42 contrast.getStationRoutes(); 42 contrast.getStationRoutes();
43 - System.out.println(result.size());  
44 } catch (Exception e) { 43 } catch (Exception e) {
45 e.printStackTrace(); 44 e.printStackTrace();
46 } 45 }
47 } 46 }
48 -  
49 -  
50 } 47 }
51 \ No newline at end of file 48 \ No newline at end of file
src/main/java/com/example/demo/service/Contrast.java
@@ -9,7 +9,11 @@ import org.slf4j.Logger; @@ -9,7 +9,11 @@ import org.slf4j.Logger;
9 import org.slf4j.LoggerFactory; 9 import org.slf4j.LoggerFactory;
10 import org.springframework.beans.factory.annotation.Autowired; 10 import org.springframework.beans.factory.annotation.Autowired;
11 import org.springframework.kafka.core.KafkaTemplate; 11 import org.springframework.kafka.core.KafkaTemplate;
  12 +import org.springframework.kafka.support.SendResult;
12 import org.springframework.stereotype.Service; 13 import org.springframework.stereotype.Service;
  14 +import org.springframework.util.concurrent.ListenableFuture;
  15 +import org.springframework.util.concurrent.ListenableFutureCallback;
  16 +
13 import java.text.SimpleDateFormat; 17 import java.text.SimpleDateFormat;
14 import java.time.*; 18 import java.time.*;
15 import java.time.format.DateTimeFormatter; 19 import java.time.format.DateTimeFormatter;
@@ -167,7 +171,7 @@ public class Contrast { @@ -167,7 +171,7 @@ public class Contrast {
167 schedulingKFKS.add(schedulingKFK); 171 schedulingKFKS.add(schedulingKFK);
168 } 172 }
169 173
170 - List<List<SchedulingKFK>> subList = getSubList(500, schedulingKFKS); 174 + List<List<SchedulingKFK>> subList = getSubList(100, schedulingKFKS);
171 if(!subList.isEmpty()){ 175 if(!subList.isEmpty()){
172 subList.forEach(data->{ 176 subList.forEach(data->{
173 if (!data.isEmpty()) { 177 if (!data.isEmpty()) {
@@ -176,17 +180,17 @@ public class Contrast { @@ -176,17 +180,17 @@ public class Contrast {
176 map2.put("datas", data); 180 map2.put("datas", data);
177 JSON j=new JSONObject(map2); 181 JSON j=new JSONObject(map2);
178 String json =j.toString(); 182 String json =j.toString();
179 - /*ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("PDGJ", json); 183 + ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("QPGJ", json);
180 future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() { 184 future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
181 @Override 185 @Override
182 public void onSuccess(SendResult<String, String> result) { 186 public void onSuccess(SendResult<String, String> result) {
183 - logger.info("kafka发送票务数据成功条数:"+data.size()); 187 + logger.info("kafka发送路单数据成功");
184 } 188 }
185 @Override 189 @Override
186 public void onFailure(Throwable ex) { 190 public void onFailure(Throwable ex) {
187 - logger.error("kafka发送票务数据异常", ex); 191 + logger.error("kafka发送单数数据异常", ex);
188 } 192 }
189 - });*/ 193 + });
190 } 194 }
191 }); 195 });
192 } 196 }
@@ -207,23 +211,23 @@ public class Contrast { @@ -207,23 +211,23 @@ public class Contrast {
207 map.put("datas", list); 211 map.put("datas", list);
208 JSON j=new JSONObject(map); 212 JSON j=new JSONObject(map);
209 String json =j.toString(); 213 String json =j.toString();
210 - /*ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("PDGJ", json); 214 + ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("QPGJ", json);
211 future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() { 215 future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
212 @Override 216 @Override
213 public void onSuccess(SendResult<String, String> result) { 217 public void onSuccess(SendResult<String, String> result) {
214 - logger.info("kafka发送票务数据成功"); 218 + logger.info("kafka站点路由数据成功");
215 } 219 }
216 @Override 220 @Override
217 public void onFailure(Throwable ex) { 221 public void onFailure(Throwable ex) {
218 - logger.error("kafka发送票务数据异常", ex); 222 + logger.error("kafka发送站点路由数据异常", ex);
219 } 223 }
220 - });*/ 224 + });
221 } 225 }
222 System.out.println(">>>>>>>>>>>>>>>>"+list.size()); 226 System.out.println(">>>>>>>>>>>>>>>>"+list.size());
223 return list; 227 return list;
224 } 228 }
225 229
226 - public List<List<SchedulingKFK>> getSubList(int length, List<SchedulingKFK> list)throws Exception{ 230 + public List<List<SchedulingKFK>> getSubList(int length, List<SchedulingKFK> list){
227 int size = list.size(); 231 int size = list.size();
228 int temp = size / length + 1; 232 int temp = size / length + 1;
229 boolean result = size % length == 0; 233 boolean result = size % length == 0;
src/main/resources/application.properties
1 server.port=8087 1 server.port=8087
2 2
3 -spring.datasource.db1.jdbc-url=jdbc:mysql://127.0.0.1:3306/control_qp?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC 3 +spring.datasource.db1.jdbc-url=jdbc:mysql://192.168.50.213:3306/control?useUnicode=true&characterEncoding=utf-8&useSSL=false
4 spring.datasource.db1.username=root 4 spring.datasource.db1.username=root
5 -spring.datasource.db1.password=123456 5 +spring.datasource.db1.password=root2jsp
6 spring.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver 6 spring.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver
7 spring.datasource.db1.druid.test-on-borrow=true 7 spring.datasource.db1.druid.test-on-borrow=true
8 spring.datasource.db1.druid.test-while-idle=true 8 spring.datasource.db1.druid.test-while-idle=true
9 9
10 -spring.datasource.db2.jdbc-url=jdbc:mysql://127.0.0.1:3306/ms?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC 10 +spring.datasource.db2.jdbc-url=jdbc:mysql://192.168.50.213:3306/ms?useUnicode=true&characterEncoding=utf-8&useSSL=false
11 spring.datasource.db2.username=root 11 spring.datasource.db2.username=root
12 -spring.datasource.db2.password=123456 12 +spring.datasource.db2.password=root2jsp
13 spring.datasource.db2.driver-class-name=com.mysql.cj.jdbc.Driver 13 spring.datasource.db2.driver-class-name=com.mysql.cj.jdbc.Driver
14 spring.datasource.db2.druid.test-on-borrow=true 14 spring.datasource.db2.druid.test-on-borrow=true
15 spring.datasource.db2.druid.test-while-idle=true 15 spring.datasource.db2.druid.test-while-idle=true
@@ -20,4 +20,12 @@ mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl @@ -20,4 +20,12 @@ mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
20 logging.level.com.example.demo.mapper=info 20 logging.level.com.example.demo.mapper=info
21 #logging.level.org.mybatis = debug 21 #logging.level.org.mybatis = debug
22 22
  23 +spring.kafka.bootstrap-servers=192.168.40.82:9092
  24 +spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
  25 +spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
  26 +spring.kafka.producer.buffer-memory=33554432
  27 +spring.kafka.producer.acks=all
  28 +spring.kafka.producer.properties.max.request.size=20971520
  29 +
  30 +
23 31