shipClazz中getPrintInfo实现
This commit is contained in:
parent
12fa14c711
commit
b9edf59dc7
|
|
@ -7,7 +7,7 @@ export default interface ShipClazz<ED extends EntityDict & BaseEntityDict, Conte
|
|||
cancelOrder(shipId: string, context: Context): Promise<void>;
|
||||
syncState(shipId: string, context: Context): Promise<EntityDict['ship']['OpSchema']['iState']>;
|
||||
syncPaths(shipId: string, context: Context): Promise<EntityDict['ship']['OpSchema']['extraPaths']>;
|
||||
getPrintInfo(shipId: string): Promise<{
|
||||
getPrintInfo(shipId: string, context: Context): Promise<{
|
||||
type: 'html';
|
||||
data: string;
|
||||
}>;
|
||||
|
|
|
|||
|
|
@ -7,4 +7,8 @@ export default class WechatMpShip<ED extends EntityDict & BaseEntityDict, Contex
|
|||
cancelOrder(shipId: string, context: Context): Promise<void>;
|
||||
syncState(shipId: string, context: Context): Promise<EntityDict['ship']['OpSchema']['iState']>;
|
||||
syncPaths(shipId: string, context: Context): Promise<EntityDict['ship']['OpSchema']['extraPaths']>;
|
||||
getPrintInfo(shipId: string, context: Context): Promise<{
|
||||
type: 'html';
|
||||
data: string;
|
||||
}>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,11 +43,17 @@ export default class WechatMpShipDebug<ED extends EntityDict & BaseEntityDict, C
|
|||
delivery_id: string;
|
||||
waybill_id: NonNullable<ED["ship"]["Schema"]["extraShipId"]>;
|
||||
}>;
|
||||
protected prepareGetOrder(shipId: string, context: Context): Promise<{
|
||||
order_id: string;
|
||||
openid: string | undefined;
|
||||
delivery_id: string;
|
||||
waybill_id: NonNullable<ED["ship"]["Schema"]["extraShipId"]>;
|
||||
}>;
|
||||
eOrder(shipId: string, context: Context): Promise<string>;
|
||||
cancelOrder(shipId: string, context: Context): Promise<void>;
|
||||
syncState(shipId: string, context: Context): Promise<EntityDict["ship"]["OpSchema"]["iState"]>;
|
||||
syncPaths(shipId: string, context: Context): Promise<EntityDict["ship"]["OpSchema"]["extraPaths"]>;
|
||||
getPrintInfo(shipId: string): Promise<{
|
||||
getPrintInfo(shipId: string, context: Context): Promise<{
|
||||
type: "html";
|
||||
data: string;
|
||||
}>;
|
||||
|
|
|
|||
|
|
@ -287,6 +287,40 @@ export default class WechatMpShipDebug {
|
|||
waybill_id: extraShipId,
|
||||
};
|
||||
}
|
||||
async prepareGetOrder(shipId, context) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: {
|
||||
id: 1,
|
||||
extraShipId: 1,
|
||||
shipService: {
|
||||
shipCompanyId: 1,
|
||||
},
|
||||
shipOrder$ship: {
|
||||
$entity: 'shipOrder',
|
||||
data: {
|
||||
orderId: 1,
|
||||
order: {}
|
||||
},
|
||||
},
|
||||
wechatMpShip: {
|
||||
applicationId: 1,
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id: shipId,
|
||||
}
|
||||
}, { dontCollect: true });
|
||||
assert(ship);
|
||||
const { extraShipId, shipService, shipOrder$ship: shipOrders, wechatMpShip } = ship;
|
||||
const orderIds = shipOrders.map(ele => ele.orderId);
|
||||
const { openId } = await this.getReceiverInfo(orderIds, wechatMpShip.applicationId, context);
|
||||
return {
|
||||
order_id: shipId,
|
||||
openid: openId,
|
||||
delivery_id: shipService.shipCompanyId,
|
||||
waybill_id: extraShipId,
|
||||
};
|
||||
}
|
||||
async eOrder(shipId, context) {
|
||||
const data = await this.prepareOrder(shipId, context);
|
||||
console.log('mock eOrder to wechatMpShip, data:', data);
|
||||
|
|
@ -302,7 +336,7 @@ export default class WechatMpShipDebug {
|
|||
syncPaths(shipId, context) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getPrintInfo(shipId) {
|
||||
getPrintInfo(shipId, context) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,4 +66,15 @@ export default class WechatMpShip extends DebugClazz {
|
|||
}));
|
||||
return paths;
|
||||
}
|
||||
async getPrintInfo(shipId, context) {
|
||||
const instance = await this.getInstance(context);
|
||||
const data = await this.prepareGetOrder(shipId, context);
|
||||
const result = await instance.getExpressOrder(data);
|
||||
const base64Html = result.print_html;
|
||||
// const html = Buffer.from(base64Html, 'base64').toString('utf8');
|
||||
return {
|
||||
type: 'html',
|
||||
data: base64Html,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ export default interface ShipClazz<ED extends EntityDict & BaseEntityDict, Conte
|
|||
cancelOrder(shipId: string, context: Context): Promise<void>;
|
||||
syncState(shipId: string, context: Context): Promise<EntityDict['ship']['OpSchema']['iState']>;
|
||||
syncPaths(shipId: string, context: Context): Promise<EntityDict['ship']['OpSchema']['extraPaths']>;
|
||||
getPrintInfo(shipId: string): Promise<{
|
||||
getPrintInfo(shipId: string, context: Context): Promise<{
|
||||
type: 'html';
|
||||
data: string;
|
||||
}>;
|
||||
|
|
|
|||
|
|
@ -7,4 +7,8 @@ export default class WechatMpShip<ED extends EntityDict & BaseEntityDict, Contex
|
|||
cancelOrder(shipId: string, context: Context): Promise<void>;
|
||||
syncState(shipId: string, context: Context): Promise<EntityDict['ship']['OpSchema']['iState']>;
|
||||
syncPaths(shipId: string, context: Context): Promise<EntityDict['ship']['OpSchema']['extraPaths']>;
|
||||
getPrintInfo(shipId: string, context: Context): Promise<{
|
||||
type: 'html';
|
||||
data: string;
|
||||
}>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,11 +43,17 @@ export default class WechatMpShipDebug<ED extends EntityDict & BaseEntityDict, C
|
|||
delivery_id: string;
|
||||
waybill_id: NonNullable<ED["ship"]["Schema"]["extraShipId"]>;
|
||||
}>;
|
||||
protected prepareGetOrder(shipId: string, context: Context): Promise<{
|
||||
order_id: string;
|
||||
openid: string | undefined;
|
||||
delivery_id: string;
|
||||
waybill_id: NonNullable<ED["ship"]["Schema"]["extraShipId"]>;
|
||||
}>;
|
||||
eOrder(shipId: string, context: Context): Promise<string>;
|
||||
cancelOrder(shipId: string, context: Context): Promise<void>;
|
||||
syncState(shipId: string, context: Context): Promise<EntityDict["ship"]["OpSchema"]["iState"]>;
|
||||
syncPaths(shipId: string, context: Context): Promise<EntityDict["ship"]["OpSchema"]["extraPaths"]>;
|
||||
getPrintInfo(shipId: string): Promise<{
|
||||
getPrintInfo(shipId: string, context: Context): Promise<{
|
||||
type: "html";
|
||||
data: string;
|
||||
}>;
|
||||
|
|
|
|||
|
|
@ -290,6 +290,40 @@ class WechatMpShipDebug {
|
|||
waybill_id: extraShipId,
|
||||
};
|
||||
}
|
||||
async prepareGetOrder(shipId, context) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: {
|
||||
id: 1,
|
||||
extraShipId: 1,
|
||||
shipService: {
|
||||
shipCompanyId: 1,
|
||||
},
|
||||
shipOrder$ship: {
|
||||
$entity: 'shipOrder',
|
||||
data: {
|
||||
orderId: 1,
|
||||
order: {}
|
||||
},
|
||||
},
|
||||
wechatMpShip: {
|
||||
applicationId: 1,
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id: shipId,
|
||||
}
|
||||
}, { dontCollect: true });
|
||||
(0, assert_1.default)(ship);
|
||||
const { extraShipId, shipService, shipOrder$ship: shipOrders, wechatMpShip } = ship;
|
||||
const orderIds = shipOrders.map(ele => ele.orderId);
|
||||
const { openId } = await this.getReceiverInfo(orderIds, wechatMpShip.applicationId, context);
|
||||
return {
|
||||
order_id: shipId,
|
||||
openid: openId,
|
||||
delivery_id: shipService.shipCompanyId,
|
||||
waybill_id: extraShipId,
|
||||
};
|
||||
}
|
||||
async eOrder(shipId, context) {
|
||||
const data = await this.prepareOrder(shipId, context);
|
||||
console.log('mock eOrder to wechatMpShip, data:', data);
|
||||
|
|
@ -305,7 +339,7 @@ class WechatMpShipDebug {
|
|||
syncPaths(shipId, context) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getPrintInfo(shipId) {
|
||||
getPrintInfo(shipId, context) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,5 +69,16 @@ class WechatMpShip extends WechatMpShip_debug_1.default {
|
|||
}));
|
||||
return paths;
|
||||
}
|
||||
async getPrintInfo(shipId, context) {
|
||||
const instance = await this.getInstance(context);
|
||||
const data = await this.prepareGetOrder(shipId, context);
|
||||
const result = await instance.getExpressOrder(data);
|
||||
const base64Html = result.print_html;
|
||||
// const html = Buffer.from(base64Html, 'base64').toString('utf8');
|
||||
return {
|
||||
type: 'html',
|
||||
data: base64Html,
|
||||
};
|
||||
}
|
||||
}
|
||||
exports.default = WechatMpShip;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ export default interface ShipClazz<ED extends EntityDict & BaseEntityDict, Conte
|
|||
syncPaths(shipId: string, context: Context): Promise<EntityDict['ship']['OpSchema']['extraPaths']>;
|
||||
|
||||
// 返回打印数据
|
||||
getPrintInfo(shipId: string): Promise<{
|
||||
getPrintInfo(shipId: string, context: Context): Promise<{
|
||||
type: 'html';
|
||||
data: string;
|
||||
}>
|
||||
|
|
|
|||
|
|
@ -338,6 +338,45 @@ export default class WechatMpShipDebug<ED extends EntityDict & BaseEntityDict, C
|
|||
};
|
||||
}
|
||||
|
||||
protected async prepareGetOrder(shipId: string, context: Context) {
|
||||
const [ship] = await context.select('ship', {
|
||||
data: {
|
||||
id: 1,
|
||||
extraShipId: 1,
|
||||
shipService: {
|
||||
shipCompanyId: 1,
|
||||
},
|
||||
shipOrder$ship: {
|
||||
$entity: 'shipOrder',
|
||||
data: {
|
||||
orderId: 1,
|
||||
order:{
|
||||
|
||||
}
|
||||
},
|
||||
},
|
||||
wechatMpShip: {
|
||||
applicationId: 1,
|
||||
},
|
||||
},
|
||||
filter: {
|
||||
id: shipId,
|
||||
}
|
||||
}, { dontCollect: true });
|
||||
|
||||
assert(ship);
|
||||
const { extraShipId, shipService, shipOrder$ship: shipOrders, wechatMpShip } = ship;
|
||||
const orderIds = shipOrders!.map(ele => ele.orderId);
|
||||
const { openId } = await this.getReceiverInfo(orderIds, wechatMpShip!.applicationId!, context);
|
||||
|
||||
return {
|
||||
order_id: shipId,
|
||||
openid: openId,
|
||||
delivery_id: shipService!.shipCompanyId!,
|
||||
waybill_id: extraShipId!,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
async eOrder(shipId: string, context: Context): Promise<string> {
|
||||
const data = await this.prepareOrder(shipId, context);
|
||||
|
|
@ -357,7 +396,7 @@ export default class WechatMpShipDebug<ED extends EntityDict & BaseEntityDict, C
|
|||
syncPaths(shipId: string, context: Context): Promise<EntityDict["ship"]["OpSchema"]["extraPaths"]> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
getPrintInfo(shipId: string): Promise<{ type: "html"; data: string; }> {
|
||||
getPrintInfo(shipId: string, context: Context): Promise<{ type: "html"; data: string; }> {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
};
|
||||
|
|
@ -77,4 +77,16 @@ export default class WechatMpShip<ED extends EntityDict & BaseEntityDict, Contex
|
|||
return paths;
|
||||
}
|
||||
|
||||
async getPrintInfo(shipId: string, context: Context): Promise<{ type: 'html'; data: string; }> {
|
||||
const instance = await this.getInstance(context);
|
||||
const data = await this.prepareGetOrder(shipId, context);
|
||||
const result = await instance.getExpressOrder(data);
|
||||
const base64Html = result.print_html;
|
||||
// const html = Buffer.from(base64Html, 'base64').toString('utf8');
|
||||
return {
|
||||
type: 'html',
|
||||
data: base64Html,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue