feat(Implement-measurement-and-bay-structure-by-go): Implement measurement and bay structure by go

http://server.baseware.net:9000/project/datart/us/38?milestone=13
This commit is contained in:
douxu 2025-08-13 16:24:29 +08:00
parent 49fbd04644
commit f7a1ea2540
2 changed files with 112 additions and 0 deletions

View File

@ -0,0 +1,69 @@
package orm
import (
"time"
"github.com/gofrs/uuid"
)
// Bay structure define abstracted info set of electrical bay
type Bay struct {
BayUUID uuid.UUID `gorm:"column:BAY_UUID;type:uuid;primaryKey;default:gen_random_uuid()"`
Name string `gorm:"column:NAME;size:64;not null;default:''"`
Type string `gorm:"column:TYPE;size:64;not null;default:''"`
Unom float64 `gorm:"column:UNOM;not null;default:-1"`
Fla float64 `gorm:"column:FLA;not null;default:-1"`
Capacity float64 `gorm:"column:CAPACITY;not null;default:-1"`
Description string `gorm:"column:DESCRIPTION;size:512;not null;default:''"`
InService bool `gorm:"column:IN_SERVICE;not null;default:false"`
State int `gorm:"column:STATE;not null;default:-1"`
Grid string `gorm:"column:GRID;size:64;not null;default:''"`
Zone string `gorm:"column:ZONE;size:64;not null;default:''"`
Station string `gorm:"column:STATION;size:64;not null;default:''"`
Business map[string]interface{} `gorm:"column:BUSINESS;type:jsonb;not null;default:'{}'"`
Context map[string]interface{} `gorm:"column:CONTEXT;type:jsonb;not null;default:'{}'"`
FromUUIDs []uuid.UUID `gorm:"column:FROM_UUIDS;type:jsonb;not null;default:'[]'"`
ToUUIDs []uuid.UUID `gorm:"column:TO_UUIDS;type:jsonb;not null;default:'[]'"`
DevProtect []interface{} `gorm:"column:DEV_PROTECT;type:jsonb;not null;default:'[]'"`
DevFaultRecord []interface{} `gorm:"column:DEV_FAULT_RECORD;type:jsonb;not null;default:'[]'"`
DevStatus []interface{} `gorm:"column:DEV_STATUS;type:jsonb;not null;default:'[]'"`
DevDynSense []interface{} `gorm:"column:DEV_DYN_SENSE;type:jsonb;not null;default:'[]'"`
DevInstruct []interface{} `gorm:"column:DEV_INSTRUCT;type:jsonb;not null;default:'[]'"`
DevEtc []interface{} `gorm:"column:DEV_ETC;type:jsonb;not null;default:'[]'"`
Components []uuid.UUID `gorm:"column:COMPONENTS;type:uuid[];not null;default:'{}'"`
Op int `gorm:"column:OP;not null;default:-1"`
Ts time.Time `gorm:"column:TS;type:timestamptz;not null;default:CURRENT_TIMESTAMP"`
}
// TableName func respresent return table name of Bay
func (Bay) TableName() string {
return "BAY"
}
// CREATE TABLE PUBLIC.BAY (
// BAY_UUID UUID PRIMARY KEY DEFAULT GEN_RANDOM_UUID(),
// NAME VARCHAR(64) NOT NULL DEFAULT '',
// TYPE VARCHAR(64) NOT NULL DEFAULT '',
// UNOM DOUBLE PRECISION NOT NULL DEFAULT -1,
// FLA DOUBLE PRECISION NOT NULL DEFAULT -1,
// CAPACITY DOUBLE PRECISION NOT NULL DEFAULT -1,
// DESCRIPTION VARCHAR(512) NOT NULL DEFAULT '',
// IN_SERVICE BOOLEAN NOT NULL DEFAULT FALSE,
// STATE INTEGER NOT NULL DEFAULT -1,
// GRID VARCHAR(64) NOT NULL DEFAULT '',
// ZONE VARCHAR(64) NOT NULL DEFAULT '',
// STATION VARCHAR(64) NOT NULL DEFAULT '',
// BUSINESS JSONB NOT NULL DEFAULT '{}', -- for Server
// CONTEXT JSONB NOT NULL DEFAULT '{}', -- for UI
// FROM_UUIDS JSONB NOT NULL DEFAULT '[]', -- uuids
// TO_UUIDS JSONB NOT NULL DEFAULT '[]', -- uuids
// DEV_PROTECT JSONB NOT NULL DEFAULT '[]', -- devices
// DEV_FAULT_RECORD JSONB NOT NULL DEFAULT '[]', -- devices
// DEV_STATUS JSONB NOT NULL DEFAULT '[]', -- devices
// DEV_DYN_SENSE JSONB NOT NULL DEFAULT '[]', -- devices
// DEV_INSTRUCT JSONB NOT NULL DEFAULT '[]', -- devices
// DEV_ETC JSONB NOT NULL DEFAULT '[]', -- devices
// COMPONENTS UUID[] NOT NULL DEFAULT '{}',
// OP INTEGER NOT NULL DEFAULT -1,
// TS TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP
// );

View File

@ -0,0 +1,43 @@
// Package orm define database data struct
package orm
import (
"time"
"github.com/gofrs/uuid"
)
// Measurement structure define abstracted info set of electrical measurement
type Measurement struct {
ID int64 `gorm:"column:ID;primaryKey;autoIncrement"`
Tag string `gorm:"column:TAG;size:64;not null;default:''"`
Name string `gorm:"column:NAME;size:64;not null;default:''"`
Type int16 `gorm:"column:TYPE;not null;default:-1"`
Size int `gorm:"column:SIZE;not null;default:-1"`
DataSource map[string]interface{} `gorm:"column:DATA_SOURCE;type:jsonb;not null;default:'{}'"`
BayUUID uuid.UUID `gorm:"column:BAY_UUID;type:uuid;not null"`
ComponentUUID uuid.UUID `gorm:"column:COMPONENT_UUID;type:uuid;not null"`
Op int `gorm:"column:OP;not null;default:-1"`
Ts time.Time `gorm:"column:TS;type:timestamptz;not null;default:CURRENT_TIMESTAMP"`
}
// TableName func respresent return table name of Measurement
func (Measurement) TableName() string {
return "MEASUREMENT"
}
// CREATE TABLE PUBLIC.MEASUREMENT (
// ID BIGSERIAL PRIMARY KEY,
// TAG VARCHAR(64) NOT NULL DEFAULT '',
// NAME VARCHAR(64) NOT NULL DEFAULT '',
// TYPE SMALLINT NOT NULL DEFAULT -1,
// SIZE INTEGER NOT NULL DEFAULT -1,
// DATA_SOURCE JSONB NOT NULL DEFAULT '{}', -- {"type":1,"main_pos":"","sub_pos":""}
// BAY_UUID UUID NOT NULL,
// COMPONENT_UUID UUID NOT NULL,
// OP INTEGER NOT NULL DEFAULT -1,
// TS TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
// FOREIGN KEY (BAY_UUID) REFERENCES PUBLIC.BAY (BAY_UUID),
// FOREIGN KEY (COMPONENT_UUID) REFERENCES PUBLIC.COMPONENT (GLOBAL_UUID)
// );