wework_msg.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package day_new
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "time"
  6. )
  7. // 企业微信会话存档表
  8. type WeworkMsg struct {
  9. Id uint64 `orm:"column(id);pk;" description:"自增ID"`
  10. MsgId string `orm:"column(msg_id)" description:"企业微信消息id"` //企业微信消息id,消息的唯一标识,企业可以使用此字段进行消息去重
  11. Action string `orm:"column(action)" description:"消息动作"` //消息动作,目前有send(发送消息)/recall(撤回消息)/switch(切换企业日志)三种类型。String类型
  12. From string `orm:"column(from)" description:"消息发送方id"` //消息发送方id。同一企业内容为userid,非相同企业为external_userid。消息如果是机器人发出,也为external_userid。String类型
  13. ToList string `orm:"column(to_list)" description:"消息接收方列表"` //消息接收方列表,可能是多个,同一个企业内容为userid,非相同企业为external_userid。数组,内容为string类型
  14. RoomId string `orm:"column(room_id)" description:"群聊消息的群id"` //群聊消息的群id。如果是单聊则为空。String类型
  15. MsgTime int64 `orm:"column(msg_time)" description:"消息发送时间戳"` //消息发送时间戳,utc时间,ms单位。
  16. MsgType string `orm:"column(msg_type)" description:"消息类型"` //消息类型文本消息为:text。
  17. Content string `orm:"column(content)" description:"消息内容"` //消息内容
  18. ContentEn string `orm:"column(content_en)" description:"翻译后的英文内容"` //翻译后的英文内容
  19. ReportId int64 `orm:"column(report_id)" description:"英文研报ID"` //英文研报ID
  20. CreateTime time.Time `orm:"column(create_time)" description:"创建时间"` //创建时间
  21. IsAdd int8 `orm:"column(is_add)" description:"是否已加入到报告当中: 0未加入,1已加入 "` //是否已加入到报告当中: 0未加入,1已加入
  22. IsDelete int8 `orm:"column(is_delete)" description:"是否被删除:0未删除,1已删除"` //是否被删除:0未删除,1已删除
  23. ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"` //修改时间
  24. }
  25. type WeworkMsgListItem struct {
  26. MsgId string `description:"企业微信消息id"`
  27. Content string `description:"消息内容"`
  28. ContentEn string `description:"翻译后的英文内容"`
  29. CreateTime string `description:"创建时间"`
  30. IsAdd int8 `description:"是否已加入到报告当中: 0未加入,1已加入 "`
  31. IsDelete int8 `description:"是否被删除:0未删除,1已删除"`
  32. ModifyTime string `description:"修改时间"`
  33. MsgTime string `description:"消息发送时间"`
  34. FromName string `description:"消息发送者"`
  35. }
  36. // WeworkMsgListResp 分页列表响应体
  37. type WeworkMsgListResp struct {
  38. List []*WeworkMsgListItem
  39. Paging *paging.PagingItem `description:"分页数据"`
  40. LastUpdateTime string `description:"上次刷新时间"`
  41. }
  42. type DeleteWeworkMsgReq struct {
  43. MsgId string `description:"企业微信消息id"`
  44. }
  45. type EditWeworkMsgContentReq struct {
  46. MsgId string `description:"企业微信消息id"`
  47. ContentEn string `description:"英文翻译内容"`
  48. }
  49. // DayNewReportDefaultResp 获取上次报告的配置信息作为默认值
  50. type DayNewReportDefaultResp struct {
  51. ClassifyIdFirst int `description:"一级分类id"`
  52. ClassifyNameFirst string `description:"一级分类名称"`
  53. ClassifyIdSecond int `description:"二级分类id"`
  54. ClassifyNameSecond string `description:"二级分类名称"`
  55. ClassifyIdThird int `description:"三级分类ID"`
  56. ClassifyNameThird string `description:"三级分类名称"`
  57. Title string `description:"标题"`
  58. Abstract string `description:"摘要"`
  59. Author string `description:"作者"`
  60. Frequency string `description:"频度"`
  61. Overview string `description:"英文概述部分"`
  62. }
  63. // AddWeworkMsg 新增消息
  64. func AddWeworkMsg(item *WeworkMsg) (err error) {
  65. o := orm.NewOrm()
  66. _, err = o.Insert(&item)
  67. return
  68. }
  69. // AddWeworkMsgMulti 批量新增消息
  70. func AddWeworkMsgMulti(list []*WeworkMsg) (err error) {
  71. o := orm.NewOrm()
  72. _, err = o.InsertMulti(len(list), list)
  73. return
  74. }
  75. // GetWeworkMsgList 获取企业微信群消息列表
  76. func GetWeworkMsgList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*WeworkMsg, err error) {
  77. o := orm.NewOrm()
  78. sql := `SELECT * FROM wework_msg WHERE 1 = 1 `
  79. sql += condition
  80. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  81. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  82. return
  83. }
  84. sql += ` ORDER BY msg_time DESC, id DESC`
  85. sql += ` LIMIT ?,?`
  86. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  87. return
  88. }
  89. // GetWeworkMsgByCondition 获取企业微信群消息列表
  90. func GetWeworkMsgByCondition(condition string, pars []interface{}) (list []*WeworkMsg, err error) {
  91. o := orm.NewOrm()
  92. sql := `SELECT * FROM wework_msg WHERE 1 = 1 `
  93. sql += condition
  94. sql += ` ORDER BY id asc`
  95. _, err = o.Raw(sql, pars).QueryRows(&list)
  96. return
  97. }
  98. // GetWeworkMsgByConditionLimit 获取企业微信群消息列表
  99. func GetWeworkMsgByConditionLimit(condition string, pars []interface{}, limit int) (list []*WeworkMsg, err error) {
  100. o := orm.NewOrm()
  101. sql := `SELECT * FROM wework_msg WHERE 1 = 1 `
  102. sql += condition
  103. sql += ` ORDER BY id asc LIMIT 0, ?`
  104. _, err = o.Raw(sql, pars, limit).QueryRows(&list)
  105. return
  106. }
  107. func UpdateContentEnByMsgId(contentEn, msgId string) (err error) {
  108. o := orm.NewOrm()
  109. sql := `UPDATE wework_msg
  110. SET modify_time=NOW(), content_en = ?
  111. WHERE
  112. msg_id = ?`
  113. _, err = o.Raw(sql, contentEn, msgId).Exec()
  114. return
  115. }
  116. // DeleteWeworkMsgByMsgId 删除消息
  117. func DeleteWeworkMsgByMsgId(msgId string) (err error) {
  118. o := orm.NewOrm()
  119. sql := `UPDATE wework_msg
  120. SET modify_time=NOW(), is_delete = 1
  121. WHERE
  122. msg_id = ?`
  123. _, err = o.Raw(sql, msgId).Exec()
  124. return
  125. }
  126. // GetWeworkMsgByMsgId 根据消息Id查询
  127. func GetWeworkMsgByMsgId(msgId string) (item *WeworkMsg, err error) {
  128. o := orm.NewOrm()
  129. sql := `select * from wework_msg where msg_id = ?`
  130. err = o.Raw(sql, msgId).QueryRow(&item)
  131. return
  132. }
  133. type AddEnglishReportReq struct {
  134. ClassifyIdFirst int `description:"一级分类id"`
  135. ClassifyNameFirst string `description:"一级分类名称"`
  136. ClassifyIdSecond int `description:"二级分类id"`
  137. ClassifyNameSecond string `description:"二级分类名称"`
  138. Title string `description:"标题"`
  139. Abstract string `description:"摘要"`
  140. Author string `description:"作者"`
  141. Frequency string `description:"频度"`
  142. }
  143. // UpdateWeworkMsgIsAdd 更新消息状态为已加入报告
  144. func UpdateWeworkMsgIsAdd(msgIds string, reportId int64) (err error) {
  145. o := orm.NewOrm()
  146. sql := `UPDATE wework_msg
  147. SET modify_time=NOW(), is_add = 1, report_id= ?
  148. WHERE
  149. msg_id in (` + msgIds + `) and is_delete = 0 and is_add = 0`
  150. _, err = o.Raw(sql, reportId).Exec()
  151. return
  152. }
  153. // GetWeworkMsgReportIdByLimit 获取企业微信群消息列表
  154. func GetWeworkMsgReportIdByLimit(limit int) (list []*WeworkMsg, err error) {
  155. o := orm.NewOrm()
  156. sql := `SELECT * FROM wework_msg WHERE is_add = 1 and report_id > 0 GROUP BY report_id ORDER BY report_id desc LIMIT ?`
  157. _, err = o.Raw(sql, limit).QueryRows(&list)
  158. return
  159. }