<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
                                <mapper namespace="com.crm.manager.dao.mapper.SysCountryMapper">

    <select id="countList" resultType="integer"
            parameterType="com.crm.rely.backend.core.entity.country.SysCountrySearchListEntity">

        select count(*) from sys_country
        <where>
            <if test="code!=null and code!=''">
                and `code`=#{code}
            </if>
            <if test="name!=null and name!=''">
                and `name` like concat(#{name},"%")
            </if>
            <if test="enName!=null and enName!=''">
                and `en_name`=#{enName}
            </if>
            <if test="pid!=null">
                and `pid`=#{pid}
            </if>
            <if test="validForStarted!=null">
                and `valid_for_started`=#{validForStarted}
            </if>
            <if test="callingCode!=null and callingCode!=''">
                and `calling_code`=#{callingCode}
            </if>
        </where>
    </select>

    <select id="pageList" resultType="com.crm.rely.backend.core.pojo.table.SysCountryTable"
            parameterType="com.crm.rely.backend.core.entity.country.SysCountrySearchListEntity">
        select * from sys_country
        <where>
            <if test="code!=null and code!=''">
                and `code`=#{code}
            </if>
            <if test="name!=null and name!=''">
                and `name` like concat(#{name},"%")
            </if>
            <if test="enName!=null and enName!=''">
                and `en_name`= #{enName}
            </if>
            <if test="pid!=null">
                and `pid`=#{pid}
            </if>
            <if test="validForStarted!=null">
                and `valid_for_started`=#{validForStarted}
            </if>
            <if test="callingCode!=null and callingCode!=''">
                and `calling_code`=#{callingCode}
            </if>
        </where>
        <if test="page!=null">
            limit #{page.offset},#{page.row}
        </if>
    </select>

    <select id="getFirstById"  resultType="com.crm.rely.backend.core.dto.country.SysCountrySearchListDto">
        select a.*,b.name pName,b.en_name pEnName from sys_country a left join sys_country b on a.pid = b.id where a.id = #{id}
    </select>

</mapper>