report_selection.go 7.2 KB

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