StationRouteRepository.java 3.55 KB
package com.bsth.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import com.bsth.entity.StationRoute;

/**
 * 
 * @Interface: StationRouteRepository(站点路由Repository数据持久层接口)
 * 
 * @Extends : BaseRepository
 * 
 * @Description: TODO(站点路由Repository数据持久层接口)
 * 
 * @Author bsth@lq
 * 
 * @Date 2016年5月03日 上午9:21:17
 *
 * @Version 公交调度系统BS版 0.1
 * 
 */

@Repository
public interface StationRouteRepository extends BaseRepository<StationRoute, Integer> {
	
	@Query(value = "SELECT  a.`stationRoute.id`," +
						    "a.`stationRoute.line`," +
						    "a.`stationRoute.station`," +
							"a.`stationRoute.stationName`," +
							"a.`stationRoute.stationRouteCode`," +
							"a.`stationRoute.lineCode`," +
							"a.`stationRoute.stationMark`," +
							"a.`stationRoute.outStationNmber`," +
							"a.`stationRoute.directions`," +
							"a.`stationRoute.distances`," +
							"a.`stationRoute.toTime`," +
							"a.`stationRoute.firstTime`," +
							"a.`stationRoute.endTime`," +
							"a.`stationRoute.descriptions`," +
							"a.`stationRoute.versions`," +
							"b.id AS 'station.id'," +
							"b.station_cod AS 'station.stationCod'," +
							"b.station_name AS 'station.stationName'," +
							"b.road_coding AS 'station.roadCoding'," +
							"b.db_type AS 'station.dbType'," +
							"b.b_jwpoints AS 'station.bJwpoints'," +
							"b.g_lonx AS 'station.gLonx'," +
							"b.g_lonx AS 'station.gLaty'," +
							"b.x AS 'station.x'," +
							"b.y AS 'station.y'," +
							"b.shapes_type AS 'station.shapesType'," +
							"b.radius AS 'station.radius'," +
							"AsText(b.g_polygon_grid) AS 'station.gPolygonGrid'," +
							"AsText(b.b_polygon_grid) AS 'station.bPolygonGrid'," +
							"b.destroy AS 'station.destroy'," +
							"b.versions AS 'station.versions'," +
							"b.descriptions AS 'station.descriptions' FROM (" +
								"SELECT r.id AS 'stationRoute.id'," +
								" r.line AS 'stationRoute.line'," +
								"r.station AS 'stationRoute.station'," +
								"r.station_name AS 'stationRoute.stationName'," +
								"r.station_route_code as 'stationRoute.stationRouteCode'," +
								"r.line_code AS 'stationRoute.lineCode'," +
								"r.station_mark AS 'stationRoute.stationMark'," +
								"r.out_station_nmber AS 'stationRoute.outStationNmber'," +
								"r.directions AS 'stationRoute.directions'," +
								"r.distances AS 'stationRoute.distances'," +
								"r.to_time AS 'stationRoute.toTime'," +
								"r.first_time AS 'stationRoute.firstTime'," +
								"r.end_time AS 'stationRoute.endTime'," +
								"r.descriptions AS 'stationRoute.descriptions'," +
								"r.versions AS 'stationRoute.versions' FROM bsth_c_stationroute r  WHERE  r.line = ?1 and r.directions = ?2) a " +
							"LEFT JOIN bsth_c_station b " +
							"ON a.`stationRoute.station` = b.id ORDER BY a.`stationRoute.stationRouteCode` ASC", nativeQuery=true)
	List<Object[]> findPoints(int line,int directions);
	

	@Query(value = "select t.station_route_code,t.station_mark from bsth_c_stationroute t where " +
			" t.station_route_code =(" +
				"select  MAX(station_route_code) as stationRouteCode   from bsth_c_stationroute r  WHERE  " +
					"r.line=?1 and r.directions =?2 and station_route_code< ?3  ) and t.line=?1 and t.directions = ?2", nativeQuery=true)
	List<Object[]> findUpStationRouteCode(Integer lineId,Integer direction,Integer stationRouteCode);
}