sys_message_report.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. "fmt"
  7. "github.com/rdlucklib/rdluck_tools/paging"
  8. )
  9. type SysMessageReportController struct {
  10. BaseAuthController
  11. }
  12. // @Title 阅读消息
  13. // @Description 阅读消息
  14. // @Param request body system.SysRoleDeleteReq true "type json string"
  15. // @Success 200 查看成功
  16. // @router /read [post]
  17. func (this *SysMessageReportController) Read() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. err := models.UpdateReadSysMessageReportByUserId(this.SysUser.SysUserId)
  24. if err != nil {
  25. br.Msg = "更新消息状态失败"
  26. br.ErrMsg = "更新消息状态失败,系统错误,Err:" + err.Error()
  27. return
  28. }
  29. br.Msg = "查看成功"
  30. br.Success = true
  31. br.Ret = 200
  32. }
  33. // List
  34. // @Title 系统消息列表
  35. // @Description 系统消息列表
  36. // @Param PageSize query int true "每页数据条数"
  37. // @Param CurrentIndex query int true "当前页页码,从1开始"
  38. // @Success 200 {object} response.SysRoleListResp
  39. // @router /list [get]
  40. func (this *SysMessageReportController) List() {
  41. br := new(models.BaseResponse).Init()
  42. defer func() {
  43. this.Data["json"] = br
  44. this.ServeJSON()
  45. }()
  46. pageSize, _ := this.GetInt("PageSize")
  47. currentIndex, _ := this.GetInt("CurrentIndex")
  48. var startSize int
  49. if pageSize <= 0 {
  50. pageSize = utils.PageSize20
  51. }
  52. if currentIndex <= 0 {
  53. currentIndex = 1
  54. }
  55. startSize = utils.StartIndex(currentIndex, pageSize)
  56. total, err := models.GetSysMessageReportCountBySysUserId(this.SysUser.SysUserId)
  57. if err != nil {
  58. br.Msg = "获取失败"
  59. br.ErrMsg = "获取失败,Err:" + err.Error()
  60. return
  61. }
  62. fmt.Println(startSize)
  63. fmt.Println(pageSize)
  64. list, err := models.GetSysMessageReportBySysUserId(this.SysUser.SysUserId, startSize, pageSize)
  65. if err != nil {
  66. br.Msg = "获取失败"
  67. br.ErrMsg = "获取失败,Err:" + err.Error()
  68. return
  69. }
  70. page := paging.GetPaging(currentIndex, pageSize, total)
  71. resp := new(response.SysMessageListResp)
  72. resp.List = list
  73. resp.Paging = page
  74. br.Ret = 200
  75. br.Success = true
  76. br.Msg = "获取成功"
  77. br.Data = resp
  78. }