北斗启航科技教育平台管理系统
This commit is contained in:
149
app/controller/BSide.js
Normal file
149
app/controller/BSide.js
Normal file
@@ -0,0 +1,149 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "BSide";
|
||||
|
||||
class BSideController extends Controller {
|
||||
// 注册B端用户
|
||||
async addBSide() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
const salt = this.generateRandomString();
|
||||
element.uid = this.generateNumberString('B');
|
||||
element.salt = this.encryptRequest(salt);
|
||||
element.status = 0;
|
||||
element.role = this.decryptRequest(element.role);
|
||||
element.account_name = this.decryptRequest(element.account_name);
|
||||
element.password = this.shaForm('123456', salt);
|
||||
element.organization = element.organization == "" ? null : this.decryptRequest(element.organization);
|
||||
element.user_name = element.user_name == "" ? "" : this.decryptRequest(element.user_name);
|
||||
element.phone = element.phone == "" ? "" : this.decryptRequest(element.phone);
|
||||
element.msg = element.msg == "" ? "" : this.decryptRequest(element.msg);
|
||||
element.created_at = new Date();
|
||||
element.updated_at = new Date();
|
||||
element.login_at = new Date();
|
||||
element.login_status = 0;
|
||||
});
|
||||
const result = await ctx.service.bSide.addBSide(requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '创建B端新用户成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '创建B端新用户失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addBSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 查看B端用户
|
||||
async showBSide() {
|
||||
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.bSide.showBSide(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let BSideMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
BSideMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
BSideMsg: BSideMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索B端用户成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索B端用户失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑B端用户
|
||||
async editBSide() {
|
||||
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.bSide.editBSide(uid, modelType, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '编辑B端用户信息成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '编辑B端用户信息失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editBSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除B端用户
|
||||
async deleteBSide() {
|
||||
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.bSide.deleteBSide(uid, modelType, deCodePassword, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '删除B端用户成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '删除B端用户失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "deleteBSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BSideController;
|
||||
141
app/controller/BdCard.js
Normal file
141
app/controller/BdCard.js
Normal file
@@ -0,0 +1,141 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "BdCard";
|
||||
|
||||
class BdCardController extends Controller {
|
||||
// 注册北斗卡
|
||||
async addBdCard() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
element.card_id = this.decryptRequest(element.card_id);
|
||||
element.card_imsi = this.decryptRequest(element.card_imsi);
|
||||
element.type = 0;
|
||||
element.status = 0;
|
||||
element.created_at = new Date();
|
||||
element.updated_at = new Date();
|
||||
});
|
||||
const result = await ctx.service.bdCard.addBdCard(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 + "--" + "addBdCard";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 查看北斗卡
|
||||
async showBdCard() {
|
||||
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.bdCard.showBdCard(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let bdCardMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
bdCardMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
bdCardMsg: bdCardMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索北斗卡成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索北斗卡失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBdCard";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑北斗卡
|
||||
async editBdCard() {
|
||||
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, updateMsg, requestMsg } = body
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.bdCard.editBdCard(uid, modelType, deCodePassword, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '编辑北斗卡成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '编辑北斗卡失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editBdCard";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除北斗卡
|
||||
async deleteBdCard() {
|
||||
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.bdCard.deleteBdCard(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 + "--" + "deleteBdCard";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BdCardController;
|
||||
75
app/controller/BindRecord.js
Normal file
75
app/controller/BindRecord.js
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "BindRecord";
|
||||
|
||||
class BindRecordController extends Controller {
|
||||
// 查看北斗卡绑定记录
|
||||
async showBindRecord() {
|
||||
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.bindRecord.showBindRecord(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let BindRecordMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
BindRecordMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
BindRecordMsg: BindRecordMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索北斗卡绑定记录成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索北斗卡绑定记录失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBindRecord";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除北斗卡绑定记录
|
||||
async deleteBindRecord() {
|
||||
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.bindRecord.deleteBindRecord(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 + "--" + "deleteBindRecord";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BindRecordController;
|
||||
75
app/controller/BindSNRecord.js
Normal file
75
app/controller/BindSNRecord.js
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "BindSNRecord";
|
||||
|
||||
class BindSNRecordController extends Controller {
|
||||
// 查看SN号绑定记录
|
||||
async showBindSNRecord() {
|
||||
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.bindSNRecord.showBindSNRecord(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let BindSNRecordMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
BindSNRecordMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
BindSNRecordMsg: BindSNRecordMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索SN号绑定记录成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索SN号绑定记录失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBindSNRecord";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除SN号绑定记录
|
||||
async deleteBindSNRecord() {
|
||||
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.bindSNRecord.deleteBindSNRecord(uid, modelType, deCodePassword, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '删除SN号绑定记录成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '删除SN号绑定记录失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "deleteBindSNRecord";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BindSNRecordController;
|
||||
207
app/controller/Business.js
Normal file
207
app/controller/Business.js
Normal file
@@ -0,0 +1,207 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Business";
|
||||
|
||||
class BusinessController extends Controller {
|
||||
// 注册公司业务
|
||||
async addBusiness() {
|
||||
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 requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
const salt = this.generateRandomString();
|
||||
element.salt = this.encryptRequest(salt);
|
||||
element.login_url = this.decryptRequest(element.login_url);
|
||||
element.client_url = this.decryptRequest(element.client_url);
|
||||
element.temporary_id = this.decryptRequest(element.temporary_id) == 'true' ? this.shaForm(this.generateRandomString(), salt) : this.decryptRequest(element.temporary_id);
|
||||
element.client_id = this.generateClientId();
|
||||
element.client_secret = this.shaForm(this.generateRandomString(), salt);
|
||||
element.name = this.decryptRequest(element.name);
|
||||
element.type = element.type ? this.decryptRequest(element.type) : 2;
|
||||
element.level = element.level ? this.decryptRequest(element.level) : 0;
|
||||
element.status = element.status ? this.decryptRequest(element.status) : 0;
|
||||
element.created_at = new Date();
|
||||
element.updated_at = new Date();
|
||||
});
|
||||
const result = await ctx.service.business.addBusiness(uid, 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 + "--" + "addBusiness";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 查看公司业务
|
||||
async showBusiness() {
|
||||
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.showBusiness(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let BusinessMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
BusinessMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
BusinessMsg: BusinessMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索公司业务成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索公司业务失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBusiness";
|
||||
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() {
|
||||
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, password } = body
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
let salt;
|
||||
if (updateMsg.salt) {
|
||||
salt = this.generateRandomString();
|
||||
updateMsg.salt = this.encryptRequest(salt);
|
||||
} else {
|
||||
delete updateMsg.salt;
|
||||
}
|
||||
if (!updateMsg.temporary_id) {
|
||||
delete updateMsg.temporary_id;
|
||||
} else if (updateMsg.temporary_id == 'true') {
|
||||
updateMsg.temporary_id = this.shaForm(this.generateRandomString(), salt);
|
||||
}
|
||||
if (updateMsg.client_id) {
|
||||
updateMsg.client_id = this.generateClientId();
|
||||
} else {
|
||||
delete updateMsg.client_id;
|
||||
}
|
||||
if (updateMsg.client_secret) {
|
||||
updateMsg.client_secret = this.shaForm(this.generateRandomString(), salt);
|
||||
} else {
|
||||
delete updateMsg.client_secret;
|
||||
}
|
||||
const result = await ctx.service.business.editBusiness(uid, modelType, deCodePassword, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '编辑公司业务成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '编辑公司业务失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editBusiness";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除公司业务
|
||||
async deleteBusiness() {
|
||||
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.business.deleteBusiness(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 + "--" + "deleteBusiness";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BusinessController;
|
||||
106
app/controller/CSide.js
Normal file
106
app/controller/CSide.js
Normal file
@@ -0,0 +1,106 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
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 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CSideController;
|
||||
209
app/controller/ContestAccount.js
Normal file
209
app/controller/ContestAccount.js
Normal file
@@ -0,0 +1,209 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "ContestAccount";
|
||||
|
||||
class ContestAccountController extends Controller {
|
||||
// 管理系统导入竞赛账号信息
|
||||
async importAccount() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
const salt = this.generateRandomString();
|
||||
element.uid = this.generateNumberString('T');
|
||||
element.salt = this.encryptRequest(salt);
|
||||
element.contest_uid = this.decryptRequest(element.contest_uid);
|
||||
element.account_name = this.decryptRequest(element.account_name);
|
||||
element.password = this.shaForm('123456', salt);
|
||||
element.status = 0;
|
||||
element.created_at = new Date();
|
||||
element.login_status = 0;
|
||||
});
|
||||
const result = await ctx.service.contestAccount.importAccount(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 + "--" + "importAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统创建竞赛账号信息
|
||||
async addAccount() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
const salt = this.generateRandomString();
|
||||
element.uid = this.generateNumberString('T');
|
||||
element.salt = this.encryptRequest(salt);
|
||||
element.contest_uid = this.decryptRequest(element.contest_uid);
|
||||
element.account_name = this.decryptRequest(element.account_name);
|
||||
element.password = this.shaForm('123456', salt);
|
||||
element.status = 0;
|
||||
element.created_at = new Date();
|
||||
element.login_status = 0;
|
||||
});
|
||||
const result = await ctx.service.contestAccount.addAccount(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 + "--" + "addAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看竞赛账号信息
|
||||
async showAccount() {
|
||||
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.contestAccount.showAccount(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let accountMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
accountMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
accountMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑竞赛账号信息
|
||||
async editAccount() {
|
||||
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.contestAccount.editAccount(uid, modelType, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除竞赛账号信息
|
||||
async delAccount() {
|
||||
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.contestAccount.delAccount(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 + "--" + "delAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统重置竞赛账号密码
|
||||
async resetAccount() {
|
||||
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 { account_uid, password } = ctx.request.body;
|
||||
const accountUid = this.decryptRequest(account_uid);
|
||||
const resetPassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.contestAccount.resetAccount(uid, accountUid, resetPassword);
|
||||
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 + "--" + "resetAccount";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestAccountController;
|
||||
131
app/controller/ContestExamination.js
Normal file
131
app/controller/ContestExamination.js
Normal file
@@ -0,0 +1,131 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "ContestExamination";
|
||||
|
||||
class ContestExaminationController extends Controller {
|
||||
// 管理系统查看账号答题情况
|
||||
async showExamination() {
|
||||
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.contestExamination.showExamination(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let examinationMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
examinationMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
examinationMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showExamination";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑账号答题情况
|
||||
async editExamination() {
|
||||
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.contestExamination.editExamination(uid, modelType, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editExamination";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除账号答题情况
|
||||
async delExamination() {
|
||||
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.contestExamination.delExamination(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 + "--" + "delExamination";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统导出账号答题情况
|
||||
async downloadExamination() {
|
||||
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.contestExamination.downloadExamination(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "downloadExamination";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestExaminationController;
|
||||
177
app/controller/ContestMsg.js
Normal file
177
app/controller/ContestMsg.js
Normal file
@@ -0,0 +1,177 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "ContestMsg";
|
||||
|
||||
class ContestMsgController extends Controller {
|
||||
// 管理系统检索竞赛 uid
|
||||
async searchContestUid() {
|
||||
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.contestMsg.searchContestUid(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let contestUid = [];
|
||||
result.forEach(element => {
|
||||
contestUid.push({ value: element.dataValues.uid });
|
||||
});
|
||||
this.setResponse(ctx, 200, '操作成功', "polymerization", contestUid);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchContestUid";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统创建竞赛信息
|
||||
async addContest() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
element.uid = this.generateNumberString('H');
|
||||
element.contest_name = this.decryptRequest(element.contest_name);
|
||||
element.contest_organizers = this.decryptRequest(element.contest_organizers);
|
||||
element.contest_term = this.decryptRequest(element.contest_term);
|
||||
element.type = Number(element.type);
|
||||
element.status = 0;
|
||||
element.online_start = new Date(element.online_start);
|
||||
element.online_end = new Date(element.online_end);
|
||||
element.offline_start = new Date(element.offline_start);
|
||||
element.offline_end = new Date(element.offline_end);
|
||||
element.contest_start = new Date(element.contest_start);
|
||||
element.contest_end = new Date(element.contest_end);
|
||||
element.created_at = new Date();
|
||||
});
|
||||
const result = await ctx.service.contestMsg.addContest(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 + "--" + "addContest";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看竞赛信息
|
||||
async showContest() {
|
||||
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.contestMsg.showContest(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let contestMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
contestMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
contestMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showContest";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑竞赛信息
|
||||
async editContest() {
|
||||
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.contestMsg.editContest(uid, modelType, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editContest";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除竞赛信息
|
||||
async delContest() {
|
||||
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.contestMsg.delContest(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 + "--" + "delContest";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestMsgController;
|
||||
173
app/controller/ContestTopic.js
Normal file
173
app/controller/ContestTopic.js
Normal file
@@ -0,0 +1,173 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "ContestTopic";
|
||||
|
||||
class ContestTopicController extends Controller {
|
||||
// 管理系统导入选择题
|
||||
async importChoiceTopic() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
element.topic = this.decryptRequest(element.topic);
|
||||
element.options_a = this.decryptRequest(element.options_a);
|
||||
element.options_b = this.decryptRequest(element.options_b);
|
||||
element.options_c = this.decryptRequest(element.options_c);
|
||||
element.options_d = this.decryptRequest(element.options_d);
|
||||
element.answer = this.decryptRequest(element.answer);
|
||||
});
|
||||
const result = await ctx.service.contestTopic.importChoiceTopic(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 + "--" + "importChoiceTopic";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统创建选择题
|
||||
async addChoiceTopic() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
element.topic = this.decryptRequest(element.topic);
|
||||
element.options_a = this.decryptRequest(element.options_a);
|
||||
element.options_b = this.decryptRequest(element.options_b);
|
||||
element.options_c = this.decryptRequest(element.options_c);
|
||||
element.options_d = this.decryptRequest(element.options_d);
|
||||
element.answer = this.decryptRequest(element.answer);
|
||||
});
|
||||
const result = await ctx.service.contestTopic.addChoiceTopic(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 + "--" + "addChoiceTopic";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看选择题
|
||||
async showChoiceTopic() {
|
||||
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.contestTopic.showChoiceTopic(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let choiceTopicMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
choiceTopicMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
choiceTopicMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showChoiceTopic";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑选择题
|
||||
async editChoiceTopic() {
|
||||
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.contestTopic.editChoiceTopic(uid, modelType, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '操作成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '操作失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editChoiceTopic";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除选择题
|
||||
async delChoiceTopic() {
|
||||
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.contestTopic.delChoiceTopic(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 + "--" + "delChoiceTopic";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestTopicController;
|
||||
149
app/controller/Insiders.js
Normal file
149
app/controller/Insiders.js
Normal file
@@ -0,0 +1,149 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Insiders";
|
||||
|
||||
class InsidersController extends Controller {
|
||||
// 注册管理系统用户
|
||||
async addInsiders() {
|
||||
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 requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
const salt = this.generateRandomString();
|
||||
element.uid = this.generateNumberString('M');
|
||||
element.salt = this.encryptRequest(salt);
|
||||
element.status = this.decryptRequest(element.role) == '99' ? 2 : 0;
|
||||
element.role = this.decryptRequest(element.role) == '99' ? 0 : this.decryptRequest(element.role);
|
||||
element.name = this.decryptRequest(element.name);
|
||||
element.password = this.shaForm('123456', salt);
|
||||
element.department = element.department == "" ? "" : this.decryptRequest(element.department);
|
||||
element.change = this.decryptRequest(element.change);
|
||||
element.created_at = new Date();
|
||||
element.updated_at = new Date();
|
||||
element.login_at = new Date();
|
||||
element.login_status = 0;
|
||||
});
|
||||
const result = await ctx.service.insiders.addInsiders(uid, 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 + "--" + "addInsiders";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 查看管理系统用户
|
||||
async showInsiders() {
|
||||
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.insiders.showInsiders(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let InsidersMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
InsidersMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
InsidersMsg: InsidersMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索公司员工成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索公司员工失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showInsiders";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑管理系统用户
|
||||
async editInsiders() {
|
||||
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.insiders.editInsiders(uid, modelType, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '编辑公司员工账号信息成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '编辑公司员工账号信息失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editInsiders";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除管理系统用户
|
||||
async deleteInsiders() {
|
||||
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.insiders.deleteInsiders(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 + "--" + "deleteInsiders";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InsidersController;
|
||||
75
app/controller/Monitoring.js
Normal file
75
app/controller/Monitoring.js
Normal file
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Monitoring";
|
||||
|
||||
class MonitoringController extends Controller {
|
||||
// 查看危险操作记录
|
||||
async showMonitoring() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const body = ctx.request.body;
|
||||
const result = await ctx.service.monitoring.showMonitoring(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let MonitoringMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
MonitoringMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
MonitoringMsg: MonitoringMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索危险操作记录成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索危险操作记录失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showMonitoring";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除危险操作记录
|
||||
async deleteMonitoring() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const uid = JSON.parse(rdmcode).uid;
|
||||
const body = ctx.request.body;
|
||||
const { model, password, requestMsg } = body
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.monitoring.deleteMonitoring(uid, modelType, deCodePassword, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '删除危险操作记录成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '删除危险操作记录失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "deleteMonitoring";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MonitoringController;
|
||||
180
app/controller/Organization.js
Normal file
180
app/controller/Organization.js
Normal file
@@ -0,0 +1,180 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Organization";
|
||||
|
||||
class OrganizationController extends Controller {
|
||||
// 注册B端用户单位
|
||||
async addOrganization() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
element.uid = this.generateNumberString('O');
|
||||
element.organization_name = this.decryptRequest(element.organization_name);
|
||||
element.address = element.address == "" ? "" : this.decryptRequest(element.address);
|
||||
element.liaison_name = element.liaison_name == "" ? "" : this.decryptRequest(element.liaison_name);
|
||||
element.phone = element.phone == "" ? "" : this.decryptRequest(element.phone);
|
||||
element.email = element.email == "" ? "" : this.decryptRequest(element.email);
|
||||
element.other_information = element.other_information == "" ? "" : this.decryptRequest(element.other_information);
|
||||
element.post_code = element.post_code == "" ? "" : this.decryptRequest(element.post_code);
|
||||
element.created_at = new Date();
|
||||
element.updated_at = new Date();
|
||||
});
|
||||
const result = await ctx.service.organization.addOrganization(requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '新增B端用户单位成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '新增B端用户单位失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addOrganization";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 查看B端用户单位
|
||||
async showOrganization() {
|
||||
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.organization.showOrganization(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let OrganizationMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
OrganizationMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
OrganizationMsg: OrganizationMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索B端用户单位成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索B端用户单位失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showOrganization";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 远程搜索B端用户单位
|
||||
async SearchOrganization() {
|
||||
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.organization.SearchOrganization(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let organization = [];
|
||||
result.forEach(element => {
|
||||
organization.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
organization: organization,
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索B端用户信息成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索B端用户信息失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBSide";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑B端用户单位
|
||||
async editOrganization() {
|
||||
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.organization.editOrganization(uid, modelType, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '编辑B端用户单位成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '编辑B端用户单位失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editOrganization";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除B端用户单位
|
||||
async deleteOrganization() {
|
||||
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.organization.deleteOrganization(uid, modelType, deCodePassword, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '删除B端用户单位成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '删除B端用户单位失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "deleteOrganization";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OrganizationController;
|
||||
161
app/controller/SNAdmin.js
Normal file
161
app/controller/SNAdmin.js
Normal file
@@ -0,0 +1,161 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "SNAdmin";
|
||||
|
||||
class SNAdminController extends Controller {
|
||||
// 搜索可分配的SN号
|
||||
async searchAllocationSN() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const result = await ctx.service.sNAdmin.searchAllocationSN();
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
const data = {
|
||||
snArr: result
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索可分配的SN号成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索可分配的SN号失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchAllocationSN";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索可分配的单位用户
|
||||
async searchAllocationUser() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const result = await ctx.service.sNAdmin.searchAllocationUser();
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
const data = {
|
||||
userArr: result
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索可分配的单位用户成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索可分配的单位用户失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "searchAllocationUser";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// B端分配SN号
|
||||
async allocationSN() {
|
||||
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.sNAdmin.allocationSN(uid, body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, 'B端分配SN号成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, 'B端分配SN号失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "allocationSN";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 查看B端SN号分配记录
|
||||
async showAllocationSNRecord() {
|
||||
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.sNAdmin.showAllocationSNRecord(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let SNAdminMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
SNAdminMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
SNAdminMsg: SNAdminMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索SN号分配记录成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索SN号分配记录失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showAllocationSNRecord";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除B端SN号分配记录
|
||||
async deleteAllocationSNRecord() {
|
||||
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.sNAdmin.deleteAllocationSNRecord(uid, modelType, deCodePassword, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '删除SN号分配记录成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '删除SN号分配记录失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "deleteAllocationSNRecord";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SNAdminController;
|
||||
139
app/controller/Sn.js
Normal file
139
app/controller/Sn.js
Normal file
@@ -0,0 +1,139 @@
|
||||
'use strict';
|
||||
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "SN";
|
||||
|
||||
class SNController extends Controller {
|
||||
// 注册SN号
|
||||
async addSN() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const requestMsg = ctx.request.body.requestMsg;
|
||||
requestMsg.forEach(element => {
|
||||
element.sn_number = this.decryptRequest(element.sn_number);
|
||||
element.status = 0;
|
||||
element.created_at = new Date();
|
||||
element.updated_at = new Date();
|
||||
});
|
||||
const result = await ctx.service.sn.addSN(requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '导入SN号成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '导入SN号失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addSN";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 查看SN号
|
||||
async showSN() {
|
||||
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.sn.showSN(body);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
let SNMsg = [];
|
||||
result.rows.forEach(element => {
|
||||
SNMsg.push(element.dataValues);
|
||||
});
|
||||
const data = {
|
||||
SNMsg: SNMsg,
|
||||
count: result.count
|
||||
};
|
||||
this.setResponse(ctx, 200, '搜索SN号成功', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '搜索SN号失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showSN";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑SN号
|
||||
async editSN() {
|
||||
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, updateMsg, requestMsg } = body
|
||||
const modelType = this.decryptRequest(model);
|
||||
const deCodePassword = this.decryptRequest(password);
|
||||
const result = await ctx.service.sn.editSN(uid, modelType, deCodePassword, updateMsg, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '编辑SN号成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '编辑SN号失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editSN";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
|
||||
// 删除SN号
|
||||
async deleteSN() {
|
||||
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.sn.deleteSN(uid, modelType, deCodePassword, requestMsg);
|
||||
if (result == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
if (result) {
|
||||
this.setResponse(ctx, 200, '删除SN号成功', "none");
|
||||
} else {
|
||||
this.setResponse(ctx, 404, '删除SN号失败', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "deleteSN";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SNController;
|
||||
29
app/controller/home.js
Normal file
29
app/controller/home.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const { Controller } = require('egg');
|
||||
|
||||
const fileName = "home";
|
||||
|
||||
class HomeController extends Controller {
|
||||
async index() {
|
||||
const { ctx } = this;
|
||||
ctx.body = {
|
||||
code:200,
|
||||
msg:'test'
|
||||
}
|
||||
}
|
||||
async home() {
|
||||
const { ctx } = this;
|
||||
ctx.body = {
|
||||
code:200,
|
||||
msg:'home'
|
||||
}
|
||||
}
|
||||
async main() {
|
||||
const { ctx } = this;
|
||||
ctx.body = {
|
||||
code:200,
|
||||
msg:'main'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = HomeController;
|
||||
133
app/core/base_controller.js
Normal file
133
app/core/base_controller.js
Normal file
@@ -0,0 +1,133 @@
|
||||
const { Controller } = require('egg');
|
||||
|
||||
const sha256 = require("crypto-js/sha256");
|
||||
|
||||
const CryptoJS = require("crypto-js");
|
||||
|
||||
const KEY = CryptoJS.enc.Utf8.parse('BDQH');
|
||||
|
||||
class BaseController extends Controller {
|
||||
shaForm = (body, salt) => {
|
||||
return sha256(sha256(body).toString() + salt).toString();
|
||||
}
|
||||
|
||||
encryptRequest = (body) => {
|
||||
return CryptoJS.AES.encrypt(body, KEY, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
}).toString();
|
||||
}
|
||||
|
||||
decryptRequest = (body) => {
|
||||
return CryptoJS.AES.decrypt(body, KEY, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
}).toString(CryptoJS.enc.Utf8);
|
||||
}
|
||||
|
||||
// 用户uid生成函数
|
||||
generateNumberString = (side) => {
|
||||
// 获取当前日期(年月日)
|
||||
const now = new Date();
|
||||
const year = String(now.getFullYear()).padStart(4, '0');
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以加1
|
||||
const date = String(now.getDate()).padStart(2, '0');
|
||||
const dateString = year + month + date;
|
||||
|
||||
// 获取当前时间戳的后三位
|
||||
const timestamp = String(Date.now()).slice(-3);
|
||||
|
||||
// 生成三位随机数字
|
||||
const randomDigits = Math.floor(Math.random() * 100).toString().padStart(3, '0');
|
||||
|
||||
// 组合成最终的15位字符串
|
||||
const fullNumberString = dateString + timestamp + randomDigits + side;
|
||||
|
||||
return fullNumberString;
|
||||
}
|
||||
|
||||
// 随机盐生成函数
|
||||
generateRandomString = () => {
|
||||
const lowerCaseLetters = 'abcdefghijklmnopqrstuvwxyz';
|
||||
const upperCaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
const numbers = '0123456789';
|
||||
|
||||
let result = '';
|
||||
|
||||
// 生成5位随机小写字母
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * lowerCaseLetters.length);
|
||||
result += lowerCaseLetters[randomIndex];
|
||||
}
|
||||
|
||||
// 生成5位随机大写字母
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * upperCaseLetters.length);
|
||||
result += upperCaseLetters[randomIndex];
|
||||
}
|
||||
|
||||
// 生成2位随机数字
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * numbers.length);
|
||||
result += numbers[randomIndex];
|
||||
}
|
||||
|
||||
// 打乱整个字符串
|
||||
const characters = result.split('');
|
||||
for (let i = characters.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[characters[i], characters[j]] = [characters[j], characters[i]];
|
||||
}
|
||||
|
||||
return characters.join('');
|
||||
}
|
||||
|
||||
// 随机生成12位客户端id
|
||||
generateClientId = () => {
|
||||
const numbers = '0123456789';
|
||||
|
||||
let result = '';
|
||||
|
||||
// 生成4位随机数字
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * numbers.length);
|
||||
result += numbers[randomIndex];
|
||||
}
|
||||
|
||||
// 打乱整个字符串
|
||||
const characters = result.split('');
|
||||
for (let i = characters.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[characters[i], characters[j]] = [characters[j], characters[i]];
|
||||
}
|
||||
|
||||
// 获取当前日期(年月日)
|
||||
const now = new Date();
|
||||
const year = String(now.getFullYear()).padStart(4, '0');
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以加1
|
||||
const date = String(now.getDate()).padStart(2, '0');
|
||||
const dateString = year + month + date;
|
||||
|
||||
const fullNumberString = dateString + characters.join('');
|
||||
|
||||
return fullNumberString;
|
||||
}
|
||||
|
||||
checkUid = async (ctx) => {
|
||||
const token = ctx.request.header.authorization;
|
||||
const redis = ctx.app.redis;
|
||||
const insiders = await redis.get('db2').get(token);
|
||||
return insiders ? insiders : false;
|
||||
};
|
||||
|
||||
setResponse = (ctx, code, msg, model, data = {}) => {
|
||||
const modelType = {
|
||||
"none": { code, msg },
|
||||
"deconstruction": { code, msg, ...data },
|
||||
"polymerization": { code, msg, data }
|
||||
}
|
||||
ctx.body = modelType[model];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseController;
|
||||
88
app/core/base_service.js
Normal file
88
app/core/base_service.js
Normal file
@@ -0,0 +1,88 @@
|
||||
const { Service } = require('egg');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const sha256 = require("crypto-js/sha256");
|
||||
|
||||
const CryptoJS = require("crypto-js");
|
||||
|
||||
const KEY = CryptoJS.enc.Utf8.parse('BDQH');
|
||||
|
||||
class BaseService extends Service {
|
||||
shaForm = (body, salt) => {
|
||||
return sha256(sha256(body).toString() + salt).toString();
|
||||
}
|
||||
|
||||
encryptRequest = (body) => {
|
||||
return CryptoJS.AES.encrypt(body, KEY, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
}).toString();
|
||||
}
|
||||
|
||||
decryptRequest = (body) => {
|
||||
return CryptoJS.AES.decrypt(body, KEY, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
}).toString(CryptoJS.enc.Utf8);
|
||||
}
|
||||
|
||||
// uid生成函数
|
||||
generateNumberString = () => {
|
||||
// 获取当前日期(年月日)
|
||||
const now = new Date();
|
||||
const year = String(now.getFullYear()).padStart(4, '0');
|
||||
const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以加1
|
||||
const date = String(now.getDate()).padStart(2, '0');
|
||||
const dateString = year + month + date;
|
||||
|
||||
// 获取当前时间戳的后四位
|
||||
const timestamp = String(Date.now()).slice(-4);
|
||||
|
||||
// 生成四位随机数字
|
||||
const randomDigits = Math.floor(Math.random() * 10000).toString().padStart(4, '0');
|
||||
|
||||
// 组合成最终的16位数字字符串
|
||||
const fullNumberString = dateString + timestamp + randomDigits;
|
||||
|
||||
return fullNumberString;
|
||||
}
|
||||
|
||||
// 随机盐生成函数
|
||||
generateRandomString = () => {
|
||||
const lowerCaseLetters = 'abcdefghijklmnopqrstuvwxyz';
|
||||
const upperCaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
const numbers = '0123456789';
|
||||
|
||||
let result = '';
|
||||
|
||||
// 生成5位随机小写字母
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * lowerCaseLetters.length);
|
||||
result += lowerCaseLetters[randomIndex];
|
||||
}
|
||||
|
||||
// 生成5位随机大写字母
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * upperCaseLetters.length);
|
||||
result += upperCaseLetters[randomIndex];
|
||||
}
|
||||
|
||||
// 生成2位随机数字
|
||||
for (let i = 0; i < 2; i++) {
|
||||
const randomIndex = Math.floor(Math.random() * numbers.length);
|
||||
result += numbers[randomIndex];
|
||||
}
|
||||
|
||||
// 打乱整个字符串
|
||||
const characters = result.split('');
|
||||
for (let i = characters.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[characters[i], characters[j]] = [characters[j], characters[i]];
|
||||
}
|
||||
|
||||
return characters.join('');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BaseService;
|
||||
72
app/middleware/log.js
Normal file
72
app/middleware/log.js
Normal file
@@ -0,0 +1,72 @@
|
||||
// 错误日志
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
|
||||
const dirCheck = (dirPath) => {
|
||||
// 检查文件夹是否存在
|
||||
fs.access(dirPath, fs.constants.F_OK, (err) => {
|
||||
if (err) {
|
||||
// 文件夹不存在
|
||||
console.log('文件夹不存在,正在创建...');
|
||||
fs.mkdir(dirPath, { recursive: true }, (err) => {
|
||||
if (err) throw err;
|
||||
console.log('文件夹已创建');
|
||||
});
|
||||
} else {
|
||||
// 文件夹存在
|
||||
console.log('文件夹已存在');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = (filePath, msg) => {
|
||||
// 获取时间
|
||||
let now = new Date(),
|
||||
times = {
|
||||
year: now.getFullYear(),
|
||||
month: now.getMonth() + 1,
|
||||
day: now.getDate(),
|
||||
hour: now.getHours(),
|
||||
minute: now.getMinutes(),
|
||||
second: now.getSeconds()
|
||||
};
|
||||
// 获取操作系统类型
|
||||
const type = os.type();
|
||||
console.log(`操作系统类型: ${type}`);
|
||||
filePath = path.join(__dirname, filePath);
|
||||
dirCheck(filePath);
|
||||
const yearPath = filePath + '/' + times.year;
|
||||
dirCheck(yearPath);
|
||||
const monthPath = yearPath + '/' + times.month;
|
||||
dirCheck(monthPath);
|
||||
const dayPath = monthPath + '/' + times.day + '.txt';
|
||||
const logTime = '[' + times.year + '-' + times.month + '-' + times.day + '>>>' + times.hour + ':' + times.minute + ':' + times.second + ']' + '>>>';
|
||||
let crlf;
|
||||
// 判断操作系统类型,设置换行符
|
||||
if (type === 'Windows_NT') {
|
||||
crlf = '\n';
|
||||
} else {
|
||||
crlf = '\r\n';
|
||||
}
|
||||
// 读取文件内容
|
||||
fs.readFile(dayPath, 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
if (err.code === 'ENOENT') {
|
||||
// 文件不存在,直接写入新内容(这里实际上还是使用了覆盖的方式)
|
||||
fs.writeFile(dayPath, logTime + msg + crlf, (err) => {
|
||||
if (err) throw err;
|
||||
console.log('文件已创建并写入新内容');
|
||||
});
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
} else {
|
||||
// 文件存在,追加新内容
|
||||
fs.appendFile(dayPath, logTime + msg + crlf, (err) => {
|
||||
if (err) throw err;
|
||||
console.log('新内容已追加到文件');
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
24
app/model/BShortMsg.js
Normal file
24
app/model/BShortMsg.js
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, TEXT, DATE } = app.Sequelize;
|
||||
|
||||
const BShortMsg = app.model.define('bshort-msg', {
|
||||
id: { type: INTEGER(11), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
card_id: CHAR(8),
|
||||
receiver_address: CHAR(8),
|
||||
original_msg: TEXT,
|
||||
send_type: INTEGER(1),
|
||||
encode_type: INTEGER(1),
|
||||
msg_data: TEXT,
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return BShortMsg;
|
||||
};
|
||||
30
app/model/BSide.js
Normal file
30
app/model/BSide.js
Normal file
@@ -0,0 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const BSide = app.model.define('b-side', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
uid: CHAR(15),
|
||||
salt: CHAR(24),
|
||||
status: INTEGER(3),
|
||||
role: INTEGER(3),
|
||||
account_name: STRING(20),
|
||||
password: CHAR(64),
|
||||
organization: CHAR(16),
|
||||
user_name: STRING(20),
|
||||
phone: CHAR(11),
|
||||
msg: STRING(300),
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
login_at: DATE,
|
||||
login_status: INTEGER(3)
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
return BSide;
|
||||
};
|
||||
21
app/model/BSnMsg.js
Normal file
21
app/model/BSnMsg.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, TEXT, DATE } = app.Sequelize;
|
||||
|
||||
const BSnMsg = app.model.define('bsn-msg', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
sn_number: STRING(8),
|
||||
original_msg: TEXT,
|
||||
msg_data: TEXT,
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return BSnMsg;
|
||||
};
|
||||
22
app/model/BSubscribe.js
Normal file
22
app/model/BSubscribe.js
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, DATE } = app.Sequelize;
|
||||
|
||||
const BSubscribe = app.model.define('bsubscribe', {
|
||||
id: { type: INTEGER(11), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
business: INTEGER(3),
|
||||
status: INTEGER(3),
|
||||
type: INTEGER(3),
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
return BSubscribe;
|
||||
};
|
||||
20
app/model/BindBSNrecord.js
Normal file
20
app/model/BindBSNrecord.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const BindBSNrecord = app.model.define('bind-bsnrecord', {
|
||||
id: { type: INTEGER(11), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
sn_number: STRING(8),
|
||||
type: INTEGER(1),
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return BindBSNrecord;
|
||||
};
|
||||
20
app/model/BindBrecord.js
Normal file
20
app/model/BindBrecord.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, DATE } = app.Sequelize;
|
||||
|
||||
const BindBrecord = app.model.define('bind-brecord', {
|
||||
id: { type: INTEGER(11), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
card_id: CHAR(8),
|
||||
type: INTEGER(1),
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return BindBrecord;
|
||||
};
|
||||
18
app/model/BuserBind.js
Normal file
18
app/model/BuserBind.js
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR } = app.Sequelize;
|
||||
|
||||
const BuserBind = app.model.define('buser-bind', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
card_id: CHAR(8),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: false,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return BuserBind;
|
||||
};
|
||||
19
app/model/BuserSNAdmin.js
Normal file
19
app/model/BuserSNAdmin.js
Normal file
@@ -0,0 +1,19 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, TEXT } = app.Sequelize;
|
||||
|
||||
const BuserSnAdmin = app.model.define('buser-snadmin', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
length: INTEGER(3),
|
||||
sn_set: TEXT,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return BuserSnAdmin;
|
||||
};
|
||||
18
app/model/BuserSNBind.js
Normal file
18
app/model/BuserSNBind.js
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING } = app.Sequelize;
|
||||
|
||||
const BuserSNBind = app.model.define('buser-snbind', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
sn_number: STRING(8),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return BuserSNBind;
|
||||
};
|
||||
18
app/model/BuserToken.js
Normal file
18
app/model/BuserToken.js
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR } = app.Sequelize;
|
||||
|
||||
const BuserToken = app.model.define('buser-token', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
token: CHAR(64),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: false,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return BuserToken;
|
||||
};
|
||||
20
app/model2/BindCSNrecord.js
Normal file
20
app/model2/BindCSNrecord.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const BindCSNrecord = app.model2.define('bind-csnrecord', {
|
||||
id: { type: INTEGER(11), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
sn_number: STRING(8),
|
||||
type: INTEGER(1),
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return BindCSNrecord;
|
||||
};
|
||||
20
app/model2/BindCrecord.js
Normal file
20
app/model2/BindCrecord.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, DATE } = app.Sequelize;
|
||||
|
||||
const BindCrecord = app.model2.define('bind-crecord', {
|
||||
id: { type: INTEGER(11), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
card_id: CHAR(8),
|
||||
type: INTEGER(1),
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return BindCrecord;
|
||||
};
|
||||
21
app/model2/CSNMsg.js
Normal file
21
app/model2/CSNMsg.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, TEXT, DATE } = app.Sequelize;
|
||||
|
||||
const CSNMsg = app.model2.define('csn-msg', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
sn_number: STRING(8),
|
||||
original_msg: TEXT,
|
||||
msg_data: TEXT,
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return CSNMsg;
|
||||
};
|
||||
24
app/model2/CShortMsg.js
Normal file
24
app/model2/CShortMsg.js
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, TEXT, DATE } = app.Sequelize;
|
||||
|
||||
const CShortMsg = app.model2.define('cshort-msg', {
|
||||
id: { type: INTEGER(11), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
card_id: CHAR(8),
|
||||
receiver_address: CHAR(8),
|
||||
original_msg: TEXT,
|
||||
send_type: INTEGER(1),
|
||||
encode_type: INTEGER(1),
|
||||
msg_data: TEXT,
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return CShortMsg;
|
||||
};
|
||||
34
app/model2/CSide.js
Normal file
34
app/model2/CSide.js
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const CSide = app.model2.define('c-side', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
uid: CHAR(15),
|
||||
salt: CHAR(24),
|
||||
status: INTEGER(3),
|
||||
role: INTEGER(3),
|
||||
avatar: STRING(200),
|
||||
account_name: STRING(20),
|
||||
password: CHAR(64),
|
||||
user_name: STRING(20),
|
||||
phone: CHAR(11),
|
||||
gender: INTEGER(1),
|
||||
age: INTEGER(3),
|
||||
email: STRING(254),
|
||||
address: STRING(300),
|
||||
post_code: CHAR(6),
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
login_at: DATE,
|
||||
login_status: INTEGER(3)
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
return CSide;
|
||||
};
|
||||
22
app/model2/CSubscribe.js
Normal file
22
app/model2/CSubscribe.js
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, DATE } = app.Sequelize;
|
||||
|
||||
const CSubscribe = app.model2.define('csubscribe', {
|
||||
id: { type: INTEGER(11), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
business: INTEGER(3),
|
||||
status: INTEGER(3),
|
||||
type: INTEGER(3),
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
return CSubscribe;
|
||||
};
|
||||
18
app/model2/CuserBind.js
Normal file
18
app/model2/CuserBind.js
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR } = app.Sequelize;
|
||||
|
||||
const CuserBind = app.model2.define('cuser-bind', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
card_id: CHAR(8),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: false,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return CuserBind;
|
||||
};
|
||||
18
app/model2/CuserSNBind.js
Normal file
18
app/model2/CuserSNBind.js
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING } = app.Sequelize;
|
||||
|
||||
const CuserSNBind = app.model2.define('cuser-snbind', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
sn_number: STRING(8),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return CuserSNBind;
|
||||
};
|
||||
22
app/model3/BDCard.js
Normal file
22
app/model3/BDCard.js
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, DATE } = app.Sequelize;
|
||||
|
||||
const BDCard = app.model3.define('bd-card', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
card_id: CHAR(8),
|
||||
card_imsi: CHAR(18),
|
||||
type: INTEGER(3),
|
||||
status: INTEGER(3),
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
return BDCard;
|
||||
};
|
||||
28
app/model3/Business.js
Normal file
28
app/model3/Business.js
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const Business = app.model3.define('business', {
|
||||
id: { type: INTEGER(3), primaryKey: true, autoIncrement: true },
|
||||
salt: CHAR(24),
|
||||
login_url: STRING(200),
|
||||
client_url: STRING(200),
|
||||
temporary_id: CHAR(64),
|
||||
client_id: CHAR(12),
|
||||
client_secret: CHAR(64),
|
||||
name: STRING(30),
|
||||
type: INTEGER(3),
|
||||
level: INTEGER(3),
|
||||
status: INTEGER(3),
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
return Business;
|
||||
};
|
||||
28
app/model3/Insiders.js
Normal file
28
app/model3/Insiders.js
Normal file
@@ -0,0 +1,28 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const Insiders = app.model3.define('insiders', {
|
||||
id: { type: INTEGER(5), primaryKey: true, autoIncrement: true },
|
||||
uid: CHAR(15),
|
||||
salt: CHAR(24),
|
||||
status: INTEGER(3),
|
||||
role: INTEGER(3),
|
||||
name: STRING(20),
|
||||
password: CHAR(64),
|
||||
department: STRING(20),
|
||||
change: STRING(200),
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
login_at: DATE,
|
||||
login_status: INTEGER(3)
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
return Insiders;
|
||||
};
|
||||
23
app/model3/Monitoring.js
Normal file
23
app/model3/Monitoring.js
Normal file
@@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, DATE } = app.Sequelize;
|
||||
|
||||
const Monitoring = app.model3.define('monitoring', {
|
||||
id: { type: INTEGER(5), primaryKey: true, autoIncrement: true },
|
||||
operate: INTEGER(3),
|
||||
operate_msg: CHAR(200),
|
||||
type: INTEGER(3),
|
||||
status: INTEGER(3),
|
||||
affect_entries: INTEGER(5),
|
||||
user: CHAR(15),
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Monitoring;
|
||||
};
|
||||
26
app/model3/Organization.js
Normal file
26
app/model3/Organization.js
Normal file
@@ -0,0 +1,26 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const Organization = app.model3.define('organization', {
|
||||
id: { type: INTEGER(5), primaryKey: true, autoIncrement: true },
|
||||
uid: CHAR(16),
|
||||
organization_name: STRING(100),
|
||||
address: STRING(300),
|
||||
liaison_name: STRING(20),
|
||||
phone: CHAR(11),
|
||||
email: STRING(254),
|
||||
other_information: STRING(200),
|
||||
post_code: CHAR(6),
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
return Organization;
|
||||
};
|
||||
20
app/model3/SNNumber.js
Normal file
20
app/model3/SNNumber.js
Normal file
@@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const SNNumber = app.model3.define('sn-number', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
sn_number: STRING(8),
|
||||
status: INTEGER(3),
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
return SNNumber;
|
||||
};
|
||||
24
app/model4/Account.js
Normal file
24
app/model4/Account.js
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, DATE } = app.Sequelize;
|
||||
|
||||
const Account = app.model4.define('account', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
uid: CHAR(15),
|
||||
salt: CHAR(24),
|
||||
contest_uid: CHAR(15),
|
||||
account_name: CHAR(20),
|
||||
password: CHAR(64),
|
||||
status: INTEGER(3),
|
||||
created_at: DATE,
|
||||
login_status: INTEGER(3),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Account;
|
||||
};
|
||||
22
app/model4/ChoiceTopic.js
Normal file
22
app/model4/ChoiceTopic.js
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR } = app.Sequelize;
|
||||
|
||||
const ChoiceTopic = app.model4.define('choice-topic', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
topic: CHAR(300),
|
||||
options_a: CHAR(300),
|
||||
options_b: CHAR(300),
|
||||
options_c: CHAR(300),
|
||||
options_d: CHAR(300),
|
||||
answer: CHAR(300),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: false,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return ChoiceTopic;
|
||||
};
|
||||
29
app/model4/Contest.js
Normal file
29
app/model4/Contest.js
Normal file
@@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, DATE } = app.Sequelize;
|
||||
|
||||
const Contest = app.model4.define('contest', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
uid: CHAR(15),
|
||||
contest_name: CHAR(50),
|
||||
contest_organizers: CHAR(50),
|
||||
contest_term: CHAR(5),
|
||||
type: INTEGER(3),
|
||||
status: INTEGER(3),
|
||||
online_start: DATE,
|
||||
online_end: DATE,
|
||||
offline_start: DATE,
|
||||
offline_end: DATE,
|
||||
contest_start: DATE,
|
||||
contest_end: DATE,
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return Contest;
|
||||
};
|
||||
34
app/model4/Examination.js
Normal file
34
app/model4/Examination.js
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, DATE } = app.Sequelize;
|
||||
|
||||
const Examination = app.model4.define('examination', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
contest_uid: CHAR(15),
|
||||
exam_type: INTEGER(3),
|
||||
topic_type: INTEGER(3),
|
||||
topic1: CHAR(2),
|
||||
topic2: CHAR(2),
|
||||
topic3: CHAR(50),
|
||||
topic5: CHAR(10),
|
||||
answer: STRING(20),
|
||||
answer1: CHAR(2),
|
||||
answer2: CHAR(2),
|
||||
answer3: CHAR(10),
|
||||
answer4: CHAR(20),
|
||||
answer5: CHAR(10),
|
||||
score: INTEGER(3),
|
||||
score_collection: CHAR(9),
|
||||
created_at: DATE,
|
||||
updated_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
return Examination;
|
||||
};
|
||||
21
app/model4/TSNMsg.js
Normal file
21
app/model4/TSNMsg.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING, TEXT, DATE } = app.Sequelize;
|
||||
|
||||
const TSNMsg = app.model4.define('tsn-msg', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
sn_number: STRING(8),
|
||||
original_msg: TEXT,
|
||||
msg_data: TEXT,
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return TSNMsg;
|
||||
};
|
||||
24
app/model4/TShortMsg.js
Normal file
24
app/model4/TShortMsg.js
Normal file
@@ -0,0 +1,24 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, TEXT, DATE } = app.Sequelize;
|
||||
|
||||
const TShortMsg = app.model4.define('tshort-msg', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
card_id: CHAR(8),
|
||||
receiver_address: CHAR(8),
|
||||
original_msg: TEXT,
|
||||
send_type: INTEGER(1),
|
||||
encode_type: INTEGER(1),
|
||||
msg_data: TEXT,
|
||||
created_at: DATE,
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: true,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return TShortMsg;
|
||||
};
|
||||
18
app/model4/TuserBind.js
Normal file
18
app/model4/TuserBind.js
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR } = app.Sequelize;
|
||||
|
||||
const TuserBind = app.model4.define('tuser-bind', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
card_id: CHAR(8),
|
||||
user_uid: CHAR(15),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: false,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return TuserBind;
|
||||
};
|
||||
18
app/model4/TuserSNBind.js
Normal file
18
app/model4/TuserSNBind.js
Normal file
@@ -0,0 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = (app) => {
|
||||
const { INTEGER, CHAR, STRING } = app.Sequelize;
|
||||
|
||||
const TuserSNBind = app.model4.define('tuser-snbind', {
|
||||
id: { type: INTEGER(8), primaryKey: true, autoIncrement: true },
|
||||
user_uid: CHAR(15),
|
||||
sn_number: STRING(8),
|
||||
},{
|
||||
freezeTableName: true,
|
||||
timestamp: true,
|
||||
createdAt: false,
|
||||
updatedAt: false,
|
||||
});
|
||||
|
||||
return TuserSNBind;
|
||||
};
|
||||
145
app/router.js
Normal file
145
app/router.js
Normal file
@@ -0,0 +1,145 @@
|
||||
/**
|
||||
* @param {Egg.Application} app - egg application
|
||||
*/
|
||||
module.exports = app => {
|
||||
const { router, controller } = app;
|
||||
router.get('/main', controller.home.main);
|
||||
router.get('/home', controller.home.home);
|
||||
router.get('/main/home', controller.home.index);
|
||||
|
||||
// 注册北斗卡
|
||||
router.post("/addBdCard", controller.bdCard.addBdCard);
|
||||
// 查看北斗卡
|
||||
router.post("/showBdCard", controller.bdCard.showBdCard);
|
||||
// 编辑北斗卡
|
||||
router.post("/editBdCard", controller.bdCard.editBdCard);
|
||||
// 删除北斗卡
|
||||
router.post("/deleteBdCard", controller.bdCard.deleteBdCard);
|
||||
|
||||
// 查看绑定记录
|
||||
router.post("/showBindRecord", controller.bindRecord.showBindRecord);
|
||||
// 删除绑定记录
|
||||
router.post("/deleteBindRecord", controller.bindRecord.deleteBindRecord);
|
||||
|
||||
// 注册公司业务
|
||||
router.post("/addBusiness", controller.business.addBusiness);
|
||||
// 查看公司业务
|
||||
router.post("/showBusiness", controller.business.showBusiness);
|
||||
// 远程搜索公司业务
|
||||
router.post("/SearchBusiness", controller.business.SearchBusiness);
|
||||
// 编辑公司业务
|
||||
router.post("/editBusiness", controller.business.editBusiness);
|
||||
// 删除公司业务
|
||||
router.post("/deleteBusiness", controller.business.deleteBusiness);
|
||||
|
||||
// 注册B端用户
|
||||
router.post("/addBSide", controller.bSide.addBSide);
|
||||
// 查看B端用户
|
||||
router.post("/showBSide", controller.bSide.showBSide);
|
||||
// 编辑B端用户
|
||||
router.post("/editBSide", controller.bSide.editBSide);
|
||||
// 删除B端用户
|
||||
router.post("/deleteBSide", controller.bSide.deleteBSide);
|
||||
|
||||
// 查看C端用户
|
||||
router.post("/showCSide", controller.cSide.showCSide);
|
||||
// 编辑C端用户
|
||||
router.post("/editCSide", controller.cSide.editCSide);
|
||||
// 删除C端用户
|
||||
router.post("/deleteCSide", controller.cSide.deleteCSide);
|
||||
|
||||
// 注册管理系统用户
|
||||
router.post("/addInsiders", controller.insiders.addInsiders);
|
||||
// 查看管理系统用户
|
||||
router.post("/showInsiders", controller.insiders.showInsiders);
|
||||
// 编辑管理系统用户
|
||||
router.post("/editInsiders", controller.insiders.editInsiders);
|
||||
// 删除管理系统用户
|
||||
router.post("/deleteInsiders", controller.insiders.deleteInsiders);
|
||||
|
||||
// 注册B端用户单位
|
||||
router.post("/addOrganization", controller.organization.addOrganization);
|
||||
// 查看B端用户单位
|
||||
router.post("/showOrganization", controller.organization.showOrganization);
|
||||
// 远程搜索B端用户单位
|
||||
router.post("/SearchOrganization", controller.organization.SearchOrganization);
|
||||
// 编辑B端用户单位
|
||||
router.post("/editOrganization", controller.organization.editOrganization);
|
||||
// 删除B端用户单位
|
||||
router.post("/deleteOrganization", controller.organization.deleteOrganization);
|
||||
|
||||
// 查看监控记录
|
||||
router.post("/showMonitoring", controller.monitoring.showMonitoring);
|
||||
// 删除监控记录
|
||||
router.post("/deleteMonitoring", controller.monitoring.deleteMonitoring);
|
||||
|
||||
// 管理系统检索竞赛 uid
|
||||
router.post("/searchContestUid", controller.contestMsg.searchContestUid);
|
||||
// 管理系统创建竞赛信息
|
||||
router.post("/addContest", controller.contestMsg.addContest);
|
||||
// 管理系统查看竞赛信息
|
||||
router.post("/showContest", controller.contestMsg.showContest);
|
||||
// 管理系统编辑竞赛信息
|
||||
router.post("/editContest", controller.contestMsg.editContest);
|
||||
// 管理系统删除竞赛信息
|
||||
router.post("/delContest", controller.contestMsg.delContest);
|
||||
|
||||
// 管理系统导入选择题
|
||||
router.post("/importChoiceTopic", controller.contestTopic.importChoiceTopic);
|
||||
// 管理系统创建选择题
|
||||
router.post("/addChoiceTopic", controller.contestTopic.addChoiceTopic);
|
||||
// 管理系统查看选择题
|
||||
router.post("/showChoiceTopic", controller.contestTopic.showChoiceTopic);
|
||||
// 管理系统编辑选择题
|
||||
router.post("/editChoiceTopic", controller.contestTopic.editChoiceTopic);
|
||||
// 管理系统删除选择题
|
||||
router.post("/delChoiceTopic", controller.contestTopic.delChoiceTopic);
|
||||
|
||||
// 管理系统导入竞赛账号信息
|
||||
router.post("/importAccount", controller.contestAccount.importAccount);
|
||||
// 管理系统创建竞赛账号信息
|
||||
router.post("/addAccount", controller.contestAccount.addAccount);
|
||||
// 管理系统查看竞赛账号信息
|
||||
router.post("/showAccount", controller.contestAccount.showAccount);
|
||||
// 管理系统编辑竞赛账号信息
|
||||
router.post("/editAccount", controller.contestAccount.editAccount);
|
||||
// 管理系统删除竞赛账号信息
|
||||
router.post("/delAccount", controller.contestAccount.delAccount);
|
||||
|
||||
// 管理系统重置竞赛账号密码
|
||||
router.post("/resetAccount", controller.contestAccount.resetAccount);
|
||||
|
||||
// 管理系统查看账号答题情况
|
||||
router.post("/showExamination", controller.contestExamination.showExamination);
|
||||
// 管理系统编辑账号答题情况
|
||||
router.post("/editExamination", controller.contestExamination.editExamination);
|
||||
// 管理系统删除账号答题情况
|
||||
router.post("/delExamination", controller.contestExamination.delExamination);
|
||||
// 管理系统导出账号答题情况
|
||||
router.post("/downloadExamination", controller.contestExamination.downloadExamination);
|
||||
|
||||
// 注册SN号
|
||||
router.post("/addSN", controller.sn.addSN);
|
||||
// 查看SN号
|
||||
router.post("/showSN", controller.sn.showSN);
|
||||
// 编辑SN号
|
||||
router.post("/editSN", controller.sn.editSN);
|
||||
// 删除SN号
|
||||
router.post("/deleteSN", controller.sn.deleteSN);
|
||||
|
||||
// 查看SN号绑定记录
|
||||
router.post("/showBindSNRecord", controller.bindSNRecord.showBindSNRecord);
|
||||
// 删除SN号绑定记录
|
||||
router.post("/deleteBindSNRecord", controller.bindSNRecord.deleteBindSNRecord);
|
||||
|
||||
// 搜索可分配的SN号
|
||||
router.get("/searchAllocationSN", controller.sNAdmin.searchAllocationSN);
|
||||
// 搜索可分配的单位用户
|
||||
router.get("/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);
|
||||
};
|
||||
173
app/service/BSide.js
Normal file
173
app/service/BSide.js
Normal file
@@ -0,0 +1,173 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "BSide";
|
||||
|
||||
class BSideService extends Service {
|
||||
// 注册B端用户
|
||||
async addBSide(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.BSide.bulkCreate(form);
|
||||
return result.length == 0 ? false : true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addBSide";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 查看B端用户
|
||||
async showBSide(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['status', 'role', 'account_name', 'organization', 'user_name', 'phone', 'msg', 'created_at', 'updated_at', 'login_at', 'login_status'],
|
||||
where = {}, order = [], dbOptions,
|
||||
joinSubstring = ['organization'],
|
||||
substring = ['account_name', 'user_name', 'phone', 'msg'],
|
||||
key = ['status', 'role', 'login_status'],
|
||||
between = ['created_at', 'updated_at', 'login_at'];
|
||||
const Organization = await ctx.model3.Organization.findAll({ attributes: ['uid', 'organization_name'] });
|
||||
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 = [];
|
||||
Organization.forEach(item => {
|
||||
if (item.dataValues.organization_name.includes(searchOptions[element])) {
|
||||
targetKeyArr.push(item.dataValues.uid);
|
||||
}
|
||||
});
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model.BSide.findAndCountAll(dbOptions);
|
||||
result.rows.forEach(element => {
|
||||
if (element.dataValues.organization !== null) {
|
||||
element.dataValues.organization = Organization.find(item => item.dataValues.uid == element.dataValues.organization).dataValues.organization_name;
|
||||
}
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBSide";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑B端用户
|
||||
async editBSide(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;
|
||||
const Organization = await ctx.model3.Organization.findAll({ attributes: ['uid', 'organization_name'] });
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
let { account_name, organization } = requestMsg;
|
||||
if (organization !== null) {
|
||||
organization = Organization.find(item => item.dataValues.organization_name == organization).dataValues.uid;
|
||||
}
|
||||
where = { account_name, organization };
|
||||
} else if (modelType == "multiple") {
|
||||
let account_name = [], organization_name = [], organization = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
account_name.push(element.account_name);
|
||||
organization_name.push(element.organization);
|
||||
});
|
||||
}
|
||||
organization_name.forEach(element => {
|
||||
if (element !== null) {
|
||||
organization.push(Organization.find(item => item.dataValues.organization_name == element).dataValues.uid);
|
||||
}
|
||||
});
|
||||
where = { account_name, organization };
|
||||
if (where.organization.length == 0) {
|
||||
delete where.organization;
|
||||
}
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
const resultList = await ctx.model.BSide.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editBSide";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除B端用户
|
||||
async deleteBSide(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除B端用户',
|
||||
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") {
|
||||
const { account_name, organization } = requestMsg;
|
||||
where = { account_name, organization };
|
||||
} else if (modelType == "multiple") {
|
||||
let account_name = [], organization = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
account_name.push(element.account_name),
|
||||
organization.push(element.organization)
|
||||
});
|
||||
}
|
||||
where = { account_name, organization };
|
||||
}
|
||||
const resultList = await ctx.model.BSide.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 + "--" + "deleteBSide";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BSideService;
|
||||
225
app/service/BdCard.js
Normal file
225
app/service/BdCard.js
Normal file
@@ -0,0 +1,225 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "BdCard";
|
||||
|
||||
class BdCardService extends Service {
|
||||
// 注册北斗卡
|
||||
async addBdCard(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model3.BDCard.bulkCreate(form);
|
||||
return result.length == 0 ? false : true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addBdCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 查看北斗卡
|
||||
async showBdCard(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
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 (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, 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') {
|
||||
where.status = null;
|
||||
} else if (where.status == undefined) {
|
||||
where.status = 0;
|
||||
}
|
||||
} else {
|
||||
let cardArr = [];
|
||||
if (where.status == '1' || where.status == undefined) {
|
||||
bside.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
bsideBind.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
cardArr.push(item2.dataValues.card_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (where.status == '2' || where.status == undefined) {
|
||||
cside.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
csideBind.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
cardArr.push(item2.dataValues.card_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (where.status == '3' || where.status == undefined) {
|
||||
contest.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
contestBind.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
cardArr.push(item2.dataValues.card_id);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
where.card_id = [...cardArr];
|
||||
}
|
||||
}
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model3.BDCard.findAndCountAll(dbOptions);
|
||||
result.rows.forEach(element => {
|
||||
element.dataValues.account_name = '';
|
||||
bsideBind.filter(item => {
|
||||
if (item.dataValues.card_id == element.dataValues.card_id) {
|
||||
bside.filter(item2 => {
|
||||
if (item2.dataValues.uid == item.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item2.dataValues.account_name;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
csideBind.filter(item => {
|
||||
if (item.dataValues.card_id == element.dataValues.card_id) {
|
||||
cside.filter(item2 => {
|
||||
if (item2.dataValues.uid == item.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item2.dataValues.account_name;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
contestBind.filter(item => {
|
||||
if (item.dataValues.card_id == element.dataValues.card_id) {
|
||||
contest.filter(item2 => {
|
||||
if (item2.dataValues.uid == item.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item2.dataValues.account_name;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBdCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑北斗卡
|
||||
async editBdCard(uid, modelType, password, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
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) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
where = requestMsg;
|
||||
} else if (modelType == "multiple") {
|
||||
let card_id = [], card_imsi = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
card_id.push(element.card_id);
|
||||
card_imsi.push(element.card_imsi);
|
||||
});
|
||||
}
|
||||
where = { card_id, card_imsi };
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
const resultList = await ctx.model3.BDCard.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editBdCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除北斗卡
|
||||
async deleteBdCard(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 card_id = [], card_imsi = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
card_id.push(element.card_id),
|
||||
card_imsi.push(element.card_imsi)
|
||||
});
|
||||
}
|
||||
where = { card_id, card_imsi };
|
||||
}
|
||||
const resultList = await ctx.model3.BDCard.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 + "--" + "deleteBdCard";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BdCardService;
|
||||
179
app/service/BindRecord.js
Normal file
179
app/service/BindRecord.js
Normal file
@@ -0,0 +1,179 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
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);
|
||||
}
|
||||
} 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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BindRecordService;
|
||||
179
app/service/BindSNRecord.js
Normal file
179
app/service/BindSNRecord.js
Normal file
@@ -0,0 +1,179 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
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);
|
||||
}
|
||||
} 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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BindSNRecordService;
|
||||
211
app/service/Business.js
Normal file
211
app/service/Business.js
Normal file
@@ -0,0 +1,211 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Business";
|
||||
|
||||
class BusinessService extends Service {
|
||||
// 注册公司业务
|
||||
async addBusiness(uid, form) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 0,
|
||||
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.role < 9) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.role < 9) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
const resultList = await ctx.model3.Business.bulkCreate(form);
|
||||
systemMonitoring.status = resultList.length == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList.length;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList.length == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "addBusiness";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 查看公司业务
|
||||
async showBusiness(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['salt', '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', 'client_id', '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 (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.Business.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showBusiness";
|
||||
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) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 1,
|
||||
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) 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 { temporary_id, client_id, client_secret, name } = requestMsg;
|
||||
where = { temporary_id, client_id, client_secret, name };
|
||||
} else if (modelType == "multiple") {
|
||||
let temporary_id = [], client_id = [], client_secret = [], name = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
temporary_id.push(element.temporary_id),
|
||||
client_id.push(element.client_id),
|
||||
client_secret.push(element.client_secret),
|
||||
name.push(element.name)
|
||||
});
|
||||
}
|
||||
where = { temporary_id, client_id, client_secret, name };
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
const resultList = await ctx.model3.Business.update(updateMsg, { where });
|
||||
systemMonitoring.status = resultList[0] == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList[0];
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "editBusiness";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除公司业务
|
||||
async deleteBusiness(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 { temporary_id, client_id, client_secret, name } = requestMsg;
|
||||
where = { temporary_id, client_id, client_secret, name };
|
||||
} else if (modelType == "multiple") {
|
||||
let temporary_id = [], client_id = [], client_secret = [], name = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
temporary_id.push(element.temporary_id),
|
||||
client_id.push(element.client_id),
|
||||
client_secret.push(element.client_secret),
|
||||
name.push(element.name)
|
||||
});
|
||||
}
|
||||
where = { temporary_id, client_id, client_secret, name };
|
||||
}
|
||||
const resultList = await ctx.model3.Business.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 + "--" + "deleteBusiness";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BusinessService;
|
||||
133
app/service/CSide.js
Normal file
133
app/service/CSide.js
Normal file
@@ -0,0 +1,133 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "CSide";
|
||||
|
||||
class CSideService extends Service {
|
||||
// 查看C端用户
|
||||
async showCSide(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['status', 'role', 'account_name', 'user_name', 'phone', 'gender', 'age', 'email', 'address', 'post_code', 'created_at', 'updated_at', 'login_at', 'login_status'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['account_name', 'user_name', 'phone', 'email', 'address', 'post_code'],
|
||||
key = ['status', 'role', 'gender', 'age', '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 (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model2.CSide.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showCSide";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑C端用户
|
||||
async editCSide(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 { account_name, phone } = requestMsg;
|
||||
where = { account_name, phone };
|
||||
} else if (modelType == "multiple") {
|
||||
let account_name = [], phone = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
account_name.push(element.account_name),
|
||||
phone.push(element.phone)
|
||||
});
|
||||
}
|
||||
where = { account_name, phone };
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
const resultList = await ctx.model2.CSide.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editCSide";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除C端用户
|
||||
async deleteCSide(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除C端用户',
|
||||
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") {
|
||||
const { account_name, phone } = requestMsg;
|
||||
where = { account_name, phone };
|
||||
} else if (modelType == "multiple") {
|
||||
let account_name = [], phone = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
account_name.push(element.account_name),
|
||||
phone.push(element.phone)
|
||||
});
|
||||
}
|
||||
where = { account_name, phone };
|
||||
}
|
||||
const resultList = await ctx.model2.CSide.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 + "--" + "deleteCSide";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CSideService;
|
||||
200
app/service/ContestAccount.js
Normal file
200
app/service/ContestAccount.js
Normal file
@@ -0,0 +1,200 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "ContestAccount";
|
||||
|
||||
class ContestAccountService extends Service {
|
||||
// 管理系统导入报名账号信息
|
||||
async importAccount(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model4.Account.bulkCreate(form);
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "importAccount";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统创建竞赛账号信息
|
||||
async addAccount(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model4.Account.bulkCreate(form);
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addAccount";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看竞赛账号信息
|
||||
async showAccount(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
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, offset, limit, where, order };
|
||||
const result = await ctx.model4.Account.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showAccount";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑竞赛账号信息
|
||||
async editAccount(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_uid, account_name, status, created_at, login_status } = requestMsg;
|
||||
where = { uid, contest_uid, account_name, status, created_at, login_status };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], contest_uid = [], account_name = [], status = [], created_at = [], login_status = [];
|
||||
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)
|
||||
});
|
||||
}
|
||||
where = { uid, contest_uid, account_name, status, created_at, login_status };
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
const resultList = await ctx.model4.Account.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editAccount";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除竞赛账号信息
|
||||
async delAccount(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_uid, account_name, status, created_at, login_status } = requestMsg;
|
||||
where = { uid, contest_uid, account_name, status, created_at, login_status };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], contest_uid = [], account_name = [], status = [], created_at = [], login_status = [];
|
||||
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)
|
||||
});
|
||||
}
|
||||
where = { uid, contest_uid, account_name, status, created_at, login_status };
|
||||
}
|
||||
const resultList = await ctx.model4.Account.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 + "--" + "delAccount";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统重置竞赛账号密码
|
||||
async resetAccount(uid, accountUid, password) {
|
||||
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;
|
||||
};
|
||||
const salt = this.generateRandomString();
|
||||
const resetResult = await ctx.model4.Account.update({ salt: this.encryptRequest(salt), password: this.shaForm('123456', salt) }, { where: { uid: accountUid } });
|
||||
return resetResult[0] == 0 ? false : true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "resetAccount";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestAccountService;
|
||||
163
app/service/ContestExamination.js
Normal file
163
app/service/ContestExamination.js
Normal file
@@ -0,0 +1,163 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
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 };
|
||||
}
|
||||
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, 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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestExaminationService;
|
||||
182
app/service/ContestMsg.js
Normal file
182
app/service/ContestMsg.js
Normal file
@@ -0,0 +1,182 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统创建竞赛信息
|
||||
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 };
|
||||
}
|
||||
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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestMsgService;
|
||||
169
app/service/ContestTopic.js
Normal file
169
app/service/ContestTopic.js
Normal file
@@ -0,0 +1,169 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "ContestChoiceTopic";
|
||||
|
||||
class ContestChoiceTopicService extends Service {
|
||||
// 管理系统导入选择题
|
||||
async importChoiceTopic(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model4.ChoiceTopic.bulkCreate(form);
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "importChoiceTopic";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统创建选择题
|
||||
async addChoiceTopic(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model4.ChoiceTopic.bulkCreate(form);
|
||||
return result.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addChoiceTopic";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统查看选择题
|
||||
async showChoiceTopic(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
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'],
|
||||
key = ['answer'],
|
||||
between = [];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (joinSubstring.includes(element)) {
|
||||
let targetKeyArr = [];
|
||||
where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null';
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model4.ChoiceTopic.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showChoiceTopic";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统编辑选择题
|
||||
async editChoiceTopic(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 { topic, options_a, options_b, options_c, options_d, answer } = requestMsg;
|
||||
where = { topic, options_a, options_b, options_c, options_d, answer };
|
||||
} else if (modelType == "multiple") {
|
||||
let topic = [], options_a = [], options_b = [], options_c = [], options_d = [], answer = [];
|
||||
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)
|
||||
});
|
||||
}
|
||||
where = { topic, options_a, options_b, options_c, options_d, answer };
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
const resultList = await ctx.model4.ChoiceTopic.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editChoiceTopic";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 管理系统删除选择题
|
||||
async delChoiceTopic(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 { topic, options_a, options_b, options_c, options_d, answer } = requestMsg;
|
||||
where = { topic, options_a, options_b, options_c, options_d, answer };
|
||||
} else if (modelType == "multiple") {
|
||||
let topic = [], options_a = [], options_b = [], options_c = [], options_d = [], answer = [];
|
||||
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)
|
||||
});
|
||||
}
|
||||
where = { topic, options_a, options_b, options_c, options_d, answer };
|
||||
}
|
||||
const resultList = await ctx.model4.ChoiceTopic.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 + "--" + "delChoiceTopic";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ContestChoiceTopicService;
|
||||
193
app/service/Insiders.js
Normal file
193
app/service/Insiders.js
Normal file
@@ -0,0 +1,193 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Insiders";
|
||||
|
||||
class InsidersService extends Service {
|
||||
// 注册管理系统用户
|
||||
async addInsiders(uid, form) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 0,
|
||||
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.role < 9) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.role < 9) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
const resultList = await ctx.model3.Insiders.bulkCreate(form);
|
||||
systemMonitoring.status = resultList.length == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList.length;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList.length == 0 ? false : true;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "addInsiders";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 查看管理系统用户
|
||||
async showInsiders(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
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'];
|
||||
where.role = { [Op.not]: 99 };
|
||||
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)) {
|
||||
if(element == 'role' && searchOptions[element] == 99) {
|
||||
where.role = { [Op.not]: 99 };
|
||||
} else{
|
||||
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 resultList = await ctx.model3.Insiders.findAndCountAll(dbOptions);
|
||||
return resultList.rows.length == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showInsiders";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑管理系统用户
|
||||
async editInsiders(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 1,
|
||||
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.role < 9) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.role < 9) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { uid, name } = requestMsg;
|
||||
where = { uid, name };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], name = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid),
|
||||
name.push(element.name)
|
||||
});
|
||||
}
|
||||
where = { uid, name };
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
where.role = { [Op.not]: 99 };
|
||||
const resultList = await ctx.model3.Insiders.update(updateMsg, { where });
|
||||
systemMonitoring.status = resultList[0] == 0 ? 3 : 4;
|
||||
systemMonitoring.affect_entries = resultList[0];
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
systemMonitoring.status = 5;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
const blockName = fileName + "--" + "editInsiders";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除管理系统用户
|
||||
async deleteInsiders(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 { uid, name } = requestMsg;
|
||||
where = { uid, name };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], name = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid),
|
||||
name.push(element.name)
|
||||
});
|
||||
}
|
||||
where = { uid, name };
|
||||
}
|
||||
where.role = { [Op.not]: 99 };
|
||||
const resultList = await ctx.model3.Insiders.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 + "--" + "deleteInsiders";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = InsidersService;
|
||||
125
app/service/Monitoring.js
Normal file
125
app/service/Monitoring.js
Normal file
@@ -0,0 +1,125 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Monitoring";
|
||||
|
||||
class MonitoringService extends Service {
|
||||
// 查看危险操作记录
|
||||
async showMonitoring(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['operate', 'operate_msg', 'type', 'status', 'affect_entries', 'user', 'created_at'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['operate_msg', 'user'],
|
||||
key = ['type', 'status', 'operate'],
|
||||
between = ['created_at'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [null, ''];
|
||||
}
|
||||
} else if (substring.includes(element)) {
|
||||
where[element] = { [Op.substring]: searchOptions[element] };
|
||||
} else if (key.includes(element)) {
|
||||
where[element] = searchOptions[element];
|
||||
} else if (between.includes(element)) {
|
||||
where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[element] == true) {
|
||||
order.push([element, 'ASC']);
|
||||
} else if (sortOptions[element] == false) {
|
||||
order.push([element, 'DESC']);
|
||||
}
|
||||
});
|
||||
const 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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MonitoringService;
|
||||
171
app/service/Organization.js
Normal file
171
app/service/Organization.js
Normal file
@@ -0,0 +1,171 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Organization";
|
||||
|
||||
class OrganizationService extends Service {
|
||||
// 注册B端用户单位
|
||||
async addOrganization(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model3.Organization.bulkCreate(form);
|
||||
return result.length == 0 ? false : true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addOrganization";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 查看B端用户单位
|
||||
async showOrganization(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
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 (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.Organization.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showOrganization";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
//远程搜索B端用户单位
|
||||
async SearchOrganization(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { query, key } = body;
|
||||
let attributes = ['uid', 'organization_name', 'created_at'], where = {}, dbOptions;
|
||||
if (query == '*空') {
|
||||
delete where[key]
|
||||
} else {
|
||||
where[key] = { [Op.substring]: query };
|
||||
}
|
||||
dbOptions = { attributes, where };
|
||||
const Organization = await ctx.model3.Organization.findAll(dbOptions);
|
||||
return Organization.length == 0 ? false : Organization;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "SearchOrganization";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑B端用户单位
|
||||
async editOrganization(uid, modelType, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model3.Insiders.findOne({ where: { uid } });
|
||||
if (!result || result.dataValues.role < 6) {
|
||||
if (!result) systemMonitoring.status = 0;
|
||||
else if (result.dataValues.role < 6) systemMonitoring.status = 2;
|
||||
await ctx.model3.Monitoring.create(systemMonitoring);
|
||||
return false;
|
||||
};
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
const { uid, organization_name } = requestMsg;
|
||||
where = { uid, organization_name };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], organization_name = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid),
|
||||
organization_name.push(element.organization_name)
|
||||
});
|
||||
}
|
||||
where = { uid, organization_name };
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
const resultList = await ctx.model3.Organization.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editOrganization";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除B端用户单位
|
||||
async deleteOrganization(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除B端用户单位',
|
||||
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") {
|
||||
const { uid, organization_name } = requestMsg;
|
||||
where = { uid, organization_name };
|
||||
} else if (modelType == "multiple") {
|
||||
let uid = [], organization_name = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
uid.push(element.uid),
|
||||
organization_name.push(element.organization_name)
|
||||
});
|
||||
}
|
||||
where = { uid, organization_name };
|
||||
}
|
||||
const resultList = await ctx.model3.Organization.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 + "--" + "deleteOrganization";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OrganizationService;
|
||||
205
app/service/SNAdmin.js
Normal file
205
app/service/SNAdmin.js
Normal file
@@ -0,0 +1,205 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索可分配的单位用户
|
||||
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';
|
||||
}
|
||||
}
|
||||
|
||||
// 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 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 };
|
||||
}
|
||||
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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SNAdminService;
|
||||
223
app/service/Sn.js
Normal file
223
app/service/Sn.js
Normal file
@@ -0,0 +1,223 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "SN";
|
||||
|
||||
class SNService extends Service {
|
||||
// 注册SN号
|
||||
async addSN(form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model3.SNNumber.bulkCreate(form);
|
||||
return result.length == 0 ? false : true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "addSN";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 查看SN号
|
||||
async showSN(body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
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 (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, contest, bsideSNBind, csideSNBind, contestSNBind] = 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.BuserSNBind.findAll({ attributes: ['user_uid', 'sn_number'] }),
|
||||
ctx.model2.CuserSNBind.findAll({ attributes: ['user_uid', 'sn_number'] }),
|
||||
ctx.model4.TuserSNBind.findAll({ attributes: ['user_uid', 'sn_number'] })
|
||||
]);
|
||||
if (searchOptions.account_name) {
|
||||
if (searchOptions.account_name == '*空') {
|
||||
if (where.status == '1' || where.status == '2' || where.status == '3') {
|
||||
where.status = null;
|
||||
} else if (where.status == undefined) {
|
||||
where.status = 0;
|
||||
}
|
||||
} else {
|
||||
let cardArr = [];
|
||||
if (where.status == '1' || where.status == undefined) {
|
||||
bside.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
bsideSNBind.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
cardArr.push(item2.dataValues.sn_number);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (where.status == '2' || where.status == undefined) {
|
||||
cside.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
csideSNBind.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
cardArr.push(item2.dataValues.sn_number);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
if (where.status == '3' || where.status == undefined) {
|
||||
contest.filter(item => {
|
||||
if (item.dataValues.account_name.includes(searchOptions.account_name)) {
|
||||
contestSNBind.filter(item2 => {
|
||||
if (item2.dataValues.user_uid == item.dataValues.uid) {
|
||||
cardArr.push(item2.dataValues.sn_number);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
where.sn_number = [...cardArr];
|
||||
}
|
||||
}
|
||||
dbOptions = { attributes, offset, limit, where, order };
|
||||
const result = await ctx.model3.SNNumber.findAndCountAll(dbOptions);
|
||||
result.rows.forEach(element => {
|
||||
element.dataValues.account_name = '';
|
||||
bsideSNBind.filter(item => {
|
||||
if (item.dataValues.sn_number == element.dataValues.sn_number) {
|
||||
bside.filter(item2 => {
|
||||
if (item2.dataValues.uid == item.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item2.dataValues.account_name;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
csideSNBind.filter(item => {
|
||||
if (item.dataValues.sn_number == element.dataValues.sn_number) {
|
||||
cside.filter(item2 => {
|
||||
if (item2.dataValues.uid == item.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item2.dataValues.account_name;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
contestSNBind.filter(item => {
|
||||
if (item.dataValues.sn_number == element.dataValues.sn_number) {
|
||||
contest.filter(item2 => {
|
||||
if (item2.dataValues.uid == item.dataValues.user_uid) {
|
||||
element.dataValues.account_name = item2.dataValues.account_name;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "showSN";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑SN号
|
||||
async editSN(uid, modelType, password, updateMsg, requestMsg) {
|
||||
const { ctx } = this;
|
||||
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) return false;
|
||||
let where = {};
|
||||
if (modelType == "single") {
|
||||
where = requestMsg;
|
||||
} else if (modelType == "multiple") {
|
||||
let sn_number = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
sn_number.push(element.sn_number);
|
||||
});
|
||||
}
|
||||
where = { sn_number };
|
||||
}
|
||||
updateMsg.updated_at = new Date();
|
||||
const resultList = await ctx.model3.SNNumber.update(updateMsg, { where });
|
||||
return resultList[0] == 0 ? false : resultList;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "editSN";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 删除SN号
|
||||
async deleteSN(uid, modelType, password, requestMsg) {
|
||||
const { ctx } = this;
|
||||
const systemMonitoring = {
|
||||
operate: 2,
|
||||
operate_msg: '删除SN号',
|
||||
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 sn_number = [];
|
||||
for (const key in requestMsg) {
|
||||
requestMsg[key].forEach(element => {
|
||||
sn_number.push(element.sn_number)
|
||||
});
|
||||
}
|
||||
where = { sn_number };
|
||||
}
|
||||
const resultList = await ctx.model3.SNNumber.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 + "--" + "deleteSN";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = SNService;
|
||||
Reference in New Issue
Block a user