129 lines
5.2 KiB
JavaScript
129 lines
5.2 KiB
JavaScript
|
|
'use strict';
|
||
|
|
|
||
|
|
const Controller = require('../core/base_controller');
|
||
|
|
|
||
|
|
const fs = require('fs');
|
||
|
|
|
||
|
|
const fileName = "UnknownSN";
|
||
|
|
|
||
|
|
class UnknownSNController extends Controller {
|
||
|
|
// 查看未知消息
|
||
|
|
async showUnknownSN() {
|
||
|
|
const { ctx } = this;
|
||
|
|
try {
|
||
|
|
let rdmcode = await this.checkUid(ctx);
|
||
|
|
if (!rdmcode) {
|
||
|
|
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
const body = ctx.request.body;
|
||
|
|
const result = await ctx.service.unknownSN.showUnknownSN(body);
|
||
|
|
if (result == "error") {
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (result) {
|
||
|
|
let unknownSNRecord = [];
|
||
|
|
result.rows.forEach(element => {
|
||
|
|
unknownSNRecord.push(element.dataValues);
|
||
|
|
});
|
||
|
|
const data = {
|
||
|
|
unknownSNRecord,
|
||
|
|
count: result.count
|
||
|
|
};
|
||
|
|
this.setResponse(ctx, 200, '搜索未知消息成功', "deconstruction", data);
|
||
|
|
} else {
|
||
|
|
this.setResponse(ctx, 404, '搜索未知消息失败', "none");
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
const blockName = fileName + "--" + "showUnknownSN";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 删除未知消息
|
||
|
|
async deleteUnknownSN() {
|
||
|
|
const { ctx } = this;
|
||
|
|
try {
|
||
|
|
let rdmcode = await this.checkUid(ctx);
|
||
|
|
if (!rdmcode) {
|
||
|
|
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
const uid = JSON.parse(rdmcode).uid;
|
||
|
|
const body = ctx.request.body;
|
||
|
|
const { model, password, requestMsg } = body
|
||
|
|
const modelType = this.decryptRequest(model);
|
||
|
|
const deCodePassword = this.decryptRequest(password);
|
||
|
|
const result = await ctx.service.unknownSN.deleteUnknownSN(uid, modelType, deCodePassword, requestMsg);
|
||
|
|
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 + "--" + "deleteUnknownSN";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 管理系统导出竞赛账号信息
|
||
|
|
async downloadUnknownSN() {
|
||
|
|
const { ctx } = this;
|
||
|
|
try {
|
||
|
|
let rdmcode = await this.checkUid(ctx);
|
||
|
|
if (!rdmcode) {
|
||
|
|
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
const uid = JSON.parse(rdmcode).uid;
|
||
|
|
const { form, searchMsg, dataHeaders } = ctx.request.body;
|
||
|
|
const result = await ctx.service.unknownSN.downloadUnknownSN(uid, searchMsg);
|
||
|
|
if (result == "error") {
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (result.code) {
|
||
|
|
const file = this.downloadData(form, result.data, dataHeaders);
|
||
|
|
if (file) {
|
||
|
|
const { filePath, completeName, buf } = file;
|
||
|
|
try {
|
||
|
|
fs.writeFileSync(filePath, Buffer.from(buf));
|
||
|
|
const data = {
|
||
|
|
// 本机服务器地址
|
||
|
|
// 'http://127.0.0.1:8012'
|
||
|
|
// 'http://192.168.31.28:8012'
|
||
|
|
// 公司服务器地址
|
||
|
|
// 'http://123.57.205.46:8012'
|
||
|
|
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||
|
|
fileUrl: 'http://127.0.0.1:8012' + `/public/${completeName}?time=${new Date().getTime()}`,
|
||
|
|
fileName: completeName,
|
||
|
|
}
|
||
|
|
this.setResponse(ctx, 200, '文件已成功写入', "deconstruction", data);
|
||
|
|
setTimeout(() => {
|
||
|
|
fs.unlinkSync(filePath);
|
||
|
|
}, 600000);
|
||
|
|
} catch (error) {
|
||
|
|
this.setResponse(ctx, 500, '写入文件时发生错误', "none");
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
const blockName = fileName + "--" + "downloadUnknownSN";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = UnknownSNController;
|