report_message.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "fmt"
  6. "strings"
  7. "time"
  8. "github.com/rdlucklib/rdluck_tools/paging"
  9. )
  10. const (
  11. ReportMessageTypeWriteNotice = 1 // 撰写通知
  12. ReportMessageTypeApprovePass = 2 // 审批通过
  13. ReportMessageTypeApproveRefuse = 3 // 审批驳回
  14. )
  15. type ReportMessage struct {
  16. Id int `gorm:"primaryKey;column:id;type:int(10) unsigned;not null"`
  17. SendUserId int `gorm:"column:send_user_id" description:"发送人ID"`
  18. ReceiveUserId int `gorm:"column:receive_user_id" description:"接受者ID"`
  19. Content string `gorm:"column:content" description:"消息内容"`
  20. Remark string `gorm:"column:remark" description:"备注信息"`
  21. ExtraContent string `gorm:"column:extra_content" description:"额外信息-JSON"`
  22. ReportType int `gorm:"column:report_type" description:"报告类型:1-研报;2-PPT"`
  23. ReportId int `gorm:"column:report_id" description:"报告/PPT-ID"`
  24. MessageType int `gorm:"column:message_type" description:"消息类型:1-撰写通知;2-审批通过;3-审批驳回"`
  25. IsRead int `gorm:"column:is_read" description:"是否已读:0-未读;1-已读"`
  26. CreateTime time.Time `gorm:"column:create_time" description:"消息时间"`
  27. ModifyTime time.Time `gorm:"column:modify_time" description:"更新时间"`
  28. }
  29. var ReportMessageCols = struct {
  30. Id string
  31. SendUserId string
  32. ReceiveUserId string
  33. Content string
  34. Remark string
  35. ExtraContent string
  36. ReportType string
  37. ReportId string
  38. MessageType string
  39. IsRead string
  40. CreateTime string
  41. }{
  42. Id: "id",
  43. SendUserId: "send_user_id",
  44. ReceiveUserId: "receive_user_id",
  45. Content: "content",
  46. Remark: "remark",
  47. ExtraContent: "extra_content",
  48. ReportType: "report_type",
  49. ReportId: "report_id",
  50. MessageType: "message_type",
  51. IsRead: "is_read",
  52. CreateTime: "create_time",
  53. }
  54. func (m *ReportMessage) TableName() string {
  55. return "report_message"
  56. }
  57. func (m *ReportMessage) PrimaryId() string {
  58. return ReportMessageCols.Id
  59. }
  60. func (m *ReportMessage) Create() (err error) {
  61. err = global.DmSQL["rddp"].Create(m).Error
  62. return
  63. }
  64. func (m *ReportMessage) CreateMulti(items []*ReportMessage) (err error) {
  65. if len(items) == 0 {
  66. return
  67. }
  68. err = global.DmSQL["rddp"].CreateInBatches(items, utils.MultiAddNum).Error
  69. return
  70. }
  71. func (m *ReportMessage) Update(cols []string) (err error) {
  72. err = global.DmSQL["rddp"].Select(cols).Updates(m).Error
  73. return
  74. }
  75. func (m *ReportMessage) Del() (err error) {
  76. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  77. err = global.DmSQL["rddp"].Exec(sql, m.Id).Error
  78. return
  79. }
  80. func (m *ReportMessage) MultiDel(menuIds []int) (err error) {
  81. if len(menuIds) == 0 {
  82. return
  83. }
  84. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  85. err = global.DmSQL["rddp"].Exec(sql, menuIds).Error
  86. return
  87. }
  88. func (m *ReportMessage) GetItemById(id int) (item *ReportMessage, err error) {
  89. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  90. err = global.DmSQL["rddp"].Raw(sql, id).First(&item).Error
  91. return
  92. }
  93. func (m *ReportMessage) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *ReportMessage, err error) {
  94. order := ``
  95. if orderRule != "" {
  96. order = ` ORDER BY ` + orderRule
  97. }
  98. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  99. err = global.DmSQL["rddp"].Raw(sql, pars...).First(&item).Error
  100. return
  101. }
  102. func (m *ReportMessage) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  103. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  104. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  105. return
  106. }
  107. func (m *ReportMessage) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*ReportMessage, err error) {
  108. fields := strings.Join(fieldArr, ",")
  109. if len(fieldArr) == 0 {
  110. fields = `*`
  111. }
  112. order := `ORDER BY create_time DESC`
  113. if orderRule != "" {
  114. order = ` ORDER BY ` + orderRule
  115. }
  116. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  117. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  118. return
  119. }
  120. func (m *ReportMessage) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*ReportMessage, err error) {
  121. fields := strings.Join(fieldArr, ",")
  122. if len(fieldArr) == 0 {
  123. fields = `*`
  124. }
  125. order := `ORDER BY create_time DESC`
  126. if orderRule != "" {
  127. order = ` ORDER BY ` + orderRule
  128. }
  129. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  130. pars = append(pars, startSize)
  131. pars = append(pars, pageSize)
  132. err = global.DmSQL["rddp"].Raw(sql, pars...).Find(&items).Error
  133. return
  134. }
  135. // ReportMessageItem 报告消息
  136. type ReportMessageItem struct {
  137. Id int
  138. SendUserId int `description:"发送人ID"`
  139. ReceiveUserId int `description:"接收者ID"`
  140. Content string `description:"消息内容"`
  141. Remark string `description:"备注信息"`
  142. ReportType int `description:"报告类型:1-研报;2-PPT"`
  143. ReportId int `description:"报告/PPT-ID"`
  144. ReportState int `description:"报告当前状态"`
  145. MessageType int `description:"消息类型:1-撰写通知;2-审批通过;3-审批驳回"`
  146. IsRead int `description:"是否已读:0-未读;1-已读"`
  147. CreateTime string `description:"消息时间"`
  148. ApproveMsg *ReportMessageApproveItem `description:"审批信息"`
  149. }
  150. // ReportMessageApproveItem 报告消息审批内容
  151. type ReportMessageApproveItem struct {
  152. Title string `description:"报告标题"`
  153. ApproveType int `description:"审批类型:1-通过;2-驳回"`
  154. ApproveUserId int `description:"审批人ID"`
  155. ApproveUserName string `description:"审批人"`
  156. ApproveRemark string `description:"审批备注(驳回意见)"`
  157. }
  158. // FormatReportMessage2Item 格式化报告消息
  159. func FormatReportMessage2Item(origin *ReportMessage) (item *ReportMessageItem) {
  160. item = new(ReportMessageItem)
  161. if origin == nil {
  162. return
  163. }
  164. item.Id = origin.Id
  165. item.SendUserId = origin.SendUserId
  166. item.ReceiveUserId = origin.ReceiveUserId
  167. item.Content = origin.Content
  168. item.Remark = origin.Remark
  169. item.ReportType = origin.ReportType
  170. item.ReportId = origin.ReportId
  171. item.MessageType = origin.MessageType
  172. item.IsRead = origin.IsRead
  173. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  174. return
  175. }
  176. // ReportMessageListReq 消息列表请求参数
  177. type ReportMessageListReq struct {
  178. PageSize int `form:"PageSize"`
  179. CurrentIndex int `form:"CurrentIndex"`
  180. }
  181. // ReportMessageListResp 消息列表响应体
  182. type ReportMessageListResp struct {
  183. List []*ReportMessageItem
  184. Paging *paging.PagingItem `description:"分页数据"`
  185. UnreadTotal int `description:"消息未读数"`
  186. }
  187. // ReportMessageReadReq 消息已读请求体
  188. type ReportMessageReadReq struct {
  189. MessageId int `description:"消息ID"`
  190. }