report.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/utils"
  7. "strings"
  8. "time"
  9. )
  10. //报告
  11. type ReportController struct {
  12. BaseAuthController
  13. }
  14. type ReportCommonController struct {
  15. BaseCommonController
  16. }
  17. // @Title 行业报告分类列表接口
  18. // @Description 获取行业报告分类列表接口
  19. // @Param ChartPermissionId query int true "分类ID"
  20. // @Success 200 {object} models.IndustrialManagementList
  21. // @router /home/tradeList [get]
  22. func (this *ReportController) TradeList() {
  23. br := new(models.BaseResponse).Init()
  24. defer func() {
  25. this.Data["json"] = br
  26. this.ServeJSON()
  27. }()
  28. user := this.User
  29. if user == nil {
  30. br.Msg = "请重新登录"
  31. br.Ret = 408
  32. return
  33. }
  34. uid := user.UserId
  35. ChartPermissionId, _ := this.GetInt("ChartPermissionId")
  36. if ChartPermissionId < 1 {
  37. br.Msg = "请输入分类ID"
  38. return
  39. }
  40. list, err := models.GetTradeAll(uid, ChartPermissionId)
  41. if err != nil {
  42. br.Msg = "获取信息失败"
  43. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  44. return
  45. }
  46. for k, v := range list {
  47. list[k].UpdateTime = utils.TimeRemoveHms(v.UpdateTime)
  48. if v.Readnum == 0 {
  49. list[k].IsRed = true
  50. }
  51. }
  52. resp := new(models.TradeReportMappingResp)
  53. resp.List = list
  54. br.Ret = 200
  55. br.Success = true
  56. br.Msg = "获取成功"
  57. br.Data = resp
  58. }
  59. // @Title 产业报告分类列表接口
  60. // @Description 获取产业报告分类列表接口
  61. // @Param ChartPermissionId query int true "分类ID"
  62. // @Param OrderColumn query int true "排序字段 ,NewTime最近更新 ,Recommend弘则推荐"
  63. // @Success 200 {object} models.IndustrialManagementList
  64. // @router /home/industryList [get]
  65. func (this *ReportController) IndustryList() {
  66. br := new(models.BaseResponse).Init()
  67. defer func() {
  68. this.Data["json"] = br
  69. this.ServeJSON()
  70. }()
  71. user := this.User
  72. if user == nil {
  73. br.Msg = "请重新登录"
  74. br.Ret = 408
  75. return
  76. }
  77. uid := user.UserId
  78. var orderSrt string
  79. ChartPermissionId, _ := this.GetInt("ChartPermissionId")
  80. orderColumn := this.GetString("OrderColumn")
  81. if orderColumn == " " {
  82. orderColumn = "NewTime"
  83. }
  84. if ChartPermissionId < 1 {
  85. br.Msg = "请输入分类ID"
  86. return
  87. }
  88. listTop, err := models.GetIndustrialManagementTopAll(ChartPermissionId, uid)
  89. for k, v := range listTop {
  90. listTop[k].IsTop = true
  91. if v.Readnum == 0 {
  92. listTop[k].IsRed = true
  93. }
  94. listTop[k].UpdateTime = utils.TimeRemoveHms(v.UpdateTime)
  95. listTop[k].LayoutTime = utils.TimeRemoveHms(v.LayoutTime)
  96. }
  97. if orderColumn == "NewTime" {
  98. orderSrt = "art.publish_date DESC"
  99. } else {
  100. orderSrt = "man.recommended_index DESC"
  101. }
  102. list, err := models.GetIndustrialManagementAll(ChartPermissionId, uid, orderSrt)
  103. for k, v := range list {
  104. if v.Readnum == 0 {
  105. list[k].IsRed = true
  106. }
  107. list[k].UpdateTime = utils.TimeRemoveHms(v.UpdateTime)
  108. list[k].LayoutTime = utils.TimeRemoveHms(v.LayoutTime)
  109. }
  110. list = append(listTop, list...)
  111. if err != nil {
  112. br.Msg = "获取信息失败"
  113. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  114. return
  115. }
  116. for k, v := range list {
  117. var analystStr string
  118. analystList, err := models.GetIndustrialAnalystAll(v.IndustrialManagementId)
  119. if err != nil {
  120. br.Msg = "获取信息失败"
  121. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  122. return
  123. }
  124. industrialSubjectList, err := models.GetIndustrialSubjectAll(v.IndustrialManagementId)
  125. if err != nil {
  126. br.Msg = "获取信息失败"
  127. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  128. return
  129. }
  130. list[k].IndustrialSubjectList = industrialSubjectList
  131. if len(analystList) > 0 {
  132. for _, v2 := range analystList {
  133. analystStr += v2.AnalystName + "/"
  134. }
  135. analystStr = strings.TrimRight(analystStr, "/")
  136. }
  137. list[k].Analyst = analystStr
  138. }
  139. resp := new(models.IndustrialManagementList)
  140. resp.List = list
  141. br.Ret = 200
  142. br.Success = true
  143. br.Msg = "获取成功"
  144. br.Data = resp
  145. }
  146. // @Title 产业下所关联的文章分类列表
  147. // @Description 产业下所关联的文章分类列表接口
  148. // @Param IndustrialManagementId query int true "产业ID"
  149. // @Success 200 {object} models.IndustrialToArticleCategoryListRep
  150. // @router /toArticleCategoryList [get]
  151. func (this *ReportController) ArticleCategoryList() {
  152. br := new(models.BaseResponse).Init()
  153. defer func() {
  154. this.Data["json"] = br
  155. this.ServeJSON()
  156. }()
  157. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  158. if industrialManagementId < 1 {
  159. br.Msg = "请输入分类ID"
  160. return
  161. }
  162. list, err := models.IndustrialToArticleCategory(industrialManagementId)
  163. if err != nil {
  164. br.Msg = "获取信息失败"
  165. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  166. return
  167. }
  168. detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
  169. fmt.Println(detail)
  170. if err != nil {
  171. br.Msg = "获取信息失败"
  172. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  173. return
  174. }
  175. resp := new(models.IndustrialToArticleCategoryListRep)
  176. resp.List = list
  177. resp.LayoutTime = detail.LayoutTime
  178. resp.IndustryName = detail.IndustryName
  179. br.Ret = 200
  180. br.Success = true
  181. br.Msg = "获取成功"
  182. br.Data = resp
  183. }
  184. // @Title 置顶/取消置顶
  185. // @Description 置顶
  186. // @Param request body models.CygxIndustryTopRep true "type json string"
  187. // @Success 200
  188. // @router /top [post]
  189. func (this *ReportController) ArticleCollect() {
  190. br := new(models.BaseResponse).Init()
  191. defer func() {
  192. this.Data["json"] = br
  193. this.ServeJSON()
  194. }()
  195. user := this.User
  196. if user == nil {
  197. br.Msg = "请重新登录"
  198. br.Ret = 408
  199. return
  200. }
  201. uid := user.UserId
  202. var req models.CygxIndustryTopRep
  203. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  204. if err != nil {
  205. br.Msg = "参数解析异常!"
  206. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  207. return
  208. }
  209. industrialManagementId := req.IndustrialManagementId
  210. fmt.Println(industrialManagementId)
  211. countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
  212. if err != nil {
  213. br.Msg = "获取数据失败!"
  214. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  215. return
  216. }
  217. if countIndustrial == 0 {
  218. br.Msg = "产业不存在!"
  219. br.ErrMsg = "产业不存在"
  220. return
  221. }
  222. count, err := models.GetCygxIndustryTop(uid, industrialManagementId)
  223. if err != nil {
  224. br.Msg = "获取数据失败!"
  225. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  226. return
  227. }
  228. resp := new(models.ArticleCollectResp)
  229. if count <= 0 {
  230. item := new(models.CygxIndustryTop)
  231. item.IndustrialManagementId = req.IndustrialManagementId
  232. item.UserId = uid
  233. item.CreateTime = time.Now()
  234. _, err = models.AddCygxIndustryTop(item)
  235. if err != nil {
  236. br.Msg = "置顶失败"
  237. br.ErrMsg = "置顶失败,Err:" + err.Error()
  238. return
  239. }
  240. br.Msg = "置顶成功"
  241. resp.Status = 1
  242. } else {
  243. err = models.RemoveCygxIndustryTop(uid, industrialManagementId)
  244. if err != nil {
  245. br.Msg = "取消置顶失败"
  246. br.ErrMsg = "取消置顶失败,Err:" + err.Error()
  247. return
  248. }
  249. br.Msg = "已取消置顶"
  250. resp.Status = 2
  251. }
  252. br.Ret = 200
  253. br.Success = true
  254. br.Data = resp
  255. }