report_chapter.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  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. reportChapterItem.ReportVideoUrl = reportInfo.VideoUrl
  251. // 版头版尾样式
  252. {
  253. if reportInfo.HeadResourceId > 0 {
  254. headResource, tmpErr := smart_report_resource.GetResourceItemById(reportInfo.HeadResourceId)
  255. if tmpErr != nil {
  256. err = tmpErr
  257. return
  258. }
  259. reportChapterItem.HeadImg = headResource.ImgURL
  260. reportChapterItem.HeadStyle = headResource.Style
  261. }
  262. if reportInfo.EndResourceId > 0 {
  263. endResource, tmpErr := smart_report_resource.GetResourceItemById(reportInfo.EndResourceId)
  264. if tmpErr != nil {
  265. err = tmpErr
  266. return
  267. }
  268. reportChapterItem.EndImg = endResource.ImgURL
  269. reportChapterItem.EndStyle = endResource.Style
  270. }
  271. }
  272. if reportChapter.VideoUrl != "" && reportChapter.VideoName == "" {
  273. reportChapterItem.VideoName = reportChapter.Title
  274. }
  275. reportChapterItem.VideoSize = reportChapter.VideoSize
  276. videoImgMap := map[string]string{
  277. "day": "report_list_chen.png",
  278. "week": "report_list_zhou.png",
  279. }
  280. reportChapterItem.VideoImg = utils.ALIYUN_YBIMG_HOST + videoImgMap[reportChapter.ReportType]
  281. reportChapterItem.TypeName = reportChapter.TypeName
  282. reportChapterItem.Author = reportChapter.Author
  283. reportChapterItem.Stage = reportChapter.Stage
  284. reportChapterItem.ClassifyNameFirst = reportChapter.ClassifyNameFirst
  285. reportChapterItem.ClassifyIdFirst = reportChapter.ClassifyIdFirst
  286. // 分享背景图
  287. reportChapterItem.ShareBgImg = utils.DEFAULT_REPORT_SHARE_BG_IMG
  288. firstClassify, e := classify.GetByClassifyId(reportInfo.ClassifyIdFirst)
  289. if e != nil {
  290. err = errors.New("报告一级分类有误")
  291. return
  292. }
  293. if firstClassify.YbShareBgImg != "" {
  294. reportChapterItem.ShareBgImg = firstClassify.YbShareBgImg
  295. }
  296. var likeNum int64
  297. var likeEnabled int8
  298. if authOk {
  299. reportChapterItem.Content = html.UnescapeString(reportChapter.Content)
  300. reportChapterItem.VideoUrl = reportChapter.VideoUrl
  301. //底部菜单切换
  302. if reportInfo.ClassifyNameFirst == "周报" {
  303. chapterMenu, err = GetMenuChapter(reportInfo.Id, newTypeIds, reportInfo.ClassifyNameFirst, reportInfo.CreateTime)
  304. } else {
  305. chapterMenu, err = GetMenuChapter(reportInfo.Id, typeIds, reportInfo.ClassifyNameFirst, reportInfo.CreateTime)
  306. }
  307. //查询点赞数
  308. likeNum, likeEnabled, _ = services.GetReportLikeByReportIdOldReportId(user.UserID, reportInfo.Id, reportChapter.ReportChapterId, 0, 0)
  309. go AddViewRecord(user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId)
  310. } else {
  311. reportChapterItem.ContentSub = html.UnescapeString(reportChapter.ContentSub)
  312. }
  313. go AddUserAccessRecord(user, reportInfo.Id, reportInfo.ClassifyNameFirst, reportChapterId, authOk)
  314. reportChapterDetail = new(response.ReportChapterDetail)
  315. reportChapterDetail.ReportChapterItem = reportChapterItem
  316. reportChapterDetail.PermissionCheck = &permissionCheckInfo
  317. reportChapterDetail.ReportChapterMenuList = chapterMenu
  318. reportChapterDetail.AuthOk = authOk
  319. reportChapterDetail.LikeNum = likeNum
  320. reportChapterDetail.LikeEnabled = likeEnabled
  321. // 收藏
  322. collectionId, e := collection.GetUserCollectByItem(int(user.UserID), collection.CollectionTypeReport, reportChapterItem.ReportId, reportChapterId)
  323. if e != nil {
  324. err = e
  325. return
  326. }
  327. reportChapterDetail.CollectionId = collectionId
  328. return
  329. }
  330. func GetMenuChapter(reportId int, typeIds []int, classifyNameFirst string, reportCreateTime time.Time) (reportTypeList response.ReportChapterMenuList, err error) {
  331. //查询有效的章节
  332. typeList, tErr := report_chapter_type.GetEffectTypes()
  333. if tErr != nil {
  334. return
  335. }
  336. if len(typeList) == 0 {
  337. err = errors.New("无有效的章节")
  338. return
  339. }
  340. typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
  341. for _, v := range typeList {
  342. typeMap[v.ReportChapterTypeId] = v
  343. }
  344. //获取所有当前研报的章节
  345. chapterList, tErr := report_chapter.GetListByReportIdTypeIds(reportId, typeIds, classifyNameFirst)
  346. if tErr != nil && tErr != utils.ErrNoRow {
  347. return
  348. }
  349. if len(chapterList) > 0 {
  350. for _, item := range chapterList {
  351. if typeItem, ok := typeMap[uint64(item.TypeId)]; ok {
  352. if reportCreateTime.Before(typeItem.PauseStartTime) || reportCreateTime.After(typeItem.PauseEndTime) {
  353. temp := new(response.ReportChapterMenu)
  354. temp.ReportChapterId = item.ReportChapterId
  355. temp.ReportId = item.ReportId
  356. temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
  357. temp.ReportChapterTypeThumb = typeItem.YbBottomIcon
  358. temp.Sort = typeItem.Sort
  359. temp.PcSelectedThumb = typeItem.PcSelectedImage
  360. temp.PcUnselectedThumb = typeItem.PcUnselectedImage
  361. reportTypeList = append(reportTypeList, temp)
  362. }
  363. }
  364. }
  365. }
  366. if len(reportTypeList) > 0 {
  367. sort.Sort(reportTypeList)
  368. }
  369. return
  370. }
  371. // CheckWeekReportPermission
  372. // @Description: 验证周报的权限(并获取拥有权限的章节id列表)
  373. // @author: Roc
  374. // @datetime 2024-06-24 11:06:52
  375. // @param userInfo user.UserInfo
  376. // @param reportId int
  377. // @param productAuthOk bool
  378. // @return authOk bool
  379. // @return permissionCheckInfo response.PermissionCheckInfo
  380. // @return validTypeIds []int 分类关联的章节类型ID列表
  381. // @return reportChapterIdList []int 并获取拥有权限的章节id列表
  382. // @return err error
  383. func CheckWeekReportPermission(userInfo user.UserInfo, reportId int, productAuthOk bool) (authOk bool, permissionCheckInfo response.PermissionCheckInfo, validTypeIds, reportChapterIdList []int, err error) {
  384. var permissionIds []int
  385. var validPermissionIds []int //最后允许显示的章节
  386. // 当前报告的品种与章节列表的map
  387. permissionChapterList := make(map[int][]int)
  388. permissionIdMap := make(map[int]bool)
  389. typeIdMap := make(map[int]bool)
  390. if productAuthOk {
  391. reportChapterMappingList, tmpErr := report_chapter_permission_mapping.GetReportChapterPermissionMappingItemListByReportId(reportId)
  392. if tmpErr != nil && errors.Is(tmpErr, utils.ErrNoRow) {
  393. return
  394. }
  395. for _, v := range reportChapterMappingList {
  396. if _, ok := permissionIdMap[v.ChartPermissionID]; !ok {
  397. permissionIdMap[v.ChartPermissionID] = true
  398. permissionIds = append(permissionIds, v.ChartPermissionID)
  399. }
  400. if _, ok := typeIdMap[v.TypeId]; !ok {
  401. typeIdMap[v.TypeId] = true
  402. validTypeIds = append(validTypeIds, v.TypeId)
  403. }
  404. tmpList, ok := permissionChapterList[v.ChartPermissionID]
  405. if !ok {
  406. tmpList = make([]int, 0)
  407. }
  408. permissionChapterList[v.ChartPermissionID] = append(tmpList, v.ReportChapterID)
  409. }
  410. }
  411. authOk, permissionCheckInfo, validPermissionIds, err = company.GetCheckPermission(userInfo.CompanyID, int(userInfo.UserID), permissionIds)
  412. if err != nil {
  413. return
  414. }
  415. //返回可用的章节列表
  416. if len(validPermissionIds) > 0 {
  417. reportChapterIdMap := make(map[int]bool)
  418. for _, v := range validPermissionIds {
  419. chapterIdList, ok := permissionChapterList[v]
  420. if !ok {
  421. continue
  422. }
  423. for _, chapterId := range chapterIdList {
  424. if _, ok := reportChapterIdMap[chapterId]; !ok {
  425. reportChapterIdMap[chapterId] = true
  426. reportChapterIdList = append(reportChapterIdList, chapterId)
  427. }
  428. }
  429. }
  430. }
  431. return
  432. }
  433. // CheckDayReportPermission 验证晨报的权限
  434. func CheckDayReportPermission(userInfo user.UserInfo, productAuthOk bool) (authOk bool, permissionCheckInfo response.PermissionCheckInfo, err error) {
  435. if productAuthOk {
  436. authOk = true
  437. return
  438. }
  439. authOk, permissionCheckInfo, _, err = company.GetCheckPermission(userInfo.CompanyID, int(userInfo.UserID), []int{})
  440. return
  441. }
  442. // GetReportChapterVideoList 根据报告获取章节的音频列表
  443. func GetReportChapterVideoList(permissionIds []int, classifyName string, list []*report.Report, userId uint64) (videoMap map[int][]*response.VideoListItem, weekAuthMap map[int]bool, errMsg string, err error) {
  444. videoMap = make(map[int][]*response.VideoListItem)
  445. weekAuthMap = make(map[int]bool)
  446. var reportIds []int
  447. reportMap := make(map[int]*report.Report)
  448. for _, reportInfo := range list {
  449. reportMap[reportInfo.Id] = reportInfo
  450. reportIds = append(reportIds, reportInfo.Id)
  451. }
  452. // 查询有效的章节
  453. //查询有效的章节
  454. typeList, tErr := report_chapter_type.GetEffectTypes()
  455. if tErr != nil {
  456. errMsg = tErr.Error()
  457. err = errors.New("章节类型查询出错")
  458. return
  459. }
  460. if len(typeList) == 0 {
  461. err = errors.New("无有效的章节")
  462. return
  463. }
  464. typeMap := make(map[int]*report_chapter_type.ReportChapterType)
  465. var typeIds []int
  466. typeIds = append(typeIds, 0)
  467. for _, v := range typeList {
  468. typeMap[int(v.ReportChapterTypeId)] = v
  469. typeIds = append(typeIds, int(v.ReportChapterTypeId))
  470. }
  471. var chapters []*report_chapter.ReportChapter
  472. setMap := make(map[int]int)
  473. if classifyName != "晨报" {
  474. // 查询用户有权限的章节列表
  475. chapters, err = report_chapter.GetByPermissionIdListAndReportList(permissionIds, reportIds)
  476. //获取音频设置章节
  477. setList, _ := user_report_chapter_set.GetUserReportChapterSet(userId)
  478. for _, v := range setList {
  479. if v.IsClose == 0 {
  480. setMap[v.TypeId] = v.TypeId
  481. }
  482. }
  483. } else {
  484. // 查询章节列表
  485. chapters, err = report_chapter.GetByTypeIdsAndReportIds(typeIds, reportIds, classifyName)
  486. }
  487. if err != nil {
  488. errMsg = err.Error()
  489. err = errors.New("查询章节出错")
  490. return
  491. }
  492. for _, v := range chapters {
  493. if classifyName != "晨报" {
  494. weekAuthMap[v.ReportId] = true
  495. }
  496. // 各种过滤条件
  497. {
  498. if v.VideoUrl == `` {
  499. continue
  500. }
  501. // 报告校验
  502. reportDetail, ok := reportMap[v.ReportId]
  503. if !ok { // 不是当前报告,那么过滤不处理
  504. continue
  505. }
  506. reportDate := reportDetail.CreateTime
  507. // 如果是系统配置的章节类型,那么需要额外校验时间
  508. if v.TypeId > 0 {
  509. // 如果不存在该类型的章节类型,那么就过滤,直接下一个循环
  510. temp, ok := typeMap[v.TypeId]
  511. if !ok {
  512. continue
  513. }
  514. // 如果晚于开始日期同时早于结束日期;或者等于开始日期;或者等于结束日期,那么就过滤,直接下一个循环
  515. if (reportDate.After(temp.PauseStartTime) && reportDate.Before(temp.PauseEndTime)) || reportDate.Equal(temp.PauseStartTime) || reportDate.Equal(temp.PauseEndTime) {
  516. continue
  517. }
  518. }
  519. if classifyName != "晨报" {
  520. if _, sok := setMap[v.TypeId]; !sok {
  521. continue
  522. }
  523. }
  524. }
  525. videoItem := new(response.VideoListItem)
  526. videoItem.VideoPlaySeconds = v.VideoPlaySeconds
  527. videoItem.VideoName = v.VideoName
  528. if v.VideoName == "" {
  529. videoItem.VideoName = v.Title
  530. }
  531. videoItem.VideoUrl = v.VideoUrl
  532. videoItem.Sort = v.Sort
  533. videoMap[v.ReportId] = append(videoMap[v.ReportId], videoItem)
  534. }
  535. return
  536. }
  537. // GetChapterListByReportChapterIdList
  538. // @Description: 根据报告获取章节列表
  539. // @author: Roc
  540. // @datetime 2024-06-24 11:23:36
  541. // @param classifyNameFirst string
  542. // @param reportId int
  543. // @param reportChapterIdList []int
  544. // @param reportCreateTime time.Time
  545. // @return reportTypeList response.ReportChapterList
  546. // @return err error
  547. func GetChapterListByReportChapterIdList(classifyNameFirst string, reportId int, reportChapterIdList []int) (reportTypeList response.ReportChapterList, err error) {
  548. var errMsg string
  549. defer func() {
  550. if err != nil {
  551. global.LOG.Critical(fmt.Sprintf("GetChapterListByReport: err:%s, errMsg:%s", err.Error(), errMsg))
  552. }
  553. }()
  554. //查询有效的章节
  555. typeList, tErr := report_chapter_type.GetEffectTypes()
  556. if tErr != nil {
  557. errMsg = tErr.Error()
  558. err = errors.New("章节类型查询出错")
  559. return
  560. }
  561. if len(typeList) == 0 {
  562. err = errors.New("无有效的章节")
  563. return
  564. }
  565. typeMap := make(map[uint64]*report_chapter_type.ReportChapterType)
  566. for _, v := range typeList {
  567. typeMap[v.ReportChapterTypeId] = v
  568. }
  569. var chapterList []*report_chapter.ReportChapter
  570. if len(reportChapterIdList) > 0 {
  571. //获取所有当前研报有权限的章节
  572. chapterList, tErr = report_chapter.GetListByChapterIds(reportChapterIdList)
  573. } else {
  574. // 获取所有报告章节
  575. chapterList, tErr = report_chapter.GetListByReportId(reportId, classifyNameFirst)
  576. }
  577. if tErr != nil && tErr != utils.ErrNoRow {
  578. errMsg = err.Error()
  579. err = errors.New("章节查询出错")
  580. return
  581. }
  582. if len(chapterList) == 0 {
  583. err = errors.New("无有效章节")
  584. return
  585. }
  586. for _, item := range chapterList {
  587. typeItem, ok1 := typeMap[uint64(item.TypeId)]
  588. // 如果是配置的章节,那么就需要判断是否禁用,如果禁用,则不展示
  589. if item.TypeId > 0 && !ok1 {
  590. continue
  591. }
  592. temp := new(response.ReportChapterListItem)
  593. temp.ReportChapterId = item.ReportChapterId
  594. temp.TypeId = item.TypeId
  595. temp.TypeName = item.TypeName
  596. temp.Title = item.Title
  597. temp.Trend = item.Trend
  598. temp.ReportId = item.ReportId
  599. temp.Sort = item.Sort
  600. temp.PublishTime = item.PublishTime
  601. temp.VideoUrl = item.VideoUrl
  602. temp.VideoName = item.VideoName
  603. temp.VideoPlaySeconds = item.VideoPlaySeconds
  604. temp.VideoSize = item.VideoSize
  605. // 系统配置的参数,只有配置的章节类型,才能赋值
  606. if typeItem != nil {
  607. temp.ReportChapterTypeKey = typeItem.ReportChapterTypeKey
  608. temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
  609. temp.ReportChapterTypeThumb = typeItem.YbIconUrl
  610. }
  611. reportTypeList = append(reportTypeList, temp)
  612. }
  613. if len(reportTypeList) > 0 {
  614. sort.Sort(reportTypeList)
  615. }
  616. return
  617. }