message.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/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, unReadBiNum 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. messageOb := new(biapprove.BiApproveMessage)
  73. pars := make([]interface{}, 0)
  74. cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, biapprove.BiApproveMessageCols.ReceiveUserId, biapprove.BiApproveMessageCols.IsRead)
  75. pars = append(pars, sysUser.AdminId, 0)
  76. // 未读消息数
  77. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  78. if e != nil {
  79. br.Msg = "获取失败"
  80. br.ErrMsg = "获取看板消息列表总数失败, Err: " + e.Error()
  81. return
  82. }
  83. unReadBiNum = unreadTotal
  84. }
  85. // 汇总数
  86. num := unReadReportNum + unReadDataPermissionNum + unReadBiNum
  87. br.Data = num
  88. br.Ret = 200
  89. br.Success = true
  90. br.Msg = "获取成功"
  91. }