package cn.hnthyy.thmz.mapper.his.zd;

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

import java.util.List;

public interface MzZdYpYshMapper {
    /**
     * 根据通用查询参数和药房编码查询有锁定库存的药品
     *
     * @param commonParams
     * @param letterParamsUpperCase 字母大写参数  因为老系统区分大小写，但是又不能改数据库结构，所以需要兼容
     * @param letterParamsLowerCase 字母小写参数  因为老系统区分大小写，但是又不能改数据库结构，所以需要兼容
     * @param groupNo
     * @return
     */
    @Select({
            "<script>",
            "SELECT  ",
            "<when test='commonParams==null'>",
            " top 20 ",
            "</when>",
            "code,serial,name,specification,charge_amount,manufactory,mini_unit,group_no,stock_amount_virtual,drug_win,yp_type=71 ",
            "    FROM view_mz_zd_yp_ysh(nolock) ",
            "where  stock_amount_virtual <![CDATA[>]]> 0 and (case when bill_code='TC' or group_no='00' then  '71' else group_no end)=#{groupNo}  ",
            "<when test='commonParams!=null'>",
            " and (py_code like #{commonParams} or d_code  like #{commonParams} or code like #{commonParams} or name like #{commonParams} or class_code like #{commonParams}",
            "<when test='letterParamsLowerCase!=null'>",
            " or py_code like #{letterParamsLowerCase} or d_code  like #{letterParamsLowerCase} or code like #{letterParamsLowerCase} or name like #{letterParamsLowerCase}  ",
            "</when>",
            "<when test='letterParamsUpperCase!=null'>",
            " or py_code like #{letterParamsUpperCase} or d_code  like #{letterParamsUpperCase} or code like #{letterParamsUpperCase} or name like #{letterParamsUpperCase}  ",
            "</when>",
            ") ",
            "</when>",
            "GROUP BY code,serial, name,specification,charge_amount,manufactory,mini_unit,group_no,stock_amount_virtual,drug_win order by stock_amount_virtual desc",
            "</script>"})
    List<MzZdYpYsh> selectMzZdYpYshByCommonParamsAndGroupNo(@Param("commonParams") String commonParams, @Param("letterParamsLowerCase") String letterParamsLowerCase, @Param("letterParamsUpperCase") String letterParamsUpperCase, @Param("groupNo") String groupNo);





    /**
     * 根据通用查询参数查询有锁定库存的医材
     *
     * @param commonParams
     * @param letterParamsUpperCase 字母大写参数  因为老系统区分大小写，但是又不能改数据库结构，所以需要兼容
     * @param letterParamsLowerCase 字母小写参数  因为老系统区分大小写，但是又不能改数据库结构，所以需要兼容
     * @param pageSize 查询的数据条数
     * @return
     */
    @Select({
            "<script>",
            "SELECT  ",
            "<when test='pageSize!=null'>",
            " top ${pageSize} ",
            "</when>",
            " code=rtrim(a.charge_code),serial=rtrim(a.serial),name=rtrim(b.name),specification=b.specification,charge_amount=a.pack_retprice,manufactory=c.name,mini_unit=b.mini_unit,group_no=a.group_no,stock_amount_virtual=a.stock_amount_virtual,drug_win=1,yp_type=91  ",
            "    FROM yp_base_yf a LEFT JOIN yp_zd_dict b on a.charge_code = b.code and a.serial = b.serial  LEFT JOIN yp_zd_manufactory c on a.charge_code = c.code ",
            "where  a.stock_amount_virtual <![CDATA[>]]> 0 and a.group_no ='91' ",
            "<when test='commonParams!=null'>",
            " and (b.py_code like #{commonParams} or b.d_code  like #{commonParams} or b.code like #{commonParams} or b.name like #{commonParams} or b.class_code like #{commonParams}",
            "<when test='letterParamsLowerCase!=null'>",
            " or b.py_code like #{letterParamsLowerCase} or b.d_code  like #{letterParamsLowerCase} or b.code like #{letterParamsLowerCase} or b.name like #{letterParamsLowerCase}  ",
            "</when>",
            "<when test='letterParamsUpperCase!=null'>",
            " or b.py_code like #{letterParamsUpperCase} or b.d_code  like #{letterParamsUpperCase} or b.code like #{letterParamsUpperCase} or b.name like #{letterParamsUpperCase}  ",
            "</when>",
            ") ",
            "</when>",
            " order by a.stock_amount_virtual desc",
            "</script>"})
    List<MzZdYpYsh> selectYcByCommonParams(@Param("commonParams") String commonParams, @Param("letterParamsLowerCase") String letterParamsLowerCase, @Param("letterParamsUpperCase") String letterParamsUpperCase,@Param("pageSize") Integer pageSize);


    /**
     * 根据通用查询参数查询有锁定库存的麻，精一
     * @param commonParams
     * @param letterParamsUpperCase 字母大写参数  因为老系统区分大小写，但是又不能改数据库结构，所以需要兼容
     * @param letterParamsLowerCase 字母小写参数  因为老系统区分大小写，但是又不能改数据库结构，所以需要兼容
     * @param pageSize 查询的数据条数
     * @return
     */
    @Select({
            "<script>",
            "SELECT  distinct ",
            "<when test='pageSize!=null'>",
            " top ${pageSize} ",
            "</when>",
            "  code=rtrim(code),serial,name,specification,charge_amount,manufactory=yb_comment,mini_unit,group_no,stock_amount_virtual,drug_win,yp_type=111  ",
            "    FROM view_mz_zd_yp_dm(nolock) ",
            "where  stock_amount_virtual <![CDATA[>]]> 0 ",
            "<when test='commonParams!=null'>",
            " and (py_code like #{commonParams} or d_code  like #{commonParams} or code like #{commonParams} or name like #{commonParams} or class_code like #{commonParams}",
            "<when test='letterParamsLowerCase!=null'>",
            " or py_code like #{letterParamsLowerCase} or d_code  like #{letterParamsLowerCase} or code like #{letterParamsLowerCase} or name like #{letterParamsLowerCase}  ",
            "</when>",
            "<when test='letterParamsUpperCase!=null'>",
            " or py_code like #{letterParamsUpperCase} or d_code  like #{letterParamsUpperCase} or code like #{letterParamsUpperCase} or name like #{letterParamsUpperCase}  ",
            "</when>",
            ") ",
            "</when>",
            " order by stock_amount_virtual desc",
            "</script>"})
    List<MzZdYpYsh> selectMjyByCommonParams(@Param("commonParams") String commonParams, @Param("letterParamsLowerCase") String letterParamsLowerCase, @Param("letterParamsUpperCase") String letterParamsUpperCase,@Param("pageSize") Integer pageSize);



    /**
     * 根据通用查询参数查询有锁定库存的精二
     * @param commonParams
     * @param letterParamsUpperCase 字母大写参数  因为老系统区分大小写，但是又不能改数据库结构，所以需要兼容
     * @param letterParamsLowerCase 字母小写参数  因为老系统区分大小写，但是又不能改数据库结构，所以需要兼容
     * @param pageSize 查询的数据条数
     * @return
     */
    @Select({
            "<script>",
            "SELECT  distinct ",
            "<when test='pageSize!=null'>",
            " top ${pageSize} ",
            "</when>",
            "  code=rtrim(code),serial,name,specification,charge_amount,manufactory=yb_comment,mini_unit,group_no,stock_amount_virtual,drug_win,yp_type=131   ",
            "    FROM view_mz_zd_yp_dm_j2(nolock)  ",
            "where  stock_amount_virtual <![CDATA[>]]> 0 ",
            "<when test='commonParams!=null'>",
            " and (py_code like #{commonParams} or d_code  like #{commonParams} or code like #{commonParams} or name like #{commonParams} or class_code like #{commonParams}",
            "<when test='letterParamsLowerCase!=null'>",
            " or py_code like #{letterParamsLowerCase} or d_code  like #{letterParamsLowerCase} or code like #{letterParamsLowerCase} or name like #{letterParamsLowerCase}  ",
            "</when>",
            "<when test='letterParamsUpperCase!=null'>",
            " or py_code like #{letterParamsUpperCase} or d_code  like #{letterParamsUpperCase} or code like #{letterParamsUpperCase} or name like #{letterParamsUpperCase}  ",
            "</when>",
            ") ",
            "</when>",
            " order by stock_amount_virtual desc",
            "</script>"})
    List<MzZdYpYsh> selectJeByCommonParams(@Param("commonParams") String commonParams, @Param("letterParamsLowerCase") String letterParamsLowerCase, @Param("letterParamsUpperCase") String letterParamsUpperCase,@Param("pageSize") Integer pageSize);




}
