<?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.aucma.dms.mapper.WcsAgvStatusMapper">

    <resultMap type="WcsAgvStatus" id="WcsAgvStatusResult">
        <result property="battery" column="battery"/>
        <result property="exclType" column="exclType"/>
        <result property="mapCode" column="mapCode"/>
        <result property="online" column="online"/>
        <result property="path" column="path"/>
        <result property="podCode" column="podCode"/>
        <result property="podDir" column="podDir"/>
        <result property="posX" column="posX"/>
        <result property="posY" column="posY"/>
        <result property="robotCode" column="robotCode"/>
        <result property="robotDir" column="robotDir"/>
        <result property="robotIp" column="robotIp"/>
        <result property="speed" column="speed"/>
        <result property="status" column="status"/>
        <result property="stop" column="stop"/>
        <result property="timestamp" column="timestamp"/>
        <result property="agvName" column="agvName"/>
    </resultMap>

    <sql id="selectWcsAgvStatusVo">
        select battery,
               exclType,
               mapCode,
               online,
               path,
               podCode,
               podDir,
               posX,
               posY,
               robotCode,
               robotDir,
               robotIp,
               speed,
               status,
               stop, timestamp, agvName
        from wcs_agv_status
    </sql>

    <select id="selectWcsAgvStatusList" parameterType="WcsAgvStatus" resultMap="WcsAgvStatusResult">
        <include refid="selectWcsAgvStatusVo"/>
        <where>
            <if test="battery != null  and battery != ''">and battery = #{battery}</if>
            <if test="exclType != null  and exclType != ''">and exclType = #{exclType}</if>
            <if test="mapCode != null  and mapCode != ''">and mapCode = #{mapCode}</if>
            <if test="online != null  and online != ''">and online = #{online}</if>
            <if test="path != null  and path != ''">and path = #{path}</if>
            <if test="podCode != null  and podCode != ''">and podCode = #{podCode}</if>
            <if test="podDir != null  and podDir != ''">and podDir = #{podDir}</if>
            <if test="posX != null  and posX != ''">and posX = #{posX}</if>
            <if test="posY != null  and posY != ''">and posY = #{posY}</if>
            <if test="robotDir != null  and robotDir != ''">and robotDir = #{robotDir}</if>
            <if test="robotIp != null  and robotIp != ''">and robotIp = #{robotIp}</if>
            <if test="speed != null  and speed != ''">and speed = #{speed}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
            <if test="stop != null  and stop != ''">and stop = #{stop}</if>
            <if test="params.beginTimestamp != null and params.beginTimestamp != '' and params.endTimestamp != null and params.endTimestamp != ''">
                and timestamp between #{params.beginTimestamp} and #{params.endTimestamp}
            </if>
            <if test="agvName != null  and agvName != ''">and agvName like concat('%', #{agvName}, '%')</if>
        </where>
    </select>

    <select id="selectWcsAgvStatusByRobotCode" parameterType="String" resultMap="WcsAgvStatusResult">
        <include refid="selectWcsAgvStatusVo"/>
        where robotCode = #{robotCode}
    </select>

    <insert id="insertWcsAgvStatus" parameterType="WcsAgvStatus">
        insert into wcs_agv_status
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="battery != null">battery,</if>
            <if test="exclType != null">exclType,</if>
            <if test="mapCode != null">mapCode,</if>
            <if test="online != null">online,</if>
            <if test="path != null">path,</if>
            <if test="podCode != null">podCode,</if>
            <if test="podDir != null">podDir,</if>
            <if test="posX != null">posX,</if>
            <if test="posY != null">posY,</if>
            <if test="robotCode != null">robotCode,</if>
            <if test="robotDir != null">robotDir,</if>
            <if test="robotIp != null">robotIp,</if>
            <if test="speed != null">speed,</if>
            <if test="status != null">status,</if>
            <if test="stop != null">stop,</if>
            <if test="timestamp != null">timestamp,</if>
            <if test="agvName != null">agvName,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="battery != null">#{battery},</if>
            <if test="exclType != null">#{exclType},</if>
            <if test="mapCode != null">#{mapCode},</if>
            <if test="online != null">#{online},</if>
            <if test="path != null">#{path},</if>
            <if test="podCode != null">#{podCode},</if>
            <if test="podDir != null">#{podDir},</if>
            <if test="posX != null">#{posX},</if>
            <if test="posY != null">#{posY},</if>
            <if test="robotCode != null">#{robotCode},</if>
            <if test="robotDir != null">#{robotDir},</if>
            <if test="robotIp != null">#{robotIp},</if>
            <if test="speed != null">#{speed},</if>
            <if test="status != null">#{status},</if>
            <if test="stop != null">#{stop},</if>
            <if test="timestamp != null">#{timestamp},</if>
            <if test="agvName != null">#{agvName},</if>
        </trim>
    </insert>

    <update id="updateWcsAgvStatus" parameterType="WcsAgvStatus">
        update wcs_agv_status
        <trim prefix="SET" suffixOverrides=",">
            <if test="battery != null">battery = #{battery},</if>
            <if test="exclType != null">exclType = #{exclType},</if>
            <if test="mapCode != null">mapCode = #{mapCode},</if>
            <if test="online != null">online = #{online},</if>
            <if test="path != null">path = #{path},</if>
            <if test="podCode != null">podCode = #{podCode},</if>
            <if test="podDir != null">podDir = #{podDir},</if>
            <if test="posX != null">posX = #{posX},</if>
            <if test="posY != null">posY = #{posY},</if>
            <if test="robotDir != null">robotDir = #{robotDir},</if>
            <if test="robotIp != null">robotIp = #{robotIp},</if>
            <if test="speed != null">speed = #{speed},</if>
            <if test="status != null">status = #{status},</if>
            <if test="stop != null">stop = #{stop},</if>
            <if test="timestamp != null">timestamp = #{timestamp},</if>
            <if test="agvName != null">agvName = #{agvName},</if>
        </trim>
        where robotCode = #{robotCode}
    </update>

    <delete id="deleteWcsAgvStatusByRobotCode" parameterType="String">
        delete
        from wcs_agv_status
        where robotCode = #{robotCode}
    </delete>

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