<?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.write.seller.StoreAddressWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.seller.pojo.StoreAddress">
    <id column="address_id" property="addressId" />
    <result column="store_id" property="storeId" />
    <result column="contact_name" property="contactName" />
    <result column="telphone" property="telphone" />
    <result column="telphone2" property="telphone2" />
    <result column="province_code" property="provinceCode" />
    <result column="city_code" property="cityCode" />
    <result column="area_code" property="areaCode" />
    <result column="street_code" property="streetCode" />
    <result column="area_info" property="areaInfo" />
    <result column="address" property="address" />
    <result column="created_time" property="createdTime" />
    <result column="update_time" property="updateTime" />
    <result column="is_default" property="isDefault" />
    <result column="type" property="type" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="storeId != null">
        `store_id`,
      </if>
      <if test="contactName != null">
        `contact_name`,
      </if>
      <if test="telphone != null">
        `telphone`,
      </if>
      <if test="telphone2 != null">
        `telphone2`,
      </if>
      <if test="provinceCode != null">
        `province_code`,
      </if>
      <if test="cityCode != null">
        `city_code`,
      </if>
      <if test="areaCode != null">
        `area_code`,
      </if>
      <if test="streetCode != null">
        `street_code`,
      </if>
      <if test="areaInfo != null">
        `area_info`,
      </if>
      <if test="address != null">
        `address`,
      </if>
      <if test="createdTime != null">
        `created_time`,
      </if>
      <if test="updateTime != null">
        `update_time`,
      </if>
      <if test="isDefault != null">
        `is_default`,
      </if>
      <if test="type != null">
        `type`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `address_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.addressIdNotEquals != null">
          AND `address_id` != #{example.addressIdNotEquals}
        </if>
        <if test="example.addressIdIn != null">
          AND `address_id` in (${example.addressIdIn})
        </if>
        <if test="example.storeId != null">
          AND `store_id` = #{example.storeId}
        </if>
        <if test="example.contactName != null">
          AND `contact_name` = #{example.contactName}
        </if>
        <if test="example.contactNameLike != null">
          AND `contact_name` like concat('%',#{example.contactNameLike},'%')
        </if>
        <if test="example.telphone != null">
          AND `telphone` = #{example.telphone}
        </if>
        <if test="example.telphone2 != null">
          AND `telphone2` = #{example.telphone2}
        </if>
        <if test="example.provinceCode != null">
          AND `province_code` = #{example.provinceCode}
        </if>
        <if test="example.cityCode != null">
          AND `city_code` = #{example.cityCode}
        </if>
        <if test="example.areaCode != null">
          AND `area_code` = #{example.areaCode}
        </if>
        <if test="example.streetCode != null">
          AND `street_code` = #{example.streetCode}
        </if>
        <if test="example.areaInfo != null">
          AND `area_info` = #{example.areaInfo}
        </if>
        <if test="example.address != null">
          AND `address` = #{example.address}
        </if>
        <if test="example.createdTimeAfter != null">
          AND `created_time` <![CDATA[ >= ]]> #{example.createdTimeAfter}
        </if>
        <if test="example.createdTimeBefore != null">
          AND `created_time` <![CDATA[ <= ]]> #{example.createdTimeBefore}
        </if>
        <if test="example.updateTimeAfter != null">
          AND `update_time` <![CDATA[ >= ]]> #{example.updateTimeAfter}
        </if>
        <if test="example.updateTimeBefore != null">
          AND `update_time` <![CDATA[ <= ]]> #{example.updateTimeBefore}
        </if>
        <if test="example.isDefault != null">
          AND `is_default` = #{example.isDefault}
        </if>
        <if test="example.type != null">
          AND `type` = #{example.type}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `address_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.seller.example.StoreAddressExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `store_address`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `store_address`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `store_address`
    <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 `store_address`
    <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 `store_address`
    <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 `store_address`
    <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>
  <!--根据条件删除记录，可多条删除-->
  <delete id="deleteByExample">
    DELETE FROM `store_address`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `store_address`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="address_id" keyProperty="addressId" parameterType="com.slodon.b2b2c.seller.pojo.StoreAddress" useGeneratedKeys="true">
    INSERT INTO `store_address`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="storeId != null">
        #{storeId},
      </if>
      <if test="contactName != null">
        #{contactName},
      </if>
      <if test="telphone != null">
        #{telphone},
      </if>
      <if test="telphone2 != null">
        #{telphone2},
      </if>
      <if test="provinceCode != null">
        #{provinceCode},
      </if>
      <if test="cityCode != null">
        #{cityCode},
      </if>
      <if test="areaCode != null">
        #{areaCode},
      </if>
      <if test="streetCode != null">
        #{streetCode},
      </if>
      <if test="areaInfo != null">
        #{areaInfo},
      </if>
      <if test="address != null">
        #{address},
      </if>
      <if test="createdTime != null">
        #{createdTime},
      </if>
      <if test="updateTime != null">
        #{updateTime},
      </if>
      <if test="isDefault != null">
        #{isDefault},
      </if>
      <if test="type != null">
        #{type},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `store_address`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.storeId != null">
        `store_id` = #{record.storeId},
      </if>
      <if test="record.contactName != null">
        `contact_name` = #{record.contactName},
      </if>
      <if test="record.telphone != null">
        `telphone` = #{record.telphone},
      </if>
      <if test="record.telphone2 != null">
        `telphone2` = #{record.telphone2},
      </if>
      <if test="record.provinceCode != null">
        `province_code` = #{record.provinceCode},
      </if>
      <if test="record.cityCode != null">
        `city_code` = #{record.cityCode},
      </if>
      <if test="record.areaCode != null">
        `area_code` = #{record.areaCode},
      </if>
      <if test="record.streetCode != null">
        `street_code` = #{record.streetCode},
      </if>
      <if test="record.areaInfo != null">
        `area_info` = #{record.areaInfo},
      </if>
      <if test="record.address != null">
        `address` = #{record.address},
      </if>
      <if test="record.createdTime != null">
        `created_time` = #{record.createdTime},
      </if>
      <if test="record.updateTime != null">
        `update_time` = #{record.updateTime},
      </if>
      <if test="record.isDefault != null">
        `is_default` = #{record.isDefault},
      </if>
      <if test="record.type != null">
        `type` = #{record.type},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `store_address`
    <trim prefix="SET" suffixOverrides=",">
      <if test="storeId != null">
        `store_id` = #{storeId},
      </if>
      <if test="contactName != null">
        `contact_name` = #{contactName},
      </if>
      <if test="telphone != null">
        `telphone` = #{telphone},
      </if>
      <if test="telphone2 != null">
        `telphone2` = #{telphone2},
      </if>
      <if test="provinceCode != null">
        `province_code` = #{provinceCode},
      </if>
      <if test="cityCode != null">
        `city_code` = #{cityCode},
      </if>
      <if test="areaCode != null">
        `area_code` = #{areaCode},
      </if>
      <if test="streetCode != null">
        `street_code` = #{streetCode},
      </if>
      <if test="areaInfo != null">
        `area_info` = #{areaInfo},
      </if>
      <if test="address != null">
        `address` = #{address},
      </if>
      <if test="createdTime != null">
        `created_time` = #{createdTime},
      </if>
      <if test="updateTime != null">
        `update_time` = #{updateTime},
      </if>
      <if test="isDefault != null">
        `is_default` = #{isDefault},
      </if>
      <if test="type != null">
        `type` = #{type},
      </if>
    </trim>
    WHERE `address_id` = #{addressId}
  </update>
</mapper>