scoreprojectcode.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package qua
  2. import (
  3. "fmt"
  4. qu "qfw/util"
  5. "unicode/utf8"
  6. u "util"
  7. )
  8. func ProjectcodeFieldScore(tmp map[string]interface{},score int64) (map[string]interface{}) {
  9. projectcode := qu.ObjToString(tmp["projectcode"])
  10. reason,desc:=fmt.Sprintf("%d初始分",score),""
  11. /*错误项*/
  12. l := utf8.RuneCountInString(projectcode)
  13. if l > 19 || l < 5 {
  14. return map[string]interface{}{
  15. "score":int64(0),
  16. "reason":"错误:长度",
  17. }
  18. }
  19. if isRegTimeDateCode(projectcode) {
  20. return map[string]interface{}{
  21. "score":int64(0),
  22. "reason":"错误:日期格式",
  23. }
  24. }
  25. if codeUnConReg.MatchString(projectcode) {
  26. return map[string]interface{}{
  27. "score":int64(0),
  28. "reason":"错误:黑名单",
  29. }
  30. }
  31. if !isAlphanumeric(projectcode) {
  32. return map[string]interface{}{
  33. "score":int64(0),
  34. "reason":"错误:不含字母数字",
  35. }
  36. }
  37. /*减分项
  38. "符号过多": 1,
  39. "连续中文": 2,
  40. */
  41. countArr := isCharCount(projectcode)
  42. if countArr[3] > 6 {
  43. desc = "符号过多"
  44. reason+="~"+desc + fmt.Sprintf("-%d",qu.Int64All(u.Projectcode_Score[desc]))
  45. score -= qu.Int64All(u.Projectcode_Score[desc])
  46. }
  47. //连续中文长度超过X个
  48. if codeUnLenReg.MatchString(projectcode) {
  49. desc = "连续中文"
  50. reason+="~"+desc + fmt.Sprintf("-%d",qu.Int64All(u.Projectcode_Score[desc]))
  51. score -= qu.Int64All(u.Projectcode_Score[desc])
  52. }
  53. return map[string]interface{}{
  54. "score":score,
  55. "reason":reason,
  56. }
  57. }