message.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package controllers
  2. import (
  3. "eta/eta_api/models"
  4. "eta/eta_api/models/data_manage/data_manage_permission"
  5. "eta/eta_api/models/report_approve"
  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 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. messageOb := new(report_approve.ReportApproveMessage)
  41. // 未读消息数
  42. cond += fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.IsRead)
  43. pars = append(pars, 0)
  44. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  45. if e != nil {
  46. br.Msg = "获取失败"
  47. br.ErrMsg = "获取审批消息列表总数失败, Err: " + e.Error()
  48. return
  49. }
  50. unReadReportNum = unreadTotal
  51. }
  52. // 获取资产消息
  53. {
  54. cond := fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.ReceiveUserId)
  55. pars := make([]interface{}, 0)
  56. pars = append(pars, sysUser.AdminId)
  57. messageOb := new(data_manage_permission.DataPermissionMessage)
  58. // 未读消息数
  59. cond += fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.IsRead)
  60. pars = append(pars, 0)
  61. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  62. if e != nil {
  63. br.Msg = "获取失败"
  64. br.ErrMsg = "获取资产消息列表总数失败, Err: " + e.Error()
  65. return
  66. }
  67. unReadDataPermissionNum = unreadTotal
  68. }
  69. // 汇总数
  70. num := unReadReportNum + unReadDataPermissionNum
  71. br.Data = num
  72. br.Ret = 200
  73. br.Success = true
  74. br.Msg = "获取成功"
  75. }