北斗应用技术培训考试管理系统
195
app/controller/Admin.js
Normal file
@@ -0,0 +1,195 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "Admin";
|
||||
|
||||
class AdminController extends Controller {
|
||||
// 管理系统新增普通管理员账号信息
|
||||
async addAdmin() {
|
||||
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 => {
|
||||
const salt = this.generateRandomString();
|
||||
element.uid = this.generateNumberString('E');
|
||||
element.salt = this.encryptRequest(salt);
|
||||
element.account_name = this.decryptRequest(element.account_name);
|
||||
element.password = this.shaForm('123456', salt);
|
||||
element.role = Number(this.decryptRequest(element.role));
|
||||
element.status = 0;
|
||||
element.created_at = new Date();
|
||||
element.updated_at = new Date();
|
||||
element.login_status = 0;
|
||||
});
|
||||
const result = await ctx.service.admin.addAdmin(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 + "--" + "addAdmin";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看普通管理员账号信息
|
||||
async showAdmin() {
|
||||
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.admin.showAdmin(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let adminMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
adminMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
adminMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showAdmin";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑普通管理员账号信息
|
||||
async editAdmin() {
|
||||
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 { model, updateMsg, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const result = await ctx.service.admin.editAdmin(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 + "--" + "editAdmin";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除普通管理员账号信息
|
||||
async deleteAdmin() {
|
||||
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 { model, password, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.admin.deleteAdmin(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 + "--" + "deleteAdmin";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出普通管理员账号信息数据
|
||||
async downloadAdminData() {
|
||||
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.admin.downloadAdminData(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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "downloadAdminData";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AdminController;
|
||||
222
app/controller/Application.js
Normal file
@@ -0,0 +1,222 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "Application";
|
||||
|
||||
class ApplicationController extends Controller {
|
||||
// 管理系统新增用户报名信息
|
||||
async addApplication() {
|
||||
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;
|
||||
let userMsgObj = {
|
||||
user_name: [],
|
||||
identity_card: []
|
||||
};
|
||||
requestMsg.forEach(item => {
|
||||
item.user_name = this.decryptRequest(item.user_name);
|
||||
item.identity_card = this.decryptRequest(item.identity_card);
|
||||
item.exam_uid = this.decryptRequest(item.exam_uid);
|
||||
item.source = this.decryptRequest(item.source);
|
||||
item.status = Number(this.decryptRequest(item.status));
|
||||
item.pay_status = Number(this.decryptRequest(item.pay_status));
|
||||
item.result = this.decryptRequest(item.result);
|
||||
userMsgObj.user_name.push(item.user_name);
|
||||
userMsgObj.identity_card.push(item.identity_card);
|
||||
});
|
||||
const result = await ctx.service.application.addApplication(userMsgObj, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
if (result.code == 400) {
|
||||
this.setResponse(ctx, 400, '全部操作失败, 请前往导入错误记录页面查看导入错误的数据', "none");
|
||||
} else if (result.code == 300) {
|
||||
this.setResponse(ctx, 300, '部分操作成功, 请前往导入错误记录页面查看导入错误的数据', "none");
|
||||
} else if (result.code == 200) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
}
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addApplication";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看用户报名信息
|
||||
async showApplication() {
|
||||
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.application.showApplication(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let idCardArr = [];
|
||||
result.rows.forEach(item => {
|
||||
idCardArr.push(item.dataValues.examinee.dataValues.identity_card);
|
||||
});
|
||||
const photoResult = await ctx.service.search.checkPhoto(idCardArr);
|
||||
let applicationMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
if (photoResult == "error") {
|
||||
element.dataValues.userPhotoUrl = '#';
|
||||
}
|
||||
if (photoResult) {
|
||||
ctx.set('Cache-Control', 'no-cache, no-store, must-revalidate');
|
||||
ctx.set("Pragma", "no-cache");
|
||||
ctx.set("Expires", "0");
|
||||
photoResult.forEach(item => {
|
||||
if (element.dataValues.examinee.dataValues.identity_card == item.identity_card) {
|
||||
element.dataValues.userPhotoUrl = item.photoUrl;
|
||||
}
|
||||
});
|
||||
}
|
||||
applicationMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
applicationMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showApplication";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑用户报名信息
|
||||
async editApplication() {
|
||||
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 { model, updateMsg, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const result = await ctx.service.application.editApplication(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 + "--" + "editApplication";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除用户报名信息
|
||||
async deleteApplication() {
|
||||
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 { model, password, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.application.deleteApplication(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 + "--" + "deleteApplication";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出考生报名信息数据
|
||||
async downloadApplicationData() {
|
||||
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.application.downloadApplicationData(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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "downloadApplicationData";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ApplicationController;
|
||||
71
app/controller/Audit.js
Normal file
@@ -0,0 +1,71 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Audit";
|
||||
|
||||
class AuditController extends Controller {
|
||||
// 管理系统查看用户关键信息变更
|
||||
async auditList() {
|
||||
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.audit.auditList(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let auditMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
auditMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
auditMsg: auditMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "auditList";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统审核用户关键信息变更
|
||||
async userMsgAudit() {
|
||||
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.audit.userMsgAudit(uid, body);
|
||||
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 + "--" + "userMsgAudit";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AuditController;
|
||||
79
app/controller/Cntev.js
Normal file
@@ -0,0 +1,79 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Cntev";
|
||||
|
||||
class CntevController extends Controller {
|
||||
// 核验用户身份证二要素
|
||||
async CNTEV() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const finishedList = ctx.request.body.finishedList;
|
||||
const failedResult = await ctx.service.cntev.siftFailedList(finishedList);
|
||||
const validateResult = await ctx.service.cntev.validateList(finishedList);
|
||||
if (failedResult == "error" || validateResult == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
let finishList = [];
|
||||
if (failedResult && failedResult.length > 0) {
|
||||
failedResult.forEach(async element => {
|
||||
const check = await ctx.app.redis.get('db3').get(element.dataValues.identity_card);
|
||||
if (check == null) {
|
||||
ctx.curl('http://127.0.0.1:' + 8011 + '/CNTEV', {
|
||||
dataType: 'json',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
method: 'POST',
|
||||
timeout: 3000,
|
||||
data: {
|
||||
user_name: element.dataValues.user_name,
|
||||
identity_card: element.dataValues.identity_card,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await ctx.service.cntev.updateCNTEV(element.dataValues.user_name, element.dataValues.identity_card, JSON.parse(check).real_check);
|
||||
await ctx.app.redis.get('db3').del(element.dataValues.identity_card);
|
||||
finishList.push(element.dataValues.identity_card);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (validateResult && validateResult.length > 0) {
|
||||
validateResult.forEach(async element => {
|
||||
const check = await ctx.app.redis.get('db3').get(element.dataValues.identity_card);
|
||||
if (check == null) {
|
||||
ctx.curl('http://127.0.0.1:' + 8011 + '/CNTEV', {
|
||||
dataType: 'json',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
method: 'POST',
|
||||
timeout: 3000,
|
||||
data: {
|
||||
user_name: element.dataValues.user_name,
|
||||
identity_card: element.dataValues.identity_card,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await ctx.service.cntev.updateCNTEV(element.dataValues.user_name, element.dataValues.identity_card, JSON.parse(check).real_check);
|
||||
await ctx.app.redis.get('db3').del(element.dataValues.identity_card);
|
||||
finishList.push(element.dataValues.identity_card);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (failedResult && failedResult.length > 0 || validateResult && validateResult.length > 0) {
|
||||
const data = { finishList };
|
||||
this.setResponse(ctx, 303, '核验中', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 200, '核验成功', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "CNTEV";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CntevController;
|
||||
79
app/controller/Diff.js
Normal file
@@ -0,0 +1,79 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Diff";
|
||||
|
||||
class DiffController extends Controller {
|
||||
// 比较身份证号
|
||||
async diffIdentityCard() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const body = ctx.request.body;
|
||||
const { identity_card, type, data } = body;
|
||||
const uid = data == 'null' ? null : data.split('?')[0];
|
||||
const result = await ctx.service.diff.diffIdentityCard(identity_card, type, uid);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (!result) {
|
||||
this.setResponse(ctx, 404, '该身份证号已注册', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 200, '验证通过', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "diffIdentityCard";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 比较邮箱
|
||||
async diffEmail() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const body = ctx.request.body;
|
||||
const { email, type, data } = body;
|
||||
const uid = data == 'null' ? null : data.split('?')[0];
|
||||
const result = await ctx.service.diff.diffEmail(email, type, uid);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (!result) {
|
||||
this.setResponse(ctx, 404, '该邮箱已经注册', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 200, '验证通过', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "diffEmail";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 比较电话号码
|
||||
async diffPhone() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const body = ctx.request.body;
|
||||
const { phone, type, data } = body;
|
||||
const uid = data == 'null' ? null : data.split('?')[0];
|
||||
const result = await ctx.service.diff.diffPhone(phone, type, uid);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (!result) {
|
||||
this.setResponse(ctx, 404, '该手机号已注册', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 200, '验证通过', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "diffPhone";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DiffController;
|
||||
427
app/controller/Download.js
Normal file
@@ -0,0 +1,427 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const fileName = "Download";
|
||||
|
||||
class DownloadController extends Controller {
|
||||
// 导出小鹅通导入用户
|
||||
async importXiaoeTech() {
|
||||
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, importForm, dataHeaders } = ctx.request.body;
|
||||
const result = await ctx.service.download.importXiaoeTech(uid, searchMsg, importForm);
|
||||
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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "importXiaoeTech";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 导出小鹅通开课学员
|
||||
async commencementXiaoeTech() {
|
||||
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, importForm, dataHeaders } = ctx.request.body;
|
||||
const result = await ctx.service.download.commencementXiaoeTech(uid, searchMsg, importForm);
|
||||
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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "commencementXiaoeTech";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 导出批量报名导入 excel 表
|
||||
async importApplicationData() {
|
||||
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, importForm, dataHeaders } = ctx.request.body;
|
||||
const result = await ctx.service.download.importApplicationData(uid, searchMsg, importForm);
|
||||
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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "importApplicationData";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 导出考试星学员导入 excel 表
|
||||
async importExamStars() {
|
||||
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, importForm, dataHeaders } = ctx.request.body;
|
||||
const result = await ctx.service.download.importExamStars(uid, searchMsg, importForm);
|
||||
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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "importExamStars";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 导出培训证书发放用户导入 excel 表
|
||||
async importIssuance() {
|
||||
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, importForm, dataHeaders } = ctx.request.body;
|
||||
const result = await ctx.service.download.importIssuance(uid, searchMsg, importForm);
|
||||
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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "importIssuance";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 导出培训证书发放用户照片文件夹
|
||||
async importUserPhoto() {
|
||||
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 { searchMsg } = ctx.request.body;
|
||||
const result = await ctx.service.download.importUserPhoto(uid, searchMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result.code) {
|
||||
const directoryPath = path.join(__dirname, '../public/userPhoto');
|
||||
const outputZipPath = path.join(__dirname, '../public/userPhoto.zip');
|
||||
// const directoryPath = '/disk/a/Download/userPhoto';
|
||||
// const outputZipPath = '/disk/a/Download/userPhoto.zip';
|
||||
if (!fs.existsSync(directoryPath)) {
|
||||
fs.mkdirSync(directoryPath);
|
||||
console.log('文件夹创建成功');
|
||||
} else {
|
||||
console.log('文件夹已存在');
|
||||
fs.rmSync(directoryPath, { recursive: true });
|
||||
console.log('文件夹已删除');
|
||||
fs.mkdirSync(directoryPath);
|
||||
console.log('文件夹创建成功');
|
||||
}
|
||||
result.data.forEach((element, index) => {
|
||||
const imagePath = path.join(__dirname.replace(/\bbd-training-exam-manager\b/g, "bd-training-exam"), `../public/userPhoto/${element.identity_card}.jpg`);
|
||||
// const imagePath = `/disk/a/userPhoto/${element.identity_card}.jpg`;
|
||||
const newImagePath = path.join(directoryPath, `${element.identity_card}.jpg`);
|
||||
if (fs.existsSync(imagePath)) {
|
||||
fs.copyFileSync(imagePath, newImagePath);
|
||||
console.log('文件复制成功');
|
||||
} else {
|
||||
console.log('文件不存在');
|
||||
}
|
||||
});
|
||||
// 压缩用户照片文件夹
|
||||
this.zipFolder(directoryPath, outputZipPath);
|
||||
ctx.set({
|
||||
'Content-Disposition': 'attachment; filename="userPhoto.zip"',
|
||||
'Content-Type': 'application/octet-stream',
|
||||
});
|
||||
const data = {
|
||||
// 本机服务器地址
|
||||
// 'http://127.0.0.1:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/public/userPhoto.zip?time=${new Date().getTime()}`,
|
||||
fileName: 'userPhoto.zip',
|
||||
}
|
||||
this.setResponse(ctx, 200, '下载用户照片文件夹压缩文件', "deconstruction", data);
|
||||
setTimeout(() => {
|
||||
fs.rmSync(directoryPath, { recursive: true });
|
||||
fs.unlinkSync(outputZipPath);
|
||||
}, 600000);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "importUserPhoto";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 上传用户照片
|
||||
async uploadUserPhoto() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const { files } = ctx.request;
|
||||
const uploadDir = path.join(__dirname.replace(/\bbd-training-exam-manager\b/g, "bd-training-exam"), '../public/userPhoto'); // 设置文件保存目录
|
||||
// const uploadDir = '/disk/a/userPhoto'; // 设置文件保存目录
|
||||
files.forEach(element => {
|
||||
const { filename, filepath } = element;
|
||||
const newPath = path.join(uploadDir, filename); // 构造新文件路径
|
||||
// 确保上传目录存在
|
||||
if (!fs.existsSync(uploadDir)) {
|
||||
fs.mkdirSync(uploadDir, { recursive: true });
|
||||
}
|
||||
// 使用 copyFileSync 复制文件,而不是 renameSync
|
||||
fs.copyFileSync(filepath, newPath);
|
||||
// 删除临时文件
|
||||
fs.unlinkSync(filepath);
|
||||
});
|
||||
this.setResponse(ctx, 200, '照片上传结束', "none");
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "uploadUserPhoto";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 导出考试成绩导入 excel 表
|
||||
async importGradesData() {
|
||||
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, formClone, dataType, passingScore, gradesType, dataHeaders } = ctx.request.body;
|
||||
const result = await ctx.service.download.importGradesData(uid, formClone, dataType, passingScore, gradesType);
|
||||
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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "importGradesData";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DownloadController;
|
||||
192
app/controller/Exam.js
Normal file
@@ -0,0 +1,192 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "Exam";
|
||||
|
||||
class ExamController extends Controller {
|
||||
// 管理系统新增考试信息
|
||||
async addExam() {
|
||||
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.decryptRequest(element.uid);
|
||||
element.exam_name = this.decryptRequest(element.exam_name);
|
||||
element.status = Number(this.decryptRequest(element.status));
|
||||
element.application_start = element.application_start;
|
||||
element.application_end = element.application_end;
|
||||
element.exam_start = element.exam_start;
|
||||
element.exam_end = element.exam_end;
|
||||
});
|
||||
const result = await ctx.service.exam.addExam(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 + "--" + "addExam";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看考试信息
|
||||
async showExam() {
|
||||
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.exam.showExam(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let examMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
examMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
examMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showExam";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑考试信息
|
||||
async editExam() {
|
||||
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 { model, updateMsg, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const result = await ctx.service.exam.editExam(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 + "--" + "editExam";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除考试信息
|
||||
async deleteExam() {
|
||||
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 { model, password, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.exam.deleteExam(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 + "--" + "deleteExam";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出考试信息数据
|
||||
async downloadExamData() {
|
||||
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.exam.downloadExamData(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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "downloadExamData";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ExamController;
|
||||
121
app/controller/Find.js
Normal file
@@ -0,0 +1,121 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Find";
|
||||
|
||||
class FindController extends Controller {
|
||||
// 管理系统检索考生姓名
|
||||
async findUserName() {
|
||||
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.find.findUserName(uid, body);
|
||||
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 + "--" + "findUserName";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索考生身份证号
|
||||
async findIdentityCard() {
|
||||
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.find.findIdentityCard(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result.code == 200) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
} else if (result.code == 303) {
|
||||
this.setResponse(ctx, 303, '信息不匹配', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "findIdentityCard";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索考试uid
|
||||
async findExamUid() {
|
||||
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.find.findExamUid(uid, body);
|
||||
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 + "--" + "findExamUid";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查找指定工作单位
|
||||
async findWorkplace() {
|
||||
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.find.findWorkplace(uid, body);
|
||||
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 + "--" + "findWorkplace";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FindController;
|
||||
221
app/controller/Grades.js
Normal file
@@ -0,0 +1,221 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "Grades";
|
||||
|
||||
class GradesController extends Controller {
|
||||
// 管理系统新增用户考试结果
|
||||
async addGrades() {
|
||||
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;
|
||||
let userMsgObj = {
|
||||
user_name: [],
|
||||
identity_card: []
|
||||
};
|
||||
requestMsg.forEach(item => {
|
||||
item.user_name = this.decryptRequest(item.user_name);
|
||||
item.identity_card = this.decryptRequest(item.identity_card);
|
||||
item.exam_uid = this.decryptRequest(item.exam_uid);
|
||||
item.status = Number(this.decryptRequest(item.status));
|
||||
item.grades = this.decryptRequest(item.grades) == 'undefined' ? null : Number(this.decryptRequest(item.grades));
|
||||
item.pass_type = Number(this.decryptRequest(item.pass_type));
|
||||
userMsgObj.user_name.push(item.user_name);
|
||||
userMsgObj.identity_card.push(item.identity_card);
|
||||
});
|
||||
const result = await ctx.service.grades.addGrades(userMsgObj, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
if (result.code == 400) {
|
||||
this.setResponse(ctx, 400, '全部操作失败, 请前往导入错误记录页面查看导入错误的数据', "none");
|
||||
} else if (result.code == 300) {
|
||||
this.setResponse(ctx, 300, '部分操作成功, 请前往导入错误记录页面查看导入错误的数据', "none");
|
||||
} else if (result.code == 200) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
}
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addGrades";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看用户考试结果
|
||||
async showGrades() {
|
||||
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.grades.showGrades(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let idCardArr = [];
|
||||
result.rows.forEach(item => {
|
||||
idCardArr.push(item.dataValues.examinee.dataValues.identity_card);
|
||||
});
|
||||
const photoResult = await ctx.service.search.checkPhoto(idCardArr);
|
||||
let gradesMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
if (photoResult == "error") {
|
||||
element.dataValues.userPhotoUrl = '#';
|
||||
}
|
||||
if (photoResult) {
|
||||
ctx.set('Cache-Control', 'no-cache, no-store, must-revalidate');
|
||||
ctx.set("Pragma", "no-cache");
|
||||
ctx.set("Expires", "0");
|
||||
photoResult.forEach(item => {
|
||||
if (element.dataValues.examinee.dataValues.identity_card == item.identity_card) {
|
||||
element.dataValues.userPhotoUrl = item.photoUrl;
|
||||
}
|
||||
});
|
||||
}
|
||||
gradesMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
gradesMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showGrades";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑用户考试结果
|
||||
async editGrades() {
|
||||
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 { model, updateMsg, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const result = await ctx.service.grades.editGrades(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 + "--" + "editGrades";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除用户考试结果
|
||||
async deleteGrades() {
|
||||
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 { model, password, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.grades.deleteGrades(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 + "--" + "deleteGrades";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出考生考试结果数据
|
||||
async downloadGradesData() {
|
||||
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.grades.downloadGradesData(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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "downloadGradesData";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GradesController;
|
||||
75
app/controller/Importerror.js
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Importerror";
|
||||
|
||||
class ImporterrorController extends Controller {
|
||||
// 查看导入错误记录
|
||||
async showImporterror() {
|
||||
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.importerror.showImporterror(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let importerrorMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
importerrorMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
importerrorMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索导入错误记录成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索导入错误记录失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showImporterror";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除导入错误记录
|
||||
async deleteImporterror() {
|
||||
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.importerror.deleteImporterror(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 + "--" + "deleteImporterror";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ImporterrorController;
|
||||
192
app/controller/Interlocution.js
Normal file
@@ -0,0 +1,192 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "Interlocution";
|
||||
|
||||
class InterlocutionController extends Controller {
|
||||
// 管理系统新增问答题
|
||||
async addInterlocution() {
|
||||
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 => {
|
||||
if (element.difficulty == '简单') {
|
||||
element.difficulty = 0;
|
||||
} else if (element.difficulty == '普通') {
|
||||
element.difficulty = 1;
|
||||
} else if (element.difficulty == '困难') {
|
||||
element.difficulty = 2;
|
||||
}
|
||||
});
|
||||
const result = await ctx.service.interlocution.addInterlocution(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 + "--" + "addInterlocution";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看问答题
|
||||
async showInterlocution() {
|
||||
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.interlocution.showInterlocution(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let interlocutionMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
interlocutionMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
interlocutionMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showInterlocution";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑问答题
|
||||
async editInterlocution() {
|
||||
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 { model, updateMsg, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const result = await ctx.service.interlocution.editInterlocution(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 + "--" + "editInterlocution";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除问答题
|
||||
async deleteInterlocution() {
|
||||
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 { model, password, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.interlocution.deleteInterlocution(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 + "--" + "deleteInterlocution";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出问答题数据
|
||||
async downloadInterlocutionData() {
|
||||
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.interlocution.downloadInterlocutionData(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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "downloadInterlocutionData";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InterlocutionController;
|
||||
194
app/controller/Judgment.js
Normal file
@@ -0,0 +1,194 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "Judgment";
|
||||
|
||||
class JudgmentController extends Controller {
|
||||
// 管理系统新增判断题
|
||||
async addJudgment() {
|
||||
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.answer = element.answer == '正确' ? true : false;
|
||||
if (element.difficulty == '简单') {
|
||||
element.difficulty = 0;
|
||||
} else if (element.difficulty == '普通') {
|
||||
element.difficulty = 1;
|
||||
} else if (element.difficulty == '困难') {
|
||||
element.difficulty = 2;
|
||||
}
|
||||
});
|
||||
const result = await ctx.service.judgment.addJudgment(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 + "--" + "addJudgment";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看判断题
|
||||
async showJudgment() {
|
||||
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.judgment.showJudgment(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let judgmentMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
judgmentMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
judgmentMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showJudgment";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑判断题
|
||||
async editJudgment() {
|
||||
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 { model, updateMsg, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
updateMsg.answer = updateMsg.answer == '1' ? true : false;
|
||||
const result = await ctx.service.judgment.editJudgment(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 + "--" + "editJudgment";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除判断题
|
||||
async deleteJudgment() {
|
||||
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 { model, password, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.judgment.deleteJudgment(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 + "--" + "deleteJudgment";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出判断题数据
|
||||
async downloadJudgmentData() {
|
||||
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.judgment.downloadJudgmentData(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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "downloadJudgmentData";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JudgmentController;
|
||||
75
app/controller/Monitoring.js
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Monitoring";
|
||||
|
||||
class MonitoringController extends Controller {
|
||||
// 查看危险操作记录
|
||||
async showMonitoring() {
|
||||
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.monitoring.showMonitoring(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let monitoringMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
monitoringMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
monitoringMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索危险操作记录成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索危险操作记录失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showMonitoring";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除危险操作记录
|
||||
async deleteMonitoring() {
|
||||
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.monitoring.deleteMonitoring(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 + "--" + "deleteMonitoring";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MonitoringController;
|
||||
192
app/controller/Multiple.js
Normal file
@@ -0,0 +1,192 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "Multiple";
|
||||
|
||||
class MultipleController extends Controller {
|
||||
// 管理系统新增多选题
|
||||
async addMultiple() {
|
||||
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 => {
|
||||
if (element.difficulty == '简单') {
|
||||
element.difficulty = 0;
|
||||
} else if (element.difficulty == '普通') {
|
||||
element.difficulty = 1;
|
||||
} else if (element.difficulty == '困难') {
|
||||
element.difficulty = 2;
|
||||
}
|
||||
});
|
||||
const result = await ctx.service.multiple.addMultiple(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 + "--" + "addMultiple";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看多选题
|
||||
async showMultiple() {
|
||||
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.multiple.showMultiple(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let multipleMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
multipleMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
multipleMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showMultiple";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑多选题
|
||||
async editMultiple() {
|
||||
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 { model, updateMsg, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const result = await ctx.service.multiple.editMultiple(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 + "--" + "editMultiple";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除多选题
|
||||
async deleteMultiple() {
|
||||
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 { model, password, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.multiple.deleteMultiple(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 + "--" + "deleteMultiple";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出多选题数据
|
||||
async downloadMultipleData() {
|
||||
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.multiple.downloadMultipleData(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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "downloadMultipleData";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MultipleController;
|
||||
192
app/controller/Radio.js
Normal file
@@ -0,0 +1,192 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "Radio";
|
||||
|
||||
class RadioController extends Controller {
|
||||
// 管理系统新增单选题
|
||||
async addRadio() {
|
||||
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 => {
|
||||
if (element.difficulty == '简单') {
|
||||
element.difficulty = 0;
|
||||
} else if (element.difficulty == '普通') {
|
||||
element.difficulty = 1;
|
||||
} else if (element.difficulty == '困难') {
|
||||
element.difficulty = 2;
|
||||
}
|
||||
});
|
||||
const result = await ctx.service.radio.addRadio(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 + "--" + "addRadio";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看单选题
|
||||
async showRadio() {
|
||||
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.radio.showRadio(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let radioMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
radioMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
radioMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showRadio";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑单选题
|
||||
async editRadio() {
|
||||
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 { model, updateMsg, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const result = await ctx.service.radio.editRadio(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 + "--" + "editRadio";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除单选题
|
||||
async deleteRadio() {
|
||||
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 { model, password, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.radio.deleteRadio(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 + "--" + "deleteRadio";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出单选题数据
|
||||
async downloadRadioData() {
|
||||
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.radio.downloadRadioData(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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "downloadRadioData";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RadioController;
|
||||
167
app/controller/Search.js
Normal file
@@ -0,0 +1,167 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Search";
|
||||
|
||||
class SearchController extends Controller {
|
||||
// 管理系统检索考生姓名
|
||||
async searchUserName() {
|
||||
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.search.searchUserName(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let userName = [];
|
||||
result.forEach(element => {
|
||||
userName.push({ value: element.dataValues.user_name });
|
||||
});
|
||||
this.setResponse(ctx, 200, '操作成功', "polymerization", userName);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchUserName";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索考生身份证号
|
||||
async searchIdentityCard() {
|
||||
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.search.searchIdentityCard(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let identityCard = [];
|
||||
result.forEach(element => {
|
||||
identityCard.push({ value: element.dataValues.identity_card });
|
||||
});
|
||||
this.setResponse(ctx, 200, '操作成功', "polymerization", identityCard);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchIdentityCard";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索考试uid
|
||||
async searchExamUid() {
|
||||
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.search.searchExamUid(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let examUid = [];
|
||||
result.forEach(element => {
|
||||
examUid.push({ value: element.dataValues.uid });
|
||||
});
|
||||
this.setResponse(ctx, 200, '操作成功', "polymerization", examUid);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchExamUid";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索工作单位
|
||||
async searchWorkplace() {
|
||||
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.search.searchWorkplace(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let workplace = [];
|
||||
result.forEach(element => {
|
||||
workplace.push({ value: element.dataValues.workplace });
|
||||
});
|
||||
this.setResponse(ctx, 200, '操作成功', "polymerization", workplace);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchWorkplace";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索报名结果说明
|
||||
async searchResult() {
|
||||
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 results = await ctx.service.search.searchResult(uid, body);
|
||||
if (results == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (results) {
|
||||
let result = [];
|
||||
results.forEach(element => {
|
||||
result.push({ value: element.dataValues.result });
|
||||
});
|
||||
this.setResponse(ctx, 200, '操作成功', "polymerization", result);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchResult";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SearchController;
|
||||
215
app/controller/TopicWhitelist.js
Normal file
@@ -0,0 +1,215 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "TopicWhitelist";
|
||||
|
||||
class TopicWhitelistController extends Controller {
|
||||
// 管理系统新增题库白名单
|
||||
async addTopicWhitelist() {
|
||||
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;
|
||||
let userMsgObj = {
|
||||
phone: [],
|
||||
};
|
||||
console.log(requestMsg)
|
||||
requestMsg.forEach(item => {
|
||||
item.phone = this.decryptRequest(item.phone);
|
||||
item.type = Number(this.decryptRequest(item.type));
|
||||
if (item.expired_at) {
|
||||
item.expired_at = this.decryptRequest(item.expired_at);
|
||||
} else {
|
||||
item.expired_at = null;
|
||||
}
|
||||
userMsgObj.phone.push(item.phone);
|
||||
});
|
||||
const result = await ctx.service.topicWhitelist.addTopicWhitelist(userMsgObj, 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 + "--" + "addTopicWhitelist";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看题库白名单
|
||||
async showTopicWhitelist() {
|
||||
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.topicWhitelist.showTopicWhitelist(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let idCardArr = [];
|
||||
result.rows.forEach(item => {
|
||||
idCardArr.push(item.dataValues.examinee.dataValues.identity_card);
|
||||
});
|
||||
const photoResult = await ctx.service.search.checkPhoto(idCardArr);
|
||||
let topicWhitelistMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
if (photoResult == "error") {
|
||||
element.dataValues.userPhotoUrl = '#';
|
||||
}
|
||||
if (photoResult) {
|
||||
ctx.set('Cache-Control', 'no-cache, no-store, must-revalidate');
|
||||
ctx.set("Pragma", "no-cache");
|
||||
ctx.set("Expires", "0");
|
||||
photoResult.forEach(item => {
|
||||
if (element.dataValues.examinee.dataValues.identity_card == item.identity_card) {
|
||||
element.dataValues.userPhotoUrl = item.photoUrl;
|
||||
}
|
||||
});
|
||||
}
|
||||
topicWhitelistMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
topicWhitelistMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showTopicWhitelist";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑题库白名单
|
||||
async editTopicWhitelist() {
|
||||
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 { model, updateMsg, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const result = await ctx.service.topicWhitelist.editTopicWhitelist(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 + "--" + "editTopicWhitelist";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除题库白名单
|
||||
async deleteTopicWhitelist() {
|
||||
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 { model, password, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.topicWhitelist.deleteTopicWhitelist(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 + "--" + "deleteTopicWhitelist";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出题库白名单
|
||||
async downloadTopicWhitelistData() {
|
||||
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.topicWhitelist.downloadTopicWhitelistData(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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "downloadTopicWhitelistData";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TopicWhitelistController;
|
||||
218
app/controller/User.js
Normal file
@@ -0,0 +1,218 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "User";
|
||||
|
||||
class UserController extends Controller {
|
||||
// 管理系统新增用户账号信息
|
||||
async addUser() {
|
||||
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 => {
|
||||
const salt = this.generateRandomString();
|
||||
element.uid = this.generateNumberString('E');
|
||||
element.salt = this.encryptRequest(salt);
|
||||
element.password = this.shaForm(this.decryptRequest(element.identity_card).slice(-6), salt);
|
||||
element.user_name = this.decryptRequest(element.user_name);
|
||||
element.identity_card = this.decryptRequest(element.identity_card);
|
||||
element.real_check = 0;
|
||||
element.workplace = this.decryptRequest(element.workplace);
|
||||
element.address = this.decryptRequest(element.address);
|
||||
element.phone = this.decryptRequest(element.phone);
|
||||
element.email = this.decryptRequest(element.email);
|
||||
element.status = 0;
|
||||
element.created_at = new Date();
|
||||
element.updated_at = new Date();
|
||||
element.login_status = 0;
|
||||
});
|
||||
const result = await ctx.service.user.addUser(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 + "--" + "addUser";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看用户账号信息
|
||||
async showUser() {
|
||||
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.user.showUser(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let idCardArr = [];
|
||||
result.rows.forEach(item => {
|
||||
idCardArr.push(item.dataValues.identity_card);
|
||||
});
|
||||
const photoResult = await ctx.service.search.checkPhoto(idCardArr);
|
||||
let userMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
if (photoResult == "error") {
|
||||
element.dataValues.userPhotoUrl = '#';
|
||||
}
|
||||
if (photoResult) {
|
||||
ctx.set('Cache-Control', 'no-cache, no-store, must-revalidate');
|
||||
ctx.set("Pragma", "no-cache");
|
||||
ctx.set("Expires", "0");
|
||||
photoResult.forEach(item => {
|
||||
if (element.dataValues.identity_card == item.identity_card) {
|
||||
element.dataValues.userPhotoUrl = item.photoUrl;
|
||||
}
|
||||
});
|
||||
}
|
||||
userMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
userMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showUser";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑用户账号信息
|
||||
async editUser() {
|
||||
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 { model, updateMsg, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const result = await ctx.service.user.editUser(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 + "--" + "editUser";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除用户账号信息
|
||||
async deleteUser() {
|
||||
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 { model, password, requestMsg } = ctx.request.body;
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.user.deleteUser(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 + "--" + "deleteUser";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出用户账号信息数据
|
||||
async downloadUserData() {
|
||||
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.user.downloadUserData(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:8020'
|
||||
// 'http://192.168.31.28:8020'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8020'
|
||||
// 'http://certadmin.hwasmart.com//bdTrainingExamManager'
|
||||
fileUrl: 'http://127.0.0.1:8020' + `/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 + "--" + "downloadUserData";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserController;
|
||||
190
app/core/base_controller.js
Normal file
@@ -0,0 +1,190 @@
|
||||
const { Controller } = require('egg');
|
||||
|
||||
const sha256 = require("crypto-js/sha256");
|
||||
|
||||
const CryptoJS = require("crypto-js");
|
||||
|
||||
const XLSX = require('xlsx');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const archiver = require('archiver');
|
||||
|
||||
const KEY = CryptoJS.enc.Utf8.parse('BDQH');
|
||||
|
||||
class BaseController extends Controller {
|
||||
shaForm = (body, salt) => {
|
||||
return sha256(sha256(body).toString() + salt).toString();
|
||||
}
|
||||
|
||||
encryptRequest = (body) => {
|
||||
return CryptoJS.AES.encrypt(body, KEY, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
}).toString();
|
||||
}
|
||||
|
||||
decryptRequest = (body) => {
|
||||
return CryptoJS.AES.decrypt(body, KEY, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
}).toString(CryptoJS.enc.Utf8);
|
||||
}
|
||||
|
||||
// 用户uid生成函数
|
||||
generateNumberString = (side) => {
|
||||
// 获取当前日期(年月日)
|
||||
const now = new Date();
|
||||
const year = String(now.getFullYear()).padStart(4, '0');
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以加1
|
||||
const date = String(now.getDate()).padStart(2, '0');
|
||||
const dateString = year + month + date;
|
||||
|
||||
// 获取当前时间戳的后三位
|
||||
const timestamp = String(Date.now()).slice(-3);
|
||||
|
||||
// 生成三位随机数字
|
||||
const randomDigits = Math.floor(Math.random() * 100).toString().padStart(3, '0');
|
||||
|
||||
// 组合成最终的15位字符串
|
||||
const fullNumberString = dateString + timestamp + randomDigits + side;
|
||||
|
||||
return fullNumberString;
|
||||
}
|
||||
|
||||
// 随机盐生成函数
|
||||
generateRandomString = () => {
|
||||
const lowerCaseLetters = 'abcdefghijklmnopqrstuvwxyz';
|
||||
const upperCaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
const numbers = '0123456789';
|
||||
|
||||
let result = '';
|
||||
|
||||
// 生成5位随机小写字母
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * lowerCaseLetters.length);
|
||||
result += lowerCaseLetters[randomIndex];
|
||||
}
|
||||
|
||||
// 生成5位随机大写字母
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * upperCaseLetters.length);
|
||||
result += upperCaseLetters[randomIndex];
|
||||
}
|
||||
|
||||
// 生成2位随机数字
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * numbers.length);
|
||||
result += numbers[randomIndex];
|
||||
}
|
||||
|
||||
// 打乱整个字符串
|
||||
const characters = result.split('');
|
||||
for (let i = characters.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[characters[i], characters[j]] = [characters[j], characters[i]];
|
||||
}
|
||||
|
||||
return characters.join('');
|
||||
}
|
||||
|
||||
// 随机生成12位客户端id
|
||||
generateClientId = () => {
|
||||
const numbers = '0123456789';
|
||||
|
||||
let result = '';
|
||||
|
||||
// 生成4位随机数字
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * numbers.length);
|
||||
result += numbers[randomIndex];
|
||||
}
|
||||
|
||||
// 打乱整个字符串
|
||||
const characters = result.split('');
|
||||
for (let i = characters.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[characters[i], characters[j]] = [characters[j], characters[i]];
|
||||
}
|
||||
|
||||
// 获取当前日期(年月日)
|
||||
const now = new Date();
|
||||
const year = String(now.getFullYear()).padStart(4, '0');
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以加1
|
||||
const date = String(now.getDate()).padStart(2, '0');
|
||||
const dateString = year + month + date;
|
||||
|
||||
const fullNumberString = dateString + characters.join('');
|
||||
|
||||
return fullNumberString;
|
||||
}
|
||||
|
||||
checkUid = async (ctx) => {
|
||||
const token = ctx.request.header.authorization;
|
||||
const redis = ctx.app.redis;
|
||||
const examManager = await redis.get('db7').get(token);
|
||||
return examManager ? examManager : false;
|
||||
};
|
||||
|
||||
setResponse = (ctx, code, msg, model, data = {}) => {
|
||||
const modelType = {
|
||||
"none": { code, msg },
|
||||
"deconstruction": { code, msg, ...data },
|
||||
"polymerization": { code, msg, data }
|
||||
}
|
||||
ctx.body = modelType[model];
|
||||
}
|
||||
|
||||
downloadData = (form, data, dataHeaders) => {
|
||||
let extensionName = ['.xlsx', '.xls', '.csv'], buf;
|
||||
const { sheetName, fileName, extensionType } = form;
|
||||
if (extensionName[extensionType] == '.xlsx' || extensionName[extensionType] == '.xls') {
|
||||
// 使用xlsx库将数据转换为工作表和工作簿
|
||||
const ws = XLSX.utils.json_to_sheet(data);
|
||||
// 动态设置表头
|
||||
dataHeaders.forEach((header, index) => {
|
||||
const cellRef = XLSX.utils.encode_cell({ r: 0, c: index }); // 生成单元格引用,如A1, B1等
|
||||
ws[cellRef] = { v: header, t: "s" }; // 设置单元格的值和类型
|
||||
});
|
||||
// 创建一个新的工作簿并添加工作表
|
||||
const wb = XLSX.utils.book_new();
|
||||
// 将工作表添加到工作簿中,并指定其名称
|
||||
XLSX.utils.book_append_sheet(wb, ws, sheetName);
|
||||
if (extensionName[extensionType] == '.xlsx') {
|
||||
// 将工作簿写入字符串(二进制)
|
||||
buf = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
|
||||
} else if (extensionName[extensionType] == '.xls') {
|
||||
// 将工作簿写入字符串(二进制)
|
||||
buf = XLSX.write(wb, { bookType: 'xls', type: 'array' });
|
||||
}
|
||||
} else if (extensionName[extensionType] == '.csv') {
|
||||
// 将数据转换为CSV格式的字符串
|
||||
buf = data.map(row => row.join(',')).join('\n') + '\n';
|
||||
}
|
||||
// 将文件的内容返回给控制器作为响应体发送给客户端
|
||||
if (buf) {
|
||||
const completeName = fileName + extensionName[extensionType];
|
||||
const filePath = 'app/public/' + completeName;
|
||||
// const filePath = '/disk/a/Download/' + completeName;
|
||||
return { filePath, completeName, buf };
|
||||
};
|
||||
return false;
|
||||
};
|
||||
|
||||
zipFolder = (sourceDir, outputZipPath) => {
|
||||
// 创建可写流来写入数据
|
||||
const output = fs.createWriteStream(outputZipPath); // 将压缩包保存到当前项目的目录下
|
||||
const archive = archiver('zip', { zlib: { level: 9 } }); // 设置压缩等级
|
||||
|
||||
// 建立管道连接
|
||||
archive.pipe(output);
|
||||
|
||||
// 压缩目录到压缩包中
|
||||
archive.directory(sourceDir + '/', false);
|
||||
|
||||
// 完成压缩
|
||||
archive.finalize();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseController;
|
||||
88
app/core/base_service.js
Normal file
@@ -0,0 +1,88 @@
|
||||
const { Service } = require('egg');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const sha256 = require("crypto-js/sha256");
|
||||
|
||||
const CryptoJS = require("crypto-js");
|
||||
|
||||
const KEY = CryptoJS.enc.Utf8.parse('BDQH');
|
||||
|
||||
class BaseService extends Service {
|
||||
shaForm = (body, salt) => {
|
||||
return sha256(sha256(body).toString() + salt).toString();
|
||||
}
|
||||
|
||||
encryptRequest = (body) => {
|
||||
return CryptoJS.AES.encrypt(body, KEY, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
}).toString();
|
||||
}
|
||||
|
||||
decryptRequest = (body) => {
|
||||
return CryptoJS.AES.decrypt(body, KEY, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
}).toString(CryptoJS.enc.Utf8);
|
||||
}
|
||||
|
||||
// uid生成函数
|
||||
generateNumberString = () => {
|
||||
// 获取当前日期(年月日)
|
||||
const now = new Date();
|
||||
const year = String(now.getFullYear()).padStart(4, '0');
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以加1
|
||||
const date = String(now.getDate()).padStart(2, '0');
|
||||
const dateString = year + month + date;
|
||||
|
||||
// 获取当前时间戳的后四位
|
||||
const timestamp = String(Date.now()).slice(-4);
|
||||
|
||||
// 生成四位随机数字
|
||||
const randomDigits = Math.floor(Math.random() * 10000).toString().padStart(4, '0');
|
||||
|
||||
// 组合成最终的16位数字字符串
|
||||
const fullNumberString = dateString + timestamp + randomDigits;
|
||||
|
||||
return fullNumberString;
|
||||
}
|
||||
|
||||
// 随机盐生成函数
|
||||
generateRandomString = () => {
|
||||
const lowerCaseLetters = 'abcdefghijklmnopqrstuvwxyz';
|
||||
const upperCaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
const numbers = '0123456789';
|
||||
|
||||
let result = '';
|
||||
|
||||
// 生成5位随机小写字母
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * lowerCaseLetters.length);
|
||||
result += lowerCaseLetters[randomIndex];
|
||||
}
|
||||
|
||||
// 生成5位随机大写字母
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * upperCaseLetters.length);
|
||||
result += upperCaseLetters[randomIndex];
|
||||
}
|
||||
|
||||
// 生成2位随机数字
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * numbers.length);
|
||||
result += numbers[randomIndex];
|
||||
}
|
||||
|
||||
// 打乱整个字符串
|
||||
const characters = result.split('');
|
||||
for (let i = characters.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[characters[i], characters[j]] = [characters[j], characters[i]];
|
||||
}
|
||||
|
||||
return characters.join('');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseService;
|
||||
72
app/middleware/log.js
Normal file
@@ -0,0 +1,72 @@
|
||||
// 错误日志
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
const dirCheck = (dirPath) => {
|
||||
// 检查文件夹是否存在
|
||||
fs.access(dirPath, fs.constants.F_OK, (err) => {
|
||||
if (err) {
|
||||
// 文件夹不存在
|
||||
console.log('文件夹不存在,正在创建...');
|
||||
fs.mkdir(dirPath, { recursive: true }, (err) => {
|
||||
if (err) throw err;
|
||||
console.log('文件夹已创建');
|
||||
});
|
||||
} else {
|
||||
// 文件夹存在
|
||||
console.log('文件夹已存在');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = (filePath, msg) => {
|
||||
// 获取时间
|
||||
let now = new Date(),
|
||||
times = {
|
||||
year: now.getFullYear(),
|
||||
month: now.getMonth() + 1,
|
||||
day: now.getDate(),
|
||||
hour: now.getHours(),
|
||||
minute: now.getMinutes(),
|
||||
second: now.getSeconds()
|
||||
};
|
||||
// 获取操作系统类型
|
||||
const type = os.type();
|
||||
console.log(`操作系统类型: ${type}`);
|
||||
filePath = path.join(__dirname, filePath);
|
||||
dirCheck(filePath);
|
||||
const yearPath = filePath + '/' + times.year;
|
||||
dirCheck(yearPath);
|
||||
const monthPath = yearPath + '/' + times.month;
|
||||
dirCheck(monthPath);
|
||||
const dayPath = monthPath + '/' + times.day + '.txt';
|
||||
const logTime = '[' + times.year + '-' + times.month + '-' + times.day + '>>>' + times.hour + ':' + times.minute + ':' + times.second + ']' + '>>>';
|
||||
let crlf;
|
||||
// 判断操作系统类型,设置换行符
|
||||
if (type === 'Windows_NT') {
|
||||
crlf = '\n';
|
||||
} else {
|
||||
crlf = '\r\n';
|
||||
}
|
||||
// 读取文件内容
|
||||
fs.readFile(dayPath, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
// 文件不存在,直接写入新内容(这里实际上还是使用了覆盖的方式)
|
||||
fs.writeFile(dayPath, logTime + msg + crlf, (err) => {
|
||||
if (err) throw err;
|
||||
console.log('文件已创建并写入新内容');
|
||||
});
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
} else {
|
||||
// 文件存在,追加新内容
|
||||
fs.appendFile(dayPath, logTime + msg + crlf, (err) => {
|
||||
if (err) throw err;
|
||||
console.log('新内容已追加到文件');
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
23
app/model/Application.js
Normal file
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const Application = app.model.define('application', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
exam_uid: CHAR(10),
|
||||
source: STRING(24),
|
||||
status: INTEGER(3),
|
||||
pay_status: INTEGER(3),
|
||||
result: STRING(24),
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Application;
|
||||
};
|
||||
21
app/model/Audit.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const Audit = app.model.define('audit', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
identity_card: CHAR(18),
|
||||
user_name: STRING(6),
|
||||
status: INTEGER(3),
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Audit;
|
||||
};
|
||||
23
app/model/Examination.js
Normal file
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const Examination = app.model.define('examination', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
uid: CHAR(10),
|
||||
exam_name: STRING(60),
|
||||
status: INTEGER(3),
|
||||
application_start: DATE,
|
||||
application_end: DATE,
|
||||
exam_start: DATE,
|
||||
exam_end: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Examination;
|
||||
};
|
||||
31
app/model/Examinee.js
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const Examinee = app.model.define('examinee', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
uid: CHAR(15),
|
||||
salt: CHAR(24),
|
||||
password: CHAR(64),
|
||||
user_name: STRING(10),
|
||||
identity_card: CHAR(18),
|
||||
real_check: INTEGER(3),
|
||||
workplace: STRING(60),
|
||||
address: STRING(120),
|
||||
phone: CHAR(11),
|
||||
email: STRING(60),
|
||||
referrers: STRING(60),
|
||||
status: INTEGER(3),
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
login_status: INTEGER(3),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
return Examinee;
|
||||
};
|
||||
21
app/model/Grades.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING } = app.Sequelize;
|
||||
|
||||
const Grades = app.model.define('grades', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
exam_uid: CHAR(10),
|
||||
status: INTEGER(3),
|
||||
grades: STRING(5),
|
||||
pass_type: INTEGER(3),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: false,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Grades;
|
||||
};
|
||||
22
app/model/Importerror.js
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const Importerror = app.model.define('importerror', {
|
||||
id: { type: INTEGER(5), primaryKey: true, autoIncrement: true },
|
||||
identity_card: CHAR(18),
|
||||
user_name: STRING(6),
|
||||
exam_uid: CHAR(10),
|
||||
type: INTEGER(3),
|
||||
status: INTEGER(3),
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Importerror;
|
||||
};
|
||||
25
app/model/Manager.js
Normal file
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const Manager = app.model.define('manager', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
uid: CHAR(15),
|
||||
salt: CHAR(24),
|
||||
account_name: STRING(5),
|
||||
password: CHAR(64),
|
||||
role: INTEGER(3),
|
||||
status: INTEGER(3),
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
login_status: INTEGER(3),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
return Manager;
|
||||
};
|
||||
23
app/model/Monitoring.js
Normal file
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, DATE } = app.Sequelize;
|
||||
|
||||
const Monitoring = app.model.define('monitoring', {
|
||||
id: { type: INTEGER(5), primaryKey: true, autoIncrement: true },
|
||||
operate: INTEGER(3),
|
||||
operate_msg: CHAR(200),
|
||||
type: INTEGER(3),
|
||||
status: INTEGER(3),
|
||||
affect_entries: INTEGER(5),
|
||||
user: CHAR(15),
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Monitoring;
|
||||
};
|
||||
19
app/model/Whitelist.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, DATE } = app.Sequelize;
|
||||
|
||||
const Whitelist = app.model.define('whitelist', {
|
||||
id: { type: INTEGER(5), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
type: INTEGER(3),
|
||||
expired_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Whitelist;
|
||||
};
|
||||
19
app/model2/Interlocution.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, STRING } = app.Sequelize;
|
||||
|
||||
const Interlocution = app.model2.define('interlocution', {
|
||||
id: { type: INTEGER(5), primaryKey: true, autoIncrement: true },
|
||||
stem: STRING(400),
|
||||
answer: STRING(400),
|
||||
difficulty: INTEGER(3),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: false,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Interlocution;
|
||||
};
|
||||
19
app/model2/Judgment.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, STRING } = app.Sequelize;
|
||||
|
||||
const Judgment = app.model2.define('judgment', {
|
||||
id: { type: INTEGER(5), primaryKey: true, autoIncrement: true },
|
||||
stem: STRING(400),
|
||||
answer: INTEGER(1),
|
||||
difficulty: INTEGER(3),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: false,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Judgment;
|
||||
};
|
||||
24
app/model2/Multiple.js
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, STRING } = app.Sequelize;
|
||||
|
||||
const Multiple = app.model2.define('multiple', {
|
||||
id: { type: INTEGER(5), primaryKey: true, autoIncrement: true },
|
||||
stem: STRING(400),
|
||||
options_a: STRING(400),
|
||||
options_b: STRING(400),
|
||||
options_c: STRING(400),
|
||||
options_d: STRING(400),
|
||||
options_e: STRING(400),
|
||||
answer: STRING(5),
|
||||
difficulty: INTEGER(3),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: false,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Multiple;
|
||||
};
|
||||
23
app/model2/Radio.js
Normal file
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, STRING, CHAR } = app.Sequelize;
|
||||
|
||||
const Radio = app.model2.define('radio', {
|
||||
id: { type: INTEGER(5), primaryKey: true, autoIncrement: true },
|
||||
stem: STRING(400),
|
||||
options_a: STRING(400),
|
||||
options_b: STRING(400),
|
||||
options_c: STRING(400),
|
||||
options_d: STRING(400),
|
||||
answer: CHAR(1),
|
||||
difficulty: INTEGER(3),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: false,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Radio;
|
||||
};
|
||||
BIN
app/public/userPhoto.zip
Normal file
BIN
app/public/userPhoto/320103196805082012.jpg
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
app/public/userPhoto/320125199007232313.jpg
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
app/public/userPhoto/320125199801230737.jpg
Normal file
|
After Width: | Height: | Size: 45 KiB |
BIN
app/public/userPhoto/320981198807164734.jpg
Normal file
|
After Width: | Height: | Size: 54 KiB |
BIN
app/public/userPhoto/320981199912304975.jpg
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
app/public/userPhoto/32128219810804023X.jpg
Normal file
|
After Width: | Height: | Size: 53 KiB |
BIN
app/public/userPhoto/330104198306103816.jpg
Normal file
|
After Width: | Height: | Size: 100 KiB |
BIN
app/public/userPhoto/340221199812160010.jpg
Normal file
|
After Width: | Height: | Size: 80 KiB |
BIN
app/public/userPhoto/341223198801191910.jpg
Normal file
|
After Width: | Height: | Size: 114 KiB |
BIN
app/public/userPhoto/342625199710150718.jpg
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
app/public/userPhoto/420222198705048711.jpg
Normal file
|
After Width: | Height: | Size: 74 KiB |
BIN
app/public/userPhoto/430111197912296032.jpg
Normal file
|
After Width: | Height: | Size: 42 KiB |
178
app/router.js
Normal file
@@ -0,0 +1,178 @@
|
||||
/**
|
||||
* @param {Egg.Application} app - egg application
|
||||
*/
|
||||
module.exports = app => {
|
||||
const { router, controller } = app;
|
||||
|
||||
// 管理系统新增普通管理员账号信息
|
||||
router.post("/addAdmin", controller.admin.addAdmin);
|
||||
// 管理系统查看普通管理员账号信息
|
||||
router.post("/showAdmin", controller.admin.showAdmin);
|
||||
// 管理系统编辑普通管理员账号信息
|
||||
router.post("/editAdmin", controller.admin.editAdmin);
|
||||
// 管理系统删除普通管理员账号信息
|
||||
router.post("/deleteAdmin", controller.admin.deleteAdmin);
|
||||
// 管理系统导出普通管理员账号信息数据
|
||||
router.post("/downloadAdminData", controller.admin.downloadAdminData);
|
||||
|
||||
// 管理系统新增考试信息
|
||||
router.post("/addExam", controller.exam.addExam);
|
||||
// 管理系统查看考试信息
|
||||
router.post("/showExam", controller.exam.showExam);
|
||||
// 管理系统编辑考试信息
|
||||
router.post("/editExam", controller.exam.editExam);
|
||||
// 管理系统删除考试信息
|
||||
router.post("/deleteExam", controller.exam.deleteExam);
|
||||
// 管理系统导出考试信息数据
|
||||
router.post("/downloadExamData", controller.exam.downloadExamData);
|
||||
|
||||
// 管理系统新增用户账号信息
|
||||
router.post("/addUser", controller.user.addUser);
|
||||
// 管理系统查看用户账号信息
|
||||
router.post("/showUser", controller.user.showUser);
|
||||
// 管理系统编辑用户账号信息
|
||||
router.post("/editUser", controller.user.editUser);
|
||||
// 管理系统删除用户账号信息
|
||||
router.post("/deleteUser", controller.user.deleteUser);
|
||||
// 管理系统导出用户账号信息数据
|
||||
router.post("/downloadUserData", controller.user.downloadUserData);
|
||||
|
||||
// 比较身份证号
|
||||
router.post("/diffIdentityCard", controller.diff.diffIdentityCard);
|
||||
// 比较邮箱
|
||||
router.post("/diffEmail", controller.diff.diffEmail);
|
||||
// 比较电话号码
|
||||
router.post("/diffPhone", controller.diff.diffPhone);
|
||||
|
||||
// 管理系统查看用户关键信息变更
|
||||
router.post("/auditList", controller.audit.auditList);
|
||||
// 管理系统审核用户关键信息变更
|
||||
router.post("/userMsgAudit", controller.audit.userMsgAudit);
|
||||
|
||||
// 管理系统检索考生姓名
|
||||
router.post("/searchUserName", controller.search.searchUserName);
|
||||
// 管理系统检索考生身份证号码
|
||||
router.post("/searchIdentityCard", controller.search.searchIdentityCard);
|
||||
// 管理系统检索考试 uid
|
||||
router.post("/searchExamUid", controller.search.searchExamUid);
|
||||
// 管理系统检索工作单位
|
||||
router.post("/searchWorkplace", controller.search.searchWorkplace);
|
||||
// 管理系统检索报名结果说明
|
||||
router.post("/searchResult", controller.search.searchResult);
|
||||
|
||||
// 管理系统查找指定考生姓名
|
||||
router.post("/findUserName", controller.find.findUserName);
|
||||
// 管理系统查找指定考生身份证号
|
||||
router.post("/findIdentityCard", controller.find.findIdentityCard);
|
||||
// 管理系统查找指定考试 uid
|
||||
router.post("/findExamUid", controller.find.findExamUid);
|
||||
// 管理系统查找指定工作单位
|
||||
router.post("/findWorkplace", controller.find.findWorkplace);
|
||||
|
||||
// 管理系统新增考生报名信息
|
||||
router.post("/addApplication", controller.application.addApplication);
|
||||
// 管理系统查看考生报名信息
|
||||
router.post("/showApplication", controller.application.showApplication);
|
||||
// 管理系统编辑考生报名信息
|
||||
router.post("/editApplication", controller.application.editApplication);
|
||||
// 管理系统删除考生报名信息
|
||||
router.post("/deleteApplication", controller.application.deleteApplication);
|
||||
// 管理系统导出考生报名信息数据
|
||||
router.post("/downloadApplicationData", controller.application.downloadApplicationData);
|
||||
|
||||
// 管理系统新增考生考试结果
|
||||
router.post("/addGrades", controller.grades.addGrades);
|
||||
// 管理系统查看考生考试结果
|
||||
router.post("/showGrades", controller.grades.showGrades);
|
||||
// 管理系统编辑考生考试结果
|
||||
router.post("/editGrades", controller.grades.editGrades);
|
||||
// 管理系统删除考生考试结果
|
||||
router.post("/deleteGrades", controller.grades.deleteGrades);
|
||||
// 管理系统导出考生考试结果数据
|
||||
router.post("/downloadGradesData", controller.grades.downloadGradesData);
|
||||
|
||||
// 查看导入错误记录
|
||||
router.post("/showImporterror", controller.importerror.showImporterror);
|
||||
// 删除导入错误记录
|
||||
router.post("/deleteImporterror", controller.importerror.deleteImporterror);
|
||||
|
||||
// 管理系统新增题库白名单
|
||||
router.post("/addTopicWhitelist", controller.topicWhitelist.addTopicWhitelist);
|
||||
// 管理系统查看题库白名单
|
||||
router.post("/showTopicWhitelist", controller.topicWhitelist.showTopicWhitelist);
|
||||
// 管理系统编辑题库白名单
|
||||
router.post("/editTopicWhitelist", controller.topicWhitelist.editTopicWhitelist);
|
||||
// 管理系统删除题库白名单
|
||||
router.post("/deleteTopicWhitelist", controller.topicWhitelist.deleteTopicWhitelist);
|
||||
// 管理系统导出题库白名单
|
||||
router.post("/downloadTopicWhitelistData", controller.topicWhitelist.downloadTopicWhitelistData);
|
||||
|
||||
// 管理系统新增问答题
|
||||
router.post("/addInterlocution", controller.interlocution.addInterlocution);
|
||||
// 管理系统查看问答题
|
||||
router.post("/showInterlocution", controller.interlocution.showInterlocution);
|
||||
// 管理系统编辑问答题
|
||||
router.post("/editInterlocution", controller.interlocution.editInterlocution);
|
||||
// 管理系统删除问答题
|
||||
router.post("/deleteInterlocution", controller.interlocution.deleteInterlocution);
|
||||
// 管理系统导出问答题
|
||||
router.post("/downloadInterlocutionData", controller.interlocution.downloadInterlocutionData);
|
||||
|
||||
// 管理系统新增选择题
|
||||
router.post("/addJudgment", controller.judgment.addJudgment);
|
||||
// 管理系统查看选择题
|
||||
router.post("/showJudgment", controller.judgment.showJudgment);
|
||||
// 管理系统编辑选择题
|
||||
router.post("/editJudgment", controller.judgment.editJudgment);
|
||||
// 管理系统删除选择题
|
||||
router.post("/deleteJudgment", controller.judgment.deleteJudgment);
|
||||
// 管理系统导出选择题
|
||||
router.post("/downloadJudgmentData", controller.judgment.downloadJudgmentData);
|
||||
|
||||
// 管理系统新增多选题
|
||||
router.post("/addMultiple", controller.multiple.addMultiple);
|
||||
// 管理系统查看多选题
|
||||
router.post("/showMultiple", controller.multiple.showMultiple);
|
||||
// 管理系统编辑多选题
|
||||
router.post("/editMultiple", controller.multiple.editMultiple);
|
||||
// 管理系统删除多选题
|
||||
router.post("/deleteMultiple", controller.multiple.deleteMultiple);
|
||||
// 管理系统导出多选题
|
||||
router.post("/downloadMultipleData", controller.multiple.downloadMultipleData);
|
||||
|
||||
// 管理系统新增单选题
|
||||
router.post("/addRadio", controller.radio.addRadio);
|
||||
// 管理系统查看单选题
|
||||
router.post("/showRadio", controller.radio.showRadio);
|
||||
// 管理系统编辑单选题
|
||||
router.post("/editRadio", controller.radio.editRadio);
|
||||
// 管理系统删除单选题
|
||||
router.post("/deleteRadio", controller.radio.deleteRadio);
|
||||
// 管理系统导出单选题
|
||||
router.post("/downloadRadioData", controller.radio.downloadRadioData);
|
||||
|
||||
// 查看监控记录
|
||||
router.post("/showMonitoring", controller.monitoring.showMonitoring);
|
||||
// 删除监控记录
|
||||
router.post("/deleteMonitoring", controller.monitoring.deleteMonitoring);
|
||||
|
||||
// 导出小鹅通导入用户
|
||||
router.post("/importXiaoeTech", controller.download.importXiaoeTech);
|
||||
// 导出小鹅通开课学员
|
||||
router.post("/commencementXiaoeTech", controller.download.commencementXiaoeTech);
|
||||
// 导出批量报名导入 excel 表
|
||||
router.post("/importApplicationData", controller.download.importApplicationData);
|
||||
// 导出考试星学员导入 excel 表
|
||||
router.post("/importExamStars", controller.download.importExamStars);
|
||||
// 导出培训证书发放用户导入 excel 表
|
||||
router.post("/importIssuance", controller.download.importIssuance);
|
||||
// 导出培训证书发放用户照片文件夹
|
||||
router.post("/importUserPhoto", controller.download.importUserPhoto);
|
||||
// 上传用户照片
|
||||
router.post("/uploadUserPhoto", controller.download.uploadUserPhoto);
|
||||
// 导出考试成绩导入 excel 表
|
||||
router.post("/importGradesData", controller.download.importGradesData);
|
||||
|
||||
// 核验用户身份证二要素
|
||||
router.post("/CNTEV", controller.cntev.CNTEV);
|
||||
};
|
||||
260
app/service/Admin.js
Normal file
@@ -0,0 +1,260 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "Admin";
|
||||
|
||||
class AdminService extends Service {
|
||||
// 管理系统新增普通管理员账号信息
|
||||
async addAdmin(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Manager.bulkCreate(form, { ignoreDuplicates: true });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addAdmin";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看普通管理员账号信息
|
||||
async showAdmin(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['uid', 'account_name', 'role', 'status', 'created_at', 'updated_at', 'login_status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'account_name'],
|
||||
key = ['role', 'status', 'login_status'],
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model.Manager.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showAdmin";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑普通管理员账号信息
|
||||
async editAdmin(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 1) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { uid, account_name, role, status } = requestMsg;
|
||||
where = { uid, account_name, role, status };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], account_name = [], role = [], status = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid);
|
||||
account_name.push(element.account_name);
|
||||
role.push(element.role);
|
||||
status.push(element.status);
|
||||
});
|
||||
}
|
||||
where = { uid, account_name, role, status };
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
const resultList = await ctx.model.Manager.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editAdmin";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除普通管理员账号信息
|
||||
async deleteAdmin(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.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 2) {
|
||||
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 < 2) systemMonitoring.status = 2;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { uid, account_name, role, status } = requestMsg;
|
||||
where = { uid, account_name, role, status };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], account_name = [], role = [], status = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid);
|
||||
account_name.push(element.account_name);
|
||||
role.push(element.role);
|
||||
status.push(element.status);
|
||||
});
|
||||
}
|
||||
where = { uid, account_name, role, status };
|
||||
}
|
||||
const resultList = await ctx.model.Manager.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteAdmin";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出普通管理员账号信息数据
|
||||
async downloadAdminData(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['uid', 'account_name', 'role', 'status', 'created_at', 'updated_at', 'login_status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'account_name'],
|
||||
key = ['role', 'status', 'login_status'],
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model.Manager.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const roleOptions = [
|
||||
{
|
||||
value: "9",
|
||||
label: "系统管理员"
|
||||
},
|
||||
{
|
||||
value: "0",
|
||||
label: "临时管理员"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "普通管理员"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "高级管理员"
|
||||
},
|
||||
];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "默认状态"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "正常使用"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "已被弃用"
|
||||
},
|
||||
];
|
||||
result.forEach(element => {
|
||||
roleOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["role"]) {
|
||||
element.dataValues["role"] = item.label;
|
||||
}
|
||||
});
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
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.login_status;
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadAdminData";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AdminService;
|
||||
483
app/service/Application.js
Normal file
@@ -0,0 +1,483 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "Application";
|
||||
|
||||
class ApplicationService extends Service {
|
||||
// 管理系统新增用户报名信息
|
||||
async addApplication(userMsgObj, form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['uid', 'user_name', 'identity_card'],
|
||||
where = userMsgObj,
|
||||
dbOptions = { attributes, where };
|
||||
const userUid = await ctx.model.Examinee.findAll(dbOptions);
|
||||
if(userUid.length == 0) {
|
||||
let errorForm = [];
|
||||
form.forEach(item => {
|
||||
errorForm.push({
|
||||
user_name: item.user_name,
|
||||
identity_card: item.identity_card,
|
||||
exam_uid: item.exam_uid,
|
||||
type: 0,
|
||||
status: 0,
|
||||
created_at: new Date()
|
||||
});
|
||||
});
|
||||
await ctx.model.Importerror.bulkCreate(errorForm);
|
||||
return { code: 400 };
|
||||
};
|
||||
let errorMark = false;
|
||||
form.forEach(async item => {
|
||||
item.user_uid = 'none';
|
||||
userUid.forEach(element => {
|
||||
if (item.user_name == element.dataValues.user_name && item.identity_card == element.dataValues.identity_card) {
|
||||
item.user_uid = element.dataValues.uid;
|
||||
}
|
||||
});
|
||||
delete item.user_name;
|
||||
delete item.identity_card;
|
||||
if(item.user_uid == 'none') {
|
||||
let errorForm = {
|
||||
user_name: item.user_name,
|
||||
identity_card: item.identity_card,
|
||||
exam_uid: item.exam_uid,
|
||||
type: 0,
|
||||
status: 0,
|
||||
created_at: new Date()
|
||||
};
|
||||
errorMark = true;
|
||||
await ctx.model.Importerror.create(errorForm);
|
||||
}
|
||||
});
|
||||
|
||||
const result = await ctx.model.Application.bulkCreate(form, { ignoreDuplicates: true });
|
||||
return result.length == 0 ? false : errorMark ? { code: 300, data: result } : { code: 200, data: result };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addApplication";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看用户报名信息
|
||||
async showApplication(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['user_uid', 'exam_uid', 'source', 'status', 'pay_status', 'result', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['user_uid', 'exam_uid', 'source', 'result'],
|
||||
key = ['status', 'pay_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 (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 examination = ['exam_name', 'application_start', 'application_end'],
|
||||
examinationWhere = {},
|
||||
examinationOrder = [],
|
||||
examinationJoinSubstring = [],
|
||||
examinationSubstring = ['exam_name'],
|
||||
examinationKey = [],
|
||||
examinationBetween = ['application_start', 'application_end'];
|
||||
|
||||
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 examinee = ['user_name', 'identity_card', 'workplace', 'phone'],
|
||||
examineeWhere = {},
|
||||
examineeOrder = [],
|
||||
examineeJoinSubstring = [],
|
||||
examineeSubstring = ['user_name', 'identity_card', 'workplace', 'phone'],
|
||||
examineeKey = [],
|
||||
examineeBetween = [];
|
||||
|
||||
examinee.forEach(item => {
|
||||
if (searchOptions[item]) {
|
||||
if (searchOptions[item] == '*空') {
|
||||
if (examineeJoinSubstring.includes(item)) {
|
||||
examineeWhere[item] = null;
|
||||
} else {
|
||||
examineeWhere[item] = [null, ''];
|
||||
}
|
||||
} else if (examineeSubstring.includes(item)) {
|
||||
examineeWhere[item] = { [Op.substring]: searchOptions[item] };
|
||||
} else if (examineeKey.includes(item)) {
|
||||
examineeWhere[item] = searchOptions[item];
|
||||
} else if (examineeBetween.includes(item)) {
|
||||
examineeWhere[item] = { [Op.between]: [searchOptions[item][0], searchOptions[item][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[item] == true) {
|
||||
examineeOrder.push([item, 'ASC']);
|
||||
} else if (sortOptions[item] == false) {
|
||||
examineeOrder.push([item, 'DESC']);
|
||||
}
|
||||
});
|
||||
let include = [
|
||||
{
|
||||
model: ctx.model.Examinee,
|
||||
attributes: ['user_name', 'identity_card', 'workplace', 'phone'],
|
||||
where: examineeWhere,
|
||||
order: examineeOrder
|
||||
},
|
||||
{
|
||||
model: ctx.model.Examination,
|
||||
attributes: ['exam_name', 'application_start', 'application_end'],
|
||||
where: examinationWhere,
|
||||
order: examinationOrder
|
||||
}
|
||||
];
|
||||
ctx.model.Application.belongsTo(ctx.model.Examinee, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
ctx.model.Application.belongsTo(ctx.model.Examination, { foreignKey: 'exam_uid', targetKey: 'uid' });
|
||||
|
||||
dbOptions = { attributes, offset, limit, where, order, include };
|
||||
const result = await ctx.model.Application.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showApplication";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑用户报名信息
|
||||
async editApplication(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 1) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user_uid, exam_uid, source, status, pay_status, result } = requestMsg;
|
||||
where = { user_uid, exam_uid, source, status, pay_status, result };
|
||||
} else if (modelType == "multiple") {
|
||||
let user_uid = [], exam_uid = [], source = [], status = [], pay_status = [], result = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user_uid.push(element.user_uid);
|
||||
exam_uid.push(element.exam_uid);
|
||||
source.push(element.source);
|
||||
status.push(element.status);
|
||||
pay_status.push(element.pay_status);
|
||||
result.push(element.result);
|
||||
});
|
||||
}
|
||||
where = { user_uid, exam_uid, source, status, pay_status, result };
|
||||
}
|
||||
const resultList = await ctx.model.Application.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editApplication";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除用户报名信息
|
||||
async deleteApplication(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.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 2) {
|
||||
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 < 2) systemMonitoring.status = 2;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user_uid, exam_uid, source, status, pay_status, result } = requestMsg;
|
||||
where = { user_uid, exam_uid, source, status, pay_status, result };
|
||||
} else if (modelType == "multiple") {
|
||||
let user_uid = [], exam_uid = [], source = [], status = [], pay_status = [], result = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user_uid.push(element.user_uid);
|
||||
exam_uid.push(element.exam_uid);
|
||||
source.push(element.source);
|
||||
status.push(element.status);
|
||||
pay_status.push(element.pay_status);
|
||||
result.push(element.result);
|
||||
});
|
||||
}
|
||||
where = { user_uid, exam_uid, source, status, pay_status, result };
|
||||
}
|
||||
const resultList = await ctx.model.Application.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteApplication";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出考生报名信息数据
|
||||
async downloadApplicationData(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['user_uid', 'exam_uid', 'source', 'status', 'pay_status', 'result', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['user_uid', 'exam_uid', 'source', 'result'],
|
||||
key = ['status', 'pay_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 (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 examination = ['exam_name', 'application_start', 'application_end'],
|
||||
examinationWhere = {},
|
||||
examinationOrder = [],
|
||||
examinationJoinSubstring = [],
|
||||
examinationSubstring = ['exam_name'],
|
||||
examinationKey = [],
|
||||
examinationBetween = ['application_start', 'application_end'];
|
||||
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 examinee = ['user_name', 'identity_card', 'workplace', 'phone'],
|
||||
examineeWhere = {},
|
||||
examineeOrder = [],
|
||||
examineeJoinSubstring = [],
|
||||
examineeSubstring = ['user_name', 'identity_card', 'workplace', 'phone'],
|
||||
examineeKey = [],
|
||||
examineeBetween = [];
|
||||
|
||||
examinee.forEach(item => {
|
||||
if (searchOptions[item]) {
|
||||
if (searchOptions[item] == '*空') {
|
||||
if (examineeJoinSubstring.includes(item)) {
|
||||
examineeWhere[item] = null;
|
||||
} else {
|
||||
examineeWhere[item] = [null, ''];
|
||||
}
|
||||
} else if (examineeSubstring.includes(item)) {
|
||||
examineeWhere[item] = { [Op.substring]: searchOptions[item] };
|
||||
} else if (examineeKey.includes(item)) {
|
||||
examineeWhere[item] = searchOptions[item];
|
||||
} else if (examineeBetween.includes(item)) {
|
||||
examineeWhere[item] = { [Op.between]: [searchOptions[item][0], searchOptions[item][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[item] == true) {
|
||||
examineeOrder.push([item, 'ASC']);
|
||||
} else if (sortOptions[item] == false) {
|
||||
examineeOrder.push([item, 'DESC']);
|
||||
}
|
||||
});
|
||||
let include = [
|
||||
{
|
||||
model: ctx.model.Examinee,
|
||||
attributes: ['user_name', 'identity_card', 'workplace', 'phone'],
|
||||
where: examineeWhere,
|
||||
order: examineeOrder
|
||||
},
|
||||
{
|
||||
model: ctx.model.Examination,
|
||||
attributes: ['exam_name', 'application_start', 'application_end'],
|
||||
where: examinationWhere,
|
||||
order: examinationOrder
|
||||
}
|
||||
];
|
||||
ctx.model.Application.belongsTo(ctx.model.Examinee, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
ctx.model.Application.belongsTo(ctx.model.Examination, { foreignKey: 'exam_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, where, order, include };
|
||||
const result = await ctx.model.Application.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "审核中"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "报名成功"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "报名失败"
|
||||
},
|
||||
{
|
||||
value: "3",
|
||||
label: "取消报名"
|
||||
},
|
||||
];
|
||||
const payStatusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "未缴费"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "缴费成功"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "缴费失败"
|
||||
},
|
||||
];
|
||||
result.forEach(element => {
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
payStatusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["pay_status"]) {
|
||||
element.dataValues["pay_status"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.user_name = element.dataValues.examinee.dataValues.user_name;
|
||||
element.dataValues.identity_card = element.dataValues.examinee.dataValues.identity_card;
|
||||
element.dataValues.exam_name = element.dataValues.examination.dataValues.exam_name;
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.application_start = moment
|
||||
.utc(element.dataValues.examination.dataValues.application_start)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.application_end = moment
|
||||
.utc(element.dataValues.examination.dataValues.application_end)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
delete element.dataValues.examinee;
|
||||
delete element.dataValues.examination;
|
||||
let elementClone = {
|
||||
user_uid: element.dataValues.user_uid,
|
||||
user_name: element.dataValues.user_name,
|
||||
identity_card: element.dataValues.identity_card,
|
||||
exam_uid: element.dataValues.exam_uid,
|
||||
exam_name: element.dataValues.exam_name,
|
||||
source: element.dataValues.source,
|
||||
status: element.dataValues.status,
|
||||
pay_status: element.dataValues.pay_status,
|
||||
result: element.dataValues.result,
|
||||
created_at: element.dataValues.created_at,
|
||||
application_start: element.dataValues.application_start,
|
||||
application_end: element.dataValues.application_end,
|
||||
}
|
||||
data.push(elementClone);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadApplicationData";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ApplicationService;
|
||||
89
app/service/Audit.js
Normal file
@@ -0,0 +1,89 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Audit";
|
||||
|
||||
class AuditService extends Service {
|
||||
// 管理系统查看用户关键信息变更
|
||||
async auditList(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['uid', 'user_name', 'identity_card', 'real_check', 'workplace', 'address', 'phone', 'email', 'status', 'created_at', 'updated_at', 'login_status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'user_name', 'identity_card', 'workplace', 'address', 'phone', 'email'],
|
||||
key = ['real_check', 'status', 'login_status'],
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
// 默认查询的 status 为 0,管理员可以请求其他状态的审核列表
|
||||
// let status = 0;
|
||||
const result = await ctx.model.Audit.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "auditList";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统审核用户关键信息变更
|
||||
async userMsgAudit(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
console.log(uid);
|
||||
console.log(body);
|
||||
// const result = await ctx.model.Audit.update({ status: 1 }, { where: { status: 0, body } });
|
||||
// console.log(result);
|
||||
// return result[0] == 0 ? false : true;
|
||||
return true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "userMsgAudit";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 保存导入考生报名信息和考生成绩时存在错误的数据,方便管理员查找问题
|
||||
async importerror(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
await ctx.model.Importerror.bulkCreate(form);
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "importerror";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AuditService;
|
||||
57
app/service/Cntev.js
Normal file
@@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Cntev";
|
||||
|
||||
class CntevService extends Service {
|
||||
// 筛选核验失败的数据
|
||||
async siftFailedList(finishedList) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['user_name', 'identity_card', 'real_check'],
|
||||
where = { identity_card: { [Op.notIn]: finishedList }, real_check: 2 },
|
||||
dbOptions = { attributes, where };
|
||||
const result = await ctx.model.Examinee.findAll(dbOptions);
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "siftFailedList";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 筛选未核验的数据
|
||||
async validateList(finishedList) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['user_name', 'identity_card', 'real_check'],
|
||||
where = { identity_card: { [Op.notIn]: finishedList }, real_check: 0 },
|
||||
dbOptions = { attributes, where };
|
||||
const result = await ctx.model.Examinee.findAll(dbOptions);
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "validateList";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 身份证二要素核验状态更新
|
||||
async updateCNTEV(user_name, identity_card, real_check) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const where = { user_name, identity_card };
|
||||
await ctx.model.Examinee.update({ real_check }, { where });
|
||||
await ctx.model.Audit.update({ status: real_check }, { where });
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "CNTEV";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CntevService;
|
||||
80
app/service/Diff.js
Normal file
@@ -0,0 +1,80 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Diff";
|
||||
|
||||
class DiffService extends Service {
|
||||
// 比较身份证号
|
||||
async diffIdentityCard(identity_card, type, uid) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['identity_card'],
|
||||
where = { identity_card },
|
||||
dbOptions = { attributes, where };
|
||||
const search = await ctx.model.Examinee.findAll(dbOptions);
|
||||
if (type == 'register') {
|
||||
return search.length == 0;
|
||||
} else if (type == 'edit') {
|
||||
where = { uid };
|
||||
dbOptions = { attributes, where };
|
||||
const result = await ctx.model.Examinee.findOne(dbOptions);
|
||||
return result == null ? true : result.dataValues.identity_card == identity_card ? true : search.length == 0;
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "diffIdentityCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 比较邮箱
|
||||
async diffEmail(email, type, uid) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['email'],
|
||||
where = { email },
|
||||
dbOptions = { attributes, where };
|
||||
const search = await ctx.model.Examinee.findAll(dbOptions);
|
||||
if (type == 'register') {
|
||||
return search.length == 0;
|
||||
} else if (type == 'edit') {
|
||||
where = { uid };
|
||||
dbOptions = { attributes, where };
|
||||
const result = await ctx.model.Examinee.findOne(dbOptions);
|
||||
return result == null ? true : result.dataValues.email == email ? true : search.length == 0;
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "diffEmail";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 比较电话号码
|
||||
async diffPhone(phone, type, uid) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['phone'],
|
||||
where = { phone },
|
||||
dbOptions = { attributes, where };
|
||||
const search = await ctx.model.Examinee.findAll(dbOptions);
|
||||
if (type == 'register') {
|
||||
return search.length == 0;
|
||||
} else if (type == 'edit') {
|
||||
where = { uid };
|
||||
dbOptions = { attributes, where };
|
||||
const result = await ctx.model.Examinee.findOne(dbOptions);
|
||||
return result == null ? true : result.dataValues.phone == phone ? true : search.length == 0;
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "diffPhone";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DiffService;
|
||||
493
app/service/Download.js
Normal file
@@ -0,0 +1,493 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Download";
|
||||
|
||||
class DownloadService extends Service {
|
||||
// 导出小鹅通导入用户
|
||||
async importXiaoeTech(uid, searchMsg, importForm) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['user_uid', 'exam_uid', 'status', 'result'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['exam_uid', 'result'],
|
||||
key = ['status'],
|
||||
between = [];
|
||||
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.model.Examinee,
|
||||
attributes: ['user_name', 'identity_card', 'workplace', 'address', 'phone', 'email'],
|
||||
}
|
||||
];
|
||||
ctx.model.Application.belongsTo(ctx.model.Examinee, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, where, order, include };
|
||||
const result = await ctx.model.Application.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
result.forEach(element => {
|
||||
let identity_card = element.dataValues.examinee.dataValues.identity_card,
|
||||
gender = parseInt(identity_card[16], 10) % 2 == 0 ? '女' : '男',
|
||||
birthday = new Date(identity_card.substring(6, 14).substring(0, 4), identity_card.substring(6, 14).substring(4, 6) - 1, identity_card.substring(6, 14).substring(6, 8)),
|
||||
age = new Date().getFullYear() - birthday.getFullYear();
|
||||
const m = new Date().getMonth() - birthday.getMonth();
|
||||
if (m < 0 || (m === 0 && new Date().getDate() < birthday.getDate())) {
|
||||
age--;
|
||||
}
|
||||
data.push({
|
||||
phone: element.dataValues.examinee.dataValues.phone,
|
||||
user_name: element.dataValues.examinee.dataValues.user_name,
|
||||
remark: "",
|
||||
gender,
|
||||
age,
|
||||
birthday,
|
||||
province: "",
|
||||
city: "",
|
||||
address: element.dataValues.examinee.dataValues.address,
|
||||
email: element.dataValues.examinee.dataValues.email,
|
||||
industry: "",
|
||||
company: element.dataValues.examinee.dataValues.workplace,
|
||||
position: "",
|
||||
description: "",
|
||||
tags: "",
|
||||
});
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "importXiaoeTech";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 导出小鹅通开课学员
|
||||
async commencementXiaoeTech(uid, searchMsg, importForm) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['user_uid', 'exam_uid', 'status', 'result'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['exam_uid', 'result'],
|
||||
key = ['status'],
|
||||
between = [];
|
||||
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.model.Examinee,
|
||||
attributes: ['phone'],
|
||||
}
|
||||
];
|
||||
ctx.model.Application.belongsTo(ctx.model.Examinee, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, where, order, include };
|
||||
const result = await ctx.model.Application.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
result.forEach(element => {
|
||||
data.push({
|
||||
phone: element.dataValues.examinee.dataValues.phone,
|
||||
expired_at: importForm.expired_at.replace(/_/g, ' ').replace(/:/g, ':'),
|
||||
});
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "commencementXiaoeTech";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 导出批量报名导入 excel 表
|
||||
async importApplicationData(uid, searchMsg, importForm) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['user_name', 'identity_card', 'workplace', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['workplace'],
|
||||
key = [],
|
||||
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 (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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model.Examinee.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
result.forEach(element => {
|
||||
data.push({
|
||||
identity_card: element.dataValues.identity_card,
|
||||
user_name: element.dataValues.user_name,
|
||||
exam_uid: importForm.exam_uid,
|
||||
source: importForm.source,
|
||||
status: "1",
|
||||
pay_status: "1",
|
||||
result: importForm.result
|
||||
});
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "importApplicationData";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 导出考试星学员导入 excel 表
|
||||
async importExamStars(uid, searchMsg, importForm) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['exam_uid', 'status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['exam_uid'],
|
||||
key = ['status'],
|
||||
between = [];
|
||||
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.model.Examinee,
|
||||
attributes: ['user_name', 'identity_card'],
|
||||
}
|
||||
];
|
||||
ctx.model.Application.belongsTo(ctx.model.Examinee, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, where, order, include };
|
||||
const result = await ctx.model.Application.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
result.forEach(element => {
|
||||
data.push({
|
||||
account: element.dataValues.examinee.dataValues.identity_card,
|
||||
password: element.dataValues.examinee.dataValues.identity_card.substr(-6),
|
||||
name: element.dataValues.examinee.dataValues.user_name,
|
||||
department: "",
|
||||
});
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "importExamStars";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 导出培训证书发放用户导入 excel 表
|
||||
async importIssuance(uid, searchMsg, importForm) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['exam_uid', 'status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['exam_uid'],
|
||||
key = ['status'],
|
||||
between = [];
|
||||
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.model.Examinee,
|
||||
attributes: ['user_name', 'identity_card', 'workplace', 'address', 'phone'],
|
||||
}
|
||||
];
|
||||
ctx.model.Application.belongsTo(ctx.model.Examinee, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, where, order, include };
|
||||
const result = await ctx.model.Application.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
result.forEach((element, index) => {
|
||||
data.push({
|
||||
id: index + 1,
|
||||
user_name: element.dataValues.examinee.dataValues.user_name,
|
||||
identity_card: element.dataValues.examinee.dataValues.identity_card,
|
||||
workplace: element.dataValues.examinee.dataValues.workplace,
|
||||
address: element.dataValues.examinee.dataValues.address,
|
||||
phone: element.dataValues.examinee.dataValues.phone,
|
||||
start: "",
|
||||
end: "",
|
||||
place: "",
|
||||
way: "",
|
||||
score: "",
|
||||
certificate_name: "",
|
||||
level: "",
|
||||
});
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "importIssuance";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 导出培训证书发放用户照片文件夹
|
||||
async importUserPhoto(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['exam_uid', 'status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['exam_uid'],
|
||||
key = ['status'],
|
||||
between = [];
|
||||
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.model.Examinee,
|
||||
attributes: ['identity_card'],
|
||||
}
|
||||
];
|
||||
ctx.model.Application.belongsTo(ctx.model.Examinee, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, where, order, include };
|
||||
const result = await ctx.model.Application.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
result.forEach(element => {
|
||||
data.push({
|
||||
identity_card: element.dataValues.examinee.dataValues.identity_card,
|
||||
});
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "importUserPhoto";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 导出考试成绩导入 excel 表
|
||||
async importGradesData(uid, formClone, dataType, passingScore, gradesType) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
const data = formClone.map(item => ({
|
||||
user_name: item.user_name,
|
||||
identity_card: item.identity_card,
|
||||
exam_uid: "",
|
||||
status: "",
|
||||
grades: item.grades,
|
||||
pass_type: "",
|
||||
}));
|
||||
const identityCards = data.map(item => item.identity_card);
|
||||
const userNames = data.map(item => item.user_name);
|
||||
const examineeUid = await ctx.model.Examinee.findAll({ attributes: ['uid', 'identity_card', 'user_name'], where: { identity_card: identityCards, user_name: userNames } });
|
||||
if (examineeUid.length == 0) return { code: false };
|
||||
const uidMap = new Map();
|
||||
const userUids = [];
|
||||
examineeUid.forEach(element => {
|
||||
uidMap.set(`${element.dataValues.identity_card}_${element.dataValues.user_name}`, element.dataValues.uid);
|
||||
userUids.push(element.dataValues.uid);
|
||||
});
|
||||
data.forEach(item => {
|
||||
const key = `${item.identity_card}_${item.user_name}`;
|
||||
if (uidMap.has(key)) {
|
||||
item.user_uid = uidMap.get(key);
|
||||
}
|
||||
});
|
||||
const applicationUid = await ctx.model.Application.findAll({ attributes: ['user_uid', 'exam_uid'], where: { user_uid: userUids, status: 1 }, order: [['created_at', 'DESC']], limit: userUids.length });
|
||||
if (applicationUid.length == 0) return { code: false };
|
||||
const applicationUidMap = new Map(applicationUid.map(item => [item.dataValues.user_uid, item.dataValues.exam_uid]));
|
||||
data.forEach(item => {
|
||||
if (applicationUidMap.has(item.user_uid)) {
|
||||
item.exam_uid = applicationUidMap.get(item.user_uid);
|
||||
}
|
||||
});
|
||||
const examUids = [...new Set(applicationUid.map(item => item.dataValues.exam_uid))];
|
||||
let include = [
|
||||
{
|
||||
model: ctx.model.Examinee,
|
||||
attributes: ['user_name', 'identity_card'],
|
||||
},
|
||||
];
|
||||
if (gradesType == '0') {
|
||||
ctx.model.Application.belongsTo(ctx.model.Examinee, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
const application = await ctx.model.Application.findAll({ attributes: ['user_uid', 'exam_uid'], where: { user_uid: { [Op.notIn]: userUids }, exam_uid: examUids, status: 1 }, include });
|
||||
application.forEach(element => {
|
||||
data.push({
|
||||
identity_card: element.dataValues.examinee.dataValues.identity_card,
|
||||
user_name: element.dataValues.examinee.dataValues.user_name,
|
||||
user_uid: element.dataValues.user_uid,
|
||||
exam_uid: element.dataValues.exam_uid,
|
||||
grades: null,
|
||||
});
|
||||
});
|
||||
}
|
||||
data.forEach(item => {
|
||||
delete item.user_uid;
|
||||
item.status = dataType == '0' ? 1 : (item.grades == null ? 0 : 1);
|
||||
item.pass_type = item.grades == null
|
||||
? (dataType == '0' ? 0 : 2)
|
||||
: (dataType == '1' && item.grades < passingScore ? 0 : 1);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "importGradesData";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = DownloadService;
|
||||
247
app/service/Exam.js
Normal file
@@ -0,0 +1,247 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "Exam";
|
||||
|
||||
class ExamService extends Service {
|
||||
// 管理系统新增考试信息
|
||||
async addExam(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Examination.bulkCreate(form, { ignoreDuplicates: true });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addExam";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看考试信息
|
||||
async showExam(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['uid', 'exam_name', 'status', 'application_start', 'application_end', 'exam_start', 'exam_end'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'exam_name'],
|
||||
key = ['status'],
|
||||
between = ['application_start', 'application_end', 'exam_start', 'exam_end'];
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model.Examination.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showExam";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑考试信息
|
||||
async editExam(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 1) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { exam_name, status, application_start, application_end, exam_start, exam_end } = requestMsg;
|
||||
where = { exam_name, status, application_start, application_end, exam_start, exam_end };
|
||||
} else if (modelType == "multiple") {
|
||||
let exam_name = [], status = [], application_start = [], application_end = [], exam_start = [], exam_end = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
exam_name.push(element.exam_name);
|
||||
status.push(element.status);
|
||||
application_start.push(element.application_start);
|
||||
application_end.push(element.application_end);
|
||||
exam_start.push(element.exam_start);
|
||||
exam_end.push(element.exam_end);
|
||||
});
|
||||
}
|
||||
where = { exam_name, status, application_start, application_end, exam_start, exam_end };
|
||||
}
|
||||
const resultList = await ctx.model.Examination.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editExam";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除考试信息
|
||||
async deleteExam(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.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 2) {
|
||||
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 < 2) systemMonitoring.status = 2;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { exam_name, status, application_start, application_end, exam_start, exam_end } = requestMsg;
|
||||
where = { exam_name, status, application_start, application_end, exam_start, exam_end };
|
||||
} else if (modelType == "multiple") {
|
||||
let exam_name = [], status = [], application_start = [], application_end = [], exam_start = [], exam_end = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
exam_name.push(element.exam_name);
|
||||
status.push(element.status);
|
||||
application_start.push(element.application_start);
|
||||
application_end.push(element.application_end);
|
||||
exam_start.push(element.exam_start);
|
||||
exam_end.push(element.exam_end);
|
||||
});
|
||||
}
|
||||
where = { exam_name, status, application_start, application_end, exam_start, exam_end };
|
||||
}
|
||||
const resultList = await ctx.model.Examination.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteExam";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出考试信息数据
|
||||
async downloadExamData(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['uid', 'exam_name', 'status', 'application_start', 'application_end', 'exam_start', 'exam_end'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'exam_name'],
|
||||
key = ['status'],
|
||||
between = ['application_start', 'application_end', 'exam_start', 'exam_end'];
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model.Examination.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "即将进行"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "正在进行"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "已经结束"
|
||||
},
|
||||
];
|
||||
result.forEach(element => {
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.application_start = moment
|
||||
.utc(element.dataValues.application_start)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.application_end = moment
|
||||
.utc(element.dataValues.application_end)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.exam_start = moment
|
||||
.utc(element.dataValues.exam_start)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.exam_end = moment
|
||||
.utc(element.dataValues.exam_end)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadExamData";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ExamService;
|
||||
82
app/service/Find.js
Normal file
@@ -0,0 +1,82 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Find";
|
||||
|
||||
class FindService extends Service {
|
||||
// 管理系统检索考生姓名
|
||||
async findUserName(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Examinee.findOne({ where: { user_name: body.user_name } });
|
||||
return result || false;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "findUserName";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索考生身份证号
|
||||
async findIdentityCard(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Examinee.findOne({ where: { identity_card: body.identity_card } });
|
||||
if (!result) return { code: 404 };
|
||||
const user = await ctx.model.Examinee.findOne({ where: { user_name: body.user_name, identity_card: body.identity_card } });
|
||||
if (!user) return { code: 303 };
|
||||
return { code: 200 };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "findIdentityCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索考生 uid
|
||||
async findUserUid(identity_card, user_name) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['uid'],
|
||||
where = { identity_card, user_name },
|
||||
dbOptions = { attributes, where };
|
||||
const result = await ctx.model.Examinee.findOne(dbOptions);
|
||||
return result || false;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "findUserUid";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索考试 uid
|
||||
async findExamUid(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Examination.findOne({ where: { uid: body.exam_uid } });
|
||||
return result || false;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "findExamUid";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查找指定工作单位
|
||||
async findWorkplace(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Examinee.findOne({ where: { workplace: body.workplace } });
|
||||
return result || false;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "findWorkplace";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = FindService;
|
||||
468
app/service/Grades.js
Normal file
@@ -0,0 +1,468 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "Grades";
|
||||
|
||||
class GradesService extends Service {
|
||||
// 管理系统新增用户考试结果
|
||||
async addGrades(userMsgObj, form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['uid', 'user_name', 'identity_card'],
|
||||
where = userMsgObj,
|
||||
dbOptions = { attributes, where };
|
||||
const userUid = await ctx.model.Examinee.findAll(dbOptions);
|
||||
if(userUid.length == 0) {
|
||||
let errorForm = [];
|
||||
form.forEach(item => {
|
||||
errorForm.push({
|
||||
user_name: item.user_name,
|
||||
identity_card: item.identity_card,
|
||||
exam_uid: item.exam_uid,
|
||||
type: 1,
|
||||
status: 0,
|
||||
created_at: new Date()
|
||||
});
|
||||
});
|
||||
await ctx.model.Importerror.bulkCreate(errorForm);
|
||||
return { code: 400 };
|
||||
};
|
||||
let errorMark = false;
|
||||
form.forEach(async item => {
|
||||
item.user_uid = 'none';
|
||||
userUid.forEach(element => {
|
||||
if (item.user_name == element.dataValues.user_name && item.identity_card == element.dataValues.identity_card) {
|
||||
item.user_uid = element.dataValues.uid;
|
||||
}
|
||||
});
|
||||
delete item.user_name;
|
||||
delete item.identity_card;
|
||||
if (item.user_uid == 'none') {
|
||||
let errorForm = {
|
||||
user_name: item.user_name,
|
||||
identity_card: item.identity_card,
|
||||
exam_uid: item.exam_uid,
|
||||
type: 1,
|
||||
status: 0,
|
||||
created_at: new Date()
|
||||
};
|
||||
errorMark = true;
|
||||
await ctx.model.Importerror.create(errorForm);
|
||||
}
|
||||
});
|
||||
const result = await ctx.model.Grades.bulkCreate(form, { ignoreDuplicates: true });
|
||||
return result.length == 0 ? false : errorMark ? { code: 300, data: result } : { code: 200, data: result };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addGrades";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看用户考试结果
|
||||
async showGrades(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['user_uid', 'exam_uid', 'status', 'grades', 'pass_type'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = ['grades'],
|
||||
substring = ['user_uid', 'exam_uid'],
|
||||
key = ['status', 'pass_type'],
|
||||
between = [];
|
||||
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)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} 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', 'exam_start', 'exam_end'],
|
||||
examinationWhere = {},
|
||||
examinationOrder = [],
|
||||
examinationJoinSubstring = [],
|
||||
examinationSubstring = ['exam_name'],
|
||||
examinationKey = [],
|
||||
examinationBetween = ['exam_start', 'exam_end'];
|
||||
|
||||
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 examinee = ['user_name', 'identity_card', 'workplace', 'phone'],
|
||||
examineeWhere = {},
|
||||
examineeOrder = [],
|
||||
examineeJoinSubstring = [],
|
||||
examineeSubstring = ['user_name', 'identity_card', 'workplace', 'phone'],
|
||||
examineeKey = [],
|
||||
examineeBetween = [];
|
||||
|
||||
examinee.forEach(item => {
|
||||
if (searchOptions[item]) {
|
||||
if (searchOptions[item] == '*空') {
|
||||
if (examineeJoinSubstring.includes(item)) {
|
||||
examineeWhere[item] = null;
|
||||
} else {
|
||||
examineeWhere[item] = [null, ''];
|
||||
}
|
||||
} else if (examineeSubstring.includes(item)) {
|
||||
examineeWhere[item] = { [Op.substring]: searchOptions[item] };
|
||||
} else if (examineeKey.includes(item)) {
|
||||
examineeWhere[item] = searchOptions[item];
|
||||
} else if (examineeBetween.includes(item)) {
|
||||
examineeWhere[item] = { [Op.between]: [searchOptions[item][0], searchOptions[item][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[item] == true) {
|
||||
examineeOrder.push([item, 'ASC']);
|
||||
} else if (sortOptions[item] == false) {
|
||||
examineeOrder.push([item, 'DESC']);
|
||||
}
|
||||
});
|
||||
let include = [
|
||||
{
|
||||
model: ctx.model.Examinee,
|
||||
attributes: ['user_name', 'identity_card', 'workplace', 'phone'],
|
||||
where: examineeWhere,
|
||||
order: examineeOrder
|
||||
},
|
||||
{
|
||||
model: ctx.model.Examination,
|
||||
attributes: ['exam_name', 'exam_start', 'exam_end'],
|
||||
where: examinationWhere,
|
||||
order: examinationOrder
|
||||
}
|
||||
];
|
||||
ctx.model.Grades.belongsTo(ctx.model.Examinee, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
ctx.model.Grades.belongsTo(ctx.model.Examination, { foreignKey: 'exam_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, offset, limit, where, order, include };
|
||||
const result = await ctx.model.Grades.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showGrades";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑用户考试结果
|
||||
async editGrades(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 1) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user_uid, exam_uid, status, grades, pass_type } = requestMsg;
|
||||
where = { user_uid, exam_uid, status, grades, pass_type };
|
||||
} else if (modelType == "multiple") {
|
||||
let user_uid = [], exam_uid = [], status = [], pass_type = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user_uid.push(element.user_uid);
|
||||
exam_uid.push(element.exam_uid);
|
||||
status.push(element.status);
|
||||
pass_type.push(element.pass_type);
|
||||
});
|
||||
}
|
||||
where = { user_uid, exam_uid, status, pass_type };
|
||||
}
|
||||
const resultList = await ctx.model.Grades.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editGrades";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除考生考试成绩
|
||||
async deleteGrades(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.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 2) {
|
||||
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 < 2) systemMonitoring.status = 2;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user_uid, exam_uid, status, grades, pass_type } = requestMsg;
|
||||
where = { user_uid, exam_uid, status, grades, pass_type };
|
||||
} else if (modelType == "multiple") {
|
||||
let user_uid = [], exam_uid = [], status = [], grades = [], pass_type = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user_uid.push(element.user_uid);
|
||||
exam_uid.push(element.exam_uid);
|
||||
status.push(element.status);
|
||||
grades.push(element.grades);
|
||||
pass_type.push(element.pass_type);
|
||||
});
|
||||
}
|
||||
where = { user_uid, exam_uid, status, grades, pass_type };
|
||||
}
|
||||
const resultList = await ctx.model.Grades.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteGrades";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出考生考试结果数据
|
||||
async downloadGradesData(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['user_uid', 'exam_uid', 'status', 'grades', 'pass_type'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = ['grades'],
|
||||
substring = ['user_uid', 'exam_uid'],
|
||||
key = ['status', 'pass_type'],
|
||||
between = [];
|
||||
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)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} 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', 'exam_start', 'exam_end'],
|
||||
examinationWhere = {},
|
||||
examinationOrder = [],
|
||||
examinationJoinSubstring = [],
|
||||
examinationSubstring = ['exam_name'],
|
||||
examinationKey = [],
|
||||
examinationBetween = ['exam_start', 'exam_end'];
|
||||
|
||||
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 examinee = ['user_name', 'identity_card', 'workplace', 'phone'],
|
||||
examineeWhere = {},
|
||||
examineeOrder = [],
|
||||
examineeJoinSubstring = [],
|
||||
examineeSubstring = ['user_name', 'identity_card', 'workplace', 'phone'],
|
||||
examineeKey = [],
|
||||
examineeBetween = [];
|
||||
|
||||
examinee.forEach(item => {
|
||||
if (searchOptions[item]) {
|
||||
if (searchOptions[item] == '*空') {
|
||||
if (examineeJoinSubstring.includes(item)) {
|
||||
examineeWhere[item] = null;
|
||||
} else {
|
||||
examineeWhere[item] = [null, ''];
|
||||
}
|
||||
} else if (examineeSubstring.includes(item)) {
|
||||
examineeWhere[item] = { [Op.substring]: searchOptions[item] };
|
||||
} else if (examineeKey.includes(item)) {
|
||||
examineeWhere[item] = searchOptions[item];
|
||||
} else if (examineeBetween.includes(item)) {
|
||||
examineeWhere[item] = { [Op.between]: [searchOptions[item][0], searchOptions[item][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[item] == true) {
|
||||
examineeOrder.push([item, 'ASC']);
|
||||
} else if (sortOptions[item] == false) {
|
||||
examineeOrder.push([item, 'DESC']);
|
||||
}
|
||||
});
|
||||
let include = [
|
||||
{
|
||||
model: ctx.model.Examinee,
|
||||
attributes: ['user_name', 'identity_card', 'workplace', 'phone'],
|
||||
where: examineeWhere,
|
||||
order: examineeOrder
|
||||
},
|
||||
{
|
||||
model: ctx.model.Examination,
|
||||
attributes: ['exam_name', 'exam_start', 'exam_end'],
|
||||
where: examinationWhere,
|
||||
order: examinationOrder
|
||||
}
|
||||
];
|
||||
ctx.model.Grades.belongsTo(ctx.model.Examinee, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
ctx.model.Grades.belongsTo(ctx.model.Examination, { foreignKey: 'exam_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, where, order, include };
|
||||
const result = await ctx.model.Grades.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "旷考"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "正常参与"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "考试作弊"
|
||||
},
|
||||
];
|
||||
const passTypeOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "成绩不及格"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "成绩及格"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "无成绩"
|
||||
},
|
||||
];
|
||||
result.forEach(element => {
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
passTypeOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["pass_type"]) {
|
||||
element.dataValues["pass_type"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.user_name = element.dataValues.examinee.dataValues.user_name;
|
||||
element.dataValues.identity_card = element.dataValues.examinee.dataValues.identity_card;
|
||||
element.dataValues.exam_name = element.dataValues.examination.dataValues.exam_name;
|
||||
element.dataValues.exam_start = moment
|
||||
.utc(element.dataValues.examination.dataValues.exam_start)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.exam_end = moment
|
||||
.utc(element.dataValues.examination.dataValues.exam_end)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
delete element.dataValues.examinee;
|
||||
delete element.dataValues.examination;
|
||||
let elementClone = {
|
||||
user_uid: element.dataValues.user_uid,
|
||||
user_name: element.dataValues.user_name,
|
||||
identity_card: element.dataValues.identity_card,
|
||||
exam_uid: element.dataValues.exam_uid,
|
||||
exam_name: element.dataValues.exam_name,
|
||||
status: element.dataValues.status,
|
||||
grades: element.dataValues.grades,
|
||||
pass_type: element.dataValues.pass_type,
|
||||
exam_start: element.dataValues.exam_start,
|
||||
exam_end: element.dataValues.exam_end,
|
||||
}
|
||||
data.push(elementClone);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadGradesData";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GradesService;
|
||||
145
app/service/Importerror.js
Normal 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;
|
||||
225
app/service/Interlocution.js
Normal file
@@ -0,0 +1,225 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "Interlocution";
|
||||
|
||||
class InterlocutionService extends Service {
|
||||
// 管理系统新增问答题
|
||||
async addInterlocution(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model2.Interlocution.bulkCreate(form, { ignoreDuplicates: true });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addInterlocution";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看问答题
|
||||
async showInterlocution(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['stem', 'answer', 'difficulty'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['stem', 'answer'],
|
||||
key = ['difficulty'],
|
||||
between = [];
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model2.Interlocution.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showInterlocution";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑问答题
|
||||
async editInterlocution(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 1) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { stem, answer, difficulty } = requestMsg;
|
||||
where = { stem, answer, difficulty };
|
||||
} else if (modelType == "multiple") {
|
||||
let stem = [], answer = [], difficulty = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
stem.push(element.stem);
|
||||
answer.push(element.answer);
|
||||
difficulty.push(element.difficulty);
|
||||
});
|
||||
}
|
||||
where = { stem, answer, difficulty };
|
||||
}
|
||||
const resultList = await ctx.model2.Interlocution.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editInterlocution";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除问答题
|
||||
async deleteInterlocution(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.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 2) {
|
||||
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 < 2) systemMonitoring.status = 2;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { stem, answer, difficulty } = requestMsg;
|
||||
where = { stem, answer, difficulty };
|
||||
} else if (modelType == "multiple") {
|
||||
let stem = [], answer = [], difficulty = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
stem.push(element.stem);
|
||||
answer.push(element.answer);
|
||||
difficulty.push(element.difficulty);
|
||||
});
|
||||
}
|
||||
where = { stem, answer, difficulty };
|
||||
}
|
||||
const resultList = await ctx.model2.Interlocution.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteInterlocution";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出问答题数据
|
||||
async downloadInterlocutionData(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return { code: false };
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['stem', 'answer', 'difficulty'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['stem', 'answer', 'difficulty'],
|
||||
key = [],
|
||||
between = [];
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model2.Interlocution.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const difficultyOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "简单"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "普通"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "困难"
|
||||
},
|
||||
];
|
||||
result.forEach(element => {
|
||||
difficultyOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["difficulty"]) {
|
||||
element.dataValues["difficulty"] = item.label;
|
||||
}
|
||||
});
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadInterlocutionData";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InterlocutionService;
|
||||
240
app/service/Judgment.js
Normal file
@@ -0,0 +1,240 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "Judgment";
|
||||
|
||||
class JudgmentService extends Service {
|
||||
// 管理系统新增判断题
|
||||
async addJudgment(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model2.Judgment.bulkCreate(form, { ignoreDuplicates: true });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addJudgment";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看判断题
|
||||
async showJudgment(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['stem', 'answer', 'difficulty'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['stem'],
|
||||
key = ['answer', 'difficulty'],
|
||||
between = [];
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model2.Judgment.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showJudgment";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑判断题
|
||||
async editJudgment(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 1) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { stem, answer, difficulty } = requestMsg;
|
||||
where = { stem, answer, difficulty };
|
||||
} else if (modelType == "multiple") {
|
||||
let stem = [], answer = [], difficulty = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
stem.push(element.stem);
|
||||
answer.push(element.answer);
|
||||
difficulty.push(element.difficulty);
|
||||
});
|
||||
}
|
||||
where = { stem, answer, difficulty };
|
||||
}
|
||||
const resultList = await ctx.model2.Judgment.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editJudgment";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除判断题
|
||||
async deleteJudgment(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.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 2) {
|
||||
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 < 2) systemMonitoring.status = 2;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { stem, answer, difficulty } = requestMsg;
|
||||
where = { stem, answer, difficulty };
|
||||
} else if (modelType == "multiple") {
|
||||
let stem = [], answer = [], difficulty = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
stem.push(element.stem);
|
||||
answer.push(element.answer);
|
||||
difficulty.push(element.difficulty);
|
||||
});
|
||||
}
|
||||
where = { stem, answer, difficulty };
|
||||
}
|
||||
const resultList = await ctx.model2.Judgment.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteJudgment";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出判断题数据
|
||||
async downloadJudgmentData(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return { code: false };
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['stem', 'answer', 'difficulty'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['stem', 'answer', 'difficulty'],
|
||||
key = [],
|
||||
between = [];
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model2.Judgment.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const answerOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "错误"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "正确"
|
||||
},
|
||||
];
|
||||
const difficultyOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "简单"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "普通"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "困难"
|
||||
},
|
||||
];
|
||||
result.forEach(element => {
|
||||
answerOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["answer"]) {
|
||||
element.dataValues["answer"] = item.label;
|
||||
}
|
||||
});
|
||||
difficultyOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["difficulty"]) {
|
||||
element.dataValues["difficulty"] = item.label;
|
||||
}
|
||||
});
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadJudgmentData";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JudgmentService;
|
||||
136
app/service/Monitoring.js
Normal file
@@ -0,0 +1,136 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Monitoring";
|
||||
|
||||
class MonitoringService extends Service {
|
||||
// 查看危险操作记录
|
||||
async showMonitoring(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['operate', 'operate_msg', 'type', 'status', 'affect_entries', 'user', 'created_at'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['operate_msg', 'user'],
|
||||
key = ['type', 'status', 'operate'],
|
||||
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']);
|
||||
}
|
||||
});
|
||||
const manager = await ctx.model.Manager.findAll({ attributes: ['uid', 'account_name', 'role'] });
|
||||
if (searchOptions.account_name) {
|
||||
if (searchOptions.account_name == '*空') {
|
||||
where.user = [null, ''];
|
||||
} else {
|
||||
let uidArr = [];
|
||||
manager.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
uidArr.push(item.dataValues.uid);
|
||||
}
|
||||
});
|
||||
where.user = [...uidArr];
|
||||
}
|
||||
}
|
||||
if (searchOptions.role) {
|
||||
let uidArr = [];
|
||||
manager.filter(item => {
|
||||
if (item.dataValues.role == searchOptions.role) {
|
||||
uidArr.push(item.dataValues.uid);
|
||||
}
|
||||
});
|
||||
where.user = [...uidArr];
|
||||
}
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model.Monitoring.findAndCountAll(dbOptions);
|
||||
result.rows.forEach(element => {
|
||||
element.dataValues.account_name = '';
|
||||
element.dataValues.role = '';
|
||||
manager.filter(item => {
|
||||
if (item.dataValues.uid == element.dataValues.user) {
|
||||
element.dataValues.account_name = item.dataValues.account_name;
|
||||
element.dataValues.role = item.dataValues.role;
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showMonitoring";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除危险操作记录
|
||||
async deleteMonitoring(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
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) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemMonitoring.status = 1;
|
||||
else if (result.dataValues.role < 2) systemMonitoring.status = 2;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user, created_at } = requestMsg;
|
||||
where = { user, created_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let user = [], created_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user.push(element.user),
|
||||
created_at.push(element.created_at)
|
||||
});
|
||||
}
|
||||
where = { user, created_at };
|
||||
}
|
||||
const resultList = await ctx.model.Monitoring.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteMonitoring";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MonitoringService;
|
||||
235
app/service/Multiple.js
Normal file
@@ -0,0 +1,235 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "Multiple";
|
||||
|
||||
class MultipleService extends Service {
|
||||
// 管理系统新增多选题
|
||||
async addMultiple(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model2.Multiple.bulkCreate(form, { ignoreDuplicates: true });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addMultiple";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看多选题
|
||||
async showMultiple(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['stem', 'options_a', 'options_b', 'options_c', 'options_d', 'options_e', 'answer', 'difficulty'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['stem', 'options_a', 'options_b', 'options_c', 'options_d', 'options_e', 'answer'],
|
||||
key = ['difficulty'],
|
||||
between = [];
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model2.Multiple.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showMultiple";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑多选题
|
||||
async editMultiple(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 1) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { stem, options_a, options_b, options_c, options_d, options_e, answer, difficulty } = requestMsg;
|
||||
where = { stem, options_a, options_b, options_c, options_d, options_e, answer, difficulty };
|
||||
} else if (modelType == "multiple") {
|
||||
let stem = [], options_a = [], options_b = [], options_c = [], options_d = [], options_e = [], answer = [], difficulty = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
stem.push(element.stem);
|
||||
options_a.push(element.options_a);
|
||||
options_b.push(element.options_b);
|
||||
options_c.push(element.options_c);
|
||||
options_d.push(element.options_d);
|
||||
options_e.push(element.options_e);
|
||||
answer.push(element.answer);
|
||||
difficulty.push(element.difficulty);
|
||||
});
|
||||
}
|
||||
where = { stem, options_a, options_b, options_c, options_d, options_e, answer, difficulty };
|
||||
}
|
||||
const resultList = await ctx.model2.Multiple.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editMultiple";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除多选题
|
||||
async deleteMultiple(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.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 2) {
|
||||
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 < 2) systemMonitoring.status = 2;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { stem, options_a, options_b, options_c, options_d, options_e, answer, difficulty } = requestMsg;
|
||||
where = { stem, options_a, options_b, options_c, options_d, options_e, answer, difficulty };
|
||||
} else if (modelType == "multiple") {
|
||||
let stem = [], options_a = [], options_b = [], options_c = [], options_d = [], options_e = [], answer = [], difficulty = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
stem.push(element.stem);
|
||||
options_a.push(element.options_a);
|
||||
options_b.push(element.options_b);
|
||||
options_c.push(element.options_c);
|
||||
options_d.push(element.options_d);
|
||||
options_e.push(element.options_e);
|
||||
answer.push(element.answer);
|
||||
difficulty.push(element.difficulty);
|
||||
});
|
||||
}
|
||||
where = { stem, options_a, options_b, options_c, options_d, options_e, answer, difficulty };
|
||||
}
|
||||
const resultList = await ctx.model2.Multiple.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteMultiple";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出多选题数据
|
||||
async downloadMultipleData(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return { code: false };
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['stem', 'options_a', 'options_b', 'options_c', 'options_d', 'options_e', 'answer', 'difficulty'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['stem', 'options_a', 'options_b', 'options_c', 'options_d', 'options_e', 'answer', 'difficulty'],
|
||||
key = [],
|
||||
between = [];
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model2.Multiple.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const difficultyOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "简单"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "普通"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "困难"
|
||||
},
|
||||
];
|
||||
result.forEach(element => {
|
||||
difficultyOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["difficulty"]) {
|
||||
element.dataValues["difficulty"] = item.label;
|
||||
}
|
||||
});
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadMultipleData";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MultipleService;
|
||||
233
app/service/Radio.js
Normal file
@@ -0,0 +1,233 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "Radio";
|
||||
|
||||
class RadioService extends Service {
|
||||
// 管理系统新增单选题
|
||||
async addRadio(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model2.Radio.bulkCreate(form, { ignoreDuplicates: true });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addRadio";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看单选题
|
||||
async showRadio(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['stem', 'options_a', 'options_b', 'options_c', 'options_d', 'answer', 'difficulty'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['stem', 'options_a', 'options_b', 'options_c', 'options_d', 'answer'],
|
||||
key = ['difficulty'],
|
||||
between = [];
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model2.Radio.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showRadio";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑单选题
|
||||
async editRadio(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 1) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { stem, options_a, options_b, options_c, options_d, answer, difficulty } = requestMsg;
|
||||
where = { stem, options_a, options_b, options_c, options_d, answer, difficulty };
|
||||
} else if (modelType == "multiple") {
|
||||
let stem = [], options_a = [], options_b = [], options_c = [], options_d = [], answer = [], difficulty = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
stem.push(element.stem);
|
||||
options_a.push(element.options_a);
|
||||
options_b.push(element.options_b);
|
||||
options_c.push(element.options_c);
|
||||
options_d.push(element.options_d);
|
||||
answer.push(element.answer);
|
||||
difficulty.push(element.difficulty);
|
||||
});
|
||||
}
|
||||
where = { stem, options_a, options_b, options_c, options_d, answer, difficulty };
|
||||
}
|
||||
const resultList = await ctx.model2.Radio.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editRadio";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除单选题
|
||||
async deleteRadio(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.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 2) {
|
||||
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 < 2) systemMonitoring.status = 2;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { stem, options_a, options_b, options_c, options_d, answer, difficulty } = requestMsg;
|
||||
where = { stem, options_a, options_b, options_c, options_d, answer, difficulty };
|
||||
} else if (modelType == "multiple") {
|
||||
let stem = [], options_a = [], options_b = [], options_c = [], options_d = [], answer = [], difficulty = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
stem.push(element.stem);
|
||||
options_a.push(element.options_a);
|
||||
options_b.push(element.options_b);
|
||||
options_c.push(element.options_c);
|
||||
options_d.push(element.options_d);
|
||||
answer.push(element.answer);
|
||||
difficulty.push(element.difficulty);
|
||||
});
|
||||
}
|
||||
where = { stem, options_a, options_b, options_c, options_d, answer, difficulty };
|
||||
}
|
||||
const resultList = await ctx.model2.Radio.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteRadio";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出单选题数据
|
||||
async downloadRadioData(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return { code: false };
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['stem', 'options_a', 'options_b', 'options_c', 'options_d', 'answer', 'difficulty'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['stem', 'options_a', 'options_b', 'options_c', 'options_d', 'answer', 'difficulty'],
|
||||
key = [],
|
||||
between = [];
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model2.Radio.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const difficultyOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "简单"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "普通"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "困难"
|
||||
},
|
||||
];
|
||||
result.forEach(element => {
|
||||
difficultyOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["difficulty"]) {
|
||||
element.dataValues["difficulty"] = item.label;
|
||||
}
|
||||
});
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadRadioData";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RadioService;
|
||||
131
app/service/Search.js
Normal file
@@ -0,0 +1,131 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const fileName = "Search";
|
||||
|
||||
class SearchService extends Service {
|
||||
// 管理系统检索考生姓名
|
||||
async searchUserName(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Examinee.findAll({ where: { user_name: { [Op.substring]: body.user_name } } });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchUserName";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索考生身份证号
|
||||
async searchIdentityCard(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Examinee.findAll({ where: { identity_card: { [Op.substring]: body.identity_card } } });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchIdentityCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索考生 uid
|
||||
async searchUserUid(identity_card, user_name) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['uid'],
|
||||
where = { identity_card, user_name },
|
||||
dbOptions = { attributes, where };
|
||||
const result = await ctx.model.Examinee.findOne(dbOptions);
|
||||
return result || false;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchUserUid";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索考试 uid
|
||||
async searchExamUid(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Examination.findAll({ where: { uid: { [Op.substring]: body.exam_uid } } });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchExamUid";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索工作单位
|
||||
async searchWorkplace(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Examinee.findAll({ where: { workplace: { [Op.substring]: body.workplace } } });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchWorkplace";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统检索报名结果说明
|
||||
async searchResult(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Application.findAll({ where: { result: { [Op.substring]: body.result } } });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchResult";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 用户照片是否存在判断
|
||||
async checkPhoto(idCardArr) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['uid', 'identity_card'],
|
||||
where = { identity_card: idCardArr },
|
||||
dbOptions = { attributes, where };
|
||||
const result = await ctx.model.Examinee.findAll(dbOptions);
|
||||
if (result.length == 0) return false;
|
||||
let photoUrlArr = [];
|
||||
result.forEach(element => {
|
||||
const filePath = path.join(__dirname.replace(/\bbd-training-exam-manager\b/g, "bd-training-exam"), `../public/userPhoto/${element.dataValues.identity_card}.jpg`);
|
||||
// const filePath = `/disk/a/userPhoto/${element.dataValues.identity_card}.jpg`;
|
||||
const fileExists = fs.existsSync(filePath);
|
||||
if (fileExists) {
|
||||
// 文件存在
|
||||
// 本机服务器地址
|
||||
// 'http://127.0.0.1:8019'
|
||||
// 'http://192.168.31.28:8019'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8019'
|
||||
// 'http://certlogin.hwasmart.com//bdTrainingExam'
|
||||
photoUrlArr.push({ identity_card: element.dataValues.identity_card, photoUrl: 'http://127.0.0.1:8019' + `/public/userPhoto/${element.dataValues.identity_card}.jpg?time=${new Date().getTime()}` });
|
||||
} else {
|
||||
// 文件不存在
|
||||
photoUrlArr.push({ identity_card: element.dataValues.identity_card, photoUrl: '#' });
|
||||
}
|
||||
});
|
||||
return photoUrlArr;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "checkPhoto";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SearchService;
|
||||
334
app/service/TopicWhitelist.js
Normal file
@@ -0,0 +1,334 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "TopicWhitelist";
|
||||
|
||||
class TopicWhitelistService extends Service {
|
||||
// 管理系统新增题库白名单
|
||||
async addTopicWhitelist(userMsgObj, form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['uid', 'phone'],
|
||||
where = userMsgObj,
|
||||
dbOptions = { attributes, where };
|
||||
const userUid = await ctx.model.Examinee.findAll(dbOptions);
|
||||
form.forEach(async item => {
|
||||
item.user_uid = 'none';
|
||||
userUid.forEach(element => {
|
||||
if (item.phone == element.dataValues.phone) {
|
||||
item.user_uid = element.dataValues.uid;
|
||||
}
|
||||
});
|
||||
delete item.phone;
|
||||
});
|
||||
const result = await ctx.model.Whitelist.bulkCreate(form, { ignoreDuplicates: true });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addTopicWhitelist";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看题库白名单
|
||||
async showTopicWhitelist(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['user_uid', 'type', 'expired_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['user_uid', 'user_name', 'identity_card'],
|
||||
key = ['type'],
|
||||
between = ['expired_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 examinee = ['user_name', 'identity_card'],
|
||||
examineeWhere = {},
|
||||
examineeOrder = [],
|
||||
examineeJoinSubstring = [],
|
||||
examineeSubstring = ['user_name', 'identity_card'],
|
||||
examineeKey = [],
|
||||
examineeBetween = [];
|
||||
|
||||
examinee.forEach(item => {
|
||||
if (searchOptions[item]) {
|
||||
if (searchOptions[item] == '*空') {
|
||||
if (examineeJoinSubstring.includes(item)) {
|
||||
examineeWhere[item] = null;
|
||||
} else {
|
||||
examineeWhere[item] = [null, ''];
|
||||
}
|
||||
} else if (examineeSubstring.includes(item)) {
|
||||
examineeWhere[item] = { [Op.substring]: searchOptions[item] };
|
||||
} else if (examineeKey.includes(item)) {
|
||||
examineeWhere[item] = searchOptions[item];
|
||||
} else if (examineeBetween.includes(item)) {
|
||||
examineeWhere[item] = { [Op.between]: [searchOptions[item][0], searchOptions[item][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[item] == true) {
|
||||
examineeOrder.push([item, 'ASC']);
|
||||
} else if (sortOptions[item] == false) {
|
||||
examineeOrder.push([item, 'DESC']);
|
||||
}
|
||||
});
|
||||
let include = [
|
||||
{
|
||||
model: ctx.model.Examinee,
|
||||
attributes: ['user_name', 'identity_card'],
|
||||
where: examineeWhere,
|
||||
order: examineeOrder
|
||||
}
|
||||
];
|
||||
ctx.model.Whitelist.belongsTo(ctx.model.Examinee, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, offset, limit, where, order, include };
|
||||
const result = await ctx.model.Whitelist.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showTopicWhitelist";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑题库白名单
|
||||
async editTopicWhitelist(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 1) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user_uid, type, expired_at } = requestMsg;
|
||||
where = { user_uid, type, expired_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let user_uid = [], type = [], expired_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user_uid.push(element.user_uid);
|
||||
type.push(element.type);
|
||||
expired_at.push(element.expired_at);
|
||||
});
|
||||
}
|
||||
where = { user_uid, type, expired_at };
|
||||
}
|
||||
updateMsg.type = Number(updateMsg.type);
|
||||
if (updateMsg.expired_at) {
|
||||
updateMsg.expired_at = new Date(updateMsg.expired_at);
|
||||
} else {
|
||||
updateMsg.expired_at = null;
|
||||
}
|
||||
const resultList = await ctx.model.Whitelist.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editTopicWhitelist";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除题库白名单
|
||||
async deleteTopicWhitelist(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.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 2) {
|
||||
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 < 2) systemMonitoring.status = 2;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { type, expired_at } = requestMsg;
|
||||
where = { type, expired_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let type = [], expired_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
type.push(element.type);
|
||||
expired_at.push(element.expired_at);
|
||||
});
|
||||
}
|
||||
where = { type, expired_at };
|
||||
}
|
||||
const resultList = await ctx.model.Whitelist.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteTopicWhitelist";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出题库白名单
|
||||
async downloadTopicWhitelistData(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['user_uid', 'type', 'expired_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['user_uid'],
|
||||
key = ['type'],
|
||||
between = ['expired_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 examinee = ['user_name', 'identity_card'],
|
||||
examineeWhere = {},
|
||||
examineeOrder = [],
|
||||
examineeJoinSubstring = [],
|
||||
examineeSubstring = ['user_name', 'identity_card'],
|
||||
examineeKey = [],
|
||||
examineeBetween = [];
|
||||
|
||||
examinee.forEach(item => {
|
||||
if (searchOptions[item]) {
|
||||
if (searchOptions[item] == '*空') {
|
||||
if (examineeJoinSubstring.includes(item)) {
|
||||
examineeWhere[item] = null;
|
||||
} else {
|
||||
examineeWhere[item] = [null, ''];
|
||||
}
|
||||
} else if (examineeSubstring.includes(item)) {
|
||||
examineeWhere[item] = { [Op.substring]: searchOptions[item] };
|
||||
} else if (examineeKey.includes(item)) {
|
||||
examineeWhere[item] = searchOptions[item];
|
||||
} else if (examineeBetween.includes(item)) {
|
||||
examineeWhere[item] = { [Op.between]: [searchOptions[item][0], searchOptions[item][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[item] == true) {
|
||||
examineeOrder.push([item, 'ASC']);
|
||||
} else if (sortOptions[item] == false) {
|
||||
examineeOrder.push([item, 'DESC']);
|
||||
}
|
||||
});
|
||||
|
||||
let include = [
|
||||
{
|
||||
model: ctx.model.Examinee,
|
||||
attributes: ['user_name', 'identity_card'],
|
||||
where: examineeWhere,
|
||||
order: examineeOrder
|
||||
}
|
||||
];
|
||||
ctx.model.Whitelist.belongsTo(ctx.model.Examinee, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, where, order, include };
|
||||
const result = await ctx.model.Whitelist.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const typeOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "永久白名单"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "临时白名单"
|
||||
},
|
||||
];
|
||||
result.forEach(element => {
|
||||
typeOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["type"]) {
|
||||
element.dataValues["type"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.user_name = element.dataValues.examinee.dataValues.user_name;
|
||||
element.dataValues.identity_card = element.dataValues.examinee.dataValues.identity_card;
|
||||
element.dataValues.expired_at = moment
|
||||
.utc(element.dataValues.examination.dataValues.expired_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
delete element.dataValues.examinee;
|
||||
let elementClone = {
|
||||
user_uid: element.dataValues.user_uid,
|
||||
user_name: element.dataValues.user_name,
|
||||
identity_card: element.dataValues.identity_card,
|
||||
type: element.dataValues.type,
|
||||
expired_at: element.dataValues.expired_at,
|
||||
}
|
||||
data.push(elementClone);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadTopicWhitelistData";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TopicWhitelistService;
|
||||
272
app/service/User.js
Normal file
@@ -0,0 +1,272 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "User";
|
||||
|
||||
class UserService extends Service {
|
||||
// 管理系统新增用户账号信息
|
||||
async addUser(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Examinee.bulkCreate(form, { ignoreDuplicates: true });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addUser";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看用户账号信息
|
||||
async showUser(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['uid', 'user_name', 'identity_card', 'real_check', 'workplace', 'address', 'phone', 'email', 'referrers', 'status', 'created_at', 'updated_at', 'login_status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'user_name', 'identity_card', 'workplace', 'address', 'phone', 'email', 'referrers'],
|
||||
key = ['real_check', 'status', 'login_status'],
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model.Examinee.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showUser";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑用户账号信息
|
||||
async editUser(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 1) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { uid, user_name, identity_card, real_check, workplace, address, phone, email, status } = requestMsg;
|
||||
where = { uid, user_name, identity_card, real_check, workplace, address, phone, email, status };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], user_name = [], identity_card = [], real_check = [], workplace = [], address = [], phone = [], email = [], status = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid);
|
||||
user_name.push(element.user_name);
|
||||
identity_card.push(element.identity_card);
|
||||
real_check.push(element.real_check);
|
||||
workplace.push(element.workplace);
|
||||
address.push(element.address);
|
||||
phone.push(element.phone);
|
||||
email.push(element.email);
|
||||
status.push(element.status);
|
||||
});
|
||||
}
|
||||
where = { uid, user_name, identity_card, real_check, workplace, address, phone, email, status };
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
const resultList = await ctx.model.Examinee.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editUser";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除用户账号信息
|
||||
async deleteUser(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.model.Manager.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 2) {
|
||||
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 < 2) systemMonitoring.status = 2;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { uid, user_name, identity_card, real_check, workplace, address, phone, email, status } = requestMsg;
|
||||
where = { uid, user_name, identity_card, real_check, workplace, address, phone, email, status };
|
||||
await ctx.model.Audit.destroy({ where : { user_uid: uid } });
|
||||
await ctx.model.Application.destroy({ where : { user_uid: uid } });
|
||||
await ctx.model.Grades.destroy({ where: { user_uid: uid } });
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], user_name = [], identity_card = [], real_check = [], workplace = [], address = [], phone = [], email = [], status = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid);
|
||||
user_name.push(element.user_name);
|
||||
identity_card.push(element.identity_card);
|
||||
real_check.push(element.real_check);
|
||||
workplace.push(element.workplace);
|
||||
address.push(element.address);
|
||||
phone.push(element.phone);
|
||||
email.push(element.email);
|
||||
status.push(element.status);
|
||||
});
|
||||
}
|
||||
where = { uid, user_name, identity_card, real_check, workplace, address, phone, email, status };
|
||||
await ctx.model.Audit.destroy({ where : { user_uid: uid } });
|
||||
await ctx.model.Application.destroy({ where : { user_uid: uid } });
|
||||
await ctx.model.Grades.destroy({ where: { user_uid: uid } });
|
||||
}
|
||||
const resultList = await ctx.model.Examinee.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteUser";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出用户账号信息数据
|
||||
async downloadUserData(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model.Manager.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 1) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['uid', 'user_name', 'identity_card', 'real_check', 'workplace', 'address', 'phone', 'email', 'status', 'created_at', 'updated_at', 'login_status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'user_name', 'identity_card', 'workplace', 'address', 'phone', 'email'],
|
||||
key = ['real_check', 'status', 'login_status'],
|
||||
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']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model.Examinee.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const realCheckOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "未核验"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "核验通过"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "核验失败"
|
||||
},
|
||||
];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "默认状态"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "正常使用"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "已被封禁"
|
||||
},
|
||||
];
|
||||
result.forEach(element => {
|
||||
realCheckOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["real_check"]) {
|
||||
element.dataValues["real_check"] = item.label;
|
||||
}
|
||||
});
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
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.login_status;
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadUserData";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserService;
|
||||