report.go 7.0 KB

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