package com.fs.hospital.mapper;

import java.util.List;
import com.fs.hospital.domain.HospitalProductPurchaseOrder;
import com.fs.hospital.param.HospitalProductPurchaseOrderParam;
import com.fs.hospital.vo.HospitalProductPurchaseOrderHVO;
import com.fs.hospital.vo.HospitalProductPurchaseOrdeHVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 采购单Mapper接口
 *
 * @author fs
 * @date 2024-03-12
 */
public interface HospitalProductPurchaseOrderMapper
{
    /**
     * 查询采购单
     *
     * @param orderId 采购单主键
     * @return 采购单
     */
    public HospitalProductPurchaseOrder selectHospitalPurchaseOrderByOrderId(Long orderId);

    /**
     * 查询采购单列表
     *
     * @param hospitalProductPurchaseOrder 采购单
     * @return 采购单集合
     */
    public List<HospitalProductPurchaseOrder> selectHospitalPurchaseOrderList(HospitalProductPurchaseOrder hospitalProductPurchaseOrder);

    /**
     * 新增采购单
     *
     * @param hospitalProductPurchaseOrder 采购单
     * @return 结果
     */
    public int insertHospitalPurchaseOrder(HospitalProductPurchaseOrder hospitalProductPurchaseOrder);

    /**
     * 修改采购单
     *
     * @param hospitalProductPurchaseOrder 采购单
     * @return 结果
     */
    public int updateHospitalPurchaseOrder(HospitalProductPurchaseOrder hospitalProductPurchaseOrder);

    /**
     * 删除采购单
     *
     * @param orderId 采购单主键
     * @return 结果
     */
    public int deleteHospitalPurchaseOrderByOrderId(Long orderId);

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

    @Select({"<script> " +
            "select hpo.*,fs.store_name,hu.nick_name  from hospital_product_purchase_order hpo    " +
            "left join fs_store fs on fs.store_id = hpo.store_id " +
            "left join hospital_user hu on hu.user_id = hpo.user_id " +
            "where 1=1  " +
            "<if test = ' maps.hospitalId!=null  '> " +
            "and hpo.hospital_id = #{maps.hospitalId} " +
            "</if>" +
            "<if test = ' maps.storeId!=null  '> " +
            "and hpo.store_id = #{maps.storeId} " +
            "</if>" +
            "<if test = ' maps.nickName!=null and maps.nickName != \"\"  '> " +
            "and hu.nick_name like concat( #{maps.nickName}, '%') " +
            "</if>" +
            "<if test = ' maps.status!=null  '> " +
            "and hpo.status = #{maps.status} " +
            "</if>" +
            "<if test = ' maps.orderType!=null '> " +
            "and hpo.order_type = #{maps.orderType} " +
            "</if>" +
            " order by hpo.create_time desc "+
            "</script>"})
    List<HospitalProductPurchaseOrdeHVO> selectHospitalPurchaseOrderListPVO(@Param("maps") HospitalProductPurchaseOrderParam param);

    @Select("select o.*,u.nick_name as producer,h.hospital_name from hospital_product_purchase_order o " +
            "left join hospital_user u on u.user_id = o.user_id  " +
            "left join hospital h on h.hospital_id = o.hospital_id " +
            "where order_id = #{orderId}")
    HospitalProductPurchaseOrderHVO selectHospitalPurchaseOrderHVOByOrderId(Long orderId);
}
