ficc_reporrt.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/models/ficc_report"
  7. "hongze/hongze_clpt/utils"
  8. "html"
  9. "strings"
  10. )
  11. // GetMinClassify
  12. // @Description: 获取最小分类ID
  13. // @author: Roc
  14. // @datetime 2024-06-20 09:23:19
  15. // @param reportInfo *models.Report
  16. // @return minClassifyId int
  17. // @return minClassifyName string
  18. // @return err error
  19. func GetMinClassify(reportInfo *ficc_report.Report) (minClassifyId int, minClassifyName string, err error) {
  20. defer func() {
  21. if err != nil {
  22. go utils.SendAlarmMsg(fmt.Sprint("获取最小分类ID失败,报告ID:%d,Err:%s", reportInfo.Id, err.Error()), 2)
  23. }
  24. }()
  25. minClassifyId = reportInfo.ClassifyIdThird
  26. minClassifyName = reportInfo.ClassifyNameThird
  27. if minClassifyId <= 0 {
  28. minClassifyId = reportInfo.ClassifyIdSecond
  29. minClassifyName = reportInfo.ClassifyNameSecond
  30. }
  31. if minClassifyId <= 0 {
  32. minClassifyId = reportInfo.ClassifyIdFirst
  33. minClassifyName = reportInfo.ClassifyNameFirst
  34. }
  35. if minClassifyId <= 0 {
  36. err = errors.New("分类异常")
  37. }
  38. return
  39. }
  40. // CheckWeekReportPermission
  41. // @Description: 验证周报的权限(并获取拥有权限的章节id列表)
  42. // @author: Roc
  43. // @datetime 2024-06-24 11:06:52
  44. // @param userInfo user.UserInfo
  45. // @param reportId int
  46. // @param productAuthOk bool
  47. // @return authOk bool
  48. // @return permissionCheckInfo response.PermissionCheckInfo
  49. // @return validTypeIds []int 分类关联的章节类型ID列表
  50. // @return reportChapterIdList []int 并获取拥有权限的章节id列表
  51. // @return err error
  52. func CheckWeekReportPermission(userInfo *models.WxUserItem, reportId int, productAuthOk bool) (authOk bool, permissionCheckInfo ficc_report.PermissionCheckInfo, validTypeIds, reportChapterIdList []int, err error) {
  53. var permissionIds []int
  54. //var validPermissionIds []int //最后允许显示的章节
  55. // 当前报告的品种与章节列表的map
  56. permissionChapterList := make(map[int][]int)
  57. permissionIdMap := make(map[int]bool)
  58. typeIdMap := make(map[int]bool)
  59. reportChapterIdMap := make(map[int]bool)
  60. if productAuthOk {
  61. reportChapterMappingList, e := ficc_report.GetReportChapterPermissionMappingItemListByReportId(reportId)
  62. if e != nil && e.Error() != utils.ErrNoRow() {
  63. err = errors.New(e.Error())
  64. return
  65. }
  66. for _, v := range reportChapterMappingList {
  67. if _, ok := permissionIdMap[v.ChartPermissionId]; !ok {
  68. permissionIdMap[v.ChartPermissionId] = true
  69. permissionIds = append(permissionIds, v.ChartPermissionId)
  70. }
  71. if _, ok := typeIdMap[v.TypeId]; !ok {
  72. typeIdMap[v.TypeId] = true
  73. validTypeIds = append(validTypeIds, v.TypeId)
  74. }
  75. tmpList, ok := permissionChapterList[v.ChartPermissionId]
  76. if !ok {
  77. tmpList = make([]int, 0)
  78. }
  79. permissionChapterList[v.ChartPermissionId] = append(tmpList, v.ReportChapterId)
  80. if _, ok := reportChapterIdMap[v.ReportChapterId]; !ok {
  81. reportChapterIdMap[v.ReportChapterId] = true
  82. reportChapterIdList = append(reportChapterIdList, v.ReportChapterId) //走权益的校验权限,到这里的权限都可以用
  83. }
  84. }
  85. }
  86. return
  87. }
  88. // GetChapterListByReportChapterIdList
  89. // @Description: 根据报告获取章节列表
  90. // @author: Roc
  91. // @datetime 2024-06-24 11:23:36
  92. // @param classifyNameFirst string
  93. // @param reportId int
  94. // @param reportChapterIdList []int
  95. // @param reportCreateTime time.Time
  96. // @return reportTypeList response.ReportChapterList
  97. // @return err error
  98. func GetChapterListByReportChapterIdList(classifyNameFirst string, reportId int, reportChapterIdList []int) (reportTypeList ficc_report.ReportChapterList, err error) {
  99. var errMsg string
  100. defer func() {
  101. if err != nil {
  102. go utils.SendAlarmMsg(fmt.Sprintf("GetChapterListByReport: err:%s, errMsg:%s", err.Error(), errMsg), 2)
  103. }
  104. }()
  105. //查询有效的章节
  106. typeList, e := ficc_report.GetEffectTypes()
  107. if e != nil {
  108. err = errors.New("章节类型查询出错" + e.Error())
  109. return
  110. }
  111. if len(typeList) == 0 {
  112. err = errors.New("无有效的章节")
  113. return
  114. }
  115. typeMap := make(map[uint64]*ficc_report.ReportChapterType)
  116. for _, v := range typeList {
  117. typeMap[v.ReportChapterTypeId] = v
  118. }
  119. var chapterList []*ficc_report.ReportChapter
  120. if len(reportChapterIdList) > 0 {
  121. //获取所有当前研报有权限的章节
  122. chapterList, e = ficc_report.GetListByChapterIds(reportChapterIdList)
  123. } else {
  124. // 获取所有报告章节
  125. chapterList, e = ficc_report.GetListByReportId(reportId, classifyNameFirst)
  126. }
  127. if e != nil && e.Error() != utils.ErrNoRow() {
  128. err = errors.New("章节查询出错" + e.Error())
  129. return
  130. }
  131. if len(chapterList) == 0 {
  132. err = errors.New("无有效章节")
  133. return
  134. }
  135. for _, item := range chapterList {
  136. typeItem, ok1 := typeMap[uint64(item.TypeId)]
  137. // 如果是配置的章节,那么就需要判断是否禁用,如果禁用,则不展示
  138. if item.TypeId > 0 && !ok1 {
  139. continue
  140. }
  141. temp := new(ficc_report.ReportChapterListItem)
  142. temp.ReportChapterId = item.ReportChapterId
  143. temp.TypeId = item.TypeId
  144. temp.TypeName = item.TypeName
  145. temp.Title = item.Title
  146. temp.Trend = item.Trend
  147. temp.ReportId = item.ReportId
  148. temp.Sort = item.Sort
  149. temp.PublishTime = item.PublishTime
  150. temp.VideoUrl = item.VideoUrl
  151. temp.VideoName = item.VideoName
  152. temp.VideoPlaySeconds = item.VideoPlaySeconds
  153. temp.VideoSize = item.VideoSize
  154. temp.Content = item.Content
  155. // 系统配置的参数,只有配置的章节类型,才能赋值
  156. if typeItem != nil {
  157. temp.ReportChapterTypeKey = typeItem.ReportChapterTypeKey
  158. temp.ReportChapterTypeName = typeItem.ReportChapterTypeName
  159. temp.ReportChapterTypeThumb = typeItem.YbIconUrl
  160. }
  161. reportTypeList = append(reportTypeList, temp)
  162. }
  163. //if len(reportTypeList) > 0 {
  164. // sort.Sort(reportTypeList)
  165. //}
  166. return
  167. }
  168. // 获取报告详情
  169. func GetReportDetail(userinfo *models.WxUserItem, reportId int) (reportDetail ficc_report.ReportDetail, err error) {
  170. //var errMsg string
  171. defer func() {
  172. if err != nil {
  173. fmt.Println(err)
  174. go utils.SendAlarmMsg(fmt.Sprint("获取研报详情失败 GetFiccYbDetailByApi ,err:", err.Error(), "ReportId:", reportId), 2)
  175. }
  176. }()
  177. detailArticle, e := models.GetArticleDetailByReportId(reportId)
  178. if e != nil {
  179. err = errors.New("报告查询出错" + e.Error())
  180. return
  181. }
  182. reportInfo, e := ficc_report.GetByReportId(reportId)
  183. if e != nil {
  184. //errMsg = err.Error()
  185. err = errors.New("报告查询出错" + e.Error())
  186. return
  187. }
  188. if reportInfo.Id == 0 {
  189. err = errors.New("报告不存在")
  190. return
  191. }
  192. if reportInfo.State != 2 && reportInfo.State != 6 {
  193. err = errors.New("报告未发布")
  194. return
  195. }
  196. // 获取最小分类
  197. minClassifyId, _, err := GetMinClassify(reportInfo)
  198. // 判断报告是否属于专栏报告
  199. firstClassify, e := ficc_report.GetByClassifyId(reportInfo.ClassifyIdFirst)
  200. if e != nil {
  201. err = errors.New("报告一级分类有误")
  202. return
  203. }
  204. // 最小分类
  205. var minClassify *ficc_report.Classify
  206. if reportInfo.ClassifyIdFirst == minClassifyId {
  207. minClassify = firstClassify
  208. } else {
  209. minClassify, e = ficc_report.GetByClassifyId(minClassifyId)
  210. if e != nil {
  211. err = errors.New("报告最小层级分类有误")
  212. return
  213. }
  214. }
  215. var hasPermission int
  216. var hasPower bool
  217. if userinfo.CompanyId > 1 {
  218. companyPermission, e := models.GetCompanyPermission(userinfo.CompanyId)
  219. if e != nil {
  220. err = errors.New("GetCompanyPermission")
  221. return
  222. }
  223. if companyPermission != "" {
  224. slice := strings.Split(companyPermission, ",")
  225. if utils.InArrayByStr(slice, "周期") {
  226. hasPower = true
  227. }
  228. }
  229. }
  230. if hasPower {
  231. hasPermission = 1
  232. } else {
  233. //hasPermission, e = GetUserPermissionCode(userinfo.UserId, userinfo.CompanyId)
  234. //if e != nil {
  235. // err = errors.New("GetUserPermissionCode")
  236. // return
  237. //}
  238. reportDetail.SellerName, reportDetail.SellerMobile, _ = GetSellerName(userinfo)
  239. applyCount, e := models.GetApplyRecordCount(userinfo.UserId)
  240. if e != nil {
  241. err = errors.New("GetApplyRecordCount")
  242. return
  243. }
  244. if userinfo.CompanyId > 1 {
  245. companyPermission, e := models.GetCompanyPermission(userinfo.CompanyId)
  246. if e != nil {
  247. err = errors.New("GetCompanyPermission")
  248. return
  249. }
  250. if companyPermission == "" {
  251. if applyCount > 0 {
  252. hasPermission = 6
  253. } else {
  254. hasPermission = 2
  255. }
  256. } else {
  257. if applyCount == 0 {
  258. hasPermission = 4
  259. } else {
  260. hasPermission = 3
  261. }
  262. }
  263. } else { //潜在客户
  264. if applyCount > 0 {
  265. hasPermission = 6
  266. } else {
  267. hasPermission = 5
  268. }
  269. }
  270. }
  271. reportDetail.HasPermission = hasPermission
  272. //判断权限
  273. var authOk bool
  274. var reportChapterIdList []int
  275. if reportInfo.HasChapter == 1 {
  276. if reportInfo.ClassifyNameFirst == "晨报" {
  277. //authOk, permissionCheckInfo, err = CheckDayReportPermission(userinfo, productAuthOk)
  278. } else {
  279. _, _, _, reportChapterIdList, err = CheckWeekReportPermission(userinfo, reportId, true)
  280. }
  281. }
  282. if hasPermission == 1 {
  283. authOk = true
  284. }
  285. reportItem := new(ficc_report.ReportItem)
  286. reportItem.ReportId = reportInfo.Id
  287. reportItem.Title = reportInfo.Title
  288. reportItem.PublishTime = reportInfo.PublishTime
  289. reportItem.ClassifyNameFirst = reportInfo.ClassifyNameFirst
  290. reportItem.ClassifyNameSecond = reportInfo.ClassifyNameSecond
  291. reportItem.Stage = reportInfo.Stage
  292. reportItem.Abstract = reportInfo.Abstract
  293. reportItem.ContentSub = html.UnescapeString(reportInfo.ContentSub)
  294. reportItem.Frequency = reportInfo.Frequency
  295. reportItem.VideoName = reportInfo.VideoName
  296. reportItem.HasChapter = reportInfo.HasChapter
  297. reportItem.ReportLayout = reportInfo.ReportLayout
  298. reportItem.HeadImg = reportInfo.HeadImg
  299. reportItem.EndImg = reportInfo.EndImg
  300. reportItem.CanvasColor = reportInfo.CanvasColor
  301. reportItem.ArticleId = detailArticle.ArticleId
  302. reportItem.Disclaimer = GetConfigCodeDisclaimer()
  303. if reportInfo.ClassifyNameFirst == "晨会纪要" && reportInfo.ClassifyNameSecond == "晨会纪要" {
  304. reportItem.Title = "FICC/周期品晨会纪要"
  305. }
  306. //版头版尾样式
  307. {
  308. if reportInfo.HeadResourceId > 0 {
  309. headResource, tmpErr := ficc_report.GetResourceItemById(reportInfo.HeadResourceId)
  310. if tmpErr != nil {
  311. err = tmpErr
  312. return
  313. }
  314. reportItem.HeadImg = headResource.ImgURL
  315. reportItem.HeadStyle = headResource.Style
  316. }
  317. if reportInfo.EndResourceId > 0 {
  318. endResource, tmpErr := ficc_report.GetResourceItemById(reportInfo.EndResourceId)
  319. if tmpErr != nil {
  320. err = tmpErr
  321. return
  322. }
  323. reportItem.EndImg = endResource.ImgURL
  324. reportItem.EndStyle = endResource.Style
  325. }
  326. }
  327. if reportInfo.VideoName == "" && reportInfo.VideoUrl != "" {
  328. reportItem.VideoName = reportInfo.Title
  329. }
  330. reportItem.VideoSize = reportInfo.VideoSize
  331. reportItem.VideoPlaySeconds = reportInfo.VideoPlaySeconds
  332. reportItem.Author = reportInfo.Author
  333. // 分享背景图取二级分类配图, 二级没有配图时使用一级配图, 一级也没有使用默认图
  334. reportItem.ShareBgImg = utils.DEFAULT_REPORT_SHARE_BG_IMG
  335. secondClassify, e := ficc_report.GetByClassifyId(reportInfo.ClassifyIdSecond)
  336. if e != nil {
  337. err = errors.New("报告二级分类有误")
  338. return
  339. }
  340. if secondClassify.YbShareBgImg != "" {
  341. reportItem.ShareBgImg = secondClassify.YbShareBgImg
  342. } else {
  343. if firstClassify.YbShareBgImg != "" {
  344. reportItem.ShareBgImg = firstClassify.YbShareBgImg
  345. }
  346. }
  347. var reportTypeList []*ficc_report.ReportChapterListItem
  348. if reportInfo.HasChapter == 1 {
  349. //(晨报和周报的banner图)
  350. if reportInfo.ClassifyNameFirst == "晨报" {
  351. reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_day.jpg"
  352. } else {
  353. reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_week.jpg"
  354. }
  355. // 如果还没有配置banner图,则取晨报的
  356. if reportItem.BannerUrl == `` {
  357. reportItem.BannerUrl = utils.ALIYUN_YBIMG_HOST + "report_banner_day.jpg"
  358. }
  359. if authOk {
  360. reportTypeList, err = GetChapterListByReportChapterIdList(reportInfo.ClassifyNameFirst, reportInfo.Id, reportChapterIdList)
  361. if err != nil {
  362. return
  363. }
  364. }
  365. } else {
  366. // 音频播放条图片用分类图片
  367. //reportItem.VideoImg = utils.HZ_DEFAULT_AVATAR
  368. //permissionIds, tmpErr := chart_permission_search_key_word_mapping.GetChartPermissionIdsByKeyWord(reportInfo.ClassifyIdSecond)
  369. //if tmpErr != nil {
  370. // errMsg = tmpErr.Error()
  371. // err = errors.New("查询报告权限失败")
  372. // return
  373. //}
  374. //if len(permissionIds) > 0 {
  375. // chartPermission, tmpErr := chart_permission.GetListByIds(permissionIds)
  376. // if tmpErr != nil {
  377. // errMsg = tmpErr.Error()
  378. // err = errors.New("查询品种信息失败")
  379. // return
  380. // }
  381. // lenChart := len(chartPermission)
  382. // for i := 0; i < lenChart; i++ {
  383. // if chartPermission[i].YbImgUrl != "" {
  384. // reportItem.VideoImg = utils.ALIYUN_YBIMG_HOST + chartPermission[i].YbImgUrl
  385. // break
  386. // }
  387. // }
  388. //}
  389. }
  390. //如果有权限则展示content
  391. if authOk {
  392. reportItem.Content = html.UnescapeString(reportInfo.Content)
  393. reportItem.VideoUrl = reportInfo.VideoUrl
  394. }
  395. reportDetail.ReportInfo = reportItem
  396. reportDetail.ReportChapterList = reportTypeList
  397. //reportDetail.PermissionCheck = &permissionCheckInfo
  398. reportDetail.AuthOk = authOk
  399. //reportDetail.LikeNum = likeNum
  400. //reportDetail.LikeEnabled = likeEnabled
  401. reportDetail.ReportShowType = int(firstClassify.ShowType)
  402. reportDetail.ReportDetailShowType = int(minClassify.ReportDetailShowType)
  403. // 如果分类配置是列表展示,那么就移除content内容
  404. if minClassify.ReportDetailShowType == 2 {
  405. for _, v := range reportTypeList {
  406. v.Content = ``
  407. }
  408. } else {
  409. for _, v := range reportTypeList {
  410. v.Content = html.UnescapeString(v.Content)
  411. }
  412. }
  413. return
  414. }