提交 5f40c73d 编写于 作者: J Jason

项目和模板 整理完成,共用一套结构(现存问题:修改了变量,自动更新项目比较麻烦)

上级 c2da5100
package models
import "time"
type Device struct {
ID int `json:"id"`
TunnelId int `json:"tunnel_id"`
LinkId int `json:"link_id"`
ProjectId int `json:"project_id"`
Name string `json:"name"`
Description string `json:"description"`
Serial string `json:"serial"`
//定位,或手动选择
Longitude float64 `json:"longitude"`
Latitude float64 `json:"latitude"`
Created time.Time `json:"created" storm:"created"`
Updated time.Time `json:"updated" storm:"updated"`
}
//默认WGS84标准,GCJ02、BD09都需要转换
type Location struct {
ID int `json:"id"`
DeviceId int `json:"device_id"`
Latitude float64 `json:"latitude"` //纬度
Longitude float64 `json:"longitude"` //经度
//Altitude float64 `json:"altitude"` //高度 单位m
Created time.Time `json:"created" storm:"created"`
}
......@@ -2,14 +2,6 @@ package models
import "time"
type Address struct {
Area string `json:"area"` //区域 类似 S I O Q WR ……
Slave uint8 `json:"slave"` //从站号 modbus
Offset uint16 `json:"offset"`
ReadCode uint8 `json:"read_code"`
WriteCode uint8 `json:"write_code"`
}
type Element struct {
ID int `json:"id"`
Name string `json:"name"`
......@@ -21,6 +13,8 @@ type Element struct {
Model string `json:"model"` //型号
Version string `json:"version"` //版本
Variables []ElementVariable `json:"variables"`
Created time.Time `json:"created" storm:"created"`
Updated time.Time `json:"updated" storm:"updated"`
}
......@@ -32,9 +26,6 @@ type Element struct {
// hold 保持寄存器(3读多个、6写单个、16写多个,--23读写多个--)
type ElementVariable struct {
ID int `json:"id"`
ElementId int `json:"element_id"`
Name string `json:"name"`
//Alias string `json:"alias"` //别名,用于编程
Area string `json:"area"`
......@@ -42,11 +33,8 @@ type ElementVariable struct {
Type string `json:"type"`
Unit string `json:"unit"` //单位
Scale float32 `json:"scale"` //倍率,比如一般是 整数÷10,得到
Scale float32 `json:"scale"` //倍率,比如一般是 整数÷10,得到
Default string `json:"default"`
ReadOnly bool `json:"read_only"` //只读
Created time.Time `json:"created" storm:"created"`
Updated time.Time `json:"updated" storm:"updated"`
}
......@@ -3,40 +3,63 @@ package models
import "time"
type Project struct {
ProjectTemplate `storm:"inline"`
TemplateId int `json:"template_id"`
LinkBinds []int `json:"link_binds"`
}
type ProjectTemplate struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Origin string `json:"origin"` //模板ID
UUID string `json:"uuid"` //唯一码,自动生成
//UUID string `json:"uuid"` //唯一码,自动生成
Version string `json:"version"`
Disabled bool `json:"disabled"`
Elements []struct {
ElementId int `json:"element_id"`
LinkId int `json:"link_id"`
Slave uint8 `json:"slave"` //从站号
Name string `json:"name"`
Alias string `json:"alias"` //别名,用于编程
Variables []struct {
VariableId int `json:"variable_id"`
Alias string `json:"alias"` //别名,用于编程
Correct float32 `json:"correct"` //校准
}
}
Jobs []struct {
Name string `json:"name"`
Cron string `json:"cron"`
Script string `json:"script"` //javascript
}
Strategies []struct {
Name string `json:"name"`
Script string `json:"script"` //javascript
}
Links []ProjectLink `json:"links"`
Elements []ProjectElement `json:"elements"`
Jobs []ProjectJob `json:"jobs"`
Strategies []ProjectStrategy `json:"strategies"`
Created time.Time `json:"created" storm:"created"`
Updated time.Time `json:"updated" storm:"updated"`
}
type ProjectLink struct {
Name string `json:"name"`
Protocol string `json:"protocol"`
}
type ProjectElement struct {
ElementId int `json:"element_id"`
Link int `json:"link"` //链接号:0,1,2,3
Slave uint8 `json:"slave"` //从站号
Name string `json:"name"`
Alias string `json:"alias"` //别名,用于编程
Variables []ProjectElementVariable `json:"variables"`
}
type ProjectElementVariable struct {
ElementVariable `storm:"inline"`
Name string `json:"name"`
Alias string `json:"alias"` //别名,用于编程
Correct float32 `json:"correct"` //校准
}
type ProjectJob struct {
Name string `json:"name"`
Cron string `json:"cron"`
Script string `json:"script"` //javascript
}
type ProjectStrategy struct {
Name string `json:"name"`
Script string `json:"script"` //javascript
}
package models
type Template struct {
Name string `json:"name"`
Description string `json:"description"`
Version string `json:"version"`
Elements []TemplateElement `json:"elements"`
Jobs []TemplateJob `json:"jobs"`
Strategies []TemplateStrategy `json:"strategies"`
}
type TemplateJob struct {
Name string `json:"name"`
Cron string `json:"cron"`
Script string `json:"script"` //javascript
}
type TemplateStrategy struct {
Name string `json:"name"`
Script string `json:"script"` //javascript
}
type TemplateElement struct {
}
......@@ -3,9 +3,7 @@ package models
import "time"
type Tunnel struct {
ID int `json:"id"`
ProjectId int `json:"project_id"` //模型ID
ID int `json:"id"`
Name string `json:"name"`
Type string `json:"type"` //tcp-server tcp-client udp-server udp-client serial
Addr string `json:"addr"`
......@@ -23,7 +21,10 @@ type Tunnel struct {
Disabled bool `json:"disabled"`
Active bool `json:"active"`
Active bool `json:"active"`
TemplateId int `json:"template_id"` //模板ID
Created time.Time `json:"created" storm:"created"`
Updated time.Time `json:"updated" storm:"updated"`
}
......@@ -31,7 +32,8 @@ type Tunnel struct {
type Link struct {
ID int `json:"id"`
TunnelId int `json:"tunnel_id"`
ProjectId int `json:"project_id"` //模型ID,默认继承自Tunnel
ProjectId int `json:"project_id"` //项目ID
Serial string `json:"serial" storm:"index"`
Addr string `json:"addr"`
......@@ -40,4 +42,3 @@ type Link struct {
Online time.Time `json:"online"`
Created time.Time `json:"created" storm:"created"`
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册