123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- package controllers
- import (
- "eta_gn/eta_api/models"
- biapprove "eta_gn/eta_api/models/bi_approve"
- "eta_gn/eta_api/models/data_manage/data_manage_permission"
- "eta_gn/eta_api/models/knowledge_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, unReadBiNum, unReadKnowledgeNum 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
- //}
- // 报告通知消息
- {
- // 未读消息数
- messageOb := new(models.ReportMessage)
- cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, models.ReportMessageCols.ReceiveUserId, models.ReportMessageCols.IsRead)
- pars := make([]interface{}, 0)
- pars = append(pars, sysUser.AdminId, 0)
- total, e := messageOb.GetCountByCondition(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告通知列表总数失败, Err: " + e.Error()
- return
- }
- unReadReportNum = total
- }
- // 获取资产消息
- {
- 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
- }
- // 获得看板消息
- {
- messageOb := new(biapprove.BiApproveMessage)
- pars := make([]interface{}, 0)
- cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, biapprove.BiApproveMessageCols.ReceiveUserId, biapprove.BiApproveMessageCols.IsRead)
- pars = append(pars, sysUser.AdminId, 0)
- // 未读消息数
- unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取看板消息列表总数失败, Err: " + e.Error()
- return
- }
- unReadBiNum = unreadTotal
- }
- // 观点库审批
- {
- messageOb := new(knowledge_approve.KnowledgeResourceApproveMessage)
- pars := make([]interface{}, 0)
- cond := fmt.Sprintf(` AND %s = ? AND %s = ?`, knowledge_approve.KnowledgeResourceApproveMessageCols.ReceiveUserId, knowledge_approve.KnowledgeResourceApproveMessageCols.IsRead)
- pars = append(pars, sysUser.AdminId, 0)
- // 未读消息数
- unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取看板消息列表总数失败, Err: " + e.Error()
- return
- }
- unReadKnowledgeNum = unreadTotal
- }
- // 汇总数
- num := unReadReportNum + unReadDataPermissionNum + unReadBiNum + unReadKnowledgeNum
- br.Data = num
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- }
|