From dbc843d0b37f786fb816131bcc7ebca86dbe72e9 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期四, 06 八月 2020 09:58:46 +0800 Subject: [PATCH] add crossRecord --- controllers/car.go | 58 ++++++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 38 insertions(+), 20 deletions(-) diff --git a/controllers/car.go b/controllers/car.go index 4a365fd..2329ce3 100644 --- a/controllers/car.go +++ b/controllers/car.go @@ -20,25 +20,31 @@ func ComputeSpaceLeftRealTime() { ticker := time.NewTicker(3 * time.Second) prePushLeft := 0 + sv := service.NewCarService() + initCacheM := false for { select { case <-ticker.C: - m := time.Now().Minute() - i := m % 10 - left := 80 - if i == 0 { - left = 10 + hikSta, flag := sv.Statistic() + if flag { + left := hikSta.Left + if !initCacheM { + models.SetSpaceNo(hikSta.TotalPermPlace) + initCacheM = true + } + if left <=5 && left != prePushLeft { + go func() { + message := fmt.Sprintf("%s 鍓╀綑杞︿綅锛�%d涓�", time.Now().Format("2006-01-02 15:04:05"), left) + b, e := service.Push("鑲茶嫳鏅烘収鍋滆溅", message) + + prePushLeft = left + + fmt.Println("b:", b,"e:",e, "message:", message) + }() + } + updateSpaceLeft(left) } - if m == 40 { - left = 5 - } - if left <=10 && left != prePushLeft { - go func() { - b, e := service.Push("鑲茶嫳鏅烘収鍋滆溅", fmt.Sprintf("褰撳墠鍓╀綑杞︿綅锛�%d涓�", left)) - fmt.Println("b:", b,"e:",e) - }() - } - updateSpaceLeft(left) + default: time.Sleep(500 * time.Millisecond) } @@ -65,7 +71,8 @@ // @router /statistic [get] func (c *CarController) Statistic() { //sv := service.NewCarService() - //sta := sv.Statistic() + //hikStc := sv.Statistic() + //left := hikStc.Left left := getSpaceLeft() sta := models.CarStatistic{ Left: left, @@ -94,8 +101,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, @@ -106,11 +114,21 @@ c.ServeJSON() } + func (c *CarController) BindCarSpace() { + + c.ServeJSON() +} + +// @router /crossRecord [get] +func (c *CarController) CrossRecord() { sv := service.NewCarService() - - if sv.BindCarSpace() { - + 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