report_selection.go 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/services"
  6. "hongze/hongze_clpt/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. resp.Detail = detail
  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.ChartPermissionId = v.ChartPermissionId
  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. CompanyLabelSlice := strings.Split(v2.Label, "{|}")
  135. for _, vCompanyLabel := range CompanyLabelSlice {
  136. v2.CompanyLabel = append(v2.CompanyLabel, vCompanyLabel+"#")
  137. }
  138. }
  139. }
  140. itemSubject.ListSubject = append(itemSubject.ListSubject, &models.ReportSelectionChartLogSubjectName{SubjectName: v2.SubjectName, IsNew: v2.IsNew, IndustrialSubjectId: v2.IndustrialSubjectId})
  141. }
  142. item.BodyChartSummary = mapChartLog[v.PermissionName]
  143. item.List = listSonLog
  144. items = append(items, item)
  145. itemsSubject = append(itemsSubject, itemSubject)
  146. //itemLogs = make([]*models.CygxReportSelectionLogDetail, 0)
  147. }
  148. existMap[v.ChartPermissionId] = v.ChartPermissionId
  149. }
  150. //historyRecord := new(models.CygxReportHistoryRecord)
  151. //historyRecord.UserId = uid
  152. //historyRecord.ArticleId = articleId
  153. //historyRecord.CreateTime = time.Now()
  154. //historyRecord.Mobile = user.Mobile
  155. //historyRecord.Email = user.Email
  156. //historyRecord.CompanyId = user.CompanyId
  157. //historyRecord.CompanyName = user.CompanyName
  158. //historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  159. //historyRecord.ReportType = "bgjx"
  160. //sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  161. //if err != nil && err.Error() != utils.ErrNoRow() {
  162. // br.Msg = "获取信息失败"
  163. // br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  164. // return
  165. //}
  166. //historyRecord.RealName = user.RealName
  167. //if sellerItem != nil {
  168. // historyRecord.SellerName = sellerItem.RealName
  169. //}
  170. //go services.AddCygxReportHistoryRecord(user, articleId, "bgjx")
  171. resp.List = items
  172. resp.ListPermissionSubject = itemsSubject
  173. resp.Detail = detail
  174. br.Ret = 200
  175. br.Success = true
  176. br.Msg = "获取成功"
  177. br.Data = resp
  178. }
  179. // @Title 标的点击记录
  180. // @Description 标的点击记录接口
  181. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  182. // @router /click/history [post]
  183. func (this *ReportSelectionController) ClickHistory() {
  184. br := new(models.BaseResponse).Init()
  185. defer func() {
  186. this.Data["json"] = br
  187. this.ServeJSON()
  188. }()
  189. user := this.User
  190. if user == nil {
  191. br.Msg = "请重新登录"
  192. br.Ret = 408
  193. return
  194. }
  195. var req models.AddCygxReportSelectionSubjectHistoryReq
  196. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  197. if err != nil {
  198. br.Msg = "参数解析异常!"
  199. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  200. return
  201. }
  202. if req.ArticleId <= 0 {
  203. br.Msg = "文章不存在"
  204. br.ErrMsg = "文章不存在,文章ID错误"
  205. return
  206. }
  207. if req.IndustrialSubjectId <= 0 {
  208. br.Msg = "标的ID不存在"
  209. br.ErrMsg = "标的ID不存在,标的ID错误"
  210. return
  211. }
  212. item := models.CygxReportSelectionSubjectHistory{
  213. UserId: user.UserId,
  214. ArticleId: req.ArticleId,
  215. CreateTime: time.Now(),
  216. ModifyTime: time.Now(),
  217. Mobile: user.Mobile,
  218. Email: user.Email,
  219. CompanyId: user.CompanyId,
  220. CompanyName: user.CompanyName,
  221. IndustrialSubjectId: req.IndustrialSubjectId,
  222. RegisterPlatform: utils.REGISTER_PLATFORM,
  223. }
  224. err = models.AddCygxReportSelectionSubjectHistory(&item)
  225. if err != nil {
  226. br.Msg = "记录失败"
  227. br.ErrMsg = "记录失败,Err:" + err.Error()
  228. return
  229. }
  230. br.Ret = 200
  231. br.Success = true
  232. br.Msg = "记录成功"
  233. }
  234. // @Title 上传文章阅读时间
  235. // @Description 上传文章阅读时间接口
  236. // @Param request body models.AddStopTimeRep true "type json string"
  237. // @Success 200 {object} models.ArticleDetailResp
  238. // @router /addStopTime [post]
  239. func (this *ReportSelectionController) AddStopTime() {
  240. br := new(models.BaseResponse).Init()
  241. defer func() {
  242. this.Data["json"] = br
  243. this.ServeJSON()
  244. }()
  245. user := this.User
  246. if user == nil {
  247. br.Msg = "请登录"
  248. br.ErrMsg = "请登录,用户信息为空"
  249. br.Ret = 408
  250. return
  251. }
  252. var req models.AddReportSelectionStopTimeRep
  253. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  254. if err != nil {
  255. br.Msg = "参数解析异常!"
  256. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  257. return
  258. }
  259. uid := user.UserId
  260. articleId := req.ArticleId
  261. stopTime := req.StopTime
  262. outType := req.OutType
  263. source := req.Source
  264. var reportType string
  265. if source == 1 {
  266. reportType = "bgjx"
  267. } else if source == 2 {
  268. reportType = "bzyjhz"
  269. } else if source == 3 {
  270. reportType = "szjyhz"
  271. }
  272. hasPermission, err := services.GetUserhasPermission(user)
  273. if err != nil {
  274. br.Msg = "获取信息失败"
  275. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  276. }
  277. if hasPermission == 1 {
  278. historyRecord := new(models.CygxReportHistoryRecord)
  279. historyRecord.UserId = uid
  280. historyRecord.ArticleId = articleId
  281. historyRecord.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  282. historyRecord.Mobile = user.Mobile
  283. historyRecord.Email = user.Email
  284. historyRecord.CompanyId = user.CompanyId
  285. historyRecord.CompanyName = user.CompanyName
  286. historyRecord.StopTime = stopTime
  287. historyRecord.OutType = outType
  288. historyRecord.ReportType = reportType
  289. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  290. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  291. if err != nil && err.Error() != utils.ErrNoRow() {
  292. br.Msg = "获取信息失败"
  293. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  294. return
  295. }
  296. historyRecord.RealName = user.RealName
  297. if sellerItem != nil {
  298. historyRecord.SellerName = sellerItem.RealName
  299. }
  300. go services.AddCygxReportHistoryRecord(historyRecord)
  301. }
  302. br.Ret = 200
  303. br.Success = true
  304. br.Msg = "操作成功"
  305. }