smart_report.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. package smart_report
  2. import (
  3. "eta/eta_api/utils"
  4. "fmt"
  5. "github.com/beego/beego/v2/client/orm"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "html"
  8. "strings"
  9. "time"
  10. )
  11. const (
  12. SmartReportStateWaitPublish = 1
  13. SmartReportStatePublished = 2
  14. )
  15. // SmartReport 智能研报
  16. type SmartReport struct {
  17. SmartReportId int `orm:"column(smart_report_id);pk" description:"智能研报ID"`
  18. ReportCode string `description:"报告唯一编码"`
  19. ClassifyIdFirst int `description:"一级分类ID"`
  20. ClassifyNameFirst string `description:"一级分类名称"`
  21. ClassifyIdSecond int `description:"二级分类ID"`
  22. ClassifyNameSecond string `description:"二级分类名称"`
  23. AddType int `description:"新增方式:1-新增报告;2-继承报告"`
  24. Title string `description:"标题"`
  25. Abstract string `description:"摘要"`
  26. Author string `description:"作者"`
  27. Frequency string `description:"频度"`
  28. Stage int `description:"期数"`
  29. Content string `description:"内容"`
  30. ContentSub string `description:"内容前两个章节"`
  31. ContentStruct string `description:"内容组件"`
  32. VideoUrl string `description:"音频文件URL"`
  33. VideoName string `description:"音频文件名称"`
  34. VideoPlaySeconds float64 `description:"音频播放时长"`
  35. VideoSize string `description:"音频文件大小,单位M"`
  36. AdminId int `description:"创建者ID"`
  37. AdminRealName string `description:"创建者姓名"`
  38. State int `description:"发布状态:1-待发布;2-已发布"`
  39. LastModifyAdminId int `description:"最后更新人ID"`
  40. LastModifyAdminName string `description:"最后更新人姓名"`
  41. ContentModifyTime time.Time `description:"内容更新时间"`
  42. Pv int `description:"pv"`
  43. Uv int `description:"uv"`
  44. PublishTime time.Time `description:"发布时间"`
  45. PrePublishTime time.Time `description:"预发布时间"`
  46. PreMsgSend int `description:"定时发布后是否推送模版消息:0-否;1-是"`
  47. MsgIsSend int `description:"消息是否已发送:0-否;1-是"`
  48. MsgSendTime time.Time `description:"模版消息发送时间"`
  49. DetailImgUrl string `description:"报告详情长图地址"`
  50. DetailPdfUrl string `description:"报告详情PDF地址"`
  51. CreateTime time.Time `description:"创建时间"`
  52. ModifyTime time.Time `description:"修改时间"`
  53. HeadImg string `description:"报告头图地址"`
  54. EndImg string `description:"报告尾图地址"`
  55. CanvasColor string `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. o := orm.NewOrmUsingDB("rddp")
  65. id, err := o.Insert(m)
  66. if err != nil {
  67. return
  68. }
  69. m.SmartReportId = int(id)
  70. return
  71. }
  72. func (m *SmartReport) CreateMulti(items []*SmartReport) (err error) {
  73. if len(items) == 0 {
  74. return
  75. }
  76. o := orm.NewOrmUsingDB("rddp")
  77. _, err = o.InsertMulti(len(items), items)
  78. return
  79. }
  80. func (m *SmartReport) Update(cols []string) (err error) {
  81. o := orm.NewOrmUsingDB("rddp")
  82. _, err = o.Update(m, cols...)
  83. return
  84. }
  85. func (m *SmartReport) Del() (err error) {
  86. o := orm.NewOrmUsingDB("rddp")
  87. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  88. _, err = o.Raw(sql, m.SmartReportId).Exec()
  89. return
  90. }
  91. func (m *SmartReport) MultiDel(menuIds []int) (err error) {
  92. if len(menuIds) == 0 {
  93. return
  94. }
  95. o := orm.NewOrmUsingDB("rddp")
  96. sql := fmt.Sprintf(`DELETE FROM %s WHERE %s IN (%s)`, m.TableName(), m.PrimaryId(), utils.GetOrmInReplace(len(menuIds)))
  97. _, err = o.Raw(sql, menuIds).Exec()
  98. return
  99. }
  100. func (m *SmartReport) GetItemById(id int) (item *SmartReport, err error) {
  101. o := orm.NewOrmUsingDB("rddp")
  102. sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
  103. err = o.Raw(sql, id).QueryRow(&item)
  104. return
  105. }
  106. func (m *SmartReport) GetItemByCondition(condition string, pars []interface{}, orderRule string) (item *SmartReport, err error) {
  107. o := orm.NewOrmUsingDB("rddp")
  108. order := ``
  109. if orderRule != "" {
  110. order = ` ORDER BY ` + orderRule
  111. }
  112. sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s %s LIMIT 1`, m.TableName(), condition, order)
  113. err = o.Raw(sql, pars).QueryRow(&item)
  114. return
  115. }
  116. func (m *SmartReport) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
  117. o := orm.NewOrmUsingDB("rddp")
  118. sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
  119. err = o.Raw(sql, pars).QueryRow(&count)
  120. return
  121. }
  122. func (m *SmartReport) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*SmartReport, err error) {
  123. o := orm.NewOrmUsingDB("rddp")
  124. fields := strings.Join(fieldArr, ",")
  125. if len(fieldArr) == 0 {
  126. fields = `*`
  127. }
  128. order := `ORDER BY create_time DESC`
  129. if orderRule != "" {
  130. order = ` ORDER BY ` + orderRule
  131. }
  132. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
  133. _, err = o.Raw(sql, pars).QueryRows(&items)
  134. return
  135. }
  136. func (m *SmartReport) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*SmartReport, err error) {
  137. o := orm.NewOrmUsingDB("rddp")
  138. fields := strings.Join(fieldArr, ",")
  139. if len(fieldArr) == 0 {
  140. fields = `*`
  141. }
  142. order := `ORDER BY FIELD(state,3,1,2,4), create_time DESC`
  143. if orderRule != "" {
  144. order = ` ORDER BY ` + orderRule
  145. }
  146. sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
  147. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  148. return
  149. }
  150. func (m *SmartReport) GetMaxStageByClassifyId(classifyId int) (stage int, err error) {
  151. o := orm.NewOrmUsingDB("rddp")
  152. sql := fmt.Sprintf(`SELECT MAX(stage) AS max_stage FROM %s WHERE classify_id_second = ?`, m.TableName())
  153. err = o.Raw(sql, classifyId).QueryRow(&stage)
  154. return
  155. }
  156. // SmartReportItem 智能研报信息
  157. type SmartReportItem struct {
  158. SmartReportId int `description:"智能研报ID"`
  159. ReportCode string `description:"报告唯一编码"`
  160. ClassifyIdFirst int `description:"一级分类ID"`
  161. ClassifyNameFirst string `description:"一级分类名称"`
  162. ClassifyIdSecond int `description:"二级分类ID"`
  163. ClassifyNameSecond string `description:"二级分类名称"`
  164. AddType int `description:"新增方式:1-新增报告;2-继承报告"`
  165. Title string `description:"标题"`
  166. Abstract string `description:"摘要"`
  167. Author string `description:"作者"`
  168. Frequency string `description:"频度"`
  169. Stage int `description:"期数"`
  170. Content string `description:"内容"`
  171. ContentSub string `description:"内容前两个章节"`
  172. ContentStruct string `description:"内容组件"`
  173. VideoUrl string `description:"音频文件URL"`
  174. VideoName string `description:"音频文件名称"`
  175. VideoPlaySeconds float64 `description:"音频播放时长"`
  176. VideoSize string `description:"音频文件大小,单位M"`
  177. AdminId int `description:"创建者姓名"`
  178. AdminRealName string `description:"创建者姓名"`
  179. LastModifyAdminId int `description:"最后更新人ID"`
  180. LastModifyAdminName string `description:"最后更新人姓名"`
  181. ContentModifyTime string `description:"内容更新时间"`
  182. Pv int `description:"pv"`
  183. Uv int `description:"uv"`
  184. State int `description:"发布状态:1-待发布;2-已发布"`
  185. PublishTime string `description:"发布时间"`
  186. PrePublishTime string `description:"预发布时间"`
  187. MsgIsSend int `description:"消息是否已发送:0-否;1-是"`
  188. MsgSendTime string `description:"模版消息发送时间"`
  189. DetailImgUrl string `description:"报告详情长图地址"`
  190. DetailPdfUrl string `description:"报告详情PDF地址"`
  191. CreateTime string `description:"创建时间"`
  192. ModifyTime string `description:"修改时间"`
  193. CanEdit bool `description:"是否可编辑"`
  194. Editor string `description:"当前编辑人"`
  195. }
  196. // FormatSmartReport2Item 格式化智能研报数据格式
  197. func FormatSmartReport2Item(origin *SmartReport) (item *SmartReportItem) {
  198. item = new(SmartReportItem)
  199. if origin == nil {
  200. return
  201. }
  202. item.SmartReportId = origin.SmartReportId
  203. item.ReportCode = origin.ReportCode
  204. item.ClassifyIdFirst = origin.ClassifyIdFirst
  205. item.ClassifyNameFirst = origin.ClassifyNameFirst
  206. item.ClassifyIdSecond = origin.ClassifyIdSecond
  207. item.ClassifyNameSecond = origin.ClassifyNameSecond
  208. item.AddType = origin.AddType
  209. item.Title = origin.Title
  210. item.Abstract = origin.Abstract
  211. item.Author = origin.Author
  212. item.Frequency = origin.Frequency
  213. item.Stage = origin.Stage
  214. item.Content = html.UnescapeString(origin.Content)
  215. item.ContentSub = html.UnescapeString(origin.ContentSub)
  216. item.ContentStruct = html.UnescapeString(origin.ContentStruct)
  217. item.VideoUrl = origin.VideoUrl
  218. item.VideoName = origin.VideoName
  219. item.VideoPlaySeconds = origin.VideoPlaySeconds
  220. item.VideoSize = origin.VideoSize
  221. item.AdminId = origin.AdminId
  222. item.AdminRealName = origin.AdminRealName
  223. item.LastModifyAdminId = origin.LastModifyAdminId
  224. item.LastModifyAdminName = origin.LastModifyAdminName
  225. item.ContentModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ContentModifyTime)
  226. item.Pv = origin.Pv
  227. item.Uv = origin.Uv
  228. item.State = origin.State
  229. item.PublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PublishTime)
  230. item.PrePublishTime = utils.TimeTransferString(utils.FormatDateTime, origin.PrePublishTime)
  231. item.MsgIsSend = origin.MsgIsSend
  232. item.MsgSendTime = utils.TimeTransferString(utils.FormatDateTime, origin.MsgSendTime)
  233. item.DetailImgUrl = origin.DetailImgUrl
  234. item.DetailPdfUrl = origin.DetailPdfUrl
  235. item.CreateTime = utils.TimeTransferString(utils.FormatDateTime, origin.CreateTime)
  236. item.ModifyTime = utils.TimeTransferString(utils.FormatDateTime, origin.ModifyTime)
  237. return
  238. }
  239. // SmartReportAddReq 新增智能研报请求体
  240. type SmartReportAddReq struct {
  241. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  242. ClassifyIdFirst int `description:"一级分类ID"`
  243. ClassifyNameFirst string `description:"一级分类名称"`
  244. ClassifyIdSecond int `description:"二级分类ID"`
  245. ClassifyNameSecond string `description:"二级分类名称"`
  246. Title string `description:"标题"`
  247. Abstract string `description:"摘要"`
  248. Author string `description:"作者"`
  249. Frequency string `description:"频度"`
  250. }
  251. // SmartReportEditReq 编辑智能研报请求体
  252. type SmartReportEditReq struct {
  253. SmartReportAddReq
  254. SmartReportId int `description:"智能研报ID"`
  255. Content string `description:"内容"`
  256. ContentStruct string `description:"内容结构"`
  257. }
  258. // SmartReportRemoveReq 删除智能研报请求体
  259. type SmartReportRemoveReq struct {
  260. SmartReportId int `description:"智能研报ID"`
  261. }
  262. // SmartReportPublishReq 发布智能研报请求体
  263. type SmartReportPublishReq struct {
  264. SmartReportId int `description:"智能研报ID"`
  265. PublishState int `description:"1-取消发布; 2-发布"`
  266. }
  267. // SmartReportPrePublishReq 预发布智能研报请求体
  268. type SmartReportPrePublishReq struct {
  269. SmartReportId int `description:"智能研报ID"`
  270. PrePublishTime string `description:"预发布时间"`
  271. PreMsgSend int `description:"定时发布成功后是否立即推送模版消息:0否,1是"`
  272. }
  273. // SmartReportSaveContentReq 保存草稿请求体
  274. type SmartReportSaveContentReq struct {
  275. SmartReportId int `description:"智能研报ID"`
  276. Content string `description:"内容"`
  277. ContentStruct string `description:"内容结构"`
  278. NoChange int `description:"内容是否未改变:1:内容未改变"`
  279. }
  280. // SmartReportSaveContentResp 保存草稿响应体
  281. type SmartReportSaveContentResp struct {
  282. SmartReportId int `description:"智能研报ID"`
  283. }
  284. // SmartReportSendMsgReq 消息推送请求体
  285. type SmartReportSendMsgReq struct {
  286. SmartReportId int `description:"智能研报ID"`
  287. }
  288. // SmartReportMarkEditReq 标记编辑英文研报的请求数据
  289. type SmartReportMarkEditReq struct {
  290. SmartReportId int `description:"智能研报ID"`
  291. Status int `description:"标记状态: 1-编辑中; 2-编辑完成"`
  292. }
  293. // SmartReportListResp 智能研报
  294. type SmartReportListResp struct {
  295. List []*SmartReportItem
  296. Paging *paging.PagingItem `description:"分页数据"`
  297. }
  298. // ElasticSmartReport 智能研报es
  299. type ElasticSmartReport struct {
  300. SmartReportId int `description:"智能研报ID"`
  301. Title string `description:"标题"`
  302. Abstract string `description:"摘要"`
  303. BodyContent string `description:"内容"`
  304. PublishTime string `description:"发布时间"`
  305. PublishState int `description:"发布状态 1-未发布 2-已发布"`
  306. Author string `description:"作者"`
  307. ClassifyIdFirst int `description:"一级分类ID"`
  308. ClassifyNameFirst string `description:"一级分类名称"`
  309. ClassifyIdSecond int `description:"二级分类ID"`
  310. ClassifyNameSecond string `description:"二级分类名称"`
  311. StageStr string `description:"报告期数"`
  312. Frequency string `description:"频度"`
  313. }
  314. // Report2ImgQueueReq 报告详情生成长图队列请求体
  315. type Report2ImgQueueReq struct {
  316. ReportType int `description:"报告类型: 1-研报; 2-智能研报"`
  317. ReportCode string `description:"报告唯一编码"`
  318. }