223 lines
9.6 KiB
JavaScript
223 lines
9.6 KiB
JavaScript
|
|
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;
|