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

import cn.hnthyy.thmz.entity.his.mz.YpZdClass;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface YpZdClassMapper {
    /**
     * 查询所有的药品分类
     *
     * @return
     */
    @Select("  SELECT py_code,d_code wb_code,code,name FROM yp_zd_class where isnull(del_flag,'0')='0'  order by code")
    List<YpZdClass> selectYpZdClasses();

    /**
     * 查询所有检验分类
     *
     * @return
     */
    @Select("SELECT dl_code=a.code,dl_name=a.name,xl_code=b.code,xl_name=b.name FROM jy_zd_class  a,jy_zd_item b  where  a.code*=b.class and isnull(b.del_flag,'') <> '1'  order  by a.code ")
    List<Map<String, Object>> selectJyZdClasses();


    /**
     * 查询所有检查分类
     *
     * @return
     */
    @Select("SELECT dl_code=a.code+b.bw_code,dl_name=rtrim(a.name)+' '+ltrim(c.name),xl_code=b.code,xl_name=b.name FROM jc_zd_class a,jc_zd_item b,ysh_zd_part_code c " +
            "where a.code*=b.class and isnull(b.del_flag,'') <> '1' and b.bw_code=c.code union SELECT dl_code=a.code,dl_name=rtrim(a.name),xl_code=b.code,xl_name=b.name FROM jc_zd_class " +
            " a,jc_zd_item b where a.code*=b.class and isnull(b.del_flag,'') <> '1' and (b.bw_code is null or b.bw_code='')")
    List<Map<String, Object>> selectJcZdClasses();

    /**
     * 根据code查询药品分类
     * @param code
     * @return
     */
    @Select(" SELECT py_code,d_code wb_code,code,name FROM yp_zd_class where isnull(del_flag,'0')='0' and code like #{code} order by code")
    List<YpZdClass> selectYpZdClassesByCode(String code);

    /**
     * 根据code查询当前药品分类是否为父节点
     * @param code
     * @return
     */
    @Select(" SELECT (case when count(1)>1 then 1 else 0 end ) FROM yp_zd_class where isnull(del_flag,'0')='0' and code like #{code}")
    int selectIsParent(String code);
}
