liuxiaolong
2020-08-18 1b20184df8a27d0c36b616bf2dd6e88c796e031e
plateNo compare,ignore chinese word and ignore D,0
1个文件已修改
42 ■■■■ 已修改文件
service/carService.go 42 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/carService.go
@@ -8,6 +8,7 @@
    "fmt"
    "github.com/astaxie/beego"
    "strconv"
    "strings"
)
type CarService struct {
    hikUtil *reqUtil.HikHttpUtil
@@ -181,8 +182,11 @@
        vehicles := sv.GetVehicleListByPerson(userId)
        if vehicles != nil {
            for _,veh := range vehicles {
                myPlateNosMap[veh.PlateNo] = veh.PlateNo
                //myPlateNos = append(myPlateNos, veh.PlateNo)
                if veh.PlateNo != "" {
                    ncStr := veh.PlateNo[1:] //把第一位汉字剔除掉
                    myPlateNosMap[ncStr] = ncStr
                }
                //myPlateNosMap[veh.PlateNo] = veh.PlateNo
            }
        }
    }
@@ -211,7 +215,6 @@
            return nil
        }
        for _,s := range spaceList {
            pi := models.PosInfo {
                SpaceNo: s.SpaceNo,
                PosNo: "",
@@ -222,11 +225,7 @@
            } else if s.PlateNos != "" {
                pi.PlateNo = s.PlateNos
            }
            isMine := false
            if _,exist := myPlateNosMap[pi.PlateNo]; exist {
                isMine = true
            }
            pi.IsMine = isMine
            pi.IsMine = isMyPlateNo(myPlateNosMap, pi.PlateNo)
            if v,ok := models.SpaceNo2Pos[s.SpaceNo];ok {
                pi.PosNo = v
            }
@@ -249,6 +248,33 @@
    return resultList
}
//判断是不是自己的车牌号
//1.目前有误识别的问题,会把D识别成0,D和0不分
//2.汉字误识别的几率比较高
func isMyPlateNo(plateNoM map[string]string, targetPlateNo string) bool {
    if targetPlateNo != "" {
        nctPlateNo := targetPlateNo[1:]
        if _,exist := plateNoM[nctPlateNo];exist {
            return true
        } else {
            match := false
            for k,_ := range plateNoM {
                newK := strings.ReplaceAll(k, "D", "*")
                newK = strings.ReplaceAll(newK, "0", "*")
                tt := strings.ReplaceAll(targetPlateNo,"D", "*")
                tt = strings.ReplaceAll(tt,"0", "*")
                if newK == tt {
                    match = true
                    break
                }
            }
            return match
        }
    }
    return false
}
func (sv *CarService) BindCarSpace() bool {
    url := "/artemis/api/pms/v1/parking_space/car_bind/add"
    reqBody := map[string]interface{} {