report_billboard.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/services"
  6. "hongze/hongze_cygx/utils"
  7. "time"
  8. )
  9. // 报告榜单
  10. type ReportBillboardController struct {
  11. BaseAuthController
  12. }
  13. // @Title 报告榜单table栏
  14. // @Description 报告榜单table栏
  15. // @Success 200 {object} models.ReportBillboardTableListResp
  16. // @router /table/list [get]
  17. func (this *ReportBillboardController) CompanyTableList() {
  18. br := new(models.BaseResponse).Init()
  19. defer func() {
  20. this.Data["json"] = br
  21. this.ServeJSON()
  22. }()
  23. user := this.User
  24. if user == nil {
  25. br.Msg = "请重新登录"
  26. br.Ret = 408
  27. return
  28. }
  29. ListPermission := []*models.ChartPermission{{PermissionName: utils.YI_YAO_NAME, ChartPermissionId: utils.YI_YAO_ID}, {PermissionName: utils.XIAO_FEI_NAME, ChartPermissionId: utils.XIAO_FEI_ID}, {PermissionName: utils.KE_JI_NAME, ChartPermissionId: utils.KE_JI_ID}, {PermissionName: utils.ZHI_ZAO_NAME, ChartPermissionId: utils.ZHI_ZAO_ID}}
  30. ListAllPermission := []*models.ChartPermission{{PermissionName: utils.YI_YAO_NAME, ChartPermissionId: utils.YI_YAO_ID}, {PermissionName: utils.XIAO_FEI_NAME, ChartPermissionId: utils.XIAO_FEI_ID}, {PermissionName: utils.KE_JI_NAME, ChartPermissionId: utils.KE_JI_ID}, {PermissionName: utils.ZHI_ZAO_NAME, ChartPermissionId: utils.ZHI_ZAO_ID}, {PermissionName: utils.CE_LUE_NAME, ChartPermissionId: utils.CE_LUE_ID}}
  31. List := []*models.ReportBillboardTableResp{{Name: "产业关注榜", Source: 1, List: ListPermission}, {Name: "阅读飙升榜", Source: 2, List: ListAllPermission}, {Name: "报告收藏榜", Source: 3, List: ListAllPermission}}
  32. resp := new(models.ReportBillboardTableListResp)
  33. resp.List = List
  34. br.Ret = 200
  35. br.Success = true
  36. br.Msg = "获取成功"
  37. br.Data = resp
  38. }
  39. // @Title 产业关注榜
  40. // @Description 获取产业关注榜接口
  41. // @Param ChartPermissionId query int false "行业ID"
  42. // @Success 200 {object} models.IndustrialManagementList
  43. // @router /industry/fllowList [get]
  44. func (this *ReportBillboardController) FllowList() {
  45. br := new(models.BaseResponse).Init()
  46. defer func() {
  47. this.Data["json"] = br
  48. this.ServeJSON()
  49. }()
  50. user := this.User
  51. if user == nil {
  52. br.Msg = "请重新登录"
  53. br.Ret = 408
  54. return
  55. }
  56. uid := user.UserId
  57. // 行业ID暂时不需要了调整为非必填
  58. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  59. // 查询有已归类行业报告的行业IDs
  60. activeIndustryIds, e := models.GetActiveArticleIndustryIds()
  61. if e != nil {
  62. br.Msg = "获取失败"
  63. br.ErrMsg = "获取已归类行业失败, Err:" + e.Error()
  64. return
  65. }
  66. activeIndustryLen := len(activeIndustryIds)
  67. topNum := utils.PageSize15
  68. var condition, subCond string
  69. var pars, subPars []interface{}
  70. if chartPermissionId > 0 {
  71. condition += ` AND man.chart_permission_id = ? `
  72. pars = append(pars, chartPermissionId)
  73. }
  74. if activeIndustryLen > 0 {
  75. condition += ` AND man.industrial_management_id IN (` + utils.GetOrmInReplace(activeIndustryLen) + `)`
  76. pars = append(pars, activeIndustryIds)
  77. }
  78. //nowTime := time.Now().Local()
  79. //startTime := nowTime.AddDate(0, -1, 0)
  80. //endTime := nowTime.AddDate(0, 0, -1)
  81. //condition += ` AND idf.create_time BETWEEN ? AND ?`
  82. //pars = append(pars, startTime, endTime)
  83. // 查询近一个月至昨日关注度最高的15个产业(不再指定行业, chartPermissionId可筛选行业)
  84. list, e := models.GetTopIndustryFollowData(0, topNum, condition, pars)
  85. if e != nil {
  86. br.Msg = "获取失败"
  87. br.ErrMsg = "获取关注度最高的产业数据失败, Err:" + e.Error()
  88. return
  89. }
  90. industryIdArr := make([]int, 0)
  91. for i := range list {
  92. industryIdArr = append(industryIdArr, list[i].IndustrialManagementId)
  93. }
  94. idsLen := len(industryIdArr)
  95. // 查询当前用户关注的产业
  96. followList, err := models.GetUserFllowIndustrialList(uid)
  97. if err != nil {
  98. br.Msg = "获取失败"
  99. br.ErrMsg = "获取失败,GetUserFllowIndustrialList Err:" + err.Error()
  100. return
  101. }
  102. followMap := make(map[int]int, 0)
  103. for i := range followList {
  104. followMap[followList[i].IndustrialManagementId] = 1
  105. }
  106. // 查询产业标的
  107. if idsLen > 0 {
  108. subCond = `AND s.industrial_management_id IN ( ` + utils.GetOrmInReplace(idsLen) + ` ) `
  109. subPars = append(subPars, industryIdArr)
  110. }
  111. subjectList, err := models.GetSubjectList(subPars, subCond)
  112. if err != nil {
  113. br.Msg = "获取失败"
  114. br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
  115. return
  116. }
  117. subjectMap := make(map[int][]*models.IndustrialSubject)
  118. for i := range subjectList {
  119. item := new(models.IndustrialSubject)
  120. item.SubjectName = subjectList[i].SubjectName
  121. item.IndustrialManagementId = subjectList[i].IndustrialManagementId
  122. subjectMap[subjectList[i].IndustrialManagementId] = append(subjectMap[subjectList[i].IndustrialManagementId], item)
  123. }
  124. // 查询行业
  125. permissionList, e := models.GetChartPermissionAll("")
  126. if e != nil {
  127. br.Msg = "获取失败"
  128. br.ErrMsg = "获取行业信息失败, Err: " + e.Error()
  129. return
  130. }
  131. permissionMap := make(map[int]string, 0)
  132. for i := range permissionList {
  133. permissionMap[permissionList[i].ChartPermissionId] = permissionList[i].PermissionName
  134. }
  135. for k, v := range list {
  136. list[k].IsFollow = followMap[v.IndustrialManagementId]
  137. list[k].IndustrialSubjectList = subjectMap[v.IndustrialManagementId]
  138. list[k].PermissionName = permissionMap[v.ChartPermissionId]
  139. }
  140. //查询产业视频
  141. industrialVideoMap := make(map[int]*models.MicroVideoSimpleInfo)
  142. var industrialManagementIds []int
  143. for _, v := range list {
  144. if v.IndustrialManagementId > 0 {
  145. industrialManagementIds = append(industrialManagementIds, v.IndustrialManagementId)
  146. }
  147. }
  148. // 用户权限
  149. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  150. if e != nil {
  151. br.Msg = "获取失败"
  152. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  153. return
  154. }
  155. mapUPdateTime := make(map[int]string)
  156. if len(industrialManagementIds) > 0 {
  157. // 获取默认图配置
  158. _, videoMap, _, _, e := services.GetMicroRoadShowDefaultImgConfig()
  159. if e != nil {
  160. br.Msg = "获取视频默认配置图失败"
  161. br.ErrMsg = "获取视频默认配置图失败, Err: " + e.Error()
  162. return
  163. }
  164. videoList, err := models.GetMicroRoadshowVideoByIndustryIds(industrialManagementIds)
  165. if err != nil {
  166. br.Msg = "产业视频列表失败"
  167. br.ErrMsg = "产业视频列表失败, Err: " + err.Error()
  168. return
  169. }
  170. for _, v := range videoList {
  171. tmp := &models.MicroVideoSimpleInfo{
  172. Id: v.VideoId,
  173. Title: "5min逻辑【" + v.IndustryName + "】解析",
  174. ResourceUrl: v.VideoUrl,
  175. BackgroundImg: v.ImgUrl,
  176. PlaySeconds: v.VideoDuration,
  177. DetailImgUrl: v.DetailImgUrl,
  178. ChartPermissionId: v.ChartPermissionId,
  179. ChartPermissionName: v.ChartPermissionName,
  180. }
  181. if tmp.BackgroundImg == "" {
  182. tmp.BackgroundImg = videoMap[v.ChartPermissionId]
  183. }
  184. industrialVideoMap[v.IndustryId] = tmp
  185. }
  186. //获取这些产业下最新更新的文章
  187. listUpdateTime, err := models.GetNewArticleDetailByIndustrialIds(industrialManagementIds)
  188. if err != nil && err.Error() != utils.ErrNoRow() {
  189. return
  190. }
  191. for _, v := range listUpdateTime {
  192. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  193. }
  194. //时间线的更新时间
  195. // maptimelineUPdateTime := make(map[int]string)
  196. listtimelinePublishdate, err := models.GetTimeLineReportIndustrialPublishdateList(industrialManagementIds)
  197. if err != nil && err.Error() != utils.ErrNoRow() {
  198. return
  199. }
  200. for _, v := range listtimelinePublishdate {
  201. if mapUPdateTime[v.IndustrialManagementId] != "" {
  202. if utils.StrTimeToTime(v.PublishDate).After(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  203. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  204. }
  205. }
  206. }
  207. }
  208. for k, v := range list {
  209. //展示产业视频
  210. if video, ok := industrialVideoMap[v.IndustrialManagementId]; ok {
  211. //控制用户权限
  212. // 权限
  213. au := new(models.UserPermissionAuthInfo)
  214. au.SellerName = authInfo.SellerName
  215. au.SellerMobile = authInfo.SellerMobile
  216. au.HasPermission = authInfo.HasPermission
  217. au.OperationMode = authInfo.OperationMode
  218. if au.HasPermission == 1 {
  219. // 非宏观权限进一步判断是否有权限
  220. if video.ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, video.ChartPermissionName) {
  221. au.HasPermission = 2
  222. }
  223. }
  224. // 无权限的弹框提示
  225. if au.HasPermission != 1 {
  226. if au.OperationMode == services.UserPermissionOperationModeCall {
  227. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  228. } else {
  229. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  230. }
  231. video.ResourceUrl = ""
  232. }
  233. list[k].AuthInfo = au
  234. list[k].IndustryVideo = video
  235. }
  236. }
  237. page := paging.GetPaging(1, topNum, len(list))
  238. resp := new(models.IndustrialManagementList)
  239. resp.List = list
  240. resp.Paging = page
  241. br.Ret = 200
  242. br.Success = true
  243. br.Msg = "获取成功"
  244. br.Data = resp
  245. }
  246. // @Title 阅读飙升榜/报告收藏榜
  247. // @Description 获取阅读飙升榜/报告收藏榜接口
  248. // @Param ChartPermissionId query int false "分类ID"
  249. // @Param Source query int true "来源 2:阅读飙升 ,3:报告收藏"
  250. // @Success 200 {object} models.ArticleReportBillboardLIstResp
  251. // @router /industry/readList [get]
  252. func (this *ReportBillboardController) ReadList() {
  253. br := new(models.BaseResponse).Init()
  254. defer func() {
  255. this.Data["json"] = br
  256. this.ServeJSON()
  257. }()
  258. user := this.User
  259. if user == nil {
  260. br.Msg = "请重新登录"
  261. br.Ret = 408
  262. return
  263. }
  264. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  265. source, _ := this.GetInt("Source")
  266. sourceArr := []int{2, 3}
  267. if !utils.InArrayByInt(sourceArr, source) {
  268. br.Msg = "来源有误"
  269. return
  270. }
  271. topNum := utils.PageSize15
  272. list := make([]*models.ArticleReportBillboardResp, 0)
  273. // 阅读飙升榜
  274. if source == 2 {
  275. var topCond string
  276. var topPars []interface{}
  277. if chartPermissionId > 0 {
  278. topCond += ` AND chart_permission_id = ?`
  279. topPars = append(topPars, chartPermissionId)
  280. }
  281. topList, e := models.GetTopReadRecordArticleListByCondition(topNum, topCond, topPars)
  282. if e != nil {
  283. br.Msg = "获取失败"
  284. br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + e.Error()
  285. return
  286. }
  287. for i := range topList {
  288. list = append(list, &models.ArticleReportBillboardResp{
  289. ArticleId: topList[i].ArticleId,
  290. Title: topList[i].Title,
  291. PublishDate: topList[i].PublishDate,
  292. PermissionName: topList[i].PermissionName,
  293. })
  294. }
  295. }
  296. // 报告收藏榜
  297. if source == 3 {
  298. var collectCond string
  299. var collectPars []interface{}
  300. if chartPermissionId > 0 {
  301. collectCond += ` AND m.chart_permission_id = ?`
  302. collectPars = append(collectPars, chartPermissionId)
  303. }
  304. // 根据关注时间一个月前至昨日的增量数据排序
  305. nowTime := time.Now().Local()
  306. startTime := nowTime.AddDate(0, -1, 0)
  307. endTime := nowTime.AddDate(0, 0, -1)
  308. collectCond += ` AND ac.create_time BETWEEN ? AND ?`
  309. collectPars = append(collectPars, startTime, endTime)
  310. collectList, e := models.GetReportCollectionBillboardList(topNum, collectPars, collectCond)
  311. if e != nil {
  312. br.Msg = "获取失败"
  313. br.ErrMsg = "获取报告收藏排行榜失败, Err:" + e.Error()
  314. return
  315. }
  316. list = collectList
  317. }
  318. articleIds := make([]int, 0)
  319. for i := range list {
  320. articleIds = append(articleIds, list[i].ArticleId)
  321. }
  322. articleMapPv := services.GetArticleHistoryByArticleId(articleIds) //文章Pv
  323. articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId) //用户收藏的文章
  324. articleCollectNumMap, _ := services.GetCygxArticleCollectNumMapByArtcileIds(articleIds) //文章收藏的数量
  325. // 报告关联产业信息
  326. industryMap := make(map[int][]*models.IndustrialManagementIdInt, 0)
  327. if len(articleIds) > 0 {
  328. var industryCond string
  329. var industryPars []interface{}
  330. industryCond += ` AND mg.article_id IN (` + utils.GetOrmInReplace(len(articleIds)) + `)`
  331. industryPars = append(industryPars, articleIds)
  332. industryList, e := models.GetIndustrialListByarticleId(industryPars, industryCond)
  333. if e != nil {
  334. br.Msg = "获取失败"
  335. br.ErrMsg = "获取报告关联的产业信息失败, Err: " + e.Error()
  336. return
  337. }
  338. for i := range industryList {
  339. v := industryList[i]
  340. industryMap[v.ArticleId] = append(industryMap[v.ArticleId], &models.IndustrialManagementIdInt{
  341. ArticleId: v.ArticleId,
  342. IndustrialManagementId: v.IndustrialManagementId,
  343. IndustryName: v.IndustryName,
  344. })
  345. }
  346. }
  347. for k, v := range list {
  348. if len(industryMap[v.ArticleId]) > 0 {
  349. list[k].List = industryMap[v.ArticleId]
  350. } else {
  351. list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  352. }
  353. v.Pv = articleMapPv[v.ArticleId]
  354. v.IsCollect = articleCollectMap[v.ArticleId]
  355. v.CollectNum = articleCollectNumMap[v.ArticleId]
  356. }
  357. resp := new(models.ArticleReportBillboardLIstResp)
  358. resp.List = list
  359. br.Ret = 200
  360. br.Success = true
  361. br.Msg = "获取成功"
  362. br.Data = resp
  363. }