<?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.prolog.cs.biz.outbound.dao.PickOrderMapper">
    <resultMap id="map" type="com.prolog.cs.biz.outbound.model.PickOrder">
        <result column="pick_order_id" property="pickOrderId"/>
        <result column="status" property="status"/>
        <result column="warehouse_id" property="warehouseId"/>
        <result column="cart_code" property="cartCode"/>
        <result column="task_count" property="taskCount"/>
        <result column="creator" property="creator"/>
        <result column="creator_name" property="creatorName"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="modifier_name" property="modifierName"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="enterprise_id" property="enterpriseId"/>
        <result column="operator_id" property="operatorId"/>
        <result column="operator_code" property="operatorCode"/>
        <result column="operator_name" property="operatorName"/>
        <result column="pick_task_type" property="pickTaskType"/>
        <result column="pick_task_type" property="pickTaskType"/>
<!--        <result column="bldg_id" property="bldgId"/>-->
        <result column="bldg_name" property="bldgName"/>
    </resultMap>

    <select id="getPickOrderList" resultMap="map">
        select DISTINCT a.*,b.bldg_name,b.type from WMS_PICK_ORDER a,WMS_PICK_TASK_H b
        where a.pick_order_id = b.pick_order_id
        <if test="warehouseId != null and warehouseId != ''">
            and a.WAREHOUSE_ID=#{warehouseId}
        </if>
        <if test="bldgId != null and bldgId != ''">
            and b.bldg_id = #{bldgId}
        </if>
        <choose>
            <when test="pickTaskType=='3'.toString()">
                and a.PICK_TASK_TYPE in ('0','3')
            </when>
            <otherwise>
                and a.PICK_TASK_TYPE = #{pickTaskType}
            </otherwise>
        </choose>
        <if test="operatorCode != null and operatorCode != ''">
            and a.operator_code = #{operatorCode}
        </if>
        <choose>
            <when test="status != null and status =='0'.toString()">
                and a.status = #{status} and b.status in('0','1')
            </when>
            <when test="status != null and status =='1'.toString()">
                and a.status = #{status} and b.status = #{status}
            </when>
            <otherwise>
                and a.status = #{status}
            </otherwise>
        </choose>
        <if test="parames != null and parames != ''">
            and (a.operator_code = #{parames} or a.pick_order_id = #{parames})
        </if>
        order by b.type desc,a.gmt_create desc
    </select>
</mapper>