message.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. "eta_gn/eta_api/models/knowledge_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, unReadBiNum, unReadKnowledgeNum 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. //
  42. // messageOb := new(report_approve.ReportApproveMessage)
  43. //
  44. // // 未读消息数
  45. // cond += fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.IsRead)
  46. // pars = append(pars, 0)
  47. // unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  48. // if e != nil {
  49. // br.Msg = "获取失败"
  50. // br.ErrMsg = "获取审批消息列表总数失败, Err: " + e.Error()
  51. // return
  52. // }
  53. // unReadReportNum = unreadTotal
  54. //}
  55. // 报告通知消息
  56. {
  57. // 未读消息数
  58. messageOb := new(models.ReportMessage)
  59. cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, models.ReportMessageCols.ReceiveUserId, models.ReportMessageCols.IsRead)
  60. pars := make([]interface{}, 0)
  61. pars = append(pars, sysUser.AdminId, 0)
  62. total, e := messageOb.GetCountByCondition(cond, pars)
  63. if e != nil {
  64. br.Msg = "获取失败"
  65. br.ErrMsg = "获取报告通知列表总数失败, Err: " + e.Error()
  66. return
  67. }
  68. unReadReportNum = total
  69. }
  70. // 获取资产消息
  71. {
  72. cond := fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.ReceiveUserId)
  73. pars := make([]interface{}, 0)
  74. pars = append(pars, sysUser.AdminId)
  75. messageOb := new(data_manage_permission.DataPermissionMessage)
  76. // 未读消息数
  77. cond += fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.IsRead)
  78. pars = append(pars, 0)
  79. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  80. if e != nil {
  81. br.Msg = "获取失败"
  82. br.ErrMsg = "获取资产消息列表总数失败, Err: " + e.Error()
  83. return
  84. }
  85. unReadDataPermissionNum = unreadTotal
  86. }
  87. // 获得看板消息
  88. {
  89. messageOb := new(biapprove.BiApproveMessage)
  90. pars := make([]interface{}, 0)
  91. cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, biapprove.BiApproveMessageCols.ReceiveUserId, biapprove.BiApproveMessageCols.IsRead)
  92. pars = append(pars, sysUser.AdminId, 0)
  93. // 未读消息数
  94. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  95. if e != nil {
  96. br.Msg = "获取失败"
  97. br.ErrMsg = "获取看板消息列表总数失败, Err: " + e.Error()
  98. return
  99. }
  100. unReadBiNum = unreadTotal
  101. }
  102. // 观点库审批
  103. {
  104. messageOb := new(knowledge_approve.KnowledgeResourceApproveMessage)
  105. pars := make([]interface{}, 0)
  106. cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, knowledge_approve.KnowledgeResourceApproveMessageCols.ReceiveUserId, knowledge_approve.KnowledgeResourceApproveMessageCols.IsRead)
  107. pars = append(pars, sysUser.AdminId, 0)
  108. // 未读消息数
  109. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  110. if e != nil {
  111. br.Msg = "获取失败"
  112. br.ErrMsg = "获取看板消息列表总数失败, Err: " + e.Error()
  113. return
  114. }
  115. unReadKnowledgeNum = unreadTotal
  116. }
  117. // 汇总数
  118. num := unReadReportNum + unReadDataPermissionNum + unReadBiNum + unReadKnowledgeNum
  119. br.Data = num
  120. br.Ret = 200
  121. br.Success = true
  122. br.Msg = "获取成功"
  123. }