1
This commit is contained in:
@@ -223,7 +223,7 @@ module.exports = {
|
||||
* /admin_api/device/update-config:
|
||||
* post:
|
||||
* summary: 更新设备配置
|
||||
* description: 更新指定设备的配置信息
|
||||
* description: 更新指定设备的配置信息,保存到 pla_account 表的 deliver_config 字段
|
||||
* tags: [后台-设备管理]
|
||||
* requestBody:
|
||||
* required: true
|
||||
@@ -233,41 +233,46 @@ module.exports = {
|
||||
* type: object
|
||||
* required:
|
||||
* - sn_code
|
||||
* - config
|
||||
* - deliver_config
|
||||
* properties:
|
||||
* sn_code:
|
||||
* type: string
|
||||
* description: 设备SN码
|
||||
* config:
|
||||
* deliver_config:
|
||||
* type: object
|
||||
* description: 配置数据
|
||||
* description: 投递配置数据
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 更新成功
|
||||
*/
|
||||
'POST /device/update-config': async (ctx) => {
|
||||
const models = Framework.getModels();
|
||||
const { account_config } = models;
|
||||
const body = ctx.getBody();
|
||||
const { sn_code, config } = body;
|
||||
const { sn_code, deliver_config } = body;
|
||||
|
||||
if (!sn_code || !config) {
|
||||
return ctx.fail('设备SN码和配置数据不能为空');
|
||||
if (!sn_code) {
|
||||
return ctx.fail('设备SN码不能为空');
|
||||
}
|
||||
|
||||
// 从 pla_account 获取账号ID
|
||||
if (!deliver_config) {
|
||||
return ctx.fail('配置数据不能为空');
|
||||
}
|
||||
|
||||
// 从 pla_account 获取账号
|
||||
const { pla_account } = models;
|
||||
const account = await pla_account.findOne({ where: { sn_code } });
|
||||
if (!account) {
|
||||
return ctx.fail('设备不存在');
|
||||
}
|
||||
|
||||
// 更新 account_config 表的配置
|
||||
await account_config.upsert({
|
||||
account_id: account.id,
|
||||
platform_type: account.platform_type,
|
||||
platform_config: config
|
||||
});
|
||||
// 更新 pla_account 表的 deliver_config 字段
|
||||
await pla_account.update(
|
||||
{
|
||||
deliver_config: deliver_config,
|
||||
auto_deliver: deliver_config.auto_delivery ? 1 : 0
|
||||
},
|
||||
{ where: { id: account.id } }
|
||||
);
|
||||
|
||||
return ctx.success({ message: '设备配置更新成功' });
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user