message.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. type MessageController struct {
  10. BaseAuthController
  11. }
  12. // @router /unread/num [get]
  13. func (c *MessageController) UnReadMessageNum() {
  14. br := new(models.BaseResponse).Init()
  15. defer func() {
  16. if br.ErrMsg == "" {
  17. br.IsSendEmail = false
  18. }
  19. c.Data["json"] = br
  20. c.ServeJSON()
  21. }()
  22. sysUser := c.SysUser
  23. if sysUser == nil {
  24. br.Msg = "请登录"
  25. br.ErrMsg = "请登录,SysUser Is Empty"
  26. br.Ret = 408
  27. return
  28. }
  29. var unReadReportNum, unReadDataPermissionNum, unReadBiNum int
  30. {
  31. cond := fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.ReceiveUserId)
  32. pars := make([]interface{}, 0)
  33. pars = append(pars, sysUser.AdminId)
  34. messageOb := new(report_approve.ReportApproveMessage)
  35. cond += fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.IsRead)
  36. pars = append(pars, 0)
  37. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  38. if e != nil {
  39. br.Msg = "获取失败"
  40. br.ErrMsg = "获取审批消息列表总数失败, Err: " + e.Error()
  41. return
  42. }
  43. unReadReportNum = unreadTotal
  44. }
  45. {
  46. cond := fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.ReceiveUserId)
  47. pars := make([]interface{}, 0)
  48. pars = append(pars, sysUser.AdminId)
  49. messageOb := new(data_manage_permission.DataPermissionMessage)
  50. cond += fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.IsRead)
  51. pars = append(pars, 0)
  52. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  53. if e != nil {
  54. br.Msg = "获取失败"
  55. br.ErrMsg = "获取资产消息列表总数失败, Err: " + e.Error()
  56. return
  57. }
  58. unReadDataPermissionNum = unreadTotal
  59. }
  60. {
  61. messageOb := new(biapprove.BiApproveMessage)
  62. pars := make([]interface{}, 0)
  63. cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, biapprove.BiApproveMessageCols.ReceiveUserId, biapprove.BiApproveMessageCols.IsRead)
  64. pars = append(pars, sysUser.AdminId, 0)
  65. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  66. if e != nil {
  67. br.Msg = "获取失败"
  68. br.ErrMsg = "获取看板消息列表总数失败, Err: " + e.Error()
  69. return
  70. }
  71. unReadBiNum = unreadTotal
  72. }
  73. num := unReadReportNum + unReadDataPermissionNum + unReadBiNum
  74. br.Data = num
  75. br.Ret = 200
  76. br.Success = true
  77. br.Msg = "获取成功"
  78. }