kpi.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package blocked
  2. import (
  3. "encoding/json"
  4. "strconv"
  5. "go-common/app/admin/main/credit/model"
  6. "go-common/library/log"
  7. xtime "go-common/library/time"
  8. )
  9. // const kpi
  10. const (
  11. RateS = int8(1)
  12. RateA = int8(2)
  13. RateB = int8(3)
  14. RateC = int8(4)
  15. RateD = int8(5)
  16. )
  17. // KPI is blocked_kpi model.
  18. type KPI struct {
  19. ID int64 `gorm:"column:id" json:"id"`
  20. UID int64 `gorm:"column:mid" json:"uid"`
  21. Day xtime.Time `gorm:"column:day" json:"day"`
  22. Rate int8 `gorm:"column:rate" json:"rate"`
  23. Rank int64 `gorm:"column:rank" json:"rank"`
  24. RankPer int16 `gorm:"column:rank_per" json:"rank_per"`
  25. RankTotal int64 `gorm:"column:rank_total" json:"rank_total"`
  26. HStatus int8 `gorm:"column:handler_status" json:"handler_status"`
  27. PStatus int8 `gorm:"column:pendent_status" json:"pendent_status"`
  28. CTime xtime.Time `gorm:"column:ctime" json:"-"`
  29. MTime xtime.Time `gorm:"column:mtime" json:"-"`
  30. }
  31. // KPIDesc is blocked_kpi_desc model.
  32. type KPIDesc struct {
  33. ID string `json:"id"`
  34. UID string `json:"uid"`
  35. Day string `json:"day"`
  36. Rate string `json:"rate"`
  37. RankPer string `json:"rank_per"`
  38. RankTotal string `json:"rank_total"`
  39. PStatus string `json:"pendent_status"`
  40. }
  41. // KPIList is kpi list.
  42. type KPIList struct {
  43. Count int64 `json:"count"`
  44. Pn int `json:"pn"`
  45. Ps int `json:"ps"`
  46. List []*KPI `json:"list"`
  47. }
  48. // TableName kpi tablename
  49. func (*KPI) TableName() string {
  50. return "blocked_kpi"
  51. }
  52. // RateDesc is rate desc.
  53. func RateDesc(rate int8) string {
  54. switch rate {
  55. case RateS:
  56. return "S"
  57. case RateA:
  58. return "A"
  59. case RateB:
  60. return "B"
  61. case RateC:
  62. return "C"
  63. case RateD:
  64. return "D"
  65. }
  66. return ""
  67. }
  68. // DealKPI deal with kpi data.
  69. func DealKPI(kpis []*KPI) (data [][]string, err error) {
  70. var kpiDescs []*KPIDesc
  71. for _, v := range kpis {
  72. kpiDesc := &KPIDesc{
  73. ID: strconv.FormatInt(v.ID, 10),
  74. UID: strconv.FormatInt(v.UID, 10),
  75. Day: v.Day.Time().Format(model.TimeFormatDay),
  76. Rate: RateDesc(v.Rate),
  77. RankPer: strconv.FormatInt(int64(v.RankPer), 10),
  78. RankTotal: strconv.FormatInt(int64(v.RankTotal), 10),
  79. PStatus: strconv.FormatInt(int64(v.PStatus), 10),
  80. }
  81. kpiDescs = append(kpiDescs, kpiDesc)
  82. }
  83. kpiMap, _ := json.Marshal(kpiDescs)
  84. var objmap []map[string]string
  85. if err = json.Unmarshal(kpiMap, &objmap); err != nil {
  86. log.Error("Unmarshal(%s) error(%v)", string(kpiMap), err)
  87. return
  88. }
  89. data = append(data, []string{"ID", "MID", "KPI日期", "评级", "排名百分比", "参与总数", "挂件发放状态"})
  90. for _, v := range objmap {
  91. var fields []string
  92. fields = append(fields, v["id"])
  93. fields = append(fields, v["uid"])
  94. fields = append(fields, v["day"])
  95. fields = append(fields, v["rate"])
  96. fields = append(fields, v["rank_per"])
  97. fields = append(fields, v["rank_total"])
  98. fields = append(fields, v["pendent_status"])
  99. data = append(data, fields)
  100. }
  101. return
  102. }
  103. // KPIPoint is blocked_kpi_point model.
  104. type KPIPoint struct {
  105. ID int64 `gorm:"column:id" json:"id"`
  106. UID int64 `gorm:"column:mid" json:"uid"`
  107. Day xtime.Time `gorm:"column:day" json:"day"`
  108. Point int16 `gorm:"column:point" json:"point"`
  109. ActiveDays int16 `gorm:"column:active_days" json:"active_days"`
  110. VoteTotal int `gorm:"column:vote_total" json:"vote_total"`
  111. VoteRadio int16 `gorm:"column:vote_radio" json:"vote_radio"`
  112. BlockedTotal int `gorm:"column:blocked_total" json:"blocked_total"`
  113. CTime xtime.Time `gorm:"column:ctime" json:"-"`
  114. MTime xtime.Time `gorm:"column:mtime" json:"-"`
  115. }
  116. // TableName kpi_point tablename
  117. func (*KPIPoint) TableName() string {
  118. return "blocked_kpi_point"
  119. }
  120. // KPIPointList is kpi_point list.
  121. type KPIPointList struct {
  122. Count int `json:"total_count"`
  123. Order string `json:"order"`
  124. Sort string `json:"sort"`
  125. PN int `json:"pn"`
  126. PS int `json:"ps"`
  127. IDs []int64 `json:"-"`
  128. List []*KPIPoint `json:"list"`
  129. }