北斗应用技术培训考试管理系统

This commit is contained in:
2026-03-27 17:54:10 +08:00
commit 359dff3cad
106 changed files with 9510 additions and 0 deletions

145
app/service/Importerror.js Normal file
View File

@@ -0,0 +1,145 @@
'use strict';
const Service = require('../core/base_service');
const { Op } = require('sequelize');
const fileName = "Importerror";
class ImporterrorService extends Service {
// 查看导入错误记录
async showImporterror(body) {
const { ctx } = this;
try {
let { offset, limit, searchOptions, sortOptions } = body;
offset = (offset - 1) * limit;
let attributes = ['user_name', 'identity_card', 'exam_uid', 'type', 'status', 'created_at'],
where = {}, order = [], dbOptions, joinSubstring = [],
substring = ['user_name', 'identity_card', 'exam_uid'],
key = ['type', 'status'],
between = ['created_at'];
attributes.forEach(element => {
if (searchOptions[element]) {
if (searchOptions[element] == '*空') {
if (joinSubstring.includes(element)) {
where[element] = null;
} else {
where[element] = [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 examination = ['exam_name'],
examinationWhere = {},
examinationOrder = [],
examinationJoinSubstring = [],
examinationSubstring = ['exam_name'],
examinationKey = [],
examinationBetween = [];
examination.forEach(item => {
if (searchOptions[item]) {
if (searchOptions[item] == '*空') {
if (examinationJoinSubstring.includes(item)) {
examinationWhere[item] = null;
} else {
examinationWhere[item] = [null, ''];
}
} else if (examinationSubstring.includes(item)) {
examinationWhere[item] = { [Op.substring]: searchOptions[item] };
} else if (examinationKey.includes(item)) {
examinationWhere[item] = searchOptions[item];
} else if (examinationBetween.includes(item)) {
examinationWhere[item] = { [Op.between]: [searchOptions[item][0], searchOptions[item][1]] };
}
}
if (sortOptions[item] == true) {
examinationOrder.push([item, 'ASC']);
} else if (sortOptions[item] == false) {
examinationOrder.push([item, 'DESC']);
}
});
let include = [
{
model: ctx.model.Examination,
attributes: ['exam_name'],
where: examinationWhere,
order: examinationOrder
}
];
ctx.model.Importerror.belongsTo(ctx.model.Examination, { foreignKey: 'exam_uid', targetKey: 'uid' });
dbOptions = { attributes, offset, limit, where, order, include };
const result = await ctx.model.Importerror.findAndCountAll(dbOptions);
return result.rows.length == 0 ? false : result;
} catch (error) {
const blockName = fileName + "--" + "showImporterror";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
// 删除导入错误记录
async deleteImporterror(uid, modelType, password, requestMsg) {
const { ctx } = this;
const systemImporterror = {
operate: 2,
operate_msg: '删除导入错误记录',
type: 2,
status: 0,
affect_entries: 0,
user: uid,
created_at: new Date()
};
try {
const result = await ctx.model.Manager.findOne({ where: { uid } });
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 2) {
if (!result) systemImporterror.status = 0;
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemImporterror.status = 1;
else if (result.dataValues.role < 2) systemImporterror.status = 2;
await ctx.model.Importerror.create(systemImporterror);
return false;
};
let where = {};
if (modelType == "single") {
const { identity_card, exam_uid, created_at } = requestMsg;
where = { identity_card, exam_uid, created_at };
} else if (modelType == "multiple") {
let identity_card = [], exam_uid = [], created_at = [];
for (const key in requestMsg) {
requestMsg[key].forEach(element => {
identity_card.push(element.identity_card),
exam_uid.push(element.exam_uid),
created_at.push(element.created_at)
});
}
where = { identity_card, exam_uid, created_at };
}
const resultList = await ctx.model.Importerror.destroy({ where });
systemImporterror.status = resultList == 0 ? 3 : 4;
systemImporterror.affect_entries = resultList;
await ctx.model.Importerror.create(systemImporterror);
return resultList == 0 ? false : true;
} catch (error) {
systemImporterror.status = 5;
await ctx.model.Importerror.create(systemImporterror);
const blockName = fileName + "--" + "deleteImporterror";
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
return 'error';
}
}
}
module.exports = ImporterrorService;