package thyyxxk.webserver.dao.his.zygl;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.zygl.CodeNameEntity;

import java.util.List;

/**
 * 城市分类
 */
public interface RegionDao {
    /**
     * 查询所有的省份
     * @return
     */
    @Select("select code,name,parent_code from t_region where level=1 and del_flag = 0")
    List<CodeNameEntity> selectProvince();

    /**
     * 根据区域编码查询
     * @param code
     * @return
     */
    @Select("select code,name,parent_code from t_region where code=#{code}")
    CodeNameEntity selectByCode(@Param("code") String code);

    /**
     * 根据父类码查询所有的下级区域
     * @param parentCode
     * @return
     */
    @Select("select code,name,parent_code from t_region where parent_code=#{parentCode} and del_flag = 0")
    List<CodeNameEntity> selectByParentCode(@Param("parentCode") String parentCode);

    /**
     * 根据区域名称查询
     * @param name
     * @param parentCode 父元素id 一级节点可以没有
     * @return
     */
    @Select({"<script>",
            "select code,name,parent_code from t_region where name=#{name}",
            "<when test='parentCode!=null'>",
            " and parent_code=#{parentCode} ",
            "</when>",
            "</script>"})
    CodeNameEntity selectByName(@Param("name") String name, @Param("parentCode") String parentCode);

    /**
     * 查询所有
     * @return
     */
    @Select("select code,name,parent_code from t_region where del_flag = 0")
    List<CodeNameEntity> selectAll();
    /**
     * @description:
     * @author: lihong
     * @date: 2025/2/12 16:07
     * @param: district
     * @return: java.util.List<cn.hnthyy.thmz.entity.his.mz.CodeNameEntity>
     **/
    @Select("select code,name,parent_code from t_region where name=#{name}")
    List<CodeNameEntity> getByName(@Param("name") String name);
}
