123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package test
- import (
- commonConfig "cicv-data-closedloop/aarch64/jili/common/config"
- "cicv-data-closedloop/common/config/c_log"
- "fmt"
- "testing"
- "time"
- )
- func init() {
- // 初始化日志配置
- c_log.InitLog(commonConfig.LogDir, commonConfig.ControlLogPrefix)
- // 初始化本地配置文件(第1处配置,在本地文件)
- commonConfig.InitLocalConfig()
- commonConfig.InitOssConfig()
- commonConfig.InitCloudConfig()
- }
- func TestGetConfig(t *testing.T) {
- fmt.Println(commonConfig.LocalConfig.EquipmentNo)
- PlatformConfig, err := commonConfig.GetPlatformTasks()
- fmt.Println("PlatformConfig", PlatformConfig)
- if err != nil {
- fmt.Println("获取配置status失败:", err)
- }
- }
- func TestControl(t *testing.T) {
- wait := false
- // 轮询任务接口判断是否有更新
- for {
- if wait { // 第一次就不等待一分钟了
- time.Sleep(time.Duration(60) * time.Second)
- }
- wait = true
- // 1. 获取当前设备的任务配置
- platformTasks, err := commonConfig.GetPlatformTasks()
- fmt.Println("platformTasks", platformTasks)
- commonConfig.PlatformTasks = platformTasks
- if err != nil {
- c_log.GlobalLogger.Error("获取平台任务失败:", err)
- continue
- }
- // 2. 判断当前时间是否有需要执行的任务
- for _, task := range platformTasks {
- flag := shouldExecuteTask(task.StartTime, task.EndTime)
- fmt.Println("flag", flag)
- }
- }
- }
- func shouldExecuteTask(startTimeStr, endTimeStr string) bool {
- // 定义时间格式(根据输入的时间字符串格式)
- timeFormat := "2006-01-02 15:04:05"
- // 解析 startTime 和 endTime
- startTime, err := time.ParseInLocation(timeFormat, startTimeStr, time.Local)
- fmt.Println("startTime", startTime)
- if err != nil {
- fmt.Println("Error parsing startTime:", err)
- return false
- }
- endTime, err := time.ParseInLocation(timeFormat, endTimeStr, time.Local)
- fmt.Println("endTime", endTime)
- if err != nil {
- fmt.Println("Error parsing endTime:", err)
- return false
- }
- // 获取当前时间
- currentTime := time.Now()
- fmt.Println("currentTime", currentTime)
- // 判断当前时间是否在 startTime 和 endTime 之间
- return !currentTime.Before(startTime) && !currentTime.After(endTime)
- }
|