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 9 import org.springframework.beans.factory.annotation.Autowired;
10 10 import org.springframework.context.annotation.Configuration;
11 11 import org.springframework.scheduling.annotation.EnableScheduling;
  12 +import org.springframework.scheduling.annotation.Scheduled;
12 13 import org.springframework.stereotype.Component;
13 14 import javax.annotation.PostConstruct;
  15 +import java.time.LocalDate;
14 16 import java.time.LocalDateTime;
15 17 import java.time.format.DateTimeFormatter;
16 18 import java.util.*;
... ... @@ -30,21 +32,16 @@ public class SaticScheduleTask {
30 32 private Contrast contrast;
31 33  
32 34  
33   - //@Scheduled(cron = "0 0/5 * * * ?")
34   - @PostConstruct
  35 + @Scheduled(cron = "0 0 12 * * ?")
35 36 void getArrivalInfos(){
36   - logger.info("票务数据缓存加载: " + LocalDateTime.now());
37 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 42 contrast.getStationRoutes();
43   - System.out.println(result.size());
44 43 } catch (Exception e) {
45 44 e.printStackTrace();
46 45 }
47 46 }
48   -
49   -
50 47 }
51 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 9 import org.slf4j.LoggerFactory;
10 10 import org.springframework.beans.factory.annotation.Autowired;
11 11 import org.springframework.kafka.core.KafkaTemplate;
  12 +import org.springframework.kafka.support.SendResult;
12 13 import org.springframework.stereotype.Service;
  14 +import org.springframework.util.concurrent.ListenableFuture;
  15 +import org.springframework.util.concurrent.ListenableFutureCallback;
  16 +
13 17 import java.text.SimpleDateFormat;
14 18 import java.time.*;
15 19 import java.time.format.DateTimeFormatter;
... ... @@ -167,7 +171,7 @@ public class Contrast {
167 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 175 if(!subList.isEmpty()){
172 176 subList.forEach(data->{
173 177 if (!data.isEmpty()) {
... ... @@ -176,17 +180,17 @@ public class Contrast {
176 180 map2.put("datas", data);
177 181 JSON j=new JSONObject(map2);
178 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 184 future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
181 185 @Override
182 186 public void onSuccess(SendResult<String, String> result) {
183   - logger.info("kafka发送票务数据成功条数:"+data.size());
  187 + logger.info("kafka发送路单数据成功");
184 188 }
185 189 @Override
186 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 211 map.put("datas", list);
208 212 JSON j=new JSONObject(map);
209 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 215 future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {
212 216 @Override
213 217 public void onSuccess(SendResult<String, String> result) {
214   - logger.info("kafka发送票务数据成功");
  218 + logger.info("kafka站点路由数据成功");
215 219 }
216 220 @Override
217 221 public void onFailure(Throwable ex) {
218   - logger.error("kafka发送票务数据异常", ex);
  222 + logger.error("kafka发送站点路由数据异常", ex);
219 223 }
220   - });*/
  224 + });
221 225 }
222 226 System.out.println(">>>>>>>>>>>>>>>>"+list.size());
223 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 231 int size = list.size();
228 232 int temp = size / length + 1;
229 233 boolean result = size % length == 0;
... ...
src/main/resources/application.properties
1 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 4 spring.datasource.db1.username=root
5   -spring.datasource.db1.password=123456
  5 +spring.datasource.db1.password=root2jsp
6 6 spring.datasource.db1.driver-class-name=com.mysql.cj.jdbc.Driver
7 7 spring.datasource.db1.druid.test-on-borrow=true
8 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 11 spring.datasource.db2.username=root
12   -spring.datasource.db2.password=123456
  12 +spring.datasource.db2.password=root2jsp
13 13 spring.datasource.db2.driver-class-name=com.mysql.cj.jdbc.Driver
14 14 spring.datasource.db2.druid.test-on-borrow=true
15 15 spring.datasource.db2.druid.test-while-idle=true
... ... @@ -20,4 +20,12 @@ mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
20 20 logging.level.com.example.demo.mapper=info
21 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  
... ...