常规推送

This commit is contained in:
2026-06-04 10:39:42 +08:00
parent 90a8407924
commit 1a362f8cd1
5 changed files with 159 additions and 67 deletions

View File

@@ -72,7 +72,7 @@ class HomeController extends Controller {
} }
const uid = JSON.parse(rdmcode).uid; const uid = JSON.parse(rdmcode).uid;
const result = await ctx.service.home.getCard(uid); const result = await ctx.service.home.getCard(uid);
if(result == "error") { if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none"); setResponse(ctx, 500, '服务器错误', "none");
return; return;
} }
@@ -100,7 +100,7 @@ class HomeController extends Controller {
const uid = JSON.parse(rdmcode).uid; const uid = JSON.parse(rdmcode).uid;
const { cardID } = ctx.request.body; const { cardID } = ctx.request.body;
const result = await ctx.service.home.searchCard(cardID); const result = await ctx.service.home.searchCard(cardID);
if(result == "error") { if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none"); setResponse(ctx, 500, '服务器错误', "none");
return; return;
} }
@@ -134,7 +134,7 @@ class HomeController extends Controller {
const uid = JSON.parse(rdmcode).uid; const uid = JSON.parse(rdmcode).uid;
const body = ctx.request.body; const body = ctx.request.body;
const result = await ctx.service.home.bindCard(uid, body); const result = await ctx.service.home.bindCard(uid, body);
if(result == "error") { if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none"); setResponse(ctx, 500, '服务器错误', "none");
return; return;
} }
@@ -162,7 +162,7 @@ class HomeController extends Controller {
const uid = JSON.parse(rdmcode).uid; const uid = JSON.parse(rdmcode).uid;
const body = ctx.request.body; const body = ctx.request.body;
const result = await ctx.service.home.unBindingCard(uid, body); const result = await ctx.service.home.unBindingCard(uid, body);
if(result == "error") { if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none"); setResponse(ctx, 500, '服务器错误', "none");
return; return;
} }
@@ -193,7 +193,7 @@ class HomeController extends Controller {
const password = decryptRequest(body.password); const password = decryptRequest(body.password);
const requestMsg = body.userMsg; const requestMsg = body.userMsg;
const result = await ctx.service.home.unBindManager(uid, model, password, requestMsg); const result = await ctx.service.home.unBindManager(uid, model, password, requestMsg);
if(result == "error") { if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none"); setResponse(ctx, 500, '服务器错误', "none");
return; return;
} }
@@ -221,7 +221,7 @@ class HomeController extends Controller {
const uid = JSON.parse(rdmcode).uid; const uid = JSON.parse(rdmcode).uid;
const body = ctx.request.body; const body = ctx.request.body;
const result = await ctx.service.home.getRecord(uid, body); const result = await ctx.service.home.getRecord(uid, body);
if(result == "error") { if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none"); setResponse(ctx, 500, '服务器错误', "none");
return; return;
} }
@@ -261,7 +261,7 @@ class HomeController extends Controller {
created_at: created_at created_at: created_at
}; };
const result = await ctx.service.home.shortMsg(form); const result = await ctx.service.home.shortMsg(form);
if(result == "error") { if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none"); setResponse(ctx, 500, '服务器错误', "none");
return; return;
} }
@@ -277,6 +277,35 @@ class HomeController extends Controller {
} }
} }
// 保存未知消息
async saveUnknown() {
const { ctx } = this;
try {
const body = ctx.request.body;
const { card_id, original_msg, msg_data, created_at } = body;
const form = {
card_id: card_id,
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() { async getHistoryMsg() {
const ctx = this.ctx; const ctx = this.ctx;
@@ -289,7 +318,7 @@ class HomeController extends Controller {
const uid = JSON.parse(rdmcode).uid; const uid = JSON.parse(rdmcode).uid;
const body = ctx.request.body; const body = ctx.request.body;
const result = await ctx.service.home.getHistoryMsg(uid, body); const result = await ctx.service.home.getHistoryMsg(uid, body);
if(result == "error") { if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none"); setResponse(ctx, 500, '服务器错误', "none");
return; return;
} }
@@ -328,7 +357,7 @@ class HomeController extends Controller {
const password = decryptRequest(body.password); const password = decryptRequest(body.password);
const requestMsg = body.userMsg; const requestMsg = body.userMsg;
const resetList = await ctx.service.home.delHistoryMsg(uid, model, password, requestMsg); const resetList = await ctx.service.home.delHistoryMsg(uid, model, password, requestMsg);
if(resetList == "error") { if (resetList == "error") {
setResponse(ctx, 500, '服务器错误', "none"); setResponse(ctx, 500, '服务器错误', "none");
return; return;
} }
@@ -355,11 +384,11 @@ class HomeController extends Controller {
} }
const uid = JSON.parse(rdmcode).uid; const uid = JSON.parse(rdmcode).uid;
let result; let result;
if(uid[uid.length - 1] == 'B') { if (uid[uid.length - 1] == 'B') {
const body = ctx.request.body; const body = ctx.request.body;
result = await ctx.service.home.bsideManager(uid, body); result = await ctx.service.home.bsideManager(uid, body);
} }
if(result == "error") { if (result == "error") {
setResponse(ctx, 500, '服务器错误', "none"); setResponse(ctx, 500, '服务器错误', "none");
return; return;
} }

View File

@@ -92,7 +92,7 @@ module.exports = (app) => {
const { senderAddress, msgData, encodingCategory } = outboundMsg; const { senderAddress, msgData, encodingCategory } = outboundMsg;
// socket接收消息后触发事件监听器,将消息发送给websocket客户端并存储在数据库中 // socket接收消息后触发事件监听器,将消息发送给websocket客户端并存储在数据库中
shunt.socketEmitter().emit(senderAddress.data, { encode_type: parseInt(encodingCategory.data), msg_data: msgData.data, created_at: new Date() }); shunt.socketEmitter().emit(senderAddress.data, { encode_type: parseInt(encodingCategory.data), msg_data: msgData.data, 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', dataType: 'json',
contentType: 'application/x-www-form-urlencoded', contentType: 'application/x-www-form-urlencoded',
method: 'POST', method: 'POST',
@@ -107,6 +107,20 @@ module.exports = (app) => {
created_at: new Date() 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: {
card_id: senderAddress.data,
original_msg: originalMsg,
msg_data: msgData.data,
created_at: new Date()
},
});
}
} }
// 重发消息处理 // 重发消息处理
if (resendResult && resendResult.type == 4) { if (resendResult && resendResult.type == 4) {
@@ -114,8 +128,8 @@ module.exports = (app) => {
const { outboundMsg, receiverAddress } = msgContent; const { outboundMsg, receiverAddress } = msgContent;
const { senderAddress, msgData, encodingCategory } = outboundMsg; const { senderAddress, msgData, encodingCategory } = outboundMsg;
// socket接收消息后触发事件监听器,将消息发送给websocket客户端并存储在数据库中 // socket接收消息后触发事件监听器,将消息发送给websocket客户端并存储在数据库中
shunt.socketEmitter().emit(senderAddress.data, msgData.data); shunt.socketEmitter().emit(senderAddress.data, { encode_type: parseInt(encodingCategory.data), msg_data: msgData.data, 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', dataType: 'json',
contentType: 'application/x-www-form-urlencoded', contentType: 'application/x-www-form-urlencoded',
method: 'POST', method: 'POST',
@@ -129,6 +143,20 @@ module.exports = (app) => {
msg_data: msgData.data, msg_data: msgData.data,
}, },
}); });
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: {
card_id: senderAddress.data,
original_msg: originalMsg,
msg_data: msgData.data,
created_at: new Date()
},
});
}
} }
} }
}); });

View File

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

View File

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

View File

@@ -208,13 +208,13 @@ class HomeService extends Service {
const uidLastCode = shunt(uid); const uidLastCode = shunt(uid);
attributes.forEach(element => { attributes.forEach(element => {
if (searchOptions[element]) { if (searchOptions[element]) {
if(searchOptions[element] == '*空') { if (searchOptions[element] == '*空') {
if(joinSubstring.includes(element)) { if (joinSubstring.includes(element)) {
where[element] = null; where[element] = null;
} else { } else {
where[element] = [null, '']; where[element] = [null, ''];
} }
} else if(substring.includes(element)) { } else if (substring.includes(element)) {
where[element] = { [Op.substring]: searchOptions[element] }; where[element] = { [Op.substring]: searchOptions[element] };
} else if (key.includes(element)) { } else if (key.includes(element)) {
where[element] = searchOptions[element] == "1" ? uidLastCode === 'B' ? 1 : 2 : 0; where[element] = searchOptions[element] == "1" ? uidLastCode === 'B' ? 1 : 2 : 0;
@@ -275,6 +275,19 @@ class HomeService extends Service {
} }
} }
// 保存未知消息
async saveUnknown(form) {
const { ctx } = this;
try {
const result = await ctx.model3.UnknownBDCard.create(form);
return result || false;
} catch (error) {
const blockName = fileName + "--" + "saveUnknown";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
// 获取历史消息 // 获取历史消息
async getHistoryMsg(uid, body) { async getHistoryMsg(uid, body) {
const { ctx } = this; const { ctx } = this;
@@ -286,8 +299,8 @@ class HomeService extends Service {
substring = ['card_id', 'msg_data'], key = ['encode_type'], between = ['created_at']; substring = ['card_id', 'msg_data'], key = ['encode_type'], between = ['created_at'];
attributes.forEach(element => { attributes.forEach(element => {
if (searchOptions[element]) { if (searchOptions[element]) {
if(searchOptions[element] == '*空') { if (searchOptions[element] == '*空') {
if(joinSubstring.includes(element)) { if (joinSubstring.includes(element)) {
where[element] = null; where[element] = null;
} else { } else {
where[element] = [null, '']; where[element] = [null, ''];
@@ -358,7 +371,7 @@ class HomeService extends Service {
"T": ctx.model4.TShortMsg, "T": ctx.model4.TShortMsg,
}; };
const resetList = await modelName[uidLastCode].destroy({ where }); const resetList = await modelName[uidLastCode].destroy({ where });
return resetList.length == 0 ? false : resetList; return resetList == 0 ? false : resetList;
} catch (error) { } catch (error) {
const blockName = fileName + "--" + "delHistoryMsg"; const blockName = fileName + "--" + "delHistoryMsg";
ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error); ctx.app.middleware.utils.log('../../../serviceLog', blockName + ">>>>" + error);
@@ -378,13 +391,13 @@ class HomeService extends Service {
where = { organization: result.organization, role: { [Op.not]: 1 } }, dbOptions, joinSubstring = []; where = { organization: result.organization, role: { [Op.not]: 1 } }, dbOptions, joinSubstring = [];
attributes.forEach(element => { attributes.forEach(element => {
if (searchOptions[element]) { if (searchOptions[element]) {
if(searchOptions[element] == '*空') { if (searchOptions[element] == '*空') {
if(joinSubstring.includes(element)) { if (joinSubstring.includes(element)) {
where[element] = null; where[element] = null;
} else { } else {
where[element] = [null, '']; where[element] = [null, ''];
} }
} else{ } else {
where[element] = { [Op.substring]: searchOptions[element] }; where[element] = { [Op.substring]: searchOptions[element] };
} }
} }