'use strict' /** * Copyright (c) 2017~2019, OBCon Inc. * All rights reserved. */ /** * @file * @copyright 2017~2019, OBCon Inc. * @author gye hyun james kim [pnuskgh@gmail.com] */ // let moment = require('moment'); const Sequelize = require('sequelize'); //--- http://docs.sequelizejs.com/ const Model = utils.getClass('include', 'model.js'); //--- 향후 테이블에 필드 추가가 필요한 경우, //--- 별도의 테이블을 생성한 후 데이터를 마이그레이션 하는 방안을 고려할 것 //--- 레코드 길이 - 2019.05.24 : 약 245 class Devicedata1sModel extends Model { constructor() { super(); this._title = '정류기 데이터'; this._database = db.db_scada; this._tableName = 'devicedata1'; this._define = config.databases.scada.define; this._timestamps = false; //--- createdAt, updatedAt 필드를 사용하지 않는다. if (config.service.name == 'service_scada_techpalm') { //--- To-Do : devicedata101 테이블의 id는 BIGINT 타입을 사용한다. //--- 데이터 조회시 BIGINT가 처리될 수 있도록 id의 필드의 데이터 타입을 재정의 할 것 //--- id 필드는 Sequelize가 자동으로 생성하는 필드라서 현재는 이를 해결할 방법이 없음 (문제점) this._tableName = 'devicedata101'; } //--- To-Do : 향후 db.db_scadadata DB를 사용하도록 수정 한다. 현재는 오류가 발생함 // this._database = db.db_scadadata; // this._tableName = 'devicedata2'; // this._define = config.databases.scadadata.define; } get fields() { return { siteKey: { type: Sequelize.STRING(8), allowNull: false, unique: false, validate: { }, title: '사이트', strType: 'string' }, type: { type: Sequelize.STRING(2), allowNull: false, defaultValue: '1', validate: { }, title: '단말기 타입', strType: 'select', enum: this.getTypeEnum() }, deviceKey: { //--- 장비 아이디, RTU ID type: Sequelize.STRING(8), allowNull: false, unique: false, validate: { }, title: '아이디', strType: 'string' }, statusDatetime: { //--- 장비 상태 수집 일자 (YYYYMMDDHHmmss) type: Sequelize.STRING(14), allowNull: true, validate: { }, title: '발생일자', strType: 'string' }, dcVoltage: { //--- 1 type: Sequelize.FLOAT, allowNull: true, defaultValue: 0.0, validate: { }, title: 'DC 전압', strType: 'float' }, dcElectric: { //--- 1 type: Sequelize.FLOAT, allowNull: true, defaultValue: 0.0, validate: { }, title: 'DC 전류', strType: 'float' }, preventPotential: { //--- 1, 2, 3, 4 type: Sequelize.FLOAT, allowNull: true, defaultValue: 0.0, validate: { }, title: '방식 전위', strType: 'float' }, onTime: { //--- 1 type: Sequelize.FLOAT, allowNull: true, defaultValue: 0.0, validate: { }, title: '인터럽트 On time', strType: 'float' }, offTime: { //--- 1 type: Sequelize.FLOAT, allowNull: true, defaultValue: 0.0, validate: { }, title: '인터럽트 Off time', strType: 'float' }, batteryVoltage: { //--- 1, 2, 3, 4, 5 type: Sequelize.FLOAT, allowNull: true, defaultValue: 0.0, validate: { }, title: '배터리 전압', strType: 'float' }, temperature: { //--- 1, 2, 3, 4, 5 type: Sequelize.FLOAT, allowNull: true, defaultValue: 0.0, validate: { }, title: '장치 온도', strType: 'float' }, acVoltage: { type: Sequelize.FLOAT, allowNull: true, defaultValue: 0.0, validate: { }, title: 'AC 전압', strType: 'float' }, acElectric: { type: Sequelize.FLOAT, allowNull: true, defaultValue: 0.0, validate: { }, title: 'AC 전류', strType: 'float' }, acVoltageControl: { type: Sequelize.FLOAT, allowNull: true, defaultValue: 0.0, validate: { }, title: 'AC 전압 (제어)', strType: 'float' }, acElectricControl: { type: Sequelize.FLOAT, allowNull: true, defaultValue: 0.0, validate: { }, title: 'AC 전류 (제어)', strType: 'float' }, rectifierStatus: { //--- 1 type: Sequelize.STRING(1), allowNull: true, validate: { }, title: '문열림', strType: 'select', enum: [ ['0', '0. 닫힘'], ['1', '1. 열림'] ] }, rtuStatus: { //--- 1 type: Sequelize.STRING(1), allowNull: true, validate: { }, title: 'RTU 전원', strType: 'select', enum: [ ['0', '0. 정상'], ['1', '1. 정전'] ] }, deviceMode: { type: Sequelize.STRING(1), allowNull: true, defaultValue: '0', validate: { }, title: '정류기/PCM', strType: 'select', enum: [ ['0', '0. 정류기'], ['1', '1. PCM'] ] }, elf: { type: Sequelize.STRING(1), allowNull: true, defaultValue: '0', validate: { }, title: 'ELF', strType: 'select', enum: [ ['0', '0. OFF'], ['1', '1. ON'] ] }, elcd: { type: Sequelize.STRING(1), allowNull: true, defaultValue: '0', validate: { }, title: 'ELCD', strType: 'select', enum: [ ['0', '0. OFF'], ['1', '1. ON'] ] }, lfcd: { type: Sequelize.STRING(1), allowNull: true, defaultValue: '0', validate: { }, title: 'LFCD', strType: 'select', enum: [ ['0', '0. OFF'], ['1', '1. ON'] ] }, powerStatus: { //--- 1 type: Sequelize.STRING(1), allowNull: true, validate: { }, title: '정류기 전원', strType: 'select', enum: [ ['0', '0. 정상'], ['1', '1. 정전'] ] }, interruptRectifier: { //--- 1 type: Sequelize.STRING(1), allowNull: true, validate: { }, title: '정류기/인터럽트', strType: 'select', enum: [ ['0', '0. 정류기'], ['1', '1. 인터럽트'] ] }, operateMode: { //--- 1 type: Sequelize.STRING(1), allowNull: true, validate: { }, title: '자동/수동', strType: 'select', enum: [ ['0', '0. 자동'], ['1', '1. 수동'] ] }, controlMode: { //--- 1 type: Sequelize.STRING(1), allowNull: true, validate: { }, title: '로컬/리모트', strType: 'select', enum: [ ['0', '0. 로컬'], ['1', '1. 리모트'] ] }, operateStatus: { //--- 1 type: Sequelize.STRING(1), allowNull: true, validate: { }, title: 'Stop/Start', strType: 'select', enum: [ ['0', '0. Stop'], ['1', '1. Start'] ] }, pcmOperateStatus: { type: Sequelize.STRING(1), allowNull: true, defaultValue: '0', validate: { }, title: 'PCM 상태', strType: 'select', enum: [ ['0', '0. Stop'], ['1', '1. Start'] ] }, gpsStatus: { type: Sequelize.STRING(1), allowNull: true, defaultValue: '0', validate: { }, title: 'GPS 상태', strType: 'select', enum: [ ['1', '1. Ready'], ['0', '0. Not Ready'] ] }, gpsTime: { type: Sequelize.STRING(6), allowNull: true, defaultValue: '000000', validate: { }, title: 'GPS 시간', //--- HHmmss strType: 'string' }, interfaceVersion: { //--- Interface 버전에 따라, customData에 저장되는 데이터가 다름 type: Sequelize.STRING(8), allowNull: true, defaultValue: '1.00', validate: { }, title: '인터페이스 버전', strType: 'select', enum: [ ['1.00', '1.00'], ['1.01', '1.01'] ] }, customData: { type: Sequelize.STRING(4096), allowNull: true, defaultValue: '{}', validate: { }, title: 'Custom data', strType: 'string' } }; } } module.exports = Devicedata1sModel;