<?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.ruoyi.tuya.mapper.BusTravelMapper">

    <resultMap type="BusTravel" id="BusTravelResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="titleImg"    column="title_img"    />
        <result property="synopsis"    column="synopsis"    />
        <result property="videoUrl"    column="video_url"    />
        <result property="imgUrl"    column="img_url"    />
        <result property="uuid"    column="uuid"    />
        <result property="stateType"    column="state_type"    />
        <result property="travelDate"    column="travel_date"    />
        <result property="travelDay"    column="travel_day"    />
        <result property="capita"    column="capita"    />
        <result property="figure"    column="figure"    />
        <result property="playType"    column="play_type"    />
        <result property="season"    column="season"    />
        <result property="destination"    column="destination"    />
        <result property="jdrq"    column="jdrq"    />
        <result property="peopleAll"    column="people_all"    />
        <result property="title"    column="title"    />
        <result property="titleTravel"    column="title_travel"    />
        <result property="demandUuid"    column="demand_uuid"    />
        <result property="lookNum"    column="look_num"    />
        <result property="titleDayName"    column="title_day_name"    />
        <result property="amount"    column="amount"    />
    </resultMap>

    <sql id="selectBusTravelVo">
        select id, code, title_img, synopsis, video_url, img_url, uuid, state_type, travel_date, travel_day,
               capita, figure, play_type, season, destination, jdrq, people_all, title, title_travel, demand_uuid,
               look_num, title_day_name, amount from bus_travel
    </sql>

    <select id="selectBusTravelList" parameterType="BusTravel" resultMap="BusTravelResult">
        <include refid="selectBusTravelVo"/>
        <where>
            <if test="code != null  and code != ''"> and code like concat('%', #{code}, '%')</if>
            <if test="titleImg != null  and titleImg != ''"> and title_img = #{titleImg}</if>
            <if test="synopsis != null  and synopsis != ''"> and synopsis = #{synopsis}</if>
            <if test="videoUrl != null  and videoUrl != ''"> and video_url = #{videoUrl}</if>
            <if test="imgUrl != null  and imgUrl != ''"> and img_url = #{imgUrl}</if>
            <if test="uuid != null  and uuid != ''"> and uuid like concat('%', #{uuid}, '%')</if>
            <if test="stateType != null  and stateType != ''"> and state_type = #{stateType}</if>
            <if test="travelDate != null  and travelDate != ''"> and travel_date like concat('%', #{travelDate}, '%')</if>
            <if test="travelDay != null  and travelDay != ''"> and travel_day = #{travelDay}</if>
            <if test="capita != null "> and capita = #{capita}</if>
            <if test="figure != null  and figure != ''"> and figure like concat('%', #{figure}, '%')</if>
            <if test="playType != null  and playType != ''"> and play_type like concat('%', #{playType}, '%')</if>
            <if test="season != null  and season != ''"> and season like concat('%', #{season}, '%')</if>
            <if test="destination != null  and destination != ''"> and destination like concat('%', #{destination}, '%')</if>
            <if test="jdrq != null "> and DATEADD(ms, -DATEPART(ms, jdrq), jdrq) = #{jdrq}</if>
            <if test="peopleAll != null  and peopleAll != ''"> and people_all = #{peopleAll}</if>
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%')</if>
            <if test="titleTravel != null  and titleTravel != ''"> and title_travel like concat('%', #{titleTravel}, '%')</if>
            <if test="demandUuid != null  and demandUuid != ''"> and demand_uuid like concat('%', #{demandUuid}, '%')</if>
            <if test="lookNum != null "> and look_num = #{lookNum}</if>
            <if test="titleDayName != null  and titleDayName != ''"> and title_day_name like concat('%', #{titleDayName}, '%')</if>
            <if test="amount != null "> and amount = #{amount}</if>
        </where>
    </select>

    <select id="selectBusTravelById" parameterType="Long" resultMap="BusTravelResult">
        <include refid="selectBusTravelVo"/>
        where id = #{id}
    </select>

    <insert id="insertBusTravel" parameterType="BusTravel">
        insert into bus_travel
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="code != null">code,</if>
            <if test="titleImg != null">title_img,</if>
            <if test="synopsis != null">synopsis,</if>
            <if test="videoUrl != null">video_url,</if>
            <if test="imgUrl != null">img_url,</if>
            <if test="uuid != null">uuid,</if>
            <if test="stateType != null">state_type,</if>
            <if test="travelDate != null">travel_date,</if>
            <if test="travelDay != null">travel_day,</if>
            <if test="capita != null">capita,</if>
            <if test="figure != null">figure,</if>
            <if test="playType != null">play_type,</if>
            <if test="season != null">season,</if>
            <if test="destination != null">destination,</if>
            <if test="jdrq != null">jdrq,</if>
            <if test="peopleAll != null">people_all,</if>
            <if test="title != null">title,</if>
            <if test="titleTravel != null">title_travel,</if>
            <if test="demandUuid != null">demand_uuid,</if>
            <if test="lookNum != null">look_num,</if>
            <if test="titleDayName != null">title_day_name,</if>
            <if test="amount != null">amount,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="code != null">#{code},</if>
            <if test="titleImg != null">#{titleImg},</if>
            <if test="synopsis != null">#{synopsis},</if>
            <if test="videoUrl != null">#{videoUrl},</if>
            <if test="imgUrl != null">#{imgUrl},</if>
            <if test="uuid != null">#{uuid},</if>
            <if test="stateType != null">#{stateType},</if>
            <if test="travelDate != null">#{travelDate},</if>
            <if test="travelDay != null">#{travelDay},</if>
            <if test="capita != null">#{capita},</if>
            <if test="figure != null">#{figure},</if>
            <if test="playType != null">#{playType},</if>
            <if test="season != null">#{season},</if>
            <if test="destination != null">#{destination},</if>
            <if test="jdrq != null">#{jdrq},</if>
            <if test="peopleAll != null">#{peopleAll},</if>
            <if test="title != null">#{title},</if>
            <if test="titleTravel != null">#{titleTravel},</if>
            <if test="demandUuid != null">#{demandUuid},</if>
            <if test="lookNum != null">#{lookNum},</if>
            <if test="titleDayName != null">#{titleDayName},</if>
            <if test="amount != null">#{amount},</if>
         </trim>
    </insert>

    <update id="updateBusTravel" parameterType="BusTravel">
        update bus_travel
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null">code = #{code},</if>
            <if test="titleImg != null">title_img = #{titleImg},</if>
            <if test="synopsis != null">synopsis = #{synopsis},</if>
            <if test="videoUrl != null">video_url = #{videoUrl},</if>
            <if test="imgUrl != null">img_url = #{imgUrl},</if>
            <if test="uuid != null">uuid = #{uuid},</if>
            <if test="stateType != null">state_type = #{stateType},</if>
            <if test="travelDate != null">travel_date = #{travelDate},</if>
            <if test="travelDay != null">travel_day = #{travelDay},</if>
            <if test="capita != null">capita = #{capita},</if>
            <if test="figure != null">figure = #{figure},</if>
            <if test="playType != null">play_type = #{playType},</if>
            <if test="season != null">season = #{season},</if>
            <if test="destination != null">destination = #{destination},</if>
            <if test="jdrq != null">jdrq = #{jdrq},</if>
            <if test="peopleAll != null">people_all = #{peopleAll},</if>
            <if test="title != null">title = #{title},</if>
            <if test="titleTravel != null">title_travel = #{titleTravel},</if>
            <if test="demandUuid != null">demand_uuid = #{demandUuid},</if>
            <if test="lookNum != null">look_num = #{lookNum},</if>
            <if test="titleDayName != null">title_day_name = #{titleDayName},</if>
            <if test="amount != null">amount = #{amount},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteBusTravelById" parameterType="Long">
        delete from bus_travel where id = #{id}
    </delete>

    <delete id="deleteBusTravelByIds" parameterType="String">
        delete from bus_travel where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <insert id="insertBusTravelDiscard" parameterType="BusTravel">
        insert into bus_travel_discard
        select code, title_img, synopsis, video_url, img_url, uuid, state_type, travel_date, travel_day,
               capita, figure, play_type, season, destination, jdrq, people_all, title, title_travel, demand_uuid,
               look_num, title_day_name, amount from bus_travel where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </insert>
</mapper>
