report.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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.Msg = "获取帖子总数失败,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. if recordCount == 0 {
  257. list[k].IsRed = true
  258. }
  259. }
  260. detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
  261. if err != nil {
  262. br.Msg = "获取信息失败"
  263. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  264. return
  265. }
  266. resp := new(models.IndustrialToArticleCategoryListRep)
  267. resp.List = list
  268. resp.LayoutTime = utils.TimeRemoveHms(detail.LayoutTime)
  269. resp.IndustryName = detail.IndustryName
  270. resp.IndustrialManagementId = industrialManagementId
  271. br.Ret = 200
  272. br.Success = true
  273. br.Msg = "获取成功"
  274. br.Data = resp
  275. }
  276. // @Title 产业文章列表接口
  277. // @Description 获取产业文章列表接口
  278. // @Param PageSize query int true "每页数据条数"
  279. // @Param CurrentIndex query int true "当前页页码,从1开始"
  280. // @Param CategoryId query int true "分类ID"
  281. // @Param IndustrialManagementId query int true "产业ID"
  282. // @Success 200 {object} models.TacticsListResp
  283. // @router /industry/ArticleList [get]
  284. func (this *ReportController) List() {
  285. br := new(models.BaseResponse).Init()
  286. defer func() {
  287. this.Data["json"] = br
  288. this.ServeJSON()
  289. }()
  290. user := this.User
  291. if user == nil {
  292. br.Msg = "请重新登录"
  293. br.Ret = 408
  294. return
  295. }
  296. uid := user.UserId
  297. pageSize, _ := this.GetInt("PageSize")
  298. currentIndex, _ := this.GetInt("CurrentIndex")
  299. categoryId, _ := this.GetInt("CategoryId")
  300. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  301. var startSize int
  302. if pageSize <= 0 {
  303. pageSize = utils.PageSize20
  304. }
  305. if currentIndex <= 0 {
  306. currentIndex = 1
  307. }
  308. startSize = paging.StartIndex(currentIndex, pageSize)
  309. var pars []interface{}
  310. var total int
  311. resp := new(models.TacticsListResp)
  312. page := paging.GetPaging(currentIndex, pageSize, total)
  313. if categoryId < 1 {
  314. br.Msg = "请输入分类ID"
  315. return
  316. }
  317. if industrialManagementId < 1 {
  318. br.Msg = "请输入产业ID"
  319. return
  320. }
  321. total, err := models.GetReportIndustrialCount(categoryId, industrialManagementId)
  322. if err != nil {
  323. br.Msg = "获取信息失败"
  324. br.ErrMsg = "获取帖子总数失败,Err:" + err.Error()
  325. return
  326. }
  327. page = paging.GetPaging(currentIndex, pageSize, total)
  328. list, err := models.GetReportIndustrialList(pars, categoryId, industrialManagementId, uid, startSize, pageSize)
  329. if err != nil {
  330. br.Msg = "获取信息失败"
  331. br.ErrMsg = "获取帖子数据失败,Err:" + err.Error()
  332. return
  333. }
  334. lenList := len(list)
  335. for i := 0; i < lenList; i++ {
  336. item := list[i]
  337. list[i].Body, _ = services.GetReportContentTextSub(item.Body)
  338. //list[i].Abstract = html.UnescapeString(item.Abstract)
  339. list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
  340. }
  341. for k, v := range list {
  342. if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
  343. list[k].IsRed = true
  344. }
  345. }
  346. resp.List = list
  347. resp.Paging = page
  348. br.Ret = 200
  349. br.Success = true
  350. br.Msg = "获取成功"
  351. br.Data = resp
  352. }
  353. // @Title 置顶/取消置顶
  354. // @Description 置顶
  355. // @Param request body models.CygxIndustryTopRep true "type json string"
  356. // @Success 200
  357. // @router /top [post]
  358. func (this *ReportController) ArticleCollect() {
  359. br := new(models.BaseResponse).Init()
  360. defer func() {
  361. this.Data["json"] = br
  362. this.ServeJSON()
  363. }()
  364. user := this.User
  365. if user == nil {
  366. br.Msg = "请重新登录"
  367. br.Ret = 408
  368. return
  369. }
  370. uid := user.UserId
  371. var req models.CygxIndustryTopRep
  372. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  373. if err != nil {
  374. br.Msg = "参数解析异常!"
  375. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  376. return
  377. }
  378. industrialManagementId := req.IndustrialManagementId
  379. fmt.Println(industrialManagementId)
  380. countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
  381. if err != nil {
  382. br.Msg = "获取数据失败!"
  383. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  384. return
  385. }
  386. if countIndustrial == 0 {
  387. br.Msg = "产业不存在!"
  388. br.ErrMsg = "产业不存在"
  389. return
  390. }
  391. count, err := models.GetCygxIndustryTop(uid, industrialManagementId)
  392. if err != nil {
  393. br.Msg = "获取数据失败!"
  394. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  395. return
  396. }
  397. resp := new(models.ArticleCollectResp)
  398. if count <= 0 {
  399. item := new(models.CygxIndustryTop)
  400. item.IndustrialManagementId = req.IndustrialManagementId
  401. item.UserId = uid
  402. item.CreateTime = time.Now()
  403. _, err = models.AddCygxIndustryTop(item)
  404. if err != nil {
  405. br.Msg = "置顶失败"
  406. br.ErrMsg = "置顶失败,Err:" + err.Error()
  407. return
  408. }
  409. br.Msg = "置顶成功"
  410. resp.Status = 1
  411. } else {
  412. err = models.RemoveCygxIndustryTop(uid, industrialManagementId)
  413. if err != nil {
  414. br.Msg = "取消置顶失败"
  415. br.ErrMsg = "取消置顶失败,Err:" + err.Error()
  416. return
  417. }
  418. br.Msg = "已取消置顶"
  419. resp.Status = 2
  420. }
  421. br.Ret = 200
  422. br.Success = true
  423. br.Data = resp
  424. }