report_selection.go 15 KB

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