package com.ywt.mg.domain.ywtDrugEntities;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface PrescriptionDrugViewRepository extends JpaRepository<PrescriptionDrugView, Integer> {

    /**
     * 查找某一段时间内，某一药品的使用数量（要发药成功才算）
     *
     * @param drugCode
     * @param startTime
     * @param endTime
     * @return
     */
    @Query(value = "select sum(quantity) from prescription_drug_view where drug_code = ? and  start_send_time >= ?  and start_send_time <= ?", nativeQuery = true)
    public int getDrugUseCountByDurgCode(String drugCode, String startTime, String endTime);

    /**
     * 查找某一段时间内，发药出去的总金额（要发药成功才算）
     *
     * @param startTime
     * @param endTime
     * @return
     */
    @Query(value = "select sum(total_price) from prescription_drug_view where  start_send_time >= ?  and start_send_time <= ?", nativeQuery = true)
    public int getDrugUseTotalPriceBySearchTime(String startTime, String endTime);

}