LEFT JOIN dc_base_transfer_complete tb2 ON tb1.deleted = tb2.deleted
AND tb1.bailun_sku = tb2.bailun_sku
AND tb1.warehouse_code = tb2.warehouse_code
AND tb1.transfer_order_id = tb2.transfer_order_id
WHERE
tb2.bailun_sku IS NULL
AND tb1.deleted = 0
GROUP BY
bailun_sku,
warehouse_code
) tb5
LEFT JOIN (
SELECT
bailun_sku,
warehouse_code,
sum( count ) count
FROM
(
SELECT
tb1.bailun_sku,
tb1.warehouse_code,
max( tb1.count ) count,
tb1.transfer_order_id
FROM
dc_base_transfer_inbound tb1
LEFT JOIN dc_base_transfer_complete tb2 ON tb2.deleted = 0
AND tb1.bailun_sku = tb2.bailun_sku
AND tb1.warehouse_code = tb2.warehouse_code
AND tb1.transfer_order_id = tb2.transfer_order_id
WHERE
tb2.bailun_sku IS NULL
AND tb1.deleted = 0
GROUP BY
bailun_sku,
warehouse_code,
transfer_order_id
) tb3
GROUP BY
bailun_sku,
warehouse_code
) tb4
ON tb5.bailun_sku = tb4.bailun_sku
AND tb5.warehouse_code = tb4.warehouse_code
WHERE ( tb5.count - IFNULL( tb4.count, 0 ) ) > 0
ON DUPLICATE KEY UPDATE quantity_transfer = VALUES(quantity_transfer),gmt_transfer_modified = VALUES(gmt_transfer_modified)
</insert>
</insert>
<insertid="calculatePurchaseTransit">
<insertid="calculatePurchaseTransit">
insert into dc_mid_transit(bailun_sku, warehouse_code, quantity_purchase,gmt_purchase_modified)
insert into dc_mid_transit(bailun_sku, warehouse_code, quantity_purchase,gmt_purchase_modified)
SELECT tb1.bailun_sku as bailun_sku,tb1.warehouse_code as warehouse_code,sum((tb1.count - IFNULL(tb2.count,0))) as count,CURRENT_TIMESTAMP FROM
SELECT tb1.bailun_sku as bailun_sku,tb1.warehouse_code as warehouse_code,sum((tb1.count - IFNULL(tb2.count,0))) as count,CURRENT_TIMESTAMP FROM
(SELECT bailun_sku, warehouse_code, parent_id, sum(count) as count FROM dc_base_purchase WHERE buy_status IN ( 0, 1, 2, 3 ) and has_delete=0 GROUP BY bailun_sku,parent_id) tb1
(SELECT bailun_sku, warehouse_code, parent_id, sum(count) as count FROM dc_base_purchase WHERE buy_status IN ( 0, 1, 2, 3 ) and has_delete=0 GROUP BY bailun_sku,parent_id) tb1
...
@@ -558,7 +561,7 @@
...
@@ -558,7 +561,7 @@
ON DUPLICATE KEY UPDATE quantity_purchase = VALUES(quantity_purchase), gmt_purchase_modified = VALUES(gmt_purchase_modified)
ON DUPLICATE KEY UPDATE quantity_purchase = VALUES(quantity_purchase), gmt_purchase_modified = VALUES(gmt_purchase_modified)
</insert>
</insert>
<insertid="insertMidDailyTransit">
<insertid="insertMidDailyTransit">
INSERT into dc_daily_transit (
INSERT into dc_daily_transit (
`bailun_sku` ,
`bailun_sku` ,
`warehouse_code`,
`warehouse_code`,
...
@@ -572,7 +575,7 @@
...
@@ -572,7 +575,7 @@
FROM dc_mid_transit
FROM dc_mid_transit
</insert>
</insert>
<insertid="calculateOutStock">
<insertid="calculateOutStock">
insert into dc_mid_transit(bailun_sku, warehouse_code, quantity_out_stock,gmt_out_stock_modified)
insert into dc_mid_transit(bailun_sku, warehouse_code, quantity_out_stock,gmt_out_stock_modified)
SELECT
SELECT
t1.bailun_sku,
t1.bailun_sku,
...
@@ -601,32 +604,32 @@
...
@@ -601,32 +604,32 @@
WHERE (t1.bailun_sku_quantity_ordered - t1.bailun_sku_quantity_picked - t2.usable_stock - t2.occupy_stock) >= 0
WHERE (t1.bailun_sku_quantity_ordered - t1.bailun_sku_quantity_picked - t2.usable_stock - t2.occupy_stock) >= 0
ON DUPLICATE KEY UPDATE quantity_out_stock = VALUES(quantity_out_stock),gmt_out_stock_modified = VALUES(gmt_out_stock_modified)
ON DUPLICATE KEY UPDATE quantity_out_stock = VALUES(quantity_out_stock),gmt_out_stock_modified = VALUES(gmt_out_stock_modified)
</insert>
</insert>
<updateid="updateOldOutStockToZero">
<updateid="updateOldOutStockToZero">
update dc_mid_transit set quantity_out_stock =0 where gmt_out_stock_modified < #{outStockModified,jdbcType=TIMESTAMP}
update dc_mid_transit set quantity_out_stock =0 where gmt_out_stock_modified < #{outStockModified,jdbcType=TIMESTAMP}
</update>
</update>
<updateid="updateOldTransferToZero">
<updateid="updateOldTransferToZero">
update dc_mid_transit set quantity_transfer =0 where gmt_transfer_modified < #{transferModified,jdbcType=TIMESTAMP}
update dc_mid_transit set quantity_transfer =0 where gmt_transfer_modified < #{transferModified,jdbcType=TIMESTAMP}
</update>
</update>
<updateid="updateOldPurchaseToZero">
<updateid="updateOldPurchaseToZero">
update dc_mid_transit set quantity_purchase =0 where gmt_purchase_modified < #{purchaseModified,jdbcType=TIMESTAMP}
update dc_mid_transit set quantity_purchase =0 where gmt_purchase_modified < #{purchaseModified,jdbcType=TIMESTAMP}
</update>
</update>
<updateid="updateOldUnshippedToZero">
<updateid="updateOldUnshippedToZero">
update dc_mid_transit set quantity_unshipped =0 where gmt_unshipped_modified < #{unshippedModified,jdbcType=TIMESTAMP}
update dc_mid_transit set quantity_unshipped =0 where gmt_unshipped_modified < #{unshippedModified,jdbcType=TIMESTAMP}
union select bailun_sku,warehouse_code,transfer_plan_order_id,null,update_time,count from dc_base_transfer_plan where status = 1 and deleted=0 AND bailun_sku = #{bailunSku}