fix push plateNo compare and add isTest push
| | |
| | | hikAppSecret = ZHhxujl06e0e5jsJLaiB |
| | | pushLowerLimit = 5 |
| | | initPushLeft = 88 |
| | | testPushPhones = 18601263339 |
| | |
| | | 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(), |
| | |
| | | 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(), |
| | |
| | | "errors" |
| | | "fmt" |
| | | "github.com/astaxie/beego" |
| | | "strings" |
| | | "sync" |
| | | "time" |
| | | ) |
| | |
| | | } |
| | | |
| | | //对已注册的用户进行消息推送。调用此接口前需调用创建消息接口设置消息内容 |
| | | 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) |
| | |
| | | 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) |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | 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) |
| | |
| | | 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 |