2026-03-27 17:49:17 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const Service = require('../core/base_service');
|
|
|
|
|
|
|
|
|
|
const { Op } = require('sequelize');
|
|
|
|
|
|
2026-06-05 17:38:10 +08:00
|
|
|
const moment = require('moment');
|
|
|
|
|
|
2026-03-27 17:49:17 +08:00
|
|
|
const fileName = "ContestExamination";
|
|
|
|
|
|
|
|
|
|
class ContestExaminationService extends Service {
|
2026-06-05 17:38:10 +08:00
|
|
|
// 管理系统查看账号答题情况
|
|
|
|
|
async showExamination(body) {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
|
|
|
|
let { offset, limit, searchOptions, sortOptions } = body;
|
|
|
|
|
offset = (offset - 1) * limit;
|
|
|
|
|
let attributes = ['user_uid', 'contest_uid', 'exam_type', 'topic_type', 'score', 'created_at', 'updated_at'],
|
|
|
|
|
where = {}, order = [], dbOptions,
|
|
|
|
|
joinSubstring = [],
|
|
|
|
|
substring = ['user_uid', 'contest_uid', 'score'],
|
|
|
|
|
key = ['exam_type', 'topic_type'],
|
|
|
|
|
between = ['created_at', 'updated_at'];
|
|
|
|
|
attributes.forEach(element => {
|
|
|
|
|
if (searchOptions[element]) {
|
|
|
|
|
if (searchOptions[element] == '*空') {
|
|
|
|
|
if (joinSubstring.includes(element)) {
|
|
|
|
|
where[element] = null;
|
|
|
|
|
} else {
|
|
|
|
|
where[element] = [null, ''];
|
|
|
|
|
}
|
|
|
|
|
} else if (joinSubstring.includes(element)) {
|
|
|
|
|
let targetKeyArr = [];
|
|
|
|
|
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
|
|
|
|
} else if (substring.includes(element)) {
|
|
|
|
|
where[element] = { [Op.substring]: searchOptions[element] };
|
|
|
|
|
} else if (key.includes(element)) {
|
|
|
|
|
where[element] = searchOptions[element];
|
|
|
|
|
} else if (between.includes(element)) {
|
|
|
|
|
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (sortOptions[element] == true) {
|
|
|
|
|
order.push([element, 'ASC']);
|
|
|
|
|
} else if (sortOptions[element] == false) {
|
|
|
|
|
order.push([element, 'DESC']);
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
2026-06-05 17:38:10 +08:00
|
|
|
});
|
|
|
|
|
dbOptions = { attributes, offset, limit, where, order };
|
|
|
|
|
const result = await ctx.model4.Examination.findAndCountAll(dbOptions);
|
|
|
|
|
return result.rows.length == 0 ? false : result;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "showExamination";
|
|
|
|
|
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
2026-06-05 17:38:10 +08:00
|
|
|
}
|
2026-03-27 17:49:17 +08:00
|
|
|
|
2026-06-05 17:38:10 +08:00
|
|
|
// 管理系统编辑账号答题情况
|
|
|
|
|
async editExamination(uid, modelType, updateMsg, requestMsg) {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
|
|
|
|
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
|
|
|
|
if (!result || result.dataValues.role < 6) return false;
|
|
|
|
|
let where = {};
|
|
|
|
|
if (modelType == "single") {
|
|
|
|
|
const { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at } = requestMsg;
|
|
|
|
|
where = { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at };
|
|
|
|
|
} else if (modelType == "multiple") {
|
|
|
|
|
let user_uid = [], contest_uid = [], exam_type = [], topic_type = [], score = [], created_at = [], updated_at = [];
|
|
|
|
|
for (const key in requestMsg) {
|
|
|
|
|
requestMsg[key].forEach(element => {
|
|
|
|
|
user_uid.push(element.user_uid),
|
|
|
|
|
contest_uid.push(element.contest_uid),
|
|
|
|
|
exam_type.push(element.exam_type),
|
|
|
|
|
topic_type.push(element.topic_type),
|
|
|
|
|
score.push(element.score),
|
|
|
|
|
created_at.push(element.created_at),
|
|
|
|
|
updated_at.push(element.updated_at)
|
|
|
|
|
});
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
2026-06-05 17:38:10 +08:00
|
|
|
where = { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at };
|
|
|
|
|
}
|
|
|
|
|
updateMsg.updated_at = new Date();
|
|
|
|
|
const resultList = await ctx.model4.Examination.update(updateMsg, { where });
|
|
|
|
|
return resultList[0] == 0 ? false : resultList;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "editExamination";
|
|
|
|
|
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
2026-06-05 17:38:10 +08:00
|
|
|
}
|
2026-03-27 17:49:17 +08:00
|
|
|
|
2026-06-05 17:38:10 +08:00
|
|
|
// 管理系统删除账号答题情况
|
|
|
|
|
async delExamination(uid, modelType, password, requestMsg) {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
const systemMonitoring = {
|
|
|
|
|
operate: 2,
|
|
|
|
|
operate_msg: '删除账号答题情况',
|
|
|
|
|
type: 0,
|
|
|
|
|
status: 0,
|
|
|
|
|
affect_entries: 0,
|
|
|
|
|
user: uid,
|
|
|
|
|
created_at: new Date()
|
|
|
|
|
};
|
|
|
|
|
try {
|
|
|
|
|
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
|
|
|
|
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
|
|
|
|
if (!result) systemMonitoring.status = 0;
|
|
|
|
|
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemMonitoring.status = 1;
|
|
|
|
|
else if (result.dataValues.role < 9) systemMonitoring.status = 2;
|
|
|
|
|
await ctx.model3.Monitoring.create(systemMonitoring);
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
let where = {};
|
|
|
|
|
if (modelType == "single") {
|
|
|
|
|
const { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at } = requestMsg;
|
|
|
|
|
where = { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at };
|
|
|
|
|
} else if (modelType == "multiple") {
|
|
|
|
|
let user_uid = [], contest_uid = [], exam_type = [], topic_type = [], score = [], created_at = [], updated_at = [];
|
|
|
|
|
for (const key in requestMsg) {
|
|
|
|
|
requestMsg[key].forEach(element => {
|
|
|
|
|
user_uid.push(element.user_uid),
|
|
|
|
|
contest_uid.push(element.contest_uid),
|
|
|
|
|
exam_type.push(element.exam_type),
|
|
|
|
|
topic_type.push(element.topic_type),
|
|
|
|
|
score.push(element.score),
|
|
|
|
|
created_at.push(element.created_at),
|
|
|
|
|
updated_at.push(element.updated_at)
|
|
|
|
|
});
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
2026-06-05 17:38:10 +08:00
|
|
|
where = { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at };
|
|
|
|
|
}
|
|
|
|
|
const resultList = await ctx.model4.Examination.destroy({ where });
|
|
|
|
|
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
|
|
|
|
systemMonitoring.affect_entries = resultList;
|
|
|
|
|
await ctx.model3.Monitoring.create(systemMonitoring);
|
|
|
|
|
return resultList == 0 ? false : true;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "delExamination";
|
|
|
|
|
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
2026-06-05 17:38:10 +08:00
|
|
|
}
|
2026-03-27 17:49:17 +08:00
|
|
|
|
2026-06-05 17:38:10 +08:00
|
|
|
// 管理系统导出账号答题情况
|
|
|
|
|
async downloadExamination(uid, searchMsg) {
|
|
|
|
|
const { ctx } = this;
|
|
|
|
|
try {
|
|
|
|
|
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
|
|
|
|
if (!user || user.dataValues.role < 3) return false;
|
|
|
|
|
let { searchOptions, sortOptions } = searchMsg;
|
|
|
|
|
let attributes = ['user_uid', 'contest_uid', 'exam_type', 'topic_type', 'topic1', 'topic2', 'topic3', 'topic5', 'answer', 'answer1', 'answer2', 'answer3', 'answer4', 'answer5', 'score', 'score_collection', 'created_at', 'updated_at'],
|
|
|
|
|
where = {}, order = [], dbOptions,
|
|
|
|
|
joinSubstring = [],
|
|
|
|
|
substring = ['user_uid', 'contest_uid', 'topic1', 'topic2', 'topic3', 'topic5', 'answer', 'answer1', 'answer2', 'answer3', 'answer4', 'answer5', 'score', 'score_collection'],
|
|
|
|
|
key = ['exam_type', 'topic_type'],
|
|
|
|
|
between = ['created_at', 'updated_at'];
|
|
|
|
|
attributes.forEach(element => {
|
|
|
|
|
if (searchOptions[element]) {
|
|
|
|
|
if (searchOptions[element] == '*空') {
|
|
|
|
|
if (joinSubstring.includes(element)) {
|
|
|
|
|
where[element] = null;
|
|
|
|
|
} else {
|
|
|
|
|
where[element] = [null, ''];
|
|
|
|
|
}
|
|
|
|
|
} else if (joinSubstring.includes(element)) {
|
|
|
|
|
let targetKeyArr = [];
|
|
|
|
|
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
|
|
|
|
} else if (substring.includes(element)) {
|
|
|
|
|
where[element] = { [Op.substring]: searchOptions[element] };
|
|
|
|
|
} else if (key.includes(element)) {
|
|
|
|
|
where[element] = searchOptions[element];
|
|
|
|
|
} else if (between.includes(element)) {
|
|
|
|
|
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (sortOptions[element] == true) {
|
|
|
|
|
order.push([element, 'ASC']);
|
|
|
|
|
} else if (sortOptions[element] == false) {
|
|
|
|
|
order.push([element, 'DESC']);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
let include = [
|
|
|
|
|
{
|
|
|
|
|
model: ctx.model4.Account,
|
|
|
|
|
attributes: ['account_name']
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
model: ctx.model4.Contest,
|
|
|
|
|
attributes: ['contest_name']
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
ctx.model4.Examination.belongsTo(ctx.model4.Account, { foreignKey: 'user_uid', targetKey: 'uid' });
|
|
|
|
|
ctx.model4.Examination.belongsTo(ctx.model4.Contest, { foreignKey: 'contest_uid', targetKey: 'uid' });
|
|
|
|
|
dbOptions = { attributes, where, order, include };
|
|
|
|
|
const result = await ctx.model4.Examination.findAll(dbOptions);
|
|
|
|
|
if (result.length == 0) return { code: false };
|
|
|
|
|
let data = [];
|
|
|
|
|
const examTypeOptions = [
|
|
|
|
|
{
|
|
|
|
|
value: "0",
|
|
|
|
|
label: "线上赛"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: "1",
|
|
|
|
|
label: "线下赛"
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
2026-06-05 17:38:10 +08:00
|
|
|
];
|
|
|
|
|
const topicTypeOptions = [
|
|
|
|
|
{
|
|
|
|
|
value: "1",
|
|
|
|
|
label: "1"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: "2",
|
|
|
|
|
label: "2"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: "3",
|
|
|
|
|
label: "3"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: "4",
|
|
|
|
|
label: "4"
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: "5",
|
|
|
|
|
label: "5"
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
result.forEach(element => {
|
|
|
|
|
examTypeOptions.forEach((item) => {
|
|
|
|
|
if (item.value == element.dataValues["exam_type"]) {
|
|
|
|
|
element.dataValues["exam_type"] = item.label;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
topicTypeOptions.forEach((item) => {
|
|
|
|
|
if (item.value == element.dataValues["topic_type"]) {
|
|
|
|
|
element.dataValues["topic_type"] = item.label;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
element.dataValues.account_name = element.dataValues.account.dataValues.account_name;
|
|
|
|
|
element.dataValues.contest_name = element.dataValues.contest.dataValues.contest_name;
|
|
|
|
|
element.dataValues.created_at = moment
|
|
|
|
|
.utc(element.dataValues.created_at)
|
|
|
|
|
.add(8, "hours")
|
|
|
|
|
.format("YYYY年MM月DD日HH时mm分ss秒");
|
|
|
|
|
element.dataValues.updated_at = moment
|
|
|
|
|
.utc(element.dataValues.updated_at)
|
|
|
|
|
.add(8, "hours")
|
|
|
|
|
.format("YYYY年MM月DD日HH时mm分ss秒");
|
|
|
|
|
delete element.dataValues.account;
|
|
|
|
|
delete element.dataValues.contest;
|
|
|
|
|
data.push(element.dataValues);
|
|
|
|
|
});
|
|
|
|
|
return { code: true, data };
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const blockName = fileName + "--" + "downloadExamination";
|
|
|
|
|
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
|
|
|
|
return 'error';
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
2026-06-05 17:38:10 +08:00
|
|
|
}
|
2026-03-27 17:49:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = ContestExaminationService;
|