<?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.msg.SmsCodeWriteMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.msg.pojo.SmsCode">
    <id column="code_id" property="codeId" />
    <result column="member_id" property="memberId" />
    <result column="member_name" property="memberName" />
    <result column="mobile" property="mobile" />
    <result column="verify_code" property="verifyCode" />
    <result column="sms_type" property="smsType" />
    <result column="request_ip" property="requestIp" />
    <result column="create_time" property="createTime" />
  </resultMap>
  <!--除主键外的所有字段，用于插入操作-->
  <sql id="columns">
    <trim suffixOverrides=",">
      <if test="memberId != null">
        `member_id`,
      </if>
      <if test="memberName != null">
        `member_name`,
      </if>
      <if test="mobile != null">
        `mobile`,
      </if>
      <if test="verifyCode != null">
        `verify_code`,
      </if>
      <if test="smsType != null">
        `sms_type`,
      </if>
      <if test="requestIp != null">
        `request_ip`,
      </if>
      <if test="createTime != null">
        `create_time`,
      </if>
    </trim>
  </sql>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `code_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.codeIdNotEquals != null">
          AND `code_id` != #{example.codeIdNotEquals}
        </if>
        <if test="example.codeIdIn != null">
          AND `code_id` in (${example.codeIdIn})
        </if>
        <if test="example.memberId != null">
          AND `member_id` = #{example.memberId}
        </if>
        <if test="example.memberName != null">
          AND `member_name` = #{example.memberName}
        </if>
        <if test="example.memberNameLike != null">
          AND `member_name` like concat('%',#{example.memberNameLike},'%')
        </if>
        <if test="example.mobile != null">
          AND `mobile` = #{example.mobile}
        </if>
        <if test="example.verifyCode != null">
          AND `verify_code` = #{example.verifyCode}
        </if>
        <if test="example.smsType != null">
          AND `sms_type` = #{example.smsType}
        </if>
        <if test="example.requestIp != null">
          AND `request_ip` = #{example.requestIp}
        </if>
        <if test="example.createTimeAfter != null">
          AND `create_time` <![CDATA[ >= ]]> #{example.createTimeAfter}
        </if>
        <if test="example.createTimeBefore != null">
          AND `create_time` <![CDATA[ <= ]]> #{example.createTimeBefore}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `code_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.msg.example.SmsCodeExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `msg_sms_code`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `msg_sms_code`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `msg_sms_code`
    <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 `msg_sms_code`
    <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 `msg_sms_code`
    <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 `msg_sms_code`
    <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 `msg_sms_code`
    <include refid="whereCondition" />
  </delete>
  <!--根据主键删除记录-->
  <delete id="deleteByPrimaryKey">
    DELETE FROM `msg_sms_code`
    <include refid="pkWhere" />
  </delete>
  <!--插入一条记录-->
  <insert id="insert" keyColumn="code_id" keyProperty="codeId" parameterType="com.slodon.b2b2c.msg.pojo.SmsCode" useGeneratedKeys="true">
    INSERT INTO `msg_sms_code`(
    <include refid="columns" />
    )
    VALUES(
    <trim suffixOverrides=",">
      <if test="memberId != null">
        #{memberId},
      </if>
      <if test="memberName != null">
        #{memberName},
      </if>
      <if test="mobile != null">
        #{mobile},
      </if>
      <if test="verifyCode != null">
        #{verifyCode},
      </if>
      <if test="smsType != null">
        #{smsType},
      </if>
      <if test="requestIp != null">
        #{requestIp},
      </if>
      <if test="createTime != null">
        #{createTime},
      </if>
    </trim>
    )
  </insert>
  <!--按条件更新记录中不为空的字段-->
  <update id="updateByExampleSelective">
    UPDATE `msg_sms_code`
    <trim prefix="SET" suffixOverrides=",">
      <if test="record.memberId != null">
        `member_id` = #{record.memberId},
      </if>
      <if test="record.memberName != null">
        `member_name` = #{record.memberName},
      </if>
      <if test="record.mobile != null">
        `mobile` = #{record.mobile},
      </if>
      <if test="record.verifyCode != null">
        `verify_code` = #{record.verifyCode},
      </if>
      <if test="record.smsType != null">
        `sms_type` = #{record.smsType},
      </if>
      <if test="record.requestIp != null">
        `request_ip` = #{record.requestIp},
      </if>
      <if test="record.createTime != null">
        `create_time` = #{record.createTime},
      </if>
    </trim>
    <include refid="whereCondition" />
  </update>
  <!--按照主键更新记录中不为空的字段-->
  <update id="updateByPrimaryKeySelective">
    UPDATE `msg_sms_code`
    <trim prefix="SET" suffixOverrides=",">
      <if test="memberId != null">
        `member_id` = #{memberId},
      </if>
      <if test="memberName != null">
        `member_name` = #{memberName},
      </if>
      <if test="mobile != null">
        `mobile` = #{mobile},
      </if>
      <if test="verifyCode != null">
        `verify_code` = #{verifyCode},
      </if>
      <if test="smsType != null">
        `sms_type` = #{smsType},
      </if>
      <if test="requestIp != null">
        `request_ip` = #{requestIp},
      </if>
      <if test="createTime != null">
        `create_time` = #{createTime},
      </if>
    </trim>
    WHERE `code_id` = #{codeId}
  </update>
</mapper>