smart_report.go 11 KB

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