Commit 7e002204f36b629c9dd79a091a298d6c6b008c43
1 parent
0a494b99
云平台数据对接(实际排班,空驶里程,烂班里程)
Showing
6 changed files
with
1643 additions
and
679 deletions
src/main/java/com/bsth/realschedule/BackClass.java
0 → 100644
| 1 | +package com.bsth.realschedule; | ||
| 2 | + | ||
| 3 | +import java.io.UnsupportedEncodingException; | ||
| 4 | +import java.util.Date; | ||
| 5 | +import java.util.HashMap; | ||
| 6 | +import java.util.List; | ||
| 7 | +import java.util.Map; | ||
| 8 | + | ||
| 9 | +import org.slf4j.Logger; | ||
| 10 | +import org.slf4j.LoggerFactory; | ||
| 11 | + | ||
| 12 | +import com.alibaba.fastjson.JSON; | ||
| 13 | +import com.bsth.utils.CallBack; | ||
| 14 | + | ||
| 15 | +public class BackClass implements CallBack { | ||
| 16 | + | ||
| 17 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 18 | + | ||
| 19 | + @Override | ||
| 20 | + public void success(byte[] bytes, Map<String, List<String>> header) { | ||
| 21 | + // TODO Auto-generated method stub | ||
| 22 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
| 23 | + try { | ||
| 24 | + System.out.println("返回如下:"); | ||
| 25 | + System.out.println(new String(bytes, "utf-8")); | ||
| 26 | + logger.info("上传返回:" + new String(bytes, "utf-8")); | ||
| 27 | + } catch (UnsupportedEncodingException e) { | ||
| 28 | + // TODO Auto-generated catch block | ||
| 29 | + System.out.println("返回内容:" + bytes); | ||
| 30 | + logger.info("返回内容:" + bytes.toString()); | ||
| 31 | + } | ||
| 32 | + System.out.println(map); | ||
| 33 | + logger.info(map.toString()); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public void failed() { | ||
| 38 | + // TODO Auto-generated method stub | ||
| 39 | + System.out.println("上传失败!("+new Date().getTime()+")"); | ||
| 40 | + logger.error("上传失败!("+new Date().getTime()+")"); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | +} |
src/main/java/com/bsth/realschedule/DataUpload.java
0 → 100644
| 1 | +package com.bsth.realschedule; | ||
| 2 | + | ||
| 3 | +import java.io.BufferedReader; | ||
| 4 | +import java.io.InputStreamReader; | ||
| 5 | +import java.net.HttpURLConnection; | ||
| 6 | +import java.net.URL; | ||
| 7 | +import java.net.URLEncoder; | ||
| 8 | +import java.security.MessageDigest; | ||
| 9 | +import java.text.SimpleDateFormat; | ||
| 10 | +import java.util.ArrayList; | ||
| 11 | +import java.util.Collections; | ||
| 12 | +import java.util.Comparator; | ||
| 13 | +import java.util.Date; | ||
| 14 | +import java.util.HashMap; | ||
| 15 | +import java.util.HashSet; | ||
| 16 | +import java.util.List; | ||
| 17 | +import java.util.Map; | ||
| 18 | +import java.util.Set; | ||
| 19 | +import org.slf4j.Logger; | ||
| 20 | +import org.slf4j.LoggerFactory; | ||
| 21 | +import org.springframework.scheduling.annotation.Scheduled; | ||
| 22 | +import org.springframework.stereotype.Component; | ||
| 23 | + | ||
| 24 | +import com.alibaba.fastjson.JSON; | ||
| 25 | +import com.alibaba.fastjson.JSONObject; | ||
| 26 | +import com.bsth.utils.Arith; | ||
| 27 | +import com.bsth.utils.HttpUtils; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | + * | ||
| 31 | + * @author LGF | ||
| 32 | + * | ||
| 33 | + */ | ||
| 34 | + | ||
| 35 | +@Component | ||
| 36 | +public class DataUpload { | ||
| 37 | + | ||
| 38 | + private final static Logger logger = LoggerFactory.getLogger(com.bsth.realschedule.DataUpload.class.getName()); | ||
| 39 | + | ||
| 40 | +// private final static String ip = "114.80.178.12:9089"; | ||
| 41 | + private final static String ip = "10.10.150.24:9089"; | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * 实际排班信息(BusDispatch_TodayBusLineScheduleInfo) | ||
| 45 | + * 云平台数据需求对接(建交委) | ||
| 46 | + * @throws Exception | ||
| 47 | + */ | ||
| 48 | + @Scheduled(cron = "0 00 06 * * ? ") | ||
| 49 | + public void realScheduleUpload() throws Exception{ | ||
| 50 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 51 | + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd"); | ||
| 52 | + long ts=new Date().getTime(); | ||
| 53 | + StringBuffer hexstr = new StringBuffer(); | ||
| 54 | + MessageDigest md = MessageDigest.getInstance("SHA-1"); | ||
| 55 | + String str = ts+"7da994576ccbe6ea1f8e83936d4da84820756b3a"+"a1503"; | ||
| 56 | + md.update(str.getBytes()); | ||
| 57 | + byte[] digest = md.digest(); | ||
| 58 | + String shaHex = ""; | ||
| 59 | + for (int i = 0; i < digest.length; i++) { | ||
| 60 | + shaHex = Integer.toHexString(digest[i] & 0xFF); | ||
| 61 | + if (shaHex.length() < 2) { | ||
| 62 | + hexstr.append(0); | ||
| 63 | + } | ||
| 64 | + hexstr.append(shaHex); | ||
| 65 | + } | ||
| 66 | + String sign =hexstr.toString(); | ||
| 67 | + | ||
| 68 | + String[] strs = {"55", "22", "05", "26"}; | ||
| 69 | + String rq = sdf2.format(sdf2.parse("20200820")); | ||
| 70 | + String accessToken = "abfed98867c64fde99f7f88a4532efa8"; | ||
| 71 | + | ||
| 72 | + List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>(); | ||
| 73 | + | ||
| 74 | + for(int s = 0; s < strs.length; s++){ | ||
| 75 | + String company = strs[s]; | ||
| 76 | + | ||
| 77 | + String carJson= getHttpInterface("http://"+ip+"/webservice/rest/car/company/"+company+"?timestamp="+ts+"&nonce=a1503&password=7da994576ccbe6ea1f8e83936d4da84820756b3a&sign="+sign); | ||
| 78 | + List<Map<String, Object>> list_car=(List<Map<String, Object>>) JSONObject.parse(carJson); | ||
| 79 | + | ||
| 80 | + String json= getHttpInterface("http://"+ip+"/webservice/rest/schedule_real/sch_jk/"+company+"/"+rq+"?timestamp="+ts+"&nonce=a1503&password=7da994576ccbe6ea1f8e83936d4da84820756b3a&sign="+sign); | ||
| 81 | + List<Map<String, Object>> list_map=(List<Map<String, Object>>) JSONObject.parse(json); | ||
| 82 | + | ||
| 83 | + Map<String, Map<String, Object>> carMap = new HashMap<String, Map<String, Object>>(); | ||
| 84 | + for(Map<String, Object> m : list_car){ | ||
| 85 | + carMap.put(m.get("nbbm").toString(), m); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + Map<String, List<Map<String, Object>>> keyMap = new HashMap<String, List<Map<String,Object>>>(); | ||
| 89 | + List<String> keyList = new ArrayList<String>(); | ||
| 90 | + | ||
| 91 | + for(Map<String, Object> m : list_map){ | ||
| 92 | + // System.out.println(m.get("scheduleDate") +" / " + m.get("lineName") +" / " + m.get("nbbm") + " / " + m.get("fcsjT")); | ||
| 93 | + String date = m.get("scheduleDate").toString(); | ||
| 94 | + String lineCode = m.get("lineCode").toString(); | ||
| 95 | + String lpName = m.get("lpName").toString(); | ||
| 96 | + String nbbm = m.get("nbbm").toString(); | ||
| 97 | + | ||
| 98 | + String key = date + "/" + lineCode + "/" + nbbm + "/" + lpName; | ||
| 99 | + | ||
| 100 | + if(keyMap.containsKey(key)){ | ||
| 101 | + keyMap.get(key).add(m); | ||
| 102 | + } else { | ||
| 103 | + List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); | ||
| 104 | + list.add(m); | ||
| 105 | + keyMap.put(key, list); | ||
| 106 | + keyList.add(key); | ||
| 107 | + } | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + for(String key : keyList){ | ||
| 111 | + List<Map<String, Object>> list = keyMap.get(key); | ||
| 112 | + Collections.sort(list, new Comparator<Map<String, Object>>() { | ||
| 113 | + @Override | ||
| 114 | + public int compare(Map<String, Object> c1, Map<String, Object> c2) { | ||
| 115 | + | ||
| 116 | + long l1 = c1.get("fcsjT")!=null?Long.valueOf(c1.get("fcsjT").toString()):9000000000000000000l; | ||
| 117 | + long l2 = c2.get("fcsjT")!=null?Long.valueOf(c2.get("fcsjT").toString()):9000000000000000000l; | ||
| 118 | + | ||
| 119 | + long diff = l1 - l2; | ||
| 120 | + if (diff > 0l) { | ||
| 121 | + return 1; | ||
| 122 | + }else if (diff < 0l) { | ||
| 123 | + return -1; | ||
| 124 | + } | ||
| 125 | + return 0; //相等为0 | ||
| 126 | + } | ||
| 127 | + }); | ||
| 128 | + | ||
| 129 | + Map<String, Object> m = new HashMap<String, Object>(); | ||
| 130 | + m.put("ScheduleDate", sdf.parse(list.get(0).get("scheduleDate").toString())); | ||
| 131 | + m.put("BusLineCode", list.get(0).get("lineCode")); | ||
| 132 | + m.put("BusLineName", list.get(0).get("lineName")); | ||
| 133 | + m.put("TemplateID", ""); | ||
| 134 | + m.put("MainBusID", ""); | ||
| 135 | + m.put("MainBusCode", ""); | ||
| 136 | + m.put("MainBusNumber", "");//牌照号 | ||
| 137 | + m.put("MainBusCompanyNumber", list.get(0).get("nbbm")); | ||
| 138 | + m.put("TerminalCode", "");//终端编码 | ||
| 139 | + m.put("GuideBoardID", ""); | ||
| 140 | + m.put("GuideBoardName", list.get(0).get("lpName")); | ||
| 141 | + | ||
| 142 | + if(carMap.containsKey(list.get(0).get("nbbm").toString())){ | ||
| 143 | + Map<String, Object> map = carMap.get(list.get(0).get("nbbm").toString()); | ||
| 144 | + m.put("MainBusNumber", map.get("carPlate")!=null?map.get("carPlate").toString():"");//牌照号 | ||
| 145 | + m.put("TerminalCode", map.get("equipmentCode")!=null?map.get("equipmentCode").toString():"");//终端编码 | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + Set<String> jsySpy = new HashSet<String>(); | ||
| 149 | + List<String> strList = new ArrayList<String>(); | ||
| 150 | + // System.out.println("-------------------------"); | ||
| 151 | + for(Map<String, Object> temp : list){ | ||
| 152 | + String jsy = temp.get("jsy")!=null?temp.get("jsy").toString():""; | ||
| 153 | + String spy = temp.get("spy")!=null?temp.get("spy").toString():""; | ||
| 154 | + if(jsySpy.add(jsy + "_" + spy)){ | ||
| 155 | + strList.add(jsy + "_" + spy); | ||
| 156 | + // System.out.println(temp.get("fcsjT")); | ||
| 157 | + } | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + for(int i = 1; i <= 3; i++){ | ||
| 161 | + m.put("DriverEmpCode" + i, ""); | ||
| 162 | + m.put("ConductorEmpCode" + i, ""); | ||
| 163 | + if(strList.size() >= i){ | ||
| 164 | + String string = strList.get(i - 1); | ||
| 165 | + String[] split = string.split("_"); | ||
| 166 | + if(split[0].length() > 1 && split[0].contains("/")){ | ||
| 167 | + String[] jsy = split[0].split("/"); | ||
| 168 | + m.put("DriverEmpName" + i, jsy[1]); | ||
| 169 | + m.put("DriverEmpNumber" + i, jsy[0]); | ||
| 170 | + } else { | ||
| 171 | + m.put("DriverEmpName" + i, ""); | ||
| 172 | + m.put("DriverEmpNumber" + i, ""); | ||
| 173 | + } | ||
| 174 | + if(split.length > 1 && split[1].length() > 1 && split[1].contains("/")){ | ||
| 175 | + String[] spy = split[1].split("/"); | ||
| 176 | + m.put("ConductorEmpName" + i, spy[1]); | ||
| 177 | + m.put("ConductorEmpNumber" + i, spy[0]); | ||
| 178 | + } else { | ||
| 179 | + m.put("ConductorEmpName" + i, ""); | ||
| 180 | + m.put("ConductorEmpNumber" + i, ""); | ||
| 181 | + } | ||
| 182 | + } else { | ||
| 183 | + m.put("DriverEmpName" + i, ""); | ||
| 184 | + m.put("DriverEmpNumber" + i, ""); | ||
| 185 | + m.put("ConductorEmpName" + i, ""); | ||
| 186 | + m.put("ConductorEmpNumber" + i, ""); | ||
| 187 | + } | ||
| 188 | + } | ||
| 189 | + resList.add(m); | ||
| 190 | + } | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + if(resList.size() > 0){ | ||
| 194 | + List<List<Map<String, Object>>> listGroup = new ArrayList<List<Map<String, Object>>>(); | ||
| 195 | + int size = resList.size(); | ||
| 196 | + int index = 1000; | ||
| 197 | + for(int i = 0; i < size; i += index){ | ||
| 198 | + if(i + index > size){ | ||
| 199 | + index = size - i; | ||
| 200 | + } | ||
| 201 | + List<Map<String, Object>> newList = resList.subList(i, i + index); | ||
| 202 | + listGroup.add(newList); | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + String json= getHttpInterface("http://180.167.126.126:8992/api/getcode"); | ||
| 206 | + Map<String, Object> map=(Map<String, Object>) JSONObject.parse(json); | ||
| 207 | + String token = encrypt(accessToken, map.get("result").toString()); | ||
| 208 | + String deleteAll = "TRUE"; | ||
| 209 | + | ||
| 210 | + for(List<Map<String, Object>> list : listGroup){ | ||
| 211 | + Map<String, String> header = new HashMap<String, String>(); | ||
| 212 | + header.put("Access-Token", token); | ||
| 213 | + Map<String, Object> param = new HashMap<String, Object>(); | ||
| 214 | +// param.put("AccessToken", token); | ||
| 215 | +// param.put("DeleteAll", deleteAll); | ||
| 216 | +// param.put("DataList", JSON.toJSONString(list)); | ||
| 217 | + param.put("list", URLEncoder.encode(JSON.toJSONStringWithDateFormat(list, "yyyy-MM-dd HH:mm:ss"), "UTF-8")); | ||
| 218 | +// HttpUtils.request("http://180.167.126.126:8992/api/todaybuslinescheduleinfo/addEntityList", | ||
| 219 | +// new BackClass(), "POST", header, param); | ||
| 220 | + deleteAll = "FALSE"; | ||
| 221 | + } | ||
| 222 | + System.out.println(resList.size()); | ||
| 223 | + logger.info("实际排班共上传:" + resList.size() + "条"); | ||
| 224 | + } | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + /** | ||
| 228 | + * 空驶里程(BusDispatch_UnCarryMileage) | ||
| 229 | + * 云平台数据需求对接(建交委) | ||
| 230 | + * @throws Exception | ||
| 231 | + */ | ||
| 232 | + @Scheduled(cron = "0 10 06 * * ? ") | ||
| 233 | + public void ksLcUpload() throws Exception{ | ||
| 234 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 235 | + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd"); | ||
| 236 | + long ts=new Date().getTime(); | ||
| 237 | + StringBuffer hexstr = new StringBuffer(); | ||
| 238 | + MessageDigest md = MessageDigest.getInstance("SHA-1"); | ||
| 239 | + String str = ts+"7da994576ccbe6ea1f8e83936d4da84820756b3a"+"a1503"; | ||
| 240 | + md.update(str.getBytes()); | ||
| 241 | + byte[] digest = md.digest(); | ||
| 242 | + String shaHex = ""; | ||
| 243 | + for (int i = 0; i < digest.length; i++) { | ||
| 244 | + shaHex = Integer.toHexString(digest[i] & 0xFF); | ||
| 245 | + if (shaHex.length() < 2) { | ||
| 246 | + hexstr.append(0); | ||
| 247 | + } | ||
| 248 | + hexstr.append(shaHex); | ||
| 249 | + } | ||
| 250 | + String sign =hexstr.toString(); | ||
| 251 | + | ||
| 252 | + String[] strs = {"55", "22", "05", "26"}; | ||
| 253 | + String rq = sdf2.format(sdf2.parse("20200822")); | ||
| 254 | + String accessToken = "abfed98867c64fde99f7f88a4532efa8"; | ||
| 255 | + | ||
| 256 | + List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>(); | ||
| 257 | + | ||
| 258 | + for(int s = 0; s < strs.length; s++){ | ||
| 259 | + String company = strs[s]; | ||
| 260 | + System.out.println(company); | ||
| 261 | + | ||
| 262 | + String lineJson= getHttpInterface("http://"+ip+"/webservice/rest/line/company/"+company+"?timestamp="+ts+"&nonce=a1503&password=7da994576ccbe6ea1f8e83936d4da84820756b3a&sign="+sign); | ||
| 263 | + List<Map<String, Object>> list_line=(List<Map<String, Object>>) JSONObject.parse(lineJson); | ||
| 264 | + | ||
| 265 | + String json= getHttpInterface("http://"+ip+"/webservice/rest/schedule_real/sch_jk/"+company+"/"+rq+"?timestamp="+ts+"&nonce=a1503&password=7da994576ccbe6ea1f8e83936d4da84820756b3a&sign="+sign); | ||
| 266 | + List<Map<String, Object>> list_map=(List<Map<String, Object>>) JSONObject.parse(json); | ||
| 267 | + | ||
| 268 | + Map<String, Map<String, Object>> lineMap = new HashMap<String, Map<String, Object>>(); | ||
| 269 | + for(Map<String, Object> m : list_line){ | ||
| 270 | + lineMap.put(m.get("lineCode").toString(), m); | ||
| 271 | + } | ||
| 272 | + | ||
| 273 | + Map<String, List<Map<String, Object>>> keyMap = new HashMap<String, List<Map<String,Object>>>(); | ||
| 274 | + List<String> keyList = new ArrayList<String>(); | ||
| 275 | + | ||
| 276 | + for(Map<String, Object> m : list_map){ | ||
| 277 | + | ||
| 278 | + String date = m.get("scheduleDate").toString(); | ||
| 279 | + String lineCode = m.get("lineCode").toString(); | ||
| 280 | + String bcType = m.get("bcType")!=null?m.get("bcType").toString():""; | ||
| 281 | + | ||
| 282 | + String key = date + "/" + lineCode + "/" + bcType; | ||
| 283 | + | ||
| 284 | + if(keyMap.containsKey(key)){ | ||
| 285 | + keyMap.get(key).add(m); | ||
| 286 | + } else { | ||
| 287 | + List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); | ||
| 288 | + list.add(m); | ||
| 289 | + keyMap.put(key, list); | ||
| 290 | + keyList.add(key); | ||
| 291 | + } | ||
| 292 | + } | ||
| 293 | + | ||
| 294 | + for(String key : keyList){ | ||
| 295 | + List<Map<String, Object>> list = keyMap.get(key); | ||
| 296 | + | ||
| 297 | + Map<String, Object> m = new HashMap<String, Object>(); | ||
| 298 | + | ||
| 299 | + m.put("ReportDate", sdf.parse(list.get(0).get("scheduleDate").toString())); | ||
| 300 | + m.put("BusLineCode", list.get(0).get("lineCode")); | ||
| 301 | + m.put("BusLineName", list.get(0).get("lineName")); | ||
| 302 | + | ||
| 303 | + if(lineMap.get(list.get(0).get("lineCode").toString()) != null){ | ||
| 304 | + Map<String, Object> map = lineMap.get(list.get(0).get("lineCode")); | ||
| 305 | + String gs = map.get("company")!=null?map.get("company").toString():""; | ||
| 306 | + String fgs = map.get("brancheCompany")!=null?map.get("brancheCompany").toString():""; | ||
| 307 | + m.put("CompanyCode", gs); | ||
| 308 | + m.put("SubCompanyCode", fgs); | ||
| 309 | + m.put("CompanyName", ""); | ||
| 310 | + m.put("SubCompanyName", ""); | ||
| 311 | + | ||
| 312 | + String gsFgsName = getGsFgsName(gs, fgs); | ||
| 313 | + if(gsFgsName.length() > 1){ | ||
| 314 | + String[] split = gsFgsName.split("_"); | ||
| 315 | + if(split.length > 1){ | ||
| 316 | + m.put("CompanyName", split[0]); | ||
| 317 | + m.put("SubCompanyName", split[1]); | ||
| 318 | + } | ||
| 319 | + } | ||
| 320 | + | ||
| 321 | + } else { | ||
| 322 | + continue; | ||
| 323 | + } | ||
| 324 | + | ||
| 325 | + double kslc = 0; | ||
| 326 | + | ||
| 327 | + for(Map<String, Object> temp : list){ | ||
| 328 | + List<Map<String, Object>> cTasks = (List<Map<String, Object>>)temp.get("cTasks"); | ||
| 329 | + if(cTasks.size() > 0){ | ||
| 330 | + for(Map<String, Object> task : cTasks){ | ||
| 331 | + if("false".equals(task.get("destroy")!=null?task.get("destroy").toString():"")){ | ||
| 332 | + if("empty".equals(task.get("mileageType")!=null?task.get("mileageType").toString():"")){ | ||
| 333 | + kslc = Arith.add(kslc, task.get("mileage")==null?0:task.get("mileage")); | ||
| 334 | + } | ||
| 335 | + } | ||
| 336 | + } | ||
| 337 | + } else { | ||
| 338 | + String bcType = temp.get("bcType")!=null?temp.get("bcType").toString():""; | ||
| 339 | + if(bcType.equals("in") || bcType.equals("out") || bcType.equals("ldks")){ | ||
| 340 | + if(temp.get("status") != null && !("-1".equals(temp.get("status").toString()))){ | ||
| 341 | + kslc = Arith.add(kslc, temp.get("jhlc")==null?0:temp.get("jhlc")); | ||
| 342 | + } | ||
| 343 | + } | ||
| 344 | + } | ||
| 345 | + } | ||
| 346 | + if(kslc > 0d){ | ||
| 347 | + m.put("Mileage", kslc); | ||
| 348 | + | ||
| 349 | + if("in".equals(list.get(0).get("bcType").toString())){ | ||
| 350 | + m.put("MileageType", "进场"); | ||
| 351 | + } else if("out".equals(list.get(0).get("bcType").toString())){ | ||
| 352 | + m.put("MileageType", "出场"); | ||
| 353 | + } else { | ||
| 354 | + m.put("MileageType", "其他"); | ||
| 355 | + } | ||
| 356 | + | ||
| 357 | + resList.add(m);//2020-08-20:785条 | ||
| 358 | + } | ||
| 359 | + } | ||
| 360 | + } | ||
| 361 | + | ||
| 362 | + if(resList.size() > 0){ | ||
| 363 | + List<List<Map<String, Object>>> listGroup = new ArrayList<List<Map<String, Object>>>(); | ||
| 364 | + int size = resList.size(); | ||
| 365 | + int index = 1000; | ||
| 366 | + for(int i = 0; i < size; i += index){ | ||
| 367 | + if(i + index > size){ | ||
| 368 | + index = size - i; | ||
| 369 | + } | ||
| 370 | + List<Map<String, Object>> newList = resList.subList(i, i + index); | ||
| 371 | + listGroup.add(newList); | ||
| 372 | + } | ||
| 373 | + | ||
| 374 | + String json= getHttpInterface("http://180.167.126.126:8992/api/getcode"); | ||
| 375 | + Map<String, Object> map=(Map<String, Object>) JSONObject.parse(json); | ||
| 376 | + String token = encrypt(accessToken, map.get("result").toString()); | ||
| 377 | + String deleteAll = "TRUE"; | ||
| 378 | + | ||
| 379 | + for(List<Map<String, Object>> list : listGroup){ | ||
| 380 | + Map<String, String> header = new HashMap<String, String>(); | ||
| 381 | + header.put("Access-Token", token); | ||
| 382 | + Map<String, Object> param = new HashMap<String, Object>(); | ||
| 383 | +// param.put("AccessToken", token); | ||
| 384 | +// param.put("DeleteAll", deleteAll); | ||
| 385 | +// param.put("DataList", JSON.toJSONString(list)); | ||
| 386 | + param.put("list", URLEncoder.encode(JSON.toJSONStringWithDateFormat(list, "yyyy-MM-dd HH:mm:ss"), "UTF-8")); | ||
| 387 | + HttpUtils.request("http://180.167.126.126:8992/api/busdispatchuncarrymileage/addEntityList", | ||
| 388 | + new BackClass(), "POST", header, param); | ||
| 389 | + deleteAll = "FALSE"; | ||
| 390 | + } | ||
| 391 | + System.out.println(resList.size()); | ||
| 392 | + logger.info("空驶里程共上传:" + resList.size() + "条"); | ||
| 393 | + } | ||
| 394 | + } | ||
| 395 | + | ||
| 396 | + /** | ||
| 397 | + * 烂班里程(BusDispatch_UnDoneMileage) | ||
| 398 | + * 云平台数据需求对接(建交委) | ||
| 399 | + * @throws Exception | ||
| 400 | + */ | ||
| 401 | + @Scheduled(cron = "0 20 06 * * ? ") | ||
| 402 | + public void lbLcUpload() throws Exception{ | ||
| 403 | + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); | ||
| 404 | + SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd"); | ||
| 405 | + long ts=new Date().getTime(); | ||
| 406 | + StringBuffer hexstr = new StringBuffer(); | ||
| 407 | + MessageDigest md = MessageDigest.getInstance("SHA-1"); | ||
| 408 | + String str = ts+"7da994576ccbe6ea1f8e83936d4da84820756b3a"+"a1503"; | ||
| 409 | + md.update(str.getBytes()); | ||
| 410 | + byte[] digest = md.digest(); | ||
| 411 | + String shaHex = ""; | ||
| 412 | + for (int i = 0; i < digest.length; i++) { | ||
| 413 | + shaHex = Integer.toHexString(digest[i] & 0xFF); | ||
| 414 | + if (shaHex.length() < 2) { | ||
| 415 | + hexstr.append(0); | ||
| 416 | + } | ||
| 417 | + hexstr.append(shaHex); | ||
| 418 | + } | ||
| 419 | + String sign =hexstr.toString(); | ||
| 420 | + | ||
| 421 | + String[] strs = {"55", "22", "05", "26"}; | ||
| 422 | + String rq = sdf2.format(sdf2.parse("20200822")); | ||
| 423 | + String accessToken = "abfed98867c64fde99f7f88a4532efa8"; | ||
| 424 | + | ||
| 425 | + String[] lbTypes = {"路阻", "吊慢", "故障", "纠纷", "肇事", "缺人", "缺车", "客稀", "配车", "保养", "气候", "援外", "抽减", "其他"}; | ||
| 426 | + | ||
| 427 | + List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>(); | ||
| 428 | + | ||
| 429 | + for(int s = 0; s < strs.length; s++){ | ||
| 430 | + String company = strs[s]; | ||
| 431 | + System.out.println(company); | ||
| 432 | + | ||
| 433 | + String lineJson= getHttpInterface("http://"+ip+"/webservice/rest/line/company/"+company+"?timestamp="+ts+"&nonce=a1503&password=7da994576ccbe6ea1f8e83936d4da84820756b3a&sign="+sign); | ||
| 434 | + List<Map<String, Object>> list_line=(List<Map<String, Object>>) JSONObject.parse(lineJson); | ||
| 435 | + | ||
| 436 | + String json= getHttpInterface("http://"+ip+"/webservice/rest/schedule_real/sch_jk/"+company+"/"+rq+"?timestamp="+ts+"&nonce=a1503&password=7da994576ccbe6ea1f8e83936d4da84820756b3a&sign="+sign); | ||
| 437 | + List<Map<String, Object>> list_map=(List<Map<String, Object>>) JSONObject.parse(json); | ||
| 438 | + | ||
| 439 | + Map<String, Map<String, Object>> lineMap = new HashMap<String, Map<String, Object>>(); | ||
| 440 | + for(Map<String, Object> m : list_line){ | ||
| 441 | + lineMap.put(m.get("lineCode").toString(), m); | ||
| 442 | + } | ||
| 443 | + | ||
| 444 | + Map<String, List<Map<String, Object>>> keyMap = new HashMap<String, List<Map<String,Object>>>(); | ||
| 445 | + List<String> keyList = new ArrayList<String>(); | ||
| 446 | + | ||
| 447 | + for(Map<String, Object> m : list_map){ | ||
| 448 | + | ||
| 449 | + String date = m.get("scheduleDate").toString(); | ||
| 450 | + String lineCode = m.get("lineCode").toString(); | ||
| 451 | + | ||
| 452 | + String key = date + "/" + lineCode; | ||
| 453 | + | ||
| 454 | + if(keyMap.containsKey(key)){ | ||
| 455 | + keyMap.get(key).add(m); | ||
| 456 | + } else { | ||
| 457 | + List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); | ||
| 458 | + list.add(m); | ||
| 459 | + keyMap.put(key, list); | ||
| 460 | + keyList.add(key); | ||
| 461 | + } | ||
| 462 | + } | ||
| 463 | + | ||
| 464 | + for(String key : keyList){ | ||
| 465 | + List<Map<String, Object>> list = keyMap.get(key); | ||
| 466 | + | ||
| 467 | + for(String lbType : lbTypes){ | ||
| 468 | + | ||
| 469 | + Map<String, Object> m = new HashMap<String, Object>(); | ||
| 470 | + | ||
| 471 | + m.put("ReportDate", sdf.parse(list.get(0).get("scheduleDate").toString())); | ||
| 472 | + m.put("BusLineCode", list.get(0).get("lineCode")); | ||
| 473 | + m.put("BusLineName", list.get(0).get("lineName")); | ||
| 474 | + m.put("MileageType", lbType); | ||
| 475 | + | ||
| 476 | + if(lineMap.get(list.get(0).get("lineCode").toString()) != null){ | ||
| 477 | + Map<String, Object> map = lineMap.get(list.get(0).get("lineCode")); | ||
| 478 | + String gs = map.get("company")!=null?map.get("company").toString():""; | ||
| 479 | + String fgs = map.get("brancheCompany")!=null?map.get("brancheCompany").toString():""; | ||
| 480 | + m.put("CompanyCode", gs); | ||
| 481 | + m.put("SubCompanyCode", fgs); | ||
| 482 | + m.put("CompanyName", ""); | ||
| 483 | + m.put("SubCompanyName", ""); | ||
| 484 | + | ||
| 485 | + String gsFgsName = getGsFgsName(gs, fgs); | ||
| 486 | + if(gsFgsName.length() > 1){ | ||
| 487 | + String[] split = gsFgsName.split("_"); | ||
| 488 | + if(split.length > 1){ | ||
| 489 | + m.put("CompanyName", split[0]); | ||
| 490 | + m.put("SubCompanyName", split[1]); | ||
| 491 | + } | ||
| 492 | + } | ||
| 493 | + | ||
| 494 | + } else { | ||
| 495 | + continue; | ||
| 496 | + } | ||
| 497 | + | ||
| 498 | + double lblc = 0; | ||
| 499 | + | ||
| 500 | + for(Map<String, Object> temp : list){ | ||
| 501 | + if("true".equals(temp.get("sflj")!=null?temp.get("sflj").toString():"")){ | ||
| 502 | + continue; | ||
| 503 | + } | ||
| 504 | + List<Map<String, Object>> cTasks = (List<Map<String, Object>>)temp.get("cTasks"); | ||
| 505 | + if(cTasks.size() > 0){ | ||
| 506 | + for(Map<String, Object> task : cTasks){ | ||
| 507 | + if("true".equals(task.get("destroy")!=null?task.get("destroy").toString():"")){ | ||
| 508 | + String destroyReason = task.get("destroyReason")!=null?task.get("destroyReason").toString().trim():""; | ||
| 509 | + if("其他".equals(lbType) && destroyReason.length() == 0){ | ||
| 510 | + lblc = Arith.add(lblc, task.get("mileage")==null?0:task.get("mileage")); | ||
| 511 | + } | ||
| 512 | + if(lbType.equals(destroyReason)){ | ||
| 513 | + lblc = Arith.add(lblc, task.get("mileage")==null?0:task.get("mileage")); | ||
| 514 | + } | ||
| 515 | + } | ||
| 516 | + } | ||
| 517 | + } else { | ||
| 518 | + String bcType = temp.get("bcType")!=null?temp.get("bcType").toString():""; | ||
| 519 | + if(bcType.equals("in") || bcType.equals("out") || bcType.equals("ldks")){ | ||
| 520 | + continue; | ||
| 521 | + } | ||
| 522 | + if(temp.get("status") != null && "-1".equals(temp.get("status").toString())){ | ||
| 523 | + String adjustExps = temp.get("adjustExps")!=null?temp.get("adjustExps").toString().trim():""; | ||
| 524 | + if("其他".equals(lbType) && adjustExps.length() == 0){ | ||
| 525 | + lblc = Arith.add(lblc, temp.get("mileage")==null?0:temp.get("mileage")); | ||
| 526 | + } | ||
| 527 | + if(lbType.equals(adjustExps)){ | ||
| 528 | + lblc = Arith.add(lblc, temp.get("mileage")==null?0:temp.get("mileage")); | ||
| 529 | + } | ||
| 530 | + } else if("其他".equals(lbType)){ | ||
| 531 | + String jhlc = temp.get("jhlc")!=null?temp.get("jhlc").toString():"0"; | ||
| 532 | + String jhlcOrig = temp.get("jhlcOrig")!=null?temp.get("jhlcOrig").toString():"0"; | ||
| 533 | + double sub = Arith.sub(jhlcOrig,jhlc); | ||
| 534 | + if(sub > 0){ | ||
| 535 | + lblc = Arith.add(lblc, sub); | ||
| 536 | + } | ||
| 537 | + } | ||
| 538 | + } | ||
| 539 | + } | ||
| 540 | + if(lblc > 0d){ | ||
| 541 | + m.put("Mileage", lblc); | ||
| 542 | + m.put("MileageType", lbType); | ||
| 543 | + | ||
| 544 | + resList.add(m);//2020-08-20:63条 | ||
| 545 | + } | ||
| 546 | + } | ||
| 547 | + } | ||
| 548 | + } | ||
| 549 | + | ||
| 550 | + if(resList.size() > 0){ | ||
| 551 | + List<List<Map<String, Object>>> listGroup = new ArrayList<List<Map<String, Object>>>(); | ||
| 552 | + int size = resList.size(); | ||
| 553 | + int index = 1000; | ||
| 554 | + for(int i = 0; i < size; i += index){ | ||
| 555 | + if(i + index > size){ | ||
| 556 | + index = size - i; | ||
| 557 | + } | ||
| 558 | + List<Map<String, Object>> newList = resList.subList(i, i + index); | ||
| 559 | + listGroup.add(newList); | ||
| 560 | + } | ||
| 561 | + | ||
| 562 | + String json= getHttpInterface("http://180.167.126.126:8992/api/getcode"); | ||
| 563 | + Map<String, Object> map=(Map<String, Object>) JSONObject.parse(json); | ||
| 564 | + String token = encrypt(accessToken, map.get("result").toString()); | ||
| 565 | + String deleteAll = "TRUE"; | ||
| 566 | + | ||
| 567 | + for(List<Map<String, Object>> list : listGroup){ | ||
| 568 | + Map<String, String> header = new HashMap<String, String>(); | ||
| 569 | + header.put("Access-Token", token); | ||
| 570 | + Map<String, Object> param = new HashMap<String, Object>(); | ||
| 571 | +// param.put("AccessToken", token); | ||
| 572 | +// param.put("DeleteAll", deleteAll); | ||
| 573 | +// param.put("DataList", JSON.toJSONString(list)); | ||
| 574 | + param.put("list", URLEncoder.encode(JSON.toJSONStringWithDateFormat(list, "yyyy-MM-dd HH:mm:ss"), "UTF-8")); | ||
| 575 | + HttpUtils.request("http://180.167.126.126:8992/api/busdispatchundonemileage/addEntityList", | ||
| 576 | + new BackClass(), "POST", header, param); | ||
| 577 | + deleteAll = "FALSE"; | ||
| 578 | + } | ||
| 579 | + System.out.println(resList.size()); | ||
| 580 | + logger.info("烂班里程共上传:" + resList.size() + "条"); | ||
| 581 | + } | ||
| 582 | + } | ||
| 583 | + | ||
| 584 | + | ||
| 585 | + public static String getHttpInterface(String path){ | ||
| 586 | + BufferedReader in = null; | ||
| 587 | + StringBuffer result = null; | ||
| 588 | + try { | ||
| 589 | + URL url = new URL(path); | ||
| 590 | + //打开和url之间的连接 | ||
| 591 | + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
| 592 | + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); | ||
| 593 | + connection.setRequestProperty("Charset", "utf-8"); | ||
| 594 | + connection.connect(); | ||
| 595 | + | ||
| 596 | + result = new StringBuffer(); | ||
| 597 | + //读取URL的响应 | ||
| 598 | + in = new BufferedReader(new InputStreamReader( | ||
| 599 | + connection.getInputStream(),"utf-8")); | ||
| 600 | + String line; | ||
| 601 | + while ((line = in.readLine()) != null) { | ||
| 602 | + result.append(line); | ||
| 603 | + } | ||
| 604 | + return result.toString(); | ||
| 605 | + } catch (Exception e) { | ||
| 606 | + e.printStackTrace(); | ||
| 607 | + }finally { | ||
| 608 | + try { | ||
| 609 | + if (in != null) { | ||
| 610 | + in.close(); | ||
| 611 | + } | ||
| 612 | + } catch (Exception e2) { | ||
| 613 | + e2.printStackTrace(); | ||
| 614 | + } | ||
| 615 | + } | ||
| 616 | + return null; | ||
| 617 | + } | ||
| 618 | + | ||
| 619 | + public static String encrypt(String token, String code) throws Exception { | ||
| 620 | + if (token.length() != 32) throw new Exception("token 长度不正确"); | ||
| 621 | + code = padRight(code, 16, '0'); | ||
| 622 | + String tmpToken = ""; | ||
| 623 | + for (int i = 0; i < 8; i++){ | ||
| 624 | + String subString = code.substring(i * 2, (i + 1) * 2); | ||
| 625 | + tmpToken += subString + token.substring(i * 4, (i + 1) * 4); | ||
| 626 | + } | ||
| 627 | + int pos = tmpToken.length() / 2; | ||
| 628 | + tmpToken = tmpToken.substring(pos) + tmpToken.substring(0, pos); | ||
| 629 | + | ||
| 630 | + pos = tmpToken.length() / 4; | ||
| 631 | + tmpToken = tmpToken.substring(pos * 3) + tmpToken.substring(pos, pos * 3) + tmpToken.substring(0, pos); | ||
| 632 | + return URLEncoder.encode(tmpToken, "GBK"); | ||
| 633 | + } | ||
| 634 | + | ||
| 635 | + public static String padRight(String s, int len, char ch){ | ||
| 636 | + int diff = len - s.length(); | ||
| 637 | + if(diff <= 0){ | ||
| 638 | + return s; | ||
| 639 | + } | ||
| 640 | + | ||
| 641 | + char[] charr = new char[len]; | ||
| 642 | + System.arraycopy(s.toCharArray(), 0, charr, 0, s.length()); | ||
| 643 | + for(int i = s.length(); i < len; i++){ | ||
| 644 | + charr[i] = ch; | ||
| 645 | + } | ||
| 646 | + | ||
| 647 | + return new String(charr); | ||
| 648 | + } | ||
| 649 | + | ||
| 650 | + public static String getGsFgsName(String gs, String fgs){ | ||
| 651 | + String gsFgs = ""; | ||
| 652 | + if("22".equals(gs)){ | ||
| 653 | + gsFgs += "金高公司_"; | ||
| 654 | + | ||
| 655 | + if("1".equals(fgs)){ | ||
| 656 | + gsFgs += "四分公司"; | ||
| 657 | + return gsFgs; | ||
| 658 | + } else if("2".equals(fgs)){ | ||
| 659 | + gsFgs += "二分公司"; | ||
| 660 | + return gsFgs; | ||
| 661 | + } else if("3".equals(fgs)){ | ||
| 662 | + gsFgs += "三分公司"; | ||
| 663 | + return gsFgs; | ||
| 664 | + } else if("5".equals(fgs)){ | ||
| 665 | + gsFgs += "一分公司"; | ||
| 666 | + return gsFgs; | ||
| 667 | + } | ||
| 668 | + } else if("26".equals(gs)){ | ||
| 669 | + gsFgs += "南汇公司_"; | ||
| 670 | + | ||
| 671 | + if("1".equals(fgs)){ | ||
| 672 | + gsFgs += "南汇一分"; | ||
| 673 | + return gsFgs; | ||
| 674 | + } else if("2".equals(fgs)){ | ||
| 675 | + gsFgs += "南汇二分"; | ||
| 676 | + return gsFgs; | ||
| 677 | + } else if("3".equals(fgs)){ | ||
| 678 | + gsFgs += "南汇三分"; | ||
| 679 | + return gsFgs; | ||
| 680 | + } else if("4".equals(fgs)){ | ||
| 681 | + gsFgs += "南汇维修公司"; | ||
| 682 | + return gsFgs; | ||
| 683 | + } else if("5".equals(fgs)){ | ||
| 684 | + gsFgs += "南汇公司"; | ||
| 685 | + return gsFgs; | ||
| 686 | + } else if("6".equals(fgs)){ | ||
| 687 | + gsFgs += "南汇六分"; | ||
| 688 | + return gsFgs; | ||
| 689 | + } | ||
| 690 | + } else if("55".equals(gs)){ | ||
| 691 | + gsFgs += "上南公司_"; | ||
| 692 | + | ||
| 693 | + if("1".equals(fgs)){ | ||
| 694 | + gsFgs += "上南二分公司"; | ||
| 695 | + return gsFgs; | ||
| 696 | + } else if("2".equals(fgs)){ | ||
| 697 | + gsFgs += "上南三分公司"; | ||
| 698 | + return gsFgs; | ||
| 699 | + } else if("3".equals(fgs)){ | ||
| 700 | + gsFgs += "上南六分公司"; | ||
| 701 | + return gsFgs; | ||
| 702 | + } else if("4".equals(fgs)){ | ||
| 703 | + gsFgs += "上南一分公司"; | ||
| 704 | + return gsFgs; | ||
| 705 | + } | ||
| 706 | + } else if("05".equals(gs)){ | ||
| 707 | + gsFgs += "杨高公司_"; | ||
| 708 | + | ||
| 709 | + if("1".equals(fgs)){ | ||
| 710 | + gsFgs += "川沙分公司"; | ||
| 711 | + return gsFgs; | ||
| 712 | + } else if("2".equals(fgs)){ | ||
| 713 | + gsFgs += "金桥分公司"; | ||
| 714 | + return gsFgs; | ||
| 715 | + } else if("3".equals(fgs)){ | ||
| 716 | + gsFgs += "芦潮港分公司"; | ||
| 717 | + return gsFgs; | ||
| 718 | + } else if("5".equals(fgs)){ | ||
| 719 | + gsFgs += "杨高分公司"; | ||
| 720 | + return gsFgs; | ||
| 721 | + } else if("6".equals(fgs)){ | ||
| 722 | + gsFgs += "周浦分公司"; | ||
| 723 | + return gsFgs; | ||
| 724 | + } | ||
| 725 | + } | ||
| 726 | + return ""; | ||
| 727 | + } | ||
| 728 | + | ||
| 729 | +} |
src/main/java/com/bsth/serviec_jk/xl_basic/XlBasicService.java
| 1 | -package com.bsth.serviec_jk.xl_basic; | ||
| 2 | - | ||
| 3 | -import com.alibaba.fastjson.JSONObject; | ||
| 4 | -import com.bsth.serviec_jk.JkToken; | ||
| 5 | -import com.bsth.serviec_jk.WebserviceSign; | ||
| 6 | -import com.bsth.utils.HttpUtils; | ||
| 7 | -import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 8 | -import org.apache.tomcat.util.http.fileupload.IOUtils; | ||
| 9 | -import org.slf4j.Logger; | ||
| 10 | -import org.slf4j.LoggerFactory; | ||
| 11 | -import org.springframework.scheduling.annotation.EnableScheduling; | ||
| 12 | -import org.springframework.scheduling.annotation.Scheduled; | ||
| 13 | -import org.springframework.stereotype.Controller; | ||
| 14 | -import org.springframework.transaction.annotation.Transactional; | ||
| 15 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 16 | -import java.io.ByteArrayOutputStream; | ||
| 17 | -import java.io.IOException; | ||
| 18 | -import java.io.InputStream; | ||
| 19 | -import java.net.HttpURLConnection; | ||
| 20 | -import java.net.MalformedURLException; | ||
| 21 | -import java.net.URL; | ||
| 22 | -import java.util.*; | ||
| 23 | -@Controller | ||
| 24 | -@RequestMapping("api") | ||
| 25 | -@EnableScheduling | ||
| 26 | -public class XlBasicService { | ||
| 27 | - | ||
| 28 | - private final static Logger log = LoggerFactory.getLogger(HttpUtils.class); | ||
| 29 | - | ||
| 30 | - //线路基本信息接口 | ||
| 31 | - @Transactional() | ||
| 32 | - @Scheduled(cron = "0 0 1 * * ?") //每天凌晨一点 执行 | ||
| 33 | - public void xlbasic() { | ||
| 34 | - log.info("调用线路基本信息接口开始---------------"); | ||
| 35 | - long startTime=System.currentTimeMillis(); | ||
| 36 | - Map<String,Object> xlmap = new LinkedHashMap<>(); | ||
| 37 | - String url = "http://180.167.126.126:8992/api/buslineinfo/insertlist"; | ||
| 38 | - try{ | ||
| 39 | - String password = "6DABD12209BEDAB0808CF7DC967EC2B4C6748277"; | ||
| 40 | - String timestamp = String.valueOf(System.currentTimeMillis()); | ||
| 41 | - String nonce = WebserviceSign.getRandomString(5); | ||
| 42 | - Map<String, String> map = new HashMap<String, String>(); | ||
| 43 | - map.put("timestamp", timestamp);//时间戳 | ||
| 44 | - map.put("nonce", nonce);//随机字符串 | ||
| 45 | - map.put("password", password);//密码 | ||
| 46 | - String signStr = WebserviceSign.getSHA1(map); | ||
| 47 | - String endpoint = "http://114.80.178.12:9089/webservice/rest/line/all?timestamp="+timestamp+"&nonce="+nonce+"&password="+password+"&sign="+signStr; | ||
| 48 | - InputStream in = null; | ||
| 49 | - try { | ||
| 50 | - HttpURLConnection con = (HttpURLConnection)new URL(endpoint).openConnection(); | ||
| 51 | - con.setDoInput(true); | ||
| 52 | - con.setDoOutput(true); | ||
| 53 | - con.setRequestMethod("GET"); | ||
| 54 | - con.setConnectTimeout(5000); | ||
| 55 | - con.setReadTimeout(5000); | ||
| 56 | - con.setRequestProperty("keep-alive", "true"); | ||
| 57 | - con.setRequestProperty("accept", "application/json"); | ||
| 58 | - con.setRequestProperty("content-type", "application/json"); | ||
| 59 | - if (con.getResponseCode() == 200) { | ||
| 60 | - in = con.getInputStream(); | ||
| 61 | - ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 62 | - IOUtils.copy(in, bout); | ||
| 63 | - List m = new ObjectMapper().readValue(bout.toByteArray(), List.class); | ||
| 64 | - String token = JkToken.jkdata(); | ||
| 65 | - xlmap.put("AccessToken", token); | ||
| 66 | - xlmap.put("DeleteAll", "true"); | ||
| 67 | - Map stmap = new LinkedHashMap(); | ||
| 68 | - List numlist = new ArrayList(); | ||
| 69 | - for (Object o:m){ | ||
| 70 | - Map ke = (Map)o; | ||
| 71 | - //替换key | ||
| 72 | - stmap.put("BusLineCode", ke.get("lineCode")); | ||
| 73 | - stmap.put("BusLineName", ke.get("name")); | ||
| 74 | - stmap.put("BusLineEngName", null); | ||
| 75 | - stmap.put("BusLineShortName", null); | ||
| 76 | - stmap.put("CompanyCode", null); | ||
| 77 | - stmap.put("CompanyName", ke.get("company")); | ||
| 78 | - stmap.put("SubCompanyCode", null); | ||
| 79 | - stmap.put("SubCompanyName", ke.get("brancheCompany")); | ||
| 80 | - stmap.put("StartDate", null); | ||
| 81 | - stmap.put("linePlayType", null); | ||
| 82 | - stmap.put("BusLinePropertyCode", ke.get("nature")); | ||
| 83 | - stmap.put("BusLineGradeCode", ke.get("level")); | ||
| 84 | - stmap.put("CompanyContacts", null); | ||
| 85 | - stmap.put("ContactsPhone", null); | ||
| 86 | - stmap.put("BusLineLeader", null); | ||
| 87 | - stmap.put("LeaderPhone", null); | ||
| 88 | - stmap.put("ParentBusLineCode", null); | ||
| 89 | - stmap.put("UpFirstTime", null); | ||
| 90 | - stmap.put("UpLastTime", null); | ||
| 91 | - stmap.put("StartingStation", ke.get("startStationName")); | ||
| 92 | - stmap.put("DnFirstTime", null); | ||
| 93 | - stmap.put("DnLastTime", null); | ||
| 94 | - stmap.put("EndStation", ke.get("endStationName")); | ||
| 95 | - stmap.put("CrossRegion", null); | ||
| 96 | - stmap.put("Remark", null); | ||
| 97 | - stmap.put("TiceSeller", null); | ||
| 98 | - stmap.put("RunTime", null); | ||
| 99 | - stmap.put("ParkCode", null); | ||
| 100 | - stmap.put("ParkName", null); | ||
| 101 | - stmap.put("VehicleConfigurationNum", null); | ||
| 102 | - stmap.put("RoadVector", null); | ||
| 103 | - stmap.put("EquipmentLineCode", ke.get("eqLinecode")); | ||
| 104 | - stmap.put("RouteEvolution", null); | ||
| 105 | - stmap.put("AirConditionedVehiclesNum", null); | ||
| 106 | - stmap.put("LineLength", null); | ||
| 107 | - stmap.put("OrdinaryVehiclesNum", null); | ||
| 108 | - stmap.put("RoutePlanningType", null); | ||
| 109 | - stmap.put("ShangHaiLineCode", null); | ||
| 110 | - stmap.put("IsNightTrain", ke.get("supperLine")); | ||
| 111 | - stmap.put("WarrantBusNum", null); | ||
| 112 | - stmap.put("WarrantBusDate", null); | ||
| 113 | - stmap.put("IsInUse", ke.get("destroy")); | ||
| 114 | - stmap.put("IsOperate", null); | ||
| 115 | - stmap.put("LargeIntervalLevel", null); | ||
| 116 | - numlist.add(stmap); | ||
| 117 | - stmap = new LinkedHashMap(); | ||
| 118 | - } | ||
| 119 | - xlmap.put("DataList", numlist); | ||
| 120 | - int count = 1; | ||
| 121 | - if (numlist.size() == 0) { | ||
| 122 | - return; | ||
| 123 | - } | ||
| 124 | - if (null != numlist && numlist.size() > 1000) { | ||
| 125 | - | ||
| 126 | - for (int i = 0; i < numlist.size(); ) { | ||
| 127 | - if (count > 1) { | ||
| 128 | - xlmap.put("DeleteAll", "false"); | ||
| 129 | - } | ||
| 130 | - if (numlist.size() > i + 1000) { | ||
| 131 | - log.info("第" + count + "次调用-----------"); | ||
| 132 | - xlmap.put("DataList", numlist.subList(i, i + 1000)); | ||
| 133 | - JSONObject json = new JSONObject(xlmap); | ||
| 134 | - int resultCount = HttpService.httpRequestResult(json, token, url, count); | ||
| 135 | - } else { | ||
| 136 | - log.info("第" + count + "次调用-----------"); | ||
| 137 | - xlmap.put("DataList", numlist.subList(i, numlist.size())); | ||
| 138 | - JSONObject json = new JSONObject(xlmap); | ||
| 139 | - int resultCount = HttpService.httpRequestResult(json, token, url, count); | ||
| 140 | - } | ||
| 141 | - i = i + 1000; | ||
| 142 | - count++; | ||
| 143 | - | ||
| 144 | - } | ||
| 145 | - } else { | ||
| 146 | - xlmap.put("DataList", numlist.subList(0, numlist.size())); | ||
| 147 | - JSONObject json = new JSONObject(xlmap); | ||
| 148 | - int resultCount = HttpService.httpRequestResult(json, token, url, count); | ||
| 149 | - } | ||
| 150 | - long endTime=System.currentTimeMillis(); | ||
| 151 | - log.info("调用线路基本信息插入接口结束---------------共计执行时间:"+(endTime-startTime)); | ||
| 152 | - } | ||
| 153 | - } catch (MalformedURLException e) { | ||
| 154 | - // TODO Auto-generated catch block | ||
| 155 | - e.printStackTrace(); | ||
| 156 | - } catch (IOException e) { | ||
| 157 | - // TODO Auto-generated catch block | ||
| 158 | - e.printStackTrace(); | ||
| 159 | - } | ||
| 160 | - }catch(Exception e){ | ||
| 161 | - e.printStackTrace(); | ||
| 162 | - } | ||
| 163 | - } | ||
| 164 | - | ||
| 165 | - //线路参数信息接口 | ||
| 166 | - @Transactional() | ||
| 167 | - @Scheduled(cron = "0 0 1 * * ?")//每天凌晨一点 执行 | ||
| 168 | - public void xlparameter(){ | ||
| 169 | - log.info("调用线路参数信息接口开始---------------"); | ||
| 170 | - long startTime=System.currentTimeMillis(); | ||
| 171 | - String url = "http://180.167.126.126:8992/api/buslineparmterinfo/insertlist"; | ||
| 172 | - Map<String,Object> xlmap = new HashMap<>(); | ||
| 173 | - try{ | ||
| 174 | - String password = "6DABD12209BEDAB0808CF7DC967EC2B4C6748277"; | ||
| 175 | - String timestamp = String.valueOf(System.currentTimeMillis()); | ||
| 176 | - String nonce = WebserviceSign.getRandomString(5); | ||
| 177 | - Map<String, String> map = new HashMap<String, String>(); | ||
| 178 | - map.put("timestamp", timestamp);//时间戳 | ||
| 179 | - map.put("nonce", nonce);//随机字符串 | ||
| 180 | - map.put("password", password);//密码 | ||
| 181 | - String signStr = WebserviceSign.getSHA1(map); | ||
| 182 | - String endpoint = "http://114.80.178.12:9089/webservice/rest/line/all?timestamp="+timestamp+"&nonce="+nonce+"&password="+password+"&sign="+signStr; | ||
| 183 | - InputStream in = null; | ||
| 184 | - try { | ||
| 185 | - HttpURLConnection con = (HttpURLConnection)new URL(endpoint).openConnection(); | ||
| 186 | - con.setDoInput(true); | ||
| 187 | - con.setDoOutput(true); | ||
| 188 | - con.setRequestMethod("GET"); | ||
| 189 | - con.setConnectTimeout(5000); | ||
| 190 | - con.setReadTimeout(5000); | ||
| 191 | - con.setRequestProperty("keep-alive", "true"); | ||
| 192 | - con.setRequestProperty("accept", "application/json"); | ||
| 193 | - con.setRequestProperty("content-type", "application/json"); | ||
| 194 | - | ||
| 195 | - if (con.getResponseCode() == 200) { | ||
| 196 | - in = con.getInputStream(); | ||
| 197 | - ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 198 | - IOUtils.copy(in, bout); | ||
| 199 | - Map stmap = new LinkedHashMap(); | ||
| 200 | - List m = new ObjectMapper().readValue(bout.toByteArray(), List.class); | ||
| 201 | - List numlist = new ArrayList(); | ||
| 202 | - for (Object o:m){ | ||
| 203 | - Map ke = (Map)o; | ||
| 204 | - stmap.put("BusLineCode",ke.get("lineCode")); | ||
| 205 | - stmap.put("UpKilometer",null); | ||
| 206 | - stmap.put("DnKilometer",null); | ||
| 207 | - stmap.put("MPBegTime",null); | ||
| 208 | - stmap.put("MPEndTime",null); | ||
| 209 | - stmap.put("EPBegTime",null); | ||
| 210 | - stmap.put("EPEndTime",null); | ||
| 211 | - stmap.put("SNPBegTime",null); | ||
| 212 | - stmap.put("SNPEndTime",null); | ||
| 213 | - stmap.put("MPUpTravelTime",null); | ||
| 214 | - stmap.put("MPDnTravelTime",null); | ||
| 215 | - stmap.put("EPUpTravelTime",null); | ||
| 216 | - stmap.put("EPDnTravelTime",null); | ||
| 217 | - stmap.put("SNPUpTravelTime",null); | ||
| 218 | - stmap.put("SNPDnTravelTime",null); | ||
| 219 | - stmap.put("LowUpTravelTime",null); | ||
| 220 | - stmap.put("LowDnTravelTime",null); | ||
| 221 | - stmap.put("StartingToParkTime",null); | ||
| 222 | - stmap.put("StartingToParkKilometer",null); | ||
| 223 | - stmap.put("LastingToParkTime",null); | ||
| 224 | - stmap.put("LastingToParkKilometer",null); | ||
| 225 | - stmap.put("MPLargeMargin",ke.get("earlyIntervalLg")); | ||
| 226 | - stmap.put("EPLargeMargin",ke.get("lateIntervalLg")); | ||
| 227 | - stmap.put("LowLargeMargin",ke.get("intervalLg")); | ||
| 228 | - stmap.put("MaxOverSpeed",null); | ||
| 229 | - stmap.put("OverStopTime",ke.get("lagStation")); | ||
| 230 | - stmap.put("LessStopTime",ke.get("skip")); | ||
| 231 | - stmap.put("BusMaxGather",null); | ||
| 232 | - stmap.put("DeleteFlag",ke.get("destroy")); | ||
| 233 | - stmap.put("Remark",null); | ||
| 234 | - stmap.put("SpeedNormal",ke.get("speedLimit")); | ||
| 235 | - stmap.put("SpeedRain",null); | ||
| 236 | - stmap.put("SpeedDenseFog",null); | ||
| 237 | - stmap.put("SpeedIce",null); | ||
| 238 | - stmap.put("SpeedFestival",null); | ||
| 239 | - stmap.put("Speeding",ke.get("speeding")); | ||
| 240 | - stmap.put("String",ke.get("crossedLine")); | ||
| 241 | - stmap.put("Transboundary",ke.get("overflights")); | ||
| 242 | - stmap.put("describe",null); | ||
| 243 | - stmap.put("ParkingLot",null); | ||
| 244 | - stmap.put("FromMileage",null); | ||
| 245 | - stmap.put("OutTime",null); | ||
| 246 | - stmap.put("ProcessionMileage",null); | ||
| 247 | - numlist.add(stmap); | ||
| 248 | - stmap = new LinkedHashMap(); | ||
| 249 | - } | ||
| 250 | - String token = JkToken.jkdata(); | ||
| 251 | - xlmap.put("AccessToken",token); | ||
| 252 | - xlmap.put("DeleteAll","true"); | ||
| 253 | - xlmap.put("DataList",numlist); | ||
| 254 | - int count = 1; | ||
| 255 | - if (numlist.size() == 0) { | ||
| 256 | - return; | ||
| 257 | - } | ||
| 258 | - if (null != numlist && numlist.size() > 1000) { | ||
| 259 | - | ||
| 260 | - for (int i = 0; i < numlist.size(); ) { | ||
| 261 | - if (count > 1) { | ||
| 262 | - xlmap.put("DeleteAll", "false"); | ||
| 263 | - } | ||
| 264 | - if (numlist.size() > i + 1000) { | ||
| 265 | - log.info("第" + count + "次调用-----------"); | ||
| 266 | - xlmap.put("DataList", numlist.subList(i, i + 1000)); | ||
| 267 | - JSONObject json = new JSONObject(xlmap); | ||
| 268 | - int resultCount = HttpService.httpRequestResult(json, token, url, count); | ||
| 269 | - } else { | ||
| 270 | - log.info("第" + count + "次调用-----------"); | ||
| 271 | - xlmap.put("DataList", numlist.subList(i, numlist.size())); | ||
| 272 | - JSONObject json = new JSONObject(xlmap); | ||
| 273 | - int resultCount = HttpService.httpRequestResult(json, token, url, count); | ||
| 274 | - } | ||
| 275 | - i = i + 1000; | ||
| 276 | - count++; | ||
| 277 | - } | ||
| 278 | - } else { | ||
| 279 | - xlmap.put("DataList", numlist.subList(0, numlist.size())); | ||
| 280 | - JSONObject json = new JSONObject(xlmap); | ||
| 281 | - int resultCount = HttpService.httpRequestResult(json, token, url, count); | ||
| 282 | - } | ||
| 283 | - long endTime=System.currentTimeMillis(); | ||
| 284 | - log.info("调用线路参数信息插入接口结束---------------共计执行时间:"+(endTime-startTime)); | ||
| 285 | - } | ||
| 286 | - } catch (MalformedURLException e) { | ||
| 287 | - // TODO Auto-generated catch block | ||
| 288 | - e.printStackTrace(); | ||
| 289 | - } catch (IOException e) { | ||
| 290 | - // TODO Auto-generated catch block | ||
| 291 | - e.printStackTrace(); | ||
| 292 | - } | ||
| 293 | - }catch(Exception e){ | ||
| 294 | - e.printStackTrace(); | ||
| 295 | - } | ||
| 296 | - } | ||
| 297 | - | ||
| 298 | - ////线路走向接口 | ||
| 299 | - @Transactional() | ||
| 300 | - @Scheduled(cron = "0 0 1 * * ?")//每天凌晨一点 执行 | ||
| 301 | - public void postrend(){ | ||
| 302 | - log.info("调用线路走向接口开始---------------"); | ||
| 303 | - long startTime=System.currentTimeMillis(); | ||
| 304 | - Map<String,Object> xlmap = new HashMap<>(); | ||
| 305 | - List numlist = new ArrayList(); | ||
| 306 | - String url="http://180.167.126.126:8992/api/stationnetpoints/insertlist"; | ||
| 307 | - try{ | ||
| 308 | - String password = "6DABD12209BEDAB0808CF7DC967EC2B4C6748277"; | ||
| 309 | - String timestamp = String.valueOf(System.currentTimeMillis()); | ||
| 310 | - String nonce = WebserviceSign.getRandomString(5); | ||
| 311 | - Map<String, String> map = new HashMap<String, String>(); | ||
| 312 | - map.put("timestamp", timestamp);//时间戳 | ||
| 313 | - map.put("nonce", nonce);//随机字符串 | ||
| 314 | - map.put("password", password);//密码 | ||
| 315 | - String signStr = WebserviceSign.getSHA1(map); | ||
| 316 | - List list = new ArrayList(); | ||
| 317 | - list.add("22");//四家公司 | ||
| 318 | - list.add("26"); | ||
| 319 | - list.add("55"); | ||
| 320 | - list.add("05"); | ||
| 321 | - try { | ||
| 322 | - for (Object t:list ) { | ||
| 323 | - String endpoint = "http://114.80.178.12:9089/webservice/rest/ld_section/"+t+"?timestamp=" + timestamp + "&nonce=" + nonce + "&password=" + password + "&sign=" + signStr; | ||
| 324 | - InputStream in = null; | ||
| 325 | - HttpURLConnection con = (HttpURLConnection) new URL(endpoint).openConnection(); | ||
| 326 | - con.setDoInput(true); | ||
| 327 | - con.setDoOutput(true); | ||
| 328 | - con.setRequestMethod("GET"); | ||
| 329 | - con.setConnectTimeout(5000); | ||
| 330 | - con.setReadTimeout(5000); | ||
| 331 | - con.setRequestProperty("keep-alive", "true"); | ||
| 332 | - con.setRequestProperty("accept", "application/json"); | ||
| 333 | - con.setRequestProperty("content-type", "application/json"); | ||
| 334 | - | ||
| 335 | - if (con.getResponseCode() == 200) { | ||
| 336 | - in = con.getInputStream(); | ||
| 337 | - ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 338 | - IOUtils.copy(in, bout); | ||
| 339 | - Map stmap = new LinkedHashMap(); | ||
| 340 | - Map m = new ObjectMapper().readValue(bout.toByteArray(), Map.class); | ||
| 341 | - Map<String, Object> numMap = new LinkedHashMap<>(); | ||
| 342 | - List n = new ArrayList(); | ||
| 343 | - for (Object key : m.keySet()) { | ||
| 344 | - List lit = (List) m.get(key); | ||
| 345 | - Map st = (Map) lit.get(0); | ||
| 346 | - Map section = (Map) st.get("section"); | ||
| 347 | - numMap.put("BusLineCode", st.get("lineCode")); | ||
| 348 | - numMap.put("BusLineName", null); | ||
| 349 | - numMap.put("Directions", st.get("directions")); | ||
| 350 | - numMap.put("DirIndex ", st.get("sectionrouteCode")); | ||
| 351 | - String lay[] = zbd(section.get("gsectionVector").toString()); | ||
| 352 | - if(lay != null) { //坐标类型问题传不过去 传null | ||
| 353 | - numMap.put("LongitudeX", String.format("%.8f", Double.parseDouble(lay[0]))); | ||
| 354 | - numMap.put("LatitudeY", String.format("%.8f", Double.parseDouble(lay[1]))); | ||
| 355 | - }else { | ||
| 356 | - numMap.put("LongitudeX", null); | ||
| 357 | - numMap.put("LatitudeY", null); | ||
| 358 | - } | ||
| 359 | - numlist.add(numMap); | ||
| 360 | - numMap = new LinkedHashMap<>(); | ||
| 361 | - } | ||
| 362 | - } | ||
| 363 | - } | ||
| 364 | - String token = JkToken.jkdata(); | ||
| 365 | - xlmap.put("AccessToken",token); | ||
| 366 | - xlmap.put("DeleteAll","true"); | ||
| 367 | - xlmap.put("DataList",numlist); | ||
| 368 | - | ||
| 369 | - int count=1; | ||
| 370 | - if(numlist.size()==0){ | ||
| 371 | - return; | ||
| 372 | - } | ||
| 373 | - if(null !=numlist && numlist.size()>1000){ | ||
| 374 | - | ||
| 375 | - for (int i = 0; i <numlist.size() ; ) { | ||
| 376 | - if(count > 1){ | ||
| 377 | - xlmap.put("DeleteAll","false"); | ||
| 378 | - } | ||
| 379 | - if(numlist.size()> i + 1000){ | ||
| 380 | - log.info("第"+count+"次调用-----------"); | ||
| 381 | - xlmap.put("DataList",numlist.subList(i,i+1000)); | ||
| 382 | - JSONObject json = new JSONObject(xlmap); | ||
| 383 | - int resultCount= HttpService.httpRequestResult(json,token,url,count); | ||
| 384 | - }else { | ||
| 385 | - log.info("第"+count+"次调用-----------"); | ||
| 386 | - xlmap.put("DataList",numlist.subList(i,numlist.size())); | ||
| 387 | - JSONObject json = new JSONObject(xlmap); | ||
| 388 | - int resultCount= HttpService.httpRequestResult(json,token,url,count); | ||
| 389 | - } | ||
| 390 | - i=i+1000; | ||
| 391 | - count++; | ||
| 392 | - } | ||
| 393 | - }else { | ||
| 394 | - xlmap.put("DataList",numlist.subList(0,numlist.size())); | ||
| 395 | - JSONObject json = new JSONObject(xlmap); | ||
| 396 | - int resultCount= HttpService.httpRequestResult(json,token,url,count); | ||
| 397 | - } | ||
| 398 | - long endTime=System.currentTimeMillis(); | ||
| 399 | - log.info("调用线路走向插入接口结束---------------共计执行时间:"+(endTime-startTime)); | ||
| 400 | - } catch (MalformedURLException e) { | ||
| 401 | - // TODO Auto-generated catch block | ||
| 402 | - e.printStackTrace(); | ||
| 403 | - } catch (IOException e) { | ||
| 404 | - // TODO Auto-generated catch block | ||
| 405 | - e.printStackTrace(); | ||
| 406 | - } | ||
| 407 | - }catch(Exception e){ | ||
| 408 | - e.printStackTrace(); | ||
| 409 | - } | ||
| 410 | - } | ||
| 411 | - | ||
| 412 | - //查询线路停靠站信息接口 | ||
| 413 | - @Transactional() | ||
| 414 | - @Scheduled(cron = "0 0 1 * * ?")//每天凌晨一点 执行 | ||
| 415 | - public void site(){ | ||
| 416 | - log.info("调用线路停靠站信息接口开始---------------"); | ||
| 417 | - long startTime=System.currentTimeMillis(); | ||
| 418 | - Map<String,Object> xlmap = new HashMap<>(); | ||
| 419 | - List numlist = new ArrayList(); | ||
| 420 | - String url="http://180.167.126.126:8992/api/buslinenetstation/insertlist"; | ||
| 421 | - try{ | ||
| 422 | - String password = "6DABD12209BEDAB0808CF7DC967EC2B4C6748277"; | ||
| 423 | - String timestamp = String.valueOf(System.currentTimeMillis()); | ||
| 424 | - String nonce = WebserviceSign.getRandomString(5); | ||
| 425 | - Map<String, String> map = new HashMap<String, String>(); | ||
| 426 | - map.put("timestamp", timestamp);//时间戳 | ||
| 427 | - map.put("nonce", nonce);//随机字符串 | ||
| 428 | - map.put("password", password);//密码 | ||
| 429 | - String signStr = WebserviceSign.getSHA1(map); | ||
| 430 | - List list = new ArrayList(); | ||
| 431 | - list.add("22"); list.add("26"); list.add("55"); list.add("05"); //四家公司 | ||
| 432 | - try { | ||
| 433 | - for (Object t:list ) { | ||
| 434 | - String endpoint = "http://114.80.178.12:9089/webservice/rest/station/" + t + "?timestamp=" + timestamp + "&nonce=" + nonce + "&password=" + password + "&sign=" + signStr; | ||
| 435 | - InputStream in = null; | ||
| 436 | - HttpURLConnection con = (HttpURLConnection) new URL(endpoint).openConnection(); | ||
| 437 | - con.setDoInput(true); | ||
| 438 | - con.setDoOutput(true); | ||
| 439 | - con.setRequestMethod("GET"); | ||
| 440 | - con.setConnectTimeout(5000); | ||
| 441 | - con.setReadTimeout(5000); | ||
| 442 | - con.setRequestProperty("keep-alive", "true"); | ||
| 443 | - con.setRequestProperty("accept", "application/json"); | ||
| 444 | - con.setRequestProperty("content-type", "application/json"); | ||
| 445 | - if (con.getResponseCode() == 200) { | ||
| 446 | - in = con.getInputStream(); | ||
| 447 | - ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 448 | - IOUtils.copy(in, bout); | ||
| 449 | - Map m = new ObjectMapper().readValue(bout.toByteArray(), Map.class); | ||
| 450 | - Map<String, Object> numMap = new LinkedHashMap<>(); | ||
| 451 | - for (Object key : m.keySet()) { | ||
| 452 | - List lit = (List) m.get(key); | ||
| 453 | - for (Object o : lit) { | ||
| 454 | - Map st = (Map) o; | ||
| 455 | - Map station = (Map) st.get("station"); | ||
| 456 | - numMap.put("BusLineCode", st.get("lineCode")); | ||
| 457 | - numMap.put("BusLineName", 0); | ||
| 458 | - numMap.put("Directions", 0); | ||
| 459 | - numMap.put("DirIndex", 0); | ||
| 460 | - numMap.put("StationCode ", st.get("stationCode")); | ||
| 461 | - numMap.put("StationName", st.get("stationName")); | ||
| 462 | - if (st.get("stationMark").equals("B")) { | ||
| 463 | - numMap.put("StationTypeCode", 1); | ||
| 464 | - } else if (st.get("stationMark").equals("E")) { | ||
| 465 | - numMap.put("StationTypeCode", 2); | ||
| 466 | - } else { | ||
| 467 | - numMap.put("StationTypeCode", 0); | ||
| 468 | - } | ||
| 469 | - numMap.put("StationEngName", 0); | ||
| 470 | - numMap.put("StationAddress", st.get("stationName")); | ||
| 471 | - if (station != null) { | ||
| 472 | - numMap.put("LongitudeX", station.get("lon")); | ||
| 473 | - numMap.put("LatitudeY", station.get("lat")); | ||
| 474 | - } else { | ||
| 475 | - numMap.put("LongitudeX", 0); | ||
| 476 | - numMap.put("LatitudeY", 0); | ||
| 477 | - } | ||
| 478 | - numMap.put("FirstTime", st.get("firstTime")); | ||
| 479 | - numMap.put("LastTime", st.get("endTime")); | ||
| 480 | - numMap.put("OperateTimes", 0); | ||
| 481 | - numlist.add(numMap); | ||
| 482 | - numMap = new LinkedHashMap<>(); | ||
| 483 | - } | ||
| 484 | - } | ||
| 485 | - } | ||
| 486 | - } | ||
| 487 | - String token = JkToken.jkdata(); | ||
| 488 | - xlmap.put("AccessToken",token); | ||
| 489 | - xlmap.put("DeleteAll","true"); | ||
| 490 | - xlmap.put("DataList",numlist); | ||
| 491 | - int count = 1; | ||
| 492 | - if(numlist.size() == 0){ | ||
| 493 | - return; | ||
| 494 | - } | ||
| 495 | - if(null !=numlist && numlist.size() > 1000){ | ||
| 496 | - | ||
| 497 | - for (int i = 0; i < numlist.size() ; ) { | ||
| 498 | - if(count > 1){ | ||
| 499 | - xlmap.put("DeleteAll","false"); | ||
| 500 | - } | ||
| 501 | - if(numlist.size() > i + 1000){ | ||
| 502 | - log.info("第"+count+"次调用-----------"); | ||
| 503 | - xlmap.put("DataList",numlist.subList(i,i+1000)); | ||
| 504 | - JSONObject json = new JSONObject(xlmap); | ||
| 505 | - int resultCount= HttpService.httpRequestResult(json,token,url,count); | ||
| 506 | - }else { | ||
| 507 | - log.info("第"+count+"次调用-----------"); | ||
| 508 | - xlmap.put("DataList",numlist.subList(i,numlist.size())); | ||
| 509 | - JSONObject json = new JSONObject(xlmap); | ||
| 510 | - int resultCount= HttpService.httpRequestResult(json,token,url,count); | ||
| 511 | - } | ||
| 512 | - i = i + 1000; | ||
| 513 | - count++; | ||
| 514 | - | ||
| 515 | - } | ||
| 516 | - }else { | ||
| 517 | - xlmap.put("DataList",numlist.subList(0,numlist.size())); | ||
| 518 | - JSONObject json = new JSONObject(xlmap); | ||
| 519 | - int resultCount= HttpService.httpRequestResult(json,token,url,count); | ||
| 520 | - } | ||
| 521 | - long endTime=System.currentTimeMillis(); | ||
| 522 | - log.info("调用线路停靠站信息插入接口结束---------------共计执行时间:"+(endTime-startTime)); | ||
| 523 | - | ||
| 524 | - } catch (MalformedURLException e) { | ||
| 525 | - // TODO Auto-generated catch block | ||
| 526 | - e.printStackTrace(); | ||
| 527 | - } catch (IOException e) { | ||
| 528 | - // TODO Auto-generated catch block | ||
| 529 | - e.printStackTrace(); | ||
| 530 | - } | ||
| 531 | - }catch(Exception e){ | ||
| 532 | - e.printStackTrace(); | ||
| 533 | - } | ||
| 534 | - } | ||
| 535 | - | ||
| 536 | - //线路走向坐标类型转换格式 | ||
| 537 | - public static String[] zbd(String gsectionVector){ | ||
| 538 | - String longStr = new String(gsectionVector.replaceAll("[^\\d,. ]+", "")); | ||
| 539 | - String [] loglat = longStr.split(","); | ||
| 540 | - String lay =""; | ||
| 541 | - lay+=loglat[loglat.length-1]; | ||
| 542 | - String [] la = loglat = lay.split(" "); | ||
| 543 | - return la; | ||
| 544 | - } | ||
| 545 | - | ||
| 546 | - | ||
| 547 | -} | 1 | +package com.bsth.serviec_jk.xl_basic; |
| 2 | + | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import com.bsth.serviec_jk.JkToken; | ||
| 5 | +import com.bsth.serviec_jk.WebserviceSign; | ||
| 6 | +import com.bsth.utils.HttpUtils; | ||
| 7 | +import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 8 | +import org.apache.tomcat.util.http.fileupload.IOUtils; | ||
| 9 | +import org.slf4j.Logger; | ||
| 10 | +import org.slf4j.LoggerFactory; | ||
| 11 | +import org.springframework.scheduling.annotation.EnableScheduling; | ||
| 12 | +import org.springframework.scheduling.annotation.Scheduled; | ||
| 13 | +import org.springframework.stereotype.Controller; | ||
| 14 | +import org.springframework.transaction.annotation.Transactional; | ||
| 15 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 16 | +import java.io.ByteArrayOutputStream; | ||
| 17 | +import java.io.IOException; | ||
| 18 | +import java.io.InputStream; | ||
| 19 | +import java.net.HttpURLConnection; | ||
| 20 | +import java.net.MalformedURLException; | ||
| 21 | +import java.net.URL; | ||
| 22 | +import java.util.*; | ||
| 23 | +@Controller | ||
| 24 | +@RequestMapping("api") | ||
| 25 | +@EnableScheduling | ||
| 26 | +public class XlBasicService { | ||
| 27 | + | ||
| 28 | + private final static Logger log = LoggerFactory.getLogger(HttpUtils.class); | ||
| 29 | + | ||
| 30 | +// private final static String ip = "114.80.178.12:9089"; | ||
| 31 | + private final static String ip = "10.10.150.24:9089"; | ||
| 32 | + | ||
| 33 | + //线路基本信息接口 | ||
| 34 | + @Transactional() | ||
| 35 | + @Scheduled(cron = "0 0 1 * * ?") //每天凌晨一点 执行 | ||
| 36 | + public void xlbasic() { | ||
| 37 | + log.info("调用线路基本信息接口开始---------------"); | ||
| 38 | + long startTime=System.currentTimeMillis(); | ||
| 39 | + Map<String,Object> xlmap = new LinkedHashMap<>(); | ||
| 40 | + String url = "http://180.167.126.126:8992/api/buslineinfo/insertlist"; | ||
| 41 | + try{ | ||
| 42 | + String password = "6DABD12209BEDAB0808CF7DC967EC2B4C6748277"; | ||
| 43 | + String timestamp = String.valueOf(System.currentTimeMillis()); | ||
| 44 | + String nonce = WebserviceSign.getRandomString(5); | ||
| 45 | + Map<String, String> map = new HashMap<String, String>(); | ||
| 46 | + map.put("timestamp", timestamp);//时间戳 | ||
| 47 | + map.put("nonce", nonce);//随机字符串 | ||
| 48 | + map.put("password", password);//密码 | ||
| 49 | + String signStr = WebserviceSign.getSHA1(map); | ||
| 50 | + String endpoint = "http://"+ip+"/webservice/rest/line/all?timestamp="+timestamp+"&nonce="+nonce+"&password="+password+"&sign="+signStr; | ||
| 51 | + InputStream in = null; | ||
| 52 | + try { | ||
| 53 | + HttpURLConnection con = (HttpURLConnection)new URL(endpoint).openConnection(); | ||
| 54 | + con.setDoInput(true); | ||
| 55 | + con.setDoOutput(true); | ||
| 56 | + con.setRequestMethod("GET"); | ||
| 57 | + con.setConnectTimeout(5000); | ||
| 58 | + con.setReadTimeout(5000); | ||
| 59 | + con.setRequestProperty("keep-alive", "true"); | ||
| 60 | + con.setRequestProperty("accept", "application/json"); | ||
| 61 | + con.setRequestProperty("content-type", "application/json"); | ||
| 62 | + if (con.getResponseCode() == 200) { | ||
| 63 | + in = con.getInputStream(); | ||
| 64 | + ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 65 | + IOUtils.copy(in, bout); | ||
| 66 | + List m = new ObjectMapper().readValue(bout.toByteArray(), List.class); | ||
| 67 | + String token = JkToken.jkdata(); | ||
| 68 | + xlmap.put("AccessToken", token); | ||
| 69 | + xlmap.put("DeleteAll", "true"); | ||
| 70 | + Map stmap = new LinkedHashMap(); | ||
| 71 | + List numlist = new ArrayList(); | ||
| 72 | + for (Object o:m){ | ||
| 73 | + Map ke = (Map)o; | ||
| 74 | + //替换key | ||
| 75 | + stmap.put("BusLineCode", ke.get("lineCode")); | ||
| 76 | + stmap.put("BusLineName", ke.get("name")); | ||
| 77 | + stmap.put("BusLineEngName", null); | ||
| 78 | + stmap.put("BusLineShortName", null); | ||
| 79 | + stmap.put("CompanyCode", null); | ||
| 80 | + stmap.put("CompanyName", ke.get("company")); | ||
| 81 | + stmap.put("SubCompanyCode", null); | ||
| 82 | + stmap.put("SubCompanyName", ke.get("brancheCompany")); | ||
| 83 | + stmap.put("StartDate", null); | ||
| 84 | + stmap.put("linePlayType", null); | ||
| 85 | + stmap.put("BusLinePropertyCode", ke.get("nature")); | ||
| 86 | + stmap.put("BusLineGradeCode", ke.get("level")); | ||
| 87 | + stmap.put("CompanyContacts", null); | ||
| 88 | + stmap.put("ContactsPhone", null); | ||
| 89 | + stmap.put("BusLineLeader", null); | ||
| 90 | + stmap.put("LeaderPhone", null); | ||
| 91 | + stmap.put("ParentBusLineCode", null); | ||
| 92 | + stmap.put("UpFirstTime", null); | ||
| 93 | + stmap.put("UpLastTime", null); | ||
| 94 | + stmap.put("StartingStation", ke.get("startStationName")); | ||
| 95 | + stmap.put("DnFirstTime", null); | ||
| 96 | + stmap.put("DnLastTime", null); | ||
| 97 | + stmap.put("EndStation", ke.get("endStationName")); | ||
| 98 | + stmap.put("CrossRegion", null); | ||
| 99 | + stmap.put("Remark", null); | ||
| 100 | + stmap.put("TiceSeller", null); | ||
| 101 | + stmap.put("RunTime", null); | ||
| 102 | + stmap.put("ParkCode", null); | ||
| 103 | + stmap.put("ParkName", null); | ||
| 104 | + stmap.put("VehicleConfigurationNum", null); | ||
| 105 | + stmap.put("RoadVector", null); | ||
| 106 | + stmap.put("EquipmentLineCode", ke.get("eqLinecode")); | ||
| 107 | + stmap.put("RouteEvolution", null); | ||
| 108 | + stmap.put("AirConditionedVehiclesNum", null); | ||
| 109 | + stmap.put("LineLength", null); | ||
| 110 | + stmap.put("OrdinaryVehiclesNum", null); | ||
| 111 | + stmap.put("RoutePlanningType", null); | ||
| 112 | + stmap.put("ShangHaiLineCode", null); | ||
| 113 | + stmap.put("IsNightTrain", ke.get("supperLine")); | ||
| 114 | + stmap.put("WarrantBusNum", null); | ||
| 115 | + stmap.put("WarrantBusDate", null); | ||
| 116 | + stmap.put("IsInUse", ke.get("destroy")); | ||
| 117 | + stmap.put("IsOperate", null); | ||
| 118 | + stmap.put("LargeIntervalLevel", null); | ||
| 119 | + numlist.add(stmap); | ||
| 120 | + stmap = new LinkedHashMap(); | ||
| 121 | + } | ||
| 122 | + xlmap.put("DataList", numlist); | ||
| 123 | + int count = 1; | ||
| 124 | + if (numlist.size() == 0) { | ||
| 125 | + return; | ||
| 126 | + } | ||
| 127 | + if (null != numlist && numlist.size() > 1000) { | ||
| 128 | + | ||
| 129 | + for (int i = 0; i < numlist.size(); ) { | ||
| 130 | + if (count > 1) { | ||
| 131 | + xlmap.put("DeleteAll", "false"); | ||
| 132 | + } | ||
| 133 | + if (numlist.size() > i + 1000) { | ||
| 134 | + log.info("第" + count + "次调用-----------"); | ||
| 135 | + xlmap.put("DataList", numlist.subList(i, i + 1000)); | ||
| 136 | + JSONObject json = new JSONObject(xlmap); | ||
| 137 | + int resultCount = HttpService.httpRequestResult(json, token, url, count); | ||
| 138 | + } else { | ||
| 139 | + log.info("第" + count + "次调用-----------"); | ||
| 140 | + xlmap.put("DataList", numlist.subList(i, numlist.size())); | ||
| 141 | + JSONObject json = new JSONObject(xlmap); | ||
| 142 | + int resultCount = HttpService.httpRequestResult(json, token, url, count); | ||
| 143 | + } | ||
| 144 | + i = i + 1000; | ||
| 145 | + count++; | ||
| 146 | + | ||
| 147 | + } | ||
| 148 | + } else { | ||
| 149 | + xlmap.put("DataList", numlist.subList(0, numlist.size())); | ||
| 150 | + JSONObject json = new JSONObject(xlmap); | ||
| 151 | + int resultCount = HttpService.httpRequestResult(json, token, url, count); | ||
| 152 | + } | ||
| 153 | + long endTime=System.currentTimeMillis(); | ||
| 154 | + log.info("调用线路基本信息插入接口结束---------------共计执行时间:"+(endTime-startTime)); | ||
| 155 | + } | ||
| 156 | + } catch (MalformedURLException e) { | ||
| 157 | + // TODO Auto-generated catch block | ||
| 158 | + e.printStackTrace(); | ||
| 159 | + } catch (IOException e) { | ||
| 160 | + // TODO Auto-generated catch block | ||
| 161 | + e.printStackTrace(); | ||
| 162 | + } | ||
| 163 | + }catch(Exception e){ | ||
| 164 | + e.printStackTrace(); | ||
| 165 | + } | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + //线路参数信息接口 | ||
| 169 | + @Transactional() | ||
| 170 | + @Scheduled(cron = "0 0 1 * * ?")//每天凌晨一点 执行 | ||
| 171 | + public void xlparameter(){ | ||
| 172 | + log.info("调用线路参数信息接口开始---------------"); | ||
| 173 | + long startTime=System.currentTimeMillis(); | ||
| 174 | + String url = "http://180.167.126.126:8992/api/buslineparmterinfo/insertlist"; | ||
| 175 | + Map<String,Object> xlmap = new HashMap<>(); | ||
| 176 | + try{ | ||
| 177 | + String password = "6DABD12209BEDAB0808CF7DC967EC2B4C6748277"; | ||
| 178 | + String timestamp = String.valueOf(System.currentTimeMillis()); | ||
| 179 | + String nonce = WebserviceSign.getRandomString(5); | ||
| 180 | + Map<String, String> map = new HashMap<String, String>(); | ||
| 181 | + map.put("timestamp", timestamp);//时间戳 | ||
| 182 | + map.put("nonce", nonce);//随机字符串 | ||
| 183 | + map.put("password", password);//密码 | ||
| 184 | + String signStr = WebserviceSign.getSHA1(map); | ||
| 185 | + String endpoint = "http://"+ip+"/webservice/rest/line/all?timestamp="+timestamp+"&nonce="+nonce+"&password="+password+"&sign="+signStr; | ||
| 186 | + InputStream in = null; | ||
| 187 | + try { | ||
| 188 | + HttpURLConnection con = (HttpURLConnection)new URL(endpoint).openConnection(); | ||
| 189 | + con.setDoInput(true); | ||
| 190 | + con.setDoOutput(true); | ||
| 191 | + con.setRequestMethod("GET"); | ||
| 192 | + con.setConnectTimeout(5000); | ||
| 193 | + con.setReadTimeout(5000); | ||
| 194 | + con.setRequestProperty("keep-alive", "true"); | ||
| 195 | + con.setRequestProperty("accept", "application/json"); | ||
| 196 | + con.setRequestProperty("content-type", "application/json"); | ||
| 197 | + | ||
| 198 | + if (con.getResponseCode() == 200) { | ||
| 199 | + in = con.getInputStream(); | ||
| 200 | + ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 201 | + IOUtils.copy(in, bout); | ||
| 202 | + Map stmap = new LinkedHashMap(); | ||
| 203 | + List m = new ObjectMapper().readValue(bout.toByteArray(), List.class); | ||
| 204 | + List numlist = new ArrayList(); | ||
| 205 | + for (Object o:m){ | ||
| 206 | + Map ke = (Map)o; | ||
| 207 | + stmap.put("BusLineCode",ke.get("lineCode")); | ||
| 208 | + stmap.put("UpKilometer",null); | ||
| 209 | + stmap.put("DnKilometer",null); | ||
| 210 | + stmap.put("MPBegTime",null); | ||
| 211 | + stmap.put("MPEndTime",null); | ||
| 212 | + stmap.put("EPBegTime",null); | ||
| 213 | + stmap.put("EPEndTime",null); | ||
| 214 | + stmap.put("SNPBegTime",null); | ||
| 215 | + stmap.put("SNPEndTime",null); | ||
| 216 | + stmap.put("MPUpTravelTime",null); | ||
| 217 | + stmap.put("MPDnTravelTime",null); | ||
| 218 | + stmap.put("EPUpTravelTime",null); | ||
| 219 | + stmap.put("EPDnTravelTime",null); | ||
| 220 | + stmap.put("SNPUpTravelTime",null); | ||
| 221 | + stmap.put("SNPDnTravelTime",null); | ||
| 222 | + stmap.put("LowUpTravelTime",null); | ||
| 223 | + stmap.put("LowDnTravelTime",null); | ||
| 224 | + stmap.put("StartingToParkTime",null); | ||
| 225 | + stmap.put("StartingToParkKilometer",null); | ||
| 226 | + stmap.put("LastingToParkTime",null); | ||
| 227 | + stmap.put("LastingToParkKilometer",null); | ||
| 228 | + stmap.put("MPLargeMargin",ke.get("earlyIntervalLg")); | ||
| 229 | + stmap.put("EPLargeMargin",ke.get("lateIntervalLg")); | ||
| 230 | + stmap.put("LowLargeMargin",ke.get("intervalLg")); | ||
| 231 | + stmap.put("MaxOverSpeed",null); | ||
| 232 | + stmap.put("OverStopTime",ke.get("lagStation")); | ||
| 233 | + stmap.put("LessStopTime",ke.get("skip")); | ||
| 234 | + stmap.put("BusMaxGather",null); | ||
| 235 | + stmap.put("DeleteFlag",ke.get("destroy")); | ||
| 236 | + stmap.put("Remark",null); | ||
| 237 | + stmap.put("SpeedNormal",ke.get("speedLimit")); | ||
| 238 | + stmap.put("SpeedRain",null); | ||
| 239 | + stmap.put("SpeedDenseFog",null); | ||
| 240 | + stmap.put("SpeedIce",null); | ||
| 241 | + stmap.put("SpeedFestival",null); | ||
| 242 | + stmap.put("Speeding",ke.get("speeding")); | ||
| 243 | + stmap.put("String",ke.get("crossedLine")); | ||
| 244 | + stmap.put("Transboundary",ke.get("overflights")); | ||
| 245 | + stmap.put("describe",null); | ||
| 246 | + stmap.put("ParkingLot",null); | ||
| 247 | + stmap.put("FromMileage",null); | ||
| 248 | + stmap.put("OutTime",null); | ||
| 249 | + stmap.put("ProcessionMileage",null); | ||
| 250 | + numlist.add(stmap); | ||
| 251 | + stmap = new LinkedHashMap(); | ||
| 252 | + } | ||
| 253 | + String token = JkToken.jkdata(); | ||
| 254 | + xlmap.put("AccessToken",token); | ||
| 255 | + xlmap.put("DeleteAll","true"); | ||
| 256 | + xlmap.put("DataList",numlist); | ||
| 257 | + int count = 1; | ||
| 258 | + if (numlist.size() == 0) { | ||
| 259 | + return; | ||
| 260 | + } | ||
| 261 | + if (null != numlist && numlist.size() > 1000) { | ||
| 262 | + | ||
| 263 | + for (int i = 0; i < numlist.size(); ) { | ||
| 264 | + if (count > 1) { | ||
| 265 | + xlmap.put("DeleteAll", "false"); | ||
| 266 | + } | ||
| 267 | + if (numlist.size() > i + 1000) { | ||
| 268 | + log.info("第" + count + "次调用-----------"); | ||
| 269 | + xlmap.put("DataList", numlist.subList(i, i + 1000)); | ||
| 270 | + JSONObject json = new JSONObject(xlmap); | ||
| 271 | + int resultCount = HttpService.httpRequestResult(json, token, url, count); | ||
| 272 | + } else { | ||
| 273 | + log.info("第" + count + "次调用-----------"); | ||
| 274 | + xlmap.put("DataList", numlist.subList(i, numlist.size())); | ||
| 275 | + JSONObject json = new JSONObject(xlmap); | ||
| 276 | + int resultCount = HttpService.httpRequestResult(json, token, url, count); | ||
| 277 | + } | ||
| 278 | + i = i + 1000; | ||
| 279 | + count++; | ||
| 280 | + } | ||
| 281 | + } else { | ||
| 282 | + xlmap.put("DataList", numlist.subList(0, numlist.size())); | ||
| 283 | + JSONObject json = new JSONObject(xlmap); | ||
| 284 | + int resultCount = HttpService.httpRequestResult(json, token, url, count); | ||
| 285 | + } | ||
| 286 | + long endTime=System.currentTimeMillis(); | ||
| 287 | + log.info("调用线路参数信息插入接口结束---------------共计执行时间:"+(endTime-startTime)); | ||
| 288 | + } | ||
| 289 | + } catch (MalformedURLException e) { | ||
| 290 | + // TODO Auto-generated catch block | ||
| 291 | + e.printStackTrace(); | ||
| 292 | + } catch (IOException e) { | ||
| 293 | + // TODO Auto-generated catch block | ||
| 294 | + e.printStackTrace(); | ||
| 295 | + } | ||
| 296 | + }catch(Exception e){ | ||
| 297 | + e.printStackTrace(); | ||
| 298 | + } | ||
| 299 | + } | ||
| 300 | + | ||
| 301 | + ////线路走向接口 | ||
| 302 | + @Transactional() | ||
| 303 | + @Scheduled(cron = "0 0 1 * * ?")//每天凌晨一点 执行 | ||
| 304 | + public void postrend(){ | ||
| 305 | + log.info("调用线路走向接口开始---------------"); | ||
| 306 | + long startTime=System.currentTimeMillis(); | ||
| 307 | + Map<String,Object> xlmap = new HashMap<>(); | ||
| 308 | + List numlist = new ArrayList(); | ||
| 309 | + String url="http://180.167.126.126:8992/api/stationnetpoints/insertlist"; | ||
| 310 | + try{ | ||
| 311 | + String password = "6DABD12209BEDAB0808CF7DC967EC2B4C6748277"; | ||
| 312 | + String timestamp = String.valueOf(System.currentTimeMillis()); | ||
| 313 | + String nonce = WebserviceSign.getRandomString(5); | ||
| 314 | + Map<String, String> map = new HashMap<String, String>(); | ||
| 315 | + map.put("timestamp", timestamp);//时间戳 | ||
| 316 | + map.put("nonce", nonce);//随机字符串 | ||
| 317 | + map.put("password", password);//密码 | ||
| 318 | + String signStr = WebserviceSign.getSHA1(map); | ||
| 319 | + List list = new ArrayList(); | ||
| 320 | + list.add("22");//四家公司 | ||
| 321 | + list.add("26"); | ||
| 322 | + list.add("55"); | ||
| 323 | + list.add("05"); | ||
| 324 | + try { | ||
| 325 | + for (Object t:list ) { | ||
| 326 | + String endpoint = "http://"+ip+"/webservice/rest/ld_section/"+t+"?timestamp=" + timestamp + "&nonce=" + nonce + "&password=" + password + "&sign=" + signStr; | ||
| 327 | + InputStream in = null; | ||
| 328 | + HttpURLConnection con = (HttpURLConnection) new URL(endpoint).openConnection(); | ||
| 329 | + con.setDoInput(true); | ||
| 330 | + con.setDoOutput(true); | ||
| 331 | + con.setRequestMethod("GET"); | ||
| 332 | + con.setConnectTimeout(5000); | ||
| 333 | + con.setReadTimeout(5000); | ||
| 334 | + con.setRequestProperty("keep-alive", "true"); | ||
| 335 | + con.setRequestProperty("accept", "application/json"); | ||
| 336 | + con.setRequestProperty("content-type", "application/json"); | ||
| 337 | + | ||
| 338 | + if (con.getResponseCode() == 200) { | ||
| 339 | + in = con.getInputStream(); | ||
| 340 | + ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 341 | + IOUtils.copy(in, bout); | ||
| 342 | + Map stmap = new LinkedHashMap(); | ||
| 343 | + Map m = new ObjectMapper().readValue(bout.toByteArray(), Map.class); | ||
| 344 | + Map<String, Object> numMap = new LinkedHashMap<>(); | ||
| 345 | + List n = new ArrayList(); | ||
| 346 | + for (Object key : m.keySet()) { | ||
| 347 | + List lit = (List) m.get(key); | ||
| 348 | + Map st = (Map) lit.get(0); | ||
| 349 | + Map section = (Map) st.get("section"); | ||
| 350 | + numMap.put("BusLineCode", st.get("lineCode")); | ||
| 351 | + numMap.put("BusLineName", null); | ||
| 352 | + numMap.put("Directions", st.get("directions")); | ||
| 353 | + numMap.put("DirIndex ", st.get("sectionrouteCode")); | ||
| 354 | + String lay[] = zbd(section.get("gsectionVector").toString()); | ||
| 355 | + if(lay != null) { //坐标类型问题传不过去 传null | ||
| 356 | + numMap.put("LongitudeX", String.format("%.8f", Double.parseDouble(lay[0]))); | ||
| 357 | + numMap.put("LatitudeY", String.format("%.8f", Double.parseDouble(lay[1]))); | ||
| 358 | + }else { | ||
| 359 | + numMap.put("LongitudeX", null); | ||
| 360 | + numMap.put("LatitudeY", null); | ||
| 361 | + } | ||
| 362 | + numlist.add(numMap); | ||
| 363 | + numMap = new LinkedHashMap<>(); | ||
| 364 | + } | ||
| 365 | + } | ||
| 366 | + } | ||
| 367 | + String token = JkToken.jkdata(); | ||
| 368 | + xlmap.put("AccessToken",token); | ||
| 369 | + xlmap.put("DeleteAll","true"); | ||
| 370 | + xlmap.put("DataList",numlist); | ||
| 371 | + | ||
| 372 | + int count=1; | ||
| 373 | + if(numlist.size()==0){ | ||
| 374 | + return; | ||
| 375 | + } | ||
| 376 | + if(null !=numlist && numlist.size()>1000){ | ||
| 377 | + | ||
| 378 | + for (int i = 0; i <numlist.size() ; ) { | ||
| 379 | + if(count > 1){ | ||
| 380 | + xlmap.put("DeleteAll","false"); | ||
| 381 | + } | ||
| 382 | + if(numlist.size()> i + 1000){ | ||
| 383 | + log.info("第"+count+"次调用-----------"); | ||
| 384 | + xlmap.put("DataList",numlist.subList(i,i+1000)); | ||
| 385 | + JSONObject json = new JSONObject(xlmap); | ||
| 386 | + int resultCount= HttpService.httpRequestResult(json,token,url,count); | ||
| 387 | + }else { | ||
| 388 | + log.info("第"+count+"次调用-----------"); | ||
| 389 | + xlmap.put("DataList",numlist.subList(i,numlist.size())); | ||
| 390 | + JSONObject json = new JSONObject(xlmap); | ||
| 391 | + int resultCount= HttpService.httpRequestResult(json,token,url,count); | ||
| 392 | + } | ||
| 393 | + i=i+1000; | ||
| 394 | + count++; | ||
| 395 | + } | ||
| 396 | + }else { | ||
| 397 | + xlmap.put("DataList",numlist.subList(0,numlist.size())); | ||
| 398 | + JSONObject json = new JSONObject(xlmap); | ||
| 399 | + int resultCount= HttpService.httpRequestResult(json,token,url,count); | ||
| 400 | + } | ||
| 401 | + long endTime=System.currentTimeMillis(); | ||
| 402 | + log.info("调用线路走向插入接口结束---------------共计执行时间:"+(endTime-startTime)); | ||
| 403 | + } catch (MalformedURLException e) { | ||
| 404 | + // TODO Auto-generated catch block | ||
| 405 | + e.printStackTrace(); | ||
| 406 | + } catch (IOException e) { | ||
| 407 | + // TODO Auto-generated catch block | ||
| 408 | + e.printStackTrace(); | ||
| 409 | + } | ||
| 410 | + }catch(Exception e){ | ||
| 411 | + e.printStackTrace(); | ||
| 412 | + } | ||
| 413 | + } | ||
| 414 | + | ||
| 415 | + //查询线路停靠站信息接口 | ||
| 416 | + @Transactional() | ||
| 417 | + @Scheduled(cron = "0 0 1 * * ?")//每天凌晨一点 执行 | ||
| 418 | + public void site(){ | ||
| 419 | + log.info("调用线路停靠站信息接口开始---------------"); | ||
| 420 | + long startTime=System.currentTimeMillis(); | ||
| 421 | + Map<String,Object> xlmap = new HashMap<>(); | ||
| 422 | + List numlist = new ArrayList(); | ||
| 423 | + String url="http://180.167.126.126:8992/api/buslinenetstation/insertlist"; | ||
| 424 | + try{ | ||
| 425 | + String password = "6DABD12209BEDAB0808CF7DC967EC2B4C6748277"; | ||
| 426 | + String timestamp = String.valueOf(System.currentTimeMillis()); | ||
| 427 | + String nonce = WebserviceSign.getRandomString(5); | ||
| 428 | + Map<String, String> map = new HashMap<String, String>(); | ||
| 429 | + map.put("timestamp", timestamp);//时间戳 | ||
| 430 | + map.put("nonce", nonce);//随机字符串 | ||
| 431 | + map.put("password", password);//密码 | ||
| 432 | + String signStr = WebserviceSign.getSHA1(map); | ||
| 433 | + List list = new ArrayList(); | ||
| 434 | + list.add("22"); list.add("26"); list.add("55"); list.add("05"); //四家公司 | ||
| 435 | + try { | ||
| 436 | + for (Object t:list ) { | ||
| 437 | + String endpoint = "http://"+ip+"/webservice/rest/station/" + t + "?timestamp=" + timestamp + "&nonce=" + nonce + "&password=" + password + "&sign=" + signStr; | ||
| 438 | + InputStream in = null; | ||
| 439 | + HttpURLConnection con = (HttpURLConnection) new URL(endpoint).openConnection(); | ||
| 440 | + con.setDoInput(true); | ||
| 441 | + con.setDoOutput(true); | ||
| 442 | + con.setRequestMethod("GET"); | ||
| 443 | + con.setConnectTimeout(5000); | ||
| 444 | + con.setReadTimeout(5000); | ||
| 445 | + con.setRequestProperty("keep-alive", "true"); | ||
| 446 | + con.setRequestProperty("accept", "application/json"); | ||
| 447 | + con.setRequestProperty("content-type", "application/json"); | ||
| 448 | + if (con.getResponseCode() == 200) { | ||
| 449 | + in = con.getInputStream(); | ||
| 450 | + ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 451 | + IOUtils.copy(in, bout); | ||
| 452 | + Map m = new ObjectMapper().readValue(bout.toByteArray(), Map.class); | ||
| 453 | + Map<String, Object> numMap = new LinkedHashMap<>(); | ||
| 454 | + for (Object key : m.keySet()) { | ||
| 455 | + List lit = (List) m.get(key); | ||
| 456 | + for (Object o : lit) { | ||
| 457 | + Map st = (Map) o; | ||
| 458 | + Map station = (Map) st.get("station"); | ||
| 459 | + numMap.put("BusLineCode", st.get("lineCode")); | ||
| 460 | + numMap.put("BusLineName", 0); | ||
| 461 | + numMap.put("Directions", 0); | ||
| 462 | + numMap.put("DirIndex", 0); | ||
| 463 | + numMap.put("StationCode ", st.get("stationCode")); | ||
| 464 | + numMap.put("StationName", st.get("stationName")); | ||
| 465 | + if (st.get("stationMark").equals("B")) { | ||
| 466 | + numMap.put("StationTypeCode", 1); | ||
| 467 | + } else if (st.get("stationMark").equals("E")) { | ||
| 468 | + numMap.put("StationTypeCode", 2); | ||
| 469 | + } else { | ||
| 470 | + numMap.put("StationTypeCode", 0); | ||
| 471 | + } | ||
| 472 | + numMap.put("StationEngName", 0); | ||
| 473 | + numMap.put("StationAddress", st.get("stationName")); | ||
| 474 | + if (station != null) { | ||
| 475 | + numMap.put("LongitudeX", station.get("lon")); | ||
| 476 | + numMap.put("LatitudeY", station.get("lat")); | ||
| 477 | + } else { | ||
| 478 | + numMap.put("LongitudeX", 0); | ||
| 479 | + numMap.put("LatitudeY", 0); | ||
| 480 | + } | ||
| 481 | + numMap.put("FirstTime", st.get("firstTime")); | ||
| 482 | + numMap.put("LastTime", st.get("endTime")); | ||
| 483 | + numMap.put("OperateTimes", 0); | ||
| 484 | + numlist.add(numMap); | ||
| 485 | + numMap = new LinkedHashMap<>(); | ||
| 486 | + } | ||
| 487 | + } | ||
| 488 | + } | ||
| 489 | + } | ||
| 490 | + String token = JkToken.jkdata(); | ||
| 491 | + xlmap.put("AccessToken",token); | ||
| 492 | + xlmap.put("DeleteAll","true"); | ||
| 493 | + xlmap.put("DataList",numlist); | ||
| 494 | + int count = 1; | ||
| 495 | + if(numlist.size() == 0){ | ||
| 496 | + return; | ||
| 497 | + } | ||
| 498 | + if(null !=numlist && numlist.size() > 1000){ | ||
| 499 | + | ||
| 500 | + for (int i = 0; i < numlist.size() ; ) { | ||
| 501 | + if(count > 1){ | ||
| 502 | + xlmap.put("DeleteAll","false"); | ||
| 503 | + } | ||
| 504 | + if(numlist.size() > i + 1000){ | ||
| 505 | + log.info("第"+count+"次调用-----------"); | ||
| 506 | + xlmap.put("DataList",numlist.subList(i,i+1000)); | ||
| 507 | + JSONObject json = new JSONObject(xlmap); | ||
| 508 | + int resultCount= HttpService.httpRequestResult(json,token,url,count); | ||
| 509 | + }else { | ||
| 510 | + log.info("第"+count+"次调用-----------"); | ||
| 511 | + xlmap.put("DataList",numlist.subList(i,numlist.size())); | ||
| 512 | + JSONObject json = new JSONObject(xlmap); | ||
| 513 | + int resultCount= HttpService.httpRequestResult(json,token,url,count); | ||
| 514 | + } | ||
| 515 | + i = i + 1000; | ||
| 516 | + count++; | ||
| 517 | + | ||
| 518 | + } | ||
| 519 | + }else { | ||
| 520 | + xlmap.put("DataList",numlist.subList(0,numlist.size())); | ||
| 521 | + JSONObject json = new JSONObject(xlmap); | ||
| 522 | + int resultCount= HttpService.httpRequestResult(json,token,url,count); | ||
| 523 | + } | ||
| 524 | + long endTime=System.currentTimeMillis(); | ||
| 525 | + log.info("调用线路停靠站信息插入接口结束---------------共计执行时间:"+(endTime-startTime)); | ||
| 526 | + | ||
| 527 | + } catch (MalformedURLException e) { | ||
| 528 | + // TODO Auto-generated catch block | ||
| 529 | + e.printStackTrace(); | ||
| 530 | + } catch (IOException e) { | ||
| 531 | + // TODO Auto-generated catch block | ||
| 532 | + e.printStackTrace(); | ||
| 533 | + } | ||
| 534 | + }catch(Exception e){ | ||
| 535 | + e.printStackTrace(); | ||
| 536 | + } | ||
| 537 | + } | ||
| 538 | + | ||
| 539 | + //线路走向坐标类型转换格式 | ||
| 540 | + public static String[] zbd(String gsectionVector){ | ||
| 541 | + String longStr = new String(gsectionVector.replaceAll("[^\\d,. ]+", "")); | ||
| 542 | + String [] loglat = longStr.split(","); | ||
| 543 | + String lay =""; | ||
| 544 | + lay+=loglat[loglat.length-1]; | ||
| 545 | + String [] la = loglat = lay.split(" "); | ||
| 546 | + return la; | ||
| 547 | + } | ||
| 548 | + | ||
| 549 | + | ||
| 550 | +} |
src/main/java/com/bsth/utils/Arith.java
0 → 100644
| 1 | +package com.bsth.utils; | ||
| 2 | + | ||
| 3 | +import java.math.BigDecimal; | ||
| 4 | + | ||
| 5 | +public class Arith { | ||
| 6 | + /** | ||
| 7 | + * 由于Java的简单类型不能够精确的对浮点数进行运算,这个工具类提供精 | ||
| 8 | + * 确的浮点数运算,包括加减乘除和四舍五入。 | ||
| 9 | + */ | ||
| 10 | + //默认除法运算精度 | ||
| 11 | + private static final int DEF_DIV_SCALE = 10; | ||
| 12 | + | ||
| 13 | + //这个类不能实例化 | ||
| 14 | + private Arith(){ | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 提供精确的加法运算。 | ||
| 19 | + * @param v1 被加数 | ||
| 20 | + * @param v2 加数 | ||
| 21 | + * @return 两个参数的和 | ||
| 22 | + */ | ||
| 23 | + public static double add(Object v1,Object v2){ | ||
| 24 | + BigDecimal b1 = new BigDecimal(v1.toString()); | ||
| 25 | + BigDecimal b2 = new BigDecimal(v2.toString()); | ||
| 26 | + return b1.add(b2).doubleValue(); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 提供精确的加法运算。 | ||
| 31 | + * @param v1 被加数 | ||
| 32 | + * @param v2 加数 | ||
| 33 | + * @return 两个参数的和 | ||
| 34 | + */ | ||
| 35 | + public static long addLong(Object v1,Object v2){ | ||
| 36 | + BigDecimal b1 = new BigDecimal(v1.toString()); | ||
| 37 | + BigDecimal b2 = new BigDecimal(v2.toString()); | ||
| 38 | + return b1.add(b2).longValue(); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * 提供精确的减法运算。 | ||
| 43 | + * @param v1 被减数 | ||
| 44 | + * @param v2 减数 | ||
| 45 | + * @return 两个参数的差 | ||
| 46 | + */ | ||
| 47 | + public static double sub(Object v1,Object v2){ | ||
| 48 | + BigDecimal b1 = new BigDecimal(v1.toString()); | ||
| 49 | + BigDecimal b2 = new BigDecimal(v2.toString()); | ||
| 50 | + return b1.subtract(b2).doubleValue(); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 提供精确的乘法运算。 | ||
| 55 | + * @param v1 被乘数 | ||
| 56 | + * @param v2 乘数 | ||
| 57 | + * @return 两个参数的积 | ||
| 58 | + */ | ||
| 59 | + public static double mul(Object v1,Object v2){ | ||
| 60 | + BigDecimal b1 = new BigDecimal(v1.toString()); | ||
| 61 | + BigDecimal b2 = new BigDecimal(v2.toString()); | ||
| 62 | + return b1.multiply(b2).doubleValue(); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 提供(相对)精确的除法运算,当发生除不尽的情况时,精确到 | ||
| 67 | + * 小数点以后10位,以后的数字四舍五入。 | ||
| 68 | + * @param v1 被除数 | ||
| 69 | + * @param v2 除数 | ||
| 70 | + * @return 两个参数的商 | ||
| 71 | + */ | ||
| 72 | + public static double div(Object v1,Object v2){ | ||
| 73 | + return div(v1,v2,DEF_DIV_SCALE); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * 提供(相对)精确的除法运算。当发生除不尽的情况时,由scale参数指 | ||
| 78 | + * 定精度,以后的数字四舍五入。 | ||
| 79 | + * @param v1 被除数 | ||
| 80 | + * @param v2 除数 | ||
| 81 | + * @param scale 表示表示需要精确到小数点以后几位。 | ||
| 82 | + * @return 两个参数的商 | ||
| 83 | + */ | ||
| 84 | + public static double div(Object v1,Object v2,int scale){ | ||
| 85 | + if(scale<0){ | ||
| 86 | + throw new IllegalArgumentException( | ||
| 87 | + "The scale must be a positive integer or zero"); | ||
| 88 | + } | ||
| 89 | + BigDecimal b1 = new BigDecimal(v1.toString()); | ||
| 90 | + BigDecimal b2 = new BigDecimal(v2.toString()); | ||
| 91 | + return b1.divide(b2,scale,BigDecimal.ROUND_HALF_UP).doubleValue(); | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * 提供精确的小数位四舍五入处理。 | ||
| 96 | + * @param v 需要四舍五入的数字 | ||
| 97 | + * @param scale 小数点后保留几位 | ||
| 98 | + * @return 四舍五入后的结果 | ||
| 99 | + */ | ||
| 100 | + public static double round(Object v,int scale){ | ||
| 101 | + if(scale<0){ | ||
| 102 | + throw new IllegalArgumentException( | ||
| 103 | + "The scale must be a positive integer or zero"); | ||
| 104 | + } | ||
| 105 | + BigDecimal b = new BigDecimal(v.toString()); | ||
| 106 | + BigDecimal one = new BigDecimal("1"); | ||
| 107 | + return b.divide(one,scale,BigDecimal.ROUND_HALF_UP).doubleValue(); | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * 提供精确的类型转换(Float) | ||
| 112 | + * @param v 需要被转换的数字 | ||
| 113 | + * @return 返回转换结果 | ||
| 114 | + */ | ||
| 115 | + public static float convertsToFloat(Object v){ | ||
| 116 | + BigDecimal b = new BigDecimal(v.toString()); | ||
| 117 | + return b.floatValue(); | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + /** | ||
| 121 | + * 提供精确的类型转换(Int)不进行四舍五入 | ||
| 122 | + * @param v 需要被转换的数字 | ||
| 123 | + * @return 返回转换结果 | ||
| 124 | + */ | ||
| 125 | + public static int convertsToInt(Object v){ | ||
| 126 | + BigDecimal b = new BigDecimal(v.toString()); | ||
| 127 | + return b.intValue(); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * 提供精确的类型转换(Long) | ||
| 132 | + * @param v 需要被转换的数字 | ||
| 133 | + * @return 返回转换结果 | ||
| 134 | + */ | ||
| 135 | + public static long convertsToLong(Object v){ | ||
| 136 | + BigDecimal b = new BigDecimal(v.toString()); | ||
| 137 | + return b.longValue(); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + /** | ||
| 141 | + * 返回两个数中大的一个值 | ||
| 142 | + * @param v1 需要被对比的第一个数 | ||
| 143 | + * @param v2 需要被对比的第二个数 | ||
| 144 | + * @return 返回两个数中大的一个值 | ||
| 145 | + */ | ||
| 146 | + public static double returnMax(Object v1,Object v2){ | ||
| 147 | + BigDecimal b1 = new BigDecimal(v1.toString()); | ||
| 148 | + BigDecimal b2 = new BigDecimal(v2.toString()); | ||
| 149 | + return b1.max(b2).doubleValue(); | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + /** | ||
| 153 | + * 返回两个数中小的一个值 | ||
| 154 | + * @param v1 需要被对比的第一个数 | ||
| 155 | + * @param v2 需要被对比的第二个数 | ||
| 156 | + * @return 返回两个数中小的一个值 | ||
| 157 | + */ | ||
| 158 | + public static double returnMin(Object v1,Object v2){ | ||
| 159 | + BigDecimal b1 = new BigDecimal(v1.toString()); | ||
| 160 | + BigDecimal b2 = new BigDecimal(v2.toString()); | ||
| 161 | + return b1.min(b2).doubleValue(); | ||
| 162 | + } | ||
| 163 | + | ||
| 164 | + /** | ||
| 165 | + * 精确对比两个数字 | ||
| 166 | + * @param v1 需要被对比的第一个数 | ||
| 167 | + * @param v2 需要被对比的第二个数 | ||
| 168 | + * @return 如果两个数一样则返回0,如果第一个数比第二个数大则返回1,反之返回-1 | ||
| 169 | + */ | ||
| 170 | + public static int compareTo(Object v1,Object v2){ | ||
| 171 | + BigDecimal b1 = new BigDecimal(v1.toString()); | ||
| 172 | + BigDecimal b2 = new BigDecimal(v2.toString()); | ||
| 173 | + return b1.compareTo(b2); | ||
| 174 | + } | ||
| 175 | +} |
src/main/java/com/bsth/utils/HttpUtils.java
| 1 | -package com.bsth.utils; | ||
| 2 | - | ||
| 3 | -import org.apache.tomcat.util.http.fileupload.IOUtils; | ||
| 4 | -import org.slf4j.Logger; | ||
| 5 | -import org.slf4j.LoggerFactory; | ||
| 6 | - | ||
| 7 | -import java.io.ByteArrayOutputStream; | ||
| 8 | -import java.io.IOException; | ||
| 9 | -import java.io.InputStream; | ||
| 10 | -import java.io.OutputStream; | ||
| 11 | -import java.net.HttpURLConnection; | ||
| 12 | -import java.net.URL; | ||
| 13 | -import java.util.HashMap; | ||
| 14 | -import java.util.List; | ||
| 15 | -import java.util.Map; | ||
| 16 | - | ||
| 17 | -/** | ||
| 18 | - * @author hill | ||
| 19 | - * @date | ||
| 20 | - */ | ||
| 21 | -public class HttpUtils { | ||
| 22 | - | ||
| 23 | - private final static Logger log = LoggerFactory.getLogger(HttpUtils.class); | ||
| 24 | - | ||
| 25 | - public static void request(String url) { | ||
| 26 | - request(url, new CallBack() { | ||
| 27 | - @Override | ||
| 28 | - public void success(byte[] bytes, Map<String, List<String>> header) { | ||
| 29 | - | ||
| 30 | - } | ||
| 31 | - | ||
| 32 | - @Override | ||
| 33 | - public void failed() { | ||
| 34 | - | ||
| 35 | - } | ||
| 36 | - }); | ||
| 37 | - } | ||
| 38 | - | ||
| 39 | - public static void request(String url, CallBack cb) { | ||
| 40 | - request(url, cb, "GET"); | ||
| 41 | - } | ||
| 42 | - | ||
| 43 | - public static void request(String url, CallBack cb, String method) { | ||
| 44 | - request(url, cb, method, new HashMap<>()); | ||
| 45 | - } | ||
| 46 | - | ||
| 47 | - public static void request(String url, CallBack cb, String method, Map<String, String> header) { | ||
| 48 | - request(url, cb, method, header, new HashMap<>()); | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - public static void request(String url, CallBack cb, String method, Map<String, String> header, Map<String, Object> param) { | ||
| 52 | - InputStream in = null; | ||
| 53 | - OutputStream out = null; | ||
| 54 | - HttpURLConnection con = null; | ||
| 55 | - long start = System.currentTimeMillis(); | ||
| 56 | - try { | ||
| 57 | - con = (HttpURLConnection)new URL(url).openConnection(); | ||
| 58 | - con.setRequestMethod(method); | ||
| 59 | - con.setRequestProperty("keep-alive", "true"); | ||
| 60 | - con.setRequestProperty("accept", "application/json"); | ||
| 61 | - con.setRequestProperty("content-type", "application/json"); | ||
| 62 | - con.setDoInput(true); | ||
| 63 | - con.setDoOutput(true); | ||
| 64 | - con.setReadTimeout(5000); | ||
| 65 | - con.setConnectTimeout(5000); | ||
| 66 | - | ||
| 67 | - if (header.size() > 0) { | ||
| 68 | - for (Map.Entry<String, String> entry : header.entrySet()) { | ||
| 69 | - con.setRequestProperty(entry.getKey(), entry.getValue()); | ||
| 70 | - } | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - if (param.size() > 0) { | ||
| 74 | - out = con.getOutputStream(); | ||
| 75 | - StringBuilder sb = new StringBuilder(); | ||
| 76 | - for (Map.Entry<String, Object> entry : param.entrySet()) { | ||
| 77 | - sb.append("&").append(entry.getKey()).append("=").append(entry.getValue()); | ||
| 78 | - } | ||
| 79 | - out.write(sb.substring(1).getBytes("UTF-8")); | ||
| 80 | - out.flush(); | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - in = con.getInputStream(); | ||
| 84 | - ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 85 | - IOUtils.copy(in, bout); bout.close(); | ||
| 86 | - if (con.getResponseCode() == 200) { | ||
| 87 | - cb.success(bout.toByteArray(), con.getHeaderFields()); | ||
| 88 | - } else { | ||
| 89 | - log.info(new String(bout.toByteArray())); | ||
| 90 | - cb.failed(); | ||
| 91 | - } | ||
| 92 | - } catch (IOException e) { | ||
| 93 | - // TODO Auto-generated catch block | ||
| 94 | - log.error("cost:" + (System.currentTimeMillis() - start)); | ||
| 95 | - log.error("HttpUtils.request异常", e); | ||
| 96 | - cb.failed(); | ||
| 97 | - } catch (Exception e) { | ||
| 98 | - log.error("处理异常", e); | ||
| 99 | - } finally { | ||
| 100 | - con.disconnect(); | ||
| 101 | - try { | ||
| 102 | - if (in != null) in.close(); | ||
| 103 | - if (out != null) out.close(); | ||
| 104 | - } catch (IOException e) { | ||
| 105 | - // TODO Auto-generated catch block | ||
| 106 | - e.printStackTrace(); | ||
| 107 | - } | ||
| 108 | - } | ||
| 109 | - } | ||
| 110 | -} | 1 | +package com.bsth.utils; |
| 2 | + | ||
| 3 | +import org.apache.tomcat.util.http.fileupload.IOUtils; | ||
| 4 | +import org.slf4j.Logger; | ||
| 5 | +import org.slf4j.LoggerFactory; | ||
| 6 | + | ||
| 7 | +import com.alibaba.fastjson.JSON; | ||
| 8 | +import com.alibaba.fastjson.JSONObject; | ||
| 9 | + | ||
| 10 | +import java.io.ByteArrayOutputStream; | ||
| 11 | +import java.io.DataOutputStream; | ||
| 12 | +import java.io.IOException; | ||
| 13 | +import java.io.InputStream; | ||
| 14 | +import java.io.OutputStream; | ||
| 15 | +import java.net.HttpURLConnection; | ||
| 16 | +import java.net.URL; | ||
| 17 | +import java.util.Date; | ||
| 18 | +import java.util.HashMap; | ||
| 19 | +import java.util.List; | ||
| 20 | +import java.util.Map; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * @author hill | ||
| 24 | + * @date | ||
| 25 | + */ | ||
| 26 | +public class HttpUtils { | ||
| 27 | + | ||
| 28 | + private final static Logger log = LoggerFactory.getLogger(HttpUtils.class); | ||
| 29 | + | ||
| 30 | + public static void request(String url) { | ||
| 31 | + request(url, new CallBack() { | ||
| 32 | + @Override | ||
| 33 | + public void success(byte[] bytes, Map<String, List<String>> header) { | ||
| 34 | + | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + @Override | ||
| 38 | + public void failed() { | ||
| 39 | + | ||
| 40 | + } | ||
| 41 | + }); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + public static void request(String url, CallBack cb) { | ||
| 45 | + request(url, cb, "GET"); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + public static void request(String url, CallBack cb, String method) { | ||
| 49 | + request(url, cb, method, new HashMap<>()); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public static void request(String url, CallBack cb, String method, Map<String, String> header) { | ||
| 53 | + request(url, cb, method, header, new HashMap<>()); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public static void request(String url, CallBack cb, String method, Map<String, String> header, Map<String, Object> param) { | ||
| 57 | + InputStream in = null; | ||
| 58 | + OutputStream out = null; | ||
| 59 | + DataOutputStream printout = null; | ||
| 60 | + HttpURLConnection con = null; | ||
| 61 | + long start = System.currentTimeMillis(); | ||
| 62 | + try { | ||
| 63 | + con = (HttpURLConnection)new URL(url).openConnection(); | ||
| 64 | + con.setRequestMethod(method); | ||
| 65 | + con.setRequestProperty("keep-alive", "true"); | ||
| 66 | + con.setRequestProperty("accept", "application/json"); | ||
| 67 | + con.setRequestProperty("content-type", "application/json"); | ||
| 68 | +// con.setRequestProperty("charset", "utf-8"); | ||
| 69 | + con.setDoInput(true); | ||
| 70 | + con.setDoOutput(true); | ||
| 71 | + con.setReadTimeout(20000); | ||
| 72 | + con.setConnectTimeout(20000); | ||
| 73 | + | ||
| 74 | + if (header.size() > 0) { | ||
| 75 | + for (Map.Entry<String, String> entry : header.entrySet()) { | ||
| 76 | + con.setRequestProperty(entry.getKey(), entry.getValue()); | ||
| 77 | + } | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + if (param.size() > 0) { | ||
| 81 | + out = con.getOutputStream(); | ||
| 82 | + StringBuilder sb = new StringBuilder(); | ||
| 83 | + for (Map.Entry<String, Object> entry : param.entrySet()) { | ||
| 84 | + sb.append("&").append(entry.getKey()).append("=").append(entry.getValue()); | ||
| 85 | + } | ||
| 86 | + out.write(sb.substring(1).getBytes("UTF-8")); | ||
| 87 | + out.flush(); | ||
| 88 | + | ||
| 89 | +// printout = new DataOutputStream(con.getOutputStream()); | ||
| 90 | +//// String jsonString = JSON.toJSONString(param); | ||
| 91 | +//// printout.write(jsonString.getBytes("GBK")); | ||
| 92 | +// printout.write(("list="+param.get("list").toString()).getBytes("GBK")); | ||
| 93 | +// printout.flush(); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + in = con.getInputStream(); | ||
| 97 | + ByteArrayOutputStream bout = new ByteArrayOutputStream(); | ||
| 98 | + IOUtils.copy(in, bout); bout.close(); | ||
| 99 | + if (con.getResponseCode() == 200) { | ||
| 100 | + cb.success(bout.toByteArray(), con.getHeaderFields()); | ||
| 101 | + } else { | ||
| 102 | + log.info(new String(bout.toByteArray())); | ||
| 103 | + cb.failed(); | ||
| 104 | + } | ||
| 105 | + } catch (IOException e) { | ||
| 106 | + // TODO Auto-generated catch block | ||
| 107 | + log.error("cost:" + (System.currentTimeMillis() - start)); | ||
| 108 | + log.error("HttpUtils.request异常", e); | ||
| 109 | + cb.failed(); | ||
| 110 | + } catch (Exception e) { | ||
| 111 | + log.error("处理异常", e); | ||
| 112 | + } finally { | ||
| 113 | + con.disconnect(); | ||
| 114 | + try { | ||
| 115 | + if (in != null) in.close(); | ||
| 116 | + if (printout != null) printout.close(); | ||
| 117 | + if (out != null) out.close(); | ||
| 118 | + } catch (IOException e) { | ||
| 119 | + // TODO Auto-generated catch block | ||
| 120 | + e.printStackTrace(); | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | + } | ||
| 124 | +} |
src/main/resources/application.yml
| 1 | -spring: | ||
| 2 | - profiles: | ||
| 3 | - active: dev | ||
| 4 | - view: | ||
| 5 | - suffix: .html | ||
| 6 | -server: | ||
| 7 | - session-timeout: -1 | ||
| 8 | -security: | ||
| 9 | - basic: | ||
| 10 | - enabled: false | ||
| 11 | - compression: | ||
| 12 | - enabled: true | ||
| 13 | - mime-types: application/json,application/xml,text/html,text/xml,text/plain,text/javascript,text/css,application/javascript | ||
| 14 | -hibernate: | ||
| 15 | - jdbc: | ||
| 16 | - batch_size: 50 | ||
| 17 | - | ||
| 18 | -# \u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F\u9650\u5236\u914D\u7F6E | ||
| 19 | -# File size limit | ||
| 20 | -multipart: | ||
| 21 | - maxFileSize: -1 | ||
| 22 | -# Total request size for a multipart/form-data | 1 | +spring: |
| 2 | + profiles: | ||
| 3 | + active: prod | ||
| 4 | + view: | ||
| 5 | + suffix: .html | ||
| 6 | +server: | ||
| 7 | + session-timeout: -1 | ||
| 8 | +security: | ||
| 9 | + basic: | ||
| 10 | + enabled: false | ||
| 11 | + compression: | ||
| 12 | + enabled: true | ||
| 13 | + mime-types: application/json,application/xml,text/html,text/xml,text/plain,text/javascript,text/css,application/javascript | ||
| 14 | +hibernate: | ||
| 15 | + jdbc: | ||
| 16 | + batch_size: 50 | ||
| 17 | + | ||
| 18 | +# \u4E0A\u4F20\u6587\u4EF6\u5927\u5C0F\u9650\u5236\u914D\u7F6E | ||
| 19 | +# File size limit | ||
| 20 | +multipart: | ||
| 21 | + maxFileSize: -1 | ||
| 22 | +# Total request size for a multipart/form-data | ||
| 23 | maxRequestSize: -1 | 23 | maxRequestSize: -1 |
| 24 | \ No newline at end of file | 24 | \ No newline at end of file |