package com.fs.his.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fs.his.domain.DoctorMsg;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 医生消息Mapper接口
 *
 * @author fs
 * @date 2025-11-04
 */
public interface DoctorMsgMapper extends BaseMapper<DoctorMsg>{
    /**
     * 查询医生消息
     *
     * @param id 医生消息主键
     * @return 医生消息
     */
    DoctorMsg selectDoctorMsgById(Long id);

    /**
     * 查询医生消息列表
     *
     * @param doctorMsg 医生消息
     * @return 医生消息集合
     */
    List<DoctorMsg> selectDoctorMsgList(DoctorMsg doctorMsg);

    /**
     * 新增医生消息
     *
     * @param doctorMsg 医生消息
     * @return 结果
     */
    int insertDoctorMsg(DoctorMsg doctorMsg);

    /**
     * 修改医生消息
     *
     * @param doctorMsg 医生消息
     * @return 结果
     */
    int updateDoctorMsg(DoctorMsg doctorMsg);

    /**
     * 删除医生消息
     *
     * @param id 医生消息主键
     * @return 结果
     */
    int deleteDoctorMsgById(Long id);

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

    //获取医生未读消息总数
    @Select("select IFNULL(count( 0),0) from doctor_msg where doctor_id = #{doctorId} and is_read = 0 ")
    Long selectDoctorMsgCountsByDoctorId(Long doctorId);

    @Select("select IFNULL(count( type),0) from doctor_msg where doctor_id = #{doctorId} and is_read = 0 and type = #{type}")
    Long selectDoctorMsgCountsByDoctorIdAndType(@Param("doctorId") Long doctorId, @Param("type") int type);

    @Update("update  doctor_msg set is_read=1 where doctor_id = #{doctorId} ")
    int setAllRead(Long doctorId);
}
