knowledge_approve_message.go 3.1 KB

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