<?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.shkj.wms.mapper.BusinDataTaskMapper">

    <resultMap type="com.shkj.wms.domain.BusinDataTask" id="BusinDataTaskInResult">
        <result property="taskCode" column="task_Code"/>
        <result property="taskStatus" column="task_Status"/>
        <result property="taskType" column="task_Type"/>
        <result property="taskPath" column="task_Path"/>
        <result property="isUrgent" column="is_Urgent"/>
        <result property="isTop" column="is_Top"/>
        <result property="priority" column="priority"/>
        <result property="fromRow" column="fromR_ow"/>
        <result property="fromColumn" column="from_Column"/>
        <result property="fromLayer" column="from_Layer"/>
        <result property="fromSide" column="from_Side"/>
        <result property="toRow" column="to_Row"/>
        <result property="toColumn" column="to_Column"/>
        <result property="toLayer" column="to_Layer"/>
        <result property="toSide" column="to_Side"/>
        <result property="plcId" column="plc_id"/>
        <result property="isDown" column="is_down"/>
    </resultMap>

    <select id="selectBusinDataTaskByQrcode" resultMap="BusinDataTaskInResult"
            parameterType="String">
        SELECT
        *
        FROM
        busin_data_task
        <if test="qrCode !=null ">
            WHERE
            busin_data_task.qr_code =#{qrCode}
        </if>
    </select>

    <select id="getBusinDataTaskByTraverseDate" resultMap="BusinDataTaskInResult"
            parameterType="String">
        SELECT
        *
        FROM
        busin_data_task
        <if test="traverseDate !=null ">
            WHERE busin_data_task.traverse_date =#{traverseDate}
        </if>
    </select>

    <select id="selectBusinDataTask" resultType="com.shkj.wms.vo.BusinDataTaskVo" parameterType="com.shkj.wms.bo.BusinTaskQueryBo">
        select * from busin_data_task
        where task_status in ('0','-1')
        order by is_top,is_urgent,create_time desc,traverse_date desc
        limit 5
    </select>

    <select id="selectBusinDataTaskByKeys" resultType="com.shkj.wms.vo.BusinDataTaskVo" parameterType="com.shkj.wms.bo.BusinTaskQueryBo">
        select task.* from busin_data_task task inner join
        base_container container on task.container_id=container.id
        where  task_status !=2
        <if test="keywords !=null ">
            and container.container_code =#{keywords}
        </if>
        ORDER BY task.id desc
        limit 1
    </select>

    <insert id="insertBusinDataTask" parameterType="BusinDataTask" useGeneratedKeys="true" keyProperty="id">
        insert into busin_data_task
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskCode != null">task_code,</if>
            <if test="taskStatus != null">task_status,</if>
            <if test="taskType != null">task_type,</if>
            <if test="exceptionMsg != null">exception_msg,</if>
            <if test="taskPath != null">task_path,</if>
            <if test="batch != null">batch,</if>
            <if test="isUrgent != null">is_urgent,</if>
            <if test="isTop != null">is_top,</if>
            <if test="priority != null">priority,</if>
            <if test="fromRow != null">from_row,</if>
            <if test="fromColumn != null">from_column,</if>
            <if test="fromLayer != null">from_layer,</if>
            <if test="fromSide != null">from_side,</if>
            <if test="toRow != null">to_row,</if>
            <if test="toColumn != null">to_column,</if>
            <if test="toLayer != null">to_layer,</if>
            <if test="toSide != null">to_side,</if>
            <if test="taskStarttime != null">task_starttime,</if>
            <if test="taskEntime != null">task_entime,</if>
            <if test="remark != null">remark,</if>
            <if test="plcId != null">plc_id,</if>
            <if test="agvNo != null">agv_no,</if>
            <if test="punchNo != null">punch_no,</if>
            <if test="dpsNoOne != null">dps_no_one,</if>
            <if test="dpsNoTwo != null">dps_no_two,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="traverseDate != null">traverse_date,</if>
            <if test="containerId != null">container_id,</if>
            <if test="transId != null">trans_id,</if>
            <if test="branchId != null">branch_id,</if>
            <if test="points != null">points,</if>
            <if test="isDown != null">is_down,</if>

        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskCode != null">#{taskCode},</if>
            <if test="taskStatus != null">#{taskStatus},</if>
            <if test="taskType != null">#{taskType},</if>
            <if test="exceptionMsg != null">#{exceptionMsg},</if>
            <if test="taskPath != null">#{taskPath},</if>
            <if test="batch != null">#{batch},</if>
            <if test="isUrgent != null">#{isUrgent},</if>
            <if test="isTop != null">#{isTop},</if>
            <if test="priority != null">#{priority},</if>
            <if test="fromRow != null">#{fromRow},</if>
            <if test="fromColumn != null">#{fromColumn},</if>
            <if test="fromLayer != null">#{fromLayer},</if>
            <if test="fromSide != null">#{fromSide},</if>
            <if test="toRow != null">#{toRow},</if>
            <if test="toColumn != null">#{toColumn},</if>
            <if test="toLayer != null">#{toLayer},</if>
            <if test="toSide != null">#{toSide},</if>
            <if test="taskStarttime != null">#{taskStarttime},</if>
            <if test="taskEntime != null">#{taskEntime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="plcId != null">#{plcId},</if>
            <if test="agvNo != null">#{agvNo},</if>
            <if test="punchNo != null">#{punchNo},</if>
            <if test="dpsNoOne != null">#{dpsNoOne},</if>
            <if test="dpsNoTwo != null">#{dpsNoTwo},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="traverseDate != null">#{traverseDate},</if>
            <if test="containerId != null">#{containerId},</if>
            <if test="transId != null">#{transId},</if>
            <if test="branchId != null">#{branchId},</if>
            <if test="points != null">#{points},</if>
            <if test="isDown != null">#{isDown},</if>

        </trim>

        <selectKey resultType="java.lang.Long" keyProperty="id">
            SELECT LAST_INSERT_ID()
        </selectKey>

    </insert>

</mapper>
