util.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package http
  2. import (
  3. "strconv"
  4. "strings"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/xstr"
  8. )
  9. type intsParam struct {
  10. value string
  11. p *[]int64
  12. }
  13. type intParam struct {
  14. value string
  15. p *int64
  16. }
  17. func dealNumsmap(intsparams []*intsParam) error {
  18. for _, isp := range intsparams {
  19. if isp.value != "" {
  20. ids, err := xstr.SplitInts(isp.value)
  21. if err != nil {
  22. log.Error("strconv.ParseInt(%s) error(%v)", isp.value, err)
  23. return err
  24. }
  25. *isp.p = ids
  26. }
  27. }
  28. return nil
  29. }
  30. func dealNummap(intparams []*intParam) error {
  31. for _, ip := range intparams {
  32. if ip.value != "" {
  33. id, err := strconv.ParseInt(ip.value, 10, 64)
  34. if err != nil {
  35. log.Error("strconv.ParseInt(%s) error(%v)", ip.value, err)
  36. return err
  37. }
  38. *ip.p = id
  39. }
  40. }
  41. return nil
  42. }
  43. // adjustOrder will convert order field from request to search service
  44. func adjustOrder(subject string, order string) string {
  45. SubOrderFields := map[string]map[string]string{
  46. "group": {
  47. "last_time": "lasttime",
  48. },
  49. "tag": {
  50. "count": "tag_all_num",
  51. "handling": "tag_todo_num",
  52. },
  53. "challenge": {},
  54. "log": {
  55. "ctime": "opt_ctime",
  56. },
  57. }
  58. orderFields, ok := SubOrderFields[subject]
  59. if !ok {
  60. return order
  61. }
  62. field, ok := orderFields[order]
  63. if !ok {
  64. return order
  65. }
  66. return field
  67. }
  68. // read permissions of an admin
  69. // only use workflow permissions in platform
  70. // like WF_BUSINESS_2_ROUND_11
  71. // round > 10 means feedback flow
  72. // one admin only has one flow permission in a business
  73. func parsePermission(permissions []string) (permissionMap map[int8]int64) {
  74. //permissionMap map[business]round
  75. //var regex = `^WF_BUSINESS_[1-9]\d*_ROUND_[1-9]\d*`
  76. permissionMap = make(map[int8]int64)
  77. for _, str := range permissions {
  78. splitStr := strings.Split(str, "_")
  79. if len(splitStr) == 5 && splitStr[0] == "WF" && splitStr[1] == "BUSINESS" && splitStr[3] == "ROUND" {
  80. business, err := strconv.ParseInt(splitStr[2], 10, 32)
  81. if err != nil {
  82. continue
  83. }
  84. round, err := strconv.ParseInt(splitStr[4], 10, 32)
  85. if err != nil {
  86. continue
  87. }
  88. permissionMap[int8(business)] = round
  89. //todo: support round??
  90. }
  91. }
  92. // todo: use cache?
  93. return
  94. }
  95. func adminInfo(ctx *bm.Context) (adminID int64, adminName string) {
  96. if IUid, ok := ctx.Get("uid"); ok {
  97. adminID = IUid.(int64)
  98. }
  99. if IUName, ok := ctx.Get("username"); ok {
  100. adminName = IUName.(string)
  101. }
  102. return
  103. }