<?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.IntegralCateMapper">
    
    <resultMap type="IntegralCate" id="IntegralCateResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="sort"    column="sort"    />
        <result property="status"    column="status"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectIntegralCateVo">
        select id, title, sort, status, created_at, updated_at from integral_cate
    </sql>

    <select id="selectIntegralCateList" parameterType="IntegralCate" resultMap="IntegralCateResult">
        <include refid="selectIntegralCateVo"/>
        <where>  
            <if test="title != null  and title != ''"> and title like  concat('%', #{title}, '%')</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectIntegralCateById" parameterType="Long" resultMap="IntegralCateResult">
        <include refid="selectIntegralCateVo"/>
        where id = #{id}
    </select>

    <insert id="insertIntegralCate" parameterType="IntegralCate" useGeneratedKeys="true" keyProperty="id">
        insert into integral_cate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">title,</if>
            <if test="sort != null">sort,</if>
            <if test="status != null">status,</if>
            created_at,
            updated_at
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">#{title},</if>
            <if test="sort != null">#{sort},</if>
            <if test="status != null">#{status},</if>
           NOW(),
            NOW()
         </trim>
    </insert>

    <update id="updateIntegralCate" parameterType="IntegralCate">
        update integral_cate
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="status != null">status = #{status},</if>
       updated_at=NOW()
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteIntegralCateById" parameterType="Long">
        delete from integral_cate where id = #{id}
    </delete>

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