<?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.zg.project.wisdom.mapper.AgvTaskResultMapper">

    <resultMap id="AgvTaskResultResultMap" type="AgvTaskResult">
        <result property="id" column="id"/>
        <result property="requestId" column="request_id"/>
        <result property="taskNo" column="task_no"/>
        <result property="status" column="status"/>
        <result property="msg" column="msg"/>
        <result property="jobId" column="job_id"/>
        <result property="owner" column="owner"/>
        <result property="type" column="type"/>
        <result property="priority" column="priority"/>
        <result property="sourceName" column="source_name"/>
        <result property="targetName" column="target_name"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="isDelete" column="is_delete"/>
    </resultMap>


    <sql id="selectAgvTaskResultVo">
        id,
    request_id,
    task_no,
    status,
    msg,
    job_id,
    owner,
    type,
    priority,
    source_name,
    target_name,
    create_by,
    create_time,
    update_by,
    update_time,
    is_delete
    </sql>

    <select id="selectAgvTaskResultById" resultMap="AgvTaskResultResultMap">
        SELECT <include refid="selectAgvTaskResultVo"/> FROM agv_task_result WHERE id = #{id}
    </select>

    <select id="selectAgvTaskResultList" resultMap="AgvTaskResultResultMap">
        SELECT <include refid="selectAgvTaskResultVo"/> FROM agv_task_result
        <where>
            <if test="taskNo != null and taskNo != ''">AND task_no = #{taskNo}</if>
            <if test="status != null">AND status = #{status}</if>
            AND is_delete = '0'
        </where>
    </select>

    <select id="selectByRequestId" resultMap="AgvTaskResultResultMap">
        SELECT * FROM agv_task_result WHERE request_id = #{requestId} AND is_delete = '0'
    </select>

    <select id="countByRequestIdAndStatus" resultType="int">
        SELECT COUNT(*) FROM agv_task_result
        WHERE request_id = #{requestId}
          AND status = #{status}
          AND is_delete = '0'
    </select>

    <select id="selectByTaskNo" resultType="com.zg.project.wisdom.domain.AgvTaskResult">
        SELECT * FROM agv_task_result WHERE task_no = #{taskNo} AND is_delete = '0'
    </select>
    <select id="countByTaskNo" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM agv_task_result WHERE task_no = #{taskNo} AND is_delete = '0'
    </select>

    <insert id="insertAgvTaskResult" parameterType="AgvTaskResult" useGeneratedKeys="true" keyProperty="id">
        INSERT INTO agv_task_result
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="requestId != null">request_id,</if>
            <if test="taskNo != null">task_no,</if>
            <if test="status != null">status,</if>
            <if test="msg != null">msg,</if>
            <if test="jobId != null">job_id,</if>
            <if test="owner != null">owner,</if>
            <if test="type != null">type,</if>
            <if test="priority != null">priority,</if>
            <if test="sourceName != null">source_name,</if>
            <if test="targetName != null">target_name,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            create_time,
            update_time,
            is_delete
        </trim>
        VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="requestId != null">#{requestId},</if>
            <if test="taskNo != null">#{taskNo},</if>
            <if test="status != null">#{status},</if>
            <if test="msg != null">#{msg},</if>
            <if test="jobId != null">#{jobId},</if>
            <if test="owner != null">#{owner},</if>
            <if test="type != null">#{type},</if>
            <if test="priority != null">#{priority},</if>
            <if test="sourceName != null">#{sourceName},</if>
            <if test="targetName != null">#{targetName},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            NOW(),
            NOW(),
            '0'
        </trim>
    </insert>

    <update id="updateAgvTaskResult" parameterType="AgvTaskResult">
        UPDATE agv_task_result SET
              request_id = #{requestId},
              task_no = #{taskNo},
              status = #{status},
              msg = #{msg},
              update_by = #{updateBy},
              update_time = NOW()
        WHERE id = #{id}
    </update>

    <delete id="deleteAgvTaskResultById">
        DELETE FROM agv_task_result WHERE id = #{id}
    </delete>

    <delete id="deleteAgvTaskResultByIds">
        DELETE FROM agv_task_result WHERE id IN
        <foreach collection="array" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>
