ACT_RU_EXECUTION.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package dao
  2. import (
  3. "gorm.io/gorm"
  4. "server/global"
  5. "time"
  6. "github.com/mumushuiding/util"
  7. )
  8. // Execution 流程实例(执行流)表
  9. // ProcInstID 流程实例ID
  10. // BusinessKey 启动业务时指定的业务主键
  11. // ProcDefID 流程定义数据的ID
  12. type Execution struct {
  13. global.GVA_MODEL
  14. Rev int `json:"rev"`
  15. ProcInstID int `json:"procInstID"`
  16. ProcDefID int `json:"procDefID"`
  17. ProcDefName string `json:"procDefName"`
  18. // NodeInfos 执行流经过的所有节点
  19. NodeInfos string `gorm:"size:4000" json:"nodeInfos"`
  20. IsActive int8 `json:"isActive"`
  21. StartTime string `json:"startTime"`
  22. }
  23. // Save save
  24. func (p *Execution) Save() (ID int, err error) {
  25. err = global.GVA_DB.Create(p).Error
  26. if err != nil {
  27. return 0, err
  28. }
  29. return int(p.ID), nil
  30. }
  31. // SaveTx SaveTx
  32. // 接收外部事务
  33. func (p *Execution) SaveTx(tx *gorm.DB) (ID int, err error) {
  34. p.StartTime = util.FormatDate(time.Now(), util.YYYY_MM_DD_HH_MM_SS)
  35. if err := tx.Create(p).Error; err != nil {
  36. return 0, err
  37. }
  38. return int(p.ID), nil
  39. }
  40. // GetExecByProcInst GetExecByProcInst
  41. // 根据流程实例id查询执行流
  42. func GetExecByProcInst(procInstID int) (*Execution, error) {
  43. var p = &Execution{}
  44. err := global.GVA_DB.Where("proc_inst_id=?", procInstID).Find(p).Error
  45. // log.Printf("procdef:%v,err:%v", p, err)
  46. if err == gorm.ErrRecordNotFound {
  47. return nil, nil
  48. }
  49. if err != nil || p == nil {
  50. return nil, err
  51. }
  52. return p, nil
  53. }
  54. // GetExecNodeInfosByProcInstID GetExecNodeInfosByProcInstID
  55. // 根据流程实例procInstID查询执行流经过的所有节点信息
  56. func GetExecNodeInfosByProcInstID(procInstID int) (string, error) {
  57. var e = &Execution{}
  58. err := global.GVA_DB.Select("node_infos").Where("proc_inst_id=?", procInstID).Find(e).Error
  59. // fmt.Println(e)
  60. if err != nil {
  61. return "", err
  62. }
  63. return e.NodeInfos, nil
  64. }
  65. // ExistsExecByProcInst ExistsExecByProcInst
  66. // 指定流程实例的执行流是否已经存在
  67. func ExistsExecByProcInst(procInst int) (bool, error) {
  68. e, err := GetExecByProcInst(procInst)
  69. // var p = &Execution{}
  70. // err := db.Where("proc_inst_id=?", procInst).Find(p).RecordNotFound
  71. // log.Printf("errnotfound:%v", err)
  72. if e != nil {
  73. return true, nil
  74. }
  75. if err != nil {
  76. return false, err
  77. }
  78. return false, nil
  79. }