列车订阅状态调整

This commit is contained in:
dong 2023-11-01 15:55:25 +08:00
parent 036fddf8fe
commit 463620a75b
6 changed files with 56 additions and 17 deletions

View File

@ -69,6 +69,11 @@ export class TrainState extends GraphicStateBase implements ITrainState {
get code(): string {
return this.states.groupId;
}
get remove(): boolean {
const rtuIdArr = [81, 82];
const hasRtuId = rtuIdArr.includes(this.states.rtuId);
return hasRtuId;
}
get states(): train.TrainInfo {
return this.getState<train.TrainInfo>();
@ -194,12 +199,12 @@ export class TrainState extends GraphicStateBase implements ITrainState {
set rate(v: number) {
this.states.rate = v;
}
get remove(): train.TrainRemove {
return this.states.remove;
}
set remove(v: train.TrainRemove) {
this.states.remove = new train.TrainRemove(v);
}
// get remove(): train.TrainRemove {
// return this.states.remove;
// }
// set remove(v: train.TrainRemove) {
// this.states.remove = new train.TrainRemove(v);
// }
get block(): train.TrainBlock {
return this.states.block;
}

View File

@ -221,6 +221,7 @@ export function initLineApp(lineId: number): IGraphicApp {
});
lineApp.subscribe({
destination: `/queue/line/${lineId}/train`,
createOnNotFound: { graphicTypes: [Train.Type] },
messageConverter: (message: Uint8Array) => {
const states: GraphicState[] = [];
const trainStorage = state.WsLineTrainMessage.deserialize(message);

View File

@ -64,8 +64,8 @@ export interface ITrainState extends GraphicState {
set routeId(v: number);
get rate(): number; // 满载率
set rate(v: number);
get remove(): train.TrainRemove;
set remove(v: train.TrainRemove);
// get remove(): train.TrainRemove;
// set remove(v: train.TrainRemove);
get block(): train.TrainBlock;
set block(v: train.TrainBlock);
get record(): train.TrainRecord;

View File

@ -25,6 +25,7 @@ import {
type AppStateSubscription,
type MessageCliOption,
GraphicQuery,
ICreateOnNotFound,
} from '../message';
import { OperationRecord } from '../operation/JlOperation';
import {
@ -475,7 +476,8 @@ export interface IGraphicScene extends EventEmitter<GraphicAppEvents> {
*/
handleGraphicStates(
graphicStates: GraphicState[],
queryer?: GraphicQuery
queryer?: GraphicQuery,
createOnNotFound?: ICreateOnNotFound
): void;
/**
*
@ -1092,7 +1094,8 @@ abstract class GraphicSceneBase
*/
handleGraphicStates(
graphicStates: GraphicState[],
queryer?: GraphicQuery
queryer?: GraphicQuery,
createOnNotFound?: ICreateOnNotFound
): void {
graphicStates.forEach((state) => {
let g: JlGraphic | undefined;
@ -1103,13 +1106,28 @@ abstract class GraphicSceneBase
}
try {
if (!g) {
// 未找到图形对象
if (
createOnNotFound &&
createOnNotFound.graphicTypes &&
createOnNotFound.graphicTypes.findIndex(
(v) => v === state.graphicType
) >= 0
) {
const template = this.getGraphicTemplatesByType(state.graphicType);
const g = template.new();
g.loadState(state);
this.addGraphics(g);
}
} else {
// 找到
if (state.remove) {
this.deleteGraphics(g);
g.destroy({ children: true });
} else if (g.updateStates(state)) {
g.repaint();
}
}
} catch (err) {
console.error('图形状态处理异常', g, state, err);
// throw err;

View File

@ -502,6 +502,7 @@ export interface GraphicData {
export interface GraphicState {
get code(): string; // 业务标识
get graphicType(): string; // 图形类型
remove?: boolean; // 是否移除图形
/**
*
*/

View File

@ -146,6 +146,7 @@ export type GraphicStateMessageConvert = (
message: Uint8Array
) => GraphicState[];
// 根据状态查询图形对象查询器
export type GraphicQuery = (
state: GraphicState,
store: GraphicQueryStore
@ -154,6 +155,10 @@ export type GraphicQuery = (
// 订阅消息处理器
export type SubscriptionMessageHandle = (message: Uint8Array) => void;
export interface ICreateOnNotFound {
graphicTypes?: string[];
}
// 图形app状态订阅
export interface AppStateSubscription {
/**
@ -168,6 +173,11 @@ export interface AppStateSubscription {
* ,code和type查询图形对象
*/
graphicQueryer?: GraphicQuery;
/**
*
*
*/
createOnNotFound?: ICreateOnNotFound;
/**
*
*/
@ -196,7 +206,11 @@ class AppMessageHandler implements IMessageHandler {
const sub = this.sub;
if (sub.messageConverter) {
const graphicStates = sub.messageConverter(data);
this.app.handleGraphicStates(graphicStates, sub.graphicQueryer);
this.app.handleGraphicStates(
graphicStates,
sub.graphicQueryer,
sub.createOnNotFound
);
} else if (sub.messageHandle) {
sub.messageHandle(data);
}