message.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. "eta_gn/eta_api/models/report_approve"
  8. "fmt"
  9. )
  10. // MessageController
  11. // @Description: 消息控制器
  12. type MessageController struct {
  13. BaseAuthController
  14. }
  15. // UnReadMessageNum
  16. // @Title 获取未读取的消息数量
  17. // @Description 获取未读取的消息数量
  18. // @Success 200 {object} data_manage_permission.MessageDetailListResp
  19. // @router /unread/num [get]
  20. func (c *MessageController) UnReadMessageNum() {
  21. br := new(models.BaseResponse).Init()
  22. defer func() {
  23. if br.ErrMsg == "" {
  24. br.IsSendEmail = false
  25. }
  26. c.Data["json"] = br
  27. c.ServeJSON()
  28. }()
  29. sysUser := c.SysUser
  30. if sysUser == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,SysUser Is Empty"
  33. br.Ret = 408
  34. return
  35. }
  36. var unReadReportNum, unReadDataPermissionNum, unReadBiNum, unReadKnowledgeNum int
  37. // 获取报告审批消息
  38. {
  39. cond := fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.ReceiveUserId)
  40. pars := make([]interface{}, 0)
  41. pars = append(pars, sysUser.AdminId)
  42. messageOb := new(report_approve.ReportApproveMessage)
  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. cond := fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.ReceiveUserId)
  57. pars := make([]interface{}, 0)
  58. pars = append(pars, sysUser.AdminId)
  59. messageOb := new(data_manage_permission.DataPermissionMessage)
  60. // 未读消息数
  61. cond += fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.IsRead)
  62. pars = append(pars, 0)
  63. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  64. if e != nil {
  65. br.Msg = "获取失败"
  66. br.ErrMsg = "获取资产消息列表总数失败, Err: " + e.Error()
  67. return
  68. }
  69. unReadDataPermissionNum = unreadTotal
  70. }
  71. // 获得看板消息
  72. {
  73. messageOb := new(biapprove.BiApproveMessage)
  74. pars := make([]interface{}, 0)
  75. cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, biapprove.BiApproveMessageCols.ReceiveUserId, biapprove.BiApproveMessageCols.IsRead)
  76. pars = append(pars, sysUser.AdminId, 0)
  77. // 未读消息数
  78. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  79. if e != nil {
  80. br.Msg = "获取失败"
  81. br.ErrMsg = "获取看板消息列表总数失败, Err: " + e.Error()
  82. return
  83. }
  84. unReadBiNum = unreadTotal
  85. }
  86. // 观点库审批
  87. {
  88. messageOb := new(knowledge_approve.KnowledgeResourceApproveMessage)
  89. pars := make([]interface{}, 0)
  90. cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, knowledge_approve.KnowledgeResourceApproveMessageCols.ReceiveUserId, knowledge_approve.KnowledgeResourceApproveMessageCols.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. unReadKnowledgeNum = unreadTotal
  100. }
  101. // 汇总数
  102. num := unReadReportNum + unReadDataPermissionNum + unReadBiNum + unReadKnowledgeNum
  103. br.Data = num
  104. br.Ret = 200
  105. br.Success = true
  106. br.Msg = "获取成功"
  107. }