From bae4af47f77a195a12a0437584d667465e826e12 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期一, 17 八月 2020 16:09:28 +0800
Subject: [PATCH] add log

---
 controllers/car.go |   86 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 80 insertions(+), 6 deletions(-)

diff --git a/controllers/car.go b/controllers/car.go
index 2093f1a..732fcff 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 <=10 && 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() == 22 && now.Minute()>=0 && now.Minute() <=30{
+					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() == 30 {
+						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,
@@ -118,4 +158,38 @@
 func (c *CarController) BindCarSpace() {
 
 	c.ServeJSON()
+}
+
+// @router /testPush [get]
+func (c *CarController) TestPush() {
+	left := getSpaceLeft()
+	message := fmt.Sprintf("%s 鍓╀綑杞︿綅锛�%d涓�", time.Now().Format("2006-01-02 15:04:05"), left)
+	b, e := service.PushByAlias("鑲茶嫳涓鍋滆溅", message)
+
+	fmt.Println("b:", b,"e:",e, "message:", message)
+	resp := code.Code{}
+	if b {
+		resp.Success = true
+		resp.Status = http.StatusOK
+		resp.Data = "鎺ㄩ�佹垚鍔�"
+	} else {
+		resp.Success = false
+		resp.Status = http.StatusInternalServerError
+		resp.Data = e.Error()
+	}
+	c.Data["json"] = resp
+	c.ServeJSON()
+}
+
+// @router /crossRecord [get]
+func (c *CarController) CrossRecord() {
+	sv := service.NewCarService()
+	records := sv.CrossRecords()
+	resp := code.Code{
+		Success: true,
+		Status:  http.StatusOK,
+		Data:    records,
+	}
+	c.Data["json"] = resp
+	c.ServeJSON()
 }
\ No newline at end of file

--
Gitblit v1.8.0