<?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.ie.mapper.AWishRecordMapper">
    
    <resultMap type="AWishRecord" id="AWishRecordResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="userId"    />
        <result property="year"    column="year"    />
        <result property="type"    column="type"    />
        <result property="seq"    column="seq"    />
        <result property="name"    column="name"    />
        <result property="batchName"    column="batchName"    />
        <result property="request"    column="request"    />
        <result property="userSnapshot"    column="userSnapshot"    />
        <result property="details"    column="details"    />
        <result property="status"    column="status"    />
        <result property="obsoleted"    column="obsoleted"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAWishRecordVo">
        select id, userId, year, type, seq, name, batchName,request, userSnapshot, details, status, obsoleted, create_time, update_time from a_wish_record
    </sql>

    <select id="selectAWishRecordList" parameterType="AWishRecord" resultMap="AWishRecordResult">
        <include refid="selectAWishRecordVo"/>
        <where>  
            <if test="userId != null "> and userId = #{userId}</if>
            <if test="year != null "> and year = #{year}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="seq != null "> and seq = #{seq}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="request != null  and request != ''"> and request = #{request}</if>
            <if test="userSnapshot != null  and userSnapshot != ''"> and userSnapshot = #{userSnapshot}</if>
            <if test="details != null  and details != ''"> and details = #{details}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="obsoleted != null "> and obsoleted = #{obsoleted}</if>
        </where>
        ORDER BY year DESC, seq DESC, id DESC
    </select>
    
    <select id="selectAWishRecordById" parameterType="Long" resultMap="AWishRecordResult">
        <include refid="selectAWishRecordVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertAWishRecord" parameterType="AWishRecord" useGeneratedKeys="true" keyProperty="id">
        insert into a_wish_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">userId,</if>
            <if test="year != null">year,</if>
            <if test="type != null">type,</if>
            <if test="seq != null">seq,</if>
            <if test="name != null">name,</if>
            <if test="batchName != null">batchName,</if>
            <if test="request != null">request,</if>
            <if test="userSnapshot != null">userSnapshot,</if>
            <if test="details != null">details,</if>
            <if test="status != null">status,</if>
            <if test="obsoleted != null">obsoleted,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="year != null">#{year},</if>
            <if test="type != null">#{type},</if>
            <if test="seq != null">#{seq},</if>
            <if test="name != null">#{name},</if>
            <if test="batchName != null">#{batchName},</if>
            <if test="request != null">#{request},</if>
            <if test="userSnapshot != null">#{userSnapshot},</if>
            <if test="details != null">#{details},</if>
            <if test="status != null">#{status},</if>
            <if test="obsoleted != null">#{obsoleted},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateAWishRecord" parameterType="AWishRecord">
        update a_wish_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">userId = #{userId},</if>
            <if test="year != null">year = #{year},</if>
            <if test="type != null">type = #{type},</if>
            <if test="seq != null">seq = #{seq},</if>
            <if test="name != null">name = #{name},</if>
            <if test="batchName != null">name = #{batchName},</if>
            <if test="request != null">request = #{request},</if>
            <if test="userSnapshot != null">userSnapshot = #{userSnapshot},</if>
            <if test="details != null">details = #{details},</if>
            <if test="status != null">status = #{status},</if>
            <if test="obsoleted != null">obsoleted = #{obsoleted},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateObsoleteByUser" parameterType="Long">
        update a_wish_record wr set wr.obsoleted = true where wr.userId  = #{userId}
    </update>

    <delete id="deleteAWishRecordById" parameterType="Long">
        delete from a_wish_record where id = #{id}
    </delete>

    <delete id="deleteAWishRecordByMap" parameterType="Map">
        delete from a_wish_record where id = #{id} and userId = #{userId}
    </delete>

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