<?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.MallGoodsTagMapper">

    <resultMap type="MallGoodsTag" id="MallGoodsTagResult">
        <result property="id"    column="id"    />
        <result property="tagName"    column="tag_name"    />
        <result property="tagImg"    column="tag_img"    />
        <result property="tagStatus"    column="tag_status"    />
        <result property="tagSort"    column="tag_sort"    />
        <result property="createAt"    column="create_at"    />
        <result property="updateAt"    column="update_at"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectMallGoodsTagVo">
        select id, tag_name, tag_img, tag_status, tag_sort, create_at, update_at, del_flag from mall_goods_tag
    </sql>

    <select id="selectMallGoodsTagList" parameterType="MallGoodsTag" resultMap="MallGoodsTagResult">
        <include refid="selectMallGoodsTagVo"/>
        <where>
            <if test="id != null "> and id = #{id}</if>
            <if test="tagName != null  and tagName != ''"> and tag_name like concat('%', #{tagName}, '%')</if>
            <if test="tagImg != null  and tagImg != ''"> and tag_img = #{tagImg}</if>
            <if test="tagStatus != null "> and tag_status = #{tagStatus}</if>
            <if test="tagSort != null "> and tag_sort = #{tagSort}</if>
            <if test="createAt != null  and createAt != ''"> and create_at = #{createAt}</if>
            <if test="updateAt != null  and updateAt != ''"> and update_at = #{updateAt}</if>
            and del_flag = '0'
        </where>
        order by tag_sort asc,create_at desc
    </select>

    <select id="getGoodsTags" parameterType="MallGoodsTag" resultMap="MallGoodsTagResult">
        <include refid="selectMallGoodsTagVo"/>
        <where>
            and tag_status = '0'
            and del_flag = '0'
        </where>
        order by tag_sort asc,create_at desc
    </select>

    <select id="selectMallGoodsTagById" parameterType="Integer" resultMap="MallGoodsTagResult">
        <include refid="selectMallGoodsTagVo"/>
        where id = #{id}
    </select>

    <insert id="insertMallGoodsTag" parameterType="MallGoodsTag" useGeneratedKeys="true" keyProperty="id">
        insert into mall_goods_tag
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="tagName != null">tag_name,</if>
            <if test="tagImg != null">tag_img,</if>
            <if test="tagStatus != null">tag_status,</if>
            <if test="tagSort != null">tag_sort,</if>
            <if test="createAt != null">create_at,</if>
            <if test="updateAt != null">update_at,</if>
            <if test="delFlag != null">del_flag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="tagName != null">#{tagName},</if>
            <if test="tagImg != null">#{tagImg},</if>
            <if test="tagStatus != null">#{tagStatus},</if>
            <if test="tagSort != null">#{tagSort},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="updateAt != null">#{updateAt},</if>
            <if test="delFlag != null">#{delFlag},</if>
        </trim>
    </insert>

    <update id="updateMallGoodsTag" parameterType="MallGoodsTag">
        update mall_goods_tag
        <trim prefix="SET" suffixOverrides=",">
            <if test="tagName != null">tag_name = #{tagName},</if>
            <if test="tagImg != null">tag_img = #{tagImg},</if>
            <if test="tagStatus != null">tag_status = #{tagStatus},</if>
            <if test="tagSort != null">tag_sort = #{tagSort},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMallGoodsTagById" parameterType="Integer">
        <!--delete from mall_goods_tag where id = #{id}-->
        update mall_goods_tag set del_flag = '1' where id = #{id}
    </delete>

    <delete id="deleteMallGoodsTagByIds" parameterType="String">
        <!--delete from mall_goods_tag where id in-->
        update mall_goods_tag set del_flag = '1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
