oa_report_message.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. package models
  2. import (
  3. "eta_gn/eta_task/global"
  4. "eta_gn/eta_task/utils"
  5. "fmt"
  6. "strings"
  7. "time"
  8. )
  9. const (
  10. OaReportMessageSourceRemind = 1
  11. OaReportMessageStatusSuccess = 1
  12. OaReportMessageStatusFail = 2
  13. )
  14. // OaReportMessage OA报告消息
  15. type OaReportMessage struct {
  16. Id int `gorm:"primaryKey;autoIncrement;column:id"`
  17. ReceiveUserId int `gorm:"column:receive_user_id" description:"接收人ID"`
  18. ReportType int `gorm:"column:report_type" description:"报告类型:1-研报;2-PPT"`
  19. ReportId int `gorm:"column:report_id" description:"报告/PPT-ID"`
  20. MessageParams string `gorm:"column:message_params" description:"消息请求"`
  21. MessageResult string `gorm:"column:message_result" description:"响应结果"`
  22. TaskId string `gorm:"column:task_id" description:"待办任务ID"`
  23. Source int `gorm:"column:source" description:"来源:1-报告提醒"`
  24. SendStatus int `gorm:"column:send_status" description:"发送状态:1-发送成功;2-发送失败"`
  25. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  26. ModifyTime time.Time `gorm:"column:modify_time" description:"更新时间"`
  27. }
  28. func (m *OaReportMessage) TableName() string {
  29. return "oa_report_message"
  30. }
  31. type OaReportMessageCols struct {
  32. PrimaryId string
  33. ReceiveUserId string
  34. ReportType string
  35. ReportId string
  36. MessageParams string
  37. MessageResult string
  38. TaskId string
  39. Source string
  40. SendStatus string
  41. CreateTime string
  42. ModifyTime string
  43. }
  44. func (m *OaReportMessage) Cols() OaReportMessageCols {
  45. return OaReportMessageCols{
  46. PrimaryId: "id",
  47. ReceiveUserId: "receive_user_id",
  48. ReportType: "report_type",
  49. ReportId: "report_id",
  50. MessageParams: "message_params",
  51. MessageResult: "message_result",
  52. TaskId: "task_id",
  53. Source: "source",
  54. SendStatus: "send_status",
  55. CreateTime: "create_time",
  56. ModifyTime: "modify_time",
  57. }
  58. }
  59. func (m *OaReportMessage) Create() (err error) {
  60. err = global.DmSQL["eta"].Create(m).Error
  61. return
  62. }
  63. func (m *OaReportMessage) CreateMulti(items []*OaReportMessage) (err error) {
  64. if len(items) == 0 {
  65. return
  66. }
  67. err = global.DmSQL["eta"].CreateInBatches(items, utils.MultiAddNum).Error
  68. return
  69. }
  70. func (m *OaReportMessage) Update(cols []string) (err error) {
  71. err = global.DmSQL["eta"].Select(cols).Updates(m).Error
  72. return
  73. }
  74. func (m *OaReportMessage) Remove() (err error) {
  75. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  76. err = global.DmSQL["eta"].Exec(sql, m.Id).Error
  77. return
  78. }
  79. func (m *OaReportMessage) MultiRemove(ids []int) (err error) {
  80. if len(ids) == 0 {
  81. return
  82. }
  83. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.Cols().PrimaryId, utils.GetOrmInReplace(len(ids)))
  84. err = global.DmSQL["eta"].Exec(sql, ids).Error
  85. return
  86. }
  87. func (m *OaReportMessage) RemoveByCondition(condition string, pars []interface{}) (err error) {
  88. if condition == "" {
  89. return
  90. }
  91. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s`, m.TableName(), condition)
  92. err = global.DmSQL["eta"].Exec(sql, pars...).Error
  93. return
  94. }
  95. func (m *OaReportMessage) GetItemById(id int) (item *OaReportMessage, err error) {
  96. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.Cols().PrimaryId)
  97. err = global.DmSQL["eta"].Raw(sql, id).First(&item).Error
  98. return
  99. }
  100. func (m *OaReportMessage) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *OaReportMessage, err error) {
  101. order := ``
  102. if orderRule != "" {
  103. order = ` ORDER BY ` + orderRule
  104. }
  105. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  106. err = global.DmSQL["eta"].Raw(sql, pars...).First(&item).Error
  107. return
  108. }
  109. func (m *OaReportMessage) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  110. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  111. err = global.DmSQL["eta"].Raw(sql, pars...).Scan(&count).Error
  112. return
  113. }
  114. func (m *OaReportMessage) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*OaReportMessage, err error) {
  115. fields := strings.Join(fieldArr, ",")
  116. if len(fieldArr) == 0 {
  117. fields = `*`
  118. }
  119. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  120. if orderRule != "" {
  121. order = ` ORDER BY ` + orderRule
  122. }
  123. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  124. err = global.DmSQL["eta"].Raw(sql, pars...).Find(&items).Error
  125. return
  126. }
  127. func (m *OaReportMessage) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*OaReportMessage, err error) {
  128. fields := strings.Join(fieldArr, ",")
  129. if len(fieldArr) == 0 {
  130. fields = `*`
  131. }
  132. order := fmt.Sprintf(`ORDER BY %s DESC`, m.Cols().CreateTime)
  133. if orderRule != "" {
  134. order = ` ORDER BY ` + orderRule
  135. }
  136. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  137. pars = append(pars, startSize, pageSize)
  138. err = global.DmSQL["eta"].Raw(sql, pars...).Find(&items).Error
  139. return
  140. }