report_selection.go 16 KB

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