<?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.ss.resetRecord.mapper.SmResetRecordMapper">

    <resultMap type="SmResetRecordVo" id="SmResetRecordResult">
        <result property="id"    column="id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="surplusTime"    column="surplus_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="mchId"    column="mch_id"    />
        <result property="deviceName"    column="device_name"    />
        <result property="mchName"    column="mch_name"    />
    </resultMap>

    <sql id="selectSmResetRecordVo">
        select
            srr.id,
            srr.device_id,
            srr.surplus_time,
            srr.create_time,
            srr.mch_id,
            sd.device_name device_name,
            su.user_name mch_name
        from sm_reset_record srr
            left join sm_device sd on sd.device_id = srr.device_id
            left join sm_user su on su.user_id = srr.mch_id
    </sql>

    <select id="selectSmResetRecordList" parameterType="SmResetRecordQuery" resultMap="SmResetRecordResult">
        <include refid="selectSmResetRecordVo"/>
        <where>
            <if test="deviceId != null "> and srr.device_id = #{deviceId}</if>
            <if test="surplusTime != null "> and srr.surplus_time = #{surplusTime}</if>
            <if test="mchId != null "> and srr.mch_id = #{mchId}</if>
        </where>
        order by srr.create_time desc
    </select>

    <select id="selectSmResetRecordById" parameterType="Long" resultMap="SmResetRecordResult">
        <include refid="selectSmResetRecordVo"/>
        where srr.id = #{id}
    </select>

    <insert id="insertSmResetRecord" parameterType="SmResetRecord">
        insert into sm_reset_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="surplusTime != null">surplus_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="mchId != null">mch_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="surplusTime != null">#{surplusTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="mchId != null">#{mchId},</if>
         </trim>
    </insert>

    <update id="updateSmResetRecord" parameterType="SmResetRecord">
        update sm_reset_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="surplusTime != null">surplus_time = #{surplusTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="mchId != null">mch_id = #{mchId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSmResetRecordById" parameterType="Long">
        delete from sm_reset_record where id = #{id}
    </delete>

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