<?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.supplier.mapper.TemplateMapper">
    <!-- 新增路线 -->
    <insert id="addRelease" parameterType="SupplierRelease">
        insert into bus_supplier_release_template(code,uuid,jdrq,update_date,price_all,title_img,offer_name,travel_time)
        values (#{code},#{uuid},GETDATE(),GETDATE(),#{priceAll},#{titleImg},#{offerName},#{travelTime})
    </insert>
    <!-- 新增每天内容 -->
    <insert id="addReleaseDay" parameterType="SupplierReleaseDay">
        insert into bus_supplier_release_day_template(uuid,plan_date,content,date_time,day_num)
        values (#{uuid},#{planDate},#{content},#{dateTime},#{dayNum})
    </insert>
    <!-- 新增游玩内容 -->
    <insert id="addReleasePlay" parameterType="SupplierReleasePlay">
        insert into bus_supplier_release_play_template(uuid,type_val,content,img_url,video_url,name,day_num)
        values (#{uuid},#{typeVal},#{content},#{imgUrl},#{videoUrl},#{name},#{dayNum})
    </insert>
    <!-- 查询供应商路线 -->
    <select id="getSupplierRelease" resultType="SupplierRelease">
        select a.*,b.headpir,b.name
        from bus_supplier_release a
        LEFT JOIN (SELECT headpir,name,code from sys_supplier) b on b.code = a.code
        <trim prefix="WHERE" prefixOverrides="and | or">
            <if test="uuid != null and uuid != ''">
                and a.uuid = #{uuid}
            </if>
            <if test="code != null and code != ''">
                and a.code = #{code}
            </if>
            <if test="offerName != null and offerName != ''">
                and a.offer_name like CONCAT(CONCAT('%', #{offerName}), '%')
            </if>
        </trim>
    </select>
    <!-- 查询供应商路线每天信息 -->
    <select id="getSupplierReleaseDay" resultType="SupplierReleaseDay">
        select * from bus_supplier_release_day where uuid = #{uuid} order by day_num
    </select>
    <!-- 查询供应商路线游玩信息 -->
    <select id="getSupplierReleasePlay" resultType="SupplierReleasePlay">
        select * from bus_supplier_release_play where uuid = #{uuid} order by day_num
    </select>
    <!-- 删除每日信息 -->
    <delete id="delSupplierReleaseDay" parameterType="SupplierRelease">
        delete from bus_supplier_release_day where uuid = #{uuid}
    </delete>
    <!-- 删除游玩信息 -->
    <delete id="delSupplierReleasePlay" parameterType="SupplierRelease">
        delete from bus_supplier_release_play where uuid = #{uuid}
    </delete>
    <!-- 修改路线信息 -->
    <update id="updateSupplierRelease" parameterType="SupplierRelease">
        update bus_supplier_release
        <set>
            <trim suffixOverrides=",">
                <if test="priceAll != null and priceAll != ''">
                    price_all = #{priceAll},
                </if>
                update_date = format(SYSDATETIME(),'yyyy-MM-dd hh:mm:ss'),
            </trim>
        </set>
        where uuid = #{uuid}
    </update>
</mapper>