<?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="cn.superdesk.uniorder.dao.mapper.marketing.department.UnifiedAreaCityMapper">
  <resultMap id="BaseResultMap" type="cn.superdesk.uniorder.dao.entity.marketing.department.UnifiedAreaCity">

    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="parent_id" jdbcType="BIGINT" property="parentId" />
    <result column="lev" jdbcType="INTEGER" property="lev" />
    <result column="area_name" jdbcType="VARCHAR" property="areaName" />
    <result column="area_code" jdbcType="VARCHAR" property="areaCode" />
    <result column="customer_users" jdbcType="VARCHAR" property="customerUsers" />
    <result column="purchase_users" jdbcType="VARCHAR" property="purchaseUsers" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_user_id" jdbcType="BIGINT" property="createUserId" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="update_user_id" jdbcType="BIGINT" property="updateUserId" />
    <result column="area_full_names" jdbcType="VARCHAR" property="areaFullNames" />
    <result column="area_full_ids" jdbcType="VARCHAR" property="areaFullIds" />
  </resultMap>
  <sql id="Example_Where_Clause">

    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">

    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">

    id, parent_id, lev, area_name, area_code, customer_users, purchase_users, remarks, 
    create_time, create_user_id, update_time, update_user_id, area_full_names, area_full_ids
  </sql>
  <select id="selectByExample" parameterType="cn.superdesk.uniorder.dao.entity.marketing.department.UnifiedAreaCityExample" resultMap="BaseResultMap">

    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from unified_area_city
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">

    select 
    <include refid="Base_Column_List" />
    from unified_area_city
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">

    delete from unified_area_city
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="cn.superdesk.uniorder.dao.entity.marketing.department.UnifiedAreaCityExample">

    delete from unified_area_city
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="cn.superdesk.uniorder.dao.entity.marketing.department.UnifiedAreaCity">

    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into unified_area_city (parent_id, lev, area_name, 
      area_code, customer_users, purchase_users, 
      remarks, create_time, create_user_id, 
      update_time, update_user_id, area_full_names, 
      area_full_ids)
    values (#{parentId,jdbcType=BIGINT}, #{lev,jdbcType=INTEGER}, #{areaName,jdbcType=VARCHAR}, 
      #{areaCode,jdbcType=VARCHAR}, #{customerUsers,jdbcType=VARCHAR}, #{purchaseUsers,jdbcType=VARCHAR}, 
      #{remarks,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{createUserId,jdbcType=BIGINT}, 
      #{updateTime,jdbcType=TIMESTAMP}, #{updateUserId,jdbcType=BIGINT}, #{areaFullNames,jdbcType=VARCHAR}, 
      #{areaFullIds,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="cn.superdesk.uniorder.dao.entity.marketing.department.UnifiedAreaCity">

    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into unified_area_city
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="parentId != null">
        parent_id,
      </if>
      <if test="lev != null">
        lev,
      </if>
      <if test="areaName != null">
        area_name,
      </if>
      <if test="areaCode != null">
        area_code,
      </if>
      <if test="customerUsers != null">
        customer_users,
      </if>
      <if test="purchaseUsers != null">
        purchase_users,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createUserId != null">
        create_user_id,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="updateUserId != null">
        update_user_id,
      </if>
      <if test="areaFullNames != null">
        area_full_names,
      </if>
      <if test="areaFullIds != null">
        area_full_ids,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="parentId != null">
        #{parentId,jdbcType=BIGINT},
      </if>
      <if test="lev != null">
        #{lev,jdbcType=INTEGER},
      </if>
      <if test="areaName != null">
        #{areaName,jdbcType=VARCHAR},
      </if>
      <if test="areaCode != null">
        #{areaCode,jdbcType=VARCHAR},
      </if>
      <if test="customerUsers != null">
        #{customerUsers,jdbcType=VARCHAR},
      </if>
      <if test="purchaseUsers != null">
        #{purchaseUsers,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUserId != null">
        #{createUserId,jdbcType=BIGINT},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUserId != null">
        #{updateUserId,jdbcType=BIGINT},
      </if>
      <if test="areaFullNames != null">
        #{areaFullNames,jdbcType=VARCHAR},
      </if>
      <if test="areaFullIds != null">
        #{areaFullIds,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="cn.superdesk.uniorder.dao.entity.marketing.department.UnifiedAreaCityExample" resultType="java.lang.Long">

    select count(*) from unified_area_city
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">

    update unified_area_city
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.parentId != null">
        parent_id = #{record.parentId,jdbcType=BIGINT},
      </if>
      <if test="record.lev != null">
        lev = #{record.lev,jdbcType=INTEGER},
      </if>
      <if test="record.areaName != null">
        area_name = #{record.areaName,jdbcType=VARCHAR},
      </if>
      <if test="record.areaCode != null">
        area_code = #{record.areaCode,jdbcType=VARCHAR},
      </if>
      <if test="record.customerUsers != null">
        customer_users = #{record.customerUsers,jdbcType=VARCHAR},
      </if>
      <if test="record.purchaseUsers != null">
        purchase_users = #{record.purchaseUsers,jdbcType=VARCHAR},
      </if>
      <if test="record.remarks != null">
        remarks = #{record.remarks,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createUserId != null">
        create_user_id = #{record.createUserId,jdbcType=BIGINT},
      </if>
      <if test="record.updateTime != null">
        update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.updateUserId != null">
        update_user_id = #{record.updateUserId,jdbcType=BIGINT},
      </if>
      <if test="record.areaFullNames != null">
        area_full_names = #{record.areaFullNames,jdbcType=VARCHAR},
      </if>
      <if test="record.areaFullIds != null">
        area_full_ids = #{record.areaFullIds,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">

    update unified_area_city
    set id = #{record.id,jdbcType=BIGINT},
      parent_id = #{record.parentId,jdbcType=BIGINT},
      lev = #{record.lev,jdbcType=INTEGER},
      area_name = #{record.areaName,jdbcType=VARCHAR},
      area_code = #{record.areaCode,jdbcType=VARCHAR},
      customer_users = #{record.customerUsers,jdbcType=VARCHAR},
      purchase_users = #{record.purchaseUsers,jdbcType=VARCHAR},
      remarks = #{record.remarks,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      create_user_id = #{record.createUserId,jdbcType=BIGINT},
      update_time = #{record.updateTime,jdbcType=TIMESTAMP},
      update_user_id = #{record.updateUserId,jdbcType=BIGINT},
      area_full_names = #{record.areaFullNames,jdbcType=VARCHAR},
      area_full_ids = #{record.areaFullIds,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="cn.superdesk.uniorder.dao.entity.marketing.department.UnifiedAreaCity">

    update unified_area_city
    <set>
      <if test="parentId != null">
        parent_id = #{parentId,jdbcType=BIGINT},
      </if>
      <if test="lev != null">
        lev = #{lev,jdbcType=INTEGER},
      </if>
      <if test="areaName != null">
        area_name = #{areaName,jdbcType=VARCHAR},
      </if>
      <if test="areaCode != null">
        area_code = #{areaCode,jdbcType=VARCHAR},
      </if>
      <if test="customerUsers != null">
        customer_users = #{customerUsers,jdbcType=VARCHAR},
      </if>
      <if test="purchaseUsers != null">
        purchase_users = #{purchaseUsers,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        remarks = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUserId != null">
        create_user_id = #{createUserId,jdbcType=BIGINT},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateUserId != null">
        update_user_id = #{updateUserId,jdbcType=BIGINT},
      </if>
      <if test="areaFullNames != null">
        area_full_names = #{areaFullNames,jdbcType=VARCHAR},
      </if>
      <if test="areaFullIds != null">
        area_full_ids = #{areaFullIds,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.superdesk.uniorder.dao.entity.marketing.department.UnifiedAreaCity">

    update unified_area_city
    set parent_id = #{parentId,jdbcType=BIGINT},
      lev = #{lev,jdbcType=INTEGER},
      area_name = #{areaName,jdbcType=VARCHAR},
      area_code = #{areaCode,jdbcType=VARCHAR},
      customer_users = #{customerUsers,jdbcType=VARCHAR},
      purchase_users = #{purchaseUsers,jdbcType=VARCHAR},
      remarks = #{remarks,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_user_id = #{createUserId,jdbcType=BIGINT},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      update_user_id = #{updateUserId,jdbcType=BIGINT},
      area_full_names = #{areaFullNames,jdbcType=VARCHAR},
      area_full_ids = #{areaFullIds,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>