123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- // Copyright 2019 getensh.com. All rights reserved.
- // Use of this source code is governed by getensh.com.
- package task
- import (
- "adm-dws/apis"
- "adm-dws/common.in/utils"
- "adm-dws/model"
- "encoding/json"
- dutils "adm-dws/utils"
- "fmt"
- "gorm.io/gorm"
- "strings"
- "unicode"
- )
- func checkNameRule(name string) []string {
- var ret []string
- // 只判断汉字
- for _, r := range name {
- if !unicode.Is(unicode.Scripts["Han"], r) && string(r) != "·" {
- return ret
- }
- }
- lastName := ""
- // 1 检查姓存在
- // 先判断复姓
- isInCompoundSurname := false
- for k,_:= range CompoundSurnameMap{
- if strings.HasPrefix(name,k){
- isInCompoundSurname = true
- lastName = name[len(k):]
- }
- }
- // 再判断单姓
- if !isInCompoundSurname{
- //复姓不存在
- firstName := name[0:3]
- if _,ok := SurnameMap[firstName]; !ok{
- ret = append(ret, fmt.Sprintf("%s姓不存在",firstName))
- }
- lastName = name[3:]
- }
- // 2 检查名存在
- for _,v := range lastName{
- if _,ok := LastNameMap[string(v)];!ok {
- ret = append(ret, fmt.Sprintf("%s名不存在",string(v)))
- }
- }
- if len(lastName)>6{
- dutils.SendMd5Msg(map[string]string{"name":name})
- //ret = append(ret, fmt.Sprintf("%s姓名不存在",name))
- }
- return ret
- }
- // 判断车牌字母个数
- func checkPlateNoLetterCount(plateNo string,maxCount int) int {
- total := 0
- for _,v := range plateNo{
- if v > 64 && v < 91 {
- total++
- }
- }
- if total>maxCount{
- return total
- }else{
- return 0
- }
- }
- func checkPlateNoRule(plateNo string) []string {
- // 1 检查前缀
- var ret []string
- defaultPlateType := utils.GetPlateType(plateNo)
- if defaultPlateType != "02"{
- return ret
- }
- sf, plateNumber := utils.ParsePlate(plateNo)
- if len(plateNumber) < 5{
- return ret
- }
- hphm := sf + plateNumber[0:1]
- plateNumber = plateNumber[1:]
- if _,ok := ProvinceMap[hphm];!ok{
- // hphm 不存在与
- ret = append(ret, fmt.Sprintf("%s不存在",hphm))
- }
- // 2 检查字母个数
- // 燃油车
- plateLen := len(plateNumber)
- if plateLen == 5{
- count := checkPlateNoLetterCount(plateNumber,2)
- if count != 0{
- ret = append(ret, fmt.Sprintf("%s车牌存在%d个字母(默认2个)",hphm,count))
- }
- // 新能源车
- }else if plateLen == 6{
- if plateNumber[0] > 64 && plateNumber[0] < 91 {
- // 小车
- if strings.HasPrefix(plateNumber,"A"){
- if hphm != "川A" && hphm != "豫A"{
- ret = append(ret, fmt.Sprintf("%s小型新能源车前缀字母%s不存在",hphm,"A"))
- }
- }
- if !strings.HasPrefix(plateNumber,"D") && !strings.HasPrefix(plateNumber,"F"){
- ret = append(ret, fmt.Sprintf("%s小型新能源车前缀字母%s不存在",hphm,plateNumber[:1]))
- }
- }else if plateNumber[plateLen-1] > 64 && plateNumber[plateLen-1] < 91 {
- // 大车
- if !strings.HasSuffix(plateNumber,"D") && !strings.HasSuffix(plateNumber,"F"){
- ret = append(ret, fmt.Sprintf("%s大型新能源车后缀字母%s不存在",hphm,plateNumber[plateLen-1:plateLen]))
- }
- }
- count := checkPlateNoLetterCount(plateNumber,3)
- if count != 0{
- ret = append(ret, fmt.Sprintf("%s新能源车牌存在%d个字母(默认3个)",hphm,count))
- }
- }
- return ret
- }
- func checkIdCardRule(idCard string) []string {
- // 1 AreaCode
- var ret []string
- areaCode := idCard[0:6]
- if _,ok := AreaMap[areaCode];!ok{
- ret = append(ret,fmt.Sprintf("%s地区不存在",areaCode))
- }
- // 2 year 1954-2004
- year := idCard[6:10]
- if year < "1954" || year > "2004"{
- ret = append(ret,fmt.Sprintf("%s年份不存在",year))
- }
- return ret
- }
- func insertRule(db *gorm.DB,ruleType int,rule []string ){
- dws14 := &model.Dws14{Type:ruleType}
- for _,v := range rule{
- dws14.Rule = v
- dws14.ID = 0
- err := dws14.Query(db,map[string]interface{}{"rule":dws14.Rule,"type":dws14.Type})
- if err != nil{
- if err == gorm.ErrRecordNotFound{
- dws14.Insert(db)
- }
- }
- }
- }
- // md5规则
- func Dws14Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
- dws14 := &model.Dws14{}
- err = json.Unmarshal([]byte(dwsMessage.Content), dws14)
- if err != nil {
- return nil, nil, nil
- }
- if dws14.Name != "" {
- rule := checkNameRule(dws14.Name)
- if len(rule) > 0{
- insertRule(db,3,rule)
- }
- }
- if dws14.Owner != ""{
- rule :=checkNameRule(dws14.Owner)
- if len(rule) > 0{
- insertRule(db,3,rule)
- }
- }
- if dws14.PlateNo != ""{
- rule :=checkPlateNoRule(dws14.PlateNo)
- if len(rule) > 0{
- insertRule(db,2,rule)
- }
- }
- if dws14.IdCard != ""{
- rule :=checkIdCardRule(dws14.IdCard)
- if len(rule) > 0{
- insertRule(db,1,rule)
- }
- }
- return nil, nil, nil
- }
|