report.go 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_clpt/models"
  7. "hongze/hongze_clpt/services"
  8. "hongze/hongze_clpt/utils"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. //报告
  14. type ReportController struct {
  15. BaseAuthController
  16. }
  17. type ReportCommonController struct {
  18. BaseCommonController
  19. }
  20. type MobileReportController struct {
  21. BaseAuthMobileController
  22. }
  23. // @Title 行业报告分类列表接口
  24. // @Description 获取行业报告分类列表接口
  25. // @Param ChartPermissionId query int true "分类ID"
  26. // @Success 200 {object} models.TradeReportMappingResp
  27. // @router /tradeList [get]
  28. func (this *MobileReportController) TradeList() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. user := this.User
  35. if user == nil {
  36. br.Msg = "请重新登录"
  37. br.Ret = 408
  38. return
  39. }
  40. fmt.Println(user)
  41. uid := user.UserId
  42. ChartPermissionId, _ := this.GetInt("ChartPermissionId")
  43. if ChartPermissionId < 1 {
  44. br.Msg = "请输入分类ID"
  45. return
  46. }
  47. //var result []*models.SearchItem
  48. var list []*models.TradeReportMapping
  49. var err error
  50. mapCategory := make(map[int]int)
  51. if ChartPermissionId == utils.CE_LUE_ID {
  52. listTrade, errTrade := models.GetReportMappingStrategyHomeAll()
  53. list = listTrade
  54. err = errTrade
  55. if user.Mobile != "" {
  56. //策略的处理
  57. categoryList, err := models.GetCygxXzsChooseCategoryList(user.Mobile)
  58. if err != nil && err.Error() != utils.ErrNoRow() {
  59. br.Msg = "获取信息失败"
  60. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  61. return
  62. }
  63. for _, v := range categoryList {
  64. mapCategory[v.CategoryId] = v.CategoryId
  65. }
  66. }
  67. } else {
  68. listTrade, errTrade := models.GetTradeAll(ChartPermissionId)
  69. err = errTrade
  70. list = listTrade
  71. }
  72. if err != nil {
  73. br.Msg = "获取信息失败"
  74. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  75. return
  76. }
  77. for k, v := range list {
  78. list[k].UpdateTime = utils.TimeRemoveHms(v.UpdateTime)
  79. count, err := models.CheckThisCategoryNewArticleIsRead(uid, v.CategoryId)
  80. if err != nil {
  81. br.Msg = "获取信息失败"
  82. br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
  83. return
  84. }
  85. if count == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.UpdateTime)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.UpdateTime)) {
  86. list[k].IsRed = true
  87. }
  88. var condition string
  89. var pars []interface{}
  90. condition = " AND a.category_id_two = " + strconv.Itoa(v.CategoryId)
  91. if ChartPermissionId != utils.CE_LUE_ID {
  92. var pageSize int
  93. if ChartPermissionId == utils.KE_JI_ID {
  94. pageSize = 12
  95. } else {
  96. pageSize = 6
  97. }
  98. listArticle, err := models.GetHomeList(condition, pars, 0, pageSize)
  99. if err != nil {
  100. br.Msg = "获取信息失败"
  101. br.Msg = "GetHomeList,Err:" + err.Error()
  102. return
  103. }
  104. list[k].ListArticle = listArticle
  105. } else {
  106. if mapCategory[v.CategoryId] > 0 {
  107. list[k].IsFollow = true
  108. }
  109. list[k].ListArticle = make([]*models.HomeArticle, 0)
  110. }
  111. }
  112. resp := new(models.TradeReportMappingResp)
  113. if len(list) == 0 {
  114. list = make([]*models.TradeReportMapping, 0)
  115. }
  116. resp.List = list
  117. br.Ret = 200
  118. br.Success = true
  119. br.Msg = "获取成功"
  120. br.Data = resp
  121. }
  122. // @Title 产业报告分类列表接口
  123. // @Description 获取产业报告分类列表接口
  124. // @Param ChartPermissionId query int true "分类ID"
  125. // @Param DeepCover query int false "是否选择深度覆盖,1是,0否 不填默认为0"
  126. // @Param RecommendFocus query int false "是否选择推荐关注,1是,0否 不填默认为0"
  127. // @Param PageSize query int true "每页数据条数"
  128. // @Param CurrentIndex query int true "当前页页码,从1开始"
  129. // @Success 200 {object} models.IndustrialManagementList
  130. // @router /industryList [get]
  131. func (this *MobileReportController) IndustryList() {
  132. br := new(models.BaseResponse).Init()
  133. defer func() {
  134. this.Data["json"] = br
  135. this.ServeJSON()
  136. }()
  137. user := this.User
  138. if user == nil {
  139. br.Msg = "请重新登录"
  140. br.Ret = 408
  141. return
  142. }
  143. uid := user.UserId
  144. ChartPermissionId, _ := this.GetInt("ChartPermissionId")
  145. orderColumn := this.GetString("OrderColumn")
  146. orderColumnNew := this.GetString("OrderColumn")
  147. pageSize, _ := this.GetInt("PageSize")
  148. currentIndex, _ := this.GetInt("CurrentIndex")
  149. deepCover, _ := this.GetInt("DeepCover")
  150. recommendFocus, _ := this.GetInt("RecommendFocus")
  151. var orderSrt string
  152. var condition string
  153. var startSize int
  154. resp := new(models.IndustrialManagementList)
  155. if pageSize <= 0 {
  156. pageSize = utils.PageSize20
  157. }
  158. if currentIndex <= 0 {
  159. currentIndex = 1
  160. }
  161. startSize = paging.StartIndex(currentIndex, pageSize)
  162. if ChartPermissionId > 0 {
  163. condition += ` AND man.chart_permission_id IN (` + strconv.Itoa(ChartPermissionId) + `)`
  164. }
  165. // 深度覆盖
  166. if deepCover == 1 {
  167. // 查询深标签产业报告数
  168. var deepCondition string
  169. var deepPars []interface{}
  170. deepCondition += ` AND man.is_deep_label = 1`
  171. if ChartPermissionId > 0 {
  172. deepCondition += ` AND man.chart_permission_id = ?`
  173. deepPars = append(deepPars, ChartPermissionId)
  174. }
  175. industryCountList, e := models.GetIndustryArtCountByCondition(deepCondition, deepPars)
  176. if e != nil {
  177. br.Msg = "获取信息失败"
  178. br.ErrMsg = "获取深标签产业报告数失败, Err: " + e.Error()
  179. return
  180. }
  181. deepIdArr := make([]string, 0)
  182. for i := range industryCountList {
  183. if industryCountList[i].ArtNum > 10 {
  184. deepIdArr = append(deepIdArr, strconv.Itoa(industryCountList[i].IndustrialManagementId))
  185. }
  186. }
  187. deepIds := strings.Join(deepIdArr, ",")
  188. if deepIds != "" {
  189. condition = `AND man.industrial_management_id IN (` + deepIds + `)`
  190. }
  191. }
  192. // 推荐关注
  193. if recommendFocus == 1 {
  194. condition += ` AND man.recommended_index >= 50`
  195. }
  196. var list []*models.IndustrialManagement
  197. total, err := models.GetIndustrialManagementAllCount(condition)
  198. if err != nil {
  199. br.Msg = "获取信息失败"
  200. br.ErrMsg = "获取数量失败,Err:" + err.Error()
  201. return
  202. }
  203. page := paging.GetPaging(currentIndex, pageSize, total)
  204. if orderColumn == "" {
  205. orderColumn = "NewTime"
  206. }
  207. if orderColumn == "NewTime" {
  208. orderSrt = "update_time DESC"
  209. } else {
  210. orderSrt = "man.recommended_index DESC,update_time DESC"
  211. }
  212. if ChartPermissionId == 0 {
  213. ChartPermissionId = 20
  214. }
  215. //获取产业下阅读数量第三的产业详情
  216. detailHot3, err := models.GetIndustrialManagementHot3(ChartPermissionId)
  217. if err != nil && err.Error() != utils.ErrNoRow() {
  218. br.Msg = "获取信息失败"
  219. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  220. return
  221. }
  222. list, err = models.GetIndustrialManagementAll(uid, condition, orderSrt, startSize, pageSize)
  223. if err != nil {
  224. br.Msg = "获取信息失败"
  225. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  226. return
  227. }
  228. industrialIdArr := make([]int, 0)
  229. for k, v := range list {
  230. industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
  231. if v.ArticleReadNum >= detailHot3.ArticleReadNum {
  232. list[k].IsHot = true
  233. }
  234. }
  235. mapUPdateTime := make(map[int]string)
  236. mapHistroyArticleId := make(map[int]int)
  237. articleIdArr := make([]int, 0)
  238. //获取这些产业下最新更新的文章
  239. fmt.Println(industrialIdArr)
  240. listUpdateTime, err := models.GetNewArticleDetailByIndustrialIds(industrialIdArr)
  241. if err != nil && err.Error() != utils.ErrNoRow() {
  242. br.Msg = "获取信息失败"
  243. br.ErrMsg = "获取信息失败 GetNewArticleDetailByIndustrialIds ,Err:" + err.Error()
  244. return
  245. }
  246. for _, v := range listUpdateTime {
  247. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  248. articleIdArr = append(articleIdArr, v.ArticleId)
  249. }
  250. if uid > 0 {
  251. listArticleHistory, err := models.GetUserToArticleHistory(uid, industrialIdArr)
  252. if err != nil && err.Error() != utils.ErrNoRow() {
  253. br.Msg = "获取信息失败"
  254. br.ErrMsg = "获取信息失败 GetUserToArticleHistory ,Err:" + err.Error()
  255. return
  256. }
  257. for _, v := range listArticleHistory {
  258. mapHistroyArticleId[v.ArticleId] = v.ArticleId
  259. }
  260. }
  261. for k, v := range list {
  262. list[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
  263. if uid > 0 {
  264. //如果文章没有阅读,而且,文章的发布时间晚于项目的上线时间,而且文章的发布时间晚于用户的注册时间,就进行标红处理
  265. if mapHistroyArticleId[v.ArticleId] == 0 && user.CreatedTime.Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  266. list[k].IsRed = true
  267. }
  268. } else {
  269. if utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(mapUPdateTime[v.IndustrialManagementId])) {
  270. list[k].IsRed = true
  271. }
  272. list[k].IsFollow = false
  273. }
  274. //标的列表
  275. industrialSubjectList, err := models.GetIndustrialSubjectAll(v.IndustrialManagementId)
  276. if err != nil {
  277. br.Msg = "获取信息失败"
  278. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  279. return
  280. }
  281. list[k].IndustrialSubjectList = industrialSubjectList
  282. }
  283. //记录用户搜索的筛选条件
  284. if orderColumnNew != "" {
  285. //item := new(models.CygxReportIndustrialSeaarchHistory)
  286. //item.UserId = user.UserId
  287. //item.Mobile = user.Mobile
  288. //item.CompanyId = user.CompanyId
  289. //item.CompanyName = user.CompanyName
  290. //item.CreateTime = time.Now()
  291. //item.IsDeepLabel = isDeepLabel
  292. //item.IsNewLabel = isNewLabel
  293. //item.ChartPermissionId = ChartPermissionId
  294. //if orderColumnNew == "NewTime" {
  295. // item.OrderColumn = "0"
  296. //} else {
  297. // item.OrderColumn = "1"
  298. //}
  299. //go models.AddCygxReportIndustrialSeaarchHistory(item)
  300. }
  301. if len(list) == 0 {
  302. list = make([]*models.IndustrialManagement, 0)
  303. }
  304. resp.List = list
  305. resp.Paging = page
  306. br.Ret = 200
  307. br.Success = true
  308. br.Msg = "获取成功"
  309. br.Data = resp
  310. }
  311. // @Title 产业下所关联的文章分类列表
  312. // @Description 产业下所关联的文章分类列表接口
  313. // @Param IndustrialManagementId query int true "产业ID"
  314. // @Success 200 {object} models.IndustrialToArticleCategoryListRep
  315. // @router /toArticleCategoryList [get]
  316. func (this *MobileReportController) ArticleCategoryList() {
  317. br := new(models.BaseResponse).Init()
  318. defer func() {
  319. this.Data["json"] = br
  320. this.ServeJSON()
  321. }()
  322. user := this.User
  323. if user == nil {
  324. br.Msg = "请重新登录"
  325. br.Ret = 408
  326. return
  327. }
  328. uid := user.UserId
  329. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  330. if industrialManagementId < 1 {
  331. br.Msg = "请输入分类ID"
  332. return
  333. }
  334. detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
  335. if err != nil {
  336. br.Msg = "获取信息失败"
  337. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  338. return
  339. }
  340. list, err := models.IndustrialToArticleCategory(industrialManagementId, detail.ChartPermissionId)
  341. if err != nil {
  342. br.Msg = "获取信息失败"
  343. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  344. return
  345. }
  346. for k, v := range list {
  347. recordCount, err := models.IndustrialUserRecordArticleCount(uid, industrialManagementId, v.CategoryId)
  348. if err != nil && err.Error() != utils.ErrNoRow() {
  349. br.Msg = "获取信息失败"
  350. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  351. return
  352. }
  353. Newdetail, err := models.GetNewIndustrialUserRecordArticle(industrialManagementId, v.CategoryId)
  354. if err != nil {
  355. br.Msg = "获取信息失败"
  356. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  357. return
  358. }
  359. if recordCount == 0 && user.CreatedTime.Before(utils.StrTimeToTime(Newdetail.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(Newdetail.PublishDate)) {
  360. list[k].IsRed = true
  361. }
  362. }
  363. //标的列表
  364. industrialSubjectList, err := models.GetIndustrialSubjectAll(industrialManagementId)
  365. if err != nil {
  366. br.Msg = "获取信息失败"
  367. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  368. return
  369. }
  370. resp := new(models.IndustrialToArticleCategoryListRep)
  371. resp.List = list
  372. resp.ListSubject = industrialSubjectList
  373. resp.LayoutTime = utils.TimeRemoveHms(detail.LayoutTime)
  374. resp.IndustryName = detail.IndustryName
  375. resp.IndustrialManagementId = industrialManagementId
  376. br.Ret = 200
  377. br.Success = true
  378. br.Msg = "获取成功"
  379. br.Data = resp
  380. }
  381. // @Title 根据行业分类获取文章列表
  382. // @Description根据行业分类获取文章列表接口
  383. // @Param PageSize query int true "每页数据条数"
  384. // @Param CurrentIndex query int true "当前页页码,从1开始"
  385. // @Param CategoryId query int true "分类ID"
  386. // @Success 200 {object} models.TacticsListResp
  387. // @router /articleList/byCategoryId [get]
  388. func (this *MobileReportController) List() {
  389. br := new(models.BaseResponse).Init()
  390. defer func() {
  391. this.Data["json"] = br
  392. this.ServeJSON()
  393. }()
  394. user := this.User
  395. if user == nil {
  396. br.Msg = "请重新登录"
  397. br.Ret = 408
  398. return
  399. }
  400. //uid := user.UserId
  401. pageSize, _ := this.GetInt("PageSize")
  402. currentIndex, _ := this.GetInt("CurrentIndex")
  403. categoryId, _ := this.GetInt("CategoryId")
  404. var startSize int
  405. if pageSize <= 0 {
  406. pageSize = utils.PageSize20
  407. }
  408. if currentIndex <= 0 {
  409. currentIndex = 1
  410. }
  411. startSize = paging.StartIndex(currentIndex, pageSize)
  412. var condition string
  413. var pars []interface{}
  414. var total int
  415. resp := new(models.TacticsListResp)
  416. page := paging.GetPaging(currentIndex, pageSize, total)
  417. //获取该产业下所对应的行业图片
  418. detail, errCategory := models.GetdetailByCategoryIdOne(categoryId)
  419. if errCategory != nil {
  420. br.Msg = "获取信息失败"
  421. br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  422. return
  423. }
  424. //对应行业的图片
  425. detailChartPermissionUrl, err := models.GetConfigByCode("category_chart_permissionimg_url")
  426. if err != nil {
  427. br.Msg = "获取数据失败"
  428. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  429. return
  430. }
  431. chartPermissionUrlList := strings.Split(detailChartPermissionUrl.ConfigValue, "{|}")
  432. mapChartPermission := make(map[string]string)
  433. var permissionName string
  434. var imgUrlChartPermission string
  435. for _, v := range chartPermissionUrlList {
  436. vslice := strings.Split(v, "_")
  437. permissionName = vslice[0]
  438. imgUrlChartPermission = vslice[len(vslice)-1]
  439. mapChartPermission[permissionName] = imgUrlChartPermission
  440. }
  441. //对应分类的所图片
  442. detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  443. if err != nil {
  444. br.Msg = "获取数据失败"
  445. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  446. return
  447. }
  448. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  449. mapCategoryUrl := make(map[string]string)
  450. var categoryIdStr string
  451. var imgUrlChart string
  452. for _, v := range categoryUrlList {
  453. vslice := strings.Split(v, "_")
  454. categoryIdStr = vslice[0]
  455. imgUrlChart = vslice[len(vslice)-1]
  456. mapCategoryUrl[categoryIdStr] = imgUrlChart
  457. }
  458. condition += ` AND category_id_two=? `
  459. pars = append(pars, categoryId)
  460. total, err = models.GetHomeCount(condition, pars)
  461. if err != nil {
  462. br.Msg = "获取信息失败"
  463. br.Msg = "获取帖子总数失败,Err:" + err.Error()
  464. return
  465. }
  466. page = paging.GetPaging(currentIndex, pageSize, total)
  467. list, err := models.GetHomeList(condition, pars, startSize, pageSize)
  468. if err != nil {
  469. br.Msg = "获取信息失败"
  470. br.Msg = "获取帖子数据失败,Err:" + err.Error()
  471. return
  472. }
  473. for k, v := range list {
  474. list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  475. }
  476. if categoryId > 0 {
  477. detail, errCategory := models.GetdetailByCategoryId(categoryId)
  478. if errCategory != nil {
  479. br.Msg = "获取信息失败"
  480. br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId)
  481. return
  482. }
  483. resp.MatchTypeName = detail.MatchTypeName
  484. }
  485. lenList := len(list)
  486. for i := 0; i < lenList; i++ {
  487. item := list[i]
  488. list[i].Body = ""
  489. list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  490. list[i].Annotation, _ = services.GetReportContentTextSub(item.Annotation)
  491. //行业比较研究、资金流向,显示报告的摘要
  492. if resp.MatchTypeName == "行业比较研究" || resp.MatchTypeName == "资金流向" {
  493. list[i].Annotation = list[i].Abstract
  494. }
  495. }
  496. resp.CategoryImgUrlPc = mapChartPermission[detail.ChartPermissionName]
  497. if len(list) == 0 {
  498. list = make([]*models.HomeArticle, 0)
  499. }
  500. resp.List = list
  501. resp.Paging = page
  502. br.Ret = 200
  503. br.Success = true
  504. br.Msg = "获取成功"
  505. br.Data = resp
  506. }
  507. // @Title 产业关注/取消关注
  508. // @Description 产业关注/取消关注 接口
  509. // @Param request body models.CygxIndustryFllowRep true "type json string"
  510. // @Success 200
  511. // @router /industrial/fllow [post]
  512. func (this *ReportController) IndustrialFllow() {
  513. br := new(models.BaseResponse).Init()
  514. defer func() {
  515. this.Data["json"] = br
  516. this.ServeJSON()
  517. }()
  518. user := this.User
  519. if user == nil {
  520. br.Msg = "请重新登录"
  521. br.Ret = 408
  522. return
  523. }
  524. uid := user.UserId
  525. var req models.CygxIndustryFllowRep
  526. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  527. if err != nil {
  528. br.Msg = "参数解析异常!"
  529. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  530. return
  531. }
  532. industrialManagementId := req.IndustrialManagementId
  533. var condition string
  534. countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
  535. if err != nil {
  536. br.Msg = "获取数据失败!"
  537. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  538. return
  539. }
  540. if countIndustrial == 0 {
  541. br.Msg = "产业不存在!"
  542. br.ErrMsg = "产业ID不存在:" + strconv.Itoa(industrialManagementId)
  543. return
  544. }
  545. count, err := models.GetCountCygxIndustryFllow(industrialManagementId, user.Mobile, condition)
  546. if err != nil {
  547. br.Msg = "获取数据失败!"
  548. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  549. return
  550. }
  551. resp := new(models.CygxIndustryFllowResp)
  552. if count == 0 {
  553. item := new(models.CygxIndustryFllow)
  554. item.IndustrialManagementId = industrialManagementId
  555. item.UserId = uid
  556. item.Email = user.Email
  557. item.Mobile = user.Mobile
  558. item.RealName = user.RealName
  559. item.CompanyId = user.CompanyId
  560. item.CompanyName = user.CompanyName
  561. item.Type = 1
  562. item.CreateTime = time.Now()
  563. item.ModifyTime = time.Now()
  564. _, err = models.AddCygxIndustryFllow(item)
  565. if err != nil {
  566. br.Msg = "操作失败"
  567. br.ErrMsg = "操作失败,Err:" + err.Error()
  568. return
  569. }
  570. resp.Status = 1
  571. br.Msg = "关注成功"
  572. } else {
  573. err = models.RemoveCygxIndustryFllow(uid, industrialManagementId)
  574. if err != nil {
  575. br.Msg = "操作失败"
  576. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  577. return
  578. }
  579. resp.Status = 2
  580. br.Msg = "已取消关注"
  581. }
  582. //处理是否关注全部赛道字段
  583. go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
  584. br.Ret = 200
  585. br.Success = true
  586. br.Data = resp
  587. }
  588. // @Title 行业关注/取消关注
  589. // @Description 行业关注/取消关注 接口
  590. // @Param request body models.CygxCategoryFllowRep true "type json string"
  591. // @Success 200
  592. // @router /category/fllow [post]
  593. func (this *ReportController) CategoryFllow() {
  594. br := new(models.BaseResponse).Init()
  595. defer func() {
  596. this.Data["json"] = br
  597. this.ServeJSON()
  598. }()
  599. user := this.User
  600. if user == nil {
  601. br.Msg = "请重新登录"
  602. br.Ret = 408
  603. return
  604. }
  605. uid := user.UserId
  606. var req models.CygxCategoryFllowRep
  607. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  608. if err != nil {
  609. br.Msg = "参数解析异常!"
  610. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  611. return
  612. }
  613. categoryId := req.CategoryId
  614. var condition string
  615. countCategory, err := models.GetCategoryCount(categoryId)
  616. if err != nil {
  617. br.Msg = "获取数据失败!"
  618. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  619. return
  620. }
  621. if countCategory == 0 {
  622. br.Msg = "产业不存在!"
  623. br.ErrMsg = "产业ID不存在:" + strconv.Itoa(categoryId)
  624. return
  625. }
  626. count, err := models.GetCountCategoryFllow(categoryId, user.Mobile, condition)
  627. if err != nil {
  628. br.Msg = "获取数据失败!"
  629. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  630. return
  631. }
  632. resp := new(models.CygxIndustryFllowResp)
  633. if count == 0 {
  634. item := new(models.CygxXzsChooseCategory)
  635. item.CategoryId = categoryId
  636. item.UserId = uid
  637. item.Email = user.Email
  638. item.Mobile = user.Mobile
  639. item.RealName = user.RealName
  640. item.CompanyId = user.CompanyId
  641. item.CompanyName = user.CompanyName
  642. item.CreateTime = time.Now()
  643. item.ModifyTime = time.Now()
  644. _, err = models.AddCygxCategoryFllow(item)
  645. if err != nil {
  646. br.Msg = "操作失败"
  647. br.ErrMsg = "操作失败,Err:" + err.Error()
  648. return
  649. }
  650. resp.Status = 1
  651. br.Msg = "关注成功"
  652. } else {
  653. err = models.RemoveCygxCategoryFllow(user.Mobile, categoryId)
  654. if err != nil {
  655. br.Msg = "操作失败"
  656. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  657. return
  658. }
  659. resp.Status = 2
  660. br.Msg = "已取消关注"
  661. }
  662. br.Ret = 200
  663. br.Success = true
  664. br.Data = resp
  665. }
  666. // @Title 报告搜索
  667. // @Description 报告搜索接口
  668. // @Param PageSize query int true "每页数据条数"
  669. // @Param CurrentIndex query int true "当前页页码,从1开始"
  670. // @Param KeyWord query string true "搜索关键词"
  671. // @Success 200 {object} models.ReoprtSearchResp
  672. // @router /searchReport [get]
  673. func (this *MobileReportController) SearchReport() {
  674. br := new(models.BaseResponse).Init()
  675. defer func() {
  676. this.Data["json"] = br
  677. this.ServeJSON()
  678. }()
  679. user := this.User
  680. if user == nil {
  681. br.Msg = "请重新登录"
  682. br.Ret = 408
  683. return
  684. }
  685. pageSize, _ := this.GetInt("PageSize")
  686. currentIndex, _ := this.GetInt("CurrentIndex")
  687. keyWord := this.GetString("KeyWord")
  688. var condition string
  689. var conditionSql string
  690. //var sqlGroup string
  691. var total int
  692. var startSize int
  693. if pageSize <= 0 {
  694. pageSize = utils.PageSize20
  695. }
  696. if currentIndex <= 0 {
  697. currentIndex = 1
  698. }
  699. startSize = paging.StartIndex(currentIndex, pageSize)
  700. page := paging.GetPaging(currentIndex, pageSize, total)
  701. resp := new(models.ReoprtSearchResp)
  702. //匹配报告标题、
  703. condition = ` AND ( a.title LIKE '%` + keyWord + `%' OR a.body LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
  704. conditionSql = ` AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + condition + ` OR ( article_type = 'lyjh' ` + condition + ` ) `
  705. total, err := models.GetReoprtSearchCount(conditionSql)
  706. if err != nil {
  707. br.Msg = "获取信息失败"
  708. br.Msg = "获取总数失败,Err:" + err.Error()
  709. return
  710. }
  711. //listHz, err := models.GetReoprtSearchList(` AND a.article_id < `+strconv.Itoa(utils.SummaryArticleId)+condition+` OR ( article_type = 'lyjh' `+condition+` ) `+sqlGroup, user.UserId, startSize, pageSize)
  712. listHz, err := models.GetReoprtSearchList(conditionSql, user.UserId, startSize, pageSize)
  713. if err != nil {
  714. br.Msg = "获取信息失败"
  715. br.ErrMsg = "获取文章列表失败,Err:" + err.Error()
  716. return
  717. }
  718. for k, _ := range listHz {
  719. listHz[k].Source = 1
  720. }
  721. var articleIds string
  722. for _, v := range listHz {
  723. articleIds += strconv.Itoa(v.ArticleId) + ","
  724. }
  725. articleIds = strings.TrimRight(articleIds, ",")
  726. silcearticleIds := strings.Split(articleIds, ",")
  727. //获取文章关联的产业
  728. var pars []interface{}
  729. pars = make([]interface{}, 0)
  730. articleIdList := make([]string, 0)
  731. for _, v := range silcearticleIds {
  732. articleIdList = append(articleIdList, v)
  733. }
  734. condition = ` AND mg.article_id IN ( ` + utils.GetOrmInReplace(len(silcearticleIds)) + ` ) `
  735. pars = append(pars, articleIdList)
  736. industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
  737. if err != nil {
  738. br.Msg = "获取失败"
  739. br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
  740. return
  741. }
  742. industrialMap := make(map[int][]*models.IndustrialManagementResp)
  743. if len(industrialList) > 0 {
  744. for _, v := range industrialList {
  745. item := new(models.IndustrialManagementResp)
  746. //item.ArticleId = v.ArticleId
  747. item.IndustrialManagementId = v.IndustrialManagementId
  748. item.IndustryName = v.IndustryName
  749. item.ChartPermissionId = v.ChartPermissionId
  750. industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
  751. }
  752. }
  753. detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url")
  754. if err != nil {
  755. br.Msg = "获取数据失败"
  756. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  757. return
  758. }
  759. categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}")
  760. mapCategoryUrl := make(map[string]string)
  761. var categoryId string
  762. var imgUrlChart string
  763. for _, v := range categoryUrlList {
  764. vslice := strings.Split(v, "_")
  765. categoryId = vslice[0]
  766. imgUrlChart = vslice[len(vslice)-1]
  767. mapCategoryUrl[categoryId] = imgUrlChart
  768. }
  769. for k, v := range listHz {
  770. if len(industrialMap[v.ArticleId]) > 0 {
  771. listHz[k].List = industrialMap[v.ArticleId]
  772. } else {
  773. listHz[k].List = make([]*models.IndustrialManagementResp, 0)
  774. }
  775. listHz[k].Body = ""
  776. listHz[k].Abstract, _ = services.GetReportContentTextSub(v.Abstract)
  777. listHz[k].Annotation, _ = services.GetReportContentTextSub(v.Annotation)
  778. //行业比较研究、资金流向,显示报告的摘要
  779. if listHz[k].CategoryName == "行业比较研究" || listHz[k].CategoryName == "资金流向" {
  780. listHz[k].Annotation = listHz[k].Abstract
  781. }
  782. listHz[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
  783. }
  784. if keyWord != "" {
  785. go services.AddUserSearchLog(user, keyWord, 5)
  786. }
  787. if len(listHz) == 0 {
  788. listHz = make([]*models.ArticleCollectionResp, 0)
  789. }
  790. page = paging.GetPaging(currentIndex, pageSize, total)
  791. resp.Paging = page
  792. resp.ListHz = listHz
  793. br.Ret = 200
  794. br.Success = true
  795. br.Msg = "获取成功"
  796. br.Data = resp
  797. }
  798. // @Title 资源包搜索
  799. // @Description 资源包搜索接口
  800. // @Param KeyWord query string true "搜索关键词"
  801. // @Success 200 {object} models.SearchResourceResp
  802. // @router /searchResource [get]
  803. func (this *MobileReportController) SearchResource() {
  804. br := new(models.BaseResponse).Init()
  805. defer func() {
  806. this.Data["json"] = br
  807. this.ServeJSON()
  808. }()
  809. user := this.User
  810. if user == nil {
  811. br.Msg = "请重新登录"
  812. br.Ret = 408
  813. return
  814. }
  815. uid := user.UserId
  816. fllowList, err := models.GetUserFllowIndustrialList(uid)
  817. if err != nil {
  818. br.Msg = "获取失败"
  819. br.ErrMsg = "获取失败,GetUserFllowIndustrialList Err:" + err.Error()
  820. return
  821. }
  822. fllowMap := make(map[int]int)
  823. if len(fllowList) > 0 {
  824. for _, v := range fllowList {
  825. fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId
  826. }
  827. }
  828. keyWord := this.GetString("KeyWord")
  829. var condition string
  830. var conditionOr string
  831. conditionOr += ` OR ( m.subject_names LIKE '%` + keyWord + `%' AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + ` AND publish_status = 1 ) `
  832. condition = ` AND m.industry_name LIKE '%` + keyWord + `%' AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + conditionOr
  833. listHz, err := models.GetSearchResourceList(condition)
  834. if err != nil {
  835. br.Msg = "获取信息失败"
  836. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  837. return
  838. }
  839. //合并产业关联的标的
  840. listSubjcet, err := models.GetThemeHeatSubjectList("")
  841. if err != nil {
  842. br.Msg = "获取信息失败"
  843. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  844. return
  845. }
  846. industrialIdArr := make([]int, 0)
  847. for k, v := range listHz {
  848. listHz[k].Source = 1
  849. if fllowMap[v.IndustrialManagementId] > 0 {
  850. listHz[k].IsFollow = true
  851. }
  852. industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
  853. }
  854. if len(industrialIdArr) > 0 {
  855. //合并产业关联的标的
  856. listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialId(industrialIdArr)
  857. if err != nil {
  858. br.Msg = "获取信息失败"
  859. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  860. return
  861. }
  862. mapIndustrial := make(map[string]int)
  863. for _, v := range listSubjcet {
  864. for k2, v2 := range listHz {
  865. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
  866. listHz[k2].IndustrialSubjectList = append(listHz[k2].IndustrialSubjectList, v)
  867. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId
  868. }
  869. }
  870. }
  871. }
  872. mapUPdateTime := make(map[int]string)
  873. articleIdArr := make([]int, 0)
  874. //获取这些产业下最新更新的文章
  875. fmt.Println(industrialIdArr)
  876. listUpdateTime, err := models.GetNewArticleDetailByIndustrialIds(industrialIdArr)
  877. if err != nil && err.Error() != utils.ErrNoRow() {
  878. br.Msg = "获取信息失败"
  879. br.ErrMsg = "获取信息失败 GetNewArticleDetailByIndustrialIds ,Err:" + err.Error()
  880. return
  881. }
  882. for _, v := range listUpdateTime {
  883. mapUPdateTime[v.IndustrialManagementId] = v.PublishDate
  884. articleIdArr = append(articleIdArr, v.ArticleId)
  885. }
  886. for k, v := range listHz {
  887. listHz[k].UpdateTime = utils.TimeRemoveHms(mapUPdateTime[v.IndustrialManagementId])
  888. }
  889. if keyWord != "" {
  890. go services.AddUserSearchLog(user, keyWord, 4)
  891. }
  892. resp := new(models.SearchResourceResp)
  893. if len(listHz) == 0 {
  894. listHz = make([]*models.IndustrialManagement, 0)
  895. }
  896. resp.ListHz = listHz
  897. br.Ret = 200
  898. br.Success = true
  899. br.Msg = "获取成功"
  900. br.Data = resp
  901. }
  902. // @Title 报告搜索、资源包搜索接口
  903. // @Description 报告搜索、资源包搜索接口接口
  904. // @Param KeyWord query string true "搜索关键词"
  905. // @Param PageSize query int true "每页数据条数"
  906. // @Param CurrentIndex query int true "当前页页码,从1开始"
  907. // @Param SearchType query int true "1:综合,2:全部"
  908. // @Success 200 {object} models.SearchReportAndResourceResp
  909. // @router /searchReportAndResource [get]
  910. func (this *MobileReportController) SearchReportAndResource() {
  911. br := new(models.BaseResponse).Init()
  912. defer func() {
  913. this.Data["json"] = br
  914. this.ServeJSON()
  915. }()
  916. user := this.User
  917. if user == nil {
  918. br.Msg = "请重新登录"
  919. br.Ret = 408
  920. return
  921. }
  922. uid := user.UserId
  923. keyWord := this.GetString("KeyWord")
  924. pageSize, _ := this.GetInt("PageSize")
  925. currentIndex, _ := this.GetInt("CurrentIndex")
  926. searchType, _ := this.GetInt("SearchType")
  927. var total int
  928. var startSize int
  929. if pageSize <= 0 {
  930. pageSize = utils.PageSize20
  931. }
  932. if currentIndex <= 0 {
  933. currentIndex = 1
  934. }
  935. startSize = paging.StartIndex(currentIndex, pageSize)
  936. page := paging.GetPaging(currentIndex, pageSize, total)
  937. var condition string
  938. var conditionSql string
  939. //匹配报告标题、
  940. condition = ` AND ( a.title LIKE '%` + keyWord + `%' OR a.body LIKE '%` + keyWord + `%') AND a.publish_status = 1 `
  941. conditionSql = ` AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + condition + ` OR ( article_type = 'lyjh' ` + condition + ` ) `
  942. total, err := models.GetReoprtSearchCount(conditionSql)
  943. if err != nil {
  944. br.Msg = "获取信息失败"
  945. br.Msg = "获取总数失败,Err:" + err.Error()
  946. return
  947. }
  948. ListHzReport, err := services.GetReoprtSearchListHz(conditionSql, user.UserId, startSize, pageSize)
  949. if err != nil {
  950. br.Msg = "获取失败"
  951. br.ErrMsg = "获取失败,GetReoprtSearchListHz Err:" + err.Error()
  952. return
  953. }
  954. if len(ListHzReport) == 0 {
  955. ListHzReport = make([]*models.ArticleCollectionResp, 0)
  956. }
  957. fllowList, err := models.GetUserFllowIndustrialList(uid)
  958. if err != nil {
  959. br.Msg = "获取失败"
  960. br.ErrMsg = "获取失败,GetUserFllowIndustrialList Err:" + err.Error()
  961. return
  962. }
  963. fllowMap := make(map[int]int)
  964. if len(fllowList) > 0 {
  965. for _, v := range fllowList {
  966. fllowMap[v.IndustrialManagementId] = v.IndustrialManagementId
  967. }
  968. }
  969. var conditionOr string
  970. conditionOr += ` OR ( m.subject_names LIKE '%` + keyWord + `%' AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + ` AND publish_status = 1 ) `
  971. condition = ` AND m.industry_name LIKE '%` + keyWord + `%' AND a.article_id < ` + strconv.Itoa(utils.SummaryArticleId) + conditionOr
  972. var pageSizeHzResource int
  973. if searchType == 1 {
  974. pageSizeHzResource = 5
  975. } else {
  976. pageSizeHzResource = 100
  977. }
  978. listHzResource, err := models.GetSearchResourceListHz(condition, 0, pageSizeHzResource)
  979. if err != nil {
  980. br.Msg = "获取信息失败"
  981. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  982. return
  983. }
  984. conditionOr = ` OR ( m.subject_names LIKE '%` + keyWord + `%' AND a.article_id >= ` + strconv.Itoa(utils.SummaryArticleId) + ` AND publish_status = 1 ) `
  985. condition = ` AND m.industry_name LIKE '%` + keyWord + `%' AND a.article_id >= ` + strconv.Itoa(utils.SummaryArticleId) + conditionOr
  986. //合并产业关联的标的
  987. listSubjcet, err := models.GetThemeHeatSubjectList("")
  988. if err != nil {
  989. br.Msg = "获取信息失败"
  990. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  991. return
  992. }
  993. industrialIdArr := make([]int, 0)
  994. for k, v := range listHzResource {
  995. listHzResource[k].Source = 1
  996. if fllowMap[v.IndustrialManagementId] > 0 {
  997. listHzResource[k].IsFollw = true
  998. }
  999. industrialIdArr = append(industrialIdArr, v.IndustrialManagementId)
  1000. }
  1001. if len(industrialIdArr) > 0 {
  1002. //合并产业关联的标的
  1003. listSubjcet, err = models.GetIndustrialSubjectAllByIndustrialId(industrialIdArr)
  1004. if err != nil {
  1005. br.Msg = "获取信息失败"
  1006. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  1007. return
  1008. }
  1009. mapIndustrial := make(map[string]int)
  1010. for _, v := range listSubjcet {
  1011. for k2, v2 := range listHzResource {
  1012. if v2.IndustrialManagementId == v.IndustrialManagementId && mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] == 0 {
  1013. listHzResource[k2].IndustrialSubjectList = append(listHzResource[k2].IndustrialSubjectList, v)
  1014. mapIndustrial[fmt.Sprint(v2.IndustrialManagementId, "Hz", v.SubjectName)] = v2.IndustrialManagementId
  1015. }
  1016. }
  1017. }
  1018. }
  1019. resp := new(models.SearchReportAndResourceResp)
  1020. if len(listHzResource) == 0 {
  1021. listHzResource = make([]*models.IndustrialManagementHotResp, 0)
  1022. }
  1023. if keyWord != "" {
  1024. go services.AddUserSearchLog(user, keyWord, 5)
  1025. }
  1026. page = paging.GetPaging(currentIndex, pageSize, total)
  1027. resp.Paging = page
  1028. resp.ListHzResource = listHzResource
  1029. resp.ListHzReport = ListHzReport
  1030. br.Ret = 200
  1031. br.Success = true
  1032. br.Msg = "获取成功"
  1033. br.Data = resp
  1034. }