<?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.younike.system.mapper.AccessPasscodeMapper">
  <resultMap id="BaseResultMap" type="com.younike.system.domain.AccessPasscode">
    <id column="access_passcode_id" jdbcType="BIGINT" property="accessPasscodeId" />
    <result column="qr_code_url" jdbcType="VARCHAR" property="qrCodeUrl" />
    <result column="order_id" jdbcType="BIGINT" property="orderId" />
    <result column="order_index" jdbcType="VARCHAR" property="orderIndex" />
    <result column="merchant_id" jdbcType="BIGINT" property="merchantId" />
    <result column="order_verification_code" jdbcType="VARCHAR" property="orderVerificationCode" />
    <result column="del_flag" jdbcType="CHAR" property="delFlag" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="remark" jdbcType="VARCHAR" property="remark" />
  </resultMap>

  <sql id="Base_Column_List">
    access_passcode_id, qr_code_url, order_id, order_index, merchant_id, order_verification_code, 
    del_flag, create_by, create_time, update_by, update_time, remark
  </sql>

  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from access_passcode
    where access_passcode_id = #{accessPasscodeId,jdbcType=BIGINT}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from access_passcode
    where access_passcode_id = #{accessPasscodeId,jdbcType=BIGINT}
  </delete>

  <insert id="insert" parameterType="com.younike.system.domain.AccessPasscode">
    <selectKey keyProperty="accessPasscodeId" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into access_passcode (qr_code_url, order_id, order_index, 
      merchant_id, order_verification_code, del_flag, 
      create_by, create_time, update_by, 
      update_time, remark)
    values (#{qrCodeUrl,jdbcType=VARCHAR}, #{orderId,jdbcType=BIGINT}, #{orderIndex,jdbcType=VARCHAR}, 
      #{merchantId,jdbcType=BIGINT}, #{orderVerificationCode,jdbcType=VARCHAR}, #{delFlag,jdbcType=CHAR}, 
      #{createBy,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=VARCHAR}, 
      #{updateTime,jdbcType=TIMESTAMP}, #{remark,jdbcType=VARCHAR})
  </insert>

  <insert id="insertSelective" parameterType="com.younike.system.domain.AccessPasscode">
    insert into access_passcode
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="accessPasscodeId != null">
        access_passcode_id,
      </if>
      <if test="qrCodeUrl != null and qrCodeUrl != ''">
        qr_code_url,
      </if>
      <if test="orderId != null">
        order_id,
      </if>
      <if test="orderIndex != null and orderIndex != ''">
        order_index,
      </if>
      <if test="merchantId != null">
        merchant_id,
      </if>
      <if test="orderVerificationCode != null and orderVerificationCode != ''">
        order_verification_code,
      </if>
      <if test="delFlag != null and delFlag != ''">
        del_flag,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="updateBy != null">
        update_by,
      </if>
      <if test="updateTime != null">
        update_time,
      </if>
      <if test="remark != null and remark != ''">
        remark,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="accessPasscodeId != null">
        #{accessPasscodeId,jdbcType=BIGINT},
      </if>
      <if test="qrCodeUrl != null and qrCodeUrl != ''">
        #{qrCodeUrl,jdbcType=VARCHAR},
      </if>
      <if test="orderId != null">
        #{orderId,jdbcType=BIGINT},
      </if>
      <if test="orderIndex != null and orderIndex != ''">
        #{orderIndex,jdbcType=VARCHAR},
      </if>
      <if test="merchantId != null">
        #{merchantId,jdbcType=BIGINT},
      </if>
      <if test="orderVerificationCode != null and orderVerificationCode != ''">
        #{orderVerificationCode,jdbcType=VARCHAR},
      </if>
      <if test="delFlag != null and delFlag != ''">
        #{delFlag,jdbcType=CHAR},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null and remark != ''">
        #{remark,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.younike.system.domain.AccessPasscode">
    update access_passcode
    <set>
      <if test="qrCodeUrl != null and qrCodeUrl != ''">
        qr_code_url = #{qrCodeUrl,jdbcType=VARCHAR},
      </if>
      <if test="orderId != null">
        order_id = #{orderId,jdbcType=BIGINT},
      </if>
      <if test="orderIndex != null and orderIndex != ''">
        order_index = #{orderIndex,jdbcType=VARCHAR},
      </if>
      <if test="merchantId != null">
        merchant_id = #{merchantId,jdbcType=BIGINT},
      </if>
      <if test="orderVerificationCode != null and orderVerificationCode != ''">
        order_verification_code = #{orderVerificationCode,jdbcType=VARCHAR},
      </if>
      <if test="delFlag != null and delFlag != ''">
        del_flag = #{delFlag,jdbcType=CHAR},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateBy != null">
        update_by = #{updateBy,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="remark != null and remark != ''">
        remark = #{remark,jdbcType=VARCHAR},
      </if>
    </set>
    where access_passcode_id = #{accessPasscodeId,jdbcType=BIGINT}
  </update>

  <update id="updateByPrimaryKey" parameterType="com.younike.system.domain.AccessPasscode">
    update access_passcode
    set qr_code_url = #{qrCodeUrl,jdbcType=VARCHAR},
      order_id = #{orderId,jdbcType=BIGINT},
      order_index = #{orderIndex,jdbcType=VARCHAR},
      merchant_id = #{merchantId,jdbcType=BIGINT},
      order_verification_code = #{orderVerificationCode,jdbcType=VARCHAR},
      del_flag = #{delFlag,jdbcType=CHAR},
      create_by = #{createBy,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_by = #{updateBy,jdbcType=VARCHAR},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      remark = #{remark,jdbcType=VARCHAR}
    where access_passcode_id = #{accessPasscodeId,jdbcType=BIGINT}
  </update>

  <!--根据订单id和核销码查询门岗通行证-->
  <select id="selectByOrderIdAndOrderVerificationCode" resultType="com.younike.system.domain.AccessPasscode">
    SELECT
    <include refid="Base_Column_List" />
    FROM access_passcode
    WHERE order_id = #{orderId}
    <if test="orderVerificationCode != null and orderVerificationCode != ''">
     AND order_verification_code = #{orderVerificationCode}
    </if>
  </select>
</mapper>