report_selection.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/services"
  8. "hongze/hongze_cygx/utils"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. // 报告
  14. type ReportSelectionController struct {
  15. BaseAuthController
  16. }
  17. // @Title 获取报告精选详情
  18. // @Description 获取报告精选详情接口
  19. // @Param ArticleId query int true "报告ID"
  20. // @Param IsBestNew query bool false "是否获取最新的一篇报告"
  21. // @Success 200 {object} models.ReportSelectionLetailResp
  22. // @router /detail [get]
  23. func (this *ReportSelectionController) Detail() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. user := this.User
  30. if user == nil {
  31. br.Msg = "请重新登录"
  32. br.Ret = 408
  33. return
  34. }
  35. //uid := user.UserId
  36. articleId, _ := this.GetInt("ArticleId")
  37. activityId, _ := this.GetInt("ActivityId")
  38. isBestNew, _ := this.GetBool("IsBestNew")
  39. if activityId > 0 && articleId == 0 {
  40. articleId = activityId
  41. }
  42. if articleId == 0 || isBestNew {
  43. isBestNew = true
  44. if isBestNew {
  45. tbdb := "cygx_report_selection"
  46. condition := ` AND publish_status = 1 `
  47. var pars []interface{}
  48. list, err := models.GetReportSelectionListPublic(condition, "1", tbdb, pars, 0, 1)
  49. if err != nil {
  50. br.Msg = "获取失败"
  51. br.ErrMsg = "获取失败,Err:" + err.Error()
  52. return
  53. }
  54. for _, v := range list {
  55. articleId = v.ArticleId
  56. }
  57. }
  58. }
  59. if articleId < 1 {
  60. br.Msg = "获取信息失败"
  61. br.ErrMsg = "报告ID错误" + strconv.Itoa(articleId)
  62. return
  63. }
  64. PermissionNameMap, err := services.GetPermissionNameMap()
  65. if err != nil {
  66. br.Msg = "获取失败"
  67. br.ErrMsg = "获取失败 GetPermissionNameMap,Err:" + err.Error()
  68. return
  69. }
  70. PermissionIcoMap, err := services.GetPermissionNameIcoMap()
  71. if err != nil {
  72. br.Msg = "获取失败"
  73. br.ErrMsg = "获取失败 GetPermissionNameMap,Err:" + err.Error()
  74. return
  75. }
  76. resp := new(models.ReportSelectionLetailResp)
  77. //判断用户权限
  78. hasPermission, err := services.GetUserhasPermissionReportSelection(user)
  79. if err != nil {
  80. br.Msg = "获取信息失败"
  81. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  82. }
  83. detail, err := models.GetCygxReportSelectionInfoById(articleId)
  84. if err != nil {
  85. br.Msg = "获取信息失败"
  86. br.ErrMsg = "报告不存在,Err:" + err.Error() + "articleId:" + strconv.Itoa(articleId)
  87. return
  88. }
  89. //未设置全部可见的只能给弘则内部查看
  90. if detail.VisibleRange == 1 || user.CompanyId == utils.HZ_COMPANY_ID {
  91. resp.IsShow = true
  92. }
  93. resp.HasPermission = hasPermission
  94. if !resp.IsShow {
  95. br.Ret = 201
  96. br.Success = true
  97. br.Msg = "获取成功"
  98. br.Data = resp
  99. return
  100. }
  101. if hasPermission != 1 || !resp.IsShow {
  102. resp.Detail = detail
  103. br.Ret = 200
  104. br.Success = true
  105. br.Msg = "获取成功"
  106. br.Data = resp
  107. return
  108. }
  109. if detail.ReportLink != "" {
  110. articleIdLink, _ := services.GetReportLinkToArticleid(detail.ReportLink)
  111. detail.CeLueArticleId = articleIdLink
  112. }
  113. articleStockMap, _ := services.GetArticleStockMap()
  114. detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  115. existMap := make(map[int]int)
  116. var items []*models.ReportSelectionChartPermission
  117. var itemsSubject []*models.ReportSelectionChartLogPermission
  118. listLog, err := models.GetReportSelectionlogListAll(articleId)
  119. if err != nil {
  120. br.Msg = "获取失败"
  121. br.ErrMsg = "获取子类信息失败,Err:" + err.Error()
  122. return
  123. }
  124. detail.VideoPlaySeconds = utils.Mp3Time(detail.VideoPlaySeconds)
  125. //获取行业核心逻辑汇总
  126. listChartLog, err := models.GetCygxReportSelectionChartLogRepList(articleId)
  127. if err != nil {
  128. br.Msg = "获取失败"
  129. br.ErrMsg = "获取失败,Err:" + err.Error()
  130. return
  131. }
  132. mapChartLog := make(map[string]string)
  133. for _, v := range listChartLog {
  134. mapChartLog[v.ChartPermissionName] = v.BodyChartSummary
  135. }
  136. for _, v := range listLog {
  137. v.PermissionName = PermissionNameMap[v.ChartPermissionId]
  138. item := new(models.ReportSelectionChartPermission)
  139. itemSubject := new(models.ReportSelectionChartLogPermission)
  140. itemSubject.PermissionName = v.PermissionName
  141. if existMap[v.ChartPermissionId] == 0 {
  142. //item.PermissionName = v.PermissionName + "领域深度报告和调研"
  143. item.PermissionName = v.PermissionName
  144. item.IcoLink = v.IcoLink
  145. listSonLog, err := models.GetReportSelectionlogSonListAll(articleId, v.ChartPermissionId)
  146. if err != nil && err.Error() != utils.ErrNoRow() {
  147. br.Msg = "获取信息失败"
  148. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  149. return
  150. }
  151. for k2, v2 := range listSonLog {
  152. if v2.IndustrialManagementId != "" {
  153. listIndustrial, err := models.GetIndustrialByIds(v2.IndustrialManagementId)
  154. if err != nil && err.Error() != utils.ErrNoRow() {
  155. br.Msg = "获取信息失败"
  156. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  157. return
  158. }
  159. //后台如果勾了隐藏那么这里就不展示 V11.3 2023-08-17
  160. if listSonLog[k2].IsShowOverviewArticle == 1 {
  161. listSonLog[k2].OverviewArticleId = articleStockMap[v2.SubjectName]
  162. } else {
  163. listSonLog[k2].OverviewArticleId = 0
  164. }
  165. listSonLog[k2].List = listIndustrial
  166. //listSonLog[k2].IsShowApplyButton = true
  167. if v2.SubjectName == "" {
  168. v2.ShowName = v2.IndustrialManagementNames
  169. } else {
  170. v2.ShowName = v2.SubjectName
  171. }
  172. }
  173. if v2.Label != "" {
  174. v2.CompanyLabel = strings.Split(v2.Label, "{|}")
  175. }
  176. if v2.ThirdName != "" {
  177. v2.ShowName = v2.ThirdName
  178. }
  179. subjectItem := new(models.ReportSelectionChartLogSubjectName)
  180. subjectItem.SubjectName = v2.SubjectName
  181. subjectItem.IsNew = v2.IsNew
  182. subjectItem.IndustrialSubjectId = v2.IndustrialSubjectId
  183. subjectItem.IndustrialManagementId, _ = strconv.Atoi(v2.IndustrialManagementId)
  184. subjectItem.IndustrialManagementName = v2.IndustrialManagementNames
  185. subjectItem.ThirdId = v2.ThirdId
  186. if v2.ThirdName != "" {
  187. subjectItem.SubjectName = v2.ThirdName
  188. } else {
  189. if subjectItem.SubjectName == "" {
  190. subjectItem.SubjectName = subjectItem.IndustrialManagementName
  191. }
  192. }
  193. subjectItem.Md5String = utils.MD5(fmt.Sprint("IN_ID", v2.IndustrialManagementId, "S_ID", v2.IndustrialSubjectId, "T_ID", v2.ThirdId))
  194. v2.Md5String = subjectItem.Md5String
  195. itemSubject.ListSubject = append(itemSubject.ListSubject, subjectItem)
  196. //itemSubject.ListSubject = append(itemSubject.ListSubject, &models.ReportSelectionChartLogSubjectName{SubjectName: v2.SubjectName, IsNew: v2.IsNew, IndustrialSubjectId: v2.IndustrialSubjectId})
  197. }
  198. item.BodyChartSummary = mapChartLog[v.PermissionName]
  199. item.List = listSonLog
  200. item.PermissionName = PermissionNameMap[v.ChartPermissionId]
  201. item.IcoLink = PermissionIcoMap[v.ChartPermissionId]
  202. items = append(items, item)
  203. itemsSubject = append(itemsSubject, itemSubject)
  204. //itemLogs = make([]*models.CygxReportSelectionLogDetail, 0)
  205. }
  206. existMap[v.ChartPermissionId] = v.ChartPermissionId
  207. }
  208. resp.List = items
  209. resp.ListPermissionSubject = itemsSubject
  210. resp.Detail = detail
  211. br.Ret = 200
  212. br.Success = true
  213. br.Msg = "获取成功"
  214. br.Data = resp
  215. }
  216. // @Title 标的点击记录
  217. // @Description 标的点击记录接口
  218. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  219. // @router /click/history [post]
  220. func (this *ReportSelectionController) ClickHistory() {
  221. br := new(models.BaseResponse).Init()
  222. defer func() {
  223. this.Data["json"] = br
  224. this.ServeJSON()
  225. }()
  226. user := this.User
  227. if user == nil {
  228. br.Msg = "请重新登录"
  229. br.Ret = 408
  230. return
  231. }
  232. var req models.AddCygxReportSelectionSubjectHistoryReq
  233. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  234. if err != nil {
  235. br.Msg = "参数解析异常!"
  236. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  237. return
  238. }
  239. if req.ArticleId <= 0 {
  240. br.Msg = "文章不存在"
  241. br.ErrMsg = "文章不存在,文章ID错误"
  242. return
  243. }
  244. if req.IndustrialSubjectId+req.IndustrialManagementId+req.ThirdId <= 0 {
  245. br.Msg = "标的ID不存在"
  246. br.ErrMsg = "产业或标的ID不存在"
  247. return
  248. }
  249. item := models.CygxReportSelectionSubjectHistory{
  250. UserId: user.UserId,
  251. ArticleId: req.ArticleId,
  252. CreateTime: time.Now(),
  253. ModifyTime: time.Now(),
  254. Mobile: user.Mobile,
  255. Email: user.Email,
  256. CompanyId: user.CompanyId,
  257. CompanyName: user.CompanyName,
  258. IndustrialSubjectId: req.IndustrialSubjectId,
  259. IndustrialManagementId: req.IndustrialManagementId,
  260. ThirdId: req.ThirdId,
  261. RegisterPlatform: utils.REGISTER_PLATFORM,
  262. }
  263. err = models.AddCygxReportSelectionSubjectHistory(&item)
  264. if err != nil {
  265. br.Msg = "记录失败"
  266. br.ErrMsg = "记录失败,Err:" + err.Error()
  267. return
  268. }
  269. go services.GetReportSelectionLabelName(req, user.UserId) //记录用户在重点公司单独点了某一个标签
  270. br.Ret = 200
  271. br.Success = true
  272. br.Msg = "记录成功"
  273. }
  274. // @Title 上传文章阅读时间
  275. // @Description 上传文章阅读时间接口
  276. // @Param request body models.AddStopTimeRep true "type json string"
  277. // @Success 200 {object} models.ArticleDetailResp
  278. // @router /addStopTime [post]
  279. func (this *ReportSelectionController) AddStopTime() {
  280. br := new(models.BaseResponse).Init()
  281. defer func() {
  282. this.Data["json"] = br
  283. this.ServeJSON()
  284. }()
  285. user := this.User
  286. if user == nil {
  287. br.Msg = "请登录"
  288. br.ErrMsg = "请登录,用户信息为空"
  289. br.Ret = 408
  290. return
  291. }
  292. var req models.AddReportSelectionStopTimeRep
  293. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  294. if err != nil {
  295. br.Msg = "参数解析异常!"
  296. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  297. return
  298. }
  299. uid := user.UserId
  300. articleId := req.ArticleId
  301. stopTime := req.StopTime
  302. outType := req.OutType
  303. source := req.Source
  304. var reportType string
  305. var tableName, label string
  306. if source == 1 {
  307. reportType = "bgjx"
  308. tableName = "cygx_report_selection"
  309. label = "重点推荐"
  310. } else if source == 2 {
  311. reportType = "bzyjhz"
  312. tableName = "cygx_research_summary"
  313. label = "本周研究汇总"
  314. } else if source == 3 {
  315. reportType = "szjyhz"
  316. }
  317. var hasPermission int
  318. if source == 1 {
  319. hasPermission, err = services.GetUserhasPermissionReportSelection(user)
  320. } else {
  321. hasPermission, err = services.GetUserhasPermission(user)
  322. }
  323. if err != nil {
  324. br.Msg = "获取信息失败"
  325. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  326. }
  327. if hasPermission == 1 {
  328. historyRecord := new(models.CygxReportHistoryRecord)
  329. historyRecord.UserId = uid
  330. historyRecord.ArticleId = articleId
  331. historyRecord.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  332. historyRecord.Mobile = user.Mobile
  333. historyRecord.Email = user.Email
  334. historyRecord.CompanyId = user.CompanyId
  335. historyRecord.CompanyName = user.CompanyName
  336. historyRecord.StopTime = stopTime
  337. historyRecord.OutType = outType
  338. historyRecord.ReportType = reportType
  339. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  340. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  341. if err != nil && err.Error() != utils.ErrNoRow() {
  342. br.Msg = "获取信息失败"
  343. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  344. return
  345. }
  346. historyRecord.RealName = user.RealName
  347. if sellerItem != nil {
  348. historyRecord.SellerName = sellerItem.RealName
  349. }
  350. go services.AddCygxReportHistoryRecord(historyRecord)
  351. if tableName != "" {
  352. go services.ReportSelectionWxUserRaiLabelRedisAdd(articleId, uid, historyRecord.CreateTime, tableName, label)
  353. }
  354. }
  355. br.Ret = 200
  356. br.Success = true
  357. br.Msg = "操作成功"
  358. }
  359. // @Title 获取报告精选列表
  360. // @Description 获取报告精选列表接口
  361. // @Param PageSize query int true "每页数据条数"
  362. // @Param CurrentIndex query int true "当前页页码,从1开始"
  363. // @Success 200 {object} models.ReportSelectionLetailResp
  364. // @router /list [get]
  365. func (this *ReportSelectionController) List() {
  366. br := new(models.BaseResponse).Init()
  367. defer func() {
  368. this.Data["json"] = br
  369. this.ServeJSON()
  370. }()
  371. user := this.User
  372. if user == nil {
  373. br.Msg = "请重新登录"
  374. br.Ret = 408
  375. return
  376. }
  377. resp := new(models.CygxReportSelectionListPublicRep)
  378. pageSize, _ := this.GetInt("PageSize")
  379. currentIndex, _ := this.GetInt("CurrentIndex")
  380. var startSize int
  381. if pageSize <= 0 {
  382. pageSize = utils.PageSize20
  383. }
  384. if currentIndex <= 0 {
  385. currentIndex = 1
  386. }
  387. startSize = utils.StartIndex(currentIndex, pageSize)
  388. var condition string
  389. var pars []interface{}
  390. condition += ` AND art.publish_status = 1 AND article_id >= 16 `
  391. total, err := models.GetCygxReportSelectionCount(condition, pars)
  392. if err != nil {
  393. br.Msg = "获取失败"
  394. br.ErrMsg = "获取失败,Err:" + err.Error()
  395. return
  396. }
  397. condition += " ORDER BY art.publish_date DESC "
  398. list, err := models.GetReportSelectionList(condition, pars, startSize, pageSize)
  399. if err != nil {
  400. br.Msg = "获取失败"
  401. br.ErrMsg = "获取失败,Err:" + err.Error()
  402. return
  403. }
  404. var articleIdArr []int
  405. for _, v := range list {
  406. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  407. articleIdArr = append(articleIdArr, v.ArticleId)
  408. }
  409. lenarticleIdArr := len(articleIdArr)
  410. maplabel := make(map[int]string)
  411. if lenarticleIdArr > 0 {
  412. condition = ""
  413. pars = make([]interface{}, 0)
  414. condition = ` AND is_new = 1 AND article_id IN (` + utils.GetOrmInReplace(lenarticleIdArr) + `)`
  415. pars = append(pars, articleIdArr)
  416. listLog, err := models.GetCygxReportSelectionLog(condition, pars, 0, 9999)
  417. if err != nil {
  418. br.Msg = "获取失败"
  419. br.ErrMsg = "获取失败,GetCygxReportSelectionLogErr:" + err.Error()
  420. return
  421. }
  422. for _, v := range listLog {
  423. maplabel[v.ArticleId] += v.SubjectName + ","
  424. }
  425. }
  426. for _, v := range list {
  427. v.SubjectName = strings.TrimRight(maplabel[v.ArticleId], ",")
  428. }
  429. page := paging.GetPaging(currentIndex, pageSize, total)
  430. resp.List = list
  431. resp.Paging = page
  432. br.Ret = 200
  433. br.Success = true
  434. br.Msg = "获取成功"
  435. br.Data = resp
  436. }
  437. // @Title 报告精选申请路演
  438. // @Description 报告精选申请路演
  439. // @Param request body cygx.CygxBannerIdReq true "type json string"
  440. // @Success 200 Ret=200 提交成功
  441. // @router /report_selection_log/apply [post]
  442. func (this *ReportSelectionController) ReportSelectionLogApply() {
  443. br := new(models.BaseResponse).Init()
  444. defer func() {
  445. this.Data["json"] = br
  446. this.ServeJSON()
  447. }()
  448. user := this.User
  449. if user == nil {
  450. br.Msg = "请登录"
  451. br.ErrMsg = "请登录,用户信息为空"
  452. br.Ret = 408
  453. return
  454. }
  455. var req models.CygxReportSelectionLogApplyReq
  456. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  457. if err != nil {
  458. br.Msg = "参数解析异常!"
  459. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  460. return
  461. }
  462. articleId := req.ArticleId
  463. subjectName := req.SubjectName
  464. var condition string
  465. var pars []interface{}
  466. condition += ` AND article_id = ? AND subject_name = ? AND user_id = ? `
  467. pars = append(pars, articleId, subjectName, user.UserId)
  468. totalApply, err := models.GetCygxReportSelectionLogApplyCount(condition, pars)
  469. if err != nil {
  470. br.Msg = "申请失败!"
  471. br.ErrMsg = "申请失败,Err:" + err.Error()
  472. return
  473. }
  474. if totalApply > 0 {
  475. br.Msg = "您已提交过此公司的路演申请,请等待销售与您联系!"
  476. return
  477. }
  478. logDetail, err := models.GetCygxReportSelectionLogDetail(articleId, subjectName)
  479. if err != nil {
  480. br.Msg = "申请失败!"
  481. br.ErrMsg = "申请失败,Err:" + err.Error()
  482. return
  483. }
  484. item := new(models.CygxReportSelectionLogApply)
  485. item.UserId = user.UserId
  486. item.CreateTime = time.Now()
  487. item.ModifyTime = time.Now()
  488. item.Mobile = user.Mobile
  489. item.Email = user.Email
  490. item.CompanyId = user.CompanyId
  491. item.CompanyName = user.CompanyName
  492. item.ArticleId = logDetail.ArticleId
  493. item.SubjectName = logDetail.SubjectName
  494. item.IndustrialSubjectId = logDetail.IndustrialSubjectId
  495. item.RegisterPlatform = utils.REGISTER_PLATFORM
  496. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  497. if err != nil && err.Error() != utils.ErrNoRow() {
  498. return
  499. }
  500. item.RealName = user.RealName
  501. if sellerItem != nil {
  502. item.SellerName = sellerItem.RealName
  503. }
  504. _, err = models.AddCygxReportSelectionLogApply(item)
  505. if err != nil {
  506. br.Msg = "申请失败"
  507. br.ErrMsg = "申请失败,Err:" + err.Error()
  508. return
  509. }
  510. go services.SendCygxReportSelectionLogApplyTemplateMsg(user, logDetail.SubjectName)
  511. br.Ret = 200
  512. br.Success = true
  513. br.Msg = "记录成功"
  514. }