<?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.ReleaseMapper">
    <!-- 供应商发布路线 -->
    <insert id="addReleaseVal" parameterType="SupplierRoute">
        insert into bus_supplier_route(code,origin,destination,start_time,end_time,look_num,title_img,offer_name,price_all,people_num,uuid,jdrq,update_date,title_day_name,state_type,announcements,features)
        values(#{code},#{origin},#{destination},#{startTime},#{endTime},0,#{titleImg},#{offerName},#{priceAll},#{peopleNum},#{uuid},CONVERT(VARCHAR(100), SYSDATETIME(), 20),CONVERT(VARCHAR(100), SYSDATETIME(), 20),#{titleDayName},'1',#{announcements},#{features})
    </insert>
    <!-- 查询路线发布 -->
    <select id="getRelease" parameterType="SupplierRoute" resultType="SupplierRoute">
        select top ${limit} * from bus_supplier_route
        <trim prefix="WHERE" prefixOverrides="and | or">
            <if test="startTime != null and startTime !=''">
                and CONVERT (datetime, start_time) <![CDATA[ >= ]]> #{startTime} and CONVERT(datetime, end_time) <![CDATA[ <= ]]> #{endTime}
            </if>
            <if test="destination != null and destination !=''">
                and destination like concat('%', #{destination}, '%')
            </if>
            <if test="code != null and code !=''">
                and code = #{code}
            </if>
            <if test="stateType != null and stateType !=''">
                and state_type = #{stateType}
            </if>
            and id not in (select top ${page} id  from bus_supplier_route
            <trim prefix="WHERE" prefixOverrides="and | or">
                <if test="startTime != null and startTime !=''">
                    and CONVERT (datetime, start_time) <![CDATA[ >= ]]> #{startTime} and CONVERT(datetime, end_time) <![CDATA[ <= ]]> #{endTime}
                </if>
                <if test="destination != null and destination !=''">
                    and destination like concat('%', #{destination}, '%')
                </if>
                <if test="code != null and code !=''">
                    and code = #{code}
                </if>
                <if test="stateType != null and stateType !=''">
                    and state_type = #{stateType}
                </if>
            </trim>
            order by id desc
        ) order by id desc
        </trim>
    </select>
    <!-- 查询路线条数 -->
    <select id="getReleaseCount" resultType="int" parameterType="SupplierRoute">
        select count(*) as count from bus_supplier_route
        <trim prefix="WHERE" prefixOverrides="and | or">
            <if test="startTime != null and startTime !=''">
                and CONVERT (datetime, start_time) <![CDATA[ >= ]]> #{startTime} and CONVERT(datetime, end_time) <![CDATA[ <= ]]> #{endTime}
            </if>
            <if test="destination != null and destination !=''">
                and destination like concat('%', #{destination}, '%')
            </if>
            <if test="code != null and code !=''">
                and code = #{code}
            </if>
            <if test="stateType != null and stateType !=''">
                and state_type = #{stateType}
            </if>
        </trim>
    </select>
    <!-- 查询路线条数 -->
    <select id="getReleaseVal" resultType="SupplierRoute" parameterType="SupplierRoute">
        select * from bus_supplier_route
        <trim prefix="WHERE" prefixOverrides="and | or">
            <if test="uuid != null and uuid !=''">
                and uuid = #{uuid}
            </if>
        </trim>
    </select>
    <!-- 修改路线 -->
    <update id="updateSupplierRoute" parameterType="SupplierRoute">
        update bus_supplier_route
        <set>
            <trim suffixOverrides=",">
                <if test="origin != null and origin != ''">
                    origin = #{origin},
                </if>
                <if test="destination != null and destination != ''">
                    destination = #{destination},
                </if>
                <if test="startTime != null and startTime != ''">
                    start_time = #{startTime},
                </if>
                <if test="endTime != null and endTime != ''">
                    end_time = #{endTime},
                </if>
                <if test="titleImg != null and titleImg != ''">
                    title_img = #{titleImg},
                </if>
                <if test="offerName != null and offerName != ''">
                    offer_name = #{offerName},
                </if>
                <if test="priceAll != null and priceAll != ''">
                    price_all = #{priceAll},
                </if>
                <if test="peopleNum != null and peopleNum != ''">
                    people_num = #{peopleNum},
                </if>
                <if test="features != null and features != ''">
                    features = #{features},
                </if>
                update_date = SYSDATETIME(),
            </trim>
            where uuid = #{uuid}
        </set>
    </update>
</mapper>