<?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.MachineProcessMapper">

    <resultMap type="MachineProcess" id="MachineProcessResult">
        <result property="consType" column="cons_type"/>
        <result property="dataVersion" column="data_version"/>
        <result property="dataTime" column="data_time"/>
        <result property="pileId" column="pile_id"/>
        <result property="designId" column="design_id"/>
        <result property="machineId" column="machine_id"/>
        <result property="realX" column="real_x"/>
        <result property="realY" column="real_y"/>
        <result property="realZ" column="real_z"/>
        <result property="latitude" column="latitude"/>
        <result property="longitude" column="longitude"/>
        <result property="pileLength" column="pile_length"/>
        <result property="realPileLength" column="real_pile_length"/>
        <result property="speed" column="speed"/>
        <result property="current" column="current"/>
        <result property="tiltAngle" column="tilt_angle"/>
        <result property="forwardTiltAngle" column="forward_tilt_angle"/>
        <result property="verticalAngle" column="vertical_angle"/>
        <result property="selfNum" column="self_num"/>
        <result property="holdCurrent" column="hold_current"/>
        <result property="sprayVolume" column="spray_volume"/>
        <result property="realDrillHeight" column="real_drill_height"/>
        <result property="vibrationCurrent" column="vibration_current"/>
        <result property="pumpCurrent" column="pump_current"/>
        <result property="sprayPressure" column="spray_pressure"/>
        <result property="spraySpeed" column="spray_speed"/>
        <result property="designLength" column="design_length"/>
        <result property="currentDrillNumber" column="current_drill_number"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="currentMechanicalType" column="current_mechanical_type"/>
        <result property="currentLayer" column="current_layer"/>
        <result property="currentLayerSendTime" column="current_layer_send_time"/>
        <result property="currentLayerHammerNumber" column="current_layer_hammer_number"/>
        <result property="uuid" column="uuid"/>
        <result property="dt" column="dt"/>
        <result property="id" column="id"/>
        <result property="createTime" column="create_time"/>
        <result property="recordTime" column="record_time"/>
        <result property="tenantId" column="tenant_id"/>
    </resultMap>

    <sql id="selectMachineProcessVo">
        select cons_type,
               data_version,
               data_time,
               pile_id,
               design_id,
               machine_id,
               real_x,
               real_y,
               real_z,
               latitude,
               longitude,
               pile_length,
               real_pile_length,
               speed,
               tilt_angle,
               forward_tilt_angle,
               vertical_angle,
               self_num,
               hold_current,
               spray_volume,
               real_drill_height,
               vibration_current,
               pump_current,
               spray_pressure,
               spray_speed,
               design_length,
               current_drill_number,
               start_time,
               end_time,
               current_mechanical_type,
               current_layer,
               current_layer_send_time,
               current_layer_hammer_number,
               uuid,
               dt,
               id,
               create_time,
               record_time,
               `current`,
               tenant_id
        from cons_machine_process
    </sql>

    <select id="selectMachineProcessList" parameterType="MachineProcess" resultMap="MachineProcessResult">
        <include refid="selectMachineProcessVo"/>
        <where>
            <if test="consType != null ">and cons_type = #{consType}</if>
            <if test="dataVersion != null ">and data_version = #{dataVersion}</if>
            <if test="dataTime != null ">and data_time = #{dataTime}</if>
            <if test="pileId != null  and pileId != ''">and pile_id = #{pileId}</if>
            <if test="designId != null  and designId != ''">and design_id = #{designId}</if>
            <if test="machineId != null  and machineId != ''">and machine_id = #{machineId}</if>
            <if test="realX != null ">and real_x = #{realX}</if>
            <if test="realY != null ">and real_y = #{realY}</if>
            <if test="realZ != null ">and real_z = #{realZ}</if>
            <if test="latitude != null ">and latitude = #{latitude}</if>
            <if test="longitude != null ">and longitude = #{longitude}</if>
            <if test="pileLength != null ">and pile_length = #{pileLength}</if>
            <if test="realPileLength != null ">and real_pile_length = #{realPileLength}</if>
            <if test="speed != null ">and speed = #{speed}</if>
            <if test="current != null ">and current = #{current}</if>
            <if test="tiltAngle != null ">and tilt_angle = #{tiltAngle}</if>
            <if test="forwardTiltAngle != null ">and forward_tilt_angle = #{forwardTiltAngle}</if>
            <if test="verticalAngle != null ">and vertical_angle = #{verticalAngle}</if>
            <if test="selfNum != null ">and self_num = #{selfNum}</if>
            <if test="holdCurrent != null ">and hold_current = #{holdCurrent}</if>
            <if test="sprayVolume != null ">and spray_volume = #{sprayVolume}</if>
            <if test="realDrillHeight != null ">and real_drill_height = #{realDrillHeight}</if>
            <if test="vibrationCurrent != null ">and vibration_current = #{vibrationCurrent}</if>
            <if test="pumpCurrent != null ">and pump_current = #{pumpCurrent}</if>
            <if test="sprayPressure != null ">and spray_pressure = #{sprayPressure}</if>
            <if test="spraySpeed != null ">and spray_speed = #{spraySpeed}</if>
            <if test="designLength != null ">and design_length = #{designLength}</if>
            <if test="currentDrillNumber != null ">and current_drill_number = #{currentDrillNumber}</if>
            <if test="startTime != null ">and start_time = #{startTime}</if>
            <if test="endTime != null ">and end_time = #{endTime}</if>
            <if test="currentMechanicalType != null ">and current_mechanical_type = #{currentMechanicalType}</if>
            <if test="currentLayer != null ">and current_layer = #{currentLayer}</if>
            <if test="currentLayerSendTime != null ">and current_layer_send_time = #{currentLayerSendTime}</if>
            <if test="currentLayerHammerNumber != null ">and current_layer_hammer_number = #{currentLayerHammerNumber}
            </if>
            <if test="uuid != null  and uuid != ''">and uuid = #{uuid}</if>
            <if test="dt != null  and dt != ''">and dt = #{dt}</if>
            <if test="id != null ">and id = #{id}</if>
            <if test="recordTime != null">and record_time = #{recordTime}</if>
            <if test="createTime != null">and create_time #{createTime}</if>
        </where>
        order by record_time asc
    </select>

    <select id="selectMachineProcessById" parameterType="Long" resultMap="MachineProcessResult">
        <include refid="selectMachineProcessVo"/>
        where id = #{id}
    </select>

    <insert id="insertMachineProcess" parameterType="MachineProcess" useGeneratedKeys="true" keyProperty="id">
        insert into cons_machine_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="consType != null">cons_type,</if>
            <if test="dataVersion != null">data_version,</if>
            <if test="dataTime != null">data_time,</if>
            <if test="pileId != null">pile_id,</if>
            <if test="designId != null">design_id,</if>
            <if test="machineId != null">machine_id,</if>
            <if test="realX != null">real_x,</if>
            <if test="realY != null">real_y,</if>
            <if test="realZ != null">real_z,</if>
            <if test="latitude != null">latitude,</if>
            <if test="longitude != null">longitude,</if>
            <if test="pileLength != null">pile_length,</if>
            <if test="realPileLength != null">real_pile_length,</if>
            <if test="speed != null">speed,</if>
            <if test="current != null">current,</if>
            <if test="tiltAngle != null">tilt_angle,</if>
            <if test="forwardTiltAngle != null">forward_tilt_angle,</if>
            <if test="verticalAngle != null">vertical_angle,</if>
            <if test="selfNum != null">self_num,</if>
            <if test="holdCurrent != null">hold_current,</if>
            <if test="sprayVolume != null">spray_volume,</if>
            <if test="realDrillHeight != null">real_drill_height,</if>
            <if test="vibrationCurrent != null">vibration_current,</if>
            <if test="pumpCurrent != null">pump_current,</if>
            <if test="sprayPressure != null">spray_pressure,</if>
            <if test="spraySpeed != null">spray_speed,</if>
            <if test="designLength != null">design_length,</if>
            <if test="currentDrillNumber != null">current_drill_number,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="currentMechanicalType != null">current_mechanical_type,</if>
            <if test="currentLayer != null">current_layer,</if>
            <if test="currentLayerSendTime != null">current_layer_send_time,</if>
            <if test="currentLayerHammerNumber != null">current_layer_hammer_number,</if>
            <if test="uuid != null">uuid,</if>
            <if test="dt != null">dt,</if>
            <if test="recordTime != null">record_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="tenantId != null">tenant_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="consType != null">#{consType},</if>
            <if test="dataVersion != null">#{dataVersion},</if>
            <if test="dataTime != null">#{dataTime},</if>
            <if test="pileId != null">#{pileId},</if>
            <if test="designId != null">#{designId},</if>
            <if test="machineId != null">#{machineId},</if>
            <if test="realX != null">#{realX},</if>
            <if test="realY != null">#{realY},</if>
            <if test="realZ != null">#{realZ},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="pileLength != null">#{pileLength},</if>
            <if test="realPileLength != null">#{realPileLength},</if>
            <if test="speed != null">#{speed},</if>
            <if test="current != null">#{current},</if>
            <if test="tiltAngle != null">#{tiltAngle},</if>
            <if test="forwardTiltAngle != null">#{forwardTiltAngle},</if>
            <if test="verticalAngle != null">#{verticalAngle},</if>
            <if test="selfNum != null">#{selfNum},</if>
            <if test="holdCurrent != null">#{holdCurrent},</if>
            <if test="sprayVolume != null">#{sprayVolume},</if>
            <if test="realDrillHeight != null">#{realDrillHeight},</if>
            <if test="vibrationCurrent != null">#{vibrationCurrent},</if>
            <if test="pumpCurrent != null">#{pumpCurrent},</if>
            <if test="sprayPressure != null">#{sprayPressure},</if>
            <if test="spraySpeed != null">#{spraySpeed},</if>
            <if test="designLength != null">#{designLength},</if>
            <if test="currentDrillNumber != null">#{currentDrillNumber},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="currentMechanicalType != null">#{currentMechanicalType},</if>
            <if test="currentLayer != null">#{currentLayer},</if>
            <if test="currentLayerSendTime != null">#{currentLayerSendTime},</if>
            <if test="currentLayerHammerNumber != null">#{currentLayerHammerNumber},</if>
            <if test="uuid != null">#{uuid},</if>
            <if test="dt != null">#{dt},</if>
            <if test="recordTime != null">#{recordTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="tenantId != null">#{tenantId},</if>
        </trim>
    </insert>

    <insert id="insertMachineProcessOrUpdate" parameterType="MachineProcess" useGeneratedKeys="true" keyProperty="id">
        insert into cons_machine_process
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="consType != null">cons_type,</if>
            <if test="dataVersion != null">data_version,</if>
            <if test="dataTime != null">data_time,</if>
            <if test="pileId != null">pile_id,</if>
            <if test="designId != null">design_id,</if>
            <if test="machineId != null">machine_id,</if>
            <if test="realX != null">real_x,</if>
            <if test="realY != null">real_y,</if>
            <if test="realZ != null">real_z,</if>
            <if test="latitude != null">latitude,</if>
            <if test="longitude != null">longitude,</if>
            <if test="pileLength != null">pile_length,</if>
            <if test="realPileLength != null">real_pile_length,</if>
            <if test="speed != null">speed,</if>
            <if test="current != null">current,</if>
            <if test="tiltAngle != null">tilt_angle,</if>
            <if test="forwardTiltAngle != null">forward_tilt_angle,</if>
            <if test="verticalAngle != null">vertical_angle,</if>
            <if test="selfNum != null">self_num,</if>
            <if test="holdCurrent != null">hold_current,</if>
            <if test="sprayVolume != null">spray_volume,</if>
            <if test="realDrillHeight != null">real_drill_height,</if>
            <if test="vibrationCurrent != null">vibration_current,</if>
            <if test="pumpCurrent != null">pump_current,</if>
            <if test="sprayPressure != null">spray_pressure,</if>
            <if test="spraySpeed != null">spray_speed,</if>
            <if test="designLength != null">design_length,</if>
            <if test="currentDrillNumber != null">current_drill_number,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="currentMechanicalType != null">current_mechanical_type,</if>
            <if test="currentLayer != null">current_layer,</if>
            <if test="currentLayerSendTime != null">current_layer_send_time,</if>
            <if test="currentLayerHammerNumber != null">current_layer_hammer_number,</if>
            <if test="uuid != null">uuid,</if>
            <if test="dt != null">dt,</if>
            <if test="recordTime != null">record_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="tenantId != null">tenant_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="consType != null">#{consType},</if>
            <if test="dataVersion != null">#{dataVersion},</if>
            <if test="dataTime != null">#{dataTime},</if>
            <if test="pileId != null">#{pileId},</if>
            <if test="designId != null">#{designId},</if>
            <if test="machineId != null">#{machineId},</if>
            <if test="realX != null">#{realX},</if>
            <if test="realY != null">#{realY},</if>
            <if test="realZ != null">#{realZ},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="pileLength != null">#{pileLength},</if>
            <if test="realPileLength != null">#{realPileLength},</if>
            <if test="speed != null">#{speed},</if>
            <if test="current != null">#{current},</if>
            <if test="tiltAngle != null">#{tiltAngle},</if>
            <if test="forwardTiltAngle != null">#{forwardTiltAngle},</if>
            <if test="verticalAngle != null">#{verticalAngle},</if>
            <if test="selfNum != null">#{selfNum},</if>
            <if test="holdCurrent != null">#{holdCurrent},</if>
            <if test="sprayVolume != null">#{sprayVolume},</if>
            <if test="realDrillHeight != null">#{realDrillHeight},</if>
            <if test="vibrationCurrent != null">#{vibrationCurrent},</if>
            <if test="pumpCurrent != null">#{pumpCurrent},</if>
            <if test="sprayPressure != null">#{sprayPressure},</if>
            <if test="spraySpeed != null">#{spraySpeed},</if>
            <if test="designLength != null">#{designLength},</if>
            <if test="currentDrillNumber != null">#{currentDrillNumber},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="currentMechanicalType != null">#{currentMechanicalType},</if>
            <if test="currentLayer != null">#{currentLayer},</if>
            <if test="currentLayerSendTime != null">#{currentLayerSendTime},</if>
            <if test="currentLayerHammerNumber != null">#{currentLayerHammerNumber},</if>
            <if test="uuid != null">#{uuid},</if>
            <if test="dt != null">#{dt},</if>
            <if test="recordTime != null">#{recordTime},</if>
            <if test="createTime != null">now(),</if>
            <if test="tenantId != null">#{tenantId},</if>
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <!-- 根据唯一约束字段自动更新（假设唯一键为uuid） -->
            <if test="consType != null">cons_type = VALUES(cons_type),</if>
            <if test="dataVersion != null">data_version = VALUES(data_version),</if>
            <if test="dataTime != null">data_time = VALUES(data_time),</if>
            <if test="pileId != null">pile_id = VALUES(pile_id),</if>
            <if test="designId != null">design_id = VALUES(design_id),</if>
            <if test="machineId != null">machine_id = VALUES(machine_id),</if>
            <if test="realX != null">real_x = VALUES(real_x),</if>
            <if test="realY != null">real_y = VALUES(real_y),</if>
            <if test="realZ != null">real_z = VALUES(real_z),</if>
            <if test="latitude != null">latitude = VALUES(latitude),</if>
            <if test="longitude != null">longitude = VALUES(longitude),</if>
            <if test="pileLength != null">pile_length = VALUES(pile_length),</if>
            <if test="realPileLength != null">real_pile_length = VALUES(real_pile_length),</if>
            <if test="speed != null">speed = VALUES(speed),</if>
            <if test="current != null">current = VALUES(current),</if>
            <if test="tiltAngle != null">tilt_angle = VALUES(tilt_angle),</if>
            <if test="forwardTiltAngle != null">forward_tilt_angle = VALUES(forward_tilt_angle),</if>
            <if test="verticalAngle != null">vertical_angle = VALUES(vertical_angle),</if>
            <if test="selfNum != null">self_num = VALUES(self_num),</if>
            <if test="holdCurrent != null">hold_current = VALUES(hold_current),</if>
            <if test="sprayVolume != null">spray_volume = VALUES(spray_volume),</if>
            <if test="realDrillHeight != null">real_drill_height = VALUES(real_drill_height),</if>
            <if test="vibrationCurrent != null">vibration_current = VALUES(vibration_current),</if>
            <if test="pumpCurrent != null">pump_current = VALUES(pump_current),</if>
            <if test="sprayPressure != null">spray_pressure = VALUES(spray_pressure),</if>
            <if test="spraySpeed != null">spray_speed = VALUES(spray_speed),</if>
            <if test="designLength != null">design_length = VALUES(design_length),</if>
            <if test="currentDrillNumber != null">current_drill_number = VALUES(current_drill_number),</if>
            <if test="startTime != null">start_time = VALUES(start_time),</if>
            <if test="endTime != null">end_time = VALUES(end_time),</if>
            <if test="currentMechanicalType != null">current_mechanical_type = VALUES(current_mechanical_type),</if>
            <if test="currentLayer != null">current_layer = VALUES(current_layer),</if>
            <if test="currentLayerSendTime != null">current_layer_send_time = VALUES(current_layer_send_time),</if>
            <if test="currentLayerHammerNumber != null">current_layer_hammer_number =
                VALUES(current_layer_hammer_number),
            </if>
            <if test="dt != null">dt = VALUES(dt),</if>
            <if test="recordTime != null">record_time = VALUES(record_time),</if>
            <if test="createTime != null">create_time = NOW(),</if>
            <if test="tenantId != null">tenant_id = VALUES(tenant_id),</if>
        </trim>
    </insert>

    <update id="updateMachineProcess" parameterType="MachineProcess">
        update cons_machine_process
        <trim prefix="SET" suffixOverrides=",">
            <if test="consType != null">cons_type = #{consType},</if>
            <if test="dataVersion != null">data_version = #{dataVersion},</if>
            <if test="dataTime != null">data_time = #{dataTime},</if>
            <if test="pileId != null">pile_id = #{pileId},</if>
            <if test="designId != null">design_id = #{designId},</if>
            <if test="machineId != null">machine_id = #{machineId},</if>
            <if test="realX != null">real_x = #{realX},</if>
            <if test="realY != null">real_y = #{realY},</if>
            <if test="realZ != null">real_z = #{realZ},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="pileLength != null">pile_length = #{pileLength},</if>
            <if test="realPileLength != null">real_pile_length = #{realPileLength},</if>
            <if test="speed != null">speed = #{speed},</if>
            <if test="current != null">current = #{current},</if>
            <if test="tiltAngle != null">tilt_angle = #{tiltAngle},</if>
            <if test="forwardTiltAngle != null">forward_tilt_angle = #{forwardTiltAngle},</if>
            <if test="verticalAngle != null">vertical_angle = #{verticalAngle},</if>
            <if test="selfNum != null">self_num = #{selfNum},</if>
            <if test="holdCurrent != null">hold_current = #{holdCurrent},</if>
            <if test="sprayVolume != null">spray_volume = #{sprayVolume},</if>
            <if test="realDrillHeight != null">real_drill_height = #{realDrillHeight},</if>
            <if test="vibrationCurrent != null">vibration_current = #{vibrationCurrent},</if>
            <if test="pumpCurrent != null">pump_current = #{pumpCurrent},</if>
            <if test="sprayPressure != null">spray_pressure = #{sprayPressure},</if>
            <if test="spraySpeed != null">spray_speed = #{spraySpeed},</if>
            <if test="designLength != null">design_length = #{designLength},</if>
            <if test="currentDrillNumber != null">current_drill_number = #{currentDrillNumber},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="currentMechanicalType != null">current_mechanical_type = #{currentMechanicalType},</if>
            <if test="currentLayer != null">current_layer = #{currentLayer},</if>
            <if test="currentLayerSendTime != null">current_layer_send_time = #{currentLayerSendTime},</if>
            <if test="currentLayerHammerNumber != null">current_layer_hammer_number = #{currentLayerHammerNumber},</if>
            <if test="uuid != null">uuid = #{uuid},</if>
            <if test="dt != null">dt = #{dt},</if>
            <if test="recordTime != null">record_time = #{recordTime},</if>
            <if test="createTime != null">create_time = NOW(),</if>
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMachineProcessById" parameterType="Long">
        delete
        from cons_machine_process
        where id = #{id}
    </delete>

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