package cn.hnthyy.thmz.mapper.his.mz;

import cn.hnthyy.thmz.entity.his.mz.Employee;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface EmployeeMapper {
    /**
     * 根据医生工号查询医生
     *
     * @param codeRs
     * @return
     */
    @Select(" select top 1 rtrim(code) employeeCode,rtrim(name) employeeName,del_flag,rtrim(mark) mark,emp_tit_code,rtrim(code_rs)  code_rs,rtrim(dept_code) dept_code from a_employee_mi  where  code_rs =#{codeRs}")
    Employee selectByCodeRs(@Param("codeRs") String codeRs);


    /**
     * 根据部门id列表查询医生列表
     *
     * @param depts 部门id列表
     * @return
     */
    @Select({"<script>",
            "select rtrim(code) employee_code,rtrim(name) employee_name,del_flag,rtrim(mark) mark,rtrim(dept_code) dept_code,emp_tit_code,rtrim(code_rs)  code_rs,rtrim(dept_code) dept_code from a_employee_mi where (del_flag is null or del_flag =0 ) ",
            "<when test='depts!=null'>",
            " and  dept_code in",
            "<foreach item='item' index='index' collection='depts' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</when>",
            "</script>"})
    List<Employee> selectEmployeeByDepts(@Param("depts") List<String> depts);


    /**
     * 根据部门id查询医生列表
     *
     * @param dept 部门id
     * @return
     */
    @Select({"<script>",
            "select rtrim(code) employee_code,rtrim(name) employee_name,del_flag,rtrim(mark) mark,emp_tit_code,rtrim(code_rs)  code_rs,rtrim(dept_code) dept_code from a_employee_mi where (del_flag is null or del_flag =0 )",
            "<when test='dept!=null'>",
            " and dept_code =#{dept}",
            "</when>",
            "</script>"})
    List<Employee> selectEmployeeByDept(@Param("dept") String dept);


    /**
     * 根据医生姓名查询医生
     *
     * @param name
     * @return
     */
    @Select(" select top 1 rtrim(code) employeeCode,rtrim(name) employeeName,del_flag,rtrim(mark) mark,emp_tit_code,rtrim(code_rs)  code_rs,rtrim(dept_code) dept_code from a_employee_mi  where name =#{name} and (del_flag is null or del_flag =0 )")
    Employee selectByUserName(@Param("name") String name);


    /**
     * 根据医生编号查询医生
     *
     * @param code
     * @return
     */
    @Select(" select top 1 rtrim(code) employeeCode,rtrim(name) employeeName,del_flag,rtrim(mark) mark,emp_tit_code,rtrim(code_rs)  code_rs,rtrim(dept_code) dept_code from a_employee_mi  where  code =#{code} and (del_flag is null or del_flag =0 )")
    Employee selectByUserCode(@Param("code") String code);


    /**
     * 根据医生code集合查询医生信息
     * @param codes
     * @return
     */
    @Select({"<script>",
            "select rtrim(code) employeeCode,rtrim(name) employeeName,del_flag,rtrim(mark) mark,emp_tit_code,rtrim(code_rs)  code_rs,rtrim(dept_code) dept_code from a_employee_mi  where  code in",
            "<foreach item='item' index='index' collection='codes' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"})
    List<Employee> selectByCodes(@Param("codes") List<String> codes);


    /**
     * 查询所有医生
     * @return
     */
    @Select("select rtrim(code) employeeCode,rtrim(name) employeeName,del_flag,rtrim(mark) mark,emp_tit_code,rtrim(code_rs)  code_rs,rtrim(dept_code) dept_code from a_employee_mi where (del_flag is null or del_flag =0 ) ")
    List<Employee> selectAll();
}
