1
This commit is contained in:
@@ -36,6 +36,64 @@ module.exports = {
|
||||
* 200:
|
||||
* description: 获取成功
|
||||
*/
|
||||
/**
|
||||
* @swagger
|
||||
* /admin_api/device/detail:
|
||||
* post:
|
||||
* summary: 获取设备详情
|
||||
* description: 根据设备SN码获取设备详细信息
|
||||
* tags: [后台-设备管理]
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - deviceSn
|
||||
* properties:
|
||||
* deviceSn:
|
||||
* type: string
|
||||
* description: 设备SN码
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 获取成功
|
||||
*/
|
||||
'POST /device/detail': async (ctx) => {
|
||||
const models = Framework.getModels();
|
||||
const { device_status } = models;
|
||||
const body = ctx.getBody();
|
||||
const { deviceSn } = body;
|
||||
|
||||
if (!deviceSn) {
|
||||
return ctx.fail('设备SN码不能为空');
|
||||
}
|
||||
|
||||
const device = await device_status.findOne({
|
||||
where: { sn_code: deviceSn }
|
||||
});
|
||||
|
||||
if (!device) {
|
||||
return ctx.fail('设备不存在');
|
||||
}
|
||||
|
||||
const deviceData = device.toJSON();
|
||||
|
||||
// 处理 JSON 字段
|
||||
if (deviceData.config) {
|
||||
try {
|
||||
deviceData.config = typeof deviceData.config === 'string'
|
||||
? JSON.parse(deviceData.config)
|
||||
: deviceData.config;
|
||||
} catch (e) {
|
||||
console.error('解析设备配置失败:', e);
|
||||
deviceData.config = {};
|
||||
}
|
||||
}
|
||||
|
||||
return ctx.success(deviceData);
|
||||
},
|
||||
|
||||
'POST /device/list': async (ctx) => {
|
||||
const models = Framework.getModels();
|
||||
const { device_status, op } = models;
|
||||
|
||||
Reference in New Issue
Block a user