research.go 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  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. resp := new(models.ArticleResearchListResp)
  90. if user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID {
  91. resp.List = make([]*models.ArticleResearchResp, 0)
  92. resp.Paging = paging.GetPaging(currentIndex, pageSize, 0)
  93. br.Ret = 200
  94. br.Success = true
  95. br.Msg = "获取成功"
  96. br.Data = resp
  97. return
  98. }
  99. condition = ` AND publish_status = 1 `
  100. if articleTypeIds == "" || strings.Contains(articleTypeIds, "999") {
  101. conditiontype = " AND is_show_yanx = 1 "
  102. } else {
  103. conditiontype = ` AND group_id IN (` + articleTypeIds + `) `
  104. }
  105. listType, err := models.GetCygxArticleTypeListCondition(conditiontype)
  106. if err != nil {
  107. br.Msg = "获取信息失败"
  108. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  109. return
  110. }
  111. needYanxuanSpecial := true
  112. if articleTypeIds != "" && !strings.Contains(articleTypeIds, "999") {
  113. needYanxuanSpecial = false
  114. }
  115. //只勾选了研选专栏时去掉文章的统计
  116. if articleTypeIds == "999" {
  117. condition += ` AND 1<0 `
  118. }
  119. articleTypeIds = ""
  120. for _, v := range listType {
  121. articleTypeIds += strconv.Itoa(v.ArticleTypeId) + ","
  122. }
  123. articleTypeIds = strings.TrimRight(articleTypeIds, ",")
  124. condition += ` AND a.article_type_id IN (` + articleTypeIds + `) `
  125. total, err := models.GetArticleResearchCount(condition, pars, needYanxuanSpecial)
  126. if err != nil {
  127. br.Msg = "获取信息失败"
  128. br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
  129. return
  130. }
  131. list, err := models.GetArticleResearchListYx(condition, pars, startSize, pageSize, user.UserId, needYanxuanSpecial)
  132. if err != nil {
  133. br.Msg = "获取信息失败"
  134. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  135. return
  136. }
  137. list, err = services.HandleArticleCategoryImg(list, user)
  138. if err != nil {
  139. br.Msg = "获取信息失败"
  140. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  141. return
  142. }
  143. //处理对应的文章类型标签按钮
  144. nameMap, styleMap, err := services.GetArticleTypeMap()
  145. if err != nil {
  146. br.Msg = "获取信息失败"
  147. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  148. return
  149. }
  150. page := paging.GetPaging(currentIndex, pageSize, total)
  151. for _, v := range list {
  152. item := models.ArticleResearchResp{
  153. ArticleId: v.ArticleId,
  154. ArticleTypeId: v.ArticleTypeId,
  155. Title: v.Title,
  156. PublishDate: v.PublishDate,
  157. DepartmentId: v.DepartmentId,
  158. NickName: v.NickName,
  159. IsCollect: v.IsCollect,
  160. Pv: v.Pv,
  161. CollectNum: v.CollectNum,
  162. Abstract: v.Abstract,
  163. Annotation: v.Annotation,
  164. ImgUrlPc: v.ImgUrlPc,
  165. ArticleTypeName: nameMap[v.ArticleTypeId],
  166. ButtonStyle: styleMap[v.ArticleTypeId],
  167. List: v.List,
  168. SpecialColumnId: v.SpecialColumnId,
  169. TopTime: v.TopTime,
  170. }
  171. if v.IsSpecial == 1 {
  172. //去除图片标签
  173. item.Annotation = utils.ArticleRemoveImgUrl(item.Annotation)
  174. item.Annotation, err = utils.ExtractText(item.Annotation)
  175. item.IsSpecial = true
  176. item.ImgUrlPc = utils.CYGX_YANXUAN_SPECIAL_IMG_PC
  177. if v.CompanyTags != "" {
  178. item.CompanyTags = strings.Split(v.CompanyTags, ",")
  179. } else {
  180. item.CompanyTags = []string{}
  181. }
  182. if v.IndustryTags != "" {
  183. item.IndustryTags = strings.Split(v.IndustryTags, ",")
  184. } else {
  185. item.IndustryTags = []string{}
  186. }
  187. item.ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
  188. if v.SpecialType == 1 {
  189. item.Title = "【笔记】" + item.Title
  190. } else if v.SpecialType == 2 {
  191. item.Title = "【观点】" + item.Title
  192. }
  193. if v.MyCollectNum > 0 {
  194. item.IsCollect = true
  195. }
  196. }
  197. if item.ArticleTypeName == "纪要" || item.ArticleTypeName == "沙龙" || item.ArticleTypeName == "专家访谈" {
  198. item.Annotation = "核心结论:" + item.Annotation
  199. } else if !item.IsSpecial {
  200. item.Annotation = "核心观点:" + item.Annotation
  201. }
  202. resp.List = append(resp.List, &item)
  203. }
  204. resp.Paging = page
  205. br.Ret = 200
  206. br.Success = true
  207. br.Msg = "获取成功"
  208. br.Data = resp
  209. }
  210. // @Title KOL榜列表
  211. // @Description KOL榜列表接口
  212. // @Param PageSize query int true "每页数据条数"
  213. // @Param CurrentIndex query int true "当前页页码,从1开始"
  214. // @Param ThemeType query int true "主题类型,1关注度、2更新时间 "
  215. // @Success 200 {object} models.DepartmentListResp
  216. // @router /kolList [get]
  217. func (this *MobileResearchController) KolList() {
  218. br := new(models.BaseResponse).Init()
  219. defer func() {
  220. this.Data["json"] = br
  221. this.ServeJSON()
  222. }()
  223. user := this.User
  224. if user == nil {
  225. br.Msg = "请重新登录"
  226. br.Ret = 408
  227. return
  228. }
  229. themeType, _ := this.GetInt("ThemeType")
  230. pageSize, _ := this.GetInt("PageSize")
  231. currentIndex, _ := this.GetInt("CurrentIndex")
  232. var startSize int
  233. if pageSize <= 0 {
  234. pageSize = utils.PageSize15
  235. }
  236. if currentIndex <= 0 {
  237. currentIndex = 1
  238. }
  239. startSize = utils.StartIndex(currentIndex, pageSize)
  240. resp := new(models.DepartmentListResp)
  241. if user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID {
  242. resp.List = make([]*models.DepartmentResp, 0)
  243. resp.Paging = paging.GetPaging(currentIndex, pageSize, 0)
  244. br.Ret = 200
  245. br.Success = true
  246. br.Msg = "获取成功"
  247. br.Data = resp
  248. return
  249. }
  250. total, err := models.GetDepartmentlistCount("")
  251. if err != nil {
  252. br.Msg = "获取失败"
  253. br.ErrMsg = "获取失败,Err:" + err.Error()
  254. return
  255. }
  256. var condition string
  257. var conditionOrder string
  258. if themeType == 2 {
  259. conditionOrder = `ORDER BY publish_date DESC `
  260. } else {
  261. conditionOrder = `ORDER BY sum_num DESC `
  262. }
  263. list, err := models.GetDepartmentList(condition, conditionOrder, user.UserId, startSize, pageSize)
  264. if err != nil {
  265. br.Msg = "获取信息失败"
  266. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  267. return
  268. }
  269. listIndustrial, err := models.GetIndustrialDepartmentList()
  270. if err != nil {
  271. br.Msg = "获取信息失败"
  272. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  273. return
  274. }
  275. mapHot := make(map[int]bool)
  276. //if themeType == 2 {
  277. conditionHot := `ORDER BY sum_num DESC `
  278. listhot, err := models.GetDepartmentList(condition, conditionHot, user.UserId, 0, 3)
  279. if err != nil {
  280. br.Msg = "获取信息失败"
  281. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  282. return
  283. }
  284. for _, v := range listhot {
  285. mapHot[v.DepartmentId] = true
  286. }
  287. //}
  288. departmentMap := make(map[string]string)
  289. for k, v := range list {
  290. if v.FllowNum > 0 {
  291. list[k].IsFollow = true
  292. }
  293. list[k].IsHot = mapHot[v.DepartmentId]
  294. list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  295. for _, v2 := range listIndustrial {
  296. if v2.DepartmentId == v.DepartmentId {
  297. if departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] == "" && len(list[k].List) < 4 {
  298. list[k].List = append(list[k].List, v2)
  299. departmentMap["D"+strconv.Itoa(v2.DepartmentId)+"In"+strconv.Itoa(v2.IndustrialManagementId)] = v.NickName
  300. }
  301. }
  302. }
  303. }
  304. page := paging.GetPaging(currentIndex, pageSize, total)
  305. resp.Paging = page
  306. resp.List = list
  307. br.Ret = 200
  308. br.Success = true
  309. br.Msg = "获取成功"
  310. br.Data = resp
  311. }
  312. // @Title 主题热度/近期更新更多,列表
  313. // @Description 主题热度/近期更新更多,列表接口
  314. // @Param ThemeType query int true "主题类型,1主题热度、2近期更新 默认1"
  315. // @Param PageSize query int true "每页数据条数"
  316. // @Param CurrentIndex query int true "当前页页码,从1开始"
  317. // @Success 200 {object} models.IndustrialManagementHotListResp
  318. // @router /hotList [get]
  319. func (this *MobileResearchController) HotList() {
  320. br := new(models.BaseResponse).Init()
  321. defer func() {
  322. this.Data["json"] = br
  323. this.ServeJSON()
  324. }()
  325. user := this.User
  326. if user == nil {
  327. br.Msg = "请重新登录"
  328. br.Ret = 408
  329. return
  330. }
  331. themeType, _ := this.GetInt("ThemeType")
  332. pageSize, _ := this.GetInt("PageSize")
  333. currentIndex, _ := this.GetInt("CurrentIndex")
  334. var startSize int
  335. if pageSize <= 0 {
  336. pageSize = utils.PageSize15
  337. }
  338. if currentIndex <= 0 {
  339. currentIndex = 1
  340. }
  341. startSize = utils.StartIndex(currentIndex, pageSize)
  342. var condition string
  343. var conditionOrder string
  344. resp := new(models.IndustrialManagementHotListResp)
  345. if user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID {
  346. resp.List = make([]*models.IndustrialManagementHotResp, 0)
  347. resp.Paging = paging.GetPaging(currentIndex, pageSize, 0)
  348. br.Ret = 200
  349. br.Success = true
  350. br.Msg = "获取成功"
  351. br.Data = resp
  352. return
  353. }
  354. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  355. if err != nil {
  356. br.Msg = "获取信息失败"
  357. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  358. return
  359. }
  360. if articleTypeIds == "" {
  361. br.Msg = "获取信息失败"
  362. br.ErrMsg = "研选分类ID不能为空"
  363. return
  364. }
  365. conditionOrder = ` ORDER BY follow_type_order DESC , `
  366. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  367. if themeType == 2 {
  368. conditionOrder += ` publish_date DESC `
  369. } else {
  370. conditionOrder += ` sum_num DESC `
  371. }
  372. total, err := models.GetThemeHeatListCount(condition)
  373. if err != nil {
  374. br.Msg = "获取失败"
  375. br.ErrMsg = "获取失败,Err:" + err.Error()
  376. return
  377. }
  378. list, err := models.GetThemeHeatList(user.UserId, condition, conditionOrder, startSize, pageSize)
  379. if err != nil {
  380. br.Msg = "获取信息失败"
  381. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  382. return
  383. }
  384. followTypeMap := services.GetCygxIndustryFllowListTypeMapByMobile(user.Mobile) // 关注的对应状态
  385. listSubjcet, err := models.GetThemeHeatSubjectList(condition)
  386. if err != nil {
  387. br.Msg = "获取信息失败"
  388. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  389. return
  390. }
  391. mapHot := make(map[int]bool)
  392. mapNew, err := services.GetYanXuanIndustrialManagementIdNewMap(articleTypeIds)
  393. if err != nil {
  394. br.Msg = "获取信息失败"
  395. br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
  396. return
  397. }
  398. //if themeType == 2 {
  399. mapHot, err = services.GetYanXuanIndustrialManagementIdHotMap(articleTypeIds)
  400. if err != nil {
  401. br.Msg = "获取信息失败"
  402. br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
  403. return
  404. }
  405. //}
  406. for k, v := range list {
  407. list[k].IsNew = mapNew[v.IndustrialManagementId]
  408. list[k].IsHot = mapHot[v.IndustrialManagementId]
  409. list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  410. if v.FllowNum > 0 {
  411. list[k].IsFollow = true
  412. }
  413. list[k].FollowType = followTypeMap[v.IndustrialManagementId]
  414. for _, v2 := range listSubjcet {
  415. if v2.IndustrialManagementId == v.IndustrialManagementId {
  416. list[k].IndustrialSubjectList = append(list[k].IndustrialSubjectList, v2)
  417. }
  418. }
  419. }
  420. page := paging.GetPaging(currentIndex, pageSize, total)
  421. resp.Paging = page
  422. resp.List = list
  423. br.Ret = 200
  424. br.Success = true
  425. br.Msg = "获取成功"
  426. br.Data = resp
  427. }
  428. // @Title 主题详情
  429. // @Description 主题详情接口
  430. // @Param IndustrialManagementId query int true "分类ID"
  431. // @Success 200 {object} models.GetThemeDetailResp
  432. // @router /theme/detail [get]
  433. func (this *MobileResearchController) ThemeDetail() {
  434. br := new(models.BaseResponse).Init()
  435. defer func() {
  436. this.Data["json"] = br
  437. this.ServeJSON()
  438. }()
  439. user := this.User
  440. if user == nil {
  441. br.Msg = "请重新登录"
  442. br.Ret = 408
  443. return
  444. }
  445. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  446. if industrialManagementId < 1 {
  447. br.Msg = "请输入产业ID"
  448. return
  449. }
  450. detailIndustrial, err := models.GetIndustrialManagementDetail(industrialManagementId)
  451. if err != nil {
  452. br.Msg = "获取信息失败"
  453. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  454. return
  455. }
  456. var condition string
  457. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  458. if err != nil {
  459. br.Msg = "获取信息失败"
  460. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  461. return
  462. }
  463. if articleTypeIds != "" {
  464. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  465. } else {
  466. br.Msg = "获取信息失败"
  467. br.ErrMsg = "研选分类ID不能为空"
  468. return
  469. }
  470. resp := new(models.GetThemeDetailResp)
  471. list, err := models.GetThemeDetail(user.UserId, industrialManagementId, condition)
  472. if err != nil {
  473. br.Msg = "获取信息失败"
  474. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  475. return
  476. }
  477. list, err = services.HandleArticleCategoryImg(list, user)
  478. if err != nil {
  479. br.Msg = "获取信息失败"
  480. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  481. return
  482. }
  483. //处理对应的文章类型标签按钮
  484. nameMap, styleMap, err := services.GetArticleTypeMap()
  485. if err != nil {
  486. br.Msg = "获取信息失败"
  487. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  488. return
  489. }
  490. var articleIds []int
  491. for _, v := range list {
  492. item := models.ArticleResearchResp{
  493. ArticleId: v.ArticleId,
  494. ArticleTypeId: v.ArticleTypeId,
  495. Title: v.Title,
  496. PublishDate: v.PublishDate,
  497. DepartmentId: v.DepartmentId,
  498. NickName: v.NickName,
  499. IsCollect: v.IsCollect,
  500. Pv: v.Pv,
  501. CollectNum: v.CollectNum,
  502. Abstract: v.Abstract,
  503. Annotation: v.Annotation,
  504. ImgUrlPc: v.ImgUrlPc,
  505. ArticleTypeName: nameMap[v.ArticleTypeId],
  506. ButtonStyle: styleMap[v.ArticleTypeId],
  507. List: v.List,
  508. }
  509. if item.ArticleTypeName == "纪要" || item.ArticleTypeName == "沙龙" || item.ArticleTypeName == "专家访谈" {
  510. item.Annotation = "核心结论:" + item.Annotation
  511. } else {
  512. item.Annotation = "核心观点:" + item.Annotation
  513. }
  514. resp.List = append(resp.List, &item)
  515. articleIds = append(articleIds, v.ArticleId)
  516. }
  517. //处理用户数是否关注该产业
  518. userFollowIndustrialMap, err := services.GetUserFollowIndustrialMap(user)
  519. if err != nil {
  520. br.Msg = "获取信息失败"
  521. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  522. return
  523. }
  524. if _, ok := userFollowIndustrialMap[industrialManagementId]; ok {
  525. resp.IsFollow = true
  526. }
  527. listSub, err := models.GetcygxIndustrialSubject(industrialManagementId)
  528. if err != nil {
  529. br.Msg = "获取信息失败"
  530. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  531. return
  532. }
  533. //处理文章关联的标的
  534. articleGroupSubjectMap, subjectMap, err := services.GetArticleGroupSubjectMap(articleIds)
  535. if err != nil {
  536. br.Msg = "获取信息失败"
  537. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  538. return
  539. }
  540. if len(articleGroupSubjectMap) > 0 {
  541. for k, v := range resp.List {
  542. resp.List[k].ListSubject = articleGroupSubjectMap[v.ArticleId]
  543. }
  544. }
  545. for _, v := range listSub {
  546. itemSubJect := new(models.IndustrialSubject)
  547. itemSubJect.SubjectName = v.SubjectName
  548. itemSubJect.IndustrialSubjectId = v.IndustrialSubjectId
  549. if subjectMap[v.IndustrialSubjectId] != "" {
  550. resp.ListSubject = append(resp.ListSubject, itemSubJect)
  551. }
  552. }
  553. followTypeMap := services.GetCygxIndustryFllowListTypeMapByMobile(user.Mobile) // 关注的对应状态
  554. resp.IndustryName = detailIndustrial.IndustryName
  555. resp.FollowType = followTypeMap[industrialManagementId]
  556. resp.IndustrialManagementId = detailIndustrial.IndustrialManagementId
  557. br.Ret = 200
  558. br.Success = true
  559. br.Msg = "获取成功"
  560. br.Data = resp
  561. }
  562. // @Title 研选作者详情
  563. // @Description 研选作者详情接口
  564. // @Param DepartmentId query int true "作者ID"
  565. // @Success 200 {object} models.DepartmentDetailResp
  566. // @router /departmentId/detail [get]
  567. func (this *MobileResearchController) DepartmentIdDetail() {
  568. br := new(models.BaseResponse).Init()
  569. defer func() {
  570. this.Data["json"] = br
  571. this.ServeJSON()
  572. }()
  573. user := this.User
  574. if user == nil {
  575. br.Msg = "请重新登录"
  576. br.Ret = 408
  577. return
  578. }
  579. pageSize, _ := this.GetInt("PageSize")
  580. currentIndex, _ := this.GetInt("CurrentIndex")
  581. var startSize int
  582. if pageSize <= 0 {
  583. pageSize = utils.PageSize20
  584. }
  585. if currentIndex <= 0 {
  586. currentIndex = 1
  587. }
  588. startSize = paging.StartIndex(currentIndex, pageSize)
  589. departmentId, _ := this.GetInt("DepartmentId")
  590. if departmentId < 1 {
  591. br.Msg = "请输入作者ID"
  592. return
  593. }
  594. var condition string
  595. var pars []interface{}
  596. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  597. if err != nil {
  598. br.Msg = "获取信息失败"
  599. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  600. return
  601. }
  602. needYanxuanSpecial := true
  603. if articleTypeIds != "" && !strings.Contains(articleTypeIds, "999") {
  604. needYanxuanSpecial = false
  605. }
  606. //只勾选了研选专栏时去掉文章的统计
  607. if articleTypeIds == "999" {
  608. condition += ` AND 1<0 `
  609. }
  610. if articleTypeIds != "" {
  611. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  612. } else {
  613. br.Msg = "获取信息失败"
  614. br.ErrMsg = "研选分类ID不能为空"
  615. return
  616. }
  617. resp := new(models.DepartmentDetailResp)
  618. detail, err := models.GetDepartmentDetail(user.UserId, departmentId, condition)
  619. if err != nil {
  620. br.Msg = "获取信息失败"
  621. br.ErrMsg = "获取作者信息失败,Err:" + err.Error()
  622. return
  623. }
  624. resp.DepartmentId = detail.DepartmentId
  625. resp.NickName = detail.NickName
  626. resp.ImgUrl = detail.ImgUrl
  627. resp.FllowNum = detail.FllowNum
  628. resp.ArticleNum = detail.ArticleNum
  629. resp.CollectNum = detail.CollectNum
  630. if detail.MyFllowNum > 0 {
  631. resp.IsFollow = true
  632. }
  633. condition += ` AND a.department_id = ` + strconv.Itoa(departmentId)
  634. total, err := models.GetArticleResearchCount(condition, pars, needYanxuanSpecial)
  635. if err != nil {
  636. br.Msg = "获取信息失败"
  637. br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
  638. return
  639. }
  640. list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId, needYanxuanSpecial)
  641. if err != nil {
  642. br.Msg = "获取信息失败"
  643. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  644. return
  645. }
  646. list, err = services.HandleArticleCategoryImg(list, user)
  647. if err != nil {
  648. br.Msg = "获取信息失败"
  649. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  650. return
  651. }
  652. //处理对应的文章类型标签按钮
  653. nameMap, styleMap, err := services.GetArticleTypeMap()
  654. if err != nil {
  655. br.Msg = "获取信息失败"
  656. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  657. return
  658. }
  659. //resp := new(models.ArticleResearchListResp)
  660. for _, v := range list {
  661. item := models.ArticleResearchResp{
  662. ArticleId: v.ArticleId,
  663. ArticleTypeId: v.ArticleTypeId,
  664. Title: v.Title,
  665. PublishDate: v.PublishDate,
  666. DepartmentId: v.DepartmentId,
  667. NickName: v.NickName,
  668. IsCollect: v.IsCollect,
  669. Pv: v.Pv,
  670. CollectNum: v.CollectNum,
  671. Abstract: v.Abstract,
  672. Annotation: v.Annotation,
  673. ImgUrlPc: v.ImgUrlPc,
  674. ArticleTypeName: nameMap[v.ArticleTypeId],
  675. ButtonStyle: styleMap[v.ArticleTypeId],
  676. List: v.List,
  677. }
  678. if item.ArticleTypeName == "纪要" || item.ArticleTypeName == "沙龙" || item.ArticleTypeName == "专家访谈" {
  679. item.Annotation = "核心结论:" + item.Annotation
  680. } else {
  681. item.Annotation = "核心观点:" + item.Annotation
  682. }
  683. resp.List = append(resp.List, &item)
  684. }
  685. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId)
  686. listIndustrial, err := models.GetIndustrialManagementNewList(condition)
  687. if err != nil {
  688. br.Msg = "获取信息失败"
  689. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  690. return
  691. }
  692. page := paging.GetPaging(currentIndex, pageSize, total)
  693. resp.ListIndustrial = listIndustrial
  694. resp.Paging = page
  695. br.Ret = 200
  696. br.Success = true
  697. br.Msg = "获取成功"
  698. br.Data = resp
  699. }
  700. // @Title 关注作者/取消关注作者
  701. // @Description 关注作者/取消关注作者 接口
  702. // @Param request body models.CygxArticleDepartmentId true "type json string"
  703. // @Success 200
  704. // @router /fllowDepartment [post]
  705. func (this *MobileResearchController) FllowDepartment() {
  706. br := new(models.BaseResponse).Init()
  707. defer func() {
  708. this.Data["json"] = br
  709. this.ServeJSON()
  710. }()
  711. user := this.User
  712. if user == nil {
  713. br.Msg = "请重新登录"
  714. br.Ret = 408
  715. return
  716. }
  717. uid := user.UserId
  718. var req models.CygxArticleDepartmentId
  719. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  720. if err != nil {
  721. br.Msg = "参数解析异常!"
  722. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  723. return
  724. }
  725. departmentId := req.DepartmentId
  726. var condition string
  727. countDepartment, err := models.GetDepartmentCount(departmentId)
  728. if err != nil {
  729. br.Msg = "获取数据失败!"
  730. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  731. return
  732. }
  733. if countDepartment == 0 {
  734. br.Msg = "作者不存在!"
  735. br.ErrMsg = "作者ID不存在:" + strconv.Itoa(departmentId)
  736. return
  737. }
  738. countUser, err := models.GetArticleDepartmentFollowByUid(uid)
  739. count, err := models.GetArticleDepartmentFollow(uid, departmentId, condition)
  740. if err != nil {
  741. br.Msg = "获取数据失败!"
  742. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  743. return
  744. }
  745. resp := new(models.CygxArticleDepartmentFollowResp)
  746. if countUser == 0 {
  747. resp.GoFollow = true
  748. }
  749. if count == 0 {
  750. item := new(models.CygxArticleDepartmentFollow)
  751. item.DepartmentId = departmentId
  752. item.UserId = uid
  753. item.Email = user.Email
  754. item.Mobile = user.Mobile
  755. item.RealName = user.RealName
  756. item.CompanyId = user.CompanyId
  757. item.CompanyName = user.CompanyName
  758. item.Type = 1
  759. item.CreateTime = time.Now()
  760. item.ModifyTime = time.Now()
  761. _, err = models.AddArticleDepartmentFollow(item)
  762. if err != nil {
  763. br.Msg = "操作失败"
  764. br.ErrMsg = "操作失败,Err:" + err.Error()
  765. return
  766. }
  767. resp.Status = 1
  768. } else {
  769. var doType int
  770. condition = ` AND type = 1`
  771. count, err = models.GetArticleDepartmentFollow(uid, departmentId, condition)
  772. if err != nil {
  773. br.Msg = "操作失败!"
  774. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  775. return
  776. }
  777. if count == 1 {
  778. resp.Status = 2
  779. doType = 2
  780. } else {
  781. resp.Status = 1
  782. doType = 1
  783. }
  784. err = models.RemoveArticleDepartmentFollow(uid, departmentId, doType)
  785. if err != nil {
  786. br.Msg = "操作失败"
  787. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  788. return
  789. }
  790. }
  791. br.Msg = "操作成功"
  792. br.Ret = 200
  793. br.Success = true
  794. br.Data = resp
  795. }
  796. // @Title 研选月度收藏榜
  797. // @Description 研选月度收藏榜接口
  798. // @Param PageSize query int true "每页数据条数"
  799. // @Success 200 {object} models.ReportBillboardListResp
  800. // @router /article/billboard [get]
  801. func (this *MobileResearchController) Billboard() {
  802. br := new(models.BaseResponse).Init()
  803. defer func() {
  804. this.Data["json"] = br
  805. this.ServeJSON()
  806. }()
  807. user := this.User
  808. if user == nil {
  809. br.Msg = "请重新登录"
  810. br.Ret = 408
  811. return
  812. }
  813. pageSize, _ := this.GetInt("PageSize", 15)
  814. var condition string
  815. var pars []interface{}
  816. resp := new(models.ArticleResearchListResp)
  817. if user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID {
  818. resp.List = make([]*models.ArticleResearchResp, 0)
  819. resp.Paging = paging.GetPaging(1, pageSize, 0)
  820. br.Ret = 200
  821. br.Success = true
  822. br.Msg = "获取成功"
  823. br.Data = resp
  824. return
  825. }
  826. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  827. if err != nil {
  828. br.Msg = "获取信息失败"
  829. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  830. return
  831. }
  832. if articleTypeIds != "" {
  833. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  834. } else {
  835. br.Msg = "获取信息失败"
  836. br.ErrMsg = "研选分类ID不能为空"
  837. return
  838. }
  839. // 根据关注时间一个月前至昨日的增量数据排序
  840. nowTime := time.Now().Local()
  841. startTime := nowTime.AddDate(0, -1, 0)
  842. endTime := nowTime.AddDate(0, 0, -1)
  843. condition += ` AND ac.create_time BETWEEN ? AND ?`
  844. pars = append(pars, startTime, endTime)
  845. list, err := models.GetReportCollectionBillboardListYx(pageSize, pars, condition)
  846. if err != nil {
  847. br.Msg = "获取失败"
  848. br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + err.Error()
  849. return
  850. }
  851. list, err = services.HandleArticleCategoryImg(list, user)
  852. if err != nil {
  853. br.Msg = "获取信息失败"
  854. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  855. return
  856. }
  857. //处理对应的文章类型标签按钮
  858. nameMap, styleMap, err := services.GetArticleTypeMap()
  859. if err != nil {
  860. br.Msg = "获取信息失败"
  861. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  862. return
  863. }
  864. for _, v := range list {
  865. item := models.ArticleResearchResp{
  866. ArticleId: v.ArticleId,
  867. ArticleTypeId: v.ArticleTypeId,
  868. Title: v.Title,
  869. PublishDate: v.PublishDate,
  870. DepartmentId: v.DepartmentId,
  871. NickName: v.NickName,
  872. IsCollect: v.IsCollect,
  873. Pv: v.Pv,
  874. CollectNum: v.CollectNum,
  875. Abstract: v.Abstract,
  876. Annotation: v.Annotation,
  877. ImgUrlPc: v.ImgUrlPc,
  878. ArticleTypeName: nameMap[v.ArticleTypeId],
  879. ButtonStyle: styleMap[v.ArticleTypeId],
  880. List: v.List,
  881. }
  882. resp.List = append(resp.List, &item)
  883. }
  884. br.Ret = 200
  885. br.Success = true
  886. br.Msg = "获取成功"
  887. br.Data = resp
  888. }