identitylinkService.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package service
  2. import (
  3. "github.com/go-workflow/go-workflow/workflow-engine/model"
  4. "github.com/jinzhu/gorm"
  5. "github.com/mumushuiding/util"
  6. )
  7. // SaveIdentitylinkTx SaveIdentitylinkTx
  8. func SaveIdentitylinkTx(i *model.Identitylink, tx *gorm.DB) error {
  9. return i.SaveTx(tx)
  10. }
  11. // AddNotifierTx 添加抄送人候选用户组
  12. func AddNotifierTx(group, company string, step, procInstID int, tx *gorm.DB) error {
  13. yes, err := ExistsNotifierByProcInstIDAndGroup(procInstID, group)
  14. if err != nil {
  15. return err
  16. }
  17. if yes {
  18. return nil
  19. }
  20. i := &model.Identitylink{
  21. Group: group,
  22. Type: model.IdentityTypes[model.NOTIFIER],
  23. Step: step,
  24. ProcInstID: procInstID,
  25. Company: company,
  26. }
  27. return SaveIdentitylinkTx(i, tx)
  28. }
  29. // AddCandidateGroupTx AddCandidateGroupTx
  30. // 添加候选用户组
  31. func AddCandidateGroupTx(group, company string, step, taskID, procInstID int, tx *gorm.DB) error {
  32. err := DelCandidateByProcInstID(procInstID, tx)
  33. if err != nil {
  34. return err
  35. }
  36. i := &model.Identitylink{
  37. Group: group,
  38. Type: model.IdentityTypes[model.CANDIDATE],
  39. TaskID: taskID,
  40. Step: step,
  41. ProcInstID: procInstID,
  42. Company: company,
  43. }
  44. return SaveIdentitylinkTx(i, tx)
  45. }
  46. // AddCandidateUserTx AddCandidateUserTx
  47. // 添加候选用户
  48. func AddCandidateUserTx(userID, company string, step, taskID, procInstID int, tx *gorm.DB) error {
  49. err := DelCandidateByProcInstID(procInstID, tx)
  50. if err != nil {
  51. return err
  52. }
  53. i := &model.Identitylink{
  54. UserID: userID,
  55. Type: model.IdentityTypes[model.CANDIDATE],
  56. TaskID: taskID,
  57. Step: step,
  58. ProcInstID: procInstID,
  59. Company: company,
  60. }
  61. return SaveIdentitylinkTx(i, tx)
  62. // var wg sync.WaitGroup
  63. // var err1, err2 error
  64. // numberOfRoutine := 2
  65. // wg.Add(numberOfRoutine)
  66. // go func() {
  67. // defer wg.Done()
  68. // err1 = DelCandidateByProcInstID(procInstID, tx)
  69. // }()
  70. // go func() {
  71. // defer wg.Done()
  72. // i := &model.Identitylink{
  73. // UserID: userID,
  74. // Type: model.IdentityTypes[model.CANDIDATE],
  75. // TaskID: taskID,
  76. // Step: step,
  77. // ProcInstID: procInstID,
  78. // Company: company,
  79. // }
  80. // err2 = SaveIdentitylinkTx(i, tx)
  81. // }()
  82. // wg.Wait()
  83. // fmt.Println("保存identyilink结束")
  84. // if err1 != nil {
  85. // return err1
  86. // }
  87. // return err2
  88. }
  89. //AddParticipantTx AddParticipantTx
  90. // 添加任务参与人
  91. func AddParticipantTx(userID, username, company, comment string, taskID, procInstID, step int, tx *gorm.DB) error {
  92. i := &model.Identitylink{
  93. Type: model.IdentityTypes[model.PARTICIPANT],
  94. UserID: userID,
  95. UserName: username,
  96. ProcInstID: procInstID,
  97. Step: step,
  98. Company: company,
  99. TaskID: taskID,
  100. Comment: comment,
  101. }
  102. return SaveIdentitylinkTx(i, tx)
  103. }
  104. // IfParticipantByTaskID IfParticipantByTaskID
  105. // 针对指定任务判断用户是否已经审批过了
  106. func IfParticipantByTaskID(userID, company string, taskID int) (bool, error) {
  107. return model.IfParticipantByTaskID(userID, company, taskID)
  108. }
  109. // DelCandidateByProcInstID DelCandidateByProcInstID
  110. // 删除历史候选人
  111. func DelCandidateByProcInstID(procInstID int, tx *gorm.DB) error {
  112. return model.DelCandidateByProcInstID(procInstID, tx)
  113. }
  114. // ExistsNotifierByProcInstIDAndGroup 抄送人是否已经存在
  115. func ExistsNotifierByProcInstIDAndGroup(procInstID int, group string) (bool, error) {
  116. return model.ExistsNotifierByProcInstIDAndGroup(procInstID, group)
  117. }
  118. // FindParticipantByProcInstID 查询参与审批的人
  119. func FindParticipantByProcInstID(procInstID int) (string, error) {
  120. datas, err := model.FindParticipantByProcInstID(procInstID)
  121. if err != nil {
  122. return "", err
  123. }
  124. str, err := util.ToJSONStr(datas)
  125. if err != nil {
  126. return "", err
  127. }
  128. return str, nil
  129. }