Commit e9ab20327f08038f36af0a34800d7bc306c7282b

Authored by zlz
1 parent 5e9579e6

批量上传线路站级数据

src/main/java/com/bsth/controller/schedule/TrafficManageController.java
@@ -30,6 +30,15 @@ public class TrafficManageController { @@ -30,6 +30,15 @@ public class TrafficManageController {
30 } 30 }
31 } 31 }
32 32
  33 + @RequestMapping(value = "/setXLByInUse", method = RequestMethod.GET)
  34 + public String setXLByInUse(@RequestParam("inUse") String inUse) throws Exception {
  35 + try {
  36 + return trManageService.setXLByInUse(inUse);
  37 + } catch (Exception exp) {
  38 + throw new Exception(exp.getCause());
  39 + }
  40 + }
  41 +
33 @RequestMapping(value = "/setCL", method = RequestMethod.GET) 42 @RequestMapping(value = "/setCL", method = RequestMethod.GET)
34 public String setCL() throws Exception { 43 public String setCL() throws Exception {
35 try { 44 try {
@@ -57,6 +66,15 @@ public class TrafficManageController { @@ -57,6 +66,15 @@ public class TrafficManageController {
57 } 66 }
58 } 67 }
59 68
  69 + @RequestMapping(value = "/setLDByDate", method = RequestMethod.GET)
  70 + public String setLDByDate(@RequestParam("theDate") String theDate) throws Exception {
  71 + try {
  72 + return trManageService.setLD(theDate);
  73 + } catch (Exception exp) {
  74 + throw new Exception(exp.getCause());
  75 + }
  76 + }
  77 +
60 @RequestMapping(value = "/setLDFile", method = RequestMethod.GET) 78 @RequestMapping(value = "/setLDFile", method = RequestMethod.GET)
61 public String setLDFile() throws Exception { 79 public String setLDFile() throws Exception {
62 try { 80 try {
src/main/java/com/bsth/service/TrafficManageService.java
1 package com.bsth.service; 1 package com.bsth.service;
2 2
3 -import java.util.Map;  
4 -  
5 /** 3 /**
6 * 4 *
7 * @Interface: LineService(线路service业务层实现接口) 5 * @Interface: LineService(线路service业务层实现接口)
@@ -27,6 +25,13 @@ public interface TrafficManageService { @@ -27,6 +25,13 @@ public interface TrafficManageService {
27 String setXL(String ids); 25 String setXL(String ids);
28 26
29 /** 27 /**
  28 + * 上传线路信息
  29 + *
  30 + * @return 调用接口返回信息
  31 + */
  32 + String setXLByInUse(String ids);
  33 +
  34 + /**
30 * 上传车辆信息 35 * 上传车辆信息
31 * 36 *
32 * @return 调用接口返回信息 37 * @return 调用接口返回信息
@@ -65,6 +70,8 @@ public interface TrafficManageService { @@ -65,6 +70,8 @@ public interface TrafficManageService {
65 */ 70 */
66 String setJHBC(); 71 String setJHBC();
67 72
  73 + String setLD(String theDate);
  74 +
68 String setLD(); 75 String setLD();
69 76
70 String setLDFile(); 77 String setLDFile();
src/main/java/com/bsth/service/impl/TrafficManageServiceImpl.java
@@ -19,7 +19,6 @@ import com.bsth.service.TrafficManageService; @@ -19,7 +19,6 @@ import com.bsth.service.TrafficManageService;
19 import com.bsth.service.traffic.YgcBasicDataService; 19 import com.bsth.service.traffic.YgcBasicDataService;
20 import com.bsth.util.TimeUtils; 20 import com.bsth.util.TimeUtils;
21 import com.bsth.util.db.DBUtils_MS; 21 import com.bsth.util.db.DBUtils_MS;
22 -import com.bsth.webService.trafficManage.geotool.services.InternalPortType;  
23 import com.bsth.webService.trafficManage.org.tempuri.Results; 22 import com.bsth.webService.trafficManage.org.tempuri.Results;
24 import com.bsth.webService.trafficManage.org.tempuri.WebServiceLocator; 23 import com.bsth.webService.trafficManage.org.tempuri.WebServiceLocator;
25 import com.bsth.webService.trafficManage.org.tempuri.WebServiceSoap; 24 import com.bsth.webService.trafficManage.org.tempuri.WebServiceSoap;
@@ -40,6 +39,7 @@ import java.sql.ResultSet; @@ -40,6 +39,7 @@ import java.sql.ResultSet;
40 import java.text.DecimalFormat; 39 import java.text.DecimalFormat;
41 import java.text.SimpleDateFormat; 40 import java.text.SimpleDateFormat;
42 import java.util.*; 41 import java.util.*;
  42 +import java.util.regex.Matcher;
43 import java.util.regex.Pattern; 43 import java.util.regex.Pattern;
44 44
45 /** 45 /**
@@ -67,10 +67,16 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -67,10 +67,16 @@ public class TrafficManageServiceImpl implements TrafficManageService{
67 @Autowired 67 @Autowired
68 private LineRepository lineRepository; 68 private LineRepository lineRepository;
69 69
  70 + @Autowired
  71 + private LineInformationRepository lineInformationRepository;
  72 +
70 // 站点路由repository 73 // 站点路由repository
71 @Autowired 74 @Autowired
72 private StationRouteRepository stationRouteRepository; 75 private StationRouteRepository stationRouteRepository;
73 76
  77 + @Autowired
  78 + private SectionRepository sectionRepository;
  79 +
74 // 车辆repository 80 // 车辆repository
75 @Autowired 81 @Autowired
76 private CarsRepository carsRepository; 82 private CarsRepository carsRepository;
@@ -104,8 +110,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -104,8 +110,8 @@ public class TrafficManageServiceImpl implements TrafficManageService{
104 private YgcBasicDataService ygcBasicDataService; 110 private YgcBasicDataService ygcBasicDataService;
105 111
106 112
107 - // 运管处接口  
108 - private InternalPortType portType = null;//new Internal().getInternalHttpSoap11Endpoint(); 113 + // 运管处上传接口
  114 + private com.bsth.webService.trafficManage.up.org.tempuri.WebServiceSoap webServiceSoapUp;
109 private WebServiceSoap ssop ; 115 private WebServiceSoap ssop ;
110 { 116 {
111 try { 117 try {
@@ -127,6 +133,23 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -127,6 +133,23 @@ public class TrafficManageServiceImpl implements TrafficManageService{
127 private final String userNameOther = "user"; 133 private final String userNameOther = "user";
128 // 密码 134 // 密码
129 private final String passwordOther = "user"; 135 private final String passwordOther = "user";
  136 +
  137 + // 用户名
  138 + private final String userNameUp = "user";
  139 + // 密码
  140 + private final String passwordUp = "user";
  141 +
  142 + private synchronized com.bsth.webService.trafficManage.up.org.tempuri.WebServiceSoap getWebServiceSoapUp(){
  143 + try {
  144 + if(webServiceSoapUp == null){
  145 + webServiceSoapUp = new com.bsth.webService.trafficManage.up.org.tempuri.WebServiceLocator().getWebServiceSoap();
  146 + }
  147 + }catch (Exception e){
  148 + e.printStackTrace();
  149 + }finally {
  150 + return webServiceSoapUp;
  151 + }
  152 + }
130 /** 153 /**
131 * 上传线路信息 154 * 上传线路信息
132 */ 155 */
@@ -137,26 +160,44 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -137,26 +160,44 @@ public class TrafficManageServiceImpl implements TrafficManageService{
137 String[] idArray = ids.split(","); 160 String[] idArray = ids.split(",");
138 try { 161 try {
139 for (String id : idArray) { 162 for (String id : idArray) {
  163 + if(id == null || id.trim().equals("")){
  164 + continue;
  165 + }
140 Map<String,Object> map = new HashMap<>(); 166 Map<String,Object> map = new HashMap<>();
141 map.put("lineCode_eq", id); 167 map.put("lineCode_eq", id);
142 Line line ; 168 Line line ;
  169 + LineInformation lineInformation;
143 line = lineRepository.findOne(new CustomerSpecs<Line>(map)); 170 line = lineRepository.findOne(new CustomerSpecs<Line>(map));
144 if(line == null){ 171 if(line == null){
145 continue; 172 continue;
146 } 173 }
147 List<StationRoute> upStationsList ;// 上行站点路由集 174 List<StationRoute> upStationsList ;// 上行站点路由集
148 - List<StationRoute> downStationsList = null;// 下行站点路由集  
149 - sBuffer.append("<Data>");  
150 - sBuffer.append("<RequestOrg>上海巴士拓华科技发展有限公司</RequestOrg>");  
151 - sBuffer.append("<DataList>"); 175 + List<StationRoute> downStationsList;// 下行站点路由集
  176 + List<Object[]> downPointList;// 下行站点集
  177 + List<Object[]> upPointList;// 上行站点集
  178 + sBuffer.append("<XLs>");
  179 + sBuffer.append("<XL>");
152 if(BasicData.lineId2ShangHaiCodeMap.get(line.getId()) == null){ 180 if(BasicData.lineId2ShangHaiCodeMap.get(line.getId()) == null){
153 return result; 181 return result;
154 } 182 }
155 - sBuffer.append("<LINE_ID>").append(line.getId()).append("</LINE_ID>");  
156 - sBuffer.append("<LINE_CODE>").append(BasicData.lineId2ShangHaiCodeMap.get(line.getId())).append("</LINE_CODE>");  
157 - sBuffer.append("<LINE_NAME>").append(line.getName()).append("</LINE_NAME>"); 183 + map = new HashMap<>();
  184 + map.put("line.id_eq",line.getId());
  185 + lineInformation = lineInformationRepository.findOne(new CustomerSpecs<LineInformation>(map));
  186 + if(lineInformation == null){
  187 + continue;
  188 + }
  189 + sBuffer.append("<XLBM>").append(BasicData.lineId2ShangHaiCodeMap.get(line.getId())).append("</XLBM>");
  190 + sBuffer.append("<XLMC>").append(line.getName()).append("</XLMC>");
  191 + sBuffer.append("<QDZ>").append(line.getStartStationName()).append("</QDZ>");
  192 + sBuffer.append("<ZDZ>").append(line.getEndStationName()).append("</ZDZ>");
  193 + sBuffer.append("<QZLC>").append(lineInformation.getUpMileage()).append("</QZLC>");
  194 + sBuffer.append("<ZQLC>").append(lineInformation.getDownMileage()).append("</ZQLC>");
  195 + sBuffer.append("<XLGH>").append(line.getLinePlayType()).append("</XLGH>");
  196 + sBuffer.append("<UPDATE_DATE>").append(sdfnyr.format(new Date())).append("</UPDATE_DATE>");
  197 +
158 // 循环添加站点信息 198 // 循环添加站点信息
159 - sBuffer.append("<LineStationList>"); 199 + sBuffer.append("<StationList>");
  200 +
160 // 先查上行 201 // 先查上行
161 upStationsList = stationRouteRepository.findByLine(line.getLineCode(), 0); 202 upStationsList = stationRouteRepository.findByLine(line.getLineCode(), 0);
162 int startId = 1; 203 int startId = 1;
@@ -167,25 +208,23 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -167,25 +208,23 @@ public class TrafficManageServiceImpl implements TrafficManageService{
167 downStationsList = stationRouteRepository.findByLine(line.getLineCode(), 1); 208 downStationsList = stationRouteRepository.findByLine(line.getLineCode(), 1);
168 packagStationXml(downStationsList, sBuffer, startId); 209 packagStationXml(downStationsList, sBuffer, startId);
169 } 210 }
170 - sBuffer.append("</LineStationList>"); 211 + sBuffer.append("</StationList>");
171 212
172 // 循环添加站点点位信息 213 // 循环添加站点点位信息
173 sBuffer.append("<LinePointList>"); 214 sBuffer.append("<LinePointList>");
  215 + upPointList = sectionRepository.getSectionDirByLineId(line.getId(),0);
174 startId = 1; 216 startId = 1;
175 - startId = packagStationPointXml(upStationsList, sBuffer, startId); 217 + startId = packagStationPointXml(upPointList, sBuffer, startId);
176 // 环线不查下行 218 // 环线不查下行
177 if(line.getLinePlayType() != 1){ 219 if(line.getLinePlayType() != 1){
178 - packagStationPointXml(downStationsList, sBuffer, startId); 220 + downPointList = sectionRepository.getSectionDirByLineId(line.getId(),1);
  221 + packagStationPointXml(downPointList, sBuffer, startId);
179 } 222 }
180 sBuffer.append("</LinePointList>"); 223 sBuffer.append("</LinePointList>");
181 - sBuffer.append("</DataList>");  
182 - sBuffer.append("</Data>"); 224 + sBuffer.append("</XL>");
  225 + sBuffer.append("</XLs>");
183 // 调用上传方法 226 // 调用上传方法
184 - result = ygcBasicDataService.invokeMethod("UpdateBusLineStation",sBuffer.toString());  
185 - String str = "ReturnCode";  
186 - // 解析返回值  
187 - result = result.substring(result.indexOf(str)+str.length()+1,result.lastIndexOf(str)-2);  
188 - if(result.equals("1")){ 227 + if(getWebServiceSoapUp().setXL(userNameUp,passwordUp,sBuffer.toString()).isSuccess()){
189 result = "success"; 228 result = "success";
190 }else{ 229 }else{
191 result = "failure"; 230 result = "failure";
@@ -201,6 +240,36 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -201,6 +240,36 @@ public class TrafficManageServiceImpl implements TrafficManageService{
201 } 240 }
202 241
203 /** 242 /**
  243 + * 上传线路信息(按in_use上传)
  244 + */
  245 + @Override
  246 + public String setXLByInUse(String inUse) {
  247 + StringBuffer result = new StringBuffer();
  248 + try {
  249 + Map<String,Object> map = new HashMap<>();
  250 + if(inUse != null && inUse.equals("1")){
  251 + map.put("inUse_eq", inUse);
  252 + }
  253 + List<Line> lines ;
  254 + Line line;
  255 + lines = lineRepository.findAll(new CustomerSpecs<Line>(map));
  256 + if(lines != null && lines.size() > 0){
  257 + for(int i = 0 ; i < lines.size() ; i ++){
  258 + line = lines.get(i);
  259 + if(line != null && line.getId() != null){
  260 + result.append(line.getLineCode()).append(":").append(setXL(line.getLineCode())).append(";");
  261 + }
  262 + }
  263 + }
  264 + } catch (Exception e) {
  265 + result.append("failure");
  266 + logger.error("setXLByInUse:",e);
  267 + e.printStackTrace();
  268 + }
  269 + return result.toString();
  270 + }
  271 +
  272 + /**
204 * 上传车辆信息 273 * 上传车辆信息
205 */ 274 */
206 @Override 275 @Override
@@ -279,14 +348,30 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -279,14 +348,30 @@ public class TrafficManageServiceImpl implements TrafficManageService{
279 } 348 }
280 349
281 /** 350 /**
  351 + * 上传路单 指定日期 yyyy-MM-dd
  352 + * @param theDate
  353 + * @return
  354 + */
  355 + public String setLD(String theDate){
  356 + return uploadLD(theDate);
  357 + }
  358 +
  359 + /**
  360 + * 上传路单 上传前一天的路单
  361 + * @return
  362 + */
  363 + public String setLD(){
  364 + return uploadLD(null);
  365 + }
  366 + /**
282 * 上传路单 367 * 上传路单
283 * @return 上传成功标识 368 * @return 上传成功标识
284 */ 369 */
285 - public String setLD(){ 370 + private String uploadLD(String theDate){
286 String result = "failure"; 371 String result = "failure";
287 Line line; 372 Line line;
288 // 取昨天 的日期 373 // 取昨天 的日期
289 - String date = sdfnyr.format(DateUtils.addDays(new Date(), -1)); 374 + String date = theDate == null ?sdfnyr.format(DateUtils.addDays(new Date(), -1)) : theDate;
290 StringBuffer sf = new StringBuffer(); 375 StringBuffer sf = new StringBuffer();
291 String str; 376 String str;
292 try { 377 try {
@@ -710,7 +795,7 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -710,7 +795,7 @@ public class TrafficManageServiceImpl implements TrafficManageService{
710 // 判断XML是否以</BCList>结尾,如果不是,则加上 795 // 判断XML是否以</BCList>结尾,如果不是,则加上
711 String regex = "^*</JHBC>$"; 796 String regex = "^*</JHBC>$";
712 Pattern p = Pattern.compile(regex); 797 Pattern p = Pattern.compile(regex);
713 - java.util.regex.Matcher m = p.matcher(sBuffer); 798 + Matcher m = p.matcher(sBuffer);
714 boolean isEndWithTrueFlag = false; 799 boolean isEndWithTrueFlag = false;
715 while (m.find()) { 800 while (m.find()) {
716 isEndWithTrueFlag = true; 801 isEndWithTrueFlag = true;
@@ -1146,15 +1231,15 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -1146,15 +1231,15 @@ public class TrafficManageServiceImpl implements TrafficManageService{
1146 } 1231 }
1147 paraMap = packageYgcStationNumParam(srRoute,null); 1232 paraMap = packageYgcStationNumParam(srRoute,null);
1148 sBuffer.append("<Station>"); 1233 sBuffer.append("<Station>");
1149 - sBuffer.append("<STATION_ID>").append(getYgcStationNumByLineCodeAndDirectionAndStationName(paraMap)).append("</STATION_ID>");  
1150 - sBuffer.append("<UPDDOWN>").append(srRoute.getDirections()).append("</UPDDOWN>");  
1151 - sBuffer.append("<STATION_NO>").append(i).append("</STATION_NO>");  
1152 - sBuffer.append("<STATION_CODE>").append(srRoute.getStationCode()).append("</STATION_CODE>");  
1153 - sBuffer.append("<STATION_NAME>").append(srRoute.getStationName()).append("</STATION_NAME>");  
1154 - sBuffer.append("<STATION_LON>").append(srRoute.getStation().getgLonx()).append("</STATION_LON>");  
1155 - sBuffer.append("<STATION_LAT>").append(srRoute.getStation().getgLaty()).append("</STATION_LAT>");  
1156 - sBuffer.append("<STATION_TYPE>").append(zdlx).append("</STATION_TYPE>");  
1157 - sBuffer.append("<STATION_DISTANCE>").append(srRoute.getDistances()).append("</STATION_DISTANCE>"); 1234 + sBuffer.append("<ZDXH>").append(getYgcStationNumByLineCodeAndDirectionAndStationName(paraMap)).append("</ZDXH>");
  1235 + sBuffer.append("<SXX>").append(srRoute.getDirections()).append("</SXX>");
  1236 + sBuffer.append("<ZDMC>").append(srRoute.getStationName()).append("</ZDMC>");
  1237 + sBuffer.append("<ZDBM>").append(srRoute.getStationCode()).append("</ZDBM>");
  1238 + sBuffer.append("<ZDJD>").append(srRoute.getStation().getgLonx()).append("</ZDJD>");
  1239 + sBuffer.append("<ZDWD>").append(srRoute.getStation().getgLaty()).append("</ZDWD>");
  1240 + sBuffer.append("<ZZ>").append(srRoute.getStation().getAddr() == null ? "" : srRoute.getStation().getAddr()).append("</ZZ>");
  1241 + sBuffer.append("<ZDLX>").append(zdlx).append("</ZDLX>");
  1242 + sBuffer.append("<ZJLC>").append(srRoute.getDistances()).append("</ZJLC>");
1158 sBuffer.append("</Station>"); 1243 sBuffer.append("</Station>");
1159 startId++; 1244 startId++;
1160 } 1245 }
@@ -1162,35 +1247,37 @@ public class TrafficManageServiceImpl implements TrafficManageService{ @@ -1162,35 +1247,37 @@ public class TrafficManageServiceImpl implements TrafficManageService{
1162 } 1247 }
1163 1248
1164 /** 1249 /**
1165 - * @param stationsList 站点路由 1250 + * @param pointList 站点点位
1166 * @param sBuffer sBuffer 1251 * @param sBuffer sBuffer
1167 * @param startId 站点序号起始ID 1252 * @param startId 站点序号起始ID
1168 * 1253 *
1169 * @return 站点序号累加后的ID 1254 * @return 站点序号累加后的ID
1170 */ 1255 */
1171 - private int packagStationPointXml(List<StationRoute> stationsList,StringBuffer sBuffer,int startId){  
1172 - int size = stationsList.size();  
1173 - StationRoute srRoute;  
1174 - HashMap<String,String> paraMap;  
1175 - String zdlx ;// 站点类型:0:起点站、1:终点站、2:中途站 1256 + private int packagStationPointXml(List<Object[]> pointList,StringBuffer sBuffer,int startId){
  1257 + int size = pointList.size();
  1258 + Object[] objs;
  1259 + String bsection,dir,section;
  1260 + String[] sections ;
1176 for (int i = 0; i < size; i++) { 1261 for (int i = 0; i < size; i++) {
1177 - srRoute = stationsList.get(i);  
1178 - zdlx = srRoute.getStationMark();  
1179 - if(zdlx.equals("B")){  
1180 - zdlx = "0";  
1181 - }else if(zdlx.equals("E")){  
1182 - zdlx = "1";  
1183 - }else{  
1184 - zdlx = "2"; 1262 + objs = pointList.get(i);
  1263 + bsection = objs[0]+"";
  1264 + dir = objs[1]+"";
  1265 + // 取括号内的内容
  1266 + Pattern pattern = Pattern.compile("(?<=\\()(.+?)(?=\\))");
  1267 + Matcher matcher = pattern.matcher(bsection);
  1268 + if(matcher.find()){
  1269 + sections = matcher.group().split(",");
  1270 + for (int j = 0 ; j < sections.length ; j ++){
  1271 + section = sections[j];
  1272 + sBuffer.append("<LinePoint>");
  1273 + sBuffer.append("<ZDXH>").append(startId).append("</ZDXH>");
  1274 + sBuffer.append("<SXX>").append(dir).append("</SXX>");
  1275 + sBuffer.append("<ZDJD>").append(section.split(" ")[0]).append("</ZDJD>");
  1276 + sBuffer.append("<ZDWD>").append(section.split(" ")[1]).append("</ZDWD>");
  1277 + sBuffer.append("</LinePoint>");
  1278 + startId++;
  1279 + }
1185 } 1280 }
1186 - paraMap = packageYgcStationNumParam(srRoute,null);  
1187 - sBuffer.append("<Point>");  
1188 - sBuffer.append("<POINT_ID>").append(getYgcStationNumByLineCodeAndDirectionAndStationName(paraMap)).append("</POINT_ID>");  
1189 - sBuffer.append("<UPDDOWN>").append(srRoute.getDirections()).append("</UPDDOWN>");  
1190 - sBuffer.append("<POINTLON>").append(srRoute.getStation().getgLonx()).append("</POINTLON>");  
1191 - sBuffer.append("<POINTLAT>").append(srRoute.getStation().getgLaty()).append("</POINTLAT>");  
1192 - sBuffer.append("</Point>");  
1193 - startId++;  
1194 } 1281 }
1195 return startId; 1282 return startId;
1196 } 1283 }