<?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.logistics.mapper.BizBannerMapper">
    
    <resultMap type="BizBanner" id="BizBannerResult">
        <result property="bannerId"    column="banner_id"    />
        <result property="bannerName"    column="banner_name"    />
        <result property="imageUrl"    column="image_url"    />
        <result property="linkUrl"    column="link_url"    />
        <result property="sortOrder"    column="sort_order"    />
        <result property="isActive"    column="is_active"    />
        <result property="sysType"    column="sys_type"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="deptId"    column="dept_id"    />
        <result property="userId"    column="user_id"    />
    </resultMap>

    <sql id="selectBizBannerVo">
        select banner_id, banner_name, image_url, link_url, sort_order, is_active, sys_type, remark, del_flag, create_time, update_time, create_by, update_by, dept_id, user_id from biz_banner
    </sql>

    <select id="selectBizBannerList" parameterType="BizBanner" resultMap="BizBannerResult">
        <include refid="selectBizBannerVo"/>
        <where>  
            <if test="bannerName != null  and bannerName != ''"> and banner_name like concat('%', #{bannerName}, '%')</if>
            <if test="imageUrl != null  and imageUrl != ''"> and image_url = #{imageUrl}</if>
            <if test="linkUrl != null  and linkUrl != ''"> and link_url = #{linkUrl}</if>
            <if test="isActive != null  and isActive != ''"> and is_active = #{isActive}</if>
            <if test="sysType != null  and sysType != ''"> and sys_type = #{sysType}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectBizBannerByBannerId" parameterType="Long" resultMap="BizBannerResult">
        <include refid="selectBizBannerVo"/>
        where banner_id = #{bannerId}
    </select>

    <insert id="insertBizBanner" parameterType="BizBanner" useGeneratedKeys="true" keyProperty="bannerId">
        insert into biz_banner
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bannerName != null and bannerName != ''">banner_name,</if>
            <if test="imageUrl != null and imageUrl != ''">image_url,</if>
            <if test="linkUrl != null and linkUrl != ''">link_url,</if>
            <if test="sortOrder != null">sort_order,</if>
            <if test="isActive != null and isActive != ''">is_active,</if>
            <if test="sysType != null and sysType != ''">sys_type,</if>
            <if test="remark != null">remark,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="userId != null">user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bannerName != null and bannerName != ''">#{bannerName},</if>
            <if test="imageUrl != null and imageUrl != ''">#{imageUrl},</if>
            <if test="linkUrl != null and linkUrl != ''">#{linkUrl},</if>
            <if test="sortOrder != null">#{sortOrder},</if>
            <if test="isActive != null and isActive != ''">#{isActive},</if>
            <if test="sysType != null and sysType != ''">#{sysType},</if>
            <if test="remark != null">#{remark},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="userId != null">#{userId},</if>
         </trim>
    </insert>

    <update id="updateBizBanner" parameterType="BizBanner">
        update biz_banner
        <trim prefix="SET" suffixOverrides=",">
            <if test="bannerName != null and bannerName != ''">banner_name = #{bannerName},</if>
            <if test="imageUrl != null and imageUrl != ''">image_url = #{imageUrl},</if>
            <if test="linkUrl != null and linkUrl != ''">link_url = #{linkUrl},</if>
            <if test="sortOrder != null">sort_order = #{sortOrder},</if>
            <if test="isActive != null and isActive != ''">is_active = #{isActive},</if>
            <if test="sysType != null and sysType != ''">sys_type = #{sysType},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="userId != null">user_id = #{userId},</if>
        </trim>
        where banner_id = #{bannerId}
    </update>

    <delete id="deleteBizBannerByBannerId" parameterType="Long">
        delete from biz_banner where banner_id = #{bannerId}
    </delete>

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