package com.ywt.outpatient.domain.entity.center;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;


public interface MedicalModuleRepository extends JpaRepository<MedicalModule, Integer> {

    @Query(value = "select * from medical_module where type = ? and doctor_id = ? order by create_time desc", nativeQuery = true)
    List<MedicalModule> getAllBytypeAndDoctorId(int type, int doctorId);


    /**
     * 判断模版名称有没有重复
     * @param moduleId
     * @param moduleName
     * @param type
     * @return
     */
    @Query(value = "select count(1) from medical_module where id != ? and module_name=? and type = ? and doctor_id = ? ", nativeQuery = true)
    int checkModuleName(int moduleId, String moduleName, int type, int doctorId);

    /**
     * 判断模版名称有没有重复
     * @param moduleName
     * @param type
     * @return
     */
    @Query(value = "select count(1) from medical_module where module_name=? and type = ? and doctor_id = ?", nativeQuery = true)
    int checkModuleName(String moduleName, int type, int doctorId);

    @Transactional
    int deleteByIdEqualsAndDoctorIdEquals(int id, int doctorId);

}
