@idm-plugin/vessel 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ais/src/index.d.ts +2 -1
- package/dist/alert/src/index.d.ts +47 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +316 -255
- package/dist/index.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/ais/src/index.d.ts
CHANGED
|
@@ -63,7 +63,8 @@ export declare class MyVesselImpl extends AISImpl {
|
|
|
63
63
|
constructor(clientId: string, clientSecret: string);
|
|
64
64
|
authToken(options?: RequestOptions): Promise<void>;
|
|
65
65
|
realTimePosition(mmsi: number, options?: RequestOptions): Promise<AISRecord>;
|
|
66
|
-
trajectory(mmsi: number, startTime: string, endTime: string, offset: number, scale?: boolean, options?: RequestOptions): Promise<
|
|
66
|
+
trajectory(mmsi: number, startTime: string, endTime: string, offset: number, scale?: boolean, options?: RequestOptions): Promise<AISRecord[]>;
|
|
67
|
+
private trajectoryIn30Day;
|
|
67
68
|
}
|
|
68
69
|
export declare class HifleetImpl extends AISImpl {
|
|
69
70
|
private readonly token;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { RequestOptions } from '../../../build/packages/index';
|
|
2
|
+
export declare enum AlertLevel {
|
|
3
|
+
NOTICE = "NOTICE",
|
|
4
|
+
WARN = "WARN",
|
|
5
|
+
HEAVY = "HEAVY",
|
|
6
|
+
SEVERE = "SEVERE",
|
|
7
|
+
ERROR = "ERROR",
|
|
8
|
+
FATAL = "FATAL"
|
|
9
|
+
}
|
|
10
|
+
export interface AlertRule {
|
|
11
|
+
operator: string;
|
|
12
|
+
number: number;
|
|
13
|
+
level: string;
|
|
14
|
+
time: number;
|
|
15
|
+
key?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class AlertHelper {
|
|
18
|
+
/**
|
|
19
|
+
* 解析告警规则, 多规则场景
|
|
20
|
+
* @param rule
|
|
21
|
+
* e.g.1 [any;[[>,maxCP,WARN,0,TotCons_VLSFO]];[[!==,0,ERROR,0,TotCons_VLSFO]]]
|
|
22
|
+
* e.g.2 [[>,0,HEAVY,Number.MAX_VALUE],[>,0,SEVERE,Number.MAX_VALUE]]
|
|
23
|
+
*
|
|
24
|
+
* @param options
|
|
25
|
+
*/
|
|
26
|
+
parsePrinciple(rule: string, options?: RequestOptions): any;
|
|
27
|
+
/**
|
|
28
|
+
* 解析单一告警规则
|
|
29
|
+
* e.g.1 [>,maxCP,WARN,0,TotCons_VLSFO]
|
|
30
|
+
* @param rule
|
|
31
|
+
* @param options
|
|
32
|
+
*/
|
|
33
|
+
parseRule(rule: string, options?: RequestOptions): AlertRule | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* 检查航路点天气
|
|
36
|
+
* @param sample 航路点
|
|
37
|
+
* @param principle 告警规则
|
|
38
|
+
* @param options
|
|
39
|
+
*/
|
|
40
|
+
checkWeather(sample: any[], principle: any, options?: RequestOptions): {
|
|
41
|
+
sample: any[];
|
|
42
|
+
dangerous: number;
|
|
43
|
+
severe: number;
|
|
44
|
+
heavy: number;
|
|
45
|
+
step: number;
|
|
46
|
+
};
|
|
47
|
+
}
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,93 +1,93 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import
|
|
5
|
-
import * as
|
|
6
|
-
import
|
|
7
|
-
const
|
|
8
|
-
class
|
|
1
|
+
var C = Object.defineProperty;
|
|
2
|
+
var O = (j, c, s) => c in j ? C(j, c, { enumerable: !0, configurable: !0, writable: !0, value: s }) : j[c] = s;
|
|
3
|
+
var q = (j, c, s) => (O(j, typeof c != "symbol" ? c + "" : c, s), s);
|
|
4
|
+
import Y from "got";
|
|
5
|
+
import * as W from "log4js";
|
|
6
|
+
import p from "moment";
|
|
7
|
+
const M = W.getLogger();
|
|
8
|
+
class V {
|
|
9
9
|
/**
|
|
10
10
|
* 解析AIS状态码
|
|
11
11
|
* @param status
|
|
12
12
|
*/
|
|
13
|
-
parseStatus(
|
|
14
|
-
let s,
|
|
15
|
-
switch (
|
|
13
|
+
parseStatus(c) {
|
|
14
|
+
let s, a;
|
|
15
|
+
switch (c) {
|
|
16
16
|
case 0:
|
|
17
|
-
s = "在航(主机推动)",
|
|
17
|
+
s = "在航(主机推动)", a = "The engine is in use";
|
|
18
18
|
break;
|
|
19
19
|
case 1:
|
|
20
|
-
s = "锚泊",
|
|
20
|
+
s = "锚泊", a = "Anchored";
|
|
21
21
|
break;
|
|
22
22
|
case 2:
|
|
23
|
-
s = "失控",
|
|
23
|
+
s = "失控", a = "Not operated";
|
|
24
24
|
break;
|
|
25
25
|
case 3:
|
|
26
|
-
s = "操纵受限",
|
|
26
|
+
s = "操纵受限", a = "Limited airworthiness";
|
|
27
27
|
break;
|
|
28
28
|
case 4:
|
|
29
|
-
s = "吃水受限",
|
|
29
|
+
s = "吃水受限", a = "Limited by ship's draft";
|
|
30
30
|
break;
|
|
31
31
|
case 5:
|
|
32
|
-
s = "靠泊",
|
|
32
|
+
s = "靠泊", a = "Mooring";
|
|
33
33
|
break;
|
|
34
34
|
case 6:
|
|
35
|
-
s = "搁浅",
|
|
35
|
+
s = "搁浅", a = "Stranded";
|
|
36
36
|
break;
|
|
37
37
|
case 7:
|
|
38
|
-
s = "捕捞作业",
|
|
38
|
+
s = "捕捞作业", a = "Engaged in fishing";
|
|
39
39
|
break;
|
|
40
40
|
case 8:
|
|
41
|
-
s = "靠帆船提供动力",
|
|
41
|
+
s = "靠帆船提供动力", a = "Sailing";
|
|
42
42
|
break;
|
|
43
43
|
default:
|
|
44
|
-
s = "未定义",
|
|
44
|
+
s = "未定义", a = "Undefined";
|
|
45
45
|
}
|
|
46
|
-
return { labelCn: s, labelEn:
|
|
46
|
+
return { labelCn: s, labelEn: a };
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
class
|
|
50
|
-
constructor(s,
|
|
49
|
+
class G extends V {
|
|
50
|
+
constructor(s, a) {
|
|
51
51
|
super();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
this.clientId = s, this.clientSecret =
|
|
52
|
+
q(this, "clientId");
|
|
53
|
+
q(this, "clientSecret");
|
|
54
|
+
q(this, "token");
|
|
55
|
+
this.clientId = s, this.clientSecret = a;
|
|
56
56
|
}
|
|
57
57
|
async authToken(s = {}) {
|
|
58
|
-
const
|
|
58
|
+
const a = "https://svc.data.myvessel.cn/ada/oauth/token", n = {
|
|
59
59
|
searchParams: {
|
|
60
60
|
client_id: this.clientId,
|
|
61
61
|
client_secret: this.clientSecret,
|
|
62
62
|
grant_type: "client_credentials"
|
|
63
63
|
}
|
|
64
|
-
},
|
|
65
|
-
|
|
66
|
-
accessToken:
|
|
67
|
-
tokenType:
|
|
68
|
-
expiresIn:
|
|
69
|
-
scope:
|
|
70
|
-
jti:
|
|
71
|
-
issuedAt:
|
|
64
|
+
}, o = await Y.post(a, n).json();
|
|
65
|
+
M.info("[%s] fetch access token from: %s - %j", s.requestId, a, o), o.error || (this.token = {
|
|
66
|
+
accessToken: o.access_token,
|
|
67
|
+
tokenType: o.token_type,
|
|
68
|
+
expiresIn: o.expires_in,
|
|
69
|
+
scope: o.scope,
|
|
70
|
+
jti: o.jti,
|
|
71
|
+
issuedAt: p().utc().format()
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
|
-
async realTimePosition(s,
|
|
75
|
-
var d,
|
|
76
|
-
(!this.token ||
|
|
77
|
-
const
|
|
74
|
+
async realTimePosition(s, a = {}) {
|
|
75
|
+
var d, h, f;
|
|
76
|
+
(!this.token || p().diff(p(this.token.issuedAt), "seconds") > ((d = this.token) == null ? void 0 : d.expiresIn) - 300) && await this.authToken(a);
|
|
77
|
+
const n = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit", o = {
|
|
78
78
|
headers: {
|
|
79
|
-
Authorization: `${(
|
|
79
|
+
Authorization: `${(h = this.token) == null ? void 0 : h.tokenType} ${(f = this.token) == null ? void 0 : f.accessToken}`
|
|
80
80
|
},
|
|
81
81
|
searchParams: { mmsi: s }
|
|
82
82
|
};
|
|
83
|
-
|
|
84
|
-
const e = await
|
|
83
|
+
M.info("[%s] fetch realtime position from: %s - %j", a.requestId, n, o);
|
|
84
|
+
const e = await Y.get(n, o).json();
|
|
85
85
|
if (e.code)
|
|
86
|
-
return
|
|
86
|
+
return M.warn("[%s] fetch realtime position failed: %j", a.requestId, n, { message: e.message, status: e.status, code: e.code }), e;
|
|
87
87
|
const t = e.data;
|
|
88
|
-
for (const
|
|
89
|
-
!isNaN(t[
|
|
90
|
-
const
|
|
88
|
+
for (const m in t)
|
|
89
|
+
!isNaN(t[m]) && Number(t[m]) !== 1 / 0 && (t[m] = Number(t[m]));
|
|
90
|
+
const r = p(`${t.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
91
91
|
return {
|
|
92
92
|
mmsi: t.mmsi,
|
|
93
93
|
name: t.vesselName,
|
|
@@ -104,88 +104,87 @@ class L extends v {
|
|
|
104
104
|
rot: t.rot,
|
|
105
105
|
eta: t.eta,
|
|
106
106
|
destination: t.dest,
|
|
107
|
-
positionTime:
|
|
107
|
+
positionTime: r.unix(),
|
|
108
108
|
status: t.status,
|
|
109
109
|
labelCn: t.statusNameCn,
|
|
110
110
|
labelEn: t.statusNameEn,
|
|
111
111
|
method: "position",
|
|
112
112
|
vendor: "myVessel",
|
|
113
|
-
utc:
|
|
113
|
+
utc: r.utc().format()
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
|
-
async trajectory(s,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const m = {
|
|
116
|
+
async trajectory(s, a, n, o, e = !0, t = {}) {
|
|
117
|
+
(!this.token || p().diff(p(this.token.issuedAt), "seconds") > this.token.expiresIn - 300) && await this.authToken(t);
|
|
118
|
+
const r = await this.realTimePosition(s, t), i = p(a), d = p(n), h = [];
|
|
119
|
+
for (; d.diff(i, "day", !0) > 30; )
|
|
120
|
+
await this.trajectoryIn30Day(s, i, i.clone().add(30, "day"), r, o, h, t), i.add(30, "day");
|
|
121
|
+
return await this.trajectoryIn30Day(s, i, d, r, o, h, t), h;
|
|
122
|
+
}
|
|
123
|
+
async trajectoryIn30Day(s, a, n, o, e, t, r = {}) {
|
|
124
|
+
var u, b, w, k, v;
|
|
125
|
+
const i = "https://svc.data.myvessel.cn/sdc/v1/vessels/status/track", d = {
|
|
127
126
|
headers: {
|
|
128
|
-
Authorization: `${(
|
|
127
|
+
Authorization: `${(u = this.token) == null ? void 0 : u.tokenType} ${(b = this.token) == null ? void 0 : b.accessToken}`
|
|
129
128
|
},
|
|
130
129
|
json: {
|
|
131
130
|
mmsi: s,
|
|
132
|
-
startTime:
|
|
133
|
-
endTime:
|
|
131
|
+
startTime: a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),
|
|
132
|
+
endTime: n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")
|
|
134
133
|
}
|
|
135
134
|
};
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
if (
|
|
139
|
-
return
|
|
140
|
-
let
|
|
141
|
-
const
|
|
142
|
-
return
|
|
143
|
-
for (const N in
|
|
144
|
-
!isNaN(
|
|
145
|
-
const
|
|
146
|
-
mmsi:
|
|
147
|
-
imo:
|
|
148
|
-
lat:
|
|
149
|
-
lng:
|
|
150
|
-
sog:
|
|
151
|
-
cog:
|
|
152
|
-
hdg:
|
|
153
|
-
draught:
|
|
154
|
-
status:
|
|
155
|
-
eta:
|
|
156
|
-
destination:
|
|
157
|
-
positionTime:
|
|
158
|
-
labelCn:
|
|
159
|
-
labelEn:
|
|
135
|
+
M.info("[%s] fetch trajectory from: %s - %j", r.requestId, i, d);
|
|
136
|
+
const h = await Y.post(i, d).json();
|
|
137
|
+
if (h.code)
|
|
138
|
+
return M.warn("[%s] fetch trajectory failed: %j", r.requestId, i, { message: h.message, status: h.status, code: h.code }), h;
|
|
139
|
+
let f = -1;
|
|
140
|
+
const m = p(`${(k = (w = h.data) == null ? void 0 : w[0]) == null ? void 0 : k.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
141
|
+
return (v = h.data) == null || v.forEach((g) => {
|
|
142
|
+
for (const N in g)
|
|
143
|
+
!isNaN(g[N]) && Number(g[N]) !== 1 / 0 && (g[N] = Number(g[N]));
|
|
144
|
+
const I = p(`${g.postime} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00"), S = g.eta ? p(`${g.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00") : void 0, l = g.status, { labelCn: H, labelEn: _ } = this.parseStatus(l), R = {
|
|
145
|
+
mmsi: g.mmsi,
|
|
146
|
+
imo: o == null ? void 0 : o.imo,
|
|
147
|
+
lat: g.lat,
|
|
148
|
+
lng: g.lon,
|
|
149
|
+
sog: g.sog,
|
|
150
|
+
cog: g.cog,
|
|
151
|
+
hdg: g.hdg,
|
|
152
|
+
draught: g.draught,
|
|
153
|
+
status: l,
|
|
154
|
+
eta: S == null ? void 0 : S.unix(),
|
|
155
|
+
destination: g.dest,
|
|
156
|
+
positionTime: I.unix(),
|
|
157
|
+
labelCn: H,
|
|
158
|
+
labelEn: _,
|
|
160
159
|
method: "trajectory",
|
|
161
160
|
vendor: "myVessel",
|
|
162
|
-
utc:
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
}),
|
|
161
|
+
utc: I.utc().format()
|
|
162
|
+
}, E = Math.floor(I.diff(m, "minute", !0) / (e || 1));
|
|
163
|
+
E !== f && (f = E, t.push(R));
|
|
164
|
+
}), t;
|
|
166
165
|
}
|
|
167
166
|
}
|
|
168
|
-
class
|
|
167
|
+
class B extends V {
|
|
169
168
|
constructor(s) {
|
|
170
169
|
super();
|
|
171
|
-
|
|
170
|
+
q(this, "token");
|
|
172
171
|
this.token = s;
|
|
173
172
|
}
|
|
174
|
-
async realTimePosition(s,
|
|
175
|
-
const
|
|
173
|
+
async realTimePosition(s, a = {}) {
|
|
174
|
+
const n = "https://api.hifleet.com/position/position/get/token", o = {
|
|
176
175
|
searchParams: {
|
|
177
176
|
mmsi: s,
|
|
178
177
|
usertoken: this.token
|
|
179
178
|
}
|
|
180
|
-
}, e = await
|
|
181
|
-
|
|
179
|
+
}, e = await Y.post(n, o).json();
|
|
180
|
+
M.info("[%s] fetch realtime position from: %s - %j", a.requestId, n, o);
|
|
182
181
|
const t = e == null ? void 0 : e.list;
|
|
183
182
|
if (!t)
|
|
184
|
-
return
|
|
185
|
-
for (const
|
|
186
|
-
!isNaN(t[
|
|
183
|
+
return M.warn("[%s] fetch realtime position failed: %j", a.requestId, n, e), e;
|
|
184
|
+
for (const m in t)
|
|
185
|
+
!isNaN(t[m]) && Number(t[m]) !== 1 / 0 && (t[m] = Number(t[m]));
|
|
187
186
|
t.status = t.sp > 3 ? 0 : 1;
|
|
188
|
-
const
|
|
187
|
+
const r = t.status, { labelCn: i, labelEn: d } = this.parseStatus(r), h = p(`${t.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
189
188
|
return {
|
|
190
189
|
mmsi: t.m,
|
|
191
190
|
name: t.n,
|
|
@@ -200,20 +199,20 @@ class K extends v {
|
|
|
200
199
|
cog: t.co,
|
|
201
200
|
hdg: t.h,
|
|
202
201
|
rot: isNaN(t.rot) ? 0 : t.rot,
|
|
203
|
-
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(t.eta) ?
|
|
202
|
+
eta: /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(t.eta) ? p(`${t.eta} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00").unix() : void 0,
|
|
204
203
|
destination: t.destination,
|
|
205
|
-
positionTime:
|
|
206
|
-
utc:
|
|
207
|
-
status:
|
|
208
|
-
labelCn:
|
|
204
|
+
positionTime: h.unix(),
|
|
205
|
+
utc: h.utc().format(),
|
|
206
|
+
status: r,
|
|
207
|
+
labelCn: i,
|
|
209
208
|
labelEn: d,
|
|
210
209
|
method: "position",
|
|
211
210
|
vendor: "hifleet"
|
|
212
211
|
};
|
|
213
212
|
}
|
|
214
|
-
async search(s,
|
|
215
|
-
let
|
|
216
|
-
const
|
|
213
|
+
async search(s, a = {}) {
|
|
214
|
+
let n = "https://www.hifleet.com/hifleetapi/searchVesselOL.do";
|
|
215
|
+
const o = {
|
|
217
216
|
searchParams: {
|
|
218
217
|
keyword: s
|
|
219
218
|
},
|
|
@@ -223,10 +222,10 @@ class K extends v {
|
|
|
223
222
|
Host: "www.hifleet.com"
|
|
224
223
|
}
|
|
225
224
|
};
|
|
226
|
-
let e = await
|
|
227
|
-
|
|
228
|
-
for (const
|
|
229
|
-
!isNaN(e[
|
|
225
|
+
let e = await Y.post(n, o).json();
|
|
226
|
+
M.info("[%s] fetch vessel props from: %s - %j", a.requestId, n, o), e instanceof Array && (e = e[0]);
|
|
227
|
+
for (const r in e)
|
|
228
|
+
!isNaN(e[r]) && Number(e[r]) !== 1 / 0 && (e[r] = Number(e[r]));
|
|
230
229
|
const t = {
|
|
231
230
|
mmsi: e.m,
|
|
232
231
|
name: e.n,
|
|
@@ -236,79 +235,79 @@ class K extends v {
|
|
|
236
235
|
breadth: e.b,
|
|
237
236
|
draught: e.dr
|
|
238
237
|
};
|
|
239
|
-
return
|
|
238
|
+
return n = "https://www.hifleet.com/hifleetapi/sameShipSearch.do", e = await Y.post(n, o).json(), M.info("[%s] fetch vessel dead weight from: %s - %j", a.requestId, n, o), e instanceof Array && (e = e[0]), e && (t.deadweight = Number(e.dwt)), t;
|
|
240
239
|
}
|
|
241
|
-
async trajectory(s,
|
|
242
|
-
var
|
|
243
|
-
const
|
|
244
|
-
let
|
|
245
|
-
const d =
|
|
240
|
+
async trajectory(s, a, n, o, e = !0, t = {}) {
|
|
241
|
+
var g, I, S;
|
|
242
|
+
const r = await this.realTimePosition(s, t);
|
|
243
|
+
let i = p(a);
|
|
244
|
+
const d = p(n), h = p();
|
|
246
245
|
if (e) {
|
|
247
|
-
let
|
|
248
|
-
|
|
246
|
+
let l = d.diff(i, "d", !0);
|
|
247
|
+
l < 0 ? i = d.clone().subtract(40, "d") : l < 30 ? i.subtract(10, "d") : l < 60 ? i.subtract(5, "d") : i = d.clone().subtract(80, "d"), l = h.diff(d, "d", !0), d.add(l > 10 ? 240 : l * 24, "h");
|
|
249
248
|
}
|
|
250
|
-
const
|
|
249
|
+
const f = {
|
|
251
250
|
searchParams: {
|
|
252
251
|
endtime: d.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
253
|
-
starttime:
|
|
252
|
+
starttime: i.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),
|
|
254
253
|
mmsi: s,
|
|
255
254
|
usertoken: this.token
|
|
256
255
|
}
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
let
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
let
|
|
263
|
-
const
|
|
264
|
-
for (const
|
|
265
|
-
for (const
|
|
266
|
-
!isNaN(
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
const { labelEn:
|
|
270
|
-
mmsi:
|
|
271
|
-
name:
|
|
272
|
-
imo:
|
|
273
|
-
lat:
|
|
274
|
-
lng:
|
|
275
|
-
draught:
|
|
276
|
-
sog:
|
|
277
|
-
cog:
|
|
278
|
-
hdg:
|
|
279
|
-
positionTime:
|
|
280
|
-
utc:
|
|
281
|
-
status:
|
|
282
|
-
labelCn:
|
|
283
|
-
labelEn:
|
|
256
|
+
}, m = "https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token", u = await Y.get(m, f).json();
|
|
257
|
+
M.info("[%s] fetch trajectory from: %s - %j", t.requestId, m, f);
|
|
258
|
+
let b;
|
|
259
|
+
u && (b = ((I = (g = u.ships) == null ? void 0 : g.offors) == null ? void 0 : I.ship) || [], b.length || M.warn("[%s] fetch trajectory failed: %j", t.requestId, u));
|
|
260
|
+
const w = [];
|
|
261
|
+
let k = -1;
|
|
262
|
+
const v = p(`${(S = b == null ? void 0 : b[0]) == null ? void 0 : S.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
263
|
+
for (const l of b) {
|
|
264
|
+
for (const x in l)
|
|
265
|
+
!isNaN(l[x]) && Number(l[x]) !== 1 / 0 && (l[x] = Number(l[x]));
|
|
266
|
+
const H = p(`${l.ti} +08:00`, "YYYY-MM-DD HH:mm:ss +08:00");
|
|
267
|
+
l.status = l.sp > 4 ? 0 : 1;
|
|
268
|
+
const { labelEn: _, labelCn: R } = this.parseStatus(l.status), E = {
|
|
269
|
+
mmsi: l.m,
|
|
270
|
+
name: l.n,
|
|
271
|
+
imo: r == null ? void 0 : r.imo,
|
|
272
|
+
lat: l.la,
|
|
273
|
+
lng: l.lo,
|
|
274
|
+
draught: l.draught,
|
|
275
|
+
sog: l.sp,
|
|
276
|
+
cog: l.co,
|
|
277
|
+
hdg: l.hdg,
|
|
278
|
+
positionTime: H.unix(),
|
|
279
|
+
utc: H.utc().format(),
|
|
280
|
+
status: l.status,
|
|
281
|
+
labelCn: R,
|
|
282
|
+
labelEn: _,
|
|
284
283
|
method: "trajectory",
|
|
285
284
|
vendor: "hifleet"
|
|
286
|
-
},
|
|
287
|
-
|
|
285
|
+
}, N = Math.floor(H.diff(v, "minute", !0) / (o || 1));
|
|
286
|
+
N !== k && (k = N, w.push(E));
|
|
288
287
|
}
|
|
289
|
-
return
|
|
288
|
+
return w;
|
|
290
289
|
}
|
|
291
290
|
}
|
|
292
|
-
class
|
|
291
|
+
class U extends V {
|
|
293
292
|
constructor(s) {
|
|
294
293
|
super();
|
|
295
|
-
|
|
294
|
+
q(this, "token");
|
|
296
295
|
this.token = s;
|
|
297
296
|
}
|
|
298
|
-
async realTimePosition(s,
|
|
299
|
-
const
|
|
297
|
+
async realTimePosition(s, a = {}) {
|
|
298
|
+
const n = {
|
|
300
299
|
searchParams: {
|
|
301
300
|
id: s,
|
|
302
301
|
k: this.token,
|
|
303
302
|
enc: 1
|
|
304
303
|
}
|
|
305
|
-
},
|
|
306
|
-
if (
|
|
304
|
+
}, o = "https://api.shipxy.com/apicall/GetSingleShip", e = await Y.get(o, n).json();
|
|
305
|
+
if (M.info("[%s] fetch realtime position from: %s - %j", a.requestId, o, n), (e == null ? void 0 : e.status) !== 0)
|
|
307
306
|
return e;
|
|
308
307
|
const t = e.data[0];
|
|
309
|
-
for (const
|
|
310
|
-
!isNaN(t[
|
|
311
|
-
const { labelCn:
|
|
308
|
+
for (const f in t)
|
|
309
|
+
!isNaN(t[f]) && Number(t[f]) !== 1 / 0 && (t[f] = Number(t[f]));
|
|
310
|
+
const { labelCn: r, labelEn: i } = await this.parseStatus(t.navistat), d = p.unix(t.lasttime);
|
|
312
311
|
return {
|
|
313
312
|
mmsi: t.ShipID,
|
|
314
313
|
name: t.name,
|
|
@@ -326,167 +325,229 @@ class V extends v {
|
|
|
326
325
|
positionTime: t.lasttime,
|
|
327
326
|
utc: d.utc().format(),
|
|
328
327
|
status: t.navistat,
|
|
329
|
-
labelEn:
|
|
330
|
-
labelCn:
|
|
328
|
+
labelEn: i,
|
|
329
|
+
labelCn: r,
|
|
331
330
|
method: "position",
|
|
332
331
|
vendor: "shipxy"
|
|
333
332
|
};
|
|
334
333
|
}
|
|
335
|
-
async trajectory(s,
|
|
336
|
-
var
|
|
337
|
-
const
|
|
334
|
+
async trajectory(s, a, n, o, e = !0, t = {}) {
|
|
335
|
+
var v;
|
|
336
|
+
const r = await this.realTimePosition(s, t), i = p(a), d = p(n), h = "https://api.shipxy.com/apicall/GetShipTrack", f = {
|
|
338
337
|
searchParams: {
|
|
339
338
|
id: s,
|
|
340
339
|
k: this.token,
|
|
341
340
|
enc: 1,
|
|
342
341
|
cut: 0,
|
|
343
|
-
btm:
|
|
342
|
+
btm: i.unix(),
|
|
344
343
|
etm: d.unix()
|
|
345
344
|
}
|
|
346
|
-
},
|
|
347
|
-
if (
|
|
348
|
-
return
|
|
349
|
-
const
|
|
350
|
-
let
|
|
351
|
-
for (const
|
|
352
|
-
const
|
|
353
|
-
imo:
|
|
345
|
+
}, m = await Y.get(h, f).json();
|
|
346
|
+
if (M.info("[%s] fetch trajectory from: %s - %j", t.requestId, h, f), (m == null ? void 0 : m.status) !== 0)
|
|
347
|
+
return m;
|
|
348
|
+
const u = m == null ? void 0 : m.points, b = [], w = p.unix((v = u[0]) == null ? void 0 : v.utc);
|
|
349
|
+
let k = -1;
|
|
350
|
+
for (const g of u) {
|
|
351
|
+
const I = p.unix(g.utc), S = {
|
|
352
|
+
imo: r == null ? void 0 : r.imo,
|
|
354
353
|
mmsi: s,
|
|
355
|
-
sog: Math.round(
|
|
356
|
-
cog: Math.round(
|
|
357
|
-
lat: Math.round(
|
|
358
|
-
lng: Math.round(
|
|
359
|
-
positionTime:
|
|
360
|
-
utc:
|
|
354
|
+
sog: Math.round(g.sog * 3600 / 1e3 / 1852 * 100) / 100,
|
|
355
|
+
cog: Math.round(g.cog / 100 * 100) / 100,
|
|
356
|
+
lat: Math.round(g.lat / 1e6 * 1e5) / 1e5,
|
|
357
|
+
lng: Math.round(g.lon / 1e6 * 1e5) / 1e5,
|
|
358
|
+
positionTime: I.unix(),
|
|
359
|
+
utc: I.utc().format(),
|
|
361
360
|
method: "trajectory",
|
|
362
361
|
vendor: "shipxy"
|
|
363
|
-
},
|
|
364
|
-
|
|
362
|
+
}, l = Math.floor(I.diff(w, "minute", !0) / (o || 1));
|
|
363
|
+
l !== k && (k = l, b.push(S));
|
|
365
364
|
}
|
|
366
|
-
return
|
|
365
|
+
return b;
|
|
367
366
|
}
|
|
368
367
|
}
|
|
369
|
-
class
|
|
368
|
+
class J extends V {
|
|
370
369
|
constructor(s) {
|
|
371
370
|
super();
|
|
372
|
-
|
|
371
|
+
q(this, "token");
|
|
373
372
|
this.token = s;
|
|
374
373
|
}
|
|
375
|
-
async getShipId(s,
|
|
376
|
-
const
|
|
374
|
+
async getShipId(s, a = {}) {
|
|
375
|
+
const n = {
|
|
377
376
|
headers: {
|
|
378
377
|
appKey: this.token
|
|
379
378
|
},
|
|
380
379
|
json: {
|
|
381
380
|
mmsiList: s
|
|
382
381
|
}
|
|
383
|
-
},
|
|
384
|
-
return
|
|
382
|
+
}, o = "https://api3.myships.com/sp/ships/getShipIdByMMSI", e = await Y.post(o, n).json();
|
|
383
|
+
return M.info("[%s] fetch ship id from: %s - %j", a.requestId, o, n), e.code !== "0" ? e : e.data[0].shipId;
|
|
385
384
|
}
|
|
386
|
-
async getShipInfo(s,
|
|
387
|
-
const
|
|
385
|
+
async getShipInfo(s, a = {}) {
|
|
386
|
+
const n = {
|
|
388
387
|
headers: {
|
|
389
388
|
appKey: this.token
|
|
390
389
|
},
|
|
391
390
|
json: {
|
|
392
391
|
shipId: s
|
|
393
392
|
}
|
|
394
|
-
},
|
|
395
|
-
if (
|
|
393
|
+
}, o = "https://api3.myships.com/sp/ships/aissta", e = await Y.post(o, n).json();
|
|
394
|
+
if (M.info("[%s] fetch ship info from: %s - %j", a.requestId, o, n), e.code !== "0")
|
|
396
395
|
return e;
|
|
397
396
|
const t = e.data;
|
|
398
|
-
let
|
|
399
|
-
return s === "407170" && (
|
|
397
|
+
let r = t.imo;
|
|
398
|
+
return s === "407170" && (r = "9198379", M.warn("[%s] ship(%s) imo error: %s, should be %s", a.requestId, s, t.imo, r)), {
|
|
400
399
|
mmsi: t.mmsi,
|
|
401
400
|
name: t.shipnameEn,
|
|
402
|
-
imo:
|
|
401
|
+
imo: r,
|
|
403
402
|
callSign: t.callSign,
|
|
404
403
|
length: t.length,
|
|
405
404
|
width: t.breadth,
|
|
406
405
|
draught: (t.draught || 100) / 10
|
|
407
406
|
};
|
|
408
407
|
}
|
|
409
|
-
async realTimePosition(s,
|
|
410
|
-
const
|
|
408
|
+
async realTimePosition(s, a = {}) {
|
|
409
|
+
const n = await this.getShipId(s, a), o = await this.getShipInfo(n, a), e = {
|
|
411
410
|
headers: {
|
|
412
411
|
appKey: this.token
|
|
413
412
|
},
|
|
414
413
|
json: {
|
|
415
|
-
shipId:
|
|
414
|
+
shipId: n
|
|
416
415
|
}
|
|
417
|
-
}, t = "https://api3.myships.com/sp/ships/position/latest",
|
|
418
|
-
|
|
419
|
-
const
|
|
420
|
-
for (const
|
|
421
|
-
!isNaN(
|
|
422
|
-
const { labelCn: d, labelEn:
|
|
416
|
+
}, t = "https://api3.myships.com/sp/ships/position/latest", r = await Y.post(t, e).json();
|
|
417
|
+
M.info("[%s] fetch realtime position from: %s - %j", a.requestId, t, e);
|
|
418
|
+
const i = r.data[0];
|
|
419
|
+
for (const u in i)
|
|
420
|
+
!isNaN(i[u]) && Number(i[u]) !== 1 / 0 && (i[u] = Number(i[u]));
|
|
421
|
+
const { labelCn: d, labelEn: h } = await this.parseStatus(i.aisNavStatus), f = p.unix(i.posTime);
|
|
423
422
|
return {
|
|
424
|
-
...
|
|
423
|
+
...o,
|
|
425
424
|
mmsi: s,
|
|
426
|
-
lat: Math.round(
|
|
427
|
-
lng: Math.round(
|
|
428
|
-
sog: Math.round(
|
|
429
|
-
cog: Math.round(
|
|
430
|
-
hdg: Math.round(
|
|
431
|
-
rot: Math.round(
|
|
432
|
-
positionTime:
|
|
433
|
-
utc:
|
|
434
|
-
status:
|
|
435
|
-
labelEn:
|
|
425
|
+
lat: Math.round(i.lat / 1e4 / 60 * 1e5) / 1e5,
|
|
426
|
+
lng: Math.round(i.lon / 1e4 / 60 * 1e5) / 1e5,
|
|
427
|
+
sog: Math.round(i.sog / 10 * 100) / 100,
|
|
428
|
+
cog: Math.round(i.cog / 10 * 100) / 100,
|
|
429
|
+
hdg: Math.round(i.heading * 100) / 100,
|
|
430
|
+
rot: Math.round(i.rot * 100) / 100,
|
|
431
|
+
positionTime: i.posTime,
|
|
432
|
+
utc: f.utc().format(),
|
|
433
|
+
status: i.aisNavStatus,
|
|
434
|
+
labelEn: h,
|
|
436
435
|
labelCn: d,
|
|
437
436
|
method: "position",
|
|
438
437
|
vendor: "myship"
|
|
439
438
|
};
|
|
440
439
|
}
|
|
441
|
-
async trajectory(s,
|
|
442
|
-
const
|
|
443
|
-
for (;
|
|
444
|
-
await this.trajectoryIn30Day(d,
|
|
445
|
-
return await this.trajectoryIn30Day(d,
|
|
440
|
+
async trajectory(s, a, n, o, e = !0, t = {}) {
|
|
441
|
+
const r = p(a), i = p(n), d = await this.getShipId(s), h = await this.getShipInfo(d), f = [];
|
|
442
|
+
for (; i.diff(r, "day", !0) > 30; )
|
|
443
|
+
await this.trajectoryIn30Day(d, r.unix(), r.add(30, "day").unix(), h, s, o, f);
|
|
444
|
+
return await this.trajectoryIn30Day(d, r.unix(), i.unix(), h, s, o, f), f;
|
|
446
445
|
}
|
|
447
|
-
async trajectoryIn30Day(s,
|
|
448
|
-
var
|
|
446
|
+
async trajectoryIn30Day(s, a, n, o, e, t, r, i = {}) {
|
|
447
|
+
var w;
|
|
449
448
|
const d = {
|
|
450
449
|
headers: {
|
|
451
450
|
appKey: this.token
|
|
452
451
|
},
|
|
453
452
|
json: {
|
|
454
453
|
shipId: s,
|
|
455
|
-
startTime:
|
|
456
|
-
endTime:
|
|
454
|
+
startTime: a,
|
|
455
|
+
endTime: n
|
|
457
456
|
}
|
|
458
|
-
},
|
|
459
|
-
if (
|
|
460
|
-
return
|
|
461
|
-
const
|
|
462
|
-
for (const
|
|
463
|
-
!isNaN(
|
|
464
|
-
const
|
|
465
|
-
let
|
|
466
|
-
for (const
|
|
467
|
-
const
|
|
468
|
-
imo:
|
|
457
|
+
}, h = "https://api3.myships.com/sp/ships/position/history", f = await Y.post(h, d).json();
|
|
458
|
+
if (M.info("[%s] fetch trajectory from: %s - %j", i.requestId, h, d), f.code !== "0")
|
|
459
|
+
return M.warn("[%s] invoke myship trajectory failed: %j", i.requestId, f), f;
|
|
460
|
+
const m = f.data;
|
|
461
|
+
for (const k in m)
|
|
462
|
+
!isNaN(m[k]) && Number(m[k]) !== 1 / 0 && (m[k] = Number(m[k]));
|
|
463
|
+
const u = p.unix((w = m[0]) == null ? void 0 : w.posTime);
|
|
464
|
+
let b = -1;
|
|
465
|
+
for (const k of m) {
|
|
466
|
+
const v = p.unix(k.posTime), g = {
|
|
467
|
+
imo: o == null ? void 0 : o.imo,
|
|
469
468
|
mmsi: e,
|
|
470
|
-
lat: Math.round(
|
|
471
|
-
lng: Math.round(
|
|
472
|
-
sog: Math.round(
|
|
473
|
-
cog: Math.round(
|
|
474
|
-
hdg: Math.round(
|
|
475
|
-
rot: Math.round(
|
|
476
|
-
positionTime:
|
|
477
|
-
utc:
|
|
469
|
+
lat: Math.round(k.lat / 1e4 / 60 * 1e5) / 1e5,
|
|
470
|
+
lng: Math.round(k.lon / 1e4 / 60 * 1e5) / 1e5,
|
|
471
|
+
sog: Math.round(k.sog / 10 * 100) / 100,
|
|
472
|
+
cog: Math.round(k.cog / 10 * 100) / 100,
|
|
473
|
+
hdg: Math.round(k.heading * 100) / 100,
|
|
474
|
+
rot: Math.round(k.rot * 100) / 100,
|
|
475
|
+
positionTime: v.unix(),
|
|
476
|
+
utc: v.utc().format(),
|
|
478
477
|
method: "trajectory",
|
|
479
478
|
vendor: "myship"
|
|
480
|
-
},
|
|
481
|
-
|
|
479
|
+
}, I = Math.floor(v.diff(u, "minute", !0) / (t || 1));
|
|
480
|
+
I !== b && (b = I, r.push(g));
|
|
481
|
+
}
|
|
482
|
+
return r;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
const $ = W.getLogger();
|
|
486
|
+
var K = /* @__PURE__ */ ((j) => (j.NOTICE = "NOTICE", j.WARN = "WARN", j.HEAVY = "HEAVY", j.SEVERE = "SEVERE", j.ERROR = "ERROR", j.FATAL = "FATAL", j))(K || {});
|
|
487
|
+
class Q {
|
|
488
|
+
/**
|
|
489
|
+
* 解析告警规则, 多规则场景
|
|
490
|
+
* @param rule
|
|
491
|
+
* e.g.1 [any;[[>,maxCP,WARN,0,TotCons_VLSFO]];[[!==,0,ERROR,0,TotCons_VLSFO]]]
|
|
492
|
+
* e.g.2 [[>,0,HEAVY,Number.MAX_VALUE],[>,0,SEVERE,Number.MAX_VALUE]]
|
|
493
|
+
*
|
|
494
|
+
* @param options
|
|
495
|
+
*/
|
|
496
|
+
parsePrinciple(c, s = {}) {
|
|
497
|
+
var t, r, i;
|
|
498
|
+
$.info("[%s] parse rule: %s", s.requestId, c);
|
|
499
|
+
const a = new RegExp("(?<=\\[)(.+)(?=\\])", "g"), n = c.match(a) ? (t = c.match(a)) == null ? void 0 : t[0] : void 0, o = n == null ? void 0 : n.split(";");
|
|
500
|
+
if (!o)
|
|
501
|
+
return;
|
|
502
|
+
const e = {};
|
|
503
|
+
for (let d = 0; d < (o == null ? void 0 : o.length); d++) {
|
|
504
|
+
const h = (i = (r = o[d].match(a)) == null ? void 0 : r[0]) == null ? void 0 : i.split("],");
|
|
505
|
+
if (d === 0 && !h)
|
|
506
|
+
e.scope = o[0];
|
|
507
|
+
else if (h)
|
|
508
|
+
for (let f = 0, m = h.length; f < m; f++) {
|
|
509
|
+
const u = this.parseRule(h[f]);
|
|
510
|
+
u && (e[u.level] ? u.key ? e[u.level][u == null ? void 0 : u.key] = u : e[u.level] = u : u.key ? e[u.level] = { [u == null ? void 0 : u.key]: u } : e[u.level] = u);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
return e;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* 解析单一告警规则
|
|
517
|
+
* e.g.1 [>,maxCP,WARN,0,TotCons_VLSFO]
|
|
518
|
+
* @param rule
|
|
519
|
+
* @param options
|
|
520
|
+
*/
|
|
521
|
+
parseRule(c, s = {}) {
|
|
522
|
+
var e;
|
|
523
|
+
$.info("[%s] parse rule: %s", s.requestId, c), c = c.startsWith("[") ? c : `[${c}`, c = c.endsWith("]") ? c : `${c}]`;
|
|
524
|
+
const a = new RegExp("(?<=\\[)(.+?)(?=\\])", "g"), n = (e = c == null ? void 0 : c.match(a)) == null ? void 0 : e[0], o = n == null ? void 0 : n.split(",");
|
|
525
|
+
if (o)
|
|
526
|
+
return { operator: o[0], number: Number(o[1]), level: o[2], time: Number(o[3]), key: o[4] };
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* 检查航路点天气
|
|
530
|
+
* @param sample 航路点
|
|
531
|
+
* @param principle 告警规则
|
|
532
|
+
* @param options
|
|
533
|
+
*/
|
|
534
|
+
checkWeather(c, s, a = {}) {
|
|
535
|
+
var u, b, w, k, v, g, I, S, l, H, _, R, E, N, x;
|
|
536
|
+
let n = 0, o = 0, e = 0, t = 0;
|
|
537
|
+
const r = ((b = (u = s == null ? void 0 : s.SEVERE) == null ? void 0 : u.sigWave) == null ? void 0 : b.number) * 1.6, i = (k = (w = s == null ? void 0 : s.SEVERE) == null ? void 0 : w.sigWave) == null ? void 0 : k.number, d = (g = (v = s == null ? void 0 : s.HEAVY) == null ? void 0 : v.sigWave) == null ? void 0 : g.number, h = ((S = (I = s == null ? void 0 : s.SEVERE) == null ? void 0 : I.wind) == null ? void 0 : S.number) + 2, f = (H = (l = s == null ? void 0 : s.SEVERE) == null ? void 0 : l.wind) == null ? void 0 : H.number, m = (R = (_ = s == null ? void 0 : s.HEAVY) == null ? void 0 : _.wind) == null ? void 0 : R.number;
|
|
538
|
+
for (let A = 1; A < (c == null ? void 0 : c.length); A++) {
|
|
539
|
+
const y = c[A], T = (N = (E = y == null ? void 0 : y.meteo) == null ? void 0 : E.wave) == null ? void 0 : N.sig, D = (x = y == null ? void 0 : y.meteo) == null ? void 0 : x.wind, P = p(y.eta).diff(p(c[A - 1].eta), "hour", !0);
|
|
540
|
+
t = P > t ? P : t, $.info("[%s] check sig.wave: %j", a.requestId, { ...T, dgThd4Wv: r, svThd4Wv: i, hvThd4Wv: d }), (T == null ? void 0 : T.height) >= r ? y.isDangerous = !0 : (T == null ? void 0 : T.height) >= i ? y.isSevere = !0 : (T == null ? void 0 : T.height) >= d && (y.isHeavy = !0), $.info("[%s] check wind: %j", a.requestId, { ...D, dgThd4Wd: h, svThd4Wd: f, hvThd4Wd: m }), (D == null ? void 0 : D.scale) >= h ? (y.isDangerous = !0, delete y.isSevere, delete y.isHeavy) : (D == null ? void 0 : D.scale) > f ? (y.isDangerous || (y.isSevere = !0), delete y.isHeavy) : (D == null ? void 0 : D.scale) === m && !y.isDangerous && !y.isSevere && (y.isHeavy = !0), n += y.isDangerous ? P : 0, o += y.isSevere ? P : 0, e += y.isHeavy ? P : 0, A === 1 && (c[0].isDangerous = y.isDangerous, c[0].isSevere = y.isSevere, c[0].isHeavy = y.isHeavy);
|
|
482
541
|
}
|
|
483
|
-
return
|
|
542
|
+
return n = Math.round(n * 100) / 100, o = Math.round(o * 100) / 100, e = Math.round(e * 100) / 100, t = Math.round(t), { sample: c, dangerous: n, severe: o, heavy: e, step: t < 3 ? 3 : t };
|
|
484
543
|
}
|
|
485
544
|
}
|
|
486
545
|
export {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
546
|
+
V as AISImpl,
|
|
547
|
+
Q as AlertHelper,
|
|
548
|
+
K as AlertLevel,
|
|
549
|
+
B as HifleetImpl,
|
|
550
|
+
J as MyShipImpl,
|
|
551
|
+
G as MyVesselImpl,
|
|
552
|
+
U as ShipxyImpl
|
|
492
553
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(y,p){typeof exports=="object"&&typeof module<"u"?p(exports,require("got"),require("log4js"),require("moment")):typeof define=="function"&&define.amd?define(["exports","got","log4js","moment"],p):(y=typeof globalThis<"u"?globalThis:y||self,p(y["idm-plugin-rabbitmq"]={},y.got,y.log4js,y.moment))})(this,function(y,p,x,l){"use strict";var V=Object.defineProperty;var K=(y,p,x)=>p in y?V(y,p,{enumerable:!0,configurable:!0,writable:!0,value:x}):y[p]=x;var q=(y,p,x)=>(K(y,typeof p!="symbol"?p+"":p,x),x);function $(w){const S=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(w){for(const s in w)if(s!=="default"){const i=Object.getOwnPropertyDescriptor(w,s);Object.defineProperty(S,s,i.get?i:{enumerable:!0,get:()=>w[s]})}}return S.default=w,Object.freeze(S)}const j=$(x).getLogger();class v{parseStatus(S){let s,i;switch(S){case 0:s="在航(主机推动)",i="The engine is in use";break;case 1:s="锚泊",i="Anchored";break;case 2:s="失控",i="Not operated";break;case 3:s="操纵受限",i="Limited airworthiness";break;case 4:s="吃水受限",i="Limited by ship's draft";break;case 5:s="靠泊",i="Mooring";break;case 6:s="搁浅",i="Stranded";break;case 7:s="捕捞作业",i="Engaged in fishing";break;case 8:s="靠帆船提供动力",i="Sailing";break;default:s="未定义",i="Undefined"}return{labelCn:s,labelEn:i}}}class E extends v{constructor(s,i){super();q(this,"clientId");q(this,"clientSecret");q(this,"token");this.clientId=s,this.clientSecret=i}async authToken(s={}){const i="https://svc.data.myvessel.cn/ada/oauth/token",r={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await p.post(i,r).json();j.info("[%s] fetch access token from: %s - %j",s.requestId,i,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:l().utc().format()})}async realTimePosition(s,i={}){var h,m,f;(!this.token||l().diff(l(this.token.issuedAt),"seconds")>((h=this.token)==null?void 0:h.expiresIn)-300)&&await this.authToken(i);const r="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(m=this.token)==null?void 0:m.tokenType} ${(f=this.token)==null?void 0:f.accessToken}`},searchParams:{mmsi:s}};j.info("[%s] fetch realtime position from: %s - %j",i.requestId,r,o);const e=await p.get(r,o).json();if(e.code)return j.warn("[%s] fetch realtime position failed: %j",i.requestId,r,{message:e.message,status:e.status,code:e.code}),e;const t=e.data;for(const c in t)!isNaN(t[c])&&Number(t[c])!==1/0&&(t[c]=Number(t[c]));const a=l(`${t.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:t.mmsi,name:t.vesselName,imo:t.imo,callSign:t.callsign,lat:t.lat,lng:t.lon,length:t.length,width:t.width,draught:t.currDraught,sog:t.sog,cog:t.cog,hdg:t.hdg,rot:t.rot,eta:t.eta,destination:t.dest,positionTime:a.unix(),status:t.status,labelCn:t.statusNameCn,labelEn:t.statusNameEn,method:"position",vendor:"myVessel",utc:a.utc().format()}}async trajectory(s,i,r,o,e=!0,t={}){var g,I,M;(!this.token||l().diff(l(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(t);const a=await this.realTimePosition(s,t),n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track";let h=l(i);const m=l(r);if(e){const d=m.diff(h,"d",!0);(d<0||d>30)&&(h=m.clone().subtract(30,"d"))}const f={headers:{Authorization:`${(g=this.token)==null?void 0:g.tokenType} ${(I=this.token)==null?void 0:I.accessToken}`},json:{mmsi:s,startTime:h.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:m.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};j.info("[%s] fetch trajectory from: %s - %j",t.requestId,n,f);const c=await p.post(n,f).json();if(c.code)return j.warn("[%s] fetch trajectory failed: %j",t.requestId,n,{message:c.message,status:c.status,code:c.code}),c;let k=-1;const b=l(`${(M=c.data[0])==null?void 0:M.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),Y=[];return c.data.forEach(d=>{for(const N in d)!isNaN(d[N])&&Number(d[N])!==1/0&&(d[N]=Number(d[N]));const T=l(`${d.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),u=d.eta?l(`${d.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,D=d.status,{labelCn:_,labelEn:P}=this.parseStatus(D),O={mmsi:d.mmsi,imo:a==null?void 0:a.imo,lat:d.lat,lng:d.lon,sog:d.sog,cog:d.cog,hdg:d.hdg,draught:d.draught,status:D,eta:u==null?void 0:u.unix(),destination:d.dest,positionTime:T.unix(),labelCn:_,labelEn:P,method:"trajectory",vendor:"myVessel",utc:T.utc().format()},H=Math.floor(T.diff(b,"minute",!0)/(o||1));H!==k&&(k=H,Y.push(O))}),Y}}class A extends v{constructor(s){super();q(this,"token");this.token=s}async realTimePosition(s,i={}){const r="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:s,usertoken:this.token}},e=await p.post(r,o).json();j.info("[%s] fetch realtime position from: %s - %j",i.requestId,r,o);const t=e==null?void 0:e.list;if(!t)return j.warn("[%s] fetch realtime position failed: %j",i.requestId,r,e),e;for(const c in t)!isNaN(t[c])&&Number(t[c])!==1/0&&(t[c]=Number(t[c]));t.status=t.sp>3?0:1;const a=t.status,{labelCn:n,labelEn:h}=this.parseStatus(a),m=l(`${t.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:t.m,name:t.n,imo:t.imonumber,callSign:t.callsign,lat:Math.round(t.la/60*1e5)/1e5,lng:Math.round(t.lo/60*1e5)/1e5,length:t.l,width:t.w,draught:t.draught,sog:t.sp,cog:t.co,hdg:t.h,rot:isNaN(t.rot)?0:t.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(t.eta)?l(`${t.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:t.destination,positionTime:m.unix(),utc:m.utc().format(),status:a,labelCn:n,labelEn:h,method:"position",vendor:"hifleet"}}async search(s,i={}){let r="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:s},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let e=await p.post(r,o).json();j.info("[%s] fetch vessel props from: %s - %j",i.requestId,r,o),e instanceof Array&&(e=e[0]);for(const a in e)!isNaN(e[a])&&Number(e[a])!==1/0&&(e[a]=Number(e[a]));const t={mmsi:e.m,name:e.n,imo:e.i,callSign:e.c,length:e.l,breadth:e.b,draught:e.dr};return r="https://www.hifleet.com/hifleetapi/sameShipSearch.do",e=await p.post(r,o).json(),j.info("[%s] fetch vessel dead weight from: %s - %j",i.requestId,r,o),e instanceof Array&&(e=e[0]),e&&(t.deadweight=Number(e.dwt)),t}async trajectory(s,i,r,o,e=!0,t={}){var M,d,T;const a=await this.realTimePosition(s,t);let n=l(i);const h=l(r),m=l();if(e){let u=h.diff(n,"d",!0);u<0?n=h.clone().subtract(40,"d"):u<30?n.subtract(10,"d"):u<60?n.subtract(5,"d"):n=h.clone().subtract(80,"d"),u=m.diff(h,"d",!0),h.add(u>10?240:u*24,"h")}const f={searchParams:{endtime:h.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:n.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:s,usertoken:this.token}},c="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",k=await p.get(c,f).json();j.info("[%s] fetch trajectory from: %s - %j",t.requestId,c,f);let b;k&&(b=((d=(M=k.ships)==null?void 0:M.offors)==null?void 0:d.ship)||[],b.length||j.warn("[%s] fetch trajectory failed: %j",t.requestId,k));const Y=[];let g=-1;const I=l(`${(T=b==null?void 0:b[0])==null?void 0:T.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const u of b){for(const N in u)!isNaN(u[N])&&Number(u[N])!==1/0&&(u[N]=Number(u[N]));const D=l(`${u.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");u.status=u.sp>4?0:1;const{labelEn:_,labelCn:P}=this.parseStatus(u.status),O={mmsi:u.m,name:u.n,imo:a==null?void 0:a.imo,lat:u.la,lng:u.lo,draught:u.draught,sog:u.sp,cog:u.co,hdg:u.hdg,positionTime:D.unix(),utc:D.utc().format(),status:u.status,labelCn:P,labelEn:_,method:"trajectory",vendor:"hifleet"},H=Math.floor(D.diff(I,"minute",!0)/(o||1));H!==g&&(g=H,Y.push(O))}return Y}}class C extends v{constructor(s){super();q(this,"token");this.token=s}async realTimePosition(s,i={}){const r={searchParams:{id:s,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",e=await p.get(o,r).json();if(j.info("[%s] fetch realtime position from: %s - %j",i.requestId,o,r),(e==null?void 0:e.status)!==0)return e;const t=e.data[0];for(const f in t)!isNaN(t[f])&&Number(t[f])!==1/0&&(t[f]=Number(t[f]));const{labelCn:a,labelEn:n}=await this.parseStatus(t.navistat),h=l.unix(t.lasttime);return{mmsi:t.ShipID,name:t.name,imo:t.imo,callSign:t.callsign,lat:Math.round(t.lat/1e6*1e5)/1e5,lng:Math.round(t.lon/1e6*1e5)/1e5,length:Math.round(t.length/10*100)/100,width:Math.round(t.width/10*100)/100,draught:Math.round(t.draught/1e3*100)/100,sog:Math.round(t.sog*3600/1e3/1852*100)/100,cog:Math.round(t.cog/100*100)/100,hdg:Math.round(t.hdg/100*100)/100,rot:Math.round(t.rot/100*100)/100,positionTime:t.lasttime,utc:h.utc().format(),status:t.navistat,labelEn:n,labelCn:a,method:"position",vendor:"shipxy"}}async trajectory(s,i,r,o,e=!0,t={}){var I;const a=await this.realTimePosition(s,t),n=l(i),h=l(r),m="https://api.shipxy.com/apicall/GetShipTrack",f={searchParams:{id:s,k:this.token,enc:1,cut:0,btm:n.unix(),etm:h.unix()}},c=await p.get(m,f).json();if(j.info("[%s] fetch trajectory from: %s - %j",t.requestId,m,f),(c==null?void 0:c.status)!==0)return c;const k=c==null?void 0:c.points,b=[],Y=l.unix((I=k[0])==null?void 0:I.utc);let g=-1;for(const M of k){const d=l.unix(M.utc),T={imo:a==null?void 0:a.imo,mmsi:s,sog:Math.round(M.sog*3600/1e3/1852*100)/100,cog:Math.round(M.cog/100*100)/100,lat:Math.round(M.lat/1e6*1e5)/1e5,lng:Math.round(M.lon/1e6*1e5)/1e5,positionTime:d.unix(),utc:d.utc().format(),method:"trajectory",vendor:"shipxy"},u=Math.floor(d.diff(Y,"minute",!0)/(o||1));u!==g&&(g=u,b.push(T))}return b}}class L extends v{constructor(s){super();q(this,"token");this.token=s}async getShipId(s,i={}){const r={headers:{appKey:this.token},json:{mmsiList:s}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",e=await p.post(o,r).json();return j.info("[%s] fetch ship id from: %s - %j",i.requestId,o,r),e.code!=="0"?e:e.data[0].shipId}async getShipInfo(s,i={}){const r={headers:{appKey:this.token},json:{shipId:s}},o="https://api3.myships.com/sp/ships/aissta",e=await p.post(o,r).json();if(j.info("[%s] fetch ship info from: %s - %j",i.requestId,o,r),e.code!=="0")return e;const t=e.data;let a=t.imo;return s==="407170"&&(a="9198379",j.warn("[%s] ship(%s) imo error: %s, should be %s",i.requestId,s,t.imo,a)),{mmsi:t.mmsi,name:t.shipnameEn,imo:a,callSign:t.callSign,length:t.length,width:t.breadth,draught:(t.draught||100)/10}}async realTimePosition(s,i={}){const r=await this.getShipId(s,i),o=await this.getShipInfo(r,i),e={headers:{appKey:this.token},json:{shipId:r}},t="https://api3.myships.com/sp/ships/position/latest",a=await p.post(t,e).json();j.info("[%s] fetch realtime position from: %s - %j",i.requestId,t,e);const n=a.data[0];for(const k in n)!isNaN(n[k])&&Number(n[k])!==1/0&&(n[k]=Number(n[k]));const{labelCn:h,labelEn:m}=await this.parseStatus(n.aisNavStatus),f=l.unix(n.posTime);return{...o,mmsi:s,lat:Math.round(n.lat/1e4/60*1e5)/1e5,lng:Math.round(n.lon/1e4/60*1e5)/1e5,sog:Math.round(n.sog/10*100)/100,cog:Math.round(n.cog/10*100)/100,hdg:Math.round(n.heading*100)/100,rot:Math.round(n.rot*100)/100,positionTime:n.posTime,utc:f.utc().format(),status:n.aisNavStatus,labelEn:m,labelCn:h,method:"position",vendor:"myship"}}async trajectory(s,i,r,o,e=!0,t={}){const a=l(i),n=l(r),h=await this.getShipId(s),m=await this.getShipInfo(h),f=[];for(;n.diff(a,"day",!0)>30;)await this.trajectoryIn30Day(h,a.unix(),a.add(30,"day").unix(),m,s,o,f);return await this.trajectoryIn30Day(h,a.unix(),n.unix(),m,s,o,f),f}async trajectoryIn30Day(s,i,r,o,e,t,a,n={}){var Y;const h={headers:{appKey:this.token},json:{shipId:s,startTime:i,endTime:r}},m="https://api3.myships.com/sp/ships/position/history",f=await p.post(m,h).json();if(j.info("[%s] fetch trajectory from: %s - %j",n.requestId,m,h),f.code!=="0")return j.warn("[%s] invoke myship trajectory failed: %j",n.requestId,f),f;const c=f.data;for(const g in c)!isNaN(c[g])&&Number(c[g])!==1/0&&(c[g]=Number(c[g]));const k=l.unix((Y=c[0])==null?void 0:Y.posTime);let b=-1;for(const g of c){const I=l.unix(g.posTime),M={imo:o==null?void 0:o.imo,mmsi:e,lat:Math.round(g.lat/1e4/60*1e5)/1e5,lng:Math.round(g.lon/1e4/60*1e5)/1e5,sog:Math.round(g.sog/10*100)/100,cog:Math.round(g.cog/10*100)/100,hdg:Math.round(g.heading*100)/100,rot:Math.round(g.rot*100)/100,positionTime:I.unix(),utc:I.utc().format(),method:"trajectory",vendor:"myship"},d=Math.floor(I.diff(k,"minute",!0)/(t||1));d!==b&&(b=d,a.push(M))}return a}}y.AISImpl=v,y.HifleetImpl=A,y.MyShipImpl=L,y.MyVesselImpl=E,y.ShipxyImpl=C,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(b,y){typeof exports=="object"&&typeof module<"u"?y(exports,require("got"),require("log4js"),require("moment")):typeof define=="function"&&define.amd?define(["exports","got","log4js","moment"],y):(b=typeof globalThis<"u"?globalThis:b||self,y(b["idm-plugin-rabbitmq"]={},b.got,b.log4js,b.moment))})(this,function(b,y,q,p){"use strict";var J=Object.defineProperty;var Q=(b,y,q)=>y in b?J(b,y,{enumerable:!0,configurable:!0,writable:!0,value:q}):b[y]=q;var A=(b,y,q)=>(Q(b,typeof y!="symbol"?y+"":y,q),q);function L(I){const h=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(I){for(const e in I)if(e!=="default"){const a=Object.getOwnPropertyDescriptor(I,e);Object.defineProperty(h,e,a.get?a:{enumerable:!0,get:()=>I[e]})}}return h.default=I,Object.freeze(h)}const C=L(q),M=C.getLogger();class O{parseStatus(h){let e,a;switch(h){case 0:e="在航(主机推动)",a="The engine is in use";break;case 1:e="锚泊",a="Anchored";break;case 2:e="失控",a="Not operated";break;case 3:e="操纵受限",a="Limited airworthiness";break;case 4:e="吃水受限",a="Limited by ship's draft";break;case 5:e="靠泊",a="Mooring";break;case 6:e="搁浅",a="Stranded";break;case 7:e="捕捞作业",a="Engaged in fishing";break;case 8:e="靠帆船提供动力",a="Sailing";break;default:e="未定义",a="Undefined"}return{labelCn:e,labelEn:a}}}class z extends O{constructor(e,a){super();A(this,"clientId");A(this,"clientSecret");A(this,"token");this.clientId=e,this.clientSecret=a}async authToken(e={}){const a="https://svc.data.myvessel.cn/ada/oauth/token",n={searchParams:{client_id:this.clientId,client_secret:this.clientSecret,grant_type:"client_credentials"}},o=await y.post(a,n).json();M.info("[%s] fetch access token from: %s - %j",e.requestId,a,o),o.error||(this.token={accessToken:o.access_token,tokenType:o.token_type,expiresIn:o.expires_in,scope:o.scope,jti:o.jti,issuedAt:p().utc().format()})}async realTimePosition(e,a={}){var d,c,l;(!this.token||p().diff(p(this.token.issuedAt),"seconds")>((d=this.token)==null?void 0:d.expiresIn)-300)&&await this.authToken(a);const n="https://svc.data.myvessel.cn/sdc/v1/vessels/status/location/unit",o={headers:{Authorization:`${(c=this.token)==null?void 0:c.tokenType} ${(l=this.token)==null?void 0:l.accessToken}`},searchParams:{mmsi:e}};M.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const s=await y.get(n,o).json();if(s.code)return M.warn("[%s] fetch realtime position failed: %j",a.requestId,n,{message:s.message,status:s.status,code:s.code}),s;const t=s.data;for(const f in t)!isNaN(t[f])&&Number(t[f])!==1/0&&(t[f]=Number(t[f]));const r=p(`${t.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:t.mmsi,name:t.vesselName,imo:t.imo,callSign:t.callsign,lat:t.lat,lng:t.lon,length:t.length,width:t.width,draught:t.currDraught,sog:t.sog,cog:t.cog,hdg:t.hdg,rot:t.rot,eta:t.eta,destination:t.dest,positionTime:r.unix(),status:t.status,labelCn:t.statusNameCn,labelEn:t.statusNameEn,method:"position",vendor:"myVessel",utc:r.utc().format()}}async trajectory(e,a,n,o,s=!0,t={}){(!this.token||p().diff(p(this.token.issuedAt),"seconds")>this.token.expiresIn-300)&&await this.authToken(t);const r=await this.realTimePosition(e,t),i=p(a),d=p(n),c=[];for(;d.diff(i,"day",!0)>30;)await this.trajectoryIn30Day(e,i,i.clone().add(30,"day"),r,o,c,t),i.add(30,"day");return await this.trajectoryIn30Day(e,i,d,r,o,c,t),c}async trajectoryIn30Day(e,a,n,o,s,t,r={}){var u,v,Y,j,S;const i="https://svc.data.myvessel.cn/sdc/v1/vessels/status/track",d={headers:{Authorization:`${(u=this.token)==null?void 0:u.tokenType} ${(v=this.token)==null?void 0:v.accessToken}`},json:{mmsi:e,startTime:a.utcOffset(8).format("YYYY-MM-DD HH:mm:ss"),endTime:n.utcOffset(8).format("YYYY-MM-DD HH:mm:ss")}};M.info("[%s] fetch trajectory from: %s - %j",r.requestId,i,d);const c=await y.post(i,d).json();if(c.code)return M.warn("[%s] fetch trajectory failed: %j",r.requestId,i,{message:c.message,status:c.status,code:c.code}),c;let l=-1;const f=p(`${(j=(Y=c.data)==null?void 0:Y[0])==null?void 0:j.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return(S=c.data)==null||S.forEach(g=>{for(const T in g)!isNaN(g[T])&&Number(g[T])!==1/0&&(g[T]=Number(g[T]));const w=p(`${g.postime} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"),N=g.eta?p(`${g.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00"):void 0,m=g.status,{labelCn:E,labelEn:P}=this.parseStatus(m),R={mmsi:g.mmsi,imo:o==null?void 0:o.imo,lat:g.lat,lng:g.lon,sog:g.sog,cog:g.cog,hdg:g.hdg,draught:g.draught,status:m,eta:N==null?void 0:N.unix(),destination:g.dest,positionTime:w.unix(),labelCn:E,labelEn:P,method:"trajectory",vendor:"myVessel",utc:w.utc().format()},x=Math.floor(w.diff(f,"minute",!0)/(s||1));x!==l&&(l=x,t.push(R))}),t}}class F extends O{constructor(e){super();A(this,"token");this.token=e}async realTimePosition(e,a={}){const n="https://api.hifleet.com/position/position/get/token",o={searchParams:{mmsi:e,usertoken:this.token}},s=await y.post(n,o).json();M.info("[%s] fetch realtime position from: %s - %j",a.requestId,n,o);const t=s==null?void 0:s.list;if(!t)return M.warn("[%s] fetch realtime position failed: %j",a.requestId,n,s),s;for(const f in t)!isNaN(t[f])&&Number(t[f])!==1/0&&(t[f]=Number(t[f]));t.status=t.sp>3?0:1;const r=t.status,{labelCn:i,labelEn:d}=this.parseStatus(r),c=p(`${t.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");return{mmsi:t.m,name:t.n,imo:t.imonumber,callSign:t.callsign,lat:Math.round(t.la/60*1e5)/1e5,lng:Math.round(t.lo/60*1e5)/1e5,length:t.l,width:t.w,draught:t.draught,sog:t.sp,cog:t.co,hdg:t.h,rot:isNaN(t.rot)?0:t.rot,eta:/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/.test(t.eta)?p(`${t.eta} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00").unix():void 0,destination:t.destination,positionTime:c.unix(),utc:c.utc().format(),status:r,labelCn:i,labelEn:d,method:"position",vendor:"hifleet"}}async search(e,a={}){let n="https://www.hifleet.com/hifleetapi/searchVesselOL.do";const o={searchParams:{keyword:e},headers:{Referer:"https://www.hifleet.com",Origin:"https://www.hifleet.com",Host:"www.hifleet.com"}};let s=await y.post(n,o).json();M.info("[%s] fetch vessel props from: %s - %j",a.requestId,n,o),s instanceof Array&&(s=s[0]);for(const r in s)!isNaN(s[r])&&Number(s[r])!==1/0&&(s[r]=Number(s[r]));const t={mmsi:s.m,name:s.n,imo:s.i,callSign:s.c,length:s.l,breadth:s.b,draught:s.dr};return n="https://www.hifleet.com/hifleetapi/sameShipSearch.do",s=await y.post(n,o).json(),M.info("[%s] fetch vessel dead weight from: %s - %j",a.requestId,n,o),s instanceof Array&&(s=s[0]),s&&(t.deadweight=Number(s.dwt)),t}async trajectory(e,a,n,o,s=!0,t={}){var g,w,N;const r=await this.realTimePosition(e,t);let i=p(a);const d=p(n),c=p();if(s){let m=d.diff(i,"d",!0);m<0?i=d.clone().subtract(40,"d"):m<30?i.subtract(10,"d"):m<60?i.subtract(5,"d"):i=d.clone().subtract(80,"d"),m=c.diff(d,"d",!0),d.add(m>10?240:m*24,"h")}const l={searchParams:{endtime:d.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),starttime:i.utcOffset("+8:00").format("YYYY-MM-DD HH:mm:ss"),mmsi:e,usertoken:this.token}},f="https://api.hifleet.com/position/trajectory/nocompressed/withstatic/token",u=await y.get(f,l).json();M.info("[%s] fetch trajectory from: %s - %j",t.requestId,f,l);let v;u&&(v=((w=(g=u.ships)==null?void 0:g.offors)==null?void 0:w.ship)||[],v.length||M.warn("[%s] fetch trajectory failed: %j",t.requestId,u));const Y=[];let j=-1;const S=p(`${(N=v==null?void 0:v[0])==null?void 0:N.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");for(const m of v){for(const _ in m)!isNaN(m[_])&&Number(m[_])!==1/0&&(m[_]=Number(m[_]));const E=p(`${m.ti} +08:00`,"YYYY-MM-DD HH:mm:ss +08:00");m.status=m.sp>4?0:1;const{labelEn:P,labelCn:R}=this.parseStatus(m.status),x={mmsi:m.m,name:m.n,imo:r==null?void 0:r.imo,lat:m.la,lng:m.lo,draught:m.draught,sog:m.sp,cog:m.co,hdg:m.hdg,positionTime:E.unix(),utc:E.utc().format(),status:m.status,labelCn:R,labelEn:P,method:"trajectory",vendor:"hifleet"},T=Math.floor(E.diff(S,"minute",!0)/(o||1));T!==j&&(j=T,Y.push(x))}return Y}}class G extends O{constructor(e){super();A(this,"token");this.token=e}async realTimePosition(e,a={}){const n={searchParams:{id:e,k:this.token,enc:1}},o="https://api.shipxy.com/apicall/GetSingleShip",s=await y.get(o,n).json();if(M.info("[%s] fetch realtime position from: %s - %j",a.requestId,o,n),(s==null?void 0:s.status)!==0)return s;const t=s.data[0];for(const l in t)!isNaN(t[l])&&Number(t[l])!==1/0&&(t[l]=Number(t[l]));const{labelCn:r,labelEn:i}=await this.parseStatus(t.navistat),d=p.unix(t.lasttime);return{mmsi:t.ShipID,name:t.name,imo:t.imo,callSign:t.callsign,lat:Math.round(t.lat/1e6*1e5)/1e5,lng:Math.round(t.lon/1e6*1e5)/1e5,length:Math.round(t.length/10*100)/100,width:Math.round(t.width/10*100)/100,draught:Math.round(t.draught/1e3*100)/100,sog:Math.round(t.sog*3600/1e3/1852*100)/100,cog:Math.round(t.cog/100*100)/100,hdg:Math.round(t.hdg/100*100)/100,rot:Math.round(t.rot/100*100)/100,positionTime:t.lasttime,utc:d.utc().format(),status:t.navistat,labelEn:i,labelCn:r,method:"position",vendor:"shipxy"}}async trajectory(e,a,n,o,s=!0,t={}){var S;const r=await this.realTimePosition(e,t),i=p(a),d=p(n),c="https://api.shipxy.com/apicall/GetShipTrack",l={searchParams:{id:e,k:this.token,enc:1,cut:0,btm:i.unix(),etm:d.unix()}},f=await y.get(c,l).json();if(M.info("[%s] fetch trajectory from: %s - %j",t.requestId,c,l),(f==null?void 0:f.status)!==0)return f;const u=f==null?void 0:f.points,v=[],Y=p.unix((S=u[0])==null?void 0:S.utc);let j=-1;for(const g of u){const w=p.unix(g.utc),N={imo:r==null?void 0:r.imo,mmsi:e,sog:Math.round(g.sog*3600/1e3/1852*100)/100,cog:Math.round(g.cog/100*100)/100,lat:Math.round(g.lat/1e6*1e5)/1e5,lng:Math.round(g.lon/1e6*1e5)/1e5,positionTime:w.unix(),utc:w.utc().format(),method:"trajectory",vendor:"shipxy"},m=Math.floor(w.diff(Y,"minute",!0)/(o||1));m!==j&&(j=m,v.push(N))}return v}}class B extends O{constructor(e){super();A(this,"token");this.token=e}async getShipId(e,a={}){const n={headers:{appKey:this.token},json:{mmsiList:e}},o="https://api3.myships.com/sp/ships/getShipIdByMMSI",s=await y.post(o,n).json();return M.info("[%s] fetch ship id from: %s - %j",a.requestId,o,n),s.code!=="0"?s:s.data[0].shipId}async getShipInfo(e,a={}){const n={headers:{appKey:this.token},json:{shipId:e}},o="https://api3.myships.com/sp/ships/aissta",s=await y.post(o,n).json();if(M.info("[%s] fetch ship info from: %s - %j",a.requestId,o,n),s.code!=="0")return s;const t=s.data;let r=t.imo;return e==="407170"&&(r="9198379",M.warn("[%s] ship(%s) imo error: %s, should be %s",a.requestId,e,t.imo,r)),{mmsi:t.mmsi,name:t.shipnameEn,imo:r,callSign:t.callSign,length:t.length,width:t.breadth,draught:(t.draught||100)/10}}async realTimePosition(e,a={}){const n=await this.getShipId(e,a),o=await this.getShipInfo(n,a),s={headers:{appKey:this.token},json:{shipId:n}},t="https://api3.myships.com/sp/ships/position/latest",r=await y.post(t,s).json();M.info("[%s] fetch realtime position from: %s - %j",a.requestId,t,s);const i=r.data[0];for(const u in i)!isNaN(i[u])&&Number(i[u])!==1/0&&(i[u]=Number(i[u]));const{labelCn:d,labelEn:c}=await this.parseStatus(i.aisNavStatus),l=p.unix(i.posTime);return{...o,mmsi:e,lat:Math.round(i.lat/1e4/60*1e5)/1e5,lng:Math.round(i.lon/1e4/60*1e5)/1e5,sog:Math.round(i.sog/10*100)/100,cog:Math.round(i.cog/10*100)/100,hdg:Math.round(i.heading*100)/100,rot:Math.round(i.rot*100)/100,positionTime:i.posTime,utc:l.utc().format(),status:i.aisNavStatus,labelEn:c,labelCn:d,method:"position",vendor:"myship"}}async trajectory(e,a,n,o,s=!0,t={}){const r=p(a),i=p(n),d=await this.getShipId(e),c=await this.getShipInfo(d),l=[];for(;i.diff(r,"day",!0)>30;)await this.trajectoryIn30Day(d,r.unix(),r.add(30,"day").unix(),c,e,o,l);return await this.trajectoryIn30Day(d,r.unix(),i.unix(),c,e,o,l),l}async trajectoryIn30Day(e,a,n,o,s,t,r,i={}){var Y;const d={headers:{appKey:this.token},json:{shipId:e,startTime:a,endTime:n}},c="https://api3.myships.com/sp/ships/position/history",l=await y.post(c,d).json();if(M.info("[%s] fetch trajectory from: %s - %j",i.requestId,c,d),l.code!=="0")return M.warn("[%s] invoke myship trajectory failed: %j",i.requestId,l),l;const f=l.data;for(const j in f)!isNaN(f[j])&&Number(f[j])!==1/0&&(f[j]=Number(f[j]));const u=p.unix((Y=f[0])==null?void 0:Y.posTime);let v=-1;for(const j of f){const S=p.unix(j.posTime),g={imo:o==null?void 0:o.imo,mmsi:s,lat:Math.round(j.lat/1e4/60*1e5)/1e5,lng:Math.round(j.lon/1e4/60*1e5)/1e5,sog:Math.round(j.sog/10*100)/100,cog:Math.round(j.cog/10*100)/100,hdg:Math.round(j.heading*100)/100,rot:Math.round(j.rot*100)/100,positionTime:S.unix(),utc:S.utc().format(),method:"trajectory",vendor:"myship"},w=Math.floor(S.diff(u,"minute",!0)/(t||1));w!==v&&(v=w,r.push(g))}return r}}const W=C.getLogger();var K=(I=>(I.NOTICE="NOTICE",I.WARN="WARN",I.HEAVY="HEAVY",I.SEVERE="SEVERE",I.ERROR="ERROR",I.FATAL="FATAL",I))(K||{});class U{parsePrinciple(h,e={}){var t,r,i;W.info("[%s] parse rule: %s",e.requestId,h);const a=new RegExp("(?<=\\[)(.+)(?=\\])","g"),n=h.match(a)?(t=h.match(a))==null?void 0:t[0]:void 0,o=n==null?void 0:n.split(";");if(!o)return;const s={};for(let d=0;d<(o==null?void 0:o.length);d++){const c=(i=(r=o[d].match(a))==null?void 0:r[0])==null?void 0:i.split("],");if(d===0&&!c)s.scope=o[0];else if(c)for(let l=0,f=c.length;l<f;l++){const u=this.parseRule(c[l]);u&&(s[u.level]?u.key?s[u.level][u==null?void 0:u.key]=u:s[u.level]=u:u.key?s[u.level]={[u==null?void 0:u.key]:u}:s[u.level]=u)}}return s}parseRule(h,e={}){var s;W.info("[%s] parse rule: %s",e.requestId,h),h=h.startsWith("[")?h:`[${h}`,h=h.endsWith("]")?h:`${h}]`;const a=new RegExp("(?<=\\[)(.+?)(?=\\])","g"),n=(s=h==null?void 0:h.match(a))==null?void 0:s[0],o=n==null?void 0:n.split(",");if(o)return{operator:o[0],number:Number(o[1]),level:o[2],time:Number(o[3]),key:o[4]}}checkWeather(h,e,a={}){var u,v,Y,j,S,g,w,N,m,E,P,R,x,T,_;let n=0,o=0,s=0,t=0;const r=((v=(u=e==null?void 0:e.SEVERE)==null?void 0:u.sigWave)==null?void 0:v.number)*1.6,i=(j=(Y=e==null?void 0:e.SEVERE)==null?void 0:Y.sigWave)==null?void 0:j.number,d=(g=(S=e==null?void 0:e.HEAVY)==null?void 0:S.sigWave)==null?void 0:g.number,c=((N=(w=e==null?void 0:e.SEVERE)==null?void 0:w.wind)==null?void 0:N.number)+2,l=(E=(m=e==null?void 0:e.SEVERE)==null?void 0:m.wind)==null?void 0:E.number,f=(R=(P=e==null?void 0:e.HEAVY)==null?void 0:P.wind)==null?void 0:R.number;for(let V=1;V<(h==null?void 0:h.length);V++){const k=h[V],D=(T=(x=k==null?void 0:k.meteo)==null?void 0:x.wave)==null?void 0:T.sig,H=(_=k==null?void 0:k.meteo)==null?void 0:_.wind,$=p(k.eta).diff(p(h[V-1].eta),"hour",!0);t=$>t?$:t,W.info("[%s] check sig.wave: %j",a.requestId,{...D,dgThd4Wv:r,svThd4Wv:i,hvThd4Wv:d}),(D==null?void 0:D.height)>=r?k.isDangerous=!0:(D==null?void 0:D.height)>=i?k.isSevere=!0:(D==null?void 0:D.height)>=d&&(k.isHeavy=!0),W.info("[%s] check wind: %j",a.requestId,{...H,dgThd4Wd:c,svThd4Wd:l,hvThd4Wd:f}),(H==null?void 0:H.scale)>=c?(k.isDangerous=!0,delete k.isSevere,delete k.isHeavy):(H==null?void 0:H.scale)>l?(k.isDangerous||(k.isSevere=!0),delete k.isHeavy):(H==null?void 0:H.scale)===f&&!k.isDangerous&&!k.isSevere&&(k.isHeavy=!0),n+=k.isDangerous?$:0,o+=k.isSevere?$:0,s+=k.isHeavy?$:0,V===1&&(h[0].isDangerous=k.isDangerous,h[0].isSevere=k.isSevere,h[0].isHeavy=k.isHeavy)}return n=Math.round(n*100)/100,o=Math.round(o*100)/100,s=Math.round(s*100)/100,t=Math.round(t),{sample:h,dangerous:n,severe:o,heavy:s,step:t<3?3:t}}}b.AISImpl=O,b.AlertHelper=U,b.AlertLevel=K,b.HifleetImpl=F,b.MyShipImpl=B,b.MyVesselImpl=z,b.ShipxyImpl=G,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|