report_chapter.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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. // ReportChapter 报告章节
  9. type ReportChapter struct {
  10. ReportChapterId int `gorm:"column:report_chapter_id;primaryKey;autoIncrement:false;not null" description:"报告章节ID"`
  11. ReportId int `gorm:"column:report_id" description:"报告ID"`
  12. ReportType string `gorm:"column:report_type" description:"报告类型 day-晨报 week-周报"`
  13. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  14. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  15. TypeId int `gorm:"column:type_id" description:"品种ID"`
  16. TypeName string `gorm:"column:type_name" description:"品种名称"`
  17. Title string `gorm:"column:title" description:"标题"`
  18. Abstract string `gorm:"column:abstract" description:"摘要"`
  19. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  20. Author string `gorm:"column:author" description:"作者"`
  21. Content string `gorm:"column:content" description:"内容"`
  22. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  23. Stage int `gorm:"column:stage" description:"期数"`
  24. Trend string `gorm:"column:trend" description:"趋势观点"`
  25. Sort int `gorm:"column:sort" description:"排序: 数值越小越靠前"`
  26. IsEdit int `gorm:"column:is_edit" description:"是否已编辑 0-待编辑 1-已编辑"`
  27. PublishState int `gorm:"column:publish_state" description:"发布状态 1-待发布,2-已发布"`
  28. PublishTime time.Time `gorm:"column:publish_time" description:"发布时间"`
  29. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  30. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  31. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  32. VideoSize string `gorm:"column:video_size" description:"音频文件大小,单位M"`
  33. VideoKind int `gorm:"column:video_kind" description:"音频生成方式:1,手动上传,2:自动生成"`
  34. CreateTime string `gorm:"column:create_time" description:"创建时间"`
  35. ModifyTime time.Time `gorm:"column:modify_time" description:"修改时间"`
  36. OriginalVideoUrl string `gorm:"column:original_video_url" description:"原始音频文件URL"`
  37. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  38. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  39. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  40. ContentModifyTime time.Time `gorm:"column:content_modify_time" description:"内容更新时间"`
  41. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  42. ReportCreateTime time.Time `gorm:"column:report_create_time" description:"报告时间创建时间"`
  43. VoiceGenerateType int `gorm:"column:voice_generate_type" description:"音频生成方式,0:系统生成,1:人工上传"`
  44. }
  45. // ReportChapterItem 报告章节详情
  46. type ReportChapterItem struct {
  47. ReportChapterId int `gorm:"column:report_chapter_id;primaryKey;autoIncrement:false;not null" description:"报告章节ID"`
  48. ReportId int `gorm:"column:report_id" description:"报告ID"`
  49. ReportType string `gorm:"column:report_type" description:"报告类型 day-晨报 week-周报"`
  50. ClassifyIdFirst int `gorm:"column:classify_id_first" description:"一级分类id"`
  51. ClassifyNameFirst string `gorm:"column:classify_name_first" description:"一级分类名称"`
  52. TypeId int `gorm:"column:type_id" description:"品种ID"`
  53. TypeName string `gorm:"column:type_name" description:"品种名称"`
  54. Title string `gorm:"column:title" description:"标题"`
  55. Abstract string `gorm:"column:abstract" description:"摘要"`
  56. AddType int `gorm:"column:add_type" description:"新增方式:1:新增报告,2:继承报告"`
  57. Author string `gorm:"column:author" description:"作者"`
  58. Content string `gorm:"column:content" description:"内容"`
  59. ContentSub string `gorm:"column:content_sub" description:"内容前两个章节"`
  60. Stage int `gorm:"column:stage" description:"期数"`
  61. Trend string `gorm:"column:trend" description:"趋势观点"`
  62. Sort int `gorm:"column:sort" description:"排序: 数值越小越靠前"`
  63. IsEdit int `gorm:"column:is_edit" description:"是否已编辑 0-待编辑 1-已编辑"`
  64. PublishState int `gorm:"column:publish_state" description:"发布状态 1-待发布,2-已发布"`
  65. PublishTime string `gorm:"column:publish_time" description:"发布时间"`
  66. VideoUrl string `gorm:"column:video_url" description:"音频文件URL"`
  67. VideoName string `gorm:"column:video_name" description:"音频文件名称"`
  68. VideoPlaySeconds string `gorm:"column:video_play_seconds" description:"音频播放时长"`
  69. VideoSize string `gorm:"column:video_size" description:"音频文件大小,单位M"`
  70. VideoKind int `gorm:"column:video_kind" description:"音频生成方式:1,手动上传,2:自动生成"`
  71. CreateTime string `gorm:"column:create_time" description:"创建时间"`
  72. ModifyTime string `gorm:"column:modify_time" description:"修改时间"`
  73. OriginalVideoUrl string `gorm:"column:original_video_url" description:"原始音频文件URL"`
  74. ContentStruct string `gorm:"column:content_struct" description:"内容组件"`
  75. LastModifyAdminId int `gorm:"column:last_modify_admin_id" description:"最后更新人ID"`
  76. LastModifyAdminName string `gorm:"column:last_modify_admin_name" description:"最后更新人姓名"`
  77. ContentModifyTime string `gorm:"column:content_modify_time" description:"内容更新时间"`
  78. ReportLayout int8 `gorm:"column:report_layout" description:"报告布局,1:常规布局,2:智能布局。默认:1"`
  79. ReportCreateTime string `gorm:"column:report_create_time" description:"报告时间创建时间"`
  80. }
  81. // ReportChapterItemResp
  82. // @Description: 章节详情(带有一些额外的数据)
  83. type ReportChapterItemResp struct {
  84. ReportChapterItem
  85. GrandAdminIdList []int `description:"授权的用户id列表"`
  86. PermissionIdList []int `description:"关联的品种id列表"`
  87. CanEdit bool `description:"是否可编辑"`
  88. Editor string `description:"编辑人"`
  89. HeadImg string `description:"报告头图地址"`
  90. EndImg string `description:"报告尾图地址"`
  91. HeadStyle string `description:"版头样式"`
  92. EndStyle string `description:"版尾样式"`
  93. }
  94. type ReportChapterResp struct {
  95. ReportChapterId int `description:"报告章节ID"`
  96. ReportId int `description:"报告ID"`
  97. ReportType string `description:"报告类型 day-晨报 week-周报"`
  98. TypeId int `description:"品种ID"`
  99. TypeName string `description:"品种名称"`
  100. TypeEditImg string `description:"后台编辑时的图片"`
  101. Title string `description:"标题"`
  102. Abstract string `description:"摘要"`
  103. Author string `description:"作者"`
  104. Content string `description:"内容"`
  105. ContentSub string `description:"内容前两个章节"`
  106. Stage int `description:"期数"`
  107. Trend string `description:"趋势观点"`
  108. Sort int `description:"排序: 数值越小越靠前"`
  109. IsEdit int `description:"是否已编辑 0-待编辑 1-已编辑"`
  110. PublishState int `description:"发布状态 1-待发布,2-已发布"`
  111. VideoUrl string `description:"音频文件URL"`
  112. VideoName string `description:"音频文件名称"`
  113. VideoPlaySeconds string `description:"音频播放时长"`
  114. VideoSize string `description:"音频文件大小,单位M"`
  115. VideoKind int `description:"音频生成方式:1,手动上传,2:自动生成"`
  116. PublishTime string `description:"发布时间"`
  117. CreateTime string `description:"创建时间"`
  118. ModifyTime string `description:"修改时间"`
  119. GrandAdminIdList []int `description:"授权的用户id列表"`
  120. PermissionIdList []int `description:"关联的品种id列表"`
  121. CanEdit bool `description:"是否可编辑"`
  122. Editor string `description:"编辑人"`
  123. IsAuth bool `description:"是否有权限"`
  124. }
  125. // GetChapterListByReportId 根据ReportId获取章节列表
  126. func GetChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  127. //o := orm.NewOrmUsingDB("rddp")
  128. sql := ` SELECT * FROM report_chapter WHERE report_id = ? ORDER BY sort ASC`
  129. //_, err = o.Raw(sql, reportId).QueryRows(&list)
  130. err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
  131. return
  132. }
  133. // GetPublishedChapterListByReportId 根据ReportId获取已发布章节列表
  134. func GetPublishedChapterListByReportId(reportId int) (list []*ReportChapter, err error) {
  135. //o := orm.NewOrmUsingDB("rddp")
  136. sql := ` SELECT * FROM report_chapter WHERE report_id = ? AND publish_state = 2 ORDER BY sort ASC`
  137. //_, err = o.Raw(sql, reportId).QueryRows(&list)
  138. err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
  139. return
  140. }
  141. // AddReportChapterReq
  142. // @Description: 新增报告章节请求体
  143. type AddReportChapterReq struct {
  144. ReportId int `description:"报告ID"`
  145. Title string `description:"标题"`
  146. PermissionIdList []int `description:"报告关联的品种权限"`
  147. AdminIdList []int `description:"授权的编辑人id列表"`
  148. }
  149. // EditReportChapterReq 编辑报告章节请求体
  150. type EditReportChapterReq struct {
  151. ReportChapterId int `description:"报告章节ID"`
  152. Title string `description:"标题"`
  153. AddType int `description:"新增方式:1:新增报告,2:继承报告"`
  154. Author string `description:"作者"`
  155. Content string `description:"内容"`
  156. TickerList []EditTickList `description:"指标信息"`
  157. CreateTime string `description:"发布时间"`
  158. VideoUrl string `description:"音频文件URL"`
  159. VideoName string `description:"音频文件名称"`
  160. VideoPlaySeconds string `description:"音频播放时长"`
  161. VideoSize string `description:"音频文件大小,单位M"`
  162. // 以下是智能研报相关
  163. ContentStruct string `description:"内容组件"`
  164. HeadImg string `description:"报告头图地址"`
  165. EndImg string `description:"报告尾图地址"`
  166. CanvasColor string `description:"画布颜色"`
  167. HeadResourceId int `description:"版头资源ID"`
  168. EndResourceId int `description:"版尾资源ID"`
  169. }
  170. type EditTickList struct {
  171. Label string
  172. Ticker string
  173. Sort int
  174. }
  175. // GetReportChapterInfoById 根据主键获取报告章节
  176. func GetReportChapterInfoById(reportChapterId int) (item *ReportChapter, err error) {
  177. //o := orm.NewOrmUsingDB("rddp")
  178. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
  179. //err = o.Raw(sql, reportChapterId).QueryRow(&item)
  180. err = global.DmSQL["rddp"].Raw(sql, reportChapterId).First(&item).Error
  181. return
  182. }
  183. // GetReportChapterItemById
  184. // @Description: 根据主键获取报告章节(时间格式为字符串的数据)
  185. // @author: Roc
  186. // @datetime 2024-06-27 14:10:29
  187. // @param reportChapterId int
  188. // @return item *ReportChapterItem
  189. // @return err error
  190. func GetReportChapterItemById(reportChapterId int) (item *ReportChapterItem, err error) {
  191. //o := orm.NewOrmUsingDB("rddp")
  192. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ? `
  193. //err = o.Raw(sql, reportChapterId).QueryRow(&item)
  194. err = global.DmSQL["rddp"].Raw(sql, reportChapterId).First(&item).Error
  195. return
  196. }
  197. // GetLastPublishedReportChapter 获取上一篇已发表的晨周报章节
  198. func GetLastPublishedReportChapter(typeId int, reportType string) (item *ReportChapter, err error) {
  199. //o := orm.NewOrmUsingDB("rddp")
  200. sql := ` SELECT * FROM report_chapter WHERE publish_state = 2 AND type_id = ? AND report_type = ? ORDER BY report_chapter_id DESC limit 1 `
  201. //err = o.Raw(sql, typeId, reportType).QueryRow(&item)
  202. err = global.DmSQL["rddp"].Raw(sql, typeId, reportType).First(&item).Error
  203. return
  204. }
  205. // Add
  206. // @Description: 新增章节报告
  207. // @author: Roc
  208. // @receiver chapterInfo
  209. // @datetime 2024-06-04 15:14:41
  210. // @return err error
  211. func (chapterChapterInfo *ReportChapter) Add() (err error) {
  212. //o := orm.NewOrmUsingDB("rddp")
  213. //lastId, err := o.Insert(chapterChapterInfo)
  214. //if err != nil {
  215. // return
  216. //}
  217. //chapterChapterInfo.ReportChapterId = int(lastId)
  218. err = global.DmSQL["rddp"].Create(chapterChapterInfo).Error
  219. return
  220. }
  221. // UpdateChapter 更新报表章节
  222. func (chapterChapterInfo *ReportChapter) UpdateChapter(cols []string) (err error) {
  223. //o := orm.NewOrmUsingDB("rddp")
  224. //_, err = o.Update(chapterChapterInfo, cols...)
  225. err = global.DmSQL["rddp"].Select(cols).Updates(chapterChapterInfo).Error
  226. return
  227. }
  228. // EditChapterTrendTagReq 编辑章节趋势标签请求体
  229. type EditChapterTrendTagReq struct {
  230. ReportChapterId int `description:"章节ID"`
  231. Trend string `description:"趋势"`
  232. }
  233. // UpdateChapterAndTicker 更新章节及ticker
  234. func UpdateChapterAndTicker(reportInfo *Report, chapterInfo *ReportChapter, updateCols []string, tickerList []*ReportChapterTicker) (err error) {
  235. // 更新报告的最近编辑人信息
  236. if err = reportInfo.UpdateReport([]string{"LastModifyAdminId", "LastModifyAdminName", "ModifyTime"}); err != nil {
  237. return
  238. }
  239. // 更新章节
  240. if err = chapterInfo.UpdateChapter(updateCols); err != nil {
  241. return
  242. }
  243. // 清空并新增章节ticker
  244. if err = ClearReportChapterTicker(chapterInfo.ReportChapterId); err != nil {
  245. return
  246. }
  247. tickerLen := len(tickerList)
  248. if tickerLen > 0 {
  249. for i := 0; i < tickerLen; i++ {
  250. _, tmpErr := InsertChapterTicker(tickerList[i])
  251. if tmpErr != nil {
  252. return
  253. }
  254. }
  255. }
  256. return
  257. }
  258. // ReportChapterVideoList 报告章节音频列表
  259. type ReportChapterVideoList struct {
  260. ReportId int `gorm:"column:report_id"` //`description:"报告ID"`
  261. ReportChapterId int `gorm:"column:report_chapter_id"` //`description:"报告章节ID"`
  262. VideoUrl string `gorm:"column:video_url"` //`description:"音频文件URL"`
  263. VideoName string `gorm:"column:video_name"` //`description:"音频文件名称"`
  264. VideoPlaySeconds string `gorm:"column:video_play_seconds"` //`description:"音频播放时长"`
  265. }
  266. // GetReportChapterVideoList 获取报告章节音频列表
  267. func GetReportChapterVideoList(reportId int) (list []*ReportChapterVideoList, err error) {
  268. //o := orm.NewOrmUsingDB("rddp")
  269. sql := ` SELECT
  270. report_id,
  271. report_chapter_id,
  272. video_url,
  273. video_name,
  274. video_play_seconds
  275. FROM
  276. report_chapter
  277. WHERE
  278. report_id = ? AND publish_state = 2 AND video_url != ""
  279. ORDER BY
  280. report_chapter_id ASC `
  281. //_, err = o.Raw(sql, reportId).QueryRows(&list)
  282. err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
  283. return
  284. }
  285. // GetReportChapterVideoListByReportIds 根据报告ID集合获取报告章节音频列表
  286. func GetReportChapterVideoListByReportIds(reportIds []int) (list []*ReportChapterVideoList, err error) {
  287. if len(reportIds) == 0 {
  288. return
  289. }
  290. //o := orm.NewOrmUsingDB("rddp")
  291. sql := ` SELECT
  292. report_id,
  293. report_chapter_id,
  294. video_url,
  295. video_name,
  296. video_play_seconds
  297. FROM
  298. report_chapter
  299. WHERE
  300. report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) AND publish_state = 2 AND video_url != ""
  301. ORDER BY
  302. report_chapter_id ASC `
  303. //_, err = o.Raw(sql, reportIds).QueryRows(&list)
  304. err = global.DmSQL["rddp"].Raw(sql, reportIds).Find(&list).Error
  305. return
  306. }
  307. // GetReportChapterVideoListByChapterIds 根据章节ID集合获取报告章节音频列表
  308. func GetReportChapterVideoListByChapterIds(chapterIds []int) (list []*ReportChapterVideoList, err error) {
  309. if len(chapterIds) == 0 {
  310. return
  311. }
  312. //o := orm.NewOrmUsingDB("rddp")
  313. sql := ` SELECT
  314. report_id,
  315. report_chapter_id,
  316. video_url,
  317. video_name,
  318. video_play_seconds
  319. FROM
  320. report_chapter
  321. WHERE
  322. report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) AND publish_state = 2
  323. ORDER BY
  324. report_chapter_id ASC `
  325. //_, err = o.Raw(sql, chapterIds).QueryRows(&list)
  326. err = global.DmSQL["rddp"].Raw(sql, chapterIds).Find(&list).Error
  327. return
  328. }
  329. // PublishReportChapterReq 发布报告章节请求体
  330. type PublishReportChapterReq struct {
  331. ReportChapterId int `description:"报告章节ID"`
  332. PublishReport int `description:"是否同时发布报告"`
  333. }
  334. // CountPublishedChapterNum 获取报告已发布的章节数
  335. func CountPublishedChapterNum(reportId int) (count int, err error) {
  336. //o := orm.NewOrmUsingDB("rddp")
  337. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 2 `
  338. //err = o.Raw(sql, reportId).QueryRow(&count)
  339. err = global.DmSQL["rddp"].Raw(sql, reportId).Scan(&count).Error
  340. return
  341. }
  342. // CountUnPublishedChapterNum
  343. // @Description: 获取报告未发布的章节数
  344. // @author: Roc
  345. // @datetime 2024-06-14 15:59:23
  346. // @param reportId int
  347. // @return count int
  348. // @return err error
  349. func CountUnPublishedChapterNum(reportId int) (count int, err error) {
  350. //o := orm.NewOrmUsingDB("rddp")
  351. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE report_id = ? AND publish_state = 1 `
  352. //err = o.Raw(sql, reportId).QueryRow(&count)
  353. err = global.DmSQL["rddp"].Raw(sql, reportId).Scan(&count).Error
  354. return
  355. }
  356. // GetUnPublishedChapterList
  357. // @Description: 获取报告未发布的章节列表
  358. // @author: Roc
  359. // @datetime 2024-06-14 15:59:23
  360. // @param reportId int
  361. // @return list []*ReportChapter
  362. // @return err error
  363. func GetUnPublishedChapterList(reportId int) (list []*ReportChapter, err error) {
  364. //o := orm.NewOrmUsingDB("rddp")
  365. sql := ` SELECT report_chapter_id,report_id,title FROM report_chapter WHERE report_id = ? AND publish_state = 1 ORDER BY sort ASC`
  366. //_, err = o.Raw(sql, reportId).QueryRows(&list)
  367. err = global.DmSQL["rddp"].Raw(sql, reportId).Find(&list).Error
  368. return
  369. }
  370. // GetChapterListByChapterIds 根据ReportId获取章节列表
  371. func GetChapterListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  372. if len(chapterIds) == 0 {
  373. return
  374. }
  375. // o := orm.NewOrmUsingDB("rddp")
  376. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY sort ASC`
  377. //_, err = o.Raw(sql, chapterIds).QueryRows(&list)
  378. err = global.DmSQL["rddp"].Raw(sql, chapterIds).Find(&list).Error
  379. return
  380. }
  381. // GetChapterSimpleListByChapterIds 根据章节ID获取章节列表
  382. func GetChapterSimpleListByChapterIds(chapterIds []int) (list []*ReportChapter, err error) {
  383. if len(chapterIds) == 0 {
  384. return
  385. }
  386. //o := orm.NewOrmUsingDB("rddp")
  387. sql := ` SELECT report_id, report_chapter_id, title, type_name, create_time, IF(publish_time,publish_time,create_time) as publish_time FROM report_chapter WHERE report_chapter_id IN (` + utils.GetOrmInReplace(len(chapterIds)) + `) ORDER BY publish_time desc, sort ASC`
  388. // _, err = o.Raw(sql, chapterIds).QueryRows(&list)
  389. err = global.DmSQL["rddp"].Raw(sql, chapterIds).Find(&list).Error
  390. return
  391. }
  392. // GetChapterSimpleListByReportIds 根据ReportId获取章节列表
  393. func GetChapterSimpleListByReportIds(reportIds []int) (list []*ReportChapter, err error) {
  394. if len(reportIds) == 0 {
  395. return
  396. }
  397. //o := orm.NewOrmUsingDB("rddp")
  398. sql := ` SELECT report_id, report_chapter_id, title, type_name, create_time, IF(publish_time,publish_time,create_time) as publish_time FROM report_chapter WHERE publish_state = 2 and report_id IN (` + utils.GetOrmInReplace(len(reportIds)) + `) ORDER BY publish_time desc, sort ASC`
  399. //_, err = o.Raw(sql, reportIds).QueryRows(&list)
  400. err = global.DmSQL["rddp"].Raw(sql, reportIds).Find(&list).Error
  401. return
  402. }
  403. // UpdateReportChapterTypeNameByTypeId 更新章节类型名称
  404. func UpdateReportChapterTypeNameByTypeId(typeId int, typeName string) (err error) {
  405. //o := orm.NewOrmUsingDB("rddp")
  406. sql := `UPDATE report_chapter SET type_name = ? WHERE type_id = ?`
  407. //_, err = o.Raw(sql, typeName, typeId).Exec()
  408. err = global.DmSQL["rddp"].Exec(sql, typeName, typeId).Error
  409. return
  410. }
  411. // CountReportChapterByTypeId 通过章节类型ID获取章节数
  412. func CountReportChapterByTypeId(typeId int) (count int, err error) {
  413. //o := orm.NewOrmUsingDB("rddp")
  414. sql := ` SELECT COUNT(1) AS ct FROM report_chapter WHERE type_id = ?`
  415. //err = o.Raw(sql, typeId).QueryRow(&count)
  416. err = global.DmSQL["rddp"].Raw(sql, typeId).Scan(&count).Error
  417. return
  418. }
  419. // AddReportChapter
  420. // @Description: 待添加的报告章节
  421. type AddReportChapter struct {
  422. ReportChapter *ReportChapter
  423. GrantList []*report.ReportChapterGrant
  424. GrantPermissionList []*report.ReportChapterPermissionMapping
  425. }
  426. // EditReportChapterBaseInfoAndPermissionReq
  427. // @Description: 编辑报告章节的基础信息请求
  428. type EditReportChapterBaseInfoAndPermissionReq struct {
  429. ReportChapterId int `description:"报告章节ID"`
  430. Title string `description:"标题"`
  431. PermissionIdList []int `description:"报告关联的品种权限"`
  432. AdminIdList []int `description:"授权的编辑人id列表"`
  433. }
  434. // GetReportChapterIdList
  435. // @Description: 获取报告的所有章节id列表
  436. // @author: Roc
  437. // @datetime 2024-06-05 11:09:40
  438. // @param reportId int
  439. // @return list []int
  440. // @return err error
  441. func GetReportChapterIdList(reportId int) (list []int, err error) {
  442. //o := orm.NewOrmUsingDB("rddp")
  443. sql := ` SELECT report_chapter_id FROM report_chapter
  444. WHERE report_id = ?
  445. ORDER BY report_chapter_id ASC `
  446. //_, err = o.Raw(sql, reportId).QueryRows(&list)
  447. err = global.DmSQL["rddp"].Raw(sql, reportId).Scan(&list).Error
  448. return
  449. }
  450. // ReportChapterMoveReq
  451. // @Description: 报告章节移动请求
  452. type ReportChapterMoveReq struct {
  453. ReportChapterId int `description:"报告章节id"`
  454. // ParentChartPermissionId int `description:"父级品种id"`
  455. PrevReportChapterId int `description:"上一个兄弟节点报告章节id"`
  456. NextReportChapterId int `description:"下一个兄弟节点报告章节id"`
  457. }
  458. // GetReportChapterById
  459. // @Description: 获取具体章节
  460. // @author: Roc
  461. // @receiver r
  462. // @datetime 2024-06-06 09:32:40
  463. // @param reportChapterId int
  464. // @return item *ReportChapter
  465. // @return err error
  466. func (chapterChapterInfo *ReportChapter) GetReportChapterById(reportChapterId int) (item *ReportChapter, err error) {
  467. // o := orm.NewOrmUsingDB("rddp")
  468. sql := ` SELECT * FROM report_chapter WHERE report_chapter_id = ?`
  469. //err = o.Raw(sql, reportChapterId).QueryRow(&item)
  470. err = global.DmSQL["rddp"].Raw(sql, reportChapterId).First(&item).Error
  471. return
  472. }
  473. // UpdateReportChapterSortByReportId
  474. // @Description: 根据父类id更新排序
  475. // @author: Roc
  476. // @receiver chapterChapterInfo
  477. // @datetime 2024-06-06 09:39:28
  478. // @param reportId int
  479. // @param reportChapterId int
  480. // @param nowSort int
  481. // @param updateSort string
  482. // @return err error
  483. func (chapterChapterInfo *ReportChapter) UpdateReportChapterSortByReportId(reportId, reportChapterId, nowSort int, updateSort string) (err error) {
  484. //o := orm.NewOrmUsingDB("rddp")
  485. pars := make([]interface{}, 0)
  486. sql := ` update report_chapter set sort = ` + updateSort + ` WHERE report_id = ? AND sort > ?`
  487. pars = append(pars, reportId, nowSort)
  488. if reportChapterId > 0 {
  489. sql += ` or ( report_chapter_id > ? and sort = ? )`
  490. pars = append(pars, reportChapterId, nowSort)
  491. }
  492. //_, err = o.Raw(sql, pars).Exec()
  493. err = global.DmSQL["rddp"].Exec(sql, pars).Error
  494. return
  495. }
  496. // GetFirstReportChapterByReportId
  497. // @Description: 获取当前报告下,且排序数相同 的排序第一条的数据
  498. // @author: Roc
  499. // @receiver chapterChapterInfo
  500. // @datetime 2024-06-06 09:45:32
  501. // @param reportId int
  502. // @return item *ReportChapter
  503. // @return err error
  504. func (chapterChapterInfo *ReportChapter) GetFirstReportChapterByReportId(reportId int) (item *ReportChapter, err error) {
  505. //o := orm.NewOrmUsingDB("rddp")
  506. sql := ` SELECT * FROM report_chapter WHERE 1 = 1 AND report_id = ? ORDER BY sort ASC, report_chapter_id ASC LIMIT 1`
  507. //err = o.Raw(sql, reportId).QueryRow(&item)
  508. err = global.DmSQL["rddp"].Raw(sql, reportId).First(&item).Error
  509. return
  510. }
  511. // GetMaxSortByReportId
  512. // @Description: 获取最大的排序值
  513. // @author: Roc
  514. // @receiver chapterChapterInfo
  515. // @datetime 2024-06-06 09:44:13
  516. // @param reportId int
  517. // @return maxSort int
  518. // @return err error
  519. func (chapterChapterInfo *ReportChapter) GetMaxSortByReportId(reportId int) (maxSort int, err error) {
  520. //o := orm.NewOrmUsingDB("rddp")
  521. sql := `SELECT max(sort) AS sort FROM report_chapter WHERE report_id = ?`
  522. //err = o.Raw(sql, reportId).QueryRow(&maxSort)
  523. err = global.DmSQL["rddp"].Raw(sql, reportId).Scan(&maxSort).Error
  524. return
  525. }
  526. // Update
  527. // @Description: 数据变更
  528. // @author: Roc
  529. // @receiver chapterChapterInfo
  530. // @datetime 2024-06-06 09:47:46
  531. // @param cols []string
  532. // @return err error
  533. func (chapterChapterInfo *ReportChapter) Update(cols []string) (err error) {
  534. //o := orm.NewOrmUsingDB("rddp")
  535. //_, err = o.Update(chapterChapterInfo, cols...)
  536. err = global.DmSQL["rddp"].Select(cols).Updates(chapterChapterInfo).Error
  537. return
  538. }
  539. // DelReportChapterReq
  540. // @Description: 删除报告章节请求体
  541. type DelReportChapterReq struct {
  542. ReportChapterId int `description:"报告章节ID"`
  543. }
  544. // GetAllReportChapter 获取所有的报告章节
  545. func GetAllReportChapter() (items []*ReportChapter, err error) {
  546. //o := orm.NewOrmUsingDB("rddp")
  547. sql := ` SELECT * FROM report_chapter ORDER BY report_chapter_id asc `
  548. //_, err = o.Raw(sql).QueryRows(&items)
  549. err = global.DmSQL["rddp"].Raw(sql).Find(&items).Error
  550. return
  551. }
  552. // GetCountReportChapterByCondition
  553. // @Description: 根据条件获取章节数量
  554. // @author: Roc
  555. // @datetime 2024-07-15 15:37:50
  556. // @param condition string
  557. // @param pars []interface{}
  558. // @return count int
  559. // @return err error
  560. func GetCountReportChapterByCondition(condition string, pars []interface{}) (count int, err error) {
  561. //o := orm.NewOrmUsingDB("rddp")
  562. sql := ` SELECT COUNT(1) AS count FROM report_chapter WHERE 1=1 `
  563. if condition != "" {
  564. sql += condition
  565. }
  566. //err = o.Raw(sql, pars).QueryRow(&count)
  567. err = global.DmSQL["rddp"].Raw(sql, pars).Scan(&count).Error
  568. return
  569. }