workflow.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package service
  2. import (
  3. "context"
  4. "strconv"
  5. "strings"
  6. "time"
  7. "go-common/app/job/main/workflow/model"
  8. srvmodel "go-common/app/service/main/workflow/model"
  9. "go-common/library/log"
  10. )
  11. // searchParams .
  12. func searchParams(c context.Context, dealType, listState int, busAttr []*model.BusinessAttr) (params *model.SearchParams) {
  13. var businessArr []string
  14. params = &model.SearchParams{}
  15. if listState == model.ListBefore {
  16. params.AssigneeAdminIDs = "0"
  17. params.AssigneeAdminIDsNot = ""
  18. switch dealType {
  19. case model.FDealType:
  20. params.States = model.FListBeforeStates
  21. params.BusinessStates = model.FListBeforeBusinessStates
  22. params.MtimeTo = time.Now().Add(-time.Minute * 1).Format("2006-01-02 15:04:05")
  23. case model.ADealType:
  24. params.States = model.AListBeforeStates
  25. }
  26. } else if listState == model.ListAfter {
  27. params.AssigneeAdminIDs = ""
  28. params.AssigneeAdminIDsNot = "0"
  29. switch dealType {
  30. case model.FDealType:
  31. params.States = model.FListAfterStates
  32. params.BusinessStates = model.FListAfterBusinessStates
  33. case model.ADealType:
  34. params.States = model.AListAfterStates
  35. }
  36. } else if listState == model.ListIng {
  37. params.AssigneeAdminIDs = ""
  38. params.AssigneeAdminIDsNot = ""
  39. switch dealType {
  40. case model.FDealType:
  41. params.States = model.FListAfterStates
  42. params.BusinessStates = model.FListAfterBusinessStates
  43. case model.ADealType:
  44. params.States = model.AListAfterStates
  45. }
  46. }
  47. for _, attr := range busAttr {
  48. if attr.AssignType == model.SysAssignType {
  49. continue
  50. }
  51. if dealType == model.ADealType {
  52. businessArr = append(businessArr, strconv.FormatInt(attr.ID, 10))
  53. } else {
  54. if attr.DealType == dealType {
  55. businessArr = append(businessArr, strconv.FormatInt(attr.ID, 10))
  56. }
  57. }
  58. }
  59. params.Business = strings.Join(businessArr, ",")
  60. return
  61. }
  62. // challByIDs .
  63. func (s *Service) challByIDs(c context.Context, params *model.SearchParams) (res map[int64]*model.Chall, err error) {
  64. var cids []int64
  65. searchRes, err := s.dao.SearchChall(c, params)
  66. if err != nil {
  67. log.Error("s.dao.SearchChall error(%v)", err)
  68. return
  69. }
  70. searchDataRes := searchRes.Result
  71. if len(searchDataRes) > 0 {
  72. for _, r := range searchDataRes {
  73. cids = append(cids, r.ID)
  74. }
  75. res, err = s.dao.ChallByIDs(c, cids)
  76. }
  77. return
  78. }
  79. // disPatchState .
  80. func (s *Service) dispatchState(c context.Context, dealType, listState, oldDispatchState int) (newDispatchState int64) {
  81. state := oldDispatchState & srvmodel.QueueState
  82. if dealType == model.FDealType {
  83. if listState == model.ListBefore {
  84. newDispatchState, _ = strconv.ParseInt("f"+strconv.Itoa(state), 16, 64)
  85. } else if listState == model.ListAfter {
  86. newDispatchState, _ = strconv.ParseInt("1"+strconv.Itoa(state), 16, 64)
  87. }
  88. } else if dealType == model.ADealType {
  89. if listState == model.ListBefore {
  90. newDispatchState = int64(srvmodel.QueueState)
  91. } else if listState == model.ListAfter {
  92. newDispatchState = int64(srvmodel.QueueStateBefore)
  93. }
  94. }
  95. return
  96. }
  97. // key .
  98. func genKey(c context.Context, business int64, dealType int) (key string) {
  99. key = _wfKeyPrefix + strconv.FormatInt(business, 10) + "_" + strconv.Itoa(dealType)
  100. return
  101. }