Skip to content
Snippets Groups Projects
Commit 679cf52f authored by Adrian Cheng's avatar Adrian Cheng
Browse files

chore: merge new_table to syslink-refactor

parents 5d87791f fd4d78e5
No related branches found
No related tags found
No related merge requests found
......@@ -15,25 +15,26 @@ model PingPong {
id Int @unique @id @default(autoincrement())
order_id Int @db.Int
source_ip String @db.VarChar(20)
gatewayip String @db.VarChar(20)
ping_time_sec BigInt @db.BigInt
ping_time_nano BigInt @db.BigInt
pong_time_sec BigInt @db.BigInt
pong_time_nano BigInt @db.BigInt
gateway_ip String @db.VarChar(20)
trader_in_sec BigInt @db.BigInt
trader_in_nano BigInt @db.BigInt
trader_out_sec BigInt @db.BigInt
trader_out_nano BigInt @db.BigInt
gateway_in_sec BigInt @db.BigInt
gateway_in_nano BigInt @db.BigInt
gateway_out_sec BigInt @db.BigInt
gateway_out_nano BigInt @db.BigInt
ticker_in_sec BigInt @db.BigInt
ticker_in_nano BigInt @db.BigInt
ome_in_sec BigInt @db.BigInt
ome_in_nano BigInt @db.BigInt
ome_out_sec BigInt @db.BigInt
ome_out_nano BigInt @db.BigInt
ticker_out_sec BigInt @db.BigInt
ticker_out_nano BigInt @db.BigInt
latency Float @db.Float
}
model Node {
id Int @unique @id @default(autoincrement())
host_name String @db.VarChar(20)
host_name String @unique @id @db.VarChar(20)
port String @db.VarChar(20)
message_num Int @db.Int
status Int @db.Int
......
......@@ -44,7 +44,7 @@ export class AppController {
async pageFromTime(@Query('skip') skip: number,@Query('take') take: number,
@Query('time') time: string): Promise<PingPongModele[]> {
console.log(time)
const {ping_time_sec, ping_time_nano} = this.splitTimePing(time);
const {trader_in_sec, trader_in_nano} = this.splitTimePing(time);
return this.pingPongService.pingPongs(
{
skip: Number(skip),
......@@ -52,16 +52,16 @@ export class AppController {
where: {
OR: [
{
ping_time_sec: {
gte: Number(ping_time_sec),
trader_in_sec: {
gte: Number(trader_in_sec),
},
ping_time_nano: {
gte: Number(ping_time_nano),
trader_in_nano: {
gte: Number(trader_in_nano),
}
},
{
ping_time_sec: {
gt: Number(ping_time_sec),
trader_in_sec: {
gt: Number(trader_in_sec),
}
}
]
......@@ -74,49 +74,58 @@ export class AppController {
@Post('pingPong')
async createPingPong(
@Body() postData: { order_id: number; source_ip: string; gatewayip: string; ping_time: string; pong_time: string; latency: number,
gateway_in: string; gateway_out: string; ticker_in: string; ticker_out: string;},
@Body() postData: { order_id: number; source_ip: string; gateway_ip: string; trader_in: string; trader_out: string; latency: number,
gateway_in: string; gateway_out: string; ticker_out: string; ome_in: string; ome_out: string;},
): Promise<PingPongModele> {
const { order_id, source_ip, gatewayip, ping_time, pong_time, latency, gateway_in,
gateway_out,ticker_in, ticker_out, } = postData;
const {ping_time_sec, ping_time_nano, pong_time_sec, pong_time_nano, gateway_in_sec,gateway_in_nano,
gateway_out_sec, gateway_out_nano, ticker_in_sec, ticker_in_nano, ticker_out_sec,
ticker_out_nano,} = this.splitTime(ping_time, pong_time, gateway_in,
gateway_out,ticker_in, ticker_out);
return this.pingPongService.createPingPong({
const { order_id, source_ip, gateway_ip, trader_in, trader_out, latency, gateway_in,
gateway_out,ome_in, ome_out, ticker_out} = postData;
const {trader_in_sec, trader_in_nano, trader_out_sec, trader_out_nano, gateway_in_sec,gateway_in_nano,
gateway_out_sec, gateway_out_nano, ome_in_sec,ome_in_nano, ome_out_sec, ome_out_nano, ticker_out_sec,
ticker_out_nano,} = this.splitTime(trader_in, trader_out, gateway_in,
gateway_out,ome_in, ome_out, ticker_out);
const result = this.pingPongService.createPingPong({
order_id,
source_ip,
gatewayip,
ping_time_sec,
ping_time_nano,
pong_time_sec,
pong_time_nano,
gateway_ip,
trader_in_sec,
trader_in_nano,
trader_out_sec,
trader_out_nano,
gateway_in_sec,
gateway_in_nano,
gateway_out_sec,
gateway_out_nano,
ticker_in_sec,
ticker_in_nano,
ome_in_sec,
ome_in_nano,
ome_out_sec,
ome_out_nano,
ticker_out_sec,
ticker_out_nano,
latency
latency,
});
await this.nodeService.updateNodeByHostName({host_name: source_ip});
return result;
}
splitTime(ping_time: string, pong_time: string, gateway_in: string,
gateway_out: string, ticker_in: string, ticker_out: string): any {
splitTime(trader_in: string, trader_out: string, gateway_in: string,
gateway_out: string, ticker_out: string, ome_in: string, ome_out: string, ): any {
return {
ping_time_sec: BigInt(ping_time.substring(0,10)),
ping_time_nano: BigInt(ping_time.substring(10)),
pong_time_sec: BigInt(pong_time.substring(0,10)),
pong_time_nano: BigInt(pong_time.substring(10)),
trader_in_sec: BigInt(trader_in.substring(0,10)),
trader_in_nano: BigInt(trader_in.substring(10)),
trader_out_sec: BigInt(trader_out.substring(0,10)),
trader_out_nano: BigInt(trader_out.substring(10)),
gateway_in_sec: BigInt(gateway_in.substring(0,10)),
gateway_in_nano: BigInt(gateway_in.substring(10)),
gateway_out_sec: BigInt(gateway_out.substring(0,10)),
gateway_out_nano: BigInt(gateway_out.substring(10)),
ticker_in_sec: BigInt(ticker_in.substring(0,10)),
ticker_in_nano: BigInt(ticker_in.substring(10)),
ome_in_sec: BigInt(ome_in.substring(0,10)),
ome_in_nano: BigInt(ome_in.substring(10)),
ome_out_sec: BigInt(ome_out.substring(0,10)),
ome_out_nano: BigInt(ome_out.substring(10)),
ticker_out_sec: BigInt(ticker_out.substring(0,10)),
ticker_out_nano: BigInt(ticker_out.substring(10)),
}
......@@ -124,8 +133,8 @@ export class AppController {
splitTimePing(ping_time: string): any {
return {
ping_time_sec: BigInt(ping_time.substring(0,10)),
ping_time_nano: BigInt(ping_time.substring(10)),
trader_in_sec: BigInt(ping_time.substring(0,10)),
trader_in_nano: BigInt(ping_time.substring(10)),
}
}
......@@ -134,9 +143,17 @@ export class AppController {
return this.pingPongService.deletePingPong({ id: Number(id) });
}
@Get('node')
async getNodeById(@Query('id') id: string): Promise<NodeModule> {
return this.nodeService.node({ id: Number(id) });
async getNodeByHostName(@Query('host_name') host_name: string): Promise<NodeModule | string> {
const check = await this.nodeService.nodeCheck(host_name);
if (check != 0) {
const result = this.nodeService.node({ host_name: host_name });
return result;
} else {
return "cannot find";
}
}
@Post('node')
......@@ -150,7 +167,7 @@ export class AppController {
}
@Delete('node')
async deleteNode(@Query('id') id: string): Promise<NodeModule> {
return this.nodeService.deleteNode({ id: Number(id) });
async deleteNode(@Query('host_name') host_name: string): Promise<NodeModule> {
return this.nodeService.deleteNode({ host_name: host_name });
}
}
......@@ -14,6 +14,17 @@ export class NodeService {
});
}
async nodeCheck(host_name: string): Promise<number> {
let placeCount = await this.prisma.node.count(
{
where: {
host_name: host_name
}
}
);
return placeCount;
}
async nodes(params: {
skip?: number;
take?: number;
......@@ -43,7 +54,7 @@ export class NodeService {
});
}
async updateNode(params: {
async updateNodeById(params: {
where: Prisma.NodeWhereUniqueInput;
data: Prisma.NodeUpdateInput;
}): Promise<Node> {
......@@ -54,6 +65,40 @@ export class NodeService {
});
}
async updateNodeByHostName(params: {
host_name: string;
}): Promise<Node> {
const { host_name } = params;
let placeCount = await this.prisma.node.count(
{
where: {
host_name: host_name
}
}
);
if (placeCount == 0) {
console.log("create")
return this.prisma.node.create({
data: {
host_name: host_name,
port: "3000",
message_num: 1,
status: 1
},
});
} else {
console.log("update")
return this.prisma.node.update({
where: {
host_name: host_name,
},
data: {
message_num: {increment: 1},
},
});
}
}
async deleteNode(where: Prisma.NodeWhereUniqueInput): Promise<Node> {
return this.prisma.node.delete({
where,
......
......@@ -41,17 +41,19 @@ export class PingPongService {
data: {
order_id: data.order_id,
source_ip: data.source_ip,
gatewayip: data.gatewayip,
ping_time_sec: data.ping_time_sec,
ping_time_nano: data.ping_time_nano,
pong_time_sec: data.pong_time_sec,
pong_time_nano: data.pong_time_nano,
gateway_ip: data.gateway_ip,
trader_in_sec: data.trader_in_sec,
trader_in_nano: data.trader_in_nano,
trader_out_sec: data.trader_out_nano,
trader_out_nano: data.trader_out_nano,
gateway_in_sec: data.gateway_in_sec,
gateway_in_nano: data.gateway_in_nano,
gateway_out_sec: data.gateway_out_sec,
gateway_out_nano: data.gateway_out_nano,
ticker_in_sec: data.ticker_in_sec,
ticker_in_nano: data.ticker_in_nano,
ome_in_sec: data.ome_in_sec,
ome_in_nano: data.ome_in_nano,
ome_out_sec: data.ome_out_sec,
ome_out_nano: data.ome_out_nano,
ticker_out_sec: data.ticker_out_sec,
ticker_out_nano: data.ticker_out_nano,
latency: data.latency
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment