| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 | 
							- package utils
 
- import (
 
- 	"fmt"
 
- 	"pbx-api-gin/pkg/lfshook"
 
- 	"strings"
 
- )
 
- func GenCronRule(mode, timeStr string, weeks []string) string {
 
- 	switch mode {
 
- 	case "once":
 
- 		return genOnceCronRule(timeStr)
 
- 	case "loop":
 
- 		return genWeekCronRule(timeStr, weeks)
 
- 	}
 
- 	return ""
 
- }
 
- //genOnceCronRule
 
- func genOnceCronRule(timeStr string) string {
 
- 	hourMinute := strings.Split(timeStr, ":")
 
- 	if len(hourMinute) != 2 {
 
- 		lfshook.NewLogger().Errorf("error timeStr %s", timeStr)
 
- 		return ""
 
- 	}
 
- 	return fmt.Sprintf("%s %s * * *", hourMinute[1], hourMinute[0])
 
- }
 
- //GenOnceCronRule
 
- func genWeekCronRule(timeStr string, weeks []string) string {
 
- 	hourMinute := strings.Split(timeStr, ":")
 
- 	if len(weeks) == 0 {
 
- 		return fmt.Sprintf("%s %s * * *", hourMinute[1], hourMinute[0])
 
- 	}
 
- 	return fmt.Sprintf("%s %s * * %s", hourMinute[1], hourMinute[0], strings.Join(weeks, ","))
 
- }
 
- //FkZero 格式化数据,去掉多余的0
 
- func FkZero(times string) (fmttime string) {
 
- 	if string(times[0]) != "0" {
 
- 		return times
 
- 	} else if strings.Split(times, "0")[1] == "" {
 
- 		fkzero := "0"
 
- 		return fkzero
 
- 	} else {
 
- 		fkzero := strings.Split(times, "0")[1]
 
- 		return fkzero
 
- 	}
 
- }
 
 
  |