diff --git a/core.go b/core.go index 869ce6b..1f8119c 100644 --- a/core.go +++ b/core.go @@ -3,6 +3,7 @@ package time_arrow import ( "errors" "fmt" + "github.com/google/uuid" "log" "sort" "strings" @@ -23,7 +24,7 @@ type DateSlice struct { } type TimeArrow struct { - TimeArrowId int `json:"time_arrow_id"` + TimeArrowId string `json:"time_arrow_id"` Group string `json:"group"` Type TimeArrowType `json:"type"` //可选 @@ -165,9 +166,15 @@ func isInExpandTags(ta TimeArrow, expandTag string) bool { return false } +func createUUID() string { + uid := uuid.Must(uuid.NewUUID()) + return uid.String() +} + //CreateDayOfWeekTypePlan 创建一个每周计划 func CreateDayOfWeekTypePlan(group string, dayOfWeek []int, timesOnDay []string, expandValue interface{}, expandTags []string, weights float64) TimeArrow { return TimeArrow{ + TimeArrowId: createUUID(), Type: TimeArrowTypeDayOfWeek, Group: group, DayOfWeek: dayOfWeek, @@ -181,6 +188,7 @@ func CreateDayOfWeekTypePlan(group string, dayOfWeek []int, timesOnDay []string, //CreateDayOfMonthTypePlan 创建一个每月计划 func CreateDayOfMonthTypePlan(group string, dayOfMonth []int, timesOnDay []string, expandValue interface{}, expandTags []string, weights float64) TimeArrow { return TimeArrow{ + TimeArrowId: createUUID(), Type: TimeArrowTypeDayOfMonth, Group: group, DayOfMonth: dayOfMonth, @@ -194,6 +202,7 @@ func CreateDayOfMonthTypePlan(group string, dayOfMonth []int, timesOnDay []strin //CreateDateSliceTypePlan 创建一个时间段计划 func CreateDateSliceTypePlan(group string, dateSlice []DateSlice, timesOnDay []string, expandValue interface{}, expandTags []string, weights float64) TimeArrow { return TimeArrow{ + TimeArrowId: createUUID(), Type: TimeArrowTypeDateSlice, Group: group, DateSlice: dateSlice,