research.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915
  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. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  366. if themeType == 2 {
  367. conditionOrder = `ORDER BY publish_date DESC `
  368. } else {
  369. conditionOrder = `ORDER BY sum_num DESC `
  370. }
  371. total, err := models.GetThemeHeatListCount(condition)
  372. if err != nil {
  373. br.Msg = "获取失败"
  374. br.ErrMsg = "获取失败,Err:" + err.Error()
  375. return
  376. }
  377. list, err := models.GetThemeHeatList(user.UserId, condition, conditionOrder, startSize, pageSize)
  378. if err != nil {
  379. br.Msg = "获取信息失败"
  380. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  381. return
  382. }
  383. listSubjcet, err := models.GetThemeHeatSubjectList(condition)
  384. if err != nil {
  385. br.Msg = "获取信息失败"
  386. br.ErrMsg = "获取标的信息失败,Err:" + err.Error()
  387. return
  388. }
  389. mapHot := make(map[int]bool)
  390. mapNew, err := services.GetYanXuanIndustrialManagementIdNewMap(articleTypeIds)
  391. if err != nil {
  392. br.Msg = "获取信息失败"
  393. br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
  394. return
  395. }
  396. //if themeType == 2 {
  397. mapHot, err = services.GetYanXuanIndustrialManagementIdHotMap(articleTypeIds)
  398. if err != nil {
  399. br.Msg = "获取信息失败"
  400. br.ErrMsg = "GetYanXuanIndustrialManagementIdNewMap,Err:" + err.Error()
  401. return
  402. }
  403. //}
  404. for k, v := range list {
  405. list[k].IsNew = mapNew[v.IndustrialManagementId]
  406. list[k].IsHot = mapHot[v.IndustrialManagementId]
  407. list[k].PublishDate = utils.StrTimeToTime(v.PublishDate).Format(utils.FormatDate) //时间字符串格式转时间格式
  408. if v.FllowNum > 0 {
  409. list[k].IsFollow = true
  410. }
  411. for _, v2 := range listSubjcet {
  412. if v2.IndustrialManagementId == v.IndustrialManagementId {
  413. list[k].IndustrialSubjectList = append(list[k].IndustrialSubjectList, v2)
  414. }
  415. }
  416. }
  417. page := paging.GetPaging(currentIndex, pageSize, total)
  418. resp.Paging = page
  419. resp.List = list
  420. br.Ret = 200
  421. br.Success = true
  422. br.Msg = "获取成功"
  423. br.Data = resp
  424. }
  425. // @Title 主题详情
  426. // @Description 主题详情接口
  427. // @Param IndustrialManagementId query int true "分类ID"
  428. // @Success 200 {object} models.GetThemeDetailResp
  429. // @router /theme/detail [get]
  430. func (this *MobileResearchController) ThemeDetail() {
  431. br := new(models.BaseResponse).Init()
  432. defer func() {
  433. this.Data["json"] = br
  434. this.ServeJSON()
  435. }()
  436. user := this.User
  437. if user == nil {
  438. br.Msg = "请重新登录"
  439. br.Ret = 408
  440. return
  441. }
  442. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  443. if industrialManagementId < 1 {
  444. br.Msg = "请输入产业ID"
  445. return
  446. }
  447. detailIndustrial, err := models.GetIndustrialManagementDetail(industrialManagementId)
  448. if err != nil {
  449. br.Msg = "获取信息失败"
  450. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  451. return
  452. }
  453. var condition string
  454. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  455. if err != nil {
  456. br.Msg = "获取信息失败"
  457. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  458. return
  459. }
  460. if articleTypeIds != "" {
  461. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  462. } else {
  463. br.Msg = "获取信息失败"
  464. br.ErrMsg = "研选分类ID不能为空"
  465. return
  466. }
  467. resp := new(models.GetThemeDetailResp)
  468. list, err := models.GetThemeDetail(user.UserId, industrialManagementId, condition)
  469. if err != nil {
  470. br.Msg = "获取信息失败"
  471. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  472. return
  473. }
  474. list, err = services.HandleArticleCategoryImg(list, user)
  475. if err != nil {
  476. br.Msg = "获取信息失败"
  477. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  478. return
  479. }
  480. //处理对应的文章类型标签按钮
  481. nameMap, styleMap, err := services.GetArticleTypeMap()
  482. if err != nil {
  483. br.Msg = "获取信息失败"
  484. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  485. return
  486. }
  487. var articleIds []int
  488. for _, v := range list {
  489. item := models.ArticleResearchResp{
  490. ArticleId: v.ArticleId,
  491. ArticleTypeId: v.ArticleTypeId,
  492. Title: v.Title,
  493. PublishDate: v.PublishDate,
  494. DepartmentId: v.DepartmentId,
  495. NickName: v.NickName,
  496. IsCollect: v.IsCollect,
  497. Pv: v.Pv,
  498. CollectNum: v.CollectNum,
  499. Abstract: v.Abstract,
  500. Annotation: v.Annotation,
  501. ImgUrlPc: v.ImgUrlPc,
  502. ArticleTypeName: nameMap[v.ArticleTypeId],
  503. ButtonStyle: styleMap[v.ArticleTypeId],
  504. List: v.List,
  505. }
  506. if item.ArticleTypeName == "纪要" || item.ArticleTypeName == "沙龙" || item.ArticleTypeName == "专家访谈" {
  507. item.Annotation = "核心结论:" + item.Annotation
  508. } else {
  509. item.Annotation = "核心观点:" + item.Annotation
  510. }
  511. resp.List = append(resp.List, &item)
  512. articleIds = append(articleIds, v.ArticleId)
  513. }
  514. //处理用户数是否关注该产业
  515. userFollowIndustrialMap, err := services.GetUserFollowIndustrialMap(user)
  516. if err != nil {
  517. br.Msg = "获取信息失败"
  518. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  519. return
  520. }
  521. if _, ok := userFollowIndustrialMap[industrialManagementId]; ok {
  522. resp.IsFollow = true
  523. }
  524. listSub, err := models.GetcygxIndustrialSubject(industrialManagementId)
  525. if err != nil {
  526. br.Msg = "获取信息失败"
  527. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  528. return
  529. }
  530. //处理文章关联的标的
  531. articleGroupSubjectMap, subjectMap, err := services.GetArticleGroupSubjectMap(articleIds)
  532. if err != nil {
  533. br.Msg = "获取信息失败"
  534. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  535. return
  536. }
  537. if len(articleGroupSubjectMap) > 0 {
  538. for k, v := range resp.List {
  539. resp.List[k].ListSubject = articleGroupSubjectMap[v.ArticleId]
  540. }
  541. }
  542. for _, v := range listSub {
  543. itemSubJect := new(models.IndustrialSubject)
  544. itemSubJect.SubjectName = v.SubjectName
  545. itemSubJect.IndustrialSubjectId = v.IndustrialSubjectId
  546. if subjectMap[v.IndustrialSubjectId] != "" {
  547. resp.ListSubject = append(resp.ListSubject, itemSubJect)
  548. }
  549. }
  550. resp.IndustryName = detailIndustrial.IndustryName
  551. resp.IndustrialManagementId = detailIndustrial.IndustrialManagementId
  552. br.Ret = 200
  553. br.Success = true
  554. br.Msg = "获取成功"
  555. br.Data = resp
  556. }
  557. // @Title 研选作者详情
  558. // @Description 研选作者详情接口
  559. // @Param DepartmentId query int true "作者ID"
  560. // @Success 200 {object} models.DepartmentDetailResp
  561. // @router /departmentId/detail [get]
  562. func (this *MobileResearchController) DepartmentIdDetail() {
  563. br := new(models.BaseResponse).Init()
  564. defer func() {
  565. this.Data["json"] = br
  566. this.ServeJSON()
  567. }()
  568. user := this.User
  569. if user == nil {
  570. br.Msg = "请重新登录"
  571. br.Ret = 408
  572. return
  573. }
  574. pageSize, _ := this.GetInt("PageSize")
  575. currentIndex, _ := this.GetInt("CurrentIndex")
  576. var startSize int
  577. if pageSize <= 0 {
  578. pageSize = utils.PageSize20
  579. }
  580. if currentIndex <= 0 {
  581. currentIndex = 1
  582. }
  583. startSize = paging.StartIndex(currentIndex, pageSize)
  584. departmentId, _ := this.GetInt("DepartmentId")
  585. if departmentId < 1 {
  586. br.Msg = "请输入作者ID"
  587. return
  588. }
  589. var condition string
  590. var pars []interface{}
  591. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  592. if err != nil {
  593. br.Msg = "获取信息失败"
  594. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  595. return
  596. }
  597. needYanxuanSpecial := true
  598. if articleTypeIds != "" && !strings.Contains(articleTypeIds, "999") {
  599. needYanxuanSpecial = false
  600. }
  601. //只勾选了研选专栏时去掉文章的统计
  602. if articleTypeIds == "999" {
  603. condition += ` AND 1<0 `
  604. }
  605. if articleTypeIds != "" {
  606. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  607. } else {
  608. br.Msg = "获取信息失败"
  609. br.ErrMsg = "研选分类ID不能为空"
  610. return
  611. }
  612. resp := new(models.DepartmentDetailResp)
  613. detail, err := models.GetDepartmentDetail(user.UserId, departmentId, condition)
  614. if err != nil {
  615. br.Msg = "获取信息失败"
  616. br.ErrMsg = "获取作者信息失败,Err:" + err.Error()
  617. return
  618. }
  619. resp.DepartmentId = detail.DepartmentId
  620. resp.NickName = detail.NickName
  621. resp.ImgUrl = detail.ImgUrl
  622. resp.FllowNum = detail.FllowNum
  623. resp.ArticleNum = detail.ArticleNum
  624. resp.CollectNum = detail.CollectNum
  625. if detail.MyFllowNum > 0 {
  626. resp.IsFollow = true
  627. }
  628. condition += ` AND a.department_id = ` + strconv.Itoa(departmentId)
  629. total, err := models.GetArticleResearchCount(condition, pars, needYanxuanSpecial)
  630. if err != nil {
  631. br.Msg = "获取信息失败"
  632. br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
  633. return
  634. }
  635. list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId, needYanxuanSpecial)
  636. if err != nil {
  637. br.Msg = "获取信息失败"
  638. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  639. return
  640. }
  641. list, err = services.HandleArticleCategoryImg(list, user)
  642. if err != nil {
  643. br.Msg = "获取信息失败"
  644. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  645. return
  646. }
  647. //处理对应的文章类型标签按钮
  648. nameMap, styleMap, err := services.GetArticleTypeMap()
  649. if err != nil {
  650. br.Msg = "获取信息失败"
  651. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  652. return
  653. }
  654. //resp := new(models.ArticleResearchListResp)
  655. for _, v := range list {
  656. item := models.ArticleResearchResp{
  657. ArticleId: v.ArticleId,
  658. ArticleTypeId: v.ArticleTypeId,
  659. Title: v.Title,
  660. PublishDate: v.PublishDate,
  661. DepartmentId: v.DepartmentId,
  662. NickName: v.NickName,
  663. IsCollect: v.IsCollect,
  664. Pv: v.Pv,
  665. CollectNum: v.CollectNum,
  666. Abstract: v.Abstract,
  667. Annotation: v.Annotation,
  668. ImgUrlPc: v.ImgUrlPc,
  669. ArticleTypeName: nameMap[v.ArticleTypeId],
  670. ButtonStyle: styleMap[v.ArticleTypeId],
  671. List: v.List,
  672. }
  673. if item.ArticleTypeName == "纪要" || item.ArticleTypeName == "沙龙" || item.ArticleTypeName == "专家访谈" {
  674. item.Annotation = "核心结论:" + item.Annotation
  675. } else {
  676. item.Annotation = "核心观点:" + item.Annotation
  677. }
  678. resp.List = append(resp.List, &item)
  679. }
  680. condition = ` AND a.department_id = ` + strconv.Itoa(departmentId)
  681. listIndustrial, err := models.GetIndustrialManagementNewList(condition)
  682. if err != nil {
  683. br.Msg = "获取信息失败"
  684. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  685. return
  686. }
  687. page := paging.GetPaging(currentIndex, pageSize, total)
  688. resp.ListIndustrial = listIndustrial
  689. resp.Paging = page
  690. br.Ret = 200
  691. br.Success = true
  692. br.Msg = "获取成功"
  693. br.Data = resp
  694. }
  695. // @Title 关注作者/取消关注作者
  696. // @Description 关注作者/取消关注作者 接口
  697. // @Param request body models.CygxArticleDepartmentId true "type json string"
  698. // @Success 200
  699. // @router /fllowDepartment [post]
  700. func (this *MobileResearchController) FllowDepartment() {
  701. br := new(models.BaseResponse).Init()
  702. defer func() {
  703. this.Data["json"] = br
  704. this.ServeJSON()
  705. }()
  706. user := this.User
  707. if user == nil {
  708. br.Msg = "请重新登录"
  709. br.Ret = 408
  710. return
  711. }
  712. uid := user.UserId
  713. var req models.CygxArticleDepartmentId
  714. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  715. if err != nil {
  716. br.Msg = "参数解析异常!"
  717. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  718. return
  719. }
  720. departmentId := req.DepartmentId
  721. var condition string
  722. countDepartment, err := models.GetDepartmentCount(departmentId)
  723. if err != nil {
  724. br.Msg = "获取数据失败!"
  725. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  726. return
  727. }
  728. if countDepartment == 0 {
  729. br.Msg = "作者不存在!"
  730. br.ErrMsg = "作者ID不存在:" + strconv.Itoa(departmentId)
  731. return
  732. }
  733. countUser, err := models.GetArticleDepartmentFollowByUid(uid)
  734. count, err := models.GetArticleDepartmentFollow(uid, departmentId, condition)
  735. if err != nil {
  736. br.Msg = "获取数据失败!"
  737. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  738. return
  739. }
  740. resp := new(models.CygxArticleDepartmentFollowResp)
  741. if countUser == 0 {
  742. resp.GoFollow = true
  743. }
  744. if count == 0 {
  745. item := new(models.CygxArticleDepartmentFollow)
  746. item.DepartmentId = departmentId
  747. item.UserId = uid
  748. item.Email = user.Email
  749. item.Mobile = user.Mobile
  750. item.RealName = user.RealName
  751. item.CompanyId = user.CompanyId
  752. item.CompanyName = user.CompanyName
  753. item.Type = 1
  754. item.CreateTime = time.Now()
  755. item.ModifyTime = time.Now()
  756. _, err = models.AddArticleDepartmentFollow(item)
  757. if err != nil {
  758. br.Msg = "操作失败"
  759. br.ErrMsg = "操作失败,Err:" + err.Error()
  760. return
  761. }
  762. resp.Status = 1
  763. } else {
  764. var doType int
  765. condition = ` AND type = 1`
  766. count, err = models.GetArticleDepartmentFollow(uid, departmentId, condition)
  767. if err != nil {
  768. br.Msg = "操作失败!"
  769. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  770. return
  771. }
  772. if count == 1 {
  773. resp.Status = 2
  774. doType = 2
  775. } else {
  776. resp.Status = 1
  777. doType = 1
  778. }
  779. err = models.RemoveArticleDepartmentFollow(uid, departmentId, doType)
  780. if err != nil {
  781. br.Msg = "操作失败"
  782. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  783. return
  784. }
  785. }
  786. br.Msg = "操作成功"
  787. br.Ret = 200
  788. br.Success = true
  789. br.Data = resp
  790. }
  791. // @Title 研选月度收藏榜
  792. // @Description 研选月度收藏榜接口
  793. // @Param PageSize query int true "每页数据条数"
  794. // @Success 200 {object} models.ReportBillboardListResp
  795. // @router /article/billboard [get]
  796. func (this *MobileResearchController) Billboard() {
  797. br := new(models.BaseResponse).Init()
  798. defer func() {
  799. this.Data["json"] = br
  800. this.ServeJSON()
  801. }()
  802. user := this.User
  803. if user == nil {
  804. br.Msg = "请重新登录"
  805. br.Ret = 408
  806. return
  807. }
  808. pageSize, _ := this.GetInt("PageSize", 15)
  809. var condition string
  810. var pars []interface{}
  811. resp := new(models.ArticleResearchListResp)
  812. if user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID {
  813. resp.List = make([]*models.ArticleResearchResp, 0)
  814. resp.Paging = paging.GetPaging(1, pageSize, 0)
  815. br.Ret = 200
  816. br.Success = true
  817. br.Msg = "获取成功"
  818. br.Data = resp
  819. return
  820. }
  821. articleTypeIds, err := services.GetYanXuanArticleTypeIds()
  822. if err != nil {
  823. br.Msg = "获取信息失败"
  824. br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
  825. return
  826. }
  827. if articleTypeIds != "" {
  828. condition = ` AND a.article_type_id IN (` + articleTypeIds + `) `
  829. } else {
  830. br.Msg = "获取信息失败"
  831. br.ErrMsg = "研选分类ID不能为空"
  832. return
  833. }
  834. // 根据关注时间一个月前至昨日的增量数据排序
  835. nowTime := time.Now().Local()
  836. startTime := nowTime.AddDate(0, -1, 0)
  837. endTime := nowTime.AddDate(0, 0, -1)
  838. condition += ` AND ac.create_time BETWEEN ? AND ?`
  839. pars = append(pars, startTime, endTime)
  840. list, err := models.GetReportCollectionBillboardListYx(pageSize, pars, condition)
  841. if err != nil {
  842. br.Msg = "获取失败"
  843. br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + err.Error()
  844. return
  845. }
  846. list, err = services.HandleArticleCategoryImg(list, user)
  847. if err != nil {
  848. br.Msg = "获取信息失败"
  849. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  850. return
  851. }
  852. //处理对应的文章类型标签按钮
  853. nameMap, styleMap, err := services.GetArticleTypeMap()
  854. if err != nil {
  855. br.Msg = "获取信息失败"
  856. br.ErrMsg = "GetArticleTypeMap Err:" + err.Error()
  857. return
  858. }
  859. for _, v := range list {
  860. item := models.ArticleResearchResp{
  861. ArticleId: v.ArticleId,
  862. ArticleTypeId: v.ArticleTypeId,
  863. Title: v.Title,
  864. PublishDate: v.PublishDate,
  865. DepartmentId: v.DepartmentId,
  866. NickName: v.NickName,
  867. IsCollect: v.IsCollect,
  868. Pv: v.Pv,
  869. CollectNum: v.CollectNum,
  870. Abstract: v.Abstract,
  871. Annotation: v.Annotation,
  872. ImgUrlPc: v.ImgUrlPc,
  873. ArticleTypeName: nameMap[v.ArticleTypeId],
  874. ButtonStyle: styleMap[v.ArticleTypeId],
  875. List: v.List,
  876. }
  877. resp.List = append(resp.List, &item)
  878. }
  879. br.Ret = 200
  880. br.Success = true
  881. br.Msg = "获取成功"
  882. br.Data = resp
  883. }