WEB/temp_stockcheck_tail.txt
liufumingren 4dc90ac539 1
2026-10-01 09:07:35 +08:00

132 lines
5.2 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

storageQuantityMap,
}));
}
/**
* å°†å<E280A0>•æ<E280A2>¡ç›˜ç‚¹æ˜Žç»†æ ¼å¼<C3A5>化为è<C2BA>šå<C5A1>ˆè¾“出行ã€?
* 商å“<C3A5>行:è<C5A1>šå<C5A1>ˆä½œä¸šè®°å½•输出已盘数é‡<C3A9>/差异/库ä½<C3A4>列表等;
* 库ä½<C3A4>行:按商å“<C3A5>è<EFBFBD>šå<C5A1>ˆä½œä¸šè®°å½•输å‡?stocks 列表(å<CB86>« wms_storage è´¦é<C2A6>¢ä¸Žå·®å¼‚)ã€?
*
* @param {Object} params æ ¼å¼<C3A5>化å<E28093>‚æ•°ã€?
* @param {Object} params.detailRow 明细原始行�
* @param {Map<number, Array<Object>>} params.recordsByDetail 按明细ID分组的作业记录�
* @param {Map<number, Object>} params.stockMap 商å“<C3A5>快照映射ã€?
* @param {Map<string, number>} params.storageQuantityMap 库ä½<C3A4>商å“<C3A5>è´¦é<C2A6>¢æ•°é‡<C3A9>映射(键 `${space_id}_${stock_id}`)ã€?
* @return {Object} æ ¼å¼<C3A5>化å<E28093>Žçš„æ˜Žç»†è¡Œã€?
*/
_formatDetailAggregationRow(params = {}) {
const { detailRow, recordsByDetail, stockMap, storageQuantityMap } = params;
const detailRowId = Number(detailRow.id);
const scopeType = (detailRow.scope_type || 'goods') === 'location' ? 'location' : 'goods';
const detailRecords = recordsByDetail.get(detailRowId) || [];
const locationCodes = [ ...new Set(detailRecords
.map(record => String(record.location_code || '').trim())
.filter(Boolean)) ];
const checkers = [ ...new Set(detailRecords
.map(record => String(record.checker_name || '').trim())
.filter(Boolean)) ];
const lastCheckedAt = detailRecords.length > 0
? detailRecords[detailRecords.length - 1].checked_at
: null;
// 按库ä½<C3A4>è<EFBFBD>šå<C5A1>ˆä½œä¸šè®°å½•(库ä½<C3A4>为空归入"无库ä½?分组,location_code ä¸?null),按首æ<E28093>¡è®°å½?id å<>‡åº<C3A5>
const locationGroups = new Map();
for (const record of detailRecords) {
const recordLocationCode = record.location_code !== null && record.location_code !== undefined
? String(record.location_code).trim()
: '';
if (!locationGroups.has(recordLocationCode)) {
locationGroups.set(recordLocationCode, {
location_id: recordLocationCode ? (Number(record.location_id) || null) : null,
location_code: recordLocationCode || null,
quantity: 0,
first_record_id: Number(record.id) || 0,
});
}
const locationGroup = locationGroups.get(recordLocationCode);
locationGroup.quantity += Number(record.quantity) || 0;
}
const locations = [ ...locationGroups.values() ]
.sort((left, right) => left.first_record_id - right.first_record_id)
.map(locationGroup => ({
location_id: locationGroup.location_id,
location_code: locationGroup.location_code,
quantity: locationGroup.quantity,
}));
const base = {
...detailRow,
scope_type: scopeType,
location_codes: locationCodes,
checkers,
last_checked_at: lastCheckedAt,
records: detailRecords,
locations,
};
if (scopeType === 'goods') {
const checkedQuantity = detailRecords.reduce((sum, record) => sum + (Number(record.quantity) || 0), 0);
const diffQuantity = checkedQuantity - Number(detailRow.system_quantity || 0);
return {
...base,
checked_quantity: detailRecords.length > 0 ? checkedQuantity : null,
diff_quantity: detailRecords.length > 0 ? diffQuantity : null,
is_diff: detailRecords.length > 0 && diffQuantity !== 0 ? 1 : 0,
status: detailRecords.length > 0 ? 'checked' : 'unchecked',
};
}
// 库ä½<C3A4>行:按商å“<C3A5>è<EFBFBD>šå<C5A1>ˆè®°å½•,账é<C2A6>¢ä»?wms_storage å<>–(location_id 为空时账é<C2A6>¢æŒ‰ 0ï¼?
const quantityByStock = new Map();
for (const record of detailRecords) {
const stockId = Number(record.stock_id);
if (!Number.isInteger(stockId) || stockId <= 0) {
continue;
}
const agg = quantityByStock.get(stockId) || { checked: 0 };
agg.checked += Number(record.quantity) || 0;
quantityByStock.set(stockId, agg);
}
const locationId = detailRow.location_id !== null && detailRow.location_id !== undefined
? Number(detailRow.location_id)
: 0;
let checkedQuantity = 0;
let diffQuantitySum = 0;
let hasDiff = false;
const stocks = [ ...quantityByStock.keys() ]
.sort((left, right) => left - right)
.map(stockId => {
const agg = quantityByStock.get(stockId);
const stock = stockMap.get(stockId) || {};
const systemQuantity = locationId > 0
? (storageQuantityMap.get(`${locationId}_${stockId}`) || 0)
: 0;
const diffQuantity = agg.checked - systemQuantity;
checkedQuantity += agg.checked;
diffQuantitySum += diffQuantity;
if (diffQuantity !== 0) {
hasDiff = true;
}
return {
stock_id: stockId,
item_code: stock.item_code || null,
item_name: stock.item_name || null,
system_quantity: systemQuantity,
checked_quantity: agg.checked,
diff_quantity: diffQuantity,
};
});
return {
...base,
stocks,
checked_quantity: detailRecords.length > 0 ? checkedQuantity : null,
diff_quantity: detailRecords.length > 0 ? diffQuantitySum : null,
is_diff: hasDiff ? 1 : 0,
status: detailRecords.length > 0 ? 'checked' : 'unchecked',
};
}
/**