report_selection.go 15 KB

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