smart_report.go 14 KB

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