LineRepository.java 3.98 KB
package com.bsth.repository;

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

import com.bsth.entity.LineSt;
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;

/**
 * 
 * @Interface: LineRepository(线路Repository数据持久层接口)
 * 
 * @Extends : BaseRepository
 * 
 * @Description: TODO(线路Repository数据持久层接口)
 * 
 * @Author bsth@lq
 * 
 * @Date 2016年4月28日 上午9:21:17
 *
 * @Version 公交调度系统BS版 0.1
 * 
 */
@Repository
public interface LineRepository extends BaseRepository<Line, Integer> {

	/**
	 * 获取线路编码
	 * 
	 * @return int <lineCode:线路编码>
	 */
	@Query(value = "  SELECT IFNULL(num,0) as maxId from (SELECT MAX(id) as num FROM bsth_c_line) k ", nativeQuery = true)
	public long selectMaxIdToLineCode();

	@Query(value = "  SELECT l FROM Line l where l.name like ?1")
	List<Line> findLine(String line);

	@Query(value = "  SELECT l FROM Line l where l.name = ?1")
	Line findLineName(String lineName);
	
	@Query(value = "  SELECT l FROM Line l where l.lineCode = ?1")
	List<Line> findLineByCode(String lineCode);

	public Line findByLineCode(String string);

	@Query(value = "  SELECT l FROM Line l where l.company like ?1 and l.brancheCompany like ?2 and l.lineCode like ?3")
	public List<Line> findLineBygsBm(String gsBm, String fgsBm, String line);

	@Query("SELECT L FROM Line L where L.destroy=0 and L.remove !=1")
	List<Line> findAllService();
	
	@Query("SELECT L FROM Line L")
	List<Line> findAll();

	@Modifying
	@Query(value = "UPDATE Line l set l.name=?1 , l.company=?2, l.brancheCompany=?3, "
			+ "l.level=?4, l.nature=?5, l.startStationName=?6, l.endStationName=?7, l.startStationFirstTime=?8, "
			+ "l.startStationEndTime=?9, l.endStationFirstTime=?10, l.endStationEndTime=?11, l.linePlayType=?12, "
			+ "l.openDate=?13, l.es=?14, l.shortName=?15, l.shanghaiLinecode=?16, l.eqLinecode=?17, l.startPhone=?18, "
			+ "l.endPhone=?19, l.carSumNumber=?20, l.hvacCarNumber=?21, l.ordCarNumber=?22, l.history=?23, "
			+ "l.descriptions=?24, l.destroy=?25, l.supperLine=?26, l.spacGrade=?27, l.warrantCar=?28, l.region=?30 , l.inUse=?31 where "
			+ "l.lineCode=?29")
	int update(String name, String company, String brancheCompany, String level, String nature,
			String startStationName, String endStationName, String startStationFirstTime, String startStationEndTime,
			String endStationFirstTime, String endStationEndTime, Integer linePlayType, Date openDate, String es,
			String shortName, String shanghaiLinecode, String eqLinecode, String startPhone, String endPhone,
			Integer carSumNumber, Integer hvacCarNumber, Integer ordCarNumber, String history, String descriptions,
			Integer destroy, Integer supperLine, Integer spacGrade, Integer warrantCar, String lineCode, Integer region, Integer inUser);

	/**
	 * 查询线路版本文件
	 * @param lineId
	 * @return
	 */
	@Query(value = "SELECT version_count FROM bsth_c_line_file_version where line = ?1", nativeQuery = true)
	Integer findfileVersions(Integer lineId);

	/**
	 *  添加线路文件版本
	 * @param lineId
	 * @param line_code
	 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO bsth_c_line_file_version (line,line_code,version_count) VALUES (?1,?2,1)", nativeQuery = true)
	public void addFileVersions(Integer lineId, String line_code);

	/**
	 *  线路文件版本修改
	 * @param lineId
	 * @param version_count
	 */
	@Transactional
	@Modifying
	@Query(value = "UPDATE bsth_c_line_file_version set version_count=?2 WHERE line = ?1", nativeQuery = true)
	public void editFileVersions(Integer lineId, Integer version_count);


	@Modifying
	@Query(value = "delete from Line l where l.lineCode in ( ?1 )")
	void deleteLineBylineCodes(List<String> lineCodes);
}