LineVersionsRepository.java 1.97 KB
package com.bsth.repository;

import java.util.Date;
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.Line;
import com.bsth.entity.LineVersions;

/**
 * 
 * @Interface: LineVersionsRepository(线路Repository数据持久层接口)
 * 
 * @Extends : BaseRepository
 * 
 * @Description: TODO(线路版本Repository数据持久层接口)
 * 
 * @Author bsth@lq
 *
 * @Version 公交调度系统BS版 0.1
 * 
 */
@Repository
public interface LineVersionsRepository extends BaseRepository<LineVersions, Integer> {
	
	/**
	 * 获取线路所有版本
	 */
	@Query(value = "  SELECT lv FROM LineVersions lv where lv.line.id = ?1")
	public List<LineVersions> findBylineCode(int lineId);
	
	@Transactional
	@Modifying
	@Query(value = "UPDATE LineVersions lv set lv.line=?2, lv.lineCode=?3, lv.startDate=?4, lv.endDate=?5, "
			+ "lv.versions=?6, lv.status=?7, lv.remark=?8 where lv.id=?1")
	public int update(Integer id, Line line, String lineCode, Date startDate, Date endDate, Integer versions, Integer status,
			String remark);
	
	/**
	 * 查询待更新线路的线路版本
	 */
	@Query(value = "SELECT lv FROM LineVersions lv where lv.status = 2 and lv.startDate<sysdate() and lv.endDate > sysdate()")
	public List<LineVersions> findupdated();

	/**
	 * 更改为历史版本
	 */
	@Modifying
	@Query(value = "UPDATE LineVersions lv set lv.status=0 where lv.line.id=?1 and lv.lineCode=?2 and lv.status=1")
	public void updateOdlVersions(Integer lineId, String lineCode);
	
	/**
	 * 更改为当前版本
	 */
	@Modifying
	@Query(value = "UPDATE LineVersions lv set lv.status=1 where lv.line.id=?1 and lv.lineCode=?2 and lv.versions=?3")
	public void updateNewVersions(Integer lineId, String lineCode, Integer versions);
	
}