smart_report.go 14 KB

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