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

    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="area_name" jdbcType="VARCHAR" property="areaName" />
    <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="customer_user_id" jdbcType="BIGINT" property="customerUserId" />
    <result column="purchase_user_id" jdbcType="BIGINT" property="purchaseUserId" />
    <result column="customer_users" jdbcType="VARCHAR" property="customerUsers" />
    <result column="purchase_users" jdbcType="VARCHAR" property="purchaseUsers" />
  </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, area_name, remarks, create_time, create_user_id, update_time, update_user_id, 
    customer_user_id, purchase_user_id, customer_users, purchase_users
  </sql>
  <select id="selectByExample" parameterType="cn.superdesk.uniorder.dao.entity.marketing.department.UnifiedAreaExample" resultMap="BaseResultMap">

    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from unified_area
    <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
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">

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

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

    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into unified_area (area_name, remarks, create_time, 
      create_user_id, update_time, update_user_id, 
      customer_user_id, purchase_user_id, customer_users, 
      purchase_users)
    values (#{areaName,jdbcType=VARCHAR}, #{remarks,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{createUserId,jdbcType=BIGINT}, #{updateTime,jdbcType=TIMESTAMP}, #{updateUserId,jdbcType=BIGINT}, 
      #{customerUserId,jdbcType=BIGINT}, #{purchaseUserId,jdbcType=BIGINT}, #{customerUsers,jdbcType=VARCHAR}, 
      #{purchaseUsers,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" parameterType="cn.superdesk.uniorder.dao.entity.marketing.department.UnifiedArea">

    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into unified_area
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="areaName != null">
        area_name,
      </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="customerUserId != null">
        customer_user_id,
      </if>
      <if test="purchaseUserId != null">
        purchase_user_id,
      </if>
      <if test="customerUsers != null">
        customer_users,
      </if>
      <if test="purchaseUsers != null">
        purchase_users,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="areaName != null">
        #{areaName,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="customerUserId != null">
        #{customerUserId,jdbcType=BIGINT},
      </if>
      <if test="purchaseUserId != null">
        #{purchaseUserId,jdbcType=BIGINT},
      </if>
      <if test="customerUsers != null">
        #{customerUsers,jdbcType=VARCHAR},
      </if>
      <if test="purchaseUsers != null">
        #{purchaseUsers,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="cn.superdesk.uniorder.dao.entity.marketing.department.UnifiedAreaExample" resultType="java.lang.Long">

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

    update unified_area
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.areaName != null">
        area_name = #{record.areaName,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.customerUserId != null">
        customer_user_id = #{record.customerUserId,jdbcType=BIGINT},
      </if>
      <if test="record.purchaseUserId != null">
        purchase_user_id = #{record.purchaseUserId,jdbcType=BIGINT},
      </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>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">

    update unified_area
    set id = #{record.id,jdbcType=BIGINT},
      area_name = #{record.areaName,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},
      customer_user_id = #{record.customerUserId,jdbcType=BIGINT},
      purchase_user_id = #{record.purchaseUserId,jdbcType=BIGINT},
      customer_users = #{record.customerUsers,jdbcType=VARCHAR},
      purchase_users = #{record.purchaseUsers,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.UnifiedArea">

    update unified_area
    <set>
      <if test="areaName != null">
        area_name = #{areaName,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="customerUserId != null">
        customer_user_id = #{customerUserId,jdbcType=BIGINT},
      </if>
      <if test="purchaseUserId != null">
        purchase_user_id = #{purchaseUserId,jdbcType=BIGINT},
      </if>
      <if test="customerUsers != null">
        customer_users = #{customerUsers,jdbcType=VARCHAR},
      </if>
      <if test="purchaseUsers != null">
        purchase_users = #{purchaseUsers,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="cn.superdesk.uniorder.dao.entity.marketing.department.UnifiedArea">

    update unified_area
    set area_name = #{areaName,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},
      customer_user_id = #{customerUserId,jdbcType=BIGINT},
      purchase_user_id = #{purchaseUserId,jdbcType=BIGINT},
      customer_users = #{customerUsers,jdbcType=VARCHAR},
      purchase_users = #{purchaseUsers,jdbcType=VARCHAR}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>