sys_message_report.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package controllers
  2. import (
  3. "eta/eta_mini_crm/models"
  4. "eta/eta_mini_crm/models/response"
  5. "eta/eta_mini_crm/utils"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. )
  8. type SysMessageReportController struct {
  9. BaseAuthController
  10. }
  11. // @Title 阅读消息
  12. // @Description 阅读消息
  13. // @Param request body system.SysRoleDeleteReq true "type json string"
  14. // @Success 200 查看成功
  15. // @router /read [post]
  16. func (this *SysMessageReportController) Read() {
  17. br := new(models.BaseResponse).Init()
  18. defer func() {
  19. this.Data["json"] = br
  20. this.ServeJSON()
  21. }()
  22. err := models.UpdateReadSysMessageReportByUserId(this.SysUser.SysUserId)
  23. if err != nil {
  24. br.Msg = "更新消息状态失败"
  25. br.ErrMsg = "更新消息状态失败,系统错误,Err:" + err.Error()
  26. return
  27. }
  28. br.Msg = "查看成功"
  29. br.Success = true
  30. br.Ret = 200
  31. }
  32. // List
  33. // @Title 系统消息列表
  34. // @Description 系统消息列表
  35. // @Param PageSize query int true "每页数据条数"
  36. // @Param CurrentIndex query int true "当前页页码,从1开始"
  37. // @Success 200 {object} response.SysRoleListResp
  38. // @router /list [get]
  39. func (this *SysMessageReportController) List() {
  40. br := new(models.BaseResponse).Init()
  41. defer func() {
  42. this.Data["json"] = br
  43. this.ServeJSON()
  44. }()
  45. pageSize, _ := this.GetInt("PageSize")
  46. currentIndex, _ := this.GetInt("CurrentIndex")
  47. var startSize int
  48. if pageSize <= 0 {
  49. pageSize = utils.PageSize20
  50. }
  51. if currentIndex <= 0 {
  52. currentIndex = 1
  53. }
  54. startSize = utils.StartIndex(currentIndex, pageSize)
  55. total, err := models.GetSysMessageReportCountBySysUserId(this.SysUser.SysUserId)
  56. if err != nil {
  57. br.Msg = "获取失败"
  58. br.ErrMsg = "获取失败,Err:" + err.Error()
  59. return
  60. }
  61. list, err := models.GetSysMessageReportBySysUserId(this.SysUser.SysUserId, startSize, pageSize)
  62. if err != nil {
  63. br.Msg = "获取失败"
  64. br.ErrMsg = "获取失败,Err:" + err.Error()
  65. return
  66. }
  67. messageList := make([]*models.SysMessageReportView, 0)
  68. for _, v := range list {
  69. messageList = append(messageList, &models.SysMessageReportView{
  70. SysMessageReportId: v.SysMessageReportId,
  71. UserId: v.UserId,
  72. ReceiveSysUserId: v.ReceiveSysUserId,
  73. MessageType: v.MessageType,
  74. Content: v.Content,
  75. Remark: v.Remark,
  76. IsRead: v.IsRead,
  77. CreateTime: v.CreateTime.Format(utils.FormatDateTime),
  78. ModifyTime: v.ModifyTime.Format(utils.FormatDateTime),
  79. })
  80. }
  81. page := paging.GetPaging(currentIndex, pageSize, total)
  82. resp := new(response.SysMessageListResp)
  83. resp.List = messageList
  84. resp.Paging = page
  85. br.Ret = 200
  86. br.Success = true
  87. br.Msg = "获取成功"
  88. br.Data = resp
  89. }