Files
energy-management-system/model/peak-valley/peak_valley_time_block.go
2024-09-03 15:52:38 +08:00

59 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package peak_valley
import (
"energy-management-system/global"
"fmt"
"gorm.io/gorm"
"time"
)
const MinutesInADay = 24 * 60
// PeakValleyTimeBlock 峰谷时间区块
type PeakValleyTimeBlock struct {
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"`
Updated time.Time `gorm:"column:updated;autoUpdateTime;comment:修改时间" json:"updated"`
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
}
func (r *PeakValleyTimeBlock) TableName() string {
return global.AppConf.Db.TablePrefix + "peak_valley_time_blocks"
}
func Init() {
// 一天有24小时即1440分钟
totalMinutes := 24 * 60
// 时间块的持续时间10分钟
blockDuration := 10
// 遍历一天中的所有时间块
for i := 0; i < totalMinutes; i += blockDuration {
startTime := i
endTime := i + blockDuration
fmt.Println("start", startTime)
fmt.Println("start", endTime)
global.Db.Create(&PeakValleyTimeBlock{
StartTime: uint(startTime),
EndTime: uint(endTime),
})
// 打印开始时间和结束时间,格式为 HH:MM
//fmt.Printf("时间块 %d: 开始时间: %02d:%02d, 结束时间: %02d:%02d\n",
// i/blockDuration+1,
// startTime/60, startTime%60,
// endTime/60, endTime%60)
// 使用整数存储时间块的开始和结束时间(以分钟为单位)
//startTime := 0 // 00:00
//endTime := 10 // 00:10
//
//fmt.Printf("开始时间: %02d:%02d\n", startTime/60, startTime%60)
//fmt.Printf("结束时间: %02d:%02d\n", endTime/60, endTime%60)
}
}