report_selection.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/services"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. // 报告
  13. type ReportSelectionController struct {
  14. BaseAuthController
  15. }
  16. // @Title 获取报告精选详情
  17. // @Description 获取报告精选详情接口
  18. // @Param ArticleId query int true "报告ID"
  19. // @Param IsBestNew query bool false "是否获取最新的一篇报告"
  20. // @Success 200 {object} models.ReportSelectionLetailResp
  21. // @router /detail [get]
  22. func (this *ReportSelectionController) Detail() {
  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. articleId, _ := this.GetInt("ArticleId")
  36. isBestNew, _ := this.GetBool("IsBestNew")
  37. if articleId == 0 || isBestNew {
  38. isBestNew = true
  39. if isBestNew {
  40. tbdb := "cygx_report_selection"
  41. condition := ` AND publish_status = 1 `
  42. var pars []interface{}
  43. list, err := models.GetReportSelectionListPublic(condition, "1", tbdb, pars, 0, 1)
  44. if err != nil {
  45. br.Msg = "获取失败"
  46. br.ErrMsg = "获取失败,Err:" + err.Error()
  47. return
  48. }
  49. for _, v := range list {
  50. articleId = v.ArticleId
  51. }
  52. }
  53. }
  54. if articleId < 1 {
  55. br.Msg = "获取信息失败"
  56. br.ErrMsg = "报告ID错误" + strconv.Itoa(articleId)
  57. return
  58. }
  59. resp := new(models.ReportSelectionLetailResp)
  60. //判断用户权限
  61. hasPermission, err := services.GetUserhasPermission(user)
  62. if err != nil {
  63. br.Msg = "获取信息失败"
  64. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  65. }
  66. detail, err := models.GetCygxReportSelectionInfoById(articleId)
  67. if err != nil {
  68. br.Msg = "获取信息失败"
  69. br.ErrMsg = "报告不存在,Err:" + err.Error() + "articleId:" + strconv.Itoa(articleId)
  70. return
  71. }
  72. //未设置全部可见的只能给弘则内部查看
  73. if detail.VisibleRange == 1 || user.CompanyId == utils.HZ_COMPANY_ID {
  74. resp.IsShow = true
  75. }
  76. resp.HasPermission = hasPermission
  77. if hasPermission != 1 || !resp.IsShow {
  78. resp.Detail = detail
  79. br.Ret = 200
  80. br.Success = true
  81. br.Msg = "获取成功"
  82. br.Data = resp
  83. return
  84. }
  85. if detail.ReportLink != "" {
  86. articleIdLink, _ := services.GetReportLinkToArticleid(detail.ReportLink)
  87. detail.CeLueArticleId = articleIdLink
  88. }
  89. articleStockMap, _ := services.GetArticleStockMap()
  90. detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  91. existMap := make(map[int]int)
  92. var items []*models.ReportSelectionChartPermission
  93. var itemsSubject []*models.ReportSelectionChartLogPermission
  94. listLog, err := models.GetReportSelectionlogListAll(articleId)
  95. if err != nil {
  96. br.Msg = "获取失败"
  97. br.ErrMsg = "获取子类信息失败,Err:" + err.Error()
  98. return
  99. }
  100. detail.VideoPlaySeconds = utils.Mp3Time(detail.VideoPlaySeconds)
  101. //获取行业核心逻辑汇总
  102. listChartLog, err := models.GetCygxReportSelectionChartLogRepList(articleId)
  103. if err != nil {
  104. br.Msg = "获取失败"
  105. br.ErrMsg = "获取失败,Err:" + err.Error()
  106. return
  107. }
  108. mapChartLog := make(map[string]string)
  109. for _, v := range listChartLog {
  110. mapChartLog[v.ChartPermissionName] = v.BodyChartSummary
  111. }
  112. for _, v := range listLog {
  113. item := new(models.ReportSelectionChartPermission)
  114. itemSubject := new(models.ReportSelectionChartLogPermission)
  115. itemSubject.PermissionName = v.PermissionName
  116. if existMap[v.ChartPermissionId] == 0 {
  117. //item.PermissionName = v.PermissionName + "领域深度报告和调研"
  118. item.PermissionName = v.PermissionName
  119. item.IcoLink = v.IcoLink
  120. listSonLog, err := models.GetReportSelectionlogSonListAll(articleId, v.ChartPermissionId)
  121. if err != nil && err.Error() != utils.ErrNoRow() {
  122. br.Msg = "获取信息失败"
  123. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  124. return
  125. }
  126. for k2, v2 := range listSonLog {
  127. if v2.IndustrialManagementId != "" {
  128. listIndustrial, err := models.GetIndustrialByIds(v2.IndustrialManagementId)
  129. if err != nil && err.Error() != utils.ErrNoRow() {
  130. br.Msg = "获取信息失败"
  131. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  132. return
  133. }
  134. listSonLog[k2].OverviewArticleId = articleStockMap[v2.SubjectName]
  135. listSonLog[k2].List = listIndustrial
  136. if v2.Label != "" {
  137. v2.CompanyLabel = strings.Split(v2.Label, "{|}")
  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.ReportType = "bgjx"
  159. //sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  160. //if err != nil && err.Error() != utils.ErrNoRow() {
  161. // br.Msg = "获取信息失败"
  162. // br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  163. // return
  164. //}
  165. //historyRecord.RealName = user.RealName
  166. //if sellerItem != nil {
  167. // historyRecord.SellerName = sellerItem.RealName
  168. //}
  169. //
  170. //go models.AddCygxReportHistoryRecord(historyRecord)
  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. }
  223. err = models.AddCygxReportSelectionSubjectHistory(&item)
  224. if err != nil {
  225. br.Msg = "记录失败"
  226. br.ErrMsg = "记录失败,Err:" + err.Error()
  227. return
  228. }
  229. br.Ret = 200
  230. br.Success = true
  231. br.Msg = "记录成功"
  232. }
  233. // @Title 上传文章阅读时间
  234. // @Description 上传文章阅读时间接口
  235. // @Param request body models.AddStopTimeRep true "type json string"
  236. // @Success 200 {object} models.ArticleDetailResp
  237. // @router /addStopTime [post]
  238. func (this *ReportSelectionController) AddStopTime() {
  239. br := new(models.BaseResponse).Init()
  240. defer func() {
  241. this.Data["json"] = br
  242. this.ServeJSON()
  243. }()
  244. user := this.User
  245. if user == nil {
  246. br.Msg = "请登录"
  247. br.ErrMsg = "请登录,用户信息为空"
  248. br.Ret = 408
  249. return
  250. }
  251. var req models.AddReportSelectionStopTimeRep
  252. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  253. if err != nil {
  254. br.Msg = "参数解析异常!"
  255. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  256. return
  257. }
  258. uid := user.UserId
  259. articleId := req.ArticleId
  260. stopTime := req.StopTime
  261. outType := req.OutType
  262. source := req.Source
  263. var reportType string
  264. if source == 1 {
  265. reportType = "bgjx"
  266. } else if source == 2 {
  267. reportType = "bzyjhz"
  268. } else if source == 3 {
  269. reportType = "szjyhz"
  270. }
  271. hasPermission, err := services.GetUserhasPermission(user)
  272. if err != nil {
  273. br.Msg = "获取信息失败"
  274. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  275. }
  276. if hasPermission == 1 {
  277. historyRecord := new(models.CygxReportHistoryRecord)
  278. historyRecord.UserId = uid
  279. historyRecord.ArticleId = articleId
  280. historyRecord.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  281. historyRecord.Mobile = user.Mobile
  282. historyRecord.Email = user.Email
  283. historyRecord.CompanyId = user.CompanyId
  284. historyRecord.CompanyName = user.CompanyName
  285. historyRecord.StopTime = stopTime
  286. historyRecord.OutType = outType
  287. historyRecord.ReportType = reportType
  288. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  289. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  290. if err != nil && err.Error() != utils.ErrNoRow() {
  291. br.Msg = "获取信息失败"
  292. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  293. return
  294. }
  295. historyRecord.RealName = user.RealName
  296. if sellerItem != nil {
  297. historyRecord.SellerName = sellerItem.RealName
  298. }
  299. go services.AddCygxReportHistoryRecord(historyRecord)
  300. }
  301. br.Ret = 200
  302. br.Success = true
  303. br.Msg = "操作成功"
  304. }
  305. // @Title 获取报告精选列表
  306. // @Description 获取报告精选列表接口
  307. // @Param PageSize query int true "每页数据条数"
  308. // @Param CurrentIndex query int true "当前页页码,从1开始"
  309. // @Success 200 {object} models.ReportSelectionLetailResp
  310. // @router /list [get]
  311. func (this *ReportSelectionController) List() {
  312. br := new(models.BaseResponse).Init()
  313. defer func() {
  314. this.Data["json"] = br
  315. this.ServeJSON()
  316. }()
  317. user := this.User
  318. if user == nil {
  319. br.Msg = "请重新登录"
  320. br.Ret = 408
  321. return
  322. }
  323. resp := new(models.CygxReportSelectionListPublicRep)
  324. pageSize, _ := this.GetInt("PageSize")
  325. currentIndex, _ := this.GetInt("CurrentIndex")
  326. var startSize int
  327. if pageSize <= 0 {
  328. pageSize = utils.PageSize20
  329. }
  330. if currentIndex <= 0 {
  331. currentIndex = 1
  332. }
  333. startSize = utils.StartIndex(currentIndex, pageSize)
  334. var condition string
  335. var pars []interface{}
  336. condition += ` AND art.publish_status = 1 AND article_id >= 16 `
  337. total, err := models.GetCygxReportSelectionCount(condition, pars)
  338. if err != nil {
  339. br.Msg = "获取失败"
  340. br.ErrMsg = "获取失败,Err:" + err.Error()
  341. return
  342. }
  343. condition += " ORDER BY art.publish_date DESC "
  344. list, err := models.GetReportSelectionList(condition, pars, startSize, pageSize)
  345. if err != nil {
  346. br.Msg = "获取失败"
  347. br.ErrMsg = "获取失败,Err:" + err.Error()
  348. return
  349. }
  350. var articleIdArr []int
  351. for _, v := range list {
  352. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  353. articleIdArr = append(articleIdArr, v.ArticleId)
  354. }
  355. lenarticleIdArr := len(articleIdArr)
  356. maplabel := make(map[int]string)
  357. if lenarticleIdArr > 0 {
  358. condition = ""
  359. pars = make([]interface{}, 0)
  360. condition = ` AND is_new = 1 AND article_id IN (` + utils.GetOrmInReplace(lenarticleIdArr) + `)`
  361. pars = append(pars, articleIdArr)
  362. listLog, err := models.GetCygxReportSelectionLog(condition, pars, 0, 9999)
  363. if err != nil {
  364. br.Msg = "获取失败"
  365. br.ErrMsg = "获取失败,GetCygxReportSelectionLogErr:" + err.Error()
  366. return
  367. }
  368. for _, v := range listLog {
  369. maplabel[v.ArticleId] += v.SubjectName + ","
  370. }
  371. }
  372. for _, v := range list {
  373. v.SubjectName = strings.TrimRight(maplabel[v.ArticleId], ",")
  374. }
  375. page := paging.GetPaging(currentIndex, pageSize, total)
  376. resp.List = list
  377. resp.Paging = page
  378. br.Ret = 200
  379. br.Success = true
  380. br.Msg = "获取成功"
  381. br.Data = resp
  382. }