task14.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. // Copyright 2019 getensh.com. All rights reserved.
  2. // Use of this source code is governed by getensh.com.
  3. package task
  4. import (
  5. "adm-dws/apis"
  6. "adm-dws/common.in/utils"
  7. "adm-dws/model"
  8. "encoding/json"
  9. dutils "adm-dws/utils"
  10. "fmt"
  11. "gorm.io/gorm"
  12. "strings"
  13. "unicode"
  14. )
  15. func checkNameRule(name string) []string {
  16. var ret []string
  17. // 只判断汉字
  18. for _, r := range name {
  19. if !unicode.Is(unicode.Scripts["Han"], r) && string(r) != "·" {
  20. return ret
  21. }
  22. }
  23. lastName := ""
  24. // 1 检查姓存在
  25. // 先判断复姓
  26. isInCompoundSurname := false
  27. for k,_:= range CompoundSurnameMap{
  28. if strings.HasPrefix(name,k){
  29. isInCompoundSurname = true
  30. lastName = name[len(k):]
  31. }
  32. }
  33. // 再判断单姓
  34. if !isInCompoundSurname{
  35. //复姓不存在
  36. firstName := name[0:3]
  37. if _,ok := SurnameMap[firstName]; !ok{
  38. ret = append(ret, fmt.Sprintf("%s姓不存在",firstName))
  39. }
  40. lastName = name[3:]
  41. }
  42. // 2 检查名存在
  43. for _,v := range lastName{
  44. if _,ok := LastNameMap[string(v)];!ok {
  45. ret = append(ret, fmt.Sprintf("%s名不存在",string(v)))
  46. }
  47. }
  48. if len(lastName)>6{
  49. dutils.SendMd5Msg(map[string]string{"name":name})
  50. //ret = append(ret, fmt.Sprintf("%s姓名不存在",name))
  51. }
  52. return ret
  53. }
  54. // 判断车牌字母个数
  55. func checkPlateNoLetterCount(plateNo string,maxCount int) int {
  56. total := 0
  57. for _,v := range plateNo{
  58. if v > 64 && v < 91 {
  59. total++
  60. }
  61. }
  62. if total>maxCount{
  63. return total
  64. }else{
  65. return 0
  66. }
  67. }
  68. func checkPlateNoRule(plateNo string) []string {
  69. // 1 检查前缀
  70. var ret []string
  71. defaultPlateType := utils.GetPlateType(plateNo)
  72. if defaultPlateType != "02"{
  73. return ret
  74. }
  75. sf, plateNumber := utils.ParsePlate(plateNo)
  76. if len(plateNumber) < 5{
  77. return ret
  78. }
  79. hphm := sf + plateNumber[0:1]
  80. plateNumber = plateNumber[1:]
  81. if _,ok := ProvinceMap[hphm];!ok{
  82. // hphm 不存在与
  83. ret = append(ret, fmt.Sprintf("%s不存在",hphm))
  84. }
  85. // 2 检查字母个数
  86. // 燃油车
  87. plateLen := len(plateNumber)
  88. if plateLen == 5{
  89. count := checkPlateNoLetterCount(plateNumber,2)
  90. if count != 0{
  91. ret = append(ret, fmt.Sprintf("%s车牌存在%d个字母(默认2个)",hphm,count))
  92. }
  93. // 新能源车
  94. }else if plateLen == 6{
  95. if plateNumber[0] > 64 && plateNumber[0] < 91 {
  96. // 小车
  97. if strings.HasPrefix(plateNumber,"A"){
  98. if hphm != "川A" && hphm != "豫A"{
  99. ret = append(ret, fmt.Sprintf("%s小型新能源车前缀字母%s不存在",hphm,"A"))
  100. }
  101. }
  102. if !strings.HasPrefix(plateNumber,"D") && !strings.HasPrefix(plateNumber,"F"){
  103. ret = append(ret, fmt.Sprintf("%s小型新能源车前缀字母%s不存在",hphm,plateNumber[:1]))
  104. }
  105. }else if plateNumber[plateLen-1] > 64 && plateNumber[plateLen-1] < 91 {
  106. // 大车
  107. if !strings.HasSuffix(plateNumber,"D") && !strings.HasSuffix(plateNumber,"F"){
  108. ret = append(ret, fmt.Sprintf("%s大型新能源车后缀字母%s不存在",hphm,plateNumber[plateLen-1:plateLen]))
  109. }
  110. }
  111. count := checkPlateNoLetterCount(plateNumber,3)
  112. if count != 0{
  113. ret = append(ret, fmt.Sprintf("%s新能源车牌存在%d个字母(默认3个)",hphm,count))
  114. }
  115. }
  116. return ret
  117. }
  118. func checkIdCardRule(idCard string) []string {
  119. // 1 AreaCode
  120. var ret []string
  121. areaCode := idCard[0:6]
  122. if _,ok := AreaMap[areaCode];!ok{
  123. ret = append(ret,fmt.Sprintf("%s地区不存在",areaCode))
  124. }
  125. // 2 year 1954-2004
  126. year := idCard[6:10]
  127. if year < "1954" || year > "2004"{
  128. ret = append(ret,fmt.Sprintf("%s年份不存在",year))
  129. }
  130. return ret
  131. }
  132. func insertRule(db *gorm.DB,ruleType int,rule []string ){
  133. dws14 := &model.Dws14{Type:ruleType}
  134. for _,v := range rule{
  135. dws14.Rule = v
  136. dws14.ID = 0
  137. err := dws14.Query(db,map[string]interface{}{"rule":dws14.Rule,"type":dws14.Type})
  138. if err != nil{
  139. if err == gorm.ErrRecordNotFound{
  140. dws14.Insert(db)
  141. }
  142. }
  143. }
  144. }
  145. // md5规则
  146. func Dws14Task(db *gorm.DB,dwsMessage *apis.DwsMessage, outputSourceCode string) (adsMsgList []*apis.AdsMessage, dwsMsgList []*apis.DwsMessage, err error) {
  147. dws14 := &model.Dws14{}
  148. err = json.Unmarshal([]byte(dwsMessage.Content), dws14)
  149. if err != nil {
  150. return nil, nil, nil
  151. }
  152. if dws14.Name != "" {
  153. rule := checkNameRule(dws14.Name)
  154. if len(rule) > 0{
  155. insertRule(db,3,rule)
  156. }
  157. }
  158. if dws14.Owner != ""{
  159. rule :=checkNameRule(dws14.Owner)
  160. if len(rule) > 0{
  161. insertRule(db,3,rule)
  162. }
  163. }
  164. if dws14.PlateNo != ""{
  165. rule :=checkPlateNoRule(dws14.PlateNo)
  166. if len(rule) > 0{
  167. insertRule(db,2,rule)
  168. }
  169. }
  170. if dws14.IdCard != ""{
  171. rule :=checkIdCardRule(dws14.IdCard)
  172. if len(rule) > 0{
  173. insertRule(db,1,rule)
  174. }
  175. }
  176. return nil, nil, nil
  177. }