CarStartService.java
6.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package com.bsth.serviec_jk.car_start;
import com.alibaba.fastjson.JSON;
import com.bsth.entity.Clfcxxb;
import com.bsth.serviec_jk.JkToken;
import com.bsth.serviec_jk.xl_basic.HttpService;
import com.bsth.utils.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.*;
@Service
@EnableScheduling
public class CarStartService {
@Autowired
JdbcTemplate jdbcTemplate;
private final static Logger log = LoggerFactory.getLogger(HttpUtils.class);
//车辆发车信息
@Transactional()
@Scheduled(cron = "0 */1 * * * ?") //每分钟执行一回
public void listall() throws UnsupportedEncodingException {
log.info("调用车辆发车信息接口开始---------------");
long startTime=System.currentTimeMillis();
String url="https://180.167.126.126:8992/api/todaybuslinescheduleshiftinfo/addEntityList";
Map<String,Object> map = new HashMap<>();
//不走缓存,暂时直连数据库
List<Clfcxxb> list = jdbcTemplate.query("select * from bsth_t_clfcxxb", BeanPropertyRowMapper.newInstance(Clfcxxb.class));
Map<String,Object> numap = new LinkedHashMap<>();
List numlist = new ArrayList();
for (Clfcxxb x:list) {
//数据整理
numap.put("ScheduleDate",x.getRq());
numap.put("BusLineCode",x.getLineCode());
numap.put("MainBusID",null);
numap.put("GuideBoardID",null);
numap.put("ShiftSN",null);
numap.put("BusLineName",x.getLineName());
numap.put("MainBusCode",x.getNbbm());
numap.put("MainBusNumber",x.getCph());
numap.put("MainBusCompanyNumber",null);
numap.put("TerminalCode",null);
numap.put("TemplateID",0);
numap.put("GuideBoardName",null);
numap.put("DriverEmpCode",null);
numap.put("DriverEmpName",x.getJName());
numap.put("DriverEmpNumber",x.getjGh());
numap.put("ConductorEmpCode",null);
numap.put("ConductorEmpName",null);
numap.put("ConductorEmpNumber",null);
numap.put("CompanyCode",null);
numap.put("CompanyName",null);
numap.put("SubCompanyCode",null);
numap.put("SubCompanyName",null);
numap.put("ShiftTypeCode",x.getBcType());
numap.put("ShiftStateCode",null);
numap.put("NondoTypeCode",null);
numap.put("ShiftDirectionCode",null);
numap.put("ShiftStartPlanTime",null);
numap.put("ShiftStartWaitTime",x.getDfsj());
numap.put("ShiftStartWaitNote",null);
numap.put("ShiftStartFinishTime",null);
numap.put("ShiftStartPlanStationCode",x.getSn());
numap.put("ShiftStartAutoCode",null);
numap.put("ShiftStartNote",null);
numap.put("ShiftEndPlanStationCode",null);
numap.put("ShiftEndPlanTime",null);
numap.put("ShiftEndFinishTime",null);
numap.put("ShiftEndAutoCode",null);
numap.put("ShiftEndNote",null);
numap.put("PlanKilometer",null);
numap.put("FinishKilometer",null);
numap.put("GPSKilometer",null);
numap.put("PlanFinishTime",null);
numap.put("FinishFinishTime",null);
numap.put("KilometerFinishRate",null);
numap.put("ShiftNumberFinishRate",null);
numap.put("ReplaceBusLineCode",null);
numap.put("ReplaceText",null);
numap.put("DispathUserName",null);
numap.put("DispathDatetime",null);
numap.put("MessageID",null);
numap.put("MessageDatetime",null);
numap.put("TerminalReceiveCode",null);
numap.put("TerminalReceiveDatetime",null);
numap.put("DriverConfirmCode",null);
numap.put("DriverConfirmDatetime",null);
numlist.add(numap);
numap = new LinkedHashMap<>();
}
String token = JkToken.jkdata();
map.put("list",numlist);
int count = 1;
if(numlist.size()==0){
return;
}
if(null !=numlist && numlist.size()>1000){
for (int i = 0; i <numlist.size() ; ) {
if(numlist.size()> i + 1000){
log.info("第"+count+"次调用-----------");
String json = "list=" + URLEncoder.encode(JSON.toJSONStringWithDateFormat(numlist.subList(i,i+1000), "yyyy-MM-dd HH:mm:ss"), "UTF-8");
int resultCount= HttpService.httpRequestResulty(json,token,url,count);
}else {
log.info("第"+count+"次调用-----------");
String json = "list=" + URLEncoder.encode(JSON.toJSONStringWithDateFormat(numlist.subList(i,numlist.size()), "yyyy-MM-dd HH:mm:ss"), "UTF-8");
int resultCount= HttpService.httpRequestResulty(json,token,url,count);
}
i=i+1000;
count++;
}
}else {
String json = "list=" + URLEncoder.encode(JSON.toJSONStringWithDateFormat(numlist.subList(0,numlist.size()), "yyyy-MM-dd HH:mm:ss"), "UTF-8");
int resultCount= HttpService.httpRequestResulty(json,token,url,count);
}
long endTime=System.currentTimeMillis();
log.info("调用车辆发车信息接口结束---------------共计执行时间:"+(endTime-startTime));
}
}