report.go 12 KB

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