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