<?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.SettledMerchantsMapper">
    
    <resultMap type="com.ruoyi.system.domain.SettledMerchants" id="SettledMerchantsResult">
        <result property="businessId"    column="business_id"    />
        <result property="businessName"    column="business_name"    />
        <result property="businessIntroduce"    column="business_introduce"    />
        <result property="businessAddress"    column="business_address"    />
        <result property="businessPhone"    column="business_phone"    />
        <result property="businessPolicy"    column="business_policy"    />
        <result property="orderNum"    column="order_num"    />
        <result property="visible"    column="visible"    />
        <result property="status"    column="status"    />
        <result property="photo"    column="photo"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="policyId"    column="policy_id"    />
    </resultMap>

    <sql id="selectSettledMerchantsVo">
        select business_id, business_name, business_introduce, business_address, business_phone, business_policy, order_num, visible, status, photo, create_by, create_time, update_by, update_time, remark,policy_id from settled_merchants
    </sql>

    <select id="selectSettledMerchantsList" parameterType="SettledMerchants" resultMap="SettledMerchantsResult">
        <include refid="selectSettledMerchantsVo"/>
        <where>  
            <if test="businessName != null  and businessName != ''"> and business_name like concat('%', #{businessName}, '%')</if>
            <if test="businessPhone != null  and businessPhone != ''"> and business_phone = #{businessPhone}</if>
        </where>
        order by order_num
    </select>
    
    <select id="selectSettledMerchantsByBusinessId" parameterType="Long" resultMap="SettledMerchantsResult">
        <include refid="selectSettledMerchantsVo"/>
        where business_id = #{businessId}
    </select>


    <select id="selectSettledMerchantsByMenuId" parameterType="Long" resultMap="SettledMerchantsResult">
        <include refid="selectSettledMerchantsVo"/>
        where policy_id = #{menuId}
    </select>
        
    <insert id="insertSettledMerchants" parameterType="SettledMerchants" useGeneratedKeys="true" keyProperty="businessId">
        insert into settled_merchants
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="businessName != null">business_name,</if>
            <if test="businessIntroduce != null">business_introduce,</if>
            <if test="businessAddress != null">business_address,</if>
            <if test="businessPhone != null">business_phone,</if>
            <if test="businessPolicy != null">business_policy,</if>
            <if test="orderNum != null">order_num,</if>
            <if test="visible != null">visible,</if>
            <if test="status != null">status,</if>
            <if test="photo != null">photo,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            <if test="policyId != null">policy_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="businessName != null">#{businessName},</if>
            <if test="businessIntroduce != null">#{businessIntroduce},</if>
            <if test="businessAddress != null">#{businessAddress},</if>
            <if test="businessPhone != null">#{businessPhone},</if>
            <if test="businessPolicy != null">#{businessPolicy},</if>
            <if test="orderNum != null">#{orderNum},</if>
            <if test="visible != null">#{visible},</if>
            <if test="status != null">#{status},</if>
            <if test="photo != null">#{photo},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="policyId != null">#{policyId},</if>
         </trim>
    </insert>

    <update id="updateSettledMerchants" parameterType="SettledMerchants">
        update settled_merchants
        <trim prefix="SET" suffixOverrides=",">
            <if test="businessName != null">business_name = #{businessName},</if>
            <if test="businessIntroduce != null">business_introduce = #{businessIntroduce},</if>
            <if test="businessAddress != null">business_address = #{businessAddress},</if>
            <if test="businessPhone != null">business_phone = #{businessPhone},</if>
            <if test="businessPolicy != null">business_policy = #{businessPolicy},</if>
            <if test="orderNum != null">order_num = #{orderNum},</if>
            <if test="visible != null">visible = #{visible},</if>
            <if test="status != null">status = #{status},</if>
            <if test="photo != null">photo = #{photo},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="policyId != null">policy_id = #{policyId},</if>
        </trim>
        where business_id = #{businessId}
    </update>

    <delete id="deleteSettledMerchantsByBusinessId" parameterType="Long">
        delete from settled_merchants where business_id = #{businessId}
    </delete>

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