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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -53,7 +53,12 @@ class PlaAccountService {
|
||||
|
||||
// 搜索条件
|
||||
if (key && value) {
|
||||
where[key] = { [op.like]: `%${value}%` };
|
||||
// 对于 sn_code 使用精确匹配,其他字段使用模糊匹配
|
||||
if (key === 'sn_code') {
|
||||
where[key] = value;
|
||||
} else {
|
||||
where[key] = { [op.like]: `%${value}%` };
|
||||
}
|
||||
}
|
||||
|
||||
// 平台筛选
|
||||
|
||||
Reference in New Issue
Block a user