| | |
| | | } |
| | | |
| | | //实时计算剩余车位数量,达到条件就推送 |
| | | //要求: |
| | | //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: |
| | |
| | | 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 |
| | | |
| | |
| | | } |
| | | 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 |
| | |
| | | // @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, |