139 lines
5.2 KiB
JavaScript
139 lines
5.2 KiB
JavaScript
|
|
'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;
|