<?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="net.lab1024.sa.admin.module.business.wms.task.dao.TaskDao">

    <!-- 查询结果列 -->
    <sql id="base_columns">
        t_task.task_id,
        t_task.bill_code,
        t_task.status,
        t_task.task_type,
        t_task.plan_qty,
        t_task.move_qty,
        t_task.item_key_id,
        t_task.asn_detail_id,
        t_task.pick_detail_id,
        t_task.src_stock_id,
        t_task.src_stock_code,
        t_task.dst_stock_id,
        t_task.src_location_id,
        t_task.dst_location_id,
        t_task.dst_location_code,
        t_task.src_location_code,
        t_task.dst_stock_code,
        t_task.inventory_id,
        t_task.agv_task_id,
        t_task.be_skip,
        t_task.create_time
    </sql>

    <!-- 分页查询 -->
    <select id="queryPage" resultType="net.lab1024.sa.admin.module.business.wms.task.domain.vo.TaskVO">
        SELECT
        <include refid="base_columns"/>
        FROM t_task
        <!--入库单-->
        <if test="queryForm.asnId != null ">
            LEFT JOIN t_asn_detail on t_asn_detail.asn_detail_id = t_task.asn_detail_id
            LEFT JOIN t_item on t_item.item_id = t_asn_detail.item_id
        </if>
        <!--出库单-->
        <if test="queryForm.pickId != null ">
            LEFT JOIN t_pick_detail on t_pick_detail.pick_detail_id = t_task.pick_detail_id
            LEFT JOIN t_item on t_item.item_id = t_pick_detail.item_id
        </if>
        <where>
            <!--入库单-->
            <if test="queryForm.asnId != null ">
                AND t_asn_detail.asn_id= #{queryForm.asnId}
            </if>

            <!--出库单-->
            <if test="queryForm.pickId != null ">
                AND t_pick_detail.pick_id= #{queryForm.pickId}
            </if>

            <!--任务类型-->
            <if test="queryForm.taskType != null and queryForm.taskType != ''">
                AND t_task.task_type = #{queryForm.taskType}
            </if>

            <!--关键字-->
            <if test="queryForm.asnId != null and queryForm.keywords !=null and queryForm.keywords!= ''">
                AND (t_item.item_code LIKE CONCAT(#{queryForm.keywords}, '%')
                OR t_item.item_name LIKE CONCAT(#{queryForm.keywords}, '%')
                OR t_task.dst_location_code LIKE CONCAT(#{queryForm.keywords}, '%')
                OR t_task.dst_stock_code LIKE CONCAT(#{queryForm.keywords}, '%')
                )
            </if>
        </where>
    </select>


</mapper>
