report_selection.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  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. isBestNew, _ := this.GetBool("IsBestNew")
  37. isBestNew = true
  38. if isBestNew {
  39. tbdb := "cygx_report_selection"
  40. condition := ` AND publish_status = 1 `
  41. var pars []interface{}
  42. list, err := models.GetReportSelectionListPublic(condition, "1", tbdb, pars, 0, 1)
  43. if err != nil {
  44. br.Msg = "获取失败"
  45. br.ErrMsg = "获取失败,Err:" + err.Error()
  46. return
  47. }
  48. for _, v := range list {
  49. articleId = v.ArticleId
  50. }
  51. }
  52. if articleId < 1 {
  53. br.Msg = "获取信息失败"
  54. br.ErrMsg = "报告ID错误" + strconv.Itoa(articleId)
  55. return
  56. }
  57. resp := new(models.ReportSelectionLetailResp)
  58. //判断用户权限
  59. hasPermission, err := services.GetUserhasPermission(user)
  60. if err != nil {
  61. br.Msg = "获取信息失败"
  62. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  63. }
  64. detail, err := models.GetCygxReportSelectionInfoById(articleId)
  65. if err != nil {
  66. br.Msg = "获取信息失败"
  67. br.ErrMsg = "报告不存在,Err:" + err.Error() + "articleId:" + strconv.Itoa(articleId)
  68. return
  69. }
  70. //未设置全部可见的只能给弘则内部查看
  71. if detail.VisibleRange == 1 || user.CompanyId == utils.HZ_COMPANY_ID {
  72. resp.IsShow = true
  73. }
  74. resp.HasPermission = hasPermission
  75. if hasPermission != 1 || !resp.IsShow {
  76. resp.Detail = detail
  77. br.Ret = 200
  78. br.Success = true
  79. br.Msg = "获取成功"
  80. br.Data = resp
  81. return
  82. }
  83. if detail.ReportLink != "" {
  84. articleIdLink, _ := services.GetReportLinkToArticleid(detail.ReportLink)
  85. detail.CeLueArticleId = articleIdLink
  86. }
  87. articleStockMap, _ := services.GetArticleStockMap()
  88. detail.PublishDate = utils.StrTimeToTime(detail.PublishDate).Format("2006-01-02")
  89. existMap := make(map[int]int)
  90. var items []*models.ReportSelectionChartPermission
  91. var itemsSubject []*models.ReportSelectionChartLogPermission
  92. listLog, err := models.GetReportSelectionlogListAll(articleId)
  93. if err != nil {
  94. br.Msg = "获取失败"
  95. br.ErrMsg = "获取子类信息失败,Err:" + err.Error()
  96. return
  97. }
  98. detail.VideoPlaySeconds = utils.Mp3Time(detail.VideoPlaySeconds)
  99. //获取行业核心逻辑汇总
  100. listChartLog, err := models.GetCygxReportSelectionChartLogRepList(articleId)
  101. if err != nil {
  102. br.Msg = "获取失败"
  103. br.ErrMsg = "获取失败,Err:" + err.Error()
  104. return
  105. }
  106. mapChartLog := make(map[string]string)
  107. for _, v := range listChartLog {
  108. mapChartLog[v.ChartPermissionName] = v.BodyChartSummary
  109. }
  110. for _, v := range listLog {
  111. item := new(models.ReportSelectionChartPermission)
  112. itemSubject := new(models.ReportSelectionChartLogPermission)
  113. itemSubject.PermissionName = v.PermissionName
  114. if existMap[v.ChartPermissionId] == 0 {
  115. //item.PermissionName = v.PermissionName + "领域深度报告和调研"
  116. item.PermissionName = v.PermissionName
  117. item.IcoLink = v.IcoLink
  118. listSonLog, err := models.GetReportSelectionlogSonListAll(articleId, v.ChartPermissionId)
  119. if err != nil && err.Error() != utils.ErrNoRow() {
  120. br.Msg = "获取信息失败"
  121. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  122. return
  123. }
  124. for k2, v2 := range listSonLog {
  125. if v2.IndustrialManagementId != "" {
  126. listIndustrial, err := models.GetIndustrialByIds(v2.IndustrialManagementId)
  127. if err != nil && err.Error() != utils.ErrNoRow() {
  128. br.Msg = "获取信息失败"
  129. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  130. return
  131. }
  132. listSonLog[k2].OverviewArticleId = articleStockMap[v2.SubjectName]
  133. listSonLog[k2].List = listIndustrial
  134. if v2.Label != "" {
  135. v2.CompanyLabel = strings.Split(v2.Label, "{|}")
  136. }
  137. }
  138. itemSubject.ListSubject = append(itemSubject.ListSubject, &models.ReportSelectionChartLogSubjectName{SubjectName: v2.SubjectName, IsNew: v2.IsNew, IndustrialSubjectId: v2.IndustrialSubjectId})
  139. }
  140. item.BodyChartSummary = mapChartLog[v.PermissionName]
  141. item.List = listSonLog
  142. items = append(items, item)
  143. itemsSubject = append(itemsSubject, itemSubject)
  144. //itemLogs = make([]*models.CygxReportSelectionLogDetail, 0)
  145. }
  146. existMap[v.ChartPermissionId] = v.ChartPermissionId
  147. }
  148. //historyRecord := new(models.CygxReportHistoryRecord)
  149. //historyRecord.UserId = uid
  150. //historyRecord.ArticleId = articleId
  151. //historyRecord.CreateTime = time.Now()
  152. //historyRecord.Mobile = user.Mobile
  153. //historyRecord.Email = user.Email
  154. //historyRecord.CompanyId = user.CompanyId
  155. //historyRecord.CompanyName = user.CompanyName
  156. //historyRecord.ReportType = "bgjx"
  157. //sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  158. //if err != nil && err.Error() != utils.ErrNoRow() {
  159. // br.Msg = "获取信息失败"
  160. // br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  161. // return
  162. //}
  163. //historyRecord.RealName = user.RealName
  164. //if sellerItem != nil {
  165. // historyRecord.SellerName = sellerItem.RealName
  166. //}
  167. //
  168. //go models.AddCygxReportHistoryRecord(historyRecord)
  169. resp.List = items
  170. resp.ListPermissionSubject = itemsSubject
  171. resp.Detail = detail
  172. br.Ret = 200
  173. br.Success = true
  174. br.Msg = "获取成功"
  175. br.Data = resp
  176. }
  177. // @Title 标的点击记录
  178. // @Description 标的点击记录接口
  179. // @Param request body models.AddCygxReportSelectionSubjectHistoryReq true "type json string"
  180. // @router /click/history [post]
  181. func (this *ReportSelectionController) ClickHistory() {
  182. br := new(models.BaseResponse).Init()
  183. defer func() {
  184. this.Data["json"] = br
  185. this.ServeJSON()
  186. }()
  187. user := this.User
  188. if user == nil {
  189. br.Msg = "请重新登录"
  190. br.Ret = 408
  191. return
  192. }
  193. var req models.AddCygxReportSelectionSubjectHistoryReq
  194. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  195. if err != nil {
  196. br.Msg = "参数解析异常!"
  197. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  198. return
  199. }
  200. if req.ArticleId <= 0 {
  201. br.Msg = "文章不存在"
  202. br.ErrMsg = "文章不存在,文章ID错误"
  203. return
  204. }
  205. if req.IndustrialSubjectId <= 0 {
  206. br.Msg = "标的ID不存在"
  207. br.ErrMsg = "标的ID不存在,标的ID错误"
  208. return
  209. }
  210. item := models.CygxReportSelectionSubjectHistory{
  211. UserId: user.UserId,
  212. ArticleId: req.ArticleId,
  213. CreateTime: time.Now(),
  214. ModifyTime: time.Now(),
  215. Mobile: user.Mobile,
  216. Email: user.Email,
  217. CompanyId: user.CompanyId,
  218. CompanyName: user.CompanyName,
  219. IndustrialSubjectId: req.IndustrialSubjectId,
  220. }
  221. err = models.AddCygxReportSelectionSubjectHistory(&item)
  222. if err != nil {
  223. br.Msg = "记录失败"
  224. br.ErrMsg = "记录失败,Err:" + err.Error()
  225. return
  226. }
  227. br.Ret = 200
  228. br.Success = true
  229. br.Msg = "记录成功"
  230. }
  231. // @Title 上传文章阅读时间
  232. // @Description 上传文章阅读时间接口
  233. // @Param request body models.AddStopTimeRep true "type json string"
  234. // @Success 200 {object} models.ArticleDetailResp
  235. // @router /addStopTime [post]
  236. func (this *ReportSelectionController) AddStopTime() {
  237. br := new(models.BaseResponse).Init()
  238. defer func() {
  239. this.Data["json"] = br
  240. this.ServeJSON()
  241. }()
  242. user := this.User
  243. if user == nil {
  244. br.Msg = "请登录"
  245. br.ErrMsg = "请登录,用户信息为空"
  246. br.Ret = 408
  247. return
  248. }
  249. var req models.AddReportSelectionStopTimeRep
  250. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  251. if err != nil {
  252. br.Msg = "参数解析异常!"
  253. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  254. return
  255. }
  256. uid := user.UserId
  257. articleId := req.ArticleId
  258. stopTime := req.StopTime
  259. outType := req.OutType
  260. source := req.Source
  261. var reportType string
  262. if source == 1 {
  263. reportType = "bgjx"
  264. } else if source == 2 {
  265. reportType = "bzyjhz"
  266. } else if source == 3 {
  267. reportType = "szjyhz"
  268. }
  269. hasPermission, err := services.GetUserhasPermission(user)
  270. if err != nil {
  271. br.Msg = "获取信息失败"
  272. br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
  273. }
  274. if hasPermission == 1 {
  275. historyRecord := new(models.CygxReportHistoryRecord)
  276. historyRecord.UserId = uid
  277. historyRecord.ArticleId = articleId
  278. historyRecord.CreateTime = time.Now()
  279. historyRecord.Mobile = user.Mobile
  280. historyRecord.Email = user.Email
  281. historyRecord.CompanyId = user.CompanyId
  282. historyRecord.CompanyName = user.CompanyName
  283. historyRecord.StopTime = stopTime
  284. historyRecord.OutType = outType
  285. historyRecord.ReportType = reportType
  286. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  287. if err != nil && err.Error() != utils.ErrNoRow() {
  288. br.Msg = "获取信息失败"
  289. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  290. return
  291. }
  292. historyRecord.RealName = user.RealName
  293. if sellerItem != nil {
  294. historyRecord.SellerName = sellerItem.RealName
  295. }
  296. go services.AddCygxReportHistoryRecord(historyRecord)
  297. }
  298. br.Ret = 200
  299. br.Success = true
  300. br.Msg = "操作成功"
  301. }
  302. func init() {
  303. st, _ := time.ParseDuration("-500s")
  304. fmt.Println(st)
  305. fmt.Println()
  306. fmt.Println("50秒之后的时间:", time.Now().Add(st))
  307. startDate := time.Now().Add(-time.Second * 300).Format(utils.FormatDateTime)
  308. fmt.Println(startDate)
  309. }