smart_report.go 13 KB

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