package cn.hnthyy.thmz.mapper.his;

import cn.hnthyy.thmz.entity.his.YpZdDict;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface YpZdDictMapper {
    /**
     * 根据药品编码和规格查询药品信息
     *
     * @param code
     * @return
     */
    @Select("select code,name,specification,mz_restrict,bill_item_mz,pack_retprice,country_flag,supply_type,pack_unit,weight,volum,weigh_unit,vol_unit,pack_size,manu_code,frequency,serial,drug_flag,mini_unit,ps_flag,retprice,fix_price,buy_price from yp_zd_dict where code = #{code,jdbcType=VARCHAR} and serial = #{serial}")
    YpZdDict selectYpZdDictByCodeAndSerial(@Param("code") String code,@Param("serial") String serial);

    /**
     * 根据药品编码集合查询药品字典列表
     *
     * @param codes
     * @return
     */
    @Select({"<script>",
            "select code,name,specification,mz_restrict,bill_item_mz,pack_retprice,country_flag,supply_type,pack_unit,weight,volum,weigh_unit,vol_unit,pack_size,manu_code,frequency,serial,drug_flag,mini_unit,ps_flag,retprice,fix_price,buy_price from yp_zd_dict",
            "<when test='codes!=null'>",
            " where code in",
            "<foreach item='item' index='index' collection='codes' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</when>",
            "</script>"})
    List<YpZdDict> selectYpZdDictByCodeList(@Param("codes") String codes);



    /**
     * 根据药品编码查询药品信息
     *
     * @param code
     * @return
     */
    @Select("select code,name,specification,mz_restrict,bill_item_mz,pack_retprice,country_flag,supply_type,pack_unit,weight,volum,weigh_unit,vol_unit,pack_size,manu_code,frequency,serial,drug_flag,mini_unit,ps_flag,retprice,fix_price,buy_price from yp_zd_dict where code = #{code,jdbcType=VARCHAR} ")
    List<YpZdDict> selectYpZdDictByCode(@Param("code") String code);

    /**
     * 模糊查询药品
     *
     * @param searchTextDrug
     * @return
     */
    @Select("select top 10 * from (SELECT distinct a.code," +
            "                a.serial," +
            "                a.name," +
            "                a.pack_size," +
            "                a.pack_retprice," +
            "                a.specification," +
            "                a.drug_flag  ," +
            "                a.fix_price," +
            "                a.manu_code," +
            "                a.del_flag" +
            " FROM yp_zd_dict a ,yp_print_name b , yp_base c" +
            " where" +
            "  (b.py_code like '${searchTextDrug}%' or a.py_code like '${searchTextDrug}%' or" +
            "  b.d_code  like '${searchTextDrug}%'  or a.d_code  like '${searchTextDrug}%' or" +
            "  b.charge_code = #{searchTextDrug} or" +
            "  b.print_name like '${searchTextDrug}%' or a.name like '${searchTextDrug}%') and" +
            "    a.code=b.charge_code and" +
            "    a.code=c.charge_code)cc")
    List<YpZdDict> selectYpBySearchText(@Param("searchTextDrug") String searchTextDrug);
}
