From 396c9bf084a66e721eaba1ae61734798f4fce7b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?zhaobing=E2=80=99?= Date: Wed, 27 Dec 2023 09:36:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=9B=BA=E4=BB=B6=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=BA=E5=8F=AF=E9=85=8D=E7=BD=AE=EF=BC=88?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=95=B0=E6=8D=AE=E5=BA=93=E8=A1=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/controllers/firmwareUpgrade/index.js | 12 +++++- api/app/lib/models/device_model.js | 35 +++++++++++++++++ .../4.1/data/1.insert_into_device_model.sql | 39 +++++++++++++++++++ script/4.1/schema/4.create_device_model.sql | 12 ++++++ 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 api/app/lib/models/device_model.js create mode 100644 script/4.1/data/1.insert_into_device_model.sql create mode 100644 script/4.1/schema/4.create_device_model.sql diff --git a/api/app/lib/controllers/firmwareUpgrade/index.js b/api/app/lib/controllers/firmwareUpgrade/index.js index 334c204..fba4fd6 100644 --- a/api/app/lib/controllers/firmwareUpgrade/index.js +++ b/api/app/lib/controllers/firmwareUpgrade/index.js @@ -17,12 +17,20 @@ const http = require('http'); //设备维护记录 async function getDeviceType (ctx) { try { - // const { models } = ctx.fs.dc + const { models } = ctx.fs.dc // const sequelize = ctx.fs.dc.ORM const { clickHouse } = ctx.app.fs + const res = await models.DeviceModel.findAll({attributes:['model_name']}) + let modelName=new Set() + modelName.add(-11) + for (let { dataValues: c } of res) { + modelName.add(c.model_name) + } + const inClause = `(${Array.from(modelName).map(item => `'${item}'`).join(',')})`; + console.log(inClause) const rlst = await clickHouse.iot.query(` SELECT id,model FROM DeviceMeta - WHERE model in ('FS-YTSW','FS-YTDZ-GD','FS-iFWL-ZXSJ','ZSJ-iVW08','FS-Q90-NHB1-HC','FS-RTU-P4-SL','FS-RTU-SL','FS-V08','FS-M24','FS-LPWAN08','FS-RTU-SL','FS-RTU-P4-SL','FS-iZD08pro') + WHERE model in ${inClause} `).toPromise() ctx.body=rlst||[] ctx.status=200 diff --git a/api/app/lib/models/device_model.js b/api/app/lib/models/device_model.js new file mode 100644 index 0000000..80b5b24 --- /dev/null +++ b/api/app/lib/models/device_model.js @@ -0,0 +1,35 @@ +/* eslint-disable*/ +'use strict'; + +module.exports = dc => { + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const DeviceModel = sequelize.define("deviceModel", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: true, + field: "id", + autoIncrement: true, + unique: "device_model_pk" + }, + modelName: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: false, + field: "model_name", + autoIncrement: false + }, + + }, { + tableName: "device_model", + comment: "", + indexes: [] + }); + dc.models.DeviceModel = DeviceModel; + return DeviceModel; +}; \ No newline at end of file diff --git a/script/4.1/data/1.insert_into_device_model.sql b/script/4.1/data/1.insert_into_device_model.sql new file mode 100644 index 0000000..19afb23 --- /dev/null +++ b/script/4.1/data/1.insert_into_device_model.sql @@ -0,0 +1,39 @@ + +insert into device_model ( model_name) +values ('FS-iZD08pro'), + ('FS-YTSW'), + ('FS-YTDZ-GD'), + ('FS-iFWL-ZXSJ'), + ('ZSJ-iVW08'), + ('FS-Q90-NHB1-HC'), + ('FS-RTU-P4-SL'), + ('FS-RTU-SL'), + ('FS-V08'), + ( 'FS-M24'), + ( 'FS-LPWAN08'), + ( 'FS-RTU-SL'), + ( 'FS-RTU-P4-SL') + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/script/4.1/schema/4.create_device_model.sql b/script/4.1/schema/4.create_device_model.sql new file mode 100644 index 0000000..352e429 --- /dev/null +++ b/script/4.1/schema/4.create_device_model.sql @@ -0,0 +1,12 @@ + +create table device_model +( + id serial + constraint device_model_pk + primary key, + model_name text +); + +comment on table device_model is '设备类型表'; + +comment on column device_model.model_name is '类型名字'; \ No newline at end of file