Files
smart_grid_iot/server/src/entity/electric_gateway.entity.ts
T

72 lines
2.6 KiB
TypeScript

import { Column, Model, Table, DataType, CreatedAt, ForeignKey, BelongsTo } from "sequelize-typescript";
import Customer from "./customer.entity";
import CustomerEquipment from "./customer_equipment.entity";
@Table({
tableName: "electric_gateway",
comment: "智电改造网关设备表(ICC 同步)",
timestamps: false,
indexes: [
{ name: "idx_gateway_customer", fields: ["customer_id"] },
{ name: "idx_gateway_equip", fields: ["equip_id"] },
{ name: "idx_gateway_imei", fields: ["icc_imei"] }
]
})
export default class ElectricGateway extends Model {
@Column({ type: DataType.BIGINT, autoIncrement: true, primaryKey: true })
id!: number;
@Column({ type: DataType.STRING(64), unique: true, field: "icc_imei", comment: "设备唯一标识码(imei)" })
iccImei!: string;
@Column({ type: DataType.STRING(64), unique: true, field: "device_code", comment: "设备编码" })
deviceCode!: string;
@Column({ type: DataType.STRING(128), field: "device_name", comment: "设备名称" })
deviceName!: string;
@ForeignKey(() => Customer)
@Column({ type: DataType.BIGINT, allowNull: false, field: "customer_id", comment: "客户 ID(由 orgCode→customer.icc_code 解析)" })
customerId!: number;
@ForeignKey(() => CustomerEquipment)
@Column({ type: DataType.BIGINT, field: "equip_id", comment: "客户设备 ID(→ customer_equipment,可手动关联)" })
equipId!: number;
@Column({ type: DataType.STRING(64), field: "org_code", comment: "ICC 组织编码" })
orgCode!: string;
@Column({ type: DataType.STRING(128), field: "org_name", comment: "ICC 组织名称" })
orgName!: string;
@Column({ type: DataType.STRING(64), field: "manufacturer_code", comment: "厂商编码" })
manufacturerCode!: string;
@Column({ type: DataType.STRING(128), field: "manufacturer_name", comment: "厂商名称" })
manufacturerName!: string;
@Column({ type: DataType.STRING(32), field: "type_code", comment: "设备类型编码" })
typeCode!: string;
@Column({ type: DataType.STRING(64), field: "type_name", comment: "设备类型名称" })
typeName!: string;
@Column({ type: DataType.STRING(64), field: "product_model", comment: "产品型号" })
productModel!: string;
@Column({ type: DataType.SMALLINT, allowNull: false, defaultValue: 1, field: "is_online", comment: "在线状态:1在线 0离线" })
isOnline!: number;
@Column({ type: DataType.DATE, field: "synced_at", comment: "ICC 同步时间" })
syncedAt!: Date;
@BelongsTo(() => Customer, { foreignKey: "customerId", as: "customer" })
customer!: Customer;
@BelongsTo(() => CustomerEquipment, { foreignKey: "equipId", as: "equipment" })
equipment!: CustomerEquipment;
@CreatedAt
created_at!: Date;
}