<?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.SupplierReleaseMapper">
    <!-- 新增路线 -->
    <insert id="addRelease" parameterType="SupplierRelease">
        insert into bus_supplier_release(code,uuid,demand_uuid,jdrq,update_date,price_all,title_img,offer_name,price_detail,contract_file,price_detail_text,other)
        values (#{code},#{uuid},#{demandUuid},format(SYSDATETIME(),'yyyy-MM-dd hh:mm:ss'),format(SYSDATETIME(),'yyyy-MM-dd hh:mm:ss'),#{priceAll},#{titleImg},#{offerName},#{priceDetail},#{contractFile},#{priceDetailText},#{other})
    </insert>
    <!-- 新增每天内容 -->
    <insert id="addReleaseDay" parameterType="SupplierReleaseDay">
        insert into bus_supplier_release_day(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(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.name
        from bus_supplier_release a
        LEFT JOIN sys_supplier b on a.code = b.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="demandUuid != null and demandUuid != ''">
                and a.demand_uuid = #{demandUuid}
            </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>
                <if test="titleImg != null and titleImg != ''">
                    title_img = #{titleImg},
                </if>
                <if test="offerName != null and offerName != ''">
                    offer_name = #{offerName},
                </if>
                <if test="priceDetail != null and priceDetail != ''">
                    price_detail = #{priceDetail},
                </if>
                <if test="contractFile != null and contractFile != ''">
                    contract_file = #{contractFile},
                </if>
                <if test="priceDetailText != null and priceDetailText != ''">
                    price_detail_text = #{priceDetailText},
                </if>
                <if test="other != null and other != ''">
                    other = #{other},
                </if>
                update_date = format(SYSDATETIME(),'yyyy-MM-dd hh:mm:ss'),
            </trim>
        </set>
        where uuid = #{uuid}
    </update>
    <!-- 新增定制单状态 -->
    <insert id="addPrivateType" parameterType="supplierRelease">
        insert into bus_private_ordering_type(code,demand_uuid,order_type) values(#{code}, #{demandUuid}, 1)
    </insert>
    <!-- 修改指定供应商定制单状态 -->
    <update id="updatePrivateType" parameterType="supplierRelease">
        update bus_private_ordering_type set order_type = #{orderType} where code = #{code} and demand_uuid = #{demandUuid}
    </update>
</mapper>