bi_approve_node.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package biapprove
  2. import (
  3. "eta_gn/eta_api/global"
  4. "fmt"
  5. "strings"
  6. "time"
  7. )
  8. type BiApproveNode struct {
  9. BiApproveNodeId int `gorm:"column:bi_approve_node_id;primaryKey"`
  10. BiApproveFlowId int `gorm:"column:bi_approve_flow_id"`
  11. PrevNodeId int `gorm:"column:prev_node_id"`
  12. NextNodeId int `gorm:"column:next_node_id"`
  13. NodeType int `gorm:"column:node_type"`
  14. ApproveType int `gorm:"column:approve_type"`
  15. Users string `gorm:"column:users"`
  16. CurrVersion int `gorm:"column:curr_version"`
  17. CreatedTime time.Time `gorm:"column:created_time"`
  18. }
  19. var BiApproveNodeCols = struct {
  20. BiApproveNodeId string
  21. BiApproveFlowId string
  22. PrevNodeId string
  23. NextNodeId string
  24. NodeType string
  25. ApproveType string
  26. Users string
  27. CurrVersion string
  28. CreatedTime string
  29. }{
  30. BiApproveNodeId: "bi_approve_node_id",
  31. BiApproveFlowId: "bi_approve_flow_id",
  32. PrevNodeId: "prev_node_id",
  33. NextNodeId: "next_node_id",
  34. NodeType: "node_type",
  35. ApproveType: "approve_type",
  36. Users: "users",
  37. CurrVersion: "curr_version",
  38. CreatedTime: "created_time",
  39. }
  40. func (b *BiApproveNode) TableName() string {
  41. return "bi_approve_node"
  42. }
  43. func (m *BiApproveNode) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*BiApproveNode, err error) {
  44. fields := strings.Join(fieldArr, ",")
  45. if len(fieldArr) == 0 {
  46. fields = `*`
  47. }
  48. order := `ORDER BY created_time DESC, bi_approve_node_id ASC`
  49. if orderRule != "" {
  50. order = ` ORDER BY ` + orderRule
  51. }
  52. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  53. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  54. return
  55. }
  56. func UpdateNextNodes(nodes []*BiApproveNode) (err error) {
  57. if len(nodes) == 0 {
  58. return
  59. }
  60. updateCols := []string{"NextNodeId"}
  61. for _, v := range nodes {
  62. e := global.DmSQL["rddp"].Select(updateCols).Updates(v).Error
  63. if e != nil {
  64. err = fmt.Errorf("prev node update err: %v", e)
  65. return
  66. }
  67. }
  68. return
  69. }
  70. func GetBiApproveNodeByCondition(condition string, pars []interface{}) (node []*BiApproveNode, err error) {
  71. o := global.DmSQL["rddp"]
  72. sql := "SELECT * FROM bi_approve_node WHERE 1=1 "
  73. if condition != "" {
  74. sql += condition
  75. }
  76. err = o.Raw(sql, pars...).Find(&node).Error
  77. return
  78. }
  79. func GetBiApproveNodeByFlowIdAndVersionId(flowId int, versionId int) (node []*BiApproveNode, err error) {
  80. err = global.DmSQL["rddp"].Model(&BiApproveNode{}).Where("bi_approve_flow_id =? AND curr_version =?", flowId, versionId).Scan(&node).Error
  81. return
  82. }