常规推送
This commit is contained in:
@@ -72,7 +72,7 @@ class HomeController extends Controller {
|
||||
}
|
||||
const uid = JSON.parse(rdmcode).uid;
|
||||
const result = await ctx.service.home.getCard(uid);
|
||||
if(result == "error") {
|
||||
if (result == "error") {
|
||||
setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ class HomeController extends Controller {
|
||||
const uid = JSON.parse(rdmcode).uid;
|
||||
const { cardID } = ctx.request.body;
|
||||
const result = await ctx.service.home.searchCard(cardID);
|
||||
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 body = ctx.request.body;
|
||||
const result = await ctx.service.home.bindCard(uid, body);
|
||||
if(result == "error") {
|
||||
if (result == "error") {
|
||||
setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
@@ -162,7 +162,7 @@ class HomeController extends Controller {
|
||||
const uid = JSON.parse(rdmcode).uid;
|
||||
const body = ctx.request.body;
|
||||
const result = await ctx.service.home.unBindingCard(uid, body);
|
||||
if(result == "error") {
|
||||
if (result == "error") {
|
||||
setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
@@ -193,7 +193,7 @@ class HomeController extends Controller {
|
||||
const password = decryptRequest(body.password);
|
||||
const requestMsg = body.userMsg;
|
||||
const result = await ctx.service.home.unBindManager(uid, model, password, requestMsg);
|
||||
if(result == "error") {
|
||||
if (result == "error") {
|
||||
setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
@@ -221,7 +221,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;
|
||||
}
|
||||
@@ -261,7 +261,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;
|
||||
}
|
||||
@@ -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() {
|
||||
const ctx = this.ctx;
|
||||
@@ -289,7 +318,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;
|
||||
}
|
||||
@@ -328,7 +357,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;
|
||||
}
|
||||
@@ -355,11 +384,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.bsideManager(uid, body);
|
||||
}
|
||||
if(result == "error") {
|
||||
if (result == "error") {
|
||||
setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ module.exports = (app) => {
|
||||
const { senderAddress, msgData, encodingCategory } = outboundMsg;
|
||||
// socket接收消息后触发事件监听器,将消息发送给websocket客户端并存储在数据库中
|
||||
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',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
method: 'POST',
|
||||
@@ -107,6 +107,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: {
|
||||
card_id: senderAddress.data,
|
||||
original_msg: originalMsg,
|
||||
msg_data: msgData.data,
|
||||
created_at: new Date()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
// 重发消息处理
|
||||
if (resendResult && resendResult.type == 4) {
|
||||
@@ -114,8 +128,8 @@ module.exports = (app) => {
|
||||
const { outboundMsg, receiverAddress } = msgContent;
|
||||
const { senderAddress, msgData, encodingCategory } = outboundMsg;
|
||||
// socket接收消息后触发事件监听器,将消息发送给websocket客户端并存储在数据库中
|
||||
shunt.socketEmitter().emit(senderAddress.data, msgData.data);
|
||||
await app.curl('http://127.0.0.1:' + app.server.address().port + '/shortMsg', {
|
||||
shunt.socketEmitter().emit(senderAddress.data, { encode_type: parseInt(encodingCategory.data), msg_data: msgData.data, created_at: new Date() });
|
||||
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',
|
||||
@@ -129,6 +143,20 @@ module.exports = (app) => {
|
||||
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()
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
20
app/model3/UnknownBDCard.js
Normal file
20
app/model3/UnknownBDCard.js
Normal 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;
|
||||
};
|
||||
@@ -32,6 +32,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);
|
||||
// 删除历史消息
|
||||
|
||||
@@ -208,13 +208,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;
|
||||
@@ -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) {
|
||||
const { ctx } = this;
|
||||
@@ -286,8 +299,8 @@ class HomeService extends Service {
|
||||
substring = ['card_id', 'msg_data'], key = ['encode_type'], 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, ''];
|
||||
@@ -358,7 +371,7 @@ class HomeService extends Service {
|
||||
"T": ctx.model4.TShortMsg,
|
||||
};
|
||||
const resetList = await modelName[uidLastCode].destroy({ where });
|
||||
return resetList.length == 0 ? false : resetList;
|
||||
return resetList == 0 ? false : resetList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "delHistoryMsg";
|
||||
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 = [];
|
||||
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] };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user