liuxiaolong
2020-10-10 bf4ca3fdb8c0f0c1f99a4a871ad39436cefc6ab6
controllers/car.go
@@ -45,7 +45,7 @@
                  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)
                     b, e, aliasArr := service.PushByAlias("剩余车位提醒", message, false)
                     //记录推送日志
                     logE := models.Log{
                        Id: uuid.NewV4().String(),
@@ -71,22 +71,22 @@
            if now.Hour() == 22 && now.Minute()>=0 && now.Minute() <=30{
               if now.Minute() == 0 {
                  if nightPushTimes ==0 {
                     go nightPush()
                     go nightPush(nightPushTimes)
                     nightPushTimes++
                  }
               } else if now.Minute() == 10 {
                  if nightPushTimes == 1 {
                     go nightPush()
                     go nightPush(nightPushTimes)
                     nightPushTimes++
                  }
               } else if now.Minute() == 20 {
                  if nightPushTimes == 2{
                     go nightPush()
                     go nightPush(nightPushTimes)
                     nightPushTimes++
                  }
               } else if now.Minute() == 30 {
                  if nightPushTimes == 3{
                     go nightPush()
                     go nightPush(nightPushTimes)
                     nightPushTimes++
                  }
               }
@@ -100,10 +100,10 @@
   }
}
func nightPush(){
func nightPush(curTimes int){
   message := fmt.Sprintf("%s 请尽快驶出停车场", time.Now().Format("2006-01-02 15:04:05"))
   b, e, aliasArr := service.NightPush("育英中学停车", message)
   b, e, aliasArr,carOwnNames := service.NightPush("温馨提示", message)
   //记录推送日志
   logE := models.Log{
      Id: uuid.NewV4().String(),
@@ -118,6 +118,28 @@
   }
   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)
      }
   }
}
@@ -191,7 +213,7 @@
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)
   b, e, aliasArr := service.PushByAlias("剩余车位提醒", message, true)
   //记录推送日志
   logE := models.Log{
      Id: uuid.NewV4().String(),
@@ -221,10 +243,50 @@
   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()
   spaceInfo := sv.FindHikSpaceInfo(userId)
   c.Data["json"] = code.Code{
      Success: true,
      Status: http.StatusOK,
@@ -233,6 +295,19 @@
   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")