新增测点配置
This commit is contained in:
23
model/device_point.go
Normal file
23
model/device_point.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"energy-management-system/global"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DevicePoint 设备测点配置
|
||||
type DevicePoint struct {
|
||||
Id int `gorm:"column:id;primaryKey" json:"id"`
|
||||
DriverId int `gorm:"column:driver_id;comment:设备ID" json:"driver_id"`
|
||||
PointId int `gorm:"column:point_id;comment:测点ID" json:"point_id"`
|
||||
EnergyType int `gorm:"column:energy_type;comment:能源类型" json:"energy_type"`
|
||||
PointNameId int `gorm:"column:point_name_id;comment:测点名称ID" json:"point_name_id"`
|
||||
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 *DevicePoint) TableName() string {
|
||||
return global.AppConf.Db.TablePrefix + "device_point_configs"
|
||||
}
|
||||
@@ -21,7 +21,10 @@ func initDB(InitDBFunctions ...InitDBFunc) (err error) {
|
||||
}
|
||||
|
||||
func InitDbData() {
|
||||
err := initDB(initPeakValleyTimeBlockData)
|
||||
err := initDB(
|
||||
initPeakValleyTimeBlockData,
|
||||
initPointNameData,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println("[-]初始化基础数据失败:", err)
|
||||
os.Exit(0)
|
||||
|
||||
56
model/init-db-data/point_name.go
Normal file
56
model/init-db-data/point_name.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package init_db_data
|
||||
|
||||
import (
|
||||
"energy-management-system/global"
|
||||
"energy-management-system/model"
|
||||
"github.com/gookit/color"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type InitPointNameData struct{}
|
||||
|
||||
var initPointNameData = new(InitPointNameData)
|
||||
|
||||
// type api struct{}
|
||||
//func buildData() (dataList []*peak_valley_model.PeakValleyTimeBlock) {
|
||||
// // 一天有24小时,即1440分钟
|
||||
// totalMinutes := 24 * 60
|
||||
// // 时间块的持续时间:10分钟
|
||||
// blockDuration := 10
|
||||
// // 遍历一天中的所有时间块
|
||||
// for i := 0; i < totalMinutes; i += blockDuration {
|
||||
// startTime := i
|
||||
// endTime := i + blockDuration
|
||||
// dataList = append(dataList, &peak_valley_model.PeakValleyTimeBlock{
|
||||
// StartTime: uint(startTime),
|
||||
// EndTime: uint(endTime),
|
||||
// })
|
||||
// }
|
||||
// return dataList
|
||||
//}
|
||||
|
||||
var pointNames = []model.PointName{
|
||||
{Name: "测点-用电量"},
|
||||
{Name: "测点-用水量"},
|
||||
}
|
||||
|
||||
// Init 初始化用户数据
|
||||
func (i *InitPointNameData) Init() error {
|
||||
return global.Db.Transaction(func(tx *gorm.DB) error {
|
||||
m := &model.PointName{}
|
||||
var count int64
|
||||
err := tx.Model(&model.PointName{}).Count(&count).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if count > 0 {
|
||||
color.Danger.Println("\n[PGSQL] --> " + m.TableName() + " 表的初始数据已存在!")
|
||||
return nil
|
||||
}
|
||||
if err := tx.Create(&pointNames).Error; err != nil { // 遇到错误时回滚事务
|
||||
return err
|
||||
}
|
||||
color.Info.Println("\n[PGSQL] --> " + m.TableName() + " 表初始数据成功!")
|
||||
return nil
|
||||
})
|
||||
}
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
)
|
||||
|
||||
type PeakValleyQuarter struct {
|
||||
Id uint `gorm:"column:id;primaryKey" json:"id"`
|
||||
Id int `gorm:"column:id;primaryKey" json:"id"`
|
||||
QuarterName string `gorm:"column:quarter_name;comment:季度名称" json:"quarter_name"`
|
||||
StartTime time.Time `gorm:"column:start_time;type:date;comment:开始时间" json:"start_time"`
|
||||
EndTime time.Time `gorm:"column:end_time;type:date;comment:结束时间" json:"end_time"`
|
||||
Rid uint `gorm:"column:rid;comment:季度使用规则" json:"rid"`
|
||||
Rid int `gorm:"column:rid;comment:季度使用规则" json:"rid"`
|
||||
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:"-"`
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
//(将时间段 转化为十分钟区块 查找到对应十分钟区块 创建该规则的电价)
|
||||
|
||||
type PeakValleyRule struct {
|
||||
RuleId uint `gorm:"column:rule_id;primaryKey" json:"rule_id"`
|
||||
RuleId int `gorm:"column:rule_id;primaryKey" json:"rule_id"`
|
||||
RuleName string `gorm:"column:rule_name;comment:规则名称" json:"rule_name"`
|
||||
Description string `gorm:"column:description;comment:描述" json:"description"`
|
||||
Created time.Time `gorm:"column:created;autoCreateTime;comment:创建时间" json:"created"`
|
||||
|
||||
@@ -11,7 +11,7 @@ const MinutesInADay = 24 * 60
|
||||
|
||||
// PeakValleyTimeBlock 峰谷时间区块
|
||||
type PeakValleyTimeBlock struct {
|
||||
BlockIndex uint `gorm:"column:block_index;primaryKey;comment:区块编号" json:"block_index"`
|
||||
BlockIndex int `gorm:"column:block_index;primaryKey;comment:区块编号" json:"block_index"`
|
||||
StartTime uint `gorm:"column:start_time;comment:开始时间" json:"start_time"`
|
||||
EndTime uint `gorm:"column:end_time;comment:结束时间" json:"end_time"`
|
||||
Created time.Time `gorm:"column:created;autoCreateTime;comment:创建时间" json:"created"`
|
||||
|
||||
@@ -35,12 +35,12 @@ type PeakValleyType struct {
|
||||
|
||||
// PeakValleyTimeBlockPrice 峰谷时间区块价格
|
||||
type PeakValleyTimeBlockPrice struct {
|
||||
Id uint `gorm:"column:id;primaryKey" json:"id"`
|
||||
BlockId uint `gorm:"column:block_id;comment:时间区块编号" json:"block_id"`
|
||||
Id int `gorm:"column:id;primaryKey" json:"id"`
|
||||
BlockId int `gorm:"column:block_id;comment:时间区块编号" json:"block_id"`
|
||||
Price int `gorm:"column:price;comment:价格" json:"price"`
|
||||
CustomName string `gorm:"column:custom_name;comment:自定义名称" json:"custom_name"`
|
||||
PeakValleyRuleId uint `gorm:"column:peak_valley_rule_id;comment:峰谷规则" json:"peak_valley_rule_id"`
|
||||
PeakValleyType uint `gorm:"column:peak_valley_type;default:1;size:10;comment:峰谷类型[1:尖,2:峰,3:平,4:谷,5:深谷]" json:"peak_valley_type"` // 峰谷类型
|
||||
PeakValleyRuleId int `gorm:"column:peak_valley_rule_id;comment:峰谷规则" json:"peak_valley_rule_id"`
|
||||
PeakValleyType int `gorm:"column:peak_valley_type;default:1;size:10;comment:峰谷类型[1:尖,2:峰,3:平,4:谷,5:深谷]" json:"peak_valley_type"` // 峰谷类型
|
||||
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:"-"`
|
||||
|
||||
20
model/point_name.go
Normal file
20
model/point_name.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"energy-management-system/global"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// PointName 测点名称
|
||||
type PointName struct {
|
||||
Id int `gorm:"column:id;primaryKey" json:"id"`
|
||||
Name string `gorm:"column:name;comment:测点名称" json:"name"`
|
||||
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 *PointName) TableName() string {
|
||||
return global.AppConf.Db.TablePrefix + "point_names"
|
||||
}
|
||||
Reference in New Issue
Block a user