123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package knowledge_approve
- import (
- "eta_gn/eta_api/models/knowledge_approve"
- "eta_gn/eta_api/models/knowledge_approve/response"
- "eta_gn/eta_api/utils"
- "fmt"
- "time"
- )
- func GetKnowledgeResourceApproveMessage(adminId, startSize, pageSize int) (list []*response.KnowledgeResourceApproveMessageItem, total, unread int, msg string, err error) {
- list = make([]*response.KnowledgeResourceApproveMessageItem, 0)
- cond := fmt.Sprintf(` AND %s = ?`, knowledge_approve.KnowledgeResourceApproveMessageCols.ReceiveUserId)
- pars := make([]interface{}, 0)
- pars = append(pars, adminId)
- order := fmt.Sprintf(`%s ASC, %s DESC`, knowledge_approve.KnowledgeResourceApproveMessageCols.IsRead, knowledge_approve.KnowledgeResourceApproveMessageCols.CreateTime)
- messageOb := new(knowledge_approve.KnowledgeResourceApproveMessage)
- total, e := messageOb.GetCountByCondition(cond, pars)
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("message.GetCountByCondition, Err: %s", e.Error())
- return
- }
- tmpList, e := messageOb.GetPageItemsByCondition(cond, pars, []string{}, order, startSize, pageSize)
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("message.GetPageItemsByCondition, Err: %s", e.Error())
- return
- }
- for _, v := range tmpList {
- t := FormatKnowledgeResourceApproveMessage2Item(v)
- list = append(list, t)
- }
- // 未读消息数
- cond += fmt.Sprintf(` AND %s = ?`, knowledge_approve.KnowledgeResourceApproveMessageCols.IsRead)
- pars = append(pars, 0)
- unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
- if e != nil {
- msg = "获取失败"
- err = fmt.Errorf("message.GetCountByCondition, Err: %s", e.Error())
- return
- }
- unread = unreadTotal
- return
- }
- func ReadKnowledgeMessage(msgId int, adminId int) (msg string, err error) {
- messageOb := new(knowledge_approve.KnowledgeResourceApproveMessage)
- messageItem, e := messageOb.GetItemById(msgId)
- if e != nil {
- if utils.IsErrNoRow(e) {
- msg = "消息不存在, 请刷新页面"
- err = e
- return
- }
- msg = "获取失败"
- err = fmt.Errorf("message.GetItemById, Err: %s", e.Error())
- return
- }
- messageItem.IsRead = 1
- messageItem.ModifyTime = time.Now().Local()
- cols := []string{"IsRead", "ModifyTime"}
- if e = messageItem.Update(cols); e != nil {
- msg = "操作失败"
- err = fmt.Errorf("message.Update, Err: %s", e.Error())
- return
- }
- return
- }
- // FormatKnowledgeResourceApproveMessage2Item 格式化报告审批消息
- func FormatKnowledgeResourceApproveMessage2Item(origin *knowledge_approve.KnowledgeResourceApproveMessage) (item *response.KnowledgeResourceApproveMessageItem) {
- item = new(response.KnowledgeResourceApproveMessageItem)
- if origin == nil {
- return
- }
- item.Id = origin.Id
- item.SendUserId = origin.SendUserId
- item.ReceiveUserId = origin.ReceiveUserId
- item.Content = origin.Content
- item.Remark = origin.Remark
- item.KnowledgeResourceApproveId = origin.KnowledgeResourceApproveId
- item.ApproveState = origin.ApproveState
- item.IsRead = origin.IsRead
- item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
- item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
- return
- }
|