diff --git a/es/types/ShipClazz.d.ts b/es/types/ShipClazz.d.ts index a3089363..2d4eefda 100644 --- a/es/types/ShipClazz.d.ts +++ b/es/types/ShipClazz.d.ts @@ -1,9 +1,10 @@ import { EntityDict } from '../oak-app-domain'; -import { BRC } from '../types/RuntimeCxt'; -export default interface ShipClazz { - available(shipServiceId: string, orderIds: string[], context: BRC): Promise; - eOrder(shipId: string, context: BRC): Promise; - cancelOrder(shipId: string, context: BRC): Promise; +import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; +import BackendRuntimeContext from '../context/BackendRuntimeContext'; +export default interface ShipClazz> { + available(shipServiceId: string, orderIds: string[], context: Context): Promise; + eOrder(shipId: string, context: Context): Promise; + cancelOrder(shipId: string, context: Context): Promise; syncState(shipId: string): Promise; syncPaths(shipId: string): Promise; getPrintInfo(shipId: string): Promise<{ diff --git a/es/utils/shipClazz/WechatMpShip/WechatMpShip.d.ts b/es/utils/shipClazz/WechatMpShip/WechatMpShip.d.ts index 80e2a379..1bfb4f84 100644 --- a/es/utils/shipClazz/WechatMpShip/WechatMpShip.d.ts +++ b/es/utils/shipClazz/WechatMpShip/WechatMpShip.d.ts @@ -1,6 +1,8 @@ -import { BRC } from "../../../types/RuntimeCxt"; +import { EntityDict } from '../../../oak-app-domain'; +import BackendRuntimeContext from '../../../context/BackendRuntimeContext'; +import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; import DebugClazz from './WechatMpShip.debug'; -export default class WechatMpShip extends DebugClazz { - eOrder(shipId: string, context: BRC): Promise; - cancelOrder(shipId: string, context: BRC): Promise; +export default class WechatMpShip> extends DebugClazz { + eOrder(shipId: string, context: Context): Promise; + cancelOrder(shipId: string, context: Context): Promise; } diff --git a/es/utils/shipClazz/WechatMpShip/WechatMpShip.debug.d.ts b/es/utils/shipClazz/WechatMpShip/WechatMpShip.debug.d.ts index 35a95bef..3318b41b 100644 --- a/es/utils/shipClazz/WechatMpShip/WechatMpShip.debug.d.ts +++ b/es/utils/shipClazz/WechatMpShip/WechatMpShip.debug.d.ts @@ -1,30 +1,31 @@ import { EntityDict } from "../../../oak-app-domain"; -import { BRC } from "../../../types/RuntimeCxt"; +import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; +import BackendRuntimeContext from '../../../context/BackendRuntimeContext'; import ShipClazz from "../../../types/ShipClazz"; import { WechatMpInstance } from "oak-external-sdk"; import { AddExpressOrderData } from 'oak-external-sdk/lib/types/Wechat'; type ExtraAddExpressOrderData = Omit; -export default class WechatMpShipDebug implements ShipClazz { +export default class WechatMpShipDebug> implements ShipClazz { private wechatMpShipId; private wechatMpShip?; private getReceiverInfo; private getExtraData; - constructor(wechatMpShipId: string, getReceiverInfo: (orderIds: string[], applicationId: string, context: BRC) => Promise<{ + constructor(wechatMpShipId: string, getReceiverInfo: (orderIds: string[], applicationId: string, context: Context) => Promise<{ openId?: string; appWxId?: string; - }>, getExtraData: (shipId: string, context: BRC) => Promise); + }>, getExtraData: (shipId: string, context: Context) => Promise); private getWechatMpShip; - available(shipServiceId: string, orderIds: string[], context: BRC): Promise; - protected getInstance(context: BRC): Promise; - protected prepareOrder(shipId: string, context: BRC): Promise; - protected prepareCancelOrder(shipId: string, context: BRC): Promise<{ + available(shipServiceId: string, orderIds: string[], context: Context): Promise; + protected getInstance(context: Context): Promise; + protected prepareOrder(shipId: string, context: Context): Promise; + protected prepareCancelOrder(shipId: string, context: Context): Promise<{ openid: string | undefined; delivery_id: string; - waybill_id: string; + waybill_id: NonNullable; order_id: string; }>; - eOrder(shipId: string, context: BRC): Promise; - cancelOrder(shipId: string, context: BRC): Promise; + eOrder(shipId: string, context: Context): Promise; + cancelOrder(shipId: string, context: Context): Promise; syncState(shipId: string): Promise; syncPaths(extraShipId: string): Promise; getPrintInfo(shipId: string): Promise<{ diff --git a/es/utils/shipClazz/index.d.ts b/es/utils/shipClazz/index.d.ts index e6f4cbe9..abcb287a 100644 --- a/es/utils/shipClazz/index.d.ts +++ b/es/utils/shipClazz/index.d.ts @@ -3,9 +3,10 @@ import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; import ShipClazz from '../../types/ShipClazz'; import { BRC } from '../../types/RuntimeCxt'; import { StorageSchema } from 'oak-domain/lib/types/Storage'; -type ShipClazzConstructor = (entityId: string, context: BRC) => Promise; -export declare function registerShipClazzEntity(entity: T, clazzConstructor: ShipClazzConstructor, schema: StorageSchema): void; -export declare function getShipClazz(entity: NonNullable, entityId: NonNullable, context: BRC): Promise; +import BackendRuntimeContext from '../../context/BackendRuntimeContext'; +type ShipClazzConstructor> = (entityId: string, context: Context) => Promise>; +export declare function registerShipClazzEntity>(entity: T, clazzConstructor: ShipClazzConstructor, schema: StorageSchema): void; +export declare function getShipClazz(entity: NonNullable, entityId: NonNullable, context: BRC): Promise>; /** * 创建ship时,根据系统物流的配置去对接对应的物流系统 * @param shipId diff --git a/lib/types/ShipClazz.d.ts b/lib/types/ShipClazz.d.ts index a3089363..2d4eefda 100644 --- a/lib/types/ShipClazz.d.ts +++ b/lib/types/ShipClazz.d.ts @@ -1,9 +1,10 @@ import { EntityDict } from '../oak-app-domain'; -import { BRC } from '../types/RuntimeCxt'; -export default interface ShipClazz { - available(shipServiceId: string, orderIds: string[], context: BRC): Promise; - eOrder(shipId: string, context: BRC): Promise; - cancelOrder(shipId: string, context: BRC): Promise; +import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; +import BackendRuntimeContext from '../context/BackendRuntimeContext'; +export default interface ShipClazz> { + available(shipServiceId: string, orderIds: string[], context: Context): Promise; + eOrder(shipId: string, context: Context): Promise; + cancelOrder(shipId: string, context: Context): Promise; syncState(shipId: string): Promise; syncPaths(shipId: string): Promise; getPrintInfo(shipId: string): Promise<{ diff --git a/lib/utils/shipClazz/WechatMpShip/WechatMpShip.d.ts b/lib/utils/shipClazz/WechatMpShip/WechatMpShip.d.ts index 80e2a379..1bfb4f84 100644 --- a/lib/utils/shipClazz/WechatMpShip/WechatMpShip.d.ts +++ b/lib/utils/shipClazz/WechatMpShip/WechatMpShip.d.ts @@ -1,6 +1,8 @@ -import { BRC } from "../../../types/RuntimeCxt"; +import { EntityDict } from '../../../oak-app-domain'; +import BackendRuntimeContext from '../../../context/BackendRuntimeContext'; +import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; import DebugClazz from './WechatMpShip.debug'; -export default class WechatMpShip extends DebugClazz { - eOrder(shipId: string, context: BRC): Promise; - cancelOrder(shipId: string, context: BRC): Promise; +export default class WechatMpShip> extends DebugClazz { + eOrder(shipId: string, context: Context): Promise; + cancelOrder(shipId: string, context: Context): Promise; } diff --git a/lib/utils/shipClazz/WechatMpShip/WechatMpShip.debug.d.ts b/lib/utils/shipClazz/WechatMpShip/WechatMpShip.debug.d.ts index 35a95bef..3318b41b 100644 --- a/lib/utils/shipClazz/WechatMpShip/WechatMpShip.debug.d.ts +++ b/lib/utils/shipClazz/WechatMpShip/WechatMpShip.debug.d.ts @@ -1,30 +1,31 @@ import { EntityDict } from "../../../oak-app-domain"; -import { BRC } from "../../../types/RuntimeCxt"; +import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; +import BackendRuntimeContext from '../../../context/BackendRuntimeContext'; import ShipClazz from "../../../types/ShipClazz"; import { WechatMpInstance } from "oak-external-sdk"; import { AddExpressOrderData } from 'oak-external-sdk/lib/types/Wechat'; type ExtraAddExpressOrderData = Omit; -export default class WechatMpShipDebug implements ShipClazz { +export default class WechatMpShipDebug> implements ShipClazz { private wechatMpShipId; private wechatMpShip?; private getReceiverInfo; private getExtraData; - constructor(wechatMpShipId: string, getReceiverInfo: (orderIds: string[], applicationId: string, context: BRC) => Promise<{ + constructor(wechatMpShipId: string, getReceiverInfo: (orderIds: string[], applicationId: string, context: Context) => Promise<{ openId?: string; appWxId?: string; - }>, getExtraData: (shipId: string, context: BRC) => Promise); + }>, getExtraData: (shipId: string, context: Context) => Promise); private getWechatMpShip; - available(shipServiceId: string, orderIds: string[], context: BRC): Promise; - protected getInstance(context: BRC): Promise; - protected prepareOrder(shipId: string, context: BRC): Promise; - protected prepareCancelOrder(shipId: string, context: BRC): Promise<{ + available(shipServiceId: string, orderIds: string[], context: Context): Promise; + protected getInstance(context: Context): Promise; + protected prepareOrder(shipId: string, context: Context): Promise; + protected prepareCancelOrder(shipId: string, context: Context): Promise<{ openid: string | undefined; delivery_id: string; - waybill_id: string; + waybill_id: NonNullable; order_id: string; }>; - eOrder(shipId: string, context: BRC): Promise; - cancelOrder(shipId: string, context: BRC): Promise; + eOrder(shipId: string, context: Context): Promise; + cancelOrder(shipId: string, context: Context): Promise; syncState(shipId: string): Promise; syncPaths(extraShipId: string): Promise; getPrintInfo(shipId: string): Promise<{ diff --git a/lib/utils/shipClazz/index.d.ts b/lib/utils/shipClazz/index.d.ts index e6f4cbe9..abcb287a 100644 --- a/lib/utils/shipClazz/index.d.ts +++ b/lib/utils/shipClazz/index.d.ts @@ -3,9 +3,10 @@ import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; import ShipClazz from '../../types/ShipClazz'; import { BRC } from '../../types/RuntimeCxt'; import { StorageSchema } from 'oak-domain/lib/types/Storage'; -type ShipClazzConstructor = (entityId: string, context: BRC) => Promise; -export declare function registerShipClazzEntity(entity: T, clazzConstructor: ShipClazzConstructor, schema: StorageSchema): void; -export declare function getShipClazz(entity: NonNullable, entityId: NonNullable, context: BRC): Promise; +import BackendRuntimeContext from '../../context/BackendRuntimeContext'; +type ShipClazzConstructor> = (entityId: string, context: Context) => Promise>; +export declare function registerShipClazzEntity>(entity: T, clazzConstructor: ShipClazzConstructor, schema: StorageSchema): void; +export declare function getShipClazz(entity: NonNullable, entityId: NonNullable, context: BRC): Promise>; /** * 创建ship时,根据系统物流的配置去对接对应的物流系统 * @param shipId diff --git a/src/types/ShipClazz.ts b/src/types/ShipClazz.ts index efc8ab38..3b141627 100644 --- a/src/types/ShipClazz.ts +++ b/src/types/ShipClazz.ts @@ -1,15 +1,16 @@ import { EntityDict } from '../oak-app-domain'; -import { BRC } from '../types/RuntimeCxt'; +import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; +import BackendRuntimeContext from '../context/BackendRuntimeContext'; -export default interface ShipClazz { +export default interface ShipClazz> { // 是否可以使用这个接口下单 - available(shipServiceId: string, orderIds: string[], context: BRC): Promise; + available(shipServiceId: string, orderIds: string[], context: Context): Promise; // 下单 - eOrder(shipId: string, context: BRC): Promise; + eOrder(shipId: string, context: Context): Promise; // 取消 - cancelOrder(shipId: string, context: BRC): Promise; + cancelOrder(shipId: string, context: Context): Promise; // 同步状态 syncState(shipId: string): Promise; diff --git a/src/utils/shipClazz/WechatMpShip/WechatMpShip.debug.ts b/src/utils/shipClazz/WechatMpShip/WechatMpShip.debug.ts index 3cd8e261..4a2a255a 100644 --- a/src/utils/shipClazz/WechatMpShip/WechatMpShip.debug.ts +++ b/src/utils/shipClazz/WechatMpShip/WechatMpShip.debug.ts @@ -1,8 +1,8 @@ -import { EntityDict } from "@project/oak-app-domain"; -import { BRC } from "@project/types/RuntimeCxt"; -import ShipClazz from "@project/types/ShipClazz"; +import { EntityDict } from "../../../oak-app-domain"; +import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; +import BackendRuntimeContext from '../../../context/BackendRuntimeContext'; +import ShipClazz from "../../../types/ShipClazz"; import assert from "assert"; -import { WechatMpConfig } from "oak-general-business/lib/entities/Application"; import WechatSDK from 'oak-external-sdk/lib/WechatSDK'; import { WechatMpInstance } from "oak-external-sdk"; import { AddExpressOrderData } from 'oak-external-sdk/lib/types/Wechat'; @@ -26,29 +26,29 @@ const ShipServiceCodeDict = { 'sto-bzkd': 1, } -export default class WechatMpShipDebug implements ShipClazz { +export default class WechatMpShipDebug> implements ShipClazz { private wechatMpShipId: string; private wechatMpShip?: EntityDict['wechatMpShip']['Schema']; - private getReceiverInfo: (orderIds: string[], applicationId: string, context: BRC) => Promise<{ + private getReceiverInfo: (orderIds: string[], applicationId: string, context: Context) => Promise<{ openId?: string; appWxId?: string; }>; - private getExtraData: (shipId: string, context: BRC) => Promise; + private getExtraData: (shipId: string, context: Context) => Promise; constructor( wechatMpShipId: string, - getReceiverInfo: (orderIds: string[], applicationId: string, context: BRC) => Promise<{ + getReceiverInfo: (orderIds: string[], applicationId: string, context: Context) => Promise<{ openId?: string; appWxId?: string; // todo }>, - getExtraData: (shipId: string, context: BRC) => Promise + getExtraData: (shipId: string, context: Context) => Promise ) { this.wechatMpShipId = wechatMpShipId; this.getReceiverInfo = getReceiverInfo; this.getExtraData = getExtraData; } - private async getWechatMpShip(context: BRC) { + private async getWechatMpShip(context: Context) { if (this.wechatMpShip) { return this.wechatMpShip; } @@ -70,7 +70,7 @@ export default class WechatMpShipDebug implements ShipClazz { return this.wechatMpShip!; } - async available(shipServiceId: string, orderIds: string[], context: BRC): Promise { + async available(shipServiceId: string, orderIds: string[], context: Context): Promise { if (!ShipServiceCodeDict.hasOwnProperty(shipServiceId!)) { return false; } @@ -84,7 +84,7 @@ export default class WechatMpShipDebug implements ShipClazz { return true; } - protected async getInstance(context: BRC) { + protected async getInstance(context: Context) { const wechatMpShip = await this.getWechatMpShip(context); const { config } = wechatMpShip!.application!; assert(config.type === 'wechatMp'); @@ -95,7 +95,7 @@ export default class WechatMpShipDebug implements ShipClazz { } - protected async prepareOrder(shipId: string, context: BRC): Promise { + protected async prepareOrder(shipId: string, context: Context): Promise { const [ship] = await context.select('ship', { data: { id: 1, @@ -207,7 +207,7 @@ export default class WechatMpShipDebug implements ShipClazz { return data; } - protected async prepareCancelOrder(shipId: string, context: BRC) { + protected async prepareCancelOrder(shipId: string, context: Context) { const [ship] = await context.select('ship', { data: { id: 1, @@ -244,14 +244,14 @@ export default class WechatMpShipDebug implements ShipClazz { } - async eOrder(shipId: string, context: BRC): Promise { + async eOrder(shipId: string, context: Context): Promise { const data = await this.prepareOrder(shipId, context); console.log('mock eOrder to wechatMpShip, data:', data); return 'mockExtraShipId'; } - async cancelOrder(shipId: string, context: BRC): Promise { + async cancelOrder(shipId: string, context: Context): Promise { const data = await this.prepareCancelOrder(shipId, context); console.log('mock cancelOrder to wechatMpShip, data:', data); } diff --git a/src/utils/shipClazz/WechatMpShip/WechatMpShip.ts b/src/utils/shipClazz/WechatMpShip/WechatMpShip.ts index 97e13742..e861d442 100644 --- a/src/utils/shipClazz/WechatMpShip/WechatMpShip.ts +++ b/src/utils/shipClazz/WechatMpShip/WechatMpShip.ts @@ -1,16 +1,19 @@ +import { EntityDict } from '../../../oak-app-domain'; +import BackendRuntimeContext from '../../../context/BackendRuntimeContext'; +import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; import { BRC } from "@project/types/RuntimeCxt"; import DebugClazz from './WechatMpShip.debug'; import { assert } from "console"; -export default class WechatMpShip extends DebugClazz { - async eOrder(shipId: string, context: BRC): Promise { +export default class WechatMpShip> extends DebugClazz { + async eOrder(shipId: string, context: Context): Promise { const data = await this.prepareOrder(shipId, context); const instance = await this.getInstance(context); const result = await instance.addExpressOrder(data); return result.waybill_id; } - async cancelOrder(shipId: string, context: BRC): Promise { + async cancelOrder(shipId: string, context: Context): Promise { const instance = await this.getInstance(context); const data = await this.prepareCancelOrder(shipId, context); await instance.cancelExpressOrder(data); diff --git a/src/utils/shipClazz/index.ts b/src/utils/shipClazz/index.ts index da353e54..fc1691ac 100644 --- a/src/utils/shipClazz/index.ts +++ b/src/utils/shipClazz/index.ts @@ -4,15 +4,16 @@ import ShipClazz from '../../types/ShipClazz'; import { BRC } from '../../types/RuntimeCxt'; import assert from 'assert'; import { StorageSchema } from 'oak-domain/lib/types/Storage'; +import BackendRuntimeContext from '../../context/BackendRuntimeContext'; let MODULE_USED = false; -type ShipClazzConstructor = (entityId: string, context: BRC) => Promise; -const ShipClazzDict: Record = {}; -const ShipClazzEntityDict: Record = {}; +type ShipClazzConstructor> = (entityId: string, context: Context) => Promise>; +const ShipClazzDict: Record> = {}; +const ShipClazzEntityDict: Record> = {}; -export function registerShipClazzEntity( +export function registerShipClazzEntity>( entity: T, - clazzConstructor: ShipClazzConstructor, + clazzConstructor: ShipClazzConstructor, schema: StorageSchema ) { assert(!MODULE_USED);