ACT_RU_IDENTITYLINK.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package dao
  2. import (
  3. "gorm.io/gorm"
  4. "server/global"
  5. )
  6. // Identitylink 用户组同任务的关系
  7. type Identitylink struct {
  8. global.GVA_MODEL
  9. Group string `json:"group,omitempty"`
  10. Type string `json:"type,omitempty"`
  11. UserID string `json:"userid,omitempty"`
  12. UserName string `json:"username,omitempty"`
  13. TaskID int `json:"taskID,omitempty"`
  14. Step int `json:"step"`
  15. ProcInstID int `json:"procInstID,omitempty"`
  16. Company string `json:"company,omitempty"`
  17. Comment string `json:"comment,omitempty"`
  18. }
  19. // IdentityType 类型
  20. type IdentityType int
  21. const (
  22. // CANDIDATE 候选
  23. CANDIDATE IdentityType = iota
  24. // PARTICIPANT 参与人
  25. PARTICIPANT
  26. // MANAGER 上级领导
  27. MANAGER
  28. // NOTIFIER 抄送人
  29. NOTIFIER
  30. )
  31. // IdentityTypes IdentityTypes
  32. var IdentityTypes = [...]string{CANDIDATE: "candidate", PARTICIPANT: "participant", MANAGER: "主管", NOTIFIER: "notifier"}
  33. // SaveTx SaveTx
  34. func (i *Identitylink) SaveTx(tx *gorm.DB) error {
  35. // if len(i.Company) == 0 {
  36. // return errors.New("Identitylink表的company字段不能为空!!")
  37. // }
  38. err := tx.Create(i).Error
  39. return err
  40. }
  41. // DelCandidateByProcInstID DelCandidateByProcInstID
  42. // 删除历史候选人
  43. func DelCandidateByProcInstID(procInstID int, tx *gorm.DB) error {
  44. return tx.Where("proc_inst_id=? and type=?", procInstID, IdentityTypes[CANDIDATE]).Delete(&Identitylink{}).Error
  45. }
  46. // ExistsNotifierByProcInstIDAndGroup 抄送人是否已经存在
  47. func ExistsNotifierByProcInstIDAndGroup(procInstID int, group string) (bool, error) {
  48. var count int64
  49. err := global.GVA_DB.Model(&Identitylink{}).Where("identitylink.proc_inst_id=? and identitylink.group=? and identitylink.type=?", procInstID, group, IdentityTypes[NOTIFIER]).Count(&count).Error
  50. if err != nil {
  51. if err == gorm.ErrRecordNotFound {
  52. return false, nil
  53. }
  54. return false, err
  55. }
  56. if count > 0 {
  57. return true, nil
  58. }
  59. return false, nil
  60. }
  61. // IfParticipantByTaskID IfParticipantByTaskID
  62. // 针对指定任务判断用户是否已经审批过了
  63. func IfParticipantByTaskID(userID, company string, taskID int) (bool, error) {
  64. var count int64
  65. err := global.GVA_DB.Model(&Identitylink{}).Where("user_id=? and company=? and task_id=?", userID, company, taskID).Count(&count).Error
  66. if err != nil {
  67. if err == gorm.ErrRecordNotFound {
  68. return false, nil
  69. }
  70. return false, err
  71. }
  72. if count > 0 {
  73. return true, nil
  74. }
  75. return false, nil
  76. }
  77. // FindParticipantByProcInstID 查询参与审批的人
  78. func FindParticipantByProcInstID(procInstID int) ([]*Identitylink, error) {
  79. var datas []*Identitylink
  80. err := global.GVA_DB.Select("id,user_id,user_name,step,comment").Where("proc_inst_id=? and type=?", procInstID, IdentityTypes[PARTICIPANT]).Order("id asc").Find(&datas).Error
  81. return datas, err
  82. }