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.YpZdDosage;

import java.util.List;

@Mapper
public interface YpZdDosageDao extends BaseMapper<YpZdDosage> {

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

    @Select(" select * from yp_zd_dosage where code = #{code} ")
    YpZdDosage selectYpDosageByCode(@Param("code") String code);

    @Update("<script>" +
            "update yp_zd_dosage " +
            "<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=\"delFlag != null and delFlag != '' \">" +
            "del_flag = #{delFlag}, " +
            "</if>" +
            "<if test=\"dosaType != null and dosaType != '' \">" +
            "dosa_type = #{dosaType}, " +
            "</if>" +
            "<if test=\"dosaRemark != null and dosaRemark != '' \">" +
            "dosa_remark = #{dosaRemark}, " +
            "</if>" +
            "<if test=\"orderNo != null and orderNo != '' \">" +
            "order_no = #{orderNo}, " +
            "</if>" +
            "<if test=\"ybCode != null and ybCode != '' \">" +
            "yb_code = #{ybCode}, " +
            "</if>" +
            "<if test=\"hnsybCode != null and hnsybCode != '' \">" +
            "hnsyb_code = #{hnsybCode}, " +
            "</if>" +
            "</trim>" +
            "where code = #{code} " +
            "</script>")
    int updateYpDosageByCode(YpZdDosage ypZdDosage);

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

    @Select("select rtrim(code) as code, rtrim(name) as name, isnull(del_flag, '0') as statusFlag, " +
            " case when del_flag = '1' then 'true' else 'false' end as disabled " +
            "from yp_zd_dosage with(nolock) order by code ")
    List<CodeName> selectYpDosageCode();

}
