1
This commit is contained in:
+27
-2
@@ -62,17 +62,42 @@ public interface InventoryQueryMapper {
|
||||
"<when test='q.inventoryStatus == \"PROCUREMENT\"'> AND b.procurement_packages > 0</when>" +
|
||||
"</choose>";
|
||||
|
||||
@Select("<script>SELECT * FROM ll_inventory_balance" + BALANCE_FILTER +
|
||||
@Select("<script>SELECT MIN(id) id," +
|
||||
"customer_id,MAX(customer_name) customer_name," +
|
||||
"overseas_warehouse_id,MAX(overseas_warehouse_code) overseas_warehouse_code," +
|
||||
"MAX(overseas_warehouse_name) overseas_warehouse_name," +
|
||||
"destination_warehouse_id,destination_warehouse_code," +
|
||||
"MAX(destination_warehouse_name) destination_warehouse_name," +
|
||||
"NULL inbound_order_id,NULL inbound_order_no,NULL inbound_code," +
|
||||
"sku_code,MAX(product_name_zh) product_name_zh,MAX(product_name_en) product_name_en," +
|
||||
"COALESCE(SUM(available_packages),0) available_packages," +
|
||||
"COALESCE(SUM(hold_packages),0) hold_packages," +
|
||||
"COALESCE(SUM(allocated_packages),0) allocated_packages," +
|
||||
"COALESCE(SUM(picked_packages),0) picked_packages," +
|
||||
"COALESCE(SUM(in_transit_packages),0) in_transit_packages," +
|
||||
"COALESCE(SUM(receiving_packages),0) receiving_packages," +
|
||||
"COALESCE(SUM(procurement_packages),0) procurement_packages," +
|
||||
"MAX(updated_at) updated_at FROM ll_inventory_balance" + BALANCE_FILTER +
|
||||
" GROUP BY customer_id,overseas_warehouse_id,destination_warehouse_id,destination_warehouse_code,sku_code" +
|
||||
" ORDER BY updated_at DESC,id DESC LIMIT #{limit} OFFSET #{offset}</script>")
|
||||
List<InventoryBalance> balances(@Param("customerId") String customerId,
|
||||
@Param("q") InventoryQueryRequests.BalanceQuery query,
|
||||
@Param("offset") long offset,
|
||||
@Param("limit") long limit);
|
||||
|
||||
@Select("<script>SELECT COUNT(*) FROM ll_inventory_balance" + BALANCE_FILTER + "</script>")
|
||||
@Select("<script>SELECT COUNT(*) FROM (SELECT 1 FROM ll_inventory_balance" + BALANCE_FILTER +
|
||||
" GROUP BY customer_id,overseas_warehouse_id,destination_warehouse_id,destination_warehouse_code,sku_code" +
|
||||
") grouped_balances</script>")
|
||||
long countBalances(@Param("customerId") String customerId,
|
||||
@Param("q") InventoryQueryRequests.BalanceQuery query);
|
||||
|
||||
@Select("<script>SELECT * FROM ll_inventory_balance" + BALANCE_FILTER +
|
||||
" ORDER BY updated_at DESC,id DESC LIMIT #{limit} OFFSET #{offset}</script>")
|
||||
List<InventoryBalance> sourceBalances(@Param("customerId") String customerId,
|
||||
@Param("q") InventoryQueryRequests.BalanceQuery query,
|
||||
@Param("offset") long offset,
|
||||
@Param("limit") long limit);
|
||||
|
||||
@Select("<script>SELECT COUNT(*) dimension_count," +
|
||||
"COALESCE(SUM(available_packages),0) available_packages," +
|
||||
"COALESCE(SUM(hold_packages),0) hold_packages," +
|
||||
|
||||
+1
-1
@@ -105,7 +105,7 @@ public class InventoryQueryService {
|
||||
final int batchSize = 1000;
|
||||
long offset = 0;
|
||||
while (true) {
|
||||
List<InventoryBalanceView> batch = mapper.balances(customerId, query, offset, batchSize).stream().map(this::balanceView).toList();
|
||||
List<InventoryBalanceView> batch = mapper.sourceBalances(customerId, query, offset, batchSize).stream().map(this::balanceView).toList();
|
||||
if (batch.isEmpty()) break;
|
||||
for (InventoryBalanceView v : batch) output.write((
|
||||
String.join(",", csv(v.customerId()), csv(v.customerName()), csv(v.overseasWarehouseCode()), csv(v.overseasWarehouseName()),
|
||||
|
||||
Reference in New Issue
Block a user