package com.fs.hospital.mapper;

import java.util.List;
import com.fs.hospital.domain.HospitalProductOutOrder;
import com.fs.hospital.vo.HospitalProductOutOrderHVO;
import com.fs.hospital.vo.HospitalProductOutOrderListHVO;
import org.apache.ibatis.annotations.Select;

/**
 * 领用单Mapper接口
 *
 * @author fs
 * @date 2024-03-14
 */
public interface HospitalProductOutOrderMapper
{
    /**
     * 查询领用单
     *
     * @param orderId 领用单主键
     * @return 领用单
     */
    public HospitalProductOutOrder selectHospitalProductOutOrderByOrderId(Long orderId);

    /**
     * 查询领用单列表
     *
     * @param hospitalProductOutOrder 领用单
     * @return 领用单集合
     */
    public List<HospitalProductOutOrder> selectHospitalProductOutOrderList(HospitalProductOutOrder hospitalProductOutOrder);

    /**
     * 新增领用单
     *
     * @param hospitalProductOutOrder 领用单
     * @return 结果
     */
    public int insertHospitalProductOutOrder(HospitalProductOutOrder hospitalProductOutOrder);

    /**
     * 修改领用单
     *
     * @param hospitalProductOutOrder 领用单
     * @return 结果
     */
    public int updateHospitalProductOutOrder(HospitalProductOutOrder hospitalProductOutOrder);

    /**
     * 删除领用单
     *
     * @param orderId 领用单主键
     * @return 结果
     */
    public int deleteHospitalProductOutOrderByOrderId(Long orderId);

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

    @Select({"<script> " +
            " select o.*,s.store_name,u.nick_name from hospital_product_out_order o LEFT JOIN fs_store s ON s.store_id= o.store_id LEFT JOIN hospital_user u ON u.user_id=o.user_id" +
            "<where>  \n" +
            "            <if test=\"orderCode != null  and orderCode != ''\"> and o.order_code = #{orderCode}</if>\n" +
            "            <if test=\"storeId != null \"> and o.store_id = #{storeId}</if>\n" +
            "            <if test=\"hospitalId != null \"> and o.hospital_id = #{hospitalId}</if>\n" +
            "            <if test=\"userId != null \"> and o.user_id = #{userId}</if>\n" +
            "            <if test=\"totalCount != null \"> and o.total_count = #{totalCount}</if>\n" +
            "            <if test=\"productCount != null \"> and o.product_count = #{productCount}</if>\n" +
            "            <if test=\"orderType != null \"> and o.order_type = #{orderType}</if>\n" +
            "            <if test=\"money != null \"> and o.money = #{money}</if>\n" +
            "            <if test=\"status != null \"> and o.status = #{status}</if>\n" +
            "        </where>"+
            " order by o.order_id desc"+
            "</script>"})
    List<HospitalProductOutOrderListHVO> selectHospitalProductOutOrderListPVO(HospitalProductOutOrder hospitalProductOutOrder);
    @Select("select o.*,s.store_name,u.nick_name,h.hospital_name from hospital_product_out_order o LEFT JOIN fs_store s ON s.store_id= o.store_id LEFT JOIN hospital_user u ON u.user_id=o.user_id LEFT JOIN hospital h ON h.hospital_id=o.hospital_id where o.order_id=#{orderId}")
    HospitalProductOutOrderHVO selectHospitalProductOutOrderByOrderIdHVO(Long orderId);


    @Select({"<script> " +
            " select o.*,s.store_name,u.nick_name from hospital_product_out_order o LEFT JOIN fs_store s ON s.store_id= o.store_id LEFT JOIN hospital_user u ON u.user_id=o.user_id " +
            " where  (o.order_type = 1 or o.order_type = 2)" +
            "            <if test=\"orderCode != null  and orderCode != ''\"> and o.order_code = #{orderCode}</if>\n" +
            "            <if test=\"storeId != null \"> and o.store_id = #{storeId}</if>\n" +
            "            <if test=\"hospitalId != null \"> and o.hospital_id = #{hospitalId}</if>\n" +
            "            <if test=\"userId != null \"> and o.user_id = #{userId}</if>\n" +
            "            <if test=\"totalCount != null \"> and o.total_count = #{totalCount}</if>\n" +
            "            <if test=\"productCount != null \"> and o.product_count = #{productCount}</if>\n" +
            "            <if test=\"orderType != null \"> and o.order_type = #{orderType} </if>\n" +
            "            <if test=\"money != null \"> and o.money = #{money}</if>\n" +
            "            <if test=\"status != null \"> and o.status = #{status}</if>\n" +
            " order by o.order_id desc"+
            "</script>"})
    List<HospitalProductOutOrderListHVO> selectHospitalProductOutOrderOutListPVO(HospitalProductOutOrder hospitalProductOutOrder);
}
