174 lines
7.0 KiB
JavaScript
174 lines
7.0 KiB
JavaScript
|
|
const Controller = require('../core/base_controller');
|
||
|
|
|
||
|
|
const fileName = "ContestTopic";
|
||
|
|
|
||
|
|
class ContestTopicController extends Controller {
|
||
|
|
// 管理系统导入选择题
|
||
|
|
async importChoiceTopic() {
|
||
|
|
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.topic = this.decryptRequest(element.topic);
|
||
|
|
element.options_a = this.decryptRequest(element.options_a);
|
||
|
|
element.options_b = this.decryptRequest(element.options_b);
|
||
|
|
element.options_c = this.decryptRequest(element.options_c);
|
||
|
|
element.options_d = this.decryptRequest(element.options_d);
|
||
|
|
element.answer = this.decryptRequest(element.answer);
|
||
|
|
});
|
||
|
|
const result = await ctx.service.contestTopic.importChoiceTopic(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 + "--" + "importChoiceTopic";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 管理系统创建选择题
|
||
|
|
async addChoiceTopic() {
|
||
|
|
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.topic = this.decryptRequest(element.topic);
|
||
|
|
element.options_a = this.decryptRequest(element.options_a);
|
||
|
|
element.options_b = this.decryptRequest(element.options_b);
|
||
|
|
element.options_c = this.decryptRequest(element.options_c);
|
||
|
|
element.options_d = this.decryptRequest(element.options_d);
|
||
|
|
element.answer = this.decryptRequest(element.answer);
|
||
|
|
});
|
||
|
|
const result = await ctx.service.contestTopic.addChoiceTopic(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 + "--" + "addChoiceTopic";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 管理系统查看选择题
|
||
|
|
async showChoiceTopic() {
|
||
|
|
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.contestTopic.showChoiceTopic(body);
|
||
|
|
if (result == "error") {
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (result) {
|
||
|
|
let choiceTopicMsg = [];
|
||
|
|
result.rows.forEach(element => {
|
||
|
|
choiceTopicMsg.push(element.dataValues);
|
||
|
|
});
|
||
|
|
const data = {
|
||
|
|
choiceTopicMsg,
|
||
|
|
count: result.count
|
||
|
|
};
|
||
|
|
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||
|
|
} else {
|
||
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
const blockName = fileName + "--" + "showChoiceTopic";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 管理系统编辑选择题
|
||
|
|
async editChoiceTopic() {
|
||
|
|
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.contestTopic.editChoiceTopic(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 + "--" + "editChoiceTopic";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 管理系统删除选择题
|
||
|
|
async delChoiceTopic() {
|
||
|
|
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.contestTopic.delChoiceTopic(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 + "--" + "delChoiceTopic";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = ContestTopicController;
|