package com.fs.hospital.mapper;

import java.util.Date;
import java.util.List;

import com.fs.hospital.domain.HospitalPharmacyOrder;
import com.fs.hospital.param.HospitalPharmacyOrderParam;
import com.fs.hospital.vo.HospitalPharmacyOrderHVO;
import com.fs.hospital.vo.HospitalPharmacyOrderListHVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * 药房订单Mapper接口
 *
 * @author fs
 * @date 2024-03-22
 */
public interface HospitalPharmacyOrderMapper
{
    /**
     * 查询药房订单
     *
     * @param orderId 药房订单主键
     * @return 药房订单
     */
//    public HospitalPharmacyOrder selectHospitalPharmacyOrderByOrderId(Long orderId);
    @Select("<script> " +
            "select h.*,hp.patient_name,hu.user_name,hp.sex,hn.hospital_name,hor.diagnose from hospital_pharmacy_order h    " +
            "left join hospital_patient hp on hp.patient_id = h.patient_id " +
            "left join hospital_user hu on h.user_id=hu.user_id "+
            "left join hospital hn on h.hospital_id=hn.hospital_id "+
            "left join hospital_outpatient_order hor on h.outpatient_order_id=hor.order_id "+
            "where h.order_id=#{orderId} " +
            " </script>")
    public HospitalPharmacyOrderHVO selectHospitalPharmacyOrderPVOByOrderId(Long orderId);


    /**
     * 查询药房订单列表
     *
     * @param hospitalPharmacyOrder 药房订单
     * @return 药房订单集合
     */
    public List<HospitalPharmacyOrder> selectHospitalPharmacyOrderList(HospitalPharmacyOrder hospitalPharmacyOrder);
    /**
     * 新增药房订单
     *
     * @param hospitalPharmacyOrder 药房订单
     * @return 结果
     */
    public int insertHospitalPharmacyOrder(HospitalPharmacyOrder hospitalPharmacyOrder);

    /**
     * 修改药房订单
     *
     * @param hospitalPharmacyOrder 药房订单
     * @return 结果
     */
    public int updateHospitalPharmacyOrder(HospitalPharmacyOrder hospitalPharmacyOrder);

    /**
     *  修改发药状态
     */
    @Update("update hospital_pharmacy_order set status= #{type} , update_time = NOW() where order_id=#{orderId}")
    public int UpdateDispensingHospitalPharmacyOrder(@Param("orderId") Long orderId,@Param("type") int type);

    /**
     * 删除药房订单
     *
     * @param orderId 药房订单主键
     * @return 结果
     */
    public int deleteHospitalPharmacyOrderByOrderId(Long orderId);

    /**
     * 批量删除药房订单
     *
     * @param orderIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteHospitalPharmacyOrderByOrderIds(Long[] orderIds);



    @Select({"<script> " +
            "select h.*,hp.patient_name,hu.user_name  from hospital_pharmacy_order h    " +
            "left join hospital_patient hp on hp.patient_id = h.patient_id " +
            "left join hospital_user hu on h.user_id=hu.user_id "+
            "where 1=1 " +
            "<if test = ' maps.hospitalId!=null and maps.hospitalId!=\"\" '> " +
            "and h.hospital_id = #{maps.hospitalId} " +
            "</if>" +
            "<if test = ' maps.status!=null and  maps.status!= \"\"'> " +
            "and h.status = #{maps.status} " +
            "</if>" +
            "<if test = \"maps.beginTime!=null and maps.beginTime!='' and maps.endTime!=null and maps.endTime!=''\"> " +
            "and h.create_time BETWEEN #{maps.beginTime} and #{maps.endTime} " +
            "</if>" +
            "<if test = ' maps.orderCode!=null and maps.orderCode!= \"\" '> " +
            "and h.order_code like concat('%', #{maps.orderCode}, '%') " +
            "</if>" +
            "<if test = ' maps.patientName!=null and maps.patientName != \"\"  '> " +
            "and hp.patient_name like concat('%', #{maps.patientName}, '%') " +
            "</if>" +
            " order by h.order_id desc "+
            "</script>"})
    List<HospitalPharmacyOrderListHVO> selectHospitalPharmacyOrderListHVO(@Param("maps") HospitalPharmacyOrderParam param);


}
