util.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package util
  2. import (
  3. "github.com/shopspring/decimal"
  4. qu "qfw/util"
  5. "reflect"
  6. "strconv"
  7. "strings"
  8. )
  9. var Fields = map[string]interface{}{
  10. "publishtime": 1,
  11. "detail": 1,
  12. "contenthtml": 1,
  13. "title": 1,
  14. "href": 1,
  15. "competehref": 1,
  16. "area": 1,
  17. "city": 1,
  18. "district": 1,
  19. "site": 1,
  20. "channel": 1,
  21. "spidercode": 1,
  22. "jsondata": 1,
  23. "_d": 1,
  24. "iscompete": 1, //由爬虫决定
  25. "comeintime": 1,
  26. "projectinfo": 1,
  27. "T": 1,
  28. "dataging": 1,
  29. "infoformat": 1,
  30. //"publishdept": 1,
  31. //"type": 1,
  32. }
  33. const GTEID = "5a862f0640d2d9bbe88e3cec"
  34. //处理因前后端交互,字段类型转换
  35. func FormatFields(tmp map[string]interface{}) {
  36. for k, v := range tmp {
  37. if k == "dataging" || k == "infoformat" {
  38. tmp[k] = qu.IntAll(v)
  39. } else if strings.HasSuffix(k, "time") { //处理时间字段
  40. tmp[k] = qu.Int64All(v)
  41. } else if k == "budget" || k == "bidamount" {
  42. tmp[k] = qu.Float64All(v)
  43. }
  44. }
  45. }
  46. /**
  47. * 前端科学计数法处理
  48. */
  49. func FormatNumber(tmp map[string]interface{}) {
  50. for k, v := range tmp {
  51. if reflect.TypeOf(v).Name() == reflect.Float64.String() {
  52. num, _ := decimal.NewFromString(strconv.FormatFloat(qu.Float64All(v), 'e', -1, 64))
  53. tmp[k], _ = num.Float64()
  54. }
  55. }
  56. }