approve_message.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package data_approve
  2. import (
  3. DataApprove "eta_gn/eta_api/models/data_manage/data_approve"
  4. "eta_gn/eta_api/models/data_manage/data_approve/response"
  5. "eta_gn/eta_api/utils"
  6. "fmt"
  7. "time"
  8. )
  9. func GetDataApproveMessage(adminId, dataType, startSize, pageSize int) (list []*response.DataApproveMessageItem, total, unread int, msg string, err error) {
  10. cond := fmt.Sprintf(` AND %s = ? AND %s = ? `, DataApprove.DataApproveMessageCols.ReceiveUserId, DataApprove.DataApproveMessageCols.DataType)
  11. pars := make([]interface{}, 0)
  12. pars = append(pars, adminId, dataType)
  13. order := fmt.Sprintf(`%s ASC, %s DESC`, DataApprove.DataApproveMessageCols.IsRead, DataApprove.DataApproveMessageCols.CreateTime)
  14. messageOb := new(DataApprove.DataApproveMessage)
  15. total, e := messageOb.GetCountByCondition(cond, pars)
  16. if e != nil {
  17. msg = "获取失败"
  18. err = fmt.Errorf("message.GetCountByCondition, Err: %s", e.Error())
  19. return
  20. }
  21. tmpList, e := messageOb.GetPageItemsByCondition(cond, pars, []string{}, order, startSize, pageSize)
  22. if e != nil {
  23. msg = "获取失败"
  24. err = fmt.Errorf("message.GetPageItemsByCondition, Err: %s", e.Error())
  25. return
  26. }
  27. for _, v := range tmpList {
  28. t := FormatDataApproveMessage2Item(v)
  29. list = append(list, t)
  30. }
  31. // 未读消息数
  32. cond += fmt.Sprintf(` AND %s = ?`, DataApprove.DataApproveMessageCols.IsRead)
  33. pars = append(pars, 0)
  34. unreadTotal, e := messageOb.GetCountByCondition(cond, pars)
  35. if e != nil {
  36. msg = "获取失败"
  37. err = fmt.Errorf("message.GetCountByCondition, Err: %s", e.Error())
  38. return
  39. }
  40. unread = unreadTotal
  41. return
  42. }
  43. func ReadBiMessage(msgId int, adminId int) (msg string, err error) {
  44. messageOb := new(DataApprove.DataApproveMessage)
  45. messageItem, e := messageOb.GetItemById(msgId)
  46. if e != nil {
  47. if utils.IsErrNoRow(e) {
  48. msg = "消息不存在, 请刷新页面"
  49. err = e
  50. return
  51. }
  52. msg = "获取失败"
  53. err = fmt.Errorf("message.GetItemById, Err: %s", e.Error())
  54. return
  55. }
  56. messageItem.IsRead = 1
  57. messageItem.ModifyTime = time.Now().Local()
  58. cols := []string{"IsRead", "ModifyTime"}
  59. if e = messageItem.Update(cols); e != nil {
  60. msg = "操作失败"
  61. err = fmt.Errorf("message.Update, Err: %s", e.Error())
  62. return
  63. }
  64. return
  65. }
  66. // FormatDataApproveMessage2Item 格式化报告审批消息
  67. func FormatDataApproveMessage2Item(origin *DataApprove.DataApproveMessage) (item *response.DataApproveMessageItem) {
  68. item = new(response.DataApproveMessageItem)
  69. if origin == nil {
  70. return
  71. }
  72. item.Id = origin.Id
  73. item.SendUserId = origin.SendUserId
  74. item.ReceiveUserId = origin.ReceiveUserId
  75. item.DataType = origin.DataType
  76. item.Content = origin.Content
  77. item.Remark = origin.Remark
  78. item.DataApproveId = origin.DataApproveId
  79. item.ApproveState = origin.ApproveState
  80. item.IsRead = origin.IsRead
  81. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  82. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  83. return
  84. }