<?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.system.mapper.SysScenicDefaultMapper">
    
    <resultMap type="SysScenicDefault" id="SysScenicDefaultResult">
        <result property="id"    column="id"    />
        <result property="scenicId"    column="scenic_id"    />
        <result property="part"    column="part"    />
        <result property="price"    column="price"    />
        <result property="workAddress"    column="work_address"    />
        <result property="createTime"    column="create_time"    />

    </resultMap>

    <resultMap id="SetPriceDtoResult" type="SetPriceAndWorkDto">
        <result column="id" property="id"/>
        <result property="cityId" column="city_id"/>
        <result property="city" column="city"/>
        <result property="scenic" column="scenic"/>
        <result property="scenicId" column="scenic_id"/>
        <result property="price" column="price"/>
        <result property="part" column="part"/>
        <result property="workAddress" column="work_address"/>

    </resultMap>

    <sql id="selectSysScenicDefaultVo">
        select id, scenic_id, part, price, work_address, create_time from sys_scenic_default
    </sql>

    <select id="selectSysScenicDefaultList" parameterType="SysScenicDefault" resultMap="SysScenicDefaultResult">
        <include refid="selectSysScenicDefaultVo"/>
        <where>  
            <if test="scenicId != null "> and scenic_id = #{scenicId}</if>
            <if test="part != null  and part != ''"> and part = #{part}</if>
            <if test="price != null  and price != ''"> and price = #{price}</if>
            <if test="workAddress != null  and workAddress != ''"> and work_address = #{workAddress}</if>
        </where>
    </select>
    
    <select id="selectSysScenicDefaultById" parameterType="Long" resultMap="SysScenicDefaultResult">
        <include refid="selectSysScenicDefaultVo"/>
        where id = #{id}
    </select>
    <select id="getPartPrice" resultMap="SetPriceDtoResult">

        select d.id, s.city_id, s.city, s.scenic, d.price, d.part, d.scenic_id, d.work_address
        from sys_scenic_default d
        left join sys_scenic s
        on d.scenic_id = s.scenic_id
        <where>
            <if test="city != null  and city != ''"> and s.city = #{city}</if>
            <if test="scenic != null  and scenic != ''"> and s.scenic = #{scenic}</if>
        </where>

    </select>
    <select id="getScenicDefaultByScenicAndPart" resultMap="SysScenicDefaultResult">

        select d.id, d.scenic_id, d.part, d.price, d.work_address, d.create_time
        from sys_scenic_default d
        left join sys_scenic s
        on d.scenic_id = s.scenic_id
        where s.scenic = #{scenic} and d.part = #{part}

    </select>

    <insert id="insertSysScenicDefault" parameterType="SysScenicDefault" useGeneratedKeys="true" keyProperty="id">
        insert into sys_scenic_default
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="scenicId != null">scenic_id,</if>
            <if test="part != null and part != ''">part,</if>
            <if test="price != null">price,</if>
            <if test="workAddress != null">work_address,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="scenicId != null">#{scenicId},</if>
            <if test="part != null and part != ''">#{part},</if>
            <if test="price != null">#{price},</if>
            <if test="workAddress != null">#{workAddress},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateSysScenicDefault" parameterType="SysScenicDefault">
        update sys_scenic_default
        <trim prefix="SET" suffixOverrides=",">
            <if test="scenicId != null">scenic_id = #{scenicId},</if>
            <if test="part != null and part != ''">part = #{part},</if>
            <if test="price != null">price = #{price},</if>
            <if test="workAddress != null">work_address = #{workAddress},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysScenicDefaultById" parameterType="Long">
        delete from sys_scenic_default where id = #{id}
    </delete>

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