StationRouteServiceImpl.java 11.8 KB
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;
	}
}