liuxiaolong
2020-08-18 b42533a6833b3b366f3f5c08bbc27f9f3ccbaeed
fix push plateNo compare and add isTest push
3个文件已修改
42 ■■■■ 已修改文件
conf/app.conf 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/car.go 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/msgPush.go 37 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
conf/app.conf
@@ -20,3 +20,4 @@
hikAppSecret = ZHhxujl06e0e5jsJLaiB
pushLowerLimit = 5
initPushLeft = 88
testPushPhones = 18601263339
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(),
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) //去掉汉字,D和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