<?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.AccessPasscodeVerifyRecordMapper">
  <resultMap id="BaseResultMap" type="com.younike.system.domain.AccessPasscodeVerifyRecord">
    <id column="access_passcode_verify_record_id" jdbcType="BIGINT" property="accessPasscodeVerifyRecordId" />
    <result column="access_passcode_id" jdbcType="BIGINT" property="accessPasscodeId" />
    <result column="verifier_phone_num" jdbcType="VARCHAR" property="verifierPhoneNum" />
    <result column="verifier_wx_nickname" jdbcType="VARCHAR" property="verifierWxNickname" />
    <result column="verifier_phone_model" jdbcType="VARCHAR" property="verifierPhoneModel" />
    <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>
  <resultMap id="AccessPasscodeVOResultMap" type="com.younike.system.domain.vo.AccessPasscodeVO">
    <id column="access_passcode_verify_record_id" jdbcType="BIGINT" property="accessPasscodeVerifyRecordId" />
    <result column="access_passcode_id" jdbcType="BIGINT" property="accessPasscodeId" />
    <result column="verifier_phone_num" jdbcType="VARCHAR" property="verifierPhoneNum" />
    <result column="verifier_wx_nickname" jdbcType="VARCHAR" property="verifierWxNickname" />
    <result column="verifier_phone_model" jdbcType="VARCHAR" property="verifierPhoneModel" />
    <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" />
    <result column="access_passcode_id" property="accessPasscodeId" />
    <result column="order_id" property="orderId" />
    <result column="order_index" property="orderIndex" />
    <result column="merchant_id" property="merchantId" />
    <result column="merchant_index" property="merchantIndex" />
    <result column="merchant_type" property="merchantType" />
    <result column="merchant_name" property="merchantName" />
    <result column="appointment_start_time" property="appointmentStartTime" />
    <result column="order_type" property="orderType" />
    <result column="address" property="address" />
    <result column="detailed" property="detailed" />
    <result column="memberName" property="memberName" />
    <result column="serverName" property="serverName" />
    <result column="memberPhone" property="memberPhone" />
    <result column="serverPhone" property="serverPhone" />
    <result column="goodsName" property="goodsName" />
    <result column="appointment_time" property="appointmentTime" />
  </resultMap>

  <sql id="Base_Column_List">
    access_passcode_verify_record_id, access_passcode_id, verifier_phone_num, verifier_wx_nickname,
    verifier_phone_model, 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_verify_record
    where access_passcode_verify_record_id = #{accessPasscodeVerifyRecordId,jdbcType=BIGINT}
  </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from access_passcode_verify_record
    where access_passcode_verify_record_id = #{accessPasscodeVerifyRecordId,jdbcType=BIGINT}
  </delete>

  <insert id="insert" parameterType="com.younike.system.domain.AccessPasscodeVerifyRecord">
    <selectKey keyProperty="accessPasscodeVerifyRecordId" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into access_passcode_verify_record (access_passcode_id, verifier_phone_num,
      verifier_wx_nickname, verifier_phone_model,
      del_flag, create_by, create_time,
      update_by, update_time, remark
      )
    values (#{accessPasscodeId,jdbcType=BIGINT}, #{verifierPhoneNum,jdbcType=VARCHAR},
      #{verifierWxNickname,jdbcType=VARCHAR}, #{verifierPhoneModel,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.AccessPasscodeVerifyRecord">
    insert into access_passcode_verify_record
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="accessPasscodeVerifyRecordId != null">
        access_passcode_verify_record_id,
      </if>
      <if test="accessPasscodeId != null">
        access_passcode_id,
      </if>
      <if test="verifierPhoneNum != null and verifierPhoneNum != ''">
        verifier_phone_num,
      </if>
      <if test="verifierWxNickname != null and verifierWxNickname != ''">
        verifier_wx_nickname,
      </if>
      <if test="verifierPhoneModel != null and verifierPhoneModel != ''">
        verifier_phone_model,
      </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="accessPasscodeVerifyRecordId != null">
        #{accessPasscodeVerifyRecordId,jdbcType=BIGINT},
      </if>
      <if test="accessPasscodeId != null">
        #{accessPasscodeId,jdbcType=BIGINT},
      </if>
      <if test="verifierPhoneNum != null and verifierPhoneNum != ''">
        #{verifierPhoneNum,jdbcType=VARCHAR},
      </if>
      <if test="verifierWxNickname != null and verifierWxNickname != ''">
        #{verifierWxNickname,jdbcType=VARCHAR},
      </if>
      <if test="verifierPhoneModel != null and verifierPhoneModel != ''">
        #{verifierPhoneModel,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.AccessPasscodeVerifyRecord">
    update access_passcode_verify_record
    <set>
      <if test="accessPasscodeId != null">
        access_passcode_id = #{accessPasscodeId,jdbcType=BIGINT},
      </if>
      <if test="verifierPhoneNum != null and verifierPhoneNum != ''">
        verifier_phone_num = #{verifierPhoneNum,jdbcType=VARCHAR},
      </if>
      <if test="verifierWxNickname != null and verifierWxNickname != ''">
        verifier_wx_nickname = #{verifierWxNickname,jdbcType=VARCHAR},
      </if>
      <if test="verifierPhoneModel != null and verifierPhoneModel != ''">
        verifier_phone_model = #{verifierPhoneModel,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_verify_record_id = #{accessPasscodeVerifyRecordId,jdbcType=BIGINT}
  </update>

  <update id="updateByPrimaryKey" parameterType="com.younike.system.domain.AccessPasscodeVerifyRecord">
    update access_passcode_verify_record
    set access_passcode_id = #{accessPasscodeId,jdbcType=BIGINT},
      verifier_phone_num = #{verifierPhoneNum,jdbcType=VARCHAR},
      verifier_wx_nickname = #{verifierWxNickname,jdbcType=VARCHAR},
      verifier_phone_model = #{verifierPhoneModel,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_verify_record_id = #{accessPasscodeVerifyRecordId,jdbcType=BIGINT}
  </update>

  <select id="selectByAccessPasscodeId" resultType="com.younike.system.domain.AccessPasscodeVerifyRecord">
    select
    <include refid="Base_Column_List" />
    from access_passcode_verify_record
    where access_passcode_id = #{accessPasscodeId}
  </select>

<!--  查询门岗通行记录列表-->
  <select id="selectAccessPasscodeVoList" parameterType="com.younike.system.domain.vo.AccessPasscodeVO" resultMap="AccessPasscodeVOResultMap">
     select opvr.access_passcode_verify_record_id,
      opvr.access_passcode_id,
      opvr.verifier_phone_num,
      opvr.verifier_wx_nickname,
      opvr.create_time,
      ap.order_id,
      ap.order_index,
      ap.merchant_id,
      m.merchant_index,
      m.merchant_type,
      m.merchant_name,
      o.appointment_start_time,
      o.order_type,
      oa.address,
      oa.detailed,
      oa.name as memberName,
      oa.phone as memberPhone,
      su.real_name as serverName,
      su.phone as serverPhone,
      og.name as goodsName,
      ovr.appointment_time
    from
      access_passcode_verify_record opvr
      LEFT JOIN access_passcode ap on opvr.access_passcode_id=ap.access_passcode_id
      LEFT JOIN `order` o on ap.order_id=o.order_id
      LEFT JOIN merchant  m on ap.merchant_id=m.merchant_id
      LEFT JOIN order_address oa on ap.order_id=oa.order_id
      LEFT JOIN order_goods_server ogs on ap.order_id=ogs.order_id
      LEFT JOIN server_user su on ogs.server_id=su.server_id
      LEFT JOIN order_goods og on ap.order_id=og.order_id
      LEFT JOIN order_verification_record ovr on ovr.order_id=ap.order_id and ap.order_verification_code=ovr.order_verification_code
    where opvr.del_flag=0
    and ap.del_flag=0
    <if test="orderIndex != null and orderIndex != ''"> and ap.order_index like concat('%', #{orderIndex}, '%')</if>
    <if test="merchantIndex != null and merchantIndex != ''"> and m.merchant_index like concat('%', #{merchantIndex}, '%')</if>
    <if test="goodsName != null and goodsName != ''"> and og.name like concat('%', #{goodsName}, '%')</if>
    <if test="serverPhone != null and serverPhone != ''"> and su.phone like concat('%', #{serverPhone}, '%')</if>
    <if test="serverName != null and serverName != ''"> and su.real_name like concat('%', #{serverName}, '%')</if>
    <if test="merchantName != null and merchantName != ''"> and m.merchant_name like concat('%', #{merchantName}, '%')</if>
    <if test="memberPhone != null and memberPhone != ''"> and oa.phone like concat('%', #{memberPhone}, '%')</if>
    <if test="merchantType != null and merchantType != ''"> and m.merchant_type =#{merchantType}</if>
    <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 -->
      AND date_format(opvr.create_time,'%y%m%d') &gt;= date_format(#{beginTime},'%y%m%d')
    </if>
    <if test="endTime != null and endTime != ''"><!-- 结束时间检索 -->
      AND date_format(opvr.create_time,'%y%m%d') &lt;= date_format(#{endTime},'%y%m%d')
    </if>
    order by opvr.create_time DESC
  </select>
</mapper>
