StationRouteServiceImpl.java 12.5 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
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 antlr.collections.impl.LList;

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;
	
	@Override
	public List<Map<String, Object>> findPoints(Map<String, Object> map) {
		
		String lineStr = map.get("line.id_eq").equals("") ? "0" : map.get("line.id_eq").toString();
		
		String directionsStr = map.get("directions_eq").equals("") ? "0" : map.get("directions_eq").toString();
		
		int line = Integer.parseInt(lineStr);
		
		int directions= Integer.parseInt(directionsStr);
		 
		List<Object[]> stationList =  repository.findPoints(line, directions);
		
		List<Object[]> sectionList = routeRepository.getSectionRoute(line, directions);
		
		
		List<Map<String, Object>> resultList= new ArrayList<Map<String, Object>>();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		
		List<Map<String, Object>> childrenTwo = new ArrayList<Map<String, Object>>();
		Map<String, Object> childrenStationMap = new HashMap<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>();
				
				// stationRoute.id
				tempM.put("stationRouteId", stationList.get(i)[0]);
				
				// stationRoute.line
				tempM.put("stationRouteLine", stationList.get(i)[1]);
				
				// stationRoute.station
				tempM.put("stationRouteStation", stationList.get(i)[2]);
				 
				// stationRoute.stationName
				tempM.put("stationRouteStationName", stationList.get(i)[3]);
				 
				// stationRoute.stationRouteCode
				tempM.put("stationRouteStationRouteCode", stationList.get(i)[4]);
				 
				// stationRoute.lineCode
				tempM.put("stationRouteLineCode", stationList.get(i)[5]);
				
				// stationRoute.stationMark
				tempM.put("stationRouteStationMark", stationList.get(i)[6]);
				
				// stationRoute.outStationNmber
				tempM.put("stationRouteOutStationNmber", stationList.get(i)[7]);
				
				// stationRoute.directions
				tempM.put("stationRouteDirections", stationList.get(i)[8]);
				
				// stationRoute.distances
				tempM.put("stationRouteDistances", stationList.get(i)[9]);
				
				// stationRoute.toTime
				tempM.put("stationRouteToTime", stationList.get(i)[10]);
				
				// stationRoute.firstTime
				tempM.put("stationRouteFirstTime", stationList.get(i)[11]);
				
				// stationRoute.endTime
				tempM.put("stationRouteEndTime", stationList.get(i)[12]);
				
				// stationRoute.descriptions
				tempM.put("stationRouteDescriptions", stationList.get(i)[13]);
				
				// stationRoute.versions
				tempM.put("stationRouteVersions", stationList.get(i)[14]);
				
				// station.id
				tempM.put("stationId", stationList.get(i)[15]);
				
				// station.stationCod
				tempM.put("stationStationCod", stationList.get(i)[16]);
				
				// station.stationName
				tempM.put("stationStationName", stationList.get(i)[17]);
				
				// station.roadCoding
				tempM.put("stationRoadCoding", stationList.get(i)[18]);
				
				// station.dbType
				tempM.put("stationDbType", stationList.get(i)[19]);
				
				// station.bJwpoints
				tempM.put("stationBJwpoints", stationList.get(i)[20]);
				
				// station.gLonx
				tempM.put("stationGLonx", stationList.get(i)[21]);
				
				// station.gLaty
				tempM.put("stationGLaty", stationList.get(i)[22]);
				
				// station.x
				tempM.put("stationx", stationList.get(i)[23]);
				
				// station.y
				tempM.put("stationy", stationList.get(i)[24]);
				
				// station.shapesType
				tempM.put("stationShapesType", stationList.get(i)[25]);
				
				// station.radius
				tempM.put("stationRadius", stationList.get(i)[26]);
				
				// station.gPolygonGrid
				tempM.put("stationGPolygonGrid", stationList.get(i)[27]);
				
				// station.bPolygonGrid
				tempM.put("stationBPolygonGrid", stationList.get(i)[28]);
				
				// station.destroy
				tempM.put("stationDestroy", stationList.get(i)[29]);
				
				// station.versions
				tempM.put("stationVersions", stationList.get(i)[30]);
				
				// station.descriptions
				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>();
				tempM.put("sectionrouteId",sectionList.get(i)[0]);
				tempM.put("sectionrouteLine",sectionList.get(i)[1]);
				tempM.put("sectionrouteLineCode",sectionList.get(i)[2]);
				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]);
				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]);
				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);
				
			}
		}
		
		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);
		
		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;
	}

	@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;
	}

	@Override
	public List<Map<String, Object>> getStationRouteCenterPoints(Map<String, Object> map) {
		
		List<Map<String, Object>> resultList = new ArrayList<Map<String,Object>>();
		
		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;
	}

	@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;
	}

}