<?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.mall.mapper.MallBannerMapper">

    <resultMap type="com.ruoyi.mall.domain.MallBanner" id="MallBannerResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="headUrl"    column="head_url"    />
        <result property="status"    column="status"    />
        <result property="type"    column="type"    />
        <result property="backgroundUrl"    column="background_url"    />
        <result property="resId"    column="res_id"    />
        <result property="sort"    column="sort"    />
        <result property="createAt"    column="create_at"    />
        <result property="updateAt"    column="update_at"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="style"    column="style"    />
    </resultMap>

    <resultMap type="com.ruoyi.mall.domain.vo.IndexBannerVO" id="IndexBannerVoResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="headUrl"    column="head_url"    />
        <result property="type"    column="type"    />
        <result property="resId"    column="res_id"    />
        <result property="style"    column="style"    />
    </resultMap>

    <sql id="selectMallBannerVo">
        select id, name, head_url, status, type, background_url, res_id, sort, create_at, update_at, del_flag, module, style from mall_banner
    </sql>

    <select id="selectMallBannerList" parameterType="MallBanner" resultMap="MallBannerResult">
        <include refid="selectMallBannerVo"/>
        <where>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="module != null  and module != ''"> and module = #{module}</if>
            <if test="style != null  and style != ''"> and style = #{style}</if>
        </where>
        order by sort asc
    </select>

    <select id="selectMallBannerById" parameterType="Long" resultMap="MallBannerResult">
        <include refid="selectMallBannerVo"/>
        where id = #{id}
    </select>
    <select id="indexSelectMallBannerList" resultMap="IndexBannerVoResult">
        select id, name, head_url, type, res_id, style
        from mall_banner
        where del_flag = '0'
        and module = '0'
        and status = '0'
        order by sort asc
    </select>

    <select id="classIndexSelectMallBannerList" resultMap="IndexBannerVoResult">
        select id, name, head_url, type, res_id, style
        from mall_banner
        where del_flag = '0'
        and module = '1'
        and status = '0'
        order by sort asc
    </select>

    <insert id="insertMallBanner" parameterType="MallBanner" useGeneratedKeys="true" keyProperty="id">
        insert into mall_banner
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="headUrl != null">head_url,</if>
            <if test="status != null">status,</if>
            <if test="type != null">type,</if>
            <if test="backgroundUrl != null">background_url,</if>
            <if test="resId != null">res_id,</if>
            <if test="sort != null">sort,</if>
            <if test="createAt != null">create_at,</if>
            <if test="updateAt != null">update_at,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="module != null">module,</if>
            <if test="style != null">style,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="headUrl != null">#{headUrl},</if>
            <if test="status != null">#{status},</if>
            <if test="type != null">#{type},</if>
            <if test="backgroundUrl != null">#{backgroundUrl},</if>
            <if test="resId != null">#{resId},</if>
            <if test="sort != null">#{sort},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="updateAt != null">#{updateAt},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="module != null">#{module},</if>
            <if test="style != null">#{style},</if>
         </trim>
    </insert>

    <update id="updateMallBanner" parameterType="MallBanner">
        update mall_banner
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="headUrl != null">head_url = #{headUrl},</if>
            <if test="status != null">status = #{status},</if>
            <if test="type != null">type = #{type},</if>
            <if test="backgroundUrl != null">background_url = #{backgroundUrl},</if>
            <if test="resId != null">res_id = #{resId},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="updateAt != null">update_at = #{updateAt},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="module != null">module = #{module},</if>
            <if test="style != null">style = #{style},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMallBannerById" parameterType="Long">
        delete from mall_banner where id = #{id}
    </delete>

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