package com.yihu.jw.hospital.dict;

import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;

/**
 * Created by Trick on 2019/6/17.
 */
public interface WlyyHospitalSysDictDao extends PagingAndSortingRepository<WlyyHospitalSysDictDO, String>, JpaSpecificationExecutor<WlyyHospitalSysDictDO> {

    WlyyHospitalSysDictDO findByHospitalAndDictCode(String hospital, String dictCode);

    List<WlyyHospitalSysDictDO> findByHospitalAndDictNameOrderBySortAsc(String hospital, String dictName);

    WlyyHospitalSysDictDO findById(String id);

    @Query("from WlyyHospitalSysDictDO where dictName = ?1  and  dictCode is null order by sort asc")
    List<WlyyHospitalSysDictDO> findByDictNameNotNull(String dictName);

    List<WlyyHospitalSysDictDO> findByDictName(String dictName);
    @Query("from WlyyHospitalSysDictDO where 1=1")
    List<WlyyHospitalSysDictDO> findAlldict();
    @Query("from WlyyHospitalSysDictDO where dictCode = ?1")
    List<WlyyHospitalSysDictDO> findByDictCode(String dictCode);

    List<WlyyHospitalSysDictDO> findByDictNameAndDictCode(String dictName,String dictCode);
    @Query("from WlyyHospitalSysDictDO where dictName = ?1 and hospital=?2 order by sort asc")
    List<WlyyHospitalSysDictDO> findByDictNameOrderBySort(String dictName,String orgCode);


    @Query("from WlyyHospitalSysDictDO where dictName = ?1 and hospital=?2 order by sort desc ")
    List<WlyyHospitalSysDictDO> getMaxSort(String dictName,String hospital);
    @Query("from WlyyHospitalSysDictDO where dictName = ?1 and hospital=?2 order by sort asc ")
    List<WlyyHospitalSysDictDO>  getMinSort(String dictName,String hospital);


    @Query("from WlyyHospitalSysDictDO where dictName = ?1  and  hospital=?2 and sort >= ?3 order by sort asc")
    List<WlyyHospitalSysDictDO> findByDictNameSortOrderBySort(String dictName,String hospital,Integer sort);

    @Query("from WlyyHospitalSysDictDO where dictName = ?1  and  dictCode=?2 ")
    WlyyHospitalSysDictDO findOneByDictNameAndDictCode(String dictName,String dictCode);

}
