StationRouteServiceImpl.java 14.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
package com.bsth.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bsth.common.ResponseCode;
import com.bsth.entity.Line;
import com.bsth.entity.Station;
import com.bsth.entity.StationRoute;
import com.bsth.repository.LineRepository;
import com.bsth.repository.SectionRouteRepository;
import com.bsth.repository.StationRepository;
import com.bsth.repository.StationRouteRepository;
import com.bsth.service.StationRouteService;

/**
 * 
 * @ClassName: StationRouteServiceImpl(站点路由service业务层实现类)
 * 
 * @Extends : BaseService
 * 
 * @Description: TODO(站点路由service业务层)
 * 
 * @Author bsth@lq
 * 
 * @Date 2016年5月03日 上午9:21:17
 *
 * @Version 公交调度系统BS版 0.1
 * 
 */

@Service
public class StationRouteServiceImpl extends BaseServiceImpl<StationRoute, Integer> implements StationRouteService{
	
	@Autowired
	private StationRouteRepository repository;
	
	@Autowired
	private SectionRouteRepository routeRepository;
	
	@Autowired
	private LineRepository lineRepository;
	
	@Autowired
	private StationRepository stationRepository;
	
	/**
	 * @Description :TODO(查询树站点与路段数据)
	 * 
	 * @param map <line.id_eq:线路ID; directions_eq:方向>
	 * 
	 * @return List<Map<String, Object>>
	 */
	@Override
	public List<Map<String, Object>> findPoints(Map<String, Object> map) {
		
		// 线路ID
		Integer line = map.get("line.id_eq").equals("") ? null : Integer.parseInt(map.get("line.id_eq").toString());
		
		// 方向
		Integer directions = map.get("directions_eq").equals("") ? null : Integer.parseInt(map.get("directions_eq").toString());
		
		// 查询站点
		List<Object[]> stationList =  repository.findPoints(line, directions);
		
		// 查询路段
		List<Object[]> sectionList = routeRepository.getSectionRoute(line, directions);
		
		return treeListMap(stationList,sectionList);
	}
	
	public List<Map<String, Object>> treeListMap(List<Object[]> stationList,List<Object[]> sectionList) {
		
		List<Map<String, Object>> resultList= new ArrayList<Map<String, Object>>();
		
		// 站点孩子节点
		List<Map<String, Object>> staitonChildren= new ArrayList<Map<String, Object>>();
		
		if(stationList.size()>0) {
			
			for(int i = 0 ; i < stationList.size(); i++) {
				
				Map<String, Object> tempM = new HashMap<String, Object>();
				
				// 站点路由ID
				tempM.put("stationRouteId", stationList.get(i)[0]);
				
				// 站点路由线路ID
				tempM.put("stationRouteLine", stationList.get(i)[1]);
				
				// 站点路由站点ID
				tempM.put("stationRouteStation", stationList.get(i)[2]);
				 
				// 站点路由站点名称
				tempM.put("stationRouteStationName", stationList.get(i)[3]);
				 
				// 站点路由站点序号
				tempM.put("stationRouteStationRouteCode", stationList.get(i)[4]);
				 
				// 站点路由线路编码
				tempM.put("stationRouteLineCode", stationList.get(i)[5]);
				
				// 站点路由站点类型
				tempM.put("stationRouteStationMark", stationList.get(i)[6]);
				
				// 站点路由出站的序号
				tempM.put("stationRouteOutStationNmber", stationList.get(i)[7]);
				
				//  站点路由站点方向
				tempM.put("stationRouteDirections", stationList.get(i)[8]);
				
				//  站点路由站点到站距离
				tempM.put("stationRouteDistances", stationList.get(i)[9]);
				
				// 站点路由到站时间
				tempM.put("stationRouteToTime", stationList.get(i)[10]);
				
				// 站点路由站点首班时间
				tempM.put("stationRouteFirstTime", stationList.get(i)[11]);
				
				// 站点路由站点末班时间
				tempM.put("stationRouteEndTime", stationList.get(i)[12]);
				
				// 站点路由站点说明
				tempM.put("stationRouteDescriptions", stationList.get(i)[13]);
				
				// 站点路由版本
				tempM.put("stationRouteVersions", stationList.get(i)[14]);
				
				// 站点ID
				tempM.put("stationId", stationList.get(i)[15]);
				
				// 站点编码
				tempM.put("stationStationCod", stationList.get(i)[16]);
				
				// 站点名称
				tempM.put("stationStationName", stationList.get(i)[17]);
				
				// 路段编码
				tempM.put("stationRoadCoding", stationList.get(i)[18]);
				
				//  原坐标类型
				tempM.put("stationDbType", stationList.get(i)[19]);
				
				// 中心点(百度坐标)
				tempM.put("stationBJwpoints", stationList.get(i)[20]);
				
				// 中心点(WGS经度)
				tempM.put("stationGLonx", stationList.get(i)[21]);
				
				// 中心点(WGS纬度)
				tempM.put("stationGLaty", stationList.get(i)[22]);
				
				// 城建坐标x
				tempM.put("stationx", stationList.get(i)[23]);
				
				// 城建坐标y
				tempM.put("stationy", stationList.get(i)[24]);
				
				// 站点图形类型
				tempM.put("stationShapesType", stationList.get(i)[25]);
				
				// 站点圆半径
				tempM.put("stationRadius", stationList.get(i)[26]);
				
				// 站点图形WGS坐标
				tempM.put("stationGPolygonGrid", stationList.get(i)[27]);
				
				// 站点图形百度坐标
				tempM.put("stationBPolygonGrid", stationList.get(i)[28]);
				
				// 是否撤销
				tempM.put("stationDestroy", stationList.get(i)[29]);
				
				// 站点版本
				tempM.put("stationVersions", stationList.get(i)[30]);
				
				// 站点说明
				tempM.put("stationDescriptions", stationList.get(i)[31]);
				
				tempM.put("name", stationList.get(i)[17]);
				
				tempM.put("text", stationList.get(i)[17]);
				 
				tempM.put("icon", "fa fa-bus");
				
				tempM.put("pId", 200);
				
				tempM.put("id", i+1);
				
				tempM.put("groupType", "3");
				
				tempM.put("chaildredType", "station");
				
				tempM.put("enable", true);
				
				staitonChildren.add(tempM);
			}
		}
		
		// 路段孩子节点
		List<Map<String, Object>> sectionChildren = new ArrayList<Map<String, Object>>();
		
		if(sectionList.size()>0) {
			
			for(int i = 0 ; i<sectionList.size() ; i++){
				
				Map<String, Object> tempM = new HashMap<String, Object>();
				
				// 路段路由ID
				tempM.put("sectionrouteId",sectionList.get(i)[0]);
				
				// 路段路由线路ID
				tempM.put("sectionrouteLine",sectionList.get(i)[1]);
				
				// 路段路由线路编码
				tempM.put("sectionrouteLineCode",sectionList.get(i)[2]);
				
				// 路段路由路段ID
				tempM.put("sectionrouteSection",sectionList.get(i)[3]);
				
				// 路段路由路段编码
				tempM.put("sectionrouteSectionCode",sectionList.get(i)[4]);
				
				tempM.put("sectionrouteCode",sectionList.get(i)[5]);
				
				tempM.put("sectionrouteDirections",sectionList.get(i)[6]);
				
				// 路段ID
				tempM.put("sectionId",sectionList.get(i)[7]);
				
				// 路段编码
				tempM.put("sectionCode",sectionList.get(i)[8]);
				
				// 路段名称
				tempM.put("sectionName",sectionList.get(i)[9]);
				
				// 道路编码
				tempM.put("sectionCrosesRoad",sectionList.get(i)[10]);
				
				// 终点站
				tempM.put("sectionEndNode",sectionList.get(i)[11]);
				
				// 起始节点
				tempM.put("sectionStartNode",sectionList.get(i)[12]);
				
				// 中间节点
				tempM.put("sectionMiddleNode",sectionList.get(i)[13]);
				
				// 路段类型
				tempM.put("sectionType",sectionList.get(i)[14]);
				
				// 路段折线图形城建坐标
				tempM.put("sectionCsectionVector",sectionList.get(i)[15]);
				
				// 路段折线图形百度坐标
				tempM.put("sectionBsectionVector",sectionList.get(i)[16]);
				
				// 路段折线图形WGS坐标
				tempM.put("sectionGsectionVector",sectionList.get(i)[17]);
				
				// 道路编码
				tempM.put("sectionRoadCoding",sectionList.get(i)[18]);
				
				// 路段距离
				tempM.put("sectionDistance",sectionList.get(i)[19]);
				
				// 路段时间
				tempM.put("sectionTime",sectionList.get(i)[20]);
				
				// 路段原坐标类型
				tempM.put("sectiondbType",sectionList.get(i)[21]);
				
				// 限速
				tempM.put("sectionSpeedLimet",sectionList.get(i)[22]);
				
				tempM.put("name", sectionList.get(i)[9]);
				
				tempM.put("text", sectionList.get(i)[9]);
				 
				tempM.put("icon", null);
				
				tempM.put("pId", 300);
				
				tempM.put("id", (i+1)*1000);
				
				tempM.put("groupType", "3");
				
				tempM.put("chaildredType", "section");
				
				tempM.put("enable", true);
				
				sectionChildren.add(tempM);
				
			}
		}
		
		// 站点与路段孩子节点
		List<Map<String, Object>> childrenTwo = new ArrayList<Map<String, Object>>();
		
		// 站点节点
		Map<String, Object> childrenStationMap = new HashMap<String, Object>();
		childrenStationMap.put("children", staitonChildren);
		childrenStationMap.put("container", "pjax-container");
		childrenStationMap.put("enable", true);
		childrenStationMap.put("groupType", "2");
		childrenStationMap.put("chaildredType", null);

		childrenStationMap.put("icon", null);
		childrenStationMap.put("id", 200);
		childrenStationMap.put("name", "站点");
		childrenStationMap.put("pId", 100);
		childrenStationMap.put("text", "站点");
		childrenTwo.add(childrenStationMap);
		
		// 路段节点
		Map<String, Object> childrenSectionMap = new HashMap<String, Object>();
		childrenSectionMap.put("children", sectionChildren);
		childrenSectionMap.put("container", "pjax-container");
		childrenSectionMap.put("enable", true);
		childrenSectionMap.put("groupType", "2");
		childrenSectionMap.put("chaildredType", null);
		childrenSectionMap.put("icon", null);
		childrenSectionMap.put("id", 300);
		childrenSectionMap.put("name", "路段");
		childrenSectionMap.put("pId", 100);
		childrenSectionMap.put("text", "路段");
		childrenTwo.add(childrenSectionMap);
		
		// 站点与路段
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("children", childrenTwo);
		resultMap.put("container", "pjax-container");
		resultMap.put("enable", true);
		resultMap.put("groupType", "1");
		resultMap.put("chaildredType", null);
		resultMap.put("icon", null);
		resultMap.put("id", 100);
		resultMap.put("name", "站点与路段");
		resultMap.put("pId", null);
		resultMap.put("text", "站点与路段");
		resultList.add(resultMap);
		
		return resultList;
	}
	
	@Override
	public Map<String, Object> systemQuote(Map<String, Object> map) {
		Map<String, Object> resultmap = new HashMap<>();
		try{
			
			StationRoute route = new StationRoute();
			
			Integer lineId = map.get("lineId").equals("") ? null : Integer.parseInt(map.get("lineId").toString());
			
			Integer stationId = map.get("stationId").equals("") ? null : Integer.parseInt(map.get("stationId").toString());
			
			Line line = lineRepository.findOne(lineId);
			
			Station station = stationRepository.findOne(stationId);
			
			route.setLine(line);
			
			route.setStation(station);
			
			//baseRepository.save(t);
			resultmap.put("status", ResponseCode.SUCCESS);
		}catch(Exception e){
			resultmap.put("status", ResponseCode.ERROR);
			logger.error("save erro.", e);
		}
		return resultmap;
	}
	
	/**
	 * @Description :TODO(查询线路某方向下的站点序号与类型)
	 * 
	 * @param map <lineId:线路ID; direction:方向;stationRouteCode:站点编码>
	 * 
	 * @return List<Map<String, Object>> 
	 */
	@Override
	public List<Map<String, Object>> findUpStationRouteCode(Map<String, Object> map) {
		
		Integer lineId = map.get("lineId").equals("") ? null : Integer.parseInt(map.get("lineId").toString());
		
		Integer direction = map.get("direction").equals("") ? null : Integer.parseInt(map.get("direction").toString());
		
		Integer stationRouteCode = map.get("stationRouteCode").equals("") ? null : Integer.parseInt(map.get("stationRouteCode").toString());
		
		List<Object[]> reslutList = repository.findUpStationRouteCode(lineId, direction, stationRouteCode);
		
		List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
		
		if(reslutList.size()>0) {
			
			for(int i = 0 ; i <reslutList.size() ;i++){
				Map<String, Object> tempM = new HashMap<String, Object>();
				tempM.put("stationRouteCode", reslutList.get(i)[0]);
				tempM.put("stationRouteMarke", reslutList.get(i)[1]);
				
				list.add(tempM);
				
			}
			
		}
		
		return list;
	}
	
	
	 /**
	  * @Description :TODO(查询线路某方向下所有站点的中心百度坐标)
	  * 
	  * @param map <lineId:线路ID; direction:方向>
	  * 
	  * @return List<Map<String, Object>> 
	  */
	@Override
	public List<Map<String, Object>> getStationRouteCenterPoints(Map<String, Object> map) {
		
		List<Map<String, Object>> resultList = new ArrayList<Map<String,Object>>();
		
		// 线路ID
		Integer lineId = map.get("lineId").equals("") ? null : Integer.parseInt(map.get("lineId").toString());
		
		// 方向
		Integer direction = map.get("direction").equals("") ? null : Integer.parseInt(map.get("direction").toString());
		
		List<Object[]> list = repository.getSelectStationRouteCenterPoints(lineId, direction);
		
		if(list.size()>0) {
			
			for(int i = 0;i<list.size();i++) {
				
				Map<String, Object> tempM = new HashMap<String,Object>();
				
				tempM.put("bJwpoints", list.get(i));
				
				resultList.add(tempM);
				
			}
			
		}
		
		return resultList;
	}
	
	/**
	 * @Description :TODO(撤销站点)
	 * 
	 * @param map <lineId:线路ID; destroy:是否撤销(0:否;1:是)>
	 * 
	 * @return Map<String, Object> <SUCCESS ; ERROR>
	 */
	@Override
	public Map<String, Object> stationRouteIsDestroy(Map<String, Object> map) {
		Map<String, Object> resultMap = new HashMap<String,Object>();
		
		try {
			
			Integer stationRouteId = map.get("stationRouteId").equals("") ? 0 : Integer.parseInt(map.get("stationRouteId").toString());
			
			Integer destroy = map.get("destroy").equals("") ? 0 : Integer.parseInt(map.get("destroy").toString());
			
			repository.stationRouteIsDestroyUpd(stationRouteId, destroy);
			
			resultMap.put("status", ResponseCode.SUCCESS);
			
		} catch (Exception e) {
			
			resultMap.put("status", ResponseCode.ERROR);
			
			logger.error("save erro.", e);
			
		}
		
		return resultMap;
	}
}