<?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.hw.mes.mapper.MesPurchaseOrderMapper" >
<resultMap type= "MesPurchaseOrder" id= "MesPurchaseOrderResult" >
<result property= "purchaseOrderId" column= "purchase_order_id" />
<result property= "erpId" column= "erp_id" />
<result property= "fentryId" column= "fentry_id" />
<result property= "poNo" column= "po_no" />
<result property= "documentStatus" column= "document_status" />
<result property= "materialId" column= "material_id" />
<result property= "materialCode" column= "material_code" />
<result property= "materialName" column= "material_name" />
<result property= "purchaseOrderClassfication" column= "purchase_order_classfication" />
<result property= "orderAmount" column= "order_amount" />
<result property= "completeAmount" column= "complete_amount" />
<result property= "approveDate" column= "approve_date" />
<result property= "erpModifyDate" column= "erp_modify_date" />
<result property= "planDeliveryDate" column= "plan_delivery_date" />
<result property= "beginDate" column= "begin_date" />
<result property= "endDate" column= "end_date" />
<result property= "orderStatus" column= "order_status" />
<result property= "completeDate" column= "complete_date" />
<result property= "isFlag" column= "is_flag" />
<result property= "unitId" column= "unit_id" />
<result property= "stockUnitId" column= "stock_unit_id" />
<result property= "priceUnitId" column= "price_unit_id" />
<result property= "auxPropId" column= "aux_prop_id" />
<result property= "srcBillNo" column= "src_bill_no" />
<result property= "purchaseOrgId" column= "purchase_org_id" />
<result property= "tondBase" column= "tond_base" />
<result property= "supplierId" column= "supplier_id" />
<result property= "remark" column= "remark" />
<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= "specificationParameter" column= "specification_parameter" />
<result property= "materialSpec" column= "material_spec" />
<result property= "orderBindId" column= "order_bind_id" />
<result property= "boundAmount" column= "bound_amount" />
<result property= "saleBindAmount" column= "sale_bind_amount" />
<result property= "safeAmount" column= "safe_amount" />
<result property= "barcodeAmount" column= "barcode_amount" />
<result property= "erpMaterialId" column= "erp_material_id" />
<result property= "batchFlag" column= "batch_flag" />
<result property= "batchAmount" column= "batch_amount" />
<result property= "mesMaterialId" column= "mes_material_id" />
<result property= "orderBindBarcodeAmount" column= "order_bind_barcode_amount" />
<result property= "safeBindBarcodeAmount" column= "safe_bind_barcode_amount" />
<result property= "alwaysFlag" column= "always_flag" />
<result property= "productId" column= "product_id" />
<result property= "productCode" column= "product_code" />
<result property= "productName" column= "product_name" />
<result property= "productSpec" column= "product_spec" />
<result property= "safeFlag" column= "safe_flag" />
<result property= "saleOrderId" column= "sale_order_id" />
<result property= "saleOrderCode" column= "sale_order_code" />
<result property= "bindAmount" column= "bind_amount" />
<result property= "saleOrderAmount" column= "sale_order_amount" />
<result property= "supplierCode" column= "supplier_code" />
<result property= "projectNo" column= "project_no" />
</resultMap>
<resultMap id= "MesPurchaseOrderMesOrderBindResult" type= "MesPurchaseOrder" extends= "MesPurchaseOrderResult" >
<collection property= "mesOrderBindList" notNullColumn= "sub_order_bind_id" javaType= "java.util.List" resultMap= "MesOrderBindResult" />
</resultMap>
<resultMap type= "MesOrderBind" id= "MesOrderBindResult" >
<result property= "orderBindId" column= "sub_order_bind_id" />
<result property= "safeFlag" column= "sub_safe_flag" />
<result property= "saleOrderId" column= "sub_sale_order_id" />
<result property= "saleOrderCode" column= "sub_sale_order_code" />
<result property= "productId" column= "sub_product_id" />
<result property= "productCode" column= "sub_product_code" />
<result property= "productName" column= "sub_product_name" />
<result property= "purchaseOrderId" column= "sub_purchase_order_id" />
<result property= "poNo" column= "sub_po_no" />
<result property= "materialId" column= "sub_material_id" />
<result property= "materialCode" column= "sub_material_code" />
<result property= "materialName" column= "sub_material_name" />
<result property= "bindAmount" column= "sub_bind_amount" />
<result property= "remark" column= "sub_remark" />
<result property= "createBy" column= "sub_create_by" />
<result property= "createTime" column= "sub_create_time" />
<result property= "updateBy" column= "sub_update_by" />
<result property= "updateTime" column= "sub_update_time" />
<result property= "productSpec" column= "sub_product_spec" />
<result property= "barcodeAmount" column= "sub_barcode_amount" />
</resultMap>
<sql id= "selectMesPurchaseOrderVo" >
select purchase_order_id, erp_id, fentry_id, po_no, document_status, material_id, material_code, material_name, order_amount, complete_amount, approve_date, erp_modify_date, plan_delivery_date, begin_date, end_date, order_status, complete_date, is_flag, unit_id, stock_unit_id, price_unit_id, aux_prop_id, specification_parameter, src_bill_no, purchase_org_id, tond_base, supplier_id, remark, create_by, create_time, update_by, update_time from mes_purchase_order
</sql>
<select id= "selectMesPurchaseOrderList" parameterType= "MesPurchaseOrder" resultMap= "MesPurchaseOrderResult" >
<include refid= "selectMesPurchaseOrderVo" />
<where >
<if test= "erpId != null " > and erp_id = #{erpId}</if>
<if test= "fentryId != null " > and fentry_id = #{fentryId}</if>
<if test= "poNo != null and poNo != ''" > and po_no = #{poNo}</if>
<if test= "documentStatus != null and documentStatus != ''" > and document_status = #{documentStatus}</if>
<if test= "materialId != null " > and material_id = #{materialId}</if>
<if test= "materialCode != null and materialCode != ''" > and material_code = #{materialCode}</if>
<if test= "materialName != null and materialName != ''" > and material_name like concat('%', #{materialName}, '%')</if>
<if test= "orderAmount != null " > and order_amount = #{orderAmount}</if>
<if test= "completeAmount != null " > and complete_amount = #{completeAmount}</if>
<if test= "approveDate != null " > and approve_date = #{approveDate}</if>
<if test= "erpModifyDate != null " > and erp_modify_date = #{erpModifyDate}</if>
<if test= "planDeliveryDate != null " > and plan_delivery_date = #{planDeliveryDate}</if>
<if test= "beginDate != null " > and begin_date = #{beginDate}</if>
<if test= "endDate != null " > and end_date = #{endDate}</if>
<if test= "orderStatus != null and orderStatus != ''" > and order_status = #{orderStatus}</if>
<if test= "completeDate != null " > and complete_date = #{completeDate}</if>
<if test= "isFlag != null and isFlag != ''" > and is_flag = #{isFlag}</if>
<if test= "srcBillNo != null and srcBillNo != ''" > and src_bill_no like concat('%', #{srcBillNo}, '%')</if>
<if test= "tondBase != null and tondBase != ''" > and tond_base like concat('%', #{tondBase}, '%')</if>
</where>
</select>
<select id= "selectMesPurchaseOrderByPurchaseOrderId" parameterType= "Long" resultMap= "MesPurchaseOrderMesOrderBindResult" >
select a.purchase_order_id, a.po_no, a.document_status, mbmi1.material_id,a.material_id as erp_material_id,
a.material_code, a.material_name, a.order_amount, a.complete_amount, a.approve_date,a.specification_parameter,
a.erp_modify_date, a.plan_delivery_date, a.order_status, a.complete_date,
a.is_flag, a.src_bill_no,
a.purchase_org_id, a.tond_base, a.supplier_id,a.create_by, a.create_time, a.update_by, a.update_time,
b.order_bind_id as sub_order_bind_id, b.safe_flag as sub_safe_flag, b.sale_order_id as sub_sale_order_id,
b.sale_order_code as sub_sale_order_code, b.product_id as sub_product_id,
mbmi.material_code as sub_product_code, mbmi.material_name as sub_product_name, mbmi.material_spec as sub_product_spec,
b.purchase_order_id as sub_purchase_order_id, b.po_no as sub_po_no,
b.material_id as sub_material_id, b.material_code as sub_material_code,
b.material_name as sub_material_name, b.bind_amount as sub_bind_amount, b.barcode_amount as sub_barcode_amount
from mes_purchase_order a
left join mes_order_bind b on b.purchase_order_id = a.purchase_order_id
left join mes_base_material_info mbmi on b.product_id=mbmi.erp_id
left join mes_base_material_info mbmi1 on a.material_id = mbmi1.erp_id
where a.purchase_order_id = #{purchaseOrderId}
</select>
<insert id= "insertMesPurchaseOrder" parameterType= "MesPurchaseOrder" useGeneratedKeys= "true" keyProperty= "purchaseOrderId" >
insert into mes_purchase_order
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "erpId != null" > erp_id,</if>
<if test= "fentryId != null" > fentry_id,</if>
<if test= "poNo != null" > po_no,</if>
<if test= "documentStatus != null" > document_status,</if>
<if test= "materialId != null" > material_id,</if>
<if test= "materialCode != null and materialCode != ''" > material_code,</if>
<if test= "materialName != null" > material_name,</if>
<if test= "purchaseOrderClassfication != null" > purchase_order_classfication,</if>
<if test= "orderAmount != null" > order_amount,</if>
<if test= "completeAmount != null" > complete_amount,</if>
<if test= "approveDate != null" > approve_date,</if>
<if test= "erpModifyDate != null" > erp_modify_date,</if>
<if test= "planDeliveryDate != null" > plan_delivery_date,</if>
<if test= "beginDate != null" > begin_date,</if>
<if test= "endDate != null" > end_date,</if>
<if test= "orderStatus != null" > order_status,</if>
<if test= "completeDate != null" > complete_date,</if>
<if test= "isFlag != null and isFlag != ''" > is_flag,</if>
<if test= "remark != null" > remark,</if>
<if test= "createBy != null" > create_by,</if>
<if test= "createTime != null" > create_time,</if>
<if test= "updateBy != null" > update_by,</if>
<if test= "updateTime != null" > update_time,</if>
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "erpId != null" > #{erpId},</if>
<if test= "fentryId != null" > #{fentryId},</if>
<if test= "poNo != null" > #{poNo},</if>
<if test= "documentStatus != null" > #{documentStatus},</if>
<if test= "materialId != null" > #{materialId},</if>
<if test= "materialCode != null and materialCode != ''" > #{materialCode},</if>
<if test= "materialName != null" > #{materialName},</if>
<if test= "purchaseOrderClassfication != null" > #{purchaseOrderClassfication},</if>
<if test= "orderAmount != null" > #{orderAmount},</if>
<if test= "completeAmount != null" > #{completeAmount},</if>
<if test= "approveDate != null" > #{approveDate},</if>
<if test= "erpModifyDate != null" > #{erpModifyDate},</if>
<if test= "planDeliveryDate != null" > #{planDeliveryDate},</if>
<if test= "beginDate != null" > #{beginDate},</if>
<if test= "endDate != null" > #{endDate},</if>
<if test= "orderStatus != null" > #{orderStatus},</if>
<if test= "completeDate != null" > #{completeDate},</if>
<if test= "isFlag != null and isFlag != ''" > #{isFlag},</if>
<if test= "remark != null" > #{remark},</if>
<if test= "createBy != null" > #{createBy},</if>
<if test= "createTime != null" > #{createTime},</if>
<if test= "updateBy != null" > #{updateBy},</if>
<if test= "updateTime != null" > #{updateTime},</if>
</trim>
</insert>
<update id= "updateMesPurchaseOrder" parameterType= "MesPurchaseOrder" >
update mes_purchase_order
<trim prefix= "SET" suffixOverrides= "," >
<if test= "erpId != null" > erp_id = #{erpId},</if>
<if test= "fentryId != null" > fentry_id = #{fentryId},</if>
<if test= "poNo != null" > po_no = #{poNo},</if>
<if test= "documentStatus != null" > document_status = #{documentStatus},</if>
<if test= "materialId != null" > material_id = #{materialId},</if>
<if test= "materialCode != null and materialCode != ''" > material_code = #{materialCode},</if>
<if test= "materialName != null" > material_name = #{materialName},</if>
<if test= "orderAmount != null" > order_amount = #{orderAmount},</if>
<if test= "completeAmount != null" > complete_amount = #{completeAmount},</if>
<if test= "approveDate != null" > approve_date = #{approveDate},</if>
<if test= "erpModifyDate != null" > erp_modify_date = #{erpModifyDate},</if>
<if test= "planDeliveryDate != null" > plan_delivery_date = #{planDeliveryDate},</if>
<if test= "beginDate != null" > begin_date = #{beginDate},</if>
<if test= "endDate != null" > end_date = #{endDate},</if>
<if test= "orderStatus != null" > order_status = #{orderStatus},</if>
<if test= "completeDate != null" > complete_date = #{completeDate},</if>
<if test= "isFlag != null and isFlag != ''" > is_flag = #{isFlag},</if>
<if test= "remark != null" > remark = #{remark},</if>
<if test= "createBy != null" > create_by = #{createBy},</if>
<if test= "createTime != null" > create_time = #{createTime},</if>
<if test= "updateBy != null" > update_by = #{updateBy},</if>
<if test= "updateTime != null" > update_time = #{updateTime},</if>
</trim>
where purchase_order_id = #{purchaseOrderId}
</update>
<delete id= "deleteMesPurchaseOrderByPurchaseOrderId" parameterType= "Long" >
delete from mes_purchase_order where purchase_order_id = #{purchaseOrderId}
</delete>
<delete id= "deleteMesPurchaseOrderByPurchaseOrderIds" parameterType= "String" >
delete from mes_purchase_order where purchase_order_id in
<foreach item= "purchaseOrderId" collection= "array" open= "(" separator= "," close= ")" >
#{purchaseOrderId}
</foreach>
</delete>
<insert id= "batchMesOrderBind" >
insert into mes_order_bind( order_bind_id, safe_flag, sale_order_id, sale_order_code, product_id, product_code, product_name, purchase_order_id, po_no, material_id, material_code, material_name, bind_amount, remark, create_by, create_time, update_by, update_time) values
<foreach item= "item" index= "index" collection= "list" separator= "," >
( #{item.orderBindId}, #{item.safeFlag}, #{item.saleOrderId}, #{item.saleOrderCode}, #{item.productId}, #{item.productCode}, #{item.productName}, #{item.purchaseOrderId}, #{item.poNo}, #{item.materialId}, #{item.materialCode}, #{item.materialName}, #{item.bindAmount}, #{item.remark}, #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime})
</foreach>
</insert>
<delete id= "deleteMesOrderBindByPurchaseOrderId" parameterType= "Long" >
delete from mes_order_bind where purchase_order_id = #{purchaseOrderId}
</delete>
<delete id= "deleteMesOrderBindByOrderBindIds" parameterType= "String" >
delete from mes_order_bind where order_bind_id in
<foreach item= "orderBindId" collection= "array" open= "(" separator= "," close= ")" >
#{orderBindId}
</foreach>
</delete>
<select id= "unbindPurchaseOrderList" parameterType= "MesPurchaseOrder" resultMap= "MesPurchaseOrderResult" >
select mpo.purchase_order_id,
mpo.erp_id,
mpo.fentry_id,
mpo.po_no,
mpo.document_status,
mpo.material_id as erp_material_id,
mbmi.material_id,
mbmi.material_code,
mbmi.material_name,
mbmi.material_spec,
mbmi.always_flag,
mpo.aux_prop_id,
mpo.specification_parameter,
mpo.order_amount,
(select ifnull(sum(mob.bind_amount), 0) from mes_order_bind mob
where mob.purchase_order_id = mpo.purchase_order_id and mob.safe_flag = '0') bound_amount, <!-- 此采购订单一共绑定的数量 -->
(select concat(ifnull(sum(bind_amount),0),'-',ifnull(sum(barcode_amount),0)) from mes_order_bind mob
where mob.purchase_order_id = mpo.purchase_order_id and sale_order_id = #{saleOrderId} and mob.safe_flag = '0') order_bind_barcode_amount,<!-- 此采购订单绑定当前销售订单的数量和生成条码的数量 -->
(select ifnull(sum(bind_amount), 0)
from mes_order_bind mob
where mob.purchase_order_id = mpo.purchase_order_id
and mob.safe_flag = '1') safe_amount <!-- 此采购订单一共的安全库存数量 -->
from mes_purchase_order mpo
left join mes_base_material_info mbmi on mbmi.erp_id = mpo.material_id
<where >
<if test= "poNo != null and poNo != ''" > and mpo.po_no like concat('%', #{poNo}, '%')</if>
<if test= "materialCode != null and materialCode != ''" > and mbmi.material_code like concat('%', #{materialCode}, '%')</if>
<if test= "materialName != null and materialName != ''" > and mbmi.material_name like concat('%', #{materialName}, '%')</if>
<if test= "specificationParameter != null and specificationParameter != ''" > and mpo.specification_parameter like concat('%', #{specificationParameter}, '%')</if>
<if test= "materialSpec != null and materialSpec != ''" > and mbmi.material_spec like concat('%', #{materialSpec}, '%')</if>
<if test= "alwaysFlag != null and alwaysFlag != ''" > and mbmi.always_flag = #{alwaysFlag}</if>
</where>
order by mpo.erp_modify_date desc,mpo.po_no ,mpo.material_name
</select>
<select id= "unbindPurchaseOrderListByPurchaseAndSaleOrderId" parameterType= "MesPurchaseOrder" resultMap= "MesPurchaseOrderResult" >
select mpo.purchase_order_id,
mpo.erp_id,
mpo.fentry_id,
mpo.po_no,
mpo.document_status,
mpo.material_id,
mpo.order_status,
mbmi.material_code,
mbmi.material_name,
mbmi.material_spec,
mbmi.always_flag,
mpo.aux_prop_id,
mpo.specification_parameter,
mpo.order_amount,
(select ifnull(sum(mob.bind_amount), 0) from mes_order_bind mob
where mob.purchase_order_id = mpo.purchase_order_id and mob.safe_flag = '0') bound_amount, <!-- 此采购订单一共绑定的数量 -->
(select concat(ifnull(sum(bind_amount),0),'-',ifnull(sum(barcode_amount),0)) from mes_order_bind mob
where mob.purchase_order_id = mpo.purchase_order_id and sale_order_id = #{saleOrderId} and mob.safe_flag = '0') order_bind_barcode_amount,<!-- 此采购订单绑定当前销售订单的数量和生成条码的数量 -->
(select ifnull(sum(bind_amount), 0)
from mes_order_bind mob
where mob.purchase_order_id = mpo.purchase_order_id
and mob.safe_flag = '1') safe_amount <!-- 此采购订单一共的安全库存数量 -->
from mes_purchase_order mpo
left join mes_base_material_info mbmi on mbmi.erp_id = mpo.material_id
where mpo.purchase_order_id = #{purchaseOrderId}
</select>
<select id= "saleBindPurchaseOrderList" parameterType= "MesPurchaseOrder" resultMap= "MesPurchaseOrderResult" >
select mpo.purchase_order_id,
mpo.erp_id,
mpo.fentry_id,
mpo.po_no,
mpo.document_status,
mpo.material_id,
mbmi.material_code,
mbmi.material_name,
mbmi.material_spec,
mpo.specification_parameter,
mpo.order_amount,
mob.order_bind_id
from mes_order_bind mob
left join mes_purchase_order mpo on mpo.purchase_order_id = mob.purchase_order_id
left join mes_base_material_info mbmi on mbmi.material_id = mob.material_id
<where >
<if test= "saleOrderId != null " > and mob.sale_order_id = #{saleOrderId}</if>
<if test= "poNo != null and poNo != ''" > and mpo.po_no = #{poNo}</if>
<if test= "materialCode != null and materialCode != ''" > and mbmi.material_code = #{materialCode}</if>
<if test= "materialName != null and materialName != ''" > and mbmi.material_name like concat('%', #{materialName}, '%')</if>
</where>
</select>
<select id= "selectPurchaseOrderBindList" parameterType= "MesPurchaseOrder" resultMap= "MesPurchaseOrderResult" >
select mpo.purchase_order_id,
mpo.erp_id,
mpo.fentry_id,
mpo.po_no,
mpo.document_status,
mpo.material_id,
mbmi.material_code,
mbmi.material_name,
mbmi.material_spec,
mbmi.batch_flag,
mbmi.batch_amount,
mbmi.material_id as mes_material_id,
mpo.aux_prop_id,
mpo.specification_parameter,
mpo.order_amount,
(select concat(ifnull(sum(bind_amount),0),'-',ifnull(sum(barcode_amount),0))
from mes_order_bind mob where mob.purchase_order_id=mpo.purchase_order_id and mob.safe_flag='0') order_bind_barcode_amount,
(select concat(ifnull(sum(bind_amount),0),'-',ifnull(sum(barcode_amount),0))
from mes_order_bind mob where mob.purchase_order_id=mpo.purchase_order_id and mob.safe_flag='1') safe_bind_barcode_amount
from mes_purchase_order mpo
left join mes_base_material_info mbmi on mbmi.erp_id = mpo.material_id
<where >
<if test= "poNo != null and poNo != ''" > and mpo.po_no like concat('%', #{poNo}, '%')</if>
<if test= "materialCode != null and materialCode != ''" > and mbmi.material_code like concat('%', #{materialCode}, '%')</if>
<if test= "materialName != null and materialName != ''" > and mbmi.material_name like concat('%', #{materialName}, '%')</if>
<if test= "specificationParameter != null and specificationParameter != ''" > and mpo.specification_parameter like concat('%', #{specificationParameter}, '%')</if>
<if test= "materialSpec != null and materialSpec != ''" > and mbmi.material_spec like concat('%', #{materialSpec}, '%')</if>
<if test= "purchaseOrderId != null " > and mpo.purchase_order_id = #{purchaseOrderId}</if>
</where>
order by mpo.erp_modify_date desc,mpo.po_no ,mpo.material_name
</select>
<select id= "selectMesPurchaseOrderJoinList" parameterType= "MesPurchaseOrder" resultMap= "MesPurchaseOrderResult" >
select mpo.purchase_order_id, mpo.erp_id, mpo.fentry_id, mpo.po_no, mpo.document_status, mpo.material_id,
mpo.order_amount, mpo.complete_amount, mpo.approve_date,
mpo.erp_modify_date, mpo.plan_delivery_date, mpo.begin_date, mpo.end_date, mpo.order_status,
mpo.complete_date, mpo.specification_parameter, mpo.src_bill_no, mpo.purchase_org_id, mpo.tond_base,
mbmi.material_code,mbmi.material_name,mbmi.material_spec,mbmi.always_flag
from mes_purchase_order mpo left join mes_base_material_info mbmi on mpo.material_id =mbmi.erp_id
<where >
<if test= "poNo != null and poNo != ''" > and mpo.po_no like concat('%', #{poNo}, '%')</if>
<if test= "materialCode != null and materialCode != ''" > and mbmi.material_code like concat('%', #{materialCode}, '%')</if>
<if test= "materialName != null and materialName != ''" > and mbmi.material_name like concat('%', #{materialName}, '%')</if>
<if test= "materialSpec != null and materialSpec != '' " > and replace(mbmi.material_spec,' ','') like concat('%', #{materialSpec},
'%')</if>
<if test= "specificationParameter != null and specificationParameter != '' " > and replace(mpo.specification_parameter,' ','') like concat('%', #{specificationParameter},
'%')</if>
<if test= "orderStatus != null and orderStatus != ''" > and mpo.order_status = #{orderStatus}</if>
<if test= "alwaysFlag != null and alwaysFlag != ''" > and mbmi.always_flag = #{alwaysFlag}</if>
<if test= "orderAmount != null " > and mpo.order_amount = #{orderAmount}</if>
<if test= "completeAmount != null " > and mpo.complete_amount = #{completeAmount}</if>
<if test= "approveDate != null " > and mpo.approve_date = #{approveDate}</if>
<if test= "erpModifyDate != null " > and mpo.erp_modify_date = #{erpModifyDate}</if>
<if test= "planDeliveryDate != null " > and mpo.plan_delivery_date = #{planDeliveryDate}</if>
<if test= "beginDate != null " > and mpo.begin_date = #{beginDate}</if>
<if test= "endDate != null " > and mpo.end_date = #{endDate}</if>
<if test= "completeDate != null " > and mpo.complete_date = #{completeDate}</if>
<if test= "isFlag != null and isFlag != ''" > and mpo.is_flag = #{isFlag}</if>
<if test= "srcBillNo != null and srcBillNo != ''" > and mpo.src_bill_no like concat('%', #{srcBillNo}, '%')</if>
<if test= "tondBase != null and tondBase != ''" > and mpo.tond_base like concat('%', #{tondBase}, '%')</if>
</where>
order by mpo.erp_modify_date desc
</select>
<select id= "selectPurchaseOrderJoinList" parameterType= "MesPurchaseOrder" resultMap= "MesPurchaseOrderResult" >
select mpo.purchase_order_id,mpo.po_no,mpo.order_amount,
mob.order_bind_id, mob.safe_flag, mob.sale_order_id, mob.sale_order_code,
mob.bind_amount, mob.barcode_amount,mpo.specification_parameter,
mob.product_id,pbmi.material_code as product_code,pbmi.material_name as product_name,pbmi.material_spec as product_spec,
mob.material_id,
mbmi.always_flag,mbmi.material_code,mbmi.material_name,mbmi.material_spec,mbmi.batch_flag,mbmi.batch_amount,
mso.order_amount as sale_order_amount
from mes_purchase_order mpo left join mes_order_bind mob on mpo.purchase_order_id = mob.purchase_order_id
left join mes_base_material_info pbmi on mob.product_id=pbmi.material_id
left join mes_base_material_info mbmi on mob.material_id=mbmi.material_id
left join mes_sale_order mso on mob.sale_order_id = mso.sale_order_id
<where >
<if test= "mergeFlag != null and mergeFlag != ''" > and mob.bind_amount=1 and mob.barcode_amount=0 and mpo.order_amount=1 and mso.order_amount=1</if>
<if test= "singleFlag != null and singleFlag != ''" > and (mob.bind_amount > mob.barcode_amount or mbmi.always_flag='1')</if>
<if test= "safeFlag != null and safeFlag != ''" > and mob.safe_flag = #{safeFlag}</if>
<if test= "alwaysFlag != null and alwaysFlag != ''" > and mbmi.always_flag = #{alwaysFlag}</if>
<if test= "saleOrderCode != null and saleOrderCode != ''" > and mob.sale_order_code like concat('%', #{saleOrderCode}, '%')</if>
<if test= "productCode != null and productCode != ''" > and pbmi.material_code like concat('%', #{productCode}, '%')</if>
<if test= "productName != null and productName != ''" > and pbmi.material_name like concat('%', #{productName}, '%')</if>
<if test= "poNo != null and poNo != ''" > and mpo.po_no like concat('%', #{poNo}, '%')</if>
<if test= "materialCode != null and materialCode != ''" > and mbmi.material_code like concat('%', #{materialCode}, '%')</if>
<if test= "materialName != null and materialName != ''" > and mbmi.material_name like concat('%', #{materialName}, '%')</if>
<if test= "materialSpec != null and materialSpec != ''" > and replace(mbmi.material_spec,' ','') like concat('%', #{materialSpec},
'%')</if>
<if test= "productSpec != null and productSpec != ''" > and replace(pbmi.material_spec,' ','') like concat('%', #{productSpec},
'%')</if>
</where>
order by mpo.po_no
</select>
<select id= "selectNotRawInstockPurchaseOrderList" parameterType= "String" resultMap= "MesPurchaseOrderResult" >
select mpo.purchase_order_id,mpo.po_no,mpo.material_id from mes_purchase_order mpo where exists (select 1 from wms_raw_instock wri where
date_format(wri.apply_date, '%y%m%d') = date_format(#{applyDateStr},'%y%m%d') and
mpo.material_id = (select mbmi.erp_id from mes_base_material_info mbmi where mbmi.material_id=wri.material_id) and mpo.po_no!=wri.po_no)
and mpo.order_status ='3' group by mpo.purchase_order_id,mpo.po_no,mpo.material_id
</select>
<select id= "selectPurchaseOrderJoinSupplierProjectByOrderId" parameterType= "Long" resultMap= "MesPurchaseOrderResult" >
select a.purchase_order_id, a.po_no, a.document_status, a.tond_base, a.supplier_id,b.supplier_code,mpi.project_no
from mes_purchase_order a
left join mes_base_supplier_info b on a.supplier_id=b.erp_id
left join mes_project_info mpi on a.tond_base = mpi.erp_id
where a.purchase_order_id = #{purchaseOrderId}
</select>
</mapper>