sys_message_report.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "eta/eta_mini_crm/models"
  5. "eta/eta_mini_crm/models/request"
  6. "eta/eta_mini_crm/models/response"
  7. "eta/eta_mini_crm/utils"
  8. "fmt"
  9. "time"
  10. "github.com/rdlucklib/rdluck_tools/paging"
  11. )
  12. type SysMessageReportController struct {
  13. BaseAuthController
  14. }
  15. // @Title 阅读消息
  16. // @Description 阅读消息
  17. // @Param request body system.SysRoleDeleteReq true "type json string"
  18. // @Success 200 查看成功
  19. // @router /read [post]
  20. func (this *SysMessageReportController) Read() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. this.Data["json"] = br
  24. this.ServeJSON()
  25. }()
  26. var req request.SysMessageReadReq
  27. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  28. if err != nil {
  29. br.Msg = "参数解析异常!"
  30. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  31. return
  32. }
  33. if len(req.SysMessageId) <= 0 {
  34. br.Msg = "参数异常"
  35. return
  36. }
  37. messages, err := models.GetSysMessageReportListById(req.SysMessageId)
  38. if err != nil {
  39. br.Msg = "查询消息出错"
  40. br.ErrMsg = "查询消息出错,系统错误,Err:" + err.Error()
  41. return
  42. }
  43. for _, msg := range messages {
  44. msg.IsRead = true
  45. msg.ModifyTime = time.Now()
  46. msg.Update([]string{"is_read", "modify_time"})
  47. }
  48. br.Msg = "查看成功"
  49. br.Success = true
  50. br.Ret = 200
  51. }
  52. // List
  53. // @Title 系统消息列表
  54. // @Description 系统消息列表
  55. // @Param PageSize query int true "每页数据条数"
  56. // @Param CurrentIndex query int true "当前页页码,从1开始"
  57. // @Success 200 {object} response.SysRoleListResp
  58. // @router /list [get]
  59. func (this *SysMessageReportController) List() {
  60. br := new(models.BaseResponse).Init()
  61. defer func() {
  62. this.Data["json"] = br
  63. this.ServeJSON()
  64. }()
  65. pageSize, _ := this.GetInt("PageSize")
  66. currentIndex, _ := this.GetInt("CurrentIndex")
  67. var startSize int
  68. if pageSize <= 0 {
  69. pageSize = utils.PageSize20
  70. }
  71. if currentIndex <= 0 {
  72. currentIndex = 1
  73. }
  74. startSize = utils.StartIndex(currentIndex, pageSize)
  75. total, err := models.GetSysMessageReportCountBySysUserId(this.SysUser.SysUserId)
  76. if err != nil {
  77. br.Msg = "获取失败"
  78. br.ErrMsg = "获取失败,Err:" + err.Error()
  79. return
  80. }
  81. fmt.Println(startSize)
  82. fmt.Println(pageSize)
  83. list, err := models.GetSysMessageReportBySysUserId(this.SysUser.SysUserId, startSize, pageSize)
  84. if err != nil {
  85. br.Msg = "获取失败"
  86. br.ErrMsg = "获取失败,Err:" + err.Error()
  87. return
  88. }
  89. page := paging.GetPaging(currentIndex, pageSize, total)
  90. resp := new(response.SysMessageListResp)
  91. resp.List = list
  92. resp.Paging = page
  93. br.Ret = 200
  94. br.Success = true
  95. br.Msg = "获取成功"
  96. br.Data = resp
  97. }