smart_report.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. package models
  2. import (
  3. "eta/eta_report/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "html"
  7. "time"
  8. )
  9. // SmartReport 智能研报
  10. type SmartReport struct {
  11. SmartReportId int `orm:"column(smart_report_id);pk" description:"智能研报ID"`
  12. ReportCode string `description:"报告唯一编码"`
  13. ClassifyIdFirst int `description:"一级分类ID"`
  14. ClassifyNameFirst string `description:"一级分类名称"`
  15. ClassifyIdSecond int `description:"二级分类ID"`
  16. ClassifyNameSecond string `description:"二级分类名称"`
  17. AddType int `description:"新增方式:1-新增报告;2-继承报告"`
  18. Title string `description:"标题"`
  19. Abstract string `description:"摘要"`
  20. Author string `description:"作者"`
  21. Frequency string `description:"频度"`
  22. Stage int `description:"期数"`
  23. Content string `description:"内容"`
  24. ContentSub string `description:"内容前两个章节"`
  25. ContentStruct string `description:"内容组件"`
  26. VideoUrl string `description:"音频文件URL"`
  27. VideoName string `description:"音频文件名称"`
  28. VideoPlaySeconds float64 `description:"音频播放时长"`
  29. VideoSize string `description:"音频文件大小,单位M"`
  30. AdminId int `description:"创建者ID"`
  31. AdminRealName string `description:"创建者姓名"`
  32. State int `description:"发布状态:1-待发布;2-已发布"`
  33. LastModifyAdminId int `description:"最后更新人ID"`
  34. LastModifyAdminName string `description:"最后更新人姓名"`
  35. ContentModifyTime time.Time `description:"内容更新时间"`
  36. Pv int `description:"pv"`
  37. Uv int `description:"uv"`
  38. PublishTime time.Time `description:"发布时间"`
  39. PrePublishTime time.Time `description:"预发布时间"`
  40. PreMsgSend int `description:"定时发布后是否推送模版消息:0-否;1-是"`
  41. MsgIsSend int `description:"消息是否已发送:0-否;1-是"`
  42. MsgSendTime time.Time `description:"模版消息发送时间"`
  43. DetailImgUrl string `description:"报告详情长图地址"`
  44. DetailPdfUrl string `description:"报告详情PDF地址"`
  45. CreateTime time.Time `description:"创建时间"`
  46. ModifyTime time.Time `description:"修改时间"`
  47. HeadImg string `description:"报告头图地址"`
  48. EndImg string `description:"报告尾图地址"`
  49. CanvasColor string `description:"画布颜色"`
  50. NeedSplice int `description:"0-不需要 1-需要"`
  51. HeadResourceId int `description:"版头资源ID"`
  52. EndResourceId int `description:"版尾资源ID"`
  53. HeadStyle string `description:"版头样式"`
  54. EndStyle string `description:"版尾样式"`
  55. }
  56. func (m *SmartReport) TableName() string {
  57. return "smart_report"
  58. }
  59. func (m *SmartReport) PrimaryId() string {
  60. return "smart_report_id"
  61. }
  62. func (m *SmartReport) Create() (err error) {
  63. o := orm.NewOrm()
  64. id, err := o.Insert(m)
  65. if err != nil {
  66. return
  67. }
  68. m.SmartReportId = int(id)
  69. return
  70. }
  71. func (m *SmartReport) Update(cols []string) (err error) {
  72. o := orm.NewOrm()
  73. _, err = o.Update(m, cols...)
  74. return
  75. }
  76. func (m *SmartReport) GetItemById(id int) (item *SmartReport, err error) {
  77. o := orm.NewOrm()
  78. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  79. err = o.Raw(sql, id).QueryRow(&item)
  80. return
  81. }
  82. func (m *SmartReport) GetItemByCondition(condition string, pars []interface{}) (item *SmartReport, err error) {
  83. o := orm.NewOrm()
  84. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
  85. err = o.Raw(sql, pars).QueryRow(&item)
  86. return
  87. }
  88. // SmartReportItem 智能研报信息
  89. type SmartReportItem struct {
  90. SmartReportId int `description:"智能研报ID"`
  91. ReportCode string `description:"报告唯一编码"`
  92. ClassifyIdFirst int `description:"一级分类ID"`
  93. ClassifyNameFirst string `description:"一级分类名称"`
  94. ClassifyIdSecond int `description:"二级分类ID"`
  95. ClassifyNameSecond string `description:"二级分类名称"`
  96. AddType int `description:"新增方式:1-新增报告;2-继承报告"`
  97. Title string `description:"标题"`
  98. Abstract string `description:"摘要"`
  99. Author string `description:"作者"`
  100. Frequency string `description:"频度"`
  101. Stage int `description:"期数"`
  102. Content string `description:"内容"`
  103. ContentSub string `description:"内容前两个章节"`
  104. ContentStruct string `description:"内容组件"`
  105. VideoUrl string `description:"音频文件URL"`
  106. VideoName string `description:"音频文件名称"`
  107. VideoPlaySeconds float64 `description:"音频播放时长"`
  108. VideoSize string `description:"音频文件大小,单位M"`
  109. AdminId int `description:"创建者姓名"`
  110. AdminRealName string `description:"创建者姓名"`
  111. Pv int `description:"pv"`
  112. Uv int `description:"uv"`
  113. State int `description:"发布状态:1-待发布;2-已发布"`
  114. PublishTime string `description:"发布时间"`
  115. PrePublishTime string `description:"预发布时间"`
  116. MsgIsSend int `description:"消息是否已发送:0-否;1-是"`
  117. DetailImgUrl string `description:"报告详情长图地址"`
  118. DetailPdfUrl string `description:"报告详情PDF地址"`
  119. CreateTime string `description:"创建时间"`
  120. ModifyTime string `description:"修改时间"`
  121. CanEdit bool `description:"是否可编辑"`
  122. Editor string `description:"当前编辑人"`
  123. HeadImg string `description:"报告头图地址"`
  124. EndImg string `description:"报告尾图地址"`
  125. CanvasColor string `description:"画布颜色"`
  126. NeedSplice int `description:"0-不需要 1-需要"`
  127. HeadResourceId int `description:"版头资源ID"`
  128. EndResourceId int `description:"版尾资源ID"`
  129. HeadStyle string `description:"版头样式"`
  130. EndStyle string `description:"版尾样式"`
  131. }
  132. // FormatSmartReport2Item 格式化智能研报数据格式
  133. func FormatSmartReport2Item(origin *SmartReport) (item *SmartReportItem) {
  134. item = new(SmartReportItem)
  135. if origin == nil {
  136. return
  137. }
  138. item.SmartReportId = origin.SmartReportId
  139. item.ReportCode = origin.ReportCode
  140. item.ClassifyIdFirst = origin.ClassifyIdFirst
  141. item.ClassifyNameFirst = origin.ClassifyNameFirst
  142. item.ClassifyIdSecond = origin.ClassifyIdSecond
  143. item.ClassifyNameSecond = origin.ClassifyNameSecond
  144. item.AddType = origin.AddType
  145. item.Title = origin.Title
  146. item.Abstract = origin.Abstract
  147. item.Author = origin.Author
  148. item.Frequency = origin.Frequency
  149. item.Stage = origin.Stage
  150. item.Content = html.UnescapeString(origin.Content)
  151. item.ContentSub = html.UnescapeString(origin.ContentSub)
  152. item.ContentStruct = html.UnescapeString(origin.ContentStruct)
  153. item.VideoUrl = origin.VideoUrl
  154. item.VideoName = origin.VideoName
  155. item.VideoPlaySeconds = origin.VideoPlaySeconds
  156. item.VideoSize = origin.VideoSize
  157. item.AdminId = origin.AdminId
  158. item.AdminRealName = origin.AdminRealName
  159. item.Pv = origin.Pv
  160. item.Uv = origin.Uv
  161. item.State = origin.State
  162. item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime)
  163. item.PrePublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PrePublishTime)
  164. item.MsgIsSend = origin.MsgIsSend
  165. item.DetailImgUrl = origin.DetailImgUrl
  166. item.DetailPdfUrl = origin.DetailPdfUrl
  167. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  168. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  169. item.CanvasColor = origin.CanvasColor
  170. item.HeadImg = origin.HeadImg
  171. item.EndImg = origin.EndImg
  172. item.NeedSplice = origin.NeedSplice
  173. item.HeadResourceId = origin.HeadResourceId
  174. item.EndResourceId = origin.EndResourceId
  175. return
  176. }
  177. // SmartReportShareDetailResp 智能研报分享详情响应体
  178. type SmartReportShareDetailResp struct {
  179. Report *SmartReportItem `description:"智能研报"`
  180. Disclaimer string `description:"免责声明"`
  181. H5ShareName string `description:"研报分享抬头"`
  182. H5ReportShareImg string `description:"研报分享图片"`
  183. Hz int
  184. }
  185. // UpdateSmartReportPv 研报pv自增
  186. func UpdateSmartReportPv(reportId int) (err error) {
  187. o := orm.NewOrm()
  188. sql := `UPDATE smart_report SET pv = pv + 1 WHERE smart_report_id = ?`
  189. _, err = o.Raw(sql, reportId).Exec()
  190. return
  191. }
  192. type SmartReportResource struct {
  193. ResourceId int `orm:"column(resource_id);pk" description:"智能研报资源ID"`
  194. ImgUrl string // 图片链接
  195. Style string // 版图样式
  196. ImgName string // 图片名称
  197. Type int // 类型 1-版头 2-版尾
  198. CreateTime time.Time // 创建时间
  199. }
  200. func GetResourceItemById(id int) (item *SmartReportResource, err error) {
  201. o := orm.NewOrm()
  202. sql := fmt.Sprintf(`SELECT * FROM smart_report_resource WHERE resource_id = ? LIMIT 1`)
  203. err = o.Raw(sql, id).QueryRow(&item)
  204. return
  205. }
  206. type SmartReportWechatShareDetailResp struct {
  207. H5ShareName string `description:"研报分享抬头"`
  208. H5ShareTitle string `description:"研报分享抬头"`
  209. H5ReportShareImg string `description:"研报分享图片"`
  210. }