<?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.slodon.b2b2c.dao.read.system.RegionDistrictReadMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.system.pojo.RegionDistrict">
    <id column="id" property="id" />
    <id column="native_code" property="nativeCode" />
    <result column="district_name" property="districtName" />
    <result column="city_name" property="cityName" />
    <result column="city_code" property="cityCode" />
    <result column="country_code" property="countryCode" />
    <result column="country_name" property="countryName" />
    <result column="province_code" property="provinceCode" />
    <result column="province_name" property="provinceName" />
    <result column="remark_code" property="remarkCode" />
    <result column="region_level" property="regionLevel" />
  </resultMap>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.idNotEquals != null">
          AND `id` != #{example.idNotEquals}
        </if>
        <if test="example.idIn != null">
          AND `id` in (${example.idIn})
        </if>
        <if test="example.districtName != null">
          AND `district_name` = #{example.districtName}
        </if>
        <if test="example.districtNameLike != null">
          AND `district_name` like concat('%',#{example.districtNameLike},'%')
        </if>
        <if test="example.cityName != null">
          AND `city_name` = #{example.cityName}
        </if>
        <if test="example.cityNameLike != null">
          AND `city_name` like concat('%',#{example.cityNameLike},'%')
        </if>
        <if test="example.cityCode != null">
          AND `city_code` = #{example.cityCode}
        </if>
        <if test="example.countryCode != null">
          AND `country_code` = #{example.countryCode}
        </if>
        <if test="example.countryName != null">
          AND `country_name` = #{example.countryName}
        </if>
        <if test="example.countryNameLike != null">
          AND `country_name` like concat('%',#{example.countryNameLike},'%')
        </if>
        <if test="example.provinceCode != null">
          AND `province_code` = #{example.provinceCode}
        </if>
        <if test="example.provinceName != null">
          AND `province_name` = #{example.provinceName}
        </if>
        <if test="example.provinceNameLike != null">
          AND `province_name` like concat('%',#{example.provinceNameLike},'%')
        </if>
        <if test="example.remarkCode != null">
          AND `remark_code` = #{example.remarkCode}
        </if>
        <if test="example.regionLevel != null">
          AND `region_level` = #{example.regionLevel}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `id` DESC
  </sql>
  <sql id="orderByOther">
    order by ${example.orderBy}
  </sql>
  <!--分组条件-->
  <sql id="groupBy">
    group by ${example.groupBy}
  </sql>
  <!--分页条件-->
  <sql id="limit">
    <if test="size != null and size &gt; 0">
      limit #{startRow},#{size}
    </if>
  </sql>
  <!--查询符合条件的记录数-->
  <select id="countByExample" parameterType="com.slodon.b2b2c.system.example.RegionDistrictExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `sys_region_district`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `sys_region_district`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `sys_region_district`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(所有字段)-->
  <select id="listPageByExample" resultMap="resultMap">
    SELECT
      *
    FROM `sys_region_district`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--查询符合条件的记录(指定字段)-->
  <select id="listFieldsByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `sys_region_district`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(指定字段)-->
  <select id="listFieldsPageByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `sys_region_district`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
</mapper>