Files
nxxmdata/government-backend/models/DeviceWarning.js

137 lines
3.1 KiB
JavaScript
Raw Normal View History

2025-10-11 08:53:47 +08:00
const { DataTypes, Sequelize } = require('sequelize');
const config = require('../config/index.js');
// 创建专门的Sequelize实例不使用underscored
const sequelize = new Sequelize(
config.DB_CONFIG.database,
config.DB_CONFIG.user,
config.DB_CONFIG.password,
{
host: config.DB_CONFIG.host,
port: config.DB_CONFIG.port,
dialect: config.DB_CONFIG.dialect,
logging: console.log,
define: {
timestamps: true,
paranoid: false,
underscored: false, // 明确设置为false
freezeTableName: true
},
timezone: '+08:00'
}
);
2025-10-09 18:01:06 +08:00
const DeviceWarning = sequelize.define('DeviceWarning', {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
farmName: {
type: DataTypes.STRING,
allowNull: false,
comment: '养殖场名称',
field: 'farmName'
},
farmerName: {
type: DataTypes.STRING,
allowNull: false,
comment: '养殖户名称',
field: 'farmerName'
},
phone: {
type: DataTypes.STRING,
allowNull: false,
comment: '联系电话',
field: 'phone'
},
deviceType: {
type: DataTypes.ENUM('智能耳标', '智能项圈', '智能主机'),
allowNull: false,
comment: '设备类型',
field: 'deviceType'
},
deviceNumber: {
type: DataTypes.STRING,
allowNull: false,
comment: '设备编号',
field: 'deviceNumber'
},
alertType: {
type: DataTypes.ENUM('设备离线', '电量不足', '信号异常', '温度异常', '其他'),
allowNull: false,
comment: '预警类型',
field: 'alertType'
},
alertLevel: {
type: DataTypes.ENUM('high', 'medium', 'low'),
allowNull: false,
defaultValue: 'medium',
comment: '预警级别 (高, 中, 低)',
field: 'alertLevel'
},
alertTime: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
comment: '预警时间',
field: 'alertTime'
},
status: {
type: DataTypes.ENUM('active', 'resolved', 'ignored'),
allowNull: false,
defaultValue: 'active',
comment: '预警状态 (活跃, 已解决, 已忽略)',
field: 'status'
},
description: {
type: DataTypes.TEXT,
comment: '预警描述',
2025-10-11 08:53:47 +08:00
field: 'description'
2025-10-09 18:01:06 +08:00
},
location: {
type: DataTypes.STRING,
comment: '设备位置',
2025-10-11 08:53:47 +08:00
field: 'location'
2025-10-09 18:01:06 +08:00
},
batteryLevel: {
type: DataTypes.INTEGER,
comment: '电池电量百分比',
2025-10-11 08:53:47 +08:00
field: 'batteryLevel'
2025-10-09 18:01:06 +08:00
},
signalStrength: {
type: DataTypes.INTEGER,
comment: '信号强度',
2025-10-11 08:53:47 +08:00
field: 'signalStrength'
2025-10-09 18:01:06 +08:00
},
temperature: {
type: DataTypes.FLOAT,
comment: '温度值',
2025-10-11 08:53:47 +08:00
field: 'temperature'
2025-10-09 18:01:06 +08:00
},
resolvedBy: {
type: DataTypes.STRING,
comment: '解决人',
2025-10-11 08:53:47 +08:00
field: 'resolvedBy'
2025-10-09 18:01:06 +08:00
},
resolvedAt: {
type: DataTypes.DATE,
comment: '解决时间',
2025-10-11 08:53:47 +08:00
field: 'resolvedAt'
2025-10-09 18:01:06 +08:00
},
remarks: {
type: DataTypes.TEXT,
comment: '备注',
2025-10-11 08:53:47 +08:00
field: 'remarks'
2025-10-09 18:01:06 +08:00
},
}, {
tableName: 'device_warnings',
timestamps: true,
createdAt: 'createdAt',
updatedAt: 'updatedAt',
paranoid: false,
2025-10-11 08:53:47 +08:00
underscored: false, // 覆盖全局配置,不使用下划线命名
2025-10-09 18:01:06 +08:00
});
module.exports = DeviceWarning;