- 订单表新增 intercept_time 拦截时间字段(迁移覆盖基表与全部分表),全拦截链路写入拦截时间、解除拦截清空 - 新增自动库内拦截确定定时任务(1h 间隔,扫描 requested+未打印订单,超时自动库内拦截确定) - 复核链路自动移除波次内未打印拦截订单回池,拦截解除后可重新抓取发货 - 打印解绑车判定排除拦截订单,修复波次含拦截订单时车无法解锁 - 同步 methods 文档与变更记录;含 wave_scope 回填、workbench token 过期等前序迁移
339 lines
10 KiB
JavaScript
339 lines
10 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';
|
||
const _noNeedRight = 'list,detail,business,getWorkbenchInfo,removeMember,bindMember,packOrder,finishPack,sendWeight,queryOrder';
|
||
const _noNeedLog = 'list,detail,getWorkbenchInfo,removeMember,bindMember';
|
||
const _noNeedAuth = 'list,detail,business,getWorkbenchInfo,removeMember,bindMember,packOrder,finishPack,sendWeight,queryOrder';
|
||
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);
|
||
}
|
||
}
|
||
}
|
||
|
||
module.exports = WorkbenchService;
|