liuxiaolong
2020-08-06 dbc843d0b37f786fb816131bcc7ebca86dbe72e9
controllers/car.go
@@ -20,29 +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
            }
            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.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)
               }()
                     fmt.Println("b:", b,"e:",e, "message:", message)
                  }()
               }
               updateSpaceLeft(left)
            }
            updateSpaceLeft(left)
      default:
         time.Sleep(500 * time.Millisecond)
      }
@@ -69,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,
@@ -98,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,
@@ -110,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()
}