From 9358e5ec2d2b65fec4ef9a1be7d1a1e1e2cf9d2d Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期一, 10 八月 2020 16:31:34 +0800 Subject: [PATCH] new push schedule --- controllers/car.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 46 insertions(+), 6 deletions(-) diff --git a/controllers/car.go b/controllers/car.go index 2329ce3..4d4141b 100644 --- a/controllers/car.go +++ b/controllers/car.go @@ -17,11 +17,17 @@ } //瀹炴椂璁$畻鍓╀綑杞︿綅鏁伴噺锛岃揪鍒版潯浠跺氨鎺ㄩ�� +//瑕佹眰锛� +//1.鍋滆溅鏁伴噺灏忎簬绛変簬5涓帹閫侊紝5涓互涓嬬殑鏁伴噺鍙樺寲閮芥帹閫侊紝鎺ㄩ�佺粰宸叉敞鍐屾墜鏈哄彿鐨勭敤鎴凤紝鏈敞鍐岀殑涓嶆帹 +//2.婊¤冻涓婁竴鏉★紝濡傛灉姝よ溅杈嗗凡缁忚繘鍏ュ鏍″仠杞﹀満浜嗭紝灏变笉鍐嶇粰杩欎釜杞︾墝瀵瑰簲鐨勬墜鏈哄彿鎺ㄩ�佺┖浣欒溅浣嶆秷鎭� +//3.鏅氫笂10鐐瑰埌10鐐瑰崐锛屾瘡闂撮殧10鍒嗛挓锛岀粰鍋滆溅鍦哄唴鐨勮溅杈嗘帹閫佹秷鎭細璇峰敖蹇┒鍑哄仠杞﹀満 func ComputeSpaceLeftRealTime() { ticker := time.NewTicker(3 * time.Second) prePushLeft := 0 sv := service.NewCarService() initCacheM := false + lowerLimit,_ := beego.AppConfig.Int("pushLowerLimit") //[0,5] + nightPushTimes := 0 for { select { case <-ticker.C: @@ -29,13 +35,14 @@ if flag { left := hikSta.Left if !initCacheM { - models.SetSpaceNo(hikSta.TotalPermPlace) + models.SetSpaceNo(hikSta.TotalPlace) initCacheM = true } - if left <=5 && left != prePushLeft { + + if left <=lowerLimit && left != prePushLeft { go func() { message := fmt.Sprintf("%s 鍓╀綑杞︿綅锛�%d涓�", time.Now().Format("2006-01-02 15:04:05"), left) - b, e := service.Push("鑲茶嫳鏅烘収鍋滆溅", message) + b, e := service.PushByAlias("鑲茶嫳鏅烘収鍋滆溅", message) prePushLeft = left @@ -44,11 +51,47 @@ } updateSpaceLeft(left) } + //鍒ゆ柇褰撳墠鏄惁鍦�22:00-22:30涔嬮棿 + now := time.Now() + if now.Hour() == 21 && now.Minute()>=0 || now.Minute() <=29{ + if now.Minute() == 0 { + if nightPushTimes ==0 { + go nightPush() + nightPushTimes++ + } + } else if now.Minute() == 10 { + if nightPushTimes == 1 { + go nightPush() + nightPushTimes++ + } + } else if now.Minute() == 20 { + if nightPushTimes == 2{ + go nightPush() + nightPushTimes++ + } + } else if now.Minute() == 29 { + if nightPushTimes == 3{ + go nightPush() + nightPushTimes++ + } + } + } else { + nightPushTimes = 0 + } default: time.Sleep(500 * time.Millisecond) } } +} + +func nightPush(){ + + message := fmt.Sprintf("%s 璇峰敖蹇┒鍑哄仠杞﹀満", time.Now().Format("2006-01-02 15:04:05")) + b, e := service.NightPush("鑲茶嫳鏅烘収鍋滆溅", message) + + fmt.Println("b:", b,"e:",e, "message:", message) + } var cacheSpaceLeft int @@ -70,9 +113,6 @@ // @Failure 403 {string} json "" // @router /statistic [get] func (c *CarController) Statistic() { - //sv := service.NewCarService() - //hikStc := sv.Statistic() - //left := hikStc.Left left := getSpaceLeft() sta := models.CarStatistic{ Left: left, -- Gitblit v1.8.0