<?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.SettledMerchantsInterestsMapper">
    
    <resultMap type="SettledMerchantsInterests" id="SettledMerchantsInterestsResult">
        <result property="id"    column="id"    />
        <result property="businessId"    column="business_id"    />
        <result property="menuId"    column="menu_id"    />
        <result property="menuName"    column="menu_name"    />
    </resultMap>

    <sql id="selectSettledMerchantsInterestsVo">
        select id, business_id, menu_id, menu_name from settled_merchants_interests
    </sql>

    <select id="selectSettledMerchantsInterestsList" parameterType="SettledMerchantsInterests" resultMap="SettledMerchantsInterestsResult">
        <include refid="selectSettledMerchantsInterestsVo"/>
        <where>  
            <if test="businessId != null "> and business_id = #{businessId}</if>
            <if test="menuId != null "> and menu_id = #{menuId}</if>
            <if test="menuName != null  and menuName != ''"> and menu_name like concat('%', #{menuName}, '%')</if>
        </where>
    </select>
    
    <select id="selectSettledMerchantsInterestsById" parameterType="Long" resultMap="SettledMerchantsInterestsResult">
        <include refid="selectSettledMerchantsInterestsVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertSettledMerchantsInterests" parameterType="SettledMerchantsInterests" useGeneratedKeys="true" keyProperty="id">
        insert into settled_merchants_interests
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="businessId != null">business_id,</if>
            <if test="menuId != null">menu_id,</if>
            <if test="menuName != null and menuName != ''">menu_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="businessId != null">#{businessId},</if>
            <if test="menuId != null">#{menuId},</if>
            <if test="menuName != null and menuName != ''">#{menuName},</if>
         </trim>
    </insert>

    <update id="updateSettledMerchantsInterests" parameterType="SettledMerchantsInterests">
        update settled_merchants_interests
        <trim prefix="SET" suffixOverrides=",">
            <if test="businessId != null">business_id = #{businessId},</if>
            <if test="menuId != null">menu_id = #{menuId},</if>
            <if test="menuName != null and menuName != ''">menu_name = #{menuName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSettledMerchantsInterestsById" parameterType="Long">
        delete from settled_merchants_interests where id = #{id}
    </delete>

    <delete id="deleteSettledMerchantsInterestsByIds" parameterType="String">
        delete from settled_merchants_interests where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="delectByBusinessId" parameterType="java.lang.Long">
        delete from settled_merchants_interests where business_id = #{businessId}
    </delete>
</mapper>