回退wavePickTaskList方法
This commit is contained in:
parent
61c530c0cc
commit
e980512db7
@ -55,9 +55,9 @@ class WaveService extends OrderBaseService {
|
||||
constructor(ctx) {
|
||||
super(ctx);
|
||||
const _noNeedLogin = '';
|
||||
const _noNeedRight = 'groupOrderFetchList,singleOrderFetchList,waveStrategyList,waveStrategyFallbackOrderList,groupFetch,singleFetch,fetch,fetchTaskProgress,batchList,batchCancel,batchCancelTaskProgress,batchRemoveExceptionOrders,batchRemoveExceptionOrdersTaskProgress,batchAllocateExpress,batchAllocateExpressTaskProgress,batchAllocateStorage,batchAllocateStorageTaskProgress,batchAutoGrouping,batchFinishAutoGrouping,batchRemoveOrders,singleFetchByIds,waveStrategyQuickScan,waveStrategyQuickScanTaskProgress';
|
||||
const _noNeedLog = 'groupOrderFetchList,singleOrderFetchList,waveStrategyList,waveStrategyFallbackOrderList,groupFetch,singleFetch,fetch,fetchTaskProgress,batchList,batchCancel,batchCancelTaskProgress,batchRemoveExceptionOrders,batchRemoveExceptionOrdersTaskProgress,batchAllocateExpress,batchAllocateExpressTaskProgress,batchAllocateStorage,batchAllocateStorageTaskProgress,batchAutoGrouping,batchFinishAutoGrouping,batchRemoveOrders,singleFetchByIds,waveStrategyQuickScan,waveStrategyQuickScanTaskProgress';
|
||||
const _noNeedAuth = 'groupOrderFetchList,singleOrderFetchList,waveStrategyList,waveStrategyFallbackOrderList,groupFetch,singleFetch,fetch,fetchTaskProgress,batchList,batchCancel,batchCancelTaskProgress,batchRemoveExceptionOrders,batchRemoveExceptionOrdersTaskProgress,batchAllocateExpress,batchAllocateExpressTaskProgress,batchAllocateStorage,batchAllocateStorageTaskProgress,batchAutoGrouping,batchFinishAutoGrouping,batchRemoveOrders,singleFetchByIds,waveStrategyQuickScan,waveStrategyQuickScanTaskProgress';
|
||||
const _noNeedRight = 'wavePickTaskList,groupOrderFetchList,singleOrderFetchList,waveStrategyList,waveStrategyFallbackOrderList,groupFetch,singleFetch,fetch,fetchTaskProgress,batchList,batchCancel,batchCancelTaskProgress,batchRemoveExceptionOrders,batchRemoveExceptionOrdersTaskProgress,batchAllocateExpress,batchAllocateExpressTaskProgress,batchAllocateStorage,batchAllocateStorageTaskProgress,batchAutoGrouping,batchFinishAutoGrouping,batchRemoveOrders,singleFetchByIds,waveStrategyQuickScan,waveStrategyQuickScanTaskProgress';
|
||||
const _noNeedLog = 'wavePickTaskList,groupOrderFetchList,singleOrderFetchList,waveStrategyList,waveStrategyFallbackOrderList,groupFetch,singleFetch,fetch,fetchTaskProgress,batchList,batchCancel,batchCancelTaskProgress,batchRemoveExceptionOrders,batchRemoveExceptionOrdersTaskProgress,batchAllocateExpress,batchAllocateExpressTaskProgress,batchAllocateStorage,batchAllocateStorageTaskProgress,batchAutoGrouping,batchFinishAutoGrouping,batchRemoveOrders,singleFetchByIds,waveStrategyQuickScan,waveStrategyQuickScanTaskProgress';
|
||||
const _noNeedAuth = 'wavePickTaskList,groupOrderFetchList,singleOrderFetchList,waveStrategyList,waveStrategyFallbackOrderList,groupFetch,singleFetch,fetch,fetchTaskProgress,batchList,batchCancel,batchCancelTaskProgress,batchRemoveExceptionOrders,batchRemoveExceptionOrdersTaskProgress,batchAllocateExpress,batchAllocateExpressTaskProgress,batchAllocateStorage,batchAllocateStorageTaskProgress,batchAutoGrouping,batchFinishAutoGrouping,batchRemoveOrders,singleFetchByIds,waveStrategyQuickScan,waveStrategyQuickScanTaskProgress';
|
||||
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||||
}
|
||||
|
||||
@ -1522,6 +1522,156 @@ class WaveService extends OrderBaseService {
|
||||
quantity: Number.isFinite(quantity) && quantity > 0 ? quantity : 0,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* 拣货任务列表查询。
|
||||
*
|
||||
* 基于 wms_wave_pick_task 主表按当前仓库维度分页查询,默认按 create_time 倒序。
|
||||
*
|
||||
* @param {Object} [data={}] 请求参数。
|
||||
* @param {number|string} [data.page] 页码(兼容 current)。
|
||||
* @param {number|string} [data.pageSize] 每页数量(兼容 size/page_size)。
|
||||
* @param {Object} [data.where] 查询过滤。
|
||||
* @return {Promise<Object>} 列表与分页结果。
|
||||
*/
|
||||
async wavePickTaskList(data = {}) {
|
||||
try {
|
||||
const requestData = this.isPlainObject(data) ? data : {};
|
||||
const { page, pageSize } = this.normalizeWavePickTaskListPagination(requestData);
|
||||
const normalizedRequest = this.normalizeWavePickTaskListRequest(requestData);
|
||||
const warehouseId = normalizedRequest.warehouseId;
|
||||
const whereClause = this.buildWavePickTaskListWhereClause(normalizedRequest.where);
|
||||
const offset = (page - 1) * pageSize;
|
||||
|
||||
const listSql = `
|
||||
SELECT
|
||||
t.id,
|
||||
t.task_no,
|
||||
t.warehouse_id,
|
||||
t.pick_mode,
|
||||
t.status,
|
||||
t.review_status,
|
||||
t.source,
|
||||
t.wave_count,
|
||||
t.order_count,
|
||||
t.box_count,
|
||||
t.pick_user_id,
|
||||
t.pick_user_name,
|
||||
t.review_user_id,
|
||||
t.review_user_name,
|
||||
t.current_cart_id,
|
||||
t.current_cart_code_snapshot,
|
||||
t.batch_no,
|
||||
t.device_id,
|
||||
t.start_time,
|
||||
t.finish_time,
|
||||
t.review_start_time,
|
||||
t.review_finish_time,
|
||||
t.create_time,
|
||||
t.update_time
|
||||
FROM wms_wave_pick_task t
|
||||
WHERE t.warehouse_id = :warehouseId
|
||||
${whereClause.sql}
|
||||
ORDER BY t.create_time DESC
|
||||
LIMIT :limit OFFSET :offset
|
||||
`;
|
||||
|
||||
const countSql = `
|
||||
SELECT COUNT(1) AS total
|
||||
FROM wms_wave_pick_task t
|
||||
WHERE t.warehouse_id = :warehouseId
|
||||
${whereClause.sql}
|
||||
`;
|
||||
|
||||
const replacements = {
|
||||
warehouseId,
|
||||
...whereClause.replacements,
|
||||
};
|
||||
|
||||
const [ listRows, countRows ] = await Promise.all([
|
||||
this.ctx.model.query(listSql, {
|
||||
replacements: {
|
||||
...replacements,
|
||||
limit: pageSize,
|
||||
offset,
|
||||
},
|
||||
}),
|
||||
this.ctx.model.query(countSql, {
|
||||
replacements,
|
||||
}),
|
||||
]);
|
||||
|
||||
const sourceList = Array.isArray(listRows && listRows[0]) ? listRows[0] : [];
|
||||
const totalRowList = Array.isArray(countRows && countRows[0]) ? countRows[0] : [];
|
||||
const total = Number(totalRowList[0] && totalRowList[0].total || 0);
|
||||
|
||||
const list = sourceList.map(item => ({
|
||||
task_id: Number(item && item.id || 0),
|
||||
task_no: String(item && item.task_no || '').trim(),
|
||||
warehouse_id: Number(item && item.warehouse_id || 0),
|
||||
pick_mode: Number(item && item.pick_mode || 0),
|
||||
status: Number(item && item.status || 0),
|
||||
review_status: Number(item && item.review_status || 0),
|
||||
source: Number(item && item.source || 0),
|
||||
wave_count: Number(item && item.wave_count || 0),
|
||||
order_count: Number(item && item.order_count || 0),
|
||||
box_count: Number(item && item.box_count || 0),
|
||||
pick_user_id: Number(item && item.pick_user_id || 0),
|
||||
pick_user_name: String(item && item.pick_user_name || '').trim(),
|
||||
operator_id: Number(item && item.pick_user_id || 0),
|
||||
operator_name: String(item && item.pick_user_name || '').trim(),
|
||||
review_user_id: Number(item && item.review_user_id || 0),
|
||||
review_user_name: String(item && item.review_user_name || '').trim(),
|
||||
current_cart_id: Number(item && item.current_cart_id || 0),
|
||||
current_cart_code_snapshot: String(item && item.current_cart_code_snapshot || '').trim(),
|
||||
batch_no: String(item && item.batch_no || '').trim(),
|
||||
device_id: String(item && item.device_id || '').trim(),
|
||||
start_time: item && item.start_time || null,
|
||||
start_at: item && item.start_time || null,
|
||||
finish_time: item && item.finish_time || null,
|
||||
finish_at: item && item.finish_time || null,
|
||||
review_start_time: item && item.review_start_time || null,
|
||||
review_finish_time: item && item.review_finish_time || null,
|
||||
create_time: item && item.create_time || null,
|
||||
created_at: item && item.create_time || null,
|
||||
update_time: item && item.update_time || null,
|
||||
}));
|
||||
|
||||
return this.success('ok', {
|
||||
list,
|
||||
total,
|
||||
page,
|
||||
page_size: pageSize,
|
||||
});
|
||||
} catch (error) {
|
||||
const errorMessage = String(error && error.message || '').trim();
|
||||
const isBadRequest = /参数|上下文/.test(errorMessage);
|
||||
return this.fail(`查询拣货任务列表失败: ${errorMessage || '未知错误'}`, isBadRequest ? 400 : 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析拣货任务列表分页参数。
|
||||
*
|
||||
* 兼容 current/size 写法,并复用通用分页归一化能力。
|
||||
*
|
||||
* @param {Object} data 请求参数。
|
||||
* @return {{ page: number, pageSize: number }} 归一化分页。
|
||||
*/
|
||||
normalizeWavePickTaskListPagination(data = {}) {
|
||||
const normalizedData = this.isPlainObject(data) ? data : {};
|
||||
const pagination = this.isPlainObject(normalizedData.pagination)
|
||||
? normalizedData.pagination
|
||||
: normalizedData;
|
||||
|
||||
const pageSource = pagination.page ?? pagination.page_no ?? pagination.pageNo ?? pagination.current;
|
||||
const pageSizeSource = pagination.pageSize ?? pagination.page_size ?? pagination.size;
|
||||
|
||||
return this.normalizePagination({
|
||||
page: pageSource,
|
||||
pageSize: pageSizeSource,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
mergeOrderItemDetails(itemRows = []) {
|
||||
const merged = new Map();
|
||||
@ -1602,6 +1752,197 @@ class WaveService extends OrderBaseService {
|
||||
return segments.join('|');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 归一化拣货任务列表请求参数。
|
||||
*
|
||||
* 兼容顶层筛选参数与 where 结构并保持旧调用可用:
|
||||
* - 顶层支持 warehouse_id/status/source/keyword/task_no
|
||||
* - 同名字段优先使用顶层值覆盖 where
|
||||
* - warehouse_id 未传时回退当前仓库上下文
|
||||
*
|
||||
* @param {Object} data 请求参数。
|
||||
* @return {{ warehouseId: number, where: Object }} 归一化仓库与查询条件。
|
||||
*/
|
||||
normalizeWavePickTaskListRequest(data = {}) {
|
||||
const requestData = this.isPlainObject(data) ? data : {};
|
||||
const baseWhere = this.isPlainObject(requestData.where) ? { ...requestData.where } : {};
|
||||
|
||||
const mergeFieldFromTopLevel = fieldName => {
|
||||
if (Object.prototype.hasOwnProperty.call(requestData, fieldName)) {
|
||||
baseWhere[fieldName] = requestData[fieldName];
|
||||
}
|
||||
};
|
||||
|
||||
[
|
||||
'status',
|
||||
'source',
|
||||
'keyword',
|
||||
'task_no',
|
||||
'pick_mode',
|
||||
'review_status',
|
||||
'pick_user_id',
|
||||
'review_user_id',
|
||||
'cart_id',
|
||||
'start_time_start',
|
||||
'start_time_end',
|
||||
].forEach(mergeFieldFromTopLevel);
|
||||
|
||||
const contextWarehouseId = Number(this.getWarehouseId() || 0);
|
||||
const inputWarehouseId = requestData.warehouse_id ?? requestData.warehouseId;
|
||||
const warehouseId = inputWarehouseId !== undefined && inputWarehouseId !== null && inputWarehouseId !== ''
|
||||
? Number(inputWarehouseId)
|
||||
: contextWarehouseId;
|
||||
|
||||
if (!Number.isInteger(warehouseId) || warehouseId <= 0) {
|
||||
throw new Error('warehouse_id 参数不合法');
|
||||
}
|
||||
|
||||
if (Number.isInteger(contextWarehouseId)
|
||||
&& contextWarehouseId > 0
|
||||
&& inputWarehouseId !== undefined
|
||||
&& inputWarehouseId !== null
|
||||
&& inputWarehouseId !== ''
|
||||
&& warehouseId !== contextWarehouseId) {
|
||||
throw new Error('warehouse_id 与当前仓库上下文不一致');
|
||||
}
|
||||
|
||||
return {
|
||||
warehouseId,
|
||||
where: baseWhere,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建拣货任务列表 where 条件(白名单字段)。
|
||||
*
|
||||
* 注意:当前 wms_wave_pick_task 主表未落 strategy_id 字段,
|
||||
* 因此 strategy_id 过滤入参会被忽略,不参与 SQL 条件拼接。
|
||||
*
|
||||
* @param {Object} whereData 查询 where 入参。
|
||||
* @return {{ sql: string, replacements: Object }} SQL 条件片段与参数。
|
||||
*/
|
||||
buildWavePickTaskListWhereClause(whereData = {}) {
|
||||
const normalizedWhere = this.isPlainObject(whereData) ? whereData : {};
|
||||
const whereKeys = Object.keys(normalizedWhere);
|
||||
const allowedFields = [
|
||||
'status',
|
||||
'review_status',
|
||||
'pick_mode',
|
||||
'source',
|
||||
'strategy_id',
|
||||
'pick_user_id',
|
||||
'review_user_id',
|
||||
'task_no',
|
||||
'cart_id',
|
||||
'keyword',
|
||||
'start_time_start',
|
||||
'start_time_end',
|
||||
];
|
||||
|
||||
const invalidFields = whereKeys.filter(key => !allowedFields.includes(key));
|
||||
if (invalidFields.length > 0) {
|
||||
throw new Error(`where 存在不支持的字段: ${invalidFields.join(',')}`);
|
||||
}
|
||||
|
||||
const conditions = [];
|
||||
const replacements = {};
|
||||
|
||||
const appendIntegerEqualCondition = (fieldKey, columnName, replacementKey, allowZero = true) => {
|
||||
const value = normalizedWhere[fieldKey];
|
||||
if (value === undefined || value === null || value === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
const numberValue = Number(value);
|
||||
const isValid = Number.isInteger(numberValue) && (allowZero ? numberValue >= 0 : numberValue > 0);
|
||||
if (!isValid) {
|
||||
throw new Error(`${fieldKey} 参数不合法`);
|
||||
}
|
||||
|
||||
conditions.push(`${columnName} = :${replacementKey}`);
|
||||
replacements[replacementKey] = numberValue;
|
||||
};
|
||||
|
||||
const status = normalizedWhere.status;
|
||||
if (Array.isArray(status)) {
|
||||
const normalizedStatusList = [ ...new Set(status
|
||||
.map(value => Number(value))
|
||||
.filter(value => Number.isInteger(value) && value >= 0)) ];
|
||||
if (normalizedStatusList.length <= 0) {
|
||||
throw new Error('status 参数不合法');
|
||||
}
|
||||
|
||||
conditions.push('t.status IN (:whereStatusList)');
|
||||
replacements.whereStatusList = normalizedStatusList;
|
||||
} else {
|
||||
appendIntegerEqualCondition('status', 't.status', 'whereStatus');
|
||||
}
|
||||
appendIntegerEqualCondition('review_status', 't.review_status', 'whereReviewStatus');
|
||||
appendIntegerEqualCondition('pick_mode', 't.pick_mode', 'wherePickMode', false);
|
||||
appendIntegerEqualCondition('source', 't.source', 'whereSource', false);
|
||||
appendIntegerEqualCondition('pick_user_id', 't.pick_user_id', 'wherePickUserId');
|
||||
appendIntegerEqualCondition('review_user_id', 't.review_user_id', 'whereReviewUserId');
|
||||
appendIntegerEqualCondition('cart_id', 't.current_cart_id', 'whereCartId', false);
|
||||
|
||||
const taskNo = normalizedWhere.task_no;
|
||||
if (taskNo !== undefined && taskNo !== null && taskNo !== '') {
|
||||
const normalizedTaskNo = String(taskNo).trim();
|
||||
if (!normalizedTaskNo) {
|
||||
throw new Error('task_no 参数不合法');
|
||||
}
|
||||
|
||||
conditions.push('t.task_no LIKE :whereTaskNo');
|
||||
replacements.whereTaskNo = `%${normalizedTaskNo}%`;
|
||||
}
|
||||
|
||||
const keyword = normalizedWhere.keyword;
|
||||
if (keyword !== undefined && keyword !== null && keyword !== '') {
|
||||
const normalizedKeyword = String(keyword).trim();
|
||||
if (!normalizedKeyword) {
|
||||
throw new Error('keyword 参数不合法');
|
||||
}
|
||||
|
||||
conditions.push(`(
|
||||
t.task_no LIKE :whereKeyword
|
||||
OR t.pick_user_name LIKE :whereKeyword
|
||||
OR t.review_user_name LIKE :whereKeyword
|
||||
OR t.batch_no LIKE :whereKeyword
|
||||
)`);
|
||||
replacements.whereKeyword = `%${normalizedKeyword}%`;
|
||||
}
|
||||
|
||||
const startTimeStart = normalizedWhere.start_time_start;
|
||||
if (startTimeStart !== undefined && startTimeStart !== null && startTimeStart !== '') {
|
||||
const normalizedStartTimeStart = String(startTimeStart).trim();
|
||||
const startDate = new Date(normalizedStartTimeStart);
|
||||
if (!normalizedStartTimeStart || Number.isNaN(startDate.getTime())) {
|
||||
throw new Error('start_time_start 参数不合法');
|
||||
}
|
||||
|
||||
conditions.push('t.create_time >= :whereCreateTimeStart');
|
||||
replacements.whereCreateTimeStart = normalizedStartTimeStart;
|
||||
}
|
||||
|
||||
const startTimeEnd = normalizedWhere.start_time_end;
|
||||
if (startTimeEnd !== undefined && startTimeEnd !== null && startTimeEnd !== '') {
|
||||
const normalizedStartTimeEnd = String(startTimeEnd).trim();
|
||||
const endDate = new Date(normalizedStartTimeEnd);
|
||||
if (!normalizedStartTimeEnd || Number.isNaN(endDate.getTime())) {
|
||||
throw new Error('start_time_end 参数不合法');
|
||||
}
|
||||
|
||||
conditions.push('t.create_time <= :whereCreateTimeEnd');
|
||||
replacements.whereCreateTimeEnd = normalizedStartTimeEnd;
|
||||
}
|
||||
|
||||
return {
|
||||
sql: conditions.length > 0 ? `\n AND ${conditions.join('\n AND ')}` : '',
|
||||
replacements,
|
||||
};
|
||||
}
|
||||
|
||||
buildItemSnapshotKey(itemDetails = []) {
|
||||
if (!Array.isArray(itemDetails) || itemDetails.length === 0) {
|
||||
return '';
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user