package com.dashitech.businessdata.dao;

import com.dashitech.businessdata.entity.InspectEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by chi on 2019/9/12.
 */
public interface IInspectDAO  extends JpaRepository<InspectEntity, String> {

    @SuppressWarnings("unchecked")
    InspectEntity save(InspectEntity inspectEntity);

    @Query(value = "select id from InspectEntity where inspectCode=:inspectCode")
    Long selectIdByInspectCode(@Param("inspectCode")String inspectCode);

    @Query(value = "select ie from InspectEntity ie where ie.inspectCode=:inspectCode")
    List<InspectEntity> selectInspectByInspectCode(@Param("inspectCode")String inspectCode);

    @Query(value = "select ie from InspectEntity ie where ie.inspectCode like CONCAT(:inspectCode,'%')")
    List<InspectEntity> selectInspectByInspectCodeLike(@Param("inspectCode")String inspectCode);

    @Query(value = "select ie from InspectEntity ie where ie.inspectState in (307,443) and ie.patientCode=:patientCode")
    List<InspectEntity> selectInspectByPatientCode(@Param("patientCode")String patientCode);

    @Modifying
    @Transactional
    @Query(value = "UPDATE itsm_transport_inspect set yytime = ?2 WHERE inspect_code = ?1",nativeQuery = true)
    int upInspectYyTime(String inspectCode,String yytime);


}
