report_chapter.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/models/report"
  5. "eta_gn/eta_api/utils"
  6. "time"
  7. )
  8. type ReportChapter struct {
  9. ReportChapterId int `gorm:"column:report_chapter_id;primaryKey;autoIncrement:true;not null" description:"报告章节ID"`
  10. ReportId int `gorm:"column:report_id" description:"报告ID"`
  11. ReportType string `gorm:"column:report_type" description:"报告类型 day-晨报 week-周报"`
  12. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  13. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  14. TypeId int `gorm:"column:type_id" description:"品种ID"`
  15. TypeName string `gorm:"column:type_name" description:"品种名称"`
  16. Title string `gorm:"column:title" description:"标题"`
  17. Abstract string `gorm:"column:abstract" description:"摘要"`
  18. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  19. Author string `gorm:"column:author" description:"作者"`
  20. Content string `gorm:"column:content" description:"内容"`
  21. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  22. Stage int `gorm:"column:stage" description:"期数"`
  23. Trend string `gorm:"column:trend" description:"趋势观点"`
  24. Sort int `gorm:"column:sort" description:"排序: 数值越小越靠前"`
  25. IsEdit int `gorm:"column:is_edit" description:"是否已编辑 0-待编辑 1-已编辑"`
  26. PublishState int `gorm:"column:publish_state" description:"发布状态 1-待发布,2-已发布"`
  27. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  28. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  29. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  30. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  31. VideoSize string `gorm:"column:video_size" description:"音频文件大小,单位M"`
  32. VideoKind int `gorm:"column:video_kind" description:"音频生成方式:1,手动上传,2:自动生成"`
  33. CreateTime time.Time `gorm:"column:create_time" description:"创建时间"`
  34. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  35. OriginalVideoUrl string `gorm:"column:original_video_url" description:"原始音频文件URL"`
  36. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  37. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  38. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  39. ContentModifyTime time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
  40. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  41. ReportCreateTime time.Time `gorm:"column:report_create_time" description:"报告时间创建时间"`
  42. VoiceGenerateType int `gorm:"column:voice_generate_type" description:"音频生成方式,0:系统生成,1:人工上传"`
  43. }
  44. type ReportChapterItem struct {
  45. ReportChapterId int `gorm:"column:report_chapter_id;primaryKey;autoIncrement:true;not null" description:"报告章节ID"`
  46. ReportId int `gorm:"column:report_id" description:"报告ID"`
  47. ReportType string `gorm:"column:report_type" description:"报告类型 day-晨报 week-周报"`
  48. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  49. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  50. TypeId int `gorm:"column:type_id" description:"品种ID"`
  51. TypeName string `gorm:"column:type_name" description:"品种名称"`
  52. Title string `gorm:"column:title" description:"标题"`
  53. Abstract string `gorm:"column:abstract" description:"摘要"`
  54. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  55. Author string `gorm:"column:author" description:"作者"`
  56. Content string `gorm:"column:content" description:"内容"`
  57. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  58. Stage int `gorm:"column:stage" description:"期数"`
  59. Trend string `gorm:"column:trend" description:"趋势观点"`
  60. Sort int `gorm:"column:sort" description:"排序: 数值越小越靠前"`
  61. IsEdit int `gorm:"column:is_edit" description:"是否已编辑 0-待编辑 1-已编辑"`
  62. PublishState int `gorm:"column:publish_state" description:"发布状态 1-待发布,2-已发布"`
  63. PublishTime string `gorm:"column:publish_time" description:"发布时间"`
  64. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  65. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  66. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  67. VideoSize string `gorm:"column:video_size" description:"音频文件大小,单位M"`
  68. VideoKind int `gorm:"column:video_kind" description:"音频生成方式:1,手动上传,2:自动生成"`
  69. CreateTime string `gorm:"column:create_time" description:"创建时间"`
  70. ModifyTime string `gorm:"column:modify_time" description:"修改时间"`
  71. OriginalVideoUrl string `gorm:"column:original_video_url" description:"原始音频文件URL"`
  72. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  73. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  74. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  75. ContentModifyTime string `gorm:"column:content_modify_time" description:"内容更新时间"`
  76. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  77. ReportCreateTime string `gorm:"column:report_create_time" description:"报告时间创建时间"`
  78. }
  79. type ReportChapterItemResp struct {
  80. ReportChapterItem
  81. GrandAdminIdList []int `description:"授权的用户id列表"`
  82. PermissionIdList []int `description:"关联的品种id列表"`
  83. CanEdit bool `description:"是否可编辑"`
  84. Editor string `description:"编辑人"`
  85. HeadImg string `description:"报告头图地址"`
  86. EndImg string `description:"报告尾图地址"`
  87. HeadStyle string `description:"版头样式"`
  88. EndStyle string `description:"版尾样式"`
  89. }
  90. type ReportChapterResp struct {
  91. ReportChapterId int `description:"报告章节ID"`
  92. ReportId int `description:"报告ID"`
  93. ReportType string `description:"报告类型 day-晨报 week-周报"`
  94. TypeId int `description:"品种ID"`
  95. TypeName string `description:"品种名称"`
  96. TypeEditImg string `description:"后台编辑时的图片"`
  97. Title string `description:"标题"`
  98. Abstract string `description:"摘要"`
  99. Author string `description:"作者"`
  100. Content string `description:"内容"`
  101. ContentSub string `description:"内容前两个章节"`
  102. Stage int `description:"期数"`
  103. Trend string `description:"趋势观点"`
  104. Sort int `description:"排序: 数值越小越靠前"`
  105. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  106. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  107. VideoUrl string `description:"音频文件URL"`
  108. VideoName string `description:"音频文件名称"`
  109. VideoPlaySeconds string `description:"音频播放时长"`
  110. VideoSize string `description:"音频文件大小,单位M"`
  111. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  112. PublishTime string `description:"发布时间"`
  113. CreateTime string `description:"创建时间"`
  114. ModifyTime string `description:"修改时间"`
  115. GrandAdminIdList []int `description:"授权的用户id列表"`
  116. PermissionIdList []int `description:"关联的品种id列表"`
  117. CanEdit bool `description:"是否可编辑"`
  118. Editor string `description:"编辑人"`
  119. IsAuth bool `description:"是否有权限"`
  120. }
  121. func GetChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  122. sql := ` SELECT * FROM report_chapter WHERE report_id = ? ORDER BY sort ASC`
  123. err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
  124. return
  125. }
  126. func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  127. sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
  128. err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
  129. return
  130. }
  131. type AddReportChapterReq struct {
  132. ReportId int `description:"报告ID"`
  133. Title string `description:"标题"`
  134. PermissionIdList []int `description:"报告关联的品种权限"`
  135. AdminIdList []int `description:"授权的编辑人id列表"`
  136. }
  137. type EditReportChapterReq struct {
  138. ReportChapterId int `description:"报告章节ID"`
  139. Title string `description:"标题"`
  140. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  141. Author string `description:"作者"`
  142. Content string `description:"内容"`
  143. TickerList []EditTickList `description:"指标信息"`
  144. CreateTime string `description:"发布时间"`
  145. VideoUrl string `description:"音频文件URL"`
  146. VideoName string `description:"音频文件名称"`
  147. VideoPlaySeconds string `description:"音频播放时长"`
  148. VideoSize string `description:"音频文件大小,单位M"`
  149. ContentStruct string `description:"内容组件"`
  150. HeadImg string `description:"报告头图地址"`
  151. EndImg string `description:"报告尾图地址"`
  152. CanvasColor string `description:"画布颜色"`
  153. HeadResourceId int `description:"版头资源ID"`
  154. EndResourceId int `description:"版尾资源ID"`
  155. }
  156. type EditTickList struct {
  157. Label string
  158. Ticker string
  159. Sort int
  160. }
  161. func GetReportChapterInfoById(reportChapterId int) (item *ReportChapter, err error) {
  162. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
  163. err = global.DmSQL["rddp"].Raw(sql, reportChapterId).First(&item).Error
  164. return
  165. }
  166. func GetReportChapterItemById(reportChapterId int) (item *ReportChapterItem, err error) {
  167. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
  168. err = global.DmSQL["rddp"].Raw(sql, reportChapterId).First(&item).Error
  169. return
  170. }
  171. func (chapterChapterInfo *ReportChapter) Add() (err error) {
  172. err = global.DmSQL["rddp"].Create(chapterChapterInfo).Error
  173. return
  174. }
  175. func (chapterChapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
  176. err = global.DmSQL["rddp"].Select(cols).Updates(chapterChapterInfo).Error
  177. return
  178. }
  179. type EditChapterTrendTagReq struct {
  180. ReportChapterId int `description:"章节ID"`
  181. Trend string `description:"趋势"`
  182. }
  183. func UpdateChapterAndTicker(reportInfo *Report, chapterInfo *ReportChapter, updateCols []string, tickerList []*ReportChapterTicker) (err error) {
  184. if err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"}); err != nil {
  185. return
  186. }
  187. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  188. return
  189. }
  190. if err = ClearReportChapterTicker(chapterInfo.ReportChapterId); err != nil {
  191. return
  192. }
  193. tickerLen := len(tickerList)
  194. if tickerLen > 0 {
  195. for i := 0; i < tickerLen; i++ {
  196. _, tmpErr := InsertChapterTicker(tickerList[i])
  197. if tmpErr != nil {
  198. return
  199. }
  200. }
  201. }
  202. return
  203. }
  204. type ReportChapterVideoList struct {
  205. ReportId int `gorm:"column:report_id"` //`description:"报告ID"`
  206. ReportChapterId int `gorm:"column:report_chapter_id"` //`description:"报告章节ID"`
  207. VideoUrl string `gorm:"column:video_url"` //`description:"音频文件URL"`
  208. VideoName string `gorm:"column:video_name"` //`description:"音频文件名称"`
  209. VideoPlaySeconds string `gorm:"column:video_play_seconds"` //`description:"音频播放时长"`
  210. }
  211. func GetReportChapterVideoList(reportId int) (list []*ReportChapterVideoList, err error) {
  212. sql := ` SELECT
  213. report_id,
  214. report_chapter_id,
  215. video_url,
  216. video_name,
  217. video_play_seconds
  218. FROM
  219. report_chapter
  220. WHERE
  221. report_id = ? AND publish_state = 2 AND video_url != ""
  222. ORDER BY
  223. report_chapter_id ASC `
  224. err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
  225. return
  226. }
  227. func GetReportChapterVideoListByReportIds(reportIds []int) (list []*ReportChapterVideoList, err error) {
  228. if len(reportIds) == 0 {
  229. return
  230. }
  231. sql := ` SELECT
  232. report_id,
  233. report_chapter_id,
  234. video_url,
  235. video_name,
  236. video_play_seconds
  237. FROM
  238. report_chapter
  239. WHERE
  240. report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) AND publish_state = 2 AND video_url != ''
  241. ORDER BY
  242. report_chapter_id ASC `
  243. err = global.DmSQL["rddp"].Raw(sql, reportIds).Find(&list).Error
  244. return
  245. }
  246. func GetReportChapterVideoListByChapterIds(chapterIds []int) (list []*ReportChapterVideoList, err error) {
  247. if len(chapterIds) == 0 {
  248. return
  249. }
  250. sql := ` SELECT
  251. report_id,
  252. report_chapter_id,
  253. video_url,
  254. video_name,
  255. video_play_seconds
  256. FROM
  257. report_chapter
  258. WHERE
  259. report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) AND publish_state = 2
  260. ORDER BY
  261. report_chapter_id ASC `
  262. err = global.DmSQL["rddp"].Raw(sql, chapterIds).Find(&list).Error
  263. return
  264. }
  265. type PublishReportChapterReq struct {
  266. ReportChapterId int `description:"报告章节ID"`
  267. PublishReport int `description:"是否同时发布报告"`
  268. }
  269. func GetUnPublishedChapterList(reportId int) (list []*ReportChapter, err error) {
  270. sql := ` SELECT report_chapter_id,report_id,title FROM report_chapter WHERE report_id = ? AND publish_state = 1 ORDER BY sort ASC`
  271. err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
  272. return
  273. }
  274. func GetChapterListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  275. if len(chapterIds) == 0 {
  276. return
  277. }
  278. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY sort ASC`
  279. err = global.DmSQL["rddp"].Raw(sql, chapterIds).Find(&list).Error
  280. return
  281. }
  282. func UpdateReportChapterTypeNameByTypeId(typeId int, typeName string) (err error) {
  283. sql := `UPDATE report_chapter SET type_name = ? WHERE type_id = ?`
  284. err = global.DmSQL["rddp"].Exec(sql, typeName, typeId).Error
  285. return
  286. }
  287. func CountReportChapterByTypeId(typeId int) (count int, err error) {
  288. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE type_id = ?`
  289. err = global.DmSQL["rddp"].Raw(sql, typeId).Scan(&count).Error
  290. return
  291. }
  292. type AddReportChapter struct {
  293. ReportChapter *ReportChapter
  294. GrantList []*report.ReportChapterGrant
  295. GrantPermissionList []*report.ReportChapterPermissionMapping
  296. }
  297. type EditReportChapterBaseInfoAndPermissionReq struct {
  298. ReportChapterId int `description:"报告章节ID"`
  299. Title string `description:"标题"`
  300. PermissionIdList []int `description:"报告关联的品种权限"`
  301. AdminIdList []int `description:"授权的编辑人id列表"`
  302. }
  303. func GetReportChapterIdList(reportId int) (list []int, err error) {
  304. sql := ` SELECT report_chapter_id FROM report_chapter
  305. WHERE report_id = ?
  306. ORDER BY report_chapter_id ASC `
  307. err = global.DmSQL["rddp"].Raw(sql, reportId).Scan(&list).Error
  308. return
  309. }
  310. type ReportChapterMoveReq struct {
  311. ReportChapterId int `description:"报告章节id"`
  312. PrevReportChapterId int `description:"上一个兄弟节点报告章节id"`
  313. NextReportChapterId int `description:"下一个兄弟节点报告章节id"`
  314. }
  315. func (chapterChapterInfo *ReportChapter) GetReportChapterById(reportChapterId int) (item *ReportChapter, err error) {
  316. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ?`
  317. err = global.DmSQL["rddp"].Raw(sql, reportChapterId).First(&item).Error
  318. return
  319. }
  320. func (chapterChapterInfo *ReportChapter) UpdateReportChapterSortByReportId(reportId, reportChapterId, nowSort int, updateSort string) (err error) {
  321. pars := make([]interface{}, 0)
  322. sql := ` update report_chapter set sort = ` + updateSort + ` WHERE report_id = ? AND sort > ?`
  323. pars = append(pars, reportId, nowSort)
  324. if reportChapterId > 0 {
  325. sql += ` or ( report_chapter_id > ? and sort = ? )`
  326. pars = append(pars, reportChapterId, nowSort)
  327. }
  328. err = global.DmSQL["rddp"].Exec(sql, pars...).Error
  329. return
  330. }
  331. func (chapterChapterInfo *ReportChapter) GetFirstReportChapterByReportId(reportId int) (item *ReportChapter, err error) {
  332. sql := ` SELECT * FROM report_chapter WHERE 1 = 1 AND report_id = ? ORDER BY sort ASC, report_chapter_id ASC LIMIT 1`
  333. err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
  334. return
  335. }
  336. func (chapterChapterInfo *ReportChapter) GetMaxSortByReportId(reportId int) (maxSort int, err error) {
  337. sql := `SELECT COALESCE(MAX(sort), 0) AS sort FROM report_chapter WHERE report_id = ?`
  338. err = global.DmSQL["rddp"].Raw(sql, reportId).Scan(&maxSort).Error
  339. return
  340. }
  341. func (chapterChapterInfo *ReportChapter) Update(cols []string) (err error) {
  342. err = global.DmSQL["rddp"].Select(cols).Updates(chapterChapterInfo).Error
  343. return
  344. }
  345. type DelReportChapterReq struct {
  346. ReportChapterId int `description:"报告章节ID"`
  347. }
  348. func GetCountReportChapterByCondition(condition string, pars []interface{}) (count int, err error) {
  349. sql := ` SELECT COUNT(1) AS count FROM report_chapter WHERE 1=1 `
  350. if condition != "" {
  351. sql += condition
  352. }
  353. err = global.DmSQL["rddp"].Raw(sql, pars...).Scan(&count).Error
  354. return
  355. }