package com.fs.his.mapper;

import java.util.List;
import com.fs.his.domain.FsInquiryOrderReport;
import com.fs.his.param.FsInquiryOrderReportParam;
import com.fs.his.vo.FsInquiryOrderReportListVO;
import com.fs.his.vo.FsInquiryOrderReportUVO;
import com.fs.his.vo.FsInquiryOrderReportVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 问诊报告Mapper接口
 *
 * @author fs
 * @date 2023-09-04
 */
public interface FsInquiryOrderReportMapper
{
    /**
     * 查询问诊报告
     *
     * @param reportId 问诊报告主键
     * @return 问诊报告
     */
    public FsInquiryOrderReport selectFsInquiryOrderReportByReportId(Long reportId);

    /**
     * 查询问诊报告列表
     *
     * @param fsInquiryOrderReport 问诊报告
     * @return 问诊报告集合
     */
    public List<FsInquiryOrderReport> selectFsInquiryOrderReportList(FsInquiryOrderReport fsInquiryOrderReport);

    /**
     * 新增问诊报告
     *
     * @param fsInquiryOrderReport 问诊报告
     * @return 结果
     */
    public int insertFsInquiryOrderReport(FsInquiryOrderReport fsInquiryOrderReport);

    /**
     * 修改问诊报告
     *
     * @param fsInquiryOrderReport 问诊报告
     * @return 结果
     */
    public int updateFsInquiryOrderReport(FsInquiryOrderReport fsInquiryOrderReport);

    /**
     * 删除问诊报告
     *
     * @param reportId 问诊报告主键
     * @return 结果
     */
    public int deleteFsInquiryOrderReportByReportId(Long reportId);

    /**
     * 批量删除问诊报告
     *
     * @param reportIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsInquiryOrderReportByReportIds(Long[] reportIds);
    @Select({"<script> " +
            "select ior.*,ior.patient_json->>'$.patientName' as  patient_name,u.nick_name,u.phone,d.doctor_name,su.nick_name user_name,send.nick_name send_name,fio.status inquiry_status,fio.inquiry_sub_type,fio.order_sn,c.company_name,cuu.nick_name company_user_name,fz.nick_name fz_name  FROM fs_inquiry_order_report ior  " +
            " LEFT JOIN fs_user u ON u.user_id=ior.user_id " +
            " LEFT JOIN fs_doctor d ON d.doctor_id=ior.doctor_id " +
            " LEFT JOIN sys_user su ON su.user_id=ior.audit_user_id " +
            " LEFT JOIN fs_inquiry_order fio ON fio.order_id=ior.order_id " +
            " LEFT JOIN fs_user_coupon fuc ON  fuc.id=fio.user_coupon_id " +
            " LEFT JOIN sys_user send ON send.user_id=fuc.send_user_id " +
            " LEFT JOIN company c ON c.company_id=fio.company_id " +
            " LEFT JOIN company_user cuu ON cuu.user_id=fio.company_user_id " +
            " LEFT JOIN company_user fz ON fz.user_id=ior.triage_user_id " +
            " LEFT join fs_patient fp on ior.patient_id = fp.patient_id " +
            " WHERE fio.`status`!=1 and fio.inquiry_sub_type!=3"+
            "            <if test=\"maps.orderId != null \"> and fio.order_sn = #{maps.orderId}</if>\n" +
            "            <if test=\"maps.doctorName != null \"> and d.doctor_name = #{maps.doctorName}</if>\n" +
            "            <if test=\"maps.reportSn != null  and maps.reportSn != ''\"> and ior.report_sn = #{maps.reportSn}</if>\n" +
            "            <if test=\"maps.sTime != null \">  and DATE(ior.create_time) &gt;= DATE(#{maps.sTime})</if>\n" +
            "            <if test=\"maps.eTime != null \">  and DATE(ior.create_time) &lt;= DATE(#{maps.eTime})</if>\n" +
            "            <if test=\"maps.beginTime != null \">  and DATE(ior.create_time) &gt;= DATE(#{maps.beginTime})</if>\n" +
            "            <if test=\"maps.endTime != null \">  and DATE(ior.update_time) &lt;= DATE(#{maps.endTime})</if>\n" +
            "            <if test=\"maps.status != null \"> and ior.status = #{maps.status}</if>\n" +
            "            <if test=\"maps.fzName != null \"> and fz.nick_name = #{maps.fzName}</if>\n" +
            "            <if test=\"maps.userName != null \"> and su.nick_name = #{maps.userName}</if>\n" +
            "            <if test=\"maps.patientMobile != null \"> and fp.mobile = #{maps.patientMobile}</if>\n" +
            "            <if test=\"maps.phone != null  and maps.phone != ''\"> and u.phone = #{maps.phone}</if>\n" +
            "            <if test=\"maps.inquiryStatus != null \"> and fio.status = #{maps.inquiryStatus}</if>\n" +
            "            <if test=\"maps.companyId != null \"> and fio.company_id = #{maps.companyId}</if>\n" +
            "            <if test=\"maps.status != null and maps.status==0\" > and fio.status = 2</if>\n" +
            "            <if test=\"maps.patientName != null \"> and ior.patient_json like concat('%',#{maps.patientName},'%')</if>\n" +
            "            <if test = 'maps.inquirySubType != null    '>  and fio.inquiry_sub_type =#{maps.inquirySubType} </if>" +
            "            <if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=  \"\" '> and cuu.nick_name like concat( #{maps.companyUserNickName}, '%') </if>" +
            "         order by report_id desc"+
            "</script>"})
    List<FsInquiryOrderReportListVO> selectFsInquiryOrderReportListVO(@Param("maps") FsInquiryOrderReportParam fsInquiryOrderReport);


    @Select("select ior.*,u.nick_name,u.phone,d.doctor_name,su.nick_name user_name,send.nick_name send_name,fio.status inquiry_status,fio. inquiry_sub_type,fio.company_user_remark FROM fs_inquiry_order_report ior  LEFT JOIN fs_user u ON u.user_id=ior.user_id LEFT JOIN fs_doctor d ON d.doctor_id=ior.doctor_id LEFT JOIN sys_user su ON su.user_id=ior.audit_user_id LEFT JOIN fs_inquiry_order fio ON fio.order_id=ior.order_id LEFT JOIN fs_user_coupon fuc ON fuc.business_type =1 AND fuc.business_id=ior.order_id LEFT JOIN sys_user send ON send.user_id=fuc.send_user_id  where ior.report_id=#{reportId}")
    FsInquiryOrderReportVO selectFsInquiryOrderReportByReportIdVO(Long reportId);
    @Select("select report_id FROM fs_inquiry_order_report WHERE order_id=#{id}")
    Integer selectFsInquiryOrderReportIdByOrderId(Long id);
    @Select("select * FROM fs_inquiry_order_report   where order_id=#{orderId}")
    FsInquiryOrderReport selectFsInquiryOrderReportByOrderId(Long orderId);
    @Select("select o.*,d.dept_id FROM fs_inquiry_order_report o  LEFT JOIN fs_doctor d ON d.doctor_id=o.doctor_id   where o.order_id=#{orderId}")
    FsInquiryOrderReportUVO selectFsInquiryOrderReportUVOByOrderId(Long orderId);
    @Select("select item_type_json FROM fs_test_temp WHERE temp_code ='C1694077002122'")
    String selectFsTestBody();

    @Select("select * from fs_inquiry_order_report where patient_json LIKE '%https://htj-1258038825.cos.ap-beijing.myqcloud.com%' order by report_id desc limit 2 ")
    List<FsInquiryOrderReport> selectFsInquiryOrderReportListByUpdate();
    @Select("select ior.*,u.nick_name,u.phone,d.doctor_name,su.nick_name user_name,send.nick_name send_name,fio.status inquiry_status,fio. inquiry_sub_type,fio.company_user_remark FROM fs_inquiry_order_report ior  LEFT JOIN fs_user u ON u.user_id=ior.user_id LEFT JOIN fs_doctor d ON d.doctor_id=ior.doctor_id LEFT JOIN sys_user su ON su.user_id=ior.audit_user_id LEFT JOIN fs_inquiry_order fio ON fio.order_id=ior.order_id LEFT JOIN fs_user_coupon fuc ON fuc.business_type =1 AND fuc.business_id=ior.order_id LEFT JOIN sys_user send ON send.user_id=fuc.send_user_id  where ior.order_id=#{orderId} limit 1")
    FsInquiryOrderReportVO selectFsInquiryOrderReportByOrderIdVO(Long orderId);
    @Select({"<script> " +
            "select count(1) FROM fs_inquiry_order_report ior  " +
            " LEFT JOIN fs_user u ON u.user_id=ior.user_id " +
            " LEFT JOIN fs_doctor d ON d.doctor_id=ior.doctor_id " +
            " LEFT JOIN sys_user su ON su.user_id=ior.audit_user_id " +
            " LEFT JOIN fs_inquiry_order fio ON fio.order_id=ior.order_id " +
            " LEFT JOIN fs_user_coupon fuc ON  fuc.id=fio.user_coupon_id " +
            " LEFT JOIN sys_user send ON send.user_id=fuc.send_user_id " +
            " LEFT JOIN company c ON c.company_id=fio.company_id " +
            " LEFT JOIN company_user cuu ON cuu.user_id=fio.company_user_id " +
            " LEFT JOIN company_user fz ON fz.user_id=ior.triage_user_id " +
            " LEFT join fs_patient fp on ior.patient_id = fp.patient_id " +
            " WHERE fio.`status`!=1 and fio.inquiry_sub_type!=3"+
            "            <if test=\"maps.orderId != null \"> and fio.order_sn = #{maps.orderId}</if>\n" +
            "            <if test=\"maps.doctorName != null \"> and d.doctor_name = #{maps.doctorName}</if>\n" +
            "            <if test=\"maps.reportSn != null  and maps.reportSn != ''\"> and ior.report_sn = #{maps.reportSn}</if>\n" +
            "            <if test=\"maps.sTime != null \">  and DATE(ior.create_time) &gt;= DATE(#{maps.sTime})</if>\n" +
            "            <if test=\"maps.eTime != null \">  and DATE(ior.create_time) &lt;= DATE(#{maps.eTime})</if>\n" +
            "            <if test=\"maps.beginTime != null \">  and DATE(ior.create_time) &gt;= DATE(#{maps.beginTime})</if>\n" +
            "            <if test=\"maps.endTime != null \">  and DATE(ior.update_time) &lt;= DATE(#{maps.endTime})</if>\n" +
            "            <if test=\"maps.status != null \"> and ior.status = #{maps.status}</if>\n" +
            "            <if test=\"maps.fzName != null \"> and fz.nick_name = #{maps.fzName}</if>\n" +
            "            <if test=\"maps.userName != null \"> and su.nick_name = #{maps.userName}</if>\n" +
            "            <if test=\"maps.patientMobile != null \"> and fp.mobile = #{maps.patientMobile}</if>\n" +
            "            <if test=\"maps.phone != null  and maps.phone != ''\"> and u.phone = #{maps.phone}</if>\n" +
            "            <if test=\"maps.inquiryStatus != null \"> and fio.status = #{maps.inquiryStatus}</if>\n" +
            "            <if test=\"maps.companyId != null \"> and fio.company_id = #{maps.companyId}</if>\n" +
            "            <if test=\"maps.status != null and maps.status==0\" > and fio.status = 2</if>\n" +
            "            <if test=\"maps.patientName != null \"> and ior.patient_json like concat('%',#{maps.patientName},'%')</if>\n" +
            "            <if test = 'maps.inquirySubType != null    '>  and fio.inquiry_sub_type =#{maps.inquirySubType} </if>" +
            "            <if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=  \"\" '> and cuu.nick_name like concat( #{maps.companyUserNickName}, '%') </if>" +
            "         order by report_id desc"+
            "</script>"})
    Long selectFsInquiryOrderReportListVOCount(@Param("maps")FsInquiryOrderReportParam fsInquiryOrderReport);
}
