package com.fs.his.mapper;

import java.util.List;
import com.fs.his.domain.FsDrugReport;
import com.fs.his.param.FsDrugReportListDParam;
import com.fs.his.param.FsDrugReportListUParam;
import com.fs.his.vo.FsDrugReportDVO;
import com.fs.his.vo.FsDrugReportListDVO;
import com.fs.his.vo.FsDrugReportListUVO;
import com.fs.his.vo.FsDrugReportUVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.fs.his.param.FsDrugReportParam;
import com.fs.his.vo.FsDrugReportListVO;
import com.fs.his.vo.FsDrugReportVO;
import org.apache.ibatis.annotations.Select;

/**
 * 用药报告Mapper接口
 *
 * @author fs
 * @date 2024-04-23
 */
public interface FsDrugReportMapper
{
    /**
     * 查询用药报告
     *
     * @param reportId 用药报告主键
     * @return 用药报告
     */
    public FsDrugReport selectFsDrugReportByReportId(Long reportId);

    /**
     * 查询用药报告列表
     *
     * @param fsDrugReport 用药报告
     * @return 用药报告集合
     */
    public List<FsDrugReport> selectFsDrugReportList(FsDrugReport fsDrugReport);

    /**
     * 新增用药报告
     *
     * @param fsDrugReport 用药报告
     * @return 结果
     */
    public int insertFsDrugReport(FsDrugReport fsDrugReport);

    /**
     * 修改用药报告
     *
     * @param fsDrugReport 用药报告
     * @return 结果
     */
    public int updateFsDrugReport(FsDrugReport fsDrugReport);

    /**
     * 删除用药报告
     *
     * @param reportId 用药报告主键
     * @return 结果
     */
    public int deleteFsDrugReportByReportId(Long reportId);

    /**
     * 批量删除用药报告
     *
     * @param reportIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsDrugReportByReportIds(Long[] reportIds);
    @Select({"<script> " +
            "select r.*,d.doctor_name,d.avatar  from fs_drug_report r left join fs_doctor d on d.doctor_id=r.doctor_id    " +
            "where 1=1  " +
            "and r.report_id = #{reportId} " +
            " order by r.create_time desc "+
            "</script>"})
    FsDrugReportUVO selectFsDrugReportUVOByReportId(@Param("reportId")Long reportId);
    @Select({"<script> " +
            "select r.*,d.doctor_name,d.avatar  from fs_drug_report r left join fs_doctor d on d.doctor_id=r.doctor_id    " +
            "where 1=1  " +
            "<if test = ' maps.status!=null  '> " +
            "and r.status = #{maps.status} " +
            "</if>" +
            "and r.user_id = #{maps.userId} " +
            " order by r.create_time desc "+
            "</script>"})
    List<FsDrugReportListUVO> selectFsDrugReportListUVO(@Param("maps")FsDrugReportListUParam param);
    @Select({"<script> " +
            "select r.*,u.nick_name,u.avatar  from fs_drug_report r left join fs_user u on u.user_id=r.user_id   " +
            "where 1=1  " +

            "and r.report_id = #{reportId} " +
            " order by r.create_time desc "+
            "</script>"})
    FsDrugReportDVO selectFsDrugReportDVOByReportId(@Param("reportId")Long reportId);
    @Select({"<script> " +
            "select r.*,u.nick_name,u.avatar,c.company_name,cu.nick_name companyNickName,f.patient_name   from fs_drug_report r left join fs_user u on u.user_id=r.user_id  LEFT JOIN fs_follow f ON f.follow_id=r.follow_id LEFT JOIN company c on c.company_id = f.company_id LEFT JOIN company_user cu on cu.user_id =f.company_user_id   " +
            "where 1=1  " +
            "<if test = ' maps.status!=null  '> " +
            "and r.status = #{maps.status} " +
            "</if>" +
            "<if test = ' maps.companyId!=null  '> " +
            "and f.company_id = #{maps.companyId} " +
            "</if>" +
            "<if test = ' maps.pingStar !=null and maps.pingStar != \"\" '> " +
            "and r.ping_star = #{maps.pingStar} " +
            "</if>" +
            "<if test = ' maps.phone !=null and maps.phone != \"\" '> " +
            "and u.phone = #{maps.phone} " +
            "</if>" +
            "<if test = ' maps.patientName !=null and maps.patientName != \"\" '> " +
            "and f.patient_name = #{maps.patientName} " +
            "</if>" +
            "<if test = ' maps.companyUserNickName !=null and maps.companyUserNickName != \"\" '> " +
            "and cu.nick_name = #{maps.companyUserNickName} " +
            "</if>" +
            "<if test=\"maps.sTime != null \">  and DATE(r.create_time) &gt;= DATE(#{maps.sTime})</if>\n" +
            "<if test=\"maps.eTime != null \">  and DATE(r.create_time) &lt;= DATE(#{maps.eTime})</if>\n" +
            "and r.doctor_id = #{maps.doctorId} " +
            " order by r.create_time desc "+
            "</script>"})
    List<FsDrugReportListDVO> selectFsDrugReportListDVO(@Param("maps")FsDrugReportListDParam param);
    @Select({"<script> " +
            "    select r.*,f.patient_name,d.doctor_name,d.account as doctor_account,o.order_code,c.company_name from fs_drug_report r " +
            " LEFT JOIN fs_follow f ON f.follow_id=r.follow_id " +
            " LEFT JOIN fs_doctor d ON d.doctor_id = r.doctor_id  " +
            " LEFT JOIN fs_store_order o on r.store_order_id= o.order_id  " +
            " left join company c on c.company_id = f.company_id " +
            "<where>\n" +
            "            <if test=\"userId != null \"> and r.user_id = #{userId}</if> " +
            "            <if test=\"doctorId != null \"> and r.doctor_id = #{doctorId}</if> " +
            "            <if test=\"doctorName != null \"> and d.doctor_name = #{doctorName}</if> " +
            "            <if test=\"patientName != null \"> and f.patient_name = #{patientName}</if> " +
            "            <if test=\"doctorAccount != null and doctorAccount!=''  \"> and d.account = #{doctorAccount}</if> " +
            "            <if test=\"companyId != null \"> and f.company_id = #{companyId}</if> " +
            "            <if test=\"orderCode != null \"> and o.order_code = #{orderCode}</if> " +
            "            <if test=\"followId != null \"> and r.follow_id = #{followId}</if> " +
            "            <if test=\"storeOrderId != null \"> and r.store_order_id = #{storeOrderId}</if> " +
            "            <if test=\"inquiryOrderId != null \"> and r.inquiry_order_id = #{inquiryOrderId}</if> " +
            "            <if test=\"status != null \"> and r.status = #{status}</if>\n" +
            "            <if test=\"reportSummary != null  and reportSummary != ''\"> and r.report_summary = #{reportSummary}</if> " +
            "            <if test=\"reportAdvice != null  and reportAdvice != ''\"> and r.report_advice = #{reportAdvice}</if> " +
            "            <if test=\"pingStar != null \"> and r.ping_star = #{pingStar}</if> " +
            "            <if test=\"pingTime != null \"> and r.ping_time = #{pingTime}</if> " +
            "            <if test=\"sTime != null \">  and DATE(r.create_time) &gt;= DATE(#{sTime})</if>\n" +
            "            <if test=\"eTime != null \">  and DATE(r.create_time) &lt;= DATE(#{eTime})</if>\n" +
            "</where> order by r.report_id desc"+
            "</script>"})
    List<FsDrugReportListVO> selectFsDrugReportListVO(FsDrugReportParam fsDrugReport);
    @Select("select r.*,f.patient_name,d.doctor_name,o.order_code from fs_drug_report r LEFT JOIN fs_follow f ON f.follow_id=r.follow_id LEFT JOIN fs_doctor d ON d.doctor_id = r.doctor_id  LEFT JOIN fs_store_order o on r.store_order_id= o.order_id  where r.report_id=#{reportId}")
    FsDrugReportVO selectFsDrugReportByReportIdVO(Long reportId);

}
