新增功能
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "BSide";
|
||||
|
||||
class BSideController extends Controller {
|
||||
@@ -144,6 +146,58 @@ class BSideController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出B端用户
|
||||
async downloadBside() {
|
||||
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.bSide.downloadBside(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadBside";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BSideController;
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "BdCard";
|
||||
|
||||
class BdCardController extends Controller {
|
||||
@@ -58,11 +60,11 @@ class BdCardController extends Controller {
|
||||
if (result) {
|
||||
let bdCardMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
bdCardMsg.push(element.dataValues);
|
||||
bdCardMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
bdCardMsg: bdCardMsg,
|
||||
count: result.count
|
||||
bdCardMsg: bdCardMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索北斗卡成功', "deconstruction", data);
|
||||
} else {
|
||||
@@ -136,6 +138,58 @@ class BdCardController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出北斗卡
|
||||
async downloadBDCard() {
|
||||
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.bdCard.downloadBDCard(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadBDCard";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BdCardController;
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "BindRecord";
|
||||
|
||||
class BindRecordController extends Controller {
|
||||
@@ -70,6 +72,58 @@ class BindRecordController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出北斗卡绑定记录绑定记录
|
||||
async downloadBindRecord() {
|
||||
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.bindRecord.downloadBindRecord(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadBindRecord";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BindRecordController;
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "BindSNRecord";
|
||||
|
||||
class BindSNRecordController extends Controller {
|
||||
@@ -70,6 +72,58 @@ class BindSNRecordController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出SN号绑定记录
|
||||
async downloadBindSNRecord() {
|
||||
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.bindSNRecord.downloadBindSNRecord(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadBindSNRecord";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BindSNRecordController;
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "Business";
|
||||
|
||||
class BusinessController extends Controller {
|
||||
@@ -84,40 +86,40 @@ class BusinessController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// 远程搜索公司业务
|
||||
async SearchBusiness() {
|
||||
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.business.SearchBusiness(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let business = [];
|
||||
result.forEach(element => {
|
||||
business.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
business: business,
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索公司业务信息成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索公司业务信息失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
// 远程搜索公司业务
|
||||
async SearchBusiness() {
|
||||
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.business.SearchBusiness(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let business = [];
|
||||
result.forEach(element => {
|
||||
business.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
business: business,
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索公司业务信息成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索公司业务信息失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑公司业务
|
||||
async editBusiness() {
|
||||
@@ -202,6 +204,58 @@ class BusinessController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出公司业务
|
||||
async downloadBusiness() {
|
||||
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.business.downloadBusiness(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadBusiness";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BusinessController;
|
||||
@@ -2,105 +2,159 @@
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "CSide";
|
||||
|
||||
class CSideController extends Controller {
|
||||
// 查看C端用户
|
||||
async showCSide() {
|
||||
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.cSide.showCSide(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let CSideMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
CSideMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
CSideMsg: CSideMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索C端用户成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索C端用户失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showCSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
// 查看C端用户
|
||||
async showCSide() {
|
||||
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.cSide.showCSide(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let CSideMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
CSideMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
CSideMsg: CSideMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索C端用户成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索C端用户失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showCSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑C端用户
|
||||
async editCSide() {
|
||||
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, updateMsg, requestMsg } = body
|
||||
const modelType = this.decryptRequest(model);
|
||||
const result = await ctx.service.cSide.editCSide(uid, modelType, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '编辑C端用户信息成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '编辑C端用户信息失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editCSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
// 编辑C端用户
|
||||
async editCSide() {
|
||||
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, updateMsg, requestMsg } = body
|
||||
const modelType = this.decryptRequest(model);
|
||||
const result = await ctx.service.cSide.editCSide(uid, modelType, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '编辑C端用户信息成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '编辑C端用户信息失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editCSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除C端用户
|
||||
async deleteCSide() {
|
||||
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.cSide.deleteCSide(uid, modelType, deCodePassword, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '删除C端用户成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '删除C端用户失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "deleteCSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
// 删除C端用户
|
||||
async deleteCSide() {
|
||||
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.cSide.deleteCSide(uid, modelType, deCodePassword, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '删除C端用户成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '删除C端用户失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "deleteCSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出C端用户
|
||||
async downloadCside() {
|
||||
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.cSide.downloadCside(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadCside";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CSideController;
|
||||
@@ -1,5 +1,7 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "ContestAccount";
|
||||
|
||||
class ContestAccountController extends Controller {
|
||||
@@ -204,6 +206,58 @@ class ContestAccountController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出竞赛账号信息
|
||||
async downloadAccount() {
|
||||
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.contestAccount.downloadAccount(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestAccountController;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "ContestExamination";
|
||||
|
||||
class ContestExaminationController extends Controller {
|
||||
@@ -109,14 +111,38 @@ class ContestExaminationController extends Controller {
|
||||
return;
|
||||
}
|
||||
const uid = JSON.parse(rdmcode).uid;
|
||||
const body = ctx.request.body;
|
||||
const result = await ctx.service.contestExamination.downloadExamination(uid, body);
|
||||
const { form, searchMsg, dataHeaders } = ctx.request.body;
|
||||
const result = await ctx.service.contestExamination.downloadExamination(uid, searchMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "ContestMsg";
|
||||
|
||||
class ContestMsgController extends Controller {
|
||||
@@ -95,11 +97,11 @@ class ContestMsgController extends Controller {
|
||||
if (result) {
|
||||
let contestMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
contestMsg.push(element.dataValues);
|
||||
contestMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
contestMsg,
|
||||
count: result.count
|
||||
contestMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
@@ -148,8 +150,8 @@ class ContestMsgController extends Controller {
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const uid = JSON.parse(rdmcode).uid;
|
||||
const body = ctx.request.body;
|
||||
@@ -158,13 +160,13 @@ class ContestMsgController extends Controller {
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.contestMsg.delContest(uid, modelType, deCodePassword, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "delContest";
|
||||
@@ -172,6 +174,58 @@ class ContestMsgController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出竞赛信息
|
||||
async downloadContest() {
|
||||
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.contestMsg.downloadContest(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadContest";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestMsgController;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "ContestTopic";
|
||||
|
||||
class ContestTopicController extends Controller {
|
||||
@@ -91,11 +93,11 @@ class ContestTopicController extends Controller {
|
||||
if (result) {
|
||||
let choiceTopicMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
choiceTopicMsg.push(element.dataValues);
|
||||
choiceTopicMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
choiceTopicMsg,
|
||||
count: result.count
|
||||
choiceTopicMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
@@ -168,6 +170,58 @@ class ContestTopicController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出选择题
|
||||
async downloadChoiceTopic() {
|
||||
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.contestTopic.downloadChoiceTopic(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadChoiceTopic";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestTopicController;
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "Insiders";
|
||||
|
||||
class InsidersController extends Controller {
|
||||
@@ -144,6 +146,58 @@ class InsidersController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出系统用户
|
||||
async downloadInsiders() {
|
||||
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.insiders.downloadInsiders(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadInsiders";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InsidersController;
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "Monitoring";
|
||||
|
||||
class MonitoringController extends Controller {
|
||||
@@ -70,6 +72,58 @@ class MonitoringController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出监控记录
|
||||
async downloadMonitoring() {
|
||||
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.monitoring.downloadMonitoring(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadMonitoring";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MonitoringController;
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "Organization";
|
||||
|
||||
class OrganizationController extends Controller {
|
||||
@@ -175,6 +177,58 @@ class OrganizationController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出B端用户单位
|
||||
async downloadOrganization() {
|
||||
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.organization.downloadOrganization(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadOrganization";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OrganizationController;
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "SNAdmin";
|
||||
|
||||
class SNAdminController extends Controller {
|
||||
@@ -43,7 +45,8 @@ class SNAdminController extends Controller {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const result = await ctx.service.sNAdmin.searchAllocationUser();
|
||||
const body = ctx.request.body;
|
||||
const result = await ctx.service.sNAdmin.searchAllocationUser(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
@@ -156,6 +159,58 @@ class SNAdminController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出B端SN号分配记录
|
||||
async downloadAllocationSNRecord() {
|
||||
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.sNAdmin.downloadAllocationSNRecord(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadAllocationSNRecord";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SNAdminController;
|
||||
98
app/controller/SNContest.js
Normal file
98
app/controller/SNContest.js
Normal file
@@ -0,0 +1,98 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "SNContest";
|
||||
|
||||
class SNContestController extends Controller {
|
||||
// 获取SN号竞赛消息
|
||||
async getSNContestMsg() {
|
||||
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.sNContest.getSNContestMsg(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let snContestMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
snContestMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
snContestMsg: snContestMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '获取SN号竞赛消息成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '获取SN号竞赛消息失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "getSNContestMsg";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出SN号竞赛消息
|
||||
async downloadSNConest() {
|
||||
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.sNContest.downloadSNConest(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadSNConest";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SNContestController;
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "SN";
|
||||
|
||||
class SNController extends Controller {
|
||||
@@ -134,6 +136,58 @@ class SNController extends Controller {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出SN号
|
||||
async downloadSN() {
|
||||
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.sn.downloadSN(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadSN";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SNController;
|
||||
129
app/controller/UnknownBDCard.js
Normal file
129
app/controller/UnknownBDCard.js
Normal file
@@ -0,0 +1,129 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "UnknownBDCard";
|
||||
|
||||
class UnknownBDCardController extends Controller {
|
||||
// 查看未知消息
|
||||
async showUnknownBDCard() {
|
||||
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.unknownBDCard.showUnknownBDCard(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let unknownBDCardRecord = [];
|
||||
result.rows.forEach(element => {
|
||||
unknownBDCardRecord.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
unknownBDCardRecord,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索未知消息成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索未知消息失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showUnknownBDCard";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除未知消息
|
||||
async deleteUnknownBDCard() {
|
||||
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.unknownBDCard.deleteUnknownBDCard(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 + "--" + "deleteUnknownBDCard";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出竞赛账号信息
|
||||
async downloadUnknownBDCard() {
|
||||
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.unknownBDCard.downloadUnknownBDCard(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadUnknownBDCard";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UnknownBDCardController;
|
||||
129
app/controller/UnknownSN.js
Normal file
129
app/controller/UnknownSN.js
Normal file
@@ -0,0 +1,129 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const fileName = "UnknownSN";
|
||||
|
||||
class UnknownSNController extends Controller {
|
||||
// 查看未知消息
|
||||
async showUnknownSN() {
|
||||
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.unknownSN.showUnknownSN(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let unknownSNRecord = [];
|
||||
result.rows.forEach(element => {
|
||||
unknownSNRecord.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
unknownSNRecord,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索未知消息成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索未知消息失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showUnknownSN";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除未知消息
|
||||
async deleteUnknownSN() {
|
||||
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.unknownSN.deleteUnknownSN(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 + "--" + "deleteUnknownSN";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出竞赛账号信息
|
||||
async downloadUnknownSN() {
|
||||
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.unknownSN.downloadUnknownSN(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:8012'
|
||||
// 'http://192.168.31.28:8012'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8012'
|
||||
// 'http://manager.bdrd.hwasmart.com//accountManager'
|
||||
fileUrl: 'http://127.0.0.1:8012' + `/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 + "--" + "downloadUnknownSN";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UnknownSNController;
|
||||
@@ -4,6 +4,10 @@ const sha256 = require("crypto-js/sha256");
|
||||
|
||||
const CryptoJS = require("crypto-js");
|
||||
|
||||
const XLSX = require('xlsx');
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const KEY = CryptoJS.enc.Utf8.parse('BDQH');
|
||||
|
||||
class BaseController extends Controller {
|
||||
@@ -128,6 +132,42 @@ class BaseController extends Controller {
|
||||
}
|
||||
ctx.body = modelType[model];
|
||||
}
|
||||
|
||||
downloadData = (form, data, dataHeaders) => {
|
||||
let extensionName = ['.xlsx', '.xls', '.csv'], buf;
|
||||
const { sheetName, fileName, extensionType } = form;
|
||||
if (extensionName[extensionType] == '.xlsx' || extensionName[extensionType] == '.xls') {
|
||||
// 使用xlsx库将数据转换为工作表和工作簿
|
||||
const ws = XLSX.utils.json_to_sheet(data);
|
||||
// 动态设置表头
|
||||
dataHeaders.forEach((header, index) => {
|
||||
const cellRef = XLSX.utils.encode_cell({ r: 0, c: index }); // 生成单元格引用,如A1, B1等
|
||||
ws[cellRef] = { v: header, t: "s" }; // 设置单元格的值和类型
|
||||
});
|
||||
// 创建一个新的工作簿并添加工作表
|
||||
const wb = XLSX.utils.book_new();
|
||||
// 将工作表添加到工作簿中,并指定其名称
|
||||
XLSX.utils.book_append_sheet(wb, ws, sheetName);
|
||||
if (extensionName[extensionType] == '.xlsx') {
|
||||
// 将工作簿写入字符串(二进制)
|
||||
buf = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
|
||||
} else if (extensionName[extensionType] == '.xls') {
|
||||
// 将工作簿写入字符串(二进制)
|
||||
buf = XLSX.write(wb, { bookType: 'xls', type: 'array' });
|
||||
}
|
||||
} else if (extensionName[extensionType] == '.csv') {
|
||||
// 将数据转换为CSV格式的字符串
|
||||
buf = data.map(row => row.join(',')).join('\n') + '\n';
|
||||
}
|
||||
// 将文件的内容返回给控制器作为响应体发送给客户端
|
||||
if (buf) {
|
||||
const completeName = fileName + extensionName[extensionType];
|
||||
const filePath = 'app/public/' + completeName;
|
||||
// const filePath = '/disk/a/Download/' + completeName;
|
||||
return { filePath, completeName, buf };
|
||||
};
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = BaseController;
|
||||
20
app/model3/UnknownBDCard.js
Normal file
20
app/model3/UnknownBDCard.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, TEXT, DATE } = app.Sequelize;
|
||||
|
||||
const UnknownBDCard = app.model3.define('unknown-bdcard', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
card_id: CHAR(8),
|
||||
original_msg: TEXT,
|
||||
msg_data: TEXT,
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return UnknownBDCard;
|
||||
};
|
||||
21
app/model3/UnknownSN.js
Normal file
21
app/model3/UnknownSN.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, STRING, TEXT, DATE } = app.Sequelize;
|
||||
|
||||
const UnknownSN = app.model3.define('unknown-sn', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
msg_id: STRING(30),
|
||||
sn_number: STRING(8),
|
||||
original_msg: TEXT,
|
||||
msg_data: TEXT,
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return UnknownSN;
|
||||
};
|
||||
BIN
app/public/test.xlsx
Normal file
BIN
app/public/test.xlsx
Normal file
Binary file not shown.
@@ -15,11 +15,15 @@ module.exports = app => {
|
||||
router.post("/editBdCard", controller.bdCard.editBdCard);
|
||||
// 删除北斗卡
|
||||
router.post("/deleteBdCard", controller.bdCard.deleteBdCard);
|
||||
// 管理系统导出北斗卡
|
||||
router.post("/downloadBDCard", controller.bdCard.downloadBDCard);
|
||||
|
||||
// 查看绑定记录
|
||||
router.post("/showBindRecord", controller.bindRecord.showBindRecord);
|
||||
// 删除绑定记录
|
||||
router.post("/deleteBindRecord", controller.bindRecord.deleteBindRecord);
|
||||
// 管理系统导出北斗卡绑定记录
|
||||
router.post("/downloadBindRecord", controller.bindRecord.downloadBindRecord);
|
||||
|
||||
// 注册公司业务
|
||||
router.post("/addBusiness", controller.business.addBusiness);
|
||||
@@ -31,6 +35,8 @@ module.exports = app => {
|
||||
router.post("/editBusiness", controller.business.editBusiness);
|
||||
// 删除公司业务
|
||||
router.post("/deleteBusiness", controller.business.deleteBusiness);
|
||||
// 管理系统导出公司业务
|
||||
router.post("/downloadBusiness", controller.business.downloadBusiness);
|
||||
|
||||
// 注册B端用户
|
||||
router.post("/addBSide", controller.bSide.addBSide);
|
||||
@@ -40,6 +46,8 @@ module.exports = app => {
|
||||
router.post("/editBSide", controller.bSide.editBSide);
|
||||
// 删除B端用户
|
||||
router.post("/deleteBSide", controller.bSide.deleteBSide);
|
||||
// 管理系统导出B端用户
|
||||
router.post("/downloadBside", controller.bSide.downloadBside);
|
||||
|
||||
// 查看C端用户
|
||||
router.post("/showCSide", controller.cSide.showCSide);
|
||||
@@ -47,6 +55,8 @@ module.exports = app => {
|
||||
router.post("/editCSide", controller.cSide.editCSide);
|
||||
// 删除C端用户
|
||||
router.post("/deleteCSide", controller.cSide.deleteCSide);
|
||||
// 管理系统导出C端用户
|
||||
router.post("/downloadCside", controller.cSide.downloadCside);
|
||||
|
||||
// 注册管理系统用户
|
||||
router.post("/addInsiders", controller.insiders.addInsiders);
|
||||
@@ -56,6 +66,8 @@ module.exports = app => {
|
||||
router.post("/editInsiders", controller.insiders.editInsiders);
|
||||
// 删除管理系统用户
|
||||
router.post("/deleteInsiders", controller.insiders.deleteInsiders);
|
||||
// 管理系统导出系统用户
|
||||
router.post("/downloadInsiders", controller.insiders.downloadInsiders);
|
||||
|
||||
// 注册B端用户单位
|
||||
router.post("/addOrganization", controller.organization.addOrganization);
|
||||
@@ -67,11 +79,15 @@ module.exports = app => {
|
||||
router.post("/editOrganization", controller.organization.editOrganization);
|
||||
// 删除B端用户单位
|
||||
router.post("/deleteOrganization", controller.organization.deleteOrganization);
|
||||
// 管理系统导出B端用户单位
|
||||
router.post("/downloadOrganization", controller.organization.downloadOrganization);
|
||||
|
||||
// 查看监控记录
|
||||
router.post("/showMonitoring", controller.monitoring.showMonitoring);
|
||||
// 删除监控记录
|
||||
router.post("/deleteMonitoring", controller.monitoring.deleteMonitoring);
|
||||
// 管理系统导出监控记录
|
||||
router.post("/downloadMonitoring", controller.monitoring.downloadMonitoring);
|
||||
|
||||
// 管理系统检索竞赛 uid
|
||||
router.post("/searchContestUid", controller.contestMsg.searchContestUid);
|
||||
@@ -83,6 +99,8 @@ module.exports = app => {
|
||||
router.post("/editContest", controller.contestMsg.editContest);
|
||||
// 管理系统删除竞赛信息
|
||||
router.post("/delContest", controller.contestMsg.delContest);
|
||||
// 管理系统导出竞赛信息
|
||||
router.post("/downloadContest", controller.contestMsg.downloadContest);
|
||||
|
||||
// 管理系统导入选择题
|
||||
router.post("/importChoiceTopic", controller.contestTopic.importChoiceTopic);
|
||||
@@ -94,6 +112,8 @@ module.exports = app => {
|
||||
router.post("/editChoiceTopic", controller.contestTopic.editChoiceTopic);
|
||||
// 管理系统删除选择题
|
||||
router.post("/delChoiceTopic", controller.contestTopic.delChoiceTopic);
|
||||
// 管理系统导出选择题
|
||||
router.post("/downloadChoiceTopic", controller.contestTopic.downloadChoiceTopic);
|
||||
|
||||
// 管理系统导入竞赛账号信息
|
||||
router.post("/importAccount", controller.contestAccount.importAccount);
|
||||
@@ -105,6 +125,8 @@ module.exports = app => {
|
||||
router.post("/editAccount", controller.contestAccount.editAccount);
|
||||
// 管理系统删除竞赛账号信息
|
||||
router.post("/delAccount", controller.contestAccount.delAccount);
|
||||
// 管理系统导出竞赛账号信息
|
||||
router.post("/downloadAccount", controller.contestAccount.downloadAccount);
|
||||
|
||||
// 管理系统重置竞赛账号密码
|
||||
router.post("/resetAccount", controller.contestAccount.resetAccount);
|
||||
@@ -126,20 +148,45 @@ module.exports = app => {
|
||||
router.post("/editSN", controller.sn.editSN);
|
||||
// 删除SN号
|
||||
router.post("/deleteSN", controller.sn.deleteSN);
|
||||
// 管理系统导出SN号
|
||||
router.post("/downloadSN", controller.sn.downloadSN);
|
||||
|
||||
// 查看SN号绑定记录
|
||||
router.post("/showBindSNRecord", controller.bindSNRecord.showBindSNRecord);
|
||||
// 删除SN号绑定记录
|
||||
router.post("/deleteBindSNRecord", controller.bindSNRecord.deleteBindSNRecord);
|
||||
// 管理系统导出SN号绑定记录
|
||||
router.post("/downloadBindSNRecord", controller.bindSNRecord.downloadBindSNRecord);
|
||||
|
||||
// 搜索可分配的SN号
|
||||
router.get("/searchAllocationSN", controller.sNAdmin.searchAllocationSN);
|
||||
router.post("/searchAllocationSN", controller.sNAdmin.searchAllocationSN);
|
||||
// 搜索可分配的单位用户
|
||||
router.get("/searchAllocationUser", controller.sNAdmin.searchAllocationUser);
|
||||
router.post("/searchAllocationUser", controller.sNAdmin.searchAllocationUser);
|
||||
// B端分配SN号
|
||||
router.post("/allocationSN", controller.sNAdmin.allocationSN);
|
||||
// 查看B端SN号分配记录
|
||||
router.post("/showAllocationSNRecord", controller.sNAdmin.showAllocationSNRecord);
|
||||
// 删除B端SN号分配记录
|
||||
router.post("/deleteAllocationSNRecord", controller.sNAdmin.deleteAllocationSNRecord);
|
||||
// 管理系统导出B端SN号分配记录
|
||||
router.post("/downloadAllocationSNRecord", controller.sNAdmin.downloadAllocationSNRecord);
|
||||
|
||||
// 查看未知北斗卡消息
|
||||
router.post("/showUnknownBDCard", controller.unknownBDCard.showUnknownBDCard);
|
||||
// 删除未知北斗卡消息
|
||||
router.post("/deleteUnknownBDCard", controller.unknownBDCard.deleteUnknownBDCard);
|
||||
// 管理系统导出未知北斗卡消息
|
||||
router.post("/downloadUnknownBDCard", controller.unknownBDCard.downloadUnknownBDCard);
|
||||
|
||||
// 查看未知SN号消息
|
||||
router.post("/showUnknownSN", controller.unknownSN.showUnknownSN);
|
||||
// 删除未知SN号消息
|
||||
router.post("/deleteUnknownSN", controller.unknownSN.deleteUnknownSN);
|
||||
// 管理系统导出未知SN号消息
|
||||
router.post("/downloadUnknownSN", controller.unknownSN.downloadUnknownSN);
|
||||
|
||||
// 获取SN号竞赛消息
|
||||
router.post("/getSNContestMsg", controller.sNContest.getSNContestMsg);
|
||||
// 管理系统导出SN号竞赛消息
|
||||
router.post("/downloadSNConest", controller.sNContest.downloadSNConest);
|
||||
};
|
||||
|
||||
@@ -4,6 +4,8 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "BSide";
|
||||
|
||||
class BSideService extends Service {
|
||||
@@ -168,6 +170,106 @@ class BSideService extends Service {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出B端用户
|
||||
async downloadBside(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['uid', 'status', 'role', 'account_name', 'organization', 'user_name', 'phone', 'msg', 'created_at', 'updated_at', 'login_at', 'login_status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'account_name', 'organization', 'user_name', 'phone', 'msg'],
|
||||
key = ['status', 'role', 'login_status'],
|
||||
between = ['created_at', 'updated_at', 'login_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model.BSide.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "默认"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "正在使用"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "封禁"
|
||||
}
|
||||
];
|
||||
const roleOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "普通用户"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "单位管理员"
|
||||
}
|
||||
];
|
||||
result.forEach(element => {
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
roleOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["role"]) {
|
||||
element.dataValues["role"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.updated_at = moment
|
||||
.utc(element.dataValues.updated_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.login_at = moment
|
||||
.utc(element.dataValues.login_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
delete element.dataValues.login_status;
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadBside";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BSideService;
|
||||
@@ -4,6 +4,8 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "BdCard";
|
||||
|
||||
class BdCardService extends Service {
|
||||
@@ -51,14 +53,14 @@ class BdCardService extends Service {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
const [bside, cside, contest, bsideBind, csideBind, contestBind ] = await Promise.all([
|
||||
const [bside, cside, contest, bsideBind, csideBind, contestBind] = await Promise.all([
|
||||
ctx.model.BSide.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
ctx.model2.CSide.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
ctx.model4.Account.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
ctx.model.BuserBind.findAll({ attributes: ['user_uid', 'card_id'] }),
|
||||
ctx.model2.CuserBind.findAll({ attributes: ['user_uid', 'card_id'] }),
|
||||
ctx.model4.TuserBind.findAll({ attributes: ['user_uid', 'card_id'] })
|
||||
]);
|
||||
]);
|
||||
if (searchOptions.account_name) {
|
||||
if (searchOptions.account_name == '*空') {
|
||||
if (where.status == '1' || where.status == '2' || where.status == '3') {
|
||||
@@ -201,7 +203,7 @@ class BdCardService extends Service {
|
||||
let card_id = [], card_imsi = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
card_id.push(element.card_id),
|
||||
card_id.push(element.card_id),
|
||||
card_imsi.push(element.card_imsi)
|
||||
});
|
||||
}
|
||||
@@ -220,6 +222,109 @@ class BdCardService extends Service {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出北斗卡
|
||||
async downloadBDCard(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['card_id', 'card_imsi', 'type', 'status', 'created_at', 'updated_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['card_id', 'card_imsi'],
|
||||
key = ['type', 'status'],
|
||||
between = ['created_at', 'updated_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model3.BDCard.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const typeOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "白名单"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "审核中"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "黑名单"
|
||||
}
|
||||
];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "未绑定"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "B端绑定"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "C端绑定"
|
||||
},
|
||||
{
|
||||
value: "3",
|
||||
label: "竞赛绑定"
|
||||
}
|
||||
];
|
||||
result.forEach(element => {
|
||||
typeOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["type"]) {
|
||||
element.dataValues["type"] = item.label;
|
||||
}
|
||||
});
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.updated_at = moment
|
||||
.utc(element.dataValues.updated_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadBDCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BdCardService;
|
||||
@@ -4,176 +4,265 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "BindRecord";
|
||||
|
||||
class BindRecordService extends Service {
|
||||
// 查看北斗卡绑定记录
|
||||
async showBindRecord(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['user_uid', 'card_id', 'type', 'created_at'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['user_uid', 'card_id'],
|
||||
key = ['type'],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
const [bside, cside, bsideRecord, csideRecord] = await Promise.all([
|
||||
ctx.model.BSide.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
ctx.model2.CSide.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
ctx.model.BindBrecord.findAll({ attributes: ['user_uid', 'card_id', 'created_at'] }),
|
||||
ctx.model2.BindCrecord.findAll({ attributes: ['user_uid', 'card_id', 'created_at'] })
|
||||
]);
|
||||
if (searchOptions.account_name) {
|
||||
if (searchOptions.account_name == '*空') {
|
||||
where.user_uid = [null, ''];
|
||||
} else {
|
||||
let userArr = [], cardArr = [], createdArr = [];
|
||||
bside.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
bsideRecord.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
userArr.push(item2.dataValues.user_uid);
|
||||
cardArr.push(item2.dataValues.card_id);
|
||||
createdArr.push(item2.dataValues.created_at);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
cside.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
csideRecord.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
userArr.push(item2.dataValues.user_uid);
|
||||
cardArr.push(item2.dataValues.card_id);
|
||||
createdArr.push(item2.dataValues.created_at);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
where.user_uid = [...userArr];
|
||||
where.card_id = [...cardArr];
|
||||
where.created_at = [...createdArr];
|
||||
}
|
||||
}
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
let result;
|
||||
if (searchOptions.side !== undefined && searchOptions.side !== '') {
|
||||
if (searchOptions.side == '0') {
|
||||
result = await ctx.model.BindBrecord.findAndCountAll(dbOptions);
|
||||
} else if (searchOptions.side == '1') {
|
||||
result = await ctx.model2.BindCrecord.findAndCountAll(dbOptions);
|
||||
}
|
||||
// 查看北斗卡绑定记录
|
||||
async showBindRecord(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['user_uid', 'card_id', 'type', 'created_at'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['user_uid', 'card_id'],
|
||||
key = ['type'],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
dbOptions.limit = Math.floor(limit / 2);
|
||||
dbOptions.offset = Math.floor(offset / 2);
|
||||
const [bresult, cresult] = await Promise.all([
|
||||
ctx.model.BindBrecord.findAndCountAll(dbOptions),
|
||||
ctx.model2.BindCrecord.findAndCountAll(dbOptions)
|
||||
]);
|
||||
result = {
|
||||
count: bresult.count + cresult.count,
|
||||
rows: bresult.rows.concat(cresult.rows)
|
||||
};
|
||||
result.rows.sort((a, b) => b.dataValues.created_at - a.dataValues.created_at);
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
result.rows.forEach(element => {
|
||||
element.dataValues.account_name = '';
|
||||
element.dataValues.side = element.dataValues.user_uid[element.dataValues.user_uid.length - 1] == 'B' ? '0' : '1';
|
||||
bside.filter(item => {
|
||||
if (item.dataValues.uid == element.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item.dataValues.account_name;
|
||||
} else {
|
||||
cside.filter(item2 => {
|
||||
if (item2.dataValues.uid == element.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item2.dataValues.account_name;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBindRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 删除北斗卡绑定记录
|
||||
async deleteBindRecord(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemBindRecord = {
|
||||
operate: 2,
|
||||
operate_msg: '删除北斗卡绑定记录',
|
||||
type: 1,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemBindRecord.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemBindRecord.status = 1;
|
||||
else if (result.dataValues.role < 9) systemBindRecord.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemBindRecord);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { card_id, type, created_at } = requestMsg;
|
||||
where = { card_id, type, created_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let card_id = [], type = [], created_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
card_id.push(element.card_id),
|
||||
type.push(element.type),
|
||||
created_at.push(element.created_at)
|
||||
});
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
const [bside, cside, bsideRecord, csideRecord] = await Promise.all([
|
||||
ctx.model.BSide.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
ctx.model2.CSide.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
ctx.model.BindBrecord.findAll({ attributes: ['user_uid', 'card_id', 'created_at'] }),
|
||||
ctx.model2.BindCrecord.findAll({ attributes: ['user_uid', 'card_id', 'created_at'] })
|
||||
]);
|
||||
if (searchOptions.account_name) {
|
||||
if (searchOptions.account_name == '*空') {
|
||||
where.user_uid = [null, ''];
|
||||
} else {
|
||||
let userArr = [], cardArr = [], createdArr = [];
|
||||
bside.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
bsideRecord.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
userArr.push(item2.dataValues.user_uid);
|
||||
cardArr.push(item2.dataValues.card_id);
|
||||
createdArr.push(item2.dataValues.created_at);
|
||||
}
|
||||
where = { card_id, type, created_at };
|
||||
});
|
||||
}
|
||||
const [bresultList, cresultList] = await Promise.all([
|
||||
ctx.model.BindBrecord.destroy({ where }),
|
||||
ctx.model2.BindCrecord.destroy({ where })
|
||||
]);
|
||||
systemBindRecord.status = bresultList + cresultList == 0 ? 3 : 4;
|
||||
systemBindRecord.affect_entries = bresultList + cresultList;
|
||||
await ctx.model3.Monitoring.create(systemBindRecord);
|
||||
return bresultList + cresultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemBindRecord.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemBindRecord);
|
||||
const blockName = fileName + "--" + "deleteBindRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
});
|
||||
cside.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
csideRecord.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
userArr.push(item2.dataValues.user_uid);
|
||||
cardArr.push(item2.dataValues.card_id);
|
||||
createdArr.push(item2.dataValues.created_at);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
where.user_uid = [...userArr];
|
||||
where.card_id = [...cardArr];
|
||||
where.created_at = [...createdArr];
|
||||
}
|
||||
}
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
let result;
|
||||
if (searchOptions.side !== undefined && searchOptions.side !== '') {
|
||||
if (searchOptions.side == '0') {
|
||||
result = await ctx.model.BindBrecord.findAndCountAll(dbOptions);
|
||||
} else if (searchOptions.side == '1') {
|
||||
result = await ctx.model2.BindCrecord.findAndCountAll(dbOptions);
|
||||
}
|
||||
} else {
|
||||
dbOptions.limit = Math.floor(limit / 2);
|
||||
dbOptions.offset = Math.floor(offset / 2);
|
||||
const [bresult, cresult] = await Promise.all([
|
||||
ctx.model.BindBrecord.findAndCountAll(dbOptions),
|
||||
ctx.model2.BindCrecord.findAndCountAll(dbOptions)
|
||||
]);
|
||||
result = {
|
||||
count: bresult.count + cresult.count,
|
||||
rows: bresult.rows.concat(cresult.rows)
|
||||
};
|
||||
result.rows.sort((a, b) => b.dataValues.created_at - a.dataValues.created_at);
|
||||
}
|
||||
result.rows.forEach(element => {
|
||||
element.dataValues.account_name = '';
|
||||
element.dataValues.side = element.dataValues.user_uid[element.dataValues.user_uid.length - 1] == 'B' ? '0' : '1';
|
||||
bside.filter(item => {
|
||||
if (item.dataValues.uid == element.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item.dataValues.account_name;
|
||||
} else {
|
||||
cside.filter(item2 => {
|
||||
if (item2.dataValues.uid == element.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item2.dataValues.account_name;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBindRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除北斗卡绑定记录
|
||||
async deleteBindRecord(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemBindRecord = {
|
||||
operate: 2,
|
||||
operate_msg: '删除北斗卡绑定记录',
|
||||
type: 1,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemBindRecord.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemBindRecord.status = 1;
|
||||
else if (result.dataValues.role < 9) systemBindRecord.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemBindRecord);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { card_id, type, created_at } = requestMsg;
|
||||
where = { card_id, type, created_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let card_id = [], type = [], created_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
card_id.push(element.card_id),
|
||||
type.push(element.type),
|
||||
created_at.push(element.created_at)
|
||||
});
|
||||
}
|
||||
where = { card_id, type, created_at };
|
||||
}
|
||||
const [bresultList, cresultList] = await Promise.all([
|
||||
ctx.model.BindBrecord.destroy({ where }),
|
||||
ctx.model2.BindCrecord.destroy({ where })
|
||||
]);
|
||||
systemBindRecord.status = bresultList + cresultList == 0 ? 3 : 4;
|
||||
systemBindRecord.affect_entries = bresultList + cresultList;
|
||||
await ctx.model3.Monitoring.create(systemBindRecord);
|
||||
return bresultList + cresultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemBindRecord.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemBindRecord);
|
||||
const blockName = fileName + "--" + "deleteBindRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出北斗卡绑定记录
|
||||
async downloadBindRecord(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['user_uid', 'card_id', 'type', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['user_uid', 'card_id'],
|
||||
key = ['type'],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const [bresult, cresult] = await Promise.all([
|
||||
ctx.model.BindBrecord.findAll(dbOptions),
|
||||
ctx.model2.BindCrecord.findAll(dbOptions)
|
||||
]);
|
||||
if (bresult.length ==0 && cresult.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const typeOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "解绑"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "绑定"
|
||||
}
|
||||
];
|
||||
bresult.forEach(element => {
|
||||
typeOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["type"]) {
|
||||
element.dataValues["type"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
cresult.forEach(element => {
|
||||
typeOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["type"]) {
|
||||
element.dataValues["type"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadBindRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BindRecordService;
|
||||
@@ -4,176 +4,265 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "BindSNRecord";
|
||||
|
||||
class BindSNRecordService extends Service {
|
||||
// 查看SN号绑定记录
|
||||
async showBindSNRecord(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['user_uid', 'sn_number', 'type', 'created_at'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['user_uid', 'sn_number'],
|
||||
key = ['type'],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
const [bside, cside, bsideRecord, csideRecord] = await Promise.all([
|
||||
ctx.model.BSide.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
ctx.model2.CSide.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
ctx.model.BindBSNrecord.findAll({ attributes: ['user_uid', 'sn_number', 'created_at'] }),
|
||||
ctx.model2.BindCSNrecord.findAll({ attributes: ['user_uid', 'sn_number', 'created_at'] })
|
||||
]);
|
||||
if (searchOptions.account_name) {
|
||||
if (searchOptions.account_name == '*空') {
|
||||
where.user_uid = [null, ''];
|
||||
} else {
|
||||
let userArr = [], SNArr = [], createdArr = [];
|
||||
bside.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
bsideRecord.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
userArr.push(item2.dataValues.user_uid);
|
||||
SNArr.push(item2.dataValues.sn_number);
|
||||
createdArr.push(item2.dataValues.created_at);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
cside.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
csideRecord.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
userArr.push(item2.dataValues.user_uid);
|
||||
SNArr.push(item2.dataValues.sn_number);
|
||||
createdArr.push(item2.dataValues.created_at);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
where.user_uid = [...userArr];
|
||||
where.sn_number = [...SNArr];
|
||||
where.created_at = [...createdArr];
|
||||
}
|
||||
}
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
let result;
|
||||
if (searchOptions.side !== undefined && searchOptions.side !== '') {
|
||||
if (searchOptions.side == '0') {
|
||||
result = await ctx.model.BindBSNrecord.findAndCountAll(dbOptions);
|
||||
} else if (searchOptions.side == '1') {
|
||||
result = await ctx.model2.BindCSNrecord.findAndCountAll(dbOptions);
|
||||
}
|
||||
// 查看SN号绑定记录
|
||||
async showBindSNRecord(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['user_uid', 'sn_number', 'type', 'created_at'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['user_uid', 'sn_number'],
|
||||
key = ['type'],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
dbOptions.limit = Math.floor(limit / 2);
|
||||
dbOptions.offset = Math.floor(offset / 2);
|
||||
const [bresult, cresult] = await Promise.all([
|
||||
ctx.model.BindBSNrecord.findAndCountAll(dbOptions),
|
||||
ctx.model2.BindCSNrecord.findAndCountAll(dbOptions)
|
||||
]);
|
||||
result = {
|
||||
count: bresult.count + cresult.count,
|
||||
rows: bresult.rows.concat(cresult.rows)
|
||||
};
|
||||
result.rows.sort((a, b) => b.dataValues.created_at - a.dataValues.created_at);
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
result.rows.forEach(element => {
|
||||
element.dataValues.account_name = '';
|
||||
element.dataValues.side = element.dataValues.user_uid[element.dataValues.user_uid.length - 1] == 'B' ? '0' : '1';
|
||||
bside.filter(item => {
|
||||
if (item.dataValues.uid == element.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item.dataValues.account_name;
|
||||
} else {
|
||||
cside.filter(item2 => {
|
||||
if (item2.dataValues.uid == element.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item2.dataValues.account_name;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBindSNRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 删除SN号绑定记录
|
||||
async deleteBindSNRecord(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemBindSNRecord = {
|
||||
operate: 2,
|
||||
operate_msg: '删除SN号绑定记录',
|
||||
type: 1,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemBindSNRecord.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemBindSNRecord.status = 1;
|
||||
else if (result.dataValues.role < 9) systemBindSNRecord.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemBindSNRecord);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { sn_number, type, created_at } = requestMsg;
|
||||
where = { sn_number, type, created_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let sn_number = [], type = [], created_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
sn_number.push(element.sn_number),
|
||||
type.push(element.type),
|
||||
created_at.push(element.created_at)
|
||||
});
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
const [bside, cside, bsideRecord, csideRecord] = await Promise.all([
|
||||
ctx.model.BSide.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
ctx.model2.CSide.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
ctx.model.BindBSNrecord.findAll({ attributes: ['user_uid', 'sn_number', 'created_at'] }),
|
||||
ctx.model2.BindCSNrecord.findAll({ attributes: ['user_uid', 'sn_number', 'created_at'] })
|
||||
]);
|
||||
if (searchOptions.account_name) {
|
||||
if (searchOptions.account_name == '*空') {
|
||||
where.user_uid = [null, ''];
|
||||
} else {
|
||||
let userArr = [], SNArr = [], createdArr = [];
|
||||
bside.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
bsideRecord.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
userArr.push(item2.dataValues.user_uid);
|
||||
SNArr.push(item2.dataValues.sn_number);
|
||||
createdArr.push(item2.dataValues.created_at);
|
||||
}
|
||||
where = { sn_number, type, created_at };
|
||||
});
|
||||
}
|
||||
const [bresultList, cresultList] = await Promise.all([
|
||||
ctx.model.BindBSNrecord.destroy({ where }),
|
||||
ctx.model2.BindCSNrecord.destroy({ where })
|
||||
]);
|
||||
systemBindSNRecord.status = bresultList + cresultList == 0 ? 3 : 4;
|
||||
systemBindSNRecord.affect_entries = bresultList + cresultList;
|
||||
await ctx.model3.Monitoring.create(systemBindSNRecord);
|
||||
return bresultList + cresultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemBindSNRecord.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemBindSNRecord);
|
||||
const blockName = fileName + "--" + "deleteBindSNRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
});
|
||||
cside.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
csideRecord.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
userArr.push(item2.dataValues.user_uid);
|
||||
SNArr.push(item2.dataValues.sn_number);
|
||||
createdArr.push(item2.dataValues.created_at);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
where.user_uid = [...userArr];
|
||||
where.sn_number = [...SNArr];
|
||||
where.created_at = [...createdArr];
|
||||
}
|
||||
}
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
let result;
|
||||
if (searchOptions.side !== undefined && searchOptions.side !== '') {
|
||||
if (searchOptions.side == '0') {
|
||||
result = await ctx.model.BindBSNrecord.findAndCountAll(dbOptions);
|
||||
} else if (searchOptions.side == '1') {
|
||||
result = await ctx.model2.BindCSNrecord.findAndCountAll(dbOptions);
|
||||
}
|
||||
} else {
|
||||
dbOptions.limit = Math.floor(limit / 2);
|
||||
dbOptions.offset = Math.floor(offset / 2);
|
||||
const [bresult, cresult] = await Promise.all([
|
||||
ctx.model.BindBSNrecord.findAndCountAll(dbOptions),
|
||||
ctx.model2.BindCSNrecord.findAndCountAll(dbOptions)
|
||||
]);
|
||||
result = {
|
||||
count: bresult.count + cresult.count,
|
||||
rows: bresult.rows.concat(cresult.rows)
|
||||
};
|
||||
result.rows.sort((a, b) => b.dataValues.created_at - a.dataValues.created_at);
|
||||
}
|
||||
result.rows.forEach(element => {
|
||||
element.dataValues.account_name = '';
|
||||
element.dataValues.side = element.dataValues.user_uid[element.dataValues.user_uid.length - 1] == 'B' ? '0' : '1';
|
||||
bside.filter(item => {
|
||||
if (item.dataValues.uid == element.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item.dataValues.account_name;
|
||||
} else {
|
||||
cside.filter(item2 => {
|
||||
if (item2.dataValues.uid == element.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item2.dataValues.account_name;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBindSNRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除SN号绑定记录
|
||||
async deleteBindSNRecord(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemBindSNRecord = {
|
||||
operate: 2,
|
||||
operate_msg: '删除SN号绑定记录',
|
||||
type: 1,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemBindSNRecord.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemBindSNRecord.status = 1;
|
||||
else if (result.dataValues.role < 9) systemBindSNRecord.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemBindSNRecord);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { sn_number, type, created_at } = requestMsg;
|
||||
where = { sn_number, type, created_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let sn_number = [], type = [], created_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
sn_number.push(element.sn_number),
|
||||
type.push(element.type),
|
||||
created_at.push(element.created_at)
|
||||
});
|
||||
}
|
||||
where = { sn_number, type, created_at };
|
||||
}
|
||||
const [bresultList, cresultList] = await Promise.all([
|
||||
ctx.model.BindBSNrecord.destroy({ where }),
|
||||
ctx.model2.BindCSNrecord.destroy({ where })
|
||||
]);
|
||||
systemBindSNRecord.status = bresultList + cresultList == 0 ? 3 : 4;
|
||||
systemBindSNRecord.affect_entries = bresultList + cresultList;
|
||||
await ctx.model3.Monitoring.create(systemBindSNRecord);
|
||||
return bresultList + cresultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemBindSNRecord.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemBindSNRecord);
|
||||
const blockName = fileName + "--" + "deleteBindSNRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出SN号绑定记录
|
||||
async downloadBindSNRecord(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['user_uid', 'sn_number', 'type', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['user_uid', 'sn_number'],
|
||||
key = ['type'],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const [bresult, cresult] = await Promise.all([
|
||||
ctx.model.BindBSNrecord.findAll(dbOptions),
|
||||
ctx.model2.BindCSNrecord.findAll(dbOptions)
|
||||
]);
|
||||
if (bresult.length == 0 && cresult.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const typeOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "解绑"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "绑定"
|
||||
}
|
||||
];
|
||||
bresult.forEach(element => {
|
||||
typeOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
cresult.forEach(element => {
|
||||
typeOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadBindSNRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BindSNRecordService;
|
||||
@@ -4,6 +4,8 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "Business";
|
||||
|
||||
class BusinessService extends Service {
|
||||
@@ -82,27 +84,27 @@ class BusinessService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
//远程搜索公司业务
|
||||
async SearchBusiness(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { query, key, timeBefor } = body;
|
||||
let attributes = ['temporary_id', 'name', 'created_at'], where = {}, dbOptions;
|
||||
if (query == '*空') {
|
||||
delete where[key]
|
||||
} else {
|
||||
where[key] = { [Op.substring]: query };
|
||||
}
|
||||
where.created_at = { [Op.lt]: timeBefor };
|
||||
dbOptions = { attributes, where };
|
||||
const Business = await ctx.model3.Business.findAll(dbOptions);
|
||||
return Business.length == 0 ? false : Business;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "SearchBusiness";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
//远程搜索公司业务
|
||||
async SearchBusiness(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { query, key, timeBefor } = body;
|
||||
let attributes = ['temporary_id', 'name', 'created_at'], where = {}, dbOptions;
|
||||
if (query == '*空') {
|
||||
delete where[key]
|
||||
} else {
|
||||
where[key] = { [Op.substring]: query };
|
||||
}
|
||||
where.created_at = { [Op.lt]: timeBefor };
|
||||
dbOptions = { attributes, where };
|
||||
const Business = await ctx.model3.Business.findAll(dbOptions);
|
||||
return Business.length == 0 ? false : Business;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "SearchBusiness";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑公司业务
|
||||
async editBusiness(uid, modelType, password, updateMsg, requestMsg) {
|
||||
@@ -206,6 +208,124 @@ class BusinessService extends Service {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出公司业务
|
||||
async downloadBusiness(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['login_url', 'client_url', 'temporary_id', 'client_id', 'client_secret', 'name', 'type', 'level', 'status', 'created_at', 'updated_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['login_url', 'client_url', 'temporary_id', 'client_id', 'client_secret', 'name'],
|
||||
key = ['type', 'level', 'status'],
|
||||
between = ['created_at', 'updated_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model3.Business.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const typeOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "B端业务"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "C端业务"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "通用业务"
|
||||
}
|
||||
];
|
||||
const levelOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "一般等级"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "重要等级"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "紧要等级"
|
||||
}
|
||||
];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "未启动"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "已启动"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "已关闭"
|
||||
}
|
||||
];
|
||||
result.forEach(element => {
|
||||
typeOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["type"]) {
|
||||
element.dataValues["type"] = item.label;
|
||||
}
|
||||
});
|
||||
levelOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["level"]) {
|
||||
element.dataValues["level"] = item.label;
|
||||
}
|
||||
});
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.updated_at = moment
|
||||
.utc(element.dataValues.updated_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadBusiness";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BusinessService;
|
||||
@@ -4,6 +4,8 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "CSide";
|
||||
|
||||
class CSideService extends Service {
|
||||
@@ -128,6 +130,121 @@ class CSideService extends Service {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出C端用户
|
||||
async downloadCside(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['uid', 'status', 'role', 'avatar', 'account_name', 'user_name', 'phone', 'gender', 'age', 'email', 'address', 'post_code', 'created_at', 'updated_at', 'login_at', 'login_status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'account_name', 'user_name', 'phone', 'age', 'email', 'address', 'post_code'],
|
||||
key = ['status', 'role', 'gender', 'login_status'],
|
||||
between = ['created_at', 'updated_at', 'login_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model2.CSide.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "默认"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "正在使用"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "封禁"
|
||||
}
|
||||
];
|
||||
const roleOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "普通用户"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "特殊用户"
|
||||
}
|
||||
];
|
||||
const genderOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "女"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "男"
|
||||
}
|
||||
];
|
||||
result.forEach(element => {
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
roleOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["role"]) {
|
||||
element.dataValues["role"] = item.label;
|
||||
}
|
||||
});
|
||||
genderOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["gender"]) {
|
||||
element.dataValues["gender"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.updated_at = moment
|
||||
.utc(element.dataValues.updated_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.login_at = moment
|
||||
.utc(element.dataValues.login_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
delete element.dataValues.login_status;
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadCside";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CSideService;
|
||||
@@ -4,6 +4,8 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "ContestAccount";
|
||||
|
||||
class ContestAccountService extends Service {
|
||||
@@ -95,11 +97,11 @@ class ContestAccountService extends Service {
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid),
|
||||
contest_uid.push(element.contest_uid),
|
||||
account_name.push(element.account_name),
|
||||
status.push(element.status),
|
||||
created_at.push(element.created_at),
|
||||
login_status.push(element.login_status)
|
||||
contest_uid.push(element.contest_uid),
|
||||
account_name.push(element.account_name),
|
||||
status.push(element.status),
|
||||
created_at.push(element.created_at),
|
||||
login_status.push(element.login_status)
|
||||
});
|
||||
}
|
||||
where = { uid, contest_uid, account_name, status, created_at, login_status };
|
||||
@@ -144,11 +146,11 @@ class ContestAccountService extends Service {
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid),
|
||||
contest_uid.push(element.contest_uid),
|
||||
account_name.push(element.account_name),
|
||||
status.push(element.status),
|
||||
created_at.push(element.created_at),
|
||||
login_status.push(element.login_status)
|
||||
contest_uid.push(element.contest_uid),
|
||||
account_name.push(element.account_name),
|
||||
status.push(element.status),
|
||||
created_at.push(element.created_at),
|
||||
login_status.push(element.login_status)
|
||||
});
|
||||
}
|
||||
where = { uid, contest_uid, account_name, status, created_at, login_status };
|
||||
@@ -195,6 +197,102 @@ class ContestAccountService extends Service {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出竞赛账号信息
|
||||
async downloadAccount(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['uid', 'contest_uid', 'account_name', 'status', 'created_at', 'login_status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'contest_uid', 'account_name'],
|
||||
key = ['status', 'login_status'],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model4.Account.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "准备参赛"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "正在参赛"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "已经结赛"
|
||||
},
|
||||
{
|
||||
value: "3",
|
||||
label: "已被封禁"
|
||||
},
|
||||
];
|
||||
const loginStatusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "未登录"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "已登录"
|
||||
}
|
||||
];
|
||||
result.forEach(element => {
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
loginStatusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["login_status"]) {
|
||||
element.dataValues["login_status"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
delete element.dataValues.login_status;
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadAccount";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestAccountService;
|
||||
@@ -4,160 +4,263 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "ContestExamination";
|
||||
|
||||
class ContestExaminationService extends Service {
|
||||
// 管理系统查看账号答题情况
|
||||
async showExamination(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['user_uid', 'contest_uid', 'exam_type', 'topic_type', 'score', 'created_at', 'updated_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['user_uid', 'contest_uid', 'score'],
|
||||
key = ['exam_type', 'topic_type'],
|
||||
between = ['created_at', 'updated_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model4.Examination.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showExamination";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑账号答题情况
|
||||
async editExamination(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 6) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at } = requestMsg;
|
||||
where = { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let user_uid = [], contest_uid = [], exam_type = [], topic_type = [], score = [], created_at = [], updated_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user_uid.push(element.user_uid),
|
||||
contest_uid.push(element.contest_uid),
|
||||
exam_type.push(element.exam_type),
|
||||
topic_type.push(element.topic_type),
|
||||
score.push(element.score),
|
||||
created_at.push(element.created_at),
|
||||
updated_at.push(element.updated_at)
|
||||
});
|
||||
}
|
||||
where = { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at };
|
||||
// 管理系统查看账号答题情况
|
||||
async showExamination(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['user_uid', 'contest_uid', 'exam_type', 'topic_type', 'score', 'created_at', 'updated_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['user_uid', 'contest_uid', 'score'],
|
||||
key = ['exam_type', 'topic_type'],
|
||||
between = ['created_at', 'updated_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
const resultList = await ctx.model4.Examination.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editExamination";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model4.Examination.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showExamination";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除账号答题情况
|
||||
async delExamination(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除账号答题情况',
|
||||
type: 0,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemMonitoring.status = 1;
|
||||
else if (result.dataValues.role < 9) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at } = requestMsg;
|
||||
where = { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let user_uid = [], contest_uid = [], exam_type = [], topic_type = [], score = [], created_at = [], updated_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user_uid.push(element.user_uid),
|
||||
contest_uid.push(element.contest_uid),
|
||||
exam_type.push(element.exam_type),
|
||||
topic_type.push(element.topic_type),
|
||||
score.push(element.score),
|
||||
created_at.push(element.created_at),
|
||||
updated_at.push(element.updated_at)
|
||||
});
|
||||
}
|
||||
where = { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at };
|
||||
// 管理系统编辑账号答题情况
|
||||
async editExamination(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 6) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at } = requestMsg;
|
||||
where = { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let user_uid = [], contest_uid = [], exam_type = [], topic_type = [], score = [], created_at = [], updated_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user_uid.push(element.user_uid),
|
||||
contest_uid.push(element.contest_uid),
|
||||
exam_type.push(element.exam_type),
|
||||
topic_type.push(element.topic_type),
|
||||
score.push(element.score),
|
||||
created_at.push(element.created_at),
|
||||
updated_at.push(element.updated_at)
|
||||
});
|
||||
}
|
||||
where = { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at };
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
const resultList = await ctx.model4.Examination.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editExamination";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除账号答题情况
|
||||
async delExamination(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除账号答题情况',
|
||||
type: 0,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemMonitoring.status = 1;
|
||||
else if (result.dataValues.role < 9) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at } = requestMsg;
|
||||
where = { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let user_uid = [], contest_uid = [], exam_type = [], topic_type = [], score = [], created_at = [], updated_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user_uid.push(element.user_uid),
|
||||
contest_uid.push(element.contest_uid),
|
||||
exam_type.push(element.exam_type),
|
||||
topic_type.push(element.topic_type),
|
||||
score.push(element.score),
|
||||
created_at.push(element.created_at),
|
||||
updated_at.push(element.updated_at)
|
||||
});
|
||||
}
|
||||
where = { user_uid, contest_uid, exam_type, topic_type, score, created_at, updated_at };
|
||||
}
|
||||
const resultList = await ctx.model4.Examination.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "delExamination";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出账号答题情况
|
||||
async downloadExamination(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['user_uid', 'contest_uid', 'exam_type', 'topic_type', 'topic1', 'topic2', 'topic3', 'topic5', 'answer', 'answer1', 'answer2', 'answer3', 'answer4', 'answer5', 'score', 'score_collection', 'created_at', 'updated_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['user_uid', 'contest_uid', 'topic1', 'topic2', 'topic3', 'topic5', 'answer', 'answer1', 'answer2', 'answer3', 'answer4', 'answer5', 'score', 'score_collection'],
|
||||
key = ['exam_type', 'topic_type'],
|
||||
between = ['created_at', 'updated_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
const resultList = await ctx.model4.Examination.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "delExamination";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出账号答题情况
|
||||
async downloadExamination(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
console.log(uid);
|
||||
console.log(body);
|
||||
// 使用分数和时间排序后导出
|
||||
// const result = await ctx.model4.Examination.findAll({ where: { body } });
|
||||
// console.log(result);
|
||||
// return result.length == 0 ? false : result;
|
||||
return true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadExamination";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
let include = [
|
||||
{
|
||||
model: ctx.model4.Account,
|
||||
attributes: ['account_name']
|
||||
},
|
||||
{
|
||||
model: ctx.model4.Contest,
|
||||
attributes: ['contest_name']
|
||||
}
|
||||
];
|
||||
ctx.model4.Examination.belongsTo(ctx.model4.Account, { foreignKey: 'user_uid', targetKey: 'uid' });
|
||||
ctx.model4.Examination.belongsTo(ctx.model4.Contest, { foreignKey: 'contest_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, where, order, include };
|
||||
const result = await ctx.model4.Examination.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const examTypeOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "线上赛"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "线下赛"
|
||||
}
|
||||
];
|
||||
const topicTypeOptions = [
|
||||
{
|
||||
value: "1",
|
||||
label: "1"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "2"
|
||||
},
|
||||
{
|
||||
value: "3",
|
||||
label: "3"
|
||||
},
|
||||
{
|
||||
value: "4",
|
||||
label: "4"
|
||||
},
|
||||
{
|
||||
value: "5",
|
||||
label: "5"
|
||||
},
|
||||
];
|
||||
result.forEach(element => {
|
||||
examTypeOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["exam_type"]) {
|
||||
element.dataValues["exam_type"] = item.label;
|
||||
}
|
||||
});
|
||||
topicTypeOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["topic_type"]) {
|
||||
element.dataValues["topic_type"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.account_name = element.dataValues.account.dataValues.account_name;
|
||||
element.dataValues.contest_name = element.dataValues.contest.dataValues.contest_name;
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.updated_at = moment
|
||||
.utc(element.dataValues.updated_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
delete element.dataValues.account;
|
||||
delete element.dataValues.contest;
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadExamination";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestExaminationService;
|
||||
@@ -4,179 +4,292 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "ContestMsg";
|
||||
|
||||
class ContestMsgService extends Service {
|
||||
// 管理系统检索竞赛 uid
|
||||
async searchContestUid(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model4.Contest.findAll({ where: { uid: { [Op.substring]: body.contest_uid } } });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchContestUid";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
// 管理系统检索竞赛 uid
|
||||
async searchContestUid(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model4.Contest.findAll({ where: { uid: { [Op.substring]: body.contest_uid } } });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchContestUid";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统创建竞赛信息
|
||||
async addContest(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model4.Contest.bulkCreate(form);
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addContest";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
// 管理系统创建竞赛信息
|
||||
async addContest(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model4.Contest.bulkCreate(form);
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addContest";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看竞赛信息
|
||||
async showContest(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['uid', 'contest_name', 'contest_organizers', 'contest_term', 'type', 'status', 'online_start', 'online_end', 'offline_start', 'offline_end', 'contest_start', 'contest_end', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'contest_name', 'contest_organizers', 'contest_term'],
|
||||
key = ['type', 'status'],
|
||||
between = ['online_start', 'online_end', 'offline_start', 'offline_end', 'contest_start', 'contest_end', 'created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model4.Contest.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showContest";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑竞赛信息
|
||||
async editContest(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 6) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { uid, contest_name, contest_organizers, contest_term, type, status, online_start, online_end, offline_start, offline_end, contest_start, contest_end, created_at } = requestMsg;
|
||||
where = { uid, contest_name, contest_organizers, contest_term, type, status, online_start, online_end, offline_start, offline_end, contest_start, contest_end, created_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], contest_name = [], contest_organizers = [], contest_term = [], type = [], status = [], online_start = [], online_end = [], offline_start = [], offline_end = [], contest_start = [], contest_end = [], created_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid),
|
||||
contest_name.push(element.contest_name),
|
||||
contest_organizers.push(element.contest_organizers),
|
||||
contest_term.push(element.contest_term),
|
||||
type.push(element.type),
|
||||
status.push(element.status),
|
||||
online_start.push(element.online_start),
|
||||
online_end.push(element.online_end),
|
||||
offline_start.push(element.offline_start),
|
||||
offline_end.push(element.offline_end),
|
||||
contest_start.push(element.contest_start),
|
||||
contest_end.push(element.contest_end),
|
||||
created_at.push(element.created_at)
|
||||
});
|
||||
}
|
||||
where = { uid, contest_name, contest_organizers, contest_term, type, status, online_start, online_end, offline_start, offline_end, contest_start, contest_end, created_at };
|
||||
// 管理系统查看竞赛信息
|
||||
async showContest(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['uid', 'contest_name', 'contest_organizers', 'contest_term', 'type', 'status', 'online_start', 'online_end', 'offline_start', 'offline_end', 'contest_start', 'contest_end', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'contest_name', 'contest_organizers', 'contest_term'],
|
||||
key = ['type', 'status'],
|
||||
between = ['online_start', 'online_end', 'offline_start', 'offline_end', 'contest_start', 'contest_end', 'created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
const resultList = await ctx.model4.Contest.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editContest";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model4.Contest.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showContest";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除竞赛信息
|
||||
async delContest(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除竞赛信息',
|
||||
type: 0,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemMonitoring.status = 1;
|
||||
else if (result.dataValues.role < 9) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { uid, contest_name, contest_organizers, contest_term, type, status, online_start, online_end, offline_start, offline_end, contest_start, contest_end, created_at } = requestMsg;
|
||||
where = { uid, contest_name, contest_organizers, contest_term, type, status, online_start, online_end, offline_start, offline_end, contest_start, contest_end, created_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], contest_name = [], contest_organizers = [], contest_term = [], type = [], status = [], online_start = [], online_end = [], offline_start = [], offline_end = [], contest_start = [], contest_end = [], created_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid),
|
||||
contest_name.push(element.contest_name),
|
||||
contest_organizers.push(element.contest_organizers),
|
||||
contest_term.push(element.contest_term),
|
||||
type.push(element.type),
|
||||
status.push(element.status),
|
||||
online_start.push(element.online_start),
|
||||
online_end.push(element.online_end),
|
||||
offline_start.push(element.offline_start),
|
||||
offline_end.push(element.offline_end),
|
||||
contest_start.push(element.contest_start),
|
||||
contest_end.push(element.contest_end),
|
||||
created_at.push(element.created_at)
|
||||
});
|
||||
}
|
||||
where = { uid, contest_name, contest_organizers, contest_term, type, status, online_start, online_end, offline_start, offline_end, contest_start, contest_end, created_at };
|
||||
}
|
||||
const resultList = await ctx.model4.Contest.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "delContest";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
// 管理系统编辑竞赛信息
|
||||
async editContest(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 6) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { uid, contest_name, contest_organizers, contest_term, type, status, online_start, online_end, offline_start, offline_end, contest_start, contest_end, created_at } = requestMsg;
|
||||
where = { uid, contest_name, contest_organizers, contest_term, type, status, online_start, online_end, offline_start, offline_end, contest_start, contest_end, created_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], contest_name = [], contest_organizers = [], contest_term = [], type = [], status = [], online_start = [], online_end = [], offline_start = [], offline_end = [], contest_start = [], contest_end = [], created_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid),
|
||||
contest_name.push(element.contest_name),
|
||||
contest_organizers.push(element.contest_organizers),
|
||||
contest_term.push(element.contest_term),
|
||||
type.push(element.type),
|
||||
status.push(element.status),
|
||||
online_start.push(element.online_start),
|
||||
online_end.push(element.online_end),
|
||||
offline_start.push(element.offline_start),
|
||||
offline_end.push(element.offline_end),
|
||||
contest_start.push(element.contest_start),
|
||||
contest_end.push(element.contest_end),
|
||||
created_at.push(element.created_at)
|
||||
});
|
||||
}
|
||||
where = { uid, contest_name, contest_organizers, contest_term, type, status, online_start, online_end, offline_start, offline_end, contest_start, contest_end, created_at };
|
||||
}
|
||||
const resultList = await ctx.model4.Contest.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editContest";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除竞赛信息
|
||||
async delContest(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除竞赛信息',
|
||||
type: 0,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemMonitoring.status = 1;
|
||||
else if (result.dataValues.role < 9) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { uid, contest_name, contest_organizers, contest_term, type, status, online_start, online_end, offline_start, offline_end, contest_start, contest_end, created_at } = requestMsg;
|
||||
where = { uid, contest_name, contest_organizers, contest_term, type, status, online_start, online_end, offline_start, offline_end, contest_start, contest_end, created_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], contest_name = [], contest_organizers = [], contest_term = [], type = [], status = [], online_start = [], online_end = [], offline_start = [], offline_end = [], contest_start = [], contest_end = [], created_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid),
|
||||
contest_name.push(element.contest_name),
|
||||
contest_organizers.push(element.contest_organizers),
|
||||
contest_term.push(element.contest_term),
|
||||
type.push(element.type),
|
||||
status.push(element.status),
|
||||
online_start.push(element.online_start),
|
||||
online_end.push(element.online_end),
|
||||
offline_start.push(element.offline_start),
|
||||
offline_end.push(element.offline_end),
|
||||
contest_start.push(element.contest_start),
|
||||
contest_end.push(element.contest_end),
|
||||
created_at.push(element.created_at)
|
||||
});
|
||||
}
|
||||
where = { uid, contest_name, contest_organizers, contest_term, type, status, online_start, online_end, offline_start, offline_end, contest_start, contest_end, created_at };
|
||||
}
|
||||
const resultList = await ctx.model4.Contest.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "delContest";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出竞赛信息
|
||||
async downloadContest(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['uid', 'contest_name', 'contest_organizers', 'contest_term', 'type', 'status', 'online_start', 'online_end', 'offline_start', 'offline_end', 'contest_start', 'contest_end', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'contest_name', 'contest_organizers', 'contest_term'],
|
||||
key = ['type', 'status'],
|
||||
between = ['online_start', 'online_end', 'offline_start', 'offline_end', 'contest_start', 'contest_end', 'created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model4.Contest.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const typeOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "线上赛"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "线下赛"
|
||||
}
|
||||
];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "正常进行"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "停止举办"
|
||||
}
|
||||
];
|
||||
result.forEach(element => {
|
||||
typeOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["type"]) {
|
||||
element.dataValues["type"] = item.label;
|
||||
}
|
||||
});
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.online_start = moment
|
||||
.utc(element.dataValues.online_start)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.online_end = moment
|
||||
.utc(element.dataValues.online_end)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.offline_start = moment
|
||||
.utc(element.dataValues.offline_start)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.offline_end = moment
|
||||
.utc(element.dataValues.offline_end)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.contest_start = moment
|
||||
.utc(element.dataValues.contest_start)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.contest_end = moment
|
||||
.utc(element.dataValues.contest_end)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadContest";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestMsgService;
|
||||
@@ -4,6 +4,8 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "ContestChoiceTopic";
|
||||
|
||||
class ContestChoiceTopicService extends Service {
|
||||
@@ -95,11 +97,11 @@ class ContestChoiceTopicService extends Service {
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
topic.push(element.topic),
|
||||
options_a.push(element.options_a),
|
||||
options_b.push(element.options_b),
|
||||
options_c.push(element.options_c),
|
||||
options_d.push(element.options_d),
|
||||
answer.push(element.answer)
|
||||
options_a.push(element.options_a),
|
||||
options_b.push(element.options_b),
|
||||
options_c.push(element.options_c),
|
||||
options_d.push(element.options_d),
|
||||
answer.push(element.answer)
|
||||
});
|
||||
}
|
||||
where = { topic, options_a, options_b, options_c, options_d, answer };
|
||||
@@ -144,11 +146,11 @@ class ContestChoiceTopicService extends Service {
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
topic.push(element.topic),
|
||||
options_a.push(element.options_a),
|
||||
options_b.push(element.options_b),
|
||||
options_c.push(element.options_c),
|
||||
options_d.push(element.options_d),
|
||||
answer.push(element.answer)
|
||||
options_a.push(element.options_a),
|
||||
options_b.push(element.options_b),
|
||||
options_c.push(element.options_c),
|
||||
options_d.push(element.options_d),
|
||||
answer.push(element.answer)
|
||||
});
|
||||
}
|
||||
where = { topic, options_a, options_b, options_c, options_d, answer };
|
||||
@@ -164,6 +166,59 @@ class ContestChoiceTopicService extends Service {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出选择题
|
||||
async downloadChoiceTopic(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['topic', 'options_a', 'options_b', 'options_c', 'options_d', 'answer'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['topic', 'options_a', 'options_b', 'options_c', 'options_d', 'answer'],
|
||||
key = [],
|
||||
between = [];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model4.ChoiceTopic.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
result.forEach(element => {
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadChoiceTopic";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestChoiceTopicService;
|
||||
@@ -4,6 +4,8 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "Insiders";
|
||||
|
||||
class InsidersService extends Service {
|
||||
@@ -64,9 +66,9 @@ class InsidersService extends Service {
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
if(element == 'role' && searchOptions[element] == 99) {
|
||||
if (element == 'role' && searchOptions[element] == 99) {
|
||||
where.role = { [Op.not]: 99 };
|
||||
} else{
|
||||
} else {
|
||||
where[element] = searchOptions[element];
|
||||
}
|
||||
} else if (between.includes(element)) {
|
||||
@@ -188,6 +190,118 @@ class InsidersService extends Service {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出系统用户
|
||||
async downloadInsiders(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['uid', 'status', 'role', 'name', 'department', 'change', 'created_at', 'updated_at', 'login_at', 'login_status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'name', 'department', 'change'],
|
||||
key = ['status', 'role', 'login_status'],
|
||||
between = ['created_at', 'updated_at', 'login_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model3.Insiders.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "默认"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "正在使用"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "已弃用"
|
||||
}
|
||||
];
|
||||
const roleOptions = [
|
||||
{
|
||||
value: "99",
|
||||
label: "超级管理员"
|
||||
},
|
||||
{
|
||||
value: "0",
|
||||
label: "临时员工"
|
||||
},
|
||||
{
|
||||
value: "3",
|
||||
label: "普通用户"
|
||||
},
|
||||
{
|
||||
value: "6",
|
||||
label: "普通管理员"
|
||||
},
|
||||
{
|
||||
value: "9",
|
||||
label: "高级管理员"
|
||||
}
|
||||
];
|
||||
result.forEach(element => {
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
roleOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["role"]) {
|
||||
element.dataValues["role"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.updated_at = moment
|
||||
.utc(element.dataValues.updated_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.login_at = moment
|
||||
.utc(element.dataValues.login_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
delete element.dataValues.login_status;
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadInsiders";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InsidersService;
|
||||
@@ -4,122 +4,250 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "Monitoring";
|
||||
|
||||
class MonitoringService extends Service {
|
||||
// 查看危险操作记录
|
||||
async showMonitoring(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['operate', 'operate_msg', 'type', 'status', 'affect_entries', 'user', 'created_at'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['operate_msg', 'user'],
|
||||
key = ['type', 'status', 'operate'],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
const insiders = await ctx.model3.Insiders.findAll({ attributes: ['uid', 'name'] });
|
||||
if (searchOptions.name) {
|
||||
if (searchOptions.name == '*空') {
|
||||
where.user = [null, ''];
|
||||
} else {
|
||||
let uidArr = [];
|
||||
insiders.filter(item => {
|
||||
if (item.dataValues.name.includes(searchOptions.name)) {
|
||||
uidArr.push(item.dataValues.uid);
|
||||
}
|
||||
});
|
||||
where.user = [...uidArr];
|
||||
}
|
||||
// 查看危险操作记录
|
||||
async showMonitoring(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['operate', 'operate_msg', 'type', 'status', 'affect_entries', 'user', 'created_at'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['operate_msg', 'user'],
|
||||
key = ['type', 'status', 'operate'],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model3.Monitoring.findAndCountAll(dbOptions);
|
||||
result.rows.forEach(element => {
|
||||
element.dataValues.name = '';
|
||||
insiders.filter(item => {
|
||||
if (item.dataValues.uid == element.dataValues.user) {
|
||||
element.dataValues.name = item.dataValues.name;
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showMonitoring";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
const insiders = await ctx.model3.Insiders.findAll({ attributes: ['uid', 'name'] });
|
||||
if (searchOptions.name) {
|
||||
if (searchOptions.name == '*空') {
|
||||
where.user = [null, ''];
|
||||
} else {
|
||||
let uidArr = [];
|
||||
insiders.filter(item => {
|
||||
if (item.dataValues.name.includes(searchOptions.name)) {
|
||||
uidArr.push(item.dataValues.uid);
|
||||
}
|
||||
});
|
||||
where.user = [...uidArr];
|
||||
}
|
||||
}
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model3.Monitoring.findAndCountAll(dbOptions);
|
||||
result.rows.forEach(element => {
|
||||
element.dataValues.name = '';
|
||||
insiders.filter(item => {
|
||||
if (item.dataValues.uid == element.dataValues.user) {
|
||||
element.dataValues.name = item.dataValues.name;
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showMonitoring";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除危险操作记录
|
||||
async deleteMonitoring(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除危险操作记录',
|
||||
type: 2,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemMonitoring.status = 1;
|
||||
else if (result.dataValues.role < 9) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user, created_at } = requestMsg;
|
||||
where = { user, created_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let user = [], created_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user.push(element.user),
|
||||
created_at.push(element.created_at)
|
||||
});
|
||||
}
|
||||
where = { user, created_at };
|
||||
}
|
||||
const resultList = await ctx.model3.Monitoring.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteMonitoring";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
// 删除危险操作记录
|
||||
async deleteMonitoring(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除危险操作记录',
|
||||
type: 2,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemMonitoring.status = 1;
|
||||
else if (result.dataValues.role < 9) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { user, created_at } = requestMsg;
|
||||
where = { user, created_at };
|
||||
} else if (modelType == "multiple") {
|
||||
let user = [], created_at = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
user.push(element.user),
|
||||
created_at.push(element.created_at)
|
||||
});
|
||||
}
|
||||
where = { user, created_at };
|
||||
}
|
||||
const resultList = await ctx.model3.Monitoring.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteMonitoring";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出监控记录
|
||||
async downloadMonitoring(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['operate', 'operate_msg', 'type', 'status', 'affect_entries', 'user', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['operate_msg', 'affect_entries', 'user'],
|
||||
key = ['operate', 'type', 'status'],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.mode3.Monitoring.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const operateOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "新增数据"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "编辑数据"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "删除数据"
|
||||
}
|
||||
];
|
||||
const typeOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "一般等级"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "重要等级"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "严重等级"
|
||||
}
|
||||
];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "因无用户身份未成功执行"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "因密码错误未成功执行"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "因权限不足未成功执行"
|
||||
},
|
||||
{
|
||||
value: "3",
|
||||
label: "因查询条件错误未成功执行"
|
||||
},
|
||||
{
|
||||
value: "4",
|
||||
label: "成功执行"
|
||||
},
|
||||
{
|
||||
value: "5",
|
||||
label: "因程序错误未成功执行"
|
||||
},
|
||||
];
|
||||
result.forEach(element => {
|
||||
operateOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["operate"]) {
|
||||
element.dataValues["operate"] = item.label;
|
||||
}
|
||||
});
|
||||
typeOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["type"]) {
|
||||
element.dataValues["type"] = item.label;
|
||||
}
|
||||
});
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadMonitoring";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MonitoringService;
|
||||
@@ -4,6 +4,8 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "Organization";
|
||||
|
||||
class OrganizationService extends Service {
|
||||
@@ -166,6 +168,67 @@ class OrganizationService extends Service {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出B端用户单位
|
||||
async downloadOrganization(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['uid', 'organization_name', 'address', 'liaison_name', 'phone', 'email', 'other_information', 'post_code', 'created_at', 'updated_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['uid', 'organization_name', 'address', 'liaison_name', 'phone', 'email', 'other_information', 'post_code'],
|
||||
key = [],
|
||||
between = ['created_at', 'updated_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model3.Organization.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
result.forEach(element => {
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.updated_at = moment
|
||||
.utc(element.dataValues.updated_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadOrganization";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OrganizationService;
|
||||
@@ -4,202 +4,299 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "SNAdmin";
|
||||
|
||||
class SNAdminService extends Service {
|
||||
// 搜索可分配的SN号
|
||||
async searchAllocationSN() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const where = { status: 0 };
|
||||
const result = await ctx.model3.SNNumber.findAll({ attributes: ['sn_number'], where });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchAllocationSN";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
// 搜索可分配的SN号
|
||||
async searchAllocationSN() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const where = { status: 0 };
|
||||
const result = await ctx.model3.SNNumber.findAll({ attributes: ['sn_number'], where });
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchAllocationSN";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索可分配的单位用户
|
||||
async searchAllocationUser() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const where = { status: { [Op.not]: 2 }, role: 1 };
|
||||
const bside = await ctx.model.BSide.findAll({ attributes: ['uid', 'account_name'], where });
|
||||
const buser = await ctx.model.BuserSNAdmin.findAll({ attributes: ['user_uid'] });
|
||||
let result = [];
|
||||
bside.forEach(element => {
|
||||
buser.filter(item => {
|
||||
if (item.dataValues.user_uid !== element.dataValues.uid) {
|
||||
result.push(element);
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchAllocationUser";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
// 搜索可分配的单位用户
|
||||
async searchAllocationUser(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const { mode } = body;
|
||||
const where = { status: { [Op.not]: 2 }, role: 1 };
|
||||
const bside = await ctx.model.BSide.findAll({ attributes: ['uid', 'account_name'], where });
|
||||
const buser = await ctx.model.BuserSNAdmin.findAll({ attributes: ['user_uid', 'length', 'sn_set'] });
|
||||
if (buser.length == 0) return false;
|
||||
const buserUidArr = [];
|
||||
let result = [];
|
||||
bside.forEach(element => {
|
||||
buser.filter(item => {
|
||||
buserUidArr.push(item.dataValues.user_uid);
|
||||
if (mode && item.dataValues.user_uid == element.dataValues.uid && item.dataValues.length > item.dataValues.sn_set.split(',').length) {
|
||||
element.dataValues.length = item.dataValues.length;
|
||||
element.dataValues.sn_set = item.dataValues.sn_set;
|
||||
result.push(element);
|
||||
}else if (!mode && item.dataValues.user_uid == element.dataValues.uid) {
|
||||
element.dataValues.length = item.dataValues.length;
|
||||
element.dataValues.sn_set = item.dataValues.sn_set;
|
||||
result.push(element);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (mode) {
|
||||
const buserUidSet = new Set(buserUidArr);
|
||||
bside.filter(element => !buserUidSet.has(element.dataValues.uid)).forEach(item => {
|
||||
item.dataValues.length = 0;
|
||||
item.dataValues.sn_set = '';
|
||||
result.push(item);
|
||||
});
|
||||
}
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchAllocationUser";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// B端分配SN号
|
||||
async allocationSN(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 6) return false;
|
||||
const { user_uid, length, sn_set } = body;
|
||||
const adminResult = await ctx.model.BuserSNAdmin.create({ user_uid, length, sn_set });
|
||||
if (adminResult == 0) return false;
|
||||
const where = { sn_number: sn_set.split(',') };
|
||||
const updateMsg = { status: 4, updated_at: new Date() };
|
||||
const resultList = await ctx.model3.SNNumber.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "allocationSN";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
// B端分配SN号
|
||||
async allocationSN(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 6) return false;
|
||||
const { user_uid, length, sn_set } = body;
|
||||
let status, sn_number;
|
||||
const existence = await ctx.model.BuserSNAdmin.findOne({ attributes: ['sn_set'], where: { user_uid: user_uid } });
|
||||
if (existence) {
|
||||
const adminResult = await ctx.model.BuserSNAdmin.update({ length, sn_set }, { where: { user_uid: user_uid } });
|
||||
if (adminResult[0] == 0) return false;
|
||||
const newSNArr = sn_set.split(',');
|
||||
const oldSNArr = existence.dataValues.sn_set.split(',');
|
||||
if (newSNArr.length > oldSNArr.length) {
|
||||
status = 4;
|
||||
sn_number = newSNArr.filter(item => !oldSNArr.includes(item));
|
||||
} else if (newSNArr.length < oldSNArr.length) {
|
||||
status = 0;
|
||||
sn_number = oldSNArr.filter(item => !newSNArr.includes(item));
|
||||
}
|
||||
} else {
|
||||
const adminResult = await ctx.model.BuserSNAdmin.create({ user_uid, length, sn_set });
|
||||
if (adminResult == 0) return false;
|
||||
status = 4;
|
||||
sn_number = sn_set.split(',');
|
||||
}
|
||||
const where = { sn_number };
|
||||
const updateMsg = { status, updated_at: new Date() };
|
||||
const resultList = await ctx.model3.SNNumber.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "allocationSN";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 查看B端SN号分配记录
|
||||
async showAllocationSNRecord(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['user_uid', 'length', 'sn_set'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['user_uid', 'sn_set'],
|
||||
key = ['length'],
|
||||
between = [];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
// const [bside, bsideSNRecord] = await Promise.all([
|
||||
// ctx.model.BSide.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
// ctx.model.BindBSNrecord.findAll({ attributes: ['user_uid', 'sn_number', 'type'] })
|
||||
// ]);
|
||||
// if (searchOptions.account_name) {
|
||||
// if (searchOptions.account_name == '*空') {
|
||||
// where.user_uid = [null, ''];
|
||||
// } else {
|
||||
// let userArr = [], lengthArr = [], SNArr = [];
|
||||
// bside.filter(item => {
|
||||
// if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
// bsideSNRecord.filter(item2 => {
|
||||
// if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
// userArr.push(item2.dataValues.user_uid);
|
||||
// lengthArr.push(item2.dataValues.length);
|
||||
// SNArr.push(item2.dataValues.sn_set);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// where.user_uid = [...userArr];
|
||||
// where.length = [...lengthArr];
|
||||
// where.sn_set = [...SNArr];
|
||||
// }
|
||||
// }
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
// let result;
|
||||
dbOptions.limit = Math.floor(limit / 2);
|
||||
dbOptions.offset = Math.floor(offset / 2);
|
||||
// const [bresult] = await Promise.all([
|
||||
// ctx.model.BuserSNAdmin.findAndCountAll(dbOptions)
|
||||
// ]);
|
||||
// result = {
|
||||
// count: bresult.count,
|
||||
// rows: bresult.rows
|
||||
// };
|
||||
const bside = await ctx.model.BSide.findAll({ attributes: ['uid', 'account_name'] });
|
||||
const result = await ctx.model.BuserSNAdmin.findAndCountAll(dbOptions);
|
||||
result.rows.forEach(element => {
|
||||
element.dataValues.account_name = '';
|
||||
bside.filter(item => {
|
||||
if (item.dataValues.uid == element.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item.dataValues.account_name;
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showAllocationSNRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除B端SN号分配记录
|
||||
async deleteAllocationSNRecord(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemSNAdmin = {
|
||||
operate: 2,
|
||||
operate_msg: '删除SN号分配记录',
|
||||
type: 1,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemSNAdmin.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemSNAdmin.status = 1;
|
||||
else if (result.dataValues.role < 9) systemSNAdmin.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemSNAdmin);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { sn_set } = requestMsg;
|
||||
where = { sn_set };
|
||||
} else if (modelType == "multiple") {
|
||||
let sn_set = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
sn_set.push(element.sn_set)
|
||||
});
|
||||
}
|
||||
where = { sn_set };
|
||||
// 查看B端SN号分配记录
|
||||
async showAllocationSNRecord(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['user_uid', 'length', 'sn_set'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['user_uid', 'sn_set'],
|
||||
key = ['length'],
|
||||
between = [];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
const [bresultList] = await Promise.all([
|
||||
ctx.model.BuserSNAdmin.destroy({ where })
|
||||
]);
|
||||
systemSNAdmin.status = bresultList == 0 ? 3 : 4;
|
||||
systemSNAdmin.affect_entries = bresultList;
|
||||
await ctx.model3.Monitoring.create(systemSNAdmin);
|
||||
return bresultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemSNAdmin.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemSNAdmin);
|
||||
const blockName = fileName + "--" + "deleteAllocationSNRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
// const [bside, bsideSNRecord] = await Promise.all([
|
||||
// ctx.model.BSide.findAll({ attributes: ['uid', 'account_name'] }),
|
||||
// ctx.model.BindBSNrecord.findAll({ attributes: ['user_uid', 'sn_number', 'type'] })
|
||||
// ]);
|
||||
// if (searchOptions.account_name) {
|
||||
// if (searchOptions.account_name == '*空') {
|
||||
// where.user_uid = [null, ''];
|
||||
// } else {
|
||||
// let userArr = [], lengthArr = [], SNArr = [];
|
||||
// bside.filter(item => {
|
||||
// if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
// bsideSNRecord.filter(item2 => {
|
||||
// if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
// userArr.push(item2.dataValues.user_uid);
|
||||
// lengthArr.push(item2.dataValues.length);
|
||||
// SNArr.push(item2.dataValues.sn_set);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
// where.user_uid = [...userArr];
|
||||
// where.length = [...lengthArr];
|
||||
// where.sn_set = [...SNArr];
|
||||
// }
|
||||
// }
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
// let result;
|
||||
dbOptions.limit = Math.floor(limit / 2);
|
||||
dbOptions.offset = Math.floor(offset / 2);
|
||||
// const [bresult] = await Promise.all([
|
||||
// ctx.model.BuserSNAdmin.findAndCountAll(dbOptions)
|
||||
// ]);
|
||||
// result = {
|
||||
// count: bresult.count,
|
||||
// rows: bresult.rows
|
||||
// };
|
||||
const bside = await ctx.model.BSide.findAll({ attributes: ['uid', 'account_name'] });
|
||||
const result = await ctx.model.BuserSNAdmin.findAndCountAll(dbOptions);
|
||||
result.rows.forEach(element => {
|
||||
element.dataValues.account_name = '';
|
||||
bside.filter(item => {
|
||||
if (item.dataValues.uid == element.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item.dataValues.account_name;
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showAllocationSNRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除B端SN号分配记录
|
||||
async deleteAllocationSNRecord(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemSNAdmin = {
|
||||
operate: 2,
|
||||
operate_msg: '删除SN号分配记录',
|
||||
type: 1,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 9) {
|
||||
if (!result) systemSNAdmin.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemSNAdmin.status = 1;
|
||||
else if (result.dataValues.role < 9) systemSNAdmin.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemSNAdmin);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { sn_set } = requestMsg;
|
||||
where = { sn_set };
|
||||
} else if (modelType == "multiple") {
|
||||
let sn_set = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
sn_set.push(element.sn_set)
|
||||
});
|
||||
}
|
||||
where = { sn_set };
|
||||
}
|
||||
const [bresultList] = await Promise.all([
|
||||
ctx.model.BuserSNAdmin.destroy({ where })
|
||||
]);
|
||||
systemSNAdmin.status = bresultList == 0 ? 3 : 4;
|
||||
systemSNAdmin.affect_entries = bresultList;
|
||||
await ctx.model3.Monitoring.create(systemSNAdmin);
|
||||
return bresultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemSNAdmin.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemSNAdmin);
|
||||
const blockName = fileName + "--" + "deleteAllocationSNRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出B端SN号分配记录
|
||||
async downloadAllocationSNRecord(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['user_uid', 'length', 'sn_set'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['user_uid', 'length', 'sn_set'],
|
||||
key = [],
|
||||
between = [];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const [bresult, cresult] = await Promise.all([
|
||||
ctx.model.BuserSNAdmin.findAll(dbOptions),
|
||||
ctx.model2.CuserSNAdmin.findAll(dbOptions)
|
||||
]);
|
||||
if (bresult.length == 0 && cresult.length == 0) return { code: false };
|
||||
let data = [];
|
||||
bresult.forEach(element => {
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
cresult.forEach(element => {
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadAllocationSNRecord";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SNAdminService;
|
||||
115
app/service/SNContest.js
Normal file
115
app/service/SNContest.js
Normal file
@@ -0,0 +1,115 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "SNContest";
|
||||
|
||||
class SNContestService extends Service {
|
||||
// 获取SN号竞赛消息
|
||||
async getSNContestMsg(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions, fiexdData } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['original_msg', 'sn_number', 'msg_data', 'created_at'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['original_msg', 'msg_data'], key = [], between = [];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element] == "1" ? true : false;
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
if (fiexdData !== undefined) {
|
||||
where.sn_number = fiexdData.SNArr;
|
||||
where.created_at = { [Op.between]: [fiexdData.time_at.contest_start, fiexdData.time_at.contest_end] }
|
||||
}
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model.BSnMsg.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "getSNContestMsg";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出SN号竞赛消息
|
||||
async downloadSNConest(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['user_uid', 'sn_number', 'original_msg', 'msg_data', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['user_uid', 'sn_number', 'original_msg', 'msg_data'],
|
||||
key = [],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model.BSnMsg.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
result.forEach(element => {
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadSNConest";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SNContestService;
|
||||
@@ -4,6 +4,8 @@ const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "SN";
|
||||
|
||||
class SNService extends Service {
|
||||
@@ -218,6 +220,94 @@ class SNService extends Service {
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出SN号
|
||||
async downloadSN(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['sn_number', 'status', 'created_at', 'updated_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['sn_number'],
|
||||
key = ['status'],
|
||||
between = ['created_at', 'updated_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model3.SNNumber.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
const statusOptions = [
|
||||
{
|
||||
value: "0",
|
||||
label: "未绑定"
|
||||
},
|
||||
{
|
||||
value: "1",
|
||||
label: "B端绑定"
|
||||
},
|
||||
{
|
||||
value: "2",
|
||||
label: "C端绑定"
|
||||
},
|
||||
{
|
||||
value: "3",
|
||||
label: "竞赛绑定"
|
||||
},
|
||||
{
|
||||
value: "4",
|
||||
label: "B端预绑定"
|
||||
}
|
||||
];
|
||||
result.forEach(element => {
|
||||
statusOptions.forEach((item) => {
|
||||
if (item.value == element.dataValues["status"]) {
|
||||
element.dataValues["status"] = item.label;
|
||||
}
|
||||
});
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
element.dataValues.updated_at = moment
|
||||
.utc(element.dataValues.updated_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadSN";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SNService;
|
||||
164
app/service/UnknownBDCard.js
Normal file
164
app/service/UnknownBDCard.js
Normal file
@@ -0,0 +1,164 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "UnknownBDCard";
|
||||
|
||||
class UnknownBDCardService extends Service {
|
||||
// 查看未知消息
|
||||
async showUnknownBDCard(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['card_id', 'original_msg', 'msg_data', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['card_id', 'original_msg', 'msg_data'],
|
||||
key = [],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model3.UnknownBDCard.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showUnknownBDCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除未知消息
|
||||
async deleteUnknownBDCard(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除未知消息',
|
||||
type: 0,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 6) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemMonitoring.status = 1;
|
||||
else if (result.dataValues.role < 6) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
where = requestMsg;
|
||||
} else if (modelType == "multiple") {
|
||||
let original_msg = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
original_msg.push(element.original_msg);
|
||||
});
|
||||
}
|
||||
where = { original_msg };
|
||||
}
|
||||
const resultList = await ctx.model3.UnknownBDCard.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteUnknownBDCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出竞赛账号信息
|
||||
async downloadUnknownBDCard(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['card_id', 'original_msg', 'msg_data', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['card_id', 'original_msg', 'msg_data'],
|
||||
key = [],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model3.UnknownBDCard.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
result.forEach(element => {
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadUnknownBDCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UnknownBDCardService;
|
||||
164
app/service/UnknownSN.js
Normal file
164
app/service/UnknownSN.js
Normal file
@@ -0,0 +1,164 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const moment = require('moment');
|
||||
|
||||
const fileName = "UnknownSN";
|
||||
|
||||
class UnknownSNService extends Service {
|
||||
// 查看未知消息
|
||||
async showUnknownSN(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['msg_id', 'sn_number', 'original_msg', 'msg_data', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['msg_id', 'sn_number', 'original_msg', 'msg_data'],
|
||||
key = [],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model3.UnknownSN.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showUnknownSN";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除未知消息
|
||||
async deleteUnknownSN(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除未知消息',
|
||||
type: 0,
|
||||
status: 0,
|
||||
affect_entries: 0,
|
||||
user: uid,
|
||||
created_at: new Date()
|
||||
};
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt)) || result.dataValues.role < 6) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.password !== this.shaForm(password, this.decryptRequest(result.dataValues.salt))) systemMonitoring.status = 1;
|
||||
else if (result.dataValues.role < 6) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
where = requestMsg;
|
||||
} else if (modelType == "multiple") {
|
||||
let original_msg = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
original_msg.push(element.original_msg);
|
||||
});
|
||||
}
|
||||
where = { original_msg };
|
||||
}
|
||||
const resultList = await ctx.model3.UnknownSN.destroy({ where });
|
||||
systemMonitoring.status = resultList == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "deleteUnknownSN";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出竞赛账号信息
|
||||
async downloadUnknownSN(uid, searchMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const user = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!user || user.dataValues.role < 3) return false;
|
||||
let { searchOptions, sortOptions } = searchMsg;
|
||||
let attributes = ['msg_id', 'sn_number', 'original_msg', 'msg_data', 'created_at'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = [],
|
||||
substring = ['msg_id', 'sn_number', 'original_msg', 'msg_data'],
|
||||
key = [],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, where, order };
|
||||
const result = await ctx.model3.UnknownSN.findAll(dbOptions);
|
||||
if (result.length == 0) return { code: false };
|
||||
let data = [];
|
||||
result.forEach(element => {
|
||||
element.dataValues.created_at = moment
|
||||
.utc(element.dataValues.created_at)
|
||||
.add(8, "hours")
|
||||
.format("YYYY年MM月DD日HH时mm分ss秒");
|
||||
data.push(element.dataValues);
|
||||
});
|
||||
return { code: true, data };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadUnknownSN";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UnknownSNService;
|
||||
Reference in New Issue
Block a user