liuxiaolong
2020-08-18 b42533a6833b3b366f3f5c08bbc27f9f3ccbaeed
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 {
         realPlateNo := preDealPlateNo(sn.PlateNo)
         if realPlateNo != "" {
            if pId,ok := carPersonM[realPlateNo];ok {
            delPersonIdM[pId] = pId
            delete(carPersonM, sn.PlateNo)
               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