report_chapter.go 21 KB

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