label.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package goblin
  2. import (
  3. "strings"
  4. "go-common/app/interface/main/tv/conf"
  5. )
  6. // Label def.
  7. type Label struct {
  8. ID int `json:"id"`
  9. Name string `json:"name"`
  10. Param string `json:"param"`
  11. ParamName string `json:"param_name"`
  12. Value string `json:"value"`
  13. }
  14. // TypeLabels def.
  15. type TypeLabels struct {
  16. ParamName string `json:"param_name"`
  17. Param string `json:"param"`
  18. Labels []*Label `json:"labels"`
  19. }
  20. // FromLabels def.
  21. func (v *TypeLabels) FromLabels(labels []*Label) {
  22. if len(labels) == 0 {
  23. return
  24. }
  25. v.Param = labels[0].Param
  26. v.ParamName = labels[0].ParamName
  27. v.Labels = labels
  28. }
  29. // IndexLabels is used to combine the data in memory
  30. type IndexLabels struct {
  31. PGC map[int][]*TypeLabels // key is category, value is all the param and their labels
  32. UGC map[int][]*TypeLabels
  33. }
  34. // YearVDur def.
  35. type YearVDur struct {
  36. Dur string `json:"dur"`
  37. }
  38. // TransYear transforms the value of year type labels
  39. func (v *Label) TransYear(cfg *conf.IndexLabel) {
  40. if !cfg.IsYear(v.Param) {
  41. return
  42. }
  43. if len(cfg.YearV) == 0 {
  44. return
  45. }
  46. if newV, ok := cfg.YearV[v.Value]; ok { // replace the value
  47. v.Value = newV.Dur
  48. }
  49. if !strings.Contains(v.Value, "-") {
  50. v.Value = v.Value + "-" + v.Value
  51. } else { // transform 2004-2000 to 2000-2004
  52. years := strings.Split(v.Value, "-")
  53. if len(years) == 2 && years[0] != "" && years[1] != "" {
  54. v.Value = years[1] + "-" + years[0]
  55. }
  56. }
  57. }