<?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.huashe.park.core.mapper.ConsMachineCmdHisMapper">

    <resultMap type="ConsMachineCmdHis" id="ConsMachineCmdHisResult">
        <result property="id" column="id"/>
        <result property="toMachineId" column="to_machine_id"/>
        <result property="cmdContent" column="cmd_content"/>
        <result property="cmdResult" column="cmd_result"/>
        <result property="updateTime" column="update_time"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <sql id="selectConsMachineCmdHisVo">
        select id,
               to_machine_id,
               cmd_content,
               cmd_result,
               update_time,
               create_time,
               create_by,
               update_by
        from cons_machine_cmd_his
    </sql>

    <select id="selectConsMachineCmdHisList" parameterType="ConsMachineCmdHis" resultMap="ConsMachineCmdHisResult">
        <include refid="selectConsMachineCmdHisVo"/>
        <where>
            <if test="cmdResult != null  and cmdResult != ''">and cmd_result = #{cmdResult}</if>
        </where>
    </select>

    <select id="selectConsMachineCmdHisById" parameterType="Long" resultMap="ConsMachineCmdHisResult">
        <include refid="selectConsMachineCmdHisVo"/>
        where id = #{id}
    </select>

    <insert id="insertConsMachineCmdHis" parameterType="ConsMachineCmdHis" useGeneratedKeys="true" keyProperty="id">
        insert into cons_machine_cmd_his
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="toMachineId != null">to_machine_id,</if>
            <if test="cmdContent != null">cmd_content,</if>
            <if test="cmdResult != null">cmd_result,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="toMachineId != null">#{toMachineId},</if>
            <if test="cmdContent != null">#{cmdContent},</if>
            <if test="cmdResult != null">#{cmdResult},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateConsMachineCmdHis" parameterType="ConsMachineCmdHis">
        update cons_machine_cmd_his
        <trim prefix="SET" suffixOverrides=",">
            <if test="toMachineId != null">to_machine_id = #{toMachineId},</if>
            <if test="cmdContent != null">cmd_content =
                #{cmdContent},
            </if>
            <if test="cmdResult != null">cmd_result = #{cmdResult},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteConsMachineCmdHisById" parameterType="Long">
        delete
        from cons_machine_cmd_his
        where id = #{id}
    </delete>

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