message.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package controllers
  2. import (
  3. "eta/eta_api/models"
  4. "eta/eta_api/models/data_manage/data_manage_permission"
  5. edbmonitor "eta/eta_api/models/edb_monitor"
  6. "eta/eta_api/models/report_approve"
  7. "fmt"
  8. )
  9. // MessageController
  10. // @Description: 消息控制器
  11. type MessageController struct {
  12. BaseAuthController
  13. }
  14. // UnReadMessageNum
  15. // @Title 获取未读取的消息数量
  16. // @Description 获取未读取的消息数量
  17. // @Success 200 {object} data_manage_permission.MessageDetailListResp
  18. // @router /unread/num [get]
  19. func (c *MessageController) UnReadMessageNum() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. if br.ErrMsg == "" {
  23. br.IsSendEmail = false
  24. }
  25. c.Data["json"] = br
  26. c.ServeJSON()
  27. }()
  28. sysUser := c.SysUser
  29. if sysUser == nil {
  30. br.Msg = "请登录"
  31. br.ErrMsg = "请登录,SysUser Is Empty"
  32. br.Ret = 408
  33. return
  34. }
  35. var unReadReportNum, unReadDataPermissionNum, unReadEdbMonitorNum int
  36. // 获取报告审批消息
  37. {
  38. cond := fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.ReceiveUserId)
  39. pars := make([]interface{}, 0)
  40. pars = append(pars, sysUser.AdminId)
  41. messageOb := new(report_approve.ReportApproveMessage)
  42. // 未读消息数
  43. cond += fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.IsRead)
  44. pars = append(pars, 0)
  45. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  46. if e != nil {
  47. br.Msg = "获取失败"
  48. br.ErrMsg = "获取审批消息列表总数失败, Err: " + e.Error()
  49. return
  50. }
  51. unReadReportNum = unreadTotal
  52. }
  53. // 获取资产消息
  54. {
  55. cond := fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.ReceiveUserId)
  56. pars := make([]interface{}, 0)
  57. pars = append(pars, sysUser.AdminId)
  58. messageOb := new(data_manage_permission.DataPermissionMessage)
  59. // 未读消息数
  60. cond += fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.IsRead)
  61. pars = append(pars, 0)
  62. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  63. if e != nil {
  64. br.Msg = "获取失败"
  65. br.ErrMsg = "获取资产消息列表总数失败, Err: " + e.Error()
  66. return
  67. }
  68. unReadDataPermissionNum = unreadTotal
  69. }
  70. // 获取预警消息
  71. {
  72. pars := make([]interface{}, 0)
  73. cond := ` AND admin_id = ? AND is_read = ?`
  74. pars = append(pars, sysUser.AdminId, 0)
  75. // 未读消息数
  76. messageOb := new(edbmonitor.EdbMonitorMessage)
  77. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  78. if e != nil {
  79. br.Msg = "获取失败"
  80. br.ErrMsg = "获取资产消息列表总数失败, Err: " + e.Error()
  81. return
  82. }
  83. unReadEdbMonitorNum = unreadTotal
  84. }
  85. // 汇总数
  86. num := unReadReportNum + unReadDataPermissionNum + unReadEdbMonitorNum
  87. br.Data = num
  88. br.Ret = 200
  89. br.Success = true
  90. br.Msg = "获取成功"
  91. }