75 lines
2.9 KiB
JavaScript
75 lines
2.9 KiB
JavaScript
|
|
'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;
|