<?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.SysSourceDefaultMapper">
    
    <resultMap type="SysSourceDefault" id="SysSourceDefaultResult">
        <result property="id"    column="id"    />
        <result property="scenicId"    column="scenic_id"    />
        <result property="sourceId"    column="source_id"    />
        <result property="price"    column="price"    />
        <result property="workAddress"    column="work_address"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="part"    column="part"    />
    </resultMap>

    <sql id="selectSysSourceDefaultVo">
        select id, scenic_id, source_id, price, work_address, create_time, update_time, part from sys_source_default
    </sql>

    <select id="selectSysSourceDefaultList" parameterType="SysSourceDefault" resultMap="SysSourceDefaultResult">
        <include refid="selectSysSourceDefaultVo"/>
        <where>  
            <if test="scenicId != null "> and scenic_id = #{scenicId}</if>
            <if test="sourceId != null "> and source_id = #{sourceId}</if>
            <if test="price != null  and price != ''"> and price = #{price}</if>
            <if test="workAddress != null  and workAddress != ''"> and work_address = #{workAddress}</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
            <if test="updateTime != null "> and update_time = #{updateTime}</if>
            <if test="part != null  and part != ''"> and part = #{part}</if>
        </where>
    </select>
    
    <select id="selectSysSourceDefaultById" parameterType="Long" resultMap="SysSourceDefaultResult">
        <include refid="selectSysSourceDefaultVo"/>
        where id = #{id}
    </select>
    <select id="getSourceDefaultBySourceId" resultMap="SysSourceDefaultResult">
        select * from sys_source_default where source_id = #{sourceId}
    </select>

    <insert id="insertSysSourceDefault" parameterType="SysSourceDefault" useGeneratedKeys="true" keyProperty="id">
        insert into sys_source_default
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="scenicId != null">scenic_id,</if>
            <if test="sourceId != null">source_id,</if>
            <if test="price != null">price,</if>
            <if test="workAddress != null">work_address,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="part != null and part != ''">part,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="scenicId != null">#{scenicId},</if>
            <if test="sourceId != null">#{sourceId},</if>
            <if test="price != null">#{price},</if>
            <if test="workAddress != null">#{workAddress},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="part != null and part != ''">#{part},</if>
         </trim>
    </insert>

    <update id="updateSysSourceDefault" parameterType="SysSourceDefault">
        update sys_source_default
        <trim prefix="SET" suffixOverrides=",">
            <if test="scenicId != null">scenic_id = #{scenicId},</if>
            <if test="sourceId != null">source_id = #{sourceId},</if>
            <if test="price != null">price = #{price},</if>
            <if test="workAddress != null">work_address = #{workAddress},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="part != null and part != ''">part = #{part},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="updateSysSourceDefaultWorkBySourceId">
        update sys_source_default set work_address = #{workAddress} where source_id = #{sourceId}
    </update>
    <update id="updateDefaultSourcePrice">
        update sys_source_default set price = #{price} where scenic_id = #{scenicId} and part = #{part}
    </update>

    <delete id="deleteSysSourceDefaultById" parameterType="Long">
        delete from sys_source_default where id = #{id}
    </delete>

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