package com.fs.his.mapper;

import java.util.Date;
import java.util.List;
import com.fs.his.domain.FsInquiryOrderMsg;
import com.fs.his.param.FsInquiryOrderMsgListDParam;
import com.fs.his.vo.FsInquiryOrderMsgListDVO;
import lombok.Data;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 图文订单Mapper接口
 *
 * @author fs
 * @date 2023-06-12
 */
public interface FsInquiryOrderMsgMapper
{
    /**
     * 查询图文订单
     *
     * @param msgId 图文订单主键
     * @return 图文订单
     */
    public FsInquiryOrderMsg selectFsInquiryOrderMsgByMsgId(Long msgId);

    /**
     * 查询图文订单列表
     *
     * @param fsInquiryOrderMsg 图文订单
     * @return 图文订单集合
     */
    public List<FsInquiryOrderMsg> selectFsInquiryOrderMsgList(FsInquiryOrderMsg fsInquiryOrderMsg);

    /**
     * 新增图文订单
     *
     * @param fsInquiryOrderMsg 图文订单
     * @return 结果
     */
    public int insertFsInquiryOrderMsg(FsInquiryOrderMsg fsInquiryOrderMsg);

    /**
     * 修改图文订单
     *
     * @param fsInquiryOrderMsg 图文订单
     * @return 结果
     */
    public int updateFsInquiryOrderMsg(FsInquiryOrderMsg fsInquiryOrderMsg);

    /**
     * 删除图文订单
     *
     * @param msgId 图文订单主键
     * @return 结果
     */
    public int deleteFsInquiryOrderMsgByMsgId(Long msgId);

    /**
     * 批量删除图文订单
     *
     * @param msgIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsInquiryOrderMsgByMsgIds(Long[] msgIds);
    @Select("select order_id from fs_inquiry_order where status=3  and doctor_id=#{doctorId} and user_id=#{userId} order by order_id desc limit 1")
    Long selectFsInquiryOrderMsgOrderId(@Param("doctorId") String doctorId, @Param("userId")String userId);
    @Select("select order_id from fs_inquiry_order where status=4  and doctor_id=#{doctorId} and user_id=#{userId} and start_time<=#{date} and finish_time>=#{date}  limit 1")
    Long selectFsInquiryOrderMsgOrderIdByDate(@Param("doctorId")String doctorId, @Param("userId")String userId, @Param("date")Date date);
    @Delete("delete from fs_inquiry_order_msg where msg_key =#{msgKey}")
    void deleteFsInquiryOrderMsgByMsgKey(String msgKey);
    @Select({"<script> " +
            "select m.*,(select d.doctor_name from fs_doctor d   where  d.doctor_id=m.to_account ) as doctor_name,(select nick_name from fs_user u where u.user_id=m.from_account ) as user_nick_name   from fs_inquiry_order_msg m  "+
            " where 1=1 " +
            " <if test = 'maps.orderId != null '> " +
            " and m.order_id=#{maps.orderId} " +
            "</if>" +
            " <if test = 'maps.userId != null '> " +
            " and (m.from_account=#{maps.userId} or  m.to_account=#{maps.userId})" +
            "</if>" +
            " <if test = 'maps.doctorId != null '> " +
            " and (m.to_account=#{maps.doctorId} or  m.from_account=#{maps.doctorId})" +
            "</if>" +
            " order by m.msg_id asc" +
            "</script>"})
    List<FsInquiryOrderMsgListDVO> selectFsInquiryOrderMsgListDVO(@Param("maps")FsInquiryOrderMsgListDParam param);
}
