report_selection.go 16 KB

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