<?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.zm.order.tool.server.history.HistoryDataSelfTakeDao">

    <resultMap id="PerformanceSelfTakeMap" type="com.zm.order.tool.server.model.PerformanceSelfTake">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="biz_type" jdbcType="INTEGER" property="bizType"/>
        <result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
        <result column="seller_id" jdbcType="BIGINT" property="sellerId"/>
        <result column="store_id" jdbcType="BIGINT" property="storeId"/>
        <result column="user_id" jdbcType="BIGINT" property="userId"/>
        <result column="self_take_name" jdbcType="VARCHAR" property="selfTakeName"/>
        <result column="self_take_mobile" jdbcType="VARCHAR" property="selfTakeMobile"/>
        <result column="self_take_code" jdbcType="BIGINT" property="selfTakeCode"/>
        <result column="code_url" jdbcType="VARCHAR" property="codeUrl"/>
        <result column="bar_code_url" jdbcType="VARCHAR" property="barCodeUrl"/>
        <result column="verify_type" jdbcType="INTEGER" property="verifyType"/>
        <result column="appointed_date_type" jdbcType="INTEGER" property="appointedDateType"/>
        <result column="self_take_start_at" jdbcType="TIMESTAMP" property="selfTakeStartAt"/>
        <result column="self_take_end_at" jdbcType="TIMESTAMP" property="selfTakeEndAt"/>
        <result column="pick_at" jdbcType="TIMESTAMP" property="pickAt"/>
        <result column="auto_verify_at" jdbcType="TIMESTAMP" property="autoVerifyAt"/>
        <result column="self_take_status" jdbcType="INTEGER" property="selfTakeStatus"/>
        <result column="unusual_reason" jdbcType="VARCHAR" property="unusualReason"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="features" jdbcType="VARCHAR" property="features"/>
        <result column="created_at" jdbcType="TIMESTAMP" property="createdAt"/>
        <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt"/>
        <result column="is_deleted" jdbcType="INTEGER" property="isDeleted"/>
    </resultMap>

    <sql id="tb">
        order_self_take
    </sql>

    <sql id="cols_all">
        id,
        <include refid="cols_exclude_id"/>
    </sql>

    <sql id="cols_exclude_id">
        biz_type, order_no, seller_id, store_id, user_id, self_take_name, self_take_mobile, self_take_code, code_url, bar_code_url,
        verify_type, appointed_date_type, self_take_start_at, self_take_end_at,
        pick_at, auto_verify_at, self_take_status, unusual_reason, remark, features, created_at, updated_at, is_deleted
    </sql>

    <select id="selectOne" parameterType="map" resultMap="PerformanceSelfTakeMap">
        select
        <include refid="cols_all"/>
        from
        <include refid="tb"/>
        where order_no = #{orderNo}
        and user_id = #{userId}
        limit 1
    </select>

    <select id="selectByOrderNoList" parameterType="map" resultMap="PerformanceSelfTakeMap">
        SELECT
        <include refid="cols_all"/>
        FROM
        <include refid="tb"/>
        <where>
            user_id = #{userId}
            and order_no in
            <foreach collection="orderNoList" item="orderNo" index="index" open="(" close=")" separator=",">
                #{orderNo}
            </foreach>
            and is_deleted = 0
        </where>
    </select>

</mapper>