From b42533a6833b3b366f3f5c08bbc27f9f3ccbaeed Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期二, 18 八月 2020 16:12:03 +0800
Subject: [PATCH] fix push plateNo compare and add isTest push
---
conf/app.conf | 1 +
service/msgPush.go | 37 ++++++++++++++++++++++++++++++++-----
controllers/car.go | 4 ++--
3 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/conf/app.conf b/conf/app.conf
index 0a12de5..5ed0fc5 100644
--- a/conf/app.conf
+++ b/conf/app.conf
@@ -20,3 +20,4 @@
hikAppSecret = ZHhxujl06e0e5jsJLaiB
pushLowerLimit = 5
initPushLeft = 88
+testPushPhones = 18601263339
diff --git a/controllers/car.go b/controllers/car.go
index 0585eb8..f867877 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)
+ b, e, aliasArr := service.PushByAlias("鑲茶嫳涓鍋滆溅", message, false)
//璁板綍鎺ㄩ�佹棩蹇�
logE := models.Log{
Id: uuid.NewV4().String(),
@@ -191,7 +191,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)
+ b, e, aliasArr := service.PushByAlias("鑲茶嫳涓鍋滆溅", message, true)
//璁板綍鎺ㄩ�佹棩蹇�
logE := models.Log{
Id: uuid.NewV4().String(),
diff --git a/service/msgPush.go b/service/msgPush.go
index 6e52527..05ebef6 100644
--- a/service/msgPush.go
+++ b/service/msgPush.go
@@ -7,6 +7,7 @@
"errors"
"fmt"
"github.com/astaxie/beego"
+ "strings"
"sync"
"time"
)
@@ -246,7 +247,7 @@
}
//瀵瑰凡娉ㄥ唽鐨勭敤鎴疯繘琛屾秷鎭帹閫併�傝皟鐢ㄦ鎺ュ彛鍓嶉渶璋冪敤鍒涘缓娑堟伅鎺ュ彛璁剧疆娑堟伅鍐呭
-func PushByAlias(title string, msg string) (bool, error, []string) {
+func PushByAlias(title string, msg string, isTest bool) (bool, error, []string) {
var aliasArr []string
pushUserM := make(map[string]string)
@@ -265,16 +266,22 @@
carPersons := csv.GetVehicleListByPerson("")
if carPersons != nil {
for _, cp := range carPersons {
- carPersonM[cp.PlateNo] = cp.PersonId
+ ncPlateNo := preDealPlateNo(cp.PlateNo) //鍘绘帀姹夊瓧锛孌鍜�0鏇挎崲鎴�*
+ if ncPlateNo != "" {
+ carPersonM[ncPlateNo] = cp.PersonId
+ }
}
}
delPersonIdM := make(map[string]string)
spaceNos := csv.FindSpaceNo("")
for _,sn := range spaceNos {
if sn.State == 1 && sn.PlateNo != "" { //宸茬粡鎶婅溅鍋滃埌鍋滆溅鍦虹殑杞︿富锛屼笉鍐嶆帹閫佹秷鎭�
- if pId,ok := carPersonM[sn.PlateNo];ok {
- delPersonIdM[pId] = pId
- delete(carPersonM, sn.PlateNo)
+ realPlateNo := preDealPlateNo(sn.PlateNo)
+ if realPlateNo != "" {
+ if pId,ok := carPersonM[realPlateNo];ok {
+ delPersonIdM[pId] = pId
+ delete(carPersonM, realPlateNo)
+ }
}
}
}
@@ -291,6 +298,14 @@
lenAS := len(aliasArr)
if lenAS == 0 {
return false, errors.New("aliasArr is empty"),aliasArr
+ }
+ if isTest {
+ //鍙粰鍐呴儴鎵嬫満鍙锋帹
+ testPhones := beego.AppConfig.String("testPushPhones")
+ if testPhones == "" {
+ return false, errors.New("test push aliasArr is empty"),aliasArr
+ }
+ aliasArr = strings.Split(testPhones, ",")
}
cResult, taskId, ce := createPushMsg(title, msg)
@@ -336,6 +351,18 @@
return false, errors.New("鎺ㄩ�佸け璐�"),aliasArr
}
+//棰勫鐞嗚溅鐗屽彿锛屽幓闄ら涓眽瀛楋紝浠ュ強蹇界暐D鍜�0
+func preDealPlateNo(pn string) string {
+ if pn != "" {
+ r := []rune(pn)
+ ncStr := string(r[1:])
+ newPlateNo := strings.ReplaceAll(ncStr, "D", "*")
+ newPlateNo = strings.ReplaceAll(newPlateNo, "0", "*")
+ return newPlateNo
+ }
+ return ""
+}
+
func doPush(taskId string, aliasArr []string) (bool,error) {
appId := beego.AppConfig.String("pushAppId")
baseUrl := beego.AppConfig.String("pushBaseUrl") + appId
--
Gitblit v1.8.0