From 2b77ad0e1f407903d85c3b7bdaae0022c4ec9bc3 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期二, 08 九月 2020 14:54:00 +0800
Subject: [PATCH] fix push bug
---
controllers/car.go | 104 +++++++++++++++++++++++++++++++++-------------------
1 files changed, 66 insertions(+), 38 deletions(-)
diff --git a/controllers/car.go b/controllers/car.go
index 63cf1a7..9b269d3 100644
--- a/controllers/car.go
+++ b/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(),
@@ -119,39 +119,28 @@
logE.Insert()
fmt.Println("b:", b,"e:",e, "message:", message)
- //濡傛灉鏈夋垚鍔熺粰杩囧杞︾殑杞︿富鎺ㄩ�侀�氱煡锛屽垯灏嗗叿浣撶殑杞︿富淇℃伅鎺ㄩ�佺粰绠$悊鍛�
- if b {
- //鑾峰彇杞︿富濮撳悕
- var leftUserNames []string
- carSv := service.NewCarService()
- hikPersons := carSv.GetHikPersonList()
- hikPersonM := make(map[string]string)
- for _,hikP := range hikPersons {
- hikPersonM[hikP.PhoneNo] = hikP.PersonName
- }
- for _, pushedPhone := range aliasArr {
- if name,in := hikPersonM[pushedPhone]; in {
- leftUserNames = append(leftUserNames, name)
+ 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)
+ 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)
}
- nameStr := strings.Join(leftUserNames, " ")
- managerMsg := fmt.Sprintf("%s 鏈┒绂昏溅涓�: %s", time.Now().Format("2006-01-02 15:04:05"), nameStr)
- mb,me, managerArr := service.Push2Manager("鑲茶嫳涓鍋滆溅", nameStr)
- 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)
-
}
+
}
var cacheSpaceLeft int
@@ -224,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(),
@@ -254,6 +243,45 @@
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)
+ 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() {
sv := service.NewCarService()
--
Gitblit v1.8.0