123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package data_approve
- import (
- DataApprove "eta_gn/eta_api/models/data_manage/data_approve"
- "eta_gn/eta_api/models/data_manage/data_approve/response"
- "eta_gn/eta_api/utils"
- "fmt"
- "time"
- )
- func GetDataApproveMessage(adminId, dataType, startSize, pageSize int) (list []*response.DataApproveMessageItem, total, unread int, msg string, err error) {
- cond := fmt.Sprintf(` AND %s = ? AND %s = ? `, DataApprove.DataApproveMessageCols.ReceiveUserId, DataApprove.DataApproveMessageCols.DataType)
- pars := make([]interface{}, 0)
- pars = append(pars, adminId, dataType)
- order := fmt.Sprintf(`%s ASC, %s DESC`, DataApprove.DataApproveMessageCols.IsRead, DataApprove.DataApproveMessageCols.CreateTime)
- messageOb := new(DataApprove.DataApproveMessage)
- 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 := FormatDataApproveMessage2Item(v)
- list = append(list, t)
- }
- // 未读消息数
- cond += fmt.Sprintf(` AND %s = ?`, DataApprove.DataApproveMessageCols.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 ReadBiMessage(msgId int, adminId int) (msg string, err error) {
- messageOb := new(DataApprove.DataApproveMessage)
- 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
- }
- // FormatDataApproveMessage2Item 格式化报告审批消息
- func FormatDataApproveMessage2Item(origin *DataApprove.DataApproveMessage) (item *response.DataApproveMessageItem) {
- item = new(response.DataApproveMessageItem)
- if origin == nil {
- return
- }
- item.Id = origin.Id
- item.SendUserId = origin.SendUserId
- item.ReceiveUserId = origin.ReceiveUserId
- item.DataType = origin.DataType
- item.Content = origin.Content
- item.Remark = origin.Remark
- item.DataApproveId = origin.DataApproveId
- 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
- }
|