161 lines
6.1 KiB
JavaScript
161 lines
6.1 KiB
JavaScript
'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; |