<?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.bonus.zlpt.equip.mapper.UserCollectMapper">
    
    <resultMap type="com.bonus.zlpt.common.core.domain.equip.UserCollect" id="UserCollectResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="maId"    column="ma_id"    />
        <result property="time"    column="time"    />
    </resultMap>

    <sql id="selectUserCollectVo">
        select id, user_id, ma_id, time from ma_user_collect
    </sql>

    <select id="selectUserCollectList" parameterType="com.bonus.zlpt.common.core.domain.equip.UserCollect" resultMap="UserCollectResult">
        <include refid="selectUserCollectVo"/>
        <where>  
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="maId != null "> and ma_id = #{maId}</if>
            <if test="time != null  and time != ''"> and time = #{time}</if>
        </where>
    </select>
    
    <select id="selectUserCollectById" parameterType="Long" resultMap="UserCollectResult">
        <include refid="selectUserCollectVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertUserCollect" parameterType="com.bonus.zlpt.common.core.domain.equip.UserCollect">
        insert into ma_user_collect
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userId != null">user_id,</if>
            <if test="maId != null">ma_id,</if>
            <if test="time != null">time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userId != null">#{userId},</if>
            <if test="maId != null">#{maId},</if>
            <if test="time != null">#{time},</if>
         </trim>
    </insert>

    <update id="updateUserCollect" parameterType="com.bonus.zlpt.common.core.domain.equip.UserCollect">
        update ma_user_collect
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="maId != null">ma_id = #{maId},</if>
            <if test="time != null">time = #{time},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUserCollectById" parameterType="Long">
        delete from ma_user_collect where id = #{id}
    </delete>

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