<?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.record.time.mapper.RecordTimeMapper">

    <resultMap type="RecordTimeVO" id="RecordTimeResult" autoMapping="true"/>

    <sql id="selectRecordTimeVo">
        select
            id,
            device_id,
            amount,
            reason,
            operator_id,
            operator_name,
            operator_type,
            operator_time,
            type
        from ss_record_time
    </sql>

    <select id="selectRecordTimeList" parameterType="RecordTimeQuery" resultMap="RecordTimeResult">
        <include refid="selectRecordTimeVo"/>
        <where>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="amount != null "> and amount = #{amount}</if>
            <if test="reason != null  and reason != ''"> and reason = #{reason}</if>
            <if test="operatorId != null "> and operator_id = #{operatorId}</if>
            <if test="operatorName != null  and operatorName != ''"> and operator_name like concat('%', #{operatorName}, '%')</if>
            <if test="operatorType != null  and operatorType != ''"> and operator_type = #{operatorType}</if>
            <if test="operatorTime != null "> and operator_time = #{operatorTime}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
        </where>
        order by operator_time desc
    </select>

    <select id="selectRecordTimeById" parameterType="Long" resultMap="RecordTimeResult">
        <include refid="selectRecordTimeVo"/>
        where id = #{id}
    </select>

    <insert id="insertRecordTime" parameterType="RecordTime">
        insert into ss_record_time
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="amount != null">amount,</if>
            <if test="reason != null">reason,</if>
            <if test="operatorId != null">operator_id,</if>
            <if test="operatorName != null">operator_name,</if>
            <if test="operatorType != null">operator_type,</if>
            <if test="operatorTime != null">operator_time,</if>
            <if test="type != null and type != ''">type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="amount != null">#{amount},</if>
            <if test="reason != null">#{reason},</if>
            <if test="operatorId != null">#{operatorId},</if>
            <if test="operatorName != null">#{operatorName},</if>
            <if test="operatorType != null">#{operatorType},</if>
            <if test="operatorTime != null">#{operatorTime},</if>
            <if test="type != null and type != ''">#{type},</if>
         </trim>
    </insert>

    <update id="updateRecordTime" parameterType="RecordTime">
        update ss_record_time
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="amount != null">amount = #{amount},</if>
            <if test="reason != null">reason = #{reason},</if>
            <if test="operatorId != null">operator_id = #{operatorId},</if>
            <if test="operatorName != null">operator_name = #{operatorName},</if>
            <if test="operatorType != null">operator_type = #{operatorType},</if>
            <if test="operatorTime != null">operator_time = #{operatorTime},</if>
            <if test="type != null and type != ''">type = #{type},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRecordTimeById" parameterType="Long">
        delete from ss_record_time where id = #{id}
    </delete>

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