report_chapter.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. package report
  2. import (
  3. "errors"
  4. "fmt"
  5. report_chapter_type_cache "hongze/hongze_yb/cache/report_chapter_type"
  6. "hongze/hongze_yb/global"
  7. "hongze/hongze_yb/models/response"
  8. "hongze/hongze_yb/models/tables/company_product"
  9. "hongze/hongze_yb/models/tables/rddp/chart_permission_chapter_mapping"
  10. "hongze/hongze_yb/models/tables/rddp/classify"
  11. "hongze/hongze_yb/models/tables/rddp/report"
  12. "hongze/hongze_yb/models/tables/rddp/report_chapter"
  13. "hongze/hongze_yb/models/tables/rddp/smart_report_resource"
  14. "hongze/hongze_yb/models/tables/report_chapter_permission_mapping"
  15. "hongze/hongze_yb/models/tables/report_chapter_type"
  16. "hongze/hongze_yb/models/tables/user_report_chapter_set"
  17. "hongze/hongze_yb/services"
  18. "hongze/hongze_yb/services/collection"
  19. "hongze/hongze_yb/services/company"
  20. "hongze/hongze_yb/services/user"
  21. "hongze/hongze_yb/utils"
  22. "html"
  23. "sort"
  24. "strings"
  25. "time"
  26. )
  27. // GetReportTypeIdsByPermissionIds 获取所有和权限绑定的报告章节ID
  28. func GetReportTypeIdsByPermissionIds(permissionIds []int) (ids []int, err error) {
  29. ids, err = chart_permission_chapter_mapping.GetReportIdsByPermisssionIds(permissionIds, "week")
  30. return
  31. }
  32. // GetLatestWeek 获取有权限的最新的周报
  33. func GetLatestWeek(permissionIds []int, typeIds []int) (reportInfo *report.Report, err error) {
  34. newTypeIds, err := GetWeekTypeIdsByPermissionIds(permissionIds, typeIds)
  35. chapters, err := report_chapter.GetLatestChaptersByTypeIdsAndClass(newTypeIds, "week")
  36. if err != nil {
  37. return
  38. }
  39. var reportIds []int
  40. for _, v := range chapters {
  41. reportIds = append(reportIds, v.ReportId)
  42. }
  43. reportInfo, err = report.GetLatestByReportIds(reportIds)
  44. return
  45. }
  46. // GetWeekTypeIdsByPermissionIds 获取有权限的章节类型ID
  47. func GetWeekTypeIdsByPermissionIds(permissionIds []int, typeIds []int) (newTypeIds []int, err error) {
  48. ids, err := GetReportTypeIdsByPermissionIds(permissionIds)
  49. if err != nil {
  50. return
  51. }
  52. if len(typeIds) == 0 {
  53. typeIds, err = report_chapter_type_cache.GetEffectTypeID()
  54. if err != nil {
  55. return
  56. }
  57. }
  58. for _, v1 := range typeIds {
  59. for _, v2 := range ids {
  60. if v1 == v2 {
  61. newTypeIds = append(newTypeIds, v2)
  62. }
  63. }
  64. }
  65. return
  66. }
  67. // GetChapterListByReport 根据报告获取章节列表
  68. func GetChapterListByReport(classifyNameFirst string, reportId int, validWeekTypeIds []int, reportCreateTime time.Time) (reportTypeList response.ReportChapterList, err error) {
  69. var errMsg string
  70. defer func() {
  71. if err != nil {
  72. global.LOG.Critical(fmt.Sprintf("GetChapterListByReport: err:%s, errMsg:%s", err.Error(), errMsg))
  73. }
  74. }()
  75. //查询有效的章节
  76. typeList, tErr := report_chapter_type.GetEffectTypes()
  77. if tErr != nil {
  78. errMsg = tErr.Error()
  79. err = errors.New("章节类型查询出错")
  80. return
  81. }
  82. if len(typeList) == 0 {
  83. err = errors.New("无有效的章节")
  84. return
  85. }
  86. typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
  87. var typeIds []int
  88. newTypeMap := make(map[int]bool)
  89. for _, v := range typeList {
  90. typeMap[v.ReportChapterTypeId] = v
  91. typeIds = append(typeIds, int(v.ReportChapterTypeId))
  92. }
  93. if classifyNameFirst != "晨报" {
  94. for _, v := range validWeekTypeIds {
  95. newTypeMap[v] = true
  96. }
  97. }
  98. //获取所有当前研报的章节
  99. chapterList, tErr := report_chapter.GetListByReportId(reportId, classifyNameFirst)
  100. if tErr != nil && tErr != utils.ErrNoRow {
  101. errMsg = err.Error()
  102. err = errors.New("章节查询出错")
  103. return
  104. }
  105. if len(chapterList) == 0 {
  106. err = errors.New("无有效章节")
  107. return
  108. }
  109. for _, item := range chapterList {
  110. if typeItem, ok := typeMap[uint64(item.TypeId)]; ok {
  111. // 如果是周报只展示有权限的章节
  112. if classifyNameFirst == "周报" {
  113. if _, ok1 := newTypeMap[item.TypeId]; !ok1 {
  114. continue
  115. }
  116. }
  117. temp := new(response.ReportChapterListItem)
  118. if reportCreateTime.Before(typeItem.PauseStartTime) || reportCreateTime.After(typeItem.PauseEndTime) {
  119. temp.ReportChapterId = item.ReportChapterId
  120. temp.TypeId = item.TypeId
  121. temp.TypeName = item.TypeName
  122. temp.Title = item.Title
  123. temp.Trend = item.Trend
  124. temp.ReportId = item.ReportId
  125. temp.Sort = typeItem.Sort
  126. temp.PublishTime = item.PublishTime
  127. temp.ReportChapterTypeKey = typeItem.ReportChapterTypeKey
  128. temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
  129. temp.ReportChapterTypeThumb = typeItem.YbIconUrl
  130. temp.VideoUrl = item.VideoUrl
  131. temp.VideoName = item.VideoName
  132. temp.VideoPlaySeconds = item.VideoPlaySeconds
  133. temp.VideoSize = item.VideoSize
  134. reportTypeList = append(reportTypeList, temp)
  135. }
  136. }
  137. }
  138. if len(reportTypeList) > 0 {
  139. sort.Sort(reportTypeList)
  140. }
  141. return
  142. }
  143. // GetChapterDetail 获取章节详情
  144. func GetChapterDetail(user user.UserInfo, reportChapterId int) (reportChapterDetail *response.ReportChapterDetail, err error) {
  145. var errMsg string
  146. defer func() {
  147. if err != nil {
  148. global.LOG.Critical(fmt.Sprintf("GetChapterDetail: userId=%d, err:%s, errMsg:%s", user.UserID, err.Error(), errMsg))
  149. }
  150. }()
  151. var authOk bool
  152. var productAuthOk bool
  153. var chapterAuthOk bool
  154. var permissionCheckInfo response.PermissionCheckInfo
  155. // 判断用户状态是否是正常和永续
  156. companyProduct, err := company_product.GetByCompany2ProductId(user.CompanyID, 1)
  157. if err == utils.ErrNoRow {
  158. err = nil
  159. }
  160. if err != nil {
  161. errMsg = err.Error()
  162. err = errors.New("查询用户购买产品出错")
  163. return
  164. }
  165. if companyProduct != nil {
  166. // 无FICC权限的客户不可见
  167. if companyProduct.CompanyProductID > 0 {
  168. // 已购或者试用用户可见
  169. if strings.Contains("永续,正式", companyProduct.Status) || (companyProduct.Status == "试用" && companyProduct.IsSuspend != 1) {
  170. productAuthOk = true
  171. }
  172. }
  173. }
  174. typeIds, err := report_chapter_type_cache.GetEffectTypeID()
  175. if err != nil {
  176. errMsg = err.Error()
  177. err = errors.New("章节类型查询出错")
  178. return
  179. }
  180. if len(typeIds) == 0 {
  181. err = errors.New("无有效的章节类型")
  182. return
  183. }
  184. reportChapter, err := report_chapter.GetItemById(reportChapterId)
  185. if err != nil {
  186. errMsg = err.Error()
  187. err = errors.New("章节查询出错")
  188. return
  189. }
  190. if reportChapter.ReportChapterId == 0 {
  191. err = errors.New("章节不存在")
  192. return
  193. }
  194. reportInfo, tErr := report.GetByReportId(reportChapter.ReportId)
  195. if tErr != nil {
  196. errMsg = tErr.Error()
  197. err = errors.New("报告查询出错")
  198. return
  199. }
  200. if reportInfo.Id == 0 {
  201. err = errors.New("报告不存在")
  202. return
  203. }
  204. if reportChapter.Author == `` {
  205. reportChapter.Author = reportInfo.Author
  206. }
  207. //if reportInfo.ClassifyNameFirst == "周报" && reportChapter.IsEdit != 1 {
  208. // err = errors.New("章节未编辑")
  209. // return
  210. //}
  211. //判断权限
  212. var newTypeIds []int
  213. var reportChapterIdList []int
  214. if reportInfo.ClassifyNameFirst == "晨报" {
  215. authOk, permissionCheckInfo, err = CheckDayReportPermission(user, productAuthOk)
  216. if err != nil && err != utils.ErrNoRow {
  217. errMsg = err.Error()
  218. err = errors.New("权限查询出错")
  219. return
  220. }
  221. } else {
  222. authOk, permissionCheckInfo, newTypeIds, reportChapterIdList, err = CheckWeekReportPermission(user, reportInfo.Id, productAuthOk)
  223. if err != nil && err != utils.ErrNoRow {
  224. errMsg = err.Error()
  225. err = errors.New("权限查询出错")
  226. return
  227. }
  228. for _, v := range reportChapterIdList {
  229. if v == reportChapter.ReportChapterId {
  230. chapterAuthOk = true
  231. }
  232. }
  233. authOk = chapterAuthOk
  234. }
  235. var chapterMenu []*response.ReportChapterMenu
  236. reportChapterItem := new(response.ReportChapterItem)
  237. reportChapterItem.ReportChapterId = reportChapter.ReportChapterId
  238. reportChapterItem.ReportId = reportChapter.ReportId
  239. reportChapterItem.Abstract = reportChapter.Abstract
  240. reportChapterItem.TypeId = reportChapter.TypeId
  241. reportChapterItem.Title = reportChapter.Title
  242. reportChapterItem.ReportId = reportChapter.ReportId
  243. reportChapterItem.PublishTime = reportChapter.PublishTime
  244. reportChapterItem.VideoPlaySeconds = reportChapter.VideoPlaySeconds
  245. reportChapterItem.VideoName = reportChapter.VideoName
  246. reportChapterItem.ReportLayout = reportChapter.ReportLayout
  247. reportChapterItem.HeadImg = reportInfo.HeadImg
  248. reportChapterItem.EndImg = reportInfo.EndImg
  249. reportChapterItem.CanvasColor = reportInfo.CanvasColor
  250. // 手工上传的才返回
  251. if reportInfo.VoiceGenerateType == 1 {
  252. reportChapterItem.ReportVideoUrl = reportInfo.VideoUrl
  253. }
  254. // 版头版尾样式
  255. {
  256. if reportInfo.HeadResourceId > 0 {
  257. headResource, tmpErr := smart_report_resource.GetResourceItemById(reportInfo.HeadResourceId)
  258. if tmpErr != nil {
  259. err = tmpErr
  260. return
  261. }
  262. reportChapterItem.HeadImg = headResource.ImgURL
  263. reportChapterItem.HeadStyle = headResource.Style
  264. }
  265. if reportInfo.EndResourceId > 0 {
  266. endResource, tmpErr := smart_report_resource.GetResourceItemById(reportInfo.EndResourceId)
  267. if tmpErr != nil {
  268. err = tmpErr
  269. return
  270. }
  271. reportChapterItem.EndImg = endResource.ImgURL
  272. reportChapterItem.EndStyle = endResource.Style
  273. }
  274. }
  275. if reportChapter.VideoUrl != "" && reportChapter.VideoName == "" {
  276. reportChapterItem.VideoName = reportChapter.Title
  277. }
  278. reportChapterItem.VideoSize = reportChapter.VideoSize
  279. videoImgMap := map[string]string{
  280. "day": "report_list_chen.png",
  281. "week": "report_list_zhou.png",
  282. }
  283. reportChapterItem.VideoImg = utils.ALIYUN_YBIMG_HOST + videoImgMap[reportChapter.ReportType]
  284. reportChapterItem.TypeName = reportChapter.TypeName
  285. reportChapterItem.Author = reportChapter.Author
  286. reportChapterItem.Stage = reportChapter.Stage
  287. reportChapterItem.ClassifyNameFirst = reportChapter.ClassifyNameFirst
  288. reportChapterItem.ClassifyIdFirst = reportChapter.ClassifyIdFirst
  289. // 分享背景图
  290. reportChapterItem.ShareBgImg = utils.DEFAULT_REPORT_SHARE_BG_IMG
  291. firstClassify, e := classify.GetByClassifyId(reportInfo.ClassifyIdFirst)
  292. if e != nil {
  293. err = errors.New("报告一级分类有误")
  294. return
  295. }
  296. if firstClassify.YbShareBgImg != "" {
  297. reportChapterItem.ShareBgImg = firstClassify.YbShareBgImg
  298. }
  299. var likeNum int64
  300. var likeEnabled int8
  301. if authOk {
  302. reportChapterItem.Content = html.UnescapeString(reportChapter.Content)
  303. reportChapterItem.VideoUrl = reportChapter.VideoUrl
  304. //底部菜单切换
  305. if reportInfo.ClassifyNameFirst == "周报" {
  306. chapterMenu, err = GetMenuChapter(reportInfo.Id, newTypeIds, reportInfo.ClassifyNameFirst, reportInfo.CreateTime)
  307. } else {
  308. chapterMenu, err = GetMenuChapter(reportInfo.Id, typeIds, reportInfo.ClassifyNameFirst, reportInfo.CreateTime)
  309. }
  310. //查询点赞数
  311. likeNum, likeEnabled, _ = services.GetReportLikeByReportIdOldReportId(user.UserID, reportInfo.Id, reportChapter.ReportChapterId, 0, 0)
  312. go AddViewRecord(user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId)
  313. } else {
  314. reportChapterItem.ContentSub = html.UnescapeString(reportChapter.ContentSub)
  315. }
  316. go AddUserAccessRecord(user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId, authOk)
  317. reportChapterDetail = new(response.ReportChapterDetail)
  318. reportChapterDetail.ReportChapterItem = reportChapterItem
  319. reportChapterDetail.PermissionCheck = &permissionCheckInfo
  320. reportChapterDetail.ReportChapterMenuList = chapterMenu
  321. reportChapterDetail.AuthOk = authOk
  322. reportChapterDetail.LikeNum = likeNum
  323. reportChapterDetail.LikeEnabled = likeEnabled
  324. // 收藏
  325. collectionId, e := collection.GetUserCollectByItem(int(user.UserID), collection.CollectionTypeReport, reportChapterItem.ReportId, reportChapterId)
  326. if e != nil {
  327. err = e
  328. return
  329. }
  330. reportChapterDetail.CollectionId = collectionId
  331. return
  332. }
  333. func GetMenuChapter(reportId int, typeIds []int, classifyNameFirst string, reportCreateTime time.Time) (reportTypeList response.ReportChapterMenuList, err error) {
  334. //查询有效的章节
  335. typeList, tErr := report_chapter_type.GetEffectTypes()
  336. if tErr != nil {
  337. return
  338. }
  339. if len(typeList) == 0 {
  340. err = errors.New("无有效的章节")
  341. return
  342. }
  343. typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
  344. for _, v := range typeList {
  345. typeMap[v.ReportChapterTypeId] = v
  346. }
  347. //获取所有当前研报的章节
  348. chapterList, tErr := report_chapter.GetListByReportIdTypeIds(reportId, typeIds, classifyNameFirst)
  349. if tErr != nil && tErr != utils.ErrNoRow {
  350. return
  351. }
  352. if len(chapterList) > 0 {
  353. for _, item := range chapterList {
  354. if typeItem, ok := typeMap[uint64(item.TypeId)]; ok {
  355. if reportCreateTime.Before(typeItem.PauseStartTime) || reportCreateTime.After(typeItem.PauseEndTime) {
  356. temp := new(response.ReportChapterMenu)
  357. temp.ReportChapterId = item.ReportChapterId
  358. temp.ReportId = item.ReportId
  359. temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
  360. temp.ReportChapterTypeThumb = typeItem.YbBottomIcon
  361. temp.Sort = typeItem.Sort
  362. temp.PcSelectedThumb = typeItem.PcSelectedImage
  363. temp.PcUnselectedThumb = typeItem.PcUnselectedImage
  364. reportTypeList = append(reportTypeList, temp)
  365. }
  366. }
  367. }
  368. }
  369. if len(reportTypeList) > 0 {
  370. sort.Sort(reportTypeList)
  371. }
  372. return
  373. }
  374. // CheckWeekReportPermission
  375. // @Description: 验证周报的权限(并获取拥有权限的章节id列表)
  376. // @author: Roc
  377. // @datetime 2024-06-24 11:06:52
  378. // @param userInfo user.UserInfo
  379. // @param reportId int
  380. // @param productAuthOk bool
  381. // @return authOk bool
  382. // @return permissionCheckInfo response.PermissionCheckInfo
  383. // @return validTypeIds []int 分类关联的章节类型ID列表
  384. // @return reportChapterIdList []int 并获取拥有权限的章节id列表
  385. // @return err error
  386. func CheckWeekReportPermission(userInfo user.UserInfo, reportId int, productAuthOk bool) (authOk bool, permissionCheckInfo response.PermissionCheckInfo, validTypeIds, reportChapterIdList []int, err error) {
  387. var permissionIds []int
  388. var validPermissionIds []int //最后允许显示的章节
  389. // 当前报告的品种与章节列表的map
  390. permissionChapterList := make(map[int][]int)
  391. permissionIdMap := make(map[int]bool)
  392. typeIdMap := make(map[int]bool)
  393. if productAuthOk {
  394. reportChapterMappingList, tmpErr := report_chapter_permission_mapping.GetReportChapterPermissionMappingItemListByReportId(reportId)
  395. if tmpErr != nil && errors.Is(tmpErr, utils.ErrNoRow) {
  396. return
  397. }
  398. for _, v := range reportChapterMappingList {
  399. if _, ok := permissionIdMap[v.ChartPermissionID]; !ok {
  400. permissionIdMap[v.ChartPermissionID] = true
  401. permissionIds = append(permissionIds, v.ChartPermissionID)
  402. }
  403. if _, ok := typeIdMap[v.TypeId]; !ok {
  404. typeIdMap[v.TypeId] = true
  405. validTypeIds = append(validTypeIds, v.TypeId)
  406. }
  407. tmpList, ok := permissionChapterList[v.ChartPermissionID]
  408. if !ok {
  409. tmpList = make([]int, 0)
  410. }
  411. permissionChapterList[v.ChartPermissionID] = append(tmpList, v.ReportChapterID)
  412. }
  413. }
  414. authOk, permissionCheckInfo, validPermissionIds, err = company.GetCheckPermission(userInfo.CompanyID, int(userInfo.UserID), permissionIds)
  415. if err != nil {
  416. return
  417. }
  418. //返回可用的章节列表
  419. if len(validPermissionIds) > 0 {
  420. reportChapterIdMap := make(map[int]bool)
  421. for _, v := range validPermissionIds {
  422. chapterIdList, ok := permissionChapterList[v]
  423. if !ok {
  424. continue
  425. }
  426. for _, chapterId := range chapterIdList {
  427. if _, ok := reportChapterIdMap[chapterId]; !ok {
  428. reportChapterIdMap[chapterId] = true
  429. reportChapterIdList = append(reportChapterIdList, chapterId)
  430. }
  431. }
  432. }
  433. }
  434. return
  435. }
  436. // CheckDayReportPermission 验证晨报的权限
  437. func CheckDayReportPermission(userInfo user.UserInfo, productAuthOk bool) (authOk bool, permissionCheckInfo response.PermissionCheckInfo, err error) {
  438. if productAuthOk {
  439. authOk = true
  440. return
  441. }
  442. authOk, permissionCheckInfo, _, err = company.GetCheckPermission(userInfo.CompanyID, int(userInfo.UserID), []int{})
  443. return
  444. }
  445. // GetReportChapterVideoList 根据报告获取章节的音频列表
  446. func GetReportChapterVideoList(permissionIds []int, classifyName string, list []*report.Report, userId uint64) (videoMap map[int][]*response.VideoListItem, weekAuthMap map[int]bool, errMsg string, err error) {
  447. videoMap = make(map[int][]*response.VideoListItem)
  448. weekAuthMap = make(map[int]bool)
  449. var reportIds []int
  450. reportMap := make(map[int]*report.Report)
  451. for _, reportInfo := range list {
  452. reportMap[reportInfo.Id] = reportInfo
  453. reportIds = append(reportIds, reportInfo.Id)
  454. }
  455. // 查询有效的章节
  456. //查询有效的章节
  457. typeList, tErr := report_chapter_type.GetEffectTypes()
  458. if tErr != nil {
  459. errMsg = tErr.Error()
  460. err = errors.New("章节类型查询出错")
  461. return
  462. }
  463. if len(typeList) == 0 {
  464. err = errors.New("无有效的章节")
  465. return
  466. }
  467. typeMap := make(map[int]*report_chapter_type.ReportChapterType)
  468. var typeIds []int
  469. typeIds = append(typeIds, 0)
  470. for _, v := range typeList {
  471. typeMap[int(v.ReportChapterTypeId)] = v
  472. typeIds = append(typeIds, int(v.ReportChapterTypeId))
  473. }
  474. var chapters []*report_chapter.ReportChapter
  475. setMap := make(map[int]int)
  476. if classifyName != "晨报" {
  477. // 查询用户有权限的章节列表
  478. chapters, err = report_chapter.GetByPermissionIdListAndReportList(permissionIds, reportIds)
  479. //获取音频设置章节
  480. setList, _ := user_report_chapter_set.GetUserReportChapterSet(userId)
  481. for _, v := range setList {
  482. if v.IsClose == 0 {
  483. setMap[v.TypeId] = v.TypeId
  484. }
  485. }
  486. } else {
  487. // 查询章节列表
  488. chapters, err = report_chapter.GetByTypeIdsAndReportIds(typeIds, reportIds, classifyName)
  489. }
  490. if err != nil {
  491. errMsg = err.Error()
  492. err = errors.New("查询章节出错")
  493. return
  494. }
  495. for _, v := range chapters {
  496. if classifyName != "晨报" {
  497. weekAuthMap[v.ReportId] = true
  498. }
  499. // 各种过滤条件
  500. {
  501. if v.VideoUrl == `` {
  502. continue
  503. }
  504. // 报告校验
  505. reportDetail, ok := reportMap[v.ReportId]
  506. if !ok { // 不是当前报告,那么过滤不处理
  507. continue
  508. }
  509. reportDate := reportDetail.CreateTime
  510. // 如果是系统配置的章节类型,那么需要额外校验时间
  511. if v.TypeId > 0 {
  512. // 如果不存在该类型的章节类型,那么就过滤,直接下一个循环
  513. temp, ok := typeMap[v.TypeId]
  514. if !ok {
  515. continue
  516. }
  517. // 如果晚于开始日期同时早于结束日期;或者等于开始日期;或者等于结束日期,那么就过滤,直接下一个循环
  518. if (reportDate.After(temp.PauseStartTime) && reportDate.Before(temp.PauseEndTime)) || reportDate.Equal(temp.PauseStartTime) || reportDate.Equal(temp.PauseEndTime) {
  519. continue
  520. }
  521. }
  522. if classifyName != "晨报" {
  523. if _, sok := setMap[v.TypeId]; !sok {
  524. continue
  525. }
  526. }
  527. }
  528. videoItem := new(response.VideoListItem)
  529. videoItem.VideoPlaySeconds = v.VideoPlaySeconds
  530. videoItem.VideoName = v.VideoName
  531. if v.VideoName == "" {
  532. videoItem.VideoName = v.Title
  533. }
  534. videoItem.VideoUrl = v.VideoUrl
  535. videoItem.Sort = v.Sort
  536. videoMap[v.ReportId] = append(videoMap[v.ReportId], videoItem)
  537. }
  538. return
  539. }
  540. // GetChapterListByReportChapterIdList
  541. // @Description: 根据报告获取章节列表
  542. // @author: Roc
  543. // @datetime 2024-06-24 11:23:36
  544. // @param classifyNameFirst string
  545. // @param reportId int
  546. // @param reportChapterIdList []int
  547. // @param reportCreateTime time.Time
  548. // @return reportTypeList response.ReportChapterList
  549. // @return err error
  550. func GetChapterListByReportChapterIdList(classifyNameFirst string, reportId int, reportChapterIdList []int) (reportTypeList response.ReportChapterList, err error) {
  551. var errMsg string
  552. defer func() {
  553. if err != nil {
  554. global.LOG.Critical(fmt.Sprintf("GetChapterListByReport: err:%s, errMsg:%s", err.Error(), errMsg))
  555. }
  556. }()
  557. //查询有效的章节
  558. typeList, tErr := report_chapter_type.GetEffectTypes()
  559. if tErr != nil {
  560. errMsg = tErr.Error()
  561. err = errors.New("章节类型查询出错")
  562. return
  563. }
  564. if len(typeList) == 0 {
  565. err = errors.New("无有效的章节")
  566. return
  567. }
  568. typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
  569. for _, v := range typeList {
  570. typeMap[v.ReportChapterTypeId] = v
  571. }
  572. var chapterList []*report_chapter.ReportChapter
  573. if len(reportChapterIdList) > 0 {
  574. //获取所有当前研报有权限的章节
  575. chapterList, tErr = report_chapter.GetListByChapterIds(reportChapterIdList)
  576. } else {
  577. // 获取所有报告章节
  578. chapterList, tErr = report_chapter.GetListByReportId(reportId, classifyNameFirst)
  579. }
  580. if tErr != nil && tErr != utils.ErrNoRow {
  581. errMsg = err.Error()
  582. err = errors.New("章节查询出错")
  583. return
  584. }
  585. if len(chapterList) == 0 {
  586. err = errors.New("无有效章节")
  587. return
  588. }
  589. for _, item := range chapterList {
  590. typeItem, ok1 := typeMap[uint64(item.TypeId)]
  591. // 如果是配置的章节,那么就需要判断是否禁用,如果禁用,则不展示
  592. if item.TypeId > 0 && !ok1 {
  593. continue
  594. }
  595. temp := new(response.ReportChapterListItem)
  596. temp.ReportChapterId = item.ReportChapterId
  597. temp.TypeId = item.TypeId
  598. temp.TypeName = item.TypeName
  599. temp.Title = item.Title
  600. temp.Trend = item.Trend
  601. temp.ReportId = item.ReportId
  602. temp.Sort = item.Sort
  603. temp.PublishTime = item.PublishTime
  604. temp.VideoUrl = item.VideoUrl
  605. temp.VideoName = item.VideoName
  606. temp.VideoPlaySeconds = item.VideoPlaySeconds
  607. temp.VideoSize = item.VideoSize
  608. temp.Content = item.Content
  609. // 系统配置的参数,只有配置的章节类型,才能赋值
  610. if typeItem != nil {
  611. temp.ReportChapterTypeKey = typeItem.ReportChapterTypeKey
  612. temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
  613. temp.ReportChapterTypeThumb = typeItem.YbIconUrl
  614. }
  615. reportTypeList = append(reportTypeList, temp)
  616. }
  617. if len(reportTypeList) > 0 {
  618. sort.Sort(reportTypeList)
  619. }
  620. return
  621. }