report.go 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. list[k].IsTop = true
  105. if v.Readnum == 0 {
  106. listTop[k].IsRed = true
  107. }
  108. list[k].UpdateTime = utils.TimeRemoveHms(v.UpdateTime)
  109. list[k].LayoutTime = utils.TimeRemoveHms(v.LayoutTime)
  110. }
  111. list = append(listTop, list...)
  112. if err != nil {
  113. br.Msg = "获取信息失败"
  114. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  115. return
  116. }
  117. for k, v := range list {
  118. var analystStr string
  119. analystList, err := models.GetIndustrialAnalystAll(v.IndustrialManagementId)
  120. if err != nil {
  121. br.Msg = "获取信息失败"
  122. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  123. return
  124. }
  125. industrialSubjectList, err := models.GetIndustrialSubjectAll(v.IndustrialManagementId)
  126. if err != nil {
  127. br.Msg = "获取信息失败"
  128. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  129. return
  130. }
  131. list[k].IndustrialSubjectList = industrialSubjectList
  132. if len(analystList) > 0 {
  133. for _, v2 := range analystList {
  134. analystStr += v2.AnalystName + "/"
  135. }
  136. analystStr = strings.TrimRight(analystStr, "/")
  137. }
  138. list[k].Analyst = analystStr
  139. }
  140. resp := new(models.IndustrialManagementList)
  141. resp.List = list
  142. br.Ret = 200
  143. br.Success = true
  144. br.Msg = "获取成功"
  145. br.Data = resp
  146. }
  147. // @Title 产业下所关联的文章分类列表
  148. // @Description 产业下所关联的文章分类列表接口
  149. // @Param IndustrialManagementId query int true "产业ID"
  150. // @Success 200 {object} models.IndustrialToArticleCategoryListRep
  151. // @router /toArticleCategoryList [get]
  152. func (this *ReportController) ArticleCategoryList() {
  153. br := new(models.BaseResponse).Init()
  154. defer func() {
  155. this.Data["json"] = br
  156. this.ServeJSON()
  157. }()
  158. industrialManagementId, _ := this.GetInt("IndustrialManagementId")
  159. if industrialManagementId < 1 {
  160. br.Msg = "请输入分类ID"
  161. return
  162. }
  163. list, err := models.IndustrialToArticleCategory(industrialManagementId)
  164. if err != nil {
  165. br.Msg = "获取信息失败"
  166. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  167. return
  168. }
  169. detail, err := models.GetIndustrialManagementDetail(industrialManagementId)
  170. fmt.Println(detail)
  171. if err != nil {
  172. br.Msg = "获取信息失败"
  173. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  174. return
  175. }
  176. resp := new(models.IndustrialToArticleCategoryListRep)
  177. resp.List = list
  178. resp.LayoutTime = detail.LayoutTime
  179. resp.IndustryName = detail.IndustryName
  180. br.Ret = 200
  181. br.Success = true
  182. br.Msg = "获取成功"
  183. br.Data = resp
  184. }
  185. // @Title 置顶/取消置顶
  186. // @Description 置顶
  187. // @Param request body models.CygxIndustryTopRep true "type json string"
  188. // @Success 200
  189. // @router /top [post]
  190. func (this *ReportController) ArticleCollect() {
  191. br := new(models.BaseResponse).Init()
  192. defer func() {
  193. this.Data["json"] = br
  194. this.ServeJSON()
  195. }()
  196. user := this.User
  197. if user == nil {
  198. br.Msg = "请重新登录"
  199. br.Ret = 408
  200. return
  201. }
  202. uid := user.UserId
  203. var req models.CygxIndustryTopRep
  204. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  205. if err != nil {
  206. br.Msg = "参数解析异常!"
  207. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  208. return
  209. }
  210. industrialManagementId := req.IndustrialManagementId
  211. fmt.Println(industrialManagementId)
  212. countIndustrial, err := models.GetIndustrialManagementCount(industrialManagementId)
  213. if err != nil {
  214. br.Msg = "获取数据失败!"
  215. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  216. return
  217. }
  218. if countIndustrial == 0 {
  219. br.Msg = "产业不存在!"
  220. br.ErrMsg = "产业不存在"
  221. return
  222. }
  223. count, err := models.GetCygxIndustryTop(uid, industrialManagementId)
  224. if err != nil {
  225. br.Msg = "获取数据失败!"
  226. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  227. return
  228. }
  229. resp := new(models.ArticleCollectResp)
  230. if count <= 0 {
  231. item := new(models.CygxIndustryTop)
  232. item.IndustrialManagementId = req.IndustrialManagementId
  233. item.UserId = uid
  234. item.CreateTime = time.Now()
  235. _, err = models.AddCygxIndustryTop(item)
  236. if err != nil {
  237. br.Msg = "置顶失败"
  238. br.ErrMsg = "置顶失败,Err:" + err.Error()
  239. return
  240. }
  241. br.Msg = "置顶成功"
  242. resp.Status = 1
  243. } else {
  244. err = models.RemoveCygxIndustryTop(uid, industrialManagementId)
  245. if err != nil {
  246. br.Msg = "取消置顶失败"
  247. br.ErrMsg = "取消置顶失败,Err:" + err.Error()
  248. return
  249. }
  250. br.Msg = "已取消置顶"
  251. resp.Status = 2
  252. }
  253. br.Ret = 200
  254. br.Success = true
  255. br.Data = resp
  256. }