Commit 5917e3583b0ed81a1d23f043840be2e97b68f91c

Authored by 王通
1 parent 1fa5d347

1.解决露虹喜欢修改基础数据造成路单上传失败的问题

src/main/java/com/bsth/repository/LineVersionsRepository.java
1 -package com.bsth.repository;  
2 -  
3 -import java.util.Date;  
4 -import java.util.List;  
5 -  
6 -import org.springframework.data.jpa.repository.Modifying;  
7 -import org.springframework.data.jpa.repository.Query;  
8 -import org.springframework.stereotype.Repository;  
9 -import org.springframework.transaction.annotation.Transactional;  
10 -  
11 -import com.bsth.entity.Line;  
12 -import com.bsth.entity.LineVersions;  
13 -  
14 -/**  
15 - *  
16 - * @Interface: LineVersionsRepository(线路Repository数据持久层接口)  
17 - *  
18 - * @Extends : BaseRepository  
19 - *  
20 - * @Description: TODO(线路版本Repository数据持久层接口)  
21 - *  
22 - * @Author bsth@lq  
23 - *  
24 - * @Version 公交调度系统BS版 0.1  
25 - *  
26 - */  
27 -@Repository  
28 -public interface LineVersionsRepository extends BaseRepository<LineVersions, Integer> {  
29 -  
30 - /**  
31 - * 获取线路所有版本  
32 - */  
33 - @Query(value = " SELECT lv FROM LineVersions lv where lv.line.id = ?1")  
34 - public List<LineVersions> findBylineId(int lineId);  
35 -  
36 - @Transactional  
37 - @Modifying  
38 - @Query(value = "UPDATE LineVersions lv set lv.line=?2, lv.lineCode=?3, lv.startDate=?4, lv.endDate=?5, "  
39 - + "lv.versions=?6, lv.status=?7, lv.remark=?8 where lv.id=?1")  
40 - public int update(Integer id, Line line, String lineCode, Date startDate, Date endDate, Integer versions, Integer status,  
41 - String remark);  
42 -  
43 - /**  
44 - * 查询待更新线路的线路版本  
45 - */  
46 - @Query(value = "SELECT lv FROM LineVersions lv where lv.status = 2 and lv.startDate<sysdate() and lv.endDate > sysdate() and lv.isupdate != 1")  
47 - public List<LineVersions> findupdated();  
48 -  
49 - /**  
50 - * 更改为历史版本  
51 - */  
52 - @Modifying  
53 - @Query(value = "UPDATE LineVersions lv set lv.status=0 where lv.line.id=?1 and lv.lineCode=?2 and lv.status=1")  
54 - public void updateOdlVersions(Integer lineId, String lineCode);  
55 -  
56 - /**  
57 - * 更改为当前版本  
58 - */  
59 - @Modifying  
60 - @Query(value = "UPDATE LineVersions lv set lv.status=1 where lv.line.id=?1 and lv.lineCode=?2 and lv.versions=?3")  
61 - public void updateNewVersions(Integer lineId, String lineCode, Integer versions);  
62 -  
63 -  
64 - /**  
65 - * 查询线路最大线路版本  
66 - */  
67 - @Query(value = "select lv2 from LineVersions lv2 where lv2.line.id =?1 and lv2.versions=(SELECT max(lv.versions) FROM LineVersions lv where lv.line.id = ?1) ")  
68 - public LineVersions findLineVersionsMax(int lineId);  
69 -  
70 - /**  
71 - * 获取线路版本的上一个版本  
72 - */  
73 - @Query(value = " SELECT lv FROM LineVersions lv where lv.line.id = ?1 and lv.versions = (SELECT MAX(v.versions) FROM LineVersions v where v.line.id = ?1 and v.versions < ?2)")  
74 - public LineVersions findBylineIdAndVersions(Integer id, Integer versions);  
75 -  
76 -  
77 - /**  
78 - * 获取线路版本的上一个版本  
79 - */  
80 - @Query(value = " SELECT lv.versions FROM LineVersions lv where lv.line.id = ?1 and lv.status=1")  
81 - public Integer findCurrentVersion(Integer id);  
82 -  
83 - /**  
84 - * 发布版本  
85 - */  
86 - @Transactional  
87 - @Modifying  
88 - @Query(value = "UPDATE LineVersions lv set lv.isupdate=1 where lv.id=?1 ")  
89 - public int issueVersion(int id);  
90 -} 1 +package com.bsth.repository;
  2 +
  3 +import java.util.Date;
  4 +import java.util.List;
  5 +
  6 +import org.springframework.data.jpa.repository.Modifying;
  7 +import org.springframework.data.jpa.repository.Query;
  8 +import org.springframework.stereotype.Repository;
  9 +import org.springframework.transaction.annotation.Transactional;
  10 +
  11 +import com.bsth.entity.Line;
  12 +import com.bsth.entity.LineVersions;
  13 +
  14 +/**
  15 + *
  16 + * @Interface: LineVersionsRepository(线路Repository数据持久层接口)
  17 + *
  18 + * @Extends : BaseRepository
  19 + *
  20 + * @Description: TODO(线路版本Repository数据持久层接口)
  21 + *
  22 + * @Author bsth@lq
  23 + *
  24 + * @Version 公交调度系统BS版 0.1
  25 + *
  26 + */
  27 +@Repository
  28 +public interface LineVersionsRepository extends BaseRepository<LineVersions, Integer> {
  29 +
  30 + /**
  31 + * 获取线路所有版本
  32 + */
  33 + @Query(value = " SELECT lv FROM LineVersions lv where lv.line.id = ?1")
  34 + public List<LineVersions> findBylineId(int lineId);
  35 +
  36 + @Transactional
  37 + @Modifying
  38 + @Query(value = "UPDATE LineVersions lv set lv.line=?2, lv.lineCode=?3, lv.startDate=?4, lv.endDate=?5, "
  39 + + "lv.versions=?6, lv.status=?7, lv.remark=?8 where lv.id=?1")
  40 + public int update(Integer id, Line line, String lineCode, Date startDate, Date endDate, Integer versions, Integer status,
  41 + String remark);
  42 +
  43 + /**
  44 + * 查询待更新线路的线路版本
  45 + */
  46 + @Query(value = "SELECT lv FROM LineVersions lv where lv.status = 2 and lv.startDate<sysdate() and lv.endDate > sysdate() and lv.isupdate != 1")
  47 + public List<LineVersions> findupdated();
  48 +
  49 + /**
  50 + * 更改为历史版本
  51 + */
  52 + @Modifying
  53 + @Query(value = "UPDATE LineVersions lv set lv.status=0 where lv.line.id=?1 and lv.lineCode=?2 and lv.status=1")
  54 + public void updateOdlVersions(Integer lineId, String lineCode);
  55 +
  56 + /**
  57 + * 更改为当前版本
  58 + */
  59 + @Modifying
  60 + @Query(value = "UPDATE LineVersions lv set lv.status=1 where lv.line.id=?1 and lv.lineCode=?2 and lv.versions=?3")
  61 + public void updateNewVersions(Integer lineId, String lineCode, Integer versions);
  62 +
  63 +
  64 + /**
  65 + * 查询线路最大线路版本
  66 + */
  67 + @Query(value = "select lv2 from LineVersions lv2 where lv2.line.id =?1 and lv2.versions=(SELECT max(lv.versions) FROM LineVersions lv where lv.line.id = ?1) ")
  68 + public LineVersions findLineVersionsMax(int lineId);
  69 +
  70 + /**
  71 + * 获取线路版本的上一个版本
  72 + */
  73 + @Query(value = " SELECT lv FROM LineVersions lv where lv.line.id = ?1 and lv.versions = (SELECT MAX(v.versions) FROM LineVersions v where v.line.id = ?1 and v.versions < ?2)")
  74 + public LineVersions findBylineIdAndVersions(Integer id, Integer versions);
  75 +
  76 +
  77 + /**
  78 + * 获取线路版本的上一个版本
  79 + */
  80 + @Query(value = " SELECT lv.versions FROM LineVersions lv where lv.line.id = ?1 and lv.status=1")
  81 + public Integer findCurrentVersion(Integer id);
  82 +
  83 + /**
  84 + * 发布版本
  85 + */
  86 + @Transactional
  87 + @Modifying
  88 + @Query(value = "UPDATE LineVersions lv set lv.isupdate=1 where lv.id=?1 ")
  89 + public int issueVersion(int id);
  90 +
  91 + /**
  92 + * 获取指定日期的线路版本
  93 + */
  94 + @Query(value = " SELECT lv FROM LineVersions lv where FROM_UNIXTIME(?1) between lv.startDate and lv.endDate")
  95 + public List<LineVersions> findLineVersionsByDate(int timestamp);
  96 +}
src/main/java/com/bsth/service/impl/TrafficManageServiceImpl.java
1 -package com.bsth.service.impl;  
2 -  
3 -import com.bsth.data.BasicData;  
4 -import com.bsth.email.SendEmailController;  
5 -import com.bsth.email.entity.EmailBean;  
6 -import com.bsth.entity.*;  
7 -import com.bsth.entity.realcontrol.ChildTaskPlan;  
8 -import com.bsth.entity.realcontrol.ScheduleRealInfo;  
9 -import com.bsth.entity.schedule.SchedulePlanInfo;  
10 -import com.bsth.entity.schedule.TTInfo;  
11 -import com.bsth.entity.schedule.TTInfoDetail;  
12 -import com.bsth.entity.search.CustomerSpecs;  
13 -import com.bsth.entity.sys.SysUser;  
14 -import com.bsth.entity.traffic.SKBUploadLogger;  
15 -import com.bsth.repository.*;  
16 -import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;  
17 -import com.bsth.repository.schedule.*;  
18 -import com.bsth.repository.traffic.SKBUploadLoggerRepository;  
19 -import com.bsth.security.util.SecurityUtils;  
20 -import com.bsth.service.TrafficManageService;  
21 -import com.bsth.service.traffic.YgcBasicDataService;  
22 -import com.bsth.util.TimeUtils;  
23 -import com.bsth.util.db.DBUtils_MS;  
24 -import com.bsth.webService.trafficManage.org.tempuri.Results;  
25 -import com.bsth.webService.trafficManage.org.tempuri.WebServiceLocator;  
26 -import com.bsth.webService.trafficManage.org.tempuri.WebServiceSoap;  
27 -import org.apache.commons.lang.StringEscapeUtils;  
28 -import org.apache.commons.lang.StringUtils;  
29 -import org.apache.commons.lang.time.DateUtils;  
30 -import org.slf4j.Logger;  
31 -import org.slf4j.LoggerFactory;  
32 -import org.springframework.beans.factory.annotation.Autowired;  
33 -import org.springframework.data.domain.Sort;  
34 -import org.springframework.data.domain.Sort.Direction;  
35 -import org.springframework.stereotype.Service;  
36 -  
37 -import java.io.*;  
38 -import java.net.InetAddress;  
39 -import java.sql.Connection;  
40 -import java.sql.PreparedStatement;  
41 -import java.sql.ResultSet;  
42 -import java.text.DecimalFormat;  
43 -import java.text.SimpleDateFormat;  
44 -import java.util.*;  
45 -import java.util.regex.Matcher;  
46 -import java.util.regex.Pattern;  
47 -  
48 -/**  
49 - *  
50 - * @ClassName: TrafficManageServiceImpl(运管处接口service业务层实现类)  
51 - *  
52 - * @Extends : BaseService  
53 - *  
54 - * @Description: TODO(运管处接口service业务层)  
55 - *  
56 - * @Author bsth@zq  
57 - *  
58 - * @Date 2016年10月28日 上午9:21:17  
59 - *  
60 - * @Version 公交调度系统BS版 0.1  
61 - *  
62 - */  
63 -  
64 -@Service  
65 -public class TrafficManageServiceImpl implements TrafficManageService{  
66 -  
67 - Logger logger = LoggerFactory.getLogger(this.getClass());  
68 -  
69 - // 线路repository  
70 - @Autowired  
71 - private LineRepository lineRepository;  
72 -  
73 - @Autowired  
74 - private LineInformationRepository lineInformationRepository;  
75 -  
76 - // 站点路由repository  
77 - @Autowired  
78 - private StationRouteRepository stationRouteRepository;  
79 -  
80 - // 历史站点路由repository  
81 - @Autowired  
82 - private LsStationRouteRepository lsStationRouteRepository;  
83 -  
84 - @Autowired  
85 - private SectionRepository sectionRepository;  
86 -  
87 - // 车辆repository  
88 - @Autowired  
89 - private CarsRepository carsRepository;  
90 -  
91 - // 人员repository  
92 - @Autowired  
93 - private PersonnelRepository personnelRepository;  
94 -  
95 - // 时刻模板repository  
96 - @Autowired  
97 - private TTInfoRepository ttInfoRepository;  
98 -  
99 - // 时刻模板明细repository  
100 - @Autowired  
101 - private TTInfoDetailRepository ttInfoDetailRepository;  
102 -  
103 - // 排班计划明细repository  
104 - @Autowired  
105 - private SchedulePlanInfoRepository schedulePlanInfoRepository;  
106 -  
107 - // 实际排班计划明细repository  
108 - @Autowired  
109 - private ScheduleRealInfoRepository scheduleRealInfoRepository;  
110 -  
111 - // 时刻表上传记录repository  
112 - @Autowired  
113 - private SKBUploadLoggerRepository skbUploadLoggerRepository;  
114 -  
115 - // 线路站点repository  
116 - @Autowired  
117 - private YgcBasicDataService ygcBasicDataService;  
118 -  
119 - // 发送邮件  
120 - @Autowired  
121 - private SendEmailController sendEmailController;  
122 -  
123 - // 运管处上传接口  
124 - private com.bsth.webService.trafficManage.up.org.tempuri.WebServiceSoap webServiceSoapUp;  
125 - private WebServiceSoap ssop ;  
126 - {  
127 - try {  
128 - ssop = new WebServiceLocator().getWebServiceSoap();  
129 - } catch (Exception e) {  
130 - e.printStackTrace();  
131 - }  
132 - }  
133 - // 格式化 年月日时分秒 nyrsfm是年月日时分秒的拼音首字母  
134 - private SimpleDateFormat sdfnyrsfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
135 -  
136 - // 格式化 年月日  
137 - private SimpleDateFormat sdfnyr = new SimpleDateFormat("yyyy-MM-dd");  
138 -  
139 - // 数字格式化  
140 - DecimalFormat format = new DecimalFormat("0.00");  
141 -  
142 - // 用户名  
143 - private final String userNameOther = "user";  
144 - // 密码  
145 - private final String passwordOther = "user";  
146 -  
147 - // 用户名  
148 - private final String userNameUp = "user";  
149 - // 密码  
150 - private final String passwordUp = "user";  
151 - // 接收邮件人  
152 - private final String emailSendToAddress = "175912183@qq.com";  
153 - // 记录路单上线的成功、失败线路数  
154 - private Integer countSuccess,countFailure;  
155 -  
156 - private synchronized com.bsth.webService.trafficManage.up.org.tempuri.WebServiceSoap getWebServiceSoapUp(){  
157 - try {  
158 - if(webServiceSoapUp == null){  
159 - webServiceSoapUp = new com.bsth.webService.trafficManage.up.org.tempuri.WebServiceLocator().getWebServiceSoap();  
160 - }  
161 - }catch (Exception e){  
162 - e.printStackTrace();  
163 - }finally {  
164 - return webServiceSoapUp;  
165 - }  
166 - }  
167 - /**  
168 - * 上传线路信息  
169 - */  
170 - @Override  
171 - public String setXL(String ids) {  
172 - String result = "failure";  
173 - StringBuffer sBuffer = new StringBuffer();  
174 - String[] idArray = ids.split(",");  
175 - try {  
176 - for (String id : idArray) {  
177 - if(id == null || id.trim().equals("")){  
178 - continue;  
179 - }  
180 - Map<String,Object> map = new HashMap<>();  
181 - map.put("lineCode_eq", id);  
182 - Line line ;  
183 - LineInformation lineInformation;  
184 - line = lineRepository.findOne(new CustomerSpecs<Line>(map));  
185 - if(line == null){  
186 - continue;  
187 - }  
188 - List<StationRoute> upStationsList ;// 上行站点路由集  
189 - List<StationRoute> downStationsList;// 下行站点路由集  
190 - List<Object[]> downPointList;// 下行站点集  
191 - List<Object[]> upPointList;// 上行站点集  
192 - sBuffer.append("<XLs>");  
193 - sBuffer.append("<XL>");  
194 - if(BasicData.lineId2ShangHaiCodeMap.get(line.getId()) == null){  
195 - return result;  
196 - }  
197 - map = new HashMap<>();  
198 - map.put("line.id_eq",line.getId());  
199 - lineInformation = lineInformationRepository.findOne(new CustomerSpecs<LineInformation>(map));  
200 - if(lineInformation == null){  
201 - continue;  
202 - }  
203 - sBuffer.append("<XLBM>").append(BasicData.lineId2ShangHaiCodeMap.get(line.getId())).append("</XLBM>");  
204 - sBuffer.append("<XLMC>").append(line.getName()).append("</XLMC>");  
205 - sBuffer.append("<QDZ>").append(line.getStartStationName()).append("</QDZ>");  
206 - sBuffer.append("<ZDZ>").append(line.getEndStationName()).append("</ZDZ>");  
207 - sBuffer.append("<QZLC>").append(lineInformation.getUpMileage()).append("</QZLC>");  
208 - sBuffer.append("<ZQLC>").append(lineInformation.getDownMileage()).append("</ZQLC>");  
209 - sBuffer.append("<XLGH>").append(line.getLinePlayType()).append("</XLGH>");  
210 - sBuffer.append("<UPDATE_DATE>").append(sdfnyr.format(new Date())).append("</UPDATE_DATE>");  
211 -  
212 - // 循环添加站点信息  
213 - sBuffer.append("<StationList>");  
214 -  
215 - // 先查上行  
216 - upStationsList = stationRouteRepository.findByLine(line.getLineCode(), 0);  
217 - Map<String, Integer> stationNumMap = getStationName2YgcNumberMap(line.getLineCode());  
218 - int startId = 1;  
219 - startId = packagStationXml(upStationsList, sBuffer, startId,stationNumMap);  
220 - // 环线不查下行  
221 - if(line.getLinePlayType() != 1){  
222 - // 再查下行  
223 - downStationsList = stationRouteRepository.findByLine(line.getLineCode(), 1);  
224 - packagStationXml(downStationsList, sBuffer, startId,stationNumMap);  
225 - }  
226 - sBuffer.append("</StationList>");  
227 -  
228 - // 循环添加站点点位信息  
229 - sBuffer.append("<LinePointList>");  
230 - upPointList = sectionRepository.getSectionDirByLineId(line.getId(),0);  
231 - startId = 1;  
232 - startId = packagStationPointXml(upPointList, sBuffer, startId);  
233 - // 环线不查下行  
234 - if(line.getLinePlayType() != 1){  
235 - downPointList = sectionRepository.getSectionDirByLineId(line.getId(),1);  
236 - packagStationPointXml(downPointList, sBuffer, startId);  
237 - }  
238 - sBuffer.append("</LinePointList>");  
239 - sBuffer.append("</XL>");  
240 - sBuffer.append("</XLs>");  
241 - // 临时添加,后面删除  
242 - if(sBuffer.indexOf("<ZDXH>0</ZDXH>") != -1){  
243 - return "0";  
244 - }  
245 - // 调用上传方法  
246 - if(getWebServiceSoapUp().setXL(userNameUp,passwordUp,sBuffer.toString()).isSuccess()){  
247 - result = "success";  
248 - }else{  
249 - result = "failure";  
250 - }  
251 - logger.info("setXL:"+sBuffer.toString());  
252 - logger.info("setXL:"+result);  
253 - }  
254 - } catch (Exception e) {  
255 - logger.error("setXL:",e);  
256 - e.printStackTrace();  
257 - }  
258 - return result;  
259 - }  
260 -  
261 - /**  
262 - * 加载运管处的站点及序号  
263 - * 上行从1开始,下行顺序续编  
264 - */  
265 - private Map<String, Integer> getStationName2YgcNumberMap (String lineCode){  
266 - Map<String, Integer> resultMap = new HashMap<>();  
267 - List<Map<String, String>> ygcLines = stationRouteRepository.findLineWithYgcByLine(lineCode);  
268 - if(ygcLines != null && ygcLines.size() > 0){  
269 - int size = ygcLines.size();  
270 - Map<String, String> tempMap ;  
271 - int num = 1;  
272 - String key;  
273 - for (int i = 0; i < size; i ++){  
274 - tempMap = ygcLines.get(i);  
275 - key = tempMap.get("lineCode") + "_"+String.valueOf(tempMap.get("directions"))  
276 - + "_"+tempMap.get("stationCode")+ "_"+tempMap.get("stationMark");  
277 - resultMap.put(key,num++);  
278 - }  
279 - }  
280 - return resultMap;  
281 - }  
282 -  
283 - /**  
284 - * 上传线路信息(按in_use上传)  
285 - */  
286 - @Override  
287 - public String setXLByInUse(String inUse) {  
288 - StringBuffer result = new StringBuffer();  
289 - try {  
290 - Map<String,Object> map = new HashMap<>();  
291 - if(inUse != null && inUse.equals("1")){  
292 - map.put("inUse_eq", inUse);  
293 - }  
294 - List<Line> lines ;  
295 - Line line;  
296 - lines = lineRepository.findAll(new CustomerSpecs<Line>(map));  
297 - if(lines != null && lines.size() > 0){  
298 - for(int i = 0 ; i < lines.size() ; i ++){  
299 - line = lines.get(i);  
300 - if(line != null && line.getId() != null){  
301 - result.append(line.getLineCode()).append(":").append(setXL(line.getLineCode())).append(";");  
302 - }  
303 - }  
304 - }  
305 - } catch (Exception e) {  
306 - result.append("failure");  
307 - logger.error("setXLByInUse:",e);  
308 - e.printStackTrace();  
309 - }  
310 - return result.toString();  
311 - }  
312 -  
313 - /**  
314 - * 上传车辆信息  
315 - */  
316 - @Override  
317 - public String setCL() {  
318 - String result = "failure";  
319 - StringBuffer sBuffer =new StringBuffer();  
320 - try {  
321 - sBuffer.append("<CLs>");  
322 - Cars cars = null;  
323 - String company;  
324 - Iterator<Cars> carsIterator = carsRepository.findAll().iterator();  
325 - while(carsIterator.hasNext()){  
326 - cars = carsIterator.next();  
327 - sBuffer.append("<CL>");  
328 - company = cars.getCompany();  
329 - setCompanyName(company);// 统一公司名称  
330 - sBuffer.append("<GSJC>").append(company).append("</GSJC>");  
331 - sBuffer.append("<NBH>").append(cars.getInsideCode()).append("</NBH>");  
332 - sBuffer.append("<CPH>").append(cars.getCarPlate()).append("</CPH>");  
333 - sBuffer.append("<YYZBH>").append(cars.getServiceNo()).append("</YYZBH>");  
334 - sBuffer.append("<CZCPH>").append(cars.getCarPlate()).append("</CZCPH>");//******这个数据没有***********  
335 - sBuffer.append("<CZZDBH>").append(cars.getEquipmentCode()).append("</CZZDBH>");  
336 - sBuffer.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");  
337 - sBuffer.append("</CL>");  
338 - }  
339 - sBuffer.append("</CLs>");  
340 - if(ssop.setCL(userNameOther, passwordOther, sBuffer.toString()).isSuccess()){  
341 - result = "success";  
342 - }  
343 - } catch (Exception e) {  
344 - logger.error("setCL:",e);  
345 - e.printStackTrace();  
346 - }finally{  
347 - logger.info("setCL:"+sBuffer.toString());  
348 - logger.info("setCL:"+result);  
349 - }  
350 - return result;  
351 - }  
352 -  
353 - /**  
354 - * 上传司机信息  
355 - */  
356 - @Override  
357 - public String setSJ() {  
358 - String result = "failure";  
359 - StringBuffer sBuffer =new StringBuffer();  
360 - try {  
361 - sBuffer.append("<SJs>");  
362 - Personnel personnel = null;  
363 - String company;  
364 - Iterator<Personnel> personIterator = personnelRepository.findAll().iterator();  
365 - while(personIterator.hasNext()){  
366 - personnel = personIterator.next();  
367 - sBuffer.append("<SJ>");  
368 - company = personnel.getCompany();  
369 - setCompanyName(company);// 统一公司名称  
370 - sBuffer.append("<GSJC>").append(company).append("</GSJC>");  
371 - sBuffer.append("<SJGH>").append(personnel.getJobCode()).append("</SJGH>");  
372 - sBuffer.append("<CYZGZH>").append(personnel.getPapersCode()).append("</CYZGZH>");//***********  
373 - sBuffer.append("<XM>").append(personnel.getPersonnelName()).append("</XM>");  
374 - sBuffer.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");  
375 - sBuffer.append("</SJ>");  
376 - }  
377 - sBuffer.append("</SJs>");  
378 - if(ssop.setSJ(userNameOther, passwordOther, sBuffer.toString()).isSuccess()){  
379 - result = "success";  
380 - };  
381 - } catch (Exception e) {  
382 - logger.error("setSJ:",e);  
383 - e.printStackTrace();  
384 - }finally{  
385 - logger.info("setSJ:"+sBuffer.toString());  
386 - logger.info("setSJ:"+result);  
387 - }  
388 - return result;  
389 - }  
390 -  
391 - /**  
392 - * 上传路单 指定日期 yyyy-MM-dd  
393 - * @param theDate  
394 - * @return  
395 - */  
396 - public String setLD(String theDate){  
397 - return uploadLD(theDate);  
398 - }  
399 -  
400 - /**  
401 - * 上传路单 上传前一天的路单  
402 - * @return  
403 - */  
404 - public String setLD(){  
405 - return uploadLD(null);  
406 - }  
407 - /**  
408 - * 上传路单  
409 - * @return 上传成功标识  
410 - */  
411 - private String uploadLD(String theDate){  
412 - String result = "failure";  
413 - countSuccess = 0 ;countFailure = 0;  
414 - Line line;  
415 - // 取昨天 的日期  
416 - String date = theDate == null ?sdfnyr.format(DateUtils.addDays(new Date(), -1)) : theDate;  
417 - StringBuffer sf = new StringBuffer();  
418 - StringBuffer logSuccess = new StringBuffer("成功:");  
419 - StringBuffer logFailure = new StringBuffer("失败:");  
420 - HashMap logXlbmSuccessMap = new HashMap();  
421 - HashMap logXlbmFailureMap = new HashMap();  
422 - HashMap logXlbmMap = new HashMap();  
423 - Results results = null;  
424 - String str = "",xlbm;  
425 - try {  
426 - int counter = 0; // 计数器  
427 - int per = 10; // 每几条线路上传一次路单  
428 -  
429 - List<ScheduleRealInfo> list = scheduleRealInfoRepository.setLD(date);  
430 - List<Map<String,Object>> listGroup = scheduleRealInfoRepository.setLDGroup(date);  
431 - Map<String,Object> map = new HashMap();  
432 - HashMap<String,String> paramMap;  
433 - HashMap<String,String> otherMap = new HashMap();  
434 - for(Map<String,Object> schRealInfo:listGroup){  
435 - if(schRealInfo != null){  
436 - //根据车辆自编号查询车牌号  
437 - map.put("insideCode_eq", schRealInfo.get("clZbh")+"");  
438 - Cars car = carsRepository.findOne(new CustomerSpecs<Cars>(map));  
439 - // 获取线路是否使用标识,如果未使用,则不查该线路数据  
440 - line = lineRepository.findByLineCode(schRealInfo.get("xlBm")+"");  
441 - if(line == null || line.getInUse() == null || line.getInUse() == 0){  
442 - continue;  
443 - }  
444 - if(counter % per == 0){  
445 - sf = new StringBuffer();  
446 - sf.append("<DLDS>");  
447 - }  
448 - counter ++;  
449 - xlbm = BasicData.lineCode2ShangHaiCodeMap.get(schRealInfo.get("xlBm")+"");  
450 - // 保存一次路单的线路编码,用于发送邮箱  
451 - if(logXlbmMap.get(xlbm) == null){  
452 - logXlbmMap.put(xlbm,xlbm);  
453 - }  
454 - sf.append("<DLD>");  
455 - sf.append("<RQ>"+date+"</RQ>");  
456 - sf.append("<XLBM>"+xlbm+"</XLBM>");  
457 - sf.append("<LPBH>"+schRealInfo.get("lpName")+"</LPBH>");  
458 - sf.append("<CPH>"+car.getCarPlate()+"</CPH>");  
459 - sf.append("<UPDT>"+sdfnyrsfm.format(new Date())+"</UPDT>");  
460 - sf.append("<LDList>");  
461 - for(ScheduleRealInfo scheduleRealInfo:list){  
462 - if((schRealInfo.get("xlBm")+"").equals(scheduleRealInfo.getXlBm()) && (schRealInfo.get("lpName")+"")  
463 - .equals(scheduleRealInfo.getLpName())  
464 - && (schRealInfo.get("clZbh")+"").equals(scheduleRealInfo.getClZbh())){  
465 -  
466 - if(scheduleRealInfo.isDestroy()){  
467 - if(scheduleRealInfo.isReissue()){  
468 - scheduleRealInfo.setFcsjActualAll(scheduleRealInfo.getDfsj());  
469 - scheduleRealInfo.setZdsjActualAll(scheduleRealInfo.getZdsj());  
470 - }  
471 - else  
472 - continue;  
473 - }  
474 -  
475 - if(scheduleRealInfo.getBcType().equals("in")  
476 - || scheduleRealInfo.getBcType().equals("out")){  
477 - continue;  
478 - }  
479 -  
480 - sf.append("<LD>");  
481 - sf.append("<SJGH>"+scheduleRealInfo.getjGh()+"</SJGH>");  
482 - sf.append("<SXX>"+scheduleRealInfo.getXlDir()+"</SXX>");  
483 - sf.append("<FCZDMC>"+scheduleRealInfo.getQdzName()+"</FCZDMC>");  
484 - // 起点站的参数  
485 - otherMap.put("stationMark","B");  
486 - paramMap = packageYgcStationNumParam(scheduleRealInfo,otherMap);  
487 - sf.append("<FCZDXH>" + getYgcStationNumByLineCodeAndDirectionAndStationName(paramMap,null) + "</FCZDXH>");  
488 - sf.append("<FCZDBM>"+scheduleRealInfo.getQdzCode()+"</FCZDBM>");  
489 - sf.append("<JHFCSJ>"+scheduleRealInfo.getFcsj()+"</JHFCSJ>");  
490 - sf.append("<DFSJ>"+scheduleRealInfo.getDfsj()+"</DFSJ>");  
491 - sf.append("<SJFCSJ>"+scheduleRealInfo.getFcsjActual()+"</SJFCSJ>");  
492 - sf.append("<FCZDLX>"+""+"</FCZDLX>");  
493 - sf.append("<DDZDMC>"+scheduleRealInfo.getZdzName()+"</DDZDMC>");  
494 - // 终点站的参数  
495 - otherMap.put("stationMark","E");  
496 - paramMap = packageYgcStationNumParam(scheduleRealInfo,otherMap);  
497 - sf.append("<DDZDXH>"+ getYgcStationNumByLineCodeAndDirectionAndStationName(paramMap,null) +"</DDZDXH>");  
498 - sf.append("<DDZDBM>"+scheduleRealInfo.getZdzCode()+"</DDZDBM>");  
499 - sf.append("<JHDDSJ>"+scheduleRealInfo.getZdsj()+"</JHDDSJ>");  
500 - sf.append("<SJDDSJ>"+scheduleRealInfo.getZdsjActual()+"</SJDDSJ>");  
501 - sf.append("<DDZDLX>"+""+"</DDZDLX>");  
502 - sf.append("<LDSCBZ>"+0+"</LDSCBZ>");  
503 - sf.append("<DDBZ>"+scheduleRealInfo.getRemarks()+"</DDBZ>");  
504 - sf.append("</LD>");  
505 - }  
506 - }  
507 - sf.append("</LDList>");  
508 - sf.append("</DLD>");  
509 - }  
510 - if(counter % per == per - 1){  
511 - counter = 0;  
512 - sf.append("</DLDS>");  
513 - str = sf.toString().replace("'","");// 去掉'号  
514 - results = ssop.setLD(userNameOther, passwordOther, StringEscapeUtils.unescapeHtml(str));  
515 - // 记录日志  
516 - result = logRecord(results,logXlbmMap,logXlbmSuccessMap,logXlbmFailureMap,logSuccess,logFailure,str);  
517 - }  
518 - }  
519 - // 每per条线路上传后剩下的数据再上传  
520 - if(counter > 0){  
521 - sf.append("</DLDS>");  
522 - str = sf.toString().replace("'","");// 去掉'号  
523 - results = ssop.setLD(userNameOther, passwordOther, StringEscapeUtils.unescapeHtml(str));  
524 - }  
525 - // 记录日志  
526 - result = logRecord(results,logXlbmMap,logXlbmSuccessMap,logXlbmFailureMap,logSuccess,logFailure,str);  
527 - } catch (Exception e) {  
528 - logger.error("setLD:",e);  
529 - logFailure.append(e).append("<br/>");  
530 - for (StackTraceElement traceElement : e.getStackTrace()){  
531 - logFailure.append("\r\t").append(traceElement);  
532 - }  
533 - e.printStackTrace();  
534 - }finally{  
535 - try {  
536 - //发送邮件  
537 - EmailBean mail = new EmailBean();  
538 - mail.setSubject(InetAddress.getLocalHost().getHostAddress()+":路单日志数据"+date);  
539 - mail.setContent("成功数:"+countSuccess+"<br/>失败数:"+countFailure+"<br/>" +logSuccess + "<br/>"+logFailure);  
540 - sendEmailController.sendMail(emailSendToAddress, mail);  
541 - logger.info("setLD-sendMail:邮件发送成功!");  
542 - }catch (Exception e){  
543 - e.printStackTrace();  
544 - logger.error("setLD-sendMail:",e);  
545 - }  
546 - }  
547 - return result;  
548 - }  
549 -  
550 - /**  
551 - * 记录日志  
552 - * @param results  
553 - * @param logXlbmMap  
554 - * @param logXlbmSuccessMap  
555 - * @param logXlbmFailureMap  
556 - * @param logSuccess  
557 - * @param logFailure  
558 - * @param str  
559 - */  
560 - private String logRecord(Results results,HashMap logXlbmMap,HashMap logXlbmSuccessMap,HashMap logXlbmFailureMap,StringBuffer logSuccess,  
561 - StringBuffer logFailure,String str){  
562 - String result = "failure";  
563 - // 记录日志  
564 - if(results != null){  
565 - if(results.isSuccess()){// 上传成功  
566 - // 把上线成功的线路编码放入 logXlbmSuccessMap,并记录logSuccess  
567 - countSuccess += fillMailXlbmMap(logXlbmMap,logXlbmSuccessMap,logSuccess);  
568 - result = "success";  
569 - }else{// 上传失败  
570 - // 把上线失败的线路编码放入 logXlbmFailureMap,并记录logFailure  
571 - countFailure += fillMailXlbmMap(logXlbmMap,logXlbmFailureMap,logFailure);  
572 - result = "failure";  
573 - }  
574 - logger.info("setLD:"+str);  
575 - logger.info("setLD:"+result);  
576 - results = null;  
577 - logXlbmMap = new HashMap();  
578 - }  
579 - return result;  
580 - }  
581 - /**  
582 - * 填充线路编码到相应的map  
583 - * @param fromMap  
584 - * @param toMap  
585 - */  
586 - private int fillMailXlbmMap(HashMap fromMap,HashMap toMap,StringBuffer logStr){  
587 - int tmpCount = 0;  
588 - for (Object key : fromMap.keySet()) {  
589 - if(toMap.get(key) == null){  
590 - toMap.put(key,fromMap.get(key));  
591 - logStr.append(key).append(",");  
592 - tmpCount ++;  
593 - }  
594 - }  
595 - fromMap = new HashMap();  
596 - return tmpCount;  
597 - }  
598 - /**  
599 - * 上传路单 xml来自文件  
600 - * @return 上传成功标识  
601 - */  
602 - public String setLDFile(){  
603 - String result = "failure";  
604 - try {  
605 - String tmp = readXmlFromFile("E:/ld.txt");  
606 - Results rss = ssop.setLD(userNameOther, passwordOther, StringEscapeUtils.unescapeHtml(tmp));  
607 - if(rss.isSuccess()){  
608 - result = "success";  
609 - }  
610 - } catch (Exception e) {  
611 - logger.error("setLD:",e);  
612 - e.printStackTrace();  
613 - }finally{  
614 -  
615 - }  
616 - return result;  
617 - }  
618 -  
619 - /**  
620 - * 从文件中读取xml  
621 - * @param fileName 例:D:/test.txt  
622 - * @return  
623 - * @throws Exception  
624 - */  
625 - private String readXmlFromFile(String fileName) throws Exception {  
626 - StringBuffer sf = new StringBuffer("");  
627 - File file = new File(fileName);  
628 - InputStreamReader reader = new InputStreamReader(new FileInputStream(file),"GBK");  
629 - BufferedReader bufferedReader = new BufferedReader(reader);  
630 - String lineTxt = "";  
631 - while((lineTxt = bufferedReader.readLine()) != null){  
632 - sf.append(lineTxt);  
633 - }  
634 - reader.close();  
635 - return sf.toString().replaceAll("\t","");  
636 - }  
637 - /**  
638 - * 上传里程油耗  
639 - * @return 上传成功标识  
640 - */  
641 - public String setLCYH(){  
642 - String result = "failure";  
643 - // 取昨天 的日期  
644 - String date = sdfnyr.format(DateUtils.addDays(new Date(), -1));  
645 - StringBuffer sf = new StringBuffer();  
646 - try {  
647 - sf.append("<LCYHS>");  
648 - List<Map<String,Object>> listGroup = scheduleRealInfoRepository.setLCYHGroup(date);  
649 - List<ScheduleRealInfo> list = scheduleRealInfoRepository.findByDate(date);  
650 - Map<String,Object> map = new HashMap<String,Object>();  
651 - for(Map<String,Object> schRealInfo:listGroup){  
652 - if(schRealInfo != null){  
653 - map.put("insideCode_eq", schRealInfo.get("clZbh")+"");  
654 - Cars car = carsRepository.findOne(new CustomerSpecs<Cars>(map));  
655 - /**  
656 - * 如果car==null,则说明该车辆是从线调中换车功能中加进去的,  
657 - * 在cars基础信息中查不到车辆的信息,所以忽略该车辆  
658 - */  
659 - if(car == null){  
660 - continue;  
661 - }  
662 - //计算总公里和空驶公里,营运公里=总公里-空驶公里  
663 - double totalKilometers = 0,emptyKilometers =0;  
664 - sf.append("<LCYH>");  
665 - sf.append("<RQ>"+date+"</RQ>");  
666 - sf.append("<XLBM>"+BasicData.lineCode2ShangHaiCodeMap.get(schRealInfo.get("xlBm"))+"</XLBM>");  
667 - sf.append("<CPH>"+car.getCarPlate()+"</CPH>");  
668 - if(list != null && list.size() > 0){  
669 - for(ScheduleRealInfo scheduleRealInfo:list){  
670 - if((schRealInfo.get("xlBm")+"").equals(scheduleRealInfo.getXlBm()) && (schRealInfo.get("clZbh")+"")  
671 - .equals(scheduleRealInfo.getClZbh())){  
672 - Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();  
673 - //如果没有子任务,里程就是已执行(Status=2);有子任务的,忽略主任务,子任务的烂班  
674 - if(childTaskPlans.isEmpty()){  
675 - if(scheduleRealInfo.getStatus() == 2){  
676 - totalKilometers += scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc();  
677 - if(scheduleRealInfo.getBcType().equals("in") || scheduleRealInfo.getBcType().equals("out")  
678 - || scheduleRealInfo.getBcType().equals("venting")){  
679 - emptyKilometers += scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc();  
680 - }  
681 - }  
682 - }else{  
683 - Iterator<ChildTaskPlan> it = childTaskPlans.iterator();  
684 - while(it.hasNext()){  
685 - ChildTaskPlan childTaskPlan = it.next();  
686 - if(!childTaskPlan.isDestroy()){  
687 - totalKilometers += childTaskPlan.getMileage()==null?0.0:childTaskPlan.getMileage();  
688 - if(childTaskPlan.getMileageType().equals("empty")){  
689 - emptyKilometers += childTaskPlan.getMileage()==null?0.0:childTaskPlan.getMileage();;  
690 - }  
691 - }  
692 - }  
693 - }  
694 - }  
695 - }  
696 - }  
697 - sf.append("<ZLC>"+totalKilometers+"</ZLC>");  
698 - sf.append("<YYLC>"+emptyKilometers+"</YYLC>");  
699 - sf.append("<YH>"+""+"</YH>");  
700 - sf.append("<JZYL>"+""+"</JZYL>");  
701 - sf.append("<DH>"+""+"</DH>");  
702 - sf.append("<UPDT>"+sdfnyrsfm.format(new Date())+"</UPDT>");  
703 - sf.append("<BBSCBZ>"+0+"</BBSCBZ>");  
704 - sf.append("</LCYH>");  
705 - }  
706 - }  
707 - sf.append("</LCYHS>");  
708 - if(ssop.setLCYH(userNameOther, passwordOther, sf.toString()).isSuccess()){  
709 - result = "success";  
710 - }  
711 - } catch (Exception e) {  
712 - logger.error("setLCYH:",e);  
713 - e.printStackTrace();  
714 - }finally{  
715 - logger.info("setLCYH:"+sf.toString());  
716 - logger.info("setLCYH:"+result);  
717 - }  
718 - return result;  
719 - }  
720 -  
721 - /**  
722 - * 上传线路调度日报  
723 - * @return  
724 - */  
725 - public String setDDRB(){  
726 - String result = "failure";  
727 - // 取昨天 的日期  
728 - String date = sdfnyr.format(DateUtils.addDays(new Date(), -1));  
729 - StringBuffer sf = new StringBuffer();  
730 - try {  
731 - sf.append("<DDRBS>");  
732 - List<Map<String,Object>> listGroup = scheduleRealInfoRepository.setDDRBGroup(date);  
733 - List<ScheduleRealInfo> list = scheduleRealInfoRepository.findByDate(date);  
734 - for(Map<String,Object> schRealInfo:listGroup){  
735 - if(schRealInfo != null){  
736 - double jhlc = 0,zlc = 0,jhkslc = 0,sjkslc = 0;  
737 - int jhbc = 0,sjbc = 0,jhzgfbc = 0,sjzgfbc = 0,jhwgfbc = 0,sjwgfbc = 0;  
738 - sf.append("<DDRB>");  
739 - sf.append("<RQ>"+date+"</RQ>");  
740 - sf.append("<XLBM>"+BasicData.lineCode2ShangHaiCodeMap.get(schRealInfo.get("xlBm"))+"</XLBM>");  
741 - for(ScheduleRealInfo scheduleRealInfo:list){  
742 - if(scheduleRealInfo != null){  
743 - if((schRealInfo.get("xlBm")+"").equals(scheduleRealInfo.getXlBm())){  
744 - //计划  
745 - if(!scheduleRealInfo.isSflj()){  
746 - jhlc += scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc();  
747 - //计划空驶  
748 - if(scheduleRealInfo.getBcType().equals("in") || scheduleRealInfo.getBcType().equals("out")){  
749 - jhkslc += scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc();  
750 - }  
751 - //计划早高峰,计划晚高峰  
752 - if(TimeUtils.morningPeak(scheduleRealInfo.getFcsj())){  
753 - jhzgfbc++;  
754 - } else if(TimeUtils.evenignPeak(scheduleRealInfo.getFcsj())){  
755 - jhwgfbc++;  
756 - }  
757 - }  
758 - jhbc++;  
759 -  
760 - //实际  
761 - Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();  
762 - //如果没有子任务,里程就是已执行(Status=2);有子任务的,忽略主任务,子任务的烂班  
763 - if(childTaskPlans.isEmpty()){  
764 - if(scheduleRealInfo.getStatus() == 2){  
765 - sjbc++;  
766 - zlc += scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc();  
767 - if(scheduleRealInfo.getBcType().equals("in") || scheduleRealInfo.getBcType().equals("out")  
768 - || scheduleRealInfo.getBcType().equals("venting")){  
769 - sjkslc += scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc();;  
770 - }  
771 - }  
772 - }else{  
773 - sjbc++;  
774 - Iterator<ChildTaskPlan> it = childTaskPlans.iterator();  
775 - while(it.hasNext()){  
776 - ChildTaskPlan childTaskPlan = it.next();  
777 - if(!childTaskPlan.isDestroy()){  
778 - zlc += childTaskPlan.getMileage()==null?0.0:childTaskPlan.getMileage();  
779 - if(childTaskPlan.getMileageType().equals("empty")){  
780 - sjkslc += childTaskPlan.getMileage()==null?0.0:childTaskPlan.getMileage();;  
781 - }  
782 - }  
783 - }  
784 - }  
785 - //实际早高峰,计划晚高峰  
786 - if(scheduleRealInfo.getFcsjActual() != null){  
787 - if(TimeUtils.morningPeak(scheduleRealInfo.getFcsj())){  
788 - sjzgfbc++;  
789 - } else if(TimeUtils.evenignPeak(scheduleRealInfo.getFcsj())){  
790 - sjwgfbc++;  
791 - }  
792 - }  
793 - }  
794 - }  
795 - }  
796 - sf.append("<JHLC>"+format.format(jhlc)+"</JHLC>");  
797 - sf.append("<SSLC>"+format.format((zlc-sjkslc))+"</SSLC>");  
798 - sf.append("<JHKSLC>"+format.format(jhkslc)+"</JHKSLC>");  
799 - sf.append("<SJKSLC>"+format.format(sjkslc)+"</SJKSLC>");  
800 - sf.append("<JHBC>"+jhbc+"</JHBC>");  
801 - sf.append("<SJBC>"+sjbc+"</SJBC>");  
802 - sf.append("<JHZGFBC>"+jhzgfbc+"</JHZGFBC>");  
803 - sf.append("<SJZGFBC>"+sjzgfbc+"</SJZGFBC>");  
804 - sf.append("<JHWGFBC>"+jhwgfbc+"</JHWGFBC>");  
805 - sf.append("<SJWGFBC>"+sjwgfbc+"</SJWGFBC>");  
806 - sf.append("<UPDT>"+sdfnyrsfm.format(new Date())+"</UPDT>");  
807 - sf.append("<RBSCBZ>"+0+"</RBSCBZ>");  
808 - sf.append("</DDRB>");  
809 - }  
810 - }  
811 - sf.append("</DDRBS>");  
812 - if(ssop.setDDRB(userNameOther, passwordOther, sf.toString()).isSuccess()){  
813 - result = "success";  
814 - }  
815 - } catch (Exception e) {  
816 - logger.error("setDDRB:",e);  
817 - e.printStackTrace();  
818 - }finally{  
819 - logger.info("setDDRB:"+sf.toString());  
820 - logger.info("setDDRB:"+result);  
821 - }  
822 - return result;  
823 - }  
824 -  
825 - /**  
826 - * 上传计划班次 指定日期 yyyy-MM-dd  
827 - * @param theDate  
828 - * @return  
829 - */  
830 - public String setJHBC(String theDate){  
831 - return uploadJHBC(theDate);  
832 - }  
833 -  
834 - /**  
835 - * 上传计划班次  
836 - * @return  
837 - */  
838 - public String setJHBC(){  
839 - return uploadJHBC(null);  
840 - }  
841 - /**  
842 - * 上传线路计划班次表  
843 - */  
844 -  
845 - private String uploadJHBC(String theDate) {  
846 - String result = "failure";  
847 - Line line;  
848 - StringBuffer sBuffer =new StringBuffer();  
849 - try {  
850 - sBuffer.append("<JHBCs>");  
851 - // 声明变量  
852 - SchedulePlanInfo schedulePlanInfo;  
853 - String xlbm,zbh = "";  
854 - Long lp = 0L;  
855 - // 取得计划班次时间  
856 - String tomorrow = theDate == null ? sdfnyr.format(DateUtils.addDays(new Date(), +1)) : theDate;  
857 - // 查询所有班次  
858 - List<SchedulePlanInfo> schedulePlanList = schedulePlanInfoRepository.findLineScheduleBc(tomorrow);  
859 - int j = 0; // 初始化标识  
860 - if(schedulePlanList != null ){  
861 - HashMap<String,String> paramMap;  
862 - HashMap<String,String> otherMap = new HashMap<String, String>();  
863 - int size = schedulePlanList.size();  
864 - for (int i = 0; i < size; i++) {  
865 - schedulePlanInfo = schedulePlanList.get(i);  
866 - xlbm = schedulePlanInfo.getXlBm();  
867 - // 获取线路是否使用标识,如果未使用,则不查该线路数据  
868 - line = lineRepository.findByLineCode(xlbm);  
869 - if(line.getInUse() == null || line.getInUse() == 0){  
870 - continue;  
871 - }  
872 - if(++j == 1){// 第一次,则初始化值  
873 - zbh = schedulePlanInfo.getClZbh();  
874 - lp = schedulePlanInfo.getLp();  
875 - // 拼装XML  
876 - assembleJHBC(sBuffer, schedulePlanInfo, xlbm, zbh, lp);  
877 - }  
878 - // 比较是否为同一条线路同一辆车  
879 - if(xlbm.equals(schedulePlanInfo.getXlBm())  
880 - && zbh.equals(schedulePlanInfo.getClZbh())  
881 - && lp == schedulePlanInfo.getLp()){  
882 - if(schedulePlanInfo.getBcType().equals("in") || schedulePlanInfo.getBcType().equals("out")){  
883 - continue;  
884 - }  
885 - sBuffer.append("<BC>");  
886 - sBuffer.append("<SJGH>").append(schedulePlanInfo.getjGh()).append("</SJGH>");  
887 - sBuffer.append("<SXX>").append(schedulePlanInfo.getXlDir()).append("</SXX>");  
888 - sBuffer.append("<FCZDMC>").append(schedulePlanInfo.getQdzName()).append("</FCZDMC>");  
889 - // 起点站的参数  
890 - otherMap.put("stationMark","B");  
891 - paramMap = packageYgcStationNumParam(schedulePlanInfo,otherMap);  
892 - sBuffer.append("<ZDXH>").append(getYgcStationNumByLineCodeAndDirectionAndStationName(paramMap,null)).append("</ZDXH>");  
893 - sBuffer.append("<JHFCSJ>").append(schedulePlanInfo.getFcsj()).append("</JHFCSJ>");  
894 - sBuffer.append("<DDZDMC>").append(schedulePlanInfo.getZdzName()).append("</DDZDMC>");  
895 - // 起点站的参数  
896 - otherMap.put("stationMark","E");  
897 - paramMap = packageYgcStationNumParam(schedulePlanInfo,otherMap);  
898 - sBuffer.append("<DDXH>").append(getYgcStationNumByLineCodeAndDirectionAndStationName(paramMap,null)).append("</DDXH>");  
899 - sBuffer.append("<JHDDSJ>").append(calcDdsj(schedulePlanInfo.getFcsj(),schedulePlanInfo.getBcsj()))  
900 - .append("</JHDDSJ>");  
901 - sBuffer.append("</BC>");  
902 - if(i == size -1 ){  
903 - sBuffer.append("</BCList>");  
904 - sBuffer.append("</JHBC>");  
905 - }  
906 - }else{  
907 - zbh = schedulePlanInfo.getClZbh();  
908 - lp = schedulePlanInfo.getLp();  
909 - sBuffer.append("</BCList>");  
910 - sBuffer.append("</JHBC>");  
911 - // 拼装XML  
912 - assembleJHBC(sBuffer, schedulePlanInfo, xlbm, zbh, lp);  
913 - }  
914 - }  
915 - }  
916 - // 判断XML是否以</BCList>结尾,如果不是,则加上  
917 - String regex = "^*</JHBC>$";  
918 - Pattern p = Pattern.compile(regex);  
919 - Matcher m = p.matcher(sBuffer);  
920 - boolean isEndWithTrueFlag = false;  
921 - while (m.find()) {  
922 - isEndWithTrueFlag = true;  
923 - }  
924 - // 加上缺失的标签  
925 - if(!isEndWithTrueFlag){  
926 - sBuffer.append("</BCList>");  
927 - sBuffer.append("</JHBC>");  
928 - }  
929 - sBuffer.append("</JHBCs>");  
930 - if(ssop.setJHBC(userNameOther, passwordOther, sBuffer.toString()).isSuccess()){  
931 - result = "success";  
932 - }  
933 - } catch (Exception e) {  
934 - logger.error("setJHBC:",e);  
935 - e.printStackTrace();  
936 - }finally{  
937 - logger.info("setJHBC:"+sBuffer.toString());  
938 - logger.info("setJHBC:"+result);  
939 - }  
940 - return result;  
941 - }  
942 -  
943 - /**  
944 - * 上传线路班次时刻表数据  
945 - */  
946 - @Override  
947 - public String setSKB(String ids) {  
948 - String result = "上传失败,";  
949 - StringBuffer sBuffer = new StringBuffer();  
950 - DecimalFormat df = new DecimalFormat("######0.000");  
951 - Map<String,String> lsStationCode2NameMap = null;  
952 - Map<String, Integer> lsStationName2YgcNumber = null;  
953 - try {  
954 - String[] idArray = ids.split(",");  
955 - StringBuffer sBufferA ,sBufferB ,sBufferC ;  
956 - double zlc,yylc,singleLc,emptyLc;// 总里程、营运里程、单程、空放里程  
957 - String bcType,sxx;// 班次类型、上下行  
958 - // 上传的时刻表集合  
959 - List<TTInfo> ttinfoList = new ArrayList<>();  
960 - TTInfo ttInfo;  
961 - TTInfoDetail ttInfoDetail;  
962 - LineInformation lineInformation;  
963 - Iterator<TTInfoDetail> ttInfoDetailIterator;  
964 - HashMap<String,Object> param ;  
965 - sBuffer.append("<SKBs>");  
966 - HashMap<String,String> paramMap;  
967 - HashMap<String,String> otherMap = new HashMap<>();  
968 - // 线路编码、周几执行、发车站点名称、发车站点序号、到达站点名称、到达站点序号  
969 - String xlbm,zjzx,fczdmc,zdxh,ddzdmc,ddxh;  
970 - // 得到时刻表版本号  
971 - int lineVersion;  
972 - long ttinfoId;  
973 - // 是否输出站点信息  
974 - boolean isLogStation;  
975 - for (int i = 0; i < idArray.length; i++) {  
976 - ttinfoId = Long.valueOf(idArray[i]);  
977 - ttInfo = ttInfoRepository.findOne(ttinfoId);  
978 - if(ttInfo == null)  
979 - continue;  
980 - ttinfoList.add(ttInfo); // 保存时刻表  
981 - // 得到时刻表版本号  
982 - lineVersion = ttInfo.getLineVersion();  
983 - // 查询历史站点路由  
984 - lsStationCode2NameMap = getLsStationCode(ttInfo.getXl().getLineCode(),lineVersion);  
985 - // 查询历史站点路由  
986 - lsStationName2YgcNumber = getLsStationRoute(ttInfo.getXl().getLineCode(),lineVersion);  
987 - zlc = 0.0f;  
988 - yylc = 0.0f;  
989 - // 获得时刻表  
990 - param = new HashMap();  
991 - param.put("ttinfo.id_eq", ttInfo.getId());  
992 - ttInfoDetailIterator = ttInfoDetailRepository.findAll(new CustomerSpecs<TTInfoDetail>(param),  
993 - new Sort(Direction.ASC, "xlDir")).iterator();  
994 - // 获得lineInformation  
995 - param = new HashMap();  
996 - param.put("line.id_eq", ttInfo.getXl().getId());  
997 - lineInformation = lineInformationRepository.findOne(new CustomerSpecs<LineInformation>(param));  
998 - // 初始化  
999 - isLogStation = true;  
1000 - if(ttInfoDetailIterator.hasNext()){  
1001 - // 得到线路信息  
1002 - Line line = lineRepository.findOne(ttInfo.getXl().getId());  
1003 - if(line == null){  
1004 - result += "未找到相应的线路信息,请设置线路信息后再上传";  
1005 - return result;  
1006 - }  
1007 - // 得到上海市线路编码  
1008 - xlbm = line.getShanghaiLinecode();  
1009 - if("".equals(xlbm) || "null".equals(xlbm)){  
1010 - result += "线路编码为空,请设置线路编码后再上传";  
1011 - return result;  
1012 - }  
1013 - // 拿到周几执行  
1014 - zjzx = changeRuleDay(ttInfo.getRule_days());  
1015 - if("".equals(zjzx) || "null".equals(zjzx)){  
1016 - result += "时刻表执行时间为空,请设置执行时间后再上传";  
1017 - return result;  
1018 - }  
1019 - sBuffer.append("<SKB>");  
1020 - sBuffer.append("<XLBM>").append(xlbm).append("</XLBM>");  
1021 - sBufferB = new StringBuffer();  
1022 - sBufferC = new StringBuffer();  
1023 - sBufferB.append("<KSRQ>").append(sdfnyr.format(ttInfo.getQyrq())).append("</KSRQ>");  
1024 - // 结束日期暂时不要,节假日的班次表才需要,如春节的班次表  
1025 - sBufferB.append("<JSRQ>").append("").append("</JSRQ>");  
1026 - sBufferB.append("<ZJZX>").append(zjzx).append("</ZJZX>");  
1027 - sBufferB.append("<TBYY>").append("").append("</TBYY>");  
1028 - sBufferB.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");  
1029 - sBufferB.append("<BCList>");  
1030 - while (ttInfoDetailIterator.hasNext()) {  
1031 - ttInfoDetail = ttInfoDetailIterator.next();  
1032 - bcType = ttInfoDetail.getBcType();  
1033 - sxx = ttInfoDetail.getXlDir();  
1034 - // 进出场班次的里程,加入总里程  
1035 - if(bcType.equals("in") || bcType.equals("out")){  
1036 - // 进出班次的计划里程,算空驶里程  
1037 - emptyLc = ttInfoDetail.getJhlc();  
1038 - // 总里程需要加上空驶里程  
1039 - zlc += emptyLc;  
1040 - continue;  
1041 - }  
1042 - // 不是正常班次,不传到运管处  
1043 - if(!bcType.equals("normal")){  
1044 - continue;  
1045 - }  
1046 - // 如果发车时间格式错误,忽略此条  
1047 - if(changeTimeFormat(ttInfoDetail) == null){  
1048 - continue;  
1049 - }  
1050 - // 发生站点名称  
1051 - fczdmc = lsStationCode2NameMap.get(ttInfoDetail.getXl().getLineCode()+"_"+ttInfoDetail.getXlDir()+"_"+ttInfoDetail.getQdzCode());  
1052 - if("".equals(fczdmc) || "null".equals(fczdmc)){  
1053 - result += "发车站点名称为空,请根据时刻表当前的版本号设置好历史站点路由再上传";  
1054 - return result;  
1055 - }  
1056 - sBufferC.append("<BC>");  
1057 - sBufferC.append("<LPBH>").append(ttInfoDetail.getLp().getLpNo()).append("</LPBH>");  
1058 - sBufferC.append("<SXX>").append(sxx).append("</SXX>");  
1059 - sBufferC.append("<FCZDMC>").append(fczdmc).append("</FCZDMC>");  
1060 - // 起点站的参数  
1061 - otherMap.put("stationMark","B");  
1062 - paramMap = packageYgcStationNumParam(ttInfoDetail,otherMap);  
1063 - if(isLogStation){// 输出起点站信息  
1064 - logger.info("setSKB:"+"起点站信息:"+paramMap);  
1065 - }  
1066 - // 发车站点序号  
1067 - zdxh = String.valueOf(getYgcStationNumByLineCodeAndDirectionAndStationName(paramMap,lsStationName2YgcNumber));  
1068 - if("".equals(zdxh) || "null".equals(zdxh) || "0".equals(zdxh)){  
1069 - result += "发车站点序号为空,请根据时刻表当前的版本号设置好历史站点路由再上传";  
1070 - return result;  
1071 - }  
1072 - // 到达站点名称  
1073 - ddzdmc = lsStationCode2NameMap.get(ttInfoDetail.getXl().getLineCode()+"_"+ttInfoDetail.getXlDir()+"_"+ttInfoDetail.getZdzCode());  
1074 - if("".equals(ddzdmc) || "null".equals(ddzdmc)){  
1075 - result += "到达站点名称为空,请根据时刻表当前的版本号设置好历史站点路由再上传";  
1076 - return result;  
1077 - }  
1078 - sBufferC.append("<ZDXH>").append(zdxh).append("</ZDXH>");  
1079 - sBufferC.append("<JHFCSJ>").append(changeTimeFormat(ttInfoDetail)).append("</JHFCSJ>");  
1080 - sBufferC.append("<DDZDMC>").append(ddzdmc).append("</DDZDMC>");  
1081 - // 终点站的参数  
1082 - otherMap.put("stationMark","E");  
1083 - paramMap = packageYgcStationNumParam(ttInfoDetail,otherMap);  
1084 - if(isLogStation){// 输出终点站信息  
1085 - logger.info("setSKB:"+"终点站信息:"+paramMap);  
1086 - }  
1087 - // 到达站点序号  
1088 - ddxh = String.valueOf(getYgcStationNumByLineCodeAndDirectionAndStationName(paramMap,lsStationName2YgcNumber));  
1089 - if("".equals(ddxh) || "null".equals(ddxh) || "0".equals(ddxh)){  
1090 - result += "到达站点序号为空,请根据时刻表当前的版本号设置好历史站点路由再上传";  
1091 - return result;  
1092 - }  
1093 - isLogStation = false; // 一条线路只输出一次,后面的不输出了  
1094 - sBufferC.append("<DDXH>").append(ddxh).append("</DDXH>");  
1095 - sBufferC.append("<JHDDSJ>").append(calcDdsj(ttInfoDetail.getFcsj(),ttInfoDetail.getBcsj())).append("</JHDDSJ>");  
1096 - sBufferC.append("</BC>");  
1097 - // 0:上行;1:下行  
1098 - if("0".equals(sxx)){  
1099 - singleLc = lineInformation.getUpMileage();  
1100 - }else{  
1101 - singleLc = lineInformation.getDownMileage();  
1102 - }  
1103 - zlc += singleLc ;  
1104 - yylc += singleLc;  
1105 - }  
1106 - sBufferC.append("</BCList>");  
1107 - sBufferC.append("</SKB>");  
1108 - sBufferA = new StringBuffer();  
1109 - sBufferA.append("<JHZLC>").append(df.format(zlc)).append("</JHZLC>");  
1110 - sBufferA.append("<JHYYLC>").append(df.format(yylc)).append("</JHYYLC>");  
1111 - sBuffer.append(sBufferA).append(sBufferB).append(sBufferC);  
1112 - }  
1113 - logger.info("setSKB:"+"ttinfoId:"+ttinfoId+";当前站点版本号:"+lineVersion+";查询历史站点路由:"+lsStationCode2NameMap+";查询历史站点编号:"+lsStationName2YgcNumber);  
1114 - }  
1115 - sBuffer.append("</SKBs>");  
1116 - if(ssop.setSKB(userNameOther, passwordOther, sBuffer.toString()).isSuccess()){  
1117 - result = "上传成功";  
1118 - SKBUploadLogger skbUploadLogger ;  
1119 - SysUser user = SecurityUtils.getCurrentUser();  
1120 - // 保存时刻表上传记录  
1121 - for(TTInfo ttInfo1 : ttinfoList){  
1122 - skbUploadLogger = new SKBUploadLogger();  
1123 - skbUploadLogger.setTtInfo(ttInfo1);  
1124 - skbUploadLogger.setUser(user);  
1125 - skbUploadLoggerRepository.save(skbUploadLogger);  
1126 - }  
1127 - }  
1128 - } catch (Exception e) {  
1129 - logger.error("setSKB:", e);  
1130 - e.printStackTrace();  
1131 - }finally{  
1132 - logger.info("setSKB:"+sBuffer.toString());  
1133 - logger.info("setSKB:"+result);  
1134 - }  
1135 - return result;  
1136 - }  
1137 -  
1138 - /**  
1139 - * 上传线路人员车辆配置信息  
1140 - */  
1141 - @Override  
1142 - public String setXLPC() {  
1143 - String result = "failure";  
1144 - StringBuffer sBuffer =new StringBuffer();  
1145 - try {  
1146 - sBuffer.append("<XLPCs>");  
1147 - // 声明变量  
1148 - Line line = null;  
1149 - Cars cars = null;  
1150 - List<Personnel> personnelList = null;  
1151 - List<Cars> carsList = null;  
1152 - int totalPersonnel,totalCar ;// 人员数量。车辆数量  
1153 - // 查询所有线路  
1154 - Iterator<Line> lineIterator = lineRepository.findAll().iterator();  
1155 - // 循环查找线路下的信息  
1156 - while(lineIterator.hasNext()){  
1157 - line = lineIterator.next();  
1158 - sBuffer.append("<XLPC>");  
1159 - sBuffer.append("<XLBM>").append(BasicData.lineId2ShangHaiCodeMap.get(line.getId())).append("</XLBM>");  
1160 - // 查询驾驶员数量  
1161 - personnelList = personnelRepository.findJsysByLineId(line.getId());  
1162 - totalPersonnel = personnelList != null ? personnelList.size():0;  
1163 - sBuffer.append("<SJRS>").append(totalPersonnel).append("</SJRS>");  
1164 - // 查询售票员人员数量  
1165 - personnelList = personnelRepository.findSpysByLineId(line.getId());  
1166 - totalPersonnel = personnelList != null ? personnelList.size():0;  
1167 - sBuffer.append("<SPYRS>").append(totalPersonnel).append("</SPYRS>");  
1168 - // 查询车辆  
1169 - carsList = carsRepository.findCarsByLineId(line.getId());  
1170 - totalCar = carsList != null ? carsList.size():0;  
1171 - sBuffer.append("<PCSL>").append(totalCar).append("</PCSL>");  
1172 - sBuffer.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");  
1173 - int carsNum = 0;  
1174 - // 取车牌号  
1175 - if(carsList != null){  
1176 - carsNum = carsList.size();  
1177 - sBuffer.append("<CPHList>");  
1178 - for (int i = 0; i < carsNum; i++) {  
1179 - cars = carsList.get(i);  
1180 - sBuffer.append("<CPH>").append("沪").append(cars.getCarCode()).append("</CPH>");  
1181 - }  
1182 - sBuffer.append("</CPHList>");  
1183 - }  
1184 - sBuffer.append("</XLPC>");  
1185 - }  
1186 - sBuffer.append("</XLPCs>");  
1187 - if(ssop.setXLPC(userNameOther, passwordOther, sBuffer.toString()).isSuccess()){  
1188 - result = "success";  
1189 - }  
1190 - } catch (Exception e) {  
1191 - logger.error("setXLPC:",e);  
1192 - e.printStackTrace();  
1193 - }finally{  
1194 - logger.info("setXLPC:"+sBuffer.toString());  
1195 - logger.info("setXLPC:"+result);  
1196 - }  
1197 - return result;  
1198 - }  
1199 -  
1200 -  
1201 - /**  
1202 - * 上传超速数据  
1203 - */  
1204 - @Override  
1205 - public String setCS() {  
1206 - String result = "failure";  
1207 - StringBuffer sBuffer =new StringBuffer();  
1208 - sBuffer.append("<CSs>");  
1209 - String sql = "SELECT * FROM bsth_c_speeding where DATE_FORMAT(create_date,'%Y-%m-%d') = ? order by create_date ";  
1210 - Connection conn = null;  
1211 - PreparedStatement ps = null;  
1212 - ResultSet rs = null;  
1213 - // 取昨天 的日期  
1214 - String yesterday = sdfnyr.format(DateUtils.addDays(new Date(), -1));  
1215 - try {  
1216 - conn = DBUtils_MS.getConnection();  
1217 - ps = conn.prepareStatement(sql);  
1218 - ps.setString(1, yesterday);  
1219 - rs = ps.executeQuery();  
1220 - Float lon, lat;  
1221 - String kssk;  
1222 - String speed;  
1223 - while (rs.next()) {  
1224 - kssk = sdfnyrsfm.format(rs.getLong("TIMESTAMP"));  
1225 - speed = rs.getString("SPEED");  
1226 - // 经纬度  
1227 - lon = rs.getFloat("LON");  
1228 - lat = rs.getFloat("LAT");  
1229 - sBuffer.append("<CS>");  
1230 - sBuffer.append("<RQ>").append(sdfnyr.format(rs.getDate("CREATE_DATE"))).append("</RQ>");  
1231 - sBuffer.append("<XLBM>").append(BasicData.lineCode2ShangHaiCodeMap.get(rs.getString("LINE"))).append("</XLBM>");////////  
1232 - sBuffer.append("<CPH>").append(rs.getString("VEHICLE")).append("</CPH>");  
1233 - sBuffer.append("<KSSK>").append(kssk).append("</KSSK>");  
1234 - sBuffer.append("<KSDDJD>").append(lon).append("</KSDDJD>");  
1235 - sBuffer.append("<KSDDWD>").append(lat).append("</KSDDWD>");  
1236 - sBuffer.append("<KSLD>").append("").append("</KSLD>");//**********************  
1237 - sBuffer.append("<JSSK>").append(kssk).append("</JSSK>");  
1238 - sBuffer.append("<JSDDJD>").append(lon).append("</JSDDJD>");  
1239 - sBuffer.append("<JSDDWD>").append(lat).append("</JSDDWD>");  
1240 - sBuffer.append("<JSLD>").append("").append("</JSLD>");//**********************  
1241 - sBuffer.append("<PJSD>").append(speed).append("</PJSD>");  
1242 - sBuffer.append("<ZGSS>").append(speed).append("</ZGSS>");  
1243 - sBuffer.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");  
1244 - sBuffer.append("</CS>");  
1245 - }  
1246 - sBuffer.append("</CSs>");  
1247 - if(ssop.setCS(userNameOther, passwordOther, sBuffer.toString()).isSuccess()){  
1248 - result = "success";  
1249 - }  
1250 - } catch (Exception e) {  
1251 - logger.error("setCS:",e);  
1252 - e.printStackTrace();  
1253 - } finally {  
1254 - logger.info("setCS:"+sBuffer.toString());  
1255 - logger.info("setCS:"+result);  
1256 - DBUtils_MS.close(rs, ps, conn);  
1257 - }  
1258 - return result;  
1259 - }  
1260 -  
1261 -  
1262 - /**  
1263 - * 下载全量的公交基础数据  
1264 - */  
1265 - public String getDownLoadAllDataFile() {  
1266 - String result = "failure";  
1267 - try {  
1268 - try {  
1269 - if(ygcBasicDataService.download("admin","000000","abc.zip")){  
1270 - result = "success";  
1271 - }  
1272 - } catch (Exception e) {  
1273 - e.printStackTrace();  
1274 - }  
1275 - } catch (Exception e) {  
1276 - e.printStackTrace();  
1277 - }  
1278 -  
1279 - return result;  
1280 - }  
1281 -  
1282 - /**  
1283 - * 下载增量的公交基础数据  
1284 - */  
1285 - public String getDownLoadIncreaseDataFile() {  
1286 - String result = "success";  
1287 - try {  
1288 - //System.out.println(portType.downloadIncreaseDataFile(args0, args1, args2));  
1289 - } catch (Exception e) {  
1290 - e.printStackTrace();  
1291 - }  
1292 -  
1293 - return result;  
1294 - }  
1295 -  
1296 - /**  
1297 - * 指定线路查询方式公交基础数据下载  
1298 - */  
1299 - public String getDownLoadWarrantsBusLineStation() {  
1300 - String result = "success";  
1301 - try {  
1302 -  
1303 - //portType.setXL(userNameXl, passwordXl, sBuffer.toString());  
1304 - } catch (Exception e) {  
1305 - e.printStackTrace();  
1306 - }  
1307 -  
1308 - return result;  
1309 - }  
1310 -  
1311 - /**  
1312 - * 计算结束时间  
1313 - * @param fcsj 发车时间  
1314 - * @param bcsj 班次历时  
1315 - * @return  
1316 - */  
1317 - private String calcDdsj(String fcsj,Integer bcsj){  
1318 - String result = "";  
1319 - if(fcsj.indexOf(":") != -1){  
1320 - if(bcsj == null){  
1321 - return fcsj;  
1322 - }  
1323 - // 时和分隔开  
1324 - String[] fcsjArray = fcsj.split(":");  
1325 - // 分和历时时间相加  
1326 - Integer fullTime = Integer.valueOf(fcsjArray[1])+ bcsj;  
1327 - int hour,min,sumHour;  
1328 - hour = fullTime / 60;  
1329 - min = fullTime % 60;  
1330 - sumHour = Integer.valueOf(fcsjArray[0])+hour;  
1331 - if(sumHour >= 24){  
1332 - result = String.format("%02d",sumHour - 24);  
1333 - }else{  
1334 - result = String.format("%02d",sumHour);;  
1335 - }  
1336 - result +=":"+String.format("%02d", min);  
1337 - }else{  
1338 - result = fcsj;  
1339 - }  
1340 - return result;  
1341 - }  
1342 -  
1343 - /**  
1344 - * 改变时间格式  
1345 - * @param ttInfoDetail 时刻表详细  
1346 - * @return xx:yy  
1347 - */  
1348 - private String changeTimeFormat(TTInfoDetail ttInfoDetail){  
1349 - String result = "00:00";  
1350 - String fcsj = ttInfoDetail.getFcsj();  
1351 - if(fcsj.indexOf(":") != -1){  
1352 - // 时和分隔开  
1353 - String[] fcsjArray = fcsj.split(":");  
1354 - result = String.format("%02d", Integer.valueOf(fcsjArray[0]))+":";  
1355 - result +=String.format("%02d", Integer.valueOf(fcsjArray[1]));  
1356 - }else{  
1357 - result = null;  
1358 - logger.info("setSKB:发车时间错误:ttInfoDetail.id="+ttInfoDetail.getId());  
1359 - }  
1360 - return result;  
1361 - }  
1362 -  
1363 - /**  
1364 - * 拼装线路计划班次表的XML  
1365 - * @param sBuffer  
1366 - * @param schedulePlanInfo  
1367 - * @param xlbm  
1368 - * @param zbh  
1369 - * @param lp  
1370 - */  
1371 - private void assembleJHBC(StringBuffer sBuffer,SchedulePlanInfo schedulePlanInfo,String xlbm,String zbh,Long lp){  
1372 - sBuffer.append("<JHBC>");  
1373 - sBuffer.append("<RQ>").append(sdfnyr.format(schedulePlanInfo.getScheduleDate())).append("</RQ>");  
1374 - sBuffer.append("<XLBM>").append(BasicData.lineCode2ShangHaiCodeMap.get(xlbm)).append("</XLBM>");  
1375 - sBuffer.append("<CPH>").append("沪"+zbh).append("</CPH>");  
1376 - sBuffer.append("<LPBH>").append(lp).append("</LPBH>");  
1377 - sBuffer.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");  
1378 - sBuffer.append("<BCList>");  
1379 - }  
1380 - /**  
1381 - * 转换排班规则  
1382 - * @param ruleDay  
1383 - * @return  
1384 - */  
1385 - private String changeRuleDay(String ruleDay){  
1386 - String result = "";  
1387 - int flag ;  
1388 - String[] ruleDayArray = ruleDay.split(",");  
1389 - for (int i = 0; i < ruleDayArray.length; i++) {  
1390 - if(ruleDayArray[i].equals("1")){  
1391 - flag = i+1;  
1392 - }else{  
1393 - flag = 0;  
1394 - }  
1395 - if(flag > 0){  
1396 - result += flag + ",";  
1397 - }  
1398 - }  
1399 - // 去掉最后一个字符  
1400 - if(StringUtils.endsWith(result,",")){  
1401 - result = StringUtils.removeEnd(result,",");  
1402 - }  
1403 - return result;  
1404 - }  
1405 - /**  
1406 - * 设置统一的公司名称  
1407 - * @param company  
1408 - */  
1409 - private void setCompanyName(String company){  
1410 - if(company.equals("闵行公司")){  
1411 - company = "浦东闵行公交公司";  
1412 - }else if(company.equals("杨高公司")){  
1413 - company = "浦东杨高公交公司";  
1414 - }else if(company.equals("上南公司")){  
1415 - company = "浦东上南公交公司";  
1416 - }else if(company.equals("金高公司")){  
1417 - company = "浦东金高公交公司";  
1418 - }else if(company.equals("南汇公司")){  
1419 - company = "浦东南汇公交公司";  
1420 - }else if(company.equals("青浦公交")){  
1421 - company = "浦东青浦公交公司";  
1422 - }  
1423 - }  
1424 - /**  
1425 - * @param stationsList 站点路由集  
1426 - * @param sBuffer sBuffer  
1427 - * @param startId 站点序号起始ID  
1428 - *  
1429 - * @return 站点序号累加后的ID  
1430 - */  
1431 - private int packagStationXml(List<StationRoute> stationsList,StringBuffer sBuffer,int startId,Map<String, Integer> stationNumMap){  
1432 - int size = stationsList.size();  
1433 - StationRoute srRoute;  
1434 - HashMap<String,String> paraMap;  
1435 - String zdlx ;// 站点类型:0:起点站、1:终点站、2:中途站  
1436 - for (int i = 0; i < size; i++) {  
1437 - srRoute = stationsList.get(i);  
1438 - zdlx = srRoute.getStationMark();  
1439 - if(zdlx.equals("B")){  
1440 - zdlx = "0";  
1441 - }else if(zdlx.equals("E")){  
1442 - zdlx = "1";  
1443 - }else{  
1444 - zdlx = "2";  
1445 - }  
1446 - paraMap = packageYgcStationNumParam(srRoute,null);  
1447 - sBuffer.append("<Station>");  
1448 - sBuffer.append("<ZDXH>").append(getYgcStationNumByLineCodeAndDirectionAndStationName(paraMap,stationNumMap)).append("</ZDXH>");  
1449 - sBuffer.append("<SXX>").append(srRoute.getDirections()).append("</SXX>");  
1450 - sBuffer.append("<ZDMC>").append(srRoute.getStationName()).append("</ZDMC>");  
1451 - sBuffer.append("<ZDBM>").append(srRoute.getStationCode()).append("</ZDBM>");  
1452 - sBuffer.append("<ZDJD>").append(srRoute.getStation().getgLonx()).append("</ZDJD>");  
1453 - sBuffer.append("<ZDWD>").append(srRoute.getStation().getgLaty()).append("</ZDWD>");  
1454 - sBuffer.append("<ZZ>").append(srRoute.getStation().getAddr() == null ? "" : srRoute.getStation().getAddr()).append("</ZZ>");  
1455 - sBuffer.append("<ZDLX>").append(zdlx).append("</ZDLX>");  
1456 - sBuffer.append("<ZJLC>").append(srRoute.getDistances()).append("</ZJLC>");  
1457 - sBuffer.append("</Station>");  
1458 - startId++;  
1459 - }  
1460 - return startId;  
1461 - }  
1462 -  
1463 - /**  
1464 - * @param pointList 站点点位集  
1465 - * @param sBuffer sBuffer  
1466 - * @param startId 站点序号起始ID  
1467 - *  
1468 - * @return 站点序号累加后的ID  
1469 - */  
1470 - private int packagStationPointXml(List<Object[]> pointList,StringBuffer sBuffer,int startId){  
1471 - int size = pointList.size();  
1472 - Object[] objs;  
1473 - String bsection,dir,section;  
1474 - String[] sections ;  
1475 - for (int i = 0; i < size; i++) {  
1476 - objs = pointList.get(i);  
1477 - bsection = objs[0]+"";  
1478 - dir = objs[1]+"";  
1479 - // 取括号内的内容  
1480 - Pattern pattern = Pattern.compile("(?<=\\()(.+?)(?=\\))");  
1481 - Matcher matcher = pattern.matcher(bsection);  
1482 - if(matcher.find()){  
1483 - sections = matcher.group().split(",");  
1484 - for (int j = 0 ; j < sections.length ; j ++){  
1485 - section = sections[j];  
1486 - sBuffer.append("<LinePoint>");  
1487 - sBuffer.append("<ZDXH>").append(startId).append("</ZDXH>");  
1488 - sBuffer.append("<SXX>").append(dir).append("</SXX>");  
1489 - sBuffer.append("<ZDJD>").append(section.split(" ")[0]).append("</ZDJD>");  
1490 - sBuffer.append("<ZDWD>").append(section.split(" ")[1]).append("</ZDWD>");  
1491 - sBuffer.append("</LinePoint>");  
1492 - startId++;  
1493 - }  
1494 - }  
1495 - }  
1496 - return startId;  
1497 - }  
1498 -  
1499 - /**  
1500 - * 获取运管处站点序号  
1501 - * @param map  
1502 - * @return 运管处站点序号  
1503 - */  
1504 - private Integer getYgcStationNumByLineCodeAndDirectionAndStationName(HashMap<String,String> map,Map<String, Integer> stationNumMap){  
1505 - // 线路编码  
1506 - String lineCode = map.get("lineCode");  
1507 - // 线路走向 0:上行 1:下行  
1508 - String direction = map.get("direction");  
1509 - // 站点编码  
1510 - String stationCode = map.get("stationCode");  
1511 - // 站点类型:B:起点站 Z:中途站 E:终点站 T:停车场  
1512 - String stationMark = map.get("stationMark");  
1513 - String[] marks = null;  
1514 - // 起点站,先从起点找,找不到再从中途站找,最后从终点找  
1515 - if(stationMark.equals("B")){  
1516 - marks= new String[]{"B","Z","E"};  
1517 - }else if(stationMark.equals("E")){// 终点站相反  
1518 - marks= new String[]{"E","Z","B"};  
1519 - }else if(stationMark.equals("Z")){  
1520 - marks= new String[]{"Z"};  
1521 - }  
1522 - // 默认从缓存BasicData.stationName2YgcNumber  
1523 - Map<String, Integer> tempMap = BasicData.stationName2YgcNumber;  
1524 - // 如果传入的stationNumMap不为空,则不是缓存取,而从stationNumMap取  
1525 - if(stationNumMap != null){  
1526 - tempMap = stationNumMap;  
1527 - }  
1528 - Integer number = null;  
1529 - for (int i = 0 ;i < marks.length ; i ++){  
1530 - number = tempMap.get(lineCode+"_"+direction+"_"+stationCode+"_"+marks[i]);  
1531 - if(number != null){  
1532 - break;  
1533 - }  
1534 - }  
1535 - return number == null ? 0 : number;  
1536 - }  
1537 -  
1538 - /**  
1539 - * 封装查询站序条件  
1540 - * @param obj  
1541 - * @return  
1542 - */  
1543 - private HashMap packageYgcStationNumParam(Object obj,HashMap<String,String> otherParam){  
1544 - HashMap<String,String> map = new HashMap<String,String>();  
1545 - String lineCode = "",direction = "",stationCode = "",stationMark = "";  
1546 - // 站点路由  
1547 - if(obj instanceof StationRoute){  
1548 - StationRoute sr = (StationRoute)obj;  
1549 - lineCode = sr.getLineCode();  
1550 - direction = String.valueOf(sr.getDirections());  
1551 - stationCode = sr.getStationCode();  
1552 - stationMark = sr.getStationMark();  
1553 - }else if(obj instanceof ScheduleRealInfo){ //实际排班计划明细。  
1554 - ScheduleRealInfo sri = (ScheduleRealInfo)obj;  
1555 - lineCode = sri.getXlBm();  
1556 - direction = sri.getXlDir();  
1557 - if(otherParam != null && otherParam.get("stationMark") != null){  
1558 - stationMark = otherParam.get("stationMark");  
1559 - if(stationMark.equals("B")){ // 起点站  
1560 - stationCode = sri.getQdzCode();  
1561 - }else if(stationMark.equals("E")){ // 终点站  
1562 - stationCode = sri.getZdzCode();  
1563 - }  
1564 - }  
1565 - }else if(obj instanceof SchedulePlanInfo){ //排班计划明细  
1566 - SchedulePlanInfo spi = (SchedulePlanInfo)obj;  
1567 - lineCode = spi.getXlBm();  
1568 - direction = spi.getXlDir();  
1569 - if(otherParam != null && otherParam.get("stationMark") != null){  
1570 - stationMark = otherParam.get("stationMark");  
1571 - if(stationMark.equals("B")){ // 起点站  
1572 - stationCode = spi.getQdzCode();  
1573 - }else if(stationMark.equals("E")){ // 终点站  
1574 - stationCode = spi.getZdzCode();  
1575 - }  
1576 - }  
1577 - }else if(obj instanceof TTInfoDetail){ //时刻表明细  
1578 - TTInfoDetail ttid = (TTInfoDetail)obj;  
1579 - lineCode = ttid.getXl().getLineCode();  
1580 - direction = ttid.getXlDir();  
1581 - if(otherParam != null && otherParam.get("stationMark") != null){  
1582 - stationMark = otherParam.get("stationMark");  
1583 - if(stationMark.equals("B")){ // 起点站  
1584 - stationCode = ttid.getQdzCode();  
1585 - }else if(stationMark.equals("E")){ // 终点站  
1586 - stationCode = ttid.getZdzCode();  
1587 - }  
1588 - }  
1589 - }  
1590 - map.put("lineCode",lineCode);// 站点编码  
1591 - map.put("direction",direction); // 上下行  
1592 - map.put("stationCode",stationCode); // 站点编号  
1593 - map.put("stationMark",stationMark); // 站点类型  
1594 - return map;  
1595 - }  
1596 -  
1597 - /**  
1598 - * 取得历史站点编码和站点名称的对应关系  
1599 - * @return  
1600 - */  
1601 - private Map<String, String> getLsStationCode(String lineCode,int lineVersion){  
1602 - Map<String,Object> map = new HashMap<>();  
1603 - map.put("lineCode_eq", lineCode);  
1604 - map.put("versions_eq",lineVersion);  
1605 - LsStationRoute lsroute;  
1606 - Iterator<LsStationRoute> iterator = lsStationRouteRepository.findAll(new CustomerSpecs<LsStationRoute>(map)).iterator();  
1607 - Map<String, String> stationCode2Name = new HashMap<>();  
1608 - while (iterator.hasNext()) {  
1609 - lsroute = iterator.next();  
1610 - stationCode2Name.put(lsroute.getLineCode() + "_" + lsroute.getDirections() + "_" + lsroute.getStationCode(), lsroute.getStationName());  
1611 - }  
1612 - return stationCode2Name;  
1613 - }  
1614 -  
1615 - private Map<String, Integer> getLsStationRoute(String xlbm,int lineVersion){  
1616 - Map<String, Integer> tempStationName2YgcNumber = new HashMap<String, Integer>();  
1617 - /**  
1618 - * 加载运管处的站点及序号  
1619 - * 上行从1开始,下行顺序续编  
1620 - */  
1621 - List<Map<String, String>> ygcLines = lsStationRouteRepository.findLineWithLineCode4Ygc(xlbm,lineVersion);  
1622 - if(ygcLines != null && ygcLines.size() > 0){  
1623 - int size = ygcLines.size();  
1624 - Map<String, String> tempMap ;  
1625 - int num = 1;  
1626 - String key;  
1627 - String lineCode = "";  
1628 - for (int i = 0; i < size; i ++){  
1629 - tempMap = ygcLines.get(i);  
1630 - if(lineCode.equals("")){  
1631 - lineCode = tempMap.get("lineCode");  
1632 - }else if(!lineCode.equals(tempMap.get("lineCode"))){  
1633 - num = 1;  
1634 - lineCode = tempMap.get("lineCode");  
1635 - }  
1636 - key = tempMap.get("lineCode") + "_"+String.valueOf(tempMap.get("directions"))  
1637 - + "_"+tempMap.get("stationCode")+ "_"+tempMap.get("stationMark");  
1638 - tempStationName2YgcNumber.put(key,num++);  
1639 - }  
1640 - }  
1641 - return tempStationName2YgcNumber;  
1642 - }  
1643 -} 1 +package com.bsth.service.impl;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +import com.bsth.email.SendEmailController;
  5 +import com.bsth.email.entity.EmailBean;
  6 +import com.bsth.entity.*;
  7 +import com.bsth.entity.realcontrol.ChildTaskPlan;
  8 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  9 +import com.bsth.entity.schedule.SchedulePlanInfo;
  10 +import com.bsth.entity.schedule.TTInfo;
  11 +import com.bsth.entity.schedule.TTInfoDetail;
  12 +import com.bsth.entity.search.CustomerSpecs;
  13 +import com.bsth.entity.sys.SysUser;
  14 +import com.bsth.entity.traffic.SKBUploadLogger;
  15 +import com.bsth.repository.*;
  16 +import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
  17 +import com.bsth.repository.schedule.*;
  18 +import com.bsth.repository.traffic.SKBUploadLoggerRepository;
  19 +import com.bsth.security.util.SecurityUtils;
  20 +import com.bsth.service.TrafficManageService;
  21 +import com.bsth.service.traffic.YgcBasicDataService;
  22 +import com.bsth.util.IpUtils;
  23 +import com.bsth.util.TimeUtils;
  24 +import com.bsth.util.db.DBUtils_MS;
  25 +import com.bsth.webService.trafficManage.org.tempuri.Results;
  26 +import com.bsth.webService.trafficManage.org.tempuri.WebServiceLocator;
  27 +import com.bsth.webService.trafficManage.org.tempuri.WebServiceSoap;
  28 +import org.apache.commons.lang.StringEscapeUtils;
  29 +import org.apache.commons.lang.StringUtils;
  30 +import org.apache.commons.lang.time.DateUtils;
  31 +import org.joda.time.DateTime;
  32 +import org.slf4j.Logger;
  33 +import org.slf4j.LoggerFactory;
  34 +import org.springframework.beans.factory.annotation.Autowired;
  35 +import org.springframework.data.domain.Sort;
  36 +import org.springframework.data.domain.Sort.Direction;
  37 +import org.springframework.stereotype.Service;
  38 +
  39 +import java.io.*;
  40 +import java.net.InetAddress;
  41 +import java.sql.Connection;
  42 +import java.sql.PreparedStatement;
  43 +import java.sql.ResultSet;
  44 +import java.text.DecimalFormat;
  45 +import java.text.SimpleDateFormat;
  46 +import java.util.*;
  47 +import java.util.regex.Matcher;
  48 +import java.util.regex.Pattern;
  49 +
  50 +/**
  51 + *
  52 + * @ClassName: TrafficManageServiceImpl(运管处接口service业务层实现类)
  53 + *
  54 + * @Extends : BaseService
  55 + *
  56 + * @Description: TODO(运管处接口service业务层)
  57 + *
  58 + * @Author bsth@zq
  59 + *
  60 + * @Date 2016年10月28日 上午9:21:17
  61 + *
  62 + * @Version 公交调度系统BS版 0.1
  63 + *
  64 + */
  65 +
  66 +@Service
  67 +public class TrafficManageServiceImpl implements TrafficManageService{
  68 +
  69 + Logger logger = LoggerFactory.getLogger(this.getClass());
  70 +
  71 + // 线路repository
  72 + @Autowired
  73 + private LineRepository lineRepository;
  74 +
  75 + @Autowired
  76 + private LineInformationRepository lineInformationRepository;
  77 +
  78 + // 站点路由repository
  79 + @Autowired
  80 + private StationRouteRepository stationRouteRepository;
  81 +
  82 + // 历史站点路由repository
  83 + @Autowired
  84 + private LsStationRouteRepository lsStationRouteRepository;
  85 +
  86 + @Autowired
  87 + private SectionRepository sectionRepository;
  88 +
  89 + // 车辆repository
  90 + @Autowired
  91 + private CarsRepository carsRepository;
  92 +
  93 + // 人员repository
  94 + @Autowired
  95 + private PersonnelRepository personnelRepository;
  96 +
  97 + // 时刻模板repository
  98 + @Autowired
  99 + private TTInfoRepository ttInfoRepository;
  100 +
  101 + // 时刻模板明细repository
  102 + @Autowired
  103 + private TTInfoDetailRepository ttInfoDetailRepository;
  104 +
  105 + // 排班计划明细repository
  106 + @Autowired
  107 + private SchedulePlanInfoRepository schedulePlanInfoRepository;
  108 +
  109 + // 实际排班计划明细repository
  110 + @Autowired
  111 + private ScheduleRealInfoRepository scheduleRealInfoRepository;
  112 +
  113 + // 时刻表上传记录repository
  114 + @Autowired
  115 + private SKBUploadLoggerRepository skbUploadLoggerRepository;
  116 +
  117 + // 线路站点repository
  118 + @Autowired
  119 + private YgcBasicDataService ygcBasicDataService;
  120 +
  121 + // 发送邮件
  122 + @Autowired
  123 + private SendEmailController sendEmailController;
  124 +
  125 + /**
  126 + * 线路版本repository
  127 + */
  128 + @Autowired
  129 + private LineVersionsRepository lineVersionsRepository;
  130 +
  131 + // 运管处上传接口
  132 + private com.bsth.webService.trafficManage.up.org.tempuri.WebServiceSoap webServiceSoapUp;
  133 + private WebServiceSoap ssop ;
  134 + {
  135 + try {
  136 + ssop = new WebServiceLocator().getWebServiceSoap();
  137 + } catch (Exception e) {
  138 + e.printStackTrace();
  139 + }
  140 + }
  141 + // 格式化 年月日时分秒 nyrsfm是年月日时分秒的拼音首字母
  142 + private SimpleDateFormat sdfnyrsfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  143 +
  144 + // 格式化 年月日
  145 + private SimpleDateFormat sdfnyr = new SimpleDateFormat("yyyy-MM-dd");
  146 +
  147 + // 数字格式化
  148 + DecimalFormat format = new DecimalFormat("0.00");
  149 +
  150 + // 用户名
  151 + private final String userNameOther = "user";
  152 + // 密码
  153 + private final String passwordOther = "user";
  154 +
  155 + // 用户名
  156 + private final String userNameUp = "user";
  157 + // 密码
  158 + private final String passwordUp = "user";
  159 + // 接收邮件人
  160 + private final String emailSendToAddress = "175912183@qq.com";
  161 + // 记录路单上线的成功、失败线路数
  162 + private Integer countSuccess,countFailure;
  163 +
  164 + private synchronized com.bsth.webService.trafficManage.up.org.tempuri.WebServiceSoap getWebServiceSoapUp(){
  165 + try {
  166 + if(webServiceSoapUp == null){
  167 + webServiceSoapUp = new com.bsth.webService.trafficManage.up.org.tempuri.WebServiceLocator().getWebServiceSoap();
  168 + }
  169 + }catch (Exception e){
  170 + e.printStackTrace();
  171 + }finally {
  172 + return webServiceSoapUp;
  173 + }
  174 + }
  175 + /**
  176 + * 上传线路信息
  177 + */
  178 + @Override
  179 + public String setXL(String ids) {
  180 + String result = "failure";
  181 + StringBuffer sBuffer = new StringBuffer();
  182 + String[] idArray = ids.split(",");
  183 + try {
  184 + for (String id : idArray) {
  185 + if(id == null || id.trim().equals("")){
  186 + continue;
  187 + }
  188 + Map<String,Object> map = new HashMap<>();
  189 + map.put("lineCode_eq", id);
  190 + Line line ;
  191 + LineInformation lineInformation;
  192 + line = lineRepository.findOne(new CustomerSpecs<Line>(map));
  193 + if(line == null){
  194 + continue;
  195 + }
  196 + List<StationRoute> upStationsList ;// 上行站点路由集
  197 + List<StationRoute> downStationsList;// 下行站点路由集
  198 + List<Object[]> downPointList;// 下行站点集
  199 + List<Object[]> upPointList;// 上行站点集
  200 + sBuffer.append("<XLs>");
  201 + sBuffer.append("<XL>");
  202 + if(BasicData.lineId2ShangHaiCodeMap.get(line.getId()) == null){
  203 + return result;
  204 + }
  205 + map = new HashMap<>();
  206 + map.put("line.id_eq",line.getId());
  207 + lineInformation = lineInformationRepository.findOne(new CustomerSpecs<LineInformation>(map));
  208 + if(lineInformation == null){
  209 + continue;
  210 + }
  211 + sBuffer.append("<XLBM>").append(BasicData.lineId2ShangHaiCodeMap.get(line.getId())).append("</XLBM>");
  212 + sBuffer.append("<XLMC>").append(line.getName()).append("</XLMC>");
  213 + sBuffer.append("<QDZ>").append(line.getStartStationName()).append("</QDZ>");
  214 + sBuffer.append("<ZDZ>").append(line.getEndStationName()).append("</ZDZ>");
  215 + sBuffer.append("<QZLC>").append(lineInformation.getUpMileage()).append("</QZLC>");
  216 + sBuffer.append("<ZQLC>").append(lineInformation.getDownMileage()).append("</ZQLC>");
  217 + sBuffer.append("<XLGH>").append(line.getLinePlayType()).append("</XLGH>");
  218 + sBuffer.append("<UPDATE_DATE>").append(sdfnyr.format(new Date())).append("</UPDATE_DATE>");
  219 +
  220 + // 循环添加站点信息
  221 + sBuffer.append("<StationList>");
  222 +
  223 + // 先查上行
  224 + upStationsList = stationRouteRepository.findByLine(line.getLineCode(), 0);
  225 + Map<String, Integer> stationNumMap = getStationName2YgcNumberMap(line.getLineCode());
  226 + int startId = 1;
  227 + startId = packagStationXml(upStationsList, sBuffer, startId,stationNumMap);
  228 + // 环线不查下行
  229 + if(line.getLinePlayType() != 1){
  230 + // 再查下行
  231 + downStationsList = stationRouteRepository.findByLine(line.getLineCode(), 1);
  232 + packagStationXml(downStationsList, sBuffer, startId,stationNumMap);
  233 + }
  234 + sBuffer.append("</StationList>");
  235 +
  236 + // 循环添加站点点位信息
  237 + sBuffer.append("<LinePointList>");
  238 + upPointList = sectionRepository.getSectionDirByLineId(line.getId(),0);
  239 + startId = 1;
  240 + startId = packagStationPointXml(upPointList, sBuffer, startId);
  241 + // 环线不查下行
  242 + if(line.getLinePlayType() != 1){
  243 + downPointList = sectionRepository.getSectionDirByLineId(line.getId(),1);
  244 + packagStationPointXml(downPointList, sBuffer, startId);
  245 + }
  246 + sBuffer.append("</LinePointList>");
  247 + sBuffer.append("</XL>");
  248 + sBuffer.append("</XLs>");
  249 + // 临时添加,后面删除
  250 + if(sBuffer.indexOf("<ZDXH>0</ZDXH>") != -1){
  251 + return "0";
  252 + }
  253 + // 调用上传方法
  254 + if(getWebServiceSoapUp().setXL(userNameUp,passwordUp,sBuffer.toString()).isSuccess()){
  255 + result = "success";
  256 + }else{
  257 + result = "failure";
  258 + }
  259 + logger.info("setXL:"+sBuffer.toString());
  260 + logger.info("setXL:"+result);
  261 + }
  262 + } catch (Exception e) {
  263 + logger.error("setXL:",e);
  264 + e.printStackTrace();
  265 + }
  266 + return result;
  267 + }
  268 +
  269 + /**
  270 + * 加载运管处的站点及序号
  271 + * 上行从1开始,下行顺序续编
  272 + */
  273 + private Map<String, Integer> getStationName2YgcNumberMap (String lineCode){
  274 + Map<String, Integer> resultMap = new HashMap<>();
  275 + List<Map<String, String>> ygcLines = stationRouteRepository.findLineWithYgcByLine(lineCode);
  276 + if(ygcLines != null && ygcLines.size() > 0){
  277 + int size = ygcLines.size();
  278 + Map<String, String> tempMap ;
  279 + int num = 1;
  280 + String key;
  281 + for (int i = 0; i < size; i ++){
  282 + tempMap = ygcLines.get(i);
  283 + key = tempMap.get("lineCode") + "_"+String.valueOf(tempMap.get("directions"))
  284 + + "_"+tempMap.get("stationCode")+ "_"+tempMap.get("stationMark");
  285 + resultMap.put(key,num++);
  286 + }
  287 + }
  288 + return resultMap;
  289 + }
  290 +
  291 + /**
  292 + * 上传线路信息(按in_use上传)
  293 + */
  294 + @Override
  295 + public String setXLByInUse(String inUse) {
  296 + StringBuffer result = new StringBuffer();
  297 + try {
  298 + Map<String,Object> map = new HashMap<>();
  299 + if(inUse != null && inUse.equals("1")){
  300 + map.put("inUse_eq", inUse);
  301 + }
  302 + List<Line> lines ;
  303 + Line line;
  304 + lines = lineRepository.findAll(new CustomerSpecs<Line>(map));
  305 + if(lines != null && lines.size() > 0){
  306 + for(int i = 0 ; i < lines.size() ; i ++){
  307 + line = lines.get(i);
  308 + if(line != null && line.getId() != null){
  309 + result.append(line.getLineCode()).append(":").append(setXL(line.getLineCode())).append(";");
  310 + }
  311 + }
  312 + }
  313 + } catch (Exception e) {
  314 + result.append("failure");
  315 + logger.error("setXLByInUse:",e);
  316 + e.printStackTrace();
  317 + }
  318 + return result.toString();
  319 + }
  320 +
  321 + /**
  322 + * 上传车辆信息
  323 + */
  324 + @Override
  325 + public String setCL() {
  326 + String result = "failure";
  327 + StringBuffer sBuffer =new StringBuffer();
  328 + try {
  329 + sBuffer.append("<CLs>");
  330 + Cars cars = null;
  331 + String company;
  332 + Iterator<Cars> carsIterator = carsRepository.findAll().iterator();
  333 + while(carsIterator.hasNext()){
  334 + cars = carsIterator.next();
  335 + sBuffer.append("<CL>");
  336 + company = cars.getCompany();
  337 + setCompanyName(company);// 统一公司名称
  338 + sBuffer.append("<GSJC>").append(company).append("</GSJC>");
  339 + sBuffer.append("<NBH>").append(cars.getInsideCode()).append("</NBH>");
  340 + sBuffer.append("<CPH>").append(cars.getCarPlate()).append("</CPH>");
  341 + sBuffer.append("<YYZBH>").append(cars.getServiceNo()).append("</YYZBH>");
  342 + sBuffer.append("<CZCPH>").append(cars.getCarPlate()).append("</CZCPH>");//******这个数据没有***********
  343 + sBuffer.append("<CZZDBH>").append(cars.getEquipmentCode()).append("</CZZDBH>");
  344 + sBuffer.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");
  345 + sBuffer.append("</CL>");
  346 + }
  347 + sBuffer.append("</CLs>");
  348 + if(ssop.setCL(userNameOther, passwordOther, sBuffer.toString()).isSuccess()){
  349 + result = "success";
  350 + }
  351 + } catch (Exception e) {
  352 + logger.error("setCL:",e);
  353 + e.printStackTrace();
  354 + }finally{
  355 + logger.info("setCL:"+sBuffer.toString());
  356 + logger.info("setCL:"+result);
  357 + }
  358 + return result;
  359 + }
  360 +
  361 + /**
  362 + * 上传司机信息
  363 + */
  364 + @Override
  365 + public String setSJ() {
  366 + String result = "failure";
  367 + StringBuffer sBuffer =new StringBuffer();
  368 + try {
  369 + sBuffer.append("<SJs>");
  370 + Personnel personnel = null;
  371 + String company;
  372 + Iterator<Personnel> personIterator = personnelRepository.findAll().iterator();
  373 + while(personIterator.hasNext()){
  374 + personnel = personIterator.next();
  375 + sBuffer.append("<SJ>");
  376 + company = personnel.getCompany();
  377 + setCompanyName(company);// 统一公司名称
  378 + sBuffer.append("<GSJC>").append(company).append("</GSJC>");
  379 + sBuffer.append("<SJGH>").append(personnel.getJobCode()).append("</SJGH>");
  380 + sBuffer.append("<CYZGZH>").append(personnel.getPapersCode()).append("</CYZGZH>");//***********
  381 + sBuffer.append("<XM>").append(personnel.getPersonnelName()).append("</XM>");
  382 + sBuffer.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");
  383 + sBuffer.append("</SJ>");
  384 + }
  385 + sBuffer.append("</SJs>");
  386 + if(ssop.setSJ(userNameOther, passwordOther, sBuffer.toString()).isSuccess()){
  387 + result = "success";
  388 + };
  389 + } catch (Exception e) {
  390 + logger.error("setSJ:",e);
  391 + e.printStackTrace();
  392 + }finally{
  393 + logger.info("setSJ:"+sBuffer.toString());
  394 + logger.info("setSJ:"+result);
  395 + }
  396 + return result;
  397 + }
  398 +
  399 + /**
  400 + * 上传路单 指定日期 yyyy-MM-dd
  401 + * @param theDate
  402 + * @return
  403 + */
  404 + public String setLD(String theDate){
  405 + return uploadLD(theDate);
  406 + }
  407 +
  408 + /**
  409 + * 上传路单 上传前一天的路单
  410 + * @return
  411 + */
  412 + public String setLD(){
  413 + return uploadLD(null);
  414 + }
  415 +
  416 + /**
  417 + * 上传路单
  418 + * @return 上传成功标识
  419 + */
  420 + private String uploadLD(String theDate){
  421 + // 取昨天 的日期
  422 + String date = theDate == null ?sdfnyr.format(DateUtils.addDays(new Date(), -1)) : theDate;
  423 + StringBuffer sf = new StringBuffer();
  424 + Results results = null;
  425 + String str = "", xlbm = null, oldXlbm = null;
  426 + List<Map<String,Object>> listGroup = null;
  427 + int scount = 0, ccount = 0;
  428 + long start = System.currentTimeMillis();
  429 + try {
  430 + // 计数器
  431 + int counter = 0;
  432 + // 每几条线路上传一次路单
  433 + int per = 10;
  434 + List<ScheduleRealInfo> list = scheduleRealInfoRepository.setLD(date);
  435 + listGroup = scheduleRealInfoRepository.setLDGroup(date);
  436 + Map<String,Object> map = new HashMap();
  437 + HashMap<String,String> paramMap;
  438 + HashMap<String,String> otherMap = new HashMap();
  439 +
  440 + // 车辆内部编码和车牌做映射
  441 + Map<String, String> inside2plate = new HashMap<>();
  442 + Iterable<Cars> cars = carsRepository.findAll();
  443 + for (Cars car : cars) {
  444 + inside2plate.put(car.getInsideCode(), car.getCarPlate());
  445 + }
  446 +
  447 + // 线路编码和线路信息映射
  448 + Map<String, Line> code2line = new HashMap<>();
  449 + Iterable<Line> lines = lineRepository.findAll();
  450 + for (Line line : lines) {
  451 + code2line.put(line.getLineCode(), line);
  452 + }
  453 +
  454 + // 线路编码和线路版本映射(电子路单日期)
  455 + Map<String, Integer> code2version = new HashMap<>();
  456 + Iterable<LineVersions> versions = lineVersionsRepository.findLineVersionsByDate((int)(DateTime.parse(date).getMillis() / 1000));
  457 + for (LineVersions version : versions) {
  458 + code2version.put(version.getLineCode(), version.getVersions());
  459 + }
  460 +
  461 + Map<String, Integer> stationNumMap = null;
  462 + for(Map<String,Object> schRealInfo:listGroup){
  463 + if(schRealInfo != null){
  464 + // 获取线路是否使用标识,如果未使用,则不查该线路数据
  465 + String lineCode = schRealInfo.get("xlBm")+"";
  466 + Line line = code2line.get(lineCode);
  467 + if(line == null || line.getInUse() == null || line.getInUse() == 0){
  468 + ccount++;
  469 + continue;
  470 + }
  471 + if(counter % per == 0){
  472 + sf = new StringBuffer();
  473 + sf.append("<DLDS>");
  474 + }
  475 + counter ++;
  476 + xlbm = BasicData.lineCode2ShangHaiCodeMap.get(lineCode);
  477 + if (!xlbm.equals(oldXlbm)) {
  478 + oldXlbm = xlbm;
  479 + Integer ver = code2version.get(lineCode);
  480 + if (ver != null) {
  481 + stationNumMap = getLsStationRoute(lineCode, ver);
  482 + }
  483 + }
  484 +
  485 + sf.append("<DLD>");
  486 + sf.append("<RQ>").append(date).append("</RQ>");
  487 + sf.append("<XLBM>").append(xlbm).append("</XLBM>");
  488 + sf.append("<LPBH>").append(schRealInfo.get("lpName")).append("</LPBH>");
  489 + sf.append("<CPH>").append(inside2plate.get(schRealInfo.get("clZbh"))).append("</CPH>");
  490 + sf.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");
  491 + sf.append("<LDList>");
  492 + for(ScheduleRealInfo scheduleRealInfo:list){
  493 + if((schRealInfo.get("xlBm")+"").equals(scheduleRealInfo.getXlBm()) && (schRealInfo.get("lpName")+"")
  494 + .equals(scheduleRealInfo.getLpName())
  495 + && (schRealInfo.get("clZbh")+"").equals(scheduleRealInfo.getClZbh())){
  496 +
  497 + if(scheduleRealInfo.isDestroy()){
  498 + if(scheduleRealInfo.isReissue()){
  499 + scheduleRealInfo.setFcsjActualAll(scheduleRealInfo.getDfsj());
  500 + scheduleRealInfo.setZdsjActualAll(scheduleRealInfo.getZdsj());
  501 + }
  502 + else
  503 + continue;
  504 + }
  505 +
  506 + if(scheduleRealInfo.getBcType().equals("in")
  507 + || scheduleRealInfo.getBcType().equals("out")){
  508 + continue;
  509 + }
  510 +
  511 + sf.append("<LD>");
  512 + sf.append("<SJGH>").append(scheduleRealInfo.getjGh()).append("</SJGH>");
  513 + sf.append("<SXX>").append(scheduleRealInfo.getXlDir()).append("</SXX>");
  514 + sf.append("<FCZDMC>").append(scheduleRealInfo.getQdzName()).append("</FCZDMC>");
  515 + // 起点站的参数
  516 + otherMap.put("stationMark","B");
  517 + paramMap = packageYgcStationNumParam(scheduleRealInfo,otherMap);
  518 + sf.append("<FCZDXH>").append(getYgcStationNumByLineCodeAndDirectionAndStationName(paramMap,stationNumMap)).append("</FCZDXH>");
  519 + sf.append("<FCZDBM>").append(scheduleRealInfo.getQdzCode()).append("</FCZDBM>");
  520 + sf.append("<JHFCSJ>").append(scheduleRealInfo.getFcsj()).append("</JHFCSJ>");
  521 + sf.append("<DFSJ>").append(scheduleRealInfo.getDfsj()).append("</DFSJ>");
  522 + sf.append("<SJFCSJ>").append(scheduleRealInfo.getFcsjActual()).append("</SJFCSJ>");
  523 + sf.append("<FCZDLX></FCZDLX>");
  524 + sf.append("<DDZDMC>").append(scheduleRealInfo.getZdzName()).append("</DDZDMC>");
  525 + // 终点站的参数
  526 + otherMap.put("stationMark","E");
  527 + paramMap = packageYgcStationNumParam(scheduleRealInfo,otherMap);
  528 + sf.append("<DDZDXH>").append(getYgcStationNumByLineCodeAndDirectionAndStationName(paramMap,stationNumMap)).append("</DDZDXH>");
  529 + sf.append("<DDZDBM>").append(scheduleRealInfo.getZdzCode()).append("</DDZDBM>");
  530 + sf.append("<JHDDSJ>").append(scheduleRealInfo.getZdsj()).append("</JHDDSJ>");
  531 + sf.append("<SJDDSJ>").append(scheduleRealInfo.getZdsjActual()).append("</SJDDSJ>");
  532 + sf.append("<DDZDLX></DDZDLX>");
  533 + sf.append("<LDSCBZ>0</LDSCBZ>");
  534 + sf.append("<DDBZ></DDBZ>");
  535 + sf.append("</LD>");
  536 + }
  537 + }
  538 + sf.append("</LDList>");
  539 + sf.append("</DLD>");
  540 + }
  541 + if(counter % per == per - 1){
  542 + sf.append("</DLDS>");
  543 + // 去掉'号
  544 + str = sf.toString().replace("'","");
  545 + scount += invokeSetLD(str, counter);
  546 + counter = 0;
  547 + }
  548 + }
  549 + // 每per条线路上传后剩下的数据再上传
  550 + if(counter > 0){
  551 + sf.append("</DLDS>");
  552 + // 去掉'号
  553 + str = sf.toString().replace("'","");
  554 + scount += invokeSetLD(str, counter);
  555 + }
  556 + } catch (Exception e) {
  557 + e.printStackTrace();
  558 + logger.error("setLD:", e);
  559 + } finally {
  560 + try {
  561 + //发送邮件
  562 + EmailBean mail = new EmailBean();
  563 + mail.setSubject(IpUtils.getLocalIpAddress() +":路单日志数据"+date);
  564 + mail.setContent("总数:" + (listGroup == null ? 0 : listGroup.size()) + "<br/>成功数:" + scount + "<br/>跳过数:" + ccount + "<br/>耗时:" + (System.currentTimeMillis() - start));
  565 + sendEmailController.sendMail(emailSendToAddress, mail);
  566 + logger.info("setLD-sendMail:邮件发送成功!");
  567 + } catch (Exception e) {
  568 + e.printStackTrace();
  569 + logger.error("setLD-sendMail:",e);
  570 + }
  571 + }
  572 + return "success";
  573 + }
  574 +
  575 + /**
  576 + * 调用运管处电子路单接口,如果上传失败或有网络问题,最多执行10次
  577 + * @param xml 拼接的xml字符串
  578 + * @param counter 分组数
  579 + * @return 成功返回counter 失败返回0
  580 + */
  581 + private int invokeSetLD(String xml, int counter) {
  582 + for (int i = 0;i < 10;i++) {
  583 + try {
  584 + Results results = ssop.setLD(userNameOther, passwordOther, StringEscapeUtils.unescapeHtml(xml));
  585 + if (results.isSuccess()) {
  586 + logger.info("setLD: " + xml);
  587 + logger.info("setLD: 成功");
  588 + return counter;
  589 + } else if (i == 9) {
  590 + logger.error("setLD: " + xml);
  591 + logger.error("setLD: 失败," + results.getMessage());
  592 + }
  593 + Thread.sleep(2000);
  594 + } catch (Exception e) {
  595 + logger.error("运管处接口调用异常", e);
  596 + try {
  597 + Thread.sleep(2000);
  598 + } catch (InterruptedException ex) {
  599 + ex.printStackTrace();
  600 + }
  601 + }
  602 + }
  603 +
  604 + return 0;
  605 + }
  606 +
  607 + /**
  608 + * 上传路单 xml来自文件
  609 + * @return 上传成功标识
  610 + */
  611 + public String setLDFile(){
  612 + String result = "failure";
  613 + try {
  614 + String tmp = readXmlFromFile("E:/ld.txt");
  615 + Results rss = ssop.setLD(userNameOther, passwordOther, StringEscapeUtils.unescapeHtml(tmp));
  616 + if(rss.isSuccess()){
  617 + result = "success";
  618 + }
  619 + } catch (Exception e) {
  620 + logger.error("setLD:",e);
  621 + e.printStackTrace();
  622 + }finally{
  623 +
  624 + }
  625 + return result;
  626 + }
  627 +
  628 + /**
  629 + * 从文件中读取xml
  630 + * @param fileName 例:D:/test.txt
  631 + * @return
  632 + * @throws Exception
  633 + */
  634 + private String readXmlFromFile(String fileName) throws Exception {
  635 + StringBuffer sf = new StringBuffer("");
  636 + File file = new File(fileName);
  637 + InputStreamReader reader = new InputStreamReader(new FileInputStream(file),"GBK");
  638 + BufferedReader bufferedReader = new BufferedReader(reader);
  639 + String lineTxt = "";
  640 + while((lineTxt = bufferedReader.readLine()) != null){
  641 + sf.append(lineTxt);
  642 + }
  643 + reader.close();
  644 + return sf.toString().replaceAll("\t","");
  645 + }
  646 + /**
  647 + * 上传里程油耗
  648 + * @return 上传成功标识
  649 + */
  650 + public String setLCYH(){
  651 + String result = "failure";
  652 + // 取昨天 的日期
  653 + String date = sdfnyr.format(DateUtils.addDays(new Date(), -1));
  654 + StringBuffer sf = new StringBuffer();
  655 + try {
  656 + sf.append("<LCYHS>");
  657 + List<Map<String,Object>> listGroup = scheduleRealInfoRepository.setLCYHGroup(date);
  658 + List<ScheduleRealInfo> list = scheduleRealInfoRepository.findByDate(date);
  659 + Map<String,Object> map = new HashMap<String,Object>();
  660 + for(Map<String,Object> schRealInfo:listGroup){
  661 + if(schRealInfo != null){
  662 + map.put("insideCode_eq", schRealInfo.get("clZbh")+"");
  663 + Cars car = carsRepository.findOne(new CustomerSpecs<Cars>(map));
  664 + /**
  665 + * 如果car==null,则说明该车辆是从线调中换车功能中加进去的,
  666 + * 在cars基础信息中查不到车辆的信息,所以忽略该车辆
  667 + */
  668 + if(car == null){
  669 + continue;
  670 + }
  671 + //计算总公里和空驶公里,营运公里=总公里-空驶公里
  672 + double totalKilometers = 0,emptyKilometers =0;
  673 + sf.append("<LCYH>");
  674 + sf.append("<RQ>"+date+"</RQ>");
  675 + sf.append("<XLBM>"+BasicData.lineCode2ShangHaiCodeMap.get(schRealInfo.get("xlBm"))+"</XLBM>");
  676 + sf.append("<CPH>"+car.getCarPlate()+"</CPH>");
  677 + if(list != null && list.size() > 0){
  678 + for(ScheduleRealInfo scheduleRealInfo:list){
  679 + if((schRealInfo.get("xlBm")+"").equals(scheduleRealInfo.getXlBm()) && (schRealInfo.get("clZbh")+"")
  680 + .equals(scheduleRealInfo.getClZbh())){
  681 + Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();
  682 + //如果没有子任务,里程就是已执行(Status=2);有子任务的,忽略主任务,子任务的烂班
  683 + if(childTaskPlans.isEmpty()){
  684 + if(scheduleRealInfo.getStatus() == 2){
  685 + totalKilometers += scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc();
  686 + if(scheduleRealInfo.getBcType().equals("in") || scheduleRealInfo.getBcType().equals("out")
  687 + || scheduleRealInfo.getBcType().equals("venting")){
  688 + emptyKilometers += scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc();
  689 + }
  690 + }
  691 + }else{
  692 + Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
  693 + while(it.hasNext()){
  694 + ChildTaskPlan childTaskPlan = it.next();
  695 + if(!childTaskPlan.isDestroy()){
  696 + totalKilometers += childTaskPlan.getMileage()==null?0.0:childTaskPlan.getMileage();
  697 + if(childTaskPlan.getMileageType().equals("empty")){
  698 + emptyKilometers += childTaskPlan.getMileage()==null?0.0:childTaskPlan.getMileage();;
  699 + }
  700 + }
  701 + }
  702 + }
  703 + }
  704 + }
  705 + }
  706 + sf.append("<ZLC>"+totalKilometers+"</ZLC>");
  707 + sf.append("<YYLC>"+emptyKilometers+"</YYLC>");
  708 + sf.append("<YH>"+""+"</YH>");
  709 + sf.append("<JZYL>"+""+"</JZYL>");
  710 + sf.append("<DH>"+""+"</DH>");
  711 + sf.append("<UPDT>"+sdfnyrsfm.format(new Date())+"</UPDT>");
  712 + sf.append("<BBSCBZ>"+0+"</BBSCBZ>");
  713 + sf.append("</LCYH>");
  714 + }
  715 + }
  716 + sf.append("</LCYHS>");
  717 + if(ssop.setLCYH(userNameOther, passwordOther, sf.toString()).isSuccess()){
  718 + result = "success";
  719 + }
  720 + } catch (Exception e) {
  721 + logger.error("setLCYH:",e);
  722 + e.printStackTrace();
  723 + }finally{
  724 + logger.info("setLCYH:"+sf.toString());
  725 + logger.info("setLCYH:"+result);
  726 + }
  727 + return result;
  728 + }
  729 +
  730 + /**
  731 + * 上传线路调度日报
  732 + * @return
  733 + */
  734 + public String setDDRB(){
  735 + String result = "failure";
  736 + // 取昨天 的日期
  737 + String date = sdfnyr.format(DateUtils.addDays(new Date(), -1));
  738 + StringBuffer sf = new StringBuffer();
  739 + try {
  740 + sf.append("<DDRBS>");
  741 + List<Map<String,Object>> listGroup = scheduleRealInfoRepository.setDDRBGroup(date);
  742 + List<ScheduleRealInfo> list = scheduleRealInfoRepository.findByDate(date);
  743 + for(Map<String,Object> schRealInfo:listGroup){
  744 + if(schRealInfo != null){
  745 + double jhlc = 0,zlc = 0,jhkslc = 0,sjkslc = 0;
  746 + int jhbc = 0,sjbc = 0,jhzgfbc = 0,sjzgfbc = 0,jhwgfbc = 0,sjwgfbc = 0;
  747 + sf.append("<DDRB>");
  748 + sf.append("<RQ>"+date+"</RQ>");
  749 + sf.append("<XLBM>"+BasicData.lineCode2ShangHaiCodeMap.get(schRealInfo.get("xlBm"))+"</XLBM>");
  750 + for(ScheduleRealInfo scheduleRealInfo:list){
  751 + if(scheduleRealInfo != null){
  752 + if((schRealInfo.get("xlBm")+"").equals(scheduleRealInfo.getXlBm())){
  753 + //计划
  754 + if(!scheduleRealInfo.isSflj()){
  755 + jhlc += scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc();
  756 + //计划空驶
  757 + if(scheduleRealInfo.getBcType().equals("in") || scheduleRealInfo.getBcType().equals("out")){
  758 + jhkslc += scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc();
  759 + }
  760 + //计划早高峰,计划晚高峰
  761 + if(TimeUtils.morningPeak(scheduleRealInfo.getFcsj())){
  762 + jhzgfbc++;
  763 + } else if(TimeUtils.evenignPeak(scheduleRealInfo.getFcsj())){
  764 + jhwgfbc++;
  765 + }
  766 + }
  767 + jhbc++;
  768 +
  769 + //实际
  770 + Set<ChildTaskPlan> childTaskPlans = scheduleRealInfo.getcTasks();
  771 + //如果没有子任务,里程就是已执行(Status=2);有子任务的,忽略主任务,子任务的烂班
  772 + if(childTaskPlans.isEmpty()){
  773 + if(scheduleRealInfo.getStatus() == 2){
  774 + sjbc++;
  775 + zlc += scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc();
  776 + if(scheduleRealInfo.getBcType().equals("in") || scheduleRealInfo.getBcType().equals("out")
  777 + || scheduleRealInfo.getBcType().equals("venting")){
  778 + sjkslc += scheduleRealInfo.getJhlc()==null?0.0:scheduleRealInfo.getJhlc();;
  779 + }
  780 + }
  781 + }else{
  782 + sjbc++;
  783 + Iterator<ChildTaskPlan> it = childTaskPlans.iterator();
  784 + while(it.hasNext()){
  785 + ChildTaskPlan childTaskPlan = it.next();
  786 + if(!childTaskPlan.isDestroy()){
  787 + zlc += childTaskPlan.getMileage()==null?0.0:childTaskPlan.getMileage();
  788 + if(childTaskPlan.getMileageType().equals("empty")){
  789 + sjkslc += childTaskPlan.getMileage()==null?0.0:childTaskPlan.getMileage();;
  790 + }
  791 + }
  792 + }
  793 + }
  794 + //实际早高峰,计划晚高峰
  795 + if(scheduleRealInfo.getFcsjActual() != null){
  796 + if(TimeUtils.morningPeak(scheduleRealInfo.getFcsj())){
  797 + sjzgfbc++;
  798 + } else if(TimeUtils.evenignPeak(scheduleRealInfo.getFcsj())){
  799 + sjwgfbc++;
  800 + }
  801 + }
  802 + }
  803 + }
  804 + }
  805 + sf.append("<JHLC>"+format.format(jhlc)+"</JHLC>");
  806 + sf.append("<SSLC>"+format.format((zlc-sjkslc))+"</SSLC>");
  807 + sf.append("<JHKSLC>"+format.format(jhkslc)+"</JHKSLC>");
  808 + sf.append("<SJKSLC>"+format.format(sjkslc)+"</SJKSLC>");
  809 + sf.append("<JHBC>"+jhbc+"</JHBC>");
  810 + sf.append("<SJBC>"+sjbc+"</SJBC>");
  811 + sf.append("<JHZGFBC>"+jhzgfbc+"</JHZGFBC>");
  812 + sf.append("<SJZGFBC>"+sjzgfbc+"</SJZGFBC>");
  813 + sf.append("<JHWGFBC>"+jhwgfbc+"</JHWGFBC>");
  814 + sf.append("<SJWGFBC>"+sjwgfbc+"</SJWGFBC>");
  815 + sf.append("<UPDT>"+sdfnyrsfm.format(new Date())+"</UPDT>");
  816 + sf.append("<RBSCBZ>"+0+"</RBSCBZ>");
  817 + sf.append("</DDRB>");
  818 + }
  819 + }
  820 + sf.append("</DDRBS>");
  821 + if(ssop.setDDRB(userNameOther, passwordOther, sf.toString()).isSuccess()){
  822 + result = "success";
  823 + }
  824 + } catch (Exception e) {
  825 + logger.error("setDDRB:",e);
  826 + e.printStackTrace();
  827 + }finally{
  828 + logger.info("setDDRB:"+sf.toString());
  829 + logger.info("setDDRB:"+result);
  830 + }
  831 + return result;
  832 + }
  833 +
  834 + /**
  835 + * 上传计划班次 指定日期 yyyy-MM-dd
  836 + * @param theDate
  837 + * @return
  838 + */
  839 + public String setJHBC(String theDate){
  840 + return uploadJHBC(theDate);
  841 + }
  842 +
  843 + /**
  844 + * 上传计划班次
  845 + * @return
  846 + */
  847 + public String setJHBC(){
  848 + return uploadJHBC(null);
  849 + }
  850 + /**
  851 + * 上传线路计划班次表
  852 + */
  853 +
  854 + private String uploadJHBC(String theDate) {
  855 + String result = "failure";
  856 + Line line;
  857 + StringBuffer sBuffer =new StringBuffer();
  858 + try {
  859 + sBuffer.append("<JHBCs>");
  860 + // 声明变量
  861 + SchedulePlanInfo schedulePlanInfo;
  862 + String xlbm,zbh = "";
  863 + Long lp = 0L;
  864 + // 取得计划班次时间
  865 + String tomorrow = theDate == null ? sdfnyr.format(DateUtils.addDays(new Date(), +1)) : theDate;
  866 + // 查询所有班次
  867 + List<SchedulePlanInfo> schedulePlanList = schedulePlanInfoRepository.findLineScheduleBc(tomorrow);
  868 + int j = 0; // 初始化标识
  869 + if(schedulePlanList != null ){
  870 + HashMap<String,String> paramMap;
  871 + HashMap<String,String> otherMap = new HashMap<String, String>();
  872 + int size = schedulePlanList.size();
  873 + for (int i = 0; i < size; i++) {
  874 + schedulePlanInfo = schedulePlanList.get(i);
  875 + xlbm = schedulePlanInfo.getXlBm();
  876 + // 获取线路是否使用标识,如果未使用,则不查该线路数据
  877 + line = lineRepository.findByLineCode(xlbm);
  878 + if(line.getInUse() == null || line.getInUse() == 0){
  879 + continue;
  880 + }
  881 + if(++j == 1){// 第一次,则初始化值
  882 + zbh = schedulePlanInfo.getClZbh();
  883 + lp = schedulePlanInfo.getLp();
  884 + // 拼装XML
  885 + assembleJHBC(sBuffer, schedulePlanInfo, xlbm, zbh, lp);
  886 + }
  887 + // 比较是否为同一条线路同一辆车
  888 + if(xlbm.equals(schedulePlanInfo.getXlBm())
  889 + && zbh.equals(schedulePlanInfo.getClZbh())
  890 + && lp == schedulePlanInfo.getLp()){
  891 + if(schedulePlanInfo.getBcType().equals("in") || schedulePlanInfo.getBcType().equals("out")){
  892 + continue;
  893 + }
  894 + sBuffer.append("<BC>");
  895 + sBuffer.append("<SJGH>").append(schedulePlanInfo.getjGh()).append("</SJGH>");
  896 + sBuffer.append("<SXX>").append(schedulePlanInfo.getXlDir()).append("</SXX>");
  897 + sBuffer.append("<FCZDMC>").append(schedulePlanInfo.getQdzName()).append("</FCZDMC>");
  898 + // 起点站的参数
  899 + otherMap.put("stationMark","B");
  900 + paramMap = packageYgcStationNumParam(schedulePlanInfo,otherMap);
  901 + sBuffer.append("<ZDXH>").append(getYgcStationNumByLineCodeAndDirectionAndStationName(paramMap,null)).append("</ZDXH>");
  902 + sBuffer.append("<JHFCSJ>").append(schedulePlanInfo.getFcsj()).append("</JHFCSJ>");
  903 + sBuffer.append("<DDZDMC>").append(schedulePlanInfo.getZdzName()).append("</DDZDMC>");
  904 + // 起点站的参数
  905 + otherMap.put("stationMark","E");
  906 + paramMap = packageYgcStationNumParam(schedulePlanInfo,otherMap);
  907 + sBuffer.append("<DDXH>").append(getYgcStationNumByLineCodeAndDirectionAndStationName(paramMap,null)).append("</DDXH>");
  908 + sBuffer.append("<JHDDSJ>").append(calcDdsj(schedulePlanInfo.getFcsj(),schedulePlanInfo.getBcsj()))
  909 + .append("</JHDDSJ>");
  910 + sBuffer.append("</BC>");
  911 + if(i == size -1 ){
  912 + sBuffer.append("</BCList>");
  913 + sBuffer.append("</JHBC>");
  914 + }
  915 + }else{
  916 + zbh = schedulePlanInfo.getClZbh();
  917 + lp = schedulePlanInfo.getLp();
  918 + sBuffer.append("</BCList>");
  919 + sBuffer.append("</JHBC>");
  920 + // 拼装XML
  921 + assembleJHBC(sBuffer, schedulePlanInfo, xlbm, zbh, lp);
  922 + }
  923 + }
  924 + }
  925 + // 判断XML是否以</BCList>结尾,如果不是,则加上
  926 + String regex = "^*</JHBC>$";
  927 + Pattern p = Pattern.compile(regex);
  928 + Matcher m = p.matcher(sBuffer);
  929 + boolean isEndWithTrueFlag = false;
  930 + while (m.find()) {
  931 + isEndWithTrueFlag = true;
  932 + }
  933 + // 加上缺失的标签
  934 + if(!isEndWithTrueFlag){
  935 + sBuffer.append("</BCList>");
  936 + sBuffer.append("</JHBC>");
  937 + }
  938 + sBuffer.append("</JHBCs>");
  939 + if(ssop.setJHBC(userNameOther, passwordOther, sBuffer.toString()).isSuccess()){
  940 + result = "success";
  941 + }
  942 + } catch (Exception e) {
  943 + logger.error("setJHBC:",e);
  944 + e.printStackTrace();
  945 + }finally{
  946 + logger.info("setJHBC:"+sBuffer.toString());
  947 + logger.info("setJHBC:"+result);
  948 + }
  949 + return result;
  950 + }
  951 +
  952 + /**
  953 + * 上传线路班次时刻表数据
  954 + */
  955 + @Override
  956 + public String setSKB(String ids) {
  957 + String result = "上传失败,";
  958 + StringBuffer sBuffer = new StringBuffer();
  959 + DecimalFormat df = new DecimalFormat("######0.000");
  960 + Map<String,String> lsStationCode2NameMap = null;
  961 + Map<String, Integer> lsStationName2YgcNumber = null;
  962 + try {
  963 + String[] idArray = ids.split(",");
  964 + StringBuffer sBufferA ,sBufferB ,sBufferC ;
  965 + double zlc,yylc,singleLc,emptyLc;// 总里程、营运里程、单程、空放里程
  966 + String bcType,sxx;// 班次类型、上下行
  967 + // 上传的时刻表集合
  968 + List<TTInfo> ttinfoList = new ArrayList<>();
  969 + TTInfo ttInfo;
  970 + TTInfoDetail ttInfoDetail;
  971 + LineInformation lineInformation;
  972 + Iterator<TTInfoDetail> ttInfoDetailIterator;
  973 + HashMap<String,Object> param ;
  974 + sBuffer.append("<SKBs>");
  975 + HashMap<String,String> paramMap;
  976 + HashMap<String,String> otherMap = new HashMap<>();
  977 + // 线路编码、周几执行、发车站点名称、发车站点序号、到达站点名称、到达站点序号
  978 + String xlbm,zjzx,fczdmc,zdxh,ddzdmc,ddxh;
  979 + // 得到时刻表版本号
  980 + int lineVersion;
  981 + long ttinfoId;
  982 + // 是否输出站点信息
  983 + boolean isLogStation;
  984 + for (int i = 0; i < idArray.length; i++) {
  985 + ttinfoId = Long.valueOf(idArray[i]);
  986 + ttInfo = ttInfoRepository.findOne(ttinfoId);
  987 + if(ttInfo == null)
  988 + continue;
  989 + ttinfoList.add(ttInfo); // 保存时刻表
  990 + // 得到时刻表版本号
  991 + lineVersion = ttInfo.getLineVersion();
  992 + // 查询历史站点路由
  993 + lsStationCode2NameMap = getLsStationCode(ttInfo.getXl().getLineCode(),lineVersion);
  994 + // 查询历史站点路由
  995 + lsStationName2YgcNumber = getLsStationRoute(ttInfo.getXl().getLineCode(),lineVersion);
  996 + zlc = 0.0f;
  997 + yylc = 0.0f;
  998 + // 获得时刻表
  999 + param = new HashMap();
  1000 + param.put("ttinfo.id_eq", ttInfo.getId());
  1001 + ttInfoDetailIterator = ttInfoDetailRepository.findAll(new CustomerSpecs<TTInfoDetail>(param),
  1002 + new Sort(Direction.ASC, "xlDir")).iterator();
  1003 + // 获得lineInformation
  1004 + param = new HashMap();
  1005 + param.put("line.id_eq", ttInfo.getXl().getId());
  1006 + lineInformation = lineInformationRepository.findOne(new CustomerSpecs<LineInformation>(param));
  1007 + // 初始化
  1008 + isLogStation = true;
  1009 + if(ttInfoDetailIterator.hasNext()){
  1010 + // 得到线路信息
  1011 + Line line = lineRepository.findOne(ttInfo.getXl().getId());
  1012 + if(line == null){
  1013 + result += "未找到相应的线路信息,请设置线路信息后再上传";
  1014 + return result;
  1015 + }
  1016 + // 得到上海市线路编码
  1017 + xlbm = line.getShanghaiLinecode();
  1018 + if("".equals(xlbm) || "null".equals(xlbm)){
  1019 + result += "线路编码为空,请设置线路编码后再上传";
  1020 + return result;
  1021 + }
  1022 + // 拿到周几执行
  1023 + zjzx = changeRuleDay(ttInfo.getRule_days());
  1024 + if("".equals(zjzx) || "null".equals(zjzx)){
  1025 + result += "时刻表执行时间为空,请设置执行时间后再上传";
  1026 + return result;
  1027 + }
  1028 + sBuffer.append("<SKB>");
  1029 + sBuffer.append("<XLBM>").append(xlbm).append("</XLBM>");
  1030 + sBufferB = new StringBuffer();
  1031 + sBufferC = new StringBuffer();
  1032 + sBufferB.append("<KSRQ>").append(sdfnyr.format(ttInfo.getQyrq())).append("</KSRQ>");
  1033 + // 结束日期暂时不要,节假日的班次表才需要,如春节的班次表
  1034 + sBufferB.append("<JSRQ>").append("").append("</JSRQ>");
  1035 + sBufferB.append("<ZJZX>").append(zjzx).append("</ZJZX>");
  1036 + sBufferB.append("<TBYY>").append("").append("</TBYY>");
  1037 + sBufferB.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");
  1038 + sBufferB.append("<BCList>");
  1039 + while (ttInfoDetailIterator.hasNext()) {
  1040 + ttInfoDetail = ttInfoDetailIterator.next();
  1041 + bcType = ttInfoDetail.getBcType();
  1042 + sxx = ttInfoDetail.getXlDir();
  1043 + // 进出场班次的里程,加入总里程
  1044 + if(bcType.equals("in") || bcType.equals("out")){
  1045 + // 进出班次的计划里程,算空驶里程
  1046 + emptyLc = ttInfoDetail.getJhlc();
  1047 + // 总里程需要加上空驶里程
  1048 + zlc += emptyLc;
  1049 + continue;
  1050 + }
  1051 + // 不是正常班次,不传到运管处
  1052 + if(!bcType.equals("normal")){
  1053 + continue;
  1054 + }
  1055 + // 如果发车时间格式错误,忽略此条
  1056 + if(changeTimeFormat(ttInfoDetail) == null){
  1057 + continue;
  1058 + }
  1059 + // 发生站点名称
  1060 + fczdmc = lsStationCode2NameMap.get(ttInfoDetail.getXl().getLineCode()+"_"+ttInfoDetail.getXlDir()+"_"+ttInfoDetail.getQdzCode());
  1061 + if("".equals(fczdmc) || "null".equals(fczdmc)){
  1062 + result += "发车站点名称为空,请根据时刻表当前的版本号设置好历史站点路由再上传";
  1063 + return result;
  1064 + }
  1065 + sBufferC.append("<BC>");
  1066 + sBufferC.append("<LPBH>").append(ttInfoDetail.getLp().getLpNo()).append("</LPBH>");
  1067 + sBufferC.append("<SXX>").append(sxx).append("</SXX>");
  1068 + sBufferC.append("<FCZDMC>").append(fczdmc).append("</FCZDMC>");
  1069 + // 起点站的参数
  1070 + otherMap.put("stationMark","B");
  1071 + paramMap = packageYgcStationNumParam(ttInfoDetail,otherMap);
  1072 + if(isLogStation){// 输出起点站信息
  1073 + logger.info("setSKB:"+"起点站信息:"+paramMap);
  1074 + }
  1075 + // 发车站点序号
  1076 + zdxh = String.valueOf(getYgcStationNumByLineCodeAndDirectionAndStationName(paramMap,lsStationName2YgcNumber));
  1077 + if("".equals(zdxh) || "null".equals(zdxh) || "0".equals(zdxh)){
  1078 + result += "发车站点序号为空,请根据时刻表当前的版本号设置好历史站点路由再上传";
  1079 + return result;
  1080 + }
  1081 + // 到达站点名称
  1082 + ddzdmc = lsStationCode2NameMap.get(ttInfoDetail.getXl().getLineCode()+"_"+ttInfoDetail.getXlDir()+"_"+ttInfoDetail.getZdzCode());
  1083 + if("".equals(ddzdmc) || "null".equals(ddzdmc)){
  1084 + result += "到达站点名称为空,请根据时刻表当前的版本号设置好历史站点路由再上传";
  1085 + return result;
  1086 + }
  1087 + sBufferC.append("<ZDXH>").append(zdxh).append("</ZDXH>");
  1088 + sBufferC.append("<JHFCSJ>").append(changeTimeFormat(ttInfoDetail)).append("</JHFCSJ>");
  1089 + sBufferC.append("<DDZDMC>").append(ddzdmc).append("</DDZDMC>");
  1090 + // 终点站的参数
  1091 + otherMap.put("stationMark","E");
  1092 + paramMap = packageYgcStationNumParam(ttInfoDetail,otherMap);
  1093 + if(isLogStation){// 输出终点站信息
  1094 + logger.info("setSKB:"+"终点站信息:"+paramMap);
  1095 + }
  1096 + // 到达站点序号
  1097 + ddxh = String.valueOf(getYgcStationNumByLineCodeAndDirectionAndStationName(paramMap,lsStationName2YgcNumber));
  1098 + if("".equals(ddxh) || "null".equals(ddxh) || "0".equals(ddxh)){
  1099 + result += "到达站点序号为空,请根据时刻表当前的版本号设置好历史站点路由再上传";
  1100 + return result;
  1101 + }
  1102 + isLogStation = false; // 一条线路只输出一次,后面的不输出了
  1103 + sBufferC.append("<DDXH>").append(ddxh).append("</DDXH>");
  1104 + sBufferC.append("<JHDDSJ>").append(calcDdsj(ttInfoDetail.getFcsj(),ttInfoDetail.getBcsj())).append("</JHDDSJ>");
  1105 + sBufferC.append("</BC>");
  1106 + // 0:上行;1:下行
  1107 + if("0".equals(sxx)){
  1108 + singleLc = lineInformation.getUpMileage();
  1109 + }else{
  1110 + singleLc = lineInformation.getDownMileage();
  1111 + }
  1112 + zlc += singleLc ;
  1113 + yylc += singleLc;
  1114 + }
  1115 + sBufferC.append("</BCList>");
  1116 + sBufferC.append("</SKB>");
  1117 + sBufferA = new StringBuffer();
  1118 + sBufferA.append("<JHZLC>").append(df.format(zlc)).append("</JHZLC>");
  1119 + sBufferA.append("<JHYYLC>").append(df.format(yylc)).append("</JHYYLC>");
  1120 + sBuffer.append(sBufferA).append(sBufferB).append(sBufferC);
  1121 + }
  1122 + logger.info("setSKB:"+"ttinfoId:"+ttinfoId+";当前站点版本号:"+lineVersion+";查询历史站点路由:"+lsStationCode2NameMap+";查询历史站点编号:"+lsStationName2YgcNumber);
  1123 + }
  1124 + sBuffer.append("</SKBs>");
  1125 + if(ssop.setSKB(userNameOther, passwordOther, sBuffer.toString()).isSuccess()){
  1126 + result = "上传成功";
  1127 + SKBUploadLogger skbUploadLogger ;
  1128 + SysUser user = SecurityUtils.getCurrentUser();
  1129 + // 保存时刻表上传记录
  1130 + for(TTInfo ttInfo1 : ttinfoList){
  1131 + skbUploadLogger = new SKBUploadLogger();
  1132 + skbUploadLogger.setTtInfo(ttInfo1);
  1133 + skbUploadLogger.setUser(user);
  1134 + skbUploadLoggerRepository.save(skbUploadLogger);
  1135 + }
  1136 + }
  1137 + } catch (Exception e) {
  1138 + logger.error("setSKB:", e);
  1139 + e.printStackTrace();
  1140 + }finally{
  1141 + logger.info("setSKB:"+sBuffer.toString());
  1142 + logger.info("setSKB:"+result);
  1143 + }
  1144 + return result;
  1145 + }
  1146 +
  1147 + /**
  1148 + * 上传线路人员车辆配置信息
  1149 + */
  1150 + @Override
  1151 + public String setXLPC() {
  1152 + String result = "failure";
  1153 + StringBuffer sBuffer =new StringBuffer();
  1154 + try {
  1155 + sBuffer.append("<XLPCs>");
  1156 + // 声明变量
  1157 + Line line = null;
  1158 + Cars cars = null;
  1159 + List<Personnel> personnelList = null;
  1160 + List<Cars> carsList = null;
  1161 + int totalPersonnel,totalCar ;// 人员数量。车辆数量
  1162 + // 查询所有线路
  1163 + Iterator<Line> lineIterator = lineRepository.findAll().iterator();
  1164 + // 循环查找线路下的信息
  1165 + while(lineIterator.hasNext()){
  1166 + line = lineIterator.next();
  1167 + sBuffer.append("<XLPC>");
  1168 + sBuffer.append("<XLBM>").append(BasicData.lineId2ShangHaiCodeMap.get(line.getId())).append("</XLBM>");
  1169 + // 查询驾驶员数量
  1170 + personnelList = personnelRepository.findJsysByLineId(line.getId());
  1171 + totalPersonnel = personnelList != null ? personnelList.size():0;
  1172 + sBuffer.append("<SJRS>").append(totalPersonnel).append("</SJRS>");
  1173 + // 查询售票员人员数量
  1174 + personnelList = personnelRepository.findSpysByLineId(line.getId());
  1175 + totalPersonnel = personnelList != null ? personnelList.size():0;
  1176 + sBuffer.append("<SPYRS>").append(totalPersonnel).append("</SPYRS>");
  1177 + // 查询车辆
  1178 + carsList = carsRepository.findCarsByLineId(line.getId());
  1179 + totalCar = carsList != null ? carsList.size():0;
  1180 + sBuffer.append("<PCSL>").append(totalCar).append("</PCSL>");
  1181 + sBuffer.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");
  1182 + int carsNum = 0;
  1183 + // 取车牌号
  1184 + if(carsList != null){
  1185 + carsNum = carsList.size();
  1186 + sBuffer.append("<CPHList>");
  1187 + for (int i = 0; i < carsNum; i++) {
  1188 + cars = carsList.get(i);
  1189 + sBuffer.append("<CPH>").append("沪").append(cars.getCarCode()).append("</CPH>");
  1190 + }
  1191 + sBuffer.append("</CPHList>");
  1192 + }
  1193 + sBuffer.append("</XLPC>");
  1194 + }
  1195 + sBuffer.append("</XLPCs>");
  1196 + if(ssop.setXLPC(userNameOther, passwordOther, sBuffer.toString()).isSuccess()){
  1197 + result = "success";
  1198 + }
  1199 + } catch (Exception e) {
  1200 + logger.error("setXLPC:",e);
  1201 + e.printStackTrace();
  1202 + }finally{
  1203 + logger.info("setXLPC:"+sBuffer.toString());
  1204 + logger.info("setXLPC:"+result);
  1205 + }
  1206 + return result;
  1207 + }
  1208 +
  1209 +
  1210 + /**
  1211 + * 上传超速数据
  1212 + */
  1213 + @Override
  1214 + public String setCS() {
  1215 + String result = "failure";
  1216 + StringBuffer sBuffer =new StringBuffer();
  1217 + sBuffer.append("<CSs>");
  1218 + String sql = "SELECT * FROM bsth_c_speeding where DATE_FORMAT(create_date,'%Y-%m-%d') = ? order by create_date ";
  1219 + Connection conn = null;
  1220 + PreparedStatement ps = null;
  1221 + ResultSet rs = null;
  1222 + // 取昨天 的日期
  1223 + String yesterday = sdfnyr.format(DateUtils.addDays(new Date(), -1));
  1224 + try {
  1225 + conn = DBUtils_MS.getConnection();
  1226 + ps = conn.prepareStatement(sql);
  1227 + ps.setString(1, yesterday);
  1228 + rs = ps.executeQuery();
  1229 + Float lon, lat;
  1230 + String kssk;
  1231 + String speed;
  1232 + while (rs.next()) {
  1233 + kssk = sdfnyrsfm.format(rs.getLong("TIMESTAMP"));
  1234 + speed = rs.getString("SPEED");
  1235 + // 经纬度
  1236 + lon = rs.getFloat("LON");
  1237 + lat = rs.getFloat("LAT");
  1238 + sBuffer.append("<CS>");
  1239 + sBuffer.append("<RQ>").append(sdfnyr.format(rs.getDate("CREATE_DATE"))).append("</RQ>");
  1240 + sBuffer.append("<XLBM>").append(BasicData.lineCode2ShangHaiCodeMap.get(rs.getString("LINE"))).append("</XLBM>");////////
  1241 + sBuffer.append("<CPH>").append(rs.getString("VEHICLE")).append("</CPH>");
  1242 + sBuffer.append("<KSSK>").append(kssk).append("</KSSK>");
  1243 + sBuffer.append("<KSDDJD>").append(lon).append("</KSDDJD>");
  1244 + sBuffer.append("<KSDDWD>").append(lat).append("</KSDDWD>");
  1245 + sBuffer.append("<KSLD>").append("").append("</KSLD>");//**********************
  1246 + sBuffer.append("<JSSK>").append(kssk).append("</JSSK>");
  1247 + sBuffer.append("<JSDDJD>").append(lon).append("</JSDDJD>");
  1248 + sBuffer.append("<JSDDWD>").append(lat).append("</JSDDWD>");
  1249 + sBuffer.append("<JSLD>").append("").append("</JSLD>");//**********************
  1250 + sBuffer.append("<PJSD>").append(speed).append("</PJSD>");
  1251 + sBuffer.append("<ZGSS>").append(speed).append("</ZGSS>");
  1252 + sBuffer.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");
  1253 + sBuffer.append("</CS>");
  1254 + }
  1255 + sBuffer.append("</CSs>");
  1256 + if(ssop.setCS(userNameOther, passwordOther, sBuffer.toString()).isSuccess()){
  1257 + result = "success";
  1258 + }
  1259 + } catch (Exception e) {
  1260 + logger.error("setCS:",e);
  1261 + e.printStackTrace();
  1262 + } finally {
  1263 + logger.info("setCS:"+sBuffer.toString());
  1264 + logger.info("setCS:"+result);
  1265 + DBUtils_MS.close(rs, ps, conn);
  1266 + }
  1267 + return result;
  1268 + }
  1269 +
  1270 +
  1271 + /**
  1272 + * 下载全量的公交基础数据
  1273 + */
  1274 + public String getDownLoadAllDataFile() {
  1275 + String result = "failure";
  1276 + try {
  1277 + try {
  1278 + if(ygcBasicDataService.download("admin","000000","abc.zip")){
  1279 + result = "success";
  1280 + }
  1281 + } catch (Exception e) {
  1282 + e.printStackTrace();
  1283 + }
  1284 + } catch (Exception e) {
  1285 + e.printStackTrace();
  1286 + }
  1287 +
  1288 + return result;
  1289 + }
  1290 +
  1291 + /**
  1292 + * 下载增量的公交基础数据
  1293 + */
  1294 + public String getDownLoadIncreaseDataFile() {
  1295 + String result = "success";
  1296 + try {
  1297 + //System.out.println(portType.downloadIncreaseDataFile(args0, args1, args2));
  1298 + } catch (Exception e) {
  1299 + e.printStackTrace();
  1300 + }
  1301 +
  1302 + return result;
  1303 + }
  1304 +
  1305 + /**
  1306 + * 指定线路查询方式公交基础数据下载
  1307 + */
  1308 + public String getDownLoadWarrantsBusLineStation() {
  1309 + String result = "success";
  1310 + try {
  1311 +
  1312 + //portType.setXL(userNameXl, passwordXl, sBuffer.toString());
  1313 + } catch (Exception e) {
  1314 + e.printStackTrace();
  1315 + }
  1316 +
  1317 + return result;
  1318 + }
  1319 +
  1320 + /**
  1321 + * 计算结束时间
  1322 + * @param fcsj 发车时间
  1323 + * @param bcsj 班次历时
  1324 + * @return
  1325 + */
  1326 + private String calcDdsj(String fcsj,Integer bcsj){
  1327 + String result = "";
  1328 + if(fcsj.indexOf(":") != -1){
  1329 + if(bcsj == null){
  1330 + return fcsj;
  1331 + }
  1332 + // 时和分隔开
  1333 + String[] fcsjArray = fcsj.split(":");
  1334 + // 分和历时时间相加
  1335 + Integer fullTime = Integer.valueOf(fcsjArray[1])+ bcsj;
  1336 + int hour,min,sumHour;
  1337 + hour = fullTime / 60;
  1338 + min = fullTime % 60;
  1339 + sumHour = Integer.valueOf(fcsjArray[0])+hour;
  1340 + if(sumHour >= 24){
  1341 + result = String.format("%02d",sumHour - 24);
  1342 + }else{
  1343 + result = String.format("%02d",sumHour);;
  1344 + }
  1345 + result +=":"+String.format("%02d", min);
  1346 + }else{
  1347 + result = fcsj;
  1348 + }
  1349 + return result;
  1350 + }
  1351 +
  1352 + /**
  1353 + * 改变时间格式
  1354 + * @param ttInfoDetail 时刻表详细
  1355 + * @return xx:yy
  1356 + */
  1357 + private String changeTimeFormat(TTInfoDetail ttInfoDetail){
  1358 + String result = "00:00";
  1359 + String fcsj = ttInfoDetail.getFcsj();
  1360 + if(fcsj.indexOf(":") != -1){
  1361 + // 时和分隔开
  1362 + String[] fcsjArray = fcsj.split(":");
  1363 + result = String.format("%02d", Integer.valueOf(fcsjArray[0]))+":";
  1364 + result +=String.format("%02d", Integer.valueOf(fcsjArray[1]));
  1365 + }else{
  1366 + result = null;
  1367 + logger.info("setSKB:发车时间错误:ttInfoDetail.id="+ttInfoDetail.getId());
  1368 + }
  1369 + return result;
  1370 + }
  1371 +
  1372 + /**
  1373 + * 拼装线路计划班次表的XML
  1374 + * @param sBuffer
  1375 + * @param schedulePlanInfo
  1376 + * @param xlbm
  1377 + * @param zbh
  1378 + * @param lp
  1379 + */
  1380 + private void assembleJHBC(StringBuffer sBuffer,SchedulePlanInfo schedulePlanInfo,String xlbm,String zbh,Long lp){
  1381 + sBuffer.append("<JHBC>");
  1382 + sBuffer.append("<RQ>").append(sdfnyr.format(schedulePlanInfo.getScheduleDate())).append("</RQ>");
  1383 + sBuffer.append("<XLBM>").append(BasicData.lineCode2ShangHaiCodeMap.get(xlbm)).append("</XLBM>");
  1384 + sBuffer.append("<CPH>").append("沪"+zbh).append("</CPH>");
  1385 + sBuffer.append("<LPBH>").append(lp).append("</LPBH>");
  1386 + sBuffer.append("<UPDT>").append(sdfnyrsfm.format(new Date())).append("</UPDT>");
  1387 + sBuffer.append("<BCList>");
  1388 + }
  1389 + /**
  1390 + * 转换排班规则
  1391 + * @param ruleDay
  1392 + * @return
  1393 + */
  1394 + private String changeRuleDay(String ruleDay){
  1395 + String result = "";
  1396 + int flag ;
  1397 + String[] ruleDayArray = ruleDay.split(",");
  1398 + for (int i = 0; i < ruleDayArray.length; i++) {
  1399 + if(ruleDayArray[i].equals("1")){
  1400 + flag = i+1;
  1401 + }else{
  1402 + flag = 0;
  1403 + }
  1404 + if(flag > 0){
  1405 + result += flag + ",";
  1406 + }
  1407 + }
  1408 + // 去掉最后一个字符
  1409 + if(StringUtils.endsWith(result,",")){
  1410 + result = StringUtils.removeEnd(result,",");
  1411 + }
  1412 + return result;
  1413 + }
  1414 + /**
  1415 + * 设置统一的公司名称
  1416 + * @param company
  1417 + */
  1418 + private void setCompanyName(String company){
  1419 + if(company.equals("闵行公司")){
  1420 + company = "浦东闵行公交公司";
  1421 + }else if(company.equals("杨高公司")){
  1422 + company = "浦东杨高公交公司";
  1423 + }else if(company.equals("上南公司")){
  1424 + company = "浦东上南公交公司";
  1425 + }else if(company.equals("金高公司")){
  1426 + company = "浦东金高公交公司";
  1427 + }else if(company.equals("南汇公司")){
  1428 + company = "浦东南汇公交公司";
  1429 + }else if(company.equals("青浦公交")){
  1430 + company = "青浦公交公司";
  1431 + }
  1432 + }
  1433 + /**
  1434 + * @param stationsList 站点路由集
  1435 + * @param sBuffer sBuffer
  1436 + * @param startId 站点序号起始ID
  1437 + *
  1438 + * @return 站点序号累加后的ID
  1439 + */
  1440 + private int packagStationXml(List<StationRoute> stationsList,StringBuffer sBuffer,int startId,Map<String, Integer> stationNumMap){
  1441 + int size = stationsList.size();
  1442 + StationRoute srRoute;
  1443 + HashMap<String,String> paraMap;
  1444 + String zdlx ;// 站点类型:0:起点站、1:终点站、2:中途站
  1445 + for (int i = 0; i < size; i++) {
  1446 + srRoute = stationsList.get(i);
  1447 + zdlx = srRoute.getStationMark();
  1448 + if(zdlx.equals("B")){
  1449 + zdlx = "0";
  1450 + }else if(zdlx.equals("E")){
  1451 + zdlx = "1";
  1452 + }else{
  1453 + zdlx = "2";
  1454 + }
  1455 + paraMap = packageYgcStationNumParam(srRoute,null);
  1456 + sBuffer.append("<Station>");
  1457 + sBuffer.append("<ZDXH>").append(getYgcStationNumByLineCodeAndDirectionAndStationName(paraMap,stationNumMap)).append("</ZDXH>");
  1458 + sBuffer.append("<SXX>").append(srRoute.getDirections()).append("</SXX>");
  1459 + sBuffer.append("<ZDMC>").append(srRoute.getStationName()).append("</ZDMC>");
  1460 + sBuffer.append("<ZDBM>").append(srRoute.getStationCode()).append("</ZDBM>");
  1461 + sBuffer.append("<ZDJD>").append(srRoute.getStation().getgLonx()).append("</ZDJD>");
  1462 + sBuffer.append("<ZDWD>").append(srRoute.getStation().getgLaty()).append("</ZDWD>");
  1463 + sBuffer.append("<ZZ>").append(srRoute.getStation().getAddr() == null ? "" : srRoute.getStation().getAddr()).append("</ZZ>");
  1464 + sBuffer.append("<ZDLX>").append(zdlx).append("</ZDLX>");
  1465 + sBuffer.append("<ZJLC>").append(srRoute.getDistances()).append("</ZJLC>");
  1466 + sBuffer.append("</Station>");
  1467 + startId++;
  1468 + }
  1469 + return startId;
  1470 + }
  1471 +
  1472 + /**
  1473 + * @param pointList 站点点位集
  1474 + * @param sBuffer sBuffer
  1475 + * @param startId 站点序号起始ID
  1476 + *
  1477 + * @return 站点序号累加后的ID
  1478 + */
  1479 + private int packagStationPointXml(List<Object[]> pointList,StringBuffer sBuffer,int startId){
  1480 + int size = pointList.size();
  1481 + Object[] objs;
  1482 + String bsection,dir,section;
  1483 + String[] sections ;
  1484 + for (int i = 0; i < size; i++) {
  1485 + objs = pointList.get(i);
  1486 + bsection = objs[0]+"";
  1487 + dir = objs[1]+"";
  1488 + // 取括号内的内容
  1489 + Pattern pattern = Pattern.compile("(?<=\\()(.+?)(?=\\))");
  1490 + Matcher matcher = pattern.matcher(bsection);
  1491 + if(matcher.find()){
  1492 + sections = matcher.group().split(",");
  1493 + for (int j = 0 ; j < sections.length ; j ++){
  1494 + section = sections[j];
  1495 + sBuffer.append("<LinePoint>");
  1496 + sBuffer.append("<ZDXH>").append(startId).append("</ZDXH>");
  1497 + sBuffer.append("<SXX>").append(dir).append("</SXX>");
  1498 + sBuffer.append("<ZDJD>").append(section.split(" ")[0]).append("</ZDJD>");
  1499 + sBuffer.append("<ZDWD>").append(section.split(" ")[1]).append("</ZDWD>");
  1500 + sBuffer.append("</LinePoint>");
  1501 + startId++;
  1502 + }
  1503 + }
  1504 + }
  1505 + return startId;
  1506 + }
  1507 +
  1508 + /**
  1509 + * 获取运管处站点序号
  1510 + * @param map
  1511 + * @return 运管处站点序号
  1512 + */
  1513 + private Integer getYgcStationNumByLineCodeAndDirectionAndStationName(HashMap<String,String> map,Map<String, Integer> stationNumMap){
  1514 + // 线路编码
  1515 + String lineCode = map.get("lineCode");
  1516 + // 线路走向 0:上行 1:下行
  1517 + String direction = map.get("direction");
  1518 + // 站点编码
  1519 + String stationCode = map.get("stationCode");
  1520 + // 站点类型:B:起点站 Z:中途站 E:终点站 T:停车场
  1521 + String stationMark = map.get("stationMark");
  1522 + String[] marks = null;
  1523 + // 起点站,先从起点找,找不到再从中途站找,最后从终点找
  1524 + if(stationMark.equals("B")){
  1525 + marks= new String[]{"B","Z","E"};
  1526 + }else if(stationMark.equals("E")){// 终点站相反
  1527 + marks= new String[]{"E","Z","B"};
  1528 + }else if(stationMark.equals("Z")){
  1529 + marks= new String[]{"Z"};
  1530 + }
  1531 + // 默认从缓存BasicData.stationName2YgcNumber
  1532 + Map<String, Integer> tempMap = BasicData.stationName2YgcNumber;
  1533 + // 如果传入的stationNumMap不为空,则不是缓存取,而从stationNumMap取
  1534 + if(stationNumMap != null){
  1535 + tempMap = stationNumMap;
  1536 + }
  1537 + Integer number = null;
  1538 + for (int i = 0 ;i < marks.length ; i ++){
  1539 + number = tempMap.get(lineCode+"_"+direction+"_"+stationCode+"_"+marks[i]);
  1540 + if(number != null){
  1541 + break;
  1542 + }
  1543 + }
  1544 + return number == null ? 0 : number;
  1545 + }
  1546 +
  1547 + /**
  1548 + * 封装查询站序条件
  1549 + * @param obj
  1550 + * @return
  1551 + */
  1552 + private HashMap packageYgcStationNumParam(Object obj,HashMap<String,String> otherParam){
  1553 + HashMap<String,String> map = new HashMap<String,String>();
  1554 + String lineCode = "",direction = "",stationCode = "",stationMark = "";
  1555 + // 站点路由
  1556 + if(obj instanceof StationRoute){
  1557 + StationRoute sr = (StationRoute)obj;
  1558 + lineCode = sr.getLineCode();
  1559 + direction = String.valueOf(sr.getDirections());
  1560 + stationCode = sr.getStationCode();
  1561 + stationMark = sr.getStationMark();
  1562 + }else if(obj instanceof ScheduleRealInfo){ //实际排班计划明细。
  1563 + ScheduleRealInfo sri = (ScheduleRealInfo)obj;
  1564 + lineCode = sri.getXlBm();
  1565 + direction = sri.getXlDir();
  1566 + if(otherParam != null && otherParam.get("stationMark") != null){
  1567 + stationMark = otherParam.get("stationMark");
  1568 + if(stationMark.equals("B")){ // 起点站
  1569 + stationCode = sri.getQdzCode();
  1570 + }else if(stationMark.equals("E")){ // 终点站
  1571 + stationCode = sri.getZdzCode();
  1572 + }
  1573 + }
  1574 + }else if(obj instanceof SchedulePlanInfo){ //排班计划明细
  1575 + SchedulePlanInfo spi = (SchedulePlanInfo)obj;
  1576 + lineCode = spi.getXlBm();
  1577 + direction = spi.getXlDir();
  1578 + if(otherParam != null && otherParam.get("stationMark") != null){
  1579 + stationMark = otherParam.get("stationMark");
  1580 + if(stationMark.equals("B")){ // 起点站
  1581 + stationCode = spi.getQdzCode();
  1582 + }else if(stationMark.equals("E")){ // 终点站
  1583 + stationCode = spi.getZdzCode();
  1584 + }
  1585 + }
  1586 + }else if(obj instanceof TTInfoDetail){ //时刻表明细
  1587 + TTInfoDetail ttid = (TTInfoDetail)obj;
  1588 + lineCode = ttid.getXl().getLineCode();
  1589 + direction = ttid.getXlDir();
  1590 + if(otherParam != null && otherParam.get("stationMark") != null){
  1591 + stationMark = otherParam.get("stationMark");
  1592 + if(stationMark.equals("B")){ // 起点站
  1593 + stationCode = ttid.getQdzCode();
  1594 + }else if(stationMark.equals("E")){ // 终点站
  1595 + stationCode = ttid.getZdzCode();
  1596 + }
  1597 + }
  1598 + }
  1599 + map.put("lineCode",lineCode);// 站点编码
  1600 + map.put("direction",direction); // 上下行
  1601 + map.put("stationCode",stationCode); // 站点编号
  1602 + map.put("stationMark",stationMark); // 站点类型
  1603 + return map;
  1604 + }
  1605 +
  1606 + /**
  1607 + * 取得历史站点编码和站点名称的对应关系
  1608 + * @return
  1609 + */
  1610 + private Map<String, String> getLsStationCode(String lineCode,int lineVersion){
  1611 + Map<String,Object> map = new HashMap<>();
  1612 + map.put("lineCode_eq", lineCode);
  1613 + map.put("versions_eq",lineVersion);
  1614 + LsStationRoute lsroute;
  1615 + Iterator<LsStationRoute> iterator = lsStationRouteRepository.findAll(new CustomerSpecs<LsStationRoute>(map)).iterator();
  1616 + Map<String, String> stationCode2Name = new HashMap<>();
  1617 + while (iterator.hasNext()) {
  1618 + lsroute = iterator.next();
  1619 + stationCode2Name.put(lsroute.getLineCode() + "_" + lsroute.getDirections() + "_" + lsroute.getStationCode(), lsroute.getStationName());
  1620 + }
  1621 + return stationCode2Name;
  1622 + }
  1623 +
  1624 + private Map<String, Integer> getLsStationRoute(String xlbm,int lineVersion){
  1625 + Map<String, Integer> tempStationName2YgcNumber = new HashMap<String, Integer>();
  1626 + /**
  1627 + * 加载运管处的站点及序号
  1628 + * 上行从1开始,下行顺序续编
  1629 + */
  1630 + List<Map<String, String>> ygcLines = lsStationRouteRepository.findLineWithLineCode4Ygc(xlbm,lineVersion);
  1631 + if(ygcLines != null && ygcLines.size() > 0){
  1632 + int size = ygcLines.size();
  1633 + Map<String, String> tempMap ;
  1634 + int num = 1;
  1635 + String key;
  1636 + String lineCode = "";
  1637 + for (int i = 0; i < size; i ++){
  1638 + tempMap = ygcLines.get(i);
  1639 + if(lineCode.equals("")){
  1640 + lineCode = tempMap.get("lineCode");
  1641 + }else if(!lineCode.equals(tempMap.get("lineCode"))){
  1642 + num = 1;
  1643 + lineCode = tempMap.get("lineCode");
  1644 + }
  1645 + key = tempMap.get("lineCode") + "_"+String.valueOf(tempMap.get("directions"))
  1646 + + "_"+tempMap.get("stationCode")+ "_"+tempMap.get("stationMark");
  1647 + tempStationName2YgcNumber.put(key,num++);
  1648 + }
  1649 + }
  1650 + return tempStationName2YgcNumber;
  1651 + }
  1652 +}
src/main/java/com/bsth/util/IpUtils.java
1 -package com.bsth.util;  
2 -  
3 -import javax.servlet.http.HttpServletRequest;  
4 -  
5 -public class IpUtils {  
6 -  
7 - public static String getIpAddr(HttpServletRequest request) {  
8 - if (request == null) {  
9 - return "unknown";  
10 - }  
11 - String ip = request.getHeader("x-forwarded-for");  
12 - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
13 - ip = request.getHeader("Proxy-Client-IP");  
14 - }  
15 - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
16 - ip = request.getHeader("X-Forwarded-For");  
17 - }  
18 - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
19 - ip = request.getHeader("WL-Proxy-Client-IP");  
20 - }  
21 - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
22 - ip = request.getHeader("X-Real-IP");  
23 - }  
24 - if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {  
25 - ip = request.getRemoteAddr();  
26 - }  
27 - return ip;  
28 - }  
29 -} 1 +package com.bsth.util;
  2 +
  3 +import javax.servlet.http.HttpServletRequest;
  4 +import java.net.Inet4Address;
  5 +import java.net.InetAddress;
  6 +import java.net.NetworkInterface;
  7 +import java.util.Enumeration;
  8 +
  9 +public class IpUtils {
  10 +
  11 + public static String getIpAddr(HttpServletRequest request) {
  12 + if (request == null) {
  13 + return "unknown";
  14 + }
  15 + String ip = request.getHeader("x-forwarded-for");
  16 + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  17 + ip = request.getHeader("Proxy-Client-IP");
  18 + }
  19 + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  20 + ip = request.getHeader("X-Forwarded-For");
  21 + }
  22 + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  23 + ip = request.getHeader("WL-Proxy-Client-IP");
  24 + }
  25 + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  26 + ip = request.getHeader("X-Real-IP");
  27 + }
  28 + if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
  29 + ip = request.getRemoteAddr();
  30 + }
  31 + return ip;
  32 + }
  33 +
  34 + /**
  35 + * 获取本地IP地址
  36 + * @return
  37 + */
  38 + public static String getLocalIpAddress() {
  39 + try {
  40 + Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
  41 + InetAddress ip = null;
  42 + while (allNetInterfaces.hasMoreElements()) {
  43 + NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
  44 + if (netInterface.isLoopback() || netInterface.isVirtual() || !netInterface.isUp() || "docker0".equals(netInterface.getDisplayName())) {
  45 + continue;
  46 + } else {
  47 + Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
  48 + while (addresses.hasMoreElements()) {
  49 + ip = addresses.nextElement();
  50 + if (ip != null && ip instanceof Inet4Address) {
  51 + return ip.getHostAddress();
  52 + }
  53 + }
  54 + }
  55 + }
  56 + } catch (Exception e) {
  57 + System.err.println("IP地址获取失败" + e.toString());
  58 + }
  59 +
  60 + return "";
  61 + }
  62 +}