report.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "rdluck_tools/paging"
  9. "strconv"
  10. "time"
  11. )
  12. //报告
  13. type ReportController struct {
  14. BaseAuthController
  15. }
  16. type ReportCommonController struct {
  17. BaseCommonController
  18. }
  19. // @Title 行业报告分类列表接口
  20. // @Description 获取行业报告分类列表接口
  21. // @Param ChartPermissionId query int true "分类ID"
  22. // @Success 200 {object} models.IndustrialManagementList
  23. // @router /home/tradeList [get]
  24. func (this *ReportController) TradeList() {
  25. br := new(models.BaseResponse).Init()
  26. defer func() {
  27. this.Data["json"] = br
  28. this.ServeJSON()
  29. }()
  30. user := this.User
  31. if user == nil {
  32. br.Msg = "请重新登录"
  33. br.Ret = 408
  34. return
  35. }
  36. uid := user.UserId
  37. ChartPermissionId, _ := this.GetInt("ChartPermissionId")
  38. if ChartPermissionId < 1 {
  39. br.Msg = "请输入分类ID"
  40. return
  41. }
  42. fmt.Println(uid)
  43. list, err := models.GetTradeAll(ChartPermissionId)
  44. if err != nil {
  45. br.Msg = "获取信息失败"
  46. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  47. return
  48. }
  49. for k, v := range list {
  50. list[k].UpdateTime = utils.TimeRemoveHms(v.UpdateTime)
  51. count, err := models.CheckThisCategoryNewArticleIsRead(uid, v.CategoryId)
  52. if err != nil {
  53. br.Msg = "获取信息失败"
  54. br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
  55. return
  56. }
  57. if count == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.UpdateTime)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.UpdateTime)) {
  58. list[k].IsRed = true
  59. }
  60. }
  61. resp := new(models.TradeReportMappingResp)
  62. resp.List = list
  63. br.Ret = 200
  64. br.Success = true
  65. br.Msg = "获取成功"
  66. br.Data = resp
  67. }
  68. // @Title 产业报告分类列表接口
  69. // @Description 获取产业报告分类列表接口
  70. // @Param ChartPermissionId query int true "分类ID"
  71. // @Param OrderColumn query int true "排序字段 ,NewTime 最近更新 ,Recommend弘则推荐"
  72. // @Param PageSize query int true "每页数据条数"
  73. // @Param CurrentIndex query int true "当前页页码,从1开始"
  74. // @Success 200 {object} models.IndustrialManagementList
  75. // @router /home/industryList [get]
  76. func (this *ReportController) IndustryList() {
  77. br := new(models.BaseResponse).Init()
  78. defer func() {
  79. this.Data["json"] = br
  80. this.ServeJSON()
  81. }()
  82. user := this.User
  83. if user == nil {
  84. br.Msg = "请重新登录"
  85. br.Ret = 408
  86. return
  87. }
  88. uid := user.UserId
  89. var orderSrt string
  90. ChartPermissionId, _ := this.GetInt("ChartPermissionId")
  91. orderColumn := this.GetString("OrderColumn")
  92. pageSize, _ := this.GetInt("PageSize")
  93. currentIndex, _ := this.GetInt("CurrentIndex")
  94. var startSize int
  95. if pageSize <= 0 {
  96. pageSize = utils.PageSize20
  97. }
  98. if currentIndex <= 0 {
  99. currentIndex = 1
  100. }
  101. startSize = paging.StartIndex(currentIndex, pageSize)
  102. resp := new(models.IndustrialManagementList)
  103. var total int
  104. var list []*models.IndustrialManagement
  105. totalTopList, errTop := models.GetIndustrialManagemenCountTop(ChartPermissionId, uid)
  106. totalTop := len(totalTopList)
  107. if errTop != nil {
  108. br.Msg = "获取信息失败"
  109. br.ErrMsg = "获取品种信息失败,Err:" + errTop.Error()
  110. return
  111. }
  112. totalNoTopList, errNoTop := models.GetIndustrialManagemenCountNoTop(ChartPermissionId, uid)
  113. totalNoTop := len(totalNoTopList)
  114. if errNoTop != nil {
  115. br.Msg = "获取信息失败"
  116. br.ErrMsg = "获取品种信息失败,Err:" + errNoTop.Error()
  117. return
  118. }
  119. total = totalTop + totalNoTop
  120. page := paging.GetPaging(currentIndex, pageSize, total)
  121. if orderColumn == "" {
  122. orderColumn = "NewTime"
  123. }
  124. if ChartPermissionId < 1 {
  125. br.Msg = "请输入分类ID"
  126. return
  127. }
  128. if orderColumn == "NewTime" {
  129. orderSrt = "update_time DESC"
  130. } else {
  131. orderSrt = "man.recommended_index DESC,update_time DESC"
  132. }
  133. fmt.Println(orderSrt)
  134. //全部都是置顶
  135. if totalTop >= currentIndex*pageSize {
  136. listTop, err := models.GetIndustrialManagementTopAll(ChartPermissionId, uid, startSize, pageSize)
  137. for k, _ := range listTop {
  138. listTop[k].IsTop = true
  139. }
  140. if err != nil {
  141. br.Msg = "获取信息失败"
  142. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  143. return
  144. }
  145. list = listTop
  146. } else if totalTop < (currentIndex-1)*pageSize { //全部都是不置顶
  147. listNoTop, err := models.GetIndustrialManagementAll(ChartPermissionId, uid, orderSrt, startSize-totalTop, pageSize)
  148. if err != nil {
  149. br.Msg = "获取信息失败"
  150. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  151. return
  152. }
  153. list = listNoTop
  154. } else { //部分置顶,部分不置顶
  155. listTop, err := models.GetIndustrialManagementTopAll(ChartPermissionId, uid, startSize, pageSize)
  156. if err != nil {
  157. br.Msg = "获取信息失败"
  158. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  159. return
  160. }
  161. for k, _ := range listTop {
  162. listTop[k].IsTop = true
  163. }
  164. listNoTop, err := models.GetIndustrialManagementAll(ChartPermissionId, uid, orderSrt, 0, pageSize-len(listTop))
  165. if err != nil {
  166. br.Msg = "获取信息失败"
  167. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  168. return
  169. }
  170. list = append(listTop, listNoTop...)
  171. }
  172. for k, v := range list {
  173. //var analystStr string
  174. //analystList, err := models.GetIndustrialAnalystAll(v.IndustrialManagementId)
  175. //if err != nil {
  176. // br.Msg = "获取信息失败"
  177. // br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  178. // return
  179. //}
  180. industrialSubjectList, err := models.GetIndustrialSubjectAll(v.IndustrialManagementId)
  181. if err != nil {
  182. br.Msg = "获取信息失败"
  183. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  184. return
  185. }
  186. list[k].IndustrialSubjectList = industrialSubjectList
  187. //if len(analystList) > 0 {
  188. // for _, v2 := range analystList {
  189. // analystStr += v2.AnalystName + "/"
  190. // }
  191. // analystStr = strings.TrimRight(analystStr, "/")
  192. //}
  193. //list[k].Analyst = analystStr
  194. list[k].LayoutTime = utils.TimeRemoveHms(v.LayoutTime)
  195. newArtinfo, err := models.GetIndustrialNewArticleDetail(v.IndustrialManagementId)
  196. if err != nil {
  197. br.Msg = "获取信息失败"
  198. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  199. return
  200. }
  201. list[k].UpdateTime = utils.TimeRemoveHms(newArtinfo.PublishDate)
  202. recordCount, err := models.GetUserToArticleCount(uid, newArtinfo.ArticleId)
  203. if err != nil && err.Error() != utils.ErrNoRow() {
  204. br.Msg = "获取信息失败"
  205. br.ErrMsg = "获取信息失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(newArtinfo.ArticleId)
  206. return
  207. }
  208. //
  209. if recordCount == 0 && user.CreatedTime.Before(utils.StrTimeToTime(newArtinfo.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(newArtinfo.PublishDate)) {
  210. list[k].IsRed = true
  211. }
  212. }
  213. resp.List = list
  214. resp.Paging = page
  215. br.Ret = 200
  216. br.Success = true
  217. br.Msg = "获取成功"
  218. br.Data = resp
  219. }
  220. // @Title 产业下所关联的文章分类列表
  221. // @Description 产业下所关联的文章分类列表接口
  222. // @Param IndustrialManagementId query int true "产业ID"
  223. // @Success 200 {object} models.IndustrialToArticleCategoryListRep
  224. // @router /toArticleCategoryList [get]
  225. func (this *ReportController) ArticleCategoryList() {
  226. br := new(models.BaseResponse).Init()
  227. defer func() {
  228. this.Data["json"] = br
  229. this.ServeJSON()
  230. }()
  231. user := this.User
  232. if user == nil {
  233. br.Msg = "请重新登录"
  234. br.Ret = 408
  235. return
  236. }
  237. uid := user.UserId
  238. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  239. if industrialManagementId < 1 {
  240. br.Msg = "请输入分类ID"
  241. return
  242. }
  243. list, err := models.IndustrialToArticleCategory(industrialManagementId)
  244. if err != nil {
  245. br.Msg = "获取信息失败"
  246. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  247. return
  248. }
  249. for k, v := range list {
  250. recordCount, err := models.IndustrialUserRecordArticleCount(uid, industrialManagementId, v.CategoryId)
  251. if err != nil && err.Error() != utils.ErrNoRow() {
  252. br.Msg = "获取信息失败"
  253. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  254. return
  255. }
  256. Newdetail, err := models.GetNewIndustrialUserRecordArticle(industrialManagementId, v.CategoryId)
  257. if err != nil {
  258. br.Msg = "获取信息失败"
  259. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  260. return
  261. }
  262. if recordCount == 0 && user.CreatedTime.Before(utils.StrTimeToTime(Newdetail.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(Newdetail.PublishDate)) {
  263. list[k].IsRed = true
  264. }
  265. }
  266. detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
  267. if err != nil {
  268. br.Msg = "获取信息失败"
  269. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  270. return
  271. }
  272. resp := new(models.IndustrialToArticleCategoryListRep)
  273. resp.List = list
  274. resp.LayoutTime = utils.TimeRemoveHms(detail.LayoutTime)
  275. resp.IndustryName = detail.IndustryName
  276. resp.IndustrialManagementId = industrialManagementId
  277. br.Ret = 200
  278. br.Success = true
  279. br.Msg = "获取成功"
  280. br.Data = resp
  281. }
  282. // @Title 产业文章列表接口
  283. // @Description 获取产业文章列表接口
  284. // @Param PageSize query int true "每页数据条数"
  285. // @Param CurrentIndex query int true "当前页页码,从1开始"
  286. // @Param CategoryId query int true "分类ID"
  287. // @Param IndustrialManagementId query int true "产业ID"
  288. // @Success 200 {object} models.TacticsListResp
  289. // @router /industry/ArticleList [get]
  290. func (this *ReportController) List() {
  291. br := new(models.BaseResponse).Init()
  292. defer func() {
  293. this.Data["json"] = br
  294. this.ServeJSON()
  295. }()
  296. user := this.User
  297. if user == nil {
  298. br.Msg = "请重新登录"
  299. br.Ret = 408
  300. return
  301. }
  302. uid := user.UserId
  303. pageSize, _ := this.GetInt("PageSize")
  304. currentIndex, _ := this.GetInt("CurrentIndex")
  305. categoryId, _ := this.GetInt("CategoryId")
  306. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  307. var startSize int
  308. if pageSize <= 0 {
  309. pageSize = utils.PageSize20
  310. }
  311. if currentIndex <= 0 {
  312. currentIndex = 1
  313. }
  314. startSize = paging.StartIndex(currentIndex, pageSize)
  315. var pars []interface{}
  316. var total int
  317. resp := new(models.TacticsListResp)
  318. page := paging.GetPaging(currentIndex, pageSize, total)
  319. if categoryId < 1 {
  320. br.Msg = "请输入分类ID"
  321. return
  322. }
  323. if industrialManagementId < 1 {
  324. br.Msg = "请输入产业ID"
  325. return
  326. }
  327. total, err := models.GetReportIndustrialCount(categoryId, industrialManagementId)
  328. if err != nil {
  329. br.Msg = "获取信息失败"
  330. br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
  331. return
  332. }
  333. page = paging.GetPaging(currentIndex, pageSize, total)
  334. list, err := models.GetReportIndustrialList(pars, categoryId, industrialManagementId, uid, startSize, pageSize)
  335. if err != nil {
  336. br.Msg = "获取信息失败"
  337. br.ErrMsg = "获取帖子数据失败,Err:" + err.Error()
  338. return
  339. }
  340. lenList := len(list)
  341. for i := 0; i < lenList; i++ {
  342. item := list[i]
  343. list[i].Body, _ = services.GetReportContentTextSub(item.Body)
  344. //list[i].Abstract = html.UnescapeString(item.Abstract)
  345. list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  346. }
  347. for k, v := range list {
  348. if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
  349. list[k].IsRed = true
  350. }
  351. }
  352. resp.List = list
  353. resp.Paging = page
  354. br.Ret = 200
  355. br.Success = true
  356. br.Msg = "获取成功"
  357. br.Data = resp
  358. }
  359. // @Title 置顶/取消置顶
  360. // @Description 置顶
  361. // @Param request body models.CygxIndustryTopRep true "type json string"
  362. // @Success 200
  363. // @router /top [post]
  364. func (this *ReportController) ArticleCollect() {
  365. br := new(models.BaseResponse).Init()
  366. defer func() {
  367. this.Data["json"] = br
  368. this.ServeJSON()
  369. }()
  370. user := this.User
  371. if user == nil {
  372. br.Msg = "请重新登录"
  373. br.Ret = 408
  374. return
  375. }
  376. uid := user.UserId
  377. var req models.CygxIndustryTopRep
  378. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  379. if err != nil {
  380. br.Msg = "参数解析异常!"
  381. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  382. return
  383. }
  384. industrialManagementId := req.IndustrialManagementId
  385. fmt.Println(industrialManagementId)
  386. countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
  387. if err != nil {
  388. br.Msg = "获取数据失败!"
  389. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  390. return
  391. }
  392. if countIndustrial == 0 {
  393. br.Msg = "产业不存在!"
  394. br.ErrMsg = "产业ID不存在:" + strconv.Itoa(industrialManagementId)
  395. return
  396. }
  397. count, err := models.GetCygxIndustryTop(uid, industrialManagementId)
  398. if err != nil {
  399. br.Msg = "获取数据失败!"
  400. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  401. return
  402. }
  403. resp := new(models.ArticleCollectResp)
  404. if count <= 0 {
  405. item := new(models.CygxIndustryTop)
  406. item.IndustrialManagementId = req.IndustrialManagementId
  407. item.UserId = uid
  408. item.CreateTime = time.Now()
  409. _, err = models.AddCygxIndustryTop(item)
  410. if err != nil {
  411. br.Msg = "置顶失败"
  412. br.ErrMsg = "置顶失败,Err:" + err.Error()
  413. return
  414. }
  415. br.Msg = "置顶成功"
  416. resp.Status = 1
  417. } else {
  418. err = models.RemoveCygxIndustryTop(uid, industrialManagementId)
  419. if err != nil {
  420. br.Msg = "取消置顶失败"
  421. br.ErrMsg = "取消置顶失败,Err:" + err.Error()
  422. return
  423. }
  424. br.Msg = "已取消置顶"
  425. resp.Status = 2
  426. }
  427. br.Ret = 200
  428. br.Success = true
  429. br.Data = resp
  430. }