message.go 3.3 KB

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