Commit 9523a187 by huluobin

调拨在途

parent bfa9e6b7
......@@ -7,6 +7,7 @@ import java.time.LocalDateTime;
@Data
public class TransferTransitQuantity {
/*bailunSku*/
private String bailunSku;
private String warehouseCode;
private String sourceWarehouseCode;
......
......@@ -10,7 +10,6 @@ import org.apache.ibatis.annotations.Select;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
public interface DcMidTransitMapper {
/**
......@@ -135,6 +134,7 @@ public interface DcMidTransitMapper {
void insertMidDailyTransit();
List<OutStockQuantity> selectQuantityOutStock();
List<PurchaseTransitQuantity> selectQuantityPurchaseTransit();
List<TransferTransitQuantity> selectQuantityTransferTransit();
......@@ -145,12 +145,17 @@ public interface DcMidTransitMapper {
String printTransactionLevel();
void updateOldTransferToZero(@Param("transferModified") String transferModified);
void updateOldPurchaseToZero(@Param("purchaseModified") String purchaseModified);
void updateOldOutStockToZero(@Param("outStockModified") String outStockModified);
LocalDateTime selectMaxOutStockModified();
LocalDateTime selectMaxTransferModified();
LocalDateTime selectMaxPurchaseModified();
LocalDateTime selectMaxUnshippedModified();
void updateOldUnshippedToZero(@Param("unshippedModified") LocalDateTime unshippedModified);
......
......@@ -6,19 +6,19 @@
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
<id column="id" jdbcType="INTEGER" property="id" />
<result column="bailun_sku" jdbcType="VARCHAR" property="bailunSku" />
<result column="warehouse_code" jdbcType="VARCHAR" property="warehouseCode" />
<result column="quantity_purchase" jdbcType="INTEGER" property="quantityPurchase" />
<result column="gmt_purchase_modified" jdbcType="TIMESTAMP" property="gmtPurchaseModified" />
<result column="quantity_transfer" jdbcType="INTEGER" property="quantityTransfer" />
<result column="gmt_transfer_modified" jdbcType="TIMESTAMP" property="gmtTransferModified" />
<result column="quantity_out_stock" jdbcType="INTEGER" property="quantityOutStock" />
<result column="gmt_out_stock_modified" jdbcType="TIMESTAMP" property="gmtOutStockModified" />
<result column="quantity_unshipped" jdbcType="INTEGER" property="quantityUnshipped" />
<result column="gmt_unshipped_modified" jdbcType="TIMESTAMP" property="gmtUnshippedModified" />
<result column="company_id" jdbcType="INTEGER" property="companyId" />
<result column="amount_purchase_transit" jdbcType="DECIMAL" property="amountPurchaseTransit" />
<id column="id" jdbcType="INTEGER" property="id"/>
<result column="bailun_sku" jdbcType="VARCHAR" property="bailunSku"/>
<result column="warehouse_code" jdbcType="VARCHAR" property="warehouseCode"/>
<result column="quantity_purchase" jdbcType="INTEGER" property="quantityPurchase"/>
<result column="gmt_purchase_modified" jdbcType="TIMESTAMP" property="gmtPurchaseModified"/>
<result column="quantity_transfer" jdbcType="INTEGER" property="quantityTransfer"/>
<result column="gmt_transfer_modified" jdbcType="TIMESTAMP" property="gmtTransferModified"/>
<result column="quantity_out_stock" jdbcType="INTEGER" property="quantityOutStock"/>
<result column="gmt_out_stock_modified" jdbcType="TIMESTAMP" property="gmtOutStockModified"/>
<result column="quantity_unshipped" jdbcType="INTEGER" property="quantityUnshipped"/>
<result column="gmt_unshipped_modified" jdbcType="TIMESTAMP" property="gmtUnshippedModified"/>
<result column="company_id" jdbcType="INTEGER" property="companyId"/>
<result column="amount_purchase_transit" jdbcType="DECIMAL" property="amountPurchaseTransit"/>
</resultMap>
<sql id="Example_Where_Clause">
<!--
......@@ -42,7 +42,8 @@
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
<foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem}
</foreach>
</when>
......@@ -75,7 +76,8 @@
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
<foreach close=")" collection="criterion.value" item="listItem" open="("
separator=",">
#{listItem}
</foreach>
</when>
......@@ -95,7 +97,8 @@
gmt_transfer_modified, quantity_out_stock, gmt_out_stock_modified, quantity_unshipped,
gmt_unshipped_modified, company_id, amount_purchase_transit
</sql>
<select id="selectByExample" parameterType="com.bailuntec.domain.example.DcMidTransitExample" resultMap="BaseResultMap">
<select id="selectByExample" parameterType="com.bailuntec.domain.example.DcMidTransitExample"
resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
......@@ -104,10 +107,10 @@
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from dc_mid_transit
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
......@@ -127,7 +130,7 @@
This element is automatically generated by MyBatis Generator, do not modify.
-->
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from dc_mid_transit
where id = #{id,jdbcType=INTEGER}
</select>
......@@ -146,7 +149,7 @@
-->
delete from dc_mid_transit
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
</delete>
<insert id="insert" parameterType="com.bailuntec.domain.entity.DcMidTransit">
......@@ -256,14 +259,15 @@
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.bailuntec.domain.example.DcMidTransitExample" resultType="java.lang.Long">
<select id="countByExample" parameterType="com.bailuntec.domain.example.DcMidTransitExample"
resultType="java.lang.Long">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
select count(*) from dc_mid_transit
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
......@@ -314,7 +318,7 @@
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByExample" parameterType="map">
......@@ -337,7 +341,7 @@
company_id = #{record.companyId,jdbcType=INTEGER},
amount_purchase_transit = #{record.amountPurchaseTransit,jdbcType=DECIMAL}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
<include refid="Update_By_Example_Where_Clause"/>
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.bailuntec.domain.entity.DcMidTransit">
......@@ -571,17 +575,18 @@
company_id = #{companyId,jdbcType=INTEGER},
amount_purchase_transit = #{amountPurchaseTransit,jdbcType=DECIMAL}
</insert>
<select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcMidTransitExample" resultMap="BaseResultMap">
<select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcMidTransitExample"
resultMap="BaseResultMap">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
@project https://github.com/itfsw/mybatis-generator-plugin
-->
select
<include refid="Base_Column_List" />
<include refid="Base_Column_List"/>
from dc_mid_transit
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
<include refid="Example_Where_Clause"/>
</if>
<if test="orderByClause != null">
order by ${orderByClause}
......@@ -589,85 +594,121 @@
limit 1
</select>
<!-- <select id="selectQuantityTransferTransit" resultType="com.bailuntec.domain.dto.TransferTransitQuantity">-->
<!-- SELECT bailun_sku as bailunSku,-->
<!-- warehouse_code as warehouseCode,-->
<!-- sum(count) as count,-->
<!-- sum(countplan) as countplan,-->
<!-- sum(IF(transport_type = '国内陆运', count, 0)) as landCount,-->
<!-- sum(IF(transport_type = '海运', count, 0)) as oceanCount,-->
<!-- sum(IF(transport_type = '空运', count, 0)) as airCount,-->
<!-- sum(IF(transport_type = '铁路运输', count, 0)) as railwayCount-->
<!-- FROM (-->
<!-- SELECT tb5.bailun_sku bailun_sku,-->
<!-- tb5.warehouse_code warehouse_code,-->
<!-- (-->
<!-- tb5.count - IFNULL(tb4.count, 0)) AS count,-->
<!-- 0 as countplan,-->
<!-- tb5.transport_type transport_type-->
<!-- FROM (-->
<!-- SELECT tb1.bailun_sku,-->
<!-- tb1.warehouse_code,-->
<!-- sum(tb1.count) count,-->
<!-- tb1.transport_type-->
<!-- FROM dc_base_transfer_bale tb1-->
<!-- LEFT JOIN dc_base_transfer_complete tb2 ON tb1.transfer_order_id = tb2.transfer_order_id-->
<!-- WHERE tb2.transfer_order_id 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 t1.bailun_sku,-->
<!-- t1.warehouse_code,-->
<!-- (case WHEN t2.count > tbb.count then tbb.count else t2.count end) as count,-->
<!-- t1.transfer_order_id-->
<!-- FROM (SELECT max(create_time) AS create_time, bailun_sku, warehouse_code, transfer_order_id-->
<!-- FROM dc_base_transfer_inbound-->
<!-- WHERE deleted = 0-->
<!-- GROUP BY bailun_sku, warehouse_code, transfer_order_id) t1-->
<!-- INNER JOIN dc_base_transfer_inbound t2 ON t1.bailun_sku = t2.bailun_sku-->
<!-- AND t1.warehouse_code = t2.warehouse_code-->
<!-- AND t1.transfer_order_id = t2.transfer_order_id-->
<!-- AND t1.create_time = t2.create_time-->
<!-- LEFT JOIN dc_base_transfer_bale tbb-->
<!-- on t1.bailun_sku = tbb.bailun_sku and t1.warehouse_code = tbb.warehouse_code and-->
<!-- t1.transfer_order_id = tbb.transfer_order_id-->
<!-- LEFT JOIN dc_base_transfer_complete tb2 ON t1.transfer_order_id = tb2.transfer_order_id-->
<!-- WHERE tb2.bailun_sku IS NULL-->
<!-- ) 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-->
<!-- UNION ALL-->
<!-- SELECT bailun_sku,-->
<!-- warehouse_code,-->
<!-- sum(count) AS count,-->
<!-- sum(count) AS countplan,-->
<!-- transport_type-->
<!-- FROM dc_base_transfer_plan-->
<!-- WHERE STATUS = 1-->
<!-- AND deleted = 0-->
<!-- GROUP BY bailun_sku,-->
<!-- warehouse_code-->
<!-- ) t-->
<!-- GROUP BY bailun_sku,-->
<!-- warehouse_code-->
<!-- </select>-->
<select id="selectQuantityTransferTransit" resultType="com.bailuntec.domain.dto.TransferTransitQuantity">
SELECT bailun_sku as bailunSku,
warehouse_code as warehouseCode,
sum(count) as count,
sum(count) as `count`,
sum(countplan) as countplan,
sum(IF(transport_type = '国内陆运', count, 0)) as landCount,
sum(IF(transport_type = '海运', count, 0)) as oceanCount,
sum(IF(transport_type = '空运', count, 0)) as airCount,
sum(IF(transport_type = '铁路运输', count, 0)) as railwayCount
FROM (
SELECT tb5.bailun_sku bailun_sku,
tb5.warehouse_code warehouse_code,
(
tb5.count - IFNULL(tb4.count, 0)) AS count,
0 as countplan,
tb5.transport_type transport_type
FROM (
SELECT tb1.bailun_sku,
tb1.warehouse_code,
sum(tb1.count) count,
tb1.transport_type
FROM dc_base_transfer_bale tb1
LEFT JOIN dc_base_transfer_complete tb2 ON tb1.transfer_order_id = tb2.transfer_order_id
WHERE tb2.transfer_order_id 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 t1.bailun_sku,
t1.warehouse_code,
(case WHEN t2.count > tbb.count then tbb.count else t2.count end) as count,
t1.transfer_order_id
FROM (SELECT max(create_time) AS create_time, bailun_sku, warehouse_code, transfer_order_id
FROM dc_base_transfer_inbound
WHERE deleted = 0
GROUP BY bailun_sku, warehouse_code, transfer_order_id) t1
INNER JOIN dc_base_transfer_inbound t2 ON t1.bailun_sku = t2.bailun_sku
AND t1.warehouse_code = t2.warehouse_code
AND t1.transfer_order_id = t2.transfer_order_id
AND t1.create_time = t2.create_time
LEFT JOIN dc_base_transfer_bale tbb
on t1.bailun_sku = tbb.bailun_sku and t1.warehouse_code = tbb.warehouse_code and
t1.transfer_order_id = tbb.transfer_order_id
LEFT JOIN dc_base_transfer_complete tb2 ON t1.transfer_order_id = tb2.transfer_order_id
WHERE tb2.bailun_sku IS NULL
) 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
SELECT t1.targetwareno as warehouse_code,
t2.sku as bailun_sku,
t1.transporttype as transport_type,
t2.deliverycount - t2.storagecount as `count`,
0 as countplan
FROM dc_base_transfer_info t1
LEFT JOIN dc_base_transfer_info_skus t2 on t1.dataid = t2.dataid
where t1.stateid &lt; 5
and t1.isdeleted = 0
UNION ALL
SELECT bailun_sku,
warehouse_code,
sum(count) AS count,
sum(count) AS countplan,
`count`,
`count` AS countplan,
transport_type
FROM dc_base_transfer_plan
WHERE STATUS = 1
AND deleted = 0
GROUP BY bailun_sku,
warehouse_code
) t
GROUP BY bailun_sku,
warehouse_code
GROUP BY bailun_sku, warehouse_code
</select>
<insert id="calculateTransferTransit">
insert into dc_mid_transit(bailun_sku, warehouse_code, quantity_transfer,quantity_transfer_plan,quantity_land_transfer,quantity_ocean_transfer,quantity_air_transfer,quantity_railway_transfer, gmt_transfer_modified)
insert into dc_mid_transit(bailun_sku, warehouse_code,
quantity_transfer,quantity_transfer_plan,quantity_land_transfer,quantity_ocean_transfer,quantity_air_transfer,quantity_railway_transfer,
gmt_transfer_modified)
values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.bailunSku,jdbcType=VARCHAR}, #{item.warehouseCode,jdbcType=VARCHAR}, #{item.count,jdbcType=INTEGER},#{item.countplan,jdbcType=INTEGER},#{item.landCount,jdbcType=INTEGER},#{item.oceanCount,jdbcType=INTEGER},#{item.airCount,jdbcType=INTEGER},#{item.railwayCount,jdbcType=INTEGER}, #{localDateTime,jdbcType=TIMESTAMP}
#{item.bailunSku,jdbcType=VARCHAR}, #{item.warehouseCode,jdbcType=VARCHAR},
#{item.count,jdbcType=INTEGER},#{item.countplan,jdbcType=INTEGER},#{item.landCount,jdbcType=INTEGER},#{item.oceanCount,jdbcType=INTEGER},#{item.airCount,jdbcType=INTEGER},#{item.railwayCount,jdbcType=INTEGER},
#{localDateTime,jdbcType=TIMESTAMP}
)
</foreach>
ON DUPLICATE KEY UPDATE quantity_transfer = values(quantity_transfer),
......@@ -680,62 +721,81 @@
</insert>
<insert id="calculatePurchaseTransit">
insert into dc_mid_transit(bailun_sku, warehouse_code, quantity_purchase,amount_purchase_transit,quantity_land_purchase,quantity_ocean_purchase,quantity_air_purchase,quantity_railway_purchase,gmt_purchase_modified)
insert into dc_mid_transit(bailun_sku, warehouse_code,
quantity_purchase,amount_purchase_transit,quantity_land_purchase,quantity_ocean_purchase,quantity_air_purchase,quantity_railway_purchase,gmt_purchase_modified)
values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.bailunSku,jdbcType=VARCHAR}, #{item.warehouseCode,jdbcType=VARCHAR}, #{item.count,jdbcType=INTEGER}, #{item.amountPurchaseTransit,jdbcType=DECIMAL},#{item.landCount,jdbcType=INTEGER},#{item.oceanCount,jdbcType=INTEGER},#{item.airCount,jdbcType=INTEGER},#{item.railwayCount,jdbcType=INTEGER}, #{localDateTime,jdbcType=TIMESTAMP}
#{item.bailunSku,jdbcType=VARCHAR}, #{item.warehouseCode,jdbcType=VARCHAR}, #{item.count,jdbcType=INTEGER},
#{item.amountPurchaseTransit,jdbcType=DECIMAL},#{item.landCount,jdbcType=INTEGER},#{item.oceanCount,jdbcType=INTEGER},#{item.airCount,jdbcType=INTEGER},#{item.railwayCount,jdbcType=INTEGER},
#{localDateTime,jdbcType=TIMESTAMP}
)
</foreach>
ON DUPLICATE KEY UPDATE quantity_purchase = values(quantity_purchase), amount_purchase_transit = values(amount_purchase_transit),quantity_land_purchase = values(quantity_land_purchase),quantity_ocean_purchase = values(quantity_ocean_purchase),quantity_air_purchase = values(quantity_air_purchase),quantity_railway_purchase = values(quantity_railway_purchase), gmt_purchase_modified = values(gmt_purchase_modified)
ON DUPLICATE KEY UPDATE quantity_purchase = values(quantity_purchase), amount_purchase_transit =
values(amount_purchase_transit),quantity_land_purchase = values(quantity_land_purchase),quantity_ocean_purchase
= values(quantity_ocean_purchase),quantity_air_purchase =
values(quantity_air_purchase),quantity_railway_purchase = values(quantity_railway_purchase),
gmt_purchase_modified = values(gmt_purchase_modified)
</insert>
<insert id="calculateOutStock">
insert into dc_mid_transit(bailun_sku, warehouse_code, quantity_out_stock,gmt_out_stock_modified, quantity_out_stock_aliexpress)
insert into dc_mid_transit(bailun_sku, warehouse_code, quantity_out_stock,gmt_out_stock_modified,
quantity_out_stock_aliexpress)
values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.bailunSku,jdbcType=VARCHAR}, #{item.warehouseCode,jdbcType=VARCHAR}, #{item.quantityOutStock,jdbcType=INTEGER}, #{localDateTime,jdbcType=TIMESTAMP}, #{item.aliexpressQuantity, jdbcType=INTEGER}
#{item.bailunSku,jdbcType=VARCHAR}, #{item.warehouseCode,jdbcType=VARCHAR},
#{item.quantityOutStock,jdbcType=INTEGER}, #{localDateTime,jdbcType=TIMESTAMP},
#{item.aliexpressQuantity, jdbcType=INTEGER}
)
</foreach>
ON DUPLICATE KEY UPDATE quantity_out_stock = values(quantity_out_stock) ,gmt_out_stock_modified = values(gmt_out_stock_modified), quantity_out_stock_aliexpress = values(quantity_out_stock_aliexpress)
ON DUPLICATE KEY UPDATE quantity_out_stock = values(quantity_out_stock) ,gmt_out_stock_modified =
values(gmt_out_stock_modified), quantity_out_stock_aliexpress = values(quantity_out_stock_aliexpress)
</insert>
<insert id="insertMidDailyTransit">
INSERT into dc_daily_transit (
`bailun_sku` ,
INSERT into dc_daily_transit (`bailun_sku`,
`warehouse_code`,
`quantity_purchase` ,
`quantity_purchase`,
`quantity_transfer`,
`quantity_transfer_plan`,
`record_time`)
SELECT `bailun_sku` ,
SELECT `bailun_sku`,
`warehouse_code`,
`quantity_purchase` ,
`quantity_transfer`,`quantity_transfer_plan`, DATE_SUB( CURDATE( ), INTERVAL 1 DAY )
`quantity_purchase`,
`quantity_transfer`,
`quantity_transfer_plan`,
DATE_SUB(CURDATE(), INTERVAL 1 DAY)
FROM dc_mid_transit
</insert>
<update id="updateSkuUnitPrice">
update dc_daily_transit t1, dc_base_sku t2 set t1.unit_price = t2.unit_price WHERE t1.record_time = DATE_SUB( CURDATE( ), INTERVAL 1 DAY ) and t1.bailun_sku=t2.bailun_sku
update dc_daily_transit t1, dc_base_sku t2
set t1.unit_price = t2.unit_price
WHERE t1.record_time = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
and t1.bailun_sku = t2.bailun_sku
</update>
<select id="selectQuantityOutStock" resultType="com.bailuntec.domain.dto.OutStockQuantity">
SELECT
t1.bailun_sku as bailunSku,
SELECT t1.bailun_sku as bailunSku,
t1.warehouse_code as warehouseCode,
t1.bailun_sku_quantity_ordered - t1.bailun_sku_quantity_pushed - t2.usable_stock - t2.occupy_stock + ifnull(t3.safe_stock, 0) as quantityOutStock,
if((t1.aliexpress_quantity - t2.usable_stock - t2.occupy_stock + ifnull(t3.safe_stock, 0)) &lt; 0, 0, (t1.aliexpress_quantity - t2.usable_stock - t2.occupy_stock + ifnull(t3.safe_stock, 0))) as aliexpressQuantity
FROM
(
SELECT
bailun_sku,warehouse_code,SUM(bailun_sku_quantity_ordered) AS bailun_sku_quantity_ordered,SUM(bailun_sku_quantity_pushed) AS bailun_sku_quantity_pushed,
sum(case when platform_type = 'Aliexpress' then bailun_sku_quantity_ordered - bailun_sku_quantity_pushed else 0 end) as aliexpress_quantity
FROM
dc_base_oms_sku
WHERE
bailun_order_status = 'Handling'
and bailun_interception_status in('None','Failed')
t1.bailun_sku_quantity_ordered - t1.bailun_sku_quantity_pushed - t2.usable_stock - t2.occupy_stock +
ifnull(t3.safe_stock, 0) as quantityOutStock,
if((t1.aliexpress_quantity - t2.usable_stock - t2.occupy_stock + ifnull(t3.safe_stock, 0)) &lt; 0, 0,
(t1.aliexpress_quantity - t2.usable_stock - t2.occupy_stock +
ifnull(t3.safe_stock, 0))) as aliexpressQuantity
FROM (
SELECT bailun_sku,
warehouse_code,
SUM(bailun_sku_quantity_ordered) AS bailun_sku_quantity_ordered,
SUM(bailun_sku_quantity_pushed) AS bailun_sku_quantity_pushed,
sum(case
when platform_type = 'Aliexpress'
then bailun_sku_quantity_ordered - bailun_sku_quantity_pushed
else 0 end) as aliexpress_quantity
FROM dc_base_oms_sku
WHERE bailun_order_status = 'Handling'
and bailun_interception_status in ('None', 'Failed')
and warehouse_code != ''
and platform_type != 'FBA'
and company_id = 1
......@@ -747,125 +807,136 @@
and has_innersale = 0
and paid_time >= '2019-03-01 12:00:00'
and bailun_sku_quantity_ordered > bailun_sku_quantity_shipped
GROUP BY
bailun_sku,
GROUP BY bailun_sku,
warehouse_code
) t1 INNER JOIN dc_base_stock t2 ON t1.bailun_sku=t2.bailun_sku and t1.warehouse_code=t2.warehouse_code
LEFT JOIN dc_auto_jit_inventory t3 ON t1.bailun_sku=t3.bailun_sku and t1.warehouse_code=t3.warehouse_code and t3.status = 1
WHERE (t1.bailun_sku_quantity_ordered - t1.bailun_sku_quantity_pushed - t2.usable_stock - t2.occupy_stock + ifnull(t3.safe_stock, 0)) >= 0
) t1
INNER JOIN dc_base_stock t2 ON t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code
LEFT JOIN dc_auto_jit_inventory t3
ON t1.bailun_sku = t3.bailun_sku and t1.warehouse_code = t3.warehouse_code and t3.status = 1
WHERE (t1.bailun_sku_quantity_ordered - t1.bailun_sku_quantity_pushed - t2.usable_stock - t2.occupy_stock +
ifnull(t3.safe_stock, 0)) >= 0
</select>
<select id="selectQuantityPurchaseTransit" resultType="com.bailuntec.domain.dto.PurchaseTransitQuantity">
SELECT
bailun_sku as bailunSku,
SELECT bailun_sku as bailunSku,
warehouse_code as warehouseCode,
sum( count ) as count,
sum( count * price ) AS amountPurchaseTransit,
sum(count) as count,
sum(count * price) AS amountPurchaseTransit,
sum(case when transport_type = 1 then count else 0 end) as landCount,
sum(case when transport_type = 2 then count else 0 end) as oceanCount,
sum(case when transport_type = 3 then count else 0 end) as airCount,
sum(case when transport_type = 4 then count else 0 end) as railwayCount
FROM
(
SELECT
tb1.bailun_sku AS bailun_sku,
FROM (
SELECT tb1.bailun_sku AS bailun_sku,
tb1.warehouse_code AS warehouse_code,
tb1.purchase_id AS purchase_id,
sum( if((tb1.count - IFNULL( tb2.count, 0 )) &lt; 0, 0, (tb1.count - IFNULL( tb2.count, 0 ))) ) AS count,
sum(if((tb1.count - IFNULL(tb2.count, 0)) &lt; 0, 0,
(tb1.count - IFNULL(tb2.count, 0)))) AS count,
tb1.transport_type AS transport_type,
price
FROM
(
SELECT
bailun_sku,
FROM (
SELECT bailun_sku,
warehouse_code,
parent_id,
purchase_id,
estimated_arrival_time,
has_transfer,
sum( count ) AS count,
sum(count) AS count,
price,
transport_type
FROM
dc_base_purchase
WHERE
buy_status IN ( 0, 1, 2, 3 )
FROM dc_base_purchase
WHERE buy_status IN (0, 1, 2, 3)
AND has_delete = 0
GROUP BY
bailun_sku,
GROUP BY bailun_sku,
parent_id
) tb1
LEFT JOIN (
SELECT
bailun_sku,
SELECT bailun_sku,
warehouse_code,
parent_id,
sum( count ) AS count
FROM
dc_base_purchase_inbound
WHERE
1=1
GROUP BY
bailun_sku,
sum(count) AS count
FROM dc_base_purchase_inbound
WHERE 1 = 1
GROUP BY bailun_sku,
parent_id
) tb2 ON tb1.bailun_sku = tb2.bailun_sku
AND tb1.parent_id = tb2.parent_id
GROUP BY
tb1.bailun_sku,
GROUP BY tb1.bailun_sku,
tb1.warehouse_code,
tb1.purchase_id
) t
GROUP BY
bailun_sku,
GROUP BY bailun_sku,
warehouse_code
HAVING
count > 0
HAVING count > 0
</select>
<update id="updateOldOutStockToZero">
update dc_mid_transit set quantity_out_stock =0, quantity_out_stock_aliexpress = 0 where gmt_out_stock_modified &lt; #{outStockModified,jdbcType=TIMESTAMP}
update dc_mid_transit
set quantity_out_stock =0,
quantity_out_stock_aliexpress = 0
where gmt_out_stock_modified &lt; #{outStockModified,jdbcType=TIMESTAMP}
</update>
<update id="updateOldTransferToZero">
update dc_mid_transit set quantity_transfer =0, quantity_transfer_plan =0, quantity_land_transfer = 0,quantity_ocean_transfer = 0,quantity_air_transfer = 0,quantity_railway_transfer = 0 where gmt_transfer_modified &lt; #{transferModified,jdbcType=TIMESTAMP}
update dc_mid_transit
set quantity_transfer =0,
quantity_transfer_plan =0,
quantity_land_transfer = 0,
quantity_ocean_transfer = 0,
quantity_air_transfer = 0,
quantity_railway_transfer = 0
where gmt_transfer_modified &lt; #{transferModified,jdbcType=TIMESTAMP}
</update>
<update id="updateOldPurchaseToZero">
update dc_mid_transit set quantity_purchase =0,amount_purchase_transit=0, quantity_land_purchase = 0,quantity_ocean_purchase = 0,quantity_air_purchase = 0,quantity_railway_purchase = 0 where gmt_purchase_modified &lt; #{purchaseModified,jdbcType=TIMESTAMP}
update dc_mid_transit
set quantity_purchase =0,
amount_purchase_transit=0,
quantity_land_purchase = 0,
quantity_ocean_purchase = 0,
quantity_air_purchase = 0,
quantity_railway_purchase = 0
where gmt_purchase_modified &lt; #{purchaseModified,jdbcType=TIMESTAMP}
</update>
<update id="updateOldUnshippedToZero">
update dc_mid_transit set quantity_unshipped =0 where gmt_unshipped_modified &lt; #{unshippedModified,jdbcType=TIMESTAMP}
update dc_mid_transit
set quantity_unshipped =0
where gmt_unshipped_modified &lt; #{unshippedModified,jdbcType=TIMESTAMP}
</update>
<select id="selectMaxOutStockModified" resultType="java.time.LocalDateTime">
select max(gmt_out_stock_modified) from dc_mid_transit
select max(gmt_out_stock_modified)
from dc_mid_transit
</select>
<select id="selectMaxTransferModified" resultType="java.time.LocalDateTime">
select max(gmt_transfer_modified) from dc_mid_transit
select max(gmt_transfer_modified)
from dc_mid_transit
</select>
<select id="selectMaxPurchaseModified" resultType="java.time.LocalDateTime">
select max(gmt_purchase_modified) from dc_mid_transit
select max(gmt_purchase_modified)
from dc_mid_transit
</select>
<select id="selectMaxUnshippedModified" resultType="java.time.LocalDateTime">
select max(gmt_unshipped_modified) from dc_mid_transit
select max(gmt_unshipped_modified)
from dc_mid_transit
</select>
<insert id="calculateUnshipped">
insert into dc_mid_transit(bailun_sku, warehouse_code, quantity_unshipped,gmt_unshipped_modified,bailun_order_ids)
SELECT
t1.bailun_sku,
insert into dc_mid_transit(bailun_sku, warehouse_code, quantity_unshipped, gmt_unshipped_modified,
bailun_order_ids)
SELECT t1.bailun_sku,
t1.warehouse_code,
t1.bailun_sku_quantity_ordered - t1.bailun_sku_quantity_shipped,
CURRENT_TIMESTAMP,
t1.bailun_order_ids
FROM
(
SELECT
bailun_sku,warehouse_code,SUM(bailun_sku_quantity_ordered) AS bailun_sku_quantity_ordered,SUM(bailun_sku_quantity_shipped) AS bailun_sku_quantity_shipped,
GROUP_CONCAT(DISTINCT (case when warehouse_code='BLGZ03' then bailun_order_id else '' end)) as 'bailun_order_ids'
FROM
dc_base_oms_sku
WHERE
bailun_order_status = 'Handling'
and bailun_interception_status in('None','Failed')
FROM (
SELECT bailun_sku,
warehouse_code,
SUM(bailun_sku_quantity_ordered) AS bailun_sku_quantity_ordered,
SUM(bailun_sku_quantity_shipped) AS bailun_sku_quantity_shipped,
GROUP_CONCAT(DISTINCT
(case when warehouse_code = 'BLGZ03' then bailun_order_id else '' end)) as 'bailun_order_ids'
FROM dc_base_oms_sku
WHERE bailun_order_status = 'Handling'
and bailun_interception_status in ('None', 'Failed')
and warehouse_code != ''
and platform_type != 'FBA'
and has_delete = 0
......@@ -876,11 +947,12 @@
and has_innersale = 0
and paid_time >= '2019-03-01 12:00:00'
and bailun_sku_quantity_ordered > bailun_sku_quantity_shipped
GROUP BY
bailun_sku,
GROUP BY bailun_sku,
warehouse_code
) t1
WHERE (t1.bailun_sku_quantity_ordered - t1.bailun_sku_quantity_shipped) >= 0
ON DUPLICATE KEY UPDATE quantity_unshipped = VALUES(quantity_unshipped),gmt_unshipped_modified = VALUES(gmt_unshipped_modified),bailun_order_ids = VALUES(bailun_order_ids)
ON DUPLICATE KEY UPDATE quantity_unshipped = VALUES(quantity_unshipped),
gmt_unshipped_modified = VALUES(gmt_unshipped_modified),
bailun_order_ids = VALUES(bailun_order_ids)
</insert>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment