package com.fs.his.mapper;

import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.his.domain.FsDoctor;
import com.fs.his.param.FsDoctorListUParam;
import com.fs.his.param.FsDoctorParam;
import com.fs.his.vo.*;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.security.core.parameters.P;

/**
 * 医生管理Mapper接口
 *
 * @author fs
 * @date 2023-06-05
 */
public interface FsDoctorMapper
{
    /**
     * 查询医生管理
     *
     * @param doctorId 医生管理主键
     * @return 医生管理
     */
    public FsDoctor selectFsDoctorByDoctorId(Long doctorId);

    /**
     * 查询医生管理列表
     *
     * @param fsDoctor 医生管理
     * @return 医生管理集合
     */
    public List<FsDoctor> selectFsDoctorList(FsDoctor fsDoctor);

    /**
     * 新增医生管理
     *
     * @param fsDoctor 医生管理
     * @return 结果
     */
    public int insertFsDoctor(FsDoctor fsDoctor);

    /**
     * 修改医生管理
     *
     * @param fsDoctor 医生管理
     * @return 结果
     */
    public int updateFsDoctor(FsDoctor fsDoctor);

    /**
     * 删除医生管理
     *
     * @param doctorId 医生管理主键
     * @return 结果
     */
    public int deleteFsDoctorByDoctorId(Long doctorId);

    /**
     * 批量删除医生管理
     *
     * @param doctorIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsDoctorByDoctorIds(Long[] doctorIds);
@Select({"<script> " +
     "        select doc.*,de.dept_name,ho.hospital_name,us.nick_name,us.phone from fs_doctor doc\n" +
        "        LEFT JOIN\n" +
        "        fs_department de ON de.dept_id=doc.dept_id\n" +
        "        LEFT JOIN\n" +
        "        fs_hospital ho ON ho.hospital_id=doc.hospital_id "+
      " LEFT JOIN\n" +
        " fs_user us ON us.user_id=doc.user_id "+


        "<where>\n" +
        "            <if test=\"doctorName != null  and doctorName != ''\"> and doc.doctor_name like concat('%', #{doctorName}, '%')</if>\n" +
        "            <if test=\"introduction != null  and introduction != ''\"> and doc.introduction = #{introduction}</if>\n" +
        "            <if test=\"speciality != null  and speciality != ''\"> and doc.speciality = #{speciality}</if>\n" +
        "            <if test=\"certificateCode != null  and certificateCode != ''\"> and doc.certificate_code = #{certificateCode}</if>\n" +
        "            <if test=\"certificateImages != null  and certificateImages != ''\"> and doc.certificate_images = #{certificateImages}</if>\n" +
        "            <if test=\"avatar != null  and avatar != ''\"> and doc.avatar = #{avatar}</if>\n" +
        "            <if test=\"userId != null \"> and doc.user_id = #{userId}</if>\n" +
        "            <if test=\"hospitalId != null \"> and doc.hospital_id = #{hospitalId}</if>\n" +
        "            <if test=\"deptId != null \"> and doc.dept_id = #{deptId}</if>\n" +
        "            <if test=\"balance != null \"> and doc.balance = #{balance}</if>\n" +
        "            <if test=\"position != null  and position != ''\"> and doc.position = #{position}</if>\n" +
        "            <if test=\"tags != null  and doc.tags != ''\"> and tags = #{tags}</if>\n" +
        "            <if test=\"status != null \"> and doc.status = #{status}</if>\n" +
        "            <if test=\"pingStar != null \"> and doc.ping_star = #{pingStar}</if>\n" +
        "            <if test=\"orderNumber != null \"> and doc.order_number = #{orderNumber}</if>\n" +
        "            <if test=\"speed != null \"> and speed = #{speed}</if>\n" +
        "            <if test=\"mobile != null  and mobile != ''\"> and doc.mobile = #{mobile}</if>\n" +
        "            <if test=\"doctorType != null \"> and doc.doctor_type = #{doctorType}</if>\n" +
        "            <if test=\"sex != null \"> and sex = #{sex}</if>\n" +
        "            <if test=\"bitthday != null \"> and doc.bitthday = #{bitthday}</if>\n" +
        "            <if test=\"idCard != null  and idCard != ''\"> and doc.id_card = #{idCard}</if>\n" +
        "            <if test=\"idCardFrontUrl != null  and idCardFrontUrl != ''\"> and doc.id_card_front_url = #{idCardFrontUrl}</if>\n" +
        "            <if test=\"idCardBackUrl != null  and idCardBackUrl != ''\"> and doc.id_card_back_url = #{idCardBackUrl}</if>\n" +
        "            <if test=\"cityIds != null  and cityIds != ''\"> and doc.city_ids = #{cityIds}</if>\n" +
        "            <if test=\"province != null  and province != ''\"> and doc.province = #{province}</if>\n" +
        "            <if test=\"city != null  and city != ''\"> and doc.city = #{city}</if>\n" +
        "            <if test=\"district != null  and district != ''\"> and doc.district = #{district}</if>\n" +
        "            <if test=\"isTui != null \"> doc.and is_tui = #{isTui}</if>\n" +
        "            <if test=\"isExpert != null \"> and doc.is_expert = #{isExpert}</if>\n" +
        "            <if test=\"workStatus != null \"> and doc.work_status = #{workStatus}</if>\n" +
        "            <if test=\"isAudit != null \"> and doc.is_audit = #{isAudit}</if>\n" +
        "            <if test=\"auditTime != null \"> and doc.audit_time = #{auditTime}</if>\n" +
        "            <if test=\"sTime != null \">  and DATE(doc.create_time) &gt;= DATE(#{sTime})</if>\n" +
        "            <if test=\"eTime != null \">  and DATE(doc.create_time) &lt;= DATE(#{eTime})</if>\n" +
        "        </where>"+
        " order by doc.sort ,doc.doctor_id desc "+
        "</script>"})
    List<FsDoctorListVO> selectFsDoctorListVO(FsDoctorParam fsDoctor);




    @Select({"<script> " +
"select user_id id,CONCAT_WS(\"-\",nick_name,phone) name from fs_user"+
" <if test=\"name != null \"> where nick_name like concat( #{name}, '%') or phone like concat('%',#{name}, '%')</if>"+
            "limit 10"+
            "</script>"})
    List<UserVo> selectuserVOList(String name);
    @Select("select doc.*,de.dept_name,ho.hospital_name,us.nick_name,us.phone,dd.doctor_name  prescribe_doctor_name from fs_doctor doc \n" +
            "LEFT JOIN fs_department de ON de.dept_id=doc.dept_id \n" +
            "LEFT JOIN fs_hospital ho ON ho.hospital_id=doc.hospital_id \n" +
            "LEFT JOIN fs_user us ON us.user_id=doc.user_id \n" +
            "LEFT JOIN fs_doctor dd ON dd.doctor_id=doc.prescribe_doctor_id \n" +
            "where doc.doctor_id = #{doctorId}\n")
    FsDoctorVO selectFsDoctorVOByDoctorId(Long doctorId);
    @Select("select doctor_id id,doctor_name name from fs_doctor where doctor_type =1 and doctor_name LIKE CONCAT('%', #{name}, '%')  limit 10")
    List<UserVo> selectuserDocVoList(String name);


    @Select({"<script> " +
            "select d.doctor_id,d.doctor_name,d.avatar,d.position,d.work_status,d.ping_star,d.order_number,d.speciality,d.price_json,h.hospital_name,h.hospital_level,de.dept_name  from   fs_doctor d    " +
            "left join fs_hospital h on h.hospital_id=d.hospital_id   " +
            "left join fs_department de on de.dept_id=d.dept_id   " +
            "where d.is_audit=1 and d.status=1 and d.is_show=1 and d.doctor_type = 1  " +
            "<if test = 'maps.keyword != null     '> " +
            "and d.doctor_name like CONCAT('%',#{maps.keyword},'%')" +
            "</if>"+
            "<if test = 'maps.isTui != null     '> " +
            "and d.is_tui = #{maps.isTui} " +
            "</if>" +
            "<if test = 'maps.doctorType != null     '> " +
            "and d.doctor_type = #{maps.doctorType} " +
            "</if>" +
            "<if test = 'maps.packageId != null     '> " +
            "and find_in_set( #{maps.packageId},d.package_ids)   " +
            "</if>" +
            "<if test = 'maps.deptId != null and maps.deptId!=0     '> " +
            "and d.dept_id = #{maps.deptId} " +
            "</if>" +
            "<if test = 'maps.hospitalId != null     '> " +
            "and d.hospital_id = #{maps.hospitalId} " +
            "</if>" +
            "<if test = 'maps.doctorName != null and maps.doctorName != \"\"     '> " +
            "and d.doctor_name = #{maps.doctorName} " +
            "</if>" +
            " order by d.sort desc "+
            "</script>"})
    List<FsDoctorListUVO> selectFsDoctorListUVO(@Param("maps") FsDoctorListUParam param);
    @Select("select * from fs_doctor where account=#{account}")
    FsDoctor selectFsDoctorByAccount(String account);
    @Select("select * from fs_doctor where user_id=#{userId}")
    FsDoctor selectFsDoctorByUserId(long userId);
    @Select("select doctor_id from fs_doctor where doctor_type=2 and  `status`=1 and is_audit=1 and sign_url is not null and audit_type LIKE CONCAT('%', #{type}, '%')  ORDER BY RAND() LIMIT 1")
    Long selectFsDoctorType2Ids(Integer type);
    @Select("select * from fs_doctor where doctor_id=#{doctorId} for update")
    FsDoctor selectFsDoctorByDoctorIdForUpdate(Long doctorId);
    @Select("select * from fs_doctor where doctor_type=2 and  `status`=1 and is_audit=1 and sign_url is not null and audit_type LIKE CONCAT('%', #{type}, '%')  ORDER BY RAND() LIMIT 1")
    FsDoctor selectPackageFsDoctorType2Ids(Integer type);
    @Select("select doctor_id from fs_doctor where doctor_type=1 and  `status`=1 and is_audit=1 and is_agreement_prescribe_doctor=1  and sign_url is not null")
    List<Long>  selectFsDoctorDoctorByPackage();
    @Select("select doctor_id from fs_doctor where doctor_type=1 and  `status`=1 and is_audit=1 and dept_id=39 and is_follow=1  ORDER BY RAND() LIMIT 1")
    Long selectFollowDoctorDoctorByPackage();
    @Select("select * from fs_doctor where doctor_type=1 and  `status`=1 and is_audit=1 and dept_id=39 ")
    List<Long> selectFollowDoctorListByPackage();

    @Select("select * from fs_doctor where sign_url  LIKE '%https://htj-1258038825.cos.ap-beijing.myqcloud.com%' ")
    List<FsDoctor> selectFsDoctorListByUpdate();
    @Select("select doctor_id dictValue,account dictLabel from fs_doctor where doctor_type=1 and  `status`=1 and is_audit=1 and dept_id=39")
    List<OptionsVO> selectfollowDoctorList();
    @Select("select doctor_id dictValue,account dictLabel from fs_doctor where doctor_type=1 and  is_audit=1 and dept_id=39")
    List<OptionsVO> selectAllfollowDoctorList();
    @Select("select account from fs_doctor where doctor_id=#{id} ")
    String selectFsDoctorNameByDoctorId(Long id);
    @Select("select doctor_id id,doctor_name name from fs_doctor where doctor_type =1 ")
    List<UserVo> selectAllDocVoList();

    @Select("SELECT doctor_id id,doctor_name name  FROM fs_doctor WHERE FIND_IN_SET(doctor_id, (select doctor_ids from company where company_id=#{companyId})); ")
    List<UserVo> selectUserDocVoListByCompany(Long companyId);
}
