report_selection.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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. br.Ret = 200
  263. br.Success = true
  264. br.Msg = "记录成功"
  265. }
  266. // @Title 上传文章阅读时间
  267. // @Description 上传文章阅读时间接口
  268. // @Param request body models.AddStopTimeRep true "type json string"
  269. // @Success 200 {object} models.ArticleDetailResp
  270. // @router /addStopTime [post]
  271. func (this *ReportSelectionController) AddStopTime() {
  272. br := new(models.BaseResponse).Init()
  273. defer func() {
  274. this.Data["json"] = br
  275. this.ServeJSON()
  276. }()
  277. user := this.User
  278. if user == nil {
  279. br.Msg = "请登录"
  280. br.ErrMsg = "请登录,用户信息为空"
  281. br.Ret = 408
  282. return
  283. }
  284. var req models.AddReportSelectionStopTimeRep
  285. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  286. if err != nil {
  287. br.Msg = "参数解析异常!"
  288. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  289. return
  290. }
  291. uid := user.UserId
  292. articleId := req.ArticleId
  293. stopTime := req.StopTime
  294. outType := req.OutType
  295. source := req.Source
  296. var reportType string
  297. if source == 1 {
  298. reportType = "bgjx"
  299. } else if source == 2 {
  300. reportType = "bzyjhz"
  301. } else if source == 3 {
  302. reportType = "szjyhz"
  303. }
  304. hasPermission, err := services.GetUserhasPermission(user)
  305. if err != nil {
  306. br.Msg = "获取信息失败"
  307. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  308. }
  309. if hasPermission == 1 {
  310. historyRecord := new(models.CygxReportHistoryRecord)
  311. historyRecord.UserId = uid
  312. historyRecord.ArticleId = articleId
  313. historyRecord.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
  314. historyRecord.Mobile = user.Mobile
  315. historyRecord.Email = user.Email
  316. historyRecord.CompanyId = user.CompanyId
  317. historyRecord.CompanyName = user.CompanyName
  318. historyRecord.StopTime = stopTime
  319. historyRecord.OutType = outType
  320. historyRecord.ReportType = reportType
  321. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  322. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  323. if err != nil && err.Error() != utils.ErrNoRow() {
  324. br.Msg = "获取信息失败"
  325. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  326. return
  327. }
  328. historyRecord.RealName = user.RealName
  329. if sellerItem != nil {
  330. historyRecord.SellerName = sellerItem.RealName
  331. }
  332. go services.AddCygxReportHistoryRecord(historyRecord)
  333. }
  334. br.Ret = 200
  335. br.Success = true
  336. br.Msg = "操作成功"
  337. }
  338. // @Title 获取报告精选列表
  339. // @Description 获取报告精选列表接口
  340. // @Param PageSize query int true "每页数据条数"
  341. // @Param CurrentIndex query int true "当前页页码,从1开始"
  342. // @Success 200 {object} models.ReportSelectionLetailResp
  343. // @router /list [get]
  344. func (this *ReportSelectionController) List() {
  345. br := new(models.BaseResponse).Init()
  346. defer func() {
  347. this.Data["json"] = br
  348. this.ServeJSON()
  349. }()
  350. user := this.User
  351. if user == nil {
  352. br.Msg = "请重新登录"
  353. br.Ret = 408
  354. return
  355. }
  356. resp := new(models.CygxReportSelectionListPublicRep)
  357. pageSize, _ := this.GetInt("PageSize")
  358. currentIndex, _ := this.GetInt("CurrentIndex")
  359. var startSize int
  360. if pageSize <= 0 {
  361. pageSize = utils.PageSize20
  362. }
  363. if currentIndex <= 0 {
  364. currentIndex = 1
  365. }
  366. startSize = utils.StartIndex(currentIndex, pageSize)
  367. var condition string
  368. var pars []interface{}
  369. condition += ` AND art.publish_status = 1 AND article_id >= 16 `
  370. total, err := models.GetCygxReportSelectionCount(condition, pars)
  371. if err != nil {
  372. br.Msg = "获取失败"
  373. br.ErrMsg = "获取失败,Err:" + err.Error()
  374. return
  375. }
  376. condition += " ORDER BY art.publish_date DESC "
  377. list, err := models.GetReportSelectionList(condition, pars, startSize, pageSize)
  378. if err != nil {
  379. br.Msg = "获取失败"
  380. br.ErrMsg = "获取失败,Err:" + err.Error()
  381. return
  382. }
  383. var articleIdArr []int
  384. for _, v := range list {
  385. v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
  386. articleIdArr = append(articleIdArr, v.ArticleId)
  387. }
  388. lenarticleIdArr := len(articleIdArr)
  389. maplabel := make(map[int]string)
  390. if lenarticleIdArr > 0 {
  391. condition = ""
  392. pars = make([]interface{}, 0)
  393. condition = ` AND is_new = 1 AND article_id IN (` + utils.GetOrmInReplace(lenarticleIdArr) + `)`
  394. pars = append(pars, articleIdArr)
  395. listLog, err := models.GetCygxReportSelectionLog(condition, pars, 0, 9999)
  396. if err != nil {
  397. br.Msg = "获取失败"
  398. br.ErrMsg = "获取失败,GetCygxReportSelectionLogErr:" + err.Error()
  399. return
  400. }
  401. for _, v := range listLog {
  402. maplabel[v.ArticleId] += v.SubjectName + ","
  403. }
  404. }
  405. for _, v := range list {
  406. v.SubjectName = strings.TrimRight(maplabel[v.ArticleId], ",")
  407. }
  408. page := paging.GetPaging(currentIndex, pageSize, total)
  409. resp.List = list
  410. resp.Paging = page
  411. br.Ret = 200
  412. br.Success = true
  413. br.Msg = "获取成功"
  414. br.Data = resp
  415. }
  416. // @Title 报告精选申请路演
  417. // @Description 报告精选申请路演
  418. // @Param request body cygx.CygxBannerIdReq true "type json string"
  419. // @Success 200 Ret=200 提交成功
  420. // @router /report_selection_log/apply [post]
  421. func (this *ReportSelectionController) ReportSelectionLogApply() {
  422. br := new(models.BaseResponse).Init()
  423. defer func() {
  424. this.Data["json"] = br
  425. this.ServeJSON()
  426. }()
  427. user := this.User
  428. if user == nil {
  429. br.Msg = "请登录"
  430. br.ErrMsg = "请登录,用户信息为空"
  431. br.Ret = 408
  432. return
  433. }
  434. var req models.CygxReportSelectionLogApplyReq
  435. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  436. if err != nil {
  437. br.Msg = "参数解析异常!"
  438. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  439. return
  440. }
  441. articleId := req.ArticleId
  442. subjectName := req.SubjectName
  443. var condition string
  444. var pars []interface{}
  445. condition += ` AND article_id = ? AND subject_name = ? AND user_id = ? `
  446. pars = append(pars, articleId, subjectName, user.UserId)
  447. totalApply, err := models.GetCygxReportSelectionLogApplyCount(condition, pars)
  448. if err != nil {
  449. br.Msg = "申请失败!"
  450. br.ErrMsg = "申请失败,Err:" + err.Error()
  451. return
  452. }
  453. if totalApply > 0 {
  454. br.Msg = "您已提交过此公司的路演申请,请等待销售与您联系!"
  455. return
  456. }
  457. logDetail, err := models.GetCygxReportSelectionLogDetail(articleId, subjectName)
  458. if err != nil {
  459. br.Msg = "申请失败!"
  460. br.ErrMsg = "申请失败,Err:" + err.Error()
  461. return
  462. }
  463. item := new(models.CygxReportSelectionLogApply)
  464. item.UserId = user.UserId
  465. item.CreateTime = time.Now()
  466. item.ModifyTime = time.Now()
  467. item.Mobile = user.Mobile
  468. item.Email = user.Email
  469. item.CompanyId = user.CompanyId
  470. item.CompanyName = user.CompanyName
  471. item.ArticleId = logDetail.ArticleId
  472. item.SubjectName = logDetail.SubjectName
  473. item.IndustrialSubjectId = logDetail.IndustrialSubjectId
  474. item.RegisterPlatform = utils.REGISTER_PLATFORM
  475. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  476. if err != nil && err.Error() != utils.ErrNoRow() {
  477. return
  478. }
  479. item.RealName = user.RealName
  480. if sellerItem != nil {
  481. item.SellerName = sellerItem.RealName
  482. }
  483. _, err = models.AddCygxReportSelectionLogApply(item)
  484. if err != nil {
  485. br.Msg = "申请失败"
  486. br.ErrMsg = "申请失败,Err:" + err.Error()
  487. return
  488. }
  489. go services.SendCygxReportSelectionLogApplyTemplateMsg(user, logDetail.SubjectName)
  490. br.Ret = 200
  491. br.Success = true
  492. br.Msg = "记录成功"
  493. }