北斗应用技术培训考试管理系统
This commit is contained in:
195
app/controller/Admin.js
Normal file
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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;
|
||||
Reference in New Issue
Block a user