ACT_RE_PROCDEF.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package dao
  2. import (
  3. "gorm.io/gorm"
  4. "server/global"
  5. )
  6. // Procdef 流程定义表
  7. type Procdef struct {
  8. global.GVA_MODEL
  9. Name string `json:"name,omitempty"`
  10. Version int `json:"version,omitempty"`
  11. // 流程定义json字符串
  12. Resource string `gorm:"size:10000" json:"resource,omitempty"`
  13. // 用户id
  14. Userid string `json:"userid,omitempty"`
  15. Username string `json:"username,omitempty"`
  16. // 用户所在公司
  17. Company string `json:"company,omitempty"`
  18. DeployTime string `json:"deployTime,omitempty"`
  19. }
  20. // Save save and return id
  21. // 保存并返回ID
  22. func (p *Procdef) Save() (ID int, err error) {
  23. err = global.GVA_DB.Create(p).Error
  24. if err != nil {
  25. return 0, err
  26. }
  27. return int(p.ID), nil
  28. }
  29. // SaveTx SaveTx
  30. func (p *Procdef) SaveTx(tx *gorm.DB) error {
  31. err := tx.Create(p).Error
  32. if err != nil {
  33. return err
  34. }
  35. return nil
  36. }
  37. // GetProcdefLatestByNameAndCompany :get latest procdef by name and company
  38. // 根据名字和公司查询最新的流程定义
  39. func GetProcdefLatestByNameAndCompany(name, company string) (*Procdef, error) {
  40. var p []*Procdef
  41. err := global.GVA_DB.Where("name=? and company=?", name, company).Order("version desc").Find(&p).Error
  42. if err != nil || len(p) == 0 {
  43. return nil, err
  44. }
  45. return p[0], err
  46. }
  47. // GetProcdefByID 根据流程定义
  48. func GetProcdefByID(id int) (*Procdef, error) {
  49. var p = &Procdef{}
  50. err := global.GVA_DB.Where("id=?", id).Find(p).Error
  51. return p, err
  52. }
  53. // DelProcdefByID del by id
  54. // 根据id删除
  55. func DelProcdefByID(id int) error {
  56. err := global.GVA_DB.Where("id = ?", id).Delete(&Procdef{}).Error
  57. return err
  58. }
  59. // DelProcdefByIDTx DelProcdefByIDTx
  60. func DelProcdefByIDTx(id int, tx *gorm.DB) error {
  61. return tx.Where("id = ?", id).Delete(&Procdef{}).Error
  62. }
  63. // FindProcdefsWithCountAndPaged return result with total count and error
  64. // 返回查询结果和总条数
  65. func FindProcdefsWithCountAndPaged(pageIndex, pageSize int, maps map[string]interface{}) (datas []*Procdef, count int64, err error) {
  66. err = global.GVA_DB.Select("id,name,version,userid,deploy_time").Where(maps).Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&datas).Error
  67. if err != nil && err != gorm.ErrRecordNotFound {
  68. return nil, 0, err
  69. }
  70. err = global.GVA_DB.Model(&Procdef{}).Where(maps).Count(&count).Error
  71. if err != nil {
  72. return nil, 0, err
  73. }
  74. return datas, count, nil
  75. }
  76. // MoveProcdefToHistoryByIDTx 将流程定义移至历史纪录表
  77. func MoveProcdefToHistoryByIDTx(ID int, tx *gorm.DB) error {
  78. err := tx.Exec("insert into procdef_history select * from procdef where id=?", ID).Error
  79. if err != nil {
  80. return err
  81. }
  82. return DelProcdefByIDTx(ID, tx)
  83. }