package thyyxxk.webserver.dao.his.medicine;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.dictionary.CodeName;
import thyyxxk.webserver.entity.medicine.YpZdDrugKind;

import java.util.List;

@Mapper
public interface YpZdDrugKindDao extends BaseMapper<YpZdDrugKind> {

    @Select(" select ki.* from yp_zd_drug_kind as ki " +
            " where ki.code like '%${text}%' or ki.name like '%${text}%' " +
            " or ki.py_code like ('%' + upper(#{text}) + '%') or ki.d_code like ('%' + upper(#{text}) + '%') " +
            " order by ki.code ")
    List<YpZdDrugKind> selectDrugKind(@Param("text") String text);

    @Select(" select * from yp_zd_drug_kind where code = #{code} ")
    YpZdDrugKind selectDrugKindByCode(@Param("code") String code);

    @Update("<script>" +
            "update yp_zd_drug_kind " +
            "<trim prefix=\"set\" suffixOverrides=\",\">" +
            "<if test=\"code != null and code != '' \">" +
            "code = #{code}, " +
            "</if>" +
            "<if test=\"name != null and name != '' \">" +
            "name = #{name}, " +
            "</if>" +
            "<if test=\"pyCode != null and pyCode != '' \">" +
            "py_code = #{pyCode}, " +
            "</if>" +
            "<if test=\"dCode != null and dCode != '' \">" +
            "d_code = #{dCode}, " +
            "</if>" +
            "<if test=\"ypType != null and ypType != '' \">" +
            "yp_type = #{ypType}, " +
            "</if>" +
            "<if test=\"mzBillCode != null and mzBillCode != '' \">" +
            "mz_bill_code = #{mzBillCode}, " +
            "</if>" +
            "<if test=\"zyBillCode != null and zyBillCode != '' \">" +
            "zy_bill_code = #{zyBillCode}, " +
            "</if>" +
            "</trim>" +
            "where code = #{code} " +
            "</script>")
    int updateDrugKindByCode(YpZdDrugKind ypZdClass);

    @Delete(" delete from yp_zd_drug_kind where code = #{code} ")
    int deleteDrugKindByCode(@Param("code") String code);

    @Select("select rtrim(code) as code, rtrim(name) as name from yp_zd_drug_kind with(nolock) order by code")
    List<CodeName> selectDrugKindCode();

}
