处理时间段是否重叠问题

This commit is contained in:
2024-08-29 09:41:48 +08:00
parent a27c5f702f
commit 2d73dada03
2 changed files with 65 additions and 0 deletions

View File

@@ -115,11 +115,26 @@ func (r *PeakValley) CreatePeakValleyRule(req *form.CreatePeakValleyRuleReq) {
var timeBlockIds []uint
var timeBlockIdsMap = make(map[string][]uint)
var timeGroup [][]int
for _, item := range req.RuleItem {
start, end, blockTotal, err = utils.GetMinutesFromTimeRange(item.StartTime, item.EndTime)
if err != nil {
return
}
if start > end {
err = errors.New("开始时间大于结束时间")
return
}
in := []int{start, end}
timeGroup = append(timeGroup, in)
if utils.HasOverlap(timeGroup) {
err = errors.New("选择的时间段与其他时间段有重叠")
return
}
// 总时常判断
total += blockTotal
if total > peak_valley_model.MinutesInADay {
err = errors.New("选择的时间段超过一天")
@@ -195,11 +210,25 @@ func (r *PeakValley) UpdatePeakValleyRule(req *form.UpdatePeakValleyRuleReq) {
var timeBlockIds []uint
var timeBlockIdsMap = make(map[string][]uint)
var timeGroup [][]int
for _, item := range req.RuleItem {
start, end, blockTotal, err = utils.GetMinutesFromTimeRange(item.StartTime, item.EndTime)
if err != nil {
return
}
if start > end {
err = errors.New("开始时间大于结束时间")
return
}
in := []int{start, end}
timeGroup = append(timeGroup, in)
if utils.HasOverlap(timeGroup) {
err = errors.New("选择的时间段与其他时间段有重叠")
return
}
// 总时常判断
total += blockTotal
if total > peak_valley_model.MinutesInADay {
err = errors.New("选择的时间段超过一天")