LsStationRouteRepository.java 2.69 KB
package com.bsth.repository;

import java.util.List;
import java.util.Map;

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

import com.bsth.entity.LsStationRoute;

/**
 * 
 * @Interface: StationRouteRepository(站点路由Repository数据持久层接口)
 * 
 * @Extends : BaseRepository
 * 
 * @Description: TODO(站点路由Repository数据持久层接口)
 * 
 * @Author bsth@lq
 *
 * @Version 公交调度系统BS版 0.1
 * 
 */

@Repository
public interface LsStationRouteRepository extends BaseRepository<LsStationRoute, Integer> {
	
	/**
	 * 查询待更新线路的站点路由
	 */
	@EntityGraph(value = "ls_stationRoute_station", type = EntityGraph.EntityGraphType.FETCH)
	@Query(value = "SELECT DISTINCT sr FROM LsStationRoute sr where sr.line.id =?1 and sr.lineCode=?2 and sr.versions=?3 and sr.destroy=0")
	List<LsStationRoute> findupdated(Integer lineId, String lineCode, Integer versions);
	
	/**
     * 更新路线前删除线路版本号历史原有站点路由
     * 
     * @param line
     * @param dir
     */
    @Modifying
    @Query(value="DELETE from bsth_c_ls_stationroute where line = ?1  and directions = ?2 and versions = ?3", nativeQuery=true)
    public void batchDelete(Integer line,Integer dir, Integer versions);

    /**
     * 更新路线前撤销线路版本号历史原有站点路由
     * 
     * @param line
     * @param dir
     */
    @Modifying
    @Query(value="UPDATE bsth_c_ls_stationroute set destroy = 1 where line = ?1  and directions = ?2 and versions = ?3", nativeQuery=true)
    public void batchDestroy(Integer sectionRouteLine, Integer directions, Integer versions);

    /**
     * 按线路编码查询各站点的顺序号
     * @param lineCode 线路编码
     * @param lineVersion 版本号
     * @return
     */
    @Query("SELECT new map(" +
            "lineCode as lineCode,directions as directions,stationName as stationName,stationCode as stationCode," +
            "line.linePlayType as linePlayType,s.stationMark as stationMark) " +
            "FROM " +
            "LsStationRoute s " +
            "WHERE " +
            "s.destroy = 0 AND s.lineCode = ?1 AND s.versions = ?2 " +
            "ORDER BY " +
            "lineCode,directions,stationRouteCode")
    List<Map<String, String>> findLineWithLineCode4Ygc(String lineCode,Integer lineVersion);


    @Modifying
    @Query(value="update bsth_c_ls_stationroute set distances =?2 where id = ?1 ", nativeQuery=true)
    public void upddis(Integer id,Double dis);
}