Browse Source

feat:固件升级修改为可配置(新增数据库表)

dev
zhaobing’ 1 year ago
parent
commit
396c9bf084
  1. 12
      api/app/lib/controllers/firmwareUpgrade/index.js
  2. 35
      api/app/lib/models/device_model.js
  3. 39
      script/4.1/data/1.insert_into_device_model.sql
  4. 12
      script/4.1/schema/4.create_device_model.sql

12
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

35
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;
};

39
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')

12
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 '类型名字';
Loading…
Cancel
Save