87 lines
2.8 KiB
Go
87 lines
2.8 KiB
Go
package peak_valley
|
|
|
|
import (
|
|
"energy-management-system/global"
|
|
"energy-management-system/utils"
|
|
"gorm.io/gorm"
|
|
"time"
|
|
)
|
|
|
|
const (
|
|
// POINTED 尖
|
|
POINTED = iota + 1
|
|
// PEAK 峰
|
|
PEAK
|
|
// FLAT 平
|
|
FLAT
|
|
// VALLEY 谷
|
|
VALLEY
|
|
// FUKAYA 深谷
|
|
FUKAYA
|
|
)
|
|
|
|
var PeakValleyTypes = map[int]string{
|
|
POINTED: "尖",
|
|
PEAK: "峰",
|
|
FLAT: "平",
|
|
VALLEY: "谷",
|
|
FUKAYA: "深谷",
|
|
}
|
|
|
|
type PeakValleyType struct {
|
|
Value int `json:"value"`
|
|
Title string `json:"title"`
|
|
}
|
|
|
|
// PeakValleyTimeBlockPrice 峰谷时间区块价格
|
|
type PeakValleyTimeBlockPrice struct {
|
|
Id uint `gorm:"column:id;primaryKey" json:"id"`
|
|
BlockId uint `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"` // 峰谷类型
|
|
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 *PeakValleyTimeBlockPrice) TableName() string {
|
|
return global.AppConf.Db.TablePrefix + "peak_valley_time_block_prices"
|
|
}
|
|
|
|
type PeakValleyRuleCustomName struct {
|
|
PeakValleyType uint `json:"peak_valley_type"`
|
|
Price int `json:"price"`
|
|
CustomName string `json:"custom_name"`
|
|
StartTime uint `json:"start_time"`
|
|
EndTime uint `json:"end_time"`
|
|
StartTimeStr string `json:"start_time_str"`
|
|
EndTimeStr string `json:"end_time_str"`
|
|
}
|
|
|
|
type PeakValleyRuleType struct {
|
|
PeakValleyType uint `json:"peak_valley_type"`
|
|
Price int `json:"price"`
|
|
RuleTimeBlocks []RuleTimeBlock `gorm:"-" json:"rule_time_blocks"`
|
|
}
|
|
|
|
type RuleTimeBlock struct {
|
|
StartTime uint `json:"start_time"`
|
|
EndTime uint `json:"end_time"`
|
|
StartTimeStr string `json:"start_time_str"`
|
|
EndTimeStr string `json:"end_time_str"`
|
|
CustomName string `json:"custom_name"`
|
|
TimeBlockIds []int `json:"-"`
|
|
}
|
|
|
|
type ByCustomNameNumber []*PeakValleyRuleCustomName
|
|
|
|
func (a ByCustomNameNumber) Len() int { return len(a) }
|
|
func (a ByCustomNameNumber) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
|
func (a ByCustomNameNumber) Less(i, j int) bool {
|
|
numI, _ := utils.ExtractNumber(a[i].CustomName)
|
|
numJ, _ := utils.ExtractNumber(a[j].CustomName)
|
|
return numI < numJ // 升序排序
|
|
}
|