卫星通信服务平台

This commit is contained in:
2026-05-19 17:12:10 +08:00
parent 098d2ff575
commit 2398f17070
5 changed files with 149 additions and 72 deletions

View File

@@ -72,7 +72,7 @@ class HomeController extends Controller {
}
const uid = JSON.parse(rdmcode).uid;
const result = await ctx.service.home.getSN(uid);
if(result == "error") {
if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none");
return;
}
@@ -101,7 +101,7 @@ class HomeController extends Controller {
const uid = JSON.parse(rdmcode).uid;
const { snNumber } = ctx.request.body;
const result = await ctx.service.home.searchSN(snNumber);
if(result == "error") {
if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none");
return;
}
@@ -134,7 +134,7 @@ class HomeController extends Controller {
}
const uid = JSON.parse(rdmcode).uid;
const result = await ctx.service.home.searchBindSN(uid);
if(result == "error") {
if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none");
return;
}
@@ -164,7 +164,7 @@ class HomeController extends Controller {
}
const uid = JSON.parse(rdmcode).uid;
const result = await ctx.service.home.searchBindUser(uid);
if(result == "error") {
if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none");
return;
}
@@ -195,7 +195,7 @@ class HomeController extends Controller {
const uid = JSON.parse(rdmcode).uid;
const body = ctx.request.body;
const result = await ctx.service.home.bindSN(uid, body);
if(result == "error") {
if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none");
return;
}
@@ -226,7 +226,7 @@ class HomeController extends Controller {
const password = decryptRequest(body.password);
const requestMsg = body.userMsg;
const result = await ctx.service.home.unBindingSN(uid, model, password, requestMsg);
if(result == "error") {
if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none");
return;
}
@@ -254,7 +254,7 @@ class HomeController extends Controller {
const uid = JSON.parse(rdmcode).uid;
const body = ctx.request.body;
const result = await ctx.service.home.getRecord(uid, body);
if(result == "error") {
if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none");
return;
}
@@ -283,7 +283,6 @@ class HomeController extends Controller {
const ctx = this.ctx;
try {
const body = ctx.request.body;
console.log(body)
const { sn_number, original_msg, msg_data, created_at } = body;
const form = {
sn_number: sn_number,
@@ -292,7 +291,7 @@ class HomeController extends Controller {
created_at: created_at
};
const result = await ctx.service.home.shortMsg(form);
if(result == "error") {
if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none");
return;
}
@@ -308,6 +307,35 @@ class HomeController extends Controller {
}
}
// 保存未知消息
async saveUnknown() {
const { ctx } = this;
try {
const body = ctx.request.body;
const { system_type, original_msg, msg_data, created_at } = body;
const form = {
system_type: system_type,
original_msg: original_msg,
msg_data: msg_data,
created_at: created_at
};
const result = await ctx.service.home.saveUnknown(form);
if (result == "error") {
this.setResponse(ctx, 500, '服务器错误', "none");
return;
}
if (result) {
this.setResponse(ctx, 200, '保存未知消息成功', "none");
} else {
this.setResponse(ctx, 404, '保存未知消息失败', "none");
}
} catch (error) {
const blockName = fileName + "--" + "saveUnknown";
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
this.setResponse(ctx, 500, '服务器错误', "none");
}
}
// 获取历史消息
async getHistoryMsg() {
const ctx = this.ctx;
@@ -320,7 +348,7 @@ class HomeController extends Controller {
const uid = JSON.parse(rdmcode).uid;
const body = ctx.request.body;
const result = await ctx.service.home.getHistoryMsg(uid, body);
if(result == "error") {
if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none");
return;
}
@@ -359,7 +387,7 @@ class HomeController extends Controller {
const password = decryptRequest(body.password);
const requestMsg = body.userMsg;
const resetList = await ctx.service.home.delHistoryMsg(uid, model, password, requestMsg);
if(resetList == "error") {
if (resetList == "error") {
setResponse(ctx, 500, '服务器错误', "none");
return;
}
@@ -399,11 +427,11 @@ class HomeController extends Controller {
}
const uid = JSON.parse(rdmcode).uid;
let result;
if(uid[uid.length - 1] == 'B') {
if (uid[uid.length - 1] == 'B') {
const body = ctx.request.body;
result = await ctx.service.home.bsideUserManager(uid, body);
}
if(result == "error") {
if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none");
return;
}
@@ -435,11 +463,11 @@ class HomeController extends Controller {
}
const uid = JSON.parse(rdmcode).uid;
let result;
if(uid[uid.length - 1] == 'B') {
if (uid[uid.length - 1] == 'B') {
const body = ctx.request.body;
result = await ctx.service.home.bsideSNManager(uid, body);
}
if(result == "error") {
if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none");
return;
}

View File

@@ -21,14 +21,14 @@ module.exports = (app) => {
// 00000043010000000000000000000000000000000000000000 18 31353037365f32303236303330333135313835315f323832 00 0f 0102030405060708090a0b0c0d0e0f
let sn_value = value.slice(52, 100),
snBuffer = Buffer.from(sn_value, 'hex'),
snNumber = snBuffer.toString('ascii').split("_")[0],
snNumber = snBuffer.toString('ascii').split("_")[0].padStart(8, '0'),
msg_value = value.slice(104, value.length),
msgBuffer = Buffer.from(msg_value, 'hex'),
msgData = msgBuffer.toString('ascii');
console.log(msgData)
// socket接收消息后触发事件监听器,将消息发送给websocket客户端并存储在数据库中
shunt.socketEmitter().emit(snNumber, { msg_data: msgData, created_at: new Date() });
await app.curl('http://127.0.0.1:' + app.server.address().port + '/shortMsg', {
const shortMsg = await app.curl('http://127.0.0.1:' + app.server.address().port + '/shortMsg', {
dataType: 'json',
contentType: 'application/x-www-form-urlencoded',
method: 'POST',
@@ -40,6 +40,20 @@ module.exports = (app) => {
created_at: new Date()
},
});
if (shortMsg.data.code == 404) {
await app.curl('http://127.0.0.1:' + app.server.address().port + '/saveUnknown', {
dataType: 'json',
contentType: 'application/x-www-form-urlencoded',
method: 'POST',
timeout: 3000,
data: {
system_type: 1,
original_msg: value,
msg_data: msgData,
created_at: new Date()
},
});
}
});
socket.on('end', function (data) {
console.log(data);

20
app/model3/Unknown.js Normal file
View File

@@ -0,0 +1,20 @@
'use strict';
module.exports = (app) => {
const { INTEGER, TEXT, DATE } = app.Sequelize;
const Unknown = app.model3.define('unknown', {
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
system_type: INTEGER(3),
original_msg: TEXT,
msg_data: TEXT,
created_at: DATE,
},{
freezeTableName: true,
timestamp: true,
createdAt: true,
updatedAt: false,
});
return Unknown;
};

View File

@@ -30,6 +30,8 @@ module.exports = app => {
router.post('/getRecord', controller.home.getRecord);
// 存储消息记录
router.post('/shortMsg', controller.home.shortMsg);
// 保存未知消息
router.post("/saveUnknown", controller.home.saveUnknown);
// 获取历史消息
router.post('/getHistoryMsg', controller.home.getHistoryMsg);
// 删除历史消息

View File

@@ -222,13 +222,13 @@ class HomeService extends Service {
const uidLastCode = shunt(uid);
attributes.forEach(element => {
if (searchOptions[element]) {
if(searchOptions[element] == '*空') {
if(joinSubstring.includes(element)) {
if (searchOptions[element] == '*空') {
if (joinSubstring.includes(element)) {
where[element] = null;
} else {
where[element] = [null, ''];
}
} else if(substring.includes(element)) {
} else if (substring.includes(element)) {
where[element] = { [Op.substring]: searchOptions[element] };
} else if (key.includes(element)) {
where[element] = searchOptions[element] == "1" ? uidLastCode === 'B' ? 1 : 2 : 0;
@@ -302,6 +302,19 @@ class HomeService extends Service {
}
}
// 保存未知消息
async saveUnknown(form) {
const { ctx } = this;
try {
const result = await ctx.model3.Unknown.create(form);
return result || false;
} catch (error) {
const blockName = fileName + "--" + "saveUnknown";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
// 获取历史消息
async getHistoryMsg(uid, body) {
const { ctx } = this;
@@ -313,8 +326,8 @@ class HomeService extends Service {
substring = ['original_msg', 'sn_number', 'msg_data'], key = [], between = ['created_at'];
attributes.forEach(element => {
if (searchOptions[element]) {
if(searchOptions[element] == '*空') {
if(joinSubstring.includes(element)) {
if (searchOptions[element] == '*空') {
if (joinSubstring.includes(element)) {
where[element] = null;
} else {
where[element] = [null, ''];
@@ -404,13 +417,13 @@ class HomeService extends Service {
where = { organization: result.organization }, dbOptions, joinSubstring = [];
attributes.forEach(element => {
if (searchOptions[element]) {
if(searchOptions[element] == '*空') {
if(joinSubstring.includes(element)) {
if (searchOptions[element] == '*空') {
if (joinSubstring.includes(element)) {
where[element] = null;
} else {
where[element] = [null, ''];
}
} else{
} else {
where[element] = { [Op.substring]: searchOptions[element] };
}
}