knowledge_approve_message.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package knowledge_approve
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "strings"
  7. "time"
  8. )
  9. type KnowledgeResourceApproveMessage struct {
  10. Id int `gorm:"primaryKey;column:id"`
  11. SendUserId int `gorm:"column:send_user_id"` // 发送人Id
  12. ReceiveUserId int `gorm:"column:receive_user_id"` // 接收者Id
  13. Content string `gorm:"column:content"` // 消息内容
  14. Remark string `gorm:"column:remark"` // 备注信息
  15. KnowledgeResourceApproveId int `gorm:"column:knowledge_resource_approve_id"` // 审批Id
  16. ApproveState int `gorm:"column:approve_state"` // 审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回
  17. IsRead int `gorm:"column:is_read"` // 是否已读:0-未读;1-已读
  18. CreateTime time.Time `gorm:"column:create_time"` // 创建时间
  19. ModifyTime time.Time `gorm:"column:modify_time"` // 修改时间
  20. }
  21. var KnowledgeResourceApproveMessageCols = struct {
  22. Id string
  23. SendUserId string
  24. ReceiveUserId string
  25. Content string
  26. Remark string
  27. KnowledgeResourceApproveId string
  28. ApproveState string
  29. IsRead string
  30. CreateTime string
  31. ModifyTime string
  32. }{
  33. Id: "id",
  34. SendUserId: "send_user_id",
  35. ReceiveUserId: "receive_user_id",
  36. Content: "content",
  37. Remark: "remark",
  38. KnowledgeResourceApproveId: "knowledge_resource_approve_id",
  39. ApproveState: "approve_state",
  40. IsRead: "is_read",
  41. CreateTime: "create_time",
  42. ModifyTime: "modify_time",
  43. }
  44. func (r *KnowledgeResourceApproveMessage) TableName() string {
  45. return "knowledge_resource_approve_message"
  46. }
  47. func (r *KnowledgeResourceApproveMessage) Create() (err error) {
  48. o := global.DmSQL["rddp"]
  49. err = o.Create(r).Error
  50. return err
  51. }
  52. func (m *KnowledgeResourceApproveMessage) PrimaryId() string {
  53. return KnowledgeResourceApproveMessageCols.Id
  54. }
  55. func (r *KnowledgeResourceApproveMessage) CreateMulti(items []*KnowledgeResourceApproveMessage) (err error) {
  56. if len(items) == 0 {
  57. return
  58. }
  59. o := global.DmSQL["rddp"]
  60. err = o.CreateInBatches(items, utils.MultiAddNum).Error
  61. return
  62. }
  63. func (m *KnowledgeResourceApproveMessage) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  64. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  65. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  66. return
  67. }
  68. func (m *KnowledgeResourceApproveMessage) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*KnowledgeResourceApproveMessage, err error) {
  69. fields := strings.Join(fieldArr, ",")
  70. if len(fieldArr) == 0 {
  71. fields = `*`
  72. }
  73. order := `ORDER BY create_time DESC`
  74. if orderRule != "" {
  75. order = ` ORDER BY ` + orderRule
  76. }
  77. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  78. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  79. return
  80. }
  81. func (m *KnowledgeResourceApproveMessage) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*KnowledgeResourceApproveMessage, err error) {
  82. fields := strings.Join(fieldArr, ",")
  83. if len(fieldArr) == 0 {
  84. fields = `*`
  85. }
  86. order := `ORDER BY create_time DESC`
  87. if orderRule != "" {
  88. order = ` ORDER BY ` + orderRule
  89. }
  90. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  91. pars = append(pars, startSize, pageSize)
  92. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  93. return
  94. }
  95. func (m *KnowledgeResourceApproveMessage) GetItemById(id int) (item *KnowledgeResourceApproveMessage, err error) {
  96. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? `, m.TableName(), m.PrimaryId())
  97. err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error
  98. return
  99. }
  100. func (m *KnowledgeResourceApproveMessage) Update(cols []string) (err error) {
  101. err = global.DmSQL["rddp"].Model(m).Select(cols).Updates(m).Error
  102. return
  103. }