2026-03-27 17:49:17 +08:00
|
|
|
const Controller = require('../core/base_controller');
|
|
|
|
|
|
2026-06-05 17:38:10 +08:00
|
|
|
const fs = require('fs');
|
|
|
|
|
|
2026-03-27 17:49:17 +08:00
|
|
|
const fileName = "ContestMsg";
|
|
|
|
|
|
|
|
|
|
class ContestMsgController extends Controller {
|
|
|
|
|
// 管理系统检索竞赛 uid
|
|
|
|
|
async searchContestUid() {
|
|
|
|
|
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 result = await ctx.service.contestMsg.searchContestUid(uid, body);
|
|
|
|
|
if (result == "error") {
|
|
|
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (result) {
|
|
|
|
|
let contestUid = [];
|
|
|
|
|
result.forEach(element => {
|
|
|
|
|
contestUid.push({ value: element.dataValues.uid });
|
|
|
|
|
});
|
|
|
|
|
this.setResponse(ctx, 200, '操作成功', "polymerization", contestUid);
|
|
|
|
|
} else {
|
|
|
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "searchContestUid";
|
|
|
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
|
|
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 管理系统创建竞赛信息
|
|
|
|
|
async addContest() {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
|
|
|
|
let rdmcode = await this.checkUid(ctx);
|
|
|
|
|
if (!rdmcode) {
|
|
|
|
|
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const requestMsg = ctx.request.body.requestMsg;
|
|
|
|
|
requestMsg.forEach(element => {
|
|
|
|
|
element.uid = this.generateNumberString('H');
|
|
|
|
|
element.contest_name = this.decryptRequest(element.contest_name);
|
|
|
|
|
element.contest_organizers = this.decryptRequest(element.contest_organizers);
|
|
|
|
|
element.contest_term = this.decryptRequest(element.contest_term);
|
|
|
|
|
element.type = Number(element.type);
|
|
|
|
|
element.status = 0;
|
|
|
|
|
element.online_start = new Date(element.online_start);
|
|
|
|
|
element.online_end = new Date(element.online_end);
|
|
|
|
|
element.offline_start = new Date(element.offline_start);
|
|
|
|
|
element.offline_end = new Date(element.offline_end);
|
|
|
|
|
element.contest_start = new Date(element.contest_start);
|
|
|
|
|
element.contest_end = new Date(element.contest_end);
|
|
|
|
|
element.created_at = new Date();
|
|
|
|
|
});
|
|
|
|
|
const result = await ctx.service.contestMsg.addContest(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 + "--" + "addContest";
|
|
|
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
|
|
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 管理系统查看竞赛信息
|
|
|
|
|
async showContest() {
|
|
|
|
|
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.contestMsg.showContest(body);
|
|
|
|
|
if (result == "error") {
|
|
|
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (result) {
|
|
|
|
|
let contestMsg = [];
|
|
|
|
|
result.rows.forEach(element => {
|
2026-06-05 17:38:10 +08:00
|
|
|
contestMsg.push(element.dataValues);
|
2026-03-27 17:49:17 +08:00
|
|
|
});
|
|
|
|
|
const data = {
|
2026-06-05 17:38:10 +08:00
|
|
|
contestMsg,
|
|
|
|
|
count: result.count
|
2026-03-27 17:49:17 +08:00
|
|
|
};
|
|
|
|
|
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
|
|
|
|
} else {
|
|
|
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "showContest";
|
|
|
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
|
|
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 管理系统编辑竞赛信息
|
|
|
|
|
async editContest() {
|
|
|
|
|
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, updateMsg, requestMsg } = body
|
|
|
|
|
const modelType = this.decryptRequest(model);
|
|
|
|
|
const result = await ctx.service.contestMsg.editContest(uid, modelType, updateMsg, 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 + "--" + "editContest";
|
|
|
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
|
|
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 管理系统删除竞赛信息
|
|
|
|
|
async delContest() {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
|
|
|
|
let rdmcode = await this.checkUid(ctx);
|
|
|
|
|
if (!rdmcode) {
|
2026-06-05 17:38:10 +08:00
|
|
|
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
|
|
|
|
return;
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
|
|
|
|
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.contestMsg.delContest(uid, modelType, deCodePassword, requestMsg);
|
|
|
|
|
if (result == "error") {
|
2026-06-05 17:38:10 +08:00
|
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
|
|
|
return;
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
|
|
|
|
if (result) {
|
2026-06-05 17:38:10 +08:00
|
|
|
this.setResponse(ctx, 200, '操作成功', "none");
|
2026-03-27 17:49:17 +08:00
|
|
|
} else {
|
2026-06-05 17:38:10 +08:00
|
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "delContest";
|
|
|
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
|
|
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-05 17:38:10 +08:00
|
|
|
|
|
|
|
|
// 管理系统导出竞赛信息
|
|
|
|
|
async downloadContest() {
|
|
|
|
|
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.contestMsg.downloadContest(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 + "--" + "downloadContest";
|
|
|
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
|
|
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = ContestMsgController;
|