home.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/services"
  8. "hongze/hongze_cygx/utils"
  9. "html"
  10. "strconv"
  11. "strings"
  12. )
  13. type HomeController struct {
  14. BaseAuthController
  15. }
  16. type BaseHomeController struct {
  17. BaseCommonController
  18. }
  19. // @Title 首页列表接口
  20. // @Description 首页列表接口
  21. // @Param PageSize query int true "每页数据条数"
  22. // @Param CurrentIndex query int true "当前页页码,从1开始"
  23. // @Param ChartPermissionId query int true "品类id,最新传0"
  24. // @Success 200 {object} models.HomeListResp
  25. // @router /list [get]
  26. func (this *HomeController) ListHome() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. user := this.User
  33. if user == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,用户信息为空"
  36. br.Ret = 408
  37. return
  38. }
  39. pageSize, _ := this.GetInt("PageSize")
  40. currentIndex, _ := this.GetInt("CurrentIndex")
  41. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  42. var startSize int
  43. if pageSize <= 0 {
  44. pageSize = utils.PageSize20
  45. }
  46. if currentIndex <= 0 {
  47. currentIndex = 1
  48. }
  49. startSize = paging.StartIndex(currentIndex, pageSize)
  50. var condition string
  51. var pars []interface{}
  52. var total int
  53. resp := new(models.HomeListResp)
  54. page := paging.GetPaging(currentIndex, pageSize, total)
  55. resp.HaveResearch = true
  56. userType, _, err := services.GetUserType(user.CompanyId)
  57. if err != nil {
  58. br.Msg = "获取信息失败"
  59. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  60. return
  61. }
  62. condition += ` AND is_summary = 1 `
  63. if chartPermissionId > 0 {
  64. categoryId, err := models.GetCategoryId(chartPermissionId)
  65. if err != nil && err.Error() != utils.ErrNoRow() {
  66. br.Msg = "获取信息失败"
  67. br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
  68. return
  69. }
  70. categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
  71. if err != nil {
  72. br.Msg = "获取信息失败"
  73. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  74. return
  75. }
  76. if userType == 1 && categoryinfo.PermissionName == "研选" {
  77. resp.HaveResearch = false
  78. resp.Paging = page
  79. br.Ret = 200
  80. br.Success = true
  81. br.Msg = "获取成功"
  82. br.Data = resp
  83. return
  84. }
  85. page = paging.GetPaging(currentIndex, pageSize, total)
  86. //if categoryId != "" {
  87. // condition += ` AND category_id IN(` + categoryId + `)`
  88. // condition += ` OR ( category_name LIKE '%研选%' AND publish_status = 1 AND is_summary = 1 )`
  89. //} else {
  90. // condition += ` AND category_name LIKE '%研选%' `
  91. //}
  92. if categoryId != "" {
  93. condition += ` AND category_id IN(` + categoryId + `)`
  94. //condition += ` OR ( category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%' AND publish_status = 1 AND is_summary = 1 )`
  95. } else {
  96. condition += ` AND category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
  97. }
  98. }
  99. //永续客户无法查看研选分类的内容
  100. if userType == 1 {
  101. condition += ` AND category_name NOT LIKE '%研选` + `%'`
  102. }
  103. total, err = models.GetHomeCount(condition, pars)
  104. if err != nil {
  105. br.Msg = "获取信息失败"
  106. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  107. return
  108. }
  109. page = paging.GetPaging(currentIndex, pageSize, total)
  110. list, err := models.GetHomeList(condition, pars, startSize, pageSize)
  111. if err != nil {
  112. br.Msg = "获取信息失败"
  113. br.Msg = "获取帖子数据失败,Err:" + err.Error()
  114. return
  115. }
  116. //研选的五张图片
  117. detailResearch, err := models.GetConfigByCode("category_research_img_url")
  118. if err != nil {
  119. br.Msg = "获取数据失败"
  120. br.ErrMsg = "获取数据研选分类图片失败,Err:" + err.Error()
  121. return
  122. }
  123. researchList := strings.Split(detailResearch.ConfigValue, "{|}")
  124. //对应分类的所图片
  125. detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  126. if err != nil {
  127. br.Msg = "获取数据失败"
  128. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  129. return
  130. }
  131. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  132. mapCategoryUrl := make(map[string]string)
  133. var categoryId string
  134. var imgUrlChart string
  135. for _, v := range categoryUrlList {
  136. vslice := strings.Split(v, "_")
  137. categoryId = vslice[0]
  138. imgUrlChart = vslice[len(vslice)-1]
  139. mapCategoryUrl[categoryId] = imgUrlChart
  140. }
  141. var articleIds []int
  142. for _, v := range list {
  143. articleIds = append(articleIds, v.ArticleId)
  144. }
  145. articleMapPv := services.GetArticleHistoryByArticleId(articleIds) //文章Pv
  146. fmt.Println(articleMapPv)
  147. for k, v := range list {
  148. list[k].Pv = articleMapPv[v.ArticleId]
  149. item := list[k]
  150. //如果文章一开始的内容是图片,优先展示第一张图片
  151. imgurl, _ := services.FixArticleImgUrl(html.UnescapeString(list[k].Body))
  152. newBody, _ := services.GetReportContentTextSub(item.Body)
  153. list[k].Body = newBody
  154. if imgurl != "" {
  155. list[k].BodyHtml = imgurl
  156. }
  157. list[k].PublishDate = utils.StrTimeToTime(item.PublishDate).Format(utils.FormatDateTimeNoSecond) //时间字符串格式转时间格式
  158. if strings.Contains(item.CategoryName, "研选") {
  159. list[k].IsResearch = true
  160. }
  161. if item.Pv > 999 {
  162. list[k].Pv = 999
  163. }
  164. //如果是研选系列的任意取五张图片的中的一张
  165. if v.CategoryId == "0" {
  166. knum := v.ArticleId % 5
  167. list[k].ImgUrlPc = researchList[knum]
  168. } else {
  169. list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  170. }
  171. if list[k].ArticleId < utils.SummaryArticleId {
  172. list[k].HttpUrl = utils.StrategyPlatform + strconv.Itoa(v.ArticleId)
  173. list[k].IsNeedJump = true
  174. }
  175. }
  176. resp.List = list
  177. resp.Paging = page
  178. br.Ret = 200
  179. br.Success = true
  180. br.Msg = "获取成功"
  181. br.Data = resp
  182. }
  183. // @Title 首页列表接口(无需token)
  184. // @Description 首页列表接口(无需token)
  185. // @Param PageSize query int true "每页数据条数"
  186. // @Param CurrentIndex query int true "当前页页码,从1开始"
  187. // @Param ChartPermissionId query int true "品类id,最新传0"
  188. // @Param CompanyCode query string false "机构编号"
  189. // @Param CompanyName query string false "机构名称"
  190. // @Param Email query string false "邮箱"
  191. // @Param Sign query string false "加密签名"
  192. // @Success 200 {object} models.HomeListResp
  193. // @router /listPublic [get]
  194. func (this *BaseHomeController) ListHomePublic() {
  195. br := new(models.BaseResponse).Init()
  196. defer func() {
  197. this.Data["json"] = br
  198. this.ServeJSON()
  199. }()
  200. companyCode := this.GetString("CompanyCode")
  201. companyName := this.GetString("CompanyName")
  202. email := this.GetString("Email")
  203. sign := this.GetString("Sign")
  204. var userType int
  205. var err error
  206. if companyCode != "" && companyName != "" && email != "" {
  207. errMsg, errHt, wxUser, _ := services.CheckHtgj(companyCode, companyName, email, sign)
  208. if errHt != nil {
  209. br.Msg = "获取"
  210. br.ErrMsg = "获取数据失败,Err:" + errHt.Error()
  211. return
  212. }
  213. if errMsg == "机构下账号个数已达上限" {
  214. goto Loop
  215. }
  216. if errMsg != "" {
  217. br.Msg = errMsg
  218. return
  219. }
  220. user := wxUser
  221. if user == nil {
  222. br.Msg = "请登录"
  223. br.ErrMsg = "请登录,用户信息为空"
  224. br.Ret = 408
  225. return
  226. }
  227. userType, _, err = services.GetUserType(user.CompanyId)
  228. if err != nil {
  229. br.Msg = "获取信息失败"
  230. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  231. return
  232. }
  233. }
  234. Loop:
  235. pageSize, _ := this.GetInt("PageSize")
  236. currentIndex, _ := this.GetInt("CurrentIndex")
  237. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  238. var startSize int
  239. if pageSize <= 0 {
  240. pageSize = utils.PageSize20
  241. }
  242. if currentIndex <= 0 {
  243. currentIndex = 1
  244. }
  245. startSize = paging.StartIndex(currentIndex, pageSize)
  246. var condition string
  247. var pars []interface{}
  248. var total int
  249. resp := new(models.HomeListResp)
  250. page := paging.GetPaging(currentIndex, pageSize, total)
  251. resp.HaveResearch = true
  252. condition += ` AND is_summary = 1 `
  253. if chartPermissionId > 0 {
  254. categoryId, err := models.GetCategoryId(chartPermissionId)
  255. if err != nil && err.Error() != utils.ErrNoRow() {
  256. br.Msg = "获取信息失败"
  257. br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
  258. return
  259. }
  260. categoryinfo, err := models.GetChartPermissionById(chartPermissionId)
  261. if err != nil {
  262. br.Msg = "获取信息失败"
  263. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  264. return
  265. }
  266. if userType == 1 && strings.Contains(categoryinfo.PermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  267. resp.HaveResearch = false
  268. resp.Paging = page
  269. br.Ret = 200
  270. br.Success = true
  271. br.Msg = "获取成功"
  272. br.Data = resp
  273. return
  274. }
  275. page = paging.GetPaging(currentIndex, pageSize, total)
  276. if categoryId != "" {
  277. condition += ` AND category_id IN(` + categoryId + `)`
  278. //condition += ` OR ( category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%' AND publish_status = 1 AND is_summary = 1 )`
  279. } else {
  280. condition += ` AND category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
  281. }
  282. }
  283. //永续客户无法查看研选分类的内容
  284. if userType == 1 {
  285. condition += ` AND category_name NOT LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
  286. }
  287. total, err = models.GetHomeCount(condition, pars)
  288. if err != nil {
  289. br.Msg = "获取信息失败"
  290. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  291. return
  292. }
  293. page = paging.GetPaging(currentIndex, pageSize, total)
  294. list, err := models.GetHomeList(condition, pars, startSize, pageSize)
  295. if err != nil {
  296. br.Msg = "获取信息失败"
  297. br.Msg = "获取帖子数据失败,Err:" + err.Error()
  298. return
  299. }
  300. list, err = services.HandleArticleCategoryImg(list)
  301. if err != nil {
  302. br.Msg = "获取信息失败"
  303. br.Msg = "图片预处理失败,HandleArticleCategoryImg,Err:" + err.Error()
  304. return
  305. }
  306. for _, v := range list {
  307. v.Annotation, _ = services.GetReportContentTextSub(v.Annotation)
  308. v.Body = v.Annotation
  309. }
  310. resp.List = list
  311. resp.Paging = page
  312. br.Ret = 200
  313. br.Success = true
  314. br.Msg = "获取成功"
  315. br.Data = resp
  316. }
  317. // @Title 首页/搜索头部导航接口
  318. // @Description 首页/搜索头部导航接口
  319. // @Param SearchPage query int false "是否为搜索页面"
  320. // @Success 200 {object} models.HomeListResp
  321. // @router /header_tab [get]
  322. func (this *HomeController) HeaderTab() {
  323. br := new(models.BaseResponse).Init()
  324. defer func() {
  325. this.Data["json"] = br
  326. this.ServeJSON()
  327. }()
  328. user := this.User
  329. if user == nil {
  330. br.Msg = "请登录"
  331. br.ErrMsg = "请登录,用户信息为空"
  332. br.Ret = 408
  333. return
  334. }
  335. searchPage, _ := this.GetInt("SearchPage")
  336. key := models.HomeHeaderTabConfigKey
  337. conf, e := models.GetConfigByCode(key)
  338. if e != nil {
  339. br.Msg = "获取失败"
  340. br.ErrMsg = "获取首页头部导航失败, Err: " + e.Error()
  341. return
  342. }
  343. if conf.ConfigValue == "" {
  344. br.Msg = "获取失败"
  345. br.ErrMsg = "首页头部导航配置值有误"
  346. return
  347. }
  348. list := new(models.HomeHeaderTabList)
  349. if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
  350. br.Msg = "获取失败"
  351. br.ErrMsg = "首页头部导航配置值解析失败, Err: " + e.Error()
  352. return
  353. }
  354. resp := list.Home
  355. if searchPage == 1 {
  356. resp = list.SearchPage
  357. }
  358. br.Ret = 200
  359. br.Success = true
  360. br.Msg = "获取成功"
  361. br.Data = resp
  362. }
  363. // @Title 首页列表接口v7.6版本
  364. // @Description 首页列表接口v7.6版本
  365. // @Param PageSize query int true "每页数据条数"
  366. // @Param CurrentIndex query int true "当前页页码,从1开始"
  367. // @Param ChartPermissionId query int true "品类id,最新传0"
  368. // @Param CtagId query int true "图表子类ID"
  369. // @Param ListType query int true "列表类型,1最新,2 纪要 ,3图表 默认1"
  370. // @Success 200 {object} models.HomeArtAndChartListResp
  371. // @router /artAndChart/list [get]
  372. func (this *HomeController) ListHomeArtAndChart() {
  373. br := new(models.BaseResponse).Init()
  374. defer func() {
  375. this.Data["json"] = br
  376. this.ServeJSON()
  377. }()
  378. user := this.User
  379. if user == nil {
  380. br.Msg = "请登录"
  381. br.ErrMsg = "请登录,用户信息为空"
  382. br.Ret = 408
  383. return
  384. }
  385. pageSize, _ := this.GetInt("PageSize")
  386. currentIndex, _ := this.GetInt("CurrentIndex")
  387. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  388. ctagId, _ := this.GetInt("CtagId")
  389. listType, _ := this.GetInt("ListType")
  390. var startSize int
  391. if pageSize <= 0 {
  392. pageSize = utils.PageSize20
  393. }
  394. if currentIndex <= 0 {
  395. currentIndex = 1
  396. }
  397. if listType <= 0 {
  398. listType = 1
  399. }
  400. startSize = paging.StartIndex(currentIndex, pageSize)
  401. var condition string
  402. var pars []interface{}
  403. var total, chartTotal int
  404. resp := new(models.HomeArtAndChartListResp)
  405. page := paging.GetPaging(currentIndex, pageSize, total)
  406. resp.HaveResearch = true
  407. var chartList []*models.HomeChartListResp
  408. var err error
  409. // 最新
  410. if listType == 1 {
  411. if currentIndex <= 2 {
  412. listCtagId := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  413. var chartIds string
  414. for _, v := range listCtagId {
  415. chartListTwo, err := models.GetChartList(`AND ctag_id = `+strconv.Itoa(v), pars, 0, 2)
  416. if err != nil {
  417. br.Msg = "获取信息失败"
  418. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  419. return
  420. }
  421. for _, vChart := range chartListTwo {
  422. chartIds += strconv.Itoa(vChart.ChartId) + ","
  423. }
  424. }
  425. chartIds = strings.TrimRight(chartIds, ",")
  426. condition += ` AND chart_id IN (` + chartIds + `) `
  427. chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
  428. if err != nil {
  429. br.Msg = "获取信息失败"
  430. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  431. return
  432. }
  433. }
  434. }
  435. // 图表
  436. if listType == 3 {
  437. if chartPermissionId > 0 {
  438. condition += ` AND a.ptag_id =? `
  439. pars = append(pars, chartPermissionId)
  440. }
  441. if ctagId > 0 {
  442. condition += ` AND a.ctag_id =? `
  443. pars = append(pars, ctagId)
  444. }
  445. chartList, err = models.GetChartList(condition, pars, startSize, pageSize)
  446. if err != nil {
  447. br.Msg = "获取信息失败"
  448. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  449. return
  450. }
  451. chartTotal, err = models.GetChartCount(condition, pars)
  452. if err != nil {
  453. br.Msg = "获取信息失败"
  454. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  455. return
  456. }
  457. }
  458. for k, v := range chartList {
  459. if v.PtagName != "" {
  460. chartList[k].CtagNamePc = v.PtagName
  461. }
  462. if v.CtagName != "" {
  463. chartList[k].CtagNamePc += "," + v.CtagName
  464. }
  465. if v.PtagNameTwo != "" {
  466. chartList[k].CtagNamePc += "," + v.PtagNameTwo
  467. }
  468. if v.CtagNameTwo != "" {
  469. chartList[k].CtagNamePc += "," + v.CtagNameTwo
  470. }
  471. chartList[k].IsNeedJump = true
  472. chartList[k].Source = 2
  473. }
  474. resp.ChartList = chartList
  475. // 最新/纪要
  476. if listType != 3 {
  477. userType, _, err := services.GetUserType(user.CompanyId)
  478. if err != nil {
  479. br.Msg = "获取信息失败"
  480. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  481. return
  482. }
  483. condition = ` AND is_summary = 1 `
  484. if chartPermissionId > 0 {
  485. categoryId, err := models.GetCategoryId(chartPermissionId)
  486. if err != nil && err.Error() != utils.ErrNoRow() {
  487. br.Msg = "获取信息失败"
  488. br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
  489. return
  490. }
  491. categoryInfo, err := models.GetChartPermissionById(chartPermissionId)
  492. if err != nil {
  493. br.Msg = "获取信息失败"
  494. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  495. return
  496. }
  497. if userType == 1 && strings.Contains(categoryInfo.PermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  498. resp.HaveResearch = false
  499. resp.Paging = page
  500. br.Ret = 200
  501. br.Success = true
  502. br.Msg = "获取成功"
  503. br.Data = resp
  504. return
  505. }
  506. page = paging.GetPaging(currentIndex, pageSize, total)
  507. if categoryId != "" {
  508. condition += ` AND category_id IN(` + categoryId + `)`
  509. //condition += ` OR ( category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%' AND publish_status = 1 AND is_summary = 1 )`
  510. } else {
  511. condition += ` AND category_name LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
  512. }
  513. }
  514. //永续客户无法查看研选分类的内容
  515. if userType == 1 {
  516. condition += ` AND category_name NOT LIKE '%` + utils.CHART_PERMISSION_NAME_YANXUAN + `%'`
  517. }
  518. list := make([]*models.HomeArticle, 0)
  519. // 7.6-与音频作联合查询, 整体进行发布时间的排序(代码写的嘎嘎烂, 将就着用吧=_=!)
  520. if listType == 1 {
  521. var unionPars []interface{}
  522. unionList, unionTotal, e := services.GetHomeNewestList(user.UserId, user.CompanyId, startSize, pageSize, condition, unionPars)
  523. if e != nil {
  524. br.Msg = "获取信息失败"
  525. br.Msg = "获取纪要音频联合列表失败, Err: " + e.Error()
  526. return
  527. }
  528. total = unionTotal
  529. list = unionList
  530. } else {
  531. total, err = models.GetHomeCount(condition, pars)
  532. if err != nil {
  533. br.Msg = "获取信息失败"
  534. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  535. return
  536. }
  537. homeList, err := models.GetHomeList(condition, pars, startSize, pageSize)
  538. if err != nil {
  539. br.Msg = "获取信息失败"
  540. br.Msg = "获取帖子数据失败,Err:" + err.Error()
  541. return
  542. }
  543. list = homeList
  544. }
  545. resp.List, err = services.HandleArticleCategoryImg(list)
  546. if err != nil {
  547. br.Msg = "获取信息失败"
  548. br.Msg = "处理封面图片失败,HandleArticleCategoryImg,Err:" + err.Error()
  549. return
  550. }
  551. resp.List = list
  552. }
  553. if chartTotal > total {
  554. total = chartTotal
  555. }
  556. page = paging.GetPaging(currentIndex, pageSize, total)
  557. resp.Paging = page
  558. br.Ret = 200
  559. br.Success = true
  560. br.Msg = "获取成功"
  561. br.Data = resp
  562. }
  563. // @Title 首页列表接口
  564. // @Description 首页列表接口
  565. // @Param TagIds query string true "标签选择"
  566. // @Param ChartPermissionId query int false "行业id"
  567. // @Param PageSize query int true "每页数据条数"
  568. // @Param CurrentIndex query int true "当前页页码,从1开始"
  569. // @Success 200 {object} models.HomeArtAndChartListResp
  570. // @router /new [get]
  571. func (this *HomeController) NewList() {
  572. br := new(models.BaseResponse).Init()
  573. defer func() {
  574. this.Data["json"] = br
  575. this.ServeJSON()
  576. }()
  577. user := this.User
  578. if user == nil {
  579. br.Msg = "请登录"
  580. br.ErrMsg = "请登录,用户信息为空"
  581. br.Ret = 408
  582. return
  583. }
  584. pageSize, _ := this.GetInt("PageSize")
  585. currentIndex, _ := this.GetInt("CurrentIndex")
  586. tagIds := this.GetString("TagIds")
  587. chartPermissionId, _ := this.GetInt("ChartPermissionId")
  588. var startSize int
  589. if pageSize <= 0 {
  590. pageSize = utils.PageSize20
  591. }
  592. if currentIndex <= 0 {
  593. currentIndex = 1
  594. }
  595. startSize = paging.StartIndex(currentIndex, pageSize)
  596. var condition string
  597. var conditionInit string
  598. var pars []interface{}
  599. //var total int
  600. resp := new(models.HomeResourceDataListResp)
  601. //totalRai, err := models.GetCountCompanyProductCompanyId(user.CompanyId, utils.COMPANY_PRODUCT_RAI_ID)
  602. //if err != nil && err.Error() != utils.ErrNoRow() {
  603. // br.Msg = "获取失败"
  604. // br.ErrMsg = "GetCountCompanyProductCompanyId,Err:" + err.Error()
  605. // return
  606. //}
  607. if tagIds != "" {
  608. conditionTagIdsInit, err := services.GetConditionInitByTagIds(tagIds, chartPermissionId)
  609. if err != nil {
  610. br.Msg = "获取失败"
  611. br.ErrMsg = "获取活动权限数据失败,GetConditionInitByTagIds Err:" + err.Error()
  612. return
  613. }
  614. conditionInit += conditionTagIdsInit
  615. }
  616. //行业筛选
  617. if chartPermissionId > 0 {
  618. conditionInit += " AND chart_permission_id = " + strconv.Itoa(chartPermissionId)
  619. condition += " AND chart_permission_id = " + strconv.Itoa(chartPermissionId)
  620. }
  621. //if tagIds == "" && chartPermissionId == 0 {
  622. // //查询近一个月的数据
  623. // conditionInit += " AND publish_date > '" + time.Now().AddDate(0, 0, -30).Format(utils.FormatDateTime) + "'"
  624. //}
  625. //conditionInit += ` AND source IN ('newchart')`
  626. //if user.CompanyId <= 1 || totalRai == 0 {
  627. // //condition += " AND source IN ('roadshow','article') "
  628. // condition += " AND source NOT IN ('activityspecial','industrialsourceHz','industrialsourceYx') "
  629. // listActivityYiDong, err := models.GetActivityListHomeNew(" AND art.yidong_activity_id != '' ", 0, 1000)
  630. // if err != nil {
  631. // br.Msg = "获取失败"
  632. // br.ErrMsg = "获取可见活动数据失败,Err:" + err.Error()
  633. // return
  634. // }
  635. // //易董的活动不查看 v12.2.1
  636. // var yiDongactivityIds []int
  637. // for _, v := range listActivityYiDong {
  638. // yiDongactivityIds = append(yiDongactivityIds, v.ActivityId)
  639. // }
  640. // lenyiDongactivityIds := len(yiDongactivityIds)
  641. // condition += ` AND IF ( source = 'activity' , source_id NOT IN (` + utils.GetOrmInReplace(lenyiDongactivityIds) + `) ,1=1 ) `
  642. // pars = append(pars, yiDongactivityIds)
  643. //} else {
  644. condition += ` AND is_hide = 0 AND source NOT IN ('activity','activityspecial','newchart','industrialsourceHz','industrialsourceYx') AND IF ( source IN('activityvoice','activityvideo') , chart_permission_id != 31 ,1=1 ) ` + conditionInit
  645. //conditionActivity, err := services.GetActivityonditionList(user, "", "", "", "1,2,3", "", 0, 0, "", 0, 1)
  646. conditionActivity, err := services.ActivityConditioninitSql(user, " AND art.active_state IN (1,2) ", 0)
  647. if err != nil && err.Error() != utils.ErrNoRow() {
  648. br.Msg = "获取失败"
  649. br.ErrMsg = "获取活动权限数据失败,Err:" + err.Error()
  650. return
  651. }
  652. conditionActivity += ` AND art.publish_status = 1 `
  653. var conditionOrder string
  654. conditionOrder = ` ORDER BY art.activity_time DESC , art.active_state ASC `
  655. conditionActivity += conditionOrder
  656. actPageSize := 200
  657. if tagIds != "" {
  658. actPageSize = 2000
  659. }
  660. listActivity, err := models.GetActivityListHomeNew(conditionActivity, 0, actPageSize)
  661. if err != nil {
  662. br.Msg = "获取失败"
  663. br.ErrMsg = "获取可见活动数据失败,Err:" + err.Error()
  664. return
  665. }
  666. var activityIds []int
  667. for _, v := range listActivity {
  668. activityIds = append(activityIds, v.ActivityId)
  669. }
  670. lenActivityIds := len(activityIds)
  671. listActivitySpecial, _, err := services.GetActivitySpecialList(user, 1, 200, "")
  672. if err != nil {
  673. br.Msg = "获取失败"
  674. br.ErrMsg = "获取专项调研可见权限失败失败,Err:" + err.Error()
  675. return
  676. }
  677. var activityspecialIds []int
  678. for _, v := range listActivitySpecial {
  679. activityspecialIds = append(activityspecialIds, v.ActivityId)
  680. }
  681. lenActivityspecialIds := len(activityspecialIds)
  682. if lenActivityIds > 0 {
  683. condition += ` OR ( source = 'activity' AND source_id IN (` + utils.GetOrmInReplace(lenActivityIds) + `) ` + conditionInit + ` ) `
  684. pars = append(pars, activityIds)
  685. }
  686. if lenActivityspecialIds > 0 {
  687. condition += ` OR ( source = 'activityspecial' AND source_id IN (` + utils.GetOrmInReplace(lenActivityspecialIds) + `) ` + conditionInit + ` ) `
  688. pars = append(pars, activityspecialIds)
  689. //}
  690. }
  691. total, err := models.GetResourceDataCount(condition, pars)
  692. if err != nil {
  693. br.Msg = "获取失败"
  694. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  695. return
  696. }
  697. page := paging.GetPaging(currentIndex, pageSize, total)
  698. //Source string `description:"资源类型 报告 :article 、图表 :newchart、微路演 :roadshow、活动 :activity、活动视频:activityvideo、活动音频:activityvoice、专项调研活动:activityspecial"`
  699. list, err := services.GetResourceDataList(condition, pars, startSize, pageSize, user)
  700. if err != nil {
  701. br.Msg = "获取失败"
  702. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  703. return
  704. }
  705. var permissionName string
  706. if chartPermissionId > 0 {
  707. chartPermissioninfo, err := models.GetChartPermissionById(chartPermissionId)
  708. if err != nil {
  709. br.Msg = "获取失败"
  710. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  711. }
  712. permissionName = chartPermissioninfo.PermissionName
  713. }
  714. if currentIndex == 1 && len(list) > 0 && permissionName == utils.ZHOU_QI_NAME && tagIds == "" { // 如果是第一页信息,选择了周期行业,同时没有选择别的筛选条件就 在第三个拼接 FICC研报的跳转信息
  715. for k, v := range list {
  716. resp.List = append(resp.List, v)
  717. if k == 1 {
  718. resp.List = append(resp.List, services.GetFiccReportXcxItem(user))
  719. }
  720. }
  721. } else {
  722. resp.List = list
  723. }
  724. page = paging.GetPaging(currentIndex, pageSize, total)
  725. resp.Paging = page
  726. br.Ret = 200
  727. br.Success = true
  728. br.Msg = "获取成功"
  729. br.Data = resp
  730. }