StationRepository.java 4.48 KB
package com.bsth.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.bsth.entity.Station;

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

@Repository
public interface StationRepository extends BaseRepository<Station, Integer> {
	
	/**
	 * @Description :TODO(查询最大站点ID)
	 * 
	 * @return int <站点id>
	 */
	@Query(value = "SELECT IFNULL(num,0) as maxId from (SELECT MAX(id) as num FROM bsth_c_station) k"
			, nativeQuery=true)
	long stationMaxId();
	
	@Query(value = "SELECT * FROM bsth_c_station s where s.station_name = ?1"
			, nativeQuery=true)
	List<Object[]> findStationName(String stationName);
	
	/**
	 * @Description :TODO(站点保存)
	 * 
	 * @param map <stationCode:站点编码;stationName:站点名称;roadCoding:道路编码;dbType:原坐标类型;bJwpoints:中心点百度坐标
	 * 
	 * 			   gLonx:中心点WGS坐标经度;gLaty:中心点WGS坐标纬度;x:城建x;y:城建坐标y;gPloygonGrid:多变形WGS坐标;
	 * 
	 * 			   bPloygonGrid:多边形百度坐标;destroy:是否撤销;radius:圆半径;shapesType:图形类型;versions:版本号;
	 * 
	 *             descriptions:说明;createBy:创建人;updateBy:更新人>
	 */
	@Transactional
    @Modifying
    @Query(value="INSERT INTO bsth_c_station (" +
    			 "station_cod , station_name , road_coding , db_type , b_jwpoints , " +
    			 "g_lonx , g_laty , x , y , g_polygon_grid,b_polygon_grid, " +
    			 "destroy , radius , shapes_type , versions , descriptions," +
    			 "create_by,update_by,id) " +
    			 " VALUES(" +
    			 "?1 , ?2 , ?3 , ?4 , ?5," +
    			 "?6 , ?7 , ?8 , ?9 , ST_GeomFromText(?10),ST_GeomFromText(?11)," +
    			 "?12 ,?13, ?14, ?15, ?16," +
    			 "?17,?18,?19)", nativeQuery=true)
	public void stationSave(String stationCode,String stationName,String roadCoding,String dbType,String bJwpoints,
					
							Float gLonx, Float gLaty, Float x,Float y, String gPloygonGrid, String bPloygonGrid,
							
							Integer destroy,Integer radius,String shapesType,Integer versions,String descriptions,Integer createBy,Integer updateBy,int id);
	
	/**
	 * @Description :TODO(站点更新)
	 * 
	 * @param map <stationCode:站点编码;stationName:站点名称;roadCoding:道路编码;dbType:原坐标类型;bJwpoints:中心点百度坐标
	 * 
	 * 			   gLonx:中心点WGS坐标经度;gLaty:中心点WGS坐标纬度;x:城建x;y:城建坐标y;gPloygonGrid:多变形WGS坐标;
	 * 
	 * 			   bPloygonGrid:多边形百度坐标;destroy:是否撤销;radius:圆半径;shapesType:图形类型;versions:版本号;
	 * 
	 *             descriptions:说明;createBy:创建人;updateBy:更新人>
	 */
	@Transactional
    @Modifying
    @Query(value="UPDATE bsth_c_station SET " +
    		"station_cod =  ?1 , " +
    		"station_name = ?2  , " +
    		"road_coding = ?3  , " +
    		"db_type = ?4  , " +
    		"b_jwpoints =  ?5  , " +
    		"g_lonx =  ?6  , " +
    		"g_laty =  ?7  , " +
    		"x =  ?8  , " +
    		"y = ?9  , " +
    		"b_polygon_grid = ST_GeomFromText(?10)  , " +
    		"g_polygon_grid = ST_GeomFromText(?11)  , " +
    		"destroy = ?12  , " +
    		"radius = ?13  , " +
    		"shapes_type = ?14  , " +
    		"versions = ?15  , " +
    		"descriptions = ?16  " +
    		" WHERE id = ?17   ", nativeQuery=true)
	public void stationUpdate(String stationCod,String stationName,String roadCoding,String dbType,String bJwpoints,
								
							  Float gLonx,Float gLaty,Float x,Float y, String bPolygonGrid,String gPolygonGrid,
							  
							  Integer  destroy, Integer radius,String shapesType, Integer versions,String descriptions,Integer stationId);
    
	
	@Query(value = "select st_astext(g_polygon_grid) as g_polygon_grid, shapes_type,concat(g_lonx, ' ', g_laty) as g_center_point ,radius, station_cod,station_name from bsth_c_station where station_cod=?1", nativeQuery = true)
	public Object[][] bufferAera(String stationCode);
}