- 新增 workbench.getWorkbenchCount:以工作台 token 鉴权,统计本地 08:00→次日 08:00 班次窗口; 个人工作台统计涉及本人数据(团购波次数量/团购订单数量/散单数量/团散/均件数), 团体工作台统计涉及工作台数据(团购波次数量/团购订单数量/散单数量) - packOrder 打包数量/商品总件数/商品种类数改为服务端复查:散单取订单分表、团购取波次实时统计 (totalOrders + 波次 SKU 聚合 15s 缓存),设备上报仅交叉校验日志;修复散单 sku_count 兜底误读 item_count 列名 - wms_pack_task 新增 (workbench_id, create_time) 复合索引迁移,避免统计查询长跨度扫描慢 SQL - 同步 methods/system.json(0.3.142)/methods/changes/system.json,刷新 AI_METHOD_ROUTING.md - 一并提交上一轮未提交的 order.wave.batchList sync_assignment_status 输出与筛选
362 lines
11 KiB
JavaScript
362 lines
11 KiB
JavaScript
'use strict';
|
||
|
||
const MainService = require('../main');
|
||
|
||
class WorkbenchService extends MainService {
|
||
constructor(ctx) {
|
||
super(ctx);
|
||
const _noNeedLogin = 'business,getWorkbenchInfo,removeMember,bindMember,packOrder,finishPack,sendWeight,queryOrder,getWorkbenchCount';
|
||
const _noNeedRight = 'list,detail,business,getWorkbenchInfo,removeMember,bindMember,packOrder,finishPack,sendWeight,queryOrder,getWorkbenchCount';
|
||
const _noNeedLog = 'list,detail,getWorkbenchInfo,removeMember,bindMember';
|
||
const _noNeedAuth = 'list,detail,business,getWorkbenchInfo,removeMember,bindMember,packOrder,finishPack,sendWeight,queryOrder,getWorkbenchCount';
|
||
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
||
}
|
||
|
||
/**
|
||
* 工作台列表(分页 + 筛选)
|
||
* @param data
|
||
*/
|
||
async list(data) {
|
||
const { service } = this;
|
||
try {
|
||
const result = await service.systems.workbench.list(data || {});
|
||
return this.success('获取成功', result);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 工作台详情
|
||
* @param data
|
||
*/
|
||
async detail(data) {
|
||
const { service } = this;
|
||
try {
|
||
const { id } = data || {};
|
||
if (!id) return this.fail('工作台ID不能为空');
|
||
const record = await service.systems.workbench.detail(parseInt(id));
|
||
return this.success('获取成功', record);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 创建工作台
|
||
* @param data
|
||
*/
|
||
async create(data) {
|
||
const { service } = this;
|
||
try {
|
||
const record = await service.systems.workbench.create(data);
|
||
return this.success('创建成功', record);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 更新工作台
|
||
* @param data
|
||
*/
|
||
async update(data) {
|
||
const { service } = this;
|
||
try {
|
||
const { id, ...fields } = data || {};
|
||
if (!id) return this.fail('工作台ID不能为空');
|
||
const record = await service.systems.workbench.update(parseInt(id), fields);
|
||
return this.success('更新成功', record);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 删除工作台(软删除)
|
||
* @param data
|
||
*/
|
||
async delete(data) {
|
||
const { service } = this;
|
||
try {
|
||
const { id } = data || {};
|
||
if (!id) return this.fail('工作台ID不能为空');
|
||
await service.systems.workbench.delete(parseInt(id));
|
||
return this.success('删除成功');
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 工作台业务入口(免登录、免鉴权)
|
||
* @param {Object} data - { name, data }
|
||
*/
|
||
async business(data) {
|
||
const { ctx, service } = this;
|
||
const { name, data: bizData } = data || {};
|
||
ctx.logger.info('[Workbench.business] 收到业务请求 name=%s data=%j', name, bizData);
|
||
try {
|
||
const result = await service.systems.workbench.business(name, bizData);
|
||
return this.success('ok', result);
|
||
} catch (error) {
|
||
ctx.logger.error('[Workbench.business] 业务处理失败 name=%s error=%s', name, error.message);
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 工作台绑定摄像头
|
||
* @param data
|
||
*/
|
||
async bindCamera(data) {
|
||
const { service } = this;
|
||
try {
|
||
const { id, camera_ids } = data || {};
|
||
if (!id) return this.fail('工作台ID不能为空');
|
||
const record = await service.systems.workbench.bindCamera(parseInt(id), camera_ids);
|
||
return this.success('绑定成功', record);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 工作台绑定:校验缓存绑定码与工作台ID,写入随机 token(需登录、需权限)
|
||
* @param data - { code, id }
|
||
*/
|
||
async bind(data) {
|
||
const { service } = this;
|
||
try {
|
||
const result = await service.systems.workbench.bindWorkbench(data || {});
|
||
if (result && result.success) {
|
||
return this.success('绑定成功', result);
|
||
}
|
||
const statusCode = result && result.statusCode;
|
||
return this.fail(
|
||
result && result.message ? result.message : '绑定失败',
|
||
statusCode ? { code: statusCode } : undefined
|
||
);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 使用 token 获取工作台信息(免登录、免鉴权)。
|
||
* 返回主表信息、成员列表 members,以及当前正在打包的波次(current_wave)与订单列表(current_orders)。
|
||
* @param {Object} data - { token }
|
||
*/
|
||
async getWorkbenchInfo(data) {
|
||
const { service } = this;
|
||
try {
|
||
const { token } = data || {};
|
||
const result = await service.systems.workbench.getWorkbenchInfoByToken({ token });
|
||
if (result && result.success) {
|
||
return this.success('获取成功', result);
|
||
}
|
||
const statusCode = result && result.statusCode;
|
||
return this.fail(
|
||
result && result.message ? result.message : '获取工作台信息失败',
|
||
statusCode ? { code: statusCode } : undefined
|
||
);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 重置工作台登录码(需登录、需权限)
|
||
* @param data - { id }
|
||
*/
|
||
async resetLoginCode(data) {
|
||
const { service } = this;
|
||
try {
|
||
const { id } = data || {};
|
||
if (!id) return this.fail('工作台ID不能为空');
|
||
const result = await service.systems.workbench.resetLoginCode(parseInt(id));
|
||
return this.success('重置成功', result);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 移除工作台成员(免登录、免鉴权,以工作台 token 鉴权)
|
||
* @param data - { ids, token }
|
||
*/
|
||
async removeMember(data) {
|
||
const { service } = this;
|
||
try {
|
||
const result = await service.systems.workbench.removeWorkbenchMember(data || {});
|
||
if (result && result.success) {
|
||
return this.success('移除成功', result);
|
||
}
|
||
const statusCode = result && result.statusCode;
|
||
return this.fail(
|
||
result && result.message ? result.message : '移除成员失败',
|
||
statusCode ? { code: statusCode } : undefined
|
||
);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 绑定工作台成员(免登录、免鉴权,以工作台 token 鉴权)
|
||
* @param data - { userId | user_id, userName | user_name | name, token }
|
||
*/
|
||
async bindMember(data) {
|
||
const { service } = this;
|
||
try {
|
||
const result = await service.systems.workbench.bindWorkbenchMember(data || {});
|
||
if (result && result.success) {
|
||
return this.success('绑定成功', result);
|
||
}
|
||
const statusCode = result && result.statusCode;
|
||
return this.fail(
|
||
result && result.message ? result.message : '绑定成员失败',
|
||
statusCode ? { code: statusCode } : undefined
|
||
);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
/**
|
||
* 工作台打包上报(免登录、免鉴权,以工作台 token 鉴权,仓库与工作台由服务端注入)
|
||
* @param {Object} data - {
|
||
* token, delivery_order_code, wave_no, status, pack_time,
|
||
* wave_total_orders, items_count, items_total, users
|
||
* }
|
||
*/
|
||
async packOrder(data) {
|
||
const { service } = this;
|
||
try {
|
||
const {
|
||
token,
|
||
delivery_order_code: deliveryOrderCode,
|
||
wave_no: waveNo,
|
||
status,
|
||
pack_time: packTime,
|
||
wave_total_orders: waveTotalOrders,
|
||
items_count: itemsCount,
|
||
items_total: itemsTotal,
|
||
users,
|
||
} = data || {};
|
||
const result = await service.systems.workbench.packOrderByToken({
|
||
token,
|
||
delivery_order_code: deliveryOrderCode,
|
||
wave_no: waveNo,
|
||
status,
|
||
pack_time: packTime,
|
||
wave_total_orders: waveTotalOrders,
|
||
items_count: itemsCount,
|
||
items_total: itemsTotal,
|
||
users,
|
||
});
|
||
if (result && result.success) {
|
||
return this.success('ok', result);
|
||
}
|
||
const statusCode = result && result.statusCode;
|
||
return this.fail(
|
||
result && result.message ? result.message : '打包上报失败',
|
||
statusCode ? { code: statusCode } : undefined
|
||
);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 工作台打包完成(免登录、免鉴权,以工作台 token 鉴权,仓库与工作台由服务端注入)
|
||
* @param {Object} data - { token }
|
||
*/
|
||
async finishPack(data) {
|
||
const { service } = this;
|
||
try {
|
||
const { token } = data || {};
|
||
const result = await service.systems.workbench.finishPackByToken({ token });
|
||
if (result && result.success) {
|
||
return this.success('ok', result);
|
||
}
|
||
const statusCode = result && result.statusCode;
|
||
return this.fail(
|
||
result && result.message ? result.message : '打包完成失败',
|
||
statusCode ? { code: statusCode } : undefined
|
||
);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 工作台称重上报(免登录、免鉴权,以工作台 token 鉴权,仓库由服务端注入)
|
||
* @param {Object} data - { token, barcode, weight }
|
||
*/
|
||
async sendWeight(data) {
|
||
const { service } = this;
|
||
try {
|
||
const { token, barcode, weight } = data || {};
|
||
const result = await service.systems.workbench.sendWeightByToken({ token, barcode, weight });
|
||
if (result && result.success) {
|
||
return this.success('ok', result);
|
||
}
|
||
const statusCode = result && result.statusCode;
|
||
return this.fail(
|
||
result && result.message ? result.message : '称重上报失败',
|
||
statusCode ? { code: statusCode } : undefined
|
||
);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 条码查询订单(免登录、免鉴权,以工作台 token 鉴权,仓库由服务端注入)
|
||
* body 传入的 warehouse_id/workbench_id 一律忽略,仅以 token 解析出的工作台仓库为准。
|
||
* @param {Object} data - { token, barcode }
|
||
*/
|
||
async queryOrder(data) {
|
||
const { service } = this;
|
||
try {
|
||
const { token, barcode } = data || {};
|
||
const result = await service.systems.workbench.queryOrderByToken({ token, barcode });
|
||
if (result && result.success) {
|
||
return this.success('ok', result);
|
||
}
|
||
const statusCode = result && result.statusCode;
|
||
return this.fail(
|
||
result && result.message ? result.message : '查询订单失败',
|
||
statusCode ? { code: statusCode } : undefined
|
||
);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 当前工作台班次打包统计(免登录、免鉴权,以工作台 token 鉴权,仓库与工作台由服务端注入)。
|
||
* 统计窗口:本地时间当日 08:00 至次日 08:00,早于 08:00 时为昨日 08:00 至今日 08:00。
|
||
* @param {Object} data - { token }
|
||
*/
|
||
async getWorkbenchCount(data) {
|
||
const { service } = this;
|
||
try {
|
||
const { token } = data || {};
|
||
const result = await service.systems.workbench.getWorkbenchCountByToken({ token });
|
||
if (result && result.success) {
|
||
return this.success('ok', result);
|
||
}
|
||
const statusCode = result && result.statusCode;
|
||
return this.fail(
|
||
result && result.message ? result.message : '获取工作台统计失败',
|
||
statusCode ? { code: statusCode } : undefined
|
||
);
|
||
} catch (error) {
|
||
return this.fail(error.message);
|
||
}
|
||
}
|
||
}
|
||
|
||
module.exports = WorkbenchService;
|