From bf4ca3fdb8c0f0c1f99a4a871ad39436cefc6ab6 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期六, 10 十月 2020 19:37:05 +0800
Subject: [PATCH] 在地图上不显示vip车辆

---
 controllers/car.go |  286 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 262 insertions(+), 24 deletions(-)

diff --git a/controllers/car.go b/controllers/car.go
index 43f47b5..9cccaff 100644
--- a/controllers/car.go
+++ b/controllers/car.go
@@ -6,8 +6,10 @@
 	"car-service/service"
 	"fmt"
 	"github.com/astaxie/beego"
+	"github.com/satori/go.uuid"
 	"net/http"
 	"sort"
+	"strings"
 	"sync"
 	"time"
 )
@@ -17,36 +19,128 @@
 }
 
 //瀹炴椂璁$畻鍓╀綑杞︿綅鏁伴噺锛岃揪鍒版潯浠跺氨鎺ㄩ��
+//瑕佹眰锛�
+//1.鍋滆溅鏁伴噺灏忎簬绛変簬5涓帹閫侊紝5涓互涓嬬殑鏁伴噺鍙樺寲閮芥帹閫侊紝鎺ㄩ�佺粰宸叉敞鍐屾墜鏈哄彿鐨勭敤鎴凤紝鏈敞鍐岀殑涓嶆帹
+//2.婊¤冻涓婁竴鏉★紝濡傛灉姝よ溅杈嗗凡缁忚繘鍏ュ鏍″仠杞﹀満浜嗭紝灏变笉鍐嶇粰杩欎釜杞︾墝瀵瑰簲鐨勬墜鏈哄彿鎺ㄩ�佺┖浣欒溅浣嶆秷鎭�
+//3.鏅氫笂10鐐瑰埌10鐐瑰崐锛屾瘡闂撮殧10鍒嗛挓锛岀粰鍋滆溅鍦哄唴鐨勮溅杈嗘帹閫佹秷鎭細璇峰敖蹇┒鍑哄仠杞﹀満
 func ComputeSpaceLeftRealTime() {
 	ticker := time.NewTicker(3 * time.Second)
-	prePushLeft := 0
+	prePushLeft, _ := beego.AppConfig.Int("initPushLeft") //鍒濆鍓╀綑鏁伴噺锛屼笂绾垮悗涓嶈兘姣忔鍚姩閮芥帹閫佹秷鎭�
+	sv := service.NewCarService()
+	initCacheM := false
+	lowerLimit,_ := beego.AppConfig.Int("pushLowerLimit") //[0,5]
+	nightPushTimes := 0
 	for {
 		select {
 			case <-ticker.C:
-				m := time.Now().Minute()
-				i := m % 10
-				left := 80
-				if i == 0 {
-					left = 10
-				}
-				if m == 40 {
-					left = 5
-				}
-				if left <=10 && left != prePushLeft {
-					go func() {
-						message := fmt.Sprintf("褰撳墠鍓╀綑杞︿綅锛�%d涓�", left)
-						b, e := service.Push("鑲茶嫳鏅烘収鍋滆溅", message)
-						if b {
+				hikSta, flag := sv.Statistic()
+				if flag {
+					left := hikSta.Left
+					if !initCacheM {
+						models.SetSpaceNo(hikSta.TotalPlace)
+						initCacheM = true
+					}
+
+					if left <=lowerLimit && left != prePushLeft {
+						go func() {
+							t := time.Now().Format("2006-01-02 15:04:05")
+							message := fmt.Sprintf("%s 鍓╀綑杞︿綅锛�%d涓�", t, left)
+							b, e, aliasArr := service.PushByAlias("鍓╀綑杞︿綅鎻愰啋", message, false)
+							//璁板綍鎺ㄩ�佹棩蹇�
+							logE := models.Log{
+								Id: uuid.NewV4().String(),
+								CreateTime: t,
+								Result: b,
+								Phones: strings.Join(aliasArr, ","),
+							}
+							if e != nil {
+								logE.Content = e.Error()
+							} else {
+								logE.Content = message
+							}
+							logE.Insert()
 							prePushLeft = left
-						}
-						fmt.Println("b:", b,"e:",e, "message:", message)
-					}()
+
+							fmt.Println("b:", b,"e:",e, "message:", message)
+						}()
+					}
+					updateSpaceLeft(left)
 				}
-				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)
+							nightPushTimes++
+						}
+					} else if now.Minute() == 10 {
+						if nightPushTimes == 1 {
+							go nightPush(nightPushTimes)
+							nightPushTimes++
+						}
+					} else if now.Minute() == 20 {
+						if nightPushTimes == 2{
+							go nightPush(nightPushTimes)
+							nightPushTimes++
+						}
+					} else if now.Minute() == 30 {
+						if nightPushTimes == 3{
+							go nightPush(nightPushTimes)
+							nightPushTimes++
+						}
+					}
+				} else {
+					nightPushTimes = 0
+				}
+
 		default:
 			time.Sleep(500 * time.Millisecond)
 		}
 	}
+}
+
+func nightPush(curTimes int){
+
+	message := fmt.Sprintf("%s 璇峰敖蹇┒鍑哄仠杞﹀満", time.Now().Format("2006-01-02 15:04:05"))
+	b, e, aliasArr,carOwnNames := service.NightPush("娓╅Θ鎻愮ず", message)
+	//璁板綍鎺ㄩ�佹棩蹇�
+	logE := models.Log{
+		Id: uuid.NewV4().String(),
+		CreateTime: time.Now().Format("2006-01-02 15:04:05"),
+		Result: b,
+		Phones: strings.Join(aliasArr, ","),
+	}
+	if e != nil {
+		logE.Content = e.Error()
+	} else {
+		logE.Content = message
+	}
+	logE.Insert()
+	fmt.Println("b:", b,"e:",e, "message:", message)
+
+	if curTimes == 3 { //鍙粰绠$悊鍛樻帹閫佷竴娆¤繖涓秷鎭�
+		//灏嗗叿浣撶殑杞︿富淇℃伅鎺ㄩ�佺粰绠$悊鍛�
+		if carOwnNames != nil && len(carOwnNames) >0 {
+			//鑾峰彇杞︿富濮撳悕
+			managerMsg := strings.Join(carOwnNames, ",")
+			mb,me, managerArr := service.Push2Manager(fmt.Sprintf("%s 鏈┒绂昏溅杈�", time.Now().Format("2006-01-02 15:04:05")), managerMsg, false)
+			mLogE := models.Log{
+				Id: uuid.NewV4().String(),
+				CreateTime: time.Now().Format("2006-01-02 15:04:05"),
+				Result: mb,
+				Phones: strings.Join(managerArr, ","),
+			}
+			if me != nil {
+				mLogE.Content = me.Error()
+			} else {
+				mLogE.Content = managerMsg
+			}
+			mLogE.Insert()
+			fmt.Println("mb:", mb, "me:", me, "message:", managerMsg)
+		}
+	}
+
 }
 
 var cacheSpaceLeft int
@@ -68,8 +162,6 @@
 // @Failure 403 {string} json ""
 // @router /statistic [get]
 func (c *CarController) Statistic() {
-	//sv := service.NewCarService()
-	//sta := sv.Statistic()
 	left := getSpaceLeft()
 	sta := models.CarStatistic{
 		Left: left,
@@ -98,8 +190,9 @@
 // @Failure 403 {string} json ""
 // @router /spaceNo [get]
 func (c *CarController) SpaceNo() {
+	userId := c.GetString("userId")
 	sv := service.NewCarService()
-	spaceNos := sv.FindSpaceNo()
+	spaceNos := sv.FindSpaceNo(userId)
 	sort.Sort(spaceNos)
 	resp := code.Code{
 		Success: true,
@@ -110,11 +203,156 @@
 	c.ServeJSON()
 }
 
+
 func (c *CarController) BindCarSpace() {
-	sv := service.NewCarService()
 
-	if sv.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, aliasArr := service.PushByAlias("鍓╀綑杞︿綅鎻愰啋", message, true)
+	//璁板綍鎺ㄩ�佹棩蹇�
+	logE := models.Log{
+		Id: uuid.NewV4().String(),
+		CreateTime: time.Now().Format("2006-01-02 15:04:05"),
+		Result: b,
+		Phones: strings.Join(aliasArr, ","),
 	}
+	if e != nil {
+		logE.Content = e.Error()
+	} else {
+		logE.Content = message
+	}
+	logE.Insert()
+
+	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 /testNightPush [get]
+func (c *CarController) TestNightPush() {
+	carOwnNames := service.GetLeftCarOwners()
+
+	//灏嗗叿浣撶殑杞︿富淇℃伅鎺ㄩ�佺粰绠$悊鍛�
+	if carOwnNames != nil && len(carOwnNames) >0 {
+		//鑾峰彇杞︿富濮撳悕
+		managerMsg := strings.Join(carOwnNames, ",")
+		mb,me, managerArr := service.Push2Manager(fmt.Sprintf("%s 鏈┒绂昏溅杈�", time.Now().Format("2006-01-02 15:04:05")), managerMsg, true)
+		mLogE := models.Log{
+			Id: uuid.NewV4().String(),
+			CreateTime: time.Now().Format("2006-01-02 15:04:05"),
+			Result: mb,
+			Phones: strings.Join(managerArr, ","),
+		}
+		if me != nil {
+			mLogE.Content = me.Error()
+		} else {
+			mLogE.Content = managerMsg
+		}
+		mLogE.Insert()
+		fmt.Println("mb:", mb, "me:", me, "message:", managerMsg)
+
+		c.Data["json"] = code.Code{
+			Success: true,
+			Status: http.StatusOK,
+			Message: "鎺ㄩ�佸畬鎴�",
+			Data: managerMsg,
+		}
+	} else {
+		c.Data["json"] = code.Code{
+			Success: true,
+			Status: http.StatusOK,
+			Message: "鏃犻渶鎺ㄩ�侊紝褰撳墠鍋滅暀杞﹁締淇℃伅涓虹┖",
+		}
+	}
+
+	c.ServeJSON()
+}
+// @router /spaceInfo [get]
+func (c *CarController) SpaceInfo() {
+	userId := c.GetString("userId")
+	sv := service.NewCarService()
+	spaceInfo := sv.FindHikSpaceInfo(userId)
+	c.Data["json"] = code.Code{
+		Success: true,
+		Status: http.StatusOK,
+		Data: spaceInfo,
+	}
+	c.ServeJSON()
+}
+
+// @router /spaceUser [get]
+func (c *CarController) SpaceUser() {
+	userId := c.GetString("userId")
+	sv := service.NewCarService()
+	spaceUser := sv.FindHikSpaceUser(userId)
+	c.Data["json"] = code.Code{
+		Success: true,
+		Status: http.StatusOK,
+		Data: spaceUser,
+	}
+	c.ServeJSON()
+}
+
+// @router /pushLog [get]
+func (c *CarController) PushLog() {
+	st := c.GetString("startTime")
+	et := c.GetString("endTime")
+	if st == "" {
+		st = time.Now().Format("2006-01-02")
+	}
+	if et == "" {
+		et = time.Now().AddDate(0,0,1).Format("2006-01-02")
+	}
+	curPage, err := c.GetInt("curPage")
+	if err != nil {
+		curPage = 1
+	}
+	pageSize, err := c.GetInt("pageSize")
+	if err != nil {
+		pageSize = 20
+	}
+	var l models.Log
+	total, logs := l.Find(curPage, pageSize, st, et)
+	var rl []models.Log
+	for _,le := range logs {
+		rl = append(rl, *le)
+	}
+	resp := code.Code{
+		Success: true,
+		Status:  http.StatusOK,
+		Data:    map[string]interface{}{
+			"total": total,
+			"list": rl,
+		},
+	}
+	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