<?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.tongran.system.mapper.RmRegistrationMachineMapper">
    
    <resultMap type="RmRegistrationMachine" id="RmRegistrationMachineResult">
        <result property="id"    column="id"    />
        <result property="clientId"    column="client_id"    />
        <result property="machineCode"    column="machine_code"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectRmRegistrationMachineVo">
        select id, client_id, machine_code, create_time, update_time, create_by, update_by from rm_registration_machine
    </sql>

    <select id="selectRmRegistrationMachineList" parameterType="RmRegistrationMachine" resultMap="RmRegistrationMachineResult">
        <include refid="selectRmRegistrationMachineVo"/>
        <where>  
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
            <if test="machineCode != null  and machineCode != ''"> and machine_code = #{machineCode}</if>
        </where>
    </select>
    
    <select id="selectRmRegistrationMachineById" parameterType="Long" resultMap="RmRegistrationMachineResult">
        <include refid="selectRmRegistrationMachineVo"/>
        where id = #{id}
    </select>

    <insert id="insertRmRegistrationMachine" parameterType="RmRegistrationMachine" useGeneratedKeys="true" keyProperty="id">
        insert into rm_registration_machine
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id,</if>
            <if test="machineCode != null and machineCode != ''">machine_code,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">#{clientId},</if>
            <if test="machineCode != null and machineCode != ''">#{machineCode},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateRmRegistrationMachine" parameterType="RmRegistrationMachine">
        update rm_registration_machine
        <trim prefix="SET" suffixOverrides=",">
            <if test="clientId != null and clientId != ''">client_id = #{clientId},</if>
            <if test="machineCode != null and machineCode != ''">machine_code = #{machineCode},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRmRegistrationMachineById" parameterType="Long">
        delete from rm_registration_machine where id = #{id}
    </delete>

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

    <select id="getAllMachineClientId" resultType="RmRegistrationMachine">
        select client_id clientId from rm_registration_machine
        <where>
            and client_id != ''
        </where>
        group by client_id
    </select>
</mapper>