| | |
| | | "car-service/service" |
| | | "fmt" |
| | | "github.com/astaxie/beego" |
| | | "github.com/satori/go.uuid" |
| | | "net/http" |
| | | "sort" |
| | | "strings" |
| | | "sync" |
| | | "time" |
| | | ) |
| | |
| | | |
| | | 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.PushByAlias("育英中学停车", message) |
| | | |
| | | t := time.Now().Format("2006-01-02 15:04:05") |
| | | message := fmt.Sprintf("%s 剩余车位:%d个", t, left) |
| | | b, e, aliasArr := service.PushByAlias("育英中学停车", message) |
| | | //记录推送日志 |
| | | 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) |
| | |
| | | func nightPush(){ |
| | | |
| | | message := fmt.Sprintf("%s 请尽快驶出停车场", time.Now().Format("2006-01-02 15:04:05")) |
| | | b, e := service.NightPush("育英中学停车", message) |
| | | |
| | | b, e, aliasArr := 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) |
| | | |
| | | } |
| | |
| | | func (c *CarController) TestPush() { |
| | | left := getSpaceLeft() |
| | | message := fmt.Sprintf("%s 剩余车位:%d个", time.Now().Format("2006-01-02 15:04:05"), left) |
| | | b, e := service.PushByAlias("育英中学停车", message) |
| | | b, e, aliasArr := service.PushByAlias("育英中学停车", 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) |
| | | resp := code.Code{} |
| | |
| | | c.ServeJSON() |
| | | } |
| | | |
| | | // @router /spaceInfo [get] |
| | | func (c *CarController) SpaceInfo() { |
| | | sv := service.NewCarService() |
| | | spaceInfo := sv.FindHikSpaceInfo() |
| | | c.Data["json"] = code.Code{ |
| | | Success: true, |
| | | Status: http.StatusOK, |
| | | Data: spaceInfo, |
| | | } |
| | | 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) |
| | | resp := code.Code{ |
| | | Success: true, |
| | | Status: http.StatusOK, |
| | | Data: map[string]interface{}{ |
| | | "total": total, |
| | | "list": logs, |
| | | }, |
| | | } |
| | | c.Data["json"] = resp |
| | | c.ServeJSON() |
| | | } |
| | | |
| | | // @router /crossRecord [get] |
| | | func (c *CarController) CrossRecord() { |
| | | sv := service.NewCarService() |