report_approve_message.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. package report_approve
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "strings"
  8. "time"
  9. )
  10. // ReportApproveMessage 报告审批消息表
  11. type ReportApproveMessage struct {
  12. Id int `orm:"column(id);pk"`
  13. SendUserId int `description:"发送人ID"`
  14. ReceiveUserId int `description:"接收者ID"`
  15. Content string `description:"消息内容"`
  16. Remark string `description:"备注信息"`
  17. ReportApproveId int `description:"审批ID"`
  18. ApproveState int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  19. IsRead int `description:"是否已读:0-未读;1-已读"`
  20. CreateTime time.Time `description:"创建时间"`
  21. ModifyTime time.Time `description:"修改时间"`
  22. }
  23. var ReportApproveMessageCols = struct {
  24. Id string
  25. SendUserId string
  26. ReceiveUserId string
  27. Content string
  28. Remark string
  29. ReportApproveId string
  30. ApproveState string
  31. IsRead string
  32. CreateTime string
  33. ModifyTime string
  34. }{
  35. Id: "id",
  36. SendUserId: "send_user_id",
  37. ReceiveUserId: "receive_user_id",
  38. Content: "content",
  39. Remark: "remark",
  40. ReportApproveId: "report_approve_id",
  41. ApproveState: "approve_state",
  42. IsRead: "is_read",
  43. CreateTime: "create_time",
  44. ModifyTime: "modify_time",
  45. }
  46. func (m *ReportApproveMessage) TableName() string {
  47. return "report_approve_message"
  48. }
  49. func (m *ReportApproveMessage) PrimaryId() string {
  50. return ReportApproveMessageCols.Id
  51. }
  52. func (m *ReportApproveMessage) Create() (err error) {
  53. o := orm.NewOrmUsingDB("rddp")
  54. id, err := o.Insert(m)
  55. if err != nil {
  56. return
  57. }
  58. m.Id = int(id)
  59. return
  60. }
  61. func (m *ReportApproveMessage) CreateMulti(items []*ReportApproveMessage) (err error) {
  62. if len(items) == 0 {
  63. return
  64. }
  65. o := orm.NewOrmUsingDB("rddp")
  66. _, err = o.InsertMulti(len(items), items)
  67. return
  68. }
  69. func (m *ReportApproveMessage) Update(cols []string) (err error) {
  70. o := orm.NewOrmUsingDB("rddp")
  71. _, err = o.Update(m, cols...)
  72. return
  73. }
  74. func (m *ReportApproveMessage) Del() (err error) {
  75. o := orm.NewOrmUsingDB("rddp")
  76. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  77. _, err = o.Raw(sql, m.Id).Exec()
  78. return
  79. }
  80. func (m *ReportApproveMessage) MultiDel(menuIds []int) (err error) {
  81. if len(menuIds) == 0 {
  82. return
  83. }
  84. o := orm.NewOrmUsingDB("rddp")
  85. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  86. _, err = o.Raw(sql, menuIds).Exec()
  87. return
  88. }
  89. func (m *ReportApproveMessage) GetItemById(id int) (item *ReportApproveMessage, err error) {
  90. o := orm.NewOrmUsingDB("rddp")
  91. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  92. err = o.Raw(sql, id).QueryRow(&item)
  93. return
  94. }
  95. func (m *ReportApproveMessage) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *ReportApproveMessage, err error) {
  96. o := orm.NewOrmUsingDB("rddp")
  97. order := ``
  98. if orderRule != "" {
  99. order = ` ORDER BY ` + orderRule
  100. }
  101. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  102. err = o.Raw(sql, pars).QueryRow(&item)
  103. return
  104. }
  105. func (m *ReportApproveMessage) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  106. o := orm.NewOrmUsingDB("rddp")
  107. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  108. err = o.Raw(sql, pars).QueryRow(&count)
  109. return
  110. }
  111. func (m *ReportApproveMessage) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*ReportApproveMessage, err error) {
  112. o := orm.NewOrmUsingDB("rddp")
  113. fields := strings.Join(fieldArr, ",")
  114. if len(fieldArr) == 0 {
  115. fields = `*`
  116. }
  117. order := `ORDER BY create_time DESC`
  118. if orderRule != "" {
  119. order = ` ORDER BY ` + orderRule
  120. }
  121. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  122. _, err = o.Raw(sql, pars).QueryRows(&items)
  123. return
  124. }
  125. func (m *ReportApproveMessage) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*ReportApproveMessage, err error) {
  126. o := orm.NewOrmUsingDB("rddp")
  127. fields := strings.Join(fieldArr, ",")
  128. if len(fieldArr) == 0 {
  129. fields = `*`
  130. }
  131. order := `ORDER BY create_time DESC`
  132. if orderRule != "" {
  133. order = ` ORDER BY ` + orderRule
  134. }
  135. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  136. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  137. return
  138. }
  139. // ReportApproveMessageItem 报告审批消息信息
  140. type ReportApproveMessageItem struct {
  141. Id int
  142. SendUserId int `description:"发送人ID"`
  143. ReceiveUserId int `description:"接收者ID"`
  144. Content string `description:"消息内容"`
  145. Remark string `description:"备注信息"`
  146. ReportApproveId int `description:"审批ID"`
  147. ApproveState int `description:"审批状态:1-待审批;2-已审批;3-已驳回;4-已撤回"`
  148. IsRead int `description:"是否已读:0-未读;1-已读"`
  149. CreateTime string `description:"创建时间"`
  150. ModifyTime string `description:"修改时间"`
  151. }
  152. // FormatReportApproveMessage2Item 格式化报告审批消息
  153. func FormatReportApproveMessage2Item(origin *ReportApproveMessage) (item *ReportApproveMessageItem) {
  154. item = new(ReportApproveMessageItem)
  155. if origin == nil {
  156. return
  157. }
  158. item.Id = origin.Id
  159. item.SendUserId = origin.SendUserId
  160. item.ReceiveUserId = origin.ReceiveUserId
  161. item.Content = origin.Content
  162. item.Remark = origin.Remark
  163. item.ReportApproveId = origin.ReportApproveId
  164. item.ApproveState = origin.ApproveState
  165. item.IsRead = origin.IsRead
  166. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  167. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  168. return
  169. }
  170. // ReportApproveMessageListReq 审批消息列表请求参数
  171. type ReportApproveMessageListReq struct {
  172. PageSize int `form:"PageSize"`
  173. CurrentIndex int `form:"CurrentIndex"`
  174. }
  175. // ReportApproveMessageListResp 审批消息列表响应体
  176. type ReportApproveMessageListResp struct {
  177. List []*ReportApproveMessageItem
  178. Paging *paging.PagingItem `description:"分页数据"`
  179. UnreadTotal int `description:"消息未读数"`
  180. }
  181. // ReportApproveMessageReadReq 审批消息已读请求体
  182. type ReportApproveMessageReadReq struct {
  183. MessageId int `description:"审批消息ID"`
  184. }