新增数据

This commit is contained in:
2025-01-07 13:50:42 +08:00
parent 27c08f735c
commit ab08f7e169
3 changed files with 70 additions and 0 deletions

View File

@@ -53,6 +53,8 @@ func InitGorm() {
func AutoMigrate(db *gorm.DB) {
err := db.AutoMigrate(
new(model.Device),
new(model.DevData),
new(model.DevUpData),
)
if err != nil {
fmt.Println("[-] 迁移数据表失败:", err.Error())

44
model/DevData.go Normal file
View File

@@ -0,0 +1,44 @@
package model
import (
"DT/global"
"gorm.io/gorm"
"time"
)
type DevData struct {
Id int `gorm:"column:id;primaryKey" json:"id"`
Imei string `gorm:"column:imei;comment:IMEI;type:varchar(255)" json:"imei"`
X1 string `gorm:"column:x1;comment:x轴加速度;type:varchar(255)" json:"x1"`
Y1 string `gorm:"column:y1;comment:y轴加速度;type:varchar(255)" json:"y1"`
Z1 string `gorm:"column:z1;comment:z轴加速度;type:varchar(255)" json:"z1"`
A string `gorm:"column:a;comment:精确楼层;type:varchar(255)" json:"a"`
B string `gorm:"column:b;comment:平层/非平层;type:varchar(255)" json:"b"`
C string `gorm:"column:c;comment:分贝数;type:varchar(255)" json:"c"`
D string `gorm:"column:d;comment:轿厢门打开/关闭状态;type:varchar(255)" json:"d"`
E string `gorm:"column:e;comment:电梯困人报警;type:varchar(255)" json:"e"`
F string `gorm:"column:f;comment:轿厢门长时间未关;type:varchar(255)" json:"f"`
R string `gorm:"column:r;comment:电梯内有人/无人;type:varchar(255)" json:"r"`
Q string `gorm:"column:q;comment:电梯反复开关门;type:varchar(255)" json:"q"`
I string `gorm:"column:i;comment:电梯开门状态下电梯运行;type:varchar(255)" json:"i"`
J string `gorm:"column:j;comment:电梯运行超速;type:varchar(255)" json:"j"`
K string `gorm:"column:k;comment:电梯运行异常抖动;type:varchar(255)" json:"k"`
L string `gorm:"column:l;comment:电梯运行中异常声音;type:varchar(255)" json:"l"`
O string `gorm:"column:o;comment:开始到结束规定时间内电梯进行了维修保养;type:varchar(255)" json:"o"`
P string `gorm:"column:p;comment:P;type:varchar(255)" json:"p"`
M string `gorm:"column:m;comment:电梯上行/下行/静止/运行;type:varchar(255)" json:"m"`
X string `gorm:"column:x;comment:x轴角度;type:varchar(255)" json:"x"`
Y string `gorm:"column:y;comment:y轴角度;type:varchar(255)" json:"y"`
Z string `gorm:"column:z;comment:z轴角度;type:varchar(255)" json:"z"`
G string `gorm:"column:g;comment:电梯有电/断电;type:varchar(255)" json:"g"`
T string `gorm:"column:t;comment:电梯正常/检修状态;type:varchar(255)" json:"t"`
Created time.Time `gorm:"column:created;autoCreateTime;comment:创建时间" json:"created"`
Updated time.Time `gorm:"column:updated;autoUpdateTime;comment:修改时间" json:"updated"`
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
}
func (r *DevData) TableName() string {
return global.AppConf.Db.TablePrefix + "dev_data"
}

24
model/DevUpData.go Normal file
View File

@@ -0,0 +1,24 @@
package model
import (
"DT/global"
"gorm.io/gorm"
"time"
)
type DevUpData struct {
Id int `gorm:"column:id;primaryKey" json:"id"`
Imei string `gorm:"column:imei;comment:IMEI;type:varchar(255)" json:"imei"`
Sum string `gorm:"column:sum;comment:IMEI;type:varchar(255)" json:"sum"`
Time string `gorm:"column:time;comment:IMEI;type:varchar(255)" json:"time"`
Mile string `gorm:"column:mile;comment:IMEI;type:varchar(255)" json:"mile"`
Created time.Time `gorm:"column:created;autoCreateTime;comment:创建时间" json:"created"`
Updated time.Time `gorm:"column:updated;autoUpdateTime;comment:修改时间" json:"updated"`
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
}
func (r *DevUpData) TableName() string {
return global.AppConf.Db.TablePrefix + "dev_up_data"
}