package com.fs.his.mapper;

import java.util.List;

import com.fs.his.domain.FsFollow;
import com.fs.his.domain.FsFollowReport;
import com.fs.his.domain.FsInquiryOrder;
import com.fs.his.param.FsFollowReportParam;
import com.fs.his.vo.FsFollowReportListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 咨询报告Mapper接口
 *
 * @author fs
 * @date 2024-01-29
 */
public interface FsFollowReportMapper
{
    /**
     * 查询咨询报告
     *
     * @param id 咨询报告主键
     * @return 咨询报告
     */
    public FsFollowReport selectFsFollowReportById(Long id);

    /**
     * 查询咨询报告列表
     *
     * @param fsFollowReport 咨询报告
     * @return 咨询报告集合
     */
    public List<FsFollowReport> selectFsFollowReportList(FsFollowReport fsFollowReport);

    /**
     * 新增咨询报告
     *
     * @param fsFollowReport 咨询报告
     * @return 结果
     */
    public int insertFsFollowReport(FsFollowReport fsFollowReport);

    /**
     * 修改咨询报告
     *
     * @param fsFollowReport 咨询报告
     * @return 结果
     */
    public int updateFsFollowReport(FsFollowReport fsFollowReport);

    /**
     * 删除咨询报告
     *
     * @param id 咨询报告主键
     * @return 结果
     */
    public int deleteFsFollowReportById(Long id);

    /**
     * 批量删除咨询报告
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsFollowReportByIds(Long[] ids);
    @Select({"<script> " +
            "select fr.*,c.company_name,s.store_name,u.nick_name,u.phone from fs_follow_report fr LEFT JOIN company c  ON c.company_id=fr.company_id LEFT JOIN fs_store s ON s.store_id=fr.store_id " +
            " LEFT JOIN fs_user u ON u.user_id=fr.user_id " +
            "<where>\n" +
            "            <if test=\"userId != null \"> and fr.user_id = #{userId}</if>\n" +
            "            <if test=\"patientName != null  and patientName != ''\"> and fr.patient_name like concat('%', #{patientName}, '%')</if>\n" +
            "            <if test=\"doctorId != null \"> and fr.doctor_id = #{doctorId}</if>\n" +
            "            <if test=\"doctorAccount != null  and doctorAccount != ''\"> and fr.doctor_account = #{doctorAccount}</if>\n" +
            "            <if test=\"doctorName != null  and doctorName != ''\"> and fr.doctor_name like concat('%', #{doctorName}, '%')</if>\n" +
            "            <if test=\"companyId != null \"> and fr.company_id = #{companyId}</if>\n" +
            "            <if test=\"storeId != null \"> and fr.store_id = #{storeId}</if>\n" +
            "            <if test=\"followCount != null \"> and fr.follow_count = #{followCount}</if>\n" +
            "            <if test=\"followNum != null \"> and fr.follow_num = #{followNum}</if>\n" +
            "            <if test=\"writeNum != null \"> and fr.write_num = #{writeNum}</if>\n" +
            "            <if test=\"month != null \"> and fr.month = #{month}</if>\n" +
            "            <if test=\"phone != null \"> and u.phone like concat( #{phone}, '%')</if>\n" +
            "        </where> order by id desc"+
            "</script>"})
    List<FsFollowReportListVO> selectFsFollowReportListVO(FsFollowReportParam fsFollowReport);
    @Select({"<script> "+
            "select * from fs_follow_report  where user_id=#{userId} and doctor_id=#{doctorId}  and `month`=#{moth} "+
            "<if test=\"companyId != null and companyId != ''\"> and company_id = #{companyId}</if>\n"+
            "<if test=\"companyId == null or companyId == '' \"> and company_id is null and store_id = #{storeId} </if>\n"+
            "</script>"})
    FsFollowReport selectFsFollowReportByCompanyIdAndUseridAndDoctorId(@Param("userId")long userId,@Param("doctorId") long doctorId,@Param("companyId") Long companyId,@Param("moth") String moth,@Param("storeId") Long storeId);
    @Select("select count(*) from fs_inquiry_order_msg  where from_account =#{userIdL} and msg_type=1 and to_account=#{doctorIdL} and DATE(create_time)= CURDATE()")
    int selectFollowByUserIdAndDoctorId(@Param("userIdL")long userIdL, @Param("doctorIdL")long doctorIdL);
    @Select("select order_id FROM fs_inquiry_order  where user_id=#{userIdL} and doctor_id=#{doctorIdL} and `status`>1 LIMIT 1 ")
    FsInquiryOrder selectFsInquiryOrderById(@Param("userIdL")long userIdL, @Param("doctorIdL")long doctorIdL);
    @Select("select * FROM fs_follow  where user_id=#{userIdL} and doctor_id=#{doctorIdL} ORDER BY follow_id desc  LIMIT 1 ")
    FsFollow selectFsFollowOrderById(@Param("userIdL")long userIdL, @Param("doctorIdL")long doctorIdL);

    @Select("select count(*)  from fs_inquiry_order_msg where msg_type=2 and from_account=#{userIdL} and msg_content_type=1 and content  like '%您的信息我已收到%' and  DATE(create_time)= CURDATE()")
    int selectFollowByUserIdAndDoctorIdAndType(@Param("userIdL")long userIdL, @Param("doctorIdL")long doctorIdL);
    @Select("select * FROM fs_inquiry_order  where user_id=#{userIdL} and doctor_id=#{doctorIdL} and `status`=3 LIMIT 1 ")
    FsInquiryOrder selectFsInquiryOrderByUserAndDoc(@Param("userIdL")long userIdL, @Param("doctorIdL")long doctorIdL);
    @Select("select * FROM fs_follow  where user_id=#{userIdL} and doctor_id=#{doctorIdL} ORDER BY follow_id desc  LIMIT 1 ")
    FsFollow selectFsFollowById(@Param("userIdL")long userIdL, @Param("doctorIdL")long doctorIdL);
    @Select({"<script> " +
            "select count(1) from fs_follow_report fr LEFT JOIN company c  ON c.company_id=fr.company_id " +
            " LEFT JOIN fs_user u ON u.user_id=fr.user_id " +
            "<where>\n" +
            "            <if test=\"userId != null \"> and fr.user_id = #{userId}</if>\n" +
            "            <if test=\"patientName != null  and patientName != ''\"> and fr.patient_name like concat('%', #{patientName}, '%')</if>\n" +
            "            <if test=\"doctorId != null \"> and fr.doctor_id = #{doctorId}</if>\n" +
            "            <if test=\"doctorAccount != null  and doctorAccount != ''\"> and fr.doctor_account = #{doctorAccount}</if>\n" +
            "            <if test=\"doctorName != null  and doctorName != ''\"> and fr.doctor_name like concat('%', #{doctorName}, '%')</if>\n" +
            "            <if test=\"companyId != null \"> and fr.company_id = #{companyId}</if>\n" +
            "            <if test=\"storeId != null \"> and fr.store_id = #{storeId}</if>\n" +
            "            <if test=\"followCount != null \"> and fr.follow_count = #{followCount}</if>\n" +
            "            <if test=\"followNum != null \"> and fr.follow_num = #{followNum}</if>\n" +
            "            <if test=\"writeNum != null \"> and fr.write_num = #{writeNum}</if>\n" +
            "            <if test=\"month != null \"> and fr.month = #{month}</if>\n" +
            "            <if test=\"phone != null \"> and u.phone like concat( #{phone}, '%')</if>\n" +
            "        </where> order by id desc"+
            "</script>"})
    Long selectFsFollowReportListVOCount(FsFollowReportParam fsFollowReport);
}
