package com.fs.his.mapper;

import java.util.List;

import com.fs.common.core.domain.R;
import com.fs.his.domain.FsUserDoctor;
import com.fs.his.param.FsUserDoctorListUParam;
import com.fs.his.vo.FsUserDoctorListUVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 会员医生Mapper接口
 *
 * @author fs
 * @date 2023-07-03
 */
public interface FsUserDoctorMapper
{
    /**
     * 查询会员医生
     *
     * @param id 会员医生主键
     * @return 会员医生
     */
    public FsUserDoctor selectFsUserDoctorById(Long id);

    /**
     * 查询会员医生列表
     *
     * @param fsUserDoctor 会员医生
     * @return 会员医生集合
     */
    public List<FsUserDoctor> selectFsUserDoctorList(FsUserDoctor fsUserDoctor);

    /**
     * 新增会员医生
     *
     * @param fsUserDoctor 会员医生
     * @return 结果
     */
    public int insertFsUserDoctor(FsUserDoctor fsUserDoctor);

    /**
     * 修改会员医生
     *
     * @param fsUserDoctor 会员医生
     * @return 结果
     */
    public int updateFsUserDoctor(FsUserDoctor fsUserDoctor);

    /**
     * 删除会员医生
     *
     * @param id 会员医生主键
     * @return 结果
     */
    public int deleteFsUserDoctorById(Long id);

    /**
     * 批量删除会员医生
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsUserDoctorByIds(Long[] ids);

    @Select({"<script> " +
            "select ud.*,d.doctor_name,d.avatar,d.position,d.ping_star,d.work_status,d.order_number,d.speciality,d.price_json,h.hospital_name,h.hospital_level,de.dept_name  from fs_user_doctor ud left join fs_doctor d on d.doctor_id=ud.doctor_id   " +
            "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 1=1  " +
            "<if test = 'maps.userId != null     '> " +
            "and ud.user_id = #{maps.userId} " +
            "</if>" +
            "<if test = 'maps.type != null     '> " +
            "and ud.type = #{maps.type} " +
            "</if>" +
            " order by ud.id desc "+
            "</script>"})
    List<FsUserDoctorListUVO> getMyDoctorList(@Param("maps") FsUserDoctorListUParam param);

    @Select("select ifnull(count(1),0) from fs_user_doctor  where type=1 and doctor_id=#{doctorId} and user_id=#{userId}")
    int checkFollow(@Param("doctorId") Long doctorId,@Param("userId")long userId);
    @Delete("delete from fs_user_doctor  where type=1 and doctor_id=#{doctorId} and user_id=#{userId} ")
    int deleteFollow(@Param("doctorId") Long doctorId,@Param("userId")long userId);
}
