LsInoutSectionRouteRepository.java 2.74 KB
package com.bsth.repository;

import com.bsth.entity.LsInoutSectionRoute;
import com.bsth.entity.LsSectionRoute;
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 java.util.List;

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

@Repository
public interface LsInoutSectionRouteRepository extends BaseRepository<LsInoutSectionRoute, Long> {

	/**
	 * 查询待更新线路的路段路由
	 */
	@Query(value = "SELECT sr FROM LsInoutSectionRoute sr where sr.line.id =?1 and sr.versions=?2 and sr.start=?3 and sr.end=?4 and sr.destroy=0 order by sr.sectionrouteCode")
	List<LsInoutSectionRoute> getRouteByStartEnd(int lineId, int version, String start, String end);

	/**
	 *
	 * @param lineCode
	 * @param version
	 * @param start
	 * @param end
	 * @param sectionrouteCode
	 */
	@Modifying
	@Query(value="UPDATE bsth_c_ls_inout_sectionroute set sectionroute_code = (sectionroute_code+1) where line_code = ?1 and versions = ?2  and start = ?3 and end = ?4 and sectionroute_code >=?5 and destroy = 0", nativeQuery=true)
	public void sectionUpdSectionRouteCode(String lineCode, int version, String start, String end, Integer sectionrouteCode);

	/**
	 * 在站点路由更新时(站点路由可能改变路由编号,如起点、改变上一站点)
	 * 将当前路由编号及以后的编号批量递增10
	 * @param sectionRoute
	 */
	@Modifying
	@Query(value="UPDATE bsth_c_ls_inout_sectionroute set sectionroute_code = (sectionroute_code + 10) where line = :#{#sectionRoute.line.id} and destroy = 0 and versions = :#{#sectionRoute.versions} and directions = :#{#sectionRoute.directions} and sectionroute_code >= :#{#sectionRoute.sectionrouteCode}", nativeQuery=true)
	void updateSectiouRouteCode(LsInoutSectionRoute sectionRoute);

	/**
	 * 撤销线路版本下某个方向进出场整个路由组
	 * @param lineCode
	 * @param version
	 * @param start
	 * @param end
	 */
	@Modifying
	@Query(value="UPDATE bsth_c_ls_inout_sectionroute set destroy = 1 where id = ?1 and versions = ?2  and start = ?3 and end = ?4", nativeQuery=true)
	void destroy(String lineCode, int version, String start, String end);

	/**
	 * 按ID撤销进出场路由组中一个路由
	 * @param id
	 */
	@Modifying
	@Query(value="UPDATE bsth_c_ls_inout_sectionroute set destroy = 1 where id = ?1", nativeQuery=true)
	void destroy(Integer id);
}