package com.fs.hospital.mapper;

import java.util.List;
import com.fs.hospital.domain.HospitalTreatOrder;
import com.fs.hospital.param.HospitalTreatOrderHParam;
import com.fs.hospital.vo.HospitalTreatOrderHVO;
import com.fs.hospital.vo.HospitalTreatOrderListHVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 治疗单Mapper接口
 *
 * @author fs
 * @date 2024-03-22
 */
public interface HospitalTreatOrderMapper
{
    /**
     * 查询治疗单
     *
     * @param orderId 治疗单主键
     * @return 治疗单
     */
    public HospitalTreatOrder selectHospitalTreatOrderByOrderId(Long orderId);

    /**
     * 查询治疗单列表
     *
     * @param hospitalTreatOrder 治疗单
     * @return 治疗单集合
     */
    public List<HospitalTreatOrder> selectHospitalTreatOrderList(HospitalTreatOrder hospitalTreatOrder);

    /**
     * 新增治疗单
     *
     * @param hospitalTreatOrder 治疗单
     * @return 结果
     */
    public int insertHospitalTreatOrder(HospitalTreatOrder hospitalTreatOrder);

    /**
     * 修改治疗单
     *
     * @param hospitalTreatOrder 治疗单
     * @return 结果
     */
    public int updateHospitalTreatOrder(HospitalTreatOrder hospitalTreatOrder);

    /**
     * 删除治疗单
     *
     * @param orderId 治疗单主键
     * @return 结果
     */
    public int deleteHospitalTreatOrderByOrderId(Long orderId);

    /**
     * 批量删除治疗单
     *
     * @param orderIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteHospitalTreatOrderByOrderIds(Long[] orderIds);
    @Select({"<script>  " +
            "    select o.*,p.patient_name from hospital_treat_order o left join hospital_patient p on o.patient_id = p.patient_id " +
            "   <where>  \n" +
            "            <if test=\"orderCode != null  and orderCode != ''\"> and o.order_code = #{orderCode}</if>\n" +
            "            <if test=\"title != null  and title != ''\"> and o.title = #{title}</if>\n" +
            "            <if test=\"hospitalId != null \"> and o.hospital_id = #{hospitalId}</if>\n" +
            "            <if test=\"outpatientOrderId != null \"> and o.outpatient_order_id = #{outpatientOrderId}</if>\n" +
            "            <if test=\"orderType != null \"> and o.order_type = #{orderType}</if>\n" +
            "            <if test=\"userId != null \"> and o.user_id = #{userId}</if>\n" +
            "            <if test=\"patientName != null \"> and p.patient_name LIKE CONCAT('%', #{patientName}, '%')</if>\n"+
            "            <if test=\"patientId != null \"> and o.patient_id = #{patientId}</if>\n" +
            "            <if test=\"beginTime!=null and beginTime!='' and endTime!=null and endTime!=''\"> " +
            "            and o.create_time BETWEEN #{beginTime} and #{endTime} " +
            "            </if>" +
            "            <if test=\"patientJson != null  and patientJson != ''\"> and o.patient_json = #{patientJson}</if>\n" +
            "            <if test=\"status != null \"> and o.status = #{status}</if>\n" +
            "        </where> order by o.order_id desc "+
            "</script>"})
    List<HospitalTreatOrderListHVO> selectHospitalTreatOrderListHVO(HospitalTreatOrderHParam hospitalTreatOrder);

    @Select("select ht.*,ho.status as order_status,ho.pay_money,hu.nick_name as doctor_name from hospital_treat_order ht " +
            " left join hospital_order ho on ht.order_id = ho.treat_order_id " +
            " left join hospital_user hu on ht.user_id = hu.user_id " +
            " where ht.order_id = #{orderId}")
    HospitalTreatOrderHVO selectHospitalTreatOrderHVOByOrderId(@Param("orderId") Long orderId);
}
