research.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. package controllers
  2. import (
  3. "github.com/rdlucklib/rdluck_tools/paging"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/services"
  6. "hongze/hongze_clpt/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. type MobileResearchController struct {
  12. BaseAuthMobileController
  13. }
  14. // @Title 研选文章类型列表
  15. // @Description 研选文章类型列表接口
  16. // @Success 200 {object} models.CygxArticleTypeListResp
  17. // @router /article/typeList [get]
  18. func (this *MobileResearchController) ArticleType() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. user := this.User
  25. if user == nil {
  26. br.Msg = "请重新登录"
  27. br.Ret = 408
  28. return
  29. }
  30. var condition string
  31. condition = " AND is_show_yanx = 1 "
  32. list, err := models.GetCygxArticleTypeListCondition(condition)
  33. if err != nil {
  34. br.Msg = "获取信息失败"
  35. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  36. return
  37. }
  38. resp := new(models.CygxArticleTypeListResp)
  39. for _, v := range list {
  40. item := models.CygxArticleTypeResp{
  41. ArticleTypeId: v.ArticleTypeId,
  42. ArticleTypeName: v.ArticleTypeName,
  43. ButtonStyle: v.ButtonStyle,
  44. }
  45. resp.List = append(resp.List, &item)
  46. }
  47. br.Ret = 200
  48. br.Success = true
  49. br.Msg = "获取成功"
  50. br.Data = resp
  51. }
  52. // @Title 研选最新报告列表
  53. // @Description 研选最新报告列表接口
  54. // @Param PageSize query int true "每页数据条数"
  55. // @Param CurrentIndex query int true "当前页页码,从1开始"
  56. // @Param ArticleTypeIds query array true "文章类型ID多个用 , 隔开"
  57. // @Success 200 {object} models.IndustrialManagementNewList
  58. // @router /article/newList [get]
  59. func (this *MobileResearchController) ArticleNewList() {
  60. br := new(models.BaseResponse).Init()
  61. defer func() {
  62. this.Data["json"] = br
  63. this.ServeJSON()
  64. }()
  65. user := this.User
  66. if user == nil {
  67. br.Msg = "请重新登录"
  68. br.Ret = 408
  69. return
  70. }
  71. pageSize, _ := this.GetInt("PageSize")
  72. currentIndex, _ := this.GetInt("CurrentIndex")
  73. articleTypeIds := this.GetString("ArticleTypeIds")
  74. var startSize int
  75. if pageSize <= 0 {
  76. pageSize = utils.PageSize20
  77. }
  78. if currentIndex <= 0 {
  79. currentIndex = 1
  80. }
  81. startSize = paging.StartIndex(currentIndex, pageSize)
  82. var condition string
  83. var pars []interface{}
  84. condition = ` AND publish_status = 1 `
  85. if articleTypeIds == "" {
  86. var conditiontype string
  87. conditiontype = " AND is_show_yanx = 1 "
  88. listType, err := models.GetCygxArticleTypeListCondition(conditiontype)
  89. if err != nil {
  90. br.Msg = "获取信息失败"
  91. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  92. return
  93. }
  94. for _, v := range listType {
  95. articleTypeIds += strconv.Itoa(v.ArticleTypeId) + ","
  96. }
  97. articleTypeIds = strings.TrimRight(articleTypeIds, ",")
  98. }
  99. condition += ` AND a.article_type_id IN (` + articleTypeIds + `) `
  100. total, err := models.GetArticleResearchCount(condition, pars)
  101. if err != nil {
  102. br.Msg = "获取信息失败"
  103. br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
  104. return
  105. }
  106. list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId)
  107. if err != nil {
  108. br.Msg = "获取信息失败"
  109. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  110. return
  111. }
  112. list, err = services.HandleArticleCategoryImg(list)
  113. if err != nil {
  114. br.Msg = "获取信息失败"
  115. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  116. return
  117. }
  118. //处理对应的文章类型标签按钮
  119. nameMap, styleMap, err := services.GetArticleTypeMap()
  120. if err != nil {
  121. br.Msg = "获取信息失败"
  122. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  123. return
  124. }
  125. page := paging.GetPaging(currentIndex, pageSize, total)
  126. resp := new(models.ArticleResearchListResp)
  127. for _, v := range list {
  128. item := models.ArticleResearchResp{
  129. ArticleId: v.ArticleId,
  130. ArticleTypeId: v.ArticleTypeId,
  131. Title: v.Title,
  132. PublishDate: v.PublishDate,
  133. DepartmentId: v.DepartmentId,
  134. NickName: v.NickName,
  135. IsCollect: v.IsCollect,
  136. Pv: v.Pv,
  137. CollectNum: v.CollectNum,
  138. Abstract: v.Abstract,
  139. Annotation: v.Annotation,
  140. ImgUrlPc: v.ImgUrlPc,
  141. ArticleTypeName: nameMap[v.ArticleTypeId],
  142. ButtonStyle: styleMap[v.ArticleTypeId],
  143. List: v.List,
  144. }
  145. resp.List = append(resp.List, &item)
  146. }
  147. resp.Paging = page
  148. br.Ret = 200
  149. br.Success = true
  150. br.Msg = "获取成功"
  151. br.Data = resp
  152. }
  153. // @Title KOL榜列表
  154. // @Description KOL榜列表接口
  155. // @Param PageSize query int true "每页数据条数"
  156. // @Param CurrentIndex query int true "当前页页码,从1开始"
  157. // @Param ThemeType query int true "主题类型,1关注度、2更新时间 "
  158. // @Success 200 {object} models.DepartmentListResp
  159. // @router /kolList [get]
  160. func (this *MobileResearchController) KolList() {
  161. br := new(models.BaseResponse).Init()
  162. defer func() {
  163. this.Data["json"] = br
  164. this.ServeJSON()
  165. }()
  166. user := this.User
  167. if user == nil {
  168. br.Msg = "请重新登录"
  169. br.Ret = 408
  170. return
  171. }
  172. themeType, _ := this.GetInt("ThemeType")
  173. pageSize, _ := this.GetInt("PageSize")
  174. currentIndex, _ := this.GetInt("CurrentIndex")
  175. var startSize int
  176. if pageSize <= 0 {
  177. pageSize = utils.PageSize15
  178. }
  179. if currentIndex <= 0 {
  180. currentIndex = 1
  181. }
  182. startSize = utils.StartIndex(currentIndex, pageSize)
  183. total, err := models.GetDepartmentlistCount("")
  184. if err != nil {
  185. br.Msg = "获取失败"
  186. br.ErrMsg = "获取失败,Err:" + err.Error()
  187. return
  188. }
  189. var condition string
  190. if themeType != 2 {
  191. condition = `ORDER BY fllow_num DESC `
  192. } else {
  193. condition = `ORDER BY publish_date DESC `
  194. }
  195. list, err := models.GetDepartmentList(condition, user.UserId, startSize, pageSize)
  196. if err != nil {
  197. br.Msg = "获取信息失败"
  198. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  199. return
  200. }
  201. listIndustrial, err := models.GetIndustrialDepartmentList()
  202. if err != nil {
  203. br.Msg = "获取信息失败"
  204. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  205. return
  206. }
  207. departmentMap := make(map[string]string)
  208. for k, v := range list {
  209. if v.FllowNum > 0 {
  210. list[k].IsFollow = true
  211. }
  212. list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  213. for _, v2 := range listIndustrial {
  214. if v2.DepartmentId == v.DepartmentId {
  215. if departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] == "" && len(list[k].List) < 4 {
  216. list[k].List = append(list[k].List, v2)
  217. departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] = v.NickName
  218. }
  219. }
  220. }
  221. }
  222. resp := new(models.DepartmentListResp)
  223. page := paging.GetPaging(currentIndex, pageSize, total)
  224. resp.Paging = page
  225. resp.List = list
  226. br.Ret = 200
  227. br.Success = true
  228. br.Msg = "获取成功"
  229. br.Data = resp
  230. }
  231. // @Title 主题热度/近期更新更多,列表
  232. // @Description 主题热度/近期更新更多,列表接口
  233. // @Param ThemeType query int true "主题类型,1主题热度、2近期更新 默认1"
  234. // @Param PageSize query int true "每页数据条数"
  235. // @Param CurrentIndex query int true "当前页页码,从1开始"
  236. // @Success 200 {object} models.IndustrialManagementHotListResp
  237. // @router /hotList [get]
  238. func (this *MobileResearchController) HotList() {
  239. br := new(models.BaseResponse).Init()
  240. defer func() {
  241. this.Data["json"] = br
  242. this.ServeJSON()
  243. }()
  244. user := this.User
  245. if user == nil {
  246. br.Msg = "请重新登录"
  247. br.Ret = 408
  248. return
  249. }
  250. themeType, _ := this.GetInt("ThemeType", 1)
  251. pageSize, _ := this.GetInt("PageSize")
  252. currentIndex, _ := this.GetInt("CurrentIndex")
  253. var startSize int
  254. if pageSize <= 0 {
  255. pageSize = utils.PageSize15
  256. }
  257. if currentIndex <= 0 {
  258. currentIndex = 1
  259. }
  260. startSize = utils.StartIndex(currentIndex, pageSize)
  261. var condition string
  262. if themeType == 1 {
  263. condition = `ORDER BY publish_date DESC `
  264. } else {
  265. condition = `ORDER BY sum_num DESC `
  266. }
  267. total, err := models.GetThemeHeatListCount("")
  268. if err != nil {
  269. br.Msg = "获取失败"
  270. br.ErrMsg = "获取失败,Err:" + err.Error()
  271. return
  272. }
  273. list, err := models.GetThemeHeatList(user.UserId, condition, startSize, pageSize)
  274. if err != nil {
  275. br.Msg = "获取信息失败"
  276. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  277. return
  278. }
  279. condition = ` AND a.article_type_id > 0 `
  280. listSubjcet, err := models.GetThemeHeatSubjectList(condition)
  281. if err != nil {
  282. br.Msg = "获取信息失败"
  283. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  284. return
  285. }
  286. mapHot := make(map[string]int)
  287. condition = ` ORDER BY sum_num DESC `
  288. listHot, err := models.GetThemeHeatList(user.UserId, condition, 0, 3)
  289. if err != nil {
  290. br.Msg = "获取信息失败"
  291. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  292. return
  293. }
  294. for _, v := range listHot {
  295. mapHot[v.IndustryName] = v.IndustrialManagementId
  296. }
  297. nowTime := time.Now().Local()
  298. threeMonBefore := nowTime.AddDate(0, -3, 0)
  299. for k, v := range list {
  300. if v.MinReportTime != "" {
  301. t, err := time.Parse(utils.FormatDateTime, v.MinReportTime)
  302. if err != nil {
  303. br.Msg = "获取信息失败"
  304. br.ErrMsg = "报告最早发布时间有误,Err:" + err.Error()
  305. return
  306. }
  307. if t.After(threeMonBefore) {
  308. list[k].IsNew = true
  309. }
  310. }
  311. if v.FllowNum > 0 {
  312. list[k].IsFollw = true
  313. }
  314. for _, v2 := range listSubjcet {
  315. if v2.IndustrialManagementId == v.IndustrialManagementId {
  316. list[k].IndustrialSubjectList = append(list[k].IndustrialSubjectList, v2)
  317. }
  318. }
  319. if mapHot[v.IndustryName] > 0 {
  320. list[k].IsHot = true
  321. }
  322. list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  323. }
  324. page := paging.GetPaging(currentIndex, pageSize, total)
  325. resp := new(models.IndustrialManagementHotListResp)
  326. resp.Paging = page
  327. resp.List = list
  328. br.Ret = 200
  329. br.Success = true
  330. br.Msg = "获取成功"
  331. br.Data = resp
  332. }
  333. // @Title 主题详情
  334. // @Description 主题详情接口
  335. // @Param IndustrialManagementId query int true "分类ID"
  336. // @Success 200 {object} models.GetThemeDetailResp
  337. // @router /theme/detail [get]
  338. func (this *MobileResearchController) ThemeDetail() {
  339. br := new(models.BaseResponse).Init()
  340. defer func() {
  341. this.Data["json"] = br
  342. this.ServeJSON()
  343. }()
  344. user := this.User
  345. if user == nil {
  346. br.Msg = "请重新登录"
  347. br.Ret = 408
  348. return
  349. }
  350. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  351. if industrialManagementId < 1 {
  352. br.Msg = "请输入产业ID"
  353. return
  354. }
  355. detailIndustrial, err := models.GetIndustrialManagementDetail(industrialManagementId)
  356. if err != nil {
  357. br.Msg = "获取信息失败"
  358. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  359. return
  360. }
  361. var condition string
  362. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  363. if err != nil {
  364. br.Msg = "获取信息失败"
  365. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  366. return
  367. }
  368. if articleTypeIds != "" {
  369. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  370. } else {
  371. br.Msg = "获取信息失败"
  372. br.ErrMsg = "研选分类ID不能为空"
  373. return
  374. }
  375. resp := new(models.GetThemeDetailResp)
  376. list, err := models.GetThemeDetail(user.UserId, industrialManagementId, condition)
  377. if err != nil {
  378. br.Msg = "获取信息失败"
  379. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  380. return
  381. }
  382. list, err = services.HandleArticleCategoryImg(list)
  383. if err != nil {
  384. br.Msg = "获取信息失败"
  385. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  386. return
  387. }
  388. //处理对应的文章类型标签按钮
  389. nameMap, styleMap, err := services.GetArticleTypeMap()
  390. if err != nil {
  391. br.Msg = "获取信息失败"
  392. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  393. return
  394. }
  395. var articleIds []int
  396. for _, v := range list {
  397. item := models.ArticleResearchResp{
  398. ArticleId: v.ArticleId,
  399. ArticleTypeId: v.ArticleTypeId,
  400. Title: v.Title,
  401. PublishDate: v.PublishDate,
  402. DepartmentId: v.DepartmentId,
  403. NickName: v.NickName,
  404. IsCollect: v.IsCollect,
  405. Pv: v.Pv,
  406. CollectNum: v.CollectNum,
  407. Abstract: v.Abstract,
  408. Annotation: v.Annotation,
  409. ImgUrlPc: v.ImgUrlPc,
  410. ArticleTypeName: nameMap[v.ArticleTypeId],
  411. ButtonStyle: styleMap[v.ArticleTypeId],
  412. List: v.List,
  413. }
  414. resp.List = append(resp.List, &item)
  415. articleIds = append(articleIds, v.ArticleId)
  416. }
  417. //处理用户数是否关注该产业
  418. userFollowIndustrialMap, err := services.GetUserFollowIndustrialMap(user)
  419. if err != nil {
  420. br.Msg = "获取信息失败"
  421. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  422. return
  423. }
  424. if _, ok := userFollowIndustrialMap[industrialManagementId]; ok {
  425. resp.IsFollw = true
  426. }
  427. //处理文章关联的标的
  428. articleGroupSubjectMap, listSubtect, err := services.GetArticleGroupSubjectMap(articleIds)
  429. if err != nil {
  430. br.Msg = "获取信息失败"
  431. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  432. return
  433. }
  434. if len(articleGroupSubjectMap) > 0 {
  435. for k, v := range resp.List {
  436. resp.List[k].ListSubject = articleGroupSubjectMap[v.ArticleId]
  437. }
  438. resp.ListSubject = listSubtect
  439. }
  440. resp.IndustryName = detailIndustrial.IndustryName
  441. resp.IndustrialManagementId = detailIndustrial.IndustrialManagementId
  442. br.Ret = 200
  443. br.Success = true
  444. br.Msg = "获取成功"
  445. br.Data = resp
  446. }
  447. // @Title 研选作者详情
  448. // @Description 研选作者详情接口
  449. // @Param DepartmentId query int true "作者ID"
  450. // @Success 200 {object} models.DepartmentDetailResp
  451. // @router /departmentId/detail [get]
  452. func (this *MobileResearchController) DepartmentIdDetail() {
  453. br := new(models.BaseResponse).Init()
  454. defer func() {
  455. this.Data["json"] = br
  456. this.ServeJSON()
  457. }()
  458. user := this.User
  459. if user == nil {
  460. br.Msg = "请重新登录"
  461. br.Ret = 408
  462. return
  463. }
  464. pageSize, _ := this.GetInt("PageSize")
  465. currentIndex, _ := this.GetInt("CurrentIndex")
  466. var startSize int
  467. if pageSize <= 0 {
  468. pageSize = utils.PageSize20
  469. }
  470. if currentIndex <= 0 {
  471. currentIndex = 1
  472. }
  473. startSize = paging.StartIndex(currentIndex, pageSize)
  474. departmentId, _ := this.GetInt("DepartmentId")
  475. if departmentId < 1 {
  476. br.Msg = "请输入作者ID"
  477. return
  478. }
  479. var condition string
  480. var pars []interface{}
  481. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  482. if err != nil {
  483. br.Msg = "获取信息失败"
  484. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  485. return
  486. }
  487. if articleTypeIds != "" {
  488. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  489. } else {
  490. br.Msg = "获取信息失败"
  491. br.ErrMsg = "研选分类ID不能为空"
  492. return
  493. }
  494. resp := new(models.DepartmentDetailResp)
  495. detail, err := models.GetDepartmentDetail(user.UserId, departmentId)
  496. if err != nil {
  497. br.Msg = "获取信息失败"
  498. br.ErrMsg = "获取作者信息失败,Err:" + err.Error()
  499. return
  500. }
  501. resp.DepartmentId = detail.DepartmentId
  502. resp.NickName = detail.NickName
  503. resp.ImgUrl = detail.ImgUrl
  504. resp.FllowNum = detail.FllowNum
  505. resp.ArticleNum = detail.ArticleNum
  506. resp.CollectNum = detail.CollectNum
  507. if detail.MyFllowNum > 0 {
  508. resp.IsFllow = true
  509. }
  510. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId)
  511. condition += ` AND a.article_type_id IN (` + articleTypeIds + `) `
  512. total, err := models.GetArticleResearchCount(condition, pars)
  513. if err != nil {
  514. br.Msg = "获取信息失败"
  515. br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
  516. return
  517. }
  518. list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId)
  519. if err != nil {
  520. br.Msg = "获取信息失败"
  521. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  522. return
  523. }
  524. list, err = services.HandleArticleCategoryImg(list)
  525. if err != nil {
  526. br.Msg = "获取信息失败"
  527. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  528. return
  529. }
  530. //处理对应的文章类型标签按钮
  531. nameMap, styleMap, err := services.GetArticleTypeMap()
  532. if err != nil {
  533. br.Msg = "获取信息失败"
  534. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  535. return
  536. }
  537. //resp := new(models.ArticleResearchListResp)
  538. for _, v := range list {
  539. item := models.ArticleResearchResp{
  540. ArticleId: v.ArticleId,
  541. ArticleTypeId: v.ArticleTypeId,
  542. Title: v.Title,
  543. PublishDate: v.PublishDate,
  544. DepartmentId: v.DepartmentId,
  545. NickName: v.NickName,
  546. IsCollect: v.IsCollect,
  547. Pv: v.Pv,
  548. CollectNum: v.CollectNum,
  549. Abstract: v.Abstract,
  550. Annotation: v.Annotation,
  551. ImgUrlPc: v.ImgUrlPc,
  552. ArticleTypeName: nameMap[v.ArticleTypeId],
  553. ButtonStyle: styleMap[v.ArticleTypeId],
  554. List: v.List,
  555. }
  556. resp.List = append(resp.List, &item)
  557. }
  558. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId)
  559. listIndustrial, err := models.GetIndustrialManagementNewList(condition)
  560. if err != nil {
  561. br.Msg = "获取信息失败"
  562. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  563. return
  564. }
  565. page := paging.GetPaging(currentIndex, pageSize, total)
  566. resp.ListIndustrial = listIndustrial
  567. resp.Paging = page
  568. br.Ret = 200
  569. br.Success = true
  570. br.Msg = "获取成功"
  571. br.Data = resp
  572. }