report_selection.go 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/services"
  6. "hongze/hongze_cygx/utils"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. // 报告
  12. type ReportSelectionController struct {
  13. BaseAuthController
  14. }
  15. // @Title 获取报告精选详情
  16. // @Description 获取报告精选详情接口
  17. // @Param ArticleId query int true "报告ID"
  18. // @Param IsBestNew query bool false "是否获取最新的一篇报告"
  19. // @Success 200 {object} models.ReportSelectionLetailResp
  20. // @router /detail [get]
  21. func (this *ReportSelectionController) Detail() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. user := this.User
  28. if user == nil {
  29. br.Msg = "请重新登录"
  30. br.Ret = 408
  31. return
  32. }
  33. uid := user.UserId
  34. articleId, _ := this.GetInt("ArticleId")
  35. isBestNew, _ := this.GetBool("IsBestNew")
  36. if isBestNew {
  37. tbdb := "cygx_report_selection"
  38. condition := ` AND publish_status = 1 `
  39. var pars []interface{}
  40. list, err := models.GetReportSelectionListPublic(condition, "1", tbdb, pars, 0, 1)
  41. if err != nil {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "获取失败,Err:" + err.Error()
  44. return
  45. }
  46. for _, v := range list {
  47. articleId = v.ArticleId
  48. }
  49. }
  50. if articleId < 1 {
  51. br.Msg = "获取信息失败"
  52. br.ErrMsg = "报告ID错误" + strconv.Itoa(articleId)
  53. return
  54. }
  55. resp := new(models.ReportSelectionLetailResp)
  56. //判断用户权限
  57. hasPermission, err := services.GetUserhasPermission(user)
  58. if err != nil {
  59. br.Msg = "获取信息失败"
  60. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  61. }
  62. detail, err := models.GetCygxReportSelectionInfoById(articleId)
  63. if err != nil {
  64. br.Msg = "获取信息失败"
  65. br.ErrMsg = "报告不存在,Err:" + err.Error() + "articleId:" + strconv.Itoa(articleId)
  66. return
  67. }
  68. //未设置全部可见的只能给弘则内部查看
  69. if detail.VisibleRange == 1 || user.CompanyId == utils.HZ_COMPANY_ID {
  70. resp.IsShow = true
  71. }
  72. resp.HasPermission = hasPermission
  73. if hasPermission != 1 || !resp.IsShow {
  74. br.Ret = 200
  75. br.Success = true
  76. br.Msg = "获取成功"
  77. br.Data = resp
  78. return
  79. }
  80. if detail.ReportLink != "" {
  81. articleIdLink, _ := services.GetReportLinkToArticleid(detail.ReportLink)
  82. detail.CeLueArticleId = articleIdLink
  83. }
  84. articleStockMap, _ := services.GetArticleStockMap()
  85. detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  86. existMap := make(map[int]int)
  87. var items []*models.ReportSelectionChartPermission
  88. var itemsSubject []*models.ReportSelectionChartLogPermission
  89. listLog, err := models.GetReportSelectionlogListAll(articleId)
  90. if err != nil {
  91. br.Msg = "获取失败"
  92. br.ErrMsg = "获取子类信息失败,Err:" + err.Error()
  93. return
  94. }
  95. detail.VideoPlaySeconds = utils.Mp3Time(detail.VideoPlaySeconds)
  96. //获取行业核心逻辑汇总
  97. listChartLog, err := models.GetCygxReportSelectionChartLogRepList(articleId)
  98. if err != nil {
  99. br.Msg = "获取失败"
  100. br.ErrMsg = "获取失败,Err:" + err.Error()
  101. return
  102. }
  103. mapChartLog := make(map[string]string)
  104. for _, v := range listChartLog {
  105. mapChartLog[v.ChartPermissionName] = v.BodyChartSummary
  106. }
  107. for _, v := range listLog {
  108. item := new(models.ReportSelectionChartPermission)
  109. itemSubject := new(models.ReportSelectionChartLogPermission)
  110. itemSubject.PermissionName = v.PermissionName
  111. if existMap[v.ChartPermissionId] == 0 {
  112. //item.PermissionName = v.PermissionName + "领域深度报告和调研"
  113. item.PermissionName = v.PermissionName
  114. item.IcoLink = v.IcoLink
  115. listSonLog, err := models.GetReportSelectionlogSonListAll(articleId, v.ChartPermissionId)
  116. if err != nil && err.Error() != utils.ErrNoRow() {
  117. br.Msg = "获取信息失败"
  118. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  119. return
  120. }
  121. for k2, v2 := range listSonLog {
  122. if v2.IndustrialManagementId != "" {
  123. listIndustrial, err := models.GetIndustrialByIds(v2.IndustrialManagementId)
  124. if err != nil && err.Error() != utils.ErrNoRow() {
  125. br.Msg = "获取信息失败"
  126. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  127. return
  128. }
  129. listSonLog[k2].OverviewArticleId = articleStockMap[v2.SubjectName]
  130. listSonLog[k2].List = listIndustrial
  131. if v2.Label != "" {
  132. v2.CompanyLabel = strings.Split(v2.Label, "{|}")
  133. }
  134. }
  135. itemSubject.ListSubject = append(itemSubject.ListSubject, &models.ReportSelectionChartLogSubjectName{SubjectName: v2.SubjectName, IsNew: v2.IsNew, IndustrialSubjectId: v2.IndustrialSubjectId})
  136. }
  137. item.BodyChartSummary = mapChartLog[v.PermissionName]
  138. item.List = listSonLog
  139. items = append(items, item)
  140. itemsSubject = append(itemsSubject, itemSubject)
  141. //itemLogs = make([]*models.CygxReportSelectionLogDetail, 0)
  142. }
  143. existMap[v.ChartPermissionId] = v.ChartPermissionId
  144. }
  145. historyRecord := new(models.CygxReportHistoryRecord)
  146. historyRecord.UserId = uid
  147. historyRecord.ArticleId = articleId
  148. historyRecord.CreateTime = time.Now()
  149. historyRecord.Mobile = user.Mobile
  150. historyRecord.Email = user.Email
  151. historyRecord.CompanyId = user.CompanyId
  152. historyRecord.CompanyName = user.CompanyName
  153. historyRecord.ReportType = "bgjx"
  154. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  155. if err != nil && err.Error() != utils.ErrNoRow() {
  156. br.Msg = "获取信息失败"
  157. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  158. return
  159. }
  160. historyRecord.RealName = user.RealName
  161. if sellerItem != nil {
  162. historyRecord.SellerName = sellerItem.RealName
  163. }
  164. go models.AddCygxReportHistoryRecord(historyRecord)
  165. resp.List = items
  166. resp.ListPermissionSubject = itemsSubject
  167. resp.Detail = detail
  168. br.Ret = 200
  169. br.Success = true
  170. br.Msg = "获取成功"
  171. br.Data = resp
  172. }
  173. // @Title 标的点击记录
  174. // @Description 标的点击记录接口
  175. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  176. // @router /click/history [post]
  177. func (this *ReportSelectionController) ClickHistory() {
  178. br := new(models.BaseResponse).Init()
  179. defer func() {
  180. this.Data["json"] = br
  181. this.ServeJSON()
  182. }()
  183. user := this.User
  184. if user == nil {
  185. br.Msg = "请重新登录"
  186. br.Ret = 408
  187. return
  188. }
  189. var req models.AddCygxReportSelectionSubjectHistoryReq
  190. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  191. if err != nil {
  192. br.Msg = "参数解析异常!"
  193. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  194. return
  195. }
  196. if req.ArticleId <= 0 {
  197. br.Msg = "文章不存在"
  198. br.ErrMsg = "文章不存在,文章ID错误"
  199. return
  200. }
  201. if req.IndustrialSubjectId <= 0 {
  202. br.Msg = "标的ID不存在"
  203. br.ErrMsg = "标的ID不存在,标的ID错误"
  204. return
  205. }
  206. item := models.CygxReportSelectionSubjectHistory{
  207. UserId: user.UserId,
  208. ArticleId: req.ArticleId,
  209. CreateTime: time.Now(),
  210. ModifyTime: time.Now(),
  211. Mobile: user.Mobile,
  212. Email: user.Email,
  213. CompanyId: user.CompanyId,
  214. CompanyName: user.CompanyName,
  215. IndustrialSubjectId: req.IndustrialSubjectId,
  216. }
  217. err = models.AddCygxReportSelectionSubjectHistory(&item)
  218. if err != nil {
  219. br.Msg = "记录失败"
  220. br.ErrMsg = "记录失败,Err:" + err.Error()
  221. return
  222. }
  223. br.Ret = 200
  224. br.Success = true
  225. br.Msg = "记录成功"
  226. }