207 lines
7.4 KiB
JavaScript
207 lines
7.4 KiB
JavaScript
|
|
'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;
|