research.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/services"
  7. "hongze/hongze_clpt/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. type MobileResearchController struct {
  13. BaseAuthMobileController
  14. }
  15. // @Title 研选文章类型列表
  16. // @Description 研选文章类型列表接口
  17. // @Success 200 {object} models.CygxArticleTypeListResp
  18. // @router /article/typeList [get]
  19. func (this *MobileResearchController) ArticleType() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. user := this.User
  26. if user == nil {
  27. br.Msg = "请重新登录"
  28. br.Ret = 408
  29. return
  30. }
  31. key := utils.YAN_XUAN_TAB_KEY
  32. conf, e := models.GetConfigByCode(key)
  33. if e != nil {
  34. br.Msg = "获取失败"
  35. br.ErrMsg = "获取首页头部导航失败, Err: " + e.Error()
  36. return
  37. }
  38. if conf.ConfigValue == "" {
  39. br.Msg = "获取失败"
  40. br.ErrMsg = "首页头部导航配置值有误"
  41. return
  42. }
  43. list := new(models.CygxArticleTypeListResp)
  44. if e = json.Unmarshal([]byte(conf.ConfigValue), &list); e != nil {
  45. br.Msg = "获取失败"
  46. br.ErrMsg = "首页头部导航配置值解析失败, Err: " + e.Error()
  47. return
  48. }
  49. resp := new(models.CygxArticleTypeListResp)
  50. resp = list
  51. br.Ret = 200
  52. br.Success = true
  53. br.Msg = "获取成功"
  54. br.Data = resp
  55. }
  56. // @Title 研选最新报告列表
  57. // @Description 研选最新报告列表接口
  58. // @Param PageSize query int true "每页数据条数"
  59. // @Param CurrentIndex query int true "当前页页码,从1开始"
  60. // @Param ArticleTypeIds query array true "文章类型ID多个用 , 隔开"
  61. // @Success 200 {object} models.IndustrialManagementNewList
  62. // @router /article/newList [get]
  63. func (this *MobileResearchController) ArticleNewList() {
  64. br := new(models.BaseResponse).Init()
  65. defer func() {
  66. this.Data["json"] = br
  67. this.ServeJSON()
  68. }()
  69. user := this.User
  70. if user == nil {
  71. br.Msg = "请重新登录"
  72. br.Ret = 408
  73. return
  74. }
  75. pageSize, _ := this.GetInt("PageSize")
  76. currentIndex, _ := this.GetInt("CurrentIndex")
  77. articleTypeIds := this.GetString("ArticleTypeIds")
  78. var startSize int
  79. if pageSize <= 0 {
  80. pageSize = utils.PageSize20
  81. }
  82. if currentIndex <= 0 {
  83. currentIndex = 1
  84. }
  85. startSize = paging.StartIndex(currentIndex, pageSize)
  86. var condition string
  87. var conditiontype string
  88. var pars []interface{}
  89. condition = ` AND publish_status = 1 `
  90. if articleTypeIds == "" {
  91. conditiontype = " AND is_show_yanx = 1 "
  92. } else {
  93. conditiontype = ` AND group_id IN (` + articleTypeIds + `) `
  94. }
  95. listType, err := models.GetCygxArticleTypeListCondition(conditiontype)
  96. if err != nil {
  97. br.Msg = "获取信息失败"
  98. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  99. return
  100. }
  101. for _, v := range listType {
  102. articleTypeIds += strconv.Itoa(v.ArticleTypeId) + ","
  103. }
  104. articleTypeIds = strings.TrimRight(articleTypeIds, ",")
  105. condition += ` AND a.article_type_id IN (` + articleTypeIds + `) `
  106. total, err := models.GetArticleResearchCount(condition, pars)
  107. if err != nil {
  108. br.Msg = "获取信息失败"
  109. br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
  110. return
  111. }
  112. list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId)
  113. if err != nil {
  114. br.Msg = "获取信息失败"
  115. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  116. return
  117. }
  118. list, err = services.HandleArticleCategoryImg(list, user)
  119. if err != nil {
  120. br.Msg = "获取信息失败"
  121. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  122. return
  123. }
  124. //处理对应的文章类型标签按钮
  125. nameMap, styleMap, err := services.GetArticleTypeMap()
  126. if err != nil {
  127. br.Msg = "获取信息失败"
  128. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  129. return
  130. }
  131. page := paging.GetPaging(currentIndex, pageSize, total)
  132. resp := new(models.ArticleResearchListResp)
  133. for _, v := range list {
  134. item := models.ArticleResearchResp{
  135. ArticleId: v.ArticleId,
  136. ArticleTypeId: v.ArticleTypeId,
  137. Title: v.Title,
  138. PublishDate: v.PublishDate,
  139. DepartmentId: v.DepartmentId,
  140. NickName: v.NickName,
  141. IsCollect: v.IsCollect,
  142. Pv: v.Pv,
  143. CollectNum: v.CollectNum,
  144. Abstract: v.Abstract,
  145. Annotation: v.Annotation,
  146. ImgUrlPc: v.ImgUrlPc,
  147. ArticleTypeName: nameMap[v.ArticleTypeId],
  148. ButtonStyle: styleMap[v.ArticleTypeId],
  149. List: v.List,
  150. }
  151. resp.List = append(resp.List, &item)
  152. }
  153. resp.Paging = page
  154. br.Ret = 200
  155. br.Success = true
  156. br.Msg = "获取成功"
  157. br.Data = resp
  158. }
  159. // @Title KOL榜列表
  160. // @Description KOL榜列表接口
  161. // @Param PageSize query int true "每页数据条数"
  162. // @Param CurrentIndex query int true "当前页页码,从1开始"
  163. // @Param ThemeType query int true "主题类型,1关注度、2更新时间 "
  164. // @Success 200 {object} models.DepartmentListResp
  165. // @router /kolList [get]
  166. func (this *MobileResearchController) KolList() {
  167. br := new(models.BaseResponse).Init()
  168. defer func() {
  169. this.Data["json"] = br
  170. this.ServeJSON()
  171. }()
  172. user := this.User
  173. if user == nil {
  174. br.Msg = "请重新登录"
  175. br.Ret = 408
  176. return
  177. }
  178. themeType, _ := this.GetInt("ThemeType")
  179. pageSize, _ := this.GetInt("PageSize")
  180. currentIndex, _ := this.GetInt("CurrentIndex")
  181. var startSize int
  182. if pageSize <= 0 {
  183. pageSize = utils.PageSize15
  184. }
  185. if currentIndex <= 0 {
  186. currentIndex = 1
  187. }
  188. startSize = utils.StartIndex(currentIndex, pageSize)
  189. total, err := models.GetDepartmentlistCount("")
  190. if err != nil {
  191. br.Msg = "获取失败"
  192. br.ErrMsg = "获取失败,Err:" + err.Error()
  193. return
  194. }
  195. var condition string
  196. var conditionOrder string
  197. if themeType == 2 {
  198. conditionOrder = `ORDER BY publish_date DESC `
  199. } else {
  200. conditionOrder = `ORDER BY sum_num DESC `
  201. }
  202. list, err := models.GetDepartmentList(condition, conditionOrder, user.UserId, startSize, pageSize)
  203. if err != nil {
  204. br.Msg = "获取信息失败"
  205. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  206. return
  207. }
  208. listIndustrial, err := models.GetIndustrialDepartmentList()
  209. if err != nil {
  210. br.Msg = "获取信息失败"
  211. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  212. return
  213. }
  214. departmentMap := make(map[string]string)
  215. for k, v := range list {
  216. if v.FllowNum > 0 {
  217. list[k].IsFollow = true
  218. }
  219. list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  220. for _, v2 := range listIndustrial {
  221. if v2.DepartmentId == v.DepartmentId {
  222. if departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] == "" && len(list[k].List) < 4 {
  223. list[k].List = append(list[k].List, v2)
  224. departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] = v.NickName
  225. }
  226. }
  227. }
  228. }
  229. resp := new(models.DepartmentListResp)
  230. page := paging.GetPaging(currentIndex, pageSize, total)
  231. resp.Paging = page
  232. resp.List = list
  233. br.Ret = 200
  234. br.Success = true
  235. br.Msg = "获取成功"
  236. br.Data = resp
  237. }
  238. // @Title 主题热度/近期更新更多,列表
  239. // @Description 主题热度/近期更新更多,列表接口
  240. // @Param ThemeType query int true "主题类型,1主题热度、2近期更新 默认1"
  241. // @Param PageSize query int true "每页数据条数"
  242. // @Param CurrentIndex query int true "当前页页码,从1开始"
  243. // @Success 200 {object} models.IndustrialManagementHotListResp
  244. // @router /hotList [get]
  245. func (this *MobileResearchController) HotList() {
  246. br := new(models.BaseResponse).Init()
  247. defer func() {
  248. this.Data["json"] = br
  249. this.ServeJSON()
  250. }()
  251. user := this.User
  252. if user == nil {
  253. br.Msg = "请重新登录"
  254. br.Ret = 408
  255. return
  256. }
  257. themeType, _ := this.GetInt("ThemeType")
  258. pageSize, _ := this.GetInt("PageSize")
  259. currentIndex, _ := this.GetInt("CurrentIndex")
  260. var startSize int
  261. if pageSize <= 0 {
  262. pageSize = utils.PageSize15
  263. }
  264. if currentIndex <= 0 {
  265. currentIndex = 1
  266. }
  267. startSize = utils.StartIndex(currentIndex, pageSize)
  268. var condition string
  269. var conditionOrder string
  270. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  271. if err != nil {
  272. br.Msg = "获取信息失败"
  273. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  274. return
  275. }
  276. if articleTypeIds == "" {
  277. br.Msg = "获取信息失败"
  278. br.ErrMsg = "研选分类ID不能为空"
  279. return
  280. }
  281. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  282. if themeType == 2 {
  283. conditionOrder = `ORDER BY publish_date DESC `
  284. } else {
  285. conditionOrder = `ORDER BY sum_num DESC `
  286. }
  287. total, err := models.GetThemeHeatListCount(condition)
  288. if err != nil {
  289. br.Msg = "获取失败"
  290. br.ErrMsg = "获取失败,Err:" + err.Error()
  291. return
  292. }
  293. list, err := models.GetThemeHeatList(user.UserId, condition, conditionOrder, startSize, pageSize)
  294. if err != nil {
  295. br.Msg = "获取信息失败"
  296. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  297. return
  298. }
  299. listSubjcet, err := models.GetThemeHeatSubjectList(condition)
  300. if err != nil {
  301. br.Msg = "获取信息失败"
  302. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  303. return
  304. }
  305. mapHot := make(map[int]bool)
  306. mapNew, err := services.GetYanXuanIndustrialManagementIdNewMap(articleTypeIds)
  307. if err != nil {
  308. br.Msg = "获取信息失败"
  309. br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
  310. return
  311. }
  312. if themeType == 2 {
  313. mapHot, err = services.GetYanXuanIndustrialManagementIdHotMap(articleTypeIds)
  314. if err != nil {
  315. br.Msg = "获取信息失败"
  316. br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
  317. return
  318. }
  319. }
  320. for k, v := range list {
  321. list[k].IsNew = mapNew[v.IndustrialManagementId]
  322. list[k].IsHot = mapHot[v.IndustrialManagementId]
  323. if v.FllowNum > 0 {
  324. list[k].IsFollow = true
  325. }
  326. for _, v2 := range listSubjcet {
  327. if v2.IndustrialManagementId == v.IndustrialManagementId {
  328. list[k].IndustrialSubjectList = append(list[k].IndustrialSubjectList, v2)
  329. }
  330. }
  331. }
  332. page := paging.GetPaging(currentIndex, pageSize, total)
  333. resp := new(models.IndustrialManagementHotListResp)
  334. resp.Paging = page
  335. resp.List = list
  336. br.Ret = 200
  337. br.Success = true
  338. br.Msg = "获取成功"
  339. br.Data = resp
  340. }
  341. // @Title 主题详情
  342. // @Description 主题详情接口
  343. // @Param IndustrialManagementId query int true "分类ID"
  344. // @Success 200 {object} models.GetThemeDetailResp
  345. // @router /theme/detail [get]
  346. func (this *MobileResearchController) ThemeDetail() {
  347. br := new(models.BaseResponse).Init()
  348. defer func() {
  349. this.Data["json"] = br
  350. this.ServeJSON()
  351. }()
  352. user := this.User
  353. if user == nil {
  354. br.Msg = "请重新登录"
  355. br.Ret = 408
  356. return
  357. }
  358. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  359. if industrialManagementId < 1 {
  360. br.Msg = "请输入产业ID"
  361. return
  362. }
  363. detailIndustrial, err := models.GetIndustrialManagementDetail(industrialManagementId)
  364. if err != nil {
  365. br.Msg = "获取信息失败"
  366. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  367. return
  368. }
  369. var condition string
  370. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  371. if err != nil {
  372. br.Msg = "获取信息失败"
  373. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  374. return
  375. }
  376. if articleTypeIds != "" {
  377. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  378. } else {
  379. br.Msg = "获取信息失败"
  380. br.ErrMsg = "研选分类ID不能为空"
  381. return
  382. }
  383. resp := new(models.GetThemeDetailResp)
  384. list, err := models.GetThemeDetail(user.UserId, industrialManagementId, condition)
  385. if err != nil {
  386. br.Msg = "获取信息失败"
  387. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  388. return
  389. }
  390. list, err = services.HandleArticleCategoryImg(list, user)
  391. if err != nil {
  392. br.Msg = "获取信息失败"
  393. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  394. return
  395. }
  396. //处理对应的文章类型标签按钮
  397. nameMap, styleMap, err := services.GetArticleTypeMap()
  398. if err != nil {
  399. br.Msg = "获取信息失败"
  400. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  401. return
  402. }
  403. var articleIds []int
  404. for _, v := range list {
  405. item := models.ArticleResearchResp{
  406. ArticleId: v.ArticleId,
  407. ArticleTypeId: v.ArticleTypeId,
  408. Title: v.Title,
  409. PublishDate: v.PublishDate,
  410. DepartmentId: v.DepartmentId,
  411. NickName: v.NickName,
  412. IsCollect: v.IsCollect,
  413. Pv: v.Pv,
  414. CollectNum: v.CollectNum,
  415. Abstract: v.Abstract,
  416. Annotation: v.Annotation,
  417. ImgUrlPc: v.ImgUrlPc,
  418. ArticleTypeName: nameMap[v.ArticleTypeId],
  419. ButtonStyle: styleMap[v.ArticleTypeId],
  420. List: v.List,
  421. }
  422. resp.List = append(resp.List, &item)
  423. articleIds = append(articleIds, v.ArticleId)
  424. }
  425. //处理用户数是否关注该产业
  426. userFollowIndustrialMap, err := services.GetUserFollowIndustrialMap(user)
  427. if err != nil {
  428. br.Msg = "获取信息失败"
  429. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  430. return
  431. }
  432. if _, ok := userFollowIndustrialMap[industrialManagementId]; ok {
  433. resp.IsFollow = true
  434. }
  435. listSub, err := models.GetcygxIndustrialSubject(industrialManagementId)
  436. if err != nil {
  437. br.Msg = "获取信息失败"
  438. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  439. return
  440. }
  441. //处理文章关联的标的
  442. articleGroupSubjectMap, subjectMap, err := services.GetArticleGroupSubjectMap(articleIds)
  443. if err != nil {
  444. br.Msg = "获取信息失败"
  445. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  446. return
  447. }
  448. if len(articleGroupSubjectMap) > 0 {
  449. for k, v := range resp.List {
  450. resp.List[k].ListSubject = articleGroupSubjectMap[v.ArticleId]
  451. }
  452. }
  453. for _, v := range listSub {
  454. itemSubJect := new(models.IndustrialSubject)
  455. itemSubJect.SubjectName = v.SubjectName
  456. itemSubJect.IndustrialSubjectId = v.IndustrialSubjectId
  457. if subjectMap[v.IndustrialSubjectId] != "" {
  458. resp.ListSubject = append(resp.ListSubject, itemSubJect)
  459. }
  460. }
  461. resp.IndustryName = detailIndustrial.IndustryName
  462. resp.IndustrialManagementId = detailIndustrial.IndustrialManagementId
  463. br.Ret = 200
  464. br.Success = true
  465. br.Msg = "获取成功"
  466. br.Data = resp
  467. }
  468. // @Title 研选作者详情
  469. // @Description 研选作者详情接口
  470. // @Param DepartmentId query int true "作者ID"
  471. // @Success 200 {object} models.DepartmentDetailResp
  472. // @router /departmentId/detail [get]
  473. func (this *MobileResearchController) DepartmentIdDetail() {
  474. br := new(models.BaseResponse).Init()
  475. defer func() {
  476. this.Data["json"] = br
  477. this.ServeJSON()
  478. }()
  479. user := this.User
  480. if user == nil {
  481. br.Msg = "请重新登录"
  482. br.Ret = 408
  483. return
  484. }
  485. pageSize, _ := this.GetInt("PageSize")
  486. currentIndex, _ := this.GetInt("CurrentIndex")
  487. var startSize int
  488. if pageSize <= 0 {
  489. pageSize = utils.PageSize20
  490. }
  491. if currentIndex <= 0 {
  492. currentIndex = 1
  493. }
  494. startSize = paging.StartIndex(currentIndex, pageSize)
  495. departmentId, _ := this.GetInt("DepartmentId")
  496. if departmentId < 1 {
  497. br.Msg = "请输入作者ID"
  498. return
  499. }
  500. var condition string
  501. var pars []interface{}
  502. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  503. if err != nil {
  504. br.Msg = "获取信息失败"
  505. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  506. return
  507. }
  508. if articleTypeIds != "" {
  509. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  510. } else {
  511. br.Msg = "获取信息失败"
  512. br.ErrMsg = "研选分类ID不能为空"
  513. return
  514. }
  515. resp := new(models.DepartmentDetailResp)
  516. detail, err := models.GetDepartmentDetail(user.UserId, departmentId)
  517. if err != nil {
  518. br.Msg = "获取信息失败"
  519. br.ErrMsg = "获取作者信息失败,Err:" + err.Error()
  520. return
  521. }
  522. resp.DepartmentId = detail.DepartmentId
  523. resp.NickName = detail.NickName
  524. resp.ImgUrl = detail.ImgUrl
  525. resp.FllowNum = detail.FllowNum
  526. resp.ArticleNum = detail.ArticleNum
  527. resp.CollectNum = detail.CollectNum
  528. if detail.MyFllowNum > 0 {
  529. resp.IsFollow = true
  530. }
  531. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId)
  532. condition += ` AND a.article_type_id IN (` + articleTypeIds + `) `
  533. total, err := models.GetArticleResearchCount(condition, pars)
  534. if err != nil {
  535. br.Msg = "获取信息失败"
  536. br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
  537. return
  538. }
  539. list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId)
  540. if err != nil {
  541. br.Msg = "获取信息失败"
  542. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  543. return
  544. }
  545. list, err = services.HandleArticleCategoryImg(list, user)
  546. if err != nil {
  547. br.Msg = "获取信息失败"
  548. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  549. return
  550. }
  551. //处理对应的文章类型标签按钮
  552. nameMap, styleMap, err := services.GetArticleTypeMap()
  553. if err != nil {
  554. br.Msg = "获取信息失败"
  555. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  556. return
  557. }
  558. //resp := new(models.ArticleResearchListResp)
  559. for _, v := range list {
  560. item := models.ArticleResearchResp{
  561. ArticleId: v.ArticleId,
  562. ArticleTypeId: v.ArticleTypeId,
  563. Title: v.Title,
  564. PublishDate: v.PublishDate,
  565. DepartmentId: v.DepartmentId,
  566. NickName: v.NickName,
  567. IsCollect: v.IsCollect,
  568. Pv: v.Pv,
  569. CollectNum: v.CollectNum,
  570. Abstract: v.Abstract,
  571. Annotation: v.Annotation,
  572. ImgUrlPc: v.ImgUrlPc,
  573. ArticleTypeName: nameMap[v.ArticleTypeId],
  574. ButtonStyle: styleMap[v.ArticleTypeId],
  575. List: v.List,
  576. }
  577. resp.List = append(resp.List, &item)
  578. }
  579. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId)
  580. listIndustrial, err := models.GetIndustrialManagementNewList(condition)
  581. if err != nil {
  582. br.Msg = "获取信息失败"
  583. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  584. return
  585. }
  586. page := paging.GetPaging(currentIndex, pageSize, total)
  587. resp.ListIndustrial = listIndustrial
  588. resp.Paging = page
  589. br.Ret = 200
  590. br.Success = true
  591. br.Msg = "获取成功"
  592. br.Data = resp
  593. }
  594. // @Title 关注作者/取消关注作者
  595. // @Description 关注作者/取消关注作者 接口
  596. // @Param request body models.CygxArticleDepartmentId true "type json string"
  597. // @Success 200
  598. // @router /fllowDepartment [post]
  599. func (this *MobileResearchController) FllowDepartment() {
  600. br := new(models.BaseResponse).Init()
  601. defer func() {
  602. this.Data["json"] = br
  603. this.ServeJSON()
  604. }()
  605. user := this.User
  606. if user == nil {
  607. br.Msg = "请重新登录"
  608. br.Ret = 408
  609. return
  610. }
  611. uid := user.UserId
  612. var req models.CygxArticleDepartmentId
  613. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  614. if err != nil {
  615. br.Msg = "参数解析异常!"
  616. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  617. return
  618. }
  619. departmentId := req.DepartmentId
  620. var condition string
  621. countDepartment, err := models.GetDepartmentCount(departmentId)
  622. if err != nil {
  623. br.Msg = "获取数据失败!"
  624. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  625. return
  626. }
  627. if countDepartment == 0 {
  628. br.Msg = "作者不存在!"
  629. br.ErrMsg = "作者ID不存在:" + strconv.Itoa(departmentId)
  630. return
  631. }
  632. countUser, err := models.GetArticleDepartmentFollowByUid(uid)
  633. count, err := models.GetArticleDepartmentFollow(uid, departmentId, condition)
  634. if err != nil {
  635. br.Msg = "获取数据失败!"
  636. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  637. return
  638. }
  639. resp := new(models.CygxArticleDepartmentFollowResp)
  640. if countUser == 0 {
  641. resp.GoFollow = true
  642. }
  643. if count == 0 {
  644. item := new(models.CygxArticleDepartmentFollow)
  645. item.DepartmentId = departmentId
  646. item.UserId = uid
  647. item.Email = user.Email
  648. item.Mobile = user.Mobile
  649. item.RealName = user.RealName
  650. item.CompanyId = user.CompanyId
  651. item.CompanyName = user.CompanyName
  652. item.Type = 1
  653. item.CreateTime = time.Now()
  654. item.ModifyTime = time.Now()
  655. _, err = models.AddArticleDepartmentFollow(item)
  656. if err != nil {
  657. br.Msg = "操作失败"
  658. br.ErrMsg = "操作失败,Err:" + err.Error()
  659. return
  660. }
  661. resp.Status = 1
  662. } else {
  663. var doType int
  664. condition = ` AND type = 1`
  665. count, err = models.GetArticleDepartmentFollow(uid, departmentId, condition)
  666. if err != nil {
  667. br.Msg = "操作失败!"
  668. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  669. return
  670. }
  671. if count == 1 {
  672. resp.Status = 2
  673. doType = 2
  674. } else {
  675. resp.Status = 1
  676. doType = 1
  677. }
  678. err = models.RemoveArticleDepartmentFollow(uid, departmentId, doType)
  679. if err != nil {
  680. br.Msg = "操作失败"
  681. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  682. return
  683. }
  684. }
  685. br.Msg = "操作成功"
  686. br.Ret = 200
  687. br.Success = true
  688. br.Data = resp
  689. }
  690. // @Title 研选月度收藏榜
  691. // @Description 研选月度收藏榜接口
  692. // @Param PageSize query int true "每页数据条数"
  693. // @Success 200 {object} models.ReportBillboardListResp
  694. // @router /article/billboard [get]
  695. func (this *MobileResearchController) Billboard() {
  696. br := new(models.BaseResponse).Init()
  697. defer func() {
  698. this.Data["json"] = br
  699. this.ServeJSON()
  700. }()
  701. user := this.User
  702. if user == nil {
  703. br.Msg = "请重新登录"
  704. br.Ret = 408
  705. return
  706. }
  707. pageSize, _ := this.GetInt("PageSize", 15)
  708. var condition string
  709. var pars []interface{}
  710. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  711. if err != nil {
  712. br.Msg = "获取信息失败"
  713. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  714. return
  715. }
  716. if articleTypeIds != "" {
  717. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  718. } else {
  719. br.Msg = "获取信息失败"
  720. br.ErrMsg = "研选分类ID不能为空"
  721. return
  722. }
  723. condition += ` AND a.article_type_id IN (` + articleTypeIds + `) `
  724. // 根据关注时间一个月前至昨日的增量数据排序
  725. nowTime := time.Now().Local()
  726. startTime := nowTime.AddDate(0, -1, 0)
  727. endTime := nowTime.AddDate(0, 0, -1)
  728. condition += ` AND ac.create_time BETWEEN ? AND ?`
  729. pars = append(pars, startTime, endTime)
  730. list, err := models.GetReportCollectionBillboardListYx(pageSize, pars, condition)
  731. if err != nil {
  732. br.Msg = "获取失败"
  733. br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + err.Error()
  734. return
  735. }
  736. list, err = services.HandleArticleCategoryImg(list, user)
  737. if err != nil {
  738. br.Msg = "获取信息失败"
  739. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  740. return
  741. }
  742. //处理对应的文章类型标签按钮
  743. nameMap, styleMap, err := services.GetArticleTypeMap()
  744. if err != nil {
  745. br.Msg = "获取信息失败"
  746. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  747. return
  748. }
  749. resp := new(models.ArticleResearchListResp)
  750. for _, v := range list {
  751. item := models.ArticleResearchResp{
  752. ArticleId: v.ArticleId,
  753. ArticleTypeId: v.ArticleTypeId,
  754. Title: v.Title,
  755. PublishDate: v.PublishDate,
  756. DepartmentId: v.DepartmentId,
  757. NickName: v.NickName,
  758. IsCollect: v.IsCollect,
  759. Pv: v.Pv,
  760. CollectNum: v.CollectNum,
  761. Abstract: v.Abstract,
  762. Annotation: v.Annotation,
  763. ImgUrlPc: v.ImgUrlPc,
  764. ArticleTypeName: nameMap[v.ArticleTypeId],
  765. ButtonStyle: styleMap[v.ArticleTypeId],
  766. List: v.List,
  767. }
  768. resp.List = append(resp.List, &item)
  769. }
  770. br.Ret = 200
  771. br.Success = true
  772. br.Msg = "获取成功"
  773. br.Data = resp
  774. }