knowledge_approve_node.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package knowledge_approve
  2. import (
  3. "eta_gn/eta_api/global"
  4. "fmt"
  5. "strings"
  6. "time"
  7. )
  8. type KnowledgeResourceApproveNode struct {
  9. KnowledgeResourceApproveNodeId int `gorm:"column:knowledge_resource_approve_node_id;primaryKey"`
  10. KnowledgeResourceApproveFlowId int `gorm:"column:knowledge_resource_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 KnowledgeResourceApproveNodeCols = struct {
  20. KnowledgeResourceApproveNodeId string
  21. KnowledgeResourceApproveFlowId string
  22. PrevNodeId string
  23. NextNodeId string
  24. NodeType string
  25. ApproveType string
  26. Users string
  27. CurrVersion string
  28. CreatedTime string
  29. }{
  30. KnowledgeResourceApproveNodeId: "knowledge_resource_approve_node_id",
  31. KnowledgeResourceApproveFlowId: "knowledge_resource_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 *KnowledgeResourceApproveNode) TableName() string {
  41. return "knowledge_resource_approve_node"
  42. }
  43. func (m *KnowledgeResourceApproveNode) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*KnowledgeResourceApproveNode, err error) {
  44. fields := strings.Join(fieldArr, ",")
  45. if len(fieldArr) == 0 {
  46. fields = `*`
  47. }
  48. order := `ORDER BY created_time DESC, knowledge_resource_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 []*KnowledgeResourceApproveNode) (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 GetKnowledgeResourceApproveNodeByCondition(condition string, pars []interface{}) (node []*KnowledgeResourceApproveNode, err error) {
  71. o := global.DmSQL["rddp"]
  72. sql := "SELECT * FROM knowledge_resource_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 GetKnowledgeResourceApproveNodeByFlowIdAndVersionId(flowId int, versionId int) (node []*KnowledgeResourceApproveNode, err error) {
  80. err = global.DmSQL["rddp"].Model(&KnowledgeResourceApproveNode{}).Where("knowledge_resource_approve_flow_id =? AND curr_version =?", flowId, versionId).Scan(&node).Error
  81. return
  82. }