wework_msg.go 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. Title string `description:"标题"`
  56. Abstract string `description:"摘要"`
  57. Author string `description:"作者"`
  58. Frequency string `description:"频度"`
  59. Overview string `description:"英文概述部分"`
  60. }
  61. // AddWeworkMsg 新增消息
  62. func AddWeworkMsg(item *WeworkMsg) (err error) {
  63. o := orm.NewOrm()
  64. _, err = o.Insert(&item)
  65. return
  66. }
  67. // AddWeworkMsgMulti 批量新增消息
  68. func AddWeworkMsgMulti(list []*WeworkMsg) (err error) {
  69. o := orm.NewOrm()
  70. _, err = o.InsertMulti(len(list), list)
  71. return
  72. }
  73. // GetWeworkMsgList 获取企业微信群消息列表
  74. func GetWeworkMsgList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*WeworkMsg, err error) {
  75. o := orm.NewOrm()
  76. sql := `SELECT * FROM wework_msg WHERE 1 = 1 `
  77. sql += condition
  78. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  79. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  80. return
  81. }
  82. sql += ` ORDER BY msg_time DESC, id DESC`
  83. sql += ` LIMIT ?,?`
  84. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  85. return
  86. }
  87. // GetWeworkMsgByCondition 获取企业微信群消息列表
  88. func GetWeworkMsgByCondition(condition string, pars []interface{}) (list []*WeworkMsg, err error) {
  89. o := orm.NewOrm()
  90. sql := `SELECT * FROM wework_msg WHERE 1 = 1 `
  91. sql += condition
  92. sql += ` ORDER BY id asc`
  93. _, err = o.Raw(sql, pars).QueryRows(&list)
  94. return
  95. }
  96. // GetWeworkMsgByConditionLimit 获取企业微信群消息列表
  97. func GetWeworkMsgByConditionLimit(condition string, pars []interface{}, limit int) (list []*WeworkMsg, err error) {
  98. o := orm.NewOrm()
  99. sql := `SELECT * FROM wework_msg WHERE 1 = 1 `
  100. sql += condition
  101. sql += ` ORDER BY id asc LIMIT 0, ?`
  102. _, err = o.Raw(sql, pars, limit).QueryRows(&list)
  103. return
  104. }
  105. func UpdateContentEnByMsgId(contentEn, msgId string) (err error) {
  106. o := orm.NewOrm()
  107. sql := `UPDATE wework_msg
  108. SET modify_time=NOW(), content_en = ?
  109. WHERE
  110. msg_id = ?`
  111. _, err = o.Raw(sql, contentEn, msgId).Exec()
  112. return
  113. }
  114. // DeleteWeworkMsgByMsgId 删除消息
  115. func DeleteWeworkMsgByMsgId(msgId string) (err error) {
  116. o := orm.NewOrm()
  117. sql := `UPDATE wework_msg
  118. SET modify_time=NOW(), is_delete = 1
  119. WHERE
  120. msg_id = ?`
  121. _, err = o.Raw(sql, msgId).Exec()
  122. return
  123. }
  124. // GetWeworkMsgByMsgId 根据消息Id查询
  125. func GetWeworkMsgByMsgId(msgId string) (item *WeworkMsg, err error) {
  126. o := orm.NewOrm()
  127. sql := `select * from wework_msg where msg_id = ?`
  128. err = o.Raw(sql, msgId).QueryRow(&item)
  129. return
  130. }
  131. type AddEnglishReportReq struct {
  132. ClassifyIdFirst int `description:"一级分类id"`
  133. ClassifyNameFirst string `description:"一级分类名称"`
  134. ClassifyIdSecond int `description:"二级分类id"`
  135. ClassifyNameSecond string `description:"二级分类名称"`
  136. Title string `description:"标题"`
  137. Abstract string `description:"摘要"`
  138. Author string `description:"作者"`
  139. Frequency string `description:"频度"`
  140. }
  141. // UpdateWeworkMsgIsAdd 更新消息状态为已加入报告
  142. func UpdateWeworkMsgIsAdd(msgIds string, reportId int64) (err error) {
  143. o := orm.NewOrm()
  144. sql := `UPDATE wework_msg
  145. SET modify_time=NOW(), is_add = 1, report_id= ?
  146. WHERE
  147. msg_id in (`+msgIds+`) and is_delete = 0 and is_add = 0`
  148. _, err = o.Raw(sql, reportId).Exec()
  149. return
  150. }
  151. // GetWeworkMsgReportIdByLimit 获取企业微信群消息列表
  152. func GetWeworkMsgReportIdByLimit(limit int) (list []*WeworkMsg, err error) {
  153. o := orm.NewOrm()
  154. sql := `SELECT * FROM wework_msg WHERE is_add = 1 and report_id > 0 GROUP BY report_id ORDER BY report_id desc LIMIT ?`
  155. _, err = o.Raw(sql, limit).QueryRows(&list)
  156. return
  157. }