关于message的数据结构改动与部分代码实现

This commit is contained in:
Xu Chang 2023-02-09 19:57:32 +08:00
parent e791c2f7c2
commit 781cfae13a
33 changed files with 828 additions and 503 deletions

View File

@ -1,17 +1,23 @@
import { String, Text } from 'oak-domain/lib/types/DataType';
import { Schema as User } from './User';
import { Schema as System } from './System';
import { EntityShape } from 'oak-domain/lib/types/Entity';
import { Channel, Weight } from '../types/Message';
declare type MessageParams = {
pathname: string;
props?: Record<string, any>;
state?: Record<string, any>;
};
declare type MessageRestriction = {
systemIds?: string[];
channels?: Array<Channel>;
};
export interface Schema extends EntityShape {
entity: String<32>;
entityId: String<64>;
user: User;
system: System;
type: String<64>;
weight: 'high' | 'medium' | 'low' | 'data';
weight: Weight;
restriction?: MessageRestriction;
title: String<256>;
content: Text;
props: Object;

View File

@ -6,7 +6,6 @@ var IActionDef = {
succeed: ['sending', 'success'],
fail: ['sending', 'failure'],
},
is: 'sending',
};
var VisitActionDef = {
stm: {
@ -17,10 +16,12 @@ var VisitActionDef = {
var locale = {
zh_CN: {
attr: {
entity: '关联对象',
entityId: '关联对象ID',
restriction: '限制',
title: '标题',
content: '内容',
user: '关联用户',
system: '系统',
type: '消息类型',
weight: '优先级',
iState: '发送状态',
@ -48,7 +49,6 @@ var locale = {
high: '高',
medium: '中',
low: '低',
data: '数据',
},
},
},

View File

@ -1,9 +1,12 @@
import { Schema as Message } from './Message';
import { EntityShape } from 'oak-domain/lib/types/Entity';
import { Channel } from '../types/Message';
import { Schema as Application } from './Application';
import { Schema as MessageSystem } from './MessageSystem';
export interface Schema extends EntityShape {
channel: 'wechat' | 'jPush' | 'jim' | 'mp' | 'sms';
channel: Channel;
application?: Application;
data: Object;
message: Message;
messageSystem: MessageSystem;
data1: Object;
data2: Object;
}

View File

@ -13,10 +13,11 @@ var locale = {
attr: {
channel: '消息渠道',
data: '消息数据',
message: '消息',
messageSystem: '消息系统连接',
data1: '数据1',
data2: '数据2',
iState: '状态',
application: '关联应用',
},
action: {
succeed: '成功',
@ -29,7 +30,7 @@ var locale = {
failure: '发送失败',
},
channel: {
wechat: '公众号',
wechatPublic: '公众号',
jPush: '极光推送',
jim: '极光消息',
mp: '小程序',

7
lib/entities/MessageSystem.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import { Schema as Message } from './Message';
import { EntityShape } from 'oak-domain/lib/types/Entity';
import { Schema as System } from './System';
export interface Schema extends EntityShape {
message: Message;
system: System;
}

View File

@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
;
var locale = {
zh_CN: {
attr: {
message: '消息',
system: '系统',
},
},
};

View File

@ -6,6 +6,7 @@ import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOper
import { GenericAction } from "oak-domain/lib/actions/action";
import { Style } from "../../types/Style";
import * as System from "../System/Schema";
import * as MessageSent from "../MessageSent/Schema";
import * as Token from "../Token/Schema";
import * as WechatPublicTag from "../WechatPublicTag/Schema";
import * as WechatQrCode from "../WechatQrCode/Schema";
@ -59,6 +60,8 @@ export declare type Schema = EntityShape & {
config: WebConfig | WechatMpConfig | WechatPublicConfig;
style?: Style | null;
system: System.Schema;
messageSent$application?: Array<MessageSent.Schema>;
messageSent$application$$aggr?: AggregationResult<MessageSent.Schema>;
token$application?: Array<Token.Schema>;
token$application$$aggr?: AggregationResult<Token.Schema>;
wechatPublicTag$application?: Array<WechatPublicTag.Schema>;
@ -97,6 +100,12 @@ export declare type Projection = {
system?: System.Projection;
config?: number;
style?: number;
messageSent$application?: MessageSent.Selection & {
$entity: "messageSent";
};
messageSent$application$$aggr?: MessageSent.Aggregation & {
$entity: "messageSent";
};
token$application?: Token.Selection & {
$entity: "token";
};
@ -168,6 +177,7 @@ export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "systemI
} | {
systemId: String<64>;
})) & {
messageSent$application?: OakOperation<MessageSent.UpdateOperation["action"], Omit<MessageSent.UpdateOperationData, "application" | "applicationId">, MessageSent.Filter> | OakOperation<"create", Omit<MessageSent.CreateOperationData, "application" | "applicationId">[]> | Array<OakOperation<"create", Omit<MessageSent.CreateOperationData, "application" | "applicationId">> | OakOperation<MessageSent.UpdateOperation["action"], Omit<MessageSent.UpdateOperationData, "application" | "applicationId">, MessageSent.Filter>>;
token$application?: OakOperation<Token.UpdateOperation["action"], Omit<Token.UpdateOperationData, "application" | "applicationId">, Token.Filter> | OakOperation<"create", Omit<Token.CreateOperationData, "application" | "applicationId">[]> | Array<OakOperation<"create", Omit<Token.CreateOperationData, "application" | "applicationId">> | OakOperation<Token.UpdateOperation["action"], Omit<Token.UpdateOperationData, "application" | "applicationId">, Token.Filter>>;
wechatPublicTag$application?: OakOperation<WechatPublicTag.UpdateOperation["action"], Omit<WechatPublicTag.UpdateOperationData, "application" | "applicationId">, WechatPublicTag.Filter> | OakOperation<"create", Omit<WechatPublicTag.CreateOperationData, "application" | "applicationId">[]> | Array<OakOperation<"create", Omit<WechatPublicTag.CreateOperationData, "application" | "applicationId">> | OakOperation<WechatPublicTag.UpdateOperation["action"], Omit<WechatPublicTag.UpdateOperationData, "application" | "applicationId">, WechatPublicTag.Filter>>;
wechatQrCode$application?: OakOperation<WechatQrCode.UpdateOperation["action"], Omit<WechatQrCode.UpdateOperationData, "application" | "applicationId">, WechatQrCode.Filter> | OakOperation<"create", Omit<WechatQrCode.CreateOperationData, "application" | "applicationId">[]> | Array<OakOperation<"create", Omit<WechatQrCode.CreateOperationData, "application" | "applicationId">> | OakOperation<WechatQrCode.UpdateOperation["action"], Omit<WechatQrCode.UpdateOperationData, "application" | "applicationId">, WechatQrCode.Filter>>;
@ -190,6 +200,7 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "systemI
systemId?: String<64> | null;
})) & {
[k: string]: any;
messageSent$application?: MessageSent.UpdateOperation | MessageSent.RemoveOperation | OakOperation<"create", Omit<MessageSent.CreateOperationData, "application" | "applicationId">[]> | Array<OakOperation<"create", Omit<MessageSent.CreateOperationData, "application" | "applicationId">> | MessageSent.UpdateOperation | MessageSent.RemoveOperation>;
token$application?: Token.UpdateOperation | Token.RemoveOperation | OakOperation<"create", Omit<Token.CreateOperationData, "application" | "applicationId">[]> | Array<OakOperation<"create", Omit<Token.CreateOperationData, "application" | "applicationId">> | Token.UpdateOperation | Token.RemoveOperation>;
wechatPublicTag$application?: WechatPublicTag.UpdateOperation | WechatPublicTag.RemoveOperation | OakOperation<"create", Omit<WechatPublicTag.CreateOperationData, "application" | "applicationId">[]> | Array<OakOperation<"create", Omit<WechatPublicTag.CreateOperationData, "application" | "applicationId">> | WechatPublicTag.UpdateOperation | WechatPublicTag.RemoveOperation>;
wechatQrCode$application?: WechatQrCode.UpdateOperation | WechatQrCode.RemoveOperation | OakOperation<"create", Omit<WechatQrCode.CreateOperationData, "application" | "applicationId">[]> | Array<OakOperation<"create", Omit<WechatQrCode.CreateOperationData, "application" | "applicationId">> | WechatQrCode.UpdateOperation | WechatQrCode.RemoveOperation>;

View File

@ -15,6 +15,7 @@ import { EntityDef as ExtraFile } from "./ExtraFile/Schema";
import { EntityDef as Livestream } from "./Livestream/Schema";
import { EntityDef as Message } from "./Message/Schema";
import { EntityDef as MessageSent } from "./MessageSent/Schema";
import { EntityDef as MessageSystem } from "./MessageSystem/Schema";
import { EntityDef as Mobile } from "./Mobile/Schema";
import { EntityDef as Platform } from "./Platform/Schema";
import { EntityDef as UserRole } from "./UserRole/Schema";
@ -45,6 +46,7 @@ export declare type EntityDict = {
livestream: Livestream;
message: Message;
messageSent: MessageSent;
messageSystem: MessageSystem;
mobile: Mobile;
platform: Platform;
userRole: UserRole;

View File

@ -6,8 +6,7 @@ var IActionDef = {
stm: {
succeed: ['sending', 'success'],
fail: ['sending', 'failure']
},
is: 'sending'
}
};
var VisitActionDef = {
stm: {

View File

@ -4,19 +4,25 @@ import { OneOf } from "oak-domain/lib/types/Polyfill";
import * as SubQuery from "../_SubQuery";
import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, EntityShape, AggregationResult } from "oak-domain/lib/types/Entity";
import { Action, ParticularAction, IState, VisitState } from "./Action";
import { Channel, Weight } from "../../types/Message";
import * as User from "../User/Schema";
import * as System from "../System/Schema";
import * as MessageSent from "../MessageSent/Schema";
import * as MessageSystem from "../MessageSystem/Schema";
declare type MessageParams = {
pathname: string;
props?: Record<string, any>;
state?: Record<string, any>;
};
declare type MessageRestriction = {
systemIds?: string[];
channels?: Array<Channel>;
};
export declare type OpSchema = EntityShape & {
entity: String<32>;
entityId: String<64>;
userId: ForeignKey<"user">;
systemId: ForeignKey<"system">;
type: String<64>;
weight: 'high' | 'medium' | 'low' | 'data';
weight: Weight;
restriction?: MessageRestriction | null;
title: String<256>;
content: Text;
props: Object;
@ -27,10 +33,12 @@ export declare type OpSchema = EntityShape & {
};
export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & {
entity: String<32>;
entityId: String<64>;
userId: ForeignKey<"user">;
systemId: ForeignKey<"system">;
type: String<64>;
weight: 'high' | 'medium' | 'low' | 'data';
weight: Weight;
restriction?: MessageRestriction | null;
title: String<256>;
content: Text;
props: Object;
@ -39,9 +47,8 @@ export declare type Schema = EntityShape & {
iState?: IState | null;
visitState?: VisitState | null;
user: User.Schema;
system: System.Schema;
messageSent$message?: Array<MessageSent.Schema>;
messageSent$message$$aggr?: AggregationResult<MessageSent.Schema>;
messageSystem$message?: Array<MessageSystem.Schema>;
messageSystem$message$$aggr?: AggregationResult<MessageSystem.Schema>;
} & {
[A in ExpressionKey]?: any;
};
@ -50,12 +57,13 @@ declare type AttrFilter = {
$$createAt$$: Q_DateValue;
$$seq$$: Q_StringValue;
$$updateAt$$: Q_DateValue;
entity: Q_StringValue;
entityId: Q_StringValue;
userId: Q_StringValue | SubQuery.UserIdSubQuery;
user: User.Filter;
systemId: Q_StringValue | SubQuery.SystemIdSubQuery;
system: System.Filter;
type: Q_StringValue;
weight: Q_EnumValue<'high' | 'medium' | 'low' | 'data'>;
weight: Q_EnumValue<Weight>;
restriction: Q_EnumValue<MessageRestriction>;
title: Q_StringValue;
content: Q_StringValue;
props: Object;
@ -72,12 +80,13 @@ export declare type Projection = {
$$createAt$$?: number;
$$updateAt$$?: number;
$$seq$$?: number;
entity?: number;
entityId?: number;
userId?: number;
user?: User.Projection;
systemId?: number;
system?: System.Projection;
type?: number;
weight?: number;
restriction?: number;
title?: number;
content?: number;
props?: number;
@ -85,11 +94,11 @@ export declare type Projection = {
params?: number;
iState?: number;
visitState?: number;
messageSent$message?: MessageSent.Selection & {
$entity: "messageSent";
messageSystem$message?: MessageSystem.Selection & {
$entity: "messageSystem";
};
messageSent$message$$aggr?: MessageSent.Aggregation & {
$entity: "messageSent";
messageSystem$message$$aggr?: MessageSystem.Aggregation & {
$entity: "messageSystem";
};
} & Partial<ExprOp<OpAttr | string>>;
declare type MessageIdProjection = OneOf<{
@ -98,9 +107,6 @@ declare type MessageIdProjection = OneOf<{
declare type UserIdProjection = OneOf<{
userId: number;
}>;
declare type SystemIdProjection = OneOf<{
systemId: number;
}>;
export declare type SortAttr = {
id: number;
} | {
@ -109,18 +115,20 @@ export declare type SortAttr = {
$$seq$$: number;
} | {
$$updateAt$$: number;
} | {
entity: number;
} | {
entityId: number;
} | {
userId: number;
} | {
user: User.SortAttr;
} | {
systemId: number;
} | {
system: System.SortAttr;
} | {
type: number;
} | {
weight: number;
} | {
restriction: number;
} | {
title: number;
} | {
@ -142,7 +150,7 @@ export declare type Sorter = SortNode[];
export declare type SelectOperation<P extends Object = Projection> = OakSelection<"select", P, Filter, Sorter>;
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
export declare type Aggregation = DeduceAggregation<Projection, Filter, Sorter>;
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "userId" | "systemId">> & (({
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity" | "entityId" | "userId">> & (({
userId?: never;
user: User.CreateSingleOperation;
} | {
@ -150,21 +158,17 @@ export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "userId"
user?: User.UpdateOperation;
} | {
userId: String<64>;
}) & ({
systemId?: never;
system: System.CreateSingleOperation;
} | {
systemId: String<64>;
system?: System.UpdateOperation;
} | {
systemId: String<64>;
})) & {
messageSent$message?: OakOperation<MessageSent.UpdateOperation["action"], Omit<MessageSent.UpdateOperationData, "message" | "messageId">, MessageSent.Filter> | OakOperation<"create", Omit<MessageSent.CreateOperationData, "message" | "messageId">[]> | Array<OakOperation<"create", Omit<MessageSent.CreateOperationData, "message" | "messageId">> | OakOperation<MessageSent.UpdateOperation["action"], Omit<MessageSent.UpdateOperationData, "message" | "messageId">, MessageSent.Filter>>;
})) & ({
entity?: string;
entityId?: string;
[K: string]: any;
}) & {
messageSystem$message?: OakOperation<MessageSystem.UpdateOperation["action"], Omit<MessageSystem.UpdateOperationData, "message" | "messageId">, MessageSystem.Filter> | OakOperation<"create", Omit<MessageSystem.CreateOperationData, "message" | "messageId">[]> | Array<OakOperation<"create", Omit<MessageSystem.CreateOperationData, "message" | "messageId">> | OakOperation<MessageSystem.UpdateOperation["action"], Omit<MessageSystem.UpdateOperationData, "message" | "messageId">, MessageSystem.Filter>>;
};
export declare type CreateSingleOperation = OakOperation<"create", CreateOperationData>;
export declare type CreateMultipleOperation = OakOperation<"create", Array<CreateOperationData>>;
export declare type CreateOperation = CreateSingleOperation | CreateMultipleOperation;
export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "userId" | "systemId">> & (({
export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "userId">> & (({
user: User.CreateSingleOperation;
userId?: never;
} | {
@ -176,32 +180,17 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "userId"
} | {
user?: never;
userId?: String<64> | null;
}) & ({
system: System.CreateSingleOperation;
systemId?: never;
} | {
system: System.UpdateOperation;
systemId?: never;
} | {
system: System.RemoveOperation;
systemId?: never;
} | {
system?: never;
systemId?: String<64> | null;
})) & {
[k: string]: any;
messageSent$message?: MessageSent.UpdateOperation | MessageSent.RemoveOperation | OakOperation<"create", Omit<MessageSent.CreateOperationData, "message" | "messageId">[]> | Array<OakOperation<"create", Omit<MessageSent.CreateOperationData, "message" | "messageId">> | MessageSent.UpdateOperation | MessageSent.RemoveOperation>;
messageSystem$message?: MessageSystem.UpdateOperation | MessageSystem.RemoveOperation | OakOperation<"create", Omit<MessageSystem.CreateOperationData, "message" | "messageId">[]> | Array<OakOperation<"create", Omit<MessageSystem.CreateOperationData, "message" | "messageId">> | MessageSystem.UpdateOperation | MessageSystem.RemoveOperation>;
};
export declare type UpdateOperation = OakOperation<"update" | ParticularAction | string, UpdateOperationData, Filter, Sorter>;
export declare type RemoveOperationData = {} & (({
user?: User.UpdateOperation | User.RemoveOperation;
}) & ({
system?: System.UpdateOperation | System.RemoveOperation;
}));
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
export declare type UserIdSubQuery = Selection<UserIdProjection>;
export declare type SystemIdSubQuery = Selection<SystemIdProjection>;
export declare type MessageIdSubQuery = Selection<MessageIdProjection>;
export declare type EntityDef = {
Schema: Schema;

View File

@ -4,14 +4,22 @@ exports.desc = void 0;
var Action_1 = require("./Action");
exports.desc = {
attributes: {
entity: {
type: "varchar",
params: {
length: 32
}
},
entityId: {
type: "varchar",
params: {
length: 64
}
},
userId: {
type: "ref",
ref: "user"
},
systemId: {
type: "ref",
ref: "system"
},
type: {
type: "varchar",
params: {
@ -19,10 +27,10 @@ exports.desc = {
}
},
weight: {
type: "varchar",
params: {
length: 24
}
type: "object"
},
restriction: {
type: "object"
},
title: {
type: "varchar",

View File

@ -1 +1 @@
{ "attr": { "title": "标题", "content": "内容", "user": "关联用户", "system": "系统", "type": "消息类型", "weight": "优先级", "iState": "发送状态", "visitState": "访问状态", "props": "属性", "params": "渠道定制参数", "data": "透传数据" }, "action": { "succeed": "成功", "fail": "失败", "visit": "阅读" }, "v": { "iState": { "sending": "发送中", "success": "发送成功", "failure": "发送失败" }, "visitState": { "unvisited": "未读", "visited": "已读" }, "weight": { "high": "高", "medium": "中", "low": "低", "data": "数据" } } }
{ "attr": { "entity": "关联对象", "entityId": "关联对象ID", "restriction": "限制", "title": "标题", "content": "内容", "user": "关联用户", "type": "消息类型", "weight": "优先级", "iState": "发送状态", "visitState": "访问状态", "props": "属性", "params": "渠道定制参数", "data": "透传数据" }, "action": { "succeed": "成功", "fail": "失败", "visit": "阅读" }, "v": { "iState": { "sending": "发送中", "success": "发送成功", "failure": "发送失败" }, "visitState": { "unvisited": "未读", "visited": "已读" }, "weight": { "high": "高", "medium": "中", "low": "低" } } }

View File

@ -4,24 +4,29 @@ import { OneOf } from "oak-domain/lib/types/Polyfill";
import * as SubQuery from "../_SubQuery";
import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, EntityShape } from "oak-domain/lib/types/Entity";
import { Action, ParticularAction, IState } from "./Action";
import * as Message from "../Message/Schema";
import { Channel } from "../../types/Message";
import * as Application from "../Application/Schema";
import * as MessageSystem from "../MessageSystem/Schema";
export declare type OpSchema = EntityShape & {
channel: 'wechat' | 'jPush' | 'jim' | 'mp' | 'sms';
channel: Channel;
applicationId?: ForeignKey<"application"> | null;
data: Object;
messageId: ForeignKey<"message">;
messageSystemId: ForeignKey<"messageSystem">;
data1: Object;
data2: Object;
iState?: IState | null;
};
export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & {
channel: 'wechat' | 'jPush' | 'jim' | 'mp' | 'sms';
channel: Channel;
applicationId?: ForeignKey<"application"> | null;
data: Object;
messageId: ForeignKey<"message">;
messageSystemId: ForeignKey<"messageSystem">;
data1: Object;
data2: Object;
iState?: IState | null;
message: Message.Schema;
application?: Application.Schema | null;
messageSystem: MessageSystem.Schema;
} & {
[A in ExpressionKey]?: any;
};
@ -30,10 +35,12 @@ declare type AttrFilter = {
$$createAt$$: Q_DateValue;
$$seq$$: Q_StringValue;
$$updateAt$$: Q_DateValue;
channel: Q_EnumValue<'wechat' | 'jPush' | 'jim' | 'mp' | 'sms'>;
channel: Q_EnumValue<Channel>;
applicationId: Q_StringValue | SubQuery.ApplicationIdSubQuery;
application: Application.Filter;
data: Object;
messageId: Q_StringValue | SubQuery.MessageIdSubQuery;
message: Message.Filter;
messageSystemId: Q_StringValue | SubQuery.MessageSystemIdSubQuery;
messageSystem: MessageSystem.Filter;
data1: Object;
data2: Object;
iState: Q_EnumValue<IState>;
@ -47,9 +54,11 @@ export declare type Projection = {
$$updateAt$$?: number;
$$seq$$?: number;
channel?: number;
applicationId?: number;
application?: Application.Projection;
data?: number;
messageId?: number;
message?: Message.Projection;
messageSystemId?: number;
messageSystem?: MessageSystem.Projection;
data1?: number;
data2?: number;
iState?: number;
@ -57,8 +66,11 @@ export declare type Projection = {
declare type MessageSentIdProjection = OneOf<{
id: number;
}>;
declare type MessageIdProjection = OneOf<{
messageId: number;
declare type ApplicationIdProjection = OneOf<{
applicationId: number;
}>;
declare type MessageSystemIdProjection = OneOf<{
messageSystemId: number;
}>;
export declare type SortAttr = {
id: number;
@ -71,9 +83,13 @@ export declare type SortAttr = {
} | {
channel: number;
} | {
messageId: number;
applicationId: number;
} | {
message: Message.SortAttr;
application: Application.SortAttr;
} | {
messageSystemId: number;
} | {
messageSystem: MessageSystem.SortAttr;
} | {
iState: number;
} | {
@ -87,40 +103,63 @@ export declare type Sorter = SortNode[];
export declare type SelectOperation<P extends Object = Projection> = OakSelection<"select", P, Filter, Sorter>;
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
export declare type Aggregation = DeduceAggregation<Projection, Filter, Sorter>;
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "messageId">> & (({
messageId?: never;
message: Message.CreateSingleOperation;
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "applicationId" | "messageSystemId">> & (({
applicationId?: never;
application?: Application.CreateSingleOperation;
} | {
messageId: String<64>;
message?: Message.UpdateOperation;
applicationId: String<64>;
application?: Application.UpdateOperation;
} | {
messageId: String<64>;
applicationId?: String<64>;
}) & ({
messageSystemId?: never;
messageSystem: MessageSystem.CreateSingleOperation;
} | {
messageSystemId: String<64>;
messageSystem?: MessageSystem.UpdateOperation;
} | {
messageSystemId: String<64>;
}));
export declare type CreateSingleOperation = OakOperation<"create", CreateOperationData>;
export declare type CreateMultipleOperation = OakOperation<"create", Array<CreateOperationData>>;
export declare type CreateOperation = CreateSingleOperation | CreateMultipleOperation;
export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "messageId">> & (({
message: Message.CreateSingleOperation;
messageId?: never;
export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "applicationId" | "messageSystemId">> & (({
application: Application.CreateSingleOperation;
applicationId?: never;
} | {
message: Message.UpdateOperation;
messageId?: never;
application: Application.UpdateOperation;
applicationId?: never;
} | {
message: Message.RemoveOperation;
messageId?: never;
application: Application.RemoveOperation;
applicationId?: never;
} | {
message?: never;
messageId?: String<64> | null;
application?: never;
applicationId?: String<64> | null;
}) & ({
messageSystem: MessageSystem.CreateSingleOperation;
messageSystemId?: never;
} | {
messageSystem: MessageSystem.UpdateOperation;
messageSystemId?: never;
} | {
messageSystem: MessageSystem.RemoveOperation;
messageSystemId?: never;
} | {
messageSystem?: never;
messageSystemId?: String<64> | null;
})) & {
[k: string]: any;
};
export declare type UpdateOperation = OakOperation<"update" | ParticularAction | string, UpdateOperationData, Filter, Sorter>;
export declare type RemoveOperationData = {} & (({
message?: Message.UpdateOperation | Message.RemoveOperation;
application?: Application.UpdateOperation | Application.RemoveOperation;
}) & ({
messageSystem?: MessageSystem.UpdateOperation | MessageSystem.RemoveOperation;
}));
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
export declare type MessageIdSubQuery = Selection<MessageIdProjection>;
export declare type ApplicationIdSubQuery = Selection<ApplicationIdProjection>;
export declare type MessageSystemIdSubQuery = Selection<MessageSystemIdProjection>;
export declare type MessageSentIdSubQuery = Selection<MessageSentIdProjection>;
export declare type EntityDef = {
Schema: Schema;

View File

@ -5,17 +5,18 @@ var Action_1 = require("./Action");
exports.desc = {
attributes: {
channel: {
type: "varchar",
params: {
length: 24
}
type: "object"
},
applicationId: {
type: "ref",
ref: "application"
},
data: {
type: "object"
},
messageId: {
messageSystemId: {
type: "ref",
ref: "message"
ref: "messageSystem"
},
data1: {
type: "object"

View File

@ -1 +1 @@
{ "attr": { "channel": "消息渠道", "data": "消息数据", "message": "消息", "data1": "数据1", "data2": "数据2", "iState": "状态" }, "action": { "succeed": "成功", "fail": "失败" }, "v": { "iState": { "sending": "发送中", "success": "发送成功", "failure": "发送失败" }, "channel": { "wechat": "公众号", "jPush": "极光推送", "jim": "极光消息", "mp": "小程序", "sms": "短信" } } }
{ "attr": { "channel": "消息渠道", "data": "消息数据", "messageSystem": "消息系统连接", "data1": "数据1", "data2": "数据2", "iState": "状态", "application": "关联应用" }, "action": { "succeed": "成功", "fail": "失败" }, "v": { "iState": { "sending": "发送中", "success": "发送成功", "failure": "发送失败" }, "channel": { "wechatPublic": "公众号", "jPush": "极光推送", "jim": "极光消息", "mp": "小程序", "sms": "短信" } } }

View File

@ -0,0 +1,164 @@
import { String, ForeignKey } from "oak-domain/lib/types/DataType";
import { Q_DateValue, Q_StringValue, NodeId, MakeFilter, ExprOp, ExpressionKey } from "oak-domain/lib/types/Demand";
import { OneOf } from "oak-domain/lib/types/Polyfill";
import * as SubQuery from "../_SubQuery";
import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, EntityShape, AggregationResult } from "oak-domain/lib/types/Entity";
import { GenericAction } from "oak-domain/lib/actions/action";
import * as Message from "../Message/Schema";
import * as System from "../System/Schema";
import * as MessageSent from "../MessageSent/Schema";
export declare type OpSchema = EntityShape & {
messageId: ForeignKey<"message">;
systemId: ForeignKey<"system">;
};
export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & {
messageId: ForeignKey<"message">;
systemId: ForeignKey<"system">;
message: Message.Schema;
system: System.Schema;
messageSent$messageSystem?: Array<MessageSent.Schema>;
messageSent$messageSystem$$aggr?: AggregationResult<MessageSent.Schema>;
} & {
[A in ExpressionKey]?: any;
};
declare type AttrFilter = {
id: Q_StringValue | SubQuery.MessageSystemIdSubQuery;
$$createAt$$: Q_DateValue;
$$seq$$: Q_StringValue;
$$updateAt$$: Q_DateValue;
messageId: Q_StringValue | SubQuery.MessageIdSubQuery;
message: Message.Filter;
systemId: Q_StringValue | SubQuery.SystemIdSubQuery;
system: System.Filter;
};
export declare type Filter = MakeFilter<AttrFilter & ExprOp<OpAttr | string>>;
export declare type Projection = {
"#id"?: NodeId;
[k: string]: any;
id?: number;
$$createAt$$?: number;
$$updateAt$$?: number;
$$seq$$?: number;
messageId?: number;
message?: Message.Projection;
systemId?: number;
system?: System.Projection;
messageSent$messageSystem?: MessageSent.Selection & {
$entity: "messageSent";
};
messageSent$messageSystem$$aggr?: MessageSent.Aggregation & {
$entity: "messageSent";
};
} & Partial<ExprOp<OpAttr | string>>;
declare type MessageSystemIdProjection = OneOf<{
id: number;
}>;
declare type MessageIdProjection = OneOf<{
messageId: number;
}>;
declare type SystemIdProjection = OneOf<{
systemId: number;
}>;
export declare type SortAttr = {
id: number;
} | {
$$createAt$$: number;
} | {
$$seq$$: number;
} | {
$$updateAt$$: number;
} | {
messageId: number;
} | {
message: Message.SortAttr;
} | {
systemId: number;
} | {
system: System.SortAttr;
} | {
[k: string]: any;
} | OneOf<ExprOp<OpAttr | string>>;
export declare type SortNode = {
$attr: SortAttr;
$direction?: "asc" | "desc";
};
export declare type Sorter = SortNode[];
export declare type SelectOperation<P extends Object = Projection> = OakSelection<"select", P, Filter, Sorter>;
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
export declare type Aggregation = DeduceAggregation<Projection, Filter, Sorter>;
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "messageId" | "systemId">> & (({
messageId?: never;
message: Message.CreateSingleOperation;
} | {
messageId: String<64>;
message?: Message.UpdateOperation;
} | {
messageId: String<64>;
}) & ({
systemId?: never;
system: System.CreateSingleOperation;
} | {
systemId: String<64>;
system?: System.UpdateOperation;
} | {
systemId: String<64>;
})) & {
messageSent$messageSystem?: OakOperation<MessageSent.UpdateOperation["action"], Omit<MessageSent.UpdateOperationData, "messageSystem" | "messageSystemId">, MessageSent.Filter> | OakOperation<"create", Omit<MessageSent.CreateOperationData, "messageSystem" | "messageSystemId">[]> | Array<OakOperation<"create", Omit<MessageSent.CreateOperationData, "messageSystem" | "messageSystemId">> | OakOperation<MessageSent.UpdateOperation["action"], Omit<MessageSent.UpdateOperationData, "messageSystem" | "messageSystemId">, MessageSent.Filter>>;
};
export declare type CreateSingleOperation = OakOperation<"create", CreateOperationData>;
export declare type CreateMultipleOperation = OakOperation<"create", Array<CreateOperationData>>;
export declare type CreateOperation = CreateSingleOperation | CreateMultipleOperation;
export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "messageId" | "systemId">> & (({
message: Message.CreateSingleOperation;
messageId?: never;
} | {
message: Message.UpdateOperation;
messageId?: never;
} | {
message: Message.RemoveOperation;
messageId?: never;
} | {
message?: never;
messageId?: String<64> | null;
}) & ({
system: System.CreateSingleOperation;
systemId?: never;
} | {
system: System.UpdateOperation;
systemId?: never;
} | {
system: System.RemoveOperation;
systemId?: never;
} | {
system?: never;
systemId?: String<64> | null;
})) & {
[k: string]: any;
messageSent$messageSystem?: MessageSent.UpdateOperation | MessageSent.RemoveOperation | OakOperation<"create", Omit<MessageSent.CreateOperationData, "messageSystem" | "messageSystemId">[]> | Array<OakOperation<"create", Omit<MessageSent.CreateOperationData, "messageSystem" | "messageSystemId">> | MessageSent.UpdateOperation | MessageSent.RemoveOperation>;
};
export declare type UpdateOperation = OakOperation<"update" | string, UpdateOperationData, Filter, Sorter>;
export declare type RemoveOperationData = {} & (({
message?: Message.UpdateOperation | Message.RemoveOperation;
}) & ({
system?: System.UpdateOperation | System.RemoveOperation;
}));
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
export declare type MessageIdSubQuery = Selection<MessageIdProjection>;
export declare type SystemIdSubQuery = Selection<SystemIdProjection>;
export declare type MessageSystemIdSubQuery = Selection<MessageSystemIdProjection>;
export declare type EntityDef = {
Schema: Schema;
OpSchema: OpSchema;
Action: OakMakeAction<GenericAction> | string;
Selection: Selection;
Aggregation: Aggregation;
Operation: Operation;
Create: CreateOperation;
Update: UpdateOperation;
Remove: RemoveOperation;
CreateSingle: CreateSingleOperation;
CreateMulti: CreateMultipleOperation;
};
export {};

View File

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@ -0,0 +1,3 @@
import { StorageDesc } from "oak-domain/lib/types/Storage";
import { OpSchema } from "./Schema";
export declare const desc: StorageDesc<OpSchema>;

View File

@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.desc = void 0;
var action_1 = require("oak-domain/lib/actions/action");
exports.desc = {
attributes: {
messageId: {
type: "ref",
ref: "message"
},
systemId: {
type: "ref",
ref: "system"
}
},
actionType: "crud",
actions: action_1.genericActions
};

View File

@ -0,0 +1 @@
{ "attr": { "message": "消息", "system": "系统" } }

View File

@ -18,18 +18,19 @@ var Storage_14 = require("./ExtraFile/Storage");
var Storage_15 = require("./Livestream/Storage");
var Storage_16 = require("./Message/Storage");
var Storage_17 = require("./MessageSent/Storage");
var Storage_18 = require("./Mobile/Storage");
var Storage_19 = require("./Platform/Storage");
var Storage_20 = require("./UserRole/Storage");
var Storage_21 = require("./Role/Storage");
var Storage_22 = require("./Subscription/Storage");
var Storage_23 = require("./System/Storage");
var Storage_24 = require("./Token/Storage");
var Storage_25 = require("./UserSystem/Storage");
var Storage_26 = require("./UserWechatPublicTag/Storage");
var Storage_27 = require("./WechatPublicTag/Storage");
var Storage_28 = require("./WechatQrCode/Storage");
var Storage_29 = require("./WechatUser/Storage");
var Storage_18 = require("./MessageSystem/Storage");
var Storage_19 = require("./Mobile/Storage");
var Storage_20 = require("./Platform/Storage");
var Storage_21 = require("./UserRole/Storage");
var Storage_22 = require("./Role/Storage");
var Storage_23 = require("./Subscription/Storage");
var Storage_24 = require("./System/Storage");
var Storage_25 = require("./Token/Storage");
var Storage_26 = require("./UserSystem/Storage");
var Storage_27 = require("./UserWechatPublicTag/Storage");
var Storage_28 = require("./WechatPublicTag/Storage");
var Storage_29 = require("./WechatQrCode/Storage");
var Storage_30 = require("./WechatUser/Storage");
exports.storageSchema = {
modi: Storage_1.desc,
modiEntity: Storage_2.desc,
@ -48,16 +49,17 @@ exports.storageSchema = {
livestream: Storage_15.desc,
message: Storage_16.desc,
messageSent: Storage_17.desc,
mobile: Storage_18.desc,
platform: Storage_19.desc,
userRole: Storage_20.desc,
role: Storage_21.desc,
subscription: Storage_22.desc,
system: Storage_23.desc,
token: Storage_24.desc,
userSystem: Storage_25.desc,
userWechatPublicTag: Storage_26.desc,
wechatPublicTag: Storage_27.desc,
wechatQrCode: Storage_28.desc,
wechatUser: Storage_29.desc
messageSystem: Storage_18.desc,
mobile: Storage_19.desc,
platform: Storage_20.desc,
userRole: Storage_21.desc,
role: Storage_22.desc,
subscription: Storage_23.desc,
system: Storage_24.desc,
token: Storage_25.desc,
userSystem: Storage_26.desc,
userWechatPublicTag: Storage_27.desc,
wechatPublicTag: Storage_28.desc,
wechatQrCode: Storage_29.desc,
wechatUser: Storage_30.desc
};

View File

@ -9,7 +9,7 @@ import { Style } from "../../types/Style";
import * as Platform from "../Platform/Schema";
import * as Application from "../Application/Schema";
import * as Domain from "../Domain/Schema";
import * as Message from "../Message/Schema";
import * as MessageSystem from "../MessageSystem/Schema";
import * as UserSystem from "../UserSystem/Schema";
export declare type OpSchema = EntityShape & {
name: String<32>;
@ -38,8 +38,8 @@ export declare type Schema = EntityShape & {
application$system$$aggr?: AggregationResult<Application.Schema>;
domain$system?: Array<Domain.Schema>;
domain$system$$aggr?: AggregationResult<Domain.Schema>;
message$system?: Array<Message.Schema>;
message$system$$aggr?: AggregationResult<Message.Schema>;
messageSystem$system?: Array<MessageSystem.Schema>;
messageSystem$system$$aggr?: AggregationResult<MessageSystem.Schema>;
userSystem$system?: Array<UserSystem.Schema>;
userSystem$system$$aggr?: AggregationResult<UserSystem.Schema>;
} & {
@ -91,11 +91,11 @@ export declare type Projection = {
domain$system$$aggr?: Domain.Aggregation & {
$entity: "domain";
};
message$system?: Message.Selection & {
$entity: "message";
messageSystem$system?: MessageSystem.Selection & {
$entity: "messageSystem";
};
message$system$$aggr?: Message.Aggregation & {
$entity: "message";
messageSystem$system$$aggr?: MessageSystem.Aggregation & {
$entity: "messageSystem";
};
userSystem$system?: UserSystem.Selection & {
$entity: "userSystem";
@ -164,7 +164,7 @@ export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity"
}) & {
application$system?: OakOperation<Application.UpdateOperation["action"], Omit<Application.UpdateOperationData, "system" | "systemId">, Application.Filter> | OakOperation<"create", Omit<Application.CreateOperationData, "system" | "systemId">[]> | Array<OakOperation<"create", Omit<Application.CreateOperationData, "system" | "systemId">> | OakOperation<Application.UpdateOperation["action"], Omit<Application.UpdateOperationData, "system" | "systemId">, Application.Filter>>;
domain$system?: OakOperation<Domain.UpdateOperation["action"], Omit<Domain.UpdateOperationData, "system" | "systemId">, Domain.Filter> | OakOperation<"create", Omit<Domain.CreateOperationData, "system" | "systemId">[]> | Array<OakOperation<"create", Omit<Domain.CreateOperationData, "system" | "systemId">> | OakOperation<Domain.UpdateOperation["action"], Omit<Domain.UpdateOperationData, "system" | "systemId">, Domain.Filter>>;
message$system?: OakOperation<Message.UpdateOperation["action"], Omit<Message.UpdateOperationData, "system" | "systemId">, Message.Filter> | OakOperation<"create", Omit<Message.CreateOperationData, "system" | "systemId">[]> | Array<OakOperation<"create", Omit<Message.CreateOperationData, "system" | "systemId">> | OakOperation<Message.UpdateOperation["action"], Omit<Message.UpdateOperationData, "system" | "systemId">, Message.Filter>>;
messageSystem$system?: OakOperation<MessageSystem.UpdateOperation["action"], Omit<MessageSystem.UpdateOperationData, "system" | "systemId">, MessageSystem.Filter> | OakOperation<"create", Omit<MessageSystem.CreateOperationData, "system" | "systemId">[]> | Array<OakOperation<"create", Omit<MessageSystem.CreateOperationData, "system" | "systemId">> | OakOperation<MessageSystem.UpdateOperation["action"], Omit<MessageSystem.UpdateOperationData, "system" | "systemId">, MessageSystem.Filter>>;
userSystem$system?: OakOperation<UserSystem.UpdateOperation["action"], Omit<UserSystem.UpdateOperationData, "system" | "systemId">, UserSystem.Filter> | OakOperation<"create", Omit<UserSystem.CreateOperationData, "system" | "systemId">[]> | Array<OakOperation<"create", Omit<UserSystem.CreateOperationData, "system" | "systemId">> | OakOperation<UserSystem.UpdateOperation["action"], Omit<UserSystem.UpdateOperationData, "system" | "systemId">, UserSystem.Filter>>;
};
export declare type CreateSingleOperation = OakOperation<"create", CreateOperationData>;
@ -186,7 +186,7 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "platfor
[k: string]: any;
application$system?: Application.UpdateOperation | Application.RemoveOperation | OakOperation<"create", Omit<Application.CreateOperationData, "system" | "systemId">[]> | Array<OakOperation<"create", Omit<Application.CreateOperationData, "system" | "systemId">> | Application.UpdateOperation | Application.RemoveOperation>;
domain$system?: Domain.UpdateOperation | Domain.RemoveOperation | OakOperation<"create", Omit<Domain.CreateOperationData, "system" | "systemId">[]> | Array<OakOperation<"create", Omit<Domain.CreateOperationData, "system" | "systemId">> | Domain.UpdateOperation | Domain.RemoveOperation>;
message$system?: Message.UpdateOperation | Message.RemoveOperation | OakOperation<"create", Omit<Message.CreateOperationData, "system" | "systemId">[]> | Array<OakOperation<"create", Omit<Message.CreateOperationData, "system" | "systemId">> | Message.UpdateOperation | Message.RemoveOperation>;
messageSystem$system?: MessageSystem.UpdateOperation | MessageSystem.RemoveOperation | OakOperation<"create", Omit<MessageSystem.CreateOperationData, "system" | "systemId">[]> | Array<OakOperation<"create", Omit<MessageSystem.CreateOperationData, "system" | "systemId">> | MessageSystem.UpdateOperation | MessageSystem.RemoveOperation>;
userSystem$system?: UserSystem.UpdateOperation | UserSystem.RemoveOperation | OakOperation<"create", Omit<UserSystem.CreateOperationData, "system" | "systemId">[]> | Array<OakOperation<"create", Omit<UserSystem.CreateOperationData, "system" | "systemId">> | UserSystem.UpdateOperation | UserSystem.RemoveOperation>;
};
export declare type UpdateOperation = OakOperation<"update" | string, UpdateOperationData, Filter, Sorter>;

View File

@ -15,6 +15,7 @@ import * as ExtraFile from "./ExtraFile/Schema";
import * as Livestream from "./Livestream/Schema";
import * as Message from "./Message/Schema";
import * as MessageSent from "./MessageSent/Schema";
import * as MessageSystem from "./MessageSystem/Schema";
import * as Mobile from "./Mobile/Schema";
import * as Platform from "./Platform/Schema";
import * as UserRole from "./UserRole/Schema";
@ -89,7 +90,9 @@ export declare type AddressIdSubQuery = {
}) | any;
};
export declare type ApplicationIdSubQuery = {
[K in "$in" | "$nin"]?: (Token.ApplicationIdSubQuery & {
[K in "$in" | "$nin"]?: (MessageSent.ApplicationIdSubQuery & {
entity: "messageSent";
}) | (Token.ApplicationIdSubQuery & {
entity: "token";
}) | (WechatPublicTag.ApplicationIdSubQuery & {
entity: "wechatPublicTag";
@ -141,8 +144,8 @@ export declare type LivestreamIdSubQuery = {
}) | any;
};
export declare type MessageIdSubQuery = {
[K in "$in" | "$nin"]?: (MessageSent.MessageIdSubQuery & {
entity: "messageSent";
[K in "$in" | "$nin"]?: (MessageSystem.MessageIdSubQuery & {
entity: "messageSystem";
}) | (Message.MessageIdSubQuery & {
entity: "message";
}) | any;
@ -152,6 +155,13 @@ export declare type MessageSentIdSubQuery = {
entity: "messageSent";
}) | any;
};
export declare type MessageSystemIdSubQuery = {
[K in "$in" | "$nin"]?: (MessageSent.MessageSystemIdSubQuery & {
entity: "messageSent";
}) | (MessageSystem.MessageSystemIdSubQuery & {
entity: "messageSystem";
}) | any;
};
export declare type MobileIdSubQuery = {
[K in "$in" | "$nin"]?: (Mobile.MobileIdSubQuery & {
entity: "mobile";
@ -186,8 +196,8 @@ export declare type SystemIdSubQuery = {
entity: "application";
}) | (Domain.SystemIdSubQuery & {
entity: "domain";
}) | (Message.SystemIdSubQuery & {
entity: "message";
}) | (MessageSystem.SystemIdSubQuery & {
entity: "messageSystem";
}) | (UserSystem.SystemIdSubQuery & {
entity: "userSystem";
}) | (System.SystemIdSubQuery & {

View File

@ -1,13 +1,11 @@
import { Trigger } from 'oak-domain/lib/types/Trigger';
import { EntityDict } from '../general-app-domain/EntityDict';
import { CreateOperationData as CreateMessageData } from '../general-app-domain/Message/Schema';
import { RuntimeCxt } from '../types/RuntimeCxt';
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
import { MessagePropsToSms, MessagePropsToWechat } from '../types/Message';
import { MessagePropsToSms, MessagePropsToWechatPublic, MessagePropsToWechatMp } from '../types/Message';
export declare function registerMessagePropsConverter(converter: {
sms?: MessagePropsToSms;
wechat?: MessagePropsToWechat;
wechatPublic?: MessagePropsToWechatPublic;
wechatMp?: MessagePropsToWechatMp;
}): void;
export declare function addMessageSent(message: CreateMessageData, context: BackendRuntimeContext<EntityDict>): Promise<0 | 1>;
declare const triggers: Trigger<EntityDict, 'message', RuntimeCxt>[];
export default triggers;

View File

@ -1,174 +1,208 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addMessageSent = exports.registerMessagePropsConverter = void 0;
exports.registerMessagePropsConverter = void 0;
var tslib_1 = require("tslib");
var uuid_1 = require("oak-domain/lib/utils/uuid");
var assert_1 = require("oak-domain/lib/utils/assert");
var SmsCoverter;
var WechatConverter;
var WechatPublicConverter;
var WechatMpConverter;
function registerMessagePropsConverter(converter) {
var sms = converter.sms, wechat = converter.wechat;
var sms = converter.sms, wechatPublic = converter.wechatPublic, wechatMp = converter.wechatMp;
SmsCoverter = sms;
WechatConverter = wechat;
WechatPublicConverter = wechatPublic;
WechatMpConverter = wechatMp;
}
exports.registerMessagePropsConverter = registerMessagePropsConverter;
function tryAddMessageSent(message, channel, context) {
var InitialChannalByWeightMatrix = {
high: ['mp', 'wechatPublic', 'sms'],
medium: ['mp', 'wechatPublic'],
low: ['mp', 'wechatPublic'],
};
function assignMessageSystemAndSent(message, context) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var systemId, props, type, _a, application, config2, appId, dispersedData, _b, _c, _d;
var _e;
return tslib_1.__generator(this, function (_f) {
switch (_f.label) {
var restriction, userId, weight, type, props, application, platformId, userSystems, systems, channels, messageSentCount, messageSystemDatas, _a;
var _b;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
if (!WechatConverter) {
return [2 /*return*/, 0];
}
systemId = message.systemId, props = message.props, type = message.type;
return [4 /*yield*/, context.select('application', {
restriction = message.restriction, userId = message.userId, weight = message.weight, type = message.type, props = message.props;
(0, assert_1.assert)(userId);
application = context.getApplication();
platformId = application.system.platformId;
return [4 /*yield*/, context.select('userSystem', {
data: {
id: 1,
name: 1,
config: 1,
type: 1,
systemId: 1,
style: 1,
system: {
id: 1,
config: 1,
application$system: {
$entity: 'application',
data: {
id: 1,
type: 1,
config: 1,
},
},
},
},
filter: {
type: 'wechatPublic',
systemId: systemId,
userId: userId,
system: {
platformId: platformId,
}
},
}, {})];
}, { dontCollect: true })];
case 1:
_a = tslib_1.__read.apply(void 0, [_f.sent(), 1]), application = _a[0];
config2 = application.config;
appId = config2.appId;
switch (channel) {
case 'weChat': {
dispersedData = WechatConverter(type, props, appId);
break;
userSystems = _c.sent();
systems = userSystems.map(function (ele) { return ele.system; }).filter(function (ele) {
if (restriction && restriction.systemIds) {
return restriction.systemIds.includes(ele.id);
}
default: {
break;
return true;
});
channels = InitialChannalByWeightMatrix[weight].filter(function (ele) {
if (restriction && restriction.channels) {
return restriction.channels.includes(ele);
}
}
if (!dispersedData) {
return [2 /*return*/, 0];
}
_c = (_b = context).operate;
_d = ['messageSent'];
_e = {};
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
case 2: return [4 /*yield*/, _c.apply(_b, _d.concat([(_e.id = _f.sent(),
_e.action = 'create',
_e.data = {
messageId: message.id,
data: dispersedData,
channel: channel,
},
_e), {}]))];
case 3:
_f.sent();
return [2 /*return*/, 1];
}
});
});
}
function addMessageSent(message, context) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var weight, _a, result, count, result, count2, result;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
case 0:
weight = message.weight;
_a = weight;
switch (_a) {
case 'high': return [3 /*break*/, 1];
case 'medium': return [3 /*break*/, 3];
case 'low': return [3 /*break*/, 9];
}
return [3 /*break*/, 11];
case 1: return [4 /*yield*/, Promise.all([
tryAddMessageSent(message, 'wechat', context),
tryAddMessageSent(message, 'sms', context),
])];
case 2:
result = _b.sent();
return [2 /*return*/, result.reduce(function (a, b) { return a || b; })];
case 3: return [4 /*yield*/, context.count('messageSent', {
filter: {
return true;
});
messageSentCount = 0;
messageSystemDatas = [];
systems.forEach(function (system) {
var applications = system.application$system, config = system.config;
var messageSentDatas = [];
channels.forEach(function (channel) {
switch (channel) {
case 'mp': {
var app = applications === null || applications === void 0 ? void 0 : applications.find(function (ele) { return ele.type === 'wechatMp'; });
if (app) {
var dispersedData = WechatMpConverter && WechatMpConverter(type, props, app.id);
if (dispersedData) {
messageSentDatas.push({
id: (0, uuid_1.generateNewId)(),
data: dispersedData,
channel: channel,
applicationId: app.id,
});
}
}
break;
}
case 'wechatPublic': {
var app = applications === null || applications === void 0 ? void 0 : applications.find(function (ele) { return ele.type === 'wechatPublic'; });
if (app) {
var id = app.id, config_1 = app.config;
var dispersedData = WechatPublicConverter && WechatPublicConverter(type, props, app.id);
if (dispersedData) {
messageSentDatas.push({
id: (0, uuid_1.generateNewId)(),
data: dispersedData,
channel: channel,
applicationId: app.id,
});
}
}
break;
}
default: {
(0, assert_1.assert)(channel === 'sms'); // 目前只支持三种
break;
}
}
});
if (channels.includes('sms')) {
var dispersedData = SmsCoverter && SmsCoverter(type, props, system.id);
if (dispersedData) {
messageSentDatas.push({
id: (0, uuid_1.generateNewId)(),
data: dispersedData,
channel: 'sms',
});
}
}
var messageSystemData = {
id: (0, uuid_1.generateNewId)(),
messageId: message.id,
},
}, {})];
case 4:
count = _b.sent();
if (!(count < 1)) return [3 /*break*/, 7];
return [4 /*yield*/, Promise.all([
tryAddMessageSent(message, 'wechat', context),
])];
case 5:
result = _b.sent();
count2 = result.reduce(function (a, b) { return a || b; });
if (count2 > 0) {
return [2 /*return*/, count2];
}
return [4 /*yield*/, tryAddMessageSent(message, 'sms', context)];
case 6: return [2 /*return*/, _b.sent()];
case 7: return [4 /*yield*/, tryAddMessageSent(message, 'sms', context)];
case 8: return [2 /*return*/, _b.sent()];
case 9: return [4 /*yield*/, Promise.all([
tryAddMessageSent(message, 'wechat', context),
])];
case 10:
result = _b.sent();
return [2 /*return*/, result.reduce(function (a, b) { return a || b; })];
case 11:
{
(0, assert_1.assert)(false);
}
_b.label = 12;
case 12: return [2 /*return*/];
systemId: system.id,
};
if (messageSentDatas.length > 0) {
messageSentCount += messageSentDatas.length;
messageSystemData.messageSent$messageSystem = {
id: (0, uuid_1.generateNewId)(),
action: 'create',
data: messageSentDatas,
};
}
messageSystemDatas.push(messageSystemData);
});
if (!(messageSystemDatas.length > 0)) return [3 /*break*/, 3];
_a = message;
_b = {};
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
case 2:
_a.messageSystem$message = (_b.id = _c.sent(),
_b.action = 'create',
_b.data = messageSystemDatas,
_b);
_c.label = 3;
case 3:
message.iState = messageSentCount ? 'sending' : 'failed';
return [2 /*return*/, messageSentCount];
}
});
});
}
exports.addMessageSent = addMessageSent;
var triggers = [
{
name: '当创建message时创建相应的messageSent',
name: '当创建message时创建相应的messageSystem和messageSent',
entity: 'message',
action: 'create',
when: 'before',
fn: function (_a, context, params) {
var operation = _a.operation;
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var data, filter, fn;
return tslib_1.__generator(this, function (_b) {
switch (_b.label) {
var data, count, data_1, data_1_1, d, _b, e_1_1;
var e_1, _c;
return tslib_1.__generator(this, function (_d) {
switch (_d.label) {
case 0:
data = operation.data, filter = operation.filter;
fn = function (messageData) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
var result;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, addMessageSent(messageData, context)];
case 1:
result = _a.sent();
if (result === 0) {
Object.assign(messageData, {
iState: 'fail',
});
}
return [2 /*return*/];
}
});
}); };
if (!(data instanceof Array)) return [3 /*break*/, 1];
(0, assert_1.assert)('不存在一对多的情况');
return [3 /*break*/, 3];
case 1: return [4 /*yield*/, fn(data)];
data = operation.data;
count = 0;
if (!(data instanceof Array)) return [3 /*break*/, 9];
_d.label = 1;
case 1:
_d.trys.push([1, 6, 7, 8]);
data_1 = tslib_1.__values(data), data_1_1 = data_1.next();
_d.label = 2;
case 2:
_b.sent();
_b.label = 3;
case 3: return [2 /*return*/, 0];
if (!!data_1_1.done) return [3 /*break*/, 5];
d = data_1_1.value;
_b = count;
return [4 /*yield*/, assignMessageSystemAndSent(d, context)];
case 3:
count = _b + _d.sent();
_d.label = 4;
case 4:
data_1_1 = data_1.next();
return [3 /*break*/, 2];
case 5: return [3 /*break*/, 8];
case 6:
e_1_1 = _d.sent();
e_1 = { error: e_1_1 };
return [3 /*break*/, 8];
case 7:
try {
if (data_1_1 && !data_1_1.done && (_c = data_1.return)) _c.call(data_1);
}
finally { if (e_1) throw e_1.error; }
return [7 /*endfinally*/];
case 8: return [3 /*break*/, 11];
case 9: return [4 /*yield*/, assignMessageSystemAndSent(data, context)];
case 10:
count = _d.sent();
_d.label = 11;
case 11: return [2 /*return*/, count];
}
});
});

View File

@ -4,42 +4,8 @@ var tslib_1 = require("tslib");
var assert_1 = require("oak-domain/lib/utils/assert");
function sendMessage(messageSentData, context) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var data, channel, messageId, _a, message, _b, application, config2, appId;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
data = messageSentData.data, channel = messageSentData.channel, messageId = messageSentData.messageId;
return [4 /*yield*/, context.select('message', {
data: {
id: 1,
systemId: 1,
},
filter: {
id: messageId,
},
}, {})];
case 1:
_a = tslib_1.__read.apply(void 0, [_c.sent(), 1]), message = _a[0];
return [4 /*yield*/, context.select('application', {
data: {
id: 1,
name: 1,
config: 1,
type: 1,
systemId: 1,
style: 1,
},
filter: {
type: 'wechatPublic',
systemId: message.systemId,
},
}, {})];
case 2:
_b = tslib_1.__read.apply(void 0, [_c.sent(), 1]), application = _b[0];
config2 = application.config;
appId = config2.appId;
return [2 /*return*/];
}
return tslib_1.__generator(this, function (_a) {
return [2 /*return*/];
});
});
}

View File

@ -1,10 +1,10 @@
export declare type MessagePropsToSms = (type: string, props: Record<string, any>) => {
export declare type MessagePropsToSms = (type: string, props: Record<string, any>, systemId?: string) => {
signName?: string;
params?: Record<string, string>;
paramsArray?: Array<string>;
} | undefined;
declare type WechatKeywordNum = 'keyword1' | 'keyword2' | 'keyword3' | 'keyword4' | 'keyword5' | 'keyword6' | 'keyword7';
export declare type MessagePropsToWechat = (type: string, props: Record<string, any>, appId?: string) => ({
declare type WechatPublicTemplateMsgKeyword = 'keyword1' | 'keyword2' | 'keyword3' | 'keyword4' | 'keyword5' | 'keyword6' | 'keyword7';
export declare type MessagePropsToWechatPublic = (type: string, props: Record<string, any>, appId?: string) => ({
first?: {
value: string;
color?: string;
@ -14,9 +14,16 @@ export declare type MessagePropsToWechat = (type: string, props: Record<string,
color?: string;
};
} & {
[K in WechatKeywordNum]?: {
[K in WechatPublicTemplateMsgKeyword]?: {
value: string;
color?: string;
};
}) | undefined;
export declare type MessagePropsToWechatMp = (type: string, props: Record<string, any>, appId?: string) => ({
[K: string]: {
value: string;
};
}) | undefined;
export declare type Channel = 'wechatPublic' | 'jPush' | 'jim' | 'mp' | 'sms';
export declare type Weight = 'high' | 'medium' | 'low';
export {};

View File

@ -4,6 +4,7 @@ import { Schema as System } from './System';
import { EntityShape } from 'oak-domain/lib/types/Entity';
import { LocaleDef } from 'oak-domain/lib/types/Locale';
import { Index, ActionDef } from 'oak-domain/lib/types';
import { Channel, Weight } from '../types/Message';
type MessageParams = {
pathname: string;
@ -11,11 +12,18 @@ type MessageParams = {
state?: Record<string, any>;
};
type MessageRestriction = {
systemIds?: string[]; // 允许发送的system
channels?: Array<Channel>; // 允许推送的渠道
}
export interface Schema extends EntityShape {
entity: String<32>;
entityId: String<64>;
user: User;
system: System;
type: String<64>;
weight: 'high' | 'medium' | 'low' | 'data';
weight: Weight;
restriction?: MessageRestriction;
title: String<256>;
content: Text;
props: Object; // 消息的结构化数据(用于向各个渠道推送时的格式化)
@ -36,7 +44,6 @@ const IActionDef: ActionDef<IAction, IState> = {
succeed: ['sending', 'success'],
fail: ['sending', 'failure'],
},
is: 'sending',
};
const VisitActionDef: ActionDef<VisitAction, VisitState> = {
@ -58,10 +65,12 @@ const locale: LocaleDef<
> = {
zh_CN: {
attr: {
entity: '关联对象',
entityId: '关联对象ID',
restriction: '限制',
title: '标题',
content: '内容',
user: '关联用户',
system: '系统',
type: '消息类型',
weight: '优先级',
iState: '发送状态',
@ -89,7 +98,6 @@ const locale: LocaleDef<
high: '高',
medium: '中',
low: '低',
data: '数据',
},
},
},

View File

@ -1,13 +1,15 @@
import { String, Int, Text, Image } from 'oak-domain/lib/types/DataType';
import { Schema as Message } from './Message';
import { EntityShape } from 'oak-domain/lib/types/Entity';
import { LocaleDef } from 'oak-domain/lib/types/Locale';
import { Index, ActionDef } from 'oak-domain/lib/types';
import { Channel } from '../types/Message';
import { Schema as Application } from './Application';
import { Schema as MessageSystem } from './MessageSystem';
export interface Schema extends EntityShape {
channel: 'wechat' | 'jPush' | 'jim' | 'mp' | 'sms',
channel: Channel,
application?: Application,
data: Object,
message: Message,
messageSystem: MessageSystem,
data1: Object,
data2: Object,
};
@ -33,10 +35,11 @@ const locale: LocaleDef<Schema, Action, '', {
attr: {
channel: '消息渠道',
data: '消息数据',
message: '消息',
messageSystem: '消息系统连接',
data1: '数据1',
data2: '数据2',
iState: '状态',
application: '关联应用',
},
action: {
succeed: '成功',
@ -49,7 +52,7 @@ const locale: LocaleDef<Schema, Action, '', {
failure: '发送失败',
},
channel: {
wechat: '公众号',
wechatPublic: '公众号',
jPush: '极光推送',
jim: '极光消息',
mp: '小程序',

View File

@ -0,0 +1,18 @@
import { Schema as Message } from './Message';
import { EntityShape } from 'oak-domain/lib/types/Entity';
import { LocaleDef } from 'oak-domain/lib/types/Locale';
import { Schema as System } from './System';
export interface Schema extends EntityShape {
message: Message,
system: System,
};
const locale: LocaleDef<Schema, '', '', {}> = {
zh_CN: {
attr: {
message: '消息',
system: '系统',
},
},
};

View File

@ -1,159 +1,199 @@
import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
import { generateNewId, generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
import { Trigger, CreateTrigger } from 'oak-domain/lib/types/Trigger';
import { EntityDict } from '../general-app-domain/EntityDict';
import { CreateOperationData as CreateMessageData } from '../general-app-domain/Message/Schema';
import { CreateOperationData as CreateMessageSentData } from '../general-app-domain/MessageSent/Schema';
import { assert } from 'oak-domain/lib/utils/assert';
import { RuntimeCxt } from '../types/RuntimeCxt';
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
import { MessagePropsToSms, MessagePropsToWechat } from '../types/Message';
import { Channel, MessagePropsToSms, MessagePropsToWechatPublic, MessagePropsToWechatMp, Weight } from '../types/Message';
import { WechatPublicConfig } from '../general-app-domain/Application/Schema';
let SmsCoverter: MessagePropsToSms | undefined;
let WechatConverter: MessagePropsToWechat | undefined;
let WechatPublicConverter: MessagePropsToWechatPublic | undefined;
let WechatMpConverter: MessagePropsToWechatMp | undefined;
export function registerMessagePropsConverter(converter: {
sms?: MessagePropsToSms;
wechat?: MessagePropsToWechat
wechatPublic?: MessagePropsToWechatPublic;
wechatMp?: MessagePropsToWechatMp;
}) {
const { sms, wechat } = converter;
const { sms, wechatPublic, wechatMp } = converter;
SmsCoverter = sms;
WechatConverter = wechat;
WechatPublicConverter = wechatPublic;
WechatMpConverter = wechatMp;
}
async function tryAddMessageSent(message: CreateMessageData, channel: string, context: BackendRuntimeContext<EntityDict>) {
if (!WechatConverter) {
return 0;
}
const { systemId, props, type } = message;
const [application] = await context.select(
'application',
{
data: {
id: 1,
name: 1,
config: 1,
type: 1,
systemId: 1,
style: 1,
},
filter: {
type: 'wechatPublic',
systemId,
},
},
{}
);
const config2 = application.config as WechatPublicConfig;
const appId = config2.appId;
let dispersedData;
switch (channel) {
case 'weChat': {
dispersedData = WechatConverter(type!, props!, appId);
break;
}
default: {
break;
}
}
if (!dispersedData) {
return 0;
}
await context.operate('messageSent', {
id: await generateNewIdAsync(),
action: 'create',
const InitialChannalByWeightMatrix: Record<Weight, Channel[]> = {
high: ['mp', 'wechatPublic', 'sms'],
medium: ['mp', 'wechatPublic'],
low: ['mp', 'wechatPublic'],
};
async function assignMessageSystemAndSent(message: CreateMessageData, context: RuntimeCxt) {
const { restriction, userId, weight, type, props } = message;
assert(userId);
// 根据用户所关联的system和定义限制选择将要发送的system。一般来说不可能跨platform
const application = context.getApplication();
const platformId = application!.system!.platformId!;
const userSystems = await context.select('userSystem', {
data: {
messageId: message.id,
data: dispersedData,
channel,
},
} as EntityDict['messageSent']['CreateSingle'], {});
return 1;
}
export async function addMessageSent(message: CreateMessageData, context: BackendRuntimeContext<EntityDict>) {
const { weight } = message;
switch (weight) {
case 'high': {
// 高权重的,所有渠道一起推
const result = await Promise.all([
tryAddMessageSent(message, 'wechat', context),
tryAddMessageSent(message, 'sms', context),
]);
return result.reduce((a, b) => a || b);
}
case 'medium': {
// 中权重的,先推免费渠道,失败了再推收费渠道
const count = await context.count(
'messageSent',
{
filter: {
messageId: message.id,
id: 1,
system: {
id: 1,
config: 1,
application$system: {
$entity: 'application',
data: {
id: 1,
type: 1,
config: 1,
},
},
{},
);
if (count < 1) {
const result = await Promise.all([
tryAddMessageSent(message, 'wechat', context),
]);
const count2 = result.reduce((a, b) => a || b);
if (count2 > 0) {
return count2;
}
return await tryAddMessageSent(message, 'sms', context);
},
},
filter: {
userId,
system: {
platformId,
}
return await tryAddMessageSent(message, 'sms', context);
}
case 'low': {
// 低权重的,只推免费渠道
const result = await Promise.all([
tryAddMessageSent(message, 'wechat', context),
]);
return result.reduce((a, b) => a || b);
}
// case 'data': {
},
}, { dontCollect: true });
// // 透传数据的只推JPush
// const result = await Promise.all([
// tryAddMessageSent(message, 'jPush', context),
// tryAddMessageSent(message, 'jim', context),
// ]);
// return result.reduce((a, b) => a || b);
// }
default: {
assert(false);
const systems = userSystems.map(
ele => ele.system!
).filter(
ele => {
if (restriction && restriction.systemIds) {
return restriction.systemIds.includes(ele.id);
}
return true;
}
);
// 根据定义所限制的渠道和weight计算出相应的推送渠道
const channels = InitialChannalByWeightMatrix[weight!].filter(
ele => {
if (restriction && restriction.channels) {
return restriction.channels.includes(ele);
}
return true;
}
);
// 逐system逐channel去构造messageSystem和messageSent数据
let messageSentCount = 0;
const messageSystemDatas: EntityDict['messageSystem']['CreateMulti']['data'] = [];
systems.forEach(
(system) => {
const { application$system: applications, config } = system;
const messageSentDatas: Omit<EntityDict['messageSent']['CreateSingle']['data'], 'messageSystemId'>[] = [];
channels.forEach(
(channel) => {
switch (channel) {
case 'mp': {
const app = applications?.find(
ele => ele.type === 'wechatMp',
);
if (app) {
const dispersedData = WechatMpConverter && WechatMpConverter(type!, props!, app.id!);
if (dispersedData) {
messageSentDatas.push({
id: generateNewId(),
data: dispersedData,
channel,
applicationId: app.id,
});
}
}
break;
}
case 'wechatPublic': {
const app = applications?.find(
ele => ele.type === 'wechatPublic',
);
if (app) {
const { id, config } = app;
const dispersedData = WechatPublicConverter && WechatPublicConverter(type!, props!, app.id!);
if (dispersedData) {
messageSentDatas.push({
id: generateNewId(),
data: dispersedData,
channel,
applicationId: app.id,
});
}
}
break;
}
default: {
assert (channel === 'sms'); // 目前只支持三种
break;
}
}
}
);
if (channels.includes('sms')) {
const dispersedData = SmsCoverter && SmsCoverter(type!, props!, system.id);
if (dispersedData) {
messageSentDatas.push({
id: generateNewId(),
data: dispersedData,
channel: 'sms',
});
}
}
const messageSystemData: EntityDict['messageSystem']['CreateSingle']['data'] = {
id: generateNewId(),
messageId: message.id,
systemId: system.id,
};
if (messageSentDatas.length > 0) {
messageSentCount += messageSentDatas.length;
messageSystemData.messageSent$messageSystem = {
id: generateNewId(),
action: 'create',
data: messageSentDatas,
};
}
messageSystemDatas.push(messageSystemData);
}
);
if (messageSystemDatas.length > 0) {
message.messageSystem$message = {
id: await generateNewIdAsync(),
action: 'create',
data: messageSystemDatas,
};
}
message.iState = messageSentCount ? 'sending' : 'failed';
return messageSentCount;
}
const triggers: Trigger<EntityDict, 'message', RuntimeCxt>[] = [
{
name: '当创建message时创建相应的messageSent',
name: '当创建message时创建相应的messageSystem和messageSent',
entity: 'message',
action: 'create',
when: 'before',
fn: async ({ operation }, context, params) => {
const { data, filter } = operation;
const fn = async (messageData: CreateMessageData) => {
const result = await addMessageSent(messageData, context as BackendRuntimeContext<EntityDict>);
if (result === 0) {
Object.assign(
messageData, {
iState: 'fail',
}
)
const { data } = operation;
let count = 0;
if (data instanceof Array) {
for (const d of data) {
count += await assignMessageSystemAndSent(d, context);
}
}
if (data instanceof Array) {
assert('不存在一对多的情况')
}
else {
await fn(data);
count = await assignMessageSystemAndSent(data, context);
}
return 0;
return count;
}
} as CreateTrigger<EntityDict, 'message', RuntimeCxt>,
];

View File

@ -3,47 +3,11 @@ import { EntityDict } from '../general-app-domain/EntityDict';
import { CreateOperationData as CreateMessageSentData } from '../general-app-domain/MessageSent/Schema';
import { assert } from 'oak-domain/lib/utils/assert';
import { RuntimeCxt } from '../types/RuntimeCxt';
import { addMessageSent } from './message';
import { BackendRuntimeContext } from '../context/BackendRuntimeContext';
import { WechatMpConfig, WechatPublicConfig, WebConfig } from '../general-app-domain/Application/Schema';
import { WechatSDK } from 'oak-external-sdk';
async function sendMessage(messageSentData: CreateMessageSentData, context: BackendRuntimeContext<EntityDict>) {
const { data, channel, messageId } = messageSentData;
const [message] = await context.select(
'message',
{
data: {
id: 1,
systemId: 1,
},
filter: {
id: messageId,
},
},
{}
);
const [application] = await context.select(
'application',
{
data: {
id: 1,
name: 1,
config: 1,
type: 1,
systemId: 1,
style: 1,
},
filter: {
type: 'wechatPublic',
systemId: message.systemId,
},
},
{}
);
const config2 = application.config as WechatPublicConfig;
const appId = config2.appId;
}
const triggers: Trigger<EntityDict, 'messageSent', RuntimeCxt>[] = [

View File

@ -1,12 +1,12 @@
export type MessagePropsToSms = (type: string, props: Record<string, any>) => {
export type MessagePropsToSms = (type: string, props: Record<string, any>, systemId?: string) => {
signName?: string; // 可能的签名
params?: Record<string, string>; // 模板参数,需要替换的参数名和 value 的键值对
paramsArray?: Array<string>; // 数组形式的模板参数,按序传入服务商接口
} | undefined;
type WechatKeywordNum = 'keyword1' | 'keyword2' | 'keyword3'| 'keyword4'| 'keyword5'| 'keyword6'| 'keyword7';
type WechatPublicTemplateMsgKeyword = 'keyword1' | 'keyword2' | 'keyword3'| 'keyword4'| 'keyword5'| 'keyword6'| 'keyword7';
export type MessagePropsToWechat = (type: string, props: Record<string, any>, appId?: string) => ({
export type MessagePropsToWechatPublic = (type: string, props: Record<string, any>, appId?: string) => ({
first?: {
value: string;
color?: string;
@ -16,8 +16,18 @@ export type MessagePropsToWechat = (type: string, props: Record<string, any>, ap
color?: string;
};
} & {
[K in WechatKeywordNum]?: {
[K in WechatPublicTemplateMsgKeyword]?: {
value: string;
color?: string;
};
}) | undefined;
// 通过小程序订阅接口下发消息的格式。https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-message-management/subscribe-message/sendMessage.html
export type MessagePropsToWechatMp = (type: string, props: Record<string, any>, appId?: string) => ({
[K : string]: {
value: string;
}
}) | undefined;
export type Channel = 'wechatPublic' | 'jPush' | 'jim' | 'mp' | 'sms';
export type Weight = 'high' | 'medium' | 'low';