report_selection.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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. resp.Detail = detail
  76. br.Ret = 200
  77. br.Success = true
  78. br.Msg = "获取成功"
  79. br.Data = resp
  80. return
  81. }
  82. if detail.ReportLink != "" {
  83. articleIdLink, _ := services.GetReportLinkToArticleid(detail.ReportLink)
  84. detail.CeLueArticleId = articleIdLink
  85. }
  86. articleStockMap, _ := services.GetArticleStockMap()
  87. detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  88. existMap := make(map[int]int)
  89. var items []*models.ReportSelectionChartPermission
  90. var itemsSubject []*models.ReportSelectionChartLogPermission
  91. listLog, err := models.GetReportSelectionlogListAll(articleId)
  92. if err != nil {
  93. br.Msg = "获取失败"
  94. br.ErrMsg = "获取子类信息失败,Err:" + err.Error()
  95. return
  96. }
  97. detail.VideoPlaySeconds = utils.Mp3Time(detail.VideoPlaySeconds)
  98. //获取行业核心逻辑汇总
  99. listChartLog, err := models.GetCygxReportSelectionChartLogRepList(articleId)
  100. if err != nil {
  101. br.Msg = "获取失败"
  102. br.ErrMsg = "获取失败,Err:" + err.Error()
  103. return
  104. }
  105. mapChartLog := make(map[string]string)
  106. for _, v := range listChartLog {
  107. mapChartLog[v.ChartPermissionName] = v.BodyChartSummary
  108. }
  109. for _, v := range listLog {
  110. item := new(models.ReportSelectionChartPermission)
  111. itemSubject := new(models.ReportSelectionChartLogPermission)
  112. itemSubject.PermissionName = v.PermissionName
  113. if existMap[v.ChartPermissionId] == 0 {
  114. //item.PermissionName = v.PermissionName + "领域深度报告和调研"
  115. item.PermissionName = v.PermissionName
  116. item.IcoLink = v.IcoLink
  117. listSonLog, err := models.GetReportSelectionlogSonListAll(articleId, v.ChartPermissionId)
  118. if err != nil && err.Error() != utils.ErrNoRow() {
  119. br.Msg = "获取信息失败"
  120. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  121. return
  122. }
  123. for k2, v2 := range listSonLog {
  124. if v2.IndustrialManagementId != "" {
  125. listIndustrial, err := models.GetIndustrialByIds(v2.IndustrialManagementId)
  126. if err != nil && err.Error() != utils.ErrNoRow() {
  127. br.Msg = "获取信息失败"
  128. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  129. return
  130. }
  131. listSonLog[k2].OverviewArticleId = articleStockMap[v2.SubjectName]
  132. listSonLog[k2].List = listIndustrial
  133. if v2.Label != "" {
  134. v2.CompanyLabel = strings.Split(v2.Label, "{|}")
  135. }
  136. }
  137. itemSubject.ListSubject = append(itemSubject.ListSubject, &models.ReportSelectionChartLogSubjectName{SubjectName: v2.SubjectName, IsNew: v2.IsNew, IndustrialSubjectId: v2.IndustrialSubjectId})
  138. }
  139. item.BodyChartSummary = mapChartLog[v.PermissionName]
  140. item.List = listSonLog
  141. items = append(items, item)
  142. itemsSubject = append(itemsSubject, itemSubject)
  143. //itemLogs = make([]*models.CygxReportSelectionLogDetail, 0)
  144. }
  145. existMap[v.ChartPermissionId] = v.ChartPermissionId
  146. }
  147. //historyRecord := new(models.CygxReportHistoryRecord)
  148. //historyRecord.UserId = uid
  149. //historyRecord.ArticleId = articleId
  150. //historyRecord.CreateTime = time.Now()
  151. //historyRecord.Mobile = user.Mobile
  152. //historyRecord.Email = user.Email
  153. //historyRecord.CompanyId = user.CompanyId
  154. //historyRecord.CompanyName = user.CompanyName
  155. //historyRecord.ReportType = "bgjx"
  156. //sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  157. //if err != nil && err.Error() != utils.ErrNoRow() {
  158. // br.Msg = "获取信息失败"
  159. // br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  160. // return
  161. //}
  162. //historyRecord.RealName = user.RealName
  163. //if sellerItem != nil {
  164. // historyRecord.SellerName = sellerItem.RealName
  165. //}
  166. //
  167. //go models.AddCygxReportHistoryRecord(historyRecord)
  168. resp.List = items
  169. resp.ListPermissionSubject = itemsSubject
  170. resp.Detail = detail
  171. br.Ret = 200
  172. br.Success = true
  173. br.Msg = "获取成功"
  174. br.Data = resp
  175. }
  176. // @Title 标的点击记录
  177. // @Description 标的点击记录接口
  178. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  179. // @router /click/history [post]
  180. func (this *ReportSelectionController) ClickHistory() {
  181. br := new(models.BaseResponse).Init()
  182. defer func() {
  183. this.Data["json"] = br
  184. this.ServeJSON()
  185. }()
  186. user := this.User
  187. if user == nil {
  188. br.Msg = "请重新登录"
  189. br.Ret = 408
  190. return
  191. }
  192. var req models.AddCygxReportSelectionSubjectHistoryReq
  193. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  194. if err != nil {
  195. br.Msg = "参数解析异常!"
  196. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  197. return
  198. }
  199. if req.ArticleId <= 0 {
  200. br.Msg = "文章不存在"
  201. br.ErrMsg = "文章不存在,文章ID错误"
  202. return
  203. }
  204. if req.IndustrialSubjectId <= 0 {
  205. br.Msg = "标的ID不存在"
  206. br.ErrMsg = "标的ID不存在,标的ID错误"
  207. return
  208. }
  209. item := models.CygxReportSelectionSubjectHistory{
  210. UserId: user.UserId,
  211. ArticleId: req.ArticleId,
  212. CreateTime: time.Now(),
  213. ModifyTime: time.Now(),
  214. Mobile: user.Mobile,
  215. Email: user.Email,
  216. CompanyId: user.CompanyId,
  217. CompanyName: user.CompanyName,
  218. IndustrialSubjectId: req.IndustrialSubjectId,
  219. }
  220. err = models.AddCygxReportSelectionSubjectHistory(&item)
  221. if err != nil {
  222. br.Msg = "记录失败"
  223. br.ErrMsg = "记录失败,Err:" + err.Error()
  224. return
  225. }
  226. br.Ret = 200
  227. br.Success = true
  228. br.Msg = "记录成功"
  229. }
  230. // @Title 上传文章阅读时间
  231. // @Description 上传文章阅读时间接口
  232. // @Param request body models.AddStopTimeRep true "type json string"
  233. // @Success 200 {object} models.ArticleDetailResp
  234. // @router /addStopTime [post]
  235. func (this *ReportSelectionController) AddStopTime() {
  236. br := new(models.BaseResponse).Init()
  237. defer func() {
  238. this.Data["json"] = br
  239. this.ServeJSON()
  240. }()
  241. user := this.User
  242. if user == nil {
  243. br.Msg = "请登录"
  244. br.ErrMsg = "请登录,用户信息为空"
  245. br.Ret = 408
  246. return
  247. }
  248. var req models.AddReportSelectionStopTimeRep
  249. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  250. if err != nil {
  251. br.Msg = "参数解析异常!"
  252. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  253. return
  254. }
  255. uid := user.UserId
  256. articleId := req.ArticleId
  257. stopTime := req.StopTime
  258. outType := req.OutType
  259. source := req.Source
  260. var reportType string
  261. if source == 1 {
  262. reportType = "bgjx"
  263. } else if source == 2 {
  264. reportType = "bzyjhz"
  265. } else if source == 3 {
  266. reportType = "szjyhz"
  267. }
  268. hasPermission, err := services.GetUserhasPermission(user)
  269. if err != nil {
  270. br.Msg = "获取信息失败"
  271. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  272. }
  273. if hasPermission == 1 {
  274. historyRecord := new(models.CygxReportHistoryRecord)
  275. historyRecord.UserId = uid
  276. historyRecord.ArticleId = articleId
  277. historyRecord.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  278. historyRecord.Mobile = user.Mobile
  279. historyRecord.Email = user.Email
  280. historyRecord.CompanyId = user.CompanyId
  281. historyRecord.CompanyName = user.CompanyName
  282. historyRecord.StopTime = stopTime
  283. historyRecord.OutType = outType
  284. historyRecord.ReportType = reportType
  285. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  286. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  287. if err != nil && err.Error() != utils.ErrNoRow() {
  288. br.Msg = "获取信息失败"
  289. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  290. return
  291. }
  292. historyRecord.RealName = user.RealName
  293. if sellerItem != nil {
  294. historyRecord.SellerName = sellerItem.RealName
  295. }
  296. go services.AddCygxReportHistoryRecord(historyRecord)
  297. }
  298. br.Ret = 200
  299. br.Success = true
  300. br.Msg = "操作成功"
  301. }