run.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // ============================================================================
  2. // This is auto-generated by gf cli tool only once. Fill this file as you wish.
  3. // ============================================================================
  4. package wf_run
  5. import (
  6. "database/sql"
  7. "github.com/gogf/gf/database/gdb"
  8. "github.com/gogf/gf/errors/gerror"
  9. "github.com/gogf/gf/frame/g"
  10. )
  11. type RunSearch struct {
  12. FromId uint `json:"from_id"`
  13. FromTable string `json:"from_table"`
  14. IsDel uint `json:"is_del"`
  15. Status uint `json:"status"`
  16. }
  17. type RunAddData struct {
  18. Pid uint `p:"pid" json:"pid"` // work_run父流转公文ID 值大于0则这个是子流程,完成后或者要返回父流程
  19. Uid uint `p:"uid" json:"uid"` //
  20. FlowId uint `p:"flow_id" json:"flow_id"` // 流程id 正常流程
  21. FromTable string `p:"from_table" json:"from_table"` // 单据表,不带前缀
  22. FromTitle string `p:"from_title" json:"from_title"` // 业务表标题字段
  23. FromStatus string `p:"from_status" json:"from_status"` // 业务表审批状态字段
  24. FromId int `p:"from_id" json:"from_id"` //
  25. RunName string `p:"run_name" json:"run_name"` // 公文名称
  26. RunFlowId uint `p:"run_flow_id" json:"run_flow_id"` // 流转到什么流程 最新流程,查询优化,进入子流程时将简化查询,子流程与父流程同步
  27. RunFlowProcess string `p:"run_flow_process" json:"run_flow_process"` // 流转到第几步
  28. Dateline uint `p:"dateline" json:"dateline"` //
  29. }
  30. //获取流程运行信息
  31. func GetRunning(where *RunSearch) (entity *Entity, err error) {
  32. entity, err = Model.Where(where).Order("id desc").FindOne()
  33. if err != nil {
  34. g.Log().Error(err)
  35. err = gerror.New("判断运行状态出错")
  36. }
  37. return
  38. }
  39. func GetRuns(where interface{}, args ...interface{}) (entities []*Entity, err error) {
  40. entities, err = Model.Where(where, args).Order("id asc").FindAll()
  41. if err != nil {
  42. g.Log().Error(err)
  43. err = gerror.New("获取流程运行状态失败")
  44. }
  45. return
  46. }
  47. //获取流程运行信息
  48. func GetRunById(id uint) (entity *Entity, err error) {
  49. entity, err = Model.FindOne(id)
  50. if err != nil {
  51. g.Log().Error(err)
  52. err = gerror.New("获取运行数据失败")
  53. return
  54. }
  55. return
  56. }
  57. func Add(data *RunAddData, tx *gdb.TX) (id int64, err error) {
  58. var res sql.Result
  59. res, err = Model.TX(tx).Save(data)
  60. if err != nil {
  61. g.Log().Error(err)
  62. err = gerror.New("保存业务流程运行信息出错")
  63. return
  64. }
  65. id, err = res.LastInsertId()
  66. return
  67. }
  68. func UpdateRun(runId uint, data g.Map, tx *gdb.TX) error {
  69. _, err := Model.TX(tx).Where("id", runId).Update(data)
  70. return err
  71. }