This commit is contained in:
张成
2025-11-26 20:25:02 +08:00
parent 60f13c3ad7
commit 4db078c80a
6 changed files with 167 additions and 17 deletions

View File

@@ -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;

View File

@@ -56,8 +56,22 @@ module.exports = {
*/
'POST /account/list': async (ctx) => {
const body = ctx.getBody();
const { key, value, platform_type, is_online } = body;
const { limit, offset } = ctx.getPageSize();
// 支持两种参数格式:直接传参或通过 seachOption 传递
const seachOption = body.seachOption || {};
const pageOption = body.pageOption || {};
// 获取搜索参数(优先使用 seachOption兼容直接传参
const key = seachOption.key || body.key;
const value = seachOption.value || body.value;
const platform_type = seachOption.platform_type || body.platform_type;
const is_online = seachOption.is_online !== undefined ? seachOption.is_online : body.is_online;
// 获取分页参数
const page = pageOption.page || body.page || 1;
const pageSize = pageOption.pageSize || body.pageSize || 20;
const limit = pageSize;
const offset = (page - 1) * pageSize;
const result = await plaAccountService.getAccountList({
key,