<?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.cool.store.mapper.TrainingExperienceMapper">
    <resultMap id="BaseResultMap" type="com.cool.store.entity.LeaseBaseInfoDO">
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="partner_id" jdbcType="VARCHAR" property="partnerId" />
        <result column="line_id" jdbcType="BIGINT" property="lineId"/>
        <result column="store_name" jdbcType="VARCHAR" property="storeName"/>
        <result column="store_id" jdbcType="VARCHAR" property="storeId"/>
        <result column="experience_start_time" jdbcType="TIMESTAMP" property="experienceStartTime"/>
        <result column="experience_end_time" jdbcType="TIMESTAMP" property="experienceEndTime"/>
        <result column="experience_status" jdbcType="TINYINT" property="experienceStatus"/>
        <result column="abandon_cause" jdbcType="VARCHAR" property="abandonCause"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
        <result column="deleted" jdbcType="TINYINT" property="deleted"/>
    </resultMap>
    <sql id="Base_Column_List">
        id,
        partner_id,
        line_id,
        store_name,
        store_id,
        experience_start_time,
        experience_end_time,
        experience_status,
        abandon_cause,
        create_time,
        update_time,
        deleted
  </sql>
    <insert id="insert">
        insert into xfsg_lease_base_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="entity.partnerId != null">partner_id,</if>
            <if test="entity.lineId != null">line_id,</if>
            <if test="entity.storeName != null">store_name,</if>
            <if test="entity.storeId != null">store_id,</if>
            <if test="entity.experienceStartTime != null">experience_start_time,</if>
            <if test="entity.experienceEndTime != null">experience_end_time,</if>
            <if test="entity.experienceStatus != null">experience_status,</if>
            <if test="entity.abandonCause != null">abandon_cause,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="entity.partnerId != null">#{entity.partnerId},</if>
            <if test="entity.lineId != null">#{entity.lineId},</if>
            <if test="entity.storeName != null">#{entity.storeName},</if>
            <if test="entity.storeId != null">#{entity.storeId},</if>
            <if test="entity.experienceStartTime != null">#{entity.experienceStartTime},</if>
            <if test="entity.experienceEndTime != null">#{entity.experienceEndTime},</if>
            <if test="entity.experienceStatus != null">#{entity.experienceStatus},</if>
            <if test="entity.abandonCause != null">#{entity.abandonCause},</if>
        </trim>
        ON DUPLICATE KEY UPDATE
        <trim  suffixOverrides=",">
            <if test="entity.partnerId != null">partner_id = #{entity.partnerId},</if>
            <if test="entity.storeName != null">store_name = #{entity.storeName},</if>
            <if test="entity.storeId != null">store_id = #{entity.storeId},</if>
            <if test="entity.experienceStartTime != null">experience_start_time = #{entity.experienceStartTime},</if>
            <if test="entity.experienceEndTime != null">experience_end_time = #{entity.experienceEndTime},</if>
            <if test="entity.experienceStatus != null">experience_status = #{entity.experienceStatus},</if>
            <if test="entity.abandonCause != null">abandon_cause = #{entity.abandonCause},</if>
        </trim>
    </insert>
    <update id="updateStatus">
        update
        xfsg_lease_base_info
        set
        experience_status = #{status},
        abandon_cause=#{abandonCause}
        where line_id = #{lineId}
    </update>
    <select id="selectByLineId" resultType="com.cool.store.entity.LeaseBaseInfoDO">
        select
        <include refid="Base_Column_List"/>
        from xfsg_lease_base_info
        where line_id = #{lineId}
    </select>
    <select id="selectByLineIds" resultType="com.cool.store.entity.LeaseBaseInfoDO">
        select
        <include refid="Base_Column_List"/>
        from xfsg_lease_base_info
        <where>
            <if test="lineIds !=null and lineIds.size>0">
                <foreach collection="lineIds" item="lineId" open="and line_id in (" close=")" separator=",">
                    #{lineId}
                </foreach>
            </if>
        </where>
    </select>
    <select id="selectESTime" resultType="com.cool.store.entity.LeaseBaseInfoDO">
        SELECT
        <include refid="Base_Column_List"/>
        FROM
        xfsg_lease_base_info
        WHERE
        DATE(experience_start_time) = CURDATE()
        AND deleted = 0
    </select>


</mapper>