123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package controllers
- import (
- "eta/eta_api/models"
- "eta/eta_api/models/data_manage/data_manage_permission"
- edbmonitor "eta/eta_api/models/edb_monitor"
- "eta/eta_api/models/report_approve"
- "fmt"
- )
- // MessageController
- // @Description: 消息控制器
- type MessageController struct {
- BaseAuthController
- }
- // UnReadMessageNum
- // @Title 获取未读取的消息数量
- // @Description 获取未读取的消息数量
- // @Success 200 {object} data_manage_permission.MessageDetailListResp
- // @router /unread/num [get]
- func (c *MessageController) UnReadMessageNum() {
- br := new(models.BaseResponse).Init()
- defer func() {
- if br.ErrMsg == "" {
- br.IsSendEmail = false
- }
- c.Data["json"] = br
- c.ServeJSON()
- }()
- sysUser := c.SysUser
- if sysUser == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,SysUser Is Empty"
- br.Ret = 408
- return
- }
- var unReadReportNum, unReadDataPermissionNum, unReadEdbMonitorNum int
- // 获取报告审批消息
- {
- cond := fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.ReceiveUserId)
- pars := make([]interface{}, 0)
- pars = append(pars, sysUser.AdminId)
- messageOb := new(report_approve.ReportApproveMessage)
- // 未读消息数
- cond += fmt.Sprintf(` AND %s = ?`, report_approve.ReportApproveMessageCols.IsRead)
- pars = append(pars, 0)
- unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取审批消息列表总数失败, Err: " + e.Error()
- return
- }
- unReadReportNum = unreadTotal
- }
- // 获取资产消息
- {
- cond := fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.ReceiveUserId)
- pars := make([]interface{}, 0)
- pars = append(pars, sysUser.AdminId)
- messageOb := new(data_manage_permission.DataPermissionMessage)
- // 未读消息数
- cond += fmt.Sprintf(` AND %s = ?`, data_manage_permission.DataPermissionMessageCols.IsRead)
- pars = append(pars, 0)
- unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取资产消息列表总数失败, Err: " + e.Error()
- return
- }
- unReadDataPermissionNum = unreadTotal
- }
- // 获取预警消息
- {
- pars := make([]interface{}, 0)
- cond := ` AND admin_id = ? AND is_read = ?`
- pars = append(pars, sysUser.AdminId, 0)
- // 未读消息数
- messageOb := new(edbmonitor.EdbMonitorMessage)
- unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取资产消息列表总数失败, Err: " + e.Error()
- return
- }
- unReadEdbMonitorNum = unreadTotal
- }
- // 汇总数
- num := unReadReportNum + unReadDataPermissionNum + unReadEdbMonitorNum
- br.Data = num
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
|