c_pcode.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package clean
  2. import (
  3. "regexp"
  4. "strings"
  5. "unicode"
  6. "unicode/utf8"
  7. )
  8. // 编号
  9. var codeUnConReg *regexp.Regexp = regexp.MustCompile("(null|勘察|包件|测试|设计|设备|项目|标段|工程|监理|范围|分包|月|日|天)")
  10. var codeUnLenReg *regexp.Regexp = regexp.MustCompile("([\u4e00-\u9fa5]{7,})")
  11. // 清洗项目编号
  12. func CleanPcode(pcode string, fns []string) string {
  13. if pcode == "无" {
  14. return ""
  15. }
  16. pcode = fieldReg1.ReplaceAllString(pcode, "")
  17. pcode = pcodeReg1.ReplaceAllString(pcode, "")
  18. pcode = pcodeReg2.ReplaceAllString(pcode, "")
  19. if utf8.RuneCountInString(pcode) < 5 {
  20. pcode = ""
  21. }
  22. if codeUnConReg.MatchString(pcode) || codeUnLenReg.MatchString(pcode) || !isAlphanumeric(pcode) || isRegTimeDateCode(pcode) {
  23. return ""
  24. }
  25. //校验与附件名字否是一致-舍弃
  26. for _, v := range fns {
  27. if utf8.RuneCountInString(v) >= utf8.RuneCountInString(pcode) {
  28. if strings.Contains(v, pcode) {
  29. return ""
  30. }
  31. }
  32. }
  33. return pcode
  34. }
  35. // 清洗其他编号
  36. func CleanOtherCode(ocode string) string {
  37. if ocode == "无" || ocode == "" {
  38. return ""
  39. }
  40. ocode = fieldReg1.ReplaceAllString(ocode, "")
  41. ocode = pcodeReg1.ReplaceAllString(ocode, "")
  42. ocode = pcodeReg2.ReplaceAllString(ocode, "")
  43. if utf8.RuneCountInString(ocode) < 5 {
  44. return ""
  45. }
  46. if codeUnConReg.MatchString(ocode) || codeUnLenReg.MatchString(ocode) || !isAlphanumeric(ocode) || isRegTimeDateCode(ocode) {
  47. return ""
  48. }
  49. return ocode
  50. }
  51. // 是否含字母数字
  52. func isAlphanumeric(str string) bool {
  53. var count int
  54. for _, v := range str {
  55. if unicode.IsNumber(v) || unicode.IsLetter(v) {
  56. count++
  57. break
  58. }
  59. }
  60. return count > 0
  61. }
  62. // 连续数字
  63. func isRegTimeDateCode(str string) bool {
  64. reg := `\d{8}`
  65. regx, _ := regexp.Compile(reg)
  66. if regx.FindString(str) != "" {
  67. return false
  68. }
  69. if utf8.RuneCountInString(str) == 8 {
  70. return true
  71. }
  72. return false
  73. }