157 lines
5.8 KiB
JavaScript
157 lines
5.8 KiB
JavaScript
|
|
const Controller = require('../core/base_controller');
|
||
|
|
|
||
|
|
const fileName = "Home";
|
||
|
|
|
||
|
|
class HomeController extends Controller {
|
||
|
|
// 题库登录接口
|
||
|
|
async login() {
|
||
|
|
const { ctx } = this;
|
||
|
|
try {
|
||
|
|
const body = ctx.request.body;
|
||
|
|
const result = await ctx.service.home.login(body);
|
||
|
|
if (result == "error") {
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (result) {
|
||
|
|
await ctx.app.redis.get('db3').set(result.dataValues.user_uid, result.dataValues.type, 'EX', 21600);
|
||
|
|
this.setResponse(ctx, 200, '操作成功', "polymerization", this.encryptRequest(result.dataValues.user_uid + '?' + new Date().getTime()));
|
||
|
|
} else {
|
||
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
const blockName = fileName + "--" + "login";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取题库登录状态接口
|
||
|
|
async loginStatus() {
|
||
|
|
const { ctx } = this;
|
||
|
|
try {
|
||
|
|
const data = ctx.request.body.data;
|
||
|
|
const topic = await ctx.app.redis.get('db3').get(this.decryptRequest(data).split('?')[0]);
|
||
|
|
if (topic == null) {
|
||
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
||
|
|
} else {
|
||
|
|
this.setResponse(ctx, 200, '操作成功', "none");
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
const blockName = fileName + "--" + "loginStatus";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取单选题接口
|
||
|
|
async radio() {
|
||
|
|
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.home.radio(body);
|
||
|
|
if (result == "error") {
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (result) {
|
||
|
|
this.setResponse(ctx, 200, '操作成功', "deconstruction", result);
|
||
|
|
} else {
|
||
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
const blockName = fileName + "--" + "radio";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取多选题接口
|
||
|
|
async multiple() {
|
||
|
|
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.home.multiple(body);
|
||
|
|
if (result == "error") {
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (result) {
|
||
|
|
this.setResponse(ctx, 200, '操作成功', "deconstruction", result);
|
||
|
|
} else {
|
||
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
const blockName = fileName + "--" + "multiple";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取判断题接口
|
||
|
|
async judgment() {
|
||
|
|
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.home.judgment(body);
|
||
|
|
if (result == "error") {
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (result) {
|
||
|
|
this.setResponse(ctx, 200, '操作成功', "deconstruction", result);
|
||
|
|
} else {
|
||
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
const blockName = fileName + "--" + "judgment";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取问答题接口
|
||
|
|
async interlocution() {
|
||
|
|
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.home.interlocution(body);
|
||
|
|
if (result == "error") {
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (result) {
|
||
|
|
this.setResponse(ctx, 200, '操作成功', "deconstruction", result);
|
||
|
|
} else {
|
||
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
||
|
|
}
|
||
|
|
} catch (error) {
|
||
|
|
const blockName = fileName + "--" + "interlocution";
|
||
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
module.exports = HomeController;
|