123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package service
- import (
- "github.com/go-workflow/go-workflow/workflow-engine/model"
- "github.com/jinzhu/gorm"
- "github.com/mumushuiding/util"
- )
- // SaveIdentitylinkTx SaveIdentitylinkTx
- func SaveIdentitylinkTx(i *model.Identitylink, tx *gorm.DB) error {
- return i.SaveTx(tx)
- }
- // AddNotifierTx 添加抄送人候选用户组
- func AddNotifierTx(group, company string, step, procInstID int, tx *gorm.DB) error {
- yes, err := ExistsNotifierByProcInstIDAndGroup(procInstID, group)
- if err != nil {
- return err
- }
- if yes {
- return nil
- }
- i := &model.Identitylink{
- Group: group,
- Type: model.IdentityTypes[model.NOTIFIER],
- Step: step,
- ProcInstID: procInstID,
- Company: company,
- }
- return SaveIdentitylinkTx(i, tx)
- }
- // AddCandidateGroupTx AddCandidateGroupTx
- // 添加候选用户组
- func AddCandidateGroupTx(group, company string, step, taskID, procInstID int, tx *gorm.DB) error {
- err := DelCandidateByProcInstID(procInstID, tx)
- if err != nil {
- return err
- }
- i := &model.Identitylink{
- Group: group,
- Type: model.IdentityTypes[model.CANDIDATE],
- TaskID: taskID,
- Step: step,
- ProcInstID: procInstID,
- Company: company,
- }
- return SaveIdentitylinkTx(i, tx)
- }
- // AddCandidateUserTx AddCandidateUserTx
- // 添加候选用户
- func AddCandidateUserTx(userID, company string, step, taskID, procInstID int, tx *gorm.DB) error {
- err := DelCandidateByProcInstID(procInstID, tx)
- if err != nil {
- return err
- }
- i := &model.Identitylink{
- UserID: userID,
- Type: model.IdentityTypes[model.CANDIDATE],
- TaskID: taskID,
- Step: step,
- ProcInstID: procInstID,
- Company: company,
- }
- return SaveIdentitylinkTx(i, tx)
- // var wg sync.WaitGroup
- // var err1, err2 error
- // numberOfRoutine := 2
- // wg.Add(numberOfRoutine)
- // go func() {
- // defer wg.Done()
- // err1 = DelCandidateByProcInstID(procInstID, tx)
- // }()
- // go func() {
- // defer wg.Done()
- // i := &model.Identitylink{
- // UserID: userID,
- // Type: model.IdentityTypes[model.CANDIDATE],
- // TaskID: taskID,
- // Step: step,
- // ProcInstID: procInstID,
- // Company: company,
- // }
- // err2 = SaveIdentitylinkTx(i, tx)
- // }()
- // wg.Wait()
- // fmt.Println("保存identyilink结束")
- // if err1 != nil {
- // return err1
- // }
- // return err2
- }
- //AddParticipantTx AddParticipantTx
- // 添加任务参与人
- func AddParticipantTx(userID, username, company, comment string, taskID, procInstID, step int, tx *gorm.DB) error {
- i := &model.Identitylink{
- Type: model.IdentityTypes[model.PARTICIPANT],
- UserID: userID,
- UserName: username,
- ProcInstID: procInstID,
- Step: step,
- Company: company,
- TaskID: taskID,
- Comment: comment,
- }
- return SaveIdentitylinkTx(i, tx)
- }
- // IfParticipantByTaskID IfParticipantByTaskID
- // 针对指定任务判断用户是否已经审批过了
- func IfParticipantByTaskID(userID, company string, taskID int) (bool, error) {
- return model.IfParticipantByTaskID(userID, company, taskID)
- }
- // DelCandidateByProcInstID DelCandidateByProcInstID
- // 删除历史候选人
- func DelCandidateByProcInstID(procInstID int, tx *gorm.DB) error {
- return model.DelCandidateByProcInstID(procInstID, tx)
- }
- // ExistsNotifierByProcInstIDAndGroup 抄送人是否已经存在
- func ExistsNotifierByProcInstIDAndGroup(procInstID int, group string) (bool, error) {
- return model.ExistsNotifierByProcInstIDAndGroup(procInstID, group)
- }
- // FindParticipantByProcInstID 查询参与审批的人
- func FindParticipantByProcInstID(procInstID int) (string, error) {
- datas, err := model.FindParticipantByProcInstID(procInstID)
- if err != nil {
- return "", err
- }
- str, err := util.ToJSONStr(datas)
- if err != nil {
- return "", err
- }
- return str, nil
- }
|